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