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 // Checks whether the codec capabilities contain a valid A2DP LDAC Source 60 // codec. 61 // NOTE: only codecs that are implemented are considered valid. 62 // Returns true if |p_codec_info| contains information about a valid LDAC 63 // codec, otherwise false. 64 bool A2DP_IsCodecValidLdac(const uint8_t* p_codec_info); 65 66 // Checks whether A2DP LDAC Sink codec is supported. 67 // |p_codec_info| contains information about the codec capabilities. 68 // Returns true if the A2DP LDAC Sink codec is supported, otherwise false. 69 tA2DP_STATUS A2DP_IsVendorSinkCodecSupportedLdac(const uint8_t* p_codec_info); 70 71 // Checks whether the A2DP data packets should contain RTP header. 72 // |content_protection_enabled| is true if Content Protection is 73 // enabled. |p_codec_info| contains information about the codec capabilities. 74 // Returns true if the A2DP data packets should contain RTP header, otherwise 75 // false. 76 bool A2DP_VendorUsesRtpHeaderLdac(bool content_protection_enabled, const uint8_t* p_codec_info); 77 78 // Gets the A2DP LDAC codec name for a given |p_codec_info|. 79 const char* A2DP_VendorCodecNameLdac(const uint8_t* p_codec_info); 80 81 // Checks whether two A2DP LDAC codecs |p_codec_info_a| and |p_codec_info_b| 82 // have the same type. 83 // Returns true if the two codecs have the same type, otherwise false. 84 bool A2DP_VendorCodecTypeEqualsLdac(const uint8_t* p_codec_info_a, const uint8_t* p_codec_info_b); 85 86 // Checks whether two A2DP LDAC codecs |p_codec_info_a| and |p_codec_info_b| 87 // are exactly the same. 88 // Returns true if the two codecs are exactly the same, otherwise false. 89 // If the codec type is not LDAC, the return value is false. 90 bool A2DP_VendorCodecEqualsLdac(const uint8_t* p_codec_info_a, const uint8_t* p_codec_info_b); 91 92 // Gets the track sample rate value for the A2DP LDAC codec. 93 // |p_codec_info| is a pointer to the LDAC codec_info to decode. 94 // Returns the track sample rate on success, or -1 if |p_codec_info| 95 // contains invalid codec information. 96 int A2DP_VendorGetTrackSampleRateLdac(const uint8_t* p_codec_info); 97 98 // Gets the track bits per sample value for the A2DP LDAC codec. 99 // |p_codec_info| is a pointer to the LDAC codec_info to decode. 100 // Returns the track bits per sample on success, or -1 if |p_codec_info| 101 // contains invalid codec information. 102 int A2DP_VendorGetTrackBitsPerSampleLdac(const uint8_t* p_codec_info); 103 104 // Gets the track bitrate value for the A2DP LDAC codec. 105 // |p_codec_info| is a pointer to the LDAC codec_info to decode. 106 // Returns the track sample rate on success, or -1 if |p_codec_info| 107 // contains invalid codec information. 108 int A2DP_VendorGetBitRateLdac(const uint8_t* p_codec_info); 109 110 // Gets the channel count for the A2DP LDAC codec. 111 // |p_codec_info| is a pointer to the LDAC codec_info to decode. 112 // Returns the channel count on success, or -1 if |p_codec_info| 113 // contains invalid codec information. 114 int A2DP_VendorGetTrackChannelCountLdac(const uint8_t* p_codec_info); 115 116 // Gets the channel type for the A2DP LDAC codec. 117 // 1 for mono, or 3 for dual channel/stereo. 118 // |p_codec_info| is a pointer to the LDAC codec_info to decode. 119 // Returns the channel count on success, or -1 if |p_codec_info| 120 // contains invalid codec information. 121 int A2DP_VendorGetSinkTrackChannelTypeLdac(const uint8_t* p_codec_info); 122 123 // Gets the channel mode code for the A2DP LDAC codec. 124 // The actual value is codec-specific - see |A2DP_LDAC_CHANNEL_MODE_*|. 125 // |p_codec_info| is a pointer to the LDAC codec_info to decode. 126 // Returns the channel mode code on success, or -1 if |p_codec_info| 127 // contains invalid codec information. 128 int A2DP_VendorGetChannelModeCodeLdac(const uint8_t* p_codec_info); 129 130 // Gets the A2DP LDAC audio data timestamp from an audio packet. 131 // |p_codec_info| contains the codec information. 132 // |p_data| contains the audio data. 133 // The timestamp is stored in |p_timestamp|. 134 // Returns true on success, otherwise false. 135 bool A2DP_VendorGetPacketTimestampLdac(const uint8_t* p_codec_info, const uint8_t* p_data, 136 uint32_t* p_timestamp); 137 138 // Builds A2DP LDAC codec header for audio data. 139 // |p_codec_info| contains the codec information. 140 // |p_buf| contains the audio data. 141 // |frames_per_packet| is the number of frames in this packet. 142 // Returns true on success, otherwise false. 143 bool A2DP_VendorBuildCodecHeaderLdac(const uint8_t* p_codec_info, BT_HDR* p_buf, 144 uint16_t frames_per_packet); 145 146 // Decodes A2DP LDAC codec info into a human readable string. 147 // |p_codec_info| is a pointer to the LDAC codec_info to decode. 148 // Returns a string describing the codec information. 149 std::string A2DP_VendorCodecInfoStringLdac(const uint8_t* p_codec_info); 150 151 // Gets the A2DP LDAC encoder interface that can be used to encode and prepare 152 // A2DP packets for transmission - see |tA2DP_ENCODER_INTERFACE|. 153 // |p_codec_info| contains the codec information. 154 // Returns the A2DP LDAC encoder interface if the |p_codec_info| is valid and 155 // supported, otherwise NULL. 156 const tA2DP_ENCODER_INTERFACE* A2DP_VendorGetEncoderInterfaceLdac(const uint8_t* p_codec_info); 157 158 // Adjusts the A2DP LDAC codec, based on local support and Bluetooth 159 // specification. 160 // |p_codec_info| contains the codec information to adjust. 161 // Returns true if |p_codec_info| is valid and supported, otherwise false. 162 bool A2DP_VendorAdjustCodecLdac(uint8_t* p_codec_info); 163 164 // Gets the A2DP LDAC Source codec index for a given |p_codec_info|. 165 // Returns the corresponding |btav_a2dp_codec_index_t| on success, 166 // otherwise |BTAV_A2DP_CODEC_INDEX_MAX|. 167 btav_a2dp_codec_index_t A2DP_VendorSourceCodecIndexLdac(const uint8_t* p_codec_info); 168 169 // Gets the A2DP LDAC Source codec name. 170 const char* A2DP_VendorCodecIndexStrLdac(void); 171 172 // Initializes A2DP LDAC Source codec information into |AvdtpSepConfig| 173 // configuration entry pointed by |p_cfg|. 174 bool A2DP_VendorInitCodecConfigLdac(AvdtpSepConfig* p_cfg); 175 176 #endif // A2DP_VENDOR_LDAC_H 177