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

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

Issue 12324005: Fix crash in VideoRendererBase::ThreadMain(). (Closed) Base URL: http://git.chromium.org/chromium/src.git@git-svn
Patch Set: Created 7 years, 10 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_base.h" 5 #include "media/filters/video_renderer_base.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/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 27 matching lines...) Expand all
38 drop_frames_(drop_frames), 38 drop_frames_(drop_frames),
39 playback_rate_(0), 39 playback_rate_(0),
40 paint_cb_(paint_cb), 40 paint_cb_(paint_cb),
41 set_opaque_cb_(set_opaque_cb), 41 set_opaque_cb_(set_opaque_cb),
42 last_timestamp_(kNoTimestamp()) { 42 last_timestamp_(kNoTimestamp()) {
43 DCHECK(!paint_cb_.is_null()); 43 DCHECK(!paint_cb_.is_null());
44 } 44 }
45 45
46 VideoRendererBase::~VideoRendererBase() { 46 VideoRendererBase::~VideoRendererBase() {
47 base::AutoLock auto_lock(lock_); 47 base::AutoLock auto_lock(lock_);
48 CHECK(state_ == kUninitialized || state_ == kStopped) << state_; 48 CHECK_EQ(state_, kStopped);
acolwell GONE FROM CHROMIUM 2013/02/20 17:01:14 Won't this crash if an error is encountered before
scherkus (not reviewing) 2013/02/21 20:43:54 Indeed it will!
49 CHECK_EQ(thread_, base::kNullThreadHandle); 49 CHECK_EQ(thread_, base::kNullThreadHandle);
50 } 50 }
51 51
52 void VideoRendererBase::Play(const base::Closure& callback) { 52 void VideoRendererBase::Play(const base::Closure& callback) {
53 DCHECK(message_loop_->BelongsToCurrentThread()); 53 DCHECK(message_loop_->BelongsToCurrentThread());
54 base::AutoLock auto_lock(lock_); 54 base::AutoLock auto_lock(lock_);
55 DCHECK_EQ(kPrerolled, state_); 55 DCHECK_EQ(kPrerolled, state_);
56 state_ = kPlaying; 56 state_ = kPlaying;
57 callback.Run(); 57 callback.Run();
58 } 58 }
(...skipping 26 matching lines...) Expand all
85 void VideoRendererBase::ResetDecoder() { 85 void VideoRendererBase::ResetDecoder() {
86 DCHECK(message_loop_->BelongsToCurrentThread()); 86 DCHECK(message_loop_->BelongsToCurrentThread());
87 base::AutoLock auto_lock(lock_); 87 base::AutoLock auto_lock(lock_);
88 decoder_->Reset(base::Bind( 88 decoder_->Reset(base::Bind(
89 &VideoRendererBase::OnDecoderResetDone, weak_this_)); 89 &VideoRendererBase::OnDecoderResetDone, weak_this_));
90 } 90 }
91 91
92 void VideoRendererBase::Stop(const base::Closure& callback) { 92 void VideoRendererBase::Stop(const base::Closure& callback) {
93 DCHECK(message_loop_->BelongsToCurrentThread()); 93 DCHECK(message_loop_->BelongsToCurrentThread());
94 base::AutoLock auto_lock(lock_); 94 base::AutoLock auto_lock(lock_);
95 if (state_ == kUninitialized || state_ == kStopped) { 95 if (state_ == kStopped) {
scherkus (not reviewing) 2013/02/20 08:26:11 note: state == kUninitialized actually runs the St
acolwell GONE FROM CHROMIUM 2013/02/20 17:01:14 This seems a little weird. Shouldn't we transition
scherkus (not reviewing) 2013/02/21 20:43:54 Yeah that was on my mind. I fully admit that I was
96 callback.Run(); 96 callback.Run();
97 return; 97 return;
98 } 98 }
99 99
100 // TODO(scherkus): Consider invalidating |weak_factory_| and replacing 100 // TODO(scherkus): Consider invalidating |weak_factory_| and replacing
101 // task-running guards that check |state_| with DCHECK(). 101 // task-running guards that check |state_| with DCHECK().
102 102
103 state_ = kStopped; 103 state_ = kStopped;
104 104
105 statistics_cb_.Reset(); 105 statistics_cb_.Reset();
(...skipping 13 matching lines...) Expand all
119 base::AutoUnlock auto_unlock(lock_); 119 base::AutoUnlock auto_unlock(lock_);
120 base::PlatformThread::Join(thread_to_join); 120 base::PlatformThread::Join(thread_to_join);
121 } 121 }
122 122
123 if (decrypting_demuxer_stream_) { 123 if (decrypting_demuxer_stream_) {
124 decrypting_demuxer_stream_->Reset(base::Bind( 124 decrypting_demuxer_stream_->Reset(base::Bind(
125 &VideoRendererBase::StopDecoder, weak_this_, callback)); 125 &VideoRendererBase::StopDecoder, weak_this_, callback));
126 return; 126 return;
127 } 127 }
128 128
129 decoder_->Stop(callback); 129 if (decoder_) {
130 decoder_->Stop(callback);
131 return;
132 }
133
134 callback.Run();
130 } 135 }
131 136
132 void VideoRendererBase::StopDecoder(const base::Closure& callback) { 137 void VideoRendererBase::StopDecoder(const base::Closure& callback) {
133 DCHECK(message_loop_->BelongsToCurrentThread()); 138 DCHECK(message_loop_->BelongsToCurrentThread());
134 base::AutoLock auto_lock(lock_); 139 base::AutoLock auto_lock(lock_);
135 decoder_->Stop(callback); 140 decoder_->Stop(callback);
136 } 141 }
137 142
138 void VideoRendererBase::SetPlaybackRate(float playback_rate) { 143 void VideoRendererBase::SetPlaybackRate(float playback_rate) {
139 DCHECK(message_loop_->BelongsToCurrentThread()); 144 DCHECK(message_loop_->BelongsToCurrentThread());
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 case kFlushed: 525 case kFlushed:
521 case kEnded: 526 case kEnded:
522 case kStopped: 527 case kStopped:
523 case kError: 528 case kError:
524 return; 529 return;
525 } 530 }
526 } 531 }
527 532
528 void VideoRendererBase::OnDecoderResetDone() { 533 void VideoRendererBase::OnDecoderResetDone() {
529 base::AutoLock auto_lock(lock_); 534 base::AutoLock auto_lock(lock_);
535 if (state_ == kStopped)
536 return;
537
530 DCHECK_EQ(kFlushingDecoder, state_); 538 DCHECK_EQ(kFlushingDecoder, state_);
531 DCHECK(!pending_read_); 539 DCHECK(!pending_read_);
532 540
533 state_ = kFlushing; 541 state_ = kFlushing;
534 AttemptFlush_Locked(); 542 AttemptFlush_Locked();
535 } 543 }
536 544
537 void VideoRendererBase::AttemptFlush_Locked() { 545 void VideoRendererBase::AttemptFlush_Locked() {
538 lock_.AssertAcquired(); 546 lock_.AssertAcquired();
539 DCHECK_EQ(kFlushing, state_); 547 DCHECK_EQ(kFlushing, state_);
(...skipping 27 matching lines...) Expand all
567 last_timestamp_ = kNoTimestamp(); 575 last_timestamp_ = kNoTimestamp();
568 ready_frames_.clear(); 576 ready_frames_.clear();
569 } 577 }
570 578
571 int VideoRendererBase::NumFrames_Locked() const { 579 int VideoRendererBase::NumFrames_Locked() const {
572 lock_.AssertAcquired(); 580 lock_.AssertAcquired();
573 return ready_frames_.size(); 581 return ready_frames_.size();
574 } 582 }
575 583
576 } // namespace media 584 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | media/filters/video_renderer_base_unittest.cc » ('j') | media/filters/video_renderer_base_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698