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