Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(436)

Unified Diff: media/base/android/java/src/org/chromium/media/MediaCodecBridge.java

Issue 1254293003: MediaCodecPlayer implementation (stage 4 - preroll) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mtplayer-browserseek
Patch Set: Rebased Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 0433a471ab7761edb371034623150fee010660fd..c9ae5ce9fcf30e13e5e9018f0521f42cee651289 100644
--- a/media/base/android/java/src/org/chromium/media/MediaCodecBridge.java
+++ b/media/base/android/java/src/org/chromium/media/MediaCodecBridge.java
@@ -74,6 +74,7 @@ class MediaCodecBridge {
private MediaCodec mMediaCodec;
private AudioTrack mAudioTrack;
+ private byte[] mPendingAudioBuffer;
private boolean mFlushed;
private long mLastPresentationTimeUs;
private String mMime;
@@ -302,6 +303,7 @@ class MediaCodecBridge {
MediaCodec mediaCodec, String mime, boolean adaptivePlaybackSupported) {
assert mediaCodec != null;
mMediaCodec = mediaCodec;
+ mPendingAudioBuffer = null;
mMime = mime;
mLastPresentationTimeUs = 0;
mFlushed = true;
@@ -366,6 +368,7 @@ class MediaCodecBridge {
if (mAudioTrack != null) {
mAudioTrack.release();
}
+ mPendingAudioBuffer = null;
}
@SuppressWarnings("deprecation")
@@ -413,6 +416,7 @@ class MediaCodecBridge {
// Need to call pause() here, or otherwise flush() is a no-op.
mAudioTrack.pause();
mAudioTrack.flush();
+ mPendingAudioBuffer = null;
}
mMediaCodec.flush();
} catch (IllegalStateException e) {
@@ -726,7 +730,14 @@ class MediaCodecBridge {
* hardware. This number resets to 0 after each flush call.
*/
@CalledByNative
- private long playOutputBuffer(byte[] buf) {
+ private long playOutputBuffer(byte[] buf, boolean postpone) {
+ if (postpone) {
+ Log.v(TAG, "Saving pending buffer");
wolenetz 2015/08/20 20:37:36 nit: Is Log.v too spammy/verbose? I defer to qinmi
Tima Vaisburd 2015/08/20 22:36:36 I agree, deleted the two Log.v() lines.
+ assert mPendingAudioBuffer == null;
wolenetz 2015/08/20 20:37:36 What protects (including any bridge java or .h met
Tima Vaisburd 2015/08/20 22:36:36 I added the documentation. Only the convention tha
+ mPendingAudioBuffer = buf;
+ return 0;
+ }
+
if (mAudioTrack == null) {
wolenetz 2015/08/20 20:37:36 Is there really a case where we should allow cachi
Tima Vaisburd 2015/08/20 22:36:36 Done. I agree that mAudioTrack check is better be
return 0;
}
@@ -734,7 +745,19 @@ class MediaCodecBridge {
if (AudioTrack.PLAYSTATE_PLAYING != mAudioTrack.getPlayState()) {
mAudioTrack.play();
}
- int size = mAudioTrack.write(buf, 0, buf.length);
+
+ int size = 0;
+ if (mPendingAudioBuffer != null) {
+ Log.v(TAG, "Writing pending buffer");
+ size = mAudioTrack.write(mPendingAudioBuffer, 0, mPendingAudioBuffer.length);
+ if (mPendingAudioBuffer.length != size) {
+ Log.i(TAG, "Failed to send all data to audio output, expected size: "
+ + mPendingAudioBuffer.length + ", actual size: " + size);
+ }
+ mPendingAudioBuffer = null;
+ }
+
+ size = mAudioTrack.write(buf, 0, buf.length);
if (buf.length != size) {
Log.i(TAG, "Failed to send all data to audio output, expected size: "
+ buf.length + ", actual size: " + size);
« no previous file with comments | « no previous file | media/base/android/media_codec_audio_decoder.h » ('j') | media/base/android/media_codec_audio_decoder.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698