a2dp_aac.h 12 KB

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