Add Format field to AudioSink.WriteException.
#exofixit PiperOrigin-RevId: 344414313
This commit is contained in:
parent
1cdf5e79e3
commit
f1cf3d98d8
@ -214,12 +214,21 @@ public interface AudioSink {
|
|||||||
public final int errorCode;
|
public final int errorCode;
|
||||||
/** If the exception can be recovered by recreating the sink. */
|
/** If the exception can be recovered by recreating the sink. */
|
||||||
public final boolean isRecoverable;
|
public final boolean isRecoverable;
|
||||||
|
/** The input {@link Format} of the sink when the error occurs. */
|
||||||
|
public final Format format;
|
||||||
|
|
||||||
/** @param errorCode The error value returned from the sink implementation. */
|
/**
|
||||||
public WriteException(int errorCode, boolean isRecoverable) {
|
* Creates an instance.
|
||||||
|
*
|
||||||
|
* @param errorCode The error value returned from the sink implementation.
|
||||||
|
* @param format The input format of the sink when the error occurs.
|
||||||
|
* @param isRecoverable Whether the exception can be recovered by recreating the sink.
|
||||||
|
*/
|
||||||
|
public WriteException(int errorCode, Format format, boolean isRecoverable) {
|
||||||
super("AudioTrack write failed: " + errorCode);
|
super("AudioTrack write failed: " + errorCode);
|
||||||
this.isRecoverable = isRecoverable;
|
this.isRecoverable = isRecoverable;
|
||||||
this.errorCode = errorCode;
|
this.errorCode = errorCode;
|
||||||
|
this.format = format;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -261,7 +261,7 @@ public abstract class DecoderAudioRenderer<
|
|||||||
try {
|
try {
|
||||||
audioSink.playToEndOfStream();
|
audioSink.playToEndOfStream();
|
||||||
} catch (AudioSink.WriteException e) {
|
} catch (AudioSink.WriteException e) {
|
||||||
throw createRendererException(e, inputFormat, e.isRecoverable);
|
throw createRendererException(e, e.format, e.isRecoverable);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -307,7 +307,7 @@ public abstract class DecoderAudioRenderer<
|
|||||||
} catch (AudioSink.InitializationException e) {
|
} catch (AudioSink.InitializationException e) {
|
||||||
throw createRendererException(e, e.format, e.isRecoverable);
|
throw createRendererException(e, e.format, e.isRecoverable);
|
||||||
} catch (AudioSink.WriteException e) {
|
} catch (AudioSink.WriteException e) {
|
||||||
throw createRendererException(e, inputFormat, e.isRecoverable);
|
throw createRendererException(e, e.format, e.isRecoverable);
|
||||||
}
|
}
|
||||||
decoderCounters.ensureUpdated();
|
decoderCounters.ensureUpdated();
|
||||||
}
|
}
|
||||||
@ -395,7 +395,7 @@ public abstract class DecoderAudioRenderer<
|
|||||||
try {
|
try {
|
||||||
processEndOfStream();
|
processEndOfStream();
|
||||||
} catch (AudioSink.WriteException e) {
|
} catch (AudioSink.WriteException e) {
|
||||||
throw createRendererException(e, getOutputFormat(decoder), e.isRecoverable);
|
throw createRendererException(e, e.format, e.isRecoverable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -952,7 +952,7 @@ public final class DefaultAudioSink implements AudioSink {
|
|||||||
if (isRecoverable) {
|
if (isRecoverable) {
|
||||||
maybeDisableOffload();
|
maybeDisableOffload();
|
||||||
}
|
}
|
||||||
WriteException e = new WriteException(error, isRecoverable);
|
WriteException e = new WriteException(error, configuration.inputFormat, isRecoverable);
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
listener.onAudioSinkError(e);
|
listener.onAudioSinkError(e);
|
||||||
}
|
}
|
||||||
|
@ -629,9 +629,7 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
|
|||||||
try {
|
try {
|
||||||
audioSink.playToEndOfStream();
|
audioSink.playToEndOfStream();
|
||||||
} catch (AudioSink.WriteException e) {
|
} catch (AudioSink.WriteException e) {
|
||||||
@Nullable Format outputFormat = getOutputFormat();
|
throw createRendererException(e, e.format, e.isRecoverable);
|
||||||
throw createRendererException(
|
|
||||||
e, outputFormat != null ? outputFormat : getInputFormat(), e.isRecoverable);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -310,7 +310,9 @@ public class MediaCodecAudioRendererTest {
|
|||||||
verify(audioSink, atLeastOnce()).setListener(listenerCaptor.capture());
|
verify(audioSink, atLeastOnce()).setListener(listenerCaptor.capture());
|
||||||
AudioSink.Listener audioSinkListener = listenerCaptor.getValue();
|
AudioSink.Listener audioSinkListener = listenerCaptor.getValue();
|
||||||
|
|
||||||
Exception error = new AudioSink.WriteException(/* errorCode= */ 1, /* isRecoverable= */ true);
|
Exception error =
|
||||||
|
new AudioSink.WriteException(
|
||||||
|
/* errorCode= */ 1, new Format.Builder().build(), /* isRecoverable= */ true);
|
||||||
audioSinkListener.onAudioSinkError(error);
|
audioSinkListener.onAudioSinkError(error);
|
||||||
|
|
||||||
shadowOf(Looper.getMainLooper()).idle();
|
shadowOf(Looper.getMainLooper()).idle();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user