1 /* 2 * Copyright 2018 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 #pragma once 18 19 #include <android/hardware/bluetooth/audio/2.1/types.h> 20 #include "BluetoothAudioSession.h" 21 22 #include <mutex> 23 #include <unordered_map> 24 25 namespace android { 26 namespace bluetooth { 27 namespace audio { 28 29 class BluetoothAudioSession_2_1 { 30 private: 31 std::shared_ptr<BluetoothAudioSession> audio_session; 32 33 ::android::hardware::bluetooth::audio::V2_1::SessionType session_type_2_1_; 34 ::android::hardware::bluetooth::audio::V2_1::SessionType raw_session_type_; 35 36 // audio data configuration for both software and offloading 37 ::android::hardware::bluetooth::audio::V2_1::AudioConfiguration 38 audio_config_2_1_; 39 40 bool UpdateAudioConfig( 41 const ::android::hardware::bluetooth::audio::V2_1::AudioConfiguration& 42 audio_config); 43 44 static ::android::hardware::bluetooth::audio::V2_1::AudioConfiguration 45 invalidSoftwareAudioConfiguration; 46 static ::android::hardware::bluetooth::audio::V2_1::AudioConfiguration 47 invalidOffloadAudioConfiguration; 48 49 public: 50 BluetoothAudioSession_2_1( 51 const ::android::hardware::bluetooth::audio::V2_1::SessionType& 52 session_type); 53 54 std::shared_ptr<BluetoothAudioSession> GetAudioSession(); 55 56 // The report function is used to report that the Bluetooth stack has started 57 // this session without any failure, and will invoke session_changed_cb_ to 58 // notify those registered bluetooth_audio outputs 59 void OnSessionStarted( 60 const sp<IBluetoothAudioPort> stack_iface, 61 const DataMQ::Descriptor* dataMQ, 62 const ::android::hardware::bluetooth::audio::V2_1::AudioConfiguration& 63 audio_config); 64 65 // The control function is for the bluetooth_audio module to get the current 66 // AudioConfiguration 67 const ::android::hardware::bluetooth::audio::V2_1::AudioConfiguration 68 GetAudioConfig(); 69 70 static constexpr ::android::hardware::bluetooth::audio::V2_1:: 71 AudioConfiguration& kInvalidSoftwareAudioConfiguration = 72 invalidSoftwareAudioConfiguration; 73 static constexpr ::android::hardware::bluetooth::audio::V2_1:: 74 AudioConfiguration& kInvalidOffloadAudioConfiguration = 75 invalidOffloadAudioConfiguration; 76 }; 77 78 class BluetoothAudioSessionInstance_2_1 { 79 public: 80 // The API is to fetch the specified session of A2DP / Hearing Aid 81 static std::shared_ptr<BluetoothAudioSession_2_1> GetSessionInstance( 82 const ::android::hardware::bluetooth::audio::V2_1::SessionType& 83 session_type); 84 85 private: 86 static std::unique_ptr<BluetoothAudioSessionInstance_2_1> instance_ptr; 87 std::mutex mutex_; 88 std::unordered_map<::android::hardware::bluetooth::audio::V2_1::SessionType, 89 std::shared_ptr<BluetoothAudioSession_2_1>> 90 sessions_map_; 91 }; 92 93 } // namespace audio 94 } // namespace bluetooth 95 } // namespace android 96