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