a2dp_vendor_ldac.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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 LDAC
  18. //
  19. #ifndef A2DP_VENDOR_LDAC_H
  20. #define A2DP_VENDOR_LDAC_H
  21. #include "a2dp_codec_api.h"
  22. #include "a2dp_vendor_ldac_constants.h"
  23. #include "avdt_api.h"
  24. class A2dpCodecConfigLdacBase : public A2dpCodecConfig {
  25. protected:
  26. A2dpCodecConfigLdacBase(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 A2dpCodecConfigLdacSource : public A2dpCodecConfigLdacBase {
  40. public:
  41. A2dpCodecConfigLdacSource(btav_a2dp_codec_priority_t codec_priority);
  42. virtual ~A2dpCodecConfigLdacSource();
  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 A2dpCodecConfigLdacSink : public A2dpCodecConfigLdacBase {
  55. public:
  56. A2dpCodecConfigLdacSink(btav_a2dp_codec_priority_t codec_priority);
  57. virtual ~A2dpCodecConfigLdacSink();
  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 LDAC 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 LDAC
  72. // codec, otherwise false.
  73. bool A2DP_IsVendorSourceCodecValidLdac(const uint8_t* p_codec_info);
  74. // Checks whether the codec capabilities contain a valid A2DP LDAC Sink
  75. // codec.
  76. // NOTE: only codecs that are implemented are considered valid.
  77. // Returns true if |p_codec_info| contains information about a valid LDAC
  78. // codec, otherwise false.
  79. bool A2DP_IsVendorSinkCodecValidLdac(const uint8_t* p_codec_info);
  80. // Checks whether the codec capabilities contain a valid peer A2DP LDAC Sink
  81. // codec.
  82. // NOTE: only codecs that are implemented are considered valid.
  83. // Returns true if |p_codec_info| contains information about a valid LDAC
  84. // codec, otherwise false.
  85. bool A2DP_IsVendorPeerSinkCodecValidLdac(const uint8_t* p_codec_info);
  86. // Checks whether the codec capabilities contain a valid peer A2DP LDAC Source
  87. // codec.
  88. // NOTE: only codecs that are implemented are considered valid.
  89. // Returns true if |p_codec_info| contains information about a valid LDAC
  90. // codec, otherwise false.
  91. bool A2DP_IsVendorPeerSourceCodecValidLdac(const uint8_t* p_codec_info);
  92. // Checks whether A2DP LDAC Sink codec is supported.
  93. // |p_codec_info| contains information about the codec capabilities.
  94. // Returns true if the A2DP LDAC Sink codec is supported, otherwise false.
  95. bool A2DP_IsVendorSinkCodecSupportedLdac(const uint8_t* p_codec_info);
  96. // Checks whether an A2DP LDAC Source codec for a peer Source device is
  97. // supported.
  98. // |p_codec_info| contains information about the codec capabilities of the
  99. // peer device.
  100. // Returns true if the A2DP LDAC Source codec for a peer Source device is
  101. // supported, otherwise false.
  102. bool A2DP_IsPeerSourceCodecSupportedLdac(const uint8_t* p_codec_info);
  103. // Checks whether the A2DP data packets should contain RTP header.
  104. // |content_protection_enabled| is true if Content Protection is
  105. // enabled. |p_codec_info| contains information about the codec capabilities.
  106. // Returns true if the A2DP data packets should contain RTP header, otherwise
  107. // false.
  108. bool A2DP_VendorUsesRtpHeaderLdac(bool content_protection_enabled,
  109. const uint8_t* p_codec_info);
  110. // Gets the A2DP LDAC codec name for a given |p_codec_info|.
  111. const char* A2DP_VendorCodecNameLdac(const uint8_t* p_codec_info);
  112. // Checks whether two A2DP LDAC codecs |p_codec_info_a| and |p_codec_info_b|
  113. // have the same type.
  114. // Returns true if the two codecs have the same type, otherwise false.
  115. bool A2DP_VendorCodecTypeEqualsLdac(const uint8_t* p_codec_info_a,
  116. const uint8_t* p_codec_info_b);
  117. // Checks whether two A2DP LDAC codecs |p_codec_info_a| and |p_codec_info_b|
  118. // are exactly the same.
  119. // Returns true if the two codecs are exactly the same, otherwise false.
  120. // If the codec type is not LDAC, the return value is false.
  121. bool A2DP_VendorCodecEqualsLdac(const uint8_t* p_codec_info_a,
  122. const uint8_t* p_codec_info_b);
  123. // Gets the track sample rate value for the A2DP LDAC codec.
  124. // |p_codec_info| is a pointer to the LDAC codec_info to decode.
  125. // Returns the track sample rate on success, or -1 if |p_codec_info|
  126. // contains invalid codec information.
  127. int A2DP_VendorGetTrackSampleRateLdac(const uint8_t* p_codec_info);
  128. // Gets the track bits per sample value for the A2DP LDAC codec.
  129. // |p_codec_info| is a pointer to the LDAC codec_info to decode.
  130. // Returns the track bits per sample on success, or -1 if |p_codec_info|
  131. // contains invalid codec information.
  132. int A2DP_VendorGetTrackBitsPerSampleLdac(const uint8_t* p_codec_info);
  133. // Gets the track bitrate value for the A2DP LDAC codec.
  134. // |p_codec_info| is a pointer to the LDAC codec_info to decode.
  135. // Returns the track sample rate on success, or -1 if |p_codec_info|
  136. // contains invalid codec information.
  137. int A2DP_VendorGetBitRateLdac(const uint8_t* p_codec_info);
  138. // Gets the channel count for the A2DP LDAC codec.
  139. // |p_codec_info| is a pointer to the LDAC codec_info to decode.
  140. // Returns the channel count on success, or -1 if |p_codec_info|
  141. // contains invalid codec information.
  142. int A2DP_VendorGetTrackChannelCountLdac(const uint8_t* p_codec_info);
  143. // Gets the channel type for the A2DP LDAC codec.
  144. // 1 for mono, or 3 for dual channel/stereo.
  145. // |p_codec_info| is a pointer to the LDAC codec_info to decode.
  146. // Returns the channel count on success, or -1 if |p_codec_info|
  147. // contains invalid codec information.
  148. int A2DP_VendorGetSinkTrackChannelTypeLdac(const uint8_t* p_codec_info);
  149. // Gets the channel mode code for the A2DP LDAC codec.
  150. // The actual value is codec-specific - see |A2DP_LDAC_CHANNEL_MODE_*|.
  151. // |p_codec_info| is a pointer to the LDAC 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_VendorGetChannelModeCodeLdac(const uint8_t* p_codec_info);
  155. // Gets the A2DP LDAC audio data timestamp from an audio packet.
  156. // |p_codec_info| contains the codec information.
  157. // |p_data| contains the audio data.
  158. // The timestamp is stored in |p_timestamp|.
  159. // Returns true on success, otherwise false.
  160. bool A2DP_VendorGetPacketTimestampLdac(const uint8_t* p_codec_info,
  161. const uint8_t* p_data,
  162. uint32_t* p_timestamp);
  163. // Builds A2DP LDAC codec header for audio data.
  164. // |p_codec_info| contains the codec information.
  165. // |p_buf| contains the audio data.
  166. // |frames_per_packet| is the number of frames in this packet.
  167. // Returns true on success, otherwise false.
  168. bool A2DP_VendorBuildCodecHeaderLdac(const uint8_t* p_codec_info, BT_HDR* p_buf,
  169. uint16_t frames_per_packet);
  170. // Decodes A2DP LDAC codec info into a human readable string.
  171. // |p_codec_info| is a pointer to the LDAC codec_info to decode.
  172. // Returns a string describing the codec information.
  173. std::string A2DP_VendorCodecInfoStringLdac(const uint8_t* p_codec_info);
  174. // Gets the A2DP LDAC encoder interface that can be used to encode and prepare
  175. // A2DP packets for transmission - see |tA2DP_ENCODER_INTERFACE|.
  176. // |p_codec_info| contains the codec information.
  177. // Returns the A2DP LDAC encoder interface if the |p_codec_info| is valid and
  178. // supported, otherwise NULL.
  179. const tA2DP_ENCODER_INTERFACE* A2DP_VendorGetEncoderInterfaceLdac(
  180. const uint8_t* p_codec_info);
  181. // Gets the current A2DP LDAC decoder interface that can be used to decode
  182. // received A2DP packets - see |tA2DP_DECODER_INTERFACE|.
  183. // |p_codec_info| contains the codec information.
  184. // Returns the A2DP LDAC decoder interface if the |p_codec_info| is valid and
  185. // supported, otherwise NULL.
  186. const tA2DP_DECODER_INTERFACE* A2DP_VendorGetDecoderInterfaceLdac(
  187. const uint8_t* p_codec_info);
  188. // Adjusts the A2DP LDAC codec, based on local support and Bluetooth
  189. // specification.
  190. // |p_codec_info| contains the codec information to adjust.
  191. // Returns true if |p_codec_info| is valid and supported, otherwise false.
  192. bool A2DP_VendorAdjustCodecLdac(uint8_t* p_codec_info);
  193. // Gets the A2DP LDAC Source codec index for a given |p_codec_info|.
  194. // Returns the corresponding |btav_a2dp_codec_index_t| on success,
  195. // otherwise |BTAV_A2DP_CODEC_INDEX_MAX|.
  196. btav_a2dp_codec_index_t A2DP_VendorSourceCodecIndexLdac(
  197. const uint8_t* p_codec_info);
  198. // Gets the A2DP LDAC Sink codec index for a given |p_codec_info|.
  199. // Returns the corresponding |btav_a2dp_codec_index_t| on success,
  200. // otherwise |BTAV_A2DP_CODEC_INDEX_MAX|.
  201. btav_a2dp_codec_index_t A2DP_VendorSinkCodecIndexLdac(
  202. const uint8_t* p_codec_info);
  203. // Gets the A2DP LDAC Source codec name.
  204. const char* A2DP_VendorCodecIndexStrLdac(void);
  205. // Gets the A2DP LDAC Sink codec name.
  206. const char* A2DP_VendorCodecIndexStrLdacSink(void);
  207. // Initializes A2DP LDAC Source codec information into |AvdtpSepConfig|
  208. // configuration entry pointed by |p_cfg|.
  209. bool A2DP_VendorInitCodecConfigLdac(AvdtpSepConfig* p_cfg);
  210. // Initializes A2DP LDAC Sink codec information into |AvdtpSepConfig|
  211. // configuration entry pointed by |p_cfg|.
  212. bool A2DP_VendorInitCodecConfigLdacSink(AvdtpSepConfig* p_cfg);
  213. #endif // A2DP_VENDOR_LDAC_H