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 AAC 19 // 20 21 #ifndef A2DP_AAC_H 22 #define A2DP_AAC_H 23 24 #include "a2dp_aac_constants.h" 25 #include "a2dp_codec_api.h" 26 #include "avdt_api.h" 27 28 class A2dpCodecConfigAacBase : public A2dpCodecConfig { 29 protected: 30 A2dpCodecConfigAacBase(btav_a2dp_codec_index_t codec_index, 31 const std::string& name, 32 btav_a2dp_codec_priority_t codec_priority, 33 bool is_source) 34 : A2dpCodecConfig(codec_index, name, codec_priority), 35 is_source_(is_source) {} 36 bool setCodecConfig(const uint8_t* p_peer_codec_info, bool is_capability, 37 uint8_t* p_result_codec_config) override; 38 bool setPeerCodecCapabilities( 39 const uint8_t* p_peer_codec_capabilities) override; 40 41 private: 42 bool is_source_; // True if local is Source 43 }; 44 45 class A2dpCodecConfigAacSource : public A2dpCodecConfigAacBase { 46 public: 47 A2dpCodecConfigAacSource(btav_a2dp_codec_priority_t codec_priority); 48 virtual ~A2dpCodecConfigAacSource(); 49 50 bool init() override; 51 period_ms_t encoderIntervalMs() const override; 52 int getEffectiveMtu() const override; 53 54 private: 55 bool useRtpHeaderMarkerBit() const override; 56 bool updateEncoderUserConfig( 57 const tA2DP_ENCODER_INIT_PEER_PARAMS* p_peer_params, 58 bool* p_restart_input, bool* p_restart_output, 59 bool* p_config_updated) override; 60 void debug_codec_dump(int fd) override; 61 }; 62 63 class A2dpCodecConfigAacSink : public A2dpCodecConfigAacBase { 64 public: 65 A2dpCodecConfigAacSink(btav_a2dp_codec_priority_t codec_priority); 66 virtual ~A2dpCodecConfigAacSink(); 67 68 bool init() override; 69 period_ms_t encoderIntervalMs() const override; 70 int getEffectiveMtu() const override; 71 72 private: 73 bool useRtpHeaderMarkerBit() const override; 74 bool updateEncoderUserConfig( 75 const tA2DP_ENCODER_INIT_PEER_PARAMS* p_peer_params, 76 bool* p_restart_input, bool* p_restart_output, 77 bool* p_config_updated) override; 78 }; 79 80 // Checks whether the codec capabilities contain a valid A2DP AAC Source 81 // codec. 82 // NOTE: only codecs that are implemented are considered valid. 83 // Returns true if |p_codec_info| contains information about a valid AAC 84 // codec, otherwise false. 85 bool A2DP_IsSourceCodecValidAac(const uint8_t* p_codec_info); 86 87 // Checks whether the codec capabilities contain a valid A2DP AAC Sink codec. 88 // NOTE: only codecs that are implemented are considered valid. 89 // Returns true if |p_codec_info| contains information about a valid AAC codec, 90 // otherwise false. 91 bool A2DP_IsSinkCodecValidAac(const uint8_t* p_codec_info); 92 93 // Checks whether the codec capabilities contain a valid peer A2DP AAC Source 94 // codec. 95 // NOTE: only codecs that are implemented are considered valid. 96 // Returns true if |p_codec_info| contains information about a valid AAC codec, 97 // otherwise false. 98 bool A2DP_IsPeerSourceCodecValidAac(const uint8_t* p_codec_info); 99 100 // Checks whether the codec capabilities contain a valid peer A2DP AAC Sink 101 // codec. 102 // NOTE: only codecs that are implemented are considered valid. 103 // Returns true if |p_codec_info| contains information about a valid AAC 104 // codec, otherwise false. 105 bool A2DP_IsPeerSinkCodecValidAac(const uint8_t* p_codec_info); 106 107 // Checks whether A2DP AAC Sink codec is supported. 108 // |p_codec_info| contains information about the codec capabilities. 109 // Returns true if the A2DP AAC Sink codec is supported, otherwise false. 110 bool A2DP_IsSinkCodecSupportedAac(const uint8_t* p_codec_info); 111 112 // Checks whether an A2DP AAC Source codec for a peer Source device is 113 // supported. 114 // |p_codec_info| contains information about the codec capabilities of the 115 // peer device. 116 // Returns true if the A2DP AAC Source codec for a peer Source device is 117 // supported, otherwise false. 118 bool A2DP_IsPeerSourceCodecSupportedAac(const uint8_t* p_codec_info); 119 120 // Checks whether the A2DP data packets should contain RTP header. 121 // |content_protection_enabled| is true if Content Protection is 122 // enabled. |p_codec_info| contains information about the codec capabilities. 123 // Returns true if the A2DP data packets should contain RTP header, otherwise 124 // false. 125 bool A2DP_UsesRtpHeaderAac(bool content_protection_enabled, 126 const uint8_t* p_codec_info); 127 128 // Gets the A2DP AAC codec name for a given |p_codec_info|. 129 const char* A2DP_CodecNameAac(const uint8_t* p_codec_info); 130 131 // Checks whether two A2DP AAC codecs |p_codec_info_a| and |p_codec_info_b| 132 // have the same type. 133 // Returns true if the two codecs have the same type, otherwise false. 134 bool A2DP_CodecTypeEqualsAac(const uint8_t* p_codec_info_a, 135 const uint8_t* p_codec_info_b); 136 137 // Checks whether two A2DP AAC codecs |p_codec_info_a| and |p_codec_info_b| 138 // are exactly the same. 139 // Returns true if the two codecs are exactly the same, otherwise false. 140 // If the codec type is not AAC, the return value is false. 141 bool A2DP_CodecEqualsAac(const uint8_t* p_codec_info_a, 142 const uint8_t* p_codec_info_b); 143 144 // Gets the track sample rate value for the A2DP AAC codec. 145 // |p_codec_info| is a pointer to the AAC codec_info to decode. 146 // Returns the track sample rate on success, or -1 if |p_codec_info| 147 // contains invalid codec information. 148 int A2DP_GetTrackSampleRateAac(const uint8_t* p_codec_info); 149 150 // Gets the channel count for the A2DP AAC codec. 151 // |p_codec_info| is a pointer to the AAC codec_info to decode. 152 // Returns the channel count on success, or -1 if |p_codec_info| 153 // contains invalid codec information. 154 int A2DP_GetTrackChannelCountAac(const uint8_t* p_codec_info); 155 156 // Gets the channel type for the A2DP AAC Sink codec: 157 // 1 for mono, or 3 for dual/stereo/joint. 158 // |p_codec_info| is a pointer to the AAC codec_info to decode. 159 // Returns the channel type on success, or -1 if |p_codec_info| 160 // contains invalid codec information. 161 int A2DP_GetSinkTrackChannelTypeAac(const uint8_t* p_codec_info); 162 163 // Gets the object type code for the A2DP AAC codec. 164 // The actual value is codec-specific - see |A2DP_AAC_OBJECT_TYPE_*|. 165 // |p_codec_info| is a pointer to the AAC codec_info to decode. 166 // Returns the object type code on success, or -1 if |p_codec_info| 167 // contains invalid codec information. 168 int A2DP_GetObjectTypeCodeAac(const uint8_t* p_codec_info); 169 170 // Gets the channel mode code for the A2DP AAC codec. 171 // The actual value is codec-specific - see |A2DP_AAC_CHANNEL_MODE_*|. 172 // |p_codec_info| is a pointer to the AAC codec_info to decode. 173 // Returns the channel mode code on success, or -1 if |p_codec_info| 174 // contains invalid codec information. 175 int A2DP_GetChannelModeCodeAac(const uint8_t* p_codec_info); 176 177 // Gets the variable bit rate support for the A2DP AAC codec. 178 // The actual value is codec-specific - see |A2DP_AAC_VARIABLE_BIT_RATE_*|. 179 // |p_codec_info| is a pointer to the AAC codec_info to decode. 180 // Returns the variable bit rate support on success, or -1 if |p_codec_info| 181 // contains invalid codec information. 182 int A2DP_GetVariableBitRateSupportAac(const uint8_t* p_codec_info); 183 184 // Gets the bit rate for the A2DP AAC codec. 185 // The actual value is codec-specific - for AAC it is in bits per second. 186 // |p_codec_info| is a pointer to the AAC codec_info to decode. 187 // Returns the bit rate on success, or -1 if |p_codec_info| 188 // contains invalid codec information. 189 int A2DP_GetBitRateAac(const uint8_t* p_codec_info); 190 191 // Computes the maximum bit rate for the A2DP AAC codec based on the MTU. 192 // The actual value is codec-specific - for AAC it is in bits per second. 193 // |p_codec_info| is a pointer to the AAC codec_info to decode. 194 // |mtu| is the MTU to use for the computation. 195 // Returns the maximum bit rate on success, or -1 if |p_codec_info| 196 // contains invalid codec information. 197 int A2DP_ComputeMaxBitRateAac(const uint8_t* p_codec_info, uint16_t mtu); 198 199 // Gets the A2DP AAC audio data timestamp from an audio packet. 200 // |p_codec_info| contains the codec information. 201 // |p_data| contains the audio data. 202 // The timestamp is stored in |p_timestamp|. 203 // Returns true on success, otherwise false. 204 bool A2DP_GetPacketTimestampAac(const uint8_t* p_codec_info, 205 const uint8_t* p_data, uint32_t* p_timestamp); 206 207 // Builds A2DP AAC codec header for audio data. 208 // |p_codec_info| contains the codec information. 209 // |p_buf| contains the audio data. 210 // |frames_per_packet| is the number of frames in this packet. 211 // Returns true on success, otherwise false. 212 bool A2DP_BuildCodecHeaderAac(const uint8_t* p_codec_info, BT_HDR* p_buf, 213 uint16_t frames_per_packet); 214 215 // Decodes A2DP AAC codec info into a human readable string. 216 // |p_codec_info| is a pointer to the AAC codec_info to decode. 217 // Returns a string describing the codec information. 218 std::string A2DP_CodecInfoStringAac(const uint8_t* p_codec_info); 219 220 // Gets the A2DP AAC encoder interface that can be used to encode and prepare 221 // A2DP packets for transmission - see |tA2DP_ENCODER_INTERFACE|. 222 // |p_codec_info| contains the codec information. 223 // Returns the A2DP AAC encoder interface if the |p_codec_info| is valid and 224 // supported, otherwise NULL. 225 const tA2DP_ENCODER_INTERFACE* A2DP_GetEncoderInterfaceAac( 226 const uint8_t* p_codec_info); 227 228 // Gets the current A2DP AAC decoder interface that can be used to decode 229 // received A2DP packets - see |tA2DP_DECODER_INTERFACE|. 230 // |p_codec_info| contains the codec information. 231 // Returns the A2DP AAC decoder interface if the |p_codec_info| is valid and 232 // supported, otherwise NULL. 233 const tA2DP_DECODER_INTERFACE* A2DP_GetDecoderInterfaceAac( 234 const uint8_t* p_codec_info); 235 236 // Adjusts the A2DP AAC codec, based on local support and Bluetooth 237 // specification. 238 // |p_codec_info| contains the codec information to adjust. 239 // Returns true if |p_codec_info| is valid and supported, otherwise false. 240 bool A2DP_AdjustCodecAac(uint8_t* p_codec_info); 241 242 // Gets the A2DP AAC Source codec index for a given |p_codec_info|. 243 // Returns the corresponding |btav_a2dp_codec_index_t| on success, 244 // otherwise |BTAV_A2DP_CODEC_INDEX_MAX|. 245 btav_a2dp_codec_index_t A2DP_SourceCodecIndexAac(const uint8_t* p_codec_info); 246 247 // Gets the A2DP AAC Sink codec index for a given |p_codec_info|. 248 // Returns the corresponding |btav_a2dp_codec_index_t| on success, 249 // otherwise |BTAV_A2DP_CODEC_INDEX_MAX|. 250 btav_a2dp_codec_index_t A2DP_SinkCodecIndexAac(const uint8_t* p_codec_info); 251 252 // Gets the A2DP AAC Source codec name. 253 const char* A2DP_CodecIndexStrAac(void); 254 255 // Gets the A2DP AAC Sink codec name. 256 const char* A2DP_CodecIndexStrAacSink(void); 257 258 // Initializes A2DP AAC Source codec information into |AvdtpSepConfig| 259 // configuration entry pointed by |p_cfg|. 260 bool A2DP_InitCodecConfigAac(AvdtpSepConfig* p_cfg); 261 262 // Initializes A2DP AAC Sink codec information into |AvdtpSepConfig| 263 // configuration entry pointed by |p_cfg|. 264 bool A2DP_InitCodecConfigAacSink(AvdtpSepConfig* p_cfg); 265 266 #endif // A2DP_AAC_H 267