Commit 0978227a by olly Committed by Oliver Woodman

Create a new CodecCounters on enable

If the same instance is reset then rapidly re-enabling the
renderer after disabling it can prevent an application from
reading the final values at the time when the renderer was
disabled. Hence we now instantiate a new CodecCounters each
time. This is needed to migrate DashTest to V2.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=124721106
parent 7ae9bf40
......@@ -15,6 +15,7 @@
*/
package com.google.android.exoplayer.demo;
import com.google.android.exoplayer.CodecCounters;
import com.google.android.exoplayer.DefaultTrackSelector;
import com.google.android.exoplayer.DefaultTrackSelector.TrackInfo;
import com.google.android.exoplayer.ExoPlaybackException;
......@@ -133,6 +134,11 @@ public class EventLogger implements ExoPlayer.EventListener, SimpleExoPlayer.Deb
// SimpleExoPlayer.DebugListener
@Override
public void onAudioEnabled(CodecCounters counters) {
Log.d(TAG, "audioEnabled [" + getSessionTimeString() + "]");
}
@Override
public void onAudioDecoderInitialized(String decoderName, long elapsedRealtimeMs,
long initializationDurationMs) {
Log.d(TAG, "audioDecoderInitialized [" + getSessionTimeString() + ", " + decoderName + "]");
......@@ -145,6 +151,16 @@ public class EventLogger implements ExoPlayer.EventListener, SimpleExoPlayer.Deb
}
@Override
public void onAudioDisabled(CodecCounters counters) {
Log.d(TAG, "audioDisabled [" + getSessionTimeString() + "]");
}
@Override
public void onVideoEnabled(CodecCounters counters) {
Log.d(TAG, "videoEnabled [" + getSessionTimeString() + "]");
}
@Override
public void onVideoDecoderInitialized(String decoderName, long elapsedRealtimeMs,
long initializationDurationMs) {
Log.d(TAG, "videoDecoderInitialized [" + getSessionTimeString() + ", " + decoderName + "]");
......@@ -157,6 +173,11 @@ public class EventLogger implements ExoPlayer.EventListener, SimpleExoPlayer.Deb
}
@Override
public void onVideoDisabled(CodecCounters counters) {
Log.d(TAG, "videoDisabled [" + getSessionTimeString() + "]");
}
@Override
public void onDroppedFrames(int count, long elapsed) {
Log.d(TAG, "droppedFrames [" + getSessionTimeString() + ", " + count + "]");
}
......
......@@ -55,14 +55,13 @@ public final class LibvpxVideoTrackRenderer extends TrackRenderer {
private static final int NUM_BUFFERS = 16;
private static final int INITIAL_INPUT_BUFFER_SIZE = 768 * 1024; // Value based on cs/SoftVpx.cpp.
public final CodecCounters codecCounters = new CodecCounters();
private final boolean scaleToFit;
private final long allowedJoiningTimeMs;
private final int maxDroppedFrameCountToNotify;
private final EventDispatcher eventDispatcher;
private final FormatHolder formatHolder;
private CodecCounters codecCounters;
private Format format;
private VpxDecoder decoder;
private DecoderInputBuffer inputBuffer;
......@@ -213,7 +212,7 @@ public final class LibvpxVideoTrackRenderer extends TrackRenderer {
// and that's also late. Else we'll render what we have.
if ((joiningDeadlineMs != -1 && outputBuffer.timestampUs < positionUs - 30000)
|| (nextOutputBuffer != null && !nextOutputBuffer.isEndOfStream()
&& nextOutputBuffer.timestampUs < positionUs)) {
&& nextOutputBuffer.timestampUs < positionUs)) {
codecCounters.droppedOutputBufferCount++;
droppedFrameCount++;
consecutiveDroppedFrameCount++;
......@@ -349,7 +348,7 @@ public final class LibvpxVideoTrackRenderer extends TrackRenderer {
@Override
protected void onEnabled(boolean joining) throws ExoPlaybackException {
codecCounters.reset();
codecCounters = new CodecCounters();
eventDispatcher.enabled(codecCounters);
}
......@@ -390,8 +389,8 @@ public final class LibvpxVideoTrackRenderer extends TrackRenderer {
codecCounters.codecReleaseCount++;
}
} finally {
super.onDisabled();
eventDispatcher.disabled();
codecCounters.ensureUpdated();
eventDispatcher.disabled(codecCounters);
}
}
......
......@@ -29,7 +29,8 @@ public interface AudioTrackRendererEventListener {
/**
* Invoked when the renderer is enabled.
*
* @param counters {@link CodecCounters} that will be updated by the renderer.
* @param counters {@link CodecCounters} that will be updated by the renderer for as long as it
* remains enabled.
*/
void onAudioEnabled(CodecCounters counters);
......@@ -64,8 +65,10 @@ public interface AudioTrackRendererEventListener {
/**
* Invoked when the renderer is disabled.
*
* @param counters {@link CodecCounters} that were updated by the renderer.
*/
void onAudioDisabled();
void onAudioDisabled(CodecCounters counters);
/**
* Dispatches events to a {@link AudioTrackRendererEventListener}.
......@@ -127,12 +130,12 @@ public interface AudioTrackRendererEventListener {
}
}
public void disabled() {
public void disabled(final CodecCounters counters) {
if (listener != null) {
handler.post(new Runnable() {
@Override
public void run() {
listener.onAudioDisabled();
listener.onAudioDisabled(counters);
}
});
}
......
......@@ -71,16 +71,19 @@ public final class CodecCounters {
}
/**
* Resets all counters to zero.
* Merges the counts from {@code other} into this instance.
*
* @param other The {@link CodecCounters} to merge into this instance.
*/
public void reset() {
codecInitCount = 0;
codecReleaseCount = 0;
inputBufferCount = 0;
renderedOutputBufferCount = 0;
skippedOutputBufferCount = 0;
droppedOutputBufferCount = 0;
maxConsecutiveDroppedOutputBufferCount = 0;
public void merge(CodecCounters other) {
codecInitCount += other.codecInitCount;
codecReleaseCount += other.codecReleaseCount;
inputBufferCount += other.inputBufferCount;
renderedOutputBufferCount += other.renderedOutputBufferCount;
skippedOutputBufferCount += other.skippedOutputBufferCount;
droppedOutputBufferCount += other.droppedOutputBufferCount;
maxConsecutiveDroppedOutputBufferCount = Math.max(maxConsecutiveDroppedOutputBufferCount,
other.maxConsecutiveDroppedOutputBufferCount);
}
}
......@@ -156,9 +156,9 @@ public class MediaCodecAudioTrackRenderer extends MediaCodecTrackRenderer implem
// Note: We assume support for unknown sampleRate and channelCount.
boolean decoderCapable = Util.SDK_INT < 21
|| ((format.sampleRate == Format.NO_VALUE
|| decoderInfo.isAudioSampleRateSupportedV21(format.sampleRate))
|| decoderInfo.isAudioSampleRateSupportedV21(format.sampleRate))
&& (format.channelCount == Format.NO_VALUE
|| decoderInfo.isAudioChannelCountSupportedV21(format.channelCount)));
|| decoderInfo.isAudioChannelCountSupportedV21(format.channelCount)));
int formatSupport = decoderCapable ? FORMAT_HANDLED : FORMAT_EXCEEDS_CAPABILITIES;
return ADAPTIVE_NOT_SEAMLESS | formatSupport;
}
......@@ -255,7 +255,6 @@ public class MediaCodecAudioTrackRenderer extends MediaCodecTrackRenderer implem
@Override
protected void onEnabled(boolean joining) throws ExoPlaybackException {
super.onEnabled(joining);
codecCounters.reset();
eventDispatcher.enabled(codecCounters);
}
......@@ -281,12 +280,16 @@ public class MediaCodecAudioTrackRenderer extends MediaCodecTrackRenderer implem
@Override
protected void onDisabled() {
eventDispatcher.disabled();
audioSessionId = AudioTrack.SESSION_ID_NOT_SET;
try {
audioTrack.release();
} finally {
super.onDisabled();
try {
super.onDisabled();
} finally {
codecCounters.ensureUpdated();
eventDispatcher.disabled(codecCounters);
}
}
}
......
......@@ -147,8 +147,6 @@ public abstract class MediaCodecTrackRenderer extends TrackRenderer {
*/
private static final int REINITIALIZATION_STATE_WAIT_END_OF_STREAM = 2;
public final CodecCounters codecCounters;
private final MediaCodecSelector mediaCodecSelector;
private final DrmSessionManager drmSessionManager;
private final boolean playClearSamplesWithoutKeys;
......@@ -182,6 +180,8 @@ public abstract class MediaCodecTrackRenderer extends TrackRenderer {
private boolean outputStreamEnded;
private boolean waitingForKeys;
protected CodecCounters codecCounters;
/**
* @param mediaCodecSelector A decoder selector.
* @param drmSessionManager For use with encrypted media. May be null if support for encrypted
......@@ -198,7 +198,6 @@ public abstract class MediaCodecTrackRenderer extends TrackRenderer {
this.mediaCodecSelector = Assertions.checkNotNull(mediaCodecSelector);
this.drmSessionManager = drmSessionManager;
this.playClearSamplesWithoutKeys = playClearSamplesWithoutKeys;
codecCounters = new CodecCounters();
buffer = new DecoderInputBuffer(DecoderInputBuffer.BUFFER_REPLACEMENT_MODE_DISABLED);
formatHolder = new FormatHolder();
decodeOnlyPresentationTimestamps = new ArrayList<>();
......@@ -356,6 +355,11 @@ public abstract class MediaCodecTrackRenderer extends TrackRenderer {
}
@Override
protected void onEnabled(boolean joining) throws ExoPlaybackException {
codecCounters = new CodecCounters();
}
@Override
protected void onReset(long positionUs, boolean joining) throws ExoPlaybackException {
inputStreamEnded = false;
outputStreamEnded = false;
......@@ -370,13 +374,9 @@ public abstract class MediaCodecTrackRenderer extends TrackRenderer {
try {
releaseCodec();
} finally {
try {
if (drmSession != null) {
drmSessionManager.releaseSession(drmSession);
drmSession = null;
}
} finally {
super.onDisabled();
if (drmSession != null) {
drmSessionManager.releaseSession(drmSession);
drmSession = null;
}
}
}
......@@ -907,9 +907,9 @@ public abstract class MediaCodecTrackRenderer extends TrackRenderer {
private static boolean codecNeedsFlushWorkaround(String name) {
return Util.SDK_INT < 18
|| (Util.SDK_INT == 18
&& ("OMX.SEC.avc.dec".equals(name) || "OMX.SEC.avc.dec.secure".equals(name)))
&& ("OMX.SEC.avc.dec".equals(name) || "OMX.SEC.avc.dec.secure".equals(name)))
|| (Util.SDK_INT == 19 && Util.MODEL.startsWith("SM-G800")
&& ("OMX.Exynos.avc.dec".equals(name) || "OMX.Exynos.avc.dec.secure".equals(name)));
&& ("OMX.Exynos.avc.dec".equals(name) || "OMX.Exynos.avc.dec.secure".equals(name)));
}
/**
......
......@@ -204,7 +204,6 @@ public class MediaCodecVideoTrackRenderer extends MediaCodecTrackRenderer {
@Override
protected void onEnabled(boolean joining) throws ExoPlaybackException {
super.onEnabled(joining);
codecCounters.reset();
eventDispatcher.enabled(codecCounters);
frameReleaseTimeHelper.enable();
}
......@@ -271,7 +270,6 @@ public class MediaCodecVideoTrackRenderer extends MediaCodecTrackRenderer {
@Override
protected void onDisabled() {
eventDispatcher.disabled();
currentWidth = -1;
currentHeight = -1;
currentPixelWidthHeightRatio = -1;
......@@ -280,7 +278,12 @@ public class MediaCodecVideoTrackRenderer extends MediaCodecTrackRenderer {
lastReportedHeight = -1;
lastReportedPixelWidthHeightRatio = -1;
frameReleaseTimeHelper.disable();
super.onDisabled();
try {
super.onDisabled();
} finally {
codecCounters.ensureUpdated();
eventDispatcher.disabled(codecCounters);
}
}
@Override
......@@ -378,7 +381,7 @@ public class MediaCodecVideoTrackRenderer extends MediaCodecTrackRenderer {
Format oldFormat, Format newFormat) {
return newFormat.sampleMimeType.equals(oldFormat.sampleMimeType)
&& (codecIsAdaptive
|| (oldFormat.width == newFormat.width && oldFormat.height == newFormat.height));
|| (oldFormat.width == newFormat.width && oldFormat.height == newFormat.height));
}
@Override
......
......@@ -61,12 +61,16 @@ public final class SimpleExoPlayer implements ExoPlayer {
* A listener for debugging information.
*/
public interface DebugListener {
void onAudioEnabled(CodecCounters counters);
void onAudioDecoderInitialized(String decoderName, long elapsedRealtimeMs,
long initializationDurationMs);
void onAudioFormatChanged(Format format);
void onAudioDisabled(CodecCounters counters);
void onVideoEnabled(CodecCounters counters);
void onVideoDecoderInitialized(String decoderName, long elapsedRealtimeMs,
long initializationDurationMs);
void onVideoFormatChanged(Format format);
void onVideoDisabled(CodecCounters counters);
void onDroppedFrames(int count, long elapsed);
void onAudioTrackUnderrun(int bufferSize, long bufferSizeMs, long elapsedSinceLastFeedMs);
}
......@@ -469,6 +473,9 @@ public final class SimpleExoPlayer implements ExoPlayer {
@Override
public void onVideoEnabled(CodecCounters counters) {
videoCodecCounters = counters;
if (debugListener != null) {
debugListener.onVideoEnabled(counters);
}
}
@Override
......@@ -512,14 +519,12 @@ public final class SimpleExoPlayer implements ExoPlayer {
}
@Override
public void onVideoDisabled() {
videoCodecCounters = null;
if (videoFormat != null) {
videoFormat = null;
if (debugListener != null) {
debugListener.onVideoFormatChanged(null);
}
public void onVideoDisabled(CodecCounters counters) {
if (debugListener != null) {
debugListener.onVideoDisabled(counters);
}
videoFormat = null;
videoCodecCounters = null;
}
// AudioTrackRendererEventListener implementation
......@@ -527,6 +532,9 @@ public final class SimpleExoPlayer implements ExoPlayer {
@Override
public void onAudioEnabled(CodecCounters counters) {
audioCodecCounters = counters;
if (debugListener != null) {
debugListener.onAudioEnabled(counters);
}
}
@Override
......@@ -555,14 +563,12 @@ public final class SimpleExoPlayer implements ExoPlayer {
}
@Override
public void onAudioDisabled() {
audioCodecCounters = null;
if (audioFormat != null) {
audioFormat = null;
if (debugListener != null) {
debugListener.onAudioFormatChanged(null);
}
public void onAudioDisabled(CodecCounters counters) {
if (debugListener != null) {
debugListener.onAudioDisabled(counters);
}
audioFormat = null;
audioCodecCounters = null;
}
// TextRenderer implementation
......
......@@ -30,7 +30,8 @@ public interface VideoTrackRendererEventListener {
/**
* Invoked when the renderer is enabled.
*
* @param counters {@link CodecCounters} that will be updated by the renderer.
* @param counters {@link CodecCounters} that will be updated by the renderer for as long as it
* remains enabled.
*/
void onVideoEnabled(CodecCounters counters);
......@@ -94,8 +95,10 @@ public interface VideoTrackRendererEventListener {
/**
* Invoked when the renderer is disabled.
*
* @param counters {@link CodecCounters} that were updated by the renderer.
*/
void onVideoDisabled();
void onVideoDisabled(CodecCounters counters);
/**
* Dispatches events to a {@link VideoTrackRendererEventListener}.
......@@ -180,12 +183,12 @@ public interface VideoTrackRendererEventListener {
}
}
public void disabled() {
public void disabled(final CodecCounters counters) {
if (listener != null) {
handler.post(new Runnable() {
@Override
public void run() {
listener.onVideoDisabled();
listener.onVideoDisabled(counters);
}
});
}
......
......@@ -39,11 +39,10 @@ import android.os.SystemClock;
*/
public abstract class AudioDecoderTrackRenderer extends TrackRenderer implements MediaClock {
public final CodecCounters codecCounters = new CodecCounters();
private final EventDispatcher eventDispatcher;
private final FormatHolder formatHolder;
private CodecCounters codecCounters;
private Format inputFormat;
private SimpleDecoder<DecoderInputBuffer, ? extends SimpleOutputBuffer,
? extends AudioDecoderException> decoder;
......@@ -292,7 +291,7 @@ public abstract class AudioDecoderTrackRenderer extends TrackRenderer implements
@Override
protected void onEnabled(boolean joining) throws ExoPlaybackException {
codecCounters.reset();
codecCounters = new CodecCounters();
eventDispatcher.enabled(codecCounters);
}
......@@ -320,7 +319,6 @@ public abstract class AudioDecoderTrackRenderer extends TrackRenderer implements
@Override
protected void onDisabled() {
eventDispatcher.disabled();
inputBuffer = null;
outputBuffer = null;
inputFormat = null;
......@@ -333,7 +331,8 @@ public abstract class AudioDecoderTrackRenderer extends TrackRenderer implements
}
audioTrack.release();
} finally {
super.onDisabled();
codecCounters.ensureUpdated();
eventDispatcher.disabled(codecCounters);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment