1 /* 2 * Copyright (c) 2025 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_DEVICE_DESCRIPTOR_H 17 #define AUDIO_DEVICE_DESCRIPTOR_H 18 19 #include <memory> 20 21 #include "parcel.h" 22 #include "audio_device_info.h" 23 #include "audio_info.h" 24 25 namespace OHOS { 26 namespace AudioStandard { 27 /** 28 * @brief The AudioDeviceDescriptor provides 29 * different sets of audio devices and their roles 30 */ 31 class AudioDeviceDescriptor : public Parcelable { 32 friend class AudioSystemManager; 33 public: 34 enum { 35 AUDIO_DEVICE_DESCRIPTOR, 36 DEVICE_INFO, 37 }; 38 39 DeviceType deviceType_ = DEVICE_TYPE_NONE; 40 DeviceRole deviceRole_ = DEVICE_ROLE_NONE; 41 int32_t deviceId_ = 0; 42 int32_t channelMasks_ = 0; 43 int32_t channelIndexMasks_ = 0; 44 std::string deviceName_; 45 std::string macAddress_; 46 int32_t interruptGroupId_ = 0; 47 int32_t volumeGroupId_ = 0; 48 std::string networkId_; 49 std::string displayName_; 50 DeviceStreamInfo audioStreamInfo_ = {}; 51 DeviceCategory deviceCategory_ = CATEGORY_DEFAULT; 52 ConnectState connectState_ = CONNECTED; 53 // AudioDeviceDescriptor 54 bool exceptionFlag_ = false; 55 int64_t connectTimeStamp_ = 0; 56 std::shared_ptr<AudioDeviceDescriptor> pairDeviceDescriptor_; 57 bool isScoRealConnected_ = false; 58 bool isEnable_ = true; 59 bool isVgsSupported_ = false; 60 // DeviceInfo 61 bool isLowLatencyDevice_ = false; 62 int32_t a2dpOffloadFlag_ = NO_A2DP_DEVICE; 63 // Other 64 int32_t descriptorType_ = AUDIO_DEVICE_DESCRIPTOR; 65 66 AudioDeviceDescriptor(int32_t descriptorType = AUDIO_DEVICE_DESCRIPTOR); 67 68 AudioDeviceDescriptor(DeviceType type, DeviceRole role); 69 70 AudioDeviceDescriptor(DeviceType type, DeviceRole role, int32_t interruptGroupId, int32_t volumeGroupId, 71 std::string networkId); 72 73 AudioDeviceDescriptor(const AudioDeviceDescriptor &deviceDescriptor); 74 75 AudioDeviceDescriptor(const sptr<AudioDeviceDescriptor> &deviceDescriptor); 76 77 virtual ~AudioDeviceDescriptor(); 78 79 DeviceType getType() const; 80 81 DeviceRole getRole() const; 82 83 bool IsAudioDeviceDescriptor() const; 84 85 bool Marshalling(Parcel &parcel) const override; 86 87 bool MarshallingToDeviceDescriptor(Parcel &parcel) const; 88 89 bool MarshallingToDeviceInfo(Parcel &parcel) const; 90 91 bool Marshalling(Parcel &parcel, bool hasBTPermission, bool hasSystemPermission, int32_t apiVersion) const; 92 93 bool MarshallingToDeviceInfo(Parcel &parcel, bool hasBTPermission, bool hasSystemPermission, 94 int32_t apiVersion) const; 95 96 void Unmarshalling(Parcel &parcel); 97 98 static sptr<AudioDeviceDescriptor> UnmarshallingPtr(Parcel &parcel); 99 100 void UnmarshallingToDeviceDescriptor(Parcel &parcel); 101 102 void UnmarshallingToDeviceInfo(Parcel &parcel); 103 104 void SetDeviceInfo(std::string deviceName, std::string macAddress); 105 106 void SetDeviceCapability(const DeviceStreamInfo &audioStreamInfo, int32_t channelMask, 107 int32_t channelIndexMasks = 0); 108 109 bool IsSameDeviceDesc(const AudioDeviceDescriptor &deviceDescriptor) const; 110 111 bool IsSameDeviceInfo(const AudioDeviceDescriptor &deviceInfo) const; 112 113 static DeviceType MapInternalToExternalDeviceType(DeviceType deviceType); 114 }; 115 } // namespace AudioStandard 116 } // namespace OHOS 117 #endif // AUDIO_DEVICE_DESCRIPTOR_H