OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "media/base/android/media_codec_audio_decoder.h" | 5 #include "media/base/android/media_codec_audio_decoder.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "media/base/android/media_codec_bridge.h" | 9 #include "media/base/android/media_codec_bridge.h" |
10 #include "media/base/android/media_statistics.h" | |
10 #include "media/base/audio_timestamp_helper.h" | 11 #include "media/base/audio_timestamp_helper.h" |
11 #include "media/base/demuxer_stream.h" | 12 #include "media/base/demuxer_stream.h" |
12 | 13 |
13 namespace { | 14 namespace { |
14 | 15 |
15 // Use 16bit PCM for audio output. Keep this value in sync with the output | 16 // Use 16bit PCM for audio output. Keep this value in sync with the output |
16 // format we passed to AudioTrack in MediaCodecBridge. | 17 // format we passed to AudioTrack in MediaCodecBridge. |
17 const int kBytesPerAudioOutputSample = 2; | 18 const int kBytesPerAudioOutputSample = 2; |
18 } | 19 } |
19 | 20 |
20 namespace media { | 21 namespace media { |
21 | 22 |
22 MediaCodecAudioDecoder::MediaCodecAudioDecoder( | 23 MediaCodecAudioDecoder::MediaCodecAudioDecoder( |
23 const scoped_refptr<base::SingleThreadTaskRunner>& media_task_runner, | 24 const scoped_refptr<base::SingleThreadTaskRunner>& media_task_runner, |
25 FrameStatistics* frame_statistics, | |
24 const base::Closure& request_data_cb, | 26 const base::Closure& request_data_cb, |
25 const base::Closure& starvation_cb, | 27 const base::Closure& starvation_cb, |
26 const base::Closure& decoder_drained_cb, | 28 const base::Closure& decoder_drained_cb, |
27 const base::Closure& stop_done_cb, | 29 const base::Closure& stop_done_cb, |
28 const base::Closure& waiting_for_decryption_key_cb, | 30 const base::Closure& waiting_for_decryption_key_cb, |
29 const base::Closure& error_cb, | 31 const base::Closure& error_cb, |
30 const SetTimeCallback& update_current_time_cb) | 32 const SetTimeCallback& update_current_time_cb) |
31 : MediaCodecDecoder(media_task_runner, | 33 : MediaCodecDecoder("AudioDecoder", |
34 media_task_runner, | |
35 frame_statistics, | |
32 request_data_cb, | 36 request_data_cb, |
33 starvation_cb, | 37 starvation_cb, |
34 decoder_drained_cb, | 38 decoder_drained_cb, |
35 stop_done_cb, | 39 stop_done_cb, |
36 waiting_for_decryption_key_cb, | 40 waiting_for_decryption_key_cb, |
37 error_cb, | 41 error_cb), |
38 "AudioDecoder"), | |
39 volume_(-1.0), | 42 volume_(-1.0), |
40 bytes_per_frame_(0), | 43 bytes_per_frame_(0), |
41 output_sampling_rate_(0), | 44 output_sampling_rate_(0), |
42 frame_count_(0), | 45 frame_count_(0), |
43 update_current_time_cb_(update_current_time_cb) { | 46 update_current_time_cb_(update_current_time_cb) { |
44 } | 47 } |
45 | 48 |
46 MediaCodecAudioDecoder::~MediaCodecAudioDecoder() { | 49 MediaCodecAudioDecoder::~MediaCodecAudioDecoder() { |
47 DCHECK(media_task_runner_->BelongsToCurrentThread()); | 50 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
48 DVLOG(1) << "AudioDecoder::~AudioDecoder()"; | 51 DVLOG(1) << "AudioDecoder::~AudioDecoder()"; |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
200 AudioCodecBridge* audio_codec = | 203 AudioCodecBridge* audio_codec = |
201 static_cast<AudioCodecBridge*>(media_codec_bridge_.get()); | 204 static_cast<AudioCodecBridge*>(media_codec_bridge_.get()); |
202 | 205 |
203 DCHECK(audio_codec); | 206 DCHECK(audio_codec); |
204 | 207 |
205 const bool postpone = (render_mode == kRenderAfterPreroll); | 208 const bool postpone = (render_mode == kRenderAfterPreroll); |
206 | 209 |
207 int64 head_position = | 210 int64 head_position = |
208 audio_codec->PlayOutputBuffer(buffer_index, size, offset, postpone); | 211 audio_codec->PlayOutputBuffer(buffer_index, size, offset, postpone); |
209 | 212 |
213 base::TimeTicks current_time = base::TimeTicks::Now(); | |
214 | |
215 DCHECK(frame_statistics_); | |
xhwang
2015/10/01 21:58:57
ditto
Tima Vaisburd
2015/10/02 00:44:32
Done.
| |
216 frame_statistics_->AddFrame(); | |
217 | |
210 // Reset the base timestamp if we have not started playing. | 218 // Reset the base timestamp if we have not started playing. |
211 // SetBaseTimestamp() must be called before AddFrames() since it resets the | 219 // SetBaseTimestamp() must be called before AddFrames() since it resets the |
212 // internal frame count. | 220 // internal frame count. |
213 if (postpone && !frame_count_) | 221 if (postpone && !frame_count_) |
214 SetBaseTimestamp(pts); | 222 SetBaseTimestamp(pts); |
215 | 223 |
216 size_t new_frames_count = size / bytes_per_frame_; | 224 size_t new_frames_count = size / bytes_per_frame_; |
217 frame_count_ += new_frames_count; | 225 frame_count_ += new_frames_count; |
218 audio_timestamp_helper_->AddFrames(new_frames_count); | 226 audio_timestamp_helper_->AddFrames(new_frames_count); |
219 | 227 |
(...skipping 13 matching lines...) Expand all Loading... | |
233 << " head_position:" << head_position; | 241 << " head_position:" << head_position; |
234 | 242 |
235 base::TimeDelta last_buffered = audio_timestamp_helper_->GetTimestamp(); | 243 base::TimeDelta last_buffered = audio_timestamp_helper_->GetTimestamp(); |
236 base::TimeDelta now_playing = | 244 base::TimeDelta now_playing = |
237 last_buffered - | 245 last_buffered - |
238 audio_timestamp_helper_->GetFrameDuration(frames_to_play); | 246 audio_timestamp_helper_->GetFrameDuration(frames_to_play); |
239 | 247 |
240 DVLOG(2) << class_name() << "::" << __FUNCTION__ << " pts:" << pts | 248 DVLOG(2) << class_name() << "::" << __FUNCTION__ << " pts:" << pts |
241 << " will play: [" << now_playing << "," << last_buffered << "]"; | 249 << " will play: [" << now_playing << "," << last_buffered << "]"; |
242 | 250 |
251 // Statistics | |
252 if (!next_frame_time_limit_.is_null() && | |
253 next_frame_time_limit_ < current_time) { | |
254 frame_statistics_->AddLateFrame(current_time - next_frame_time_limit_); | |
255 } | |
256 | |
257 next_frame_time_limit_ = current_time + (last_buffered - now_playing); | |
258 | |
243 media_task_runner_->PostTask( | 259 media_task_runner_->PostTask( |
244 FROM_HERE, base::Bind(update_current_time_cb_, now_playing, | 260 FROM_HERE, base::Bind(update_current_time_cb_, now_playing, |
245 last_buffered, false)); | 261 last_buffered, false)); |
246 } | 262 } |
247 } | 263 } |
248 | 264 |
249 media_codec_bridge_->ReleaseOutputBuffer(buffer_index, false); | 265 media_codec_bridge_->ReleaseOutputBuffer(buffer_index, false); |
250 | 266 |
251 CheckLastFrame(eos_encountered, false); // no delayed tasks | 267 CheckLastFrame(eos_encountered, false); // no delayed tasks |
252 } | 268 } |
(...skipping 15 matching lines...) Expand all Loading... | |
268 if (audio_timestamp_helper_) | 284 if (audio_timestamp_helper_) |
269 base_timestamp_ = audio_timestamp_helper_->GetTimestamp(); | 285 base_timestamp_ = audio_timestamp_helper_->GetTimestamp(); |
270 | 286 |
271 audio_timestamp_helper_.reset( | 287 audio_timestamp_helper_.reset( |
272 new AudioTimestampHelper(configs_.audio_sampling_rate)); | 288 new AudioTimestampHelper(configs_.audio_sampling_rate)); |
273 | 289 |
274 audio_timestamp_helper_->SetBaseTimestamp(base_timestamp_); | 290 audio_timestamp_helper_->SetBaseTimestamp(base_timestamp_); |
275 } | 291 } |
276 | 292 |
277 } // namespace media | 293 } // namespace media |
OLD | NEW |