blob: 2d0d8c9e966655c0f11b74a1ee03e82f2f8112e7 [file] [log] [blame]
Josh Wu6ab53e72021-12-29 23:53:33 -08001/*
2 * Copyright (C) 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#define LOG_TAG "BTAudioProviderA2dpHW"
18
19#include "A2dpOffloadAudioProvider.h"
20
21#include <BluetoothAudioCodecs.h>
22#include <BluetoothAudioSessionReport.h>
23#include <android-base/logging.h>
24
25namespace aidl {
26namespace android {
27namespace hardware {
28namespace bluetooth {
29namespace audio {
30
Alice Kuoadcceec2022-03-28 13:28:43 +080031A2dpOffloadEncodingAudioProvider::A2dpOffloadEncodingAudioProvider()
32 : A2dpOffloadAudioProvider() {
Josh Wu6ab53e72021-12-29 23:53:33 -080033 session_type_ = SessionType::A2DP_HARDWARE_OFFLOAD_ENCODING_DATAPATH;
34}
35
Alice Kuoadcceec2022-03-28 13:28:43 +080036A2dpOffloadDecodingAudioProvider::A2dpOffloadDecodingAudioProvider()
37 : A2dpOffloadAudioProvider() {
38 session_type_ = SessionType::A2DP_HARDWARE_OFFLOAD_DECODING_DATAPATH;
39}
40
41A2dpOffloadAudioProvider::A2dpOffloadAudioProvider() {}
42
Josh Wu6ab53e72021-12-29 23:53:33 -080043bool A2dpOffloadAudioProvider::isValid(const SessionType& session_type) {
44 return (session_type == session_type_);
45}
46
47ndk::ScopedAStatus A2dpOffloadAudioProvider::startSession(
48 const std::shared_ptr<IBluetoothAudioPort>& host_if,
Chen Chenc92270e2022-02-14 18:29:52 -080049 const AudioConfiguration& audio_config,
Cheney Ni6ecbc762022-03-03 00:12:48 +080050 const std::vector<LatencyMode>& latency_modes, DataMQDesc* _aidl_return) {
Josh Wu6ab53e72021-12-29 23:53:33 -080051 if (audio_config.getTag() != AudioConfiguration::a2dpConfig) {
52 LOG(WARNING) << __func__ << " - Invalid Audio Configuration="
53 << audio_config.toString();
54 *_aidl_return = DataMQDesc();
55 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
56 }
57 if (!BluetoothAudioCodecs::IsOffloadCodecConfigurationValid(
58 session_type_, audio_config.get<AudioConfiguration::a2dpConfig>())) {
59 LOG(WARNING) << __func__ << " - Invalid Audio Configuration="
60 << audio_config.toString();
61 *_aidl_return = DataMQDesc();
62 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
63 }
Chen Chenc92270e2022-02-14 18:29:52 -080064 return BluetoothAudioProvider::startSession(
65 host_if, audio_config, latency_modes, _aidl_return);
Josh Wu6ab53e72021-12-29 23:53:33 -080066}
67
68ndk::ScopedAStatus A2dpOffloadAudioProvider::onSessionReady(
69 DataMQDesc* _aidl_return) {
70 *_aidl_return = DataMQDesc();
Cheney Ni6ecbc762022-03-03 00:12:48 +080071 BluetoothAudioSessionReport::OnSessionStarted(
72 session_type_, stack_iface_, nullptr, *audio_config_, latency_modes_);
Josh Wu6ab53e72021-12-29 23:53:33 -080073 return ndk::ScopedAStatus::ok();
74}
75
76} // namespace audio
77} // namespace bluetooth
78} // namespace hardware
79} // namespace android
Cheney Ni6ecbc762022-03-03 00:12:48 +080080} // namespace aidl