blob: 866eaebad67c502fd4bd5ca8f8a5229125c5155f [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#pragma once
17
18#include <aidl/android/hardware/bluetooth/audio/BnBluetoothAudioProvider.h>
Chen Chenc92270e2022-02-14 18:29:52 -080019#include <aidl/android/hardware/bluetooth/audio/LatencyMode.h>
Josh Wu6ab53e72021-12-29 23:53:33 -080020#include <aidl/android/hardware/bluetooth/audio/SessionType.h>
21#include <fmq/AidlMessageQueue.h>
22
23using ::aidl::android::hardware::common::fmq::MQDescriptor;
24using ::aidl::android::hardware::common::fmq::SynchronizedReadWrite;
25using ::android::AidlMessageQueue;
26
27using MqDataType = int8_t;
28using MqDataMode = SynchronizedReadWrite;
29using DataMQ = AidlMessageQueue<MqDataType, MqDataMode>;
30using DataMQDesc = MQDescriptor<MqDataType, MqDataMode>;
31
32namespace aidl {
33namespace android {
34namespace hardware {
35namespace bluetooth {
36namespace audio {
37
Henri Chataing7f9c47a2024-02-09 18:20:50 +000038/// Enable flag for the reference implementation for A2dp Codec
39/// Extensibility.
40///
41/// A2dp Codec extensibility cannot be enabled until the following
42/// requirements are fulfilled.
43///
44/// 1. The Bluetooth controller must support the HCI Requirements
45/// v1.04 or later, and must support the vendor HCI command
46/// A2DP Offload Start (v2), A2DP Offload Stop (v2) as indicated
47/// by the field a2dp_offload_v2 of the vendor capabilities.
48///
49/// 2. The implementation of the provider must be completed with
50/// DSP configuration for streaming.
51enum : bool {
52 kEnableA2dpCodecExtensibility = false,
53};
54
Josh Wu6ab53e72021-12-29 23:53:33 -080055class BluetoothAudioProvider : public BnBluetoothAudioProvider {
56 public:
57 BluetoothAudioProvider();
Josh Wu6ab53e72021-12-29 23:53:33 -080058 ndk::ScopedAStatus startSession(
59 const std::shared_ptr<IBluetoothAudioPort>& host_if,
Chen Chenc92270e2022-02-14 18:29:52 -080060 const AudioConfiguration& audio_config,
Bao Do6aeb5d72023-12-11 10:53:18 +000061 const std::vector<LatencyMode>& latency_modes, DataMQDesc* _aidl_return);
Josh Wu6ab53e72021-12-29 23:53:33 -080062 ndk::ScopedAStatus endSession();
63 ndk::ScopedAStatus streamStarted(BluetoothAudioStatus status);
64 ndk::ScopedAStatus streamSuspended(BluetoothAudioStatus status);
65 ndk::ScopedAStatus updateAudioConfiguration(
66 const AudioConfiguration& audio_config);
Chen Chen7cdf8322022-02-08 13:24:11 -080067 ndk::ScopedAStatus setLowLatencyModeAllowed(bool allowed);
Jakub Tyszkowskiccceb2f2023-11-10 09:55:22 +000068 ndk::ScopedAStatus setCodecPriority(
69 const ::aidl::android::hardware::bluetooth::audio::CodecId& in_codecId,
70 int32_t in_priority) override;
71 ndk::ScopedAStatus getLeAudioAseConfiguration(
72 const std::optional<std::vector<std::optional<
73 ::aidl::android::hardware::bluetooth::audio::IBluetoothAudioProvider::
74 LeAudioDeviceCapabilities>>>& in_remoteSinkAudioCapabilities,
75 const std::optional<std::vector<std::optional<
76 ::aidl::android::hardware::bluetooth::audio::IBluetoothAudioProvider::
77 LeAudioDeviceCapabilities>>>& in_remoteSourceAudioCapabilities,
78 const std::vector<
79 ::aidl::android::hardware::bluetooth::audio::IBluetoothAudioProvider::
80 LeAudioConfigurationRequirement>& in_requirements,
81 std::vector<::aidl::android::hardware::bluetooth::audio::
82 IBluetoothAudioProvider::LeAudioAseConfigurationSetting>*
83 _aidl_return) override;
84 ndk::ScopedAStatus getLeAudioAseQosConfiguration(
85 const ::aidl::android::hardware::bluetooth::audio::
86 IBluetoothAudioProvider::LeAudioAseQosConfigurationRequirement&
87 in_qosRequirement,
88 ::aidl::android::hardware::bluetooth::audio::IBluetoothAudioProvider::
89 LeAudioAseQosConfigurationPair* _aidl_return) override;
90 ndk::ScopedAStatus getLeAudioAseDatapathConfiguration(
Jakub Tyszkowski48563082024-01-04 16:02:38 +000091 const std::optional<::aidl::android::hardware::bluetooth::audio::
92 IBluetoothAudioProvider::StreamConfig>&
93 in_sinkConfig,
94 const std::optional<::aidl::android::hardware::bluetooth::audio::
95 IBluetoothAudioProvider::StreamConfig>&
96 in_sourceConfig,
Jakub Tyszkowskiccceb2f2023-11-10 09:55:22 +000097 ::aidl::android::hardware::bluetooth::audio::IBluetoothAudioProvider::
98 LeAudioDataPathConfigurationPair* _aidl_return) override;
99 ndk::ScopedAStatus onSinkAseMetadataChanged(
100 ::aidl::android::hardware::bluetooth::audio::IBluetoothAudioProvider::
101 AseState in_state,
102 int32_t cigId, int32_t cisId,
103 const std::optional<std::vector<std::optional<
104 ::aidl::android::hardware::bluetooth::audio::MetadataLtv>>>&
105 in_metadata) override;
106 ndk::ScopedAStatus onSourceAseMetadataChanged(
107 ::aidl::android::hardware::bluetooth::audio::IBluetoothAudioProvider::
108 AseState in_state,
109 int32_t cigId, int32_t cisId,
110 const std::optional<std::vector<std::optional<
111 ::aidl::android::hardware::bluetooth::audio::MetadataLtv>>>&
112 in_metadata) override;
113 ndk::ScopedAStatus getLeAudioBroadcastConfiguration(
114 const std::optional<std::vector<std::optional<
115 ::aidl::android::hardware::bluetooth::audio::IBluetoothAudioProvider::
116 LeAudioDeviceCapabilities>>>& in_remoteSinkAudioCapabilities,
117 const ::aidl::android::hardware::bluetooth::audio::
118 IBluetoothAudioProvider::LeAudioBroadcastConfigurationRequirement&
119 in_requirement,
120 ::aidl::android::hardware::bluetooth::audio::IBluetoothAudioProvider::
121 LeAudioBroadcastConfigurationSetting* _aidl_return) override;
122 ndk::ScopedAStatus getLeAudioBroadcastDatapathConfiguration(
123 const ::aidl::android::hardware::bluetooth::audio::AudioContext&
124 in_context,
125 const std::vector<::aidl::android::hardware::bluetooth::audio::
126 LeAudioBroadcastConfiguration::BroadcastStreamMap>&
127 in_streamMap,
128 ::aidl::android::hardware::bluetooth::audio::IBluetoothAudioProvider::
129 LeAudioDataPathConfiguration* _aidl_return) override;
Josh Wu6ab53e72021-12-29 23:53:33 -0800130
Antoine SOULIER33c4e5a2023-09-28 21:59:19 +0000131 ndk::ScopedAStatus parseA2dpConfiguration(
132 const CodecId& codec_id, const std::vector<uint8_t>& configuration,
133 CodecParameters* codec_parameters, A2dpStatus* _aidl_return);
134 ndk::ScopedAStatus getA2dpConfiguration(
135 const std::vector<A2dpRemoteCapabilities>& remote_a2dp_capabilities,
136 const A2dpConfigurationHint& hint,
137 std::optional<audio::A2dpConfiguration>* _aidl_return);
138
Josh Wu6ab53e72021-12-29 23:53:33 -0800139 virtual bool isValid(const SessionType& sessionType) = 0;
140
141 protected:
142 virtual ndk::ScopedAStatus onSessionReady(DataMQDesc* _aidl_return) = 0;
Josh Wu6ab53e72021-12-29 23:53:33 -0800143
144 ::ndk::ScopedAIBinder_DeathRecipient death_recipient_;
145
146 std::shared_ptr<IBluetoothAudioPort> stack_iface_;
147 std::unique_ptr<AudioConfiguration> audio_config_ = nullptr;
148 SessionType session_type_;
Chen Chenc92270e2022-02-14 18:29:52 -0800149 std::vector<LatencyMode> latency_modes_;
Josh Wu6ab53e72021-12-29 23:53:33 -0800150};
Josh Wu6ab53e72021-12-29 23:53:33 -0800151} // namespace audio
152} // namespace bluetooth
153} // namespace hardware
154} // namespace android
Cheney Ni6ecbc762022-03-03 00:12:48 +0800155} // namespace aidl