1 /**
2  * Copyright 2023 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 #pragma once
18 
19 #include <vector>
20 
21 #include "a2dp_codec_api.h"
22 #include "audio_hal_interface/a2dp_encoding.h"
23 
24 /// Codec configuration for codecs that are supported by a2dp hardware offload
25 /// codec extensibility. The codec index may be a standard codec, in which case
26 /// this class is preferred over the dedicated class, or an unknown codec in
27 /// the reserved ranges for codec extensibility.
28 /// The codec priority is always the lowest, so that software codecs
29 /// can be picked over offloaded codecs.
30 class A2dpCodecConfigExt : public A2dpCodecConfig {
31 public:
32   A2dpCodecConfigExt(btav_a2dp_codec_index_t codec_index, bool is_source);
33 
init()34   bool init() override { return false; }
useRtpHeaderMarkerBit()35   bool useRtpHeaderMarkerBit() const override { return false; }
36   tA2DP_STATUS setCodecConfig(const uint8_t* p_peer_codec_info, bool is_capability,
37                               uint8_t* p_result_codec_config) override;
38   bool setPeerCodecCapabilities(const uint8_t* p_peer_codec_capabilities) override;
39 
getVendorCodecParameters()40   const std::vector<uint8_t>& getVendorCodecParameters() const {
41     return vendor_specific_parameters_;
42   }
43 
setVendorSpecificParameters(std::vector<uint8_t> const &)44   void setVendorSpecificParameters(std::vector<uint8_t> const& /* parameters */) {}
45 
setCodecConfig(btav_a2dp_codec_config_t codec_parameters,uint8_t const codec_config[AVDT_CODEC_SIZE],std::vector<uint8_t> const & vendor_specific_parameters)46   void setCodecConfig(btav_a2dp_codec_config_t codec_parameters,
47                       uint8_t const codec_config[AVDT_CODEC_SIZE],
48                       std::vector<uint8_t> const& vendor_specific_parameters) {
49     codec_config_ = codec_parameters;
50     codec_capability_ = codec_parameters;
51     memcpy(ota_codec_config_, codec_config, sizeof(ota_codec_config_));
52     vendor_specific_parameters_ = vendor_specific_parameters;
53   }
54 
55 private:
56   [[maybe_unused]] bool is_source_;  // True if local is Source
57   std::vector<uint8_t> vendor_specific_parameters_;
58 };
59 
60 // Gets a mock A2DP encoder interface.
61 // The A2DP source path always sets up the encoder interface,
62 // whether the codec encoding is offloaded or not.
63 // |p_codec_info| contains the codec information.
64 const tA2DP_ENCODER_INTERFACE* A2DP_GetEncoderInterfaceExt(const uint8_t* p_codec_info);
65