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; ...@@ -248,7 +248,7 @@ import java.util.Locale;
} }
@Override @Override
public void onAudioTrackUnderrun(int bufferSize, long bufferSizeMs, long elapsedSinceLastFeedMs) { public void onAudioSinkUnderrun(int bufferSize, long bufferSizeMs, long elapsedSinceLastFeedMs) {
printInternalError("audioTrackUnderrun [" + bufferSize + ", " + bufferSizeMs + ", " printInternalError("audioTrackUnderrun [" + bufferSize + ", " + bufferSizeMs + ", "
+ elapsedSinceLastFeedMs + "]", null); + elapsedSinceLastFeedMs + "]", null);
} }
......
...@@ -976,10 +976,10 @@ public class SimpleExoPlayer implements ExoPlayer { ...@@ -976,10 +976,10 @@ public class SimpleExoPlayer implements ExoPlayer {
} }
@Override @Override
public void onAudioTrackUnderrun(int bufferSize, long bufferSizeMs, public void onAudioSinkUnderrun(int bufferSize, long bufferSizeMs,
long elapsedSinceLastFeedMs) { long elapsedSinceLastFeedMs) {
if (audioDebugListener != null) { if (audioDebugListener != null) {
audioDebugListener.onAudioTrackUnderrun(bufferSize, bufferSizeMs, elapsedSinceLastFeedMs); audioDebugListener.onAudioSinkUnderrun(bufferSize, bufferSizeMs, elapsedSinceLastFeedMs);
} }
} }
......
...@@ -63,15 +63,15 @@ public interface AudioRendererEventListener { ...@@ -63,15 +63,15 @@ public interface AudioRendererEventListener {
void onAudioInputFormatChanged(Format format); 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 bufferSize The size of the {@link AudioSink}'s buffer, in bytes.
* @param bufferSizeMs The size of the {@link AudioTrack}'s buffer, in milliseconds, if it is * @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, * 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. * 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. * Called when the renderer is disabled.
...@@ -144,7 +144,7 @@ public interface AudioRendererEventListener { ...@@ -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, public void audioTrackUnderrun(final int bufferSize, final long bufferSizeMs,
final long elapsedSinceLastFeedMs) { final long elapsedSinceLastFeedMs) {
...@@ -152,7 +152,7 @@ public interface AudioRendererEventListener { ...@@ -152,7 +152,7 @@ public interface AudioRendererEventListener {
handler.post(new Runnable() { handler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
listener.onAudioTrackUnderrun(bufferSize, bufferSizeMs, elapsedSinceLastFeedMs); listener.onAudioSinkUnderrun(bufferSize, bufferSizeMs, elapsedSinceLastFeedMs);
} }
}); });
} }
......
...@@ -52,7 +52,7 @@ import java.util.Arrays; ...@@ -52,7 +52,7 @@ import java.util.Arrays;
* Resets the channel mapping. After calling this method, call {@link #configure(int, int, int)} * Resets the channel mapping. After calling this method, call {@link #configure(int, int, int)}
* to start using the new channel map. * 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) { public void setChannelMap(int[] outputChannels) {
pendingOutputChannels = outputChannels; pendingOutputChannels = outputChannels;
......
...@@ -55,7 +55,7 @@ import java.nio.ByteOrder; ...@@ -55,7 +55,7 @@ import java.nio.ByteOrder;
* *
* @param trimStartSamples The number of audio samples to trim from the start of audio. * @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 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) { public void setTrimSampleCount(int trimStartSamples, int trimEndSamples) {
this.trimStartSamples = trimStartSamples; this.trimStartSamples = trimStartSamples;
......
...@@ -29,7 +29,7 @@ import com.google.android.exoplayer2.Player; ...@@ -29,7 +29,7 @@ import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.RenderersFactory; import com.google.android.exoplayer2.RenderersFactory;
import com.google.android.exoplayer2.SimpleExoPlayer; import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.audio.AudioRendererEventListener; 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.decoder.DecoderCounters;
import com.google.android.exoplayer2.drm.DrmSessionManager; import com.google.android.exoplayer2.drm.DrmSessionManager;
import com.google.android.exoplayer2.drm.FrameworkMediaCrypto; import com.google.android.exoplayer2.drm.FrameworkMediaCrypto;
...@@ -53,10 +53,10 @@ public abstract class ExoHostedTest extends Player.DefaultEventListener implemen ...@@ -53,10 +53,10 @@ public abstract class ExoHostedTest extends Player.DefaultEventListener implemen
AudioRendererEventListener, VideoRendererEventListener { AudioRendererEventListener, VideoRendererEventListener {
static { static {
// ExoPlayer's AudioTrack class is able to work around spurious timestamps reported by the // DefaultAudioSink is able to work around spurious timestamps reported by the platform (by
// platform (by ignoring them). Disable this workaround, since we're interested in testing // ignoring them). Disable this workaround, since we're interested in testing that the
// that the underlying platform is behaving correctly. // underlying platform is behaving correctly.
AudioTrack.failOnSpuriousAudioTimestamp = true; DefaultAudioSink.failOnSpuriousAudioTimestamp = true;
} }
public static final long MAX_PLAYING_TIME_DISCREPANCY_MS = 2000; public static final long MAX_PLAYING_TIME_DISCREPANCY_MS = 2000;
...@@ -253,7 +253,7 @@ public abstract class ExoHostedTest extends Player.DefaultEventListener implemen ...@@ -253,7 +253,7 @@ public abstract class ExoHostedTest extends Player.DefaultEventListener implemen
} }
@Override @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 + ", " Log.e(tag, "audioTrackUnderrun [" + bufferSize + ", " + bufferSizeMs + ", "
+ elapsedSinceLastFeedMs + "]", null); + 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