Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2023 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 | |
Andy Hung | c6f227f | 2023-07-18 18:31:50 -0700 | [diff] [blame] | 19 | #include <android/media/IAudioTrackCallback.h> |
| 20 | #include <android/media/IEffectClient.h> |
| 21 | #include <audiomanager/IAudioManager.h> |
Andy Hung | 954b971 | 2023-08-28 18:36:53 -0700 | [diff] [blame] | 22 | #include <audio_utils/mutex.h> |
Andy Hung | c6f227f | 2023-07-18 18:31:50 -0700 | [diff] [blame] | 23 | #include <audio_utils/MelProcessor.h> |
| 24 | #include <binder/MemoryDealer.h> |
| 25 | #include <datapath/AudioStreamIn.h> |
| 26 | #include <datapath/AudioStreamOut.h> |
| 27 | #include <datapath/VolumeInterface.h> |
| 28 | #include <fastpath/FastMixerDumpState.h> |
| 29 | #include <media/DeviceDescriptorBase.h> |
| 30 | #include <media/MmapStreamInterface.h> |
| 31 | #include <media/audiohal/StreamHalInterface.h> |
| 32 | #include <media/nblog/NBLog.h> |
| 33 | #include <timing/SyncEvent.h> |
Andy Hung | c6f227f | 2023-07-18 18:31:50 -0700 | [diff] [blame] | 34 | #include <utils/RefBase.h> |
| 35 | #include <vibrator/ExternalVibration.h> |
| 36 | |
| 37 | #include <optional> |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 38 | |
| 39 | namespace android { |
| 40 | |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 41 | class IAfDirectOutputThread; |
| 42 | class IAfDuplicatingThread; |
Andy Hung | 7aa7d10 | 2023-07-07 15:58:48 -0700 | [diff] [blame] | 43 | class IAfMmapCaptureThread; |
| 44 | class IAfMmapPlaybackThread; |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 45 | class IAfPlaybackThread; |
| 46 | class IAfRecordThread; |
Andy Hung | c6f227f | 2023-07-18 18:31:50 -0700 | [diff] [blame] | 47 | |
| 48 | class IAfEffectChain; |
| 49 | class IAfEffectHandle; |
| 50 | class IAfEffectModule; |
| 51 | class IAfPatchPanel; |
| 52 | class IAfPatchRecord; |
| 53 | class IAfPatchTrack; |
| 54 | class IAfRecordTrack; |
| 55 | class IAfTrack; |
| 56 | class IAfTrackBase; |
| 57 | class Client; |
Andy Hung | 583043b | 2023-07-17 17:05:00 -0700 | [diff] [blame] | 58 | class MelReporter; |
| 59 | |
Andy Hung | 25a80ac | 2023-07-19 12:47:35 -0700 | [diff] [blame] | 60 | // Used internally for Threads.cpp and AudioFlinger.cpp |
| 61 | struct stream_type_t { |
| 62 | float volume = 1.f; |
| 63 | bool mute = false; |
| 64 | }; |
| 65 | |
Andy Hung | 583043b | 2023-07-17 17:05:00 -0700 | [diff] [blame] | 66 | // Note this is exposed through IAfThreadBase::afThreadCallback() |
| 67 | // and hence may be used by the Effect / Track framework. |
| 68 | class IAfThreadCallback : public virtual RefBase { |
| 69 | public: |
Andy Hung | 972bec1 | 2023-08-31 16:13:39 -0700 | [diff] [blame] | 70 | virtual audio_utils::mutex& mutex() const |
| 71 | RETURN_CAPABILITY(audio_utils::AudioFlinger_Mutex) = 0; |
| 72 | virtual bool isNonOffloadableGlobalEffectEnabled_l() const |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 73 | REQUIRES(mutex()) EXCLUDES_ThreadBase_Mutex = 0; // Tracks |
Andy Hung | 583043b | 2023-07-17 17:05:00 -0700 | [diff] [blame] | 74 | virtual audio_unique_id_t nextUniqueId(audio_unique_id_use_t use) = 0; |
| 75 | virtual bool btNrecIsOff() const = 0; |
Andy Hung | 972bec1 | 2023-08-31 16:13:39 -0700 | [diff] [blame] | 76 | virtual float masterVolume_l() const |
| 77 | REQUIRES(mutex()) = 0; |
| 78 | virtual bool masterMute_l() const |
| 79 | REQUIRES(mutex()) = 0; |
| 80 | virtual float getMasterBalance_l() const |
| 81 | REQUIRES(mutex()) = 0; |
| 82 | virtual bool streamMute_l(audio_stream_type_t stream) const |
| 83 | REQUIRES(mutex()) = 0; |
Andy Hung | 583043b | 2023-07-17 17:05:00 -0700 | [diff] [blame] | 84 | virtual audio_mode_t getMode() const = 0; |
| 85 | virtual bool isLowRamDevice() const = 0; |
| 86 | virtual bool isAudioPolicyReady() const = 0; // Effects |
Andy Hung | 1d2d2aea | 2023-07-19 16:22:58 -0700 | [diff] [blame] | 87 | virtual uint32_t getScreenState() const = 0; |
Andy Hung | 972bec1 | 2023-08-31 16:13:39 -0700 | [diff] [blame] | 88 | virtual std::optional<media::AudioVibratorInfo> getDefaultVibratorInfo_l() const |
| 89 | REQUIRES(mutex()) = 0; |
Andy Hung | 583043b | 2023-07-17 17:05:00 -0700 | [diff] [blame] | 90 | virtual const sp<IAfPatchPanel>& getPatchPanel() const = 0; |
| 91 | virtual const sp<MelReporter>& getMelReporter() const = 0; |
| 92 | virtual const sp<EffectsFactoryHalInterface>& getEffectsFactoryHal() const = 0; |
| 93 | virtual sp<IAudioManager> getOrCreateAudioManager() = 0; // Tracks |
| 94 | |
Andy Hung | 972bec1 | 2023-08-31 16:13:39 -0700 | [diff] [blame] | 95 | virtual bool updateOrphanEffectChains(const sp<IAfEffectModule>& effect) |
| 96 | EXCLUDES_AudioFlinger_Mutex = 0; |
| 97 | virtual status_t moveEffectChain_ll(audio_session_t sessionId, |
Francois Gaffie | f2591bc | 2021-11-22 18:20:16 +0100 | [diff] [blame^] | 98 | IAfPlaybackThread* srcThread, IAfPlaybackThread* dstThread, |
| 99 | IAfEffectChain* srcChain = nullptr) |
Andy Hung | 972bec1 | 2023-08-31 16:13:39 -0700 | [diff] [blame] | 100 | REQUIRES(mutex(), audio_utils::ThreadBase_Mutex) = 0; |
Andy Hung | 583043b | 2023-07-17 17:05:00 -0700 | [diff] [blame] | 101 | |
| 102 | virtual void requestLogMerge() = 0; |
Andy Hung | 972bec1 | 2023-08-31 16:13:39 -0700 | [diff] [blame] | 103 | virtual sp<NBLog::Writer> newWriter_l(size_t size, const char *name) |
| 104 | REQUIRES(mutex()) = 0; |
Andy Hung | 583043b | 2023-07-17 17:05:00 -0700 | [diff] [blame] | 105 | virtual void unregisterWriter(const sp<NBLog::Writer>& writer) = 0; |
| 106 | |
| 107 | virtual sp<audioflinger::SyncEvent> createSyncEvent(AudioSystem::sync_event_t type, |
| 108 | audio_session_t triggerSession, |
| 109 | audio_session_t listenerSession, |
| 110 | const audioflinger::SyncEventCallback& callBack, |
Andy Hung | 972bec1 | 2023-08-31 16:13:39 -0700 | [diff] [blame] | 111 | const wp<IAfTrackBase>& cookie) |
| 112 | EXCLUDES_AudioFlinger_Mutex = 0; |
Andy Hung | 583043b | 2023-07-17 17:05:00 -0700 | [diff] [blame] | 113 | |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 114 | // Hold either AudioFlinger::mutex or ThreadBase::mutex |
| 115 | virtual void ioConfigChanged_l(audio_io_config_event_t event, |
Andy Hung | 583043b | 2023-07-17 17:05:00 -0700 | [diff] [blame] | 116 | const sp<AudioIoDescriptor>& ioDesc, |
Andy Hung | 972bec1 | 2023-08-31 16:13:39 -0700 | [diff] [blame] | 117 | pid_t pid = 0) EXCLUDES_AudioFlinger_ClientMutex = 0; |
| 118 | virtual void onNonOffloadableGlobalEffectEnable() EXCLUDES_AudioFlinger_Mutex = 0; |
Andy Hung | 583043b | 2023-07-17 17:05:00 -0700 | [diff] [blame] | 119 | virtual void onSupportedLatencyModesChanged( |
Andy Hung | 972bec1 | 2023-08-31 16:13:39 -0700 | [diff] [blame] | 120 | audio_io_handle_t output, const std::vector<audio_latency_mode_t>& modes) |
| 121 | EXCLUDES_AudioFlinger_ClientMutex = 0; |
Andy Hung | 583043b | 2023-07-17 17:05:00 -0700 | [diff] [blame] | 122 | }; |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 123 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 124 | class IAfThreadBase : public virtual RefBase { |
| 125 | public: |
| 126 | enum type_t { |
| 127 | MIXER, // Thread class is MixerThread |
| 128 | DIRECT, // Thread class is DirectOutputThread |
| 129 | DUPLICATING, // Thread class is DuplicatingThread |
| 130 | RECORD, // Thread class is RecordThread |
| 131 | OFFLOAD, // Thread class is OffloadThread |
| 132 | MMAP_PLAYBACK, // Thread class for MMAP playback stream |
| 133 | MMAP_CAPTURE, // Thread class for MMAP capture stream |
| 134 | SPATIALIZER, // |
| 135 | BIT_PERFECT, // Thread class for BitPerfectThread |
| 136 | // When adding a value, also update IAfThreadBase::threadTypeToString() |
| 137 | }; |
| 138 | |
| 139 | static const char* threadTypeToString(type_t type); |
Andy Hung | 25a80ac | 2023-07-19 12:47:35 -0700 | [diff] [blame] | 140 | static std::string formatToString(audio_format_t format); // compliant for MediaMetrics |
Andy Hung | 81994d6 | 2023-07-20 21:44:14 -0700 | [diff] [blame] | 141 | static bool isValidPcmSinkChannelMask(audio_channel_mask_t channelMask); |
| 142 | static bool isValidPcmSinkFormat(audio_format_t format); |
| 143 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 144 | virtual status_t readyToRun() = 0; |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 145 | virtual void clearPowerManager() EXCLUDES_ThreadBase_Mutex = 0; |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 146 | virtual status_t initCheck() const = 0; |
| 147 | virtual type_t type() const = 0; |
| 148 | virtual bool isDuplicating() const = 0; |
| 149 | virtual audio_io_handle_t id() const = 0; |
| 150 | virtual uint32_t sampleRate() const = 0; |
| 151 | virtual audio_channel_mask_t channelMask() const = 0; |
| 152 | virtual audio_channel_mask_t mixerChannelMask() const = 0; |
| 153 | virtual audio_format_t format() const = 0; |
| 154 | virtual uint32_t channelCount() const = 0; |
| 155 | |
| 156 | // Called by AudioFlinger::frameCount(audio_io_handle_t output) and effects, |
| 157 | // and returns the [normal mix] buffer's frame count. |
| 158 | virtual size_t frameCount() const = 0; |
| 159 | virtual audio_channel_mask_t hapticChannelMask() const = 0; |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 160 | virtual uint32_t hapticChannelCount() const = 0; |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 161 | virtual uint32_t latency_l() const = 0; // NO_THREAD_SAFETY_ANALYSIS |
| 162 | virtual void setVolumeForOutput_l(float left, float right) const REQUIRES(mutex()) = 0; |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 163 | |
| 164 | // Return's the HAL's frame count i.e. fast mixer buffer size. |
| 165 | virtual size_t frameCountHAL() const = 0; |
| 166 | virtual size_t frameSize() const = 0; |
| 167 | // Should be "virtual status_t requestExitAndWait()" and override same |
| 168 | // method in Thread, but Thread::requestExitAndWait() is not yet virtual. |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 169 | virtual void exit() EXCLUDES_ThreadBase_Mutex = 0; |
| 170 | virtual bool checkForNewParameter_l(const String8& keyValuePair, status_t& status) |
| 171 | REQUIRES(mutex()) = 0; |
| 172 | virtual status_t setParameters(const String8& keyValuePairs) EXCLUDES_ThreadBase_Mutex = 0; |
| 173 | virtual String8 getParameters(const String8& keys) EXCLUDES_ThreadBase_Mutex = 0; |
| 174 | virtual void ioConfigChanged_l( |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 175 | audio_io_config_event_t event, pid_t pid = 0, |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 176 | audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE) |
| 177 | /* holds either AF::mutex or TB::mutex */ = 0; |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 178 | |
| 179 | // sendConfigEvent_l() must be called with ThreadBase::mLock held |
| 180 | // Can temporarily release the lock if waiting for a reply from |
| 181 | // processConfigEvents_l(). |
| 182 | // status_t sendConfigEvent_l(sp<ConfigEvent>& event); |
| 183 | virtual void sendIoConfigEvent( |
| 184 | audio_io_config_event_t event, pid_t pid = 0, |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 185 | audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE) EXCLUDES_ThreadBase_Mutex = 0; |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 186 | virtual void sendIoConfigEvent_l( |
| 187 | audio_io_config_event_t event, pid_t pid = 0, |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 188 | audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE) REQUIRES(mutex()) = 0; |
| 189 | virtual void sendPrioConfigEvent(pid_t pid, pid_t tid, int32_t prio, bool forApp) |
| 190 | EXCLUDES_ThreadBase_Mutex = 0; |
| 191 | virtual void sendPrioConfigEvent_l(pid_t pid, pid_t tid, int32_t prio, bool forApp) |
| 192 | REQUIRES(mutex()) = 0; |
| 193 | virtual status_t sendSetParameterConfigEvent_l(const String8& keyValuePair) |
| 194 | REQUIRES(mutex()) = 0; |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 195 | virtual status_t sendCreateAudioPatchConfigEvent( |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 196 | const struct audio_patch* patch, audio_patch_handle_t* handle) |
| 197 | EXCLUDES_ThreadBase_Mutex = 0; |
| 198 | virtual status_t sendReleaseAudioPatchConfigEvent(audio_patch_handle_t handle) |
| 199 | EXCLUDES_ThreadBase_Mutex = 0; |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 200 | virtual status_t sendUpdateOutDeviceConfigEvent( |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 201 | const DeviceDescriptorBaseVector& outDevices) EXCLUDES_ThreadBase_Mutex = 0; |
| 202 | virtual void sendResizeBufferConfigEvent_l(int32_t maxSharedAudioHistoryMs) |
| 203 | REQUIRES(mutex()) = 0; |
| 204 | virtual void sendCheckOutputStageEffectsEvent() EXCLUDES_ThreadBase_Mutex = 0; |
| 205 | virtual void sendCheckOutputStageEffectsEvent_l() |
| 206 | REQUIRES(mutex()) = 0; |
| 207 | virtual void sendHalLatencyModesChangedEvent_l() |
| 208 | REQUIRES(mutex()) = 0; |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 209 | |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 210 | virtual void processConfigEvents_l() |
| 211 | REQUIRES(mutex()) = 0; |
| 212 | virtual void setCheckOutputStageEffects() = 0; // no mutex needed |
| 213 | virtual void cacheParameters_l() |
| 214 | REQUIRES(mutex()) = 0; |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 215 | virtual status_t createAudioPatch_l( |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 216 | const struct audio_patch* patch, audio_patch_handle_t* handle) |
| 217 | REQUIRES(mutex()) = 0; |
| 218 | virtual status_t releaseAudioPatch_l(const audio_patch_handle_t handle) |
| 219 | REQUIRES(mutex()) = 0; |
| 220 | virtual void updateOutDevices(const DeviceDescriptorBaseVector& outDevices) |
| 221 | EXCLUDES_ThreadBase_Mutex = 0; |
| 222 | virtual void toAudioPortConfig(struct audio_port_config* config) |
| 223 | EXCLUDES_ThreadBase_Mutex = 0; |
| 224 | virtual void resizeInputBuffer_l(int32_t maxSharedAudioHistoryMs) |
| 225 | REQUIRES(mutex()) = 0; |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 226 | |
| 227 | // see note at declaration of mStandby, mOutDevice and mInDevice |
| 228 | virtual bool inStandby() const = 0; |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 229 | virtual const DeviceTypeSet outDeviceTypes_l() const REQUIRES(mutex()) = 0; |
| 230 | virtual audio_devices_t inDeviceType_l() const REQUIRES(mutex()) = 0; |
| 231 | virtual DeviceTypeSet getDeviceTypes_l() const REQUIRES(mutex()) = 0; |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 232 | virtual const AudioDeviceTypeAddrVector& outDeviceTypeAddrs() const = 0; |
| 233 | virtual const AudioDeviceTypeAddr& inDeviceTypeAddr() const = 0; |
| 234 | virtual bool isOutput() const = 0; |
| 235 | virtual bool isOffloadOrMmap() const = 0; |
| 236 | virtual sp<StreamHalInterface> stream() const = 0; |
| 237 | virtual sp<IAfEffectHandle> createEffect_l( |
| 238 | const sp<Client>& client, |
| 239 | const sp<media::IEffectClient>& effectClient, |
| 240 | int32_t priority, |
| 241 | audio_session_t sessionId, |
| 242 | effect_descriptor_t* desc, |
| 243 | int* enabled, |
| 244 | status_t* status /*non-NULL*/, |
| 245 | bool pinned, |
| 246 | bool probe, |
Andy Hung | 972bec1 | 2023-08-31 16:13:39 -0700 | [diff] [blame] | 247 | bool notifyFramesProcessed) |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 248 | REQUIRES(audio_utils::AudioFlinger_Mutex) EXCLUDES_ThreadBase_Mutex = 0; |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 249 | |
| 250 | // return values for hasAudioSession (bit field) |
| 251 | enum effect_state { |
| 252 | EFFECT_SESSION = 0x1, // the audio session corresponds to at least one |
| 253 | // effect |
| 254 | TRACK_SESSION = 0x2, // the audio session corresponds to at least one |
| 255 | // track |
| 256 | FAST_SESSION = 0x4, // the audio session corresponds to at least one |
| 257 | // fast track |
| 258 | SPATIALIZED_SESSION = 0x8, // the audio session corresponds to at least one |
| 259 | // spatialized track |
| 260 | BIT_PERFECT_SESSION = 0x10 // the audio session corresponds to at least one |
| 261 | // bit-perfect track |
| 262 | }; |
| 263 | |
| 264 | // get effect chain corresponding to session Id. |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 265 | virtual sp<IAfEffectChain> getEffectChain(audio_session_t sessionId) const |
| 266 | EXCLUDES_ThreadBase_Mutex = 0; |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 267 | // same as getEffectChain() but must be called with ThreadBase mutex locked |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 268 | virtual sp<IAfEffectChain> getEffectChain_l(audio_session_t sessionId) const |
| 269 | REQUIRES(mutex()) = 0; |
| 270 | virtual std::vector<int> getEffectIds_l(audio_session_t sessionId) const |
| 271 | REQUIRES(mutex()) = 0; |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 272 | // add an effect chain to the chain list (mEffectChains) |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 273 | virtual status_t addEffectChain_l(const sp<IAfEffectChain>& chain) |
| 274 | REQUIRES(mutex()) = 0; |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 275 | // remove an effect chain from the chain list (mEffectChains) |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 276 | virtual size_t removeEffectChain_l(const sp<IAfEffectChain>& chain) |
| 277 | REQUIRES(mutex()) = 0; |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 278 | // lock all effect chains Mutexes. Must be called before releasing the |
| 279 | // ThreadBase mutex before processing the mixer and effects. This guarantees the |
| 280 | // integrity of the chains during the process. |
| 281 | // Also sets the parameter 'effectChains' to current value of mEffectChains. |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 282 | virtual void lockEffectChains_l(Vector<sp<IAfEffectChain>>& effectChains) |
Shunkai Yao | d125e40 | 2024-01-20 03:19:06 +0000 | [diff] [blame] | 283 | REQUIRES(mutex()) EXCLUDES_EffectChain_Mutex = 0; |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 284 | // unlock effect chains after process |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 285 | virtual void unlockEffectChains(const Vector<sp<IAfEffectChain>>& effectChains) |
| 286 | EXCLUDES_ThreadBase_Mutex = 0; |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 287 | // get a copy of mEffectChains vector |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 288 | virtual Vector<sp<IAfEffectChain>> getEffectChains_l() const |
| 289 | REQUIRES(mutex()) = 0; |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 290 | // set audio mode to all effect chains |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 291 | virtual void setMode(audio_mode_t mode) |
| 292 | EXCLUDES_ThreadBase_Mutex = 0; |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 293 | // get effect module with corresponding ID on specified audio session |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 294 | virtual sp<IAfEffectModule> getEffect(audio_session_t sessionId, int effectId) const |
| 295 | EXCLUDES_ThreadBase_Mutex = 0; |
| 296 | virtual sp<IAfEffectModule> getEffect_l(audio_session_t sessionId, int effectId) const |
| 297 | REQUIRES(mutex()) = 0; |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 298 | // add and effect module. Also creates the effect chain is none exists for |
| 299 | // the effects audio session. Only called in a context of moving an effect |
| 300 | // from one thread to another |
Andy Hung | 972bec1 | 2023-08-31 16:13:39 -0700 | [diff] [blame] | 301 | virtual status_t addEffect_ll(const sp<IAfEffectModule>& effect) |
| 302 | REQUIRES(audio_utils::AudioFlinger_Mutex, mutex()) = 0; |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 303 | // remove and effect module. Also removes the effect chain is this was the last |
| 304 | // effect |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 305 | virtual void removeEffect_l(const sp<IAfEffectModule>& effect, bool release = false) |
| 306 | REQUIRES(mutex()) = 0; |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 307 | // disconnect an effect handle from module and destroy module if last handle |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 308 | virtual void disconnectEffectHandle(IAfEffectHandle* handle, bool unpinIfLast) |
| 309 | EXCLUDES_ThreadBase_Mutex = 0; |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 310 | // detach all tracks connected to an auxiliary effect |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 311 | virtual void detachAuxEffect_l(int effectId) REQUIRES(mutex()) = 0; |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 312 | // returns a combination of: |
| 313 | // - EFFECT_SESSION if effects on this audio session exist in one chain |
| 314 | // - TRACK_SESSION if tracks on this audio session exist |
| 315 | // - FAST_SESSION if fast tracks on this audio session exist |
| 316 | // - SPATIALIZED_SESSION if spatialized tracks on this audio session exist |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 317 | virtual uint32_t hasAudioSession_l(audio_session_t sessionId) const REQUIRES(mutex()) = 0; |
| 318 | virtual uint32_t hasAudioSession(audio_session_t sessionId) const |
| 319 | EXCLUDES_ThreadBase_Mutex = 0; |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 320 | |
| 321 | // the value returned by default implementation is not important as the |
| 322 | // strategy is only meaningful for PlaybackThread which implements this method |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 323 | virtual product_strategy_t getStrategyForSession_l(audio_session_t sessionId) const |
| 324 | REQUIRES(mutex()) = 0; |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 325 | |
| 326 | // check if some effects must be suspended/restored when an effect is enabled |
| 327 | // or disabled |
| 328 | virtual void checkSuspendOnEffectEnabled( |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 329 | bool enabled, audio_session_t sessionId, bool threadLocked) |
| 330 | EXCLUDES_ThreadBase_Mutex = 0; |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 331 | |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 332 | virtual status_t setSyncEvent(const sp<audioflinger::SyncEvent>& event) |
| 333 | EXCLUDES_ThreadBase_Mutex = 0; |
| 334 | // internally static, perhaps make static member. |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 335 | virtual bool isValidSyncEvent(const sp<audioflinger::SyncEvent>& event) const = 0; |
| 336 | |
| 337 | // Return a reference to a per-thread heap which can be used to allocate IMemory |
| 338 | // objects that will be read-only to client processes, read/write to mediaserver, |
| 339 | // and shared by all client processes of the thread. |
| 340 | // The heap is per-thread rather than common across all threads, because |
| 341 | // clients can't be trusted not to modify the offset of the IMemory they receive. |
| 342 | // If a thread does not have such a heap, this method returns 0. |
| 343 | virtual sp<MemoryDealer> readOnlyHeap() const = 0; |
| 344 | |
| 345 | virtual sp<IMemory> pipeMemory() const = 0; |
| 346 | |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 347 | virtual void systemReady() EXCLUDES_ThreadBase_Mutex = 0; |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 348 | |
| 349 | // checkEffectCompatibility_l() must be called with ThreadBase::mLock held |
| 350 | virtual status_t checkEffectCompatibility_l( |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 351 | const effect_descriptor_t* desc, audio_session_t sessionId) REQUIRES(mutex()) = 0; |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 352 | |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 353 | virtual void broadcast_l() REQUIRES(mutex()) = 0; |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 354 | |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 355 | virtual bool isTimestampCorrectionEnabled_l() const REQUIRES(mutex()) = 0; |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 356 | |
| 357 | virtual bool isMsdDevice() const = 0; |
| 358 | |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 359 | virtual void dump(int fd, const Vector<String16>& args) EXCLUDES_ThreadBase_Mutex = 0; |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 360 | |
| 361 | // deliver stats to mediametrics. |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 362 | virtual void sendStatistics(bool force) EXCLUDES_ThreadBase_Mutex = 0; |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 363 | |
Andy Hung | 972bec1 | 2023-08-31 16:13:39 -0700 | [diff] [blame] | 364 | virtual audio_utils::mutex& mutex() const |
| 365 | RETURN_CAPABILITY(audio_utils::ThreadBase_Mutex) = 0; |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 366 | |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 367 | virtual void onEffectEnable(const sp<IAfEffectModule>& effect) EXCLUDES_ThreadBase_Mutex = 0; |
| 368 | virtual void onEffectDisable() EXCLUDES_ThreadBase_Mutex = 0; |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 369 | |
| 370 | // invalidateTracksForAudioSession_l must be called with holding mLock. |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 371 | virtual void invalidateTracksForAudioSession_l(audio_session_t sessionId) const |
| 372 | REQUIRES(mutex()) = 0; |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 373 | // Invalidate all the tracks with the given audio session. |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 374 | virtual void invalidateTracksForAudioSession(audio_session_t sessionId) const |
| 375 | EXCLUDES_ThreadBase_Mutex = 0; |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 376 | |
| 377 | virtual bool isStreamInitialized() const = 0; |
Andy Hung | 972bec1 | 2023-08-31 16:13:39 -0700 | [diff] [blame] | 378 | virtual void startMelComputation_l(const sp<audio_utils::MelProcessor>& processor) |
| 379 | REQUIRES(audio_utils::AudioFlinger_Mutex) = 0; |
| 380 | virtual void stopMelComputation_l() |
| 381 | REQUIRES(audio_utils::AudioFlinger_Mutex) = 0; |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 382 | |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 383 | virtual product_strategy_t getStrategyForStream(audio_stream_type_t stream) const |
| 384 | EXCLUDES_AUDIO_ALL = 0; |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 385 | |
| 386 | virtual void setEffectSuspended_l( |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 387 | const effect_uuid_t* type, bool suspend, audio_session_t sessionId) |
| 388 | REQUIRES(mutex()) = 0; |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 389 | |
Andy Hung | 6c498e9 | 2023-12-05 17:28:17 -0800 | [diff] [blame] | 390 | // Wait while the Thread is busy. This is done to ensure that |
| 391 | // the Thread is not busy releasing the Tracks, during which the Thread mutex |
| 392 | // may be temporarily unlocked. Some Track methods will use this method to |
| 393 | // avoid races. |
| 394 | virtual void waitWhileThreadBusy_l(audio_utils::unique_lock& ul) |
| 395 | REQUIRES(mutex()) = 0; |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 396 | // Dynamic cast to derived interface |
| 397 | virtual sp<IAfDirectOutputThread> asIAfDirectOutputThread() { return nullptr; } |
| 398 | virtual sp<IAfDuplicatingThread> asIAfDuplicatingThread() { return nullptr; } |
| 399 | virtual sp<IAfPlaybackThread> asIAfPlaybackThread() { return nullptr; } |
| 400 | virtual sp<IAfRecordThread> asIAfRecordThread() { return nullptr; } |
Andy Hung | 583043b | 2023-07-17 17:05:00 -0700 | [diff] [blame] | 401 | virtual IAfThreadCallback* afThreadCallback() const = 0; |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 402 | }; |
| 403 | |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 404 | class IAfPlaybackThread : public virtual IAfThreadBase, public virtual VolumeInterface { |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 405 | public: |
Andy Hung | ee58e4a | 2023-07-07 13:47:37 -0700 | [diff] [blame] | 406 | static sp<IAfPlaybackThread> createBitPerfectThread( |
Andy Hung | 583043b | 2023-07-17 17:05:00 -0700 | [diff] [blame] | 407 | const sp<IAfThreadCallback>& afThreadCallback, AudioStreamOut* output, |
| 408 | audio_io_handle_t id, bool systemReady); |
Andy Hung | ee58e4a | 2023-07-07 13:47:37 -0700 | [diff] [blame] | 409 | |
| 410 | static sp<IAfPlaybackThread> createDirectOutputThread( |
Andy Hung | 583043b | 2023-07-17 17:05:00 -0700 | [diff] [blame] | 411 | const sp<IAfThreadCallback>& afThreadCallback, AudioStreamOut* output, |
| 412 | audio_io_handle_t id, bool systemReady, const audio_offload_info_t& offloadInfo); |
Andy Hung | ee58e4a | 2023-07-07 13:47:37 -0700 | [diff] [blame] | 413 | |
| 414 | static sp<IAfPlaybackThread> createMixerThread( |
Andy Hung | 583043b | 2023-07-17 17:05:00 -0700 | [diff] [blame] | 415 | const sp<IAfThreadCallback>& afThreadCallback, AudioStreamOut* output, |
| 416 | audio_io_handle_t id, bool systemReady, type_t type = MIXER, |
| 417 | audio_config_base_t* mixerConfig = nullptr); |
Andy Hung | ee58e4a | 2023-07-07 13:47:37 -0700 | [diff] [blame] | 418 | |
| 419 | static sp<IAfPlaybackThread> createOffloadThread( |
Andy Hung | 583043b | 2023-07-17 17:05:00 -0700 | [diff] [blame] | 420 | const sp<IAfThreadCallback>& afThreadCallback, AudioStreamOut* output, |
| 421 | audio_io_handle_t id, bool systemReady, const audio_offload_info_t& offloadInfo); |
Andy Hung | ee58e4a | 2023-07-07 13:47:37 -0700 | [diff] [blame] | 422 | |
| 423 | static sp<IAfPlaybackThread> createSpatializerThread( |
Andy Hung | 583043b | 2023-07-17 17:05:00 -0700 | [diff] [blame] | 424 | const sp<IAfThreadCallback>& afThreadCallback, AudioStreamOut* output, |
| 425 | audio_io_handle_t id, bool systemReady, audio_config_base_t* mixerConfig); |
Andy Hung | ee58e4a | 2023-07-07 13:47:37 -0700 | [diff] [blame] | 426 | |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 427 | static constexpr int8_t kMaxTrackStopRetriesOffload = 2; |
| 428 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 429 | enum mixer_state { |
| 430 | MIXER_IDLE, // no active tracks |
| 431 | MIXER_TRACKS_ENABLED, // at least one active track, but no track has any data ready |
| 432 | MIXER_TRACKS_READY, // at least one active track, and at least one track has data |
| 433 | MIXER_DRAIN_TRACK, // drain currently playing track |
| 434 | MIXER_DRAIN_ALL, // fully drain the hardware |
| 435 | // standby mode does not have an enum value |
| 436 | // suspend by audio policy manager is orthogonal to mixer state |
| 437 | }; |
| 438 | |
| 439 | // return estimated latency in milliseconds, as reported by HAL |
| 440 | virtual uint32_t latency() const = 0; // should be in IAfThreadBase? |
| 441 | |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 442 | virtual uint32_t& fastTrackAvailMask_l() REQUIRES(mutex()) = 0; |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 443 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 444 | virtual sp<IAfTrack> createTrack_l( |
| 445 | const sp<Client>& client, |
| 446 | audio_stream_type_t streamType, |
| 447 | const audio_attributes_t& attr, |
| 448 | uint32_t* sampleRate, |
| 449 | audio_format_t format, |
| 450 | audio_channel_mask_t channelMask, |
| 451 | size_t* pFrameCount, |
| 452 | size_t* pNotificationFrameCount, |
| 453 | uint32_t notificationsPerBuffer, |
| 454 | float speed, |
| 455 | const sp<IMemory>& sharedBuffer, |
| 456 | audio_session_t sessionId, |
| 457 | audio_output_flags_t* flags, |
| 458 | pid_t creatorPid, |
| 459 | const AttributionSourceState& attributionSource, |
| 460 | pid_t tid, |
| 461 | status_t* status /*non-NULL*/, |
| 462 | audio_port_handle_t portId, |
| 463 | const sp<media::IAudioTrackCallback>& callback, |
| 464 | bool isSpatialized, |
jiabin | 94ed47c | 2023-07-27 23:34:20 +0000 | [diff] [blame] | 465 | bool isBitPerfect, |
Andy Hung | 972bec1 | 2023-08-31 16:13:39 -0700 | [diff] [blame] | 466 | audio_output_flags_t* afTrackFlags) |
| 467 | REQUIRES(audio_utils::AudioFlinger_Mutex) = 0; |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 468 | |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 469 | virtual status_t addTrack_l(const sp<IAfTrack>& track) REQUIRES(mutex()) = 0; |
| 470 | virtual bool destroyTrack_l(const sp<IAfTrack>& track) REQUIRES(mutex()) = 0; |
| 471 | virtual bool isTrackActive(const sp<IAfTrack>& track) const REQUIRES(mutex()) = 0; |
| 472 | virtual void addOutputTrack_l(const sp<IAfTrack>& track) REQUIRES(mutex()) = 0; |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 473 | |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 474 | virtual AudioStreamOut* getOutput_l() const REQUIRES(mutex()) = 0; |
Andy Hung | 8d672e0 | 2023-09-15 18:19:28 -0700 | [diff] [blame] | 475 | virtual AudioStreamOut* getOutput() const EXCLUDES_ThreadBase_Mutex = 0; |
| 476 | virtual AudioStreamOut* clearOutput() EXCLUDES_ThreadBase_Mutex = 0; |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 477 | |
| 478 | // a very large number of suspend() will eventually wraparound, but unlikely |
| 479 | virtual void suspend() = 0; |
| 480 | virtual void restore() = 0; |
| 481 | virtual bool isSuspended() const = 0; |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 482 | virtual status_t getRenderPosition(uint32_t* halFrames, uint32_t* dspFrames) const |
| 483 | EXCLUDES_ThreadBase_Mutex = 0; |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 484 | // Consider also removing and passing an explicit mMainBuffer initialization |
| 485 | // parameter to AF::IAfTrack::Track(). |
| 486 | virtual float* sinkBuffer() const = 0; |
| 487 | |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 488 | virtual status_t attachAuxEffect(const sp<IAfTrack>& track, int EffectId) |
| 489 | EXCLUDES_ThreadBase_Mutex = 0; |
| 490 | virtual status_t attachAuxEffect_l(const sp<IAfTrack>& track, int EffectId) |
| 491 | REQUIRES(mutex()) = 0; |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 492 | |
| 493 | // called with AudioFlinger lock held |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 494 | virtual bool invalidateTracks_l(audio_stream_type_t streamType) REQUIRES(mutex()) = 0; |
| 495 | virtual bool invalidateTracks_l(std::set<audio_port_handle_t>& portIds) REQUIRES(mutex()) = 0; |
| 496 | virtual void invalidateTracks(audio_stream_type_t streamType) |
| 497 | EXCLUDES_ThreadBase_Mutex = 0; |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 498 | // Invalidate tracks by a set of port ids. The port id will be removed from |
| 499 | // the given set if the corresponding track is found and invalidated. |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 500 | virtual void invalidateTracks(std::set<audio_port_handle_t>& portIds) |
| 501 | EXCLUDES_ThreadBase_Mutex = 0; |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 502 | |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 503 | virtual status_t getTimestamp_l(AudioTimestamp& timestamp) REQUIRES(mutex()) = 0; |
| 504 | virtual void addPatchTrack(const sp<IAfPatchTrack>& track) EXCLUDES_ThreadBase_Mutex = 0; |
| 505 | virtual void deletePatchTrack(const sp<IAfPatchTrack>& track) EXCLUDES_ThreadBase_Mutex = 0; |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 506 | |
| 507 | // Return the asynchronous signal wait time. |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 508 | virtual int64_t computeWaitTimeNs_l() const REQUIRES(mutex()) = 0; |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 509 | // returns true if the track is allowed to be added to the thread. |
| 510 | virtual bool isTrackAllowed_l( |
| 511 | audio_channel_mask_t channelMask, audio_format_t format, audio_session_t sessionId, |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 512 | uid_t uid) const REQUIRES(mutex()) = 0; |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 513 | |
| 514 | virtual bool supportsHapticPlayback() const = 0; |
| 515 | |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 516 | virtual void setDownStreamPatch(const struct audio_patch* patch) |
| 517 | EXCLUDES_ThreadBase_Mutex = 0; |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 518 | |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 519 | virtual IAfTrack* getTrackById_l(audio_port_handle_t trackId) REQUIRES(mutex()) = 0; |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 520 | |
| 521 | virtual bool hasMixer() const = 0; |
| 522 | |
| 523 | virtual status_t setRequestedLatencyMode(audio_latency_mode_t mode) = 0; |
| 524 | |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 525 | virtual status_t getSupportedLatencyModes(std::vector<audio_latency_mode_t>* modes) |
| 526 | EXCLUDES_ThreadBase_Mutex = 0; |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 527 | |
| 528 | virtual status_t setBluetoothVariableLatencyEnabled(bool enabled) = 0; |
| 529 | |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 530 | virtual void setStandby() EXCLUDES_ThreadBase_Mutex = 0; |
| 531 | virtual void setStandby_l() REQUIRES(mutex()) = 0; |
| 532 | virtual bool waitForHalStart() EXCLUDES_ThreadBase_Mutex = 0; |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 533 | |
| 534 | virtual bool hasFastMixer() const = 0; |
| 535 | virtual FastTrackUnderruns getFastTrackUnderruns(size_t fastIndex) const = 0; |
| 536 | virtual const std::atomic<int64_t>& framesWritten() const = 0; |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 537 | |
| 538 | virtual bool usesHwAvSync() const = 0; |
| 539 | }; |
| 540 | |
| 541 | class IAfDirectOutputThread : public virtual IAfPlaybackThread { |
| 542 | public: |
| 543 | virtual status_t selectPresentation(int presentationId, int programId) = 0; |
| 544 | }; |
| 545 | |
| 546 | class IAfDuplicatingThread : public virtual IAfPlaybackThread { |
| 547 | public: |
Andy Hung | ee58e4a | 2023-07-07 13:47:37 -0700 | [diff] [blame] | 548 | static sp<IAfDuplicatingThread> create( |
Andy Hung | 583043b | 2023-07-17 17:05:00 -0700 | [diff] [blame] | 549 | const sp<IAfThreadCallback>& afThreadCallback, IAfPlaybackThread* mainThread, |
Andy Hung | ee58e4a | 2023-07-07 13:47:37 -0700 | [diff] [blame] | 550 | audio_io_handle_t id, bool systemReady); |
| 551 | |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 552 | virtual void addOutputTrack(IAfPlaybackThread* thread) EXCLUDES_ThreadBase_Mutex = 0; |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 553 | virtual uint32_t waitTimeMs() const = 0; |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 554 | virtual void removeOutputTrack(IAfPlaybackThread* thread) EXCLUDES_ThreadBase_Mutex = 0; |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 555 | }; |
| 556 | |
| 557 | class IAfRecordThread : public virtual IAfThreadBase { |
| 558 | public: |
| 559 | static sp<IAfRecordThread> create( |
Andy Hung | 583043b | 2023-07-17 17:05:00 -0700 | [diff] [blame] | 560 | const sp<IAfThreadCallback>& afThreadCallback, AudioStreamIn* input, |
| 561 | audio_io_handle_t id, bool systemReady); |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 562 | |
| 563 | virtual sp<IAfRecordTrack> createRecordTrack_l( |
| 564 | const sp<Client>& client, |
| 565 | const audio_attributes_t& attr, |
| 566 | uint32_t* pSampleRate, |
| 567 | audio_format_t format, |
| 568 | audio_channel_mask_t channelMask, |
| 569 | size_t* pFrameCount, |
| 570 | audio_session_t sessionId, |
| 571 | size_t* pNotificationFrameCount, |
| 572 | pid_t creatorPid, |
| 573 | const AttributionSourceState& attributionSource, |
| 574 | audio_input_flags_t* flags, |
| 575 | pid_t tid, |
| 576 | status_t* status /*non-NULL*/, |
| 577 | audio_port_handle_t portId, |
Andy Hung | 972bec1 | 2023-08-31 16:13:39 -0700 | [diff] [blame] | 578 | int32_t maxSharedAudioHistoryMs) |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 579 | REQUIRES(audio_utils::AudioFlinger_Mutex) EXCLUDES_ThreadBase_Mutex = 0; |
| 580 | virtual void destroyTrack_l(const sp<IAfRecordTrack>& track) REQUIRES(mutex()) = 0; |
| 581 | virtual void removeTrack_l(const sp<IAfRecordTrack>& track) REQUIRES(mutex()) = 0; |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 582 | |
| 583 | virtual status_t start( |
| 584 | IAfRecordTrack* recordTrack, AudioSystem::sync_event_t event, |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 585 | audio_session_t triggerSession) EXCLUDES_ThreadBase_Mutex = 0; |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 586 | |
| 587 | // ask the thread to stop the specified track, and |
| 588 | // return true if the caller should then do it's part of the stopping process |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 589 | virtual bool stop(IAfRecordTrack* recordTrack) EXCLUDES_ThreadBase_Mutex = 0; |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 590 | |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 591 | // NO_THREAD_SAFETY_ANALYSIS: consider atomics |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 592 | virtual AudioStreamIn* getInput() const = 0; |
| 593 | virtual AudioStreamIn* clearInput() = 0; |
| 594 | |
| 595 | virtual status_t getActiveMicrophones( |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 596 | std::vector<media::MicrophoneInfoFw>* activeMicrophones) |
| 597 | const EXCLUDES_ThreadBase_Mutex = 0; |
| 598 | virtual status_t setPreferredMicrophoneDirection(audio_microphone_direction_t direction) |
| 599 | EXCLUDES_ThreadBase_Mutex = 0; |
| 600 | virtual status_t setPreferredMicrophoneFieldDimension(float zoom) |
| 601 | EXCLUDES_ThreadBase_Mutex = 0; |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 602 | |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 603 | virtual void addPatchTrack(const sp<IAfPatchRecord>& record) |
| 604 | EXCLUDES_ThreadBase_Mutex = 0; |
| 605 | virtual void deletePatchTrack(const sp<IAfPatchRecord>& record) |
| 606 | EXCLUDES_ThreadBase_Mutex = 0; |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 607 | virtual bool fastTrackAvailable() const = 0; |
| 608 | virtual void setFastTrackAvailable(bool available) = 0; |
| 609 | |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 610 | virtual void setRecordSilenced(audio_port_handle_t portId, bool silenced) |
| 611 | EXCLUDES_ThreadBase_Mutex = 0; |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 612 | virtual bool hasFastCapture() const = 0; |
| 613 | |
Andy Hung | 3f49ebb | 2023-09-19 14:48:41 -0700 | [diff] [blame] | 614 | virtual void checkBtNrec() EXCLUDES_ThreadBase_Mutex = 0; |
| 615 | virtual uint32_t getInputFramesLost() const EXCLUDES_ThreadBase_Mutex = 0; |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 616 | |
| 617 | virtual status_t shareAudioHistory( |
| 618 | const std::string& sharedAudioPackageName, |
| 619 | audio_session_t sharedSessionId = AUDIO_SESSION_NONE, |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 620 | int64_t sharedAudioStartMs = -1) EXCLUDES_ThreadBase_Mutex = 0; |
| 621 | virtual void resetAudioHistory_l() REQUIRES(mutex()) = 0; |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 622 | }; |
| 623 | |
Andy Hung | 7aa7d10 | 2023-07-07 15:58:48 -0700 | [diff] [blame] | 624 | class IAfMmapThread : public virtual IAfThreadBase { |
| 625 | public: |
| 626 | // createIAudioTrackAdapter() is a static constructor which creates an |
| 627 | // MmapStreamInterface AIDL interface adapter from the MmapThread object that |
| 628 | // may be passed back to the client. |
| 629 | // |
| 630 | // Only one AIDL MmapStreamInterface interface adapter should be created per MmapThread. |
| 631 | static sp<MmapStreamInterface> createMmapStreamInterfaceAdapter( |
| 632 | const sp<IAfMmapThread>& mmapThread); |
| 633 | |
| 634 | virtual void configure( |
| 635 | const audio_attributes_t* attr, |
| 636 | audio_stream_type_t streamType, |
| 637 | audio_session_t sessionId, |
| 638 | const sp<MmapStreamCallback>& callback, |
| 639 | audio_port_handle_t deviceId, |
Andy Hung | 3f49ebb | 2023-09-19 14:48:41 -0700 | [diff] [blame] | 640 | audio_port_handle_t portId) EXCLUDES_ThreadBase_Mutex = 0; |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 641 | virtual void disconnect() EXCLUDES_ThreadBase_Mutex = 0; |
Andy Hung | 7aa7d10 | 2023-07-07 15:58:48 -0700 | [diff] [blame] | 642 | |
| 643 | // MmapStreamInterface handling (see adapter) |
| 644 | virtual status_t createMmapBuffer( |
Andy Hung | 3f49ebb | 2023-09-19 14:48:41 -0700 | [diff] [blame] | 645 | int32_t minSizeFrames, struct audio_mmap_buffer_info* info) |
| 646 | EXCLUDES_ThreadBase_Mutex = 0; |
| 647 | virtual status_t getMmapPosition(struct audio_mmap_position* position) const |
| 648 | EXCLUDES_ThreadBase_Mutex = 0; |
Andy Hung | 7aa7d10 | 2023-07-07 15:58:48 -0700 | [diff] [blame] | 649 | virtual status_t start( |
| 650 | const AudioClient& client, const audio_attributes_t* attr, |
Andy Hung | 3f49ebb | 2023-09-19 14:48:41 -0700 | [diff] [blame] | 651 | audio_port_handle_t* handle) EXCLUDES_ThreadBase_Mutex = 0; |
| 652 | virtual status_t stop(audio_port_handle_t handle) EXCLUDES_ThreadBase_Mutex = 0; |
| 653 | virtual status_t standby() EXCLUDES_ThreadBase_Mutex = 0; |
| 654 | virtual status_t getExternalPosition(uint64_t* position, int64_t* timeNanos) const |
| 655 | EXCLUDES_ThreadBase_Mutex = 0; |
| 656 | virtual status_t reportData(const void* buffer, size_t frameCount) |
| 657 | EXCLUDES_ThreadBase_Mutex = 0; |
Andy Hung | 7aa7d10 | 2023-07-07 15:58:48 -0700 | [diff] [blame] | 658 | |
Andy Hung | 99b1ba6 | 2023-07-14 11:00:08 -0700 | [diff] [blame] | 659 | // TODO(b/291317898) move to IAfThreadBase? |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 660 | virtual void invalidateTracks(std::set<audio_port_handle_t>& portIds) |
| 661 | EXCLUDES_ThreadBase_Mutex = 0; |
Andy Hung | 7aa7d10 | 2023-07-07 15:58:48 -0700 | [diff] [blame] | 662 | |
Andy Hung | 99b1ba6 | 2023-07-14 11:00:08 -0700 | [diff] [blame] | 663 | // Sets the UID records silence - TODO(b/291317898) move to IAfMmapCaptureThread |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 664 | virtual void setRecordSilenced(audio_port_handle_t portId, bool silenced) |
| 665 | EXCLUDES_ThreadBase_Mutex = 0; |
Andy Hung | 7aa7d10 | 2023-07-07 15:58:48 -0700 | [diff] [blame] | 666 | |
| 667 | virtual sp<IAfMmapPlaybackThread> asIAfMmapPlaybackThread() { return nullptr; } |
| 668 | virtual sp<IAfMmapCaptureThread> asIAfMmapCaptureThread() { return nullptr; } |
| 669 | }; |
| 670 | |
| 671 | class IAfMmapPlaybackThread : public virtual IAfMmapThread, public virtual VolumeInterface { |
| 672 | public: |
Andy Hung | ee58e4a | 2023-07-07 13:47:37 -0700 | [diff] [blame] | 673 | static sp<IAfMmapPlaybackThread> create( |
Andy Hung | 583043b | 2023-07-17 17:05:00 -0700 | [diff] [blame] | 674 | const sp<IAfThreadCallback>& afThreadCallback, audio_io_handle_t id, |
| 675 | AudioHwDevice* hwDev, AudioStreamOut* output, bool systemReady); |
Andy Hung | ee58e4a | 2023-07-07 13:47:37 -0700 | [diff] [blame] | 676 | |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 677 | virtual AudioStreamOut* clearOutput() EXCLUDES_ThreadBase_Mutex = 0; |
Andy Hung | 7aa7d10 | 2023-07-07 15:58:48 -0700 | [diff] [blame] | 678 | }; |
| 679 | |
| 680 | class IAfMmapCaptureThread : public virtual IAfMmapThread { |
| 681 | public: |
Andy Hung | ee58e4a | 2023-07-07 13:47:37 -0700 | [diff] [blame] | 682 | static sp<IAfMmapCaptureThread> create( |
Andy Hung | 583043b | 2023-07-17 17:05:00 -0700 | [diff] [blame] | 683 | const sp<IAfThreadCallback>& afThreadCallback, audio_io_handle_t id, |
| 684 | AudioHwDevice* hwDev, AudioStreamIn* input, bool systemReady); |
Andy Hung | ee58e4a | 2023-07-07 13:47:37 -0700 | [diff] [blame] | 685 | |
Andy Hung | ab65b18 | 2023-09-06 19:41:47 -0700 | [diff] [blame] | 686 | virtual AudioStreamIn* clearInput() EXCLUDES_ThreadBase_Mutex = 0; |
Andy Hung | 7aa7d10 | 2023-07-07 15:58:48 -0700 | [diff] [blame] | 687 | }; |
| 688 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 689 | } // namespace android |