/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include <android/media/IAudioTrackCallback.h>
#include <android/media/IEffectClient.h>
#include <audiomanager/IAudioManager.h>
#include <audio_utils/mutex.h>
#include <audio_utils/MelProcessor.h>
#include <binder/MemoryDealer.h>
#include <datapath/AudioStreamIn.h>
#include <datapath/AudioStreamOut.h>
#include <datapath/VolumeInterface.h>
#include <fastpath/FastMixerDumpState.h>
#include <media/DeviceDescriptorBase.h>
#include <media/MmapStreamInterface.h>
#include <media/audiohal/StreamHalInterface.h>
#include <media/nblog/NBLog.h>
#include <timing/SyncEvent.h>
#include <utils/RefBase.h>
#include <vibrator/ExternalVibration.h>

#include <optional>

namespace android {

class IAfDirectOutputThread;
class IAfDuplicatingThread;
class IAfMmapCaptureThread;
class IAfMmapPlaybackThread;
class IAfPlaybackThread;
class IAfRecordThread;

class IAfEffectChain;
class IAfEffectHandle;
class IAfEffectModule;
class IAfPatchPanel;
class IAfPatchRecord;
class IAfPatchTrack;
class IAfRecordTrack;
class IAfTrack;
class IAfTrackBase;
class Client;
class MelReporter;

// Used internally for Threads.cpp and AudioFlinger.cpp
struct stream_type_t {
    float volume = 1.f;
    bool mute = false;
};

// Note this is exposed through IAfThreadBase::afThreadCallback()
// and hence may be used by the Effect / Track framework.
class IAfThreadCallback : public virtual RefBase {
public:
    virtual audio_utils::mutex& mutex() const
            RETURN_CAPABILITY(audio_utils::AudioFlinger_Mutex) = 0;
    virtual bool isNonOffloadableGlobalEffectEnabled_l() const
            REQUIRES(mutex()) EXCLUDES_ThreadBase_Mutex = 0;  // Tracks
    virtual audio_unique_id_t nextUniqueId(audio_unique_id_use_t use) = 0;
    virtual bool btNrecIsOff() const = 0;
    virtual float masterVolume_l() const
            REQUIRES(mutex()) = 0;
    virtual bool masterMute_l() const
            REQUIRES(mutex()) = 0;
    virtual float getMasterBalance_l() const
            REQUIRES(mutex()) = 0;
    virtual bool streamMute_l(audio_stream_type_t stream) const
            REQUIRES(mutex()) = 0;
    virtual audio_mode_t getMode() const = 0;
    virtual bool isLowRamDevice() const = 0;
    virtual bool isAudioPolicyReady() const = 0;  // Effects
    virtual uint32_t getScreenState() const = 0;
    virtual std::optional<media::AudioVibratorInfo> getDefaultVibratorInfo_l() const
            REQUIRES(mutex()) = 0;
    virtual const sp<IAfPatchPanel>& getPatchPanel() const = 0;
    virtual const sp<MelReporter>& getMelReporter() const = 0;
    virtual const sp<EffectsFactoryHalInterface>& getEffectsFactoryHal() const = 0;
    virtual sp<IAudioManager> getOrCreateAudioManager() = 0;  // Tracks

    virtual bool updateOrphanEffectChains(const sp<IAfEffectModule>& effect)
            EXCLUDES_AudioFlinger_Mutex = 0;
    virtual status_t moveEffectChain_ll(audio_session_t sessionId,
            IAfPlaybackThread* srcThread, IAfPlaybackThread* dstThread)
            REQUIRES(mutex(), audio_utils::ThreadBase_Mutex) = 0;

    virtual void requestLogMerge() = 0;
    virtual sp<NBLog::Writer> newWriter_l(size_t size, const char *name)
            REQUIRES(mutex()) = 0;
    virtual void unregisterWriter(const sp<NBLog::Writer>& writer) = 0;

    virtual sp<audioflinger::SyncEvent> createSyncEvent(AudioSystem::sync_event_t type,
            audio_session_t triggerSession,
            audio_session_t listenerSession,
            const audioflinger::SyncEventCallback& callBack,
            const wp<IAfTrackBase>& cookie)
            EXCLUDES_AudioFlinger_Mutex = 0;

