Skip to content

Commit fe4f235

Browse files
toniheicopybara-github
authored andcommitted
Move AudioTrack config and creation to a separate class
This adds an AudioOutputProvider interface to encapsulate the 3-step process in DefaultAudioSink: check format support, configure the output, create the output from the config. The interface and classes are package-private for now and can made configurable in a follow-up step. PiperOrigin-RevId: 819755885
1 parent c8044ca commit fe4f235

File tree

8 files changed

+1722
-529
lines changed

8 files changed

+1722
-529
lines changed

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

Lines changed: 0 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,12 @@
1515
*/
1616
package androidx.media3.exoplayer.audio;
1717

18-
import android.content.Context;
1918
import android.media.AudioDeviceInfo;
2019
import android.media.AudioTrack;
2120
import androidx.annotation.Nullable;
22-
import androidx.media3.common.AudioAttributes;
2321
import androidx.media3.common.C;
2422
import androidx.media3.common.PlaybackParameters;
2523
import androidx.media3.exoplayer.analytics.PlayerId;
26-
import com.google.errorprone.annotations.CanIgnoreReturnValue;
2724
import java.nio.ByteBuffer;
2825

2926
/** An interface to wrap an object that can play audio, like an {@link AudioTrack}. */
@@ -55,153 +52,6 @@ interface Listener {
5552
void onReleased();
5653
}
5754

58-
/** Configuration for an {@link AudioOutput}. */
59-
final class OutputConfig {
60-
61-
/** The {@link C.Encoding} of the audio data. */
62-
public final @C.Encoding int encoding;
63-
64-
/** The sample rate of the audio data. */
65-
public final int sampleRate;
66-
67-
/**
68-
* The channel configuration of the output. See {@code AudioFormat.CHANNEL_OUT_XXX} constants
69-
* like {@link android.media.AudioFormat#CHANNEL_OUT_5POINT1}.
70-
*/
71-
public final int channelConfig;
72-
73-
/** Whether tunneling is enabled for this output. */
74-
public final boolean isTunneling;
75-
76-
/** Whether offload is enabled for this output. */
77-
public final boolean isOffload;
78-
79-
/** The buffer size of the output in bytes. */
80-
public final int bufferSize;
81-
82-
/** The {@link AudioAttributes} for the audio output. */
83-
public final AudioAttributes audioAttributes;
84-
85-
/** The audio session ID. */
86-
public final int audioSessionId;
87-
88-
/** The {@link Context}, or null if it should not be used to configure the output. */
89-
@Nullable public final Context context;
90-
91-
private OutputConfig(Builder builder) {
92-
this.encoding = builder.encoding;
93-
this.sampleRate = builder.sampleRate;
94-
this.channelConfig = builder.channelConfig;
95-
this.isTunneling = builder.isTunneling;
96-
this.isOffload = builder.isOffload;
97-
this.bufferSize = builder.bufferSize;
98-
this.audioAttributes = builder.audioAttributes;
99-
this.audioSessionId = builder.audioSessionId;
100-
this.context = builder.context;
101-
}
102-
103-
/** Returns a {@link Builder} initialized with the values of this instance. */
104-
public Builder buildUpon() {
105-
return new Builder(this);
106-
}
107-
108-
/** Builder for {@link OutputConfig} instances. */
109-
public static final class Builder {
110-
private @C.Encoding int encoding;
111-
private int sampleRate;
112-
private int channelConfig;
113-
private boolean isTunneling;
114-
private boolean isOffload;
115-
private int bufferSize;
116-
private AudioAttributes audioAttributes = AudioAttributes.DEFAULT;
117-
private int audioSessionId;
118-
@Nullable private Context context;
119-
120-
/** Creates a new instance. */
121-
public Builder() {}
122-
123-
private Builder(OutputConfig config) {
124-
this.encoding = config.encoding;
125-
this.sampleRate = config.sampleRate;
126-
this.channelConfig = config.channelConfig;
127-
this.isTunneling = config.isTunneling;
128-
this.isOffload = config.isOffload;
129-
this.bufferSize = config.bufferSize;
130-
this.audioAttributes = config.audioAttributes;
131-
this.audioSessionId = config.audioSessionId;
132-
this.context = config.context;
133-
}
134-
135-
/** Sets the {@link C.Encoding} of the audio data. */
136-
@CanIgnoreReturnValue
137-
public Builder setEncoding(@C.Encoding int encoding) {
138-
this.encoding = encoding;
139-
return this;
140-
}
141-
142-
/** Sets the sample rate of the audio data. */
143-
@CanIgnoreReturnValue
144-
public Builder setSampleRate(int sampleRate) {
145-
this.sampleRate = sampleRate;
146-
return this;
147-
}
148-
149-
/** Sets the channel configuration of the output. */
150-
@CanIgnoreReturnValue
151-
public Builder setChannelConfig(int channelConfig) {
152-
this.channelConfig = channelConfig;
153-
return this;
154-
}
155-
156-
/** Sets whether tunneling is enabled for this output. */
157-
@CanIgnoreReturnValue
158-
public Builder setIsTunneling(boolean isTunneling) {
159-
this.isTunneling = isTunneling;
160-
return this;
161-
}
162-
163-
/** Sets whether offload is enabled for this output. */
164-
@CanIgnoreReturnValue
165-
public Builder setIsOffload(boolean isOffload) {
166-
this.isOffload = isOffload;
167-
return this;
168-
}
169-
170-
/** Sets the buffer size of the output in bytes. */
171-
@CanIgnoreReturnValue
172-
public Builder setBufferSize(int bufferSize) {
173-
this.bufferSize = bufferSize;
174-
return this;
175-
}
176-
177-
/** Sets the {@link AudioAttributes}. */
178-
@CanIgnoreReturnValue
179-
public Builder setAudioAttributes(AudioAttributes audioAttributes) {
180-
this.audioAttributes = audioAttributes;
181-
return this;
182-
}
183-
184-
/** Sets the audio session ID. */
185-
@CanIgnoreReturnValue
186-
public Builder setAudioSessionId(int audioSessionId) {
187-
this.audioSessionId = audioSessionId;
188-
return this;
189-
}
190-
191-
/** Sets the {@link Context}, or null if it should not be used to configure the output. */
192-
@CanIgnoreReturnValue
193-
public Builder setContext(@Nullable Context context) {
194-
this.context = context;
195-
return this;
196-
}
197-
198-
/** Builds the {@link OutputConfig}. */
199-
public OutputConfig build() {
200-
return new OutputConfig(this);
201-
}
202-
}
203-
}
204-
20555
/** Thrown when a failure occurs writing to the output. */
20656
final class WriteException extends Exception {
20757

0 commit comments

Comments
 (0)