Commit ffc6a0d5 by samrobinson Committed by kim-vde

Add Format field to AudioSink.ConfigurationException

#exofixit

PiperOrigin-RevId: 343857564
parent aec3e458
......@@ -144,20 +144,20 @@ public interface AudioSink {
*/
final class ConfigurationException extends Exception {
/**
* Creates a new configuration exception with the specified {@code cause} and no message.
*/
public ConfigurationException(Throwable cause) {
/** Input {@link Format} of the sink when the configuration failure occurs. */
public final Format format;
/** Creates a new configuration exception with the specified {@code cause} and no message. */
public ConfigurationException(Throwable cause, Format format) {
super(cause);
this.format = format;
}
/**
* Creates a new configuration exception with the specified {@code message} and no cause.
*/
public ConfigurationException(String message) {
/** Creates a new configuration exception with the specified {@code message} and no cause. */
public ConfigurationException(String message, Format format) {
super(message);
this.format = format;
}
}
/** Thrown when a failure occurs initializing the sink. */
......
......@@ -300,8 +300,10 @@ public abstract class DecoderAudioRenderer<
while (drainOutputBuffer()) {}
while (feedInputBuffer()) {}
TraceUtil.endSection();
} catch (DecoderException | AudioSink.ConfigurationException e) {
} catch (DecoderException e) {
throw createRendererException(e, inputFormat);
} catch (AudioSink.ConfigurationException e) {
throw createRendererException(e, e.format);
} catch (AudioSink.InitializationException e) {
throw createRendererException(e, inputFormat, e.isRecoverable);
} catch (AudioSink.WriteException e) {
......
......@@ -535,7 +535,7 @@ public final class DefaultAudioSink implements AudioSink {
outputFormat = nextFormat;
}
} catch (UnhandledAudioFormatException e) {
throw new ConfigurationException(e);
throw new ConfigurationException(e, inputFormat);
}
}
......@@ -562,7 +562,8 @@ public final class DefaultAudioSink implements AudioSink {
Pair<Integer, Integer> encodingAndChannelConfig =
getEncodingAndChannelConfigForPassthrough(inputFormat, audioCapabilities);
if (encodingAndChannelConfig == null) {
throw new ConfigurationException("Unable to configure passthrough for: " + inputFormat);
throw new ConfigurationException(
"Unable to configure passthrough for: " + inputFormat, inputFormat);
}
outputEncoding = encodingAndChannelConfig.first;
outputChannelConfig = encodingAndChannelConfig.second;
......@@ -571,11 +572,12 @@ public final class DefaultAudioSink implements AudioSink {
if (outputEncoding == C.ENCODING_INVALID) {
throw new ConfigurationException(
"Invalid output encoding (mode=" + outputMode + ") for: " + inputFormat);
"Invalid output encoding (mode=" + outputMode + ") for: " + inputFormat, inputFormat);
}
if (outputChannelConfig == AudioFormat.CHANNEL_INVALID) {
throw new ConfigurationException(
"Invalid output channel config (mode=" + outputMode + ") for: " + inputFormat);
"Invalid output channel config (mode=" + outputMode + ") for: " + inputFormat,
inputFormat);
}
offloadDisabledUntilNextConfiguration = false;
......
......@@ -436,7 +436,7 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
try {
audioSink.configure(audioSinkInputFormat, /* specifiedBufferSize= */ 0, channelMap);
} catch (AudioSink.ConfigurationException e) {
throw createRendererException(e, format);
throw createRendererException(e, e.format);
}
}
......
......@@ -30,6 +30,7 @@ import com.google.android.exoplayer2.util.MimeTypes;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Arrays;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
......@@ -307,6 +308,18 @@ public final class DefaultAudioSinkTest {
.isEqualTo(CURRENT_POSITION_NOT_SET);
}
@Test
public void configure_throwsConfigurationException_withInvalidInput() {
Format format = new Format.Builder().setSampleMimeType(MimeTypes.AUDIO_AAC).build();
AudioSink.ConfigurationException thrown =
Assert.assertThrows(
AudioSink.ConfigurationException.class,
() ->
defaultAudioSink.configure(
format, /* specifiedBufferSize= */ 0, /* outputChannels= */ null));
assertThat(thrown.format).isEqualTo(format);
}
private void configureDefaultAudioSink(int channelCount) throws AudioSink.ConfigurationException {
configureDefaultAudioSink(channelCount, /* trimStartFrames= */ 0, /* trimEndFrames= */ 0);
}
......
......@@ -236,7 +236,7 @@ public class MediaCodecAudioRendererTest {
if (!format.equals(AUDIO_AAC)) {
setPendingPlaybackException(
ExoPlaybackException.createForRenderer(
new AudioSink.ConfigurationException("Test"),
new AudioSink.ConfigurationException("Test", format),
"rendererName",
/* rendererIndex= */ 0,
format,
......
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