1 /* 2 * Copyright 2022 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_encoding.h" 22 #include "a2dp_sbc_constants.h" 23 #include "audio_a2dp_hw/include/audio_a2dp_hw.h" 24 #include "btif/include/btif_a2dp_source.h" 25 #include "btif/include/btif_av.h" 26 #include "btif/include/btif_av_co.h" 27 #include "btif/include/btif_hf.h" 28 #include "common/message_loop_thread.h" 29 #include "os/log.h" 30 #include "osi/include/properties.h" 31 #include "types/raw_address.h" 32 33 namespace bluetooth { 34 namespace audio { 35 namespace aidl { 36 namespace a2dp { 37 38 bool update_codec_offloading_capabilities( 39 const std::vector<btav_a2dp_codec_config_t>& framework_preference, 40 bool supports_a2dp_hw_offload_v2); 41 42 /*** 43 * Check if new bluetooth_audio is enabled 44 ***/ 45 bool is_hal_enabled(); 46 47 /*** 48 * Check if new bluetooth_audio is running with offloading encoders 49 ***/ 50 bool is_hal_offloading(); 51 52 /*** 53 * Initialize BluetoothAudio HAL: openProvider 54 ***/ 55 bool init(bluetooth::common::MessageLoopThread* message_loop); 56 57 /*** 58 * Clean up BluetoothAudio HAL 59 ***/ 60 void cleanup(); 61 62 /*** 63 * Set up the codec into BluetoothAudio HAL 64 ***/ 65 bool setup_codec(); 66 67 /*** 68 * Send command to the BluetoothAudio HAL: StartSession, EndSession, 69 * StreamStarted, StreamSuspended 70 ***/ 71 void start_session(); 72 void end_session(); 73 void ack_stream_started(const tA2DP_CTRL_ACK& status); 74 void ack_stream_suspended(const tA2DP_CTRL_ACK& status); 75 76 /*** 77 * Read from the FMQ of BluetoothAudio HAL 78 ***/ 79 size_t read(uint8_t* p_buf, uint32_t len); 80 81 /*** 82 * Update A2DP delay report to BluetoothAudio HAL 83 ***/ 84 void set_remote_delay(uint16_t delay_report); 85 86 /*** 87 * Set low latency buffer mode allowed or disallowed 88 ***/ 89 void set_low_latency_mode_allowed(bool allowed); 90 91 namespace provider { 92 93 /*** 94 * Lookup the codec info in the list of supported offloaded sink codecs. 95 * Should not be called before update_codec_offloading_capabilities. 96 ***/ 97 std::optional<btav_a2dp_codec_index_t> sink_codec_index( 98 const uint8_t* p_codec_info); 99 100 /*** 101 * Lookup the codec info in the list of supported offloaded source codecs. 102 * Should not be called before update_codec_offloading_capabilities. 103 ***/ 104 std::optional<btav_a2dp_codec_index_t> source_codec_index( 105 const uint8_t* p_codec_info); 106 107 /*** 108 * Return the name of the codec which is assigned to the input index. 109 * The codec index must be in the ranges 110 * BTAV_A2DP_CODEC_INDEX_SINK_EXT_MIN..BTAV_A2DP_CODEC_INDEX_SINK_EXT_MAX or 111 * BTAV_A2DP_CODEC_INDEX_SOURCE_EXT_MIN..BTAV_A2DP_CODEC_INDEX_SOURCE_EXT_MAX. 112 * Returns nullopt if the codec_index is not assigned or codec extensibility 113 * is not supported or enabled. 114 * Should not be called before update_codec_offloading_capabilities. 115 ***/ 116 std::optional<const char*> codec_index_str(btav_a2dp_codec_index_t codec_index); 117 118 /*** 119 * Return true if the codec is supported for the session type 120 * A2DP_HARDWARE_ENCODING_DATAPATH or A2DP_HARDWARE_DECODING_DATAPATH. 121 ***/ 122 bool supports_codec(btav_a2dp_codec_index_t codec_index); 123 124 /*** 125 * Return the A2DP capabilities for the selected codec. 126 ***/ 127 bool codec_info(btav_a2dp_codec_index_t codec_index, uint64_t* codec_id, 128 uint8_t* codec_info, btav_a2dp_codec_config_t* codec_config); 129 130 /*** 131 * Query the codec selection fromt the audio HAL. 132 * The HAL is expected to pick the best audio configuration based on the 133 * discovered remote SEPs. 134 ***/ 135 std::optional<::bluetooth::audio::a2dp::provider::a2dp_configuration> 136 get_a2dp_configuration( 137 RawAddress peer_address, 138 std::vector< 139 ::bluetooth::audio::a2dp::provider::a2dp_remote_capabilities> const& 140 remote_seps, 141 btav_a2dp_codec_config_t const& user_preferences); 142 143 /*** 144 * Query the codec parameters from the audio HAL. 145 * The HAL is expected to parse the codec configuration 146 * received from the peer and decide whether accept 147 * the it or not. 148 ***/ 149 tA2DP_STATUS parse_a2dp_configuration( 150 btav_a2dp_codec_index_t codec_index, const uint8_t* codec_info, 151 btav_a2dp_codec_config_t* codec_parameters, 152 std::vector<uint8_t>* vendor_specific_parameters); 153 154 } // namespace provider 155 } // namespace a2dp 156 } // namespace aidl 157 } // namespace audio 158 } // namespace bluetooth 159