• 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 aptX-HD
19 //
20 
21 #ifndef A2DP_VENDOR_APTX_HD_H
22 #define A2DP_VENDOR_APTX_HD_H
23 
24 #include <stddef.h>
25 #include <stdint.h>
26 
27 #include "a2dp_codec_api.h"
28 #include "a2dp_vendor_aptx_hd_constants.h"
29 #include "avdt_api.h"
30 #include "internal_include/bt_target.h"
31 #include "stack/include/bt_hdr.h"
32 
33 class A2dpCodecConfigAptxHd : public A2dpCodecConfig {
34 public:
35   A2dpCodecConfigAptxHd(btav_a2dp_codec_priority_t codec_priority);
36   virtual ~A2dpCodecConfigAptxHd();
37 
38   bool init() override;
39   tA2DP_STATUS setCodecConfig(const uint8_t* p_peer_codec_info, bool is_capability,
40                               uint8_t* p_result_codec_config) override;
41   bool setPeerCodecCapabilities(const uint8_t* p_peer_codec_capabilities) override;
42 
43 private:
44   bool useRtpHeaderMarkerBit() const override;
45   void debug_codec_dump(int fd) override;
46 };
47 
48 // Checks whether the codec capabilities contain a valid A2DP aptX-HD Source
49 // codec.
50 // NOTE: only codecs that are implemented are considered valid.
51 // Returns true if |p_codec_info| contains information about a valid aptX-HD
52 // codec, otherwise false.
53 bool A2DP_IsCodecValidAptxHd(const uint8_t* p_codec_info);
54 
55 // Checks whether the codec capabilities contain a valid peer A2DP aptX-HD Sink
56 // codec.
57 // NOTE: only codecs that are implemented are considered valid.
58 // Returns true if |p_codec_info| contains information about a valid aptX-HD
59 // codec, otherwise false.
60 bool A2DP_IsVendorPeerSinkCodecValidAptxHd(const uint8_t* p_codec_info);
61 
62 // Checks whether the A2DP data packets should contain RTP header.
63 // |content_protection_enabled| is true if Content Protection is
64 // enabled. |p_codec_info| contains information about the codec capabilities.
65 // Returns true if the A2DP data packets should contain RTP header, otherwise
66 // false.
67 bool A2DP_VendorUsesRtpHeaderAptxHd(bool content_protection_enabled, const uint8_t* p_codec_info);
68 
69 // Gets the A2DP aptX-HD codec name for a given |p_codec_info|.
70 const char* A2DP_VendorCodecNameAptxHd(const uint8_t* p_codec_info);
71 
72 // Checks whether two A2DP aptX-HD codecs |p_codec_info_a| and |p_codec_info_b|
73 // have the same type.
74 // Returns true if the two codecs have the same type, otherwise false.
75 bool A2DP_VendorCodecTypeEqualsAptxHd(const uint8_t* p_codec_info_a, const uint8_t* p_codec_info_b);
76 
77 // Checks whether two A2DP aptX-HD codecs |p_codec_info_a| and |p_codec_info_b|
78 // are exactly the same.
79 // Returns true if the two codecs are exactly the same, otherwise false.
80 // If the codec type is not aptX-HD, the return value is false.
81 bool A2DP_VendorCodecEqualsAptxHd(const uint8_t* p_codec_info_a, const uint8_t* p_codec_info_b);
82 
83 // Gets the track sample rate value for the A2DP aptX-HD codec.
84 // |p_codec_info| is a pointer to the aptX-HD codec_info to decode.
85 // Returns the track sample rate on success, or -1 if |p_codec_info|
86 // contains invalid codec information.
87 int A2DP_VendorGetTrackSampleRateAptxHd(const uint8_t* p_codec_info);
88 
89 // Gets the track bits per sample value for the A2DP aptX-HD codec.
90 // |p_codec_info| is a pointer to the aptX-HD codec_info to decode.
91 // Returns the track bits per sample on success, or -1 if |p_codec_info|
92 // contains invalid codec information.
93 int A2DP_VendorGetTrackBitsPerSampleAptxHd(const uint8_t* p_codec_info);
94 
95 // Gets the track bitrate value for the A2DP aptX-HD codec.
96 // |p_codec_info| is a pointer to the aptX-HD codec_info to decode.
97 // Returns the track sample rate on success, or -1 if |p_codec_info|
98 // contains invalid codec information.
99 int A2DP_VendorGetBitRateAptxHd(const uint8_t* p_codec_info);
100 
101 // Gets the channel count for the A2DP aptX-HD codec.
102 // |p_codec_info| is a pointer to the aptX-HD codec_info to decode.
103 // Returns the channel count on success, or -1 if |p_codec_info|
104 // contains invalid codec information.
105 int A2DP_VendorGetTrackChannelCountAptxHd(const uint8_t* p_codec_info);
106 
107 // Gets the A2DP aptX-HD audio data timestamp from an audio packet.
108 // |p_codec_info| contains the codec information.
109 // |p_data| contains the audio data.
110 // The timestamp is stored in |p_timestamp|.
111 // Returns true on success, otherwise false.
112 bool A2DP_VendorGetPacketTimestampAptxHd(const uint8_t* p_codec_info, const uint8_t* p_data,
113                                          uint32_t* p_timestamp);
114 
115 // Builds A2DP aptX-HD codec header for audio data.
116 // |p_codec_info| contains the codec information.
117 // |p_buf| contains the audio data.
118 // |frames_per_packet| is the number of frames in this packet.
119 // Returns true on success, otherwise false.
120 bool A2DP_VendorBuildCodecHeaderAptxHd(const uint8_t* p_codec_info, BT_HDR* p_buf,
121                                        uint16_t frames_per_packet);
122 
123 // Decodes A2DP aptX-HD codec info into a human readable string.
124 // |p_codec_info| is a pointer to the aptX-HD codec_info to decode.
125 // Returns a string describing the codec information.
126 std::string A2DP_VendorCodecInfoStringAptxHd(const uint8_t* p_codec_info);
127 
128 // Gets the A2DP aptX-HD encoder interface that can be used to encode and
129 // prepare A2DP packets for transmission - see |tA2DP_ENCODER_INTERFACE|.
130 // |p_codec_info| contains the codec information.
131 // Returns the A2DP aptX-HD encoder interface if the |p_codec_info| is valid
132 // and supported, otherwise NULL.
133 const tA2DP_ENCODER_INTERFACE* A2DP_VendorGetEncoderInterfaceAptxHd(const uint8_t* p_codec_info);
134 
135 // Adjusts the A2DP aptX-HD codec, based on local support and Bluetooth
136 // specification.
137 // |p_codec_info| contains the codec information to adjust.
138 // Returns true if |p_codec_info| is valid and supported, otherwise false.
139 bool A2DP_VendorAdjustCodecAptxHd(uint8_t* p_codec_info);
140 
141 // Gets the A2DP aptX-HD Source codec index for a given |p_codec_info|.
142 // Returns the corresponding |btav_a2dp_codec_index_t| on success,
143 // otherwise |BTAV_A2DP_CODEC_INDEX_MAX|.
144 btav_a2dp_codec_index_t A2DP_VendorSourceCodecIndexAptxHd(const uint8_t* p_codec_info);
145 
146 // Gets the A2DP aptX-HD Source codec name.
147 const char* A2DP_VendorCodecIndexStrAptxHd(void);
148 
149 // Initializes A2DP aptX-HD Source codec information into |AvdtpSepConfig|
150 // configuration entry pointed by |p_cfg|.
151 bool A2DP_VendorInitCodecConfigAptxHd(AvdtpSepConfig* p_cfg);
152 
153 #endif  // A2DP_VENDOR_APTX_HD_H
154