Commit f1c646b7 by Oliver Woodman

Add diagnostic info to decoder exceptions + minor cleanup

parent 59688397
...@@ -68,8 +68,8 @@ public class MediaCodecAudioTrackRenderer extends MediaCodecTrackRenderer { ...@@ -68,8 +68,8 @@ public class MediaCodecAudioTrackRenderer extends MediaCodecTrackRenderer {
public AudioTrackInitializationException(int audioTrackState, int sampleRate, public AudioTrackInitializationException(int audioTrackState, int sampleRate,
int channelConfig, int bufferSize) { int channelConfig, int bufferSize) {
super("AudioTrack init failed: " + audioTrackState + ", Config(" + sampleRate + ", " + super("AudioTrack init failed: " + audioTrackState + ", Config(" + sampleRate + ", "
channelConfig + ", " + bufferSize + ")"); + channelConfig + ", " + bufferSize + ")");
this.audioTrackState = audioTrackState; this.audioTrackState = audioTrackState;
} }
...@@ -538,8 +538,8 @@ public class MediaCodecAudioTrackRenderer extends MediaCodecTrackRenderer { ...@@ -538,8 +538,8 @@ public class MediaCodecAudioTrackRenderer extends MediaCodecTrackRenderer {
// Compute the audio track latency, excluding the latency due to the buffer (leaving // Compute the audio track latency, excluding the latency due to the buffer (leaving
// latency due to the mixer and audio hardware driver). // latency due to the mixer and audio hardware driver).
audioTrackLatencyUs = audioTrackLatencyUs =
(Integer) audioTrackGetLatencyMethod.invoke(audioTrack, (Object[]) null) * 1000L - (Integer) audioTrackGetLatencyMethod.invoke(audioTrack, (Object[]) null) * 1000L
framesToDurationUs(bufferSize / frameSize); - framesToDurationUs(bufferSize / frameSize);
// Sanity check that the latency is non-negative. // Sanity check that the latency is non-negative.
audioTrackLatencyUs = Math.max(audioTrackLatencyUs, 0); audioTrackLatencyUs = Math.max(audioTrackLatencyUs, 0);
// Sanity check that the latency isn't too large. // Sanity check that the latency isn't too large.
...@@ -612,19 +612,19 @@ public class MediaCodecAudioTrackRenderer extends MediaCodecTrackRenderer { ...@@ -612,19 +612,19 @@ public class MediaCodecAudioTrackRenderer extends MediaCodecTrackRenderer {
if (temporaryBufferSize == 0) { if (temporaryBufferSize == 0) {
// This is the first time we've seen this {@code buffer}. // This is the first time we've seen this {@code buffer}.
// Note: presentationTimeUs corresponds to the end of the sample, not the start. // Note: presentationTimeUs corresponds to the end of the sample, not the start.
long bufferStartTime = bufferInfo.presentationTimeUs - long bufferStartTime = bufferInfo.presentationTimeUs
framesToDurationUs(bufferInfo.size / frameSize); - framesToDurationUs(bufferInfo.size / frameSize);
if (audioTrackStartMediaTimeState == START_NOT_SET) { if (audioTrackStartMediaTimeState == START_NOT_SET) {
audioTrackStartMediaTimeUs = Math.max(0, bufferStartTime); audioTrackStartMediaTimeUs = Math.max(0, bufferStartTime);
audioTrackStartMediaTimeState = START_IN_SYNC; audioTrackStartMediaTimeState = START_IN_SYNC;
} else { } else {
// Sanity check that bufferStartTime is consistent with the expected value. // Sanity check that bufferStartTime is consistent with the expected value.
long expectedBufferStartTime = audioTrackStartMediaTimeUs + long expectedBufferStartTime = audioTrackStartMediaTimeUs
framesToDurationUs(submittedBytes / frameSize); + framesToDurationUs(submittedBytes / frameSize);
if (audioTrackStartMediaTimeState == START_IN_SYNC if (audioTrackStartMediaTimeState == START_IN_SYNC
&& Math.abs(expectedBufferStartTime - bufferStartTime) > 200000) { && Math.abs(expectedBufferStartTime - bufferStartTime) > 200000) {
Log.e(TAG, "Discontinuity detected [expected " + expectedBufferStartTime + ", got " + Log.e(TAG, "Discontinuity detected [expected " + expectedBufferStartTime + ", got "
bufferStartTime + "]"); + bufferStartTime + "]");
audioTrackStartMediaTimeState = START_NEED_SYNC; audioTrackStartMediaTimeState = START_NEED_SYNC;
} }
if (audioTrackStartMediaTimeState == START_NEED_SYNC) { if (audioTrackStartMediaTimeState == START_NEED_SYNC) {
...@@ -679,7 +679,7 @@ public class MediaCodecAudioTrackRenderer extends MediaCodecTrackRenderer { ...@@ -679,7 +679,7 @@ public class MediaCodecAudioTrackRenderer extends MediaCodecTrackRenderer {
} }
@TargetApi(21) @TargetApi(21)
private int writeNonBlockingV21(AudioTrack audioTrack, ByteBuffer buffer, int size) { private static int writeNonBlockingV21(AudioTrack audioTrack, ByteBuffer buffer, int size) {
return audioTrack.write(buffer, size, AudioTrack.WRITE_NON_BLOCKING); return audioTrack.write(buffer, size, AudioTrack.WRITE_NON_BLOCKING);
} }
...@@ -703,8 +703,8 @@ public class MediaCodecAudioTrackRenderer extends MediaCodecTrackRenderer { ...@@ -703,8 +703,8 @@ public class MediaCodecAudioTrackRenderer extends MediaCodecTrackRenderer {
} }
private int getPendingFrameCount() { private int getPendingFrameCount() {
return audioTrack == null ? return audioTrack == null
0 : (int) (submittedBytes / frameSize - getPlaybackHeadPosition()); ? 0 : (int) (submittedBytes / frameSize - getPlaybackHeadPosition());
} }
@Override @Override
......
...@@ -21,6 +21,7 @@ import com.google.android.exoplayer.util.Util; ...@@ -21,6 +21,7 @@ import com.google.android.exoplayer.util.Util;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.media.MediaCodec; import android.media.MediaCodec;
import android.media.MediaCodec.CodecException;
import android.media.MediaCodec.CryptoException; import android.media.MediaCodec.CryptoException;
import android.media.MediaCrypto; import android.media.MediaCrypto;
import android.media.MediaExtractor; import android.media.MediaExtractor;
...@@ -70,10 +71,24 @@ public abstract class MediaCodecTrackRenderer extends TrackRenderer { ...@@ -70,10 +71,24 @@ public abstract class MediaCodecTrackRenderer extends TrackRenderer {
*/ */
public final String decoderName; public final String decoderName;
/**
* An optional developer-readable diagnostic information string. May be null.
*/
public final String diagnosticInfo;
public DecoderInitializationException(String decoderName, MediaFormat mediaFormat, public DecoderInitializationException(String decoderName, MediaFormat mediaFormat,
Exception cause) { Throwable cause) {
super("Decoder init failed: " + decoderName + ", " + mediaFormat, cause); super("Decoder init failed: " + decoderName + ", " + mediaFormat, cause);
this.decoderName = decoderName; this.decoderName = decoderName;
this.diagnosticInfo = Util.SDK_INT >= 21 ? getDiagnosticInfoV21(cause) : null;
}
@TargetApi(21)
private static String getDiagnosticInfoV21(Throwable cause) {
if (cause instanceof CodecException) {
return ((CodecException) cause).getDiagnosticInfo();
}
return null;
} }
} }
...@@ -235,6 +250,7 @@ public abstract class MediaCodecTrackRenderer extends TrackRenderer { ...@@ -235,6 +250,7 @@ public abstract class MediaCodecTrackRenderer extends TrackRenderer {
codec.configure(x, null, crypto, 0); codec.configure(x, null, crypto, 0);
} }
@SuppressWarnings("deprecation")
protected final void maybeInitCodec() throws ExoPlaybackException { protected final void maybeInitCodec() throws ExoPlaybackException {
if (!shouldInitCodec()) { if (!shouldInitCodec()) {
return; return;
...@@ -694,6 +710,7 @@ public abstract class MediaCodecTrackRenderer extends TrackRenderer { ...@@ -694,6 +710,7 @@ public abstract class MediaCodecTrackRenderer extends TrackRenderer {
* @return True if it may be possible to drain more output data. False otherwise. * @return True if it may be possible to drain more output data. False otherwise.
* @throws ExoPlaybackException If an error occurs draining the output buffer. * @throws ExoPlaybackException If an error occurs draining the output buffer.
*/ */
@SuppressWarnings("deprecation")
private boolean drainOutputBuffer(long positionUs, long elapsedRealtimeUs) private boolean drainOutputBuffer(long positionUs, long elapsedRealtimeUs)
throws ExoPlaybackException { throws ExoPlaybackException {
if (outputStreamEnded) { if (outputStreamEnded) {
......
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