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 peer A2DP 58 // vendor-specific Source 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_IsVendorPeerSourceCodecValid(const uint8_t* p_codec_info); 63 64 // Checks whether the codec capabilities contain a valid peer A2DP 65 // vendor-specific Sink 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_IsVendorPeerSinkCodecValid(const uint8_t* p_codec_info); 70 71 // Checks whether a vendor-specific A2DP Sink codec is supported. 72 // |p_codec_info| contains information about the codec capabilities. 73 // Returns true if the vendor-specific A2DP Sink codec is supported, 74 // otherwise false. 75 tA2DP_STATUS A2DP_IsVendorSinkCodecSupported(const uint8_t* p_codec_info); 76 77 // Gets the Vendor ID for the vendor-specific A2DP codec. 78 // |p_codec_info| contains information about the codec capabilities. 79 // Returns the Vendor ID for the vendor-specific A2DP codec. 80 uint32_t A2DP_VendorCodecGetVendorId(const uint8_t* p_codec_info); 81 82 // Gets the Codec ID for the vendor-specific A2DP codec. 83 // |p_codec_info| contains information about the codec capabilities. 84 // Returns the Codec ID for the vendor-specific A2DP codec. 85 uint16_t A2DP_VendorCodecGetCodecId(const uint8_t* p_codec_info); 86 87 // Checks whether the A2DP vendor-specific data packets should contain RTP 88 // header. |content_protection_enabled| is true if Content Protection is 89 // enabled. |p_codec_info| contains information about the codec capabilities. 90 // Returns true if the A2DP vendor-specific data packets should contain RTP 91 // header, otherwise false. 92 bool A2DP_VendorUsesRtpHeader(bool content_protection_enabled, const uint8_t* p_codec_info); 93 94 // Gets the A2DP vendor-specific codec name for a given |p_codec_info|. 95 const char* A2DP_VendorCodecName(const uint8_t* p_codec_info); 96 97 // Checks whether two A2DP vendor-specific codecs |p_codec_info_a| and 98 // |p_codec_info_b| have the same type. 99 // Returns true if the two codecs have the same type, otherwise false. 100 // If the codec type is not recognized, the return value is false. 101 bool A2DP_VendorCodecTypeEquals(const uint8_t* p_codec_info_a, const uint8_t* p_codec_info_b); 102 103 // Gets the bitrate for the A2DP vendor-specific codec. 104 // |p_codec_info| is a pointer to the vendor-specific codec_info to decode. 105 // Returns the channel count on success, or -1 if |p_codec_info| 106 // contains invalid codec information. 107 int A2DP_VendorGetBitRate(const uint8_t* p_codec_info); 108 109 // Gets the channel type for the A2DP vendor-specific Sink codec: 110 // 1 for mono, or 3 for dual/stereo/joint. 111 // |p_codec_info| is a pointer to the vendor-specific codec_info to decode. 112 // Returns the channel type on success, or -1 if |p_codec_info| 113 // contains invalid codec information. 114 int A2DP_VendorGetSinkTrackChannelType(const uint8_t* p_codec_info); 115 116 // Builds A2DP vendor-specific codec header for audio data. 117 // |p_codec_info| contains the codec information. 118 // |p_buf| contains the audio data. 119 // |frames_per_packet| is the number of frames in this packet. 120 // Returns true on success, otherwise false. 121 bool A2DP_VendorBuildCodecHeader(const uint8_t* p_codec_info, BT_HDR* p_buf, 122 uint16_t frames_per_packet); 123 124 // Gets the A2DP vendor encoder interface that can be used to encode and 125 // prepare A2DP packets for transmission - see |tA2DP_ENCODER_INTERFACE|. 126 // |p_codec_info| contains the codec information. 127 // Returns the A2DP vendor encoder interface if the |p_codec_info| is valid and 128 // supported, otherwise NULL. 129 const tA2DP_ENCODER_INTERFACE* A2DP_VendorGetEncoderInterface(const uint8_t* p_codec_info); 130 131 // Gets the current A2DP vendor decoder interface that can be used to decode 132 // received A2DP packets - see |tA2DP_DECODER_INTERFACE|. 133 // |p_codec_info| contains the codec information. 134 // Returns the A2DP vendor decoder interface if the |p_codec_info| is valid and 135 // supported, otherwise NULL. 136 const tA2DP_DECODER_INTERFACE* A2DP_VendorGetDecoderInterface(const uint8_t* p_codec_info); 137 138 // Adjusts the A2DP vendor-specific codec, based on local support and Bluetooth 139 // specification. 140 // |p_codec_info| contains the codec information to adjust. 141 // Returns true if |p_codec_info| is valid and supported, otherwise false. 142 bool A2DP_VendorAdjustCodec(uint8_t* p_codec_info); 143 144 // Gets the A2DP vendor Source codec index for a given |p_codec_info|. 145 // Returns the corresponding |btav_a2dp_codec_index_t| on success, 146 // otherwise |BTAV_A2DP_CODEC_INDEX_MAX|. 147 btav_a2dp_codec_index_t A2DP_VendorSourceCodecIndex(const uint8_t* p_codec_info); 148 149 // Gets the A2DP vendor Sink codec index for a given |p_codec_info|. 150 // Returns the corresponding |btav_a2dp_codec_index_t| on success, 151 // otherwise |BTAV_A2DP_CODEC_INDEX_MAX|. 152 btav_a2dp_codec_index_t A2DP_VendorSinkCodecIndex(const uint8_t* p_codec_info); 153 154 // Gets the A2DP vendor codec name for a given |codec_index|. 155 const char* A2DP_VendorCodecIndexStr(btav_a2dp_codec_index_t codec_index); 156 157 // Initializes A2DP vendor codec-specific information into |AvdtpSepConfig| 158 // configuration entry pointed by |p_cfg|. The selected codec is defined by 159 // |codec_index|. 160 // Returns true on success, otherwise false. 161 bool A2DP_VendorInitCodecConfig(btav_a2dp_codec_index_t codec_index, AvdtpSepConfig* p_cfg); 162 163 // Decodes A2DP vendor codec info into a human readable string. 164 // |p_codec_info| is a pointer to the codec_info to decode. 165 // Returns a string describing the codec information. 166 std::string A2DP_VendorCodecInfoString(const uint8_t* p_codec_info); 167 168 #endif // A2DP_VENDOR_H 169