Commit e284d616 by olly Committed by Oliver Woodman

Remove AudioTrack API level 16 dependency.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=121685491
parent 523f2662
...@@ -237,7 +237,13 @@ public class MediaCodecAudioTrackRenderer extends MediaCodecTrackRenderer implem ...@@ -237,7 +237,13 @@ public class MediaCodecAudioTrackRenderer extends MediaCodecTrackRenderer implem
@Override @Override
protected void onOutputFormatChanged(MediaCodec codec, MediaFormat outputFormat) { protected void onOutputFormatChanged(MediaCodec codec, MediaFormat outputFormat) {
boolean passthrough = passthroughMediaFormat != null; boolean passthrough = passthroughMediaFormat != null;
audioTrack.configure(passthrough ? passthroughMediaFormat : outputFormat, passthrough); String mimeType = passthrough
? passthroughMediaFormat.getString(android.media.MediaFormat.KEY_MIME)
: MimeTypes.AUDIO_RAW;
android.media.MediaFormat format = passthrough ? passthroughMediaFormat : outputFormat;
int channelCount = format.getInteger(android.media.MediaFormat.KEY_CHANNEL_COUNT);
int sampleRate = format.getInteger(android.media.MediaFormat.KEY_SAMPLE_RATE);
audioTrack.configure(mimeType, channelCount, sampleRate);
} }
/** /**
......
...@@ -26,7 +26,6 @@ import android.annotation.TargetApi; ...@@ -26,7 +26,6 @@ import android.annotation.TargetApi;
import android.media.AudioFormat; import android.media.AudioFormat;
import android.media.AudioManager; import android.media.AudioManager;
import android.media.AudioTimestamp; import android.media.AudioTimestamp;
import android.media.MediaFormat;
import android.media.PlaybackParams; import android.media.PlaybackParams;
import android.os.ConditionVariable; import android.os.ConditionVariable;
import android.os.SystemClock; import android.os.SystemClock;
...@@ -57,7 +56,6 @@ import java.nio.ByteBuffer; ...@@ -57,7 +56,6 @@ import java.nio.ByteBuffer;
* <p> * <p>
* Call {@link #release()} when the instance will no longer be used. * Call {@link #release()} when the instance will no longer be used.
*/ */
@TargetApi(16)
public final class AudioTrack { public final class AudioTrack {
/** /**
...@@ -333,26 +331,27 @@ public final class AudioTrack { ...@@ -333,26 +331,27 @@ public final class AudioTrack {
} }
/** /**
* Configures (or reconfigures) the audio track to play back media in {@code format}, inferring a * Configures (or reconfigures) the audio track, inferring a suitable buffer size automatically.
* buffer size from the format.
* *
* @param format Specifies the channel count and sample rate to play back. * @param mimeType The mime type.
* @param passthrough Whether to play back using a passthrough encoding. * @param channelCount The number of channels.
* @param sampleRate The sample rate in Hz.
*/ */
public void configure(MediaFormat format, boolean passthrough) { public void configure(String mimeType, int channelCount, int sampleRate) {
configure(format, passthrough, 0); configure(mimeType, channelCount, sampleRate, 0);
} }
/** /**
* Configures (or reconfigures) the audio track to play back media in {@code format}. * Configures (or reconfigures) the audio track.
* *
* @param format Specifies the channel count and sample rate to play back. * @param mimeType The mime type.
* @param passthrough Whether to play back using a passthrough encoding. * @param channelCount The number of channels.
* @param specifiedBufferSize A specific size for the playback buffer in bytes, or 0 to use a * @param sampleRate The sample rate in Hz.
* size inferred from the format. * @param specifiedBufferSize A specific size for the playback buffer in bytes, or 0 to infer a
* suitable buffer size automatically.
*/ */
public void configure(MediaFormat format, boolean passthrough, int specifiedBufferSize) { public void configure(String mimeType, int channelCount, int sampleRate,
int channelCount = format.getInteger(MediaFormat.KEY_CHANNEL_COUNT); int specifiedBufferSize) {
int channelConfig; int channelConfig;
switch (channelCount) { switch (channelCount) {
case 1: case 1:
...@@ -382,8 +381,7 @@ public final class AudioTrack { ...@@ -382,8 +381,7 @@ public final class AudioTrack {
default: default:
throw new IllegalArgumentException("Unsupported channel count: " + channelCount); throw new IllegalArgumentException("Unsupported channel count: " + channelCount);
} }
int sampleRate = format.getInteger(MediaFormat.KEY_SAMPLE_RATE); boolean passthrough = !MimeTypes.AUDIO_RAW.equals(mimeType);
String mimeType = format.getString(MediaFormat.KEY_MIME);
int encoding = passthrough ? getEncodingForMimeType(mimeType) : AudioFormat.ENCODING_PCM_16BIT; int encoding = passthrough ? getEncodingForMimeType(mimeType) : AudioFormat.ENCODING_PCM_16BIT;
if (isInitialized() && this.sampleRate == sampleRate && this.channelConfig == channelConfig if (isInitialized() && this.sampleRate == sampleRate && this.channelConfig == channelConfig
&& this.encoding == encoding) { && this.encoding == encoding) {
...@@ -543,7 +541,7 @@ public final class AudioTrack { ...@@ -543,7 +541,7 @@ public final class AudioTrack {
* <p> * <p>
* If the data was not written in full then the same {@link ByteBuffer} must be provided to * If the data was not written in full then the same {@link ByteBuffer} must be provided to
* subsequent calls until it has been fully consumed, except in the case of an interleaving call * subsequent calls until it has been fully consumed, except in the case of an interleaving call
* to {@link #configure(MediaFormat, boolean)} or {@link #reset}. * to {@link #configure} or {@link #reset}.
* *
* @param buffer The buffer containing audio data to play back. * @param buffer The buffer containing audio data to play back.
* @param presentationTimeUs Presentation timestamp of the next buffer in microseconds. * @param presentationTimeUs Presentation timestamp of the next buffer in microseconds.
......
...@@ -27,6 +27,7 @@ import com.google.android.exoplayer.MediaClock; ...@@ -27,6 +27,7 @@ import com.google.android.exoplayer.MediaClock;
import com.google.android.exoplayer.TrackRenderer; import com.google.android.exoplayer.TrackRenderer;
import com.google.android.exoplayer.TrackStream; import com.google.android.exoplayer.TrackStream;
import com.google.android.exoplayer.audio.AudioTrack; import com.google.android.exoplayer.audio.AudioTrack;
import com.google.android.exoplayer.util.MimeTypes;
import android.os.Handler; import android.os.Handler;
...@@ -291,7 +292,7 @@ public abstract class AudioDecoderTrackRenderer extends TrackRenderer implements ...@@ -291,7 +292,7 @@ public abstract class AudioDecoderTrackRenderer extends TrackRenderer implements
int result = readSource(formatHolder, null); int result = readSource(formatHolder, null);
if (result == TrackStream.FORMAT_READ) { if (result == TrackStream.FORMAT_READ) {
format = formatHolder.format; format = formatHolder.format;
audioTrack.configure(format.getFrameworkMediaFormatV16(), false); audioTrack.configure(MimeTypes.AUDIO_RAW, format.channelCount, format.sampleRate);
return true; return true;
} }
return false; return false;
......
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