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 #include "hearing_aid_software_encoding.h"
18
19 #include "aidl/hearing_aid_software_encoding_aidl.h"
20 #include "hal_version_manager.h"
21 #include "hidl/hearing_aid_software_encoding_hidl.h"
22
23 namespace bluetooth {
24 namespace audio {
25 namespace hearing_aid {
26
27 // Check if new bluetooth_audio is enabled
is_hal_enabled()28 bool is_hal_enabled() {
29 if (HalVersionManager::GetHalTransport() ==
30 BluetoothAudioHalTransport::HIDL) {
31 return hidl::hearing_aid::is_hal_2_0_enabled();
32 }
33 return aidl::hearing_aid::is_hal_enabled();
34 }
35
36 // Initialize BluetoothAudio HAL: openProvider
init(StreamCallbacks stream_cb,bluetooth::common::MessageLoopThread * message_loop)37 bool init(StreamCallbacks stream_cb,
38 bluetooth::common::MessageLoopThread* message_loop) {
39 if (HalVersionManager::GetHalTransport() ==
40 BluetoothAudioHalTransport::HIDL) {
41 return hidl::hearing_aid::init(stream_cb, message_loop);
42 }
43 return aidl::hearing_aid::init(stream_cb, message_loop);
44 }
45
46 // Clean up BluetoothAudio HAL
cleanup()47 void cleanup() {
48 if (HalVersionManager::GetHalTransport() ==
49 BluetoothAudioHalTransport::HIDL) {
50 hidl::hearing_aid::cleanup();
51 return;
52 }
53 aidl::hearing_aid::cleanup();
54 }
55
56 // Send command to the BluetoothAudio HAL: StartSession, EndSession
start_session()57 void start_session() {
58 if (HalVersionManager::GetHalTransport() ==
59 BluetoothAudioHalTransport::HIDL) {
60 hidl::hearing_aid::start_session();
61 return;
62 }
63 aidl::hearing_aid::start_session();
64 }
65
end_session()66 void end_session() {
67 if (HalVersionManager::GetHalTransport() ==
68 BluetoothAudioHalTransport::HIDL) {
69 hidl::hearing_aid::end_session();
70 return;
71 }
72 aidl::hearing_aid::end_session();
73 }
74
set_remote_delay(uint16_t delay_report_ms)75 void set_remote_delay(uint16_t delay_report_ms) {
76 if (HalVersionManager::GetHalTransport() ==
77 BluetoothAudioHalTransport::HIDL) {
78 hidl::hearing_aid::set_remote_delay(delay_report_ms);
79 return;
80 }
81 aidl::hearing_aid::set_remote_delay(delay_report_ms);
82 }
83
84 // Read from the FMQ of BluetoothAudio HAL
read(uint8_t * p_buf,uint32_t len)85 size_t read(uint8_t* p_buf, uint32_t len) {
86 if (HalVersionManager::GetHalTransport() ==
87 BluetoothAudioHalTransport::HIDL) {
88 return hidl::hearing_aid::read(p_buf, len);
89 }
90 return aidl::hearing_aid::read(p_buf, len);
91 }
92
93 } // namespace hearing_aid
94 } // namespace audio
95 } // namespace bluetooth
96