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

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: comments addressed 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
« no previous file with comments | « media/filters/video_renderer_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 // Always request more decoded video if we have capacity. This serves two 356 // Always request more decoded video if we have capacity. This serves two
354 // purposes: 357 // purposes:
355 // 1) Prerolling while paused 358 // 1) Prerolling while paused
356 // 2) Keeps decoding going if video rendering thread starts falling behind 359 // 2) Keeps decoding going if video rendering thread starts falling behind
357 AttemptRead_Locked(); 360 AttemptRead_Locked();
358 } 361 }
359 362
360 bool VideoRendererImpl::HaveEnoughData_Locked() { 363 bool VideoRendererImpl::HaveEnoughData_Locked() {
361 DCHECK_EQ(state_, kPlaying); 364 DCHECK_EQ(state_, kPlaying);
362 return received_end_of_stream_ || 365 return received_end_of_stream_ ||
363 !video_frame_stream_.CanReadWithoutStalling() || 366 !video_frame_stream_->CanReadWithoutStalling() ||
364 ready_frames_.size() >= static_cast<size_t>(limits::kMaxVideoFrames) || 367 ready_frames_.size() >= static_cast<size_t>(limits::kMaxVideoFrames) ||
365 (low_delay_ && ready_frames_.size() > 0); 368 (low_delay_ && ready_frames_.size() > 0);
366 } 369 }
367 370
368 void VideoRendererImpl::TransitionToHaveEnough_Locked() { 371 void VideoRendererImpl::TransitionToHaveEnough_Locked() {
369 DCHECK_EQ(buffering_state_, BUFFERING_HAVE_NOTHING); 372 DCHECK_EQ(buffering_state_, BUFFERING_HAVE_NOTHING);
370 373
371 if (received_end_of_stream_) 374 if (received_end_of_stream_)
372 max_time_cb_.Run(get_duration_cb_.Run()); 375 max_time_cb_.Run(get_duration_cb_.Run());
373 376
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 lock_.AssertAcquired(); 436 lock_.AssertAcquired();
434 437
435 if (pending_read_ || received_end_of_stream_ || 438 if (pending_read_ || received_end_of_stream_ ||
436 ready_frames_.size() == static_cast<size_t>(limits::kMaxVideoFrames)) { 439 ready_frames_.size() == static_cast<size_t>(limits::kMaxVideoFrames)) {
437 return; 440 return;
438 } 441 }
439 442
440 switch (state_) { 443 switch (state_) {
441 case kPlaying: 444 case kPlaying:
442 pending_read_ = true; 445 pending_read_ = true;
443 video_frame_stream_.Read(base::Bind(&VideoRendererImpl::FrameReady, 446 video_frame_stream_->Read(base::Bind(&VideoRendererImpl::FrameReady,
444 weak_factory_.GetWeakPtr())); 447 weak_factory_.GetWeakPtr()));
445 return; 448 return;
446 449
447 case kUninitialized: 450 case kUninitialized:
448 case kInitializing: 451 case kInitializing:
449 case kFlushing: 452 case kFlushing:
450 case kFlushed: 453 case kFlushed:
451 case kStopped: 454 case kStopped:
452 return; 455 return;
453 } 456 }
454 } 457 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 statistics_cb_.Run(statistics); 492 statistics_cb_.Run(statistics);
490 493
491 frames_decoded_ = 0; 494 frames_decoded_ = 0;
492 frames_dropped_ = 0; 495 frames_dropped_ = 0;
493 } 496 }
494 497
495 frame_available_.TimedWait(wait_duration); 498 frame_available_.TimedWait(wait_duration);
496 } 499 }
497 500
498 } // namespace media 501 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/video_renderer_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698