• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 AUDIO_SYSTEM_MANAGER_ADAPTER_H
17 #define AUDIO_SYSTEM_MANAGER_ADAPTER_H
18 
19 #include <vector>
20 
21 #include "audio_renderer_adapter.h"
22 
23 namespace OHOS::NWeb {
24 enum class AudioAdapterStreamType {
25     STREAM_DEFAULT = -1,
26     STREAM_VOICE_CALL = 0,
27     STREAM_MUSIC = 1,
28     STREAM_RING = 2,
29     STREAM_MEDIA = 3,
30     STREAM_VOICE_ASSISTANT = 4,
31     STREAM_SYSTEM = 5,
32     STREAM_ALARM = 6,
33     STREAM_NOTIFICATION = 7,
34     STREAM_BLUETOOTH_SCO = 8,
35     STREAM_ENFORCED_AUDIBLE = 9,
36     STREAM_DTMF = 10,
37     STREAM_TTS = 11,
38     STREAM_ACCESSIBILITY = 12,
39     STREAM_RECORDING = 13,
40     STREAM_ALL = 100
41 };
42 
43 enum AdapterDeviceFlag {
44     NONE_DEVICES_FLAG = 0,
45     OUTPUT_DEVICES_FLAG = 1,
46     INPUT_DEVICES_FLAG = 2,
47     ALL_DEVICES_FLAG = 3,
48     DISTRIBUTED_OUTPUT_DEVICES_FLAG = 4,
49     DISTRIBUTED_INPUT_DEVICES_FLAG = 8,
50     ALL_DISTRIBUTED_DEVICES_FLAG = 12,
51     ALL_L_D_DEVICES_FLAG = 15,
52     DEVICE_FLAG_MAX
53 };
54 
55 struct AudioAdapterInterrupt {
56     AudioAdapterStreamUsage streamUsage;
57     AudioAdapterContentType contentType;
58     AudioAdapterStreamType streamType;
59     uint32_t sessionID;
60     bool pauseWhenDucked;
61 };
62 
63 struct AudioAdapterDeviceDesc {
64     int32_t deviceId;
65     std::string deviceName;
66 };
67 
68 class AudioManagerCallbackAdapter {
69 public:
70     AudioManagerCallbackAdapter() = default;
71 
72     virtual ~AudioManagerCallbackAdapter() = default;
73 
74     virtual void OnSuspend() = 0;
75 
76     virtual void OnResume() = 0;
77 };
78 
79 class AudioManagerDeviceChangeCallbackAdapter {
80 public:
81     AudioManagerDeviceChangeCallbackAdapter() = default;
82 
83     virtual ~AudioManagerDeviceChangeCallbackAdapter() = default;
84 
85     virtual void OnDeviceChange() = 0;
86 };
87 
88 class AudioSystemManagerAdapter {
89 public:
90     AudioSystemManagerAdapter() = default;
91 
92     virtual ~AudioSystemManagerAdapter() = default;
93 
94     virtual bool HasAudioOutputDevices() const = 0;
95 
96     virtual bool HasAudioInputDevices() const = 0;
97 
98     virtual int32_t RequestAudioFocus(const AudioAdapterInterrupt& audioInterrupt) = 0;
99 
100     virtual int32_t AbandonAudioFocus(const AudioAdapterInterrupt& audioInterrupt) = 0;
101 
102     virtual int32_t SetAudioManagerInterruptCallback(const std::shared_ptr<AudioManagerCallbackAdapter>& callback) = 0;
103 
104     virtual int32_t UnsetAudioManagerInterruptCallback() = 0;
105 
106     virtual std::vector<AudioAdapterDeviceDesc> GetDevices(AdapterDeviceFlag flag) const = 0;
107 
108     virtual int32_t SelectAudioDevice(AudioAdapterDeviceDesc desc, bool isInput) const = 0;
109 
110     virtual int32_t SetDeviceChangeCallback(
111         const std::shared_ptr<AudioManagerDeviceChangeCallbackAdapter>& callback) = 0;
112 
113     virtual int32_t UnsetDeviceChangeCallback() = 0;
114 
115     virtual AudioAdapterDeviceDesc GetDefaultOutputDevice() = 0;
116 };
117 } // namespace OHOS::NWeb
118 
119 #endif // AUDIO_RENDERER_ADAPTER_H