Chromium Code Reviews| Index: media/base/android/media_codec_audio_decoder.cc |
| diff --git a/media/base/android/media_codec_audio_decoder.cc b/media/base/android/media_codec_audio_decoder.cc |
| index 88bdeb5de2ea122a8aeedb6e12634a2b4f18a0a3..19de52ca5192e5903f513bea02efde797ffc4522 100644 |
| --- a/media/base/android/media_codec_audio_decoder.cc |
| +++ b/media/base/android/media_codec_audio_decoder.cc |
| @@ -7,6 +7,7 @@ |
| #include "base/bind.h" |
| #include "base/logging.h" |
| #include "media/base/android/media_codec_bridge.h" |
| +#include "media/base/android/media_statistics.h" |
| #include "media/base/audio_timestamp_helper.h" |
| #include "media/base/demuxer_stream.h" |
| @@ -27,7 +28,8 @@ MediaCodecAudioDecoder::MediaCodecAudioDecoder( |
| const base::Closure& stop_done_cb, |
| const base::Closure& key_required_cb, |
| const base::Closure& error_cb, |
| - const SetTimeCallback& update_current_time_cb) |
| + const SetTimeCallback& update_current_time_cb, |
| + FrameStatistics* frame_statistics) |
| : MediaCodecDecoder(media_task_runner, |
| request_data_cb, |
| starvation_cb, |
| @@ -35,7 +37,8 @@ MediaCodecAudioDecoder::MediaCodecAudioDecoder( |
| stop_done_cb, |
| key_required_cb, |
| error_cb, |
| - "AudioDecoder"), |
| + "AudioDecoder", |
| + frame_statistics), |
| volume_(-1.0), |
| bytes_per_frame_(0), |
| output_sampling_rate_(0), |
| @@ -205,6 +208,11 @@ void MediaCodecAudioDecoder::Render(int buffer_index, |
| int64 head_position = |
| audio_codec->PlayOutputBuffer(buffer_index, size, offset, postpone); |
| + base::TimeTicks current_time = base::TimeTicks::Now(); |
| + |
| + if (frame_statistics_) |
| + frame_statistics_->AddFrame(); |
|
xhwang
2015/09/30 21:02:57
When can frame_statistics_ be null? Is it only in
Tima Vaisburd
2015/10/01 20:05:15
Done.
|
| + |
| // Reset the base timestamp if we have not started playing. |
| // SetBaseTimestamp() must be called before AddFrames() since it resets the |
| // internal frame count. |
| @@ -238,6 +246,13 @@ void MediaCodecAudioDecoder::Render(int buffer_index, |
| DVLOG(2) << class_name() << "::" << __FUNCTION__ << " pts:" << pts |
| << " will play: [" << now_playing << "," << last_buffered << "]"; |
| + // Statistics |
| + if (frame_statistics_ && !next_frame_time_limit_.is_null() && |
| + next_frame_time_limit_ < current_time) |
| + frame_statistics_->AddLateFrame(current_time - next_frame_time_limit_); |
| + |
| + next_frame_time_limit_ = current_time + (last_buffered - now_playing); |
| + |
| media_task_runner_->PostTask( |
| FROM_HERE, base::Bind(update_current_time_cb_, now_playing, |
| last_buffered, false)); |
| @@ -246,7 +261,10 @@ void MediaCodecAudioDecoder::Render(int buffer_index, |
| media_codec_bridge_->ReleaseOutputBuffer(buffer_index, false); |
| - CheckLastFrame(eos_encountered, false); // no delayed tasks |
| + if (CheckLastFrame(eos_encountered, false)) { // no delayed tasks |
| + // This is the last frame |
| + next_frame_time_limit_ = base::TimeTicks(); |
| + } |
| } |
| void MediaCodecAudioDecoder::SetVolumeInternal() { |