Improve error logging

Log at debug level immediately when MediaCodec throws. This logging will be
output closer to the time when the error actually happened so should make it
easier to identify the order of components failing.

Downgrade logging of errors after export ends to warning level, as output may
still be fine if there was a problem after exporting completed (though it's
still worth logging a warning as the device may not be in a good state).

PiperOrigin-RevId: 523370457
This commit is contained in:
andrewlewis 2023-04-11 13:09:18 +01:00 committed by Rohit Singh
parent be85684dc9
commit ba2c32738f
2 changed files with 10 additions and 1 deletions

View File

@ -126,6 +126,8 @@ public final class DefaultCodec implements Codec {
} }
startCodec(mediaCodec); startCodec(mediaCodec);
} catch (Exception e) { } catch (Exception e) {
Log.d(TAG, "MediaCodec error", e);
if (inputSurface != null) { if (inputSurface != null) {
inputSurface.release(); inputSurface.release();
} }
@ -181,6 +183,7 @@ public final class DefaultCodec implements Codec {
try { try {
inputBufferIndex = mediaCodec.dequeueInputBuffer(/* timeoutUs= */ 0); inputBufferIndex = mediaCodec.dequeueInputBuffer(/* timeoutUs= */ 0);
} catch (RuntimeException e) { } catch (RuntimeException e) {
Log.d(TAG, "MediaCodec error", e);
throw createExportException(e); throw createExportException(e);
} }
if (inputBufferIndex < 0) { if (inputBufferIndex < 0) {
@ -189,6 +192,7 @@ public final class DefaultCodec implements Codec {
try { try {
inputBuffer.data = mediaCodec.getInputBuffer(inputBufferIndex); inputBuffer.data = mediaCodec.getInputBuffer(inputBufferIndex);
} catch (RuntimeException e) { } catch (RuntimeException e) {
Log.d(TAG, "MediaCodec error", e);
throw createExportException(e); throw createExportException(e);
} }
inputBuffer.clear(); inputBuffer.clear();
@ -216,6 +220,7 @@ public final class DefaultCodec implements Codec {
try { try {
mediaCodec.queueInputBuffer(inputBufferIndex, offset, size, inputBuffer.timeUs, flags); mediaCodec.queueInputBuffer(inputBufferIndex, offset, size, inputBuffer.timeUs, flags);
} catch (RuntimeException e) { } catch (RuntimeException e) {
Log.d(TAG, "MediaCodec error", e);
throw createExportException(e); throw createExportException(e);
} }
inputBufferIndex = C.INDEX_UNSET; inputBufferIndex = C.INDEX_UNSET;
@ -227,6 +232,7 @@ public final class DefaultCodec implements Codec {
try { try {
mediaCodec.signalEndOfInputStream(); mediaCodec.signalEndOfInputStream();
} catch (RuntimeException e) { } catch (RuntimeException e) {
Log.d(TAG, "MediaCodec error", e);
throw createExportException(e); throw createExportException(e);
} }
} }
@ -272,6 +278,7 @@ public final class DefaultCodec implements Codec {
mediaCodec.releaseOutputBuffer(outputBufferIndex, /* render= */ false); mediaCodec.releaseOutputBuffer(outputBufferIndex, /* render= */ false);
} }
} catch (RuntimeException e) { } catch (RuntimeException e) {
Log.d(TAG, "MediaCodec error", e);
throw createExportException(e); throw createExportException(e);
} }
outputBufferIndex = C.INDEX_UNSET; outputBufferIndex = C.INDEX_UNSET;
@ -329,6 +336,7 @@ public final class DefaultCodec implements Codec {
try { try {
outputBufferIndex = mediaCodec.dequeueOutputBuffer(outputBufferInfo, /* timeoutUs= */ 0); outputBufferIndex = mediaCodec.dequeueOutputBuffer(outputBufferInfo, /* timeoutUs= */ 0);
} catch (RuntimeException e) { } catch (RuntimeException e) {
Log.d(TAG, "MediaCodec error", e);
throw createExportException(e); throw createExportException(e);
} }
if (outputBufferIndex < 0) { if (outputBufferIndex < 0) {
@ -370,6 +378,7 @@ public final class DefaultCodec implements Codec {
try { try {
outputBuffer = checkNotNull(mediaCodec.getOutputBuffer(outputBufferIndex)); outputBuffer = checkNotNull(mediaCodec.getOutputBuffer(outputBufferIndex));
} catch (RuntimeException e) { } catch (RuntimeException e) {
Log.d(TAG, "MediaCodec error", e);
throw createExportException(e); throw createExportException(e);
} }
outputBuffer.position(outputBufferInfo.offset); outputBuffer.position(outputBufferInfo.offset);

View File

@ -398,7 +398,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
if (exception != null) { if (exception != null) {
if (releasedPreviously) { if (releasedPreviously) {
Log.e(TAG, "Export error after export ended: ", exception); Log.w(TAG, "Export error after export ended", exception);
return; return;
} }
ExportException finalException = exception; ExportException finalException = exception;