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

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

Issue 215783002: Fix an issue that audio and video may run out of sync (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressing acolwell's comments Created 6 years, 8 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 3f1506113848f1cecd9dd045f6def102e8b2d946..f7f2b5223ddd39bdcbcfcfe380f49f533fbe8b33 100644
--- a/media/base/android/java/src/org/chromium/media/MediaCodecBridge.java
+++ b/media/base/android/java/src/org/chromium/media/MediaCodecBridge.java
@@ -280,6 +280,8 @@ class MediaCodecBridge {
try {
mFlushed = true;
if (mAudioTrack != null) {
+ // Need to call pause() here, or otherwise flush() is a no-op.
+ mAudioTrack.pause();
mAudioTrack.flush();
}
mMediaCodec.flush();
@@ -520,8 +522,15 @@ class MediaCodecBridge {
return false;
}
+ /**
+ * Play the audio buffer that is passed in.
+ *
+ * @param buf Audio buffer to be rendered.
+ * @return The number of frames that have already been consumed by the
+ * hardware. This number resets to 0 after each flush call.
+ */
@CalledByNative
- private void playOutputBuffer(byte[] buf) {
+ private long playOutputBuffer(byte[] buf) {
if (mAudioTrack != null) {
acolwell GONE FROM CHROMIUM 2014/04/14 16:00:47 nit: reverse condition and return early?
qinmin 2014/04/14 19:01:58 Done.
if (AudioTrack.PLAYSTATE_PLAYING != mAudioTrack.getPlayState()) {
mAudioTrack.play();
@@ -531,7 +540,17 @@ class MediaCodecBridge {
Log.i(TAG, "Failed to send all data to audio output, expected size: " +
buf.length + ", actual size: " + size);
}
+ // TODO(qinmin): Returning the head position allows us to estimate
+ // the current presentation time in native code. However, it is
+ // better to use AudioTrack.getCurrentTimestamp() to get the last
+ // known time when a frame is played. However, we will need to
+ // convert the java nano time to C++ timestamp.
+ // If the stream runs too long, getPlaybackHeadPosition() could
+ // overflow. AudioTimestampHelper in MediaSourcePlayer has the same
+ // issue. See http://crbug.com/358801.
+ return mAudioTrack.getPlaybackHeadPosition();
}
+ return 0;
}
@CalledByNative

Powered by Google App Engine
This is Rietveld 408576698