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

Commit daf20796 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Metrics for AudioRecord"

parents 8ff36d74 734d186d
Loading
Loading
Loading
Loading
+32 −0
Original line number Diff line number Diff line
@@ -26,6 +26,8 @@
#include <utils/Log.h>
#include <private/media/AudioTrackShared.h>
#include <media/IAudioFlinger.h>
#include <media/MediaAnalyticsItem.h>
#include <media/TypeConverter.h>

#define WAIT_PERIOD_MS          10

@@ -65,6 +67,34 @@ status_t AudioRecord::getMinFrameCount(

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

static std::string audioFormatTypeString(audio_format_t value) {
    std::string formatType;
    if (FormatConverter::toString(value, formatType)) {
        return formatType;
    }
    char rawbuffer[16];  // room for "%d"
    snprintf(rawbuffer, sizeof(rawbuffer), "%d", value);
    return rawbuffer;
}

void AudioRecord::MediaMetrics::gather(const AudioRecord *record)
{
    // key for media statistics is defined in the header
    // attrs for media statistics
    static constexpr char kAudioRecordChannelCount[] = "android.media.audiorecord.channels";
    static constexpr char kAudioRecordFormat[] = "android.media.audiorecord.format";
    static constexpr char kAudioRecordLatency[] = "android.media.audiorecord.latency";
    static constexpr char kAudioRecordSampleRate[] = "android.media.audiorecord.samplerate";

    // constructor guarantees mAnalyticsItem is valid

    mAnalyticsItem->setInt32(kAudioRecordLatency, record->mLatency);
    mAnalyticsItem->setInt32(kAudioRecordSampleRate, record->mSampleRate);
    mAnalyticsItem->setInt32(kAudioRecordChannelCount, record->mChannelCount);
    mAnalyticsItem->setCString(kAudioRecordFormat,
                               audioFormatTypeString(record->mFormat).c_str());
}

AudioRecord::AudioRecord(const String16 &opPackageName)
    : mActive(false), mStatus(NO_INIT), mOpPackageName(opPackageName),
      mSessionId(AUDIO_SESSION_ALLOCATE),
@@ -105,6 +135,8 @@ AudioRecord::AudioRecord(

AudioRecord::~AudioRecord()
{
    mMediaMetrics.gather(this);

    if (mStatus == NO_ERROR) {
        // Make sure that callback function exits in the case where
        // it is looping on buffer empty condition in obtainBuffer().
+19 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@
#include <cutils/sched_policy.h>
#include <media/AudioSystem.h>
#include <media/AudioTimestamp.h>
#include <media/MediaAnalyticsItem.h>
#include <media/Modulo.h>
#include <utils/RefBase.h>
#include <utils/threads.h>
@@ -688,6 +689,24 @@ private:
                                              // activity and connected devices
    wp<AudioSystem::AudioDeviceCallback> mDeviceCallback;

private:
    class MediaMetrics {
      public:
        MediaMetrics() : mAnalyticsItem(new MediaAnalyticsItem("audiorecord")) {
        }
        ~MediaMetrics() {
            // mAnalyticsItem alloc failure will be flagged in the constructor
            // don't log empty records
            if (mAnalyticsItem->count() > 0) {
                mAnalyticsItem->setFinalized(true);
                mAnalyticsItem->selfrecord();
            }
        }
        void gather(const AudioRecord *record);
      private:
        std::unique_ptr<MediaAnalyticsItem> mAnalyticsItem;
    };
    MediaMetrics mMediaMetrics;
};

}; // namespace android