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;
|
||||
/** If the exception can be recovered by recreating the sink. */
|
||||
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);
|
||||
this.isRecoverable = isRecoverable;
|
||||
this.errorCode = errorCode;
|
||||
this.format = format;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -261,7 +261,7 @@ public abstract class DecoderAudioRenderer<
|
||||
try {
|
||||
audioSink.playToEndOfStream();
|
||||
} catch (AudioSink.WriteException e) {
|
||||
throw createRendererException(e, inputFormat, e.isRecoverable);
|
||||
throw createRendererException(e, e.format, e.isRecoverable);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -307,7 +307,7 @@ public abstract class DecoderAudioRenderer<
|
||||
} catch (AudioSink.InitializationException e) {
|
||||
throw createRendererException(e, e.format, e.isRecoverable);
|
||||
} catch (AudioSink.WriteException e) {
|
||||
throw createRendererException(e, inputFormat, e.isRecoverable);
|
||||
throw createRendererException(e, e.format, e.isRecoverable);
|
||||
}
|
||||
decoderCounters.ensureUpdated();
|
||||
}
|
||||
@ -395,7 +395,7 @@ public abstract class DecoderAudioRenderer<
|
||||
try {
|
||||
processEndOfStream();
|
||||
} catch (AudioSink.WriteException e) {
|
||||
throw createRendererException(e, getOutputFormat(decoder), e.isRecoverable);
|
||||
throw createRendererException(e, e.format, e.isRecoverable);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
@ -952,7 +952,7 @@ public final class DefaultAudioSink implements AudioSink {
|
||||
if (isRecoverable) {
|
||||
maybeDisableOffload();
|
||||
}
|
||||
WriteException e = new WriteException(error, isRecoverable);
|
||||
WriteException e = new WriteException(error, configuration.inputFormat, isRecoverable);
|
||||
if (listener != null) {
|
||||
listener.onAudioSinkError(e);
|
||||
}
|
||||
|
@ -629,9 +629,7 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
|
||||
try {
|
||||
audioSink.playToEndOfStream();
|
||||
} catch (AudioSink.WriteException e) {
|
||||
@Nullable Format outputFormat = getOutputFormat();
|
||||
throw createRendererException(
|
||||
e, outputFormat != null ? outputFormat : getInputFormat(), e.isRecoverable);
|
||||
throw createRendererException(e, e.format, e.isRecoverable);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -310,7 +310,9 @@ public class MediaCodecAudioRendererTest {
|
||||
verify(audioSink, atLeastOnce()).setListener(listenerCaptor.capture());
|
||||
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);
|
||||
|
||||
shadowOf(Looper.getMainLooper()).idle();
|
||||
|
Loading…
x
Reference in New Issue
Block a user