    // Hold either AudioFlinger::mutex or ThreadBase::mutex
    virtual void ioConfigChanged_l(audio_io_config_event_t event,
            const sp<AudioIoDescriptor>& ioDesc,
            pid_t pid = 0) EXCLUDES_AudioFlinger_ClientMutex = 0;
    virtual void onNonOffloadableGlobalEffectEnable() EXCLUDES_AudioFlinger_Mutex = 0;
    virtual void onSupportedLatencyModesChanged(
            audio_io_handle_t output, const std::vector<audio_latency_mode_t>& modes)
            EXCLUDES_AudioFlinger_ClientMutex = 0;
};

class IAfThreadBase : public virtual RefBase {
public:
    enum type_t {
        MIXER,          // Thread class is MixerThread
        DIRECT,         // Thread class is DirectOutputThread
        DUPLICATING,    // Thread class is DuplicatingThread
        RECORD,         // Thread class is RecordThread
        OFFLOAD,        // Thread class is OffloadThread
        MMAP_PLAYBACK,  // Thread class for MMAP playback stream
        MMAP_CAPTURE,   // Thread class for MMAP capture stream
        SPATIALIZER,    //
        BIT_PERFECT,    // Thread class for BitPerfectThread
        // When adding a value, also update IAfThreadBase::threadTypeToString()
    };

    static const char* threadTypeToString(type_t type);
    static std::string formatToString(audio_format_t format);  // compliant for MediaMetrics
    static bool isValidPcmSinkChannelMask(audio_channel_mask_t channelMask);
    static bool isValidPcmSinkFormat(audio_format_t format);

    virtual status_t readyToRun() = 0;
    virtual void clearPowerManager() EXCLUDES_ThreadBase_Mutex = 0;
    virtual status_t initCheck() const = 0;
    virtual type_t type() const = 0;
    virtual bool isDuplicating() const = 0;
    virtual audio_io_handle_t id() const = 0;
    virtual uint32_t sampleRate() const = 0;
    virtual audio_channel_mask_t channelMask() const = 0;
    virtual audio_channel_mask_t mixerChannelMask() const = 0;
    virtual audio_format_t format() const = 0;
    virtual uint32_t channelCount() const = 0;

    // Called by AudioFlinger::frameCount(audio_io_handle_t output) and effects,
    // and returns the [normal mix] buffer's frame count.
    virtual size_t frameCount() const = 0;
    virtual audio_channel_mask_t hapticChannelMask() const = 0;
    virtual uint32_t hapticChannelCount() const = 0;
    virtual uint32_t latency_l() const = 0;  // NO_THREAD_SAFETY_ANALYSIS
    virtual void setVolumeForOutput_l(float left, float right) const REQUIRES(mutex()) = 0;

    // Return's the HAL's frame count i.e. fast mixer buffer size.
    virtual size_t frameCountHAL() const = 0;
    virtual size_t frameSize() const = 0;
    // Should be "virtual status_t requestExitAndWait()" and override same
    // method in Thread, but Thread::requestExitAndWait() is not yet virtual.
    virtual void exit() EXCLUDES_ThreadBase_Mutex = 0;
    virtual bool checkForNewParameter_l(const String8& keyValuePair, status_t& status)
             REQUIRES(mutex()) = 0;
    virtual status_t setParameters(const String8& keyValuePairs) EXCLUDES_ThreadBase_Mutex = 0;
    virtual String8 getParameters(const String8& keys) EXCLUDES_ThreadBase_Mutex = 0;
    virtual void ioConfigChanged_l(
            audio_io_config_event_t event, pid_t pid = 0,
            audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE)
            /* holds either AF::mutex or TB::mutex */ = 0;

