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

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

Issue 393313004: Fold DecoderStream::Stop() into the dtor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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/buffers.h" 14 #include "media/base/buffers.h"
15 #include "media/base/limits.h" 15 #include "media/base/limits.h"
16 #include "media/base/pipeline.h" 16 #include "media/base/pipeline.h"
17 #include "media/base/video_frame.h" 17 #include "media/base/video_frame.h"
18 18
19 namespace media { 19 namespace media {
20 20
21 VideoRendererImpl::VideoRendererImpl( 21 VideoRendererImpl::VideoRendererImpl(
22 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, 22 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
23 ScopedVector<VideoDecoder> decoders, 23 ScopedVector<VideoDecoder> decoders,
24 const SetDecryptorReadyCB& set_decryptor_ready_cb, 24 const SetDecryptorReadyCB& set_decryptor_ready_cb,
25 const PaintCB& paint_cb, 25 const PaintCB& paint_cb,
26 bool drop_frames) 26 bool drop_frames)
27 : task_runner_(task_runner), 27 : task_runner_(task_runner),
28 video_frame_stream_(task_runner, decoders.Pass(), set_decryptor_ready_cb), 28 video_frame_stream_(new VideoFrameStream(task_runner,
29 decoders.Pass(),
30 set_decryptor_ready_cb)),
29 low_delay_(false), 31 low_delay_(false),
30 received_end_of_stream_(false), 32 received_end_of_stream_(false),
31 rendered_end_of_stream_(false), 33 rendered_end_of_stream_(false),
32 frame_available_(&lock_), 34 frame_available_(&lock_),
33 state_(kUninitialized), 35 state_(kUninitialized),
34 thread_(), 36 thread_(),
35 pending_read_(false), 37 pending_read_(false),
36 drop_frames_(drop_frames), 38 drop_frames_(drop_frames),
37 buffering_state_(BUFFERING_HAVE_NOTHING), 39 buffering_state_(BUFFERING_HAVE_NOTHING),
38 paint_cb_(paint_cb), 40 paint_cb_(paint_cb),
(...skipping 20 matching lines...) Expand all
59 // This is necessary if the |video_frame_stream_| has already seen an end of 61 // This is necessary if the |video_frame_stream_| has already seen an end of
60 // stream and needs to drain it before flushing it. 62 // stream and needs to drain it before flushing it.
61 ready_frames_.clear(); 63 ready_frames_.clear();
62 if (buffering_state_ != BUFFERING_HAVE_NOTHING) { 64 if (buffering_state_ != BUFFERING_HAVE_NOTHING) {
63 buffering_state_ = BUFFERING_HAVE_NOTHING; 65 buffering_state_ = BUFFERING_HAVE_NOTHING;
64 buffering_state_cb_.Run(BUFFERING_HAVE_NOTHING); 66 buffering_state_cb_.Run(BUFFERING_HAVE_NOTHING);
65 } 67 }
66 received_end_of_stream_ = false; 68 received_end_of_stream_ = false;
67 rendered_end_of_stream_ = false; 69 rendered_end_of_stream_ = false;
68 70
69 video_frame_stream_.Reset( 71 video_frame_stream_->Reset(
70 base::Bind(&VideoRendererImpl::OnVideoFrameStreamResetDone, 72 base::Bind(&VideoRendererImpl::OnVideoFrameStreamResetDone,
71 weak_factory_.GetWeakPtr())); 73 weak_factory_.GetWeakPtr()));
72 } 74 }
73 75
74 void VideoRendererImpl::Stop(const base::Closure& callback) { 76 void VideoRendererImpl::Stop(const base::Closure& callback) {
75 DCHECK(task_runner_->BelongsToCurrentThread()); 77 DCHECK(task_runner_->BelongsToCurrentThread());
76 base::AutoLock auto_lock(lock_); 78 base::AutoLock auto_lock(lock_);
77 if (state_ == kUninitialized || state_ == kStopped) { 79 if (state_ == kUninitialized || state_ == kStopped) {
78 callback.Run(); 80 task_runner_->PostTask(FROM_HERE, callback);
79 return; 81 return;
80 } 82 }
81 83
82 // TODO(scherkus): Consider invalidating |weak_factory_| and replacing 84 // TODO(scherkus): Consider invalidating |weak_factory_| and replacing
83 // task-running guards that check |state_| with DCHECK(). 85 // task-running guards that check |state_| with DCHECK().
84 86
85 state_ = kStopped; 87 state_ = kStopped;
86 88
87 statistics_cb_.Reset(); 89 statistics_cb_.Reset();
88 max_time_cb_.Reset(); 90 max_time_cb_.Reset();
89 DoStopOrError_Locked(); 91 DoStopOrError_Locked();
90 92
91 // Clean up our thread if present. 93 // Clean up our thread if present.
92 base::PlatformThreadHandle thread_to_join = base::PlatformThreadHandle(); 94 base::PlatformThreadHandle thread_to_join = base::PlatformThreadHandle();
93 if (!thread_.is_null()) { 95 if (!thread_.is_null()) {
94 // Signal the thread since it's possible to get stopped with the video 96 // Signal the thread since it's possible to get stopped with the video
95 // thread waiting for a read to complete. 97 // thread waiting for a read to complete.
96 frame_available_.Signal(); 98 frame_available_.Signal();
97 std::swap(thread_, thread_to_join); 99 std::swap(thread_, thread_to_join);
98 } 100 }
99 101
100 if (!thread_to_join.is_null()) { 102 if (!thread_to_join.is_null()) {
101 base::AutoUnlock auto_unlock(lock_); 103 base::AutoUnlock auto_unlock(lock_);
102 base::PlatformThread::Join(thread_to_join); 104 base::PlatformThread::Join(thread_to_join);
103 } 105 }
104 106
105 video_frame_stream_.Stop(callback); 107 video_frame_stream_.reset();
scherkus (not reviewing) 2014/07/16 17:49:48 ditto
xhwang 2014/07/16 23:45:49 ditto
108 task_runner_->PostTask(FROM_HERE, callback);
106 } 109 }
107 110
108 void VideoRendererImpl::StartPlayingFrom(base::TimeDelta timestamp) { 111 void VideoRendererImpl::StartPlayingFrom(base::TimeDelta timestamp) {
109 DCHECK(task_runner_->BelongsToCurrentThread()); 112 DCHECK(task_runner_->BelongsToCurrentThread());
110 base::AutoLock auto_lock(lock_); 113 base::AutoLock auto_lock(lock_);
111 DCHECK_EQ(state_, kFlushed); 114 DCHECK_EQ(state_, kFlushed);
112 DCHECK(!pending_read_); 115 DCHECK(!pending_read_);
113 DCHECK(ready_frames_.empty()); 116 DCHECK(ready_frames_.empty());
114 DCHECK_EQ(buffering_state_, BUFFERING_HAVE_NOTHING); 117 DCHECK_EQ(buffering_state_, BUFFERING_HAVE_NOTHING);
115 118
(...skipping 30 matching lines...) Expand all
146 init_cb_ = init_cb; 149 init_cb_ = init_cb;
147 statistics_cb_ = statistics_cb; 150 statistics_cb_ = statistics_cb;
148 max_time_cb_ = max_time_cb; 151 max_time_cb_ = max_time_cb;
149 buffering_state_cb_ = buffering_state_cb; 152 buffering_state_cb_ = buffering_state_cb;
150 ended_cb_ = ended_cb; 153 ended_cb_ = ended_cb;
151 error_cb_ = error_cb; 154 error_cb_ = error_cb;
152 get_time_cb_ = get_time_cb; 155 get_time_cb_ = get_time_cb;
153 get_duration_cb_ = get_duration_cb; 156 get_duration_cb_ = get_duration_cb;
154 state_ = kInitializing; 157 state_ = kInitializing;
155 158
156 video_frame_stream_.Initialize( 159 video_frame_stream_->Initialize(
157 stream, 160 stream,
158 low_delay, 161 low_delay,
159 statistics_cb, 162 statistics_cb,
160 base::Bind(&VideoRendererImpl::OnVideoFrameStreamInitialized, 163 base::Bind(&VideoRendererImpl::OnVideoFrameStreamInitialized,
161 weak_factory_.GetWeakPtr())); 164 weak_factory_.GetWeakPtr()));
162 } 165 }
163 166
164 void VideoRendererImpl::OnVideoFrameStreamInitialized(bool success) { 167 void VideoRendererImpl::OnVideoFrameStreamInitialized(bool success) {
165 DCHECK(task_runner_->BelongsToCurrentThread()); 168 DCHECK(task_runner_->BelongsToCurrentThread());
166 base::AutoLock auto_lock(lock_); 169 base::AutoLock auto_lock(lock_);
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 // Always request more decoded video if we have capacity. This serves two 350 // Always request more decoded video if we have capacity. This serves two
348 // purposes: 351 // purposes:
349 // 1) Prerolling while paused 352 // 1) Prerolling while paused
350 // 2) Keeps decoding going if video rendering thread starts falling behind 353 // 2) Keeps decoding going if video rendering thread starts falling behind
351 AttemptRead_Locked(); 354 AttemptRead_Locked();
352 } 355 }
353 356
354 bool VideoRendererImpl::HaveEnoughData_Locked() { 357 bool VideoRendererImpl::HaveEnoughData_Locked() {
355 DCHECK_EQ(state_, kPlaying); 358 DCHECK_EQ(state_, kPlaying);
356 return received_end_of_stream_ || 359 return received_end_of_stream_ ||
357 !video_frame_stream_.CanReadWithoutStalling() || 360 !video_frame_stream_->CanReadWithoutStalling() ||
358 ready_frames_.size() >= static_cast<size_t>(limits::kMaxVideoFrames) || 361 ready_frames_.size() >= static_cast<size_t>(limits::kMaxVideoFrames) ||
359 (low_delay_ && ready_frames_.size() > 0); 362 (low_delay_ && ready_frames_.size() > 0);
360 } 363 }
361 364
362 void VideoRendererImpl::TransitionToHaveEnough_Locked() { 365 void VideoRendererImpl::TransitionToHaveEnough_Locked() {
363 DCHECK_EQ(buffering_state_, BUFFERING_HAVE_NOTHING); 366 DCHECK_EQ(buffering_state_, BUFFERING_HAVE_NOTHING);
364 367
365 if (received_end_of_stream_) 368 if (received_end_of_stream_)
366 max_time_cb_.Run(get_duration_cb_.Run()); 369 max_time_cb_.Run(get_duration_cb_.Run());
367 370
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 lock_.AssertAcquired(); 430 lock_.AssertAcquired();
428 431
429 if (pending_read_ || received_end_of_stream_ || 432 if (pending_read_ || received_end_of_stream_ ||
430 ready_frames_.size() == static_cast<size_t>(limits::kMaxVideoFrames)) { 433 ready_frames_.size() == static_cast<size_t>(limits::kMaxVideoFrames)) {
431 return; 434 return;
432 } 435 }
433 436
434 switch (state_) { 437 switch (state_) {
435 case kPlaying: 438 case kPlaying:
436 pending_read_ = true; 439 pending_read_ = true;
437 video_frame_stream_.Read(base::Bind(&VideoRendererImpl::FrameReady, 440 video_frame_stream_->Read(base::Bind(&VideoRendererImpl::FrameReady,
438 weak_factory_.GetWeakPtr())); 441 weak_factory_.GetWeakPtr()));
439 return; 442 return;
440 443
441 case kUninitialized: 444 case kUninitialized:
442 case kInitializing: 445 case kInitializing:
443 case kFlushing: 446 case kFlushing:
444 case kFlushed: 447 case kFlushed:
445 case kStopped: 448 case kStopped:
446 return; 449 return;
447 } 450 }
448 } 451 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 statistics_cb_.Run(statistics); 486 statistics_cb_.Run(statistics);
484 487
485 frames_decoded_ = 0; 488 frames_decoded_ = 0;
486 frames_dropped_ = 0; 489 frames_dropped_ = 0;
487 } 490 }
488 491
489 frame_available_.TimedWait(wait_duration); 492 frame_available_.TimedWait(wait_duration);
490 } 493 }
491 494
492 } // namespace media 495 } // namespace media
OLDNEW
« media/filters/decoder_stream.cc ('K') | « media/filters/video_renderer_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698