a2dp_vendor_aptx.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 aptX
  18. //
  19. #ifndef A2DP_VENDOR_APTX_H
  20. #define A2DP_VENDOR_APTX_H
  21. #include "a2dp_codec_api.h"
  22. #include "a2dp_vendor_aptx_constants.h"
  23. #include "avdt_api.h"
  24. class A2dpCodecConfigAptx : public A2dpCodecConfig {
  25. public:
  26. A2dpCodecConfigAptx(btav_a2dp_codec_priority_t codec_priority);
  27. virtual ~A2dpCodecConfigAptx();
  28. bool init() override;
  29. uint64_t encoderIntervalMs() const override;
  30. int getEffectiveMtu() const override;
  31. bool setCodecConfig(const uint8_t* p_peer_codec_info, bool is_capability,
  32. uint8_t* p_result_codec_config) override;
  33. bool setPeerCodecCapabilities(
  34. const uint8_t* p_peer_codec_capabilities) override;
  35. private:
  36. bool useRtpHeaderMarkerBit() const override;
  37. bool updateEncoderUserConfig(
  38. const tA2DP_ENCODER_INIT_PEER_PARAMS* p_peer_params,
  39. bool* p_restart_input, bool* p_restart_output,
  40. bool* p_config_updated) override;
  41. void debug_codec_dump(int fd) override;
  42. };
  43. // Checks whether the codec capabilities contain a valid A2DP aptX Source
  44. // codec.
  45. // NOTE: only codecs that are implemented are considered valid.
  46. // Returns true if |p_codec_info| contains information about a valid aptX
  47. // codec, otherwise false.
  48. bool A2DP_IsVendorSourceCodecValidAptx(const uint8_t* p_codec_info);
  49. // Checks whether the codec capabilities contain a valid peer A2DP aptX Sink
  50. // codec.
  51. // NOTE: only codecs that are implemented are considered valid.
  52. // Returns true if |p_codec_info| contains information about a valid aptX
  53. // codec, otherwise false.
  54. bool A2DP_IsVendorPeerSinkCodecValidAptx(const uint8_t* p_codec_info);
  55. // Checks whether the A2DP data packets should contain RTP header.
  56. // |content_protection_enabled| is true if Content Protection is
  57. // enabled. |p_codec_info| contains information about the codec capabilities.
  58. // Returns true if the A2DP data packets should contain RTP header, otherwise
  59. // false.
  60. bool A2DP_VendorUsesRtpHeaderAptx(bool content_protection_enabled,
  61. const uint8_t* p_codec_info);
  62. // Gets the A2DP aptX codec name for a given |p_codec_info|.
  63. const char* A2DP_VendorCodecNameAptx(const uint8_t* p_codec_info);
  64. // Checks whether two A2DP aptX codecs |p_codec_info_a| and |p_codec_info_b|
  65. // have the same type.
  66. // Returns true if the two codecs have the same type, otherwise false.
  67. bool A2DP_VendorCodecTypeEqualsAptx(const uint8_t* p_codec_info_a,
  68. const uint8_t* p_codec_info_b);
  69. // Checks whether two A2DP aptX codecs |p_codec_info_a| and |p_codec_info_b|
  70. // are exactly the same.
  71. // Returns true if the two codecs are exactly the same, otherwise false.
  72. // If the codec type is not aptX, the return value is false.
  73. bool A2DP_VendorCodecEqualsAptx(const uint8_t* p_codec_info_a,
  74. const uint8_t* p_codec_info_b);
  75. // Gets the track sample rate value for the A2DP aptX codec.
  76. // |p_codec_info| is a pointer to the aptX codec_info to decode.
  77. // Returns the track sample rate on success, or -1 if |p_codec_info|
  78. // contains invalid codec information.
  79. int A2DP_VendorGetTrackSampleRateAptx(const uint8_t* p_codec_info);
  80. // Gets the track bits per sample value for the A2DP aptX codec.
  81. // |p_codec_info| is a pointer to the aptX codec_info to decode.
  82. // Returns the track bits per sample on success, or -1 if |p_codec_info|
  83. // contains invalid codec information.
  84. int A2DP_VendorGetTrackBitsPerSampleAptx(const uint8_t* p_codec_info);
  85. // Gets the track bitrate value for the A2DP aptX codec.
  86. // |p_codec_info| is a pointer to the aptX codec_info to decode.
  87. // Returns the track sample rate on success, or -1 if |p_codec_info|
  88. // contains invalid codec information.
  89. int A2DP_VendorGetBitRateAptx(const uint8_t* p_codec_info);
  90. // Gets the channel count for the A2DP aptX codec.
  91. // |p_codec_info| is a pointer to the aptX codec_info to decode.
  92. // Returns the channel count on success, or -1 if |p_codec_info|
  93. // contains invalid codec information.
  94. int A2DP_VendorGetTrackChannelCountAptx(const uint8_t* p_codec_info);
  95. // Gets the A2DP aptX audio data timestamp from an audio packet.
  96. // |p_codec_info| contains the codec information.
  97. // |p_data| contains the audio data.
  98. // The timestamp is stored in |p_timestamp|.
  99. // Returns true on success, otherwise false.
  100. bool A2DP_VendorGetPacketTimestampAptx(const uint8_t* p_codec_info,
  101. const uint8_t* p_data,
  102. uint32_t* p_timestamp);
  103. // Builds A2DP aptX codec header for audio data.
  104. // |p_codec_info| contains the codec information.
  105. // |p_buf| contains the audio data.
  106. // |frames_per_packet| is the number of frames in this packet.
  107. // Returns true on success, otherwise false.
  108. bool A2DP_VendorBuildCodecHeaderAptx(const uint8_t* p_codec_info, BT_HDR* p_buf,
  109. uint16_t frames_per_packet);
  110. // Decodes A2DP aptX codec info into a human readable string.
  111. // |p_codec_info| is a pointer to the aptX codec_info to decode.
  112. // Returns a string describing the codec information.
  113. std::string A2DP_VendorCodecInfoStringAptx(const uint8_t* p_codec_info);
  114. // Gets the A2DP aptX encoder interface that can be used to encode and prepare
  115. // A2DP packets for transmission - see |tA2DP_ENCODER_INTERFACE|.
  116. // |p_codec_info| contains the codec information.
  117. // Returns the A2DP aptX encoder interface if the |p_codec_info| is valid and
  118. // supported, otherwise NULL.
  119. const tA2DP_ENCODER_INTERFACE* A2DP_VendorGetEncoderInterfaceAptx(
  120. const uint8_t* p_codec_info);
  121. // Adjusts the A2DP aptX codec, based on local support and Bluetooth
  122. // specification.
  123. // |p_codec_info| contains the codec information to adjust.
  124. // Returns true if |p_codec_info| is valid and supported, otherwise false.
  125. bool A2DP_VendorAdjustCodecAptx(uint8_t* p_codec_info);
  126. // Gets the A2DP aptX Source codec index for a given |p_codec_info|.
  127. // Returns the corresponding |btav_a2dp_codec_index_t| on success,
  128. // otherwise |BTAV_A2DP_CODEC_INDEX_MAX|.
  129. btav_a2dp_codec_index_t A2DP_VendorSourceCodecIndexAptx(
  130. const uint8_t* p_codec_info);
  131. // Gets the A2DP aptX Source codec name.
  132. const char* A2DP_VendorCodecIndexStrAptx(void);
  133. // Initializes A2DP aptX Source codec information into |AvdtpSepConfig|
  134. // configuration entry pointed by |p_cfg|.
  135. bool A2DP_VendorInitCodecConfigAptx(AvdtpSepConfig* p_cfg);
  136. #endif // A2DP_VENDOR_APTX_H