mirror of
https://github.com/androidx/media.git
synced 2025-05-14 02:59:52 +08:00
Move DefaultAudioSink.AudioProcessorChain
to AudioProcessorChain
Split inner interface into separate file, which will go in common module. The old interface will be deprecated and extends the new. #cleanup PiperOrigin-RevId: 483732226 (cherry picked from commit ad52b68c738e8321b966b904d3cd2139f7a560ef)
This commit is contained in:
parent
8debe79333
commit
fe9bad1119
@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package androidx.media3.common.audio;
|
||||||
|
|
||||||
|
import com.google.android.exoplayer2.PlaybackParameters;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides a chain of audio processors, which are used for any user-defined processing and applying
|
||||||
|
* playback parameters (if supported). Because applying playback parameters can skip and
|
||||||
|
* stretch/compress audio, the sink will query the chain for information on how to transform its
|
||||||
|
* output position to map it onto a media position, via {@link #getMediaDuration(long)} and {@link
|
||||||
|
* #getSkippedOutputFrameCount()}.
|
||||||
|
*/
|
||||||
|
public interface AudioProcessorChain {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the fixed chain of audio processors that will process audio. This method is called once
|
||||||
|
* during initialization, but audio processors may change state to become active/inactive during
|
||||||
|
* playback.
|
||||||
|
*/
|
||||||
|
AudioProcessor[] getAudioProcessors();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configures audio processors to apply the specified playback parameters immediately, returning
|
||||||
|
* the new playback parameters, which may differ from those passed in. Only called when processors
|
||||||
|
* have no input pending.
|
||||||
|
*
|
||||||
|
* @param playbackParameters The playback parameters to try to apply.
|
||||||
|
* @return The playback parameters that were actually applied.
|
||||||
|
*/
|
||||||
|
PlaybackParameters applyPlaybackParameters(PlaybackParameters playbackParameters);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configures audio processors to apply whether to skip silences immediately, returning the new
|
||||||
|
* value. Only called when processors have no input pending.
|
||||||
|
*
|
||||||
|
* @param skipSilenceEnabled Whether silences should be skipped in the audio stream.
|
||||||
|
* @return The new value.
|
||||||
|
*/
|
||||||
|
boolean applySkipSilenceEnabled(boolean skipSilenceEnabled);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the media duration corresponding to the specified playout duration, taking speed
|
||||||
|
* adjustment due to audio processing into account.
|
||||||
|
*
|
||||||
|
* <p>The scaling performed by this method will use the actual playback speed achieved by the
|
||||||
|
* audio processor chain, on average, since it was last flushed. This may differ very slightly
|
||||||
|
* from the target playback speed.
|
||||||
|
*
|
||||||
|
* @param playoutDuration The playout duration to scale.
|
||||||
|
* @return The corresponding media duration, in the same units as {@code duration}.
|
||||||
|
*/
|
||||||
|
long getMediaDuration(long playoutDuration);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number of output audio frames skipped since the audio processors were last flushed.
|
||||||
|
*/
|
||||||
|
long getSkippedOutputFrameCount();
|
||||||
|
}
|
@ -102,64 +102,16 @@ public final class DefaultAudioSink implements AudioSink {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides a chain of audio processors, which are used for any user-defined processing and
|
* @deprecated Use {@link androidx.media3.common.audio.AudioProcessorChain}.
|
||||||
* applying playback parameters (if supported). Because applying playback parameters can skip and
|
|
||||||
* stretch/compress audio, the sink will query the chain for information on how to transform its
|
|
||||||
* output position to map it onto a media position, via {@link #getMediaDuration(long)} and {@link
|
|
||||||
* #getSkippedOutputFrameCount()}.
|
|
||||||
*/
|
*/
|
||||||
public interface AudioProcessorChain {
|
@Deprecated
|
||||||
|
public interface AudioProcessorChain extends androidx.media3.common.audio.AudioProcessorChain {}
|
||||||
/**
|
|
||||||
* Returns the fixed chain of audio processors that will process audio. This method is called
|
|
||||||
* once during initialization, but audio processors may change state to become active/inactive
|
|
||||||
* during playback.
|
|
||||||
*/
|
|
||||||
AudioProcessor[] getAudioProcessors();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Configures audio processors to apply the specified playback parameters immediately, returning
|
|
||||||
* the new playback parameters, which may differ from those passed in. Only called when
|
|
||||||
* processors have no input pending.
|
|
||||||
*
|
|
||||||
* @param playbackParameters The playback parameters to try to apply.
|
|
||||||
* @return The playback parameters that were actually applied.
|
|
||||||
*/
|
|
||||||
PlaybackParameters applyPlaybackParameters(PlaybackParameters playbackParameters);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Configures audio processors to apply whether to skip silences immediately, returning the new
|
|
||||||
* value. Only called when processors have no input pending.
|
|
||||||
*
|
|
||||||
* @param skipSilenceEnabled Whether silences should be skipped in the audio stream.
|
|
||||||
* @return The new value.
|
|
||||||
*/
|
|
||||||
boolean applySkipSilenceEnabled(boolean skipSilenceEnabled);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the media duration corresponding to the specified playout duration, taking speed
|
|
||||||
* adjustment due to audio processing into account.
|
|
||||||
*
|
|
||||||
* <p>The scaling performed by this method will use the actual playback speed achieved by the
|
|
||||||
* audio processor chain, on average, since it was last flushed. This may differ very slightly
|
|
||||||
* from the target playback speed.
|
|
||||||
*
|
|
||||||
* @param playoutDuration The playout duration to scale.
|
|
||||||
* @return The corresponding media duration, in the same units as {@code duration}.
|
|
||||||
*/
|
|
||||||
long getMediaDuration(long playoutDuration);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the number of output audio frames skipped since the audio processors were last
|
|
||||||
* flushed.
|
|
||||||
*/
|
|
||||||
long getSkippedOutputFrameCount();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The default audio processor chain, which applies a (possibly empty) chain of user-defined audio
|
* The default audio processor chain, which applies a (possibly empty) chain of user-defined audio
|
||||||
* processors followed by {@link SilenceSkippingAudioProcessor} and {@link SonicAudioProcessor}.
|
* processors followed by {@link SilenceSkippingAudioProcessor} and {@link SonicAudioProcessor}.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public static class DefaultAudioProcessorChain implements AudioProcessorChain {
|
public static class DefaultAudioProcessorChain implements AudioProcessorChain {
|
||||||
|
|
||||||
private final AudioProcessor[] audioProcessors;
|
private final AudioProcessor[] audioProcessors;
|
||||||
@ -263,7 +215,7 @@ public final class DefaultAudioSink implements AudioSink {
|
|||||||
public static final class Builder {
|
public static final class Builder {
|
||||||
|
|
||||||
private AudioCapabilities audioCapabilities;
|
private AudioCapabilities audioCapabilities;
|
||||||
@Nullable private AudioProcessorChain audioProcessorChain;
|
@Nullable private androidx.media3.common.audio.AudioProcessorChain audioProcessorChain;
|
||||||
private boolean enableFloatOutput;
|
private boolean enableFloatOutput;
|
||||||
private boolean enableAudioTrackPlaybackParams;
|
private boolean enableAudioTrackPlaybackParams;
|
||||||
private int offloadMode;
|
private int offloadMode;
|
||||||
@ -304,14 +256,15 @@ public final class DefaultAudioSink implements AudioSink {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the {@link AudioProcessorChain} to process audio before playback. The instance passed in
|
* Sets the {@link androidx.media3.common.audio.AudioProcessorChain} to process audio before
|
||||||
* must not be reused in other sinks. Processing chains are only supported for PCM playback (not
|
* playback. The instance passed in must not be reused in other sinks. Processing chains are
|
||||||
* passthrough or offload).
|
* only supported for PCM playback (not passthrough or offload).
|
||||||
*
|
*
|
||||||
* <p>By default, no processing will be applied.
|
* <p>By default, no processing will be applied.
|
||||||
*/
|
*/
|
||||||
@CanIgnoreReturnValue
|
@CanIgnoreReturnValue
|
||||||
public Builder setAudioProcessorChain(AudioProcessorChain audioProcessorChain) {
|
public Builder setAudioProcessorChain(
|
||||||
|
androidx.media3.common.audio.AudioProcessorChain audioProcessorChain) {
|
||||||
checkNotNull(audioProcessorChain);
|
checkNotNull(audioProcessorChain);
|
||||||
this.audioProcessorChain = audioProcessorChain;
|
this.audioProcessorChain = audioProcessorChain;
|
||||||
return this;
|
return this;
|
||||||
@ -501,7 +454,7 @@ public final class DefaultAudioSink implements AudioSink {
|
|||||||
private static int pendingReleaseCount;
|
private static int pendingReleaseCount;
|
||||||
|
|
||||||
private final AudioCapabilities audioCapabilities;
|
private final AudioCapabilities audioCapabilities;
|
||||||
private final AudioProcessorChain audioProcessorChain;
|
private final androidx.media3.common.audio.AudioProcessorChain audioProcessorChain;
|
||||||
private final boolean enableFloatOutput;
|
private final boolean enableFloatOutput;
|
||||||
private final ChannelMappingAudioProcessor channelMappingAudioProcessor;
|
private final ChannelMappingAudioProcessor channelMappingAudioProcessor;
|
||||||
private final TrimmingAudioProcessor trimmingAudioProcessor;
|
private final TrimmingAudioProcessor trimmingAudioProcessor;
|
||||||
|
@ -18,6 +18,7 @@ package com.google.android.exoplayer2.audio;
|
|||||||
import static java.lang.Math.min;
|
import static java.lang.Math.min;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.media3.common.audio.AudioProcessorChain;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
import com.google.android.exoplayer2.util.Assertions;
|
import com.google.android.exoplayer2.util.Assertions;
|
||||||
import com.google.android.exoplayer2.util.Log;
|
import com.google.android.exoplayer2.util.Log;
|
||||||
@ -34,8 +35,8 @@ import java.nio.ByteOrder;
|
|||||||
* <p>This audio processor can be inserted into the audio processor chain to access audio data
|
* <p>This audio processor can be inserted into the audio processor chain to access audio data
|
||||||
* before/after particular processing steps have been applied. For example, to get audio output
|
* before/after particular processing steps have been applied. For example, to get audio output
|
||||||
* after playback speed adjustment and silence skipping have been applied it is necessary to pass a
|
* after playback speed adjustment and silence skipping have been applied it is necessary to pass a
|
||||||
* custom {@link DefaultAudioSink.AudioProcessorChain} when creating the audio sink, and include
|
* custom {@link AudioProcessorChain} when creating the audio sink, and include this audio processor
|
||||||
* this audio processor after all other audio processors.
|
* after all other audio processors.
|
||||||
*/
|
*/
|
||||||
public final class TeeAudioProcessor extends BaseAudioProcessor {
|
public final class TeeAudioProcessor extends BaseAudioProcessor {
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user