Skip to content

Commit 92dc1d3

Browse files
Samrobbomicrokatz
authored andcommitted
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 7fcb53d)
1 parent 35900f9 commit 92dc1d3

File tree

3 files changed

+88
-60
lines changed

3 files changed

+88
-60
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Copyright 2022 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package androidx.media3.common.audio;
17+
18+
import androidx.media3.common.PlaybackParameters;
19+
import androidx.media3.common.util.UnstableApi;
20+
21+
/**
22+
* Provides a chain of audio processors, which are used for any user-defined processing and applying
23+
* playback parameters (if supported). Because applying playback parameters can skip and
24+
* stretch/compress audio, the sink will query the chain for information on how to transform its
25+
* output position to map it onto a media position, via {@link #getMediaDuration(long)} and {@link
26+
* #getSkippedOutputFrameCount()}.
27+
*/
28+
@UnstableApi
29+
public interface AudioProcessorChain {
30+
31+
/**
32+
* Returns the fixed chain of audio processors that will process audio. This method is called once
33+
* during initialization, but audio processors may change state to become active/inactive during
34+
* playback.
35+
*/
36+
AudioProcessor[] getAudioProcessors();
37+
38+
/**
39+
* Configures audio processors to apply the specified playback parameters immediately, returning
40+
* the new playback parameters, which may differ from those passed in. Only called when processors
41+
* have no input pending.
42+
*
43+
* @param playbackParameters The playback parameters to try to apply.
44+
* @return The playback parameters that were actually applied.
45+
*/
46+
PlaybackParameters applyPlaybackParameters(PlaybackParameters playbackParameters);
47+
48+
/**
49+
* Configures audio processors to apply whether to skip silences immediately, returning the new
50+
* value. Only called when processors have no input pending.
51+
*
52+
* @param skipSilenceEnabled Whether silences should be skipped in the audio stream.
53+
* @return The new value.
54+
*/
55+
boolean applySkipSilenceEnabled(boolean skipSilenceEnabled);
56+
57+
/**
58+
* Returns the media duration corresponding to the specified playout duration, taking speed
59+
* adjustment due to audio processing into account.
60+
*
61+
*

The scaling performed by this method will use the actual playback speed achieved by the

62+
* audio processor chain, on average, since it was last flushed. This may differ very slightly
63+
* from the target playback speed.
64+
*
65+
* @param playoutDuration The playout duration to scale.
66+
* @return The corresponding media duration, in the same units as {@code duration}.
67+
*/
68+
long getMediaDuration(long playoutDuration);
69+
70+
/**
71+
* Returns the number of output audio frames skipped since the audio processors were last flushed.
72+
*/
73+
long getSkippedOutputFrameCount();
74+
}

libraries/exoplayer/src/main/java/androidx/media3/exoplayer/audio/DefaultAudioSink.java

Lines changed: 11 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -111,64 +111,16 @@ private InvalidAudioTrackTimestampException(String message) {
111111
}
112112

113113
/**
114-
* Provides a chain of audio processors, which are used for any user-defined processing and
115-
* applying playback parameters (if supported). Because applying playback parameters can skip and
116-
* stretch/compress audio, the sink will query the chain for information on how to transform its
117-
* output position to map it onto a media position, via {@link #getMediaDuration(long)} and {@link
118-
* #getSkippedOutputFrameCount()}.
114+
* @deprecated Use {@link androidx.media3.common.audio.AudioProcessorChain}.
119115
*/
120-
public interface AudioProcessorChain {
121-
122-
/**
123-
* Returns the fixed chain of audio processors that will process audio. This method is called
124-
* once during initialization, but audio processors may change state to become active/inactive
125-
* during playback.
126-
*/
127-
AudioProcessor[] getAudioProcessors();
128-
129-
/**
130-
* Configures audio processors to apply the specified playback parameters immediately, returning
131-
* the new playback parameters, which may differ from those passed in. Only called when
132-
* processors have no input pending.
133-
*
134-
* @param playbackParameters The playback parameters to try to apply.
135-
* @return The playback parameters that were actually applied.
136-
*/
137-
PlaybackParameters applyPlaybackParameters(PlaybackParameters playbackParameters);
138-
139-
/**
140-
* Configures audio processors to apply whether to skip silences immediately, returning the new
141-
* value. Only called when processors have no input pending.
142-
*
143-
* @param skipSilenceEnabled Whether silences should be skipped in the audio stream.
144-
* @return The new value.
145-
*/
146-
boolean applySkipSilenceEnabled(boolean skipSilenceEnabled);
147-
148-
/**
149-
* Returns the media duration corresponding to the specified playout duration, taking speed
150-
* adjustment due to audio processing into account.
151-
*
152-
*

The scaling performed by this method will use the actual playback speed achieved by the

153-
* audio processor chain, on average, since it was last flushed. This may differ very slightly
154-
* from the target playback speed.
155-
*
156-
* @param playoutDuration The playout duration to scale.
157-
* @return The corresponding media duration, in the same units as {@code duration}.
158-
*/
159-
long getMediaDuration(long playoutDuration);
160-
161-
/**
162-
* Returns the number of output audio frames skipped since the audio processors were last
163-
* flushed.
164-
*/
165-
long getSkippedOutputFrameCount();
166-
}
116+
@Deprecated
117+
public interface AudioProcessorChain extends androidx.media3.common.audio.AudioProcessorChain {}
167118

