blob: 4b4713d0361d1024493e02dcb664c6e5ee68a4e1 [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
31A2dpOffloadAudioProvider::A2dpOffloadAudioProvider() {
32 session_type_ = SessionType::A2DP_HARDWARE_OFFLOAD_ENCODING_DATAPATH;
33}
34
35bool A2dpOffloadAudioProvider::isValid(const SessionType& session_type) {
36 return (session_type == session_type_);
37}
38
39ndk::ScopedAStatus A2dpOffloadAudioProvider::startSession(
40 const std::shared_ptr<IBluetoothAudioPort>& host_if,
Chen Chenc92270e2022-02-14 18:29:52 -080041 const AudioConfiguration& audio_config,
Cheney Ni6ecbc762022-03-03 00:12:48 +080042 const std::vector<LatencyMode>& latency_modes, DataMQDesc* _aidl_return) {
Josh Wu6ab53e72021-12-29 23:53:33 -080043 if (audio_config.getTag() != AudioConfiguration::a2dpConfig) {
44 LOG(WARNING) << __func__ << " - Invalid Audio Configuration="
45 << audio_config.toString();
46 *_aidl_return = DataMQDesc();
47 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
48 }
49 if (!BluetoothAudioCodecs::IsOffloadCodecConfigurationValid(
50 session_type_, audio_config.get<AudioConfiguration::a2dpConfig>())) {
51 LOG(WARNING) << __func__ << " - Invalid Audio Configuration="
52 << audio_config.toString();
53 *_aidl_return = DataMQDesc();
54 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
55 }
Chen Chenc92270e2022-02-14 18:29:52 -080056 return BluetoothAudioProvider::startSession(
57 host_if, audio_config, latency_modes, _aidl_return);
Josh Wu6ab53e72021-12-29 23:53:33 -080058}
59
60ndk::ScopedAStatus A2dpOffloadAudioProvider::onSessionReady(
61 DataMQDesc* _aidl_return) {
62 *_aidl_return = DataMQDesc();
Cheney Ni6ecbc762022-03-03 00:12:48 +080063 BluetoothAudioSessionReport::OnSessionStarted(
64 session_type_, stack_iface_, nullptr, *audio_config_, latency_modes_);
Josh Wu6ab53e72021-12-29 23:53:33 -080065 return ndk::ScopedAStatus::ok();
66}
67
68} // namespace audio
69} // namespace bluetooth
70} // namespace hardware
71} // namespace android
Cheney Ni6ecbc762022-03-03 00:12:48 +080072} // namespace aidl