• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef OHOS_AUDIO_DEVICE_MANAGER_H
17 #define OHOS_AUDIO_DEVICE_MANAGER_H
18 
19 #include "audio_device_info.h"
20 #include "audio_routing_manager.h"
21 #include "migrate_avsession_server.h"
22 
23 namespace OHOS::AVSession {
24 enum OutputDevice {
25     AUDIO_OUTPUT_SINK = 0,
26     AUDIO_OUTPUT_SOURCE
27 };
28 
29 class AudioDeviceManager {
30 public:
31     AudioDeviceManager() = default;
32     ~AudioDeviceManager() = default;
33     static AudioDeviceManager &GetInstance();
34     bool GetSessionInfoSyncState();
35     void InitAudioStateCallback(std::shared_ptr<MigrateAVSessionServer> migrateAVSession,
36         std::string deviceId);
37     void UnInitAudioStateCallback();
38     void SendRemoteAvSessionInfo(const std::string &deviceId);
39     void ClearRemoteAvSessionInfo(const std::string &deviceId);
40     void SetAudioState(int32_t state);
41     int32_t GetAudioState();
42     std::string GetDeviceId();
43 
44 private:
45     void RegisterAudioDeviceChangeCallback();
46     void UnRegisterAudioDeviceChangeCallback();
47     void RegisterPreferedOutputDeviceChangeCallback();
48     void UnRegisterPreferedOutputDeviceChangeCallback();
49     std::shared_ptr<AudioStandard::AudioManagerDeviceChangeCallback> audioDeviceChangeCallback_;
50     std::shared_ptr<AudioStandard::AudioPreferredOutputDeviceChangeCallback> audioPreferedOutputDeviceChangeCallback_;
51     bool isRegistered_ = false;
52     std::shared_ptr<MigrateAVSessionServer> migrateSession_;
53     std::string deviceId_;
54     int32_t outputDevice_ = AUDIO_OUTPUT_SINK;
55 };
56 
57 class DeviceChangeCallback : public AudioStandard::AudioManagerDeviceChangeCallback {
58 public:
59     void OnDeviceChange(const AudioStandard::DeviceChangeAction& deviceChangeAction) override;
60 };
61 
62 class OutputDeviceChangeCallback : public AudioStandard::AudioPreferredOutputDeviceChangeCallback {
63 public:
64     void OnPreferredOutputDeviceUpdated(
65         const std::vector<std::shared_ptr<AudioStandard::AudioDeviceDescriptor>> &desc) override;
66 private:
67     std::recursive_mutex lock_;
68 };
69 }
70 #endif