blob: 866776e7bf68d1e74d4ad307cf1cd1eaceb6e968 [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,
42 const std::vector<LatencyMode>& latency_modes,
43 DataMQDesc* _aidl_return) {
44 latency_modes_ = latency_modes;
Josh Wu6ab53e72021-12-29 23:53:33 -080045 if (audio_config.getTag() != AudioConfiguration::a2dpConfig) {
46 LOG(WARNING) << __func__ << " - Invalid Audio Configuration="
47 << audio_config.toString();
48 *_aidl_return = DataMQDesc();
49 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
50 }
51 if (!BluetoothAudioCodecs::IsOffloadCodecConfigurationValid(
52 session_type_, audio_config.get<AudioConfiguration::a2dpConfig>())) {
53 LOG(WARNING) << __func__ << " - Invalid Audio Configuration="
54 << audio_config.toString();
55 *_aidl_return = DataMQDesc();
56 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
57 }
Chen Chenc92270e2022-02-14 18:29:52 -080058 return BluetoothAudioProvider::startSession(
59 host_if, audio_config, latency_modes, _aidl_return);
Josh Wu6ab53e72021-12-29 23:53:33 -080060}
61
62ndk::ScopedAStatus A2dpOffloadAudioProvider::onSessionReady(
63 DataMQDesc* _aidl_return) {
64 *_aidl_return = DataMQDesc();
65 BluetoothAudioSessionReport::OnSessionStarted(session_type_, stack_iface_,
66 nullptr, *audio_config_);
67 return ndk::ScopedAStatus::ok();
68}
69
70} // namespace audio
71} // namespace bluetooth
72} // namespace hardware
73} // namespace android
74} // namespace aidl