1 /* 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> 19 #include <aidl/android/hardware/bluetooth/audio/LatencyMode.h> 20 #include <aidl/android/hardware/bluetooth/audio/SessionType.h> 21 #include <fmq/AidlMessageQueue.h> 22 23 using ::aidl::android::hardware::common::fmq::MQDescriptor; 24 using ::aidl::android::hardware::common::fmq::SynchronizedReadWrite; 25 using ::android::AidlMessageQueue; 26 27 using MqDataType = int8_t; 28 using MqDataMode = SynchronizedReadWrite; 29 using DataMQ = AidlMessageQueue<MqDataType, MqDataMode>; 30 using DataMQDesc = MQDescriptor<MqDataType, MqDataMode>; 31 32 namespace aidl { 33 namespace android { 34 namespace hardware { 35 namespace bluetooth { 36 namespace audio { 37 38 class BluetoothAudioProvider : public BnBluetoothAudioProvider { 39 public: 40 BluetoothAudioProvider(); 41 ndk::ScopedAStatus startSession( 42 const std::shared_ptr<IBluetoothAudioPort>& host_if, 43 const AudioConfiguration& audio_config, 44 const std::vector<LatencyMode>& latency_modes, 45 DataMQDesc* _aidl_return); 46 ndk::ScopedAStatus endSession(); 47 ndk::ScopedAStatus streamStarted(BluetoothAudioStatus status); 48 ndk::ScopedAStatus streamSuspended(BluetoothAudioStatus status); 49 ndk::ScopedAStatus updateAudioConfiguration( 50 const AudioConfiguration& audio_config); 51 ndk::ScopedAStatus setLowLatencyModeAllowed(bool allowed); 52 53 virtual bool isValid(const SessionType& sessionType) = 0; 54 55 protected: 56 virtual ndk::ScopedAStatus onSessionReady(DataMQDesc* _aidl_return) = 0; 57 58 ::ndk::ScopedAIBinder_DeathRecipient death_recipient_; 59 60 std::shared_ptr<IBluetoothAudioPort> stack_iface_; 61 std::unique_ptr<AudioConfiguration> audio_config_ = nullptr; 62 SessionType session_type_; 63 std::vector<LatencyMode> latency_modes_; 64 }; 65 } // namespace audio 66 } // namespace bluetooth 67 } // namespace hardware 68 } // namespace android 69 } // namespace aidl 70