Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4d693a3a authored by Andy Hung's avatar Andy Hung
Browse files

AudioFlinger: Update Thread class includes

Test: atest AudioRecordTest AudioTrackTest
Test: Camera YouTube
Bug: 182392769
Bug: 292018229
Merged-In: I4f3792a5a270c45e788ff4f98cc3e04ee434d075
Change-Id: I4f3792a5a270c45e788ff4f98cc3e04ee434d075
parent f8ab469a
Loading
Loading
Loading
Loading
+0 −8
Original line number Original line Diff line number Diff line
@@ -254,14 +254,6 @@ class DevicesFactoryHalCallbackImpl : public DevicesFactoryHalCallback {


// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------


std::string formatToString(audio_format_t format) {
    std::string result;
    FormatConverter::toString(format, result);
    return result;
}

// ----------------------------------------------------------------------------

void AudioFlinger::instantiate() {
void AudioFlinger::instantiate() {
    sp<IServiceManager> sm(defaultServiceManager());
    sp<IServiceManager> sm(defaultServiceManager());
    sm->addService(String16(IAudioFlinger::DEFAULT_SERVICE_NAME),
    sm->addService(String16(IAudioFlinger::DEFAULT_SERVICE_NAME),
+0 −16
Original line number Original line Diff line number Diff line
@@ -151,11 +151,6 @@ class ServerProxy;


using android::content::AttributionSourceState;
using android::content::AttributionSourceState;


struct stream_type_t {
    float volume = 1.f;
    bool mute = false;
};

class AudioFlinger
class AudioFlinger
    : public AudioFlingerServerAdapter::Delegate  // IAudioFlinger client interface
    : public AudioFlingerServerAdapter::Delegate  // IAudioFlinger client interface
    , public IAfClientCallback
    , public IAfClientCallback
@@ -801,11 +796,6 @@ private:


    static inline constexpr const char *mMetricsId = AMEDIAMETRICS_KEY_AUDIO_FLINGER;
    static inline constexpr const char *mMetricsId = AMEDIAMETRICS_KEY_AUDIO_FLINGER;


public:
    // Keep in sync with java definition in media/java/android/media/AudioRecord.java
    static constexpr int32_t kMaxSharedAudioHistoryMs = 5000;
private:

    std::map<media::audio::common::AudioMMapPolicyType,
    std::map<media::audio::common::AudioMMapPolicyType,
             std::vector<media::audio::common::AudioMMapPolicyInfo>> mPolicyInfos;
             std::vector<media::audio::common::AudioMMapPolicyInfo>> mPolicyInfos;
    int32_t mAAudioBurstsPerBuffer = 0;
    int32_t mAAudioBurstsPerBuffer = 0;
@@ -818,12 +808,6 @@ private:
    std::atomic_bool mBluetoothLatencyModesEnabled;
    std::atomic_bool mBluetoothLatencyModesEnabled;
};
};


std::string formatToString(audio_format_t format);
std::string inputFlagsToString(audio_input_flags_t flags);
std::string outputFlagsToString(audio_output_flags_t flags);
std::string devicesToString(audio_devices_t devices);
const char *sourceToString(audio_source_t source);

// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------


} // namespace android
} // namespace android
+7 −0
Original line number Original line Diff line number Diff line
@@ -57,6 +57,12 @@ class IAfTrackBase;
class Client;
class Client;
class MelReporter;
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()
// Note this is exposed through IAfThreadBase::afThreadCallback()
// and hence may be used by the Effect / Track framework.
// and hence may be used by the Effect / Track framework.
class IAfThreadCallback : public virtual RefBase {
class IAfThreadCallback : public virtual RefBase {
@@ -117,6 +123,7 @@ public:
    };
    };


    static const char* threadTypeToString(type_t type);
    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 isValidPcmSinkChannelMask(audio_channel_mask_t channelMask);
    static bool isValidPcmSinkFormat(audio_format_t format);
    static bool isValidPcmSinkFormat(audio_format_t format);


+75 −66
Original line number Original line Diff line number Diff line
@@ -20,45 +20,49 @@
// #define LOG_NDEBUG 0
// #define LOG_NDEBUG 0
#define ATRACE_TAG ATRACE_TAG_AUDIO
#define ATRACE_TAG ATRACE_TAG_AUDIO


#include "Configuration.h"
#include "Threads.h"
#include <math.h>

#include <fcntl.h>
#include "Client.h"
#include <memory>
#include "IAfEffect.h"
#include <sstream>
#include "MelReporter.h"
#include <string>
#include "ResamplerBufferProvider.h"
#include <linux/futex.h>

#include <sys/stat.h>
#include <afutils/DumpTryLock.h>
#include <sys/syscall.h>
#include <afutils/Permission.h>
#include <afutils/TypedLogger.h>
#include <afutils/Vibrator.h>
#include <audio_utils/MelProcessor.h>
#include <audio_utils/Metadata.h>
#ifdef DEBUG_CPU_USAGE
#include <audio_utils/Statistics.h>
#include <cpustats/ThreadCpuUsage.h>
#endif
#include <audio_utils/channels.h>
#include <audio_utils/format.h>
#include <audio_utils/minifloat.h>
#include <audio_utils/mono_blend.h>
#include <audio_utils/primitives.h>
#include <audio_utils/safe_math.h>
#include <audiomanager/AudioManager.h>
#include <binder/IPCThreadState.h>
#include <binder/IServiceManager.h>
#include <binder/PersistableBundle.h>
#include <cutils/bitops.h>
#include <cutils/bitops.h>
#include <cutils/properties.h>
#include <cutils/properties.h>
#include <binder/PersistableBundle.h>
#include <fastpath/AutoPark.h>
#include <media/AudioContainers.h>
#include <media/AudioContainers.h>
#include <media/AudioDeviceTypeAddr.h>
#include <media/AudioDeviceTypeAddr.h>
#include <media/AudioParameter.h>
#include <media/AudioParameter.h>
#include <media/AudioResamplerPublic.h>
#include <media/AudioResamplerPublic.h>
#ifdef ADD_BATTERY_DATA
#include <media/IMediaPlayerService.h>
#include <media/IMediaDeathNotifier.h>
#endif
#include <media/MmapStreamCallback.h>
#include <media/RecordBufferConverter.h>
#include <media/RecordBufferConverter.h>
#include <media/TypeConverter.h>
#include <media/TypeConverter.h>
#include <utils/Log.h>
#include <media/audiohal/EffectsFactoryHalInterface.h>
#include <utils/Trace.h>
#include <media/audiohal/StreamHalInterface.h>

#include <private/media/AudioTrackShared.h>
#include <private/android_filesystem_config.h>
#include <audio_utils/Balance.h>
#include <audio_utils/MelProcessor.h>
#include <audio_utils/Metadata.h>
#include <audio_utils/channels.h>
#include <audio_utils/mono_blend.h>
#include <audio_utils/primitives.h>
#include <audio_utils/format.h>
#include <audio_utils/minifloat.h>
#include <audio_utils/safe_math.h>
#include <system/audio_effects/effect_aec.h>
#include <system/audio_effects/effect_downmix.h>
#include <system/audio_effects/effect_ns.h>
#include <system/audio_effects/effect_spatializer.h>
#include <system/audio.h>

// NBAIO implementations
#include <media/nbaio/AudioStreamInSource.h>
#include <media/nbaio/AudioStreamInSource.h>
#include <media/nbaio/AudioStreamOutSink.h>
#include <media/nbaio/AudioStreamOutSink.h>
#include <media/nbaio/MonoPipe.h>
#include <media/nbaio/MonoPipe.h>
@@ -68,36 +72,27 @@
#include <media/nbaio/SourceAudioBufferProvider.h>
#include <media/nbaio/SourceAudioBufferProvider.h>
#include <mediautils/BatteryNotifier.h>
#include <mediautils/BatteryNotifier.h>
#include <mediautils/Process.h>
#include <mediautils/Process.h>

#include <audiomanager/AudioManager.h>
#include <powermanager/PowerManager.h>

#include <media/audiohal/EffectsFactoryHalInterface.h>
#include <media/audiohal/StreamHalInterface.h>

#include "AudioFlinger.h"
#include "Threads.h"

#include <mediautils/SchedulingPolicyService.h>
#include <mediautils/SchedulingPolicyService.h>
#include <mediautils/ServiceUtilities.h>
#include <mediautils/ServiceUtilities.h>
#include <powermanager/PowerManager.h>
#include <private/android_filesystem_config.h>
#include <private/media/AudioTrackShared.h>
#include <system/audio_effects/effect_aec.h>
#include <system/audio_effects/effect_downmix.h>
#include <system/audio_effects/effect_ns.h>
#include <system/audio_effects/effect_spatializer.h>
#include <utils/Log.h>
#include <utils/Trace.h>


#ifdef ADD_BATTERY_DATA
#include <fcntl.h>
#include <media/IMediaPlayerService.h>
#include <linux/futex.h>
#include <media/IMediaDeathNotifier.h>
#include <math.h>
#endif
#include <memory>

#ifdef DEBUG_CPU_USAGE
#include <audio_utils/Statistics.h>
#include <cpustats/ThreadCpuUsage.h>
#endif

#include <fastpath/AutoPark.h>

#include <pthread.h>
#include <pthread.h>
#include <afutils/DumpTryLock.h>
#include <sstream>
#include <afutils/Permission.h>
#include <string>
#include <afutils/TypedLogger.h>
#include <sys/stat.h>
#include <afutils/Vibrator.h>
#include <sys/syscall.h>


// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------


@@ -129,6 +124,9 @@ using audioflinger::SyncEvent;
using media::IEffectClient;
using media::IEffectClient;
using content::AttributionSourceState;
using content::AttributionSourceState;


// Keep in sync with java definition in media/java/android/media/AudioRecord.java
static constexpr int32_t kMaxSharedAudioHistoryMs = 5000;

// retry counts for buffer fill timeout
// retry counts for buffer fill timeout
// 50 * ~20msecs = 1 second
// 50 * ~20msecs = 1 second
static const int8_t kMaxTrackRetries = 50;
static const int8_t kMaxTrackRetries = 50;
@@ -245,7 +243,7 @@ static int sFastTrackMultiplier = kFastTrackMultiplier;
// and that all "fast" AudioRecord clients read from.  In either case, the size can be small.
// and that all "fast" AudioRecord clients read from.  In either case, the size can be small.
static const size_t kRecordThreadReadOnlyHeapSize = 0xD000;
static const size_t kRecordThreadReadOnlyHeapSize = 0xD000;


static constexpr nsecs_t kDefaultStandbyTimeInNsecs = seconds(3);
static const nsecs_t kDefaultStandbyTimeInNsecs = seconds(3);


static nsecs_t getStandbyTimeInNanos() {
static nsecs_t getStandbyTimeInNanos() {
    static nsecs_t standbyTimeInNanos = []() {
    static nsecs_t standbyTimeInNanos = []() {
@@ -314,6 +312,15 @@ bool IAfThreadBase::isValidPcmSinkFormat(audio_format_t format) {


// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------


// formatToString() needs to be exact for MediaMetrics purposes.
// Do not use media/TypeConverter.h toString().
/* static */
std::string IAfThreadBase::formatToString(audio_format_t format) {
    std::string result;
    FormatConverter::toString(format, result);
    return result;
}

// TODO: move all toString helpers to audio.h
// TODO: move all toString helpers to audio.h
// under  #ifdef __cplusplus #endif
// under  #ifdef __cplusplus #endif
static std::string patchSinksToString(const struct audio_patch *patch)
static std::string patchSinksToString(const struct audio_patch *patch)
@@ -1057,12 +1064,14 @@ void ThreadBase::dumpBase_l(int fd, const Vector<String16>& /* args */)
    dprintf(fd, "  Standby: %s\n", mStandby ? "yes" : "no");
    dprintf(fd, "  Standby: %s\n", mStandby ? "yes" : "no");
    dprintf(fd, "  Sample rate: %u Hz\n", mSampleRate);
    dprintf(fd, "  Sample rate: %u Hz\n", mSampleRate);
    dprintf(fd, "  HAL frame count: %zu\n", mFrameCount);
    dprintf(fd, "  HAL frame count: %zu\n", mFrameCount);
    dprintf(fd, "  HAL format: 0x%x (%s)\n", mHALFormat, formatToString(mHALFormat).c_str());
    dprintf(fd, "  HAL format: 0x%x (%s)\n", mHALFormat,
            IAfThreadBase::formatToString(mHALFormat).c_str());
    dprintf(fd, "  HAL buffer size: %zu bytes\n", mBufferSize);
    dprintf(fd, "  HAL buffer size: %zu bytes\n", mBufferSize);
    dprintf(fd, "  Channel count: %u\n", mChannelCount);
    dprintf(fd, "  Channel count: %u\n", mChannelCount);
    dprintf(fd, "  Channel mask: 0x%08x (%s)\n", mChannelMask,
    dprintf(fd, "  Channel mask: 0x%08x (%s)\n", mChannelMask,
            channelMaskToString(mChannelMask, mType != RECORD).c_str());
            channelMaskToString(mChannelMask, mType != RECORD).c_str());
    dprintf(fd, "  Processing format: 0x%x (%s)\n", mFormat, formatToString(mFormat).c_str());
    dprintf(fd, "  Processing format: 0x%x (%s)\n", mFormat,
            IAfThreadBase::formatToString(mFormat).c_str());
    dprintf(fd, "  Processing frame size: %zu bytes\n", mFrameSize);
    dprintf(fd, "  Processing frame size: %zu bytes\n", mFrameSize);
    dprintf(fd, "  Pending config events:");
    dprintf(fd, "  Pending config events:");
    size_t numConfig = mConfigEvents.size();
    size_t numConfig = mConfigEvents.size();
@@ -3289,7 +3298,7 @@ void PlaybackThread::readOutputParameters_l()
    audio_output_flags_t flags = mOutput->flags;
    audio_output_flags_t flags = mOutput->flags;
    mediametrics::LogItem item(mThreadMetrics.getMetricsId()); // TODO: method in ThreadMetrics?
    mediametrics::LogItem item(mThreadMetrics.getMetricsId()); // TODO: method in ThreadMetrics?
    item.set(AMEDIAMETRICS_PROP_EVENT, AMEDIAMETRICS_PROP_EVENT_VALUE_READPARAMETERS)
    item.set(AMEDIAMETRICS_PROP_EVENT, AMEDIAMETRICS_PROP_EVENT_VALUE_READPARAMETERS)
        .set(AMEDIAMETRICS_PROP_ENCODING, formatToString(mFormat).c_str())
        .set(AMEDIAMETRICS_PROP_ENCODING, IAfThreadBase::formatToString(mFormat).c_str())
        .set(AMEDIAMETRICS_PROP_SAMPLERATE, (int32_t)mSampleRate)
        .set(AMEDIAMETRICS_PROP_SAMPLERATE, (int32_t)mSampleRate)
        .set(AMEDIAMETRICS_PROP_CHANNELMASK, (int32_t)mChannelMask)
        .set(AMEDIAMETRICS_PROP_CHANNELMASK, (int32_t)mChannelMask)
        .set(AMEDIAMETRICS_PROP_CHANNELCOUNT, (int32_t)mChannelCount)
        .set(AMEDIAMETRICS_PROP_CHANNELCOUNT, (int32_t)mChannelCount)
@@ -3300,7 +3309,7 @@ void PlaybackThread::readOutputParameters_l()
        .set(AMEDIAMETRICS_PROP_PREFIX_HAPTIC AMEDIAMETRICS_PROP_CHANNELCOUNT,
        .set(AMEDIAMETRICS_PROP_PREFIX_HAPTIC AMEDIAMETRICS_PROP_CHANNELCOUNT,
                (int32_t)mHapticChannelCount)
                (int32_t)mHapticChannelCount)
        .set(AMEDIAMETRICS_PROP_PREFIX_HAL    AMEDIAMETRICS_PROP_ENCODING,
        .set(AMEDIAMETRICS_PROP_PREFIX_HAL    AMEDIAMETRICS_PROP_ENCODING,
                formatToString(mHALFormat).c_str())
                IAfThreadBase::formatToString(mHALFormat).c_str())
        .set(AMEDIAMETRICS_PROP_PREFIX_HAL    AMEDIAMETRICS_PROP_FRAMECOUNT,
        .set(AMEDIAMETRICS_PROP_PREFIX_HAL    AMEDIAMETRICS_PROP_FRAMECOUNT,
                (int32_t)mFrameCount) // sic - added HAL
                (int32_t)mFrameCount) // sic - added HAL
        ;
        ;
@@ -8747,7 +8756,7 @@ sp<IAfRecordTrack> RecordThread::createRecordTrack_l(
            goto Exit;
            goto Exit;
        }
        }
        if (maxSharedAudioHistoryMs < 0
        if (maxSharedAudioHistoryMs < 0
                || maxSharedAudioHistoryMs > AudioFlinger::kMaxSharedAudioHistoryMs) {
                || maxSharedAudioHistoryMs > kMaxSharedAudioHistoryMs) {
            lStatus = BAD_VALUE;
            lStatus = BAD_VALUE;
            goto Exit;
            goto Exit;
        }
        }
@@ -9571,7 +9580,7 @@ void RecordThread::readInputParameters_l()
    audio_input_flags_t flags = mInput->flags;
    audio_input_flags_t flags = mInput->flags;
    mediametrics::LogItem item(mThreadMetrics.getMetricsId());
    mediametrics::LogItem item(mThreadMetrics.getMetricsId());
    item.set(AMEDIAMETRICS_PROP_EVENT, AMEDIAMETRICS_PROP_EVENT_VALUE_READPARAMETERS)
    item.set(AMEDIAMETRICS_PROP_EVENT, AMEDIAMETRICS_PROP_EVENT_VALUE_READPARAMETERS)
        .set(AMEDIAMETRICS_PROP_ENCODING, formatToString(mFormat).c_str())
        .set(AMEDIAMETRICS_PROP_ENCODING, IAfThreadBase::formatToString(mFormat).c_str())
        .set(AMEDIAMETRICS_PROP_FLAGS, toString(flags).c_str())
        .set(AMEDIAMETRICS_PROP_FLAGS, toString(flags).c_str())
        .set(AMEDIAMETRICS_PROP_SAMPLERATE, (int32_t)mSampleRate)
        .set(AMEDIAMETRICS_PROP_SAMPLERATE, (int32_t)mSampleRate)
        .set(AMEDIAMETRICS_PROP_CHANNELMASK, (int32_t)mChannelMask)
        .set(AMEDIAMETRICS_PROP_CHANNELMASK, (int32_t)mChannelMask)
@@ -10311,7 +10320,7 @@ void MmapThread::readHalParameters_l()
    // TODO: make a readHalParameters call?
    // TODO: make a readHalParameters call?
    mediametrics::LogItem item(mThreadMetrics.getMetricsId());
    mediametrics::LogItem item(mThreadMetrics.getMetricsId());
    item.set(AMEDIAMETRICS_PROP_EVENT, AMEDIAMETRICS_PROP_EVENT_VALUE_READPARAMETERS)
    item.set(AMEDIAMETRICS_PROP_EVENT, AMEDIAMETRICS_PROP_EVENT_VALUE_READPARAMETERS)
        .set(AMEDIAMETRICS_PROP_ENCODING, formatToString(mFormat).c_str())
        .set(AMEDIAMETRICS_PROP_ENCODING, IAfThreadBase::formatToString(mFormat).c_str())
        .set(AMEDIAMETRICS_PROP_SAMPLERATE, (int32_t)mSampleRate)
        .set(AMEDIAMETRICS_PROP_SAMPLERATE, (int32_t)mSampleRate)
        .set(AMEDIAMETRICS_PROP_CHANNELMASK, (int32_t)mChannelMask)
        .set(AMEDIAMETRICS_PROP_CHANNELMASK, (int32_t)mChannelMask)
        .set(AMEDIAMETRICS_PROP_CHANNELCOUNT, (int32_t)mChannelCount)
        .set(AMEDIAMETRICS_PROP_CHANNELCOUNT, (int32_t)mChannelCount)
@@ -10324,7 +10333,7 @@ void MmapThread::readHalParameters_l()
                (int32_t)mHapticChannelCount)
                (int32_t)mHapticChannelCount)
        */
        */
        .set(AMEDIAMETRICS_PROP_PREFIX_HAL    AMEDIAMETRICS_PROP_ENCODING,
        .set(AMEDIAMETRICS_PROP_PREFIX_HAL    AMEDIAMETRICS_PROP_ENCODING,
                formatToString(mHALFormat).c_str())
                IAfThreadBase::formatToString(mHALFormat).c_str())
        .set(AMEDIAMETRICS_PROP_PREFIX_HAL    AMEDIAMETRICS_PROP_FRAMECOUNT,
        .set(AMEDIAMETRICS_PROP_PREFIX_HAL    AMEDIAMETRICS_PROP_FRAMECOUNT,
                (int32_t)mFrameCount) // sic - added HAL
                (int32_t)mFrameCount) // sic - added HAL
        .record();
        .record();
+19 −0
Original line number Original line Diff line number Diff line
@@ -17,6 +17,25 @@


#pragma once
#pragma once


// ADD_BATTERY_DATA AUDIO_WATCHDOG FAST_THREAD_STATISTICS STATE_QUEUE_DUMP TEE_SINK
#include "Configuration.h"
#include "IAfThread.h"
#include "IAfTrack.h"

#include <android-base/macros.h>  // DISALLOW_COPY_AND_ASSIGN
#include <android/os/IPowerManager.h>
#include <afutils/AudioWatchdog.h>
#include <afutils/NBAIO_Tee.h>
#include <audio_utils/Balance.h>
#include <audio_utils/SimpleLog.h>
#include <datapath/ThreadMetrics.h>
#include <fastpath/FastCapture.h>
#include <fastpath/FastMixer.h>
#include <mediautils/Synchronization.h>
#include <mediautils/ThreadSnapshot.h>
#include <timing/MonotonicFrameCounter.h>
#include <utils/Log.h>

namespace android {
namespace android {


class AsyncCallbackThread;
class AsyncCallbackThread;