• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 track bits per sample value for the A2DP vendor-specific codec.
121 // |p_codec_info| is a pointer to the vendor-specific codec_info to decode.
122 // Returns the track sample rate on success, or -1 if |p_codec_info|
123 // contains invalid codec information.
124 int A2DP_VendorGetTrackBitsPerSample(const uint8_t* p_codec_info);
125 
126 // Gets the channel count 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_VendorGetTrackChannelCount(const uint8_t* p_codec_info);
131 
132 // Gets the bitrate for the A2DP vendor-specific codec.
133 // |p_codec_info| is a pointer to the vendor-specific codec_info to decode.
134 // Returns the channel count on success, or -1 if |p_codec_info|
135 // contains invalid codec information.
136 int A2DP_VendorGetBitRate(const uint8_t* p_codec_info);
137 
138 // Gets the channel type for the A2DP vendor-specific Sink codec:
139 // 1 for mono, or 3 for dual/stereo/joint.
140 // |p_codec_info| is a pointer to the vendor-specific codec_info to decode.
141 // Returns the channel type on success, or -1 if |p_codec_info|
142 // contains invalid codec information.
143 int A2DP_VendorGetSinkTrackChannelType(const uint8_t* p_codec_info);
144 
145 // Gets the A2DP codec-specific audio data timestamp from an audio packet.
146 // |p_codec_info| contains the codec information.
147 // |p_data| contains the audio data.
148 // The timestamp is stored in |p_timestamp|.
149 // Returns true on success, otherwise false.
150 bool A2DP_VendorGetPacketTimestamp(const uint8_t* p_codec_info,
151                                    const uint8_t* p_data,
152                                    uint32_t* p_timestamp);
153 
154 // Builds A2DP vendor-specific codec header for audio data.
155 // |p_codec_info| contains the codec information.
156 // |p_buf| contains the audio data.
157 // |frames_per_packet| is the number of frames in this packet.
158 // Returns true on success, otherwise false.
159 bool A2DP_VendorBuildCodecHeader(const uint8_t* p_codec_info, BT_HDR* p_buf,
160                                  uint16_t frames_per_packet);
161 
162 // Gets the A2DP vendor encoder interface that can be used to encode and
163 // prepare A2DP packets for transmission - see |tA2DP_ENCODER_INTERFACE|.
164 // |p_codec_info| contains the codec information.
165 // Returns the A2DP vendor encoder interface if the |p_codec_info| is valid and
166 // supported, otherwise NULL.
167 const tA2DP_ENCODER_INTERFACE* A2DP_VendorGetEncoderInterface(
168     const uint8_t* p_codec_info);
169 
170 // Gets the current A2DP vendor decoder interface that can be used to decode
171 // received A2DP packets - see |tA2DP_DECODER_INTERFACE|.
172 // |p_codec_info| contains the codec information.
173 // Returns the A2DP vendor decoder interface if the |p_codec_info| is valid and
174 // supported, otherwise NULL.
175 const tA2DP_DECODER_INTERFACE* A2DP_VendorGetDecoderInterface(
176     const uint8_t* p_codec_info);
177 
178 // Adjusts the A2DP vendor-specific codec, based on local support and Bluetooth
179 // specification.
180 // |p_codec_info| contains the codec information to adjust.
181 // Returns true if |p_codec_info| is valid and supported, otherwise false.
182 bool A2DP_VendorAdjustCodec(uint8_t* p_codec_info);
183 
184 // Gets the A2DP vendor Source 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_VendorSourceCodecIndex(
188     const uint8_t* p_codec_info);
189 
190 // Gets the A2DP vendor Sink codec index for a given |p_codec_info|.
191 // Returns the corresponding |btav_a2dp_codec_index_t| on success,
192 // otherwise |BTAV_A2DP_CODEC_INDEX_MAX|.
193 btav_a2dp_codec_index_t A2DP_VendorSinkCodecIndex(const uint8_t* p_codec_info);
194 
195 // Gets the A2DP vendor codec name for a given |codec_index|.
196 const char* A2DP_VendorCodecIndexStr(btav_a2dp_codec_index_t codec_index);
197 
198 // Initializes A2DP vendor codec-specific information into |AvdtpSepConfig|
199 // configuration entry pointed by |p_cfg|. The selected codec is defined by
200 // |codec_index|.
201 // Returns true on success, otherwise false.
202 bool A2DP_VendorInitCodecConfig(btav_a2dp_codec_index_t codec_index,
203                                 AvdtpSepConfig* p_cfg);
204 
205 // Decodes A2DP vendor codec info into a human readable string.
206 // |p_codec_info| is a pointer to the codec_info to decode.
207 // Returns a string describing the codec information.
208 std::string A2DP_VendorCodecInfoString(const uint8_t* p_codec_info);
209 
210 #endif  // A2DP_VENDOR_H
211