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