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

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
« no previous file with comments | « media/base/android/audio_decoder_job.cc ('k') | media/base/android/media_codec_bridge.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 cfcebb01517423c635dea67f66eba8df300905ae..5eb7b5bcc6dd59904a80fe2fc432476d8b31c872 100644
--- a/media/base/android/java/src/org/chromium/media/MediaCodecBridge.java
+++ b/media/base/android/java/src/org/chromium/media/MediaCodecBridge.java
@@ -285,6 +285,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();
@@ -525,18 +527,36 @@ 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) {
- if (mAudioTrack != null) {
- if (AudioTrack.PLAYSTATE_PLAYING != mAudioTrack.getPlayState()) {
- mAudioTrack.play();
- }
- int 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);
- }
+ private long playOutputBuffer(byte[] buf) {
+ if (mAudioTrack == null) {
+ return 0;
+ }
+
+ if (AudioTrack.PLAYSTATE_PLAYING != mAudioTrack.getPlayState()) {
+ mAudioTrack.play();
+ }
+ int 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);
}
+ // 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();
}
@CalledByNative
« no previous file with comments | « media/base/android/audio_decoder_job.cc ('k') | media/base/android/media_codec_bridge.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698