• 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 RegisterPreferedOutputDeviceChangeCallback();
46     void UnRegisterPreferedOutputDeviceChangeCallback();
47     void RegisterAudioDeviceChangeCallback();
48     void UnRegisterAudioDeviceChangeCallback();
49     std::shared_ptr<AudioStandard::AudioPreferredOutputDeviceChangeCallback> audioPreferedOutputDeviceChangeCallback_;
50     std::shared_ptr<AudioStandard::AudioManagerDeviceChangeCallback> audioDeviceChangeCallback_;
51 
52     bool isRegistered_ = false;
53     std::shared_ptr<MigrateAVSessionServer> migrateSession_;
54     std::string deviceId_;
55     int32_t outputDevice_ = AUDIO_OUTPUT_SOURCE;
56 };
57 
58 class OutputDeviceChangeCallback : public AudioStandard::AudioPreferredOutputDeviceChangeCallback {
59 public:
60     void OnPreferredOutputDeviceUpdated(
61         const std::vector<std::shared_ptr<AudioStandard::AudioDeviceDescriptor>> &desc) override;
62 private:
63     std::recursive_mutex lock_;
64 };
65 
66 class DeviceChangeCallback : public AudioStandard::AudioManagerDeviceChangeCallback {
67 public:
68     void OnDeviceChange(const AudioStandard::DeviceChangeAction &deviceChangeAction) override;
69 };
70 }
71 #endif