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/renderers/video_renderer_impl.h" | 5 #include "media/renderers/video_renderer_impl.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 DVLOG(1) << __func__ << "(" << timestamp.InMicroseconds() << ")"; | 122 DVLOG(1) << __func__ << "(" << timestamp.InMicroseconds() << ")"; |
123 DCHECK(task_runner_->BelongsToCurrentThread()); | 123 DCHECK(task_runner_->BelongsToCurrentThread()); |
124 base::AutoLock auto_lock(lock_); | 124 base::AutoLock auto_lock(lock_); |
125 DCHECK_EQ(state_, kFlushed); | 125 DCHECK_EQ(state_, kFlushed); |
126 DCHECK(!pending_read_); | 126 DCHECK(!pending_read_); |
127 DCHECK_EQ(buffering_state_, BUFFERING_HAVE_NOTHING); | 127 DCHECK_EQ(buffering_state_, BUFFERING_HAVE_NOTHING); |
128 | 128 |
129 state_ = kPlaying; | 129 state_ = kPlaying; |
130 start_timestamp_ = timestamp; | 130 start_timestamp_ = timestamp; |
131 painted_first_frame_ = false; | 131 painted_first_frame_ = false; |
| 132 start_rendering_time_ = tick_clock_->NowTicks(); |
132 AttemptRead_Locked(); | 133 AttemptRead_Locked(); |
133 } | 134 } |
134 | 135 |
135 void VideoRendererImpl::Initialize( | 136 void VideoRendererImpl::Initialize( |
136 DemuxerStream* stream, | 137 DemuxerStream* stream, |
137 CdmContext* cdm_context, | 138 CdmContext* cdm_context, |
138 RendererClient* client, | 139 RendererClient* client, |
139 const TimeSource::WallClockTimeCB& wall_clock_time_cb, | 140 const TimeSource::WallClockTimeCB& wall_clock_time_cb, |
140 const PipelineStatusCB& init_cb) { | 141 const PipelineStatusCB& init_cb) { |
141 DCHECK(task_runner_->BelongsToCurrentThread()); | 142 DCHECK(task_runner_->BelongsToCurrentThread()); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 } | 204 } |
204 | 205 |
205 // We don't count dropped frames in the background to avoid skewing the count | 206 // We don't count dropped frames in the background to avoid skewing the count |
206 // and impacting JavaScript visible metrics used by web developers. | 207 // and impacting JavaScript visible metrics used by web developers. |
207 // | 208 // |
208 // Just after resuming from background rendering, we also don't count the | 209 // Just after resuming from background rendering, we also don't count the |
209 // dropped frames since they are likely just dropped due to being too old. | 210 // dropped frames since they are likely just dropped due to being too old. |
210 if (!background_rendering && !was_background_rendering_) | 211 if (!background_rendering && !was_background_rendering_) |
211 frames_dropped_ += frames_dropped; | 212 frames_dropped_ += frames_dropped; |
212 UpdateStats_Locked(); | 213 UpdateStats_Locked(); |
| 214 |
213 was_background_rendering_ = background_rendering; | 215 was_background_rendering_ = background_rendering; |
214 | 216 |
215 // Always post this task, it will acquire new frames if necessary and since it | 217 // Always post this task, it will acquire new frames if necessary and since it |
216 // happens on another thread, even if we don't have room in the queue now, by | 218 // happens on another thread, even if we don't have room in the queue now, by |
217 // the time it runs (may be delayed up to 50ms for complex decodes!) we might. | 219 // the time it runs (may be delayed up to 50ms for complex decodes!) we might. |
218 task_runner_->PostTask( | 220 task_runner_->PostTask( |
219 FROM_HERE, | 221 FROM_HERE, |
220 base::Bind(&VideoRendererImpl::AttemptReadAndCheckForMetadataChanges, | 222 base::Bind(&VideoRendererImpl::AttemptReadAndCheckForMetadataChanges, |
221 weak_factory_.GetWeakPtr(), result->format(), | 223 weak_factory_.GetWeakPtr(), result->format(), |
222 result->natural_size())); | 224 result->natural_size())); |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 // prerolling frames before the actual start time that will be dropped. | 417 // prerolling frames before the actual start time that will be dropped. |
416 if (algorithm_->frames_queued() > 1 || received_end_of_stream_ || | 418 if (algorithm_->frames_queued() > 1 || received_end_of_stream_ || |
417 frame->timestamp() >= start_timestamp_ || low_delay_ || | 419 frame->timestamp() >= start_timestamp_ || low_delay_ || |
418 !video_frame_stream_->CanReadWithoutStalling()) { | 420 !video_frame_stream_->CanReadWithoutStalling()) { |
419 scoped_refptr<VideoFrame> first_frame = | 421 scoped_refptr<VideoFrame> first_frame = |
420 algorithm_->Render(base::TimeTicks(), base::TimeTicks(), nullptr); | 422 algorithm_->Render(base::TimeTicks(), base::TimeTicks(), nullptr); |
421 CheckForMetadataChanges(first_frame->format(), | 423 CheckForMetadataChanges(first_frame->format(), |
422 first_frame->natural_size()); | 424 first_frame->natural_size()); |
423 sink_->PaintSingleFrame(first_frame); | 425 sink_->PaintSingleFrame(first_frame); |
424 painted_first_frame_ = true; | 426 painted_first_frame_ = true; |
| 427 |
| 428 if (!start_rendering_time_.is_null()) { |
| 429 UMA_HISTOGRAM_MEDIUM_TIMES( |
| 430 "Media.Video.FirstRenderTime", |
| 431 tick_clock_->NowTicks() - start_rendering_time_); |
| 432 start_rendering_time_ = base::TimeTicks(); |
| 433 } |
425 } | 434 } |
426 } | 435 } |
427 | 436 |
428 // Signal buffering state if we've met our conditions. | 437 // Signal buffering state if we've met our conditions. |
429 if (buffering_state_ == BUFFERING_HAVE_NOTHING && HaveEnoughData_Locked()) | 438 if (buffering_state_ == BUFFERING_HAVE_NOTHING && HaveEnoughData_Locked()) |
430 TransitionToHaveEnough_Locked(); | 439 TransitionToHaveEnough_Locked(); |
431 | 440 |
432 // Always request more decoded video if we have capacity. | 441 // Always request more decoded video if we have capacity. |
433 AttemptRead_Locked(); | 442 AttemptRead_Locked(); |
434 } | 443 } |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
710 | 719 |
711 void VideoRendererImpl::AttemptReadAndCheckForMetadataChanges( | 720 void VideoRendererImpl::AttemptReadAndCheckForMetadataChanges( |
712 VideoPixelFormat pixel_format, | 721 VideoPixelFormat pixel_format, |
713 const gfx::Size& natural_size) { | 722 const gfx::Size& natural_size) { |
714 base::AutoLock auto_lock(lock_); | 723 base::AutoLock auto_lock(lock_); |
715 CheckForMetadataChanges(pixel_format, natural_size); | 724 CheckForMetadataChanges(pixel_format, natural_size); |
716 AttemptRead_Locked(); | 725 AttemptRead_Locked(); |
717 } | 726 } |
718 | 727 |
719 } // namespace media | 728 } // namespace media |
OLD | NEW |