1 /* 2 * Copyright 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 // 18 // A2DP Codec API for LDAC 19 // 20 21 #ifndef A2DP_VENDOR_LDAC_H 22 #define A2DP_VENDOR_LDAC_H 23 24 #include <stddef.h> 25 #include <stdint.h> 26 27 #include "a2dp_codec_api.h" 28 #include "a2dp_vendor_ldac_constants.h" 29 #include "avdt_api.h" 30 #include "internal_include/bt_target.h" 31 #include "stack/include/bt_hdr.h" 32 33 class A2dpCodecConfigLdacBase : public A2dpCodecConfig { 34 protected: A2dpCodecConfigLdacBase(btav_a2dp_codec_index_t codec_index,const std::string & name,btav_a2dp_codec_priority_t codec_priority,bool is_source)35 A2dpCodecConfigLdacBase(btav_a2dp_codec_index_t codec_index, const std::string& name, 36 btav_a2dp_codec_priority_t codec_priority, bool is_source) 37 : A2dpCodecConfig(codec_index, bluetooth::a2dp::CodecId::LDAC, name, codec_priority), 38 is_source_(is_source) {} 39 tA2DP_STATUS setCodecConfig(const uint8_t* p_peer_codec_info, bool is_capability, 40 uint8_t* p_result_codec_config) override; 41 bool setPeerCodecCapabilities(const uint8_t* p_peer_codec_capabilities) override; 42 43 private: 44 [[maybe_unused]] bool is_source_; // True if local is Source 45 }; 46 47 class A2dpCodecConfigLdacSource : public A2dpCodecConfigLdacBase { 48 public: 49 A2dpCodecConfigLdacSource(btav_a2dp_codec_priority_t codec_priority); 50 virtual ~A2dpCodecConfigLdacSource(); 51 52 bool init() override; 53 54 private: 55 bool useRtpHeaderMarkerBit() const override; 56 void debug_codec_dump(int fd) override; 57 }; 58 59 class A2dpCodecConfigLdacSink : public A2dpCodecConfigLdacBase { 60 public: 61 A2dpCodecConfigLdacSink(btav_a2dp_codec_priority_t codec_priority); 62 virtual ~A2dpCodecConfigLdacSink(); 63 64 bool init() override; 65 66 private: 67 bool useRtpHeaderMarkerBit() const override; 68 }; 69 70 // Checks whether the codec capabilities contain a valid A2DP LDAC Source 71 // codec. 72 // NOTE: only codecs that are implemented are considered valid. 73 // Returns true if |p_codec_info| contains information about a valid LDAC 74 // codec, otherwise false. 75 bool A2DP_IsCodecValidLdac(const uint8_t* p_codec_info); 76 77 // Checks whether A2DP LDAC Sink codec is supported. 78 // |p_codec_info| contains information about the codec capabilities. 79 // Returns true if the A2DP LDAC Sink codec is supported, otherwise false. 80 tA2DP_STATUS A2DP_IsVendorSinkCodecSupportedLdac(const uint8_t* p_codec_info); 81 82 // Checks whether the A2DP data packets should contain RTP header. 83 // |content_protection_enabled| is true if Content Protection is 84 // enabled. |p_codec_info| contains information about the codec capabilities. 85 // Returns true if the A2DP data packets should contain RTP header, otherwise 86 // false. 87 bool A2DP_VendorUsesRtpHeaderLdac(bool content_protection_enabled, const uint8_t* p_codec_info); 88 89 // Gets the A2DP LDAC codec name for a given |p_codec_info|. 90 const char* A2DP_VendorCodecNameLdac(const uint8_t* p_codec_info); 91 92 // Checks whether two A2DP LDAC codecs |p_codec_info_a| and |p_codec_info_b| 93 // have the same type. 94 // Returns true if the two codecs have the same type, otherwise false. 95 bool A2DP_VendorCodecTypeEqualsLdac(const uint8_t* p_codec_info_a, const uint8_t* p_codec_info_b); 96 97 // Checks whether two A2DP LDAC codecs |p_codec_info_a| and |p_codec_info_b| 98 // are exactly the same. 99 // Returns true if the two codecs are exactly the same, otherwise false. 100 // If the codec type is not LDAC, the return value is false. 101 bool A2DP_VendorCodecEqualsLdac(const uint8_t* p_codec_info_a, const uint8_t* p_codec_info_b); 102 103 // Gets the track sample rate value for the A2DP LDAC codec. 104 // |p_codec_info| is a pointer to the LDAC codec_info to decode. 105 // Returns the track sample rate on success, or -1 if |p_codec_info| 106 // contains invalid codec information. 107 int A2DP_VendorGetTrackSampleRateLdac(const uint8_t* p_codec_info); 108 109 // Gets the track bits per sample value for the A2DP LDAC codec. 110 // |p_codec_info| is a pointer to the LDAC codec_info to decode. 111 // Returns the track bits per sample on success, or -1 if |p_codec_info| 112 // contains invalid codec information. 113 int A2DP_VendorGetTrackBitsPerSampleLdac(const uint8_t* p_codec_info); 114 115 // Gets the track bitrate value for the A2DP LDAC codec. 116 // |p_codec_info| is a pointer to the LDAC codec_info to decode. 117 // Returns the track sample rate on success, or -1 if |p_codec_info| 118 // contains invalid codec information. 119 int A2DP_VendorGetBitRateLdac(const uint8_t* p_codec_info); 120 121 // Gets the channel count for the A2DP LDAC codec. 122 // |p_codec_info| is a pointer to the LDAC codec_info to decode. 123 // Returns the channel count on success, or -1 if |p_codec_info| 124 // contains invalid codec information. 125 int A2DP_VendorGetTrackChannelCountLdac(const uint8_t* p_codec_info); 126 127 // Gets the channel type for the A2DP LDAC codec. 128 // 1 for mono, or 3 for dual channel/stereo. 129 // |p_codec_info| is a pointer to the LDAC codec_info to decode. 130 // Returns the channel count on success, or -1 if |p_codec_info| 131 // contains invalid codec information. 132 int A2DP_VendorGetSinkTrackChannelTypeLdac(const uint8_t* p_codec_info); 133 134 // Gets the channel mode code for the A2DP LDAC codec. 135 // The actual value is codec-specific - see |A2DP_LDAC_CHANNEL_MODE_*|. 136 // |p_codec_info| is a pointer to the LDAC codec_info to decode. 137 // Returns the channel mode code on success, or -1 if |p_codec_info| 138 // contains invalid codec information. 139 int A2DP_VendorGetChannelModeCodeLdac(const uint8_t* p_codec_info); 140 141 // Gets the A2DP LDAC audio data timestamp from an audio packet. 142 // |p_codec_info| contains the codec information. 143 // |p_data| contains the audio data. 144 // The timestamp is stored in |p_timestamp|. 145 // Returns true on success, otherwise false. 146 bool A2DP_VendorGetPacketTimestampLdac(const uint8_t* p_codec_info, const uint8_t* p_data, 147 uint32_t* p_timestamp); 148 149 // Builds A2DP LDAC codec header for audio data. 150 // |p_codec_info| contains the codec information. 151 // |p_buf| contains the audio data. 152 // |frames_per_packet| is the number of frames in this packet. 153 // Returns true on success, otherwise false. 154 bool A2DP_VendorBuildCodecHeaderLdac(const uint8_t* p_codec_info, BT_HDR* p_buf, 155 uint16_t frames_per_packet); 156 157 // Decodes A2DP LDAC codec info into a human readable string. 158 // |p_codec_info| is a pointer to the LDAC codec_info to decode. 159 // Returns a string describing the codec information. 160 std::string A2DP_VendorCodecInfoStringLdac(const uint8_t* p_codec_info); 161 162 // Gets the A2DP LDAC encoder interface that can be used to encode and prepare 163 // A2DP packets for transmission - see |tA2DP_ENCODER_INTERFACE|. 164 // |p_codec_info| contains the codec information. 165 // Returns the A2DP LDAC encoder interface if the |p_codec_info| is valid and 166 // supported, otherwise NULL. 167 const tA2DP_ENCODER_INTERFACE* A2DP_VendorGetEncoderInterfaceLdac(const uint8_t* p_codec_info); 168 169 // Gets the current A2DP LDAC decoder interface that can be used to decode 170 // received A2DP packets - see |tA2DP_DECODER_INTERFACE|. 171 // |p_codec_info| contains the codec information. 172 // Returns the A2DP LDAC decoder interface if the |p_codec_info| is valid and 173 // supported, otherwise NULL. 174 const tA2DP_DECODER_INTERFACE* A2DP_VendorGetDecoderInterfaceLdac(const uint8_t* p_codec_info); 175 176 // Adjusts the A2DP LDAC codec, based on local support and Bluetooth 177 // specification. 178 // |p_codec_info| contains the codec information to adjust. 179 // Returns true if |p_codec_info| is valid and supported, otherwise false. 180 bool A2DP_VendorAdjustCodecLdac(uint8_t* p_codec_info); 181 182 // Gets the A2DP LDAC Source codec index for a given |p_codec_info|. 183 // Returns the corresponding |btav_a2dp_codec_index_t| on success, 184 // otherwise |BTAV_A2DP_CODEC_INDEX_MAX|. 185 btav_a2dp_codec_index_t A2DP_VendorSourceCodecIndexLdac(const uint8_t* p_codec_info); 186 187 // Gets the A2DP LDAC Sink codec index for a given |p_codec_info|. 188 // Returns the corresponding |btav_a2dp_codec_index_t| on success, 189 // otherwise |BTAV_A2DP_CODEC_INDEX_MAX|. 190 btav_a2dp_codec_index_t A2DP_VendorSinkCodecIndexLdac(const uint8_t* p_codec_info); 191 192 // Gets the A2DP LDAC Source codec name. 193 const char* A2DP_VendorCodecIndexStrLdac(void); 194 195 // Gets the A2DP LDAC Sink codec name. 196 const char* A2DP_VendorCodecIndexStrLdacSink(void); 197 198 // Initializes A2DP LDAC Source codec information into |AvdtpSepConfig| 199 // configuration entry pointed by |p_cfg|. 200 bool A2DP_VendorInitCodecConfigLdac(AvdtpSepConfig* p_cfg); 201 202 // Initializes A2DP LDAC Sink codec information into |AvdtpSepConfig| 203 // configuration entry pointed by |p_cfg|. 204 bool A2DP_VendorInitCodecConfigLdacSink(AvdtpSepConfig* p_cfg); 205 206 #endif // A2DP_VENDOR_LDAC_H 207