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