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