OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_decoder_job.h" | 5 #include "media/base/android/media_decoder_job.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
11 #include "base/trace_event/trace_event.h" | 11 #include "base/trace_event/trace_event.h" |
12 #include "media/base/android/media_drm_bridge.h" | 12 #include "media/base/android/media_drm_bridge.h" |
| 13 #include "media/base/android/media_statistics.h" |
13 #include "media/base/bind_to_current_loop.h" | 14 #include "media/base/bind_to_current_loop.h" |
14 #include "media/base/timestamp_constants.h" | 15 #include "media/base/timestamp_constants.h" |
15 | 16 |
16 namespace media { | 17 namespace media { |
17 | 18 |
18 // Timeout value for media codec operations. Because the first | 19 // Timeout value for media codec operations. Because the first |
19 // DequeInputBuffer() can take about 150 milliseconds, use 250 milliseconds | 20 // DequeInputBuffer() can take about 150 milliseconds, use 250 milliseconds |
20 // here. See http://b/9357571. | 21 // here. See http://b/9357571. |
21 static const int kMediaCodecTimeoutInMilliseconds = 250; | 22 static const int kMediaCodecTimeoutInMilliseconds = 250; |
22 | 23 |
23 MediaDecoderJob::MediaDecoderJob( | 24 MediaDecoderJob::MediaDecoderJob( |
24 const scoped_refptr<base::SingleThreadTaskRunner>& decoder_task_runner, | 25 const scoped_refptr<base::SingleThreadTaskRunner>& decoder_task_runner, |
25 const base::Closure& request_data_cb, | 26 const base::Closure& request_data_cb, |
26 const base::Closure& config_changed_cb) | 27 const base::Closure& config_changed_cb, |
| 28 FrameStatistics* frame_statistics) |
27 : need_to_reconfig_decoder_job_(false), | 29 : need_to_reconfig_decoder_job_(false), |
| 30 frame_statistics_(frame_statistics), |
28 ui_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 31 ui_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
29 decoder_task_runner_(decoder_task_runner), | 32 decoder_task_runner_(decoder_task_runner), |
30 needs_flush_(false), | 33 needs_flush_(false), |
31 input_eos_encountered_(false), | 34 input_eos_encountered_(false), |
32 output_eos_encountered_(false), | 35 output_eos_encountered_(false), |
33 skip_eos_enqueue_(true), | 36 skip_eos_enqueue_(true), |
34 prerolling_(true), | 37 prerolling_(true), |
35 request_data_cb_(request_data_cb), | 38 request_data_cb_(request_data_cb), |
36 config_changed_cb_(config_changed_cb), | 39 config_changed_cb_(config_changed_cb), |
37 current_demuxer_data_index_(0), | 40 current_demuxer_data_index_(0), |
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 // TODO(xhwang/qinmin): This logic is correct but strange. Clean it up. | 481 // TODO(xhwang/qinmin): This logic is correct but strange. Clean it up. |
479 if (output_eos_encountered_) | 482 if (output_eos_encountered_) |
480 status = MEDIA_CODEC_OUTPUT_END_OF_STREAM; | 483 status = MEDIA_CODEC_OUTPUT_END_OF_STREAM; |
481 else if (has_format_change) | 484 else if (has_format_change) |
482 status = MEDIA_CODEC_OUTPUT_FORMAT_CHANGED; | 485 status = MEDIA_CODEC_OUTPUT_FORMAT_CHANGED; |
483 | 486 |
484 bool render_output = presentation_timestamp >= preroll_timestamp_ && | 487 bool render_output = presentation_timestamp >= preroll_timestamp_ && |
485 (status != MEDIA_CODEC_OUTPUT_END_OF_STREAM || size != 0u); | 488 (status != MEDIA_CODEC_OUTPUT_END_OF_STREAM || size != 0u); |
486 base::TimeDelta time_to_render; | 489 base::TimeDelta time_to_render; |
487 DCHECK(!start_time_ticks.is_null()); | 490 DCHECK(!start_time_ticks.is_null()); |
488 if (render_output && ComputeTimeToRender()) { | 491 if (render_output) { |
489 time_to_render = presentation_timestamp - (base::TimeTicks::Now() - | 492 if (frame_statistics_) |
490 start_time_ticks + start_presentation_timestamp); | 493 frame_statistics_->AddFrame(); |
| 494 |
| 495 if (ComputeTimeToRender()) { |
| 496 time_to_render = |
| 497 presentation_timestamp - (base::TimeTicks::Now() - start_time_ticks + |
| 498 start_presentation_timestamp); |
| 499 |
| 500 // ComputeTimeToRender() returns true for video streams only, this is a |
| 501 // video stream. |
| 502 if (frame_statistics_ && time_to_render < base::TimeDelta()) |
| 503 frame_statistics_->AddLateFrame((-1) * time_to_render); |
| 504 } |
491 } | 505 } |
492 | 506 |
493 if (time_to_render > base::TimeDelta()) { | 507 if (time_to_render > base::TimeDelta()) { |
494 decoder_task_runner_->PostDelayedTask( | 508 decoder_task_runner_->PostDelayedTask( |
495 FROM_HERE, | 509 FROM_HERE, |
496 base::Bind(&MediaDecoderJob::ReleaseOutputBuffer, | 510 base::Bind(&MediaDecoderJob::ReleaseOutputBuffer, |
497 base::Unretained(this), | 511 base::Unretained(this), |
498 buffer_index, | 512 buffer_index, |
499 offset, | 513 offset, |
500 size, | 514 size, |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
688 | 702 |
689 void MediaDecoderJob::ReleaseMediaCodecBridge() { | 703 void MediaDecoderJob::ReleaseMediaCodecBridge() { |
690 if (!media_codec_bridge_) | 704 if (!media_codec_bridge_) |
691 return; | 705 return; |
692 | 706 |
693 media_codec_bridge_.reset(); | 707 media_codec_bridge_.reset(); |
694 input_buf_index_ = -1; | 708 input_buf_index_ = -1; |
695 } | 709 } |
696 | 710 |
697 } // namespace media | 711 } // namespace media |
OLD | NEW |