1 /* 2 * Copyright (C) 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 aptX-HD 19 // 20 21 #ifndef A2DP_VENDOR_APTX_HD_H 22 #define A2DP_VENDOR_APTX_HD_H 23 24 #include "a2dp_codec_api.h" 25 #include "a2dp_vendor_aptx_hd_constants.h" 26 #include "avdt_api.h" 27 28 class A2dpCodecConfigAptxHd : public A2dpCodecConfig { 29 public: 30 A2dpCodecConfigAptxHd(btav_a2dp_codec_priority_t codec_priority); 31 virtual ~A2dpCodecConfigAptxHd(); 32 33 bool init() override; 34 period_ms_t encoderIntervalMs() const override; 35 bool setCodecConfig(const uint8_t* p_peer_codec_info, bool is_capability, 36 uint8_t* p_result_codec_config) override; 37 38 private: 39 bool useRtpHeaderMarkerBit() const override; 40 bool updateEncoderUserConfig( 41 const tA2DP_ENCODER_INIT_PEER_PARAMS* p_peer_params, 42 bool* p_restart_input, bool* p_restart_output, 43 bool* p_config_updated) override; 44 void debug_codec_dump(int fd) override; 45 }; 46 47 // Checks whether the codec capabilities contain a valid A2DP aptX-HD Source 48 // codec. 49 // NOTE: only codecs that are implemented are considered valid. 50 // Returns true if |p_codec_info| contains information about a valid aptX-HD 51 // codec, otherwise false. 52 bool A2DP_IsVendorSourceCodecValidAptxHd(const uint8_t* p_codec_info); 53 54 // Checks whether the codec capabilities contain a valid peer A2DP aptX-HD Sink 55 // codec. 56 // NOTE: only codecs that are implemented are considered valid. 57 // Returns true if |p_codec_info| contains information about a valid aptX-HD 58 // codec, otherwise false. 59 bool A2DP_IsVendorPeerSinkCodecValidAptxHd(const uint8_t* p_codec_info); 60 61 // Checks whether the A2DP data packets should contain RTP header. 62 // |content_protection_enabled| is true if Content Protection is 63 // enabled. |p_codec_info| contains information about the codec capabilities. 64 // Returns true if the A2DP data packets should contain RTP header, otherwise 65 // false. 66 bool A2DP_VendorUsesRtpHeaderAptxHd(bool content_protection_enabled, 67 const uint8_t* p_codec_info); 68 69 // Gets the A2DP aptX-HD codec name for a given |p_codec_info|. 70 const char* A2DP_VendorCodecNameAptxHd(const uint8_t* p_codec_info); 71 72 // Checks whether two A2DP aptX-HD codecs |p_codec_info_a| and |p_codec_info_b| 73 // have the same type. 74 // Returns true if the two codecs have the same type, otherwise false. 75 bool A2DP_VendorCodecTypeEqualsAptxHd(const uint8_t* p_codec_info_a, 76 const uint8_t* p_codec_info_b); 77 78 // Checks whether two A2DP aptX-HD codecs |p_codec_info_a| and |p_codec_info_b| 79 // are exactly the same. 80 // Returns true if the two codecs are exactly the same, otherwise false. 81 // If the codec type is not aptX-HD, the return value is false. 82 bool A2DP_VendorCodecEqualsAptxHd(const uint8_t* p_codec_info_a, 83 const uint8_t* p_codec_info_b); 84 85 // Gets the track sample rate value for the A2DP aptX-HD codec. 86 // |p_codec_info| is a pointer to the aptX-HD 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_VendorGetTrackSampleRateAptxHd(const uint8_t* p_codec_info); 90 91 // Gets the bits per audio sample for the A2DP aptX-HD codec. 92 // |p_codec_info| is a pointer to the aptX-HD codec_info to decode. 93 // Returns the bits per audio sample on success, or -1 if |p_codec_info| 94 // contains invalid codec information. 95 int A2DP_VendorGetTrackBitsPerSampleAptxHd(const uint8_t* p_codec_info); 96 97 // Gets the channel count for the A2DP aptX-HD codec. 98 // |p_codec_info| is a pointer to the aptX-HD codec_info to decode. 99 // Returns the channel count on success, or -1 if |p_codec_info| 100 // contains invalid codec information. 101 int A2DP_VendorGetTrackChannelCountAptxHd(const uint8_t* p_codec_info); 102 103 // Gets the A2DP aptX-HD audio data timestamp from an audio packet. 104 // |p_codec_info| contains the codec information. 105 // |p_data| contains the audio data. 106 // The timestamp is stored in |p_timestamp|. 107 // Returns true on success, otherwise false. 108 bool A2DP_VendorGetPacketTimestampAptxHd(const uint8_t* p_codec_info, 109 const uint8_t* p_data, 110 uint32_t* p_timestamp); 111 112 // Builds A2DP aptX-HD codec header for audio data. 113 // |p_codec_info| contains the codec information. 114 // |p_buf| contains the audio data. 115 // |frames_per_packet| is the number of frames in this packet. 116 // Returns true on success, otherwise false. 117 bool A2DP_VendorBuildCodecHeaderAptxHd(const uint8_t* p_codec_info, 118 BT_HDR* p_buf, 119 uint16_t frames_per_packet); 120 121 // Decodes and displays aptX-HD codec info (for debugging). 122 // |p_codec_info| is a pointer to the aptX-HD codec_info to decode and display. 123 void A2DP_VendorDumpCodecInfoAptxHd(const uint8_t* p_codec_info); 124 125 // Gets the A2DP aptX-HD encoder interface that can be used to encode and 126 // prepare A2DP packets for transmission - see |tA2DP_ENCODER_INTERFACE|. 127 // |p_codec_info| contains the codec information. 128 // Returns the A2DP aptX-HD encoder interface if the |p_codec_info| is valid 129 // and supported, otherwise NULL. 130 const tA2DP_ENCODER_INTERFACE* A2DP_VendorGetEncoderInterfaceAptxHd( 131 const uint8_t* p_codec_info); 132 133 // Adjusts the A2DP aptX-HD codec, based on local support and Bluetooth 134 // specification. 135 // |p_codec_info| contains the codec information to adjust. 136 // Returns true if |p_codec_info| is valid and supported, otherwise false. 137 bool A2DP_VendorAdjustCodecAptxHd(uint8_t* p_codec_info); 138 139 // Gets the A2DP aptX-HD Source codec index for a given |p_codec_info|. 140 // Returns the corresponding |btav_a2dp_codec_index_t| on success, 141 // otherwise |BTAV_A2DP_CODEC_INDEX_MAX|. 142 btav_a2dp_codec_index_t A2DP_VendorSourceCodecIndexAptxHd( 143 const uint8_t* p_codec_info); 144 145 // Gets the A2DP aptX-HD Source codec name. 146 const char* A2DP_VendorCodecIndexStrAptxHd(void); 147 148 // Initializes A2DP aptX-HD Source codec information into |tAVDT_CFG| 149 // configuration entry pointed by |p_cfg|. 150 bool A2DP_VendorInitCodecConfigAptxHd(tAVDT_CFG* p_cfg); 151 152 #endif // A2DP_VENDOR_APTX_HD_H 153