• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 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 // Builds a vendor-specific A2DP preferred Sink capability from a vendor
80 // Source capability.
81 // |p_src_cap| is the Source capability to use.
82 // |p_pref_cfg| is the result Sink capability to store.
83 // Returns |A2DP_SUCCESS| on success, otherwise the corresponding A2DP error
84 // status code.
85 tA2DP_STATUS A2DP_VendorBuildSrc2SinkConfig(const uint8_t* p_src_cap,
86                                             uint8_t* p_pref_cfg);
87 
88 // Gets the Vendor ID for the vendor-specific A2DP codec.
89 // |p_codec_info| contains information about the codec capabilities.
90 // Returns the Vendor ID for the vendor-specific A2DP codec.
91 uint32_t A2DP_VendorCodecGetVendorId(const uint8_t* p_codec_info);
92 
93 // Gets the Codec ID for the vendor-specific A2DP codec.
94 // |p_codec_info| contains information about the codec capabilities.
95 // Returns the Codec ID for the vendor-specific A2DP codec.
96 uint16_t A2DP_VendorCodecGetCodecId(const uint8_t* p_codec_info);
97 
98 // Checks whether the A2DP vendor-specific data packets should contain RTP
99 // header. |content_protection_enabled| is true if Content Protection is
100 // enabled. |p_codec_info| contains information about the codec capabilities.
101 // Returns true if the A2DP vendor-specific data packets should contain RTP
102 // header, otherwise false.
103 bool A2DP_VendorUsesRtpHeader(bool content_protection_enabled,
104                               const uint8_t* p_codec_info);
105 
106 // Gets the A2DP vendor-specific codec name for a given |p_codec_info|.
107 const char* A2DP_VendorCodecName(const uint8_t* p_codec_info);
108 
109 // Checks whether two A2DP vendor-specific codecs |p_codec_info_a| and
110 // |p_codec_info_b| have the same type.
111 // Returns true if the two codecs have the same type, otherwise false.
112 // If the codec type is not recognized, the return value is false.
113 bool A2DP_VendorCodecTypeEquals(const uint8_t* p_codec_info_a,
114                                 const uint8_t* p_codec_info_b);
115 
116 // Checks whether two A2DP vendor-specific codecs |p_codec_info_a| and
117 // |p_codec_info_b| are exactly the same.
118 // Returns true if the two codecs are exactly the same, otherwise false.
119 // If the codec type is not recognized, the return value is false.
120 bool A2DP_VendorCodecEquals(const uint8_t* p_codec_info_a,
121                             const uint8_t* p_codec_info_b);
122 
123 // Gets the track sample rate value for the A2DP vendor-specific codec.
124 // |p_codec_info| is a pointer to the vendor-specific codec_info to decode.
125 // Returns the track sample rate on success, or -1 if |p_codec_info|
126 // contains invalid codec information.
127 int A2DP_VendorGetTrackSampleRate(const uint8_t* p_codec_info);
128 
129 // Gets the bits per audio sample for the A2DP vendor-specific codec.
130 // |p_codec_info| is a pointer to the vendor-specific codec_info to decode.
131 // Returns the bits per audio sample on success, or -1 if |p_codec_info|
132 // contains invalid codec information.
133 int A2DP_VendorGetTrackBitsPerSample(const uint8_t* p_codec_info);
134 
135 // Gets the channel count for the A2DP vendor-specific codec.
136 // |p_codec_info| is a pointer to the vendor-specific codec_info to decode.
137 // Returns the channel count on success, or -1 if |p_codec_info|
138 // contains invalid codec information.
139 int A2DP_VendorGetTrackChannelCount(const uint8_t* p_codec_info);
140 
141 // Gets the channel type for the A2DP vendor-specific Sink codec:
142 // 1 for mono, or 3 for dual/stereo/joint.
143 // |p_codec_info| is a pointer to the vendor-specific codec_info to decode.
144 // Returns the channel type on success, or -1 if |p_codec_info|
145 // contains invalid codec information.
146 int A2DP_VendorGetSinkTrackChannelType(const uint8_t* p_codec_info);
147 
148 // Computes the number of frames to process in a time window for the A2DP
149 // vendor-specific Sink codec. |time_interval_ms| is the time interval
150 // (in milliseconds).
151 // |p_codec_info| is a pointer to the codec_info to decode.
152 // Returns the number of frames to process on success, or -1 if |p_codec_info|
153 // contains invalid codec information.
154 int A2DP_VendorGetSinkFramesCountToProcess(uint64_t time_interval_ms,
155                                            const uint8_t* p_codec_info);
156 
157 // Gets the A2DP codec-specific audio data timestamp from an audio packet.
158 // |p_codec_info| contains the codec information.
159 // |p_data| contains the audio data.
160 // The timestamp is stored in |p_timestamp|.
161 // Returns true on success, otherwise false.
162 bool A2DP_VendorGetPacketTimestamp(const uint8_t* p_codec_info,
163                                    const uint8_t* p_data,
164                                    uint32_t* p_timestamp);
165 
166 // Builds A2DP vendor-specific codec header for audio data.
167 // |p_codec_info| contains the codec information.
168 // |p_buf| contains the audio data.
169 // |frames_per_packet| is the number of frames in this packet.
170 // Returns true on success, otherwise false.
171 bool A2DP_VendorBuildCodecHeader(const uint8_t* p_codec_info, BT_HDR* p_buf,
172                                  uint16_t frames_per_packet);
173 
174 // Gets the A2DP vendor encoder interface that can be used to encode and
175 // prepare A2DP packets for transmission - see |tA2DP_ENCODER_INTERFACE|.
176 // |p_codec_info| contains the codec information.
177 // Returns the A2DP vendor encoder interface if the |p_codec_info| is valid and
178 // supported, otherwise NULL.
179 const tA2DP_ENCODER_INTERFACE* A2DP_VendorGetEncoderInterface(
180     const uint8_t* p_codec_info);
181 
182 // Adjusts the A2DP vendor-specific codec, based on local support and Bluetooth
183 // specification.
184 // |p_codec_info| contains the codec information to adjust.
185 // Returns true if |p_codec_info| is valid and supported, otherwise false.
186 bool A2DP_VendorAdjustCodec(uint8_t* p_codec_info);
187 
188 // Gets the A2DP vendor Source codec index for a given |p_codec_info|.
189 // Returns the corresponding |btav_a2dp_codec_index_t| on success,
190 // otherwise |BTAV_A2DP_CODEC_INDEX_MAX|.
191 btav_a2dp_codec_index_t A2DP_VendorSourceCodecIndex(
192     const uint8_t* p_codec_info);
193 
194 // Gets the A2DP vendor codec name for a given |codec_index|.
195 const char* A2DP_VendorCodecIndexStr(btav_a2dp_codec_index_t codec_index);
196 
197 // Initializes A2DP vendor codec-specific information into |tAVDT_CFG|
198 // configuration entry pointed by |p_cfg|. The selected codec is defined by
199 // |codec_index|.
200 // Returns true on success, otherwise false.
201 bool A2DP_VendorInitCodecConfig(btav_a2dp_codec_index_t codec_index,
202                                 tAVDT_CFG* p_cfg);
203 
204 #endif  // A2DP_VENDOR_H
205