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 // Vendor Specific A2DP Codecs Support 19 // 20 21 #ifndef A2DP_VENDOR_H 22 #define A2DP_VENDOR_H 23 24 #include <dlfcn.h> 25 #include <stdbool.h> 26 #include <stddef.h> 27 #include <stdint.h> 28 29 #include <vector> 30 31 #include "a2dp_codec_api.h" 32 #include "stack/include/bt_hdr.h" 33 34 typedef enum { 35 LOAD_SUCCESS, 36 LOAD_ERROR_MISSING_CODEC, 37 LOAD_ERROR_VERSION_MISMATCH, 38 } tLOADING_CODEC_STATUS; 39 40 /* Offset for A2DP vendor codec */ 41 #define A2DP_VENDOR_CODEC_START_IDX 3 42 43 /* Offset for Vendor ID for A2DP vendor codec */ 44 #define A2DP_VENDOR_CODEC_VENDOR_ID_START_IDX A2DP_VENDOR_CODEC_START_IDX 45 46 /* Offset for Codec ID for A2DP vendor codec */ 47 #define A2DP_VENDOR_CODEC_CODEC_ID_START_IDX \ 48 (A2DP_VENDOR_CODEC_VENDOR_ID_START_IDX + sizeof(uint32_t)) 49 50 // Checks whether the codec capabilities contain a valid A2DP vendor-specific 51 // Source codec. 52 // NOTE: only codecs that are implemented are considered valid. 53 // Returns true if |p_codec_info| contains information about a valid 54 // vendor-specific codec, otherwise false. 55 bool A2DP_IsVendorSourceCodecValid(const uint8_t* p_codec_info); 56 57 // Checks whether the codec capabilities contain a valid A2DP vendor-specific 58 // Sink codec. 59 // NOTE: only codecs that are implemented are considered valid. 60 // Returns true if |p_codec_info| contains information about a valid 61 // vendor-specific codec, otherwise false. 62 bool A2DP_IsVendorSinkCodecValid(const uint8_t* p_codec_info); 63 64 // Checks whether the codec capabilities contain a valid peer A2DP 65 // vendor-specific Source codec. 66 // NOTE: only codecs that are implemented are considered valid. 67 // Returns true if |p_codec_info| contains information about a valid 68 // vendor-specific codec, otherwise false. 69 bool A2DP_IsVendorPeerSourceCodecValid(const uint8_t* p_codec_info); 70 71 // Checks whether the codec capabilities contain a valid peer A2DP 72 // vendor-specific Sink codec. 73 // NOTE: only codecs that are implemented are considered valid. 74 // Returns true if |p_codec_info| contains information about a valid 75 // vendor-specific codec, otherwise false. 76 bool A2DP_IsVendorPeerSinkCodecValid(const uint8_t* p_codec_info); 77 78 // Checks whether a vendor-specific A2DP Sink codec is supported. 79 // |p_codec_info| contains information about the codec capabilities. 80 // Returns true if the vendor-specific A2DP Sink codec is supported, 81 // otherwise false. 82 bool A2DP_IsVendorSinkCodecSupported(const uint8_t* p_codec_info); 83 84 // Checks whether a vendor-specific A2DP Source codec for a peer Source device 85 // is supported. 86 // |p_codec_info| contains information about the codec capabilities of the 87 // peer device. 88 // Returns true if the vendor-specific A2DP Source codec for a peer Source 89 // device is supported, otherwise false. 90 bool A2DP_IsVendorPeerSourceCodecSupported(const uint8_t* p_codec_info); 91 92 // Gets the Vendor ID for the vendor-specific A2DP codec. 93 // |p_codec_info| contains information about the codec capabilities. 94 // Returns the Vendor ID for the vendor-specific A2DP codec. 95 uint32_t A2DP_VendorCodecGetVendorId(const uint8_t* p_codec_info); 96 97 // Gets the Codec ID for the vendor-specific A2DP codec. 98 // |p_codec_info| contains information about the codec capabilities. 99 // Returns the Codec ID for the vendor-specific A2DP codec. 100 uint16_t A2DP_VendorCodecGetCodecId(const uint8_t* p_codec_info); 101 102 // Checks whether the A2DP vendor-specific data packets should contain RTP 103 // header. |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 vendor-specific data packets should contain RTP 106 // header, otherwise false. 107 bool A2DP_VendorUsesRtpHeader(bool content_protection_enabled, 108 const uint8_t* p_codec_info); 109 110 // Gets the A2DP vendor-specific codec name for a given |p_codec_info|. 111 const char* A2DP_VendorCodecName(const uint8_t* p_codec_info); 112 113 // Checks whether two A2DP vendor-specific codecs |p_codec_info_a| and 114 // |p_codec_info_b| have the same type. 115 // Returns true if the two codecs have the same type, otherwise false. 116 // If the codec type is not recognized, the return value is false. 117 bool A2DP_VendorCodecTypeEquals(const uint8_t* p_codec_info_a, 118 const uint8_t* p_codec_info_b); 119 120 // Checks whether two A2DP vendor-specific codecs |p_codec_info_a| and 121 // |p_codec_info_b| are exactly the same. 122 // Returns true if the two codecs are exactly the same, otherwise false. 123 // If the codec type is not recognized, the return value is false. 124 bool A2DP_VendorCodecEquals(const uint8_t* p_codec_info_a, 125 const uint8_t* p_codec_info_b); 126 127 // Gets the track sample rate value for the A2DP vendor-specific codec. 128 // |p_codec_info| is a pointer to the vendor-specific codec_info to decode. 129 // Returns the track sample rate on success, or -1 if |p_codec_info| 130 // contains invalid codec information. 131 int A2DP_VendorGetTrackSampleRate(const uint8_t* p_codec_info); 132 133 // Gets the track bits per sample value for the A2DP vendor-specific codec. 134 // |p_codec_info| is a pointer to the vendor-specific 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_VendorGetTrackBitsPerSample(const uint8_t* p_codec_info); 138 139 // Gets the channel count for the A2DP vendor-specific codec. 140 // |p_codec_info| is a pointer to the vendor-specific codec_info to decode. 141 // Returns the channel count on success, or -1 if |p_codec_info| 142 // contains invalid codec information. 143 int A2DP_VendorGetTrackChannelCount(const uint8_t* p_codec_info); 144 145 // Gets the bitrate for the A2DP vendor-specific codec. 146 // |p_codec_info| is a pointer to the vendor-specific codec_info to decode. 147 // Returns the channel count on success, or -1 if |p_codec_info| 148 // contains invalid codec information. 149 int A2DP_VendorGetBitRate(const uint8_t* p_codec_info); 150 151 // Gets the channel type for the A2DP vendor-specific Sink codec: 152 // 1 for mono, or 3 for dual/stereo/joint. 153 // |p_codec_info| is a pointer to the vendor-specific codec_info to decode. 154 // Returns the channel type on success, or -1 if |p_codec_info| 155 // contains invalid codec information. 156 int A2DP_VendorGetSinkTrackChannelType(const uint8_t* p_codec_info); 157 158 // Gets the A2DP codec-specific audio data timestamp from an audio packet. 159 // |p_codec_info| contains the codec information. 160 // |p_data| contains the audio data. 161 // The timestamp is stored in |p_timestamp|. 162 // Returns true on success, otherwise false. 163 bool A2DP_VendorGetPacketTimestamp(const uint8_t* p_codec_info, 164 const uint8_t* p_data, 165 uint32_t* p_timestamp); 166 167 // Builds A2DP vendor-specific codec header for audio data. 168 // |p_codec_info| contains the codec information. 169 // |p_buf| contains the audio data. 170 // |frames_per_packet| is the number of frames in this packet. 171 // Returns true on success, otherwise false. 172 bool A2DP_VendorBuildCodecHeader(const uint8_t* p_codec_info, BT_HDR* p_buf, 173 uint16_t frames_per_packet); 174 175 // Gets the A2DP vendor encoder interface that can be used to encode and 176 // prepare A2DP packets for transmission - see |tA2DP_ENCODER_INTERFACE|. 177 // |p_codec_info| contains the codec information. 178 // Returns the A2DP vendor encoder interface if the |p_codec_info| is valid and 179 // supported, otherwise NULL. 180 const tA2DP_ENCODER_INTERFACE* A2DP_VendorGetEncoderInterface( 181 const uint8_t* p_codec_info); 182 183 // Gets the current A2DP vendor decoder interface that can be used to decode 184 // received A2DP packets - see |tA2DP_DECODER_INTERFACE|. 185 // |p_codec_info| contains the codec information. 186 // Returns the A2DP vendor decoder interface if the |p_codec_info| is valid and 187 // supported, otherwise NULL. 188 const tA2DP_DECODER_INTERFACE* A2DP_VendorGetDecoderInterface( 189 const uint8_t* p_codec_info); 190 191 // Adjusts the A2DP vendor-specific codec, based on local support and Bluetooth 192 // specification. 193 // |p_codec_info| contains the codec information to adjust. 194 // Returns true if |p_codec_info| is valid and supported, otherwise false. 195 bool A2DP_VendorAdjustCodec(uint8_t* p_codec_info); 196 197 // Gets the A2DP vendor Source codec index for a given |p_codec_info|. 198 // Returns the corresponding |btav_a2dp_codec_index_t| on success, 199 // otherwise |BTAV_A2DP_CODEC_INDEX_MAX|. 200 btav_a2dp_codec_index_t A2DP_VendorSourceCodecIndex( 201 const uint8_t* p_codec_info); 202 203 // Gets the A2DP vendor Sink codec index for a given |p_codec_info|. 204 // Returns the corresponding |btav_a2dp_codec_index_t| on success, 205 // otherwise |BTAV_A2DP_CODEC_INDEX_MAX|. 206 btav_a2dp_codec_index_t A2DP_VendorSinkCodecIndex(const uint8_t* p_codec_info); 207 208 // Gets the A2DP vendor codec name for a given |codec_index|. 209 const char* A2DP_VendorCodecIndexStr(btav_a2dp_codec_index_t codec_index); 210 211 // Initializes A2DP vendor codec-specific information into |AvdtpSepConfig| 212 // configuration entry pointed by |p_cfg|. The selected codec is defined by 213 // |codec_index|. 214 // Returns true on success, otherwise false. 215 bool A2DP_VendorInitCodecConfig(btav_a2dp_codec_index_t codec_index, 216 AvdtpSepConfig* p_cfg); 217 218 // Decodes A2DP vendor codec info into a human readable string. 219 // |p_codec_info| is a pointer to the codec_info to decode. 220 // Returns a string describing the codec information. 221 std::string A2DP_VendorCodecInfoString(const uint8_t* p_codec_info); 222 223 #endif // A2DP_VENDOR_H 224