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