Loading media/libstagefright/MediaCodec.cpp +51 −1 Original line number Diff line number Diff line Loading @@ -101,6 +101,10 @@ static const char *kCodecLatencyCount = "android.media.mediacodec.latency.n"; static const char *kCodecLatencyHist = "android.media.mediacodec.latency.hist"; /* in us */ static const char *kCodecLatencyUnknown = "android.media.mediacodec.latency.unknown"; static const char *kCodecNumLowLatencyModeOn = "android.media.mediacodec.low-latency.on"; /* 0..n */ static const char *kCodecNumLowLatencyModeOff = "android.media.mediacodec.low-latency.off"; /* 0..n */ static const char *kCodecFirstFrameIndexLowLatencyModeOn = "android.media.mediacodec.low-latency.first-frame"; /* 0..n */ // the kCodecRecent* fields appear only in getMetrics() results static const char *kCodecRecentLatencyMax = "android.media.mediacodec.recent.max"; /* in us */ static const char *kCodecRecentLatencyMin = "android.media.mediacodec.recent.min"; /* in us */ Loading Loading @@ -583,7 +587,12 @@ MediaCodec::MediaCodec(const sp<ALooper> &looper, pid_t pid, uid_t uid) mHaveInputSurface(false), mHavePendingInputBuffers(false), mCpuBoostRequested(false), mLatencyUnknown(0) { mLatencyUnknown(0), mNumLowLatencyEnables(0), mNumLowLatencyDisables(0), mIsLowLatencyModeOn(false), mIndexOfFirstFrameWhenLowLatencyOn(-1), mInputBufferCounter(0) { if (uid == kNoUid) { mUid = AIBinder_getCallingUid(); } else { Loading Loading @@ -616,6 +625,16 @@ void MediaCodec::initMediametrics() { } mRecentHead = 0; } { Mutex::Autolock al(mLatencyLock); mBuffersInFlight.clear(); mNumLowLatencyEnables = 0; mNumLowLatencyDisables = 0; mIsLowLatencyModeOn = false; mIndexOfFirstFrameWhenLowLatencyOn = -1; mInputBufferCounter = 0; } } void MediaCodec::updateMediametrics() { Loading @@ -641,6 +660,13 @@ void MediaCodec::updateMediametrics() { mediametrics_setInt64(mMetricsHandle, kCodecLatencyUnknown, mLatencyUnknown); } { Mutex::Autolock al(mLatencyLock); mediametrics_setInt64(mMetricsHandle, kCodecNumLowLatencyModeOn, mNumLowLatencyEnables); mediametrics_setInt64(mMetricsHandle, kCodecNumLowLatencyModeOff, mNumLowLatencyDisables); mediametrics_setInt64(mMetricsHandle, kCodecFirstFrameIndexLowLatencyModeOn, mIndexOfFirstFrameWhenLowLatencyOn); } #if 0 // enable for short term, only while debugging updateEphemeralMediametrics(mMetricsHandle); Loading Loading @@ -697,6 +723,22 @@ void MediaCodec::flushMediametrics() { } } void MediaCodec::updateLowLatency(const sp<AMessage> &msg) { int32_t lowLatency = 0; if (msg->findInt32("low-latency", &lowLatency)) { Mutex::Autolock al(mLatencyLock); if (lowLatency > 0) { ++mNumLowLatencyEnables; // This is just an estimate since low latency mode change happens ONLY at key frame mIsLowLatencyModeOn = true; } else if (lowLatency == 0) { ++mNumLowLatencyDisables; // This is just an estimate since low latency mode change happens ONLY at key frame mIsLowLatencyModeOn = false; } } } bool MediaCodec::Histogram::setup(int nbuckets, int64_t width, int64_t floor) { if (nbuckets <= 0 || width <= 0) { Loading Loading @@ -813,6 +855,11 @@ void MediaCodec::statsBufferSent(int64_t presentationUs) { // XXX: we *could* make sure that the time is later than the end of queue // as part of a consistency check... mBuffersInFlight.push_back(startdata); if (mIsLowLatencyModeOn && mIndexOfFirstFrameWhenLowLatencyOn < 0) { mIndexOfFirstFrameWhenLowLatencyOn = mInputBufferCounter; } ++mInputBufferCounter; } } Loading Loading @@ -1133,6 +1180,8 @@ status_t MediaCodec::configure( } } updateLowLatency(format); msg->setMessage("format", format); msg->setInt32("flags", flags); msg->setObject("surface", surface); Loading Loading @@ -3714,6 +3763,7 @@ status_t MediaCodec::setParameters(const sp<AMessage> ¶ms) { } status_t MediaCodec::onSetParameters(const sp<AMessage> ¶ms) { updateLowLatency(params); mCodec->signalSetParameters(params); return OK; Loading media/libstagefright/include/media/stagefright/MediaCodec.h +7 −0 Original line number Diff line number Diff line Loading @@ -313,6 +313,7 @@ private: void updateMediametrics(); void flushMediametrics(); void updateEphemeralMediametrics(mediametrics_handle_t item); void updateLowLatency(const sp<AMessage> &msg); sp<AMessage> mOutputFormat; sp<AMessage> mInputFormat; Loading Loading @@ -440,6 +441,12 @@ private: std::deque<BufferFlightTiming_t> mBuffersInFlight; Mutex mLatencyLock; int64_t mLatencyUnknown; // buffers for which we couldn't calculate latency int64_t mNumLowLatencyEnables; // how many times low latency mode is enabled int64_t mNumLowLatencyDisables; // how many times low latency mode is disabled bool mIsLowLatencyModeOn; // is low latency mode on currently int64_t mIndexOfFirstFrameWhenLowLatencyOn; // index of the first frame queued // when low latency is on int64_t mInputBufferCounter; // number of input buffers queued since last reset/flush sp<BatteryChecker> mBatteryChecker; Loading Loading
media/libstagefright/MediaCodec.cpp +51 −1 Original line number Diff line number Diff line Loading @@ -101,6 +101,10 @@ static const char *kCodecLatencyCount = "android.media.mediacodec.latency.n"; static const char *kCodecLatencyHist = "android.media.mediacodec.latency.hist"; /* in us */ static const char *kCodecLatencyUnknown = "android.media.mediacodec.latency.unknown"; static const char *kCodecNumLowLatencyModeOn = "android.media.mediacodec.low-latency.on"; /* 0..n */ static const char *kCodecNumLowLatencyModeOff = "android.media.mediacodec.low-latency.off"; /* 0..n */ static const char *kCodecFirstFrameIndexLowLatencyModeOn = "android.media.mediacodec.low-latency.first-frame"; /* 0..n */ // the kCodecRecent* fields appear only in getMetrics() results static const char *kCodecRecentLatencyMax = "android.media.mediacodec.recent.max"; /* in us */ static const char *kCodecRecentLatencyMin = "android.media.mediacodec.recent.min"; /* in us */ Loading Loading @@ -583,7 +587,12 @@ MediaCodec::MediaCodec(const sp<ALooper> &looper, pid_t pid, uid_t uid) mHaveInputSurface(false), mHavePendingInputBuffers(false), mCpuBoostRequested(false), mLatencyUnknown(0) { mLatencyUnknown(0), mNumLowLatencyEnables(0), mNumLowLatencyDisables(0), mIsLowLatencyModeOn(false), mIndexOfFirstFrameWhenLowLatencyOn(-1), mInputBufferCounter(0) { if (uid == kNoUid) { mUid = AIBinder_getCallingUid(); } else { Loading Loading @@ -616,6 +625,16 @@ void MediaCodec::initMediametrics() { } mRecentHead = 0; } { Mutex::Autolock al(mLatencyLock); mBuffersInFlight.clear(); mNumLowLatencyEnables = 0; mNumLowLatencyDisables = 0; mIsLowLatencyModeOn = false; mIndexOfFirstFrameWhenLowLatencyOn = -1; mInputBufferCounter = 0; } } void MediaCodec::updateMediametrics() { Loading @@ -641,6 +660,13 @@ void MediaCodec::updateMediametrics() { mediametrics_setInt64(mMetricsHandle, kCodecLatencyUnknown, mLatencyUnknown); } { Mutex::Autolock al(mLatencyLock); mediametrics_setInt64(mMetricsHandle, kCodecNumLowLatencyModeOn, mNumLowLatencyEnables); mediametrics_setInt64(mMetricsHandle, kCodecNumLowLatencyModeOff, mNumLowLatencyDisables); mediametrics_setInt64(mMetricsHandle, kCodecFirstFrameIndexLowLatencyModeOn, mIndexOfFirstFrameWhenLowLatencyOn); } #if 0 // enable for short term, only while debugging updateEphemeralMediametrics(mMetricsHandle); Loading Loading @@ -697,6 +723,22 @@ void MediaCodec::flushMediametrics() { } } void MediaCodec::updateLowLatency(const sp<AMessage> &msg) { int32_t lowLatency = 0; if (msg->findInt32("low-latency", &lowLatency)) { Mutex::Autolock al(mLatencyLock); if (lowLatency > 0) { ++mNumLowLatencyEnables; // This is just an estimate since low latency mode change happens ONLY at key frame mIsLowLatencyModeOn = true; } else if (lowLatency == 0) { ++mNumLowLatencyDisables; // This is just an estimate since low latency mode change happens ONLY at key frame mIsLowLatencyModeOn = false; } } } bool MediaCodec::Histogram::setup(int nbuckets, int64_t width, int64_t floor) { if (nbuckets <= 0 || width <= 0) { Loading Loading @@ -813,6 +855,11 @@ void MediaCodec::statsBufferSent(int64_t presentationUs) { // XXX: we *could* make sure that the time is later than the end of queue // as part of a consistency check... mBuffersInFlight.push_back(startdata); if (mIsLowLatencyModeOn && mIndexOfFirstFrameWhenLowLatencyOn < 0) { mIndexOfFirstFrameWhenLowLatencyOn = mInputBufferCounter; } ++mInputBufferCounter; } } Loading Loading @@ -1133,6 +1180,8 @@ status_t MediaCodec::configure( } } updateLowLatency(format); msg->setMessage("format", format); msg->setInt32("flags", flags); msg->setObject("surface", surface); Loading Loading @@ -3714,6 +3763,7 @@ status_t MediaCodec::setParameters(const sp<AMessage> ¶ms) { } status_t MediaCodec::onSetParameters(const sp<AMessage> ¶ms) { updateLowLatency(params); mCodec->signalSetParameters(params); return OK; Loading
media/libstagefright/include/media/stagefright/MediaCodec.h +7 −0 Original line number Diff line number Diff line Loading @@ -313,6 +313,7 @@ private: void updateMediametrics(); void flushMediametrics(); void updateEphemeralMediametrics(mediametrics_handle_t item); void updateLowLatency(const sp<AMessage> &msg); sp<AMessage> mOutputFormat; sp<AMessage> mInputFormat; Loading Loading @@ -440,6 +441,12 @@ private: std::deque<BufferFlightTiming_t> mBuffersInFlight; Mutex mLatencyLock; int64_t mLatencyUnknown; // buffers for which we couldn't calculate latency int64_t mNumLowLatencyEnables; // how many times low latency mode is enabled int64_t mNumLowLatencyDisables; // how many times low latency mode is disabled bool mIsLowLatencyModeOn; // is low latency mode on currently int64_t mIndexOfFirstFrameWhenLowLatencyOn; // index of the first frame queued // when low latency is on int64_t mInputBufferCounter; // number of input buffers queued since last reset/flush sp<BatteryChecker> mBatteryChecker; Loading