Commit 78825a41 by krocard Committed by Oliver Woodman

Store encodings in Format instead of just pcm encodings

Previously only pcm encoding were stored in Format,
this was an issue as for audio passthrough and offload
lots of code needs to pass complex format informations
(encoding, sample rate, channel count, gapless metadata)
but could not use Format and each function was taking
each as different parameter.

By allowing Format to contain any encoding, and not only
pcmEncoding, it allows to pass a Format everywhere in ExoPlayer
code that needs a Format.

This patch does not have any functional change. It is only an internal refactor.

PiperOrigin-RevId: 318789444
parent f770ff67
Showing with 250 additions and 310 deletions
...@@ -137,25 +137,27 @@ public final class FfmpegAudioRenderer extends DecoderAudioRenderer { ...@@ -137,25 +137,27 @@ public final class FfmpegAudioRenderer extends DecoderAudioRenderer {
.setSampleMimeType(MimeTypes.AUDIO_RAW) .setSampleMimeType(MimeTypes.AUDIO_RAW)
.setChannelCount(decoder.getChannelCount()) .setChannelCount(decoder.getChannelCount())
.setSampleRate(decoder.getSampleRate()) .setSampleRate(decoder.getSampleRate())
.setPcmEncoding(decoder.getEncoding()) .setEncoding(decoder.getEncoding())
.build(); .build();
} }
private boolean isOutputSupported(Format inputFormat) { private boolean isOutputSupported(Format inputFormat) {
return shouldUseFloatOutput(inputFormat) || supportsOutput(inputFormat, C.ENCODING_PCM_16BIT); return shouldUseFloatOutput(inputFormat)
|| supportsOutput(inputFormat.buildUpon().setEncoding(C.ENCODING_PCM_16BIT).build());
} }
private boolean shouldUseFloatOutput(Format inputFormat) { private boolean shouldUseFloatOutput(Format inputFormat) {
Assertions.checkNotNull(inputFormat.sampleMimeType); Assertions.checkNotNull(inputFormat.sampleMimeType);
if (!enableFloatOutput || !supportsOutput(inputFormat, C.ENCODING_PCM_FLOAT)) { if (!enableFloatOutput
|| !supportsOutput(inputFormat.buildUpon().setEncoding(C.ENCODING_PCM_FLOAT).build())) {
return false; return false;
} }
switch (inputFormat.sampleMimeType) { switch (inputFormat.sampleMimeType) {
case MimeTypes.AUDIO_RAW: case MimeTypes.AUDIO_RAW:
// For raw audio, output in 32-bit float encoding if the bit depth is > 16-bit. // For raw audio, output in 32-bit float encoding if the bit depth is > 16-bit.
return inputFormat.pcmEncoding == C.ENCODING_PCM_24BIT return inputFormat.encoding == C.ENCODING_PCM_24BIT
|| inputFormat.pcmEncoding == C.ENCODING_PCM_32BIT || inputFormat.encoding == C.ENCODING_PCM_32BIT
|| inputFormat.pcmEncoding == C.ENCODING_PCM_FLOAT; || inputFormat.encoding == C.ENCODING_PCM_FLOAT;
case MimeTypes.AUDIO_AC3: case MimeTypes.AUDIO_AC3:
// AC-3 is always 16-bit, so there is no point outputting in 32-bit float encoding. // AC-3 is always 16-bit, so there is no point outputting in 32-bit float encoding.
return false; return false;
......
...@@ -279,7 +279,7 @@ public final class FlacExtractor implements Extractor { ...@@ -279,7 +279,7 @@ public final class FlacExtractor implements Extractor {
.setMaxInputSize(streamMetadata.getMaxDecodedFrameSize()) .setMaxInputSize(streamMetadata.getMaxDecodedFrameSize())
.setChannelCount(streamMetadata.channels) .setChannelCount(streamMetadata.channels)
.setSampleRate(streamMetadata.sampleRate) .setSampleRate(streamMetadata.sampleRate)
.setPcmEncoding(getPcmEncoding(streamMetadata.bitsPerSample)) .setEncoding(getPcmEncoding(streamMetadata.bitsPerSample))
.setMetadata(metadata) .setMetadata(metadata)
.build(); .build();
output.format(mediaFormat); output.format(mediaFormat);
......
...@@ -100,7 +100,7 @@ public final class LibflacAudioRenderer extends DecoderAudioRenderer { ...@@ -100,7 +100,7 @@ public final class LibflacAudioRenderer extends DecoderAudioRenderer {
new FlacStreamMetadata(format.initializationData.get(0), streamMetadataOffset); new FlacStreamMetadata(format.initializationData.get(0), streamMetadataOffset);
pcmEncoding = Util.getPcmEncoding(streamMetadata.bitsPerSample); pcmEncoding = Util.getPcmEncoding(streamMetadata.bitsPerSample);
} }
if (!supportsOutput(format, pcmEncoding)) { if (!supportsOutput(format.buildUpon().setEncoding(pcmEncoding).build())) {
return FORMAT_UNSUPPORTED_SUBTYPE; return FORMAT_UNSUPPORTED_SUBTYPE;
} else if (format.drmInitData != null && format.exoMediaCryptoType == null) { } else if (format.drmInitData != null && format.exoMediaCryptoType == null) {
return FORMAT_UNSUPPORTED_DRM; return FORMAT_UNSUPPORTED_DRM;
...@@ -127,7 +127,7 @@ public final class LibflacAudioRenderer extends DecoderAudioRenderer { ...@@ -127,7 +127,7 @@ public final class LibflacAudioRenderer extends DecoderAudioRenderer {
.setSampleMimeType(MimeTypes.AUDIO_RAW) .setSampleMimeType(MimeTypes.AUDIO_RAW)
.setChannelCount(streamMetadata.channels) .setChannelCount(streamMetadata.channels)
.setSampleRate(streamMetadata.sampleRate) .setSampleRate(streamMetadata.sampleRate)
.setPcmEncoding(Util.getPcmEncoding(streamMetadata.bitsPerSample)) .setEncoding(Util.getPcmEncoding(streamMetadata.bitsPerSample))
.build(); .build();
} }
} }
...@@ -69,7 +69,7 @@ public class LibopusAudioRenderer extends DecoderAudioRenderer { ...@@ -69,7 +69,7 @@ public class LibopusAudioRenderer extends DecoderAudioRenderer {
if (!OpusLibrary.isAvailable() if (!OpusLibrary.isAvailable()
|| !MimeTypes.AUDIO_OPUS.equalsIgnoreCase(format.sampleMimeType)) { || !MimeTypes.AUDIO_OPUS.equalsIgnoreCase(format.sampleMimeType)) {
return FORMAT_UNSUPPORTED_TYPE; return FORMAT_UNSUPPORTED_TYPE;
} else if (!supportsOutput(format, C.ENCODING_PCM_16BIT)) { } else if (!supportsOutput(format.buildUpon().setEncoding(C.ENCODING_PCM_16BIT).build())) {
return FORMAT_UNSUPPORTED_SUBTYPE; return FORMAT_UNSUPPORTED_SUBTYPE;
} else if (!drmIsSupported) { } else if (!drmIsSupported) {
return FORMAT_UNSUPPORTED_DRM; return FORMAT_UNSUPPORTED_DRM;
...@@ -103,7 +103,7 @@ public class LibopusAudioRenderer extends DecoderAudioRenderer { ...@@ -103,7 +103,7 @@ public class LibopusAudioRenderer extends DecoderAudioRenderer {
.setSampleMimeType(MimeTypes.AUDIO_RAW) .setSampleMimeType(MimeTypes.AUDIO_RAW)
.setChannelCount(channelCount) .setChannelCount(channelCount)
.setSampleRate(sampleRate) .setSampleRate(sampleRate)
.setPcmEncoding(C.ENCODING_PCM_16BIT) .setEncoding(C.ENCODING_PCM_16BIT)
.build(); .build();
} }
} }
...@@ -94,7 +94,7 @@ import java.util.List; ...@@ -94,7 +94,7 @@ import java.util.List;
* <ul> * <ul>
* <li>{@link #channelCount} * <li>{@link #channelCount}
* <li>{@link #sampleRate} * <li>{@link #sampleRate}
* <li>{@link #pcmEncoding} * <li>{@link #encoding}
* <li>{@link #encoderDelay} * <li>{@link #encoderDelay}
* <li>{@link #encoderPadding} * <li>{@link #encoderPadding}
* </ul> * </ul>
...@@ -155,7 +155,7 @@ public final class Format implements Parcelable { ...@@ -155,7 +155,7 @@ public final class Format implements Parcelable {
private int channelCount; private int channelCount;
private int sampleRate; private int sampleRate;
@C.PcmEncoding private int pcmEncoding; @C.Encoding private int encoding;
private int encoderDelay; private int encoderDelay;
private int encoderPadding; private int encoderPadding;
...@@ -183,7 +183,7 @@ public final class Format implements Parcelable { ...@@ -183,7 +183,7 @@ public final class Format implements Parcelable {
// Audio specific. // Audio specific.
channelCount = NO_VALUE; channelCount = NO_VALUE;
sampleRate = NO_VALUE; sampleRate = NO_VALUE;
pcmEncoding = NO_VALUE; encoding = NO_VALUE;
// Text specific. // Text specific.
accessibilityChannel = NO_VALUE; accessibilityChannel = NO_VALUE;
} }
...@@ -223,7 +223,7 @@ public final class Format implements Parcelable { ...@@ -223,7 +223,7 @@ public final class Format implements Parcelable {
// Audio specific. // Audio specific.
this.channelCount = format.channelCount; this.channelCount = format.channelCount;
this.sampleRate = format.sampleRate; this.sampleRate = format.sampleRate;
this.pcmEncoding = format.pcmEncoding; this.encoding = format.encoding;
this.encoderDelay = format.encoderDelay; this.encoderDelay = format.encoderDelay;
this.encoderPadding = format.encoderPadding; this.encoderPadding = format.encoderPadding;
// Text specific. // Text specific.
...@@ -528,13 +528,13 @@ public final class Format implements Parcelable { ...@@ -528,13 +528,13 @@ public final class Format implements Parcelable {
} }
/** /**
* Sets {@link Format#pcmEncoding}. The default value is {@link #NO_VALUE}. * Sets {@link Format#encoding}. The default value is {@link #NO_VALUE}.
* *
* @param pcmEncoding The {@link Format#pcmEncoding}. * @param encoding The {@link Format#encoding}.
* @return The builder. * @return The builder.
*/ */
public Builder setPcmEncoding(@C.PcmEncoding int pcmEncoding) { public Builder setEncoding(@C.Encoding int encoding) {
this.pcmEncoding = pcmEncoding; this.encoding = encoding;
return this; return this;
} }
...@@ -616,7 +616,7 @@ public final class Format implements Parcelable { ...@@ -616,7 +616,7 @@ public final class Format implements Parcelable {
colorInfo, colorInfo,
channelCount, channelCount,
sampleRate, sampleRate,
pcmEncoding, encoding,
encoderDelay, encoderDelay,
encoderPadding, encoderPadding,
accessibilityChannel, accessibilityChannel,
...@@ -765,8 +765,10 @@ public final class Format implements Parcelable { ...@@ -765,8 +765,10 @@ public final class Format implements Parcelable {
* The audio sampling rate in Hz, or {@link #NO_VALUE} if unknown or not applicable. * The audio sampling rate in Hz, or {@link #NO_VALUE} if unknown or not applicable.
*/ */
public final int sampleRate; public final int sampleRate;
/** The {@link C.PcmEncoding} for PCM audio. Set to {@link #NO_VALUE} for other media types. */ /** @deprecated Use {@link #encoding}. */
@C.PcmEncoding public final int pcmEncoding; @Deprecated @C.PcmEncoding public final int pcmEncoding;
/** The {@link C.Encoding} for audio. Set to {@link #NO_VALUE} for other media types. */
@C.Encoding public final int encoding;
/** /**
* The number of frames to trim from the start of the decoded audio stream, or 0 if not * The number of frames to trim from the start of the decoded audio stream, or 0 if not
* applicable. * applicable.
...@@ -1004,7 +1006,7 @@ public final class Format implements Parcelable { ...@@ -1004,7 +1006,7 @@ public final class Format implements Parcelable {
int maxInputSize, int maxInputSize,
int channelCount, int channelCount,
int sampleRate, int sampleRate,
@C.PcmEncoding int pcmEncoding, @C.Encoding int encoding,
@Nullable List<byte[]> initializationData, @Nullable List<byte[]> initializationData,
@Nullable DrmInitData drmInitData, @Nullable DrmInitData drmInitData,
@C.SelectionFlags int selectionFlags, @C.SelectionFlags int selectionFlags,
...@@ -1022,7 +1024,7 @@ public final class Format implements Parcelable { ...@@ -1022,7 +1024,7 @@ public final class Format implements Parcelable {
.setDrmInitData(drmInitData) .setDrmInitData(drmInitData)
.setChannelCount(channelCount) .setChannelCount(channelCount)
.setSampleRate(sampleRate) .setSampleRate(sampleRate)
.setPcmEncoding(pcmEncoding) .setEncoding(encoding)
.build(); .build();
} }
...@@ -1036,7 +1038,7 @@ public final class Format implements Parcelable { ...@@ -1036,7 +1038,7 @@ public final class Format implements Parcelable {
int maxInputSize, int maxInputSize,
int channelCount, int channelCount,
int sampleRate, int sampleRate,
@C.PcmEncoding int pcmEncoding, @C.Encoding int encoding,
int encoderDelay, int encoderDelay,
int encoderPadding, int encoderPadding,
@Nullable List<byte[]> initializationData, @Nullable List<byte[]> initializationData,
...@@ -1058,7 +1060,7 @@ public final class Format implements Parcelable { ...@@ -1058,7 +1060,7 @@ public final class Format implements Parcelable {
.setDrmInitData(drmInitData) .setDrmInitData(drmInitData)
.setChannelCount(channelCount) .setChannelCount(channelCount)
.setSampleRate(sampleRate) .setSampleRate(sampleRate)
.setPcmEncoding(pcmEncoding) .setEncoding(encoding)
.setEncoderDelay(encoderDelay) .setEncoderDelay(encoderDelay)
.setEncoderPadding(encoderPadding) .setEncoderPadding(encoderPadding)
.build(); .build();
...@@ -1239,7 +1241,7 @@ public final class Format implements Parcelable { ...@@ -1239,7 +1241,7 @@ public final class Format implements Parcelable {
// Audio specific. // Audio specific.
int channelCount, int channelCount,
int sampleRate, int sampleRate,
@C.PcmEncoding int pcmEncoding, @C.Encoding int encoding,
int encoderDelay, int encoderDelay,
int encoderPadding, int encoderPadding,
// Text specific. // Text specific.
...@@ -1277,7 +1279,8 @@ public final class Format implements Parcelable { ...@@ -1277,7 +1279,8 @@ public final class Format implements Parcelable {
// Audio specific. // Audio specific.
this.channelCount = channelCount; this.channelCount = channelCount;
this.sampleRate = sampleRate; this.sampleRate = sampleRate;
this.pcmEncoding = pcmEncoding; this.encoding = encoding;
this.pcmEncoding = toPcmEncoding(encoding);
this.encoderDelay = encoderDelay == NO_VALUE ? 0 : encoderDelay; this.encoderDelay = encoderDelay == NO_VALUE ? 0 : encoderDelay;
this.encoderPadding = encoderPadding == NO_VALUE ? 0 : encoderPadding; this.encoderPadding = encoderPadding == NO_VALUE ? 0 : encoderPadding;
// Text specific. // Text specific.
...@@ -1323,7 +1326,8 @@ public final class Format implements Parcelable { ...@@ -1323,7 +1326,8 @@ public final class Format implements Parcelable {
// Audio specific. // Audio specific.
channelCount = in.readInt(); channelCount = in.readInt();
sampleRate = in.readInt(); sampleRate = in.readInt();
pcmEncoding = in.readInt(); encoding = in.readInt();
pcmEncoding = toPcmEncoding(encoding);
encoderDelay = in.readInt(); encoderDelay = in.readInt();
encoderPadding = in.readInt(); encoderPadding = in.readInt();
// Text specific. // Text specific.
...@@ -1551,7 +1555,7 @@ public final class Format implements Parcelable { ...@@ -1551,7 +1555,7 @@ public final class Format implements Parcelable {
// Audio specific. // Audio specific.
result = 31 * result + channelCount; result = 31 * result + channelCount;
result = 31 * result + sampleRate; result = 31 * result + sampleRate;
result = 31 * result + pcmEncoding; result = 31 * result + encoding;
result = 31 * result + encoderDelay; result = 31 * result + encoderDelay;
result = 31 * result + encoderPadding; result = 31 * result + encoderPadding;
// Text specific. // Text specific.
...@@ -1588,7 +1592,7 @@ public final class Format implements Parcelable { ...@@ -1588,7 +1592,7 @@ public final class Format implements Parcelable {
&& stereoMode == other.stereoMode && stereoMode == other.stereoMode
&& channelCount == other.channelCount && channelCount == other.channelCount
&& sampleRate == other.sampleRate && sampleRate == other.sampleRate
&& pcmEncoding == other.pcmEncoding && encoding == other.encoding
&& encoderDelay == other.encoderDelay && encoderDelay == other.encoderDelay
&& encoderPadding == other.encoderPadding && encoderPadding == other.encoderPadding
&& accessibilityChannel == other.accessibilityChannel && accessibilityChannel == other.accessibilityChannel
...@@ -1709,7 +1713,7 @@ public final class Format implements Parcelable { ...@@ -1709,7 +1713,7 @@ public final class Format implements Parcelable {
// Audio specific. // Audio specific.
dest.writeInt(channelCount); dest.writeInt(channelCount);
dest.writeInt(sampleRate); dest.writeInt(sampleRate);
dest.writeInt(pcmEncoding); dest.writeInt(encoding);
dest.writeInt(encoderDelay); dest.writeInt(encoderDelay);
dest.writeInt(encoderPadding); dest.writeInt(encoderPadding);
// Text specific. // Text specific.
...@@ -1729,4 +1733,9 @@ public final class Format implements Parcelable { ...@@ -1729,4 +1733,9 @@ public final class Format implements Parcelable {
} }
}; };
@C.PcmEncoding
private static int toPcmEncoding(@C.Encoding int encoding) {
return Util.isEncodingLinearPcm(encoding) ? encoding : NO_VALUE;
}
} }
...@@ -18,7 +18,6 @@ package com.google.android.exoplayer2.audio; ...@@ -18,7 +18,6 @@ package com.google.android.exoplayer2.audio;
import android.media.AudioTrack; import android.media.AudioTrack;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.C.Encoding;
import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.PlaybackParameters; import com.google.android.exoplayer2.PlaybackParameters;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
...@@ -26,16 +25,15 @@ import java.nio.ByteBuffer; ...@@ -26,16 +25,15 @@ import java.nio.ByteBuffer;
/** /**
* A sink that consumes audio data. * A sink that consumes audio data.
* *
* <p>Before starting playback, specify the input audio format by calling {@link #configure(int, * <p>Before starting playback, specify the input audio format by calling {@link #configure(Format,
* int, int, int, int[], int, int)}. * int, int[])}.
* *
* <p>Call {@link #handleBuffer(ByteBuffer, long, int)} to write data, and {@link * <p>Call {@link #handleBuffer(ByteBuffer, long, int)} to write data, and {@link
* #handleDiscontinuity()} when the data being fed is discontinuous. Call {@link #play()} to start * #handleDiscontinuity()} when the data being fed is discontinuous. Call {@link #play()} to start
* playing the written data. * playing the written data.
* *
* <p>Call {@link #configure(int, int, int, int, int[], int, int)} whenever the input format * <p>Call {@link #configure(Format, int, int[])} whenever the input format changes. The sink will
* changes. The sink will be reinitialized on the next call to {@link #handleBuffer(ByteBuffer, * be reinitialized on the next call to {@link #handleBuffer(ByteBuffer, long, int)}.
* long, int)}.
* *
* <p>Call {@link #flush()} to prepare the sink to receive audio data from a new playback position. * <p>Call {@link #flush()} to prepare the sink to receive audio data from a new playback position.
* *
...@@ -188,12 +186,10 @@ public interface AudioSink { ...@@ -188,12 +186,10 @@ public interface AudioSink {
/** /**
* Returns whether the sink supports the audio format. * Returns whether the sink supports the audio format.
* *
* @param format The format of the audio. {@link Format#pcmEncoding} is ignored and the {@code * @param format The format of the audio.
* encoding} argument is used instead.
* @param encoding The audio encoding, or {@link Format#NO_VALUE} if not known.
* @return Whether the sink supports the audio format. * @return Whether the sink supports the audio format.
*/ */
boolean supportsOutput(Format format, @Encoding int encoding); boolean supportsOutput(Format format);
/** /**
* Returns the playback position in the stream starting at zero, in microseconds, or * Returns the playback position in the stream starting at zero, in microseconds, or
...@@ -207,9 +203,7 @@ public interface AudioSink { ...@@ -207,9 +203,7 @@ public interface AudioSink {
/** /**
* Configures (or reconfigures) the sink. * Configures (or reconfigures) the sink.
* *
* @param inputEncoding The encoding of audio data provided in the input buffers. * @param inputFormat The format of audio data provided in the input buffers.
* @param inputChannelCount The number of channels.
* @param inputSampleRate The sample rate in Hz.
* @param specifiedBufferSize A specific size for the playback buffer in bytes, or 0 to infer a * @param specifiedBufferSize A specific size for the playback buffer in bytes, or 0 to infer a
* suitable buffer size. * suitable buffer size.
* @param outputChannels A mapping from input to output channels that is applied to this sink's * @param outputChannels A mapping from input to output channels that is applied to this sink's
...@@ -217,20 +211,9 @@ public interface AudioSink { ...@@ -217,20 +211,9 @@ public interface AudioSink {
* input unchanged. Otherwise, the element at index {@code i} specifies index of the input * input unchanged. Otherwise, the element at index {@code i} specifies index of the input
* channel to map to output channel {@code i} when preprocessing input buffers. After the map * channel to map to output channel {@code i} when preprocessing input buffers. After the map
* is applied the audio data will have {@code outputChannels.length} channels. * is applied the audio data will have {@code outputChannels.length} channels.
* @param trimStartFrames The number of audio frames to trim from the start of data written to the
* sink after this call.
* @param trimEndFrames The number of audio frames to trim from data written to the sink
* immediately preceding the next call to {@link #flush()} or this method.
* @throws ConfigurationException If an error occurs configuring the sink. * @throws ConfigurationException If an error occurs configuring the sink.
*/ */
void configure( void configure(Format inputFormat, int specifiedBufferSize, @Nullable int[] outputChannels)
@C.Encoding int inputEncoding,
int inputChannelCount,
int inputSampleRate,
int specifiedBufferSize,
@Nullable int[] outputChannels,
int trimStartFrames,
int trimEndFrames)
throws ConfigurationException; throws ConfigurationException;
/** /**
...@@ -249,8 +232,8 @@ public interface AudioSink { ...@@ -249,8 +232,8 @@ public interface AudioSink {
* *
* <p>Returns whether the data was handled in full. If the data was not handled in full then the * <p>Returns whether the data was handled in full. If the data was not handled in full then the
* same {@link ByteBuffer} must be provided to subsequent calls until it has been fully consumed, * same {@link ByteBuffer} must be provided to subsequent calls until it has been fully consumed,
* except in the case of an intervening call to {@link #flush()} (or to {@link #configure(int, * except in the case of an intervening call to {@link #flush()} (or to {@link #configure(Format,
* int, int, int, int[], int, int)} that causes the sink to be flushed). * int, int[])} that causes the sink to be flushed).
* *
* @param buffer The buffer containing audio data. * @param buffer The buffer containing audio data.
* @param presentationTimeUs The presentation timestamp of the buffer in microseconds. * @param presentationTimeUs The presentation timestamp of the buffer in microseconds.
......
...@@ -35,7 +35,7 @@ import java.nio.ByteBuffer; ...@@ -35,7 +35,7 @@ import java.nio.ByteBuffer;
* *
* @param outputChannels The mapping from input to output channel indices, or {@code null} to * @param outputChannels The mapping from input to output channel indices, or {@code null} to
* leave the input unchanged. * leave the input unchanged.
* @see AudioSink#configure(int, int, int, int, int[], int, int) * @see AudioSink#configure(com.google.android.exoplayer2.Format, int, int[])
*/ */
public void setChannelMap(@Nullable int[] outputChannels) { public void setChannelMap(@Nullable int[] outputChannels) {
pendingOutputChannels = outputChannels; pendingOutputChannels = outputChannels;
......
...@@ -213,10 +213,10 @@ public abstract class DecoderAudioRenderer extends BaseRenderer implements Media ...@@ -213,10 +213,10 @@ public abstract class DecoderAudioRenderer extends BaseRenderer implements Media
/** /**
* Returns whether the sink supports the audio format. * Returns whether the sink supports the audio format.
* *
* @see AudioSink#supportsOutput(Format, int) * @see AudioSink#supportsOutput(Format)
*/ */
protected final boolean supportsOutput(Format format, @C.Encoding int encoding) { protected final boolean supportsOutput(Format format) {
return audioSink.supportsOutput(format, encoding); return audioSink.supportsOutput(format);
} }
@Override @Override
...@@ -358,9 +358,13 @@ public abstract class DecoderAudioRenderer extends BaseRenderer implements Media ...@@ -358,9 +358,13 @@ public abstract class DecoderAudioRenderer extends BaseRenderer implements Media
} }
if (audioTrackNeedsConfigure) { if (audioTrackNeedsConfigure) {
Format outputFormat = getOutputFormat(); Format outputFormat =
audioSink.configure(outputFormat.pcmEncoding, outputFormat.channelCount, getOutputFormat()
outputFormat.sampleRate, 0, null, encoderDelay, encoderPadding); .buildUpon()
.setEncoderDelay(encoderDelay)
.setEncoderPadding(encoderPadding)
.build();
audioSink.configure(outputFormat, /* specifiedBufferSize= */ 0, /* outputChannels= */ null);
audioTrackNeedsConfigure = false; audioTrackNeedsConfigure = false;
} }
......
...@@ -419,28 +419,28 @@ public final class DefaultAudioSink implements AudioSink { ...@@ -419,28 +419,28 @@ public final class DefaultAudioSink implements AudioSink {
} }
@Override @Override
public boolean supportsOutput(Format format, @C.Encoding int encoding) { public boolean supportsOutput(Format format) {
if (encoding == C.ENCODING_INVALID) { if (format.encoding == C.ENCODING_INVALID) {
return false; return false;
} }
if (Util.isEncodingLinearPcm(encoding)) { if (Util.isEncodingLinearPcm(format.encoding)) {
// AudioTrack supports 16-bit integer PCM output in all platform API versions, and float // AudioTrack supports 16-bit integer PCM output in all platform API versions, and float
// output from platform API version 21 only. Other integer PCM encodings are resampled by this // output from platform API version 21 only. Other integer PCM encodings are resampled by this
// sink to 16-bit PCM. We assume that the audio framework will downsample any number of // sink to 16-bit PCM. We assume that the audio framework will downsample any number of
// channels to the output device's required number of channels. // channels to the output device's required number of channels.
return encoding != C.ENCODING_PCM_FLOAT || Util.SDK_INT >= 21; return format.encoding != C.ENCODING_PCM_FLOAT || Util.SDK_INT >= 21;
} }
if (enableOffload if (enableOffload
&& isOffloadedPlaybackSupported( && isOffloadedPlaybackSupported(
format.channelCount, format.channelCount,
format.sampleRate, format.sampleRate,
encoding, format.encoding,
audioAttributes, audioAttributes,
format.encoderDelay, format.encoderDelay,
format.encoderPadding)) { format.encoderPadding)) {
return true; return true;
} }
return isPassthroughPlaybackSupported(encoding, format.channelCount); return isPassthroughPlaybackSupported(format);
} }
@Override @Override
...@@ -454,16 +454,9 @@ public final class DefaultAudioSink implements AudioSink { ...@@ -454,16 +454,9 @@ public final class DefaultAudioSink implements AudioSink {
} }
@Override @Override
public void configure( public void configure(Format inputFormat, int specifiedBufferSize, @Nullable int[] outputChannels)
@C.Encoding int inputEncoding,
int inputChannelCount,
int inputSampleRate,
int specifiedBufferSize,
@Nullable int[] outputChannels,
int trimStartFrames,
int trimEndFrames)
throws ConfigurationException { throws ConfigurationException {
if (Util.SDK_INT < 21 && inputChannelCount == 8 && outputChannels == null) { if (Util.SDK_INT < 21 && inputFormat.channelCount == 8 && outputChannels == null) {
// AudioTrack doesn't support 8 channel output before Android L. Discard the last two (side) // AudioTrack doesn't support 8 channel output before Android L. Discard the last two (side)
// channels to give a 6 channel stream that is supported. // channels to give a 6 channel stream that is supported.
outputChannels = new int[6]; outputChannels = new int[6];
...@@ -472,24 +465,20 @@ public final class DefaultAudioSink implements AudioSink { ...@@ -472,24 +465,20 @@ public final class DefaultAudioSink implements AudioSink {
} }
} }
boolean isInputPcm = Util.isEncodingLinearPcm(inputEncoding); boolean isInputPcm = Util.isEncodingLinearPcm(inputFormat.encoding);
boolean processingEnabled = isInputPcm; boolean processingEnabled = isInputPcm;
int sampleRate = inputSampleRate; int sampleRate = inputFormat.sampleRate;
int channelCount = inputChannelCount; int channelCount = inputFormat.channelCount;
@C.Encoding int encoding = inputEncoding; @C.Encoding int encoding = inputFormat.encoding;
boolean useFloatOutput = boolean useFloatOutput =
enableFloatOutput enableFloatOutput
&& Util.isEncodingHighResolutionPcm(inputEncoding) && Util.isEncodingHighResolutionPcm(inputFormat.encoding)
&& supportsOutput( && supportsOutput(inputFormat.buildUpon().setEncoding(C.ENCODING_PCM_FLOAT).build());
new Format.Builder()
.setChannelCount(inputChannelCount)
.setSampleRate(inputSampleRate)
.build(),
C.ENCODING_PCM_FLOAT);
AudioProcessor[] availableAudioProcessors = AudioProcessor[] availableAudioProcessors =
useFloatOutput ? toFloatPcmAvailableAudioProcessors : toIntPcmAvailableAudioProcessors; useFloatOutput ? toFloatPcmAvailableAudioProcessors : toIntPcmAvailableAudioProcessors;
if (processingEnabled) { if (processingEnabled) {
trimmingAudioProcessor.setTrimFrameCount(trimStartFrames, trimEndFrames); trimmingAudioProcessor.setTrimFrameCount(
inputFormat.encoderDelay, inputFormat.encoderPadding);
channelMappingAudioProcessor.setChannelMap(outputChannels); channelMappingAudioProcessor.setChannelMap(outputChannels);
AudioProcessor.AudioFormat outputFormat = AudioProcessor.AudioFormat outputFormat =
new AudioProcessor.AudioFormat(sampleRate, channelCount, encoding); new AudioProcessor.AudioFormat(sampleRate, channelCount, encoding);
...@@ -514,7 +503,9 @@ public final class DefaultAudioSink implements AudioSink { ...@@ -514,7 +503,9 @@ public final class DefaultAudioSink implements AudioSink {
} }
int inputPcmFrameSize = int inputPcmFrameSize =
isInputPcm ? Util.getPcmFrameSize(inputEncoding, inputChannelCount) : C.LENGTH_UNSET; isInputPcm
? Util.getPcmFrameSize(inputFormat.encoding, inputFormat.channelCount)
: C.LENGTH_UNSET;
int outputPcmFrameSize = int outputPcmFrameSize =
isInputPcm ? Util.getPcmFrameSize(encoding, channelCount) : C.LENGTH_UNSET; isInputPcm ? Util.getPcmFrameSize(encoding, channelCount) : C.LENGTH_UNSET;
boolean canApplyPlaybackParameters = processingEnabled && !useFloatOutput; boolean canApplyPlaybackParameters = processingEnabled && !useFloatOutput;
...@@ -526,14 +517,14 @@ public final class DefaultAudioSink implements AudioSink { ...@@ -526,14 +517,14 @@ public final class DefaultAudioSink implements AudioSink {
sampleRate, sampleRate,
encoding, encoding,
audioAttributes, audioAttributes,
trimStartFrames, inputFormat.encoderDelay,
trimEndFrames); inputFormat.encoderPadding);
Configuration pendingConfiguration = Configuration pendingConfiguration =
new Configuration( new Configuration(
isInputPcm, isInputPcm,
inputPcmFrameSize, inputPcmFrameSize,
inputSampleRate, inputFormat.sampleRate,
outputPcmFrameSize, outputPcmFrameSize,
sampleRate, sampleRate,
outputChannelConfig, outputChannelConfig,
...@@ -542,8 +533,8 @@ public final class DefaultAudioSink implements AudioSink { ...@@ -542,8 +533,8 @@ public final class DefaultAudioSink implements AudioSink {
processingEnabled, processingEnabled,
canApplyPlaybackParameters, canApplyPlaybackParameters,
availableAudioProcessors, availableAudioProcessors,
trimStartFrames, inputFormat.encoderDelay,
trimEndFrames, inputFormat.encoderPadding,
useOffload); useOffload);
if (isInitialized()) { if (isInitialized()) {
this.pendingConfiguration = pendingConfiguration; this.pendingConfiguration = pendingConfiguration;
...@@ -1253,21 +1244,21 @@ public final class DefaultAudioSink implements AudioSink { ...@@ -1253,21 +1244,21 @@ public final class DefaultAudioSink implements AudioSink {
: writtenEncodedFrames; : writtenEncodedFrames;
} }
private boolean isPassthroughPlaybackSupported(@C.Encoding int encoding, int channelCount) { private boolean isPassthroughPlaybackSupported(Format format) {
// Check for encodings that are known to work for passthrough with the implementation in this // Check for encodings that are known to work for passthrough with the implementation in this
// class. This avoids trying to use passthrough with an encoding where the device/app reports // class. This avoids trying to use passthrough with an encoding where the device/app reports
// it's capable but it is untested or known to be broken (for example AAC-LC). // it's capable but it is untested or known to be broken (for example AAC-LC).
return audioCapabilities != null return audioCapabilities != null
&& audioCapabilities.supportsEncoding(encoding) && audioCapabilities.supportsEncoding(format.encoding)
&& (encoding == C.ENCODING_AC3 && (format.encoding == C.ENCODING_AC3
|| encoding == C.ENCODING_E_AC3 || format.encoding == C.ENCODING_E_AC3
|| encoding == C.ENCODING_E_AC3_JOC || format.encoding == C.ENCODING_E_AC3_JOC
|| encoding == C.ENCODING_AC4 || format.encoding == C.ENCODING_AC4
|| encoding == C.ENCODING_DTS || format.encoding == C.ENCODING_DTS
|| encoding == C.ENCODING_DTS_HD || format.encoding == C.ENCODING_DTS_HD
|| encoding == C.ENCODING_DOLBY_TRUEHD) || format.encoding == C.ENCODING_DOLBY_TRUEHD)
&& (channelCount == Format.NO_VALUE && (format.channelCount == Format.NO_VALUE
|| channelCount <= audioCapabilities.getMaxChannelCount()); || format.channelCount <= audioCapabilities.getMaxChannelCount());
} }
private static boolean isOffloadedPlaybackSupported( private static boolean isOffloadedPlaybackSupported(
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
package com.google.android.exoplayer2.audio; package com.google.android.exoplayer2.audio;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C.Encoding;
import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.PlaybackParameters; import com.google.android.exoplayer2.PlaybackParameters;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
...@@ -36,8 +35,8 @@ public class ForwardingAudioSink implements AudioSink { ...@@ -36,8 +35,8 @@ public class ForwardingAudioSink implements AudioSink {
} }
@Override @Override
public boolean supportsOutput(Format format, @Encoding int encoding) { public boolean supportsOutput(Format format) {
return sink.supportsOutput(format, encoding); return sink.supportsOutput(format);
} }
@Override @Override
...@@ -46,23 +45,9 @@ public class ForwardingAudioSink implements AudioSink { ...@@ -46,23 +45,9 @@ public class ForwardingAudioSink implements AudioSink {
} }
@Override @Override
public void configure( public void configure(Format inputFormat, int specifiedBufferSize, @Nullable int[] outputChannels)
int inputEncoding,
int inputChannelCount,
int inputSampleRate,
int specifiedBufferSize,
@Nullable int[] outputChannels,
int trimStartFrames,
int trimEndFrames)
throws ConfigurationException { throws ConfigurationException {
sink.configure( sink.configure(inputFormat, specifiedBufferSize, outputChannels);
inputEncoding,
inputChannelCount,
inputSampleRate,
specifiedBufferSize,
outputChannels,
trimStartFrames,
trimEndFrames);
} }
@Override @Override
......
...@@ -39,6 +39,7 @@ import com.google.android.exoplayer2.mediacodec.MediaCodecSelector; ...@@ -39,6 +39,7 @@ import com.google.android.exoplayer2.mediacodec.MediaCodecSelector;
import com.google.android.exoplayer2.mediacodec.MediaCodecUtil; import com.google.android.exoplayer2.mediacodec.MediaCodecUtil;
import com.google.android.exoplayer2.mediacodec.MediaCodecUtil.DecoderQueryException; import com.google.android.exoplayer2.mediacodec.MediaCodecUtil.DecoderQueryException;
import com.google.android.exoplayer2.mediacodec.MediaFormatUtil; import com.google.android.exoplayer2.mediacodec.MediaFormatUtil;
import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.MediaClock; import com.google.android.exoplayer2.util.MediaClock;
import com.google.android.exoplayer2.util.MimeTypes; import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
...@@ -86,7 +87,7 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media ...@@ -86,7 +87,7 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
private boolean passthroughEnabled; private boolean passthroughEnabled;
private boolean codecNeedsDiscardChannelsWorkaround; private boolean codecNeedsDiscardChannelsWorkaround;
private boolean codecNeedsEosBufferTimestampWorkaround; private boolean codecNeedsEosBufferTimestampWorkaround;
@Nullable private Format passthroughFormat; @Nullable private Format passthroughCodecFormat;
@Nullable private Format inputFormat; @Nullable private Format inputFormat;
private long currentPositionUs; private long currentPositionUs;
private boolean allowFirstBufferPositionDiscontinuity; private boolean allowFirstBufferPositionDiscontinuity;
...@@ -226,9 +227,9 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media ...@@ -226,9 +227,9 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
&& (format.drmInitData == null || MediaCodecUtil.getPassthroughDecoderInfo() != null)) { && (format.drmInitData == null || MediaCodecUtil.getPassthroughDecoderInfo() != null)) {
return RendererCapabilities.create(FORMAT_HANDLED, ADAPTIVE_NOT_SEAMLESS, tunnelingSupport); return RendererCapabilities.create(FORMAT_HANDLED, ADAPTIVE_NOT_SEAMLESS, tunnelingSupport);
} }
if ((MimeTypes.AUDIO_RAW.equals(format.sampleMimeType) if ((MimeTypes.AUDIO_RAW.equals(format.sampleMimeType) && !audioSink.supportsOutput(format))
&& !audioSink.supportsOutput(format, format.pcmEncoding)) || !audioSink.supportsOutput(
|| !audioSink.supportsOutput(format, C.ENCODING_PCM_16BIT)) { format.buildUpon().setEncoding(C.ENCODING_PCM_16BIT).build())) {
// Assume the decoder outputs 16-bit PCM, unless the input is raw. // Assume the decoder outputs 16-bit PCM, unless the input is raw.
return RendererCapabilities.create(FORMAT_UNSUPPORTED_SUBTYPE); return RendererCapabilities.create(FORMAT_UNSUPPORTED_SUBTYPE);
} }
...@@ -304,7 +305,7 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media ...@@ -304,7 +305,7 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
getMediaFormat(format, codecInfo.codecMimeType, codecMaxInputSize, codecOperatingRate); getMediaFormat(format, codecInfo.codecMimeType, codecMaxInputSize, codecOperatingRate);
codecAdapter.configure(mediaFormat, /* surface= */ null, crypto, /* flags= */ 0); codecAdapter.configure(mediaFormat, /* surface= */ null, crypto, /* flags= */ 0);
// Store the input MIME type if we're using the passthrough codec. // Store the input MIME type if we're using the passthrough codec.
passthroughFormat = passthroughEnabled ? format : null; passthroughCodecFormat = passthroughEnabled ? format : null;
} }
@Override @Override
...@@ -339,7 +340,7 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media ...@@ -339,7 +340,7 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
return Util.areEqual(oldFormat.sampleMimeType, newFormat.sampleMimeType) return Util.areEqual(oldFormat.sampleMimeType, newFormat.sampleMimeType)
&& oldFormat.channelCount == newFormat.channelCount && oldFormat.channelCount == newFormat.channelCount
&& oldFormat.sampleRate == newFormat.sampleRate && oldFormat.sampleRate == newFormat.sampleRate
&& oldFormat.pcmEncoding == newFormat.pcmEncoding && oldFormat.encoding == newFormat.encoding
&& oldFormat.initializationDataEquals(newFormat) && oldFormat.initializationDataEquals(newFormat)
&& !MimeTypes.AUDIO_OPUS.equals(oldFormat.sampleMimeType); && !MimeTypes.AUDIO_OPUS.equals(oldFormat.sampleMimeType);
} }
...@@ -385,40 +386,39 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media ...@@ -385,40 +386,39 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
@Override @Override
protected void configureOutput(Format outputFormat) throws ExoPlaybackException { protected void configureOutput(Format outputFormat) throws ExoPlaybackException {
@C.Encoding int encoding; Format audioSinkInputFormat;
MediaFormat mediaFormat; if (passthroughCodecFormat != null) {
int channelCount; @C.Encoding int passthroughEncoding = getPassthroughEncoding(passthroughCodecFormat);
int sampleRate; // TODO(b/112299307): Passthrough can have become unavailable since usePassthrough was called.
if (passthroughFormat != null) { Assertions.checkState(passthroughEncoding != C.ENCODING_INVALID);
encoding = getPassthroughEncoding(passthroughFormat); audioSinkInputFormat = outputFormat.buildUpon().setEncoding(passthroughEncoding).build();
channelCount = passthroughFormat.channelCount;
sampleRate = passthroughFormat.sampleRate;
} else { } else {
mediaFormat = getCodec().getOutputFormat(); MediaFormat mediaFormat = getCodec().getOutputFormat();
@C.Encoding int encoding;
if (mediaFormat.containsKey(VIVO_BITS_PER_SAMPLE_KEY)) { if (mediaFormat.containsKey(VIVO_BITS_PER_SAMPLE_KEY)) {
encoding = Util.getPcmEncoding(mediaFormat.getInteger(VIVO_BITS_PER_SAMPLE_KEY)); encoding = Util.getPcmEncoding(mediaFormat.getInteger(VIVO_BITS_PER_SAMPLE_KEY));
} else { } else {
encoding = getPcmEncoding(outputFormat); encoding = getPcmEncoding(outputFormat);
} }
channelCount = mediaFormat.getInteger(MediaFormat.KEY_CHANNEL_COUNT); audioSinkInputFormat =
sampleRate = mediaFormat.getInteger(MediaFormat.KEY_SAMPLE_RATE); outputFormat
.buildUpon()
.setEncoding(encoding)
.setChannelCount(mediaFormat.getInteger(MediaFormat.KEY_CHANNEL_COUNT))
.setSampleRate(mediaFormat.getInteger(MediaFormat.KEY_SAMPLE_RATE))
.build();
} }
@Nullable int[] channelMap = null; @Nullable int[] channelMap = null;
if (codecNeedsDiscardChannelsWorkaround && channelCount == 6 && outputFormat.channelCount < 6) { if (codecNeedsDiscardChannelsWorkaround
&& audioSinkInputFormat.channelCount == 6
&& outputFormat.channelCount < 6) {
channelMap = new int[outputFormat.channelCount]; channelMap = new int[outputFormat.channelCount];
for (int i = 0; i < outputFormat.channelCount; i++) { for (int i = 0; i < outputFormat.channelCount; i++) {
channelMap[i] = i; channelMap[i] = i;
} }
} }
try { try {
audioSink.configure( audioSink.configure(audioSinkInputFormat, /* specifiedBufferSize= */ 0, channelMap);
encoding,
channelCount,
sampleRate,
/* specifiedBufferSize= */ 0,
channelMap,
outputFormat.encoderDelay,
outputFormat.encoderPadding);
} catch (AudioSink.ConfigurationException e) { } catch (AudioSink.ConfigurationException e) {
throw createRendererException(e, outputFormat); throw createRendererException(e, outputFormat);
} }
...@@ -426,16 +426,12 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media ...@@ -426,16 +426,12 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
@Override @Override
protected void onOutputPassthroughFormatChanged(Format outputFormat) throws ExoPlaybackException { protected void onOutputPassthroughFormatChanged(Format outputFormat) throws ExoPlaybackException {
@C.Encoding int encoding = getPassthroughEncoding(outputFormat); @C.Encoding int passthroughEncoding = getPassthroughEncoding(outputFormat);
// TODO(b/112299307): Passthrough can have become unavailable since usePassthrough was called.
Assertions.checkState(passthroughEncoding != C.ENCODING_INVALID);
Format format = outputFormat.buildUpon().setEncoding(passthroughEncoding).build();
try { try {
audioSink.configure( audioSink.configure(format, /* specifiedBufferSize= */ 0, /* outputChannels= */ null);
encoding,
outputFormat.channelCount,
outputFormat.sampleRate,
/* specifiedBufferSize= */ 0,
/* outputChannels= */ null,
outputFormat.encoderDelay,
outputFormat.encoderPadding);
} catch (AudioSink.ConfigurationException e) { } catch (AudioSink.ConfigurationException e) {
throw createRendererException(e, outputFormat); throw createRendererException(e, outputFormat);
} }
...@@ -458,16 +454,22 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media ...@@ -458,16 +454,22 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
} }
if (MimeTypes.AUDIO_E_AC3_JOC.equals(mimeType)) { if (MimeTypes.AUDIO_E_AC3_JOC.equals(mimeType)) {
// E-AC3 JOC is object-based so the output channel count is arbitrary. // E-AC3 JOC is object-based so the output channel count is arbitrary.
Format eAc3JocFormat = format.buildUpon().setChannelCount(Format.NO_VALUE).build(); Format eAc3JocFormat =
if (audioSink.supportsOutput(eAc3JocFormat, C.ENCODING_E_AC3_JOC)) { format
return MimeTypes.getEncoding(MimeTypes.AUDIO_E_AC3_JOC, format.codecs); .buildUpon()
.setChannelCount(Format.NO_VALUE)
.setEncoding(C.ENCODING_E_AC3_JOC)
.build();
if (audioSink.supportsOutput(eAc3JocFormat)) {
return C.ENCODING_E_AC3_JOC;
} }
// E-AC3 receivers can decode JOC streams, but in 2-D rather than 3-D, so try to fall back. // E-AC3 receivers can decode JOC streams, but in 2-D rather than 3-D, so try to fall back.
mimeType = MimeTypes.AUDIO_E_AC3; mimeType = MimeTypes.AUDIO_E_AC3;
} }
@C.Encoding int encoding = MimeTypes.getEncoding(mimeType, format.codecs); @C.Encoding int encoding = MimeTypes.getEncoding(mimeType, format.codecs);
if (audioSink.supportsOutput(format, encoding)) { Format passthroughFormat = format.buildUpon().setEncoding(encoding).build();
if (audioSink.supportsOutput(passthroughFormat)) {
return encoding; return encoding;
} else { } else {
return C.ENCODING_INVALID; return C.ENCODING_INVALID;
...@@ -844,7 +846,7 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media ...@@ -844,7 +846,7 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
// If the format is anything other than PCM then we assume that the audio decoder will output // If the format is anything other than PCM then we assume that the audio decoder will output
// 16-bit PCM. // 16-bit PCM.
return MimeTypes.AUDIO_RAW.equals(format.sampleMimeType) return MimeTypes.AUDIO_RAW.equals(format.sampleMimeType)
? format.pcmEncoding ? format.encoding
: C.ENCODING_PCM_16BIT; : C.ENCODING_PCM_16BIT;
} }
......
...@@ -45,7 +45,7 @@ import java.nio.ByteBuffer; ...@@ -45,7 +45,7 @@ import java.nio.ByteBuffer;
* *
* @param trimStartFrames The number of audio frames to trim from the start of audio. * @param trimStartFrames The number of audio frames to trim from the start of audio.
* @param trimEndFrames The number of audio frames to trim from the end of audio. * @param trimEndFrames The number of audio frames to trim from the end of audio.
* @see AudioSink#configure(int, int, int, int, int[], int, int) * @see AudioSink#configure(com.google.android.exoplayer2.Format, int, int[])
*/ */
public void setTrimFrameCount(int trimStartFrames, int trimEndFrames) { public void setTrimFrameCount(int trimStartFrames, int trimEndFrames) {
this.trimStartFrames = trimStartFrames; this.trimStartFrames = trimStartFrames;
......
...@@ -87,7 +87,7 @@ public final class SilenceMediaSource extends BaseMediaSource { ...@@ -87,7 +87,7 @@ public final class SilenceMediaSource extends BaseMediaSource {
.setSampleMimeType(MimeTypes.AUDIO_RAW) .setSampleMimeType(MimeTypes.AUDIO_RAW)
.setChannelCount(CHANNEL_COUNT) .setChannelCount(CHANNEL_COUNT)
.setSampleRate(SAMPLE_RATE_HZ) .setSampleRate(SAMPLE_RATE_HZ)
.setPcmEncoding(PCM_ENCODING) .setEncoding(PCM_ENCODING)
.build(); .build();
private static final MediaItem MEDIA_ITEM = private static final MediaItem MEDIA_ITEM =
new MediaItem.Builder() new MediaItem.Builder()
......
...@@ -207,13 +207,15 @@ public final class DefaultAudioSinkTest { ...@@ -207,13 +207,15 @@ public final class DefaultAudioSinkTest {
@Config(minSdk = OLDEST_SDK, maxSdk = 20) @Config(minSdk = OLDEST_SDK, maxSdk = 20)
@Test @Test
public void doesNotSupportFloatOutputBeforeApi21() { public void doesNotSupportFloatOutputBeforeApi21() {
assertThat(defaultAudioSink.supportsOutput(STEREO_44_1_FORMAT, C.ENCODING_PCM_FLOAT)).isFalse(); Format floatFormat = STEREO_44_1_FORMAT.buildUpon().setEncoding(C.ENCODING_PCM_FLOAT).build();
assertThat(defaultAudioSink.supportsOutput(floatFormat)).isFalse();
} }
@Config(minSdk = 21, maxSdk = TARGET_SDK) @Config(minSdk = 21, maxSdk = TARGET_SDK)
@Test @Test
public void supportsFloatOutputFromApi21() { public void supportsFloatOutputFromApi21() {
assertThat(defaultAudioSink.supportsOutput(STEREO_44_1_FORMAT, C.ENCODING_PCM_FLOAT)).isTrue(); Format floatFormat = STEREO_44_1_FORMAT.buildUpon().setEncoding(C.ENCODING_PCM_FLOAT).build();
assertThat(defaultAudioSink.supportsOutput(floatFormat)).isTrue();
} }
@Test @Test
...@@ -221,7 +223,8 @@ public final class DefaultAudioSinkTest { ...@@ -221,7 +223,8 @@ public final class DefaultAudioSinkTest {
DefaultAudioSink defaultAudioSink = DefaultAudioSink defaultAudioSink =
new DefaultAudioSink( new DefaultAudioSink(
new AudioCapabilities(new int[] {C.ENCODING_AAC_LC}, 2), new AudioProcessor[0]); new AudioCapabilities(new int[] {C.ENCODING_AAC_LC}, 2), new AudioProcessor[0]);
assertThat(defaultAudioSink.supportsOutput(STEREO_44_1_FORMAT, C.ENCODING_AAC_LC)).isFalse(); Format aacLcFormat = STEREO_44_1_FORMAT.buildUpon().setEncoding(C.ENCODING_AAC_LC).build();
assertThat(defaultAudioSink.supportsOutput(aacLcFormat)).isFalse();
} }
private void configureDefaultAudioSink(int channelCount) throws AudioSink.ConfigurationException { private void configureDefaultAudioSink(int channelCount) throws AudioSink.ConfigurationException {
...@@ -230,14 +233,15 @@ public final class DefaultAudioSinkTest { ...@@ -230,14 +233,15 @@ public final class DefaultAudioSinkTest {
private void configureDefaultAudioSink(int channelCount, int trimStartFrames, int trimEndFrames) private void configureDefaultAudioSink(int channelCount, int trimStartFrames, int trimEndFrames)
throws AudioSink.ConfigurationException { throws AudioSink.ConfigurationException {
defaultAudioSink.configure( Format format =
C.ENCODING_PCM_16BIT, new Format.Builder()
channelCount, .setEncoding(C.ENCODING_PCM_16BIT)
SAMPLE_RATE_44_1, .setChannelCount(channelCount)
/* specifiedBufferSize= */ 0, .setSampleRate(SAMPLE_RATE_44_1)
/* outputChannels= */ null, .setEncoderDelay(trimStartFrames)
/* trimStartFrames= */ trimStartFrames, .setEncoderPadding(trimEndFrames)
/* trimEndFrames= */ trimEndFrames); .build();
defaultAudioSink.configure(format, /* specifiedBufferSize= */ 0, /* outputChannels= */ null);
} }
/** Creates a one second silence buffer for 44.1 kHz stereo 16-bit audio. */ /** Creates a one second silence buffer for 44.1 kHz stereo 16-bit audio. */
......
...@@ -53,7 +53,7 @@ public class MediaCodecAudioRendererTest { ...@@ -53,7 +53,7 @@ public class MediaCodecAudioRendererTest {
private static final Format AUDIO_AAC = private static final Format AUDIO_AAC =
new Format.Builder() new Format.Builder()
.setSampleMimeType(MimeTypes.AUDIO_AAC) .setSampleMimeType(MimeTypes.AUDIO_AAC)
.setPcmEncoding(C.ENCODING_PCM_16BIT) .setEncoding(C.ENCODING_PCM_16BIT)
.setChannelCount(2) .setChannelCount(2)
.setSampleRate(44100) .setSampleRate(44100)
.setEncoderDelay(100) .setEncoderDelay(100)
...@@ -143,24 +143,10 @@ public class MediaCodecAudioRendererTest { ...@@ -143,24 +143,10 @@ public class MediaCodecAudioRendererTest {
} while (!mediaCodecAudioRenderer.isEnded()); } while (!mediaCodecAudioRenderer.isEnded());
verify(audioSink) verify(audioSink)
.configure( .configure(AUDIO_AAC, /* specifiedBufferSize= */ 0, /* outputChannels= */ null);
AUDIO_AAC.pcmEncoding,
AUDIO_AAC.channelCount,
AUDIO_AAC.sampleRate,
/* specifiedBufferSize= */ 0,
/* outputChannels= */ null,
AUDIO_AAC.encoderDelay,
AUDIO_AAC.encoderPadding);
verify(audioSink) verify(audioSink)
.configure( .configure(changedFormat, /* specifiedBufferSize= */ 0, /* outputChannels= */ null);
changedFormat.pcmEncoding,
changedFormat.channelCount,
changedFormat.sampleRate,
/* specifiedBufferSize= */ 0,
/* outputChannels= */ null,
changedFormat.encoderDelay,
changedFormat.encoderPadding);
} }
@Test @Test
...@@ -205,24 +191,10 @@ public class MediaCodecAudioRendererTest { ...@@ -205,24 +191,10 @@ public class MediaCodecAudioRendererTest {
} while (!mediaCodecAudioRenderer.isEnded()); } while (!mediaCodecAudioRenderer.isEnded());
verify(audioSink) verify(audioSink)
.configure( .configure(AUDIO_AAC, /* specifiedBufferSize= */ 0, /* outputChannels= */ null);
AUDIO_AAC.pcmEncoding,
AUDIO_AAC.channelCount,
AUDIO_AAC.sampleRate,
/* specifiedBufferSize= */ 0,
/* outputChannels= */ null,
AUDIO_AAC.encoderDelay,
AUDIO_AAC.encoderPadding);
verify(audioSink) verify(audioSink)
.configure( .configure(changedFormat, /* specifiedBufferSize= */ 0, /* outputChannels= */ null);
changedFormat.pcmEncoding,
changedFormat.channelCount,
changedFormat.sampleRate,
/* specifiedBufferSize= */ 0,
/* outputChannels= */ null,
changedFormat.encoderDelay,
changedFormat.encoderPadding);
} }
@Test @Test
......
...@@ -34,7 +34,7 @@ public final class C2Mp3TimestampTrackerTest { ...@@ -34,7 +34,7 @@ public final class C2Mp3TimestampTrackerTest {
private static final Format AUDIO_MP3 = private static final Format AUDIO_MP3 =
new Format.Builder() new Format.Builder()
.setSampleMimeType(MimeTypes.AUDIO_MPEG) .setSampleMimeType(MimeTypes.AUDIO_MPEG)
.setPcmEncoding(C.ENCODING_PCM_16BIT) .setEncoding(C.ENCODING_PCM_16BIT)
.setChannelCount(2) .setChannelCount(2)
.setSampleRate(44_100) .setSampleRate(44_100)
.build(); .build();
......
...@@ -2098,7 +2098,7 @@ public class MatroskaExtractor implements Extractor { ...@@ -2098,7 +2098,7 @@ public class MatroskaExtractor implements Extractor {
formatBuilder formatBuilder
.setChannelCount(channelCount) .setChannelCount(channelCount)
.setSampleRate(sampleRate) .setSampleRate(sampleRate)
.setPcmEncoding(pcmEncoding); .setEncoding(pcmEncoding);
} else if (MimeTypes.isVideo(mimeType)) { } else if (MimeTypes.isVideo(mimeType)) {
type = C.TRACK_TYPE_VIDEO; type = C.TRACK_TYPE_VIDEO;
if (displayUnit == Track.DISPLAY_UNIT_PIXELS) { if (displayUnit == Track.DISPLAY_UNIT_PIXELS) {
......
...@@ -294,7 +294,24 @@ import org.checkerframework.checker.nullness.compatqual.NullableType; ...@@ -294,7 +294,24 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
long timestampTimeUnits = 0; long timestampTimeUnits = 0;
long duration; long duration;
if (!isFixedSampleSizeRawAudio) { if (isFixedSampleSizeRawAudio) {
long[] chunkOffsetsBytes = new long[chunkIterator.length];
int[] chunkSampleCounts = new int[chunkIterator.length];
while (chunkIterator.moveNext()) {
chunkOffsetsBytes[chunkIterator.index] = chunkIterator.offset;
chunkSampleCounts[chunkIterator.index] = chunkIterator.numSamples;
}
int fixedSampleSize = Util.getPcmFrameSize(track.format.encoding, track.format.channelCount);
FixedSampleSizeRechunker.Results rechunkedResults =
FixedSampleSizeRechunker.rechunk(
fixedSampleSize, chunkOffsetsBytes, chunkSampleCounts, timestampDeltaInTimeUnits);
offsets = rechunkedResults.offsets;
sizes = rechunkedResults.sizes;
maximumSize = rechunkedResults.maximumSize;
timestamps = rechunkedResults.timestamps;
flags = rechunkedResults.flags;
duration = rechunkedResults.duration;
} else {
offsets = new long[sampleCount]; offsets = new long[sampleCount];
sizes = new int[sampleCount]; sizes = new int[sampleCount];
timestamps = new long[sampleCount]; timestamps = new long[sampleCount];
...@@ -404,23 +421,6 @@ import org.checkerframework.checker.nullness.compatqual.NullableType; ...@@ -404,23 +421,6 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
+ remainingSamplesAtTimestampOffset + remainingSamplesAtTimestampOffset
+ (!isCttsValid ? ", ctts invalid" : "")); + (!isCttsValid ? ", ctts invalid" : ""));
} }
} else {
long[] chunkOffsetsBytes = new long[chunkIterator.length];
int[] chunkSampleCounts = new int[chunkIterator.length];
while (chunkIterator.moveNext()) {
chunkOffsetsBytes[chunkIterator.index] = chunkIterator.offset;
chunkSampleCounts[chunkIterator.index] = chunkIterator.numSamples;
}
int fixedSampleSize =
Util.getPcmFrameSize(track.format.pcmEncoding, track.format.channelCount);
FixedSampleSizeRechunker.Results rechunkedResults = FixedSampleSizeRechunker.rechunk(
fixedSampleSize, chunkOffsetsBytes, chunkSampleCounts, timestampDeltaInTimeUnits);
offsets = rechunkedResults.offsets;
sizes = rechunkedResults.sizes;
maximumSize = rechunkedResults.maximumSize;
timestamps = rechunkedResults.timestamps;
flags = rechunkedResults.flags;
duration = rechunkedResults.duration;
} }
long durationUs = Util.scaleLargeTimestamp(duration, C.MICROS_PER_SECOND, track.timescale); long durationUs = Util.scaleLargeTimestamp(duration, C.MICROS_PER_SECOND, track.timescale);
...@@ -1303,7 +1303,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType; ...@@ -1303,7 +1303,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
.setCodecs(codecs) .setCodecs(codecs)
.setChannelCount(channelCount) .setChannelCount(channelCount)
.setSampleRate(sampleRate) .setSampleRate(sampleRate)
.setPcmEncoding(pcmEncoding) .setEncoding(pcmEncoding)
.setInitializationData( .setInitializationData(
initializationData == null ? null : Collections.singletonList(initializationData)) initializationData == null ? null : Collections.singletonList(initializationData))
.setDrmInitData(drmInitData) .setDrmInitData(drmInitData)
......
...@@ -231,7 +231,7 @@ public final class WavExtractor implements Extractor { ...@@ -231,7 +231,7 @@ public final class WavExtractor implements Extractor {
.setMaxInputSize(targetSampleSizeBytes) .setMaxInputSize(targetSampleSizeBytes)
.setChannelCount(header.numChannels) .setChannelCount(header.numChannels)
.setSampleRate(header.frameRateHz) .setSampleRate(header.frameRateHz)
.setPcmEncoding(pcmEncoding) .setEncoding(pcmEncoding)
.build(); .build();
} }
...@@ -373,7 +373,7 @@ public final class WavExtractor implements Extractor { ...@@ -373,7 +373,7 @@ public final class WavExtractor implements Extractor {
.setMaxInputSize(numOutputFramesToBytes(targetSampleSizeFrames, numChannels)) .setMaxInputSize(numOutputFramesToBytes(targetSampleSizeFrames, numChannels))
.setChannelCount(header.numChannels) .setChannelCount(header.numChannels)
.setSampleRate(header.frameRateHz) .setSampleRate(header.frameRateHz)
.setPcmEncoding(C.ENCODING_PCM_16BIT) .setEncoding(C.ENCODING_PCM_16BIT)
.build(); .build();
} }
......
...@@ -16,7 +16,7 @@ track 0: ...@@ -16,7 +16,7 @@ track 0:
maxInputSize = 16384 maxInputSize = 16384
channelCount = 2 channelCount = 2
sampleRate = 48000 sampleRate = 48000
pcmEncoding = 2 encoding = 2
sample 0: sample 0:
time = 0 time = 0
flags = 1 flags = 1
......
...@@ -16,7 +16,7 @@ track 0: ...@@ -16,7 +16,7 @@ track 0:
maxInputSize = 16384 maxInputSize = 16384
channelCount = 2 channelCount = 2
sampleRate = 48000 sampleRate = 48000
pcmEncoding = 2 encoding = 2
sample 0: sample 0:
time = 853333 time = 853333
flags = 1 flags = 1
......
...@@ -16,7 +16,7 @@ track 0: ...@@ -16,7 +16,7 @@ track 0:
maxInputSize = 16384 maxInputSize = 16384
channelCount = 2 channelCount = 2
sampleRate = 48000 sampleRate = 48000
pcmEncoding = 2 encoding = 2
sample 0: sample 0:
time = 1792000 time = 1792000
flags = 1 flags = 1
......
...@@ -16,7 +16,7 @@ track 0: ...@@ -16,7 +16,7 @@ track 0:
maxInputSize = 16384 maxInputSize = 16384
channelCount = 2 channelCount = 2
sampleRate = 48000 sampleRate = 48000
pcmEncoding = 2 encoding = 2
sample 0: sample 0:
time = 2645333 time = 2645333
flags = 1 flags = 1
......
...@@ -16,7 +16,7 @@ track 0: ...@@ -16,7 +16,7 @@ track 0:
maxInputSize = 16384 maxInputSize = 16384
channelCount = 2 channelCount = 2
sampleRate = 48000 sampleRate = 48000
pcmEncoding = 2 encoding = 2
sample 0: sample 0:
time = 0 time = 0
flags = 1 flags = 1
......
...@@ -14,7 +14,7 @@ track 0: ...@@ -14,7 +14,7 @@ track 0:
maxInputSize = 16384 maxInputSize = 16384
channelCount = 2 channelCount = 2
sampleRate = 48000 sampleRate = 48000
pcmEncoding = 2 encoding = 2
sample 0: sample 0:
time = 0 time = 0
flags = 1 flags = 1
......
...@@ -14,7 +14,7 @@ track 0: ...@@ -14,7 +14,7 @@ track 0:
maxInputSize = 16384 maxInputSize = 16384
channelCount = 2 channelCount = 2
sampleRate = 48000 sampleRate = 48000
pcmEncoding = 2 encoding = 2
sample 0: sample 0:
time = 0 time = 0
flags = 1 flags = 1
......
...@@ -13,7 +13,7 @@ track 0: ...@@ -13,7 +13,7 @@ track 0:
maxInputSize = 16384 maxInputSize = 16384
channelCount = 2 channelCount = 2
sampleRate = 48000 sampleRate = 48000
pcmEncoding = 2 encoding = 2
sample 0: sample 0:
time = 0 time = 0
flags = 1 flags = 1
......
...@@ -13,7 +13,7 @@ track 0: ...@@ -13,7 +13,7 @@ track 0:
maxInputSize = 16384 maxInputSize = 16384
channelCount = 2 channelCount = 2
sampleRate = 48000 sampleRate = 48000
pcmEncoding = 2 encoding = 2
sample 0: sample 0:
time = 0 time = 0
flags = 1 flags = 1
......
...@@ -16,7 +16,7 @@ track 0: ...@@ -16,7 +16,7 @@ track 0:
maxInputSize = 16384 maxInputSize = 16384
channelCount = 2 channelCount = 2
sampleRate = 48000 sampleRate = 48000
pcmEncoding = 2 encoding = 2
sample 0: sample 0:
time = 0 time = 0
flags = 1 flags = 1
......
...@@ -16,7 +16,7 @@ track 0: ...@@ -16,7 +16,7 @@ track 0:
maxInputSize = 16384 maxInputSize = 16384
channelCount = 2 channelCount = 2
sampleRate = 48000 sampleRate = 48000
pcmEncoding = 2 encoding = 2
sample 0: sample 0:
time = 853333 time = 853333
flags = 1 flags = 1
......
...@@ -16,7 +16,7 @@ track 0: ...@@ -16,7 +16,7 @@ track 0:
maxInputSize = 16384 maxInputSize = 16384
channelCount = 2 channelCount = 2
sampleRate = 48000 sampleRate = 48000
pcmEncoding = 2 encoding = 2
sample 0: sample 0:
time = 1792000 time = 1792000
flags = 1 flags = 1
......
...@@ -16,7 +16,7 @@ track 0: ...@@ -16,7 +16,7 @@ track 0:
maxInputSize = 16384 maxInputSize = 16384
channelCount = 2 channelCount = 2
sampleRate = 48000 sampleRate = 48000
pcmEncoding = 2 encoding = 2
sample 0: sample 0:
time = 2730666 time = 2730666
flags = 1 flags = 1
......
...@@ -13,7 +13,7 @@ track 0: ...@@ -13,7 +13,7 @@ track 0:
maxInputSize = 16384 maxInputSize = 16384
channelCount = 2 channelCount = 2
sampleRate = 48000 sampleRate = 48000
pcmEncoding = 2 encoding = 2
sample 0: sample 0:
time = 0 time = 0
flags = 1 flags = 1
......
...@@ -16,7 +16,7 @@ track 0: ...@@ -16,7 +16,7 @@ track 0:
maxInputSize = 16384 maxInputSize = 16384
channelCount = 2 channelCount = 2
sampleRate = 48000 sampleRate = 48000
pcmEncoding = 2 encoding = 2
sample 0: sample 0:
time = 0 time = 0
flags = 1 flags = 1
......
...@@ -16,7 +16,7 @@ track 0: ...@@ -16,7 +16,7 @@ track 0:
maxInputSize = 16384 maxInputSize = 16384
channelCount = 2 channelCount = 2
sampleRate = 48000 sampleRate = 48000
pcmEncoding = 2 encoding = 2
sample 0: sample 0:
time = 853333 time = 853333
flags = 1 flags = 1
......
...@@ -16,7 +16,7 @@ track 0: ...@@ -16,7 +16,7 @@ track 0:
maxInputSize = 16384 maxInputSize = 16384
channelCount = 2 channelCount = 2
sampleRate = 48000 sampleRate = 48000
pcmEncoding = 2 encoding = 2
sample 0: sample 0:
time = 1792000 time = 1792000
flags = 1 flags = 1
......
...@@ -16,7 +16,7 @@ track 0: ...@@ -16,7 +16,7 @@ track 0:
maxInputSize = 16384 maxInputSize = 16384
channelCount = 2 channelCount = 2
sampleRate = 48000 sampleRate = 48000
pcmEncoding = 2 encoding = 2
sample 0: sample 0:
time = 2645333 time = 2645333
flags = 1 flags = 1
......
...@@ -16,7 +16,7 @@ track 0: ...@@ -16,7 +16,7 @@ track 0:
maxInputSize = 16384 maxInputSize = 16384
channelCount = 2 channelCount = 2
sampleRate = 48000 sampleRate = 48000
pcmEncoding = 2 encoding = 2
sample 0: sample 0:
time = 0 time = 0
flags = 1 flags = 1
......
...@@ -16,7 +16,7 @@ track 0: ...@@ -16,7 +16,7 @@ track 0:
maxInputSize = 18432 maxInputSize = 18432
channelCount = 2 channelCount = 2
sampleRate = 44000 sampleRate = 44000
pcmEncoding = 2 encoding = 2
sample 0: sample 0:
time = 0 time = 0
flags = 1 flags = 1
......
...@@ -16,7 +16,7 @@ track 0: ...@@ -16,7 +16,7 @@ track 0:
maxInputSize = 18432 maxInputSize = 18432
channelCount = 2 channelCount = 2
sampleRate = 44000 sampleRate = 44000
pcmEncoding = 2 encoding = 2
sample 0: sample 0:
time = 837818 time = 837818
flags = 1 flags = 1
......
...@@ -16,7 +16,7 @@ track 0: ...@@ -16,7 +16,7 @@ track 0:
maxInputSize = 18432 maxInputSize = 18432
channelCount = 2 channelCount = 2
sampleRate = 44000 sampleRate = 44000
pcmEncoding = 2 encoding = 2
sample 0: sample 0:
time = 1780363 time = 1780363
flags = 1 flags = 1
......
...@@ -16,7 +16,7 @@ track 0: ...@@ -16,7 +16,7 @@ track 0:
maxInputSize = 18432 maxInputSize = 18432
channelCount = 2 channelCount = 2
sampleRate = 44000 sampleRate = 44000
pcmEncoding = 2 encoding = 2
sample 0: sample 0:
time = 2618181 time = 2618181
flags = 1 flags = 1
......
...@@ -16,7 +16,7 @@ track 0: ...@@ -16,7 +16,7 @@ track 0:
maxInputSize = 18432 maxInputSize = 18432
channelCount = 2 channelCount = 2
sampleRate = 44000 sampleRate = 44000
pcmEncoding = 2 encoding = 2
sample 0: sample 0:
time = 0 time = 0
flags = 1 flags = 1
......
...@@ -16,7 +16,7 @@ track 0: ...@@ -16,7 +16,7 @@ track 0:
maxInputSize = 16384 maxInputSize = 16384
channelCount = 2 channelCount = 2
sampleRate = 48000 sampleRate = 48000
pcmEncoding = 2 encoding = 2
sample 0: sample 0:
time = 0 time = 0
flags = 1 flags = 1
......
...@@ -16,7 +16,7 @@ track 0: ...@@ -16,7 +16,7 @@ track 0:
maxInputSize = 16384 maxInputSize = 16384
channelCount = 2 channelCount = 2
sampleRate = 48000 sampleRate = 48000
pcmEncoding = 2 encoding = 2
sample 0: sample 0:
time = 853333 time = 853333
flags = 1 flags = 1
......
...@@ -16,7 +16,7 @@ track 0: ...@@ -16,7 +16,7 @@ track 0:
maxInputSize = 16384 maxInputSize = 16384
channelCount = 2 channelCount = 2
sampleRate = 48000 sampleRate = 48000
pcmEncoding = 2 encoding = 2
sample 0: sample 0:
time = 1792000 time = 1792000
flags = 1 flags = 1
......
...@@ -16,7 +16,7 @@ track 0: ...@@ -16,7 +16,7 @@ track 0:
maxInputSize = 16384 maxInputSize = 16384
channelCount = 2 channelCount = 2
sampleRate = 48000 sampleRate = 48000
pcmEncoding = 2 encoding = 2
sample 0: sample 0:
time = 2645333 time = 2645333
flags = 1 flags = 1
......
...@@ -16,7 +16,7 @@ track 0: ...@@ -16,7 +16,7 @@ track 0:
maxInputSize = 16384 maxInputSize = 16384
channelCount = 2 channelCount = 2
sampleRate = 48000 sampleRate = 48000
pcmEncoding = 2 encoding = 2
sample 0: sample 0:
time = 0 time = 0
flags = 1 flags = 1
......
...@@ -16,7 +16,7 @@ track 0: ...@@ -16,7 +16,7 @@ track 0:
maxInputSize = 16384 maxInputSize = 16384
channelCount = 2 channelCount = 2
sampleRate = 48000 sampleRate = 48000
pcmEncoding = 2 encoding = 2
metadata = entries=[TXXX: description=ID: value=105519843, TIT2: description=null: value=那么爱你为什么, TPE1: description=null: value=阿强, TALB: description=null: value=华丽的外衣, TXXX: description=ID: value=105519843, APIC: mimeType=image/jpeg, description=] metadata = entries=[TXXX: description=ID: value=105519843, TIT2: description=null: value=那么爱你为什么, TPE1: description=null: value=阿强, TALB: description=null: value=华丽的外衣, TXXX: description=ID: value=105519843, APIC: mimeType=image/jpeg, description=]
sample 0: sample 0:
time = 0 time = 0
......
...@@ -16,7 +16,7 @@ track 0: ...@@ -16,7 +16,7 @@ track 0:
maxInputSize = 16384 maxInputSize = 16384
channelCount = 2 channelCount = 2
sampleRate = 48000 sampleRate = 48000
pcmEncoding = 2 encoding = 2
metadata = entries=[TXXX: description=ID: value=105519843, TIT2: description=null: value=那么爱你为什么, TPE1: description=null: value=阿强, TALB: description=null: value=华丽的外衣, TXXX: description=ID: value=105519843, APIC: mimeType=image/jpeg, description=] metadata = entries=[TXXX: description=ID: value=105519843, TIT2: description=null: value=那么爱你为什么, TPE1: description=null: value=阿强, TALB: description=null: value=华丽的外衣, TXXX: description=ID: value=105519843, APIC: mimeType=image/jpeg, description=]
sample 0: sample 0:
time = 853333 time = 853333
......
...@@ -16,7 +16,7 @@ track 0: ...@@ -16,7 +16,7 @@ track 0:
maxInputSize = 16384 maxInputSize = 16384
channelCount = 2 channelCount = 2
sampleRate = 48000 sampleRate = 48000
pcmEncoding = 2 encoding = 2
metadata = entries=[TXXX: description=ID: value=105519843, TIT2: description=null: value=那么爱你为什么, TPE1: description=null: value=阿强, TALB: description=null: value=华丽的外衣, TXXX: description=ID: value=105519843, APIC: mimeType=image/jpeg, description=] metadata = entries=[TXXX: description=ID: value=105519843, TIT2: description=null: value=那么爱你为什么, TPE1: description=null: value=阿强, TALB: description=null: value=华丽的外衣, TXXX: description=ID: value=105519843, APIC: mimeType=image/jpeg, description=]
sample 0: sample 0:
time = 1792000 time = 1792000
......
...@@ -16,7 +16,7 @@ track 0: ...@@ -16,7 +16,7 @@ track 0:
maxInputSize = 16384 maxInputSize = 16384
channelCount = 2 channelCount = 2
sampleRate = 48000 sampleRate = 48000
pcmEncoding = 2 encoding = 2
metadata = entries=[TXXX: description=ID: value=105519843, TIT2: description=null: value=那么爱你为什么, TPE1: description=null: value=阿强, TALB: description=null: value=华丽的外衣, TXXX: description=ID: value=105519843, APIC: mimeType=image/jpeg, description=] metadata = entries=[TXXX: description=ID: value=105519843, TIT2: description=null: value=那么爱你为什么, TPE1: description=null: value=阿强, TALB: description=null: value=华丽的外衣, TXXX: description=ID: value=105519843, APIC: mimeType=image/jpeg, description=]
sample 0: sample 0:
time = 2645333 time = 2645333
......
...@@ -16,7 +16,7 @@ track 0: ...@@ -16,7 +16,7 @@ track 0:
maxInputSize = 16384 maxInputSize = 16384
channelCount = 2 channelCount = 2
sampleRate = 48000 sampleRate = 48000
pcmEncoding = 2 encoding = 2
metadata = entries=[TXXX: description=ID: value=105519843, TIT2: description=null: value=那么爱你为什么, TPE1: description=null: value=阿强, TALB: description=null: value=华丽的外衣, TXXX: description=ID: value=105519843, APIC: mimeType=image/jpeg, description=] metadata = entries=[TXXX: description=ID: value=105519843, TIT2: description=null: value=那么爱你为什么, TPE1: description=null: value=阿强, TALB: description=null: value=华丽的外衣, TXXX: description=ID: value=105519843, APIC: mimeType=image/jpeg, description=]
sample 0: sample 0:
time = 0 time = 0
......
...@@ -16,7 +16,7 @@ track 0: ...@@ -16,7 +16,7 @@ track 0:
maxInputSize = 16384 maxInputSize = 16384
channelCount = 2 channelCount = 2
sampleRate = 48000 sampleRate = 48000
pcmEncoding = 2 encoding = 2
metadata = entries=[Picture: mimeType=image/png, description=] metadata = entries=[Picture: mimeType=image/png, description=]
sample 0: sample 0:
time = 0 time = 0
......
...@@ -16,7 +16,7 @@ track 0: ...@@ -16,7 +16,7 @@ track 0:
maxInputSize = 16384 maxInputSize = 16384
channelCount = 2 channelCount = 2
sampleRate = 48000 sampleRate = 48000
pcmEncoding = 2 encoding = 2
metadata = entries=[Picture: mimeType=image/png, description=] metadata = entries=[Picture: mimeType=image/png, description=]
sample 0: sample 0:
time = 853333 time = 853333
......
...@@ -16,7 +16,7 @@ track 0: ...@@ -16,7 +16,7 @@ track 0:
maxInputSize = 16384 maxInputSize = 16384
channelCount = 2 channelCount = 2
sampleRate = 48000 sampleRate = 48000
pcmEncoding = 2 encoding = 2
metadata = entries=[Picture: mimeType=image/png, description=] metadata = entries=[Picture: mimeType=image/png, description=]
sample 0: sample 0:
time = 1792000 time = 1792000
......
...@@ -16,7 +16,7 @@ track 0: ...@@ -16,7 +16,7 @@ track 0:
maxInputSize = 16384 maxInputSize = 16384
channelCount = 2 channelCount = 2
sampleRate = 48000 sampleRate = 48000
pcmEncoding = 2 encoding = 2
metadata = entries=[Picture: mimeType=image/png, description=] metadata = entries=[Picture: mimeType=image/png, description=]
sample 0: sample 0:
time = 2645333 time = 2645333
......
...@@ -16,7 +16,7 @@ track 0: ...@@ -16,7 +16,7 @@ track 0:
maxInputSize = 16384 maxInputSize = 16384
channelCount = 2 channelCount = 2
sampleRate = 48000 sampleRate = 48000
pcmEncoding = 2 encoding = 2
metadata = entries=[Picture: mimeType=image/png, description=] metadata = entries=[Picture: mimeType=image/png, description=]
sample 0: sample 0:
time = 0 time = 0
......
...@@ -16,7 +16,7 @@ track 0: ...@@ -16,7 +16,7 @@ track 0:
maxInputSize = 16384 maxInputSize = 16384
channelCount = 2 channelCount = 2
sampleRate = 48000 sampleRate = 48000
pcmEncoding = 2 encoding = 2
metadata = entries=[VC: TITLE=test title, VC: ARTIST=test artist] metadata = entries=[VC: TITLE=test title, VC: ARTIST=test artist]
sample 0: sample 0:
time = 0 time = 0
......
...@@ -16,7 +16,7 @@ track 0: ...@@ -16,7 +16,7 @@ track 0:
maxInputSize = 16384 maxInputSize = 16384
channelCount = 2 channelCount = 2
sampleRate = 48000 sampleRate = 48000
pcmEncoding = 2 encoding = 2
metadata = entries=[VC: TITLE=test title, VC: ARTIST=test artist] metadata = entries=[VC: TITLE=test title, VC: ARTIST=test artist]
sample 0: sample 0:
time = 853333 time = 853333
......
...@@ -16,7 +16,7 @@ track 0: ...@@ -16,7 +16,7 @@ track 0:
maxInputSize = 16384 maxInputSize = 16384
channelCount = 2 channelCount = 2
sampleRate = 48000 sampleRate = 48000
pcmEncoding = 2 encoding = 2
metadata = entries=[VC: TITLE=test title, VC: ARTIST=test artist] metadata = entries=[VC: TITLE=test title, VC: ARTIST=test artist]
sample 0: sample 0:
time = 1792000 time = 1792000
......
...@@ -16,7 +16,7 @@ track 0: ...@@ -16,7 +16,7 @@ track 0:
maxInputSize = 16384 maxInputSize = 16384
channelCount = 2 channelCount = 2
sampleRate = 48000 sampleRate = 48000
pcmEncoding = 2 encoding = 2
metadata = entries=[VC: TITLE=test title, VC: ARTIST=test artist] metadata = entries=[VC: TITLE=test title, VC: ARTIST=test artist]
sample 0: sample 0:
time = 2645333 time = 2645333
......
...@@ -16,7 +16,7 @@ track 0: ...@@ -16,7 +16,7 @@ track 0:
maxInputSize = 16384 maxInputSize = 16384
channelCount = 2 channelCount = 2
sampleRate = 48000 sampleRate = 48000
pcmEncoding = 2 encoding = 2
metadata = entries=[VC: TITLE=test title, VC: ARTIST=test artist] metadata = entries=[VC: TITLE=test title, VC: ARTIST=test artist]
sample 0: sample 0:
time = 0 time = 0
......
...@@ -16,7 +16,7 @@ track 0: ...@@ -16,7 +16,7 @@ track 0:
maxInputSize = 8820 maxInputSize = 8820
channelCount = 1 channelCount = 1
sampleRate = 44100 sampleRate = 44100
pcmEncoding = 2 encoding = 2
sample 0: sample 0:
time = 0 time = 0
flags = 1 flags = 1
......
...@@ -16,7 +16,7 @@ track 0: ...@@ -16,7 +16,7 @@ track 0:
maxInputSize = 8820 maxInputSize = 8820
channelCount = 1 channelCount = 1
sampleRate = 44100 sampleRate = 44100
pcmEncoding = 2 encoding = 2
sample 0: sample 0:
time = 333333 time = 333333
flags = 1 flags = 1
......
...@@ -16,7 +16,7 @@ track 0: ...@@ -16,7 +16,7 @@ track 0:
maxInputSize = 8820 maxInputSize = 8820
channelCount = 1 channelCount = 1
sampleRate = 44100 sampleRate = 44100
pcmEncoding = 2 encoding = 2
sample 0: sample 0:
time = 666666 time = 666666
flags = 1 flags = 1
......
...@@ -16,7 +16,7 @@ track 0: ...@@ -16,7 +16,7 @@ track 0:
maxInputSize = 8820 maxInputSize = 8820
channelCount = 1 channelCount = 1
sampleRate = 44100 sampleRate = 44100
pcmEncoding = 2 encoding = 2
sample 0: sample 0:
time = 1000000 time = 1000000
flags = 1 flags = 1
......
...@@ -16,7 +16,7 @@ track 0: ...@@ -16,7 +16,7 @@ track 0:
maxInputSize = 8820 maxInputSize = 8820
channelCount = 1 channelCount = 1
sampleRate = 44100 sampleRate = 44100
pcmEncoding = 2 encoding = 2
sample 0: sample 0:
time = 0 time = 0
flags = 1 flags = 1
......
...@@ -16,7 +16,7 @@ track 0: ...@@ -16,7 +16,7 @@ track 0:
maxInputSize = 8820 maxInputSize = 8820
channelCount = 1 channelCount = 1
sampleRate = 44100 sampleRate = 44100
pcmEncoding = 2 encoding = 2
sample 0: sample 0:
time = 0 time = 0
flags = 1 flags = 1
......
...@@ -16,7 +16,7 @@ track 0: ...@@ -16,7 +16,7 @@ track 0:
maxInputSize = 8820 maxInputSize = 8820
channelCount = 1 channelCount = 1
sampleRate = 44100 sampleRate = 44100
pcmEncoding = 2 encoding = 2
sample 0: sample 0:
time = 339395 time = 339395
flags = 1 flags = 1
......
...@@ -16,7 +16,7 @@ track 0: ...@@ -16,7 +16,7 @@ track 0:
maxInputSize = 8820 maxInputSize = 8820
channelCount = 1 channelCount = 1
sampleRate = 44100 sampleRate = 44100
pcmEncoding = 2 encoding = 2
sample 0: sample 0:
time = 678790 time = 678790
flags = 1 flags = 1
......
...@@ -16,7 +16,7 @@ track 0: ...@@ -16,7 +16,7 @@ track 0:
maxInputSize = 8820 maxInputSize = 8820
channelCount = 1 channelCount = 1
sampleRate = 44100 sampleRate = 44100
pcmEncoding = 2 encoding = 2
sample 0: sample 0:
time = 1018185 time = 1018185
flags = 1 flags = 1
......
...@@ -16,7 +16,7 @@ track 0: ...@@ -16,7 +16,7 @@ track 0:
maxInputSize = 8820 maxInputSize = 8820
channelCount = 1 channelCount = 1
sampleRate = 44100 sampleRate = 44100
pcmEncoding = 2 encoding = 2
sample 0: sample 0:
time = 0 time = 0
flags = 1 flags = 1
......
...@@ -19,6 +19,7 @@ import static com.google.common.truth.Truth.assertWithMessage; ...@@ -19,6 +19,7 @@ import static com.google.common.truth.Truth.assertWithMessage;
import android.content.Context; import android.content.Context;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.audio.AudioSink; import com.google.android.exoplayer2.audio.AudioSink;
import com.google.android.exoplayer2.audio.ForwardingAudioSink; import com.google.android.exoplayer2.audio.ForwardingAudioSink;
import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Assertions;
...@@ -52,25 +53,12 @@ public final class CapturingAudioSink extends ForwardingAudioSink implements Dum ...@@ -52,25 +53,12 @@ public final class CapturingAudioSink extends ForwardingAudioSink implements Dum
} }
@Override @Override
public void configure( public void configure(Format inputFormat, int specifiedBufferSize, @Nullable int[] outputChannels)
int inputEncoding,
int inputChannelCount,
int inputSampleRate,
int specifiedBufferSize,
@Nullable int[] outputChannels,
int trimStartFrames,
int trimEndFrames)
throws ConfigurationException { throws ConfigurationException {
interceptedData.add( interceptedData.add(
new DumpableConfiguration(inputEncoding, inputChannelCount, inputSampleRate)); new DumpableConfiguration(
super.configure( inputFormat.encoding, inputFormat.channelCount, inputFormat.sampleRate));
inputEncoding, super.configure(inputFormat, specifiedBufferSize, outputChannels);
inputChannelCount,
inputSampleRate,
specifiedBufferSize,
outputChannels,
trimStartFrames,
trimEndFrames);
} }
@Override @Override
......
...@@ -312,7 +312,7 @@ public final class FakeTrackOutput implements TrackOutput, Dumper.Dumpable { ...@@ -312,7 +312,7 @@ public final class FakeTrackOutput implements TrackOutput, Dumper.Dumpable {
addIfNonDefault(dumper, "pixelWidthHeightRatio", format -> format.pixelWidthHeightRatio); addIfNonDefault(dumper, "pixelWidthHeightRatio", format -> format.pixelWidthHeightRatio);
addIfNonDefault(dumper, "channelCount", format -> format.channelCount); addIfNonDefault(dumper, "channelCount", format -> format.channelCount);
addIfNonDefault(dumper, "sampleRate", format -> format.sampleRate); addIfNonDefault(dumper, "sampleRate", format -> format.sampleRate);
addIfNonDefault(dumper, "pcmEncoding", format -> format.pcmEncoding); addIfNonDefault(dumper, "encoding", format -> format.encoding);
addIfNonDefault(dumper, "encoderDelay", format -> format.encoderDelay); addIfNonDefault(dumper, "encoderDelay", format -> format.encoderDelay);
addIfNonDefault(dumper, "encoderPadding", format -> format.encoderPadding); addIfNonDefault(dumper, "encoderPadding", format -> format.encoderPadding);
addIfNonDefault(dumper, "subsampleOffsetUs", format -> format.subsampleOffsetUs); addIfNonDefault(dumper, "subsampleOffsetUs", format -> format.subsampleOffsetUs);
......
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