diff --git a/library/core/src/main/java/com/google/android/exoplayer2/Format.java b/library/core/src/main/java/com/google/android/exoplayer2/Format.java index 16225982ae..b18225fc70 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/Format.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/Format.java @@ -145,12 +145,12 @@ public final class Format implements Parcelable { @C.PcmEncoding public final int pcmEncoding; /** - * The number of samples 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. */ public final int encoderDelay; /** - * The number of samples to trim from the end of the decoded audio stream, or 0 if not applicable. + * The number of frames to trim from the end of the decoded audio stream, or 0 if not applicable. */ public final int encoderPadding; diff --git a/library/core/src/main/java/com/google/android/exoplayer2/audio/AudioSink.java b/library/core/src/main/java/com/google/android/exoplayer2/audio/AudioSink.java index 6bb5bf7d8e..07584d575e 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/audio/AudioSink.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/audio/AudioSink.java @@ -192,17 +192,23 @@ public interface AudioSink { * @param outputChannels A mapping from input to output channels that is applied to this sink's * input as a preprocessing step, if handling PCM input. Specify {@code null} to leave the * 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 is applied the audio data will have {@code outputChannels.length} channels. - * @param trimStartSamples The number of audio samples to trim from the start of data written to - * the sink after this call. - * @param trimEndSamples The number of audio samples to trim from data written to the sink + * 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. + * @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 #reset()} or this method. * @throws ConfigurationException If an error occurs configuring the sink. */ - void configure(@C.Encoding int inputEncoding, int inputChannelCount, int inputSampleRate, - int specifiedBufferSize, @Nullable int[] outputChannels, int trimStartSamples, - int trimEndSamples) throws ConfigurationException; + void configure( + @C.Encoding int inputEncoding, + int inputChannelCount, + int inputSampleRate, + int specifiedBufferSize, + @Nullable int[] outputChannels, + int trimStartFrames, + int trimEndFrames) + throws ConfigurationException; /** * Starts or resumes consuming audio if initialized. diff --git a/library/core/src/main/java/com/google/android/exoplayer2/audio/DefaultAudioSink.java b/library/core/src/main/java/com/google/android/exoplayer2/audio/DefaultAudioSink.java index 137517cdcb..5f363cdaf1 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/audio/DefaultAudioSink.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/audio/DefaultAudioSink.java @@ -278,9 +278,15 @@ public final class DefaultAudioSink implements AudioSink { } @Override - public void configure(@C.Encoding int inputEncoding, int inputChannelCount, int inputSampleRate, - int specifiedBufferSize, @Nullable int[] outputChannels, int trimStartSamples, - int trimEndSamples) throws ConfigurationException { + public void configure( + @C.Encoding int inputEncoding, + int inputChannelCount, + int inputSampleRate, + int specifiedBufferSize, + @Nullable int[] outputChannels, + int trimStartFrames, + int trimEndFrames) + throws ConfigurationException { boolean flush = false; this.inputSampleRate = inputSampleRate; int channelCount = inputChannelCount; @@ -297,7 +303,7 @@ public final class DefaultAudioSink implements AudioSink { boolean processingEnabled = isInputPcm && inputEncoding != C.ENCODING_PCM_FLOAT; canApplyPlaybackParameters = processingEnabled && !shouldConvertHighResIntPcmToFloat; if (processingEnabled) { - trimmingAudioProcessor.setTrimSampleCount(trimStartSamples, trimEndSamples); + trimmingAudioProcessor.setTrimFrameCount(trimStartFrames, trimEndFrames); channelMappingAudioProcessor.setChannelMap(outputChannels); for (AudioProcessor audioProcessor : getAvailableAudioProcessors()) { try { diff --git a/library/core/src/main/java/com/google/android/exoplayer2/audio/TrimmingAudioProcessor.java b/library/core/src/main/java/com/google/android/exoplayer2/audio/TrimmingAudioProcessor.java index 25db5fc871..ccaa9c3fed 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/audio/TrimmingAudioProcessor.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/audio/TrimmingAudioProcessor.java @@ -26,8 +26,8 @@ import java.nio.ByteOrder; /* package */ final class TrimmingAudioProcessor implements AudioProcessor { private boolean isActive; - private int trimStartSamples; - private int trimEndSamples; + private int trimStartFrames; + private int trimEndFrames; private int channelCount; private int sampleRateHz; @@ -48,17 +48,17 @@ import java.nio.ByteOrder; } /** - * Sets the number of audio samples to trim from the start and end of audio passed to this + * Sets the number of audio frames to trim from the start and end of audio passed to this * processor. After calling this method, call {@link #configure(int, int, int)} to apply the new - * trimming sample counts. + * trimming frame counts. * - * @param trimStartSamples The number of audio samples to trim from the start of audio. - * @param trimEndSamples The number of audio samples to trim from the end 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. * @see AudioSink#configure(int, int, int, int, int[], int, int) */ - public void setTrimSampleCount(int trimStartSamples, int trimEndSamples) { - this.trimStartSamples = trimStartSamples; - this.trimEndSamples = trimEndSamples; + public void setTrimFrameCount(int trimStartFrames, int trimEndFrames) { + this.trimStartFrames = trimStartFrames; + this.trimEndFrames = trimEndFrames; } @Override @@ -69,11 +69,11 @@ import java.nio.ByteOrder; } this.channelCount = channelCount; this.sampleRateHz = sampleRateHz; - endBuffer = new byte[trimEndSamples * channelCount * 2]; + endBuffer = new byte[trimEndFrames * channelCount * 2]; endBufferSize = 0; - pendingTrimStartBytes = trimStartSamples * channelCount * 2; + pendingTrimStartBytes = trimStartFrames * channelCount * 2; boolean wasActive = isActive; - isActive = trimStartSamples != 0 || trimEndSamples != 0; + isActive = trimStartFrames != 0 || trimEndFrames != 0; return wasActive != isActive; }