1 /* 2 * Copyright 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 #pragma once 18 19 #include <hardware/audio.h> 20 21 #include "audio_aidl_interfaces.h" 22 #include "audio_ctrl_ack.h" 23 24 namespace bluetooth { 25 namespace audio { 26 namespace aidl { 27 28 using ::aidl::android::hardware::bluetooth::audio::AudioConfiguration; 29 using ::aidl::android::hardware::bluetooth::audio::LatencyMode; 30 using ::aidl::android::hardware::bluetooth::audio::SessionType; 31 32 /*** 33 * An IBluetoothTransportInstance needs to be implemented by a Bluetooth 34 * audio transport, such as A2DP or Hearing Aid, to handle callbacks from Audio 35 * HAL. 36 ***/ 37 class IBluetoothTransportInstance { 38 public: IBluetoothTransportInstance(SessionType sessionType,AudioConfiguration audioConfig)39 IBluetoothTransportInstance(SessionType sessionType, AudioConfiguration audioConfig) 40 : session_type_(sessionType), audio_config_(std::move(audioConfig)) {} 41 virtual ~IBluetoothTransportInstance() = default; 42 GetSessionType()43 SessionType GetSessionType() const { return session_type_; } 44 GetAudioConfiguration()45 AudioConfiguration GetAudioConfiguration() const { return audio_config_; } 46 UpdateAudioConfiguration(const AudioConfiguration & audio_config)47 void UpdateAudioConfiguration(const AudioConfiguration& audio_config) { 48 switch (audio_config.getTag()) { 49 case AudioConfiguration::pcmConfig: 50 audio_config_.set<AudioConfiguration::pcmConfig>( 51 audio_config.get<AudioConfiguration::pcmConfig>()); 52 break; 53 case AudioConfiguration::a2dpConfig: 54 audio_config_.set<AudioConfiguration::a2dpConfig>( 55 audio_config.get<AudioConfiguration::a2dpConfig>()); 56 break; 57 case AudioConfiguration::hfpConfig: 58 audio_config_.set<AudioConfiguration::hfpConfig>( 59 audio_config.get<AudioConfiguration::hfpConfig>()); 60 break; 61 case AudioConfiguration::leAudioConfig: 62 audio_config_.set<AudioConfiguration::leAudioConfig>( 63 audio_config.get<AudioConfiguration::leAudioConfig>()); 64 break; 65 case AudioConfiguration::leAudioBroadcastConfig: 66 audio_config_.set<AudioConfiguration::leAudioBroadcastConfig>( 67 audio_config.get<AudioConfiguration::leAudioBroadcastConfig>()); 68 break; 69 case AudioConfiguration::a2dp: 70 audio_config_.set<AudioConfiguration::a2dp>(audio_config.get<AudioConfiguration::a2dp>()); 71 break; 72 } 73 } 74 75 virtual BluetoothAudioCtrlAck StartRequest(bool is_low_latency) = 0; 76 77 virtual BluetoothAudioCtrlAck SuspendRequest() = 0; 78 79 virtual void StopRequest() = 0; 80 81 virtual void SetLatencyMode(LatencyMode latency_mode) = 0; 82 83 virtual bool GetPresentationPosition(uint64_t* remote_delay_report_ns, 84 uint64_t* total_bytes_readed, timespec* data_position) = 0; 85 86 virtual void SourceMetadataChanged(const source_metadata_v7_t& source_metadata) = 0; 87 virtual void SinkMetadataChanged(const sink_metadata_v7_t& sink_metadata) = 0; 88 89 /*** 90 * Invoked when the transport is requested to reset presentation position 91 ***/ 92 virtual void ResetPresentationPosition() = 0; 93 94 private: 95 const SessionType session_type_; 96 AudioConfiguration audio_config_; 97 }; 98 99 /*** 100 * An IBluetoothSinkTransportInstance needs to be implemented by a Bluetooth 101 * audio transport, such as A2DP, Hearing Aid or LeAudio, to handle callbacks 102 * from Audio HAL. 103 ***/ 104 class IBluetoothSinkTransportInstance : public IBluetoothTransportInstance { 105 public: IBluetoothSinkTransportInstance(SessionType sessionType,AudioConfiguration audioConfig)106 IBluetoothSinkTransportInstance(SessionType sessionType, AudioConfiguration audioConfig) 107 : IBluetoothTransportInstance{sessionType, audioConfig} {} 108 virtual ~IBluetoothSinkTransportInstance() = default; 109 110 /*** 111 * Invoked when the transport is requested to log bytes read 112 ***/ 113 virtual void LogBytesRead(size_t bytes_readed) = 0; 114 }; 115 116 class IBluetoothSourceTransportInstance : public IBluetoothTransportInstance { 117 public: IBluetoothSourceTransportInstance(SessionType sessionType,AudioConfiguration audioConfig)118 IBluetoothSourceTransportInstance(SessionType sessionType, AudioConfiguration audioConfig) 119 : IBluetoothTransportInstance{sessionType, audioConfig} {} 120 virtual ~IBluetoothSourceTransportInstance() = default; 121 122 /*** 123 * Invoked when the transport is requested to log bytes written 124 ***/ 125 virtual void LogBytesWritten(size_t bytes_written) = 0; 126 }; 127 128 } // namespace aidl 129 } // namespace audio 130 } // namespace bluetooth 131