    // sendConfigEvent_l() must be called with ThreadBase::mLock held
    // Can temporarily release the lock if waiting for a reply from
    // processConfigEvents_l().
    // status_t sendConfigEvent_l(sp<ConfigEvent>& event);
    virtual void sendIoConfigEvent(
            audio_io_config_event_t event, pid_t pid = 0,
            audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE) EXCLUDES_ThreadBase_Mutex = 0;
    virtual void sendIoConfigEvent_l(
            audio_io_config_event_t event, pid_t pid = 0,
            audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE) REQUIRES(mutex()) = 0;
    virtual void sendPrioConfigEvent(pid_t pid, pid_t tid, int32_t prio, bool forApp)
            EXCLUDES_ThreadBase_Mutex = 0;
    virtual void sendPrioConfigEvent_l(pid_t pid, pid_t tid, int32_t prio, bool forApp)
            REQUIRES(mutex()) = 0;
    virtual status_t sendSetParameterConfigEvent_l(const String8& keyValuePair)
            REQUIRES(mutex()) = 0;
    virtual status_t sendCreateAudioPatchConfigEvent(
            const struct audio_patch* patch, audio_patch_handle_t* handle)
            EXCLUDES_ThreadBase_Mutex = 0;
    virtual status_t sendReleaseAudioPatchConfigEvent(audio_patch_handle_t handle)
            EXCLUDES_ThreadBase_Mutex = 0;
    virtual status_t sendUpdateOutDeviceConfigEvent(
            const DeviceDescriptorBaseVector& outDevices) EXCLUDES_ThreadBase_Mutex = 0;
    virtual void sendResizeBufferConfigEvent_l(int32_t maxSharedAudioHistoryMs)
            REQUIRES(mutex()) = 0;
    virtual void sendCheckOutputStageEffectsEvent() EXCLUDES_ThreadBase_Mutex = 0;
    virtual void sendCheckOutputStageEffectsEvent_l()
            REQUIRES(mutex()) = 0;
    virtual void sendHalLatencyModesChangedEvent_l()
            REQUIRES(mutex()) = 0;

    virtual void processConfigEvents_l()
            REQUIRES(mutex()) = 0;
    virtual void setCheckOutputStageEffects() = 0;  // no mutex needed
    virtual void cacheParameters_l()
            REQUIRES(mutex()) = 0;
    virtual status_t createAudioPatch_l(
            const struct audio_patch* patch, audio_patch_handle_t* handle)
            REQUIRES(mutex()) = 0;
    virtual status_t releaseAudioPatch_l(const audio_patch_handle_t handle)
            REQUIRES(mutex()) = 0;
    virtual void updateOutDevices(const DeviceDescriptorBaseVector& outDevices)
            EXCLUDES_ThreadBase_Mutex = 0;
    virtual void toAudioPortConfig(struct audio_port_config* config)
            EXCLUDES_ThreadBase_Mutex = 0;
    virtual void resizeInputBuffer_l(int32_t maxSharedAudioHistoryMs)
            REQUIRES(mutex()) = 0;

    // see note at declaration of mStandby, mOutDevice and mInDevice
    virtual bool inStandby() const = 0;
    virtual const DeviceTypeSet outDeviceTypes_l() const REQUIRES(mutex()) = 0;
    virtual audio_devices_t inDeviceType_l() const REQUIRES(mutex()) = 0;
    virtual DeviceTypeSet getDeviceTypes_l() const REQUIRES(mutex()) = 0;
    virtual const AudioDeviceTypeAddrVector& outDeviceTypeAddrs() const = 0;
    virtual const AudioDeviceTypeAddr& inDeviceTypeAddr() const = 0;
    virtual bool isOutput() const = 0;
    virtual bool isOffloadOrMmap() const = 0;
    virtual sp<StreamHalInterface> stream() const = 0;
    virtual sp<IAfEffectHandle> createEffect_l(
            const sp<Client>& client,
            const sp<media::IEffectClient>& effectClient,
            int32_t priority,
            audio_session_t sessionId,
            effect_descriptor_t* desc,
            int* enabled,
            status_t* status /*non-NULL*/,
            bool pinned,
            bool probe,
            bool notifyFramesProcessed)
            REQUIRES(audio_utils::AudioFlinger_Mutex) EXCLUDES_ThreadBase_Mutex = 0;

    // return values for hasAudioSession (bit field)
    enum effect_state {
        EFFECT_SESSION = 0x1,       // the audio session corresponds to at least one
                                    // effect
        TRACK_SESSION = 0x2,        // the audio session corresponds to at least one
                                    // track
        FAST_SESSION = 0x4,         // the audio session corresponds to at least one
                                    // fast track
        SPATIALIZED_SESSION = 0x8,  // the audio session corresponds to at least one
                                    // spatialized track
        BIT_PERFECT_SESSION = 0x10  // the audio session corresponds to at least one
                                    // bit-perfect track
    };

