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

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 comments Created 6 years, 9 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..cbfccfd2f80d1b099afa442e62b4d69ab2df9045 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();
@@ -521,7 +523,7 @@ class MediaCodecBridge {
}
@CalledByNative
- private void playOutputBuffer(byte[] buf) {
+ private long playOutputBuffer(byte[] buf) {
wolenetz 2014/04/03 18:14:40 nit: I'm less familiar with Chromium java coding s
qinmin 2014/04/03 21:59:45 Done. Java doc added. On 2014/04/03 18:14:40, wol
if (mAudioTrack != null) {
if (AudioTrack.PLAYSTATE_PLAYING != mAudioTrack.getPlayState()) {
mAudioTrack.play();
@@ -531,7 +533,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 crbug.com/358801.
wolenetz 2014/04/03 18:14:40 nit: s/crbug.com/http:\/\/crbug.com/
qinmin 2014/04/03 21:59:45 Done.
+ return mAudioTrack.getPlaybackHeadPosition();
}
+ return 0;
wolenetz 2014/04/03 18:14:40 Might we ever call this method when |mAudioTrack|
qinmin 2014/04/03 21:59:45 This should never happen in our code. The if state
}
@CalledByNative

Powered by Google App Engine
This is Rietveld 408576698