Commit 9c7950f3 by andrewlewis Committed by Oliver Woodman

Add AudioSink interface and use it from audio renderers

This change allows applications to provide custom AudioSinks, which could be
based on android.media.AudioTrack like AudioTrackAudioSink, or could be
completely custom.

The refactoring is mostly mechanical and shouldn't result in any functionality
changes.

Some android.media.AudioTrack-specific details have to appear in the AudioSink
interface so this change modifies the javadoc on the AudioTrack (now AudioSink)
to note that some methods will have no effect.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=170311083
parent b14b3d43
......@@ -248,7 +248,7 @@ import java.util.Locale;
}
@Override
public void onAudioTrackUnderrun(int bufferSize, long bufferSizeMs, long elapsedSinceLastFeedMs) {
public void onAudioSinkUnderrun(int bufferSize, long bufferSizeMs, long elapsedSinceLastFeedMs) {
printInternalError("audioTrackUnderrun [" + bufferSize + ", " + bufferSizeMs + ", "
+ elapsedSinceLastFeedMs + "]", null);
}
......
......@@ -976,10 +976,10 @@ public class SimpleExoPlayer implements ExoPlayer {
}
@Override
public void onAudioTrackUnderrun(int bufferSize, long bufferSizeMs,
public void onAudioSinkUnderrun(int bufferSize, long bufferSizeMs,
long elapsedSinceLastFeedMs) {
if (audioDebugListener != null) {
audioDebugListener.onAudioTrackUnderrun(bufferSize, bufferSizeMs, elapsedSinceLastFeedMs);
audioDebugListener.onAudioSinkUnderrun(bufferSize, bufferSizeMs, elapsedSinceLastFeedMs);
}
}
......
......@@ -63,15 +63,15 @@ public interface AudioRendererEventListener {
void onAudioInputFormatChanged(Format format);
/**
* Called when an {@link AudioTrack} underrun occurs.
* Called when an {@link AudioSink} underrun occurs.
*
* @param bufferSize The size of the {@link AudioTrack}'s buffer, in bytes.
* @param bufferSizeMs The size of the {@link AudioTrack}'s buffer, in milliseconds, if it is
* @param bufferSize The size of the {@link AudioSink}'s buffer, in bytes.
* @param bufferSizeMs The size of the {@link AudioSink}'s buffer, in milliseconds, if it is
* configured for PCM output. {@link C#TIME_UNSET} if it is configured for passthrough output,
* as the buffered media can have a variable bitrate so the duration may be unknown.
* @param elapsedSinceLastFeedMs The time since the {@link AudioTrack} was last fed data.
* @param elapsedSinceLastFeedMs The time since the {@link AudioSink} was last fed data.
*/
void onAudioTrackUnderrun(int bufferSize, long bufferSizeMs, long elapsedSinceLastFeedMs);
void onAudioSinkUnderrun(int bufferSize, long bufferSizeMs, long elapsedSinceLastFeedMs);
/**
* Called when the renderer is disabled.
......@@ -144,7 +144,7 @@ public interface AudioRendererEventListener {
}
/**
* Invokes {@link AudioRendererEventListener#onAudioTrackUnderrun(int, long, long)}.
* Invokes {@link AudioRendererEventListener#onAudioSinkUnderrun(int, long, long)}.
*/
public void audioTrackUnderrun(final int bufferSize, final long bufferSizeMs,
final long elapsedSinceLastFeedMs) {
......@@ -152,7 +152,7 @@ public interface AudioRendererEventListener {
handler.post(new Runnable() {
@Override
public void run() {
listener.onAudioTrackUnderrun(bufferSize, bufferSizeMs, elapsedSinceLastFeedMs);
listener.onAudioSinkUnderrun(bufferSize, bufferSizeMs, elapsedSinceLastFeedMs);
}
});
}
......
......@@ -52,7 +52,7 @@ import java.util.Arrays;
* Resets the channel mapping. After calling this method, call {@link #configure(int, int, int)}
* to start using the new channel map.
*
* @see AudioTrack#configure(String, int, int, int, int, int[], int, int)
* @see AudioSink#configure(String, int, int, int, int, int[], int, int)
*/
public void setChannelMap(int[] outputChannels) {
pendingOutputChannels = outputChannels;
......
......@@ -55,7 +55,7 @@ import java.nio.ByteOrder;
*
* @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.
* @see AudioTrack#configure(String, int, int, int, int, int[], int, int)
* @see AudioSink#configure(String, int, int, int, int, int[], int, int)
*/
public void setTrimSampleCount(int trimStartSamples, int trimEndSamples) {
this.trimStartSamples = trimStartSamples;
......
......@@ -29,7 +29,7 @@ import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.RenderersFactory;
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.audio.AudioRendererEventListener;
import com.google.android.exoplayer2.audio.AudioTrack;
import com.google.android.exoplayer2.audio.DefaultAudioSink;
import com.google.android.exoplayer2.decoder.DecoderCounters;
import com.google.android.exoplayer2.drm.DrmSessionManager;
import com.google.android.exoplayer2.drm.FrameworkMediaCrypto;
......@@ -53,10 +53,10 @@ public abstract class ExoHostedTest extends Player.DefaultEventListener implemen
AudioRendererEventListener, VideoRendererEventListener {
static {
// ExoPlayer's AudioTrack class is able to work around spurious timestamps reported by the
// platform (by ignoring them). Disable this workaround, since we're interested in testing
// that the underlying platform is behaving correctly.
AudioTrack.failOnSpuriousAudioTimestamp = true;
// DefaultAudioSink is able to work around spurious timestamps reported by the platform (by
// ignoring them). Disable this workaround, since we're interested in testing that the
// underlying platform is behaving correctly.
DefaultAudioSink.failOnSpuriousAudioTimestamp = true;
}
public static final long MAX_PLAYING_TIME_DISCREPANCY_MS = 2000;
......@@ -253,7 +253,7 @@ public abstract class ExoHostedTest extends Player.DefaultEventListener implemen
}
@Override
public void onAudioTrackUnderrun(int bufferSize, long bufferSizeMs, long elapsedSinceLastFeedMs) {
public void onAudioSinkUnderrun(int bufferSize, long bufferSizeMs, long elapsedSinceLastFeedMs) {
Log.e(tag, "audioTrackUnderrun [" + bufferSize + ", " + bufferSizeMs + ", "
+ elapsedSinceLastFeedMs + "]", null);
}
......
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