    // get effect chain corresponding to session Id.
    virtual sp<IAfEffectChain> getEffectChain(audio_session_t sessionId) const
            EXCLUDES_ThreadBase_Mutex = 0;
    // same as getEffectChain() but must be called with ThreadBase mutex locked
    virtual sp<IAfEffectChain> getEffectChain_l(audio_session_t sessionId) const
            REQUIRES(mutex()) = 0;
    virtual std::vector<int> getEffectIds_l(audio_session_t sessionId) const
            REQUIRES(mutex()) = 0;
    // add an effect chain to the chain list (mEffectChains)
    virtual status_t addEffectChain_l(const sp<IAfEffectChain>& chain)
            REQUIRES(mutex()) = 0;
    // remove an effect chain from the chain list (mEffectChains)
    virtual size_t removeEffectChain_l(const sp<IAfEffectChain>& chain)
            REQUIRES(mutex()) = 0;
    // lock all effect chains Mutexes. Must be called before releasing the
    // ThreadBase mutex before processing the mixer and effects. This guarantees the
    // integrity of the chains during the process.
    // Also sets the parameter 'effectChains' to current value of mEffectChains.
    virtual void lockEffectChains_l(Vector<sp<IAfEffectChain>>& effectChains)
            REQUIRES(mutex()) = 0;
    // unlock effect chains after process
    virtual void unlockEffectChains(const Vector<sp<IAfEffectChain>>& effectChains)
            EXCLUDES_ThreadBase_Mutex = 0;
    // get a copy of mEffectChains vector
    virtual Vector<sp<IAfEffectChain>> getEffectChains_l() const
            REQUIRES(mutex()) = 0;
    // set audio mode to all effect chains
    virtual void setMode(audio_mode_t mode)
            EXCLUDES_ThreadBase_Mutex = 0;
    // get effect module with corresponding ID on specified audio session
    virtual sp<IAfEffectModule> getEffect(audio_session_t sessionId, int effectId) const
            EXCLUDES_ThreadBase_Mutex = 0;
    virtual sp<IAfEffectModule> getEffect_l(audio_session_t sessionId, int effectId) const
            REQUIRES(mutex()) = 0;
    // add and effect module. Also creates the effect chain is none exists for
    // the effects audio session. Only called in a context of moving an effect
    // from one thread to another
    virtual status_t addEffect_ll(const sp<IAfEffectModule>& effect)
            REQUIRES(audio_utils::AudioFlinger_Mutex, mutex()) = 0;
    // remove and effect module. Also removes the effect chain is this was the last
    // effect
    virtual void removeEffect_l(const sp<IAfEffectModule>& effect, bool release = false)
            REQUIRES(mutex()) = 0;
    // disconnect an effect handle from module and destroy module if last handle
    virtual void disconnectEffectHandle(IAfEffectHandle* handle, bool unpinIfLast)
            EXCLUDES_ThreadBase_Mutex = 0;
    // detach all tracks connected to an auxiliary effect
    virtual void detachAuxEffect_l(int effectId) REQUIRES(mutex()) = 0;
    // returns a combination of:
    // - EFFECT_SESSION if effects on this audio session exist in one chain
    // - TRACK_SESSION if tracks on this audio session exist
    // - FAST_SESSION if fast tracks on this audio session exist
    // - SPATIALIZED_SESSION if spatialized tracks on this audio session exist
    virtual uint32_t hasAudioSession_l(audio_session_t sessionId) const REQUIRES(mutex()) = 0;
    virtual uint32_t hasAudioSession(audio_session_t sessionId) const
            EXCLUDES_ThreadBase_Mutex = 0;

    // the value returned by default implementation is not important as the
    // strategy is only meaningful for PlaybackThread which implements this method
    virtual product_strategy_t getStrategyForSession_l(audio_session_t sessionId) const
            REQUIRES(mutex()) = 0;

    // check if some effects must be suspended/restored when an effect is enabled
    // or disabled
    virtual void checkSuspendOnEffectEnabled(
            bool enabled, audio_session_t sessionId, bool threadLocked)
            EXCLUDES_ThreadBase_Mutex = 0;

    virtual status_t setSyncEvent(const sp<audioflinger::SyncEvent>& event)
            EXCLUDES_ThreadBase_Mutex = 0;
    // internally static, perhaps make static member.
    virtual bool isValidSyncEvent(const sp<audioflinger::SyncEvent>& event) const = 0;

    // Return a reference to a per-thread heap which can be used to allocate IMemory
    // objects that will be read-only to client processes, read/write to mediaserver,
    // and shared by all client processes of the thread.
    // The heap is per-thread rather than common across all threads, because
    // clients can't be trusted not to modify the offset of the IMemory they receive.
    // If a thread does not have such a heap, this method returns 0.
    virtual sp<MemoryDealer> readOnlyHeap() const = 0;

    virtual sp<IMemory> pipeMemory() const = 0;

    virtual void systemReady() EXCLUDES_ThreadBase_Mutex = 0;