168119
/**
169120
* The default audio processor chain, which applies a (possibly empty) chain of user-defined audio
170121
* processors followed by {@link SilenceSkippingAudioProcessor} and {@link SonicAudioProcessor}.
171122
*/
123+
@SuppressWarnings("deprecation")
172124
public static class DefaultAudioProcessorChain implements AudioProcessorChain {
173125

174126
private final AudioProcessor[] audioProcessors;
@@ -272,7 +224,7 @@ int getBufferSizeInBytes(
272224
public static final class Builder {
273225

274226
private AudioCapabilities audioCapabilities;
275-
@Nullable private AudioProcessorChain audioProcessorChain;
227+
@Nullable private androidx.media3.common.audio.AudioProcessorChain audioProcessorChain;
276228
private boolean enableFloatOutput;
277229
private boolean enableAudioTrackPlaybackParams;
278230
private int offloadMode;
@@ -313,14 +265,15 @@ public Builder setAudioProcessors(AudioProcessor[] audioProcessors) {
313265
}
314266

315267
/**
316-
* Sets the {@link AudioProcessorChain} to process audio before playback. The instance passed in
317-
* must not be reused in other sinks. Processing chains are only supported for PCM playback (not
318-
* passthrough or offload).
268+
* Sets the {@link androidx.media3.common.audio.AudioProcessorChain} to process audio before
269+
* playback. The instance passed in must not be reused in other sinks. Processing chains are
270+
* only supported for PCM playback (not passthrough or offload).
319271
*
320272
*

By default, no processing will be applied.

321273
*/
322274
@CanIgnoreReturnValue
323-
public Builder setAudioProcessorChain(AudioProcessorChain audioProcessorChain) {
275+
public Builder setAudioProcessorChain(
276+
androidx.media3.common.audio.AudioProcessorChain audioProcessorChain) {
324277
checkNotNull(audioProcessorChain);
325278
this.audioProcessorChain = audioProcessorChain;
326279
return this;
@@ -510,7 +463,7 @@ public DefaultAudioSink build() {
510463
private static int pendingReleaseCount;
511464

512465
private final AudioCapabilities audioCapabilities;
513-
private final AudioProcessorChain audioProcessorChain;
466+
private final androidx.media3.common.audio.AudioProcessorChain audioProcessorChain;
514467
private final boolean enableFloatOutput;
515468
private final ChannelMappingAudioProcessor channelMappingAudioProcessor;
516469
private final TrimmingAudioProcessor trimmingAudioProcessor;

libraries/exoplayer/src/main/java/androidx/media3/exoplayer/audio/TeeAudioProcessor.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import androidx.annotation.Nullable;
2121
import androidx.media3.common.C;
22+
import androidx.media3.common.audio.AudioProcessorChain;
2223
import androidx.media3.common.util.Assertions;
2324
import androidx.media3.common.util.Log;
2425
import androidx.media3.common.util.UnstableApi;
@@ -36,8 +37,8 @@
3637
*

This audio processor can be inserted into the audio processor chain to access audio data

3738
* before/after particular processing steps have been applied. For example, to get audio output
3839
* after playback speed adjustment and silence skipping have been applied it is necessary to pass a
39-
* custom {@link DefaultAudioSink.AudioProcessorChain} when creating the audio sink, and include
40-
* this audio processor after all other audio processors.
40+
* custom {@link AudioProcessorChain} when creating the audio sink, and include this audio processor
41+
* after all other audio processors.
4142
*/
4243
@UnstableApi
4344
public final class TeeAudioProcessor extends BaseAudioProcessor {

0 commit comments

Comments
 (0)