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