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/filters/video_renderer_impl.h" | 5 #include "media/filters/video_renderer_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
11 #include "base/location.h" | 11 #include "base/location.h" |
12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
13 #include "base/threading/platform_thread.h" | 13 #include "base/threading/platform_thread.h" |
14 #include "media/base/bind_to_current_loop.h" | |
15 #include "media/base/buffers.h" | 14 #include "media/base/buffers.h" |
16 #include "media/base/limits.h" | 15 #include "media/base/limits.h" |
17 #include "media/base/pipeline.h" | 16 #include "media/base/pipeline.h" |
18 #include "media/base/video_frame.h" | 17 #include "media/base/video_frame.h" |
19 | 18 |
20 namespace media { | 19 namespace media { |
21 | 20 |
22 VideoRendererImpl::VideoRendererImpl( | 21 VideoRendererImpl::VideoRendererImpl( |
23 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 22 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
24 ScopedVector<VideoDecoder> decoders, | 23 ScopedVector<VideoDecoder> decoders, |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 DCHECK(!statistics_cb.is_null()); | 119 DCHECK(!statistics_cb.is_null()); |
121 DCHECK(!max_time_cb.is_null()); | 120 DCHECK(!max_time_cb.is_null()); |
122 DCHECK(!buffering_state_cb.is_null()); | 121 DCHECK(!buffering_state_cb.is_null()); |
123 DCHECK(!ended_cb.is_null()); | 122 DCHECK(!ended_cb.is_null()); |
124 DCHECK(!get_time_cb.is_null()); | 123 DCHECK(!get_time_cb.is_null()); |
125 DCHECK(!get_duration_cb.is_null()); | 124 DCHECK(!get_duration_cb.is_null()); |
126 DCHECK_EQ(kUninitialized, state_); | 125 DCHECK_EQ(kUninitialized, state_); |
127 | 126 |
128 low_delay_ = low_delay; | 127 low_delay_ = low_delay; |
129 | 128 |
130 // Always post |init_cb_| because |this| could be destroyed if initialization | 129 init_cb_ = init_cb; |
131 // failed. | |
132 init_cb_ = BindToCurrentLoop(init_cb); | |
133 | |
134 statistics_cb_ = statistics_cb; | 130 statistics_cb_ = statistics_cb; |
135 max_time_cb_ = max_time_cb; | 131 max_time_cb_ = max_time_cb; |
136 buffering_state_cb_ = buffering_state_cb; | 132 buffering_state_cb_ = buffering_state_cb; |
137 ended_cb_ = ended_cb; | 133 ended_cb_ = ended_cb; |
138 error_cb_ = error_cb; | 134 error_cb_ = error_cb; |
139 get_time_cb_ = get_time_cb; | 135 get_time_cb_ = get_time_cb; |
140 get_duration_cb_ = get_duration_cb; | 136 get_duration_cb_ = get_duration_cb; |
141 state_ = kInitializing; | 137 state_ = kInitializing; |
142 | 138 |
143 video_frame_stream_->Initialize( | 139 video_frame_stream_->Initialize( |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 frames_decoded_++; | 285 frames_decoded_++; |
290 frames_dropped_++; | 286 frames_dropped_++; |
291 | 287 |
292 task_runner_->PostTask( | 288 task_runner_->PostTask( |
293 FROM_HERE, | 289 FROM_HERE, |
294 base::Bind(&VideoRendererImpl::AttemptRead, weak_factory_.GetWeakPtr())); | 290 base::Bind(&VideoRendererImpl::AttemptRead, weak_factory_.GetWeakPtr())); |
295 } | 291 } |
296 | 292 |
297 void VideoRendererImpl::FrameReady(VideoFrameStream::Status status, | 293 void VideoRendererImpl::FrameReady(VideoFrameStream::Status status, |
298 const scoped_refptr<VideoFrame>& frame) { | 294 const scoped_refptr<VideoFrame>& frame) { |
299 DCHECK(task_runner_->BelongsToCurrentThread()); | |
300 base::AutoLock auto_lock(lock_); | 295 base::AutoLock auto_lock(lock_); |
301 DCHECK_NE(state_, kUninitialized); | 296 DCHECK_NE(state_, kUninitialized); |
302 DCHECK_NE(state_, kFlushed); | 297 DCHECK_NE(state_, kFlushed); |
303 | 298 |
304 CHECK(pending_read_); | 299 CHECK(pending_read_); |
305 pending_read_ = false; | 300 pending_read_ = false; |
306 | 301 |
307 if (status == VideoFrameStream::DECODE_ERROR || | 302 if (status == VideoFrameStream::DECODE_ERROR || |
308 status == VideoFrameStream::DECRYPT_ERROR) { | 303 status == VideoFrameStream::DECRYPT_ERROR) { |
309 DCHECK(!frame.get()); | 304 DCHECK(!frame.get()); |
310 PipelineStatus error = PIPELINE_ERROR_DECODE; | 305 PipelineStatus error = PIPELINE_ERROR_DECODE; |
311 if (status == VideoFrameStream::DECRYPT_ERROR) | 306 if (status == VideoFrameStream::DECRYPT_ERROR) |
312 error = PIPELINE_ERROR_DECRYPT; | 307 error = PIPELINE_ERROR_DECRYPT; |
313 task_runner_->PostTask(FROM_HERE, base::Bind(error_cb_, error)); | 308 error_cb_.Run(error); |
314 return; | 309 return; |
315 } | 310 } |
316 | 311 |
317 // Already-queued VideoFrameStream ReadCB's can fire after various state | 312 // Already-queued VideoFrameStream ReadCB's can fire after various state |
318 // transitions have happened; in that case just drop those frames immediately. | 313 // transitions have happened; in that case just drop those frames immediately. |
319 if (state_ == kFlushing) | 314 if (state_ == kFlushing) |
320 return; | 315 return; |
321 | 316 |
322 DCHECK_EQ(state_, kPlaying); | 317 DCHECK_EQ(state_, kPlaying); |
323 | 318 |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 task_runner_->PostTask(FROM_HERE, base::Bind(statistics_cb_, statistics)); | 469 task_runner_->PostTask(FROM_HERE, base::Bind(statistics_cb_, statistics)); |
475 | 470 |
476 frames_decoded_ = 0; | 471 frames_decoded_ = 0; |
477 frames_dropped_ = 0; | 472 frames_dropped_ = 0; |
478 } | 473 } |
479 | 474 |
480 frame_available_.TimedWait(wait_duration); | 475 frame_available_.TimedWait(wait_duration); |
481 } | 476 } |
482 | 477 |
483 } // namespace media | 478 } // namespace media |
OLD | NEW |