• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 #ifndef AUDIO_DEVICE_INFO_H
16 #define AUDIO_DEVICE_INFO_H
17 
18 #include <parcel.h>
19 #include <audio_stream_info.h>
20 #include <set>
21 #include <limits>
22 #include <unordered_set>
23 #include "audio_device_stream_info.h"
24 
25 namespace OHOS {
26 namespace AudioStandard {
27 constexpr int32_t INVALID_GROUP_ID = -1;
28 namespace {
29 const char* LOCAL_NETWORK_ID = "LocalDevice";
30 const char* REMOTE_NETWORK_ID = "RemoteDevice";
31 }
32 
33 enum API_VERSION {
34     API_7 = 7,
35     API_8,
36     API_9,
37     API_10,
38     API_11,
39     API_MAX = 1000
40 };
41 
42 enum DeviceFlag {
43     /**
44      * Device flag none.
45      */
46     NONE_DEVICES_FLAG = 0,
47     /**
48      * Indicates all output audio devices.
49      */
50     OUTPUT_DEVICES_FLAG = 1,
51     /**
52      * Indicates all input audio devices.
53      */
54     INPUT_DEVICES_FLAG = 2,
55     /**
56      * Indicates all audio devices.
57      */
58     ALL_DEVICES_FLAG = 3,
59     /**
60      * Indicates all distributed output audio devices.
61      */
62     DISTRIBUTED_OUTPUT_DEVICES_FLAG = 4,
63     /**
64      * Indicates all distributed input audio devices.
65      */
66     DISTRIBUTED_INPUT_DEVICES_FLAG = 8,
67     /**
68      * Indicates all distributed audio devices.
69      */
70     ALL_DISTRIBUTED_DEVICES_FLAG = 12,
71     /**
72      * Indicates all local and distributed audio devices.
73      */
74     ALL_L_D_DEVICES_FLAG = 15,
75     /**
76      * Device flag max count.
77      */
78     DEVICE_FLAG_MAX
79 };
80 
81 enum DeviceRole {
82     /**
83      * Device role none.
84      */
85     DEVICE_ROLE_NONE = -1,
86     /**
87      * Input device role.
88      */
89     INPUT_DEVICE = 1,
90     /**
91      * Output device role.
92      */
93     OUTPUT_DEVICE = 2,
94     /**
95      * Device role max count.
96      */
97     DEVICE_ROLE_MAX
98 };
99 
100 enum DeviceType {
101     /**
102      * Indicates device type none.
103      */
104     DEVICE_TYPE_NONE = -1,
105     /**
106      * Indicates invalid device
107      */
108     DEVICE_TYPE_INVALID = 0,
109     /**
110      * Indicates a built-in earpiece device
111      */
112     DEVICE_TYPE_EARPIECE = 1,
113     /**
114      * Indicates a speaker built in a device.
115      */
116     DEVICE_TYPE_SPEAKER = 2,
117     /**
118      * Indicates a headset, which is the combination of a pair of headphones and a microphone.
119      */
120     DEVICE_TYPE_WIRED_HEADSET = 3,
121     /**
122      * Indicates a pair of wired headphones.
123      */
124     DEVICE_TYPE_WIRED_HEADPHONES = 4,
125     /**
126      * Indicates a Bluetooth device used for telephony.
127      */
128     DEVICE_TYPE_BLUETOOTH_SCO = 7,
129     /**
130      * Indicates a Bluetooth device supporting the Advanced Audio Distribution Profile (A2DP).
131      */
132     DEVICE_TYPE_BLUETOOTH_A2DP = 8,
133     /**
134      * Indicates a Bluetooth device supporting the Advanced Audio Distribution Profile (A2DP) recording.
135      */
136     DEVICE_TYPE_BLUETOOTH_A2DP_IN = 9,
137     /**
138      * Indicates a microphone built in a device.
139      */
140     DEVICE_TYPE_MIC = 15,
141     /**
142      * Indicates a microphone built in a device.
143      */
144     DEVICE_TYPE_WAKEUP = 16,
145     /**
146      * Indicates a microphone built in a device.
147      */
148     DEVICE_TYPE_USB_HEADSET = 22,
149     /**
150      * Indicates a display device.
151      */
152     DEVICE_TYPE_DP = 23,
153     /**
154      * Indicates a virtual remote cast device
155      */
156     DEVICE_TYPE_REMOTE_CAST = 24,
157     /**
158      * Indicates a non-headset usb device.
159      */
160     DEVICE_TYPE_USB_DEVICE = 25,
161     /**
162      * Indicates a accessory audio device.
163      */
164     DEVICE_TYPE_ACCESSORY = 26,
165     /**
166      * Indicates a Distributed virtualization audio device.
167      */
168     DEVICE_TYPE_REMOTE_DAUDIO = 29,
169     /**
170      * Indicates a Bluetooth HearingAid device.
171      */
172     DEVICE_TYPE_HEARING_AID = 30,
173     /**
174      * Indicates a hdmi device
175      */
176     DEVICE_TYPE_HDMI = 27,
177     /**
178      * Indicates a line digital device
179      */
180     DEVICE_TYPE_LINE_DIGITAL = 28,
181     /**
182      * Indicates a Nearlink device for output.
183      */
184     DEVICE_TYPE_NEARLINK = 31,
185     /**
186      * Indicates a Nearlink device for input.
187      */
188     DEVICE_TYPE_NEARLINK_IN = 32,
189     /**
190      * Indicates a debug sink device
191      */
192     DEVICE_TYPE_FILE_SINK = 50,
193     /**
194      * Indicates a debug source device
195      */
196     DEVICE_TYPE_FILE_SOURCE = 51,
197     /**
198      * Indicates any headset/headphone for disconnect
199      */
200     DEVICE_TYPE_EXTERN_CABLE = 100,
201     /**
202      * Indicates default device
203      */
204     DEVICE_TYPE_DEFAULT = 1000,
205     /**
206      * Indicates a usb-arm device.
207      */
208     DEVICE_TYPE_USB_ARM_HEADSET = 1001,
209     /**
210      * Indicates device type max count.
211      */
212     DEVICE_TYPE_MAX
213 };
214 
215 inline const std::unordered_set<DeviceType> INPUT_DEVICE_TYPE_SET = {
216     DeviceType::DEVICE_TYPE_WIRED_HEADSET,
217     DeviceType::DEVICE_TYPE_BLUETOOTH_SCO,
218     DeviceType::DEVICE_TYPE_BLUETOOTH_A2DP_IN,
219     DeviceType::DEVICE_TYPE_MIC,
220     DeviceType::DEVICE_TYPE_WAKEUP,
221     DeviceType::DEVICE_TYPE_USB_HEADSET,
222     DeviceType::DEVICE_TYPE_USB_ARM_HEADSET,
223     DeviceType::DEVICE_TYPE_FILE_SOURCE,
224     DeviceType::DEVICE_TYPE_ACCESSORY,
225     DeviceType::DEVICE_TYPE_NEARLINK_IN,
226 };
227 
228 inline bool IsInputDevice(DeviceType deviceType, DeviceRole deviceRole = DEVICE_ROLE_NONE)
229 {
230     // Arm usb device distinguishes input and output through device roles.
231     if (deviceType == DEVICE_TYPE_USB_ARM_HEADSET || deviceType == DEVICE_TYPE_USB_HEADSET) {
232         return deviceRole == INPUT_DEVICE;
233     } else {
234         return INPUT_DEVICE_TYPE_SET.count(deviceType) > 0;
235     }
236 }
237 
238 enum DmDeviceType {
239     DM_DEVICE_TYPE_DEFAULT = 0,
240     DM_DEVICE_TYPE_PENCIL = 0xA07,
241     DM_DEVICE_TYPE_UWB = 0x06C,
242     DM_DEVICE_TYPE_NEARLINK_SCO = 0x032,
243 };
244 
245 inline const std::unordered_set<DeviceType> OUTPUT_DEVICE_TYPE_SET = {
246     DeviceType::DEVICE_TYPE_EARPIECE,
247     DeviceType::DEVICE_TYPE_SPEAKER,
248     DeviceType::DEVICE_TYPE_WIRED_HEADSET,
249     DeviceType::DEVICE_TYPE_WIRED_HEADPHONES,
250     DeviceType::DEVICE_TYPE_BLUETOOTH_SCO,
251     DeviceType::DEVICE_TYPE_BLUETOOTH_A2DP,
252     DeviceType::DEVICE_TYPE_USB_HEADSET,
253     DeviceType::DEVICE_TYPE_DP,
254     DeviceType::DEVICE_TYPE_USB_ARM_HEADSET,
255     DeviceType::DEVICE_TYPE_FILE_SINK,
256     DeviceType::DEVICE_TYPE_REMOTE_CAST,
257     DeviceType::DEVICE_TYPE_HDMI,
258     DeviceType::DEVICE_TYPE_LINE_DIGITAL,
259     DeviceType::DEVICE_TYPE_REMOTE_DAUDIO,
260     DeviceType::DEVICE_TYPE_NEARLINK,
261     DeviceType::DEVICE_TYPE_HEARING_AID,
262 };
263 
264 inline bool IsOutputDevice(DeviceType deviceType, DeviceRole deviceRole = DEVICE_ROLE_NONE)
265 {
266     // Arm usb device distinguishes input and output through device roles.
267     if (deviceType == DEVICE_TYPE_USB_ARM_HEADSET || deviceType == DEVICE_TYPE_USB_HEADSET) {
268         return deviceRole == OUTPUT_DEVICE;
269     } else {
270         return OUTPUT_DEVICE_TYPE_SET.count(deviceType) > 0;
271     }
272 }
273 
274 enum DeviceBlockStatus {
275     DEVICE_UNBLOCKED = 0,
276     DEVICE_BLOCKED = 1,
277 };
278 
279 enum DeviceChangeType {
280     CONNECT = 0,
281     DISCONNECT = 1,
282 };
283 
284 enum DeviceVolumeType {
285     EARPIECE_VOLUME_TYPE = 0,
286     SPEAKER_VOLUME_TYPE = 1,
287     HEADSET_VOLUME_TYPE = 2,
288 };
289 
290 inline const std::unordered_set<DeviceType> ACTIVE_DEVICE_TYPE_SET = {
291     DeviceType::DEVICE_TYPE_EARPIECE,
292     DeviceType::DEVICE_TYPE_SPEAKER,
293     DeviceType::DEVICE_TYPE_BLUETOOTH_SCO,
294     DeviceType::DEVICE_TYPE_USB_HEADSET,
295     DeviceType::DEVICE_TYPE_FILE_SINK,
296 };
297 
IsActiveDeviceType(DeviceType deviceType)298 inline bool IsActiveDeviceType(DeviceType deviceType)
299 {
300     return ACTIVE_DEVICE_TYPE_SET.count(deviceType) > 0;
301 }
302 
303 inline const std::unordered_set<DeviceType> COMMUNICATION_DEVICE_TYPE_SET = {
304     DeviceType::DEVICE_TYPE_SPEAKER,
305 };
306 
IsCommunicationDeviceType(DeviceType deviceType)307 inline bool IsCommunicationDeviceType(DeviceType deviceType)
308 {
309     return COMMUNICATION_DEVICE_TYPE_SET.count(deviceType) > 0;
310 }
311 
312 enum AudioDeviceManagerType {
313     DEV_MGR_UNKNOW = 0,
314     LOCAL_DEV_MGR,
315     REMOTE_DEV_MGR,
316     BLUETOOTH_DEV_MGR,
317 };
318 
319 enum AudioDevicePrivacyType {
320     TYPE_PRIVACY,
321     TYPE_PUBLIC,
322     TYPE_NEGATIVE,
323 };
324 
325 enum DeviceCategory {
326     CATEGORY_DEFAULT = 0,
327     BT_HEADPHONE = 1 << 0,
328     BT_SOUNDBOX = 1 << 1,
329     BT_CAR = 1 << 2,
330     BT_GLASSES = 1 << 3,
331     BT_WATCH = 1 << 4,
332     BT_HEARAID = 1 << 5,
333     BT_UNWEAR_HEADPHONE = 1 << 6,
334 };
335 
336 enum DeviceUsage {
337     MEDIA = 1 << 0,
338     VOICE = 1 << 1,
339     RECOGNITION = 1 << 2,
340     ALL_USAGE = (1 << 3) - 1, // Represents the bitwise OR of all the above usages.
341 };
342 
343 enum DeviceInfoUpdateCommand {
344     CATEGORY_UPDATE = 1,
345     CONNECTSTATE_UPDATE,
346     ENABLE_UPDATE,
347     USAGE_UPDATE,
348     EXCEPTION_FLAG_UPDATE,
349 };
350 
351 enum ConnectState {
352     CONNECTED,
353     SUSPEND_CONNECTED,
354     VIRTUAL_CONNECTED,
355     DEACTIVE_CONNECTED
356 };
357 
358 enum PreferredType {
359     AUDIO_MEDIA_RENDER = 0,
360     AUDIO_CALL_RENDER = 1,
361     AUDIO_CALL_CAPTURE = 2,
362     AUDIO_RING_RENDER = 3,
363     AUDIO_RECORD_CAPTURE = 4,
364     AUDIO_TONE_RENDER = 5,
365 };
366 
367 enum BluetoothOffloadState {
368     NO_A2DP_DEVICE = 0,
369     A2DP_NOT_OFFLOAD = 1,
370     A2DP_OFFLOAD = 2,
371 };
372 
373 struct VolumeBehavior : public Parcelable {
374     bool isReady = false;
375     bool isVolumeControlDisabled = false;
376     std::string databaseVolumeName = "";
377 
VolumeBehaviorVolumeBehavior378     VolumeBehavior(bool isReady_, bool isVolumeControlDisabled_, std::string databaseVolumeName_)
379         : isReady(isReady_), isVolumeControlDisabled(isVolumeControlDisabled_), databaseVolumeName(databaseVolumeName_)
380     {}
381     VolumeBehavior() = default;
382 
MarshallingVolumeBehavior383     bool Marshalling(Parcel &parcel) const override
384     {
385         return parcel.WriteBool(isReady) &&
386             parcel.WriteBool(isVolumeControlDisabled) &&
387             parcel.WriteString(databaseVolumeName);
388     }
389 
UnmarshallingVolumeBehavior390     static VolumeBehavior *Unmarshalling(Parcel &parcel)
391     {
392         auto info = new(std::nothrow) VolumeBehavior();
393         if (info == nullptr) {
394             return nullptr;
395         }
396 
397         info->isReady = parcel.ReadBool();
398         info->isVolumeControlDisabled = parcel.ReadBool();
399         info->databaseVolumeName = parcel.ReadString();
400         return info;
401     }
402 
UnmarshallingSelfVolumeBehavior403     void UnmarshallingSelf(Parcel &parcel)
404     {
405         isReady = parcel.ReadBool();
406         isVolumeControlDisabled = parcel.ReadBool();
407         databaseVolumeName = parcel.ReadString();
408     }
409 };
410 
411 struct DevicePrivacyInfo {
412     std::string deviceName;
413     DeviceType deviceType;
414     DeviceRole deviceRole;
415     DeviceCategory deviceCategory;
416     DeviceUsage deviceUsage;
417 };
418 
419 struct AffinityDeviceInfo {
420     std::string groupName;
421     DeviceType deviceType;
422     DeviceFlag deviceFlag;
423     std::string networkID;
424     uint64_t chooseTimeStamp;
425     bool isPrimary;
426     bool SupportedConcurrency;
427 };
428 
429 enum class AudioStreamDeviceChangeReason {
430     UNKNOWN = 0,
431     NEW_DEVICE_AVAILABLE = 1,
432     OLD_DEVICE_UNAVALIABLE = 2,
433     OVERRODE = 3,
434     AUDIO_SESSION_ACTIVATE = 4,
435     STREAM_PRIORITY_CHANGED = 5,
436 };
437 
438 class AudioStreamDeviceChangeReasonExt : public Parcelable {
439 public:
440     enum class ExtEnum {
441         UNKNOWN = 0,
442         NEW_DEVICE_AVAILABLE = 1,
443         OLD_DEVICE_UNAVALIABLE = 2,
444         OVERRODE = 3,
445         AUDIO_SESSION_ACTIVATE = 4,
446         STREAM_PRIORITY_CHANGED = 5,
447         MIN = 1000,
448         OLD_DEVICE_UNAVALIABLE_EXT = 1000,
449         SET_AUDIO_SCENE = 1001,
450         SET_DEFAULT_OUTPUT_DEVICE = 1002,
451         DISTRIBUTED_DEVICE_UNAVAILABLE = 1003,
452         SET_INPUT_DEVICE = 1004
453     };
454 
AudioStreamDeviceChangeReason()455     operator AudioStreamDeviceChangeReason() const
456     {
457         if (reason_ < ExtEnum::MIN) {
458             return static_cast<AudioStreamDeviceChangeReason>(reason_);
459         } else {
460             return AudioStreamDeviceChangeReason::UNKNOWN;
461         }
462     }
463 
464     operator int() const
465     {
466         return static_cast<int>(reason_);
467     }
468 
AudioStreamDeviceChangeReasonExt()469     AudioStreamDeviceChangeReasonExt()
470         : reason_(ExtEnum::UNKNOWN) {}
AudioStreamDeviceChangeReasonExt(const AudioStreamDeviceChangeReason & reason)471     AudioStreamDeviceChangeReasonExt(const AudioStreamDeviceChangeReason &reason)
472         : reason_(static_cast<ExtEnum>(reason)) {}
473 
AudioStreamDeviceChangeReasonExt(const ExtEnum & reason)474     AudioStreamDeviceChangeReasonExt(const ExtEnum &reason) : reason_(reason) {}
475 
IsOldDeviceUnavaliable()476     bool IsOldDeviceUnavaliable() const
477     {
478         return reason_ == ExtEnum::OLD_DEVICE_UNAVALIABLE;
479     }
480 
IsOldDeviceUnavaliableExt()481     bool IsOldDeviceUnavaliableExt() const
482     {
483         return reason_ == ExtEnum::OLD_DEVICE_UNAVALIABLE_EXT;
484     }
485 
IsNewDeviceAvailable()486     bool IsNewDeviceAvailable() const
487     {
488         return reason_ == ExtEnum::NEW_DEVICE_AVAILABLE;
489     }
490 
IsOverride()491     bool IsOverride() const
492     {
493         return reason_ == ExtEnum::OVERRODE;
494     }
495 
IsSetAudioScene()496     bool IsSetAudioScene() const
497     {
498         return reason_ == ExtEnum::SET_AUDIO_SCENE;
499     }
500 
IsSetDefaultOutputDevice()501     bool IsSetDefaultOutputDevice() const
502     {
503         return reason_ == ExtEnum::SET_DEFAULT_OUTPUT_DEVICE;
504     }
505 
IsUnknown()506     bool IsUnknown() const
507     {
508         return reason_ == ExtEnum::UNKNOWN;
509     }
510 
IsDistributedDeviceUnavailable()511     bool IsDistributedDeviceUnavailable() const
512     {
513         return reason_ == ExtEnum::DISTRIBUTED_DEVICE_UNAVAILABLE;
514     }
515 
Marshalling(Parcel & parcel)516     bool Marshalling(Parcel &parcel) const override
517     {
518         return parcel.WriteInt32(static_cast<int32_t>(reason_));
519     }
520 
Unmarshalling(Parcel & parcel)521     static AudioStreamDeviceChangeReasonExt *Unmarshalling(Parcel &parcel)
522     {
523         auto info = new(std::nothrow) AudioStreamDeviceChangeReasonExt();
524         if (info == nullptr) {
525             return nullptr;
526         }
527         info->reason_ = static_cast<ExtEnum>(parcel.ReadInt32());
528         return info;
529     }
530 
531 private:
532     ExtEnum reason_;
533 };
534 } // namespace AudioStandard
535 } // namespace OHOS
536 #endif // AUDIO_DEVICE_INFO_H
537