• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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::leAudioConfig:
59         audio_config_.set<AudioConfiguration::leAudioConfig>(
60             audio_config.get<AudioConfiguration::leAudioConfig>());
61         break;
62       case AudioConfiguration::leAudioBroadcastConfig:
63         audio_config_.set<AudioConfiguration::leAudioBroadcastConfig>(
64             audio_config.get<AudioConfiguration::leAudioBroadcastConfig>());
65     }
66   }
67 
68   virtual BluetoothAudioCtrlAck StartRequest(bool is_low_latency) = 0;
69 
70   virtual BluetoothAudioCtrlAck SuspendRequest() = 0;
71 
72   virtual void StopRequest() = 0;
73 
74   virtual void SetLowLatency(bool is_low_latency) = 0;
75 
76   virtual bool GetPresentationPosition(uint64_t* remote_delay_report_ns,
77                                        uint64_t* total_bytes_readed,
78                                        timespec* data_position) = 0;
79 
80   virtual void SourceMetadataChanged(
81       const source_metadata_t& source_metadata) = 0;
82   virtual void SinkMetadataChanged(const sink_metadata_t& sink_metadata) = 0;
83 
84   /***
85    * Invoked when the transport is requested to reset presentation position
86    ***/
87   virtual void ResetPresentationPosition() = 0;
88 
89  private:
90   const SessionType session_type_;
91   AudioConfiguration audio_config_;
92 };
93 
94 /***
95  * An IBluetoothSinkTransportInstance needs to be implemented by a Bluetooth
96  * audio transport, such as A2DP, Hearing Aid or LeAudio, to handle callbacks
97  * from Audio HAL.
98  ***/
99 class IBluetoothSinkTransportInstance : public IBluetoothTransportInstance {
100  public:
IBluetoothSinkTransportInstance(SessionType sessionType,AudioConfiguration audioConfig)101   IBluetoothSinkTransportInstance(SessionType sessionType,
102                                   AudioConfiguration audioConfig)
103       : IBluetoothTransportInstance{sessionType, audioConfig} {}
104   virtual ~IBluetoothSinkTransportInstance() = default;
105 
106   /***
107    * Invoked when the transport is requested to log bytes read
108    ***/
109   virtual void LogBytesRead(size_t bytes_readed) = 0;
110 };
111 
112 class IBluetoothSourceTransportInstance : public IBluetoothTransportInstance {
113  public:
IBluetoothSourceTransportInstance(SessionType sessionType,AudioConfiguration audioConfig)114   IBluetoothSourceTransportInstance(SessionType sessionType,
115                                     AudioConfiguration audioConfig)
116       : IBluetoothTransportInstance{sessionType, audioConfig} {}
117   virtual ~IBluetoothSourceTransportInstance() = default;
118 
119   /***
120    * Invoked when the transport is requested to log bytes written
121    ***/
122   virtual void LogBytesWritten(size_t bytes_written) = 0;
123 };
124 
125 }  // namespace aidl
126 }  // namespace audio
127 }  // namespace bluetooth
128