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