    // checkEffectCompatibility_l() must be called with ThreadBase::mLock held
    virtual status_t checkEffectCompatibility_l(
            const effect_descriptor_t* desc, audio_session_t sessionId) REQUIRES(mutex()) = 0;

    virtual void broadcast_l() REQUIRES(mutex()) = 0;

    virtual bool isTimestampCorrectionEnabled_l() const REQUIRES(mutex()) = 0;

    virtual bool isMsdDevice() const = 0;

    virtual void dump(int fd, const Vector<String16>& args) EXCLUDES_ThreadBase_Mutex = 0;

    // deliver stats to mediametrics.
    virtual void sendStatistics(bool force) EXCLUDES_ThreadBase_Mutex = 0;

    virtual audio_utils::mutex& mutex() const
            RETURN_CAPABILITY(audio_utils::ThreadBase_Mutex) = 0;

    virtual void onEffectEnable(const sp<IAfEffectModule>& effect) EXCLUDES_ThreadBase_Mutex = 0;
    virtual void onEffectDisable() EXCLUDES_ThreadBase_Mutex = 0;

    // invalidateTracksForAudioSession_l must be called with holding mLock.
    virtual void invalidateTracksForAudioSession_l(audio_session_t sessionId) const
            REQUIRES(mutex()) = 0;
    // Invalidate all the tracks with the given audio session.
    virtual void invalidateTracksForAudioSession(audio_session_t sessionId) const
            EXCLUDES_ThreadBase_Mutex = 0;

    virtual bool isStreamInitialized() const = 0;
    virtual void startMelComputation_l(const sp<audio_utils::MelProcessor>& processor)
            REQUIRES(audio_utils::AudioFlinger_Mutex) = 0;
    virtual void stopMelComputation_l()
            REQUIRES(audio_utils::AudioFlinger_Mutex) = 0;

    virtual product_strategy_t getStrategyForStream(audio_stream_type_t stream) const
            EXCLUDES_AUDIO_ALL = 0;

    virtual void setEffectSuspended_l(
            const effect_uuid_t* type, bool suspend, audio_session_t sessionId)
            REQUIRES(mutex()) = 0;

    // Dynamic cast to derived interface
    virtual sp<IAfDirectOutputThread> asIAfDirectOutputThread() { return nullptr; }
    virtual sp<IAfDuplicatingThread> asIAfDuplicatingThread() { return nullptr; }
    virtual sp<IAfPlaybackThread> asIAfPlaybackThread() { return nullptr; }
    virtual sp<IAfRecordThread> asIAfRecordThread() { return nullptr; }
    virtual IAfThreadCallback* afThreadCallback() const = 0;
};

class IAfPlaybackThread : public virtual IAfThreadBase, public virtual VolumeInterface {
public:
    static sp<IAfPlaybackThread> createBitPerfectThread(
            const sp<IAfThreadCallback>& afThreadCallback, AudioStreamOut* output,
            audio_io_handle_t id, bool systemReady);

    static sp<IAfPlaybackThread> createDirectOutputThread(
            const sp<IAfThreadCallback>& afThreadCallback, AudioStreamOut* output,
            audio_io_handle_t id, bool systemReady, const audio_offload_info_t& offloadInfo);

    static sp<IAfPlaybackThread> createMixerThread(
            const sp<IAfThreadCallback>& afThreadCallback, AudioStreamOut* output,
            audio_io_handle_t id, bool systemReady, type_t type = MIXER,
            audio_config_base_t* mixerConfig = nullptr);

    static sp<IAfPlaybackThread> createOffloadThread(
            const sp<IAfThreadCallback>& afThreadCallback, AudioStreamOut* output,
            audio_io_handle_t id, bool systemReady, const audio_offload_info_t& offloadInfo);

    static sp<IAfPlaybackThread> createSpatializerThread(
            const sp<IAfThreadCallback>& afThreadCallback, AudioStreamOut* output,
            audio_io_handle_t id, bool systemReady, audio_config_base_t* mixerConfig);

    static constexpr int8_t kMaxTrackStopRetriesOffload = 2;

    enum mixer_state {
        MIXER_IDLE,            // no active tracks
        MIXER_TRACKS_ENABLED,  // at least one active track, but no track has any data ready
        MIXER_TRACKS_READY,    // at least one active track, and at least one track has data
        MIXER_DRAIN_TRACK,     // drain currently playing track
        MIXER_DRAIN_ALL,       // fully drain the hardware
        // standby mode does not have an enum value
        // suspend by audio policy manager is orthogonal to mixer state
    };

    // return estimated latency in milliseconds, as reported by HAL
    virtual uint32_t latency() const = 0;  // should be in IAfThreadBase?

    virtual uint32_t& fastTrackAvailMask_l() REQUIRES(mutex()) = 0;

    virtual sp<IAfTrack> createTrack_l(
            const sp<Client>& client,
            audio_stream_type_t streamType,
            const audio_attributes_t& attr,
            uint32_t* sampleRate,
            audio_format_t format,
            audio_channel_mask_t channelMask,
            size_t* pFrameCount,
            size_t* pNotificationFrameCount,
            uint32_t notificationsPerBuffer,
            float speed,
            const sp<IMemory>& sharedBuffer,
            audio_session_t sessionId,
            audio_output_flags_t* flags,
            pid_t creatorPid,
            const AttributionSourceState& attributionSource,
            pid_t tid,
            status_t* status /*non-NULL*/,
            audio_port_handle_t portId,
            const sp<media::IAudioTrackCallback>& callback,
            bool isSpatialized,
            bool isBitPerfect,
            audio_output_flags_t* afTrackFlags)
            REQUIRES(audio_utils::AudioFlinger_Mutex) = 0;

    virtual status_t addTrack_l(const sp<IAfTrack>& track) REQUIRES(mutex()) = 0;
    virtual bool destroyTrack_l(const sp<IAfTrack>& track) REQUIRES(mutex()) = 0;
    virtual bool isTrackActive(const sp<IAfTrack>& track) const REQUIRES(mutex()) = 0;
    virtual void addOutputTrack_l(const sp<IAfTrack>& track) REQUIRES(mutex()) = 0;

    virtual AudioStreamOut* getOutput_l() const REQUIRES(mutex()) = 0;
    virtual AudioStreamOut* getOutput() const EXCLUDES_ThreadBase_Mutex = 0;
    virtual AudioStreamOut* clearOutput() EXCLUDES_ThreadBase_Mutex = 0;

    // a very large number of suspend() will eventually wraparound, but unlikely
    virtual void suspend() = 0;
    virtual void restore() = 0;
    virtual bool isSuspended() const = 0;
    virtual status_t getRenderPosition(uint32_t* halFrames, uint32_t* dspFrames) const
            EXCLUDES_ThreadBase_Mutex = 0;
    // Consider also removing and passing an explicit mMainBuffer initialization
    // parameter to AF::IAfTrack::Track().
    virtual float* sinkBuffer() const = 0;

    virtual status_t attachAuxEffect(const sp<IAfTrack>& track, int EffectId)
            EXCLUDES_ThreadBase_Mutex = 0;
    virtual status_t attachAuxEffect_l(const sp<IAfTrack>& track, int EffectId)
            REQUIRES(mutex()) = 0;

    // called with AudioFlinger lock held
    virtual bool invalidateTracks_l(audio_stream_type_t streamType) REQUIRES(mutex()) = 0;
    virtual bool invalidateTracks_l(std::set<audio_port_handle_t>& portIds) REQUIRES(mutex()) = 0;
    virtual void invalidateTracks(audio_stream_type_t streamType)
            EXCLUDES_ThreadBase_Mutex = 0;
    // Invalidate tracks by a set of port ids. The port id will be removed from
    // the given set if the corresponding track is found and invalidated.
    virtual void invalidateTracks(std::set<audio_port_handle_t>& portIds)
            EXCLUDES_ThreadBase_Mutex = 0;

    virtual status_t getTimestamp_l(AudioTimestamp& timestamp) REQUIRES(mutex()) = 0;
    virtual void addPatchTrack(const sp<IAfPatchTrack>& track) EXCLUDES_ThreadBase_Mutex = 0;
    virtual void deletePatchTrack(const sp<IAfPatchTrack>& track) EXCLUDES_ThreadBase_Mutex = 0;

    // Return the asynchronous signal wait time.
    virtual int64_t computeWaitTimeNs_l() const REQUIRES(mutex()) = 0;
    // returns true if the track is allowed to be added to the thread.
    virtual bool isTrackAllowed_l(
            audio_channel_mask_t channelMask, audio_format_t format, audio_session_t sessionId,
            uid_t uid) const REQUIRES(mutex()) = 0;

    virtual bool supportsHapticPlayback() const = 0;

    virtual void setDownStreamPatch(const struct audio_patch* patch)
            EXCLUDES_ThreadBase_Mutex = 0;

    virtual IAfTrack* getTrackById_l(audio_port_handle_t trackId) REQUIRES(mutex()) = 0;

    virtual bool hasMixer() const = 0;

    virtual status_t setRequestedLatencyMode(audio_latency_mode_t mode) = 0;

    virtual status_t getSupportedLatencyModes(std::vector<audio_latency_mode_t>* modes)
           EXCLUDES_ThreadBase_Mutex = 0;

    virtual status_t setBluetoothVariableLatencyEnabled(bool enabled) = 0;

    virtual void setStandby() EXCLUDES_ThreadBase_Mutex = 0;
    virtual void setStandby_l() REQUIRES(mutex()) = 0;
    virtual bool waitForHalStart() EXCLUDES_ThreadBase_Mutex = 0;

    virtual bool hasFastMixer() const = 0;
    virtual FastTrackUnderruns getFastTrackUnderruns(size_t fastIndex) const = 0;
    virtual const std::atomic<int64_t>& framesWritten() const = 0;

    virtual bool usesHwAvSync() const = 0;
};

class IAfDirectOutputThread : public virtual IAfPlaybackThread {
public:
    virtual status_t selectPresentation(int presentationId, int programId) = 0;
};

class IAfDuplicatingThread : public virtual IAfPlaybackThread {
public:
    static sp<IAfDuplicatingThread> create(
            const sp<IAfThreadCallback>& afThreadCallback, IAfPlaybackThread* mainThread,
            audio_io_handle_t id, bool systemReady);

    virtual void addOutputTrack(IAfPlaybackThread* thread) EXCLUDES_ThreadBase_Mutex = 0;
    virtual uint32_t waitTimeMs() const = 0;
    virtual void removeOutputTrack(IAfPlaybackThread* thread) EXCLUDES_ThreadBase_Mutex = 0;
};

class IAfRecordThread : public virtual IAfThreadBase {
public:
    static sp<IAfRecordThread> create(
            const sp<IAfThreadCallback>& afThreadCallback, AudioStreamIn* input,
            audio_io_handle_t id, bool systemReady);

    virtual sp<IAfRecordTrack> createRecordTrack_l(
            const sp<Client>& client,
            const audio_attributes_t& attr,
            uint32_t* pSampleRate,
            audio_format_t format,
            audio_channel_mask_t channelMask,
            size_t* pFrameCount,
            audio_session_t sessionId,
            size_t* pNotificationFrameCount,
            pid_t creatorPid,
            const AttributionSourceState& attributionSource,
            audio_input_flags_t* flags,
            pid_t tid,
            status_t* status /*non-NULL*/,
            audio_port_handle_t portId,
            int32_t maxSharedAudioHistoryMs)
            REQUIRES(audio_utils::AudioFlinger_Mutex) EXCLUDES_ThreadBase_Mutex = 0;
    virtual void destroyTrack_l(const sp<IAfRecordTrack>& track) REQUIRES(mutex()) = 0;
    virtual void removeTrack_l(const sp<IAfRecordTrack>& track) REQUIRES(mutex()) = 0;

    virtual status_t start(
            IAfRecordTrack* recordTrack, AudioSystem::sync_event_t event,
            audio_session_t triggerSession) EXCLUDES_ThreadBase_Mutex = 0;

    // ask the thread to stop the specified track, and
    // return true if the caller should then do it's part of the stopping process
    virtual bool stop(IAfRecordTrack* recordTrack) EXCLUDES_ThreadBase_Mutex = 0;

    // NO_THREAD_SAFETY_ANALYSIS: consider atomics
    virtual AudioStreamIn* getInput() const = 0;
    virtual AudioStreamIn* clearInput() = 0;

    virtual status_t getActiveMicrophones(
            std::vector<media::MicrophoneInfoFw>* activeMicrophones)
            const EXCLUDES_ThreadBase_Mutex = 0;
    virtual status_t setPreferredMicrophoneDirection(audio_microphone_direction_t direction)
            EXCLUDES_ThreadBase_Mutex = 0;
    virtual status_t setPreferredMicrophoneFieldDimension(float zoom)
            EXCLUDES_ThreadBase_Mutex = 0;

    virtual void addPatchTrack(const sp<IAfPatchRecord>& record)
            EXCLUDES_ThreadBase_Mutex = 0;
    virtual void deletePatchTrack(const sp<IAfPatchRecord>& record)
            EXCLUDES_ThreadBase_Mutex = 0;
    virtual bool fastTrackAvailable() const = 0;
    virtual void setFastTrackAvailable(bool available) = 0;

    virtual void setRecordSilenced(audio_port_handle_t portId, bool silenced)
            EXCLUDES_ThreadBase_Mutex = 0;
    virtual bool hasFastCapture() const = 0;

    virtual void checkBtNrec() EXCLUDES_ThreadBase_Mutex = 0;
    virtual uint32_t getInputFramesLost() const EXCLUDES_ThreadBase_Mutex = 0;

    virtual status_t shareAudioHistory(
            const std::string& sharedAudioPackageName,
            audio_session_t sharedSessionId = AUDIO_SESSION_NONE,
            int64_t sharedAudioStartMs = -1) EXCLUDES_ThreadBase_Mutex = 0;
    virtual void resetAudioHistory_l() REQUIRES(mutex()) = 0;
};

class IAfMmapThread : public virtual IAfThreadBase {
public:
    // createIAudioTrackAdapter() is a static constructor which creates an
    // MmapStreamInterface AIDL interface adapter from the MmapThread object that
    // may be passed back to the client.
    //
    // Only one AIDL MmapStreamInterface interface adapter should be created per MmapThread.
    static sp<MmapStreamInterface> createMmapStreamInterfaceAdapter(
            const sp<IAfMmapThread>& mmapThread);

    virtual void configure(
            const audio_attributes_t* attr,
            audio_stream_type_t streamType,
            audio_session_t sessionId,
            const sp<MmapStreamCallback>& callback,
            audio_port_handle_t deviceId,
            audio_port_handle_t portId) EXCLUDES_ThreadBase_Mutex = 0;
    virtual void disconnect() EXCLUDES_ThreadBase_Mutex = 0;

    // MmapStreamInterface handling (see adapter)
    virtual status_t createMmapBuffer(
            int32_t minSizeFrames, struct audio_mmap_buffer_info* info)
            EXCLUDES_ThreadBase_Mutex = 0;
    virtual status_t getMmapPosition(struct audio_mmap_position* position) const
            EXCLUDES_ThreadBase_Mutex = 0;
    virtual status_t start(
            const AudioClient& client, const audio_attributes_t* attr,
            audio_port_handle_t* handle) EXCLUDES_ThreadBase_Mutex = 0;
    virtual status_t stop(audio_port_handle_t handle) EXCLUDES_ThreadBase_Mutex = 0;
    virtual status_t standby() EXCLUDES_ThreadBase_Mutex = 0;
    virtual status_t getExternalPosition(uint64_t* position, int64_t* timeNanos) const
            EXCLUDES_ThreadBase_Mutex = 0;
    virtual status_t reportData(const void* buffer, size_t frameCount)
            EXCLUDES_ThreadBase_Mutex = 0;

    // TODO(b/291317898)  move to IAfThreadBase?
    virtual void invalidateTracks(std::set<audio_port_handle_t>& portIds)
            EXCLUDES_ThreadBase_Mutex = 0;

    // Sets the UID records silence - TODO(b/291317898)  move to IAfMmapCaptureThread
    virtual void setRecordSilenced(audio_port_handle_t portId, bool silenced)
            EXCLUDES_ThreadBase_Mutex = 0;

    virtual sp<IAfMmapPlaybackThread> asIAfMmapPlaybackThread() { return nullptr; }
    virtual sp<IAfMmapCaptureThread> asIAfMmapCaptureThread() { return nullptr; }
};

class IAfMmapPlaybackThread : public virtual IAfMmapThread, public virtual VolumeInterface {
public:
    static sp<IAfMmapPlaybackThread> create(
            const sp<IAfThreadCallback>& afThreadCallback, audio_io_handle_t id,
            AudioHwDevice* hwDev, AudioStreamOut* output, bool systemReady);

    virtual AudioStreamOut* clearOutput() EXCLUDES_ThreadBase_Mutex = 0;
};

class IAfMmapCaptureThread : public virtual IAfMmapThread {
public:
    static sp<IAfMmapCaptureThread> create(
            const sp<IAfThreadCallback>& afThreadCallback, audio_io_handle_t id,
            AudioHwDevice* hwDev, AudioStreamIn* input, bool systemReady);

    virtual AudioStreamIn* clearInput() EXCLUDES_ThreadBase_Mutex = 0;
};

}  // namespace android
