Index: media/base/android/java/src/org/chromium/media/MediaCodecBridge.java |
diff --git a/media/base/android/java/src/org/chromium/media/MediaCodecBridge.java b/media/base/android/java/src/org/chromium/media/MediaCodecBridge.java |
index c229df48aa5dbc833e3fc2a11f91dd8c9ac56c66..831414e70b7a0ac6048b7ddd8919d5c069248212 100644 |
--- a/media/base/android/java/src/org/chromium/media/MediaCodecBridge.java |
+++ b/media/base/android/java/src/org/chromium/media/MediaCodecBridge.java |
@@ -77,7 +77,6 @@ class MediaCodecBridge { |
private long mLastPresentationTimeUs; |
private String mMime; |
private boolean mAdaptivePlaybackSupported; |
- private int mSampleRate; |
private static class DequeueInputResult { |
private final int mStatus; |
@@ -449,6 +448,12 @@ class MediaCodecBridge { |
} |
@CalledByNative |
+ private int getOutputSamplingRate() { |
+ MediaFormat format = mMediaCodec.getOutputFormat(); |
+ return format.getInteger(MediaFormat.KEY_SAMPLE_RATE); |
+ } |
+ |
+ @CalledByNative |
private ByteBuffer getInputBuffer(int index) { |
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) { |
return mMediaCodec.getInputBuffer(index); |
@@ -566,13 +571,6 @@ class MediaCodecBridge { |
status = MEDIA_CODEC_OUTPUT_BUFFERS_CHANGED; |
} else if (indexOrStatus == MediaCodec.INFO_OUTPUT_FORMAT_CHANGED) { |
status = MEDIA_CODEC_OUTPUT_FORMAT_CHANGED; |
- MediaFormat newFormat = mMediaCodec.getOutputFormat(); |
- if (mAudioTrack != null && newFormat.containsKey(MediaFormat.KEY_SAMPLE_RATE)) { |
- int newSampleRate = newFormat.getInteger(MediaFormat.KEY_SAMPLE_RATE); |
- if (newSampleRate != mSampleRate && !reconfigureAudioTrack(newFormat)) { |
- status = MEDIA_CODEC_ERROR; |
- } |
- } |
} else if (indexOrStatus == MediaCodec.INFO_TRY_AGAIN_LATER) { |
status = MEDIA_CODEC_DEQUEUE_OUTPUT_AGAIN_LATER; |
} else { |
@@ -672,7 +670,7 @@ class MediaCodecBridge { |
boolean playAudio) { |
try { |
mMediaCodec.configure(format, null, crypto, flags); |
- if (playAudio && !reconfigureAudioTrack(format)) { |
+ if (playAudio && !createNewAudioTrack(format)) { |
return false; |
} |
return true; |
@@ -682,6 +680,11 @@ class MediaCodecBridge { |
return false; |
} |
+ @CalledByNative |
+ private boolean reconfigureAudioTrack() { |
+ return createNewAudioTrack(mMediaCodec.getOutputFormat()); |
+ } |
+ |
/** |
* Resets the AudioTrack instance, configured according to the given format. |
* If a previous AudioTrack instance already exists, release it. |
@@ -689,19 +692,19 @@ class MediaCodecBridge { |
* @param format The format from which to get sample rate and channel count. |
* @return Whether or not creating the AudioTrack succeeded. |
*/ |
- private boolean reconfigureAudioTrack(MediaFormat format) { |
+ private boolean createNewAudioTrack(MediaFormat format) { |
if (mAudioTrack != null) { |
mAudioTrack.release(); |
} |
- mSampleRate = format.getInteger(MediaFormat.KEY_SAMPLE_RATE); |
+ int sampleRate = format.getInteger(MediaFormat.KEY_SAMPLE_RATE); |
int channelCount = format.getInteger(MediaFormat.KEY_CHANNEL_COUNT); |
int channelConfig = getAudioFormat(channelCount); |
// Using 16bit PCM for output. Keep this value in sync with |
// kBytesPerAudioOutputSample in media_codec_bridge.cc. |
- int minBufferSize = AudioTrack.getMinBufferSize(mSampleRate, channelConfig, |
+ int minBufferSize = AudioTrack.getMinBufferSize(sampleRate, channelConfig, |
AudioFormat.ENCODING_PCM_16BIT); |
- mAudioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, mSampleRate, channelConfig, |
+ mAudioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, sampleRate, channelConfig, |
AudioFormat.ENCODING_PCM_16BIT, minBufferSize, AudioTrack.MODE_STREAM); |
if (mAudioTrack.getState() == AudioTrack.STATE_UNINITIALIZED) { |
mAudioTrack = null; |