• 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 // A2DP Codec API for AAC
19 //
20 
21 #ifndef A2DP_AAC_H
22 #define A2DP_AAC_H
23 
24 #include <bt_target.h>
25 #include <stddef.h>
26 #include <stdint.h>
27 
28 #include "a2dp_aac_constants.h"
29 #include "a2dp_codec_api.h"
30 #include "avdt_api.h"
31 #include "stack/include/bt_hdr.h"
32 
33 class A2dpCodecConfigAacBase : public A2dpCodecConfig {
34  protected:
A2dpCodecConfigAacBase(btav_a2dp_codec_index_t codec_index,const std::string & name,btav_a2dp_codec_priority_t codec_priority,bool is_source)35   A2dpCodecConfigAacBase(btav_a2dp_codec_index_t codec_index,
36                          const std::string& name,
37                          btav_a2dp_codec_priority_t codec_priority,
38                          bool is_source)
39       : A2dpCodecConfig(codec_index, name, codec_priority),
40         is_source_(is_source) {}
41   bool setCodecConfig(const uint8_t* p_peer_codec_info, bool is_capability,
42                       uint8_t* p_result_codec_config) override;
43   bool setPeerCodecCapabilities(
44       const uint8_t* p_peer_codec_capabilities) override;
45 
46  private:
47   bool is_source_;  // True if local is Source
48 };
49 
50 class A2dpCodecConfigAacSource : public A2dpCodecConfigAacBase {
51  public:
52   A2dpCodecConfigAacSource(btav_a2dp_codec_priority_t codec_priority);
53   virtual ~A2dpCodecConfigAacSource();
54 
55   bool init() override;
56 
57  private:
58   bool useRtpHeaderMarkerBit() const override;
59   void debug_codec_dump(int fd) override;
60 };
61 
62 class A2dpCodecConfigAacSink : public A2dpCodecConfigAacBase {
63  public:
64   A2dpCodecConfigAacSink(btav_a2dp_codec_priority_t codec_priority);
65   virtual ~A2dpCodecConfigAacSink();
66 
67   bool init() override;
68 
69  private:
70   bool useRtpHeaderMarkerBit() const override;
71 };
72 
73 // Checks whether the codec capabilities contain a valid A2DP AAC Source
74 // codec.
75 // NOTE: only codecs that are implemented are considered valid.
76 // Returns true if |p_codec_info| contains information about a valid AAC
77 // codec, otherwise false.
78 bool A2DP_IsSourceCodecValidAac(const uint8_t* p_codec_info);
79 
80 // Checks whether the codec capabilities contain a valid A2DP AAC Sink codec.
81 // NOTE: only codecs that are implemented are considered valid.
82 // Returns true if |p_codec_info| contains information about a valid AAC codec,
83 // otherwise false.
84 bool A2DP_IsSinkCodecValidAac(const uint8_t* p_codec_info);
85 
86 // Checks whether the codec capabilities contain a valid peer A2DP AAC Source
87 // codec.
88 // NOTE: only codecs that are implemented are considered valid.
89 // Returns true if |p_codec_info| contains information about a valid AAC codec,
90 // otherwise false.
91 bool A2DP_IsPeerSourceCodecValidAac(const uint8_t* p_codec_info);
92 
93 // Checks whether the codec capabilities contain a valid peer A2DP AAC Sink
94 // codec.
95 // NOTE: only codecs that are implemented are considered valid.
96 // Returns true if |p_codec_info| contains information about a valid AAC
97 // codec, otherwise false.
98 bool A2DP_IsPeerSinkCodecValidAac(const uint8_t* p_codec_info);
99 
100 // Checks whether A2DP AAC Sink codec is supported.
101 // |p_codec_info| contains information about the codec capabilities.
102 // Returns true if the A2DP AAC Sink codec is supported, otherwise false.
103 bool A2DP_IsSinkCodecSupportedAac(const uint8_t* p_codec_info);
104 
105 // Checks whether an A2DP AAC Source codec for a peer Source device is
106 // supported.
107 // |p_codec_info| contains information about the codec capabilities of the
108 // peer device.
109 // Returns true if the A2DP AAC Source codec for a peer Source device is
110 // supported, otherwise false.
111 bool A2DP_IsPeerSourceCodecSupportedAac(const uint8_t* p_codec_info);
112 
113 // Checks whether the A2DP data packets should contain RTP header.
114 // |content_protection_enabled| is true if Content Protection is
115 // enabled. |p_codec_info| contains information about the codec capabilities.
116 // Returns true if the A2DP data packets should contain RTP header, otherwise
117 // false.
118 bool A2DP_UsesRtpHeaderAac(bool content_protection_enabled,
119                            const uint8_t* p_codec_info);
120 
121 // Gets the A2DP AAC codec name for a given |p_codec_info|.
122 const char* A2DP_CodecNameAac(const uint8_t* p_codec_info);
123 
124 // Checks whether two A2DP AAC codecs |p_codec_info_a| and |p_codec_info_b|
125 // have the same type.
126 // Returns true if the two codecs have the same type, otherwise false.
127 bool A2DP_CodecTypeEqualsAac(const uint8_t* p_codec_info_a,
128                              const uint8_t* p_codec_info_b);
129 
130 // Checks whether two A2DP AAC codecs |p_codec_info_a| and |p_codec_info_b|
131 // are exactly the same.
132 // Returns true if the two codecs are exactly the same, otherwise false.
133 // If the codec type is not AAC, the return value is false.
134 bool A2DP_CodecEqualsAac(const uint8_t* p_codec_info_a,
135                          const uint8_t* p_codec_info_b);
136 
137 // Gets the track sample rate value for the A2DP AAC codec.
138 // |p_codec_info| is a pointer to the AAC codec_info to decode.
139 // Returns the track sample rate on success, or -1 if |p_codec_info|
140 // contains invalid codec information.
141 int A2DP_GetTrackSampleRateAac(const uint8_t* p_codec_info);
142 
143 // Gets the track bits per sample value for the A2DP AAC codec.
144 // |p_codec_info| is a pointer to the AAC codec_info to decode.
145 // Returns the track bits per sample on success, or -1 if |p_codec_info|
146 // contains invalid codec information.
147 int A2DP_GetTrackBitsPerSampleAac(const uint8_t* p_codec_info);
148 
149 // Gets the channel count for the A2DP AAC codec.
150 // |p_codec_info| is a pointer to the AAC codec_info to decode.
151 // Returns the channel count on success, or -1 if |p_codec_info|
152 // contains invalid codec information.
153 int A2DP_GetTrackChannelCountAac(const uint8_t* p_codec_info);
154 
155 // Gets the channel type for the A2DP AAC Sink codec:
156 // 1 for mono, or 3 for dual/stereo/joint.
157 // |p_codec_info| is a pointer to the AAC codec_info to decode.
158 // Returns the channel type on success, or -1 if |p_codec_info|
159 // contains invalid codec information.
160 int A2DP_GetSinkTrackChannelTypeAac(const uint8_t* p_codec_info);
161 
162 // Gets the object type code for the A2DP AAC codec.
163 // The actual value is codec-specific - see |A2DP_AAC_OBJECT_TYPE_*|.
164 // |p_codec_info| is a pointer to the AAC codec_info to decode.
165 // Returns the object type code on success, or -1 if |p_codec_info|
166 // contains invalid codec information.
167 int A2DP_GetObjectTypeCodeAac(const uint8_t* p_codec_info);
168 
169 // Gets the channel mode code for the A2DP AAC codec.
170 // The actual value is codec-specific - see |A2DP_AAC_CHANNEL_MODE_*|.
171 // |p_codec_info| is a pointer to the AAC codec_info to decode.
172 // Returns the channel mode code on success, or -1 if |p_codec_info|
173 // contains invalid codec information.
174 int A2DP_GetChannelModeCodeAac(const uint8_t* p_codec_info);
175 
176 // Gets the variable bit rate support for the A2DP AAC codec.
177 // The actual value is codec-specific - see |A2DP_AAC_VARIABLE_BIT_RATE_*|.
178 // |p_codec_info| is a pointer to the AAC codec_info to decode.
179 // Returns the variable bit rate support on success, or -1 if |p_codec_info|
180 // contains invalid codec information.
181 int A2DP_GetVariableBitRateSupportAac(const uint8_t* p_codec_info);
182 
183 // Gets the bit rate for the A2DP AAC codec.
184 // The actual value is codec-specific - for AAC it is in bits per second.
185 // |p_codec_info| is a pointer to the AAC codec_info to decode.
186 // Returns the bit rate on success, or -1 if |p_codec_info|
187 // contains invalid codec information.
188 int A2DP_GetBitRateAac(const uint8_t* p_codec_info);
189 
190 // Computes the maximum bit rate for the A2DP AAC codec based on the MTU.
191 // The actual value is codec-specific - for AAC it is in bits per second.
192 // |p_codec_info| is a pointer to the AAC codec_info to decode.
193 // |mtu| is the MTU to use for the computation.
194 // Returns the maximum bit rate on success, or -1 if |p_codec_info|
195 // contains invalid codec information.
196 int A2DP_ComputeMaxBitRateAac(const uint8_t* p_codec_info, uint16_t mtu);
197 
198 // Gets the A2DP AAC audio data timestamp from an audio packet.
199 // |p_codec_info| contains the codec information.
200 // |p_data| contains the audio data.
201 // The timestamp is stored in |p_timestamp|.
202 // Returns true on success, otherwise false.
203 bool A2DP_GetPacketTimestampAac(const uint8_t* p_codec_info,
204                                 const uint8_t* p_data, uint32_t* p_timestamp);
205 
206 // Builds A2DP AAC codec header for audio data.
207 // |p_codec_info| contains the codec information.
208 // |p_buf| contains the audio data.
209 // |frames_per_packet| is the number of frames in this packet.
210 // Returns true on success, otherwise false.
211 bool A2DP_BuildCodecHeaderAac(const uint8_t* p_codec_info, BT_HDR* p_buf,
212                               uint16_t frames_per_packet);
213 
214 // Decodes A2DP AAC codec info into a human readable string.
215 // |p_codec_info| is a pointer to the AAC codec_info to decode.
216 // Returns a string describing the codec information.
217 std::string A2DP_CodecInfoStringAac(const uint8_t* p_codec_info);
218 
219 // Gets the A2DP AAC encoder interface that can be used to encode and prepare
220 // A2DP packets for transmission - see |tA2DP_ENCODER_INTERFACE|.
221 // |p_codec_info| contains the codec information.
222 // Returns the A2DP AAC encoder interface if the |p_codec_info| is valid and
223 // supported, otherwise NULL.
224 const tA2DP_ENCODER_INTERFACE* A2DP_GetEncoderInterfaceAac(
225     const uint8_t* p_codec_info);
226 
227 // Gets the current A2DP AAC decoder interface that can be used to decode
228 // received A2DP packets - see |tA2DP_DECODER_INTERFACE|.
229 // |p_codec_info| contains the codec information.
230 // Returns the A2DP AAC decoder interface if the |p_codec_info| is valid and
231 // supported, otherwise NULL.
232 const tA2DP_DECODER_INTERFACE* A2DP_GetDecoderInterfaceAac(
233     const uint8_t* p_codec_info);
234 
235 // Adjusts the A2DP AAC codec, based on local support and Bluetooth
236 // specification.
237 // |p_codec_info| contains the codec information to adjust.
238 // Returns true if |p_codec_info| is valid and supported, otherwise false.
239 bool A2DP_AdjustCodecAac(uint8_t* p_codec_info);
240 
241 // Gets the A2DP AAC Source codec index for a given |p_codec_info|.
242 // Returns the corresponding |btav_a2dp_codec_index_t| on success,
243 // otherwise |BTAV_A2DP_CODEC_INDEX_MAX|.
244 btav_a2dp_codec_index_t A2DP_SourceCodecIndexAac(const uint8_t* p_codec_info);
245 
246 // Gets the A2DP AAC Sink codec index for a given |p_codec_info|.
247 // Returns the corresponding |btav_a2dp_codec_index_t| on success,
248 // otherwise |BTAV_A2DP_CODEC_INDEX_MAX|.
249 btav_a2dp_codec_index_t A2DP_SinkCodecIndexAac(const uint8_t* p_codec_info);
250 
251 // Gets the A2DP AAC Source codec name.
252 const char* A2DP_CodecIndexStrAac(void);
253 
254 // Gets the A2DP AAC Sink codec name.
255 const char* A2DP_CodecIndexStrAacSink(void);
256 
257 // Initializes A2DP AAC Source codec information into |AvdtpSepConfig|
258 // configuration entry pointed by |p_cfg|.
259 bool A2DP_InitCodecConfigAac(AvdtpSepConfig* p_cfg);
260 
261 // Initializes A2DP AAC Sink codec information into |AvdtpSepConfig|
262 // configuration entry pointed by |p_cfg|.
263 bool A2DP_InitCodecConfigAacSink(AvdtpSepConfig* p_cfg);
264 
265 #endif  // A2DP_AAC_H
266