Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(949)

Side by Side Diff: media/filters/video_renderer_impl.cc

Issue 418143005: media: Introduce Renderer interface and RendererImpl. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix media/BUILD.gn Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
14 #include "media/base/buffers.h" 15 #include "media/base/buffers.h"
15 #include "media/base/limits.h" 16 #include "media/base/limits.h"
16 #include "media/base/pipeline.h" 17 #include "media/base/pipeline.h"
17 #include "media/base/video_frame.h" 18 #include "media/base/video_frame.h"
18 19
19 namespace media { 20 namespace media {
20 21
21 VideoRendererImpl::VideoRendererImpl( 22 VideoRendererImpl::VideoRendererImpl(
22 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, 23 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
23 ScopedVector<VideoDecoder> decoders, 24 ScopedVector<VideoDecoder> decoders,
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 DCHECK(!statistics_cb.is_null()); 119 DCHECK(!statistics_cb.is_null());
119 DCHECK(!max_time_cb.is_null()); 120 DCHECK(!max_time_cb.is_null());
120 DCHECK(!buffering_state_cb.is_null()); 121 DCHECK(!buffering_state_cb.is_null());
121 DCHECK(!ended_cb.is_null()); 122 DCHECK(!ended_cb.is_null());
122 DCHECK(!get_time_cb.is_null()); 123 DCHECK(!get_time_cb.is_null());
123 DCHECK(!get_duration_cb.is_null()); 124 DCHECK(!get_duration_cb.is_null());
124 DCHECK_EQ(kUninitialized, state_); 125 DCHECK_EQ(kUninitialized, state_);
125 126
126 low_delay_ = low_delay; 127 low_delay_ = low_delay;
127 128
128 init_cb_ = init_cb; 129 // Always post |init_cb_| because |this| could be destroyed if initialization
130 // failed.
damienv1 2014/08/06 16:10:03 Could you please give me a callstack / sequence of
xhwang 2014/08/07 05:46:49 See: https://codereview.chromium.org/418143005/dif
131 init_cb_ = BindToCurrentLoop(init_cb);
132
129 statistics_cb_ = statistics_cb; 133 statistics_cb_ = statistics_cb;
130 max_time_cb_ = max_time_cb; 134 max_time_cb_ = max_time_cb;
131 buffering_state_cb_ = buffering_state_cb; 135 buffering_state_cb_ = buffering_state_cb;
132 ended_cb_ = ended_cb; 136 ended_cb_ = ended_cb;
133 error_cb_ = error_cb; 137 error_cb_ = error_cb;
134 get_time_cb_ = get_time_cb; 138 get_time_cb_ = get_time_cb;
135 get_duration_cb_ = get_duration_cb; 139 get_duration_cb_ = get_duration_cb;
136 state_ = kInitializing; 140 state_ = kInitializing;
137 141
138 video_frame_stream_->Initialize( 142 video_frame_stream_->Initialize(
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 frames_decoded_++; 280 frames_decoded_++;
277 frames_dropped_++; 281 frames_dropped_++;
278 282
279 task_runner_->PostTask( 283 task_runner_->PostTask(
280 FROM_HERE, 284 FROM_HERE,
281 base::Bind(&VideoRendererImpl::AttemptRead, weak_factory_.GetWeakPtr())); 285 base::Bind(&VideoRendererImpl::AttemptRead, weak_factory_.GetWeakPtr()));
282 } 286 }
283 287
284 void VideoRendererImpl::FrameReady(VideoFrameStream::Status status, 288 void VideoRendererImpl::FrameReady(VideoFrameStream::Status status,
285 const scoped_refptr<VideoFrame>& frame) { 289 const scoped_refptr<VideoFrame>& frame) {
290 DCHECK(task_runner_->BelongsToCurrentThread());
286 base::AutoLock auto_lock(lock_); 291 base::AutoLock auto_lock(lock_);
287 DCHECK_NE(state_, kUninitialized); 292 DCHECK_NE(state_, kUninitialized);
288 DCHECK_NE(state_, kFlushed); 293 DCHECK_NE(state_, kFlushed);
289 294
290 CHECK(pending_read_); 295 CHECK(pending_read_);
291 pending_read_ = false; 296 pending_read_ = false;
292 297
293 if (status == VideoFrameStream::DECODE_ERROR || 298 if (status == VideoFrameStream::DECODE_ERROR ||
294 status == VideoFrameStream::DECRYPT_ERROR) { 299 status == VideoFrameStream::DECRYPT_ERROR) {
295 DCHECK(!frame.get()); 300 DCHECK(!frame.get());
296 PipelineStatus error = PIPELINE_ERROR_DECODE; 301 PipelineStatus error = PIPELINE_ERROR_DECODE;
297 if (status == VideoFrameStream::DECRYPT_ERROR) 302 if (status == VideoFrameStream::DECRYPT_ERROR)
298 error = PIPELINE_ERROR_DECRYPT; 303 error = PIPELINE_ERROR_DECRYPT;
299 error_cb_.Run(error); 304 task_runner_->PostTask(FROM_HERE, base::Bind(error_cb_, error));
300 return; 305 return;
301 } 306 }
302 307
303 // Already-queued VideoFrameStream ReadCB's can fire after various state 308 // Already-queued VideoFrameStream ReadCB's can fire after various state
304 // transitions have happened; in that case just drop those frames immediately. 309 // transitions have happened; in that case just drop those frames immediately.
305 if (state_ == kFlushing) 310 if (state_ == kFlushing)
306 return; 311 return;
307 312
308 DCHECK_EQ(state_, kPlaying); 313 DCHECK_EQ(state_, kPlaying);
309 314
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 task_runner_->PostTask(FROM_HERE, base::Bind(statistics_cb_, statistics)); 464 task_runner_->PostTask(FROM_HERE, base::Bind(statistics_cb_, statistics));
460 465
461 frames_decoded_ = 0; 466 frames_decoded_ = 0;
462 frames_dropped_ = 0; 467 frames_dropped_ = 0;
463 } 468 }
464 469
465 frame_available_.TimedWait(wait_duration); 470 frame_available_.TimedWait(wait_duration);
466 } 471 }
467 472
468 } // namespace media 473 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698