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

Commit ef348b84 authored by jiabin's avatar jiabin
Browse files

Update logging logic in AudioStream.

In destructor, it may point to a wrong virtual function for subclasses.
In that case, move the logging logic from destructor of AudioStream to
close_l.

In AudioStream::logOpen, the performance mode is the actual performance
mode instead of the requested one. In that case, log the requested
performance mode when the metric id is set.

Renamed ENCODINGREQUESTED as ENCODINGAPP to make it consitent with atom
definition.

Test: atest MediaMetricsAtomTests
Bug: 185788699
Change-Id: I35b40d7ccd7d135f79bc2c84f7cbfe73946f9d2f
parent c6a7e314
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -100,8 +100,9 @@ aaudio_result_t AudioStreamInternal::open(const AudioStreamBuilder &builder) {
    const int32_t burstMinMicros = AAudioProperty_getHardwareBurstMinMicros();
    int32_t burstMicros = 0;

    const audio_format_t requestedFormat = getFormat();
    // We have to do volume scaling. So we prefer FLOAT format.
    if (getFormat() == AUDIO_FORMAT_DEFAULT) {
    if (requestedFormat == AUDIO_FORMAT_DEFAULT) {
        setFormat(AUDIO_FORMAT_PCM_FLOAT);
    }
    // Request FLOAT for the shared mixer or the device.
@@ -156,6 +157,12 @@ aaudio_result_t AudioStreamInternal::open(const AudioStreamBuilder &builder) {
    mMetricsId = std::string(AMEDIAMETRICS_KEY_PREFIX_AUDIO_STREAM)
            + std::to_string(mServiceStreamHandle);

    android::mediametrics::LogItem(mMetricsId)
            .set(AMEDIAMETRICS_PROP_PERFORMANCEMODE,
                 AudioGlobal_convertPerformanceModeToText(getPerformanceMode()))
            .set(AMEDIAMETRICS_PROP_ENCODINGCLIENT,
                 android::toString(requestedFormat).c_str()).record();

    result = configurationOutput.validate();
    if (result != AAUDIO_OK) {
        goto error;
+3 −12
Original line number Diff line number Diff line
@@ -56,16 +56,6 @@ AudioStream::~AudioStream() {

    ALOGE_IF(mHasThread, "%s() callback thread never join()ed", __func__);

    if (!mMetricsId.empty()) {
        android::mediametrics::LogItem(mMetricsId)
                .set(AMEDIAMETRICS_PROP_EVENT, AMEDIAMETRICS_PROP_EVENT_VALUE_ENDAAUDIOSTREAM)
                .set(AMEDIAMETRICS_PROP_ENCODINGREQUESTED,
                     android::toString(mDeviceFormat).c_str())
                .set(AMEDIAMETRICS_PROP_PERFORMANCEMODEACTUAL,
                     AudioGlobal_convertPerformanceModeToText(getPerformanceMode()))
                .record();
    }

    // If the stream is deleted when OPEN or in use then audio resources will leak.
    // This would indicate an internal error. So we want to find this ASAP.
    LOG_ALWAYS_FATAL_IF(!(getState() == AAUDIO_STREAM_STATE_CLOSED
@@ -121,11 +111,11 @@ aaudio_result_t AudioStream::open(const AudioStreamBuilder& builder)
    return AAUDIO_OK;
}

void AudioStream::logOpen() {
void AudioStream::logOpenActual() {
    if (mMetricsId.size() > 0) {
        android::mediametrics::LogItem item(mMetricsId);
        item.set(AMEDIAMETRICS_PROP_EVENT, AMEDIAMETRICS_PROP_EVENT_VALUE_OPEN)
            .set(AMEDIAMETRICS_PROP_PERFORMANCEMODE,
            .set(AMEDIAMETRICS_PROP_PERFORMANCEMODEACTUAL,
                AudioGlobal_convertPerformanceModeToText(getPerformanceMode()))
            .set(AMEDIAMETRICS_PROP_SHARINGMODE,
                AudioGlobal_convertSharingModeToText(getSharingMode()))
@@ -359,6 +349,7 @@ void AudioStream::close_l() {
                .set(AMEDIAMETRICS_PROP_FRAMESTRANSFERRED,
                        getDirection() == AAUDIO_DIRECTION_INPUT ? getFramesWritten()
                                                                 : getFramesRead())
                .set(AMEDIAMETRICS_PROP_EVENT, AMEDIAMETRICS_PROP_EVENT_VALUE_ENDAAUDIOSTREAM)
                .record();
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -118,7 +118,7 @@ public:
    virtual aaudio_result_t open(const AudioStreamBuilder& builder);

    // log to MediaMetrics
    virtual void logOpen();
    virtual void logOpenActual();
    void logReleaseBufferState();

    /* Note about naming for "release"  and "close" related methods.
+1 −1
Original line number Diff line number Diff line
@@ -189,7 +189,7 @@ aaudio_result_t AudioStreamBuilder::build(AudioStream** streamPtr) {
        }
        if (result == AAUDIO_OK) {
            audioStream->registerPlayerBase();
            audioStream->logOpen();
            audioStream->logOpenActual();
            *streamPtr = startUsingStream(audioStream);
        } // else audioStream will go out of scope and be deleted
    }
+7 −1
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@
#include <media/AudioRecord.h>
#include <utils/String16.h>

#include "core/AudioGlobal.h"
#include "legacy/AudioStreamLegacy.h"
#include "legacy/AudioStreamRecord.h"
#include "utility/AudioClock.h"
@@ -92,8 +93,9 @@ aaudio_result_t AudioStreamRecord::open(const AudioStreamBuilder& builder)
            break;
    }

    const audio_format_t requestedFormat = getFormat();
    // Preserve behavior of API 26
    if (getFormat() == AUDIO_FORMAT_DEFAULT) {
    if (requestedFormat == AUDIO_FORMAT_DEFAULT) {
        setFormat(AUDIO_FORMAT_PCM_FLOAT);
    }

@@ -217,6 +219,10 @@ aaudio_result_t AudioStreamRecord::open(const AudioStreamBuilder& builder)

    mMetricsId = std::string(AMEDIAMETRICS_KEY_PREFIX_AUDIO_RECORD)
            + std::to_string(mAudioRecord->getPortId());
    android::mediametrics::LogItem(mMetricsId)
            .set(AMEDIAMETRICS_PROP_PERFORMANCEMODE,
                 AudioGlobal_convertPerformanceModeToText(getPerformanceMode()))
            .set(AMEDIAMETRICS_PROP_ENCODINGCLIENT, toString(requestedFormat).c_str()).record();

    // Get the actual values from the AudioRecord.
    setSamplesPerFrame(mAudioRecord->channelCount());
Loading