Index: media/base/android/media_source_player.cc |
diff --git a/media/base/android/media_source_player.cc b/media/base/android/media_source_player.cc |
index e52d0e49fc2e651e0d6352b391a96432fc8cb6bc..fa1095f9a7f8f595703ca55eb15c0c61ea49d51d 100644 |
--- a/media/base/android/media_source_player.cc |
+++ b/media/base/android/media_source_player.cc |
@@ -316,9 +316,11 @@ void MediaSourcePlayer::OnDemuxerConfigsAvailable( |
is_audio_encrypted_ = configs.is_audio_encrypted; |
audio_extra_data_ = configs.audio_extra_data; |
if (HasAudio()) { |
- DCHECK_GT(num_channels_, 0); |
- audio_timestamp_helper_.reset(new AudioTimestampHelper(sampling_rate_)); |
- audio_timestamp_helper_->SetBaseTimestamp(GetCurrentTime()); |
+ if (reconfig_audio_decoder_ || !audio_decoder_job_) { |
+ DCHECK_GT(num_channels_, 0); |
+ audio_timestamp_helper_.reset(new AudioTimestampHelper(sampling_rate_)); |
+ audio_timestamp_helper_->SetBaseTimestamp(GetCurrentTime()); |
+ } |
} else { |
audio_timestamp_helper_.reset(); |
} |
@@ -471,16 +473,25 @@ void MediaSourcePlayer::OnDemuxerSeekDone( |
} |
void MediaSourcePlayer::UpdateTimestamps( |
- base::TimeDelta presentation_timestamp, size_t audio_output_bytes) { |
- base::TimeDelta new_max_time = presentation_timestamp; |
- |
+ base::TimeDelta presentation_timestamp, size_t audio_output_bytes, |
+ int64 audio_head_position, base::TimeTicks audio_render_time) { |
if (audio_output_bytes > 0) { |
audio_timestamp_helper_->AddFrames( |
audio_output_bytes / (kBytesPerAudioOutputSample * num_channels_)); |
- new_max_time = audio_timestamp_helper_->GetTimestamp(); |
+ int64 frames_to_play = |
+ audio_timestamp_helper_->frame_count() - audio_head_position; |
+ DCHECK(frames_to_play >= 0); |
wolenetz
2014/04/01 18:15:47
nit: lint: "Consider using DCHECK_GE instead of DC
qinmin
2014/04/01 20:42:34
Done.
|
+ base::TimeDelta new_max_time = audio_timestamp_helper_->GetTimestamp(); |
+ base::TimeDelta current_presentation_timestamp = |
+ base::TimeTicks::Now() - audio_render_time + new_max_time - |
+ audio_timestamp_helper_->GetFrameDuration(frames_to_play); |
+ if (current_presentation_timestamp >= new_max_time) |
+ current_presentation_timestamp = new_max_time; |
+ clock_.SetTime(current_presentation_timestamp, new_max_time); |
+ } else { |
+ clock_.SetMaxTime(presentation_timestamp); |
} |
- clock_.SetMaxTime(new_max_time); |
manager()->OnTimeUpdate(player_id(), GetCurrentTime()); |
} |
@@ -581,7 +592,8 @@ void MediaSourcePlayer::ProcessPendingEvents() { |
void MediaSourcePlayer::MediaDecoderCallback( |
bool is_audio, MediaCodecStatus status, |
- base::TimeDelta presentation_timestamp, size_t audio_output_bytes) { |
+ base::TimeDelta presentation_timestamp, size_t audio_output_bytes, |
+ int64 audio_head_position, base::TimeTicks audio_render_time) { |
DVLOG(1) << __FUNCTION__ << ": " << is_audio << ", " << status; |
// TODO(xhwang): Drop IntToString() when http://crbug.com/303899 is fixed. |
@@ -625,6 +637,13 @@ void MediaSourcePlayer::MediaDecoderCallback( |
return; |
} |
+ if (status == MEDIA_CODEC_OK && is_clock_manager && |
+ presentation_timestamp != kNoTimestamp()) { |
+ UpdateTimestamps( |
+ presentation_timestamp, audio_output_bytes, audio_head_position, |
+ audio_render_time); |
+ } |
+ |
if (status == MEDIA_CODEC_OUTPUT_END_OF_STREAM) |
PlaybackCompleted(is_audio); |
@@ -636,11 +655,6 @@ void MediaSourcePlayer::MediaDecoderCallback( |
if (status == MEDIA_CODEC_OUTPUT_END_OF_STREAM) |
return; |
- if (status == MEDIA_CODEC_OK && is_clock_manager && |
- presentation_timestamp != kNoTimestamp()) { |
- UpdateTimestamps(presentation_timestamp, audio_output_bytes); |
- } |
- |
if (!playing_) { |
if (is_clock_manager) |
clock_.Pause(); |