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

Side by Side Diff: media/base/pipeline.cc

Issue 10825280: Merge Pipeline's kError state with kStopped: a baby step towards bringing sanity to shutdown. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src
Patch Set: rebase Created 8 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 (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/base/pipeline.h" 5 #include "media/base/pipeline.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 scoped_refptr<AudioDecoder> audio_decoder; 65 scoped_refptr<AudioDecoder> audio_decoder;
66 scoped_refptr<VideoDecoder> video_decoder; 66 scoped_refptr<VideoDecoder> video_decoder;
67 }; 67 };
68 68
69 Pipeline::Pipeline(MessageLoop* message_loop, MediaLog* media_log) 69 Pipeline::Pipeline(MessageLoop* message_loop, MediaLog* media_log)
70 : message_loop_(message_loop->message_loop_proxy()), 70 : message_loop_(message_loop->message_loop_proxy()),
71 media_log_(media_log), 71 media_log_(media_log),
72 running_(false), 72 running_(false),
73 seek_pending_(false), 73 seek_pending_(false),
74 tearing_down_(false), 74 tearing_down_(false),
75 error_caused_teardown_(false),
scherkus (not reviewing) 2012/08/09 19:26:53 this is synonymous with (status_ != PIPELINE_OK &&
76 playback_rate_change_pending_(false), 75 playback_rate_change_pending_(false),
77 did_loading_progress_(false), 76 did_loading_progress_(false),
78 total_bytes_(0), 77 total_bytes_(0),
79 natural_size_(0, 0), 78 natural_size_(0, 0),
80 volume_(1.0f), 79 volume_(1.0f),
81 playback_rate_(0.0f), 80 playback_rate_(0.0f),
82 pending_playback_rate_(0.0f), 81 pending_playback_rate_(0.0f),
83 clock_(new Clock(&base::Time::Now)), 82 clock_(new Clock(&base::Time::Now)),
84 waiting_for_clock_update_(false), 83 waiting_for_clock_update_(false),
85 status_(PIPELINE_OK), 84 status_(PIPELINE_OK),
(...skipping 28 matching lines...) Expand all
114 CHECK(!running_) << "Media pipeline is already running"; 113 CHECK(!running_) << "Media pipeline is already running";
115 114
116 running_ = true; 115 running_ = true;
117 message_loop_->PostTask(FROM_HERE, base::Bind( 116 message_loop_->PostTask(FROM_HERE, base::Bind(
118 &Pipeline::StartTask, this, base::Passed(&collection), 117 &Pipeline::StartTask, this, base::Passed(&collection),
119 ended_cb, error_cb, start_cb)); 118 ended_cb, error_cb, start_cb));
120 } 119 }
121 120
122 void Pipeline::Stop(const base::Closure& stop_cb) { 121 void Pipeline::Stop(const base::Closure& stop_cb) {
123 base::AutoLock auto_lock(lock_); 122 base::AutoLock auto_lock(lock_);
124 CHECK(running_) << "Media pipeline isn't running";
125
126 // Stop the pipeline, which will set |running_| to false on our behalf.
127 message_loop_->PostTask(FROM_HERE, base::Bind( 123 message_loop_->PostTask(FROM_HERE, base::Bind(
128 &Pipeline::StopTask, this, stop_cb)); 124 &Pipeline::StopTask, this, stop_cb));
129 } 125 }
130 126
131 void Pipeline::Seek(TimeDelta time, const PipelineStatusCB& seek_cb) { 127 void Pipeline::Seek(TimeDelta time, const PipelineStatusCB& seek_cb) {
132 base::AutoLock auto_lock(lock_); 128 base::AutoLock auto_lock(lock_);
133 CHECK(running_) << "Media pipeline isn't running"; 129 CHECK(running_) << "Media pipeline isn't running";
134 130
135 message_loop_->PostTask(FROM_HERE, base::Bind( 131 message_loop_->PostTask(FROM_HERE, base::Bind(
136 &Pipeline::SeekTask, this, time, seek_cb)); 132 &Pipeline::SeekTask, this, time, seek_cb));
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 bool ret = did_loading_progress_; 227 bool ret = did_loading_progress_;
232 did_loading_progress_ = false; 228 did_loading_progress_ = false;
233 return ret; 229 return ret;
234 } 230 }
235 231
236 PipelineStatistics Pipeline::GetStatistics() const { 232 PipelineStatistics Pipeline::GetStatistics() const {
237 base::AutoLock auto_lock(lock_); 233 base::AutoLock auto_lock(lock_);
238 return statistics_; 234 return statistics_;
239 } 235 }
240 236
241 bool Pipeline::IsInitializedForTesting() {
242 DCHECK(message_loop_->BelongsToCurrentThread())
243 << "Tests should run on the same thread as Pipeline";
244 switch (state_) {
245 case kPausing:
246 case kFlushing:
247 case kSeeking:
248 case kStarting:
249 case kStarted:
250 return true;
251 default:
252 return false;
253 }
254 }
255
256 void Pipeline::SetClockForTesting(Clock* clock) { 237 void Pipeline::SetClockForTesting(Clock* clock) {
257 clock_.reset(clock); 238 clock_.reset(clock);
258 } 239 }
259 240
260 void Pipeline::SetErrorForTesting(PipelineStatus status) { 241 void Pipeline::SetErrorForTesting(PipelineStatus status) {
261 SetError(status); 242 SetError(status);
262 } 243 }
263 244
264 void Pipeline::SetState(State next_state) { 245 void Pipeline::SetState(State next_state) {
265 if (state_ != kStarted && next_state == kStarted && 246 if (state_ != kStarted && next_state == kStarted &&
266 !creation_time_.is_null()) { 247 !creation_time_.is_null()) {
267 UMA_HISTOGRAM_TIMES( 248 UMA_HISTOGRAM_TIMES(
268 "Media.TimeToPipelineStarted", base::Time::Now() - creation_time_); 249 "Media.TimeToPipelineStarted", base::Time::Now() - creation_time_);
269 creation_time_ = base::Time(); 250 creation_time_ = base::Time();
270 } 251 }
271 state_ = next_state; 252 state_ = next_state;
272 media_log_->AddEvent(media_log_->CreatePipelineStateChangedEvent(next_state)); 253 media_log_->AddEvent(media_log_->CreatePipelineStateChangedEvent(next_state));
273 } 254 }
274 255
275 bool Pipeline::IsPipelineOk() { 256 bool Pipeline::IsPipelineOk() {
276 base::AutoLock auto_lock(lock_); 257 base::AutoLock auto_lock(lock_);
277 return status_ == PIPELINE_OK; 258 return status_ == PIPELINE_OK;
278 } 259 }
279 260
280 bool Pipeline::IsPipelineStopped() {
281 DCHECK(message_loop_->BelongsToCurrentThread());
282 return state_ == kStopped || state_ == kError;
283 }
284
285 bool Pipeline::IsPipelineTearingDown() {
286 DCHECK(message_loop_->BelongsToCurrentThread());
287 return tearing_down_;
288 }
289
290 bool Pipeline::IsPipelineSeeking() { 261 bool Pipeline::IsPipelineSeeking() {
291 DCHECK(message_loop_->BelongsToCurrentThread()); 262 DCHECK(message_loop_->BelongsToCurrentThread());
292 if (!seek_pending_) 263 if (!seek_pending_)
293 return false; 264 return false;
294 DCHECK(kSeeking == state_ || kPausing == state_ || 265 DCHECK(kSeeking == state_ || kPausing == state_ ||
295 kFlushing == state_ || kStarting == state_) 266 kFlushing == state_ || kStarting == state_)
296 << "Current state : " << state_; 267 << "Current state : " << state_;
297 return true; 268 return true;
298 } 269 }
299 270
(...skipping 28 matching lines...) Expand all
328 // static 299 // static
329 Pipeline::State Pipeline::FindNextState(State current) { 300 Pipeline::State Pipeline::FindNextState(State current) {
330 // TODO(scherkus): refactor InitializeTask() to make use of this function. 301 // TODO(scherkus): refactor InitializeTask() to make use of this function.
331 if (current == kPausing) { 302 if (current == kPausing) {
332 return kFlushing; 303 return kFlushing;
333 } else if (current == kFlushing) { 304 } else if (current == kFlushing) {
334 // We will always honor Seek() before Stop(). This is based on the 305 // We will always honor Seek() before Stop(). This is based on the
335 // assumption that we never accept Seek() after Stop(). 306 // assumption that we never accept Seek() after Stop().
336 DCHECK(IsPipelineSeeking() || 307 DCHECK(IsPipelineSeeking() ||
337 !stop_cb_.is_null() || 308 !stop_cb_.is_null() ||
338 IsPipelineTearingDown()); 309 tearing_down_);
339 return IsPipelineSeeking() ? kSeeking : kStopping; 310 return IsPipelineSeeking() ? kSeeking : kStopping;
340 } else if (current == kSeeking) { 311 } else if (current == kSeeking) {
341 return kStarting; 312 return kStarting;
342 } else if (current == kStarting) { 313 } else if (current == kStarting) {
343 return kStarted; 314 return kStarted;
344 } else if (current == kStopping) { 315 } else if (current == kStopping) {
345 return error_caused_teardown_ ? kError : kStopped; 316 return kStopped;
346 } else { 317 } else {
347 return current; 318 return current;
348 } 319 }
349 } 320 }
350 321
351 void Pipeline::OnDemuxerError(PipelineStatus error) { 322 void Pipeline::OnDemuxerError(PipelineStatus error) {
352 SetError(error); 323 SetError(error);
353 } 324 }
354 325
355 void Pipeline::SetError(PipelineStatus error) { 326 void Pipeline::SetError(PipelineStatus error) {
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 if (state_ == kInitVideoDecoder && 588 if (state_ == kInitVideoDecoder &&
618 last_stage_status == DECODER_ERROR_NOT_SUPPORTED) { 589 last_stage_status == DECODER_ERROR_NOT_SUPPORTED) {
619 state_ = kInitAudioRenderer; 590 state_ = kInitAudioRenderer;
620 } else { 591 } else {
621 SetError(last_stage_status); 592 SetError(last_stage_status);
622 return; 593 return;
623 } 594 }
624 } 595 }
625 596
626 // If we have received the stop or error signal, return immediately. 597 // If we have received the stop or error signal, return immediately.
627 if (!stop_cb_.is_null() || IsPipelineStopped() || !IsPipelineOk()) 598 if (!stop_cb_.is_null() || state_ == kStopped || !IsPipelineOk())
628 return; 599 return;
629 600
630 DCHECK(state_ == kInitDemuxer || 601 DCHECK(state_ == kInitDemuxer ||
631 state_ == kInitAudioDecoder || 602 state_ == kInitAudioDecoder ||
632 state_ == kInitAudioRenderer || 603 state_ == kInitAudioRenderer ||
633 state_ == kInitVideoDecoder || 604 state_ == kInitVideoDecoder ||
634 state_ == kInitVideoRenderer); 605 state_ == kInitVideoRenderer);
635 606
636 // Demuxer created, create audio decoder. 607 // Demuxer created, create audio decoder.
637 if (state_ == kInitDemuxer) { 608 if (state_ == kInitDemuxer) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 // This method is called as a result of the client calling Pipeline::Stop() or 670 // This method is called as a result of the client calling Pipeline::Stop() or
700 // as the result of an error condition. 671 // as the result of an error condition.
701 // We stop the filters in the reverse order. 672 // We stop the filters in the reverse order.
702 // 673 //
703 // TODO(scherkus): beware! this can get posted multiple times since we post 674 // TODO(scherkus): beware! this can get posted multiple times since we post
704 // Stop() tasks even if we've already stopped. Perhaps this should no-op for 675 // Stop() tasks even if we've already stopped. Perhaps this should no-op for
705 // additional calls, however most of this logic will be changing. 676 // additional calls, however most of this logic will be changing.
706 void Pipeline::StopTask(const base::Closure& stop_cb) { 677 void Pipeline::StopTask(const base::Closure& stop_cb) {
707 DCHECK(message_loop_->BelongsToCurrentThread()); 678 DCHECK(message_loop_->BelongsToCurrentThread());
708 DCHECK(stop_cb_.is_null()); 679 DCHECK(stop_cb_.is_null());
709 DCHECK_NE(state_, kStopped); 680
681 if (state_ == kStopped) {
682 stop_cb.Run();
683 return;
684 }
710 685
711 if (video_decoder_) { 686 if (video_decoder_) {
712 video_decoder_->PrepareForShutdownHack(); 687 video_decoder_->PrepareForShutdownHack();
713 video_decoder_ = NULL; 688 video_decoder_ = NULL;
714 } 689 }
715 690
716 if (IsPipelineTearingDown() && error_caused_teardown_) { 691 if (tearing_down_ && status_ != PIPELINE_OK) {
717 // If we are stopping due to SetError(), stop normally instead of 692 // If we are stopping due to SetError(), stop normally instead of
718 // going to error state and calling |error_cb_|. This converts 693 // going to error state and calling |error_cb_|. This converts
719 // the teardown in progress from an error teardown into one that acts 694 // the teardown in progress from an error teardown into one that acts
720 // like the error never occurred. 695 // like the error never occurred.
Ami GONE FROM CHROMIUM 2012/08/09 20:55:41 This seems crazy. Why do we want this?
scherkus (not reviewing) 2012/08/09 22:07:49 It _is_ a bit crazy but not _that_ crazy -- it bas
721 base::AutoLock auto_lock(lock_); 696 base::AutoLock auto_lock(lock_);
722 status_ = PIPELINE_OK; 697 status_ = PIPELINE_OK;
723 error_caused_teardown_ = false;
724 } 698 }
725 699
726 stop_cb_ = stop_cb; 700 stop_cb_ = stop_cb;
727 701
728 if (!IsPipelineSeeking() && !IsPipelineTearingDown()) { 702 if (!IsPipelineSeeking() && !tearing_down_) {
729 // We will tear down pipeline immediately when there is no seek operation 703 // We will tear down pipeline immediately when there is no seek operation
730 // pending and no teardown in progress. This should include the case where 704 // pending and no teardown in progress. This should include the case where
731 // we are partially initialized. 705 // we are partially initialized.
732 TearDownPipeline(); 706 TearDownPipeline();
733 } 707 }
734 } 708 }
735 709
736 void Pipeline::ErrorChangedTask(PipelineStatus error) { 710 void Pipeline::ErrorChangedTask(PipelineStatus error) {
737 DCHECK(message_loop_->BelongsToCurrentThread()); 711 DCHECK(message_loop_->BelongsToCurrentThread());
738 DCHECK_NE(PIPELINE_OK, error) << "PIPELINE_OK isn't an error!"; 712 DCHECK_NE(PIPELINE_OK, error) << "PIPELINE_OK isn't an error!";
739 713
740 // Suppress executing additional error logic. Note that if we are currently 714 // Suppress executing additional error logic. Note that if we are currently
741 // performing a normal stop, then we return immediately and continue the 715 // performing a normal stop, then we return immediately and continue the
742 // normal stop. 716 // normal stop.
743 if (IsPipelineStopped() || IsPipelineTearingDown()) { 717 if (state_ == kStopped || tearing_down_) {
744 return; 718 return;
745 } 719 }
746 720
747 base::AutoLock auto_lock(lock_); 721 base::AutoLock auto_lock(lock_);
748 status_ = error; 722 status_ = error;
749 723
750 error_caused_teardown_ = true;
751
752 // Posting TearDownPipeline() to message loop so that we can make sure 724 // Posting TearDownPipeline() to message loop so that we can make sure
753 // it runs after any pending callbacks that are already queued. 725 // it runs after any pending callbacks that are already queued.
754 // |tearing_down_| is set early here to make sure that pending callbacks 726 // |tearing_down_| is set early here to make sure that pending callbacks
755 // don't modify the state before TeadDownPipeline() can run. 727 // don't modify the state before TearDownPipeline() can run.
756 tearing_down_ = true; 728 tearing_down_ = true;
757 message_loop_->PostTask(FROM_HERE, base::Bind( 729 message_loop_->PostTask(FROM_HERE, base::Bind(
758 &Pipeline::TearDownPipeline, this)); 730 &Pipeline::TearDownPipeline, this));
759 } 731 }
760 732
761 void Pipeline::PlaybackRateChangedTask(float playback_rate) { 733 void Pipeline::PlaybackRateChangedTask(float playback_rate) {
762 DCHECK(message_loop_->BelongsToCurrentThread()); 734 DCHECK(message_loop_->BelongsToCurrentThread());
763 735
764 if (!running_ || tearing_down_) 736 if (!running_ || tearing_down_)
Ami GONE FROM CHROMIUM 2012/08/09 20:55:41 This (and other places) read running_ not under lo
scherkus (not reviewing) 2012/08/09 22:07:49 probably not!
765 return; 737 return;
766 738
767 // Suppress rate change until after seeking. 739 // Suppress rate change until after seeking.
768 if (IsPipelineSeeking()) { 740 if (IsPipelineSeeking()) {
769 pending_playback_rate_ = playback_rate; 741 pending_playback_rate_ = playback_rate;
770 playback_rate_change_pending_ = true; 742 playback_rate_change_pending_ = true;
771 return; 743 return;
772 } 744 }
773 745
774 { 746 {
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 clock_->SetMaxTime(clock_->Duration()); 868 clock_->SetMaxTime(clock_->Duration());
897 StartClockIfWaitingForTimeUpdate_Locked(); 869 StartClockIfWaitingForTimeUpdate_Locked();
898 } 870 }
899 871
900 void Pipeline::FilterStateTransitionTask() { 872 void Pipeline::FilterStateTransitionTask() {
901 DCHECK(message_loop_->BelongsToCurrentThread()); 873 DCHECK(message_loop_->BelongsToCurrentThread());
902 DCHECK(pending_callbacks_.get()) 874 DCHECK(pending_callbacks_.get())
903 << "Filter state transitions must be completed via pending_callbacks_"; 875 << "Filter state transitions must be completed via pending_callbacks_";
904 pending_callbacks_.reset(); 876 pending_callbacks_.reset();
905 877
906 // No reason transitioning if we've errored or have stopped. 878 // No reason transitioning if we're stopped or tearing down as teardown
Ami GONE FROM CHROMIUM 2012/08/09 20:55:41 English this up.
scherkus (not reviewing) 2012/08/09 22:07:49 Done.
907 if (IsPipelineStopped()) { 879 // state transitions are handled via TeardownStateTransitionTask().
880 //
881 // TODO(scherkus): Merge all state machinery!
882 if (state_ == kStopped || tearing_down_) {
908 return; 883 return;
909 } 884 }
910 885
911 // If we are tearing down, don't allow any state changes. Teardown
912 // state changes will come in via TeardownStateTransitionTask().
913 if (IsPipelineTearingDown()) {
914 return;
915 }
916
917 if (!TransientState(state_)) { 886 if (!TransientState(state_)) {
918 NOTREACHED() << "Invalid current state: " << state_; 887 NOTREACHED() << "Invalid current state: " << state_;
919 SetError(PIPELINE_ERROR_ABORT); 888 SetError(PIPELINE_ERROR_ABORT);
920 return; 889 return;
921 } 890 }
922 891
923 // Decrement the number of remaining transitions, making sure to transition 892 // Decrement the number of remaining transitions, making sure to transition
924 // to the next state if needed. 893 // to the next state if needed.
925 SetState(FindNextState(state_)); 894 SetState(FindNextState(state_));
926 if (state_ == kSeeking) { 895 if (state_ == kSeeking) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
970 // Check if we have a pending stop request that needs to be honored. 939 // Check if we have a pending stop request that needs to be honored.
971 if (!stop_cb_.is_null()) { 940 if (!stop_cb_.is_null()) {
972 TearDownPipeline(); 941 TearDownPipeline();
973 } 942 }
974 } else { 943 } else {
975 NOTREACHED() << "Unexpected state: " << state_; 944 NOTREACHED() << "Unexpected state: " << state_;
976 } 945 }
977 } 946 }
978 947
979 void Pipeline::TeardownStateTransitionTask() { 948 void Pipeline::TeardownStateTransitionTask() {
980 DCHECK(IsPipelineTearingDown()); 949 DCHECK(tearing_down_);
981 DCHECK(pending_callbacks_.get()) 950 DCHECK(pending_callbacks_.get())
982 << "Teardown state transitions must be completed via pending_callbacks_"; 951 << "Teardown state transitions must be completed via pending_callbacks_";
983 pending_callbacks_.reset(); 952 pending_callbacks_.reset();
984 953
985 switch (state_) { 954 switch (state_) {
986 case kStopping: 955 case kStopping:
987 SetState(error_caused_teardown_ ? kError : kStopped); 956 SetState(kStopped);
988 FinishDestroyingFiltersTask(); 957 FinishDestroyingFiltersTask();
989 break; 958 break;
990 case kPausing: 959 case kPausing:
991 SetState(kFlushing); 960 SetState(kFlushing);
992 DoFlush(base::Bind(&Pipeline::OnTeardownStateTransition, this)); 961 DoFlush(base::Bind(&Pipeline::OnTeardownStateTransition, this));
993 break; 962 break;
994 case kFlushing: 963 case kFlushing:
995 SetState(kStopping); 964 SetState(kStopping);
996 DoStop(base::Bind(&Pipeline::OnTeardownStateTransition, this)); 965 DoStop(base::Bind(&Pipeline::OnTeardownStateTransition, this));
997 break; 966 break;
998 967
999 case kCreated: 968 case kCreated:
1000 case kError:
1001 case kInitDemuxer: 969 case kInitDemuxer:
1002 case kInitAudioDecoder: 970 case kInitAudioDecoder:
1003 case kInitAudioRenderer: 971 case kInitAudioRenderer:
1004 case kInitVideoDecoder: 972 case kInitVideoDecoder:
1005 case kInitVideoRenderer: 973 case kInitVideoRenderer:
1006 case kSeeking: 974 case kSeeking:
1007 case kStarting: 975 case kStarting:
1008 case kStopped: 976 case kStopped:
1009 case kStarted: 977 case kStarted:
1010 NOTREACHED() << "Unexpected state for teardown: " << state_; 978 NOTREACHED() << "Unexpected state for teardown: " << state_;
1011 break; 979 break;
1012 // default: intentionally left out to force new states to cause compiler 980 // default: intentionally left out to force new states to cause compiler
1013 // errors. 981 // errors.
1014 }; 982 };
1015 } 983 }
1016 984
1017 void Pipeline::FinishDestroyingFiltersTask() { 985 void Pipeline::FinishDestroyingFiltersTask() {
1018 DCHECK(message_loop_->BelongsToCurrentThread()); 986 DCHECK(message_loop_->BelongsToCurrentThread());
1019 DCHECK(IsPipelineStopped()); 987 DCHECK_EQ(state_, kStopped);
1020 988
1021 audio_renderer_ = NULL; 989 audio_renderer_ = NULL;
1022 video_renderer_ = NULL; 990 video_renderer_ = NULL;
1023 demuxer_ = NULL; 991 demuxer_ = NULL;
992 tearing_down_ = false;
993 {
994 base::AutoLock l(lock_);
995 running_ = false;
996 }
1024 997
1025 if (error_caused_teardown_ && !IsPipelineOk() && !error_cb_.is_null()) 998 if (!IsPipelineOk() && !error_cb_.is_null())
1026 error_cb_.Run(status_); 999 error_cb_.Run(status_);
1027 1000
1028 if (!stop_cb_.is_null()) { 1001 if (!stop_cb_.is_null())
1029 {
1030 base::AutoLock l(lock_);
1031 running_ = false;
1032 }
1033
1034 // Notify the client that stopping has finished.
1035 base::ResetAndReturn(&stop_cb_).Run(); 1002 base::ResetAndReturn(&stop_cb_).Run();
1036 }
1037
1038 tearing_down_ = false;
1039 error_caused_teardown_ = false;
1040 } 1003 }
1041 1004
1042 void Pipeline::InitializeDemuxer() { 1005 void Pipeline::InitializeDemuxer() {
1043 DCHECK(message_loop_->BelongsToCurrentThread()); 1006 DCHECK(message_loop_->BelongsToCurrentThread());
1044 DCHECK(IsPipelineOk()); 1007 DCHECK(IsPipelineOk());
1045 1008
1046 demuxer_ = filter_collection_->GetDemuxer(); 1009 demuxer_ = filter_collection_->GetDemuxer();
1047 if (!demuxer_) { 1010 if (!demuxer_) {
1048 SetError(PIPELINE_ERROR_REQUIRED_FILTER_MISSING); 1011 SetError(PIPELINE_ERROR_REQUIRED_FILTER_MISSING);
1049 return; 1012 return;
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1182 1145
1183 void Pipeline::TearDownPipeline() { 1146 void Pipeline::TearDownPipeline() {
1184 DCHECK(message_loop_->BelongsToCurrentThread()); 1147 DCHECK(message_loop_->BelongsToCurrentThread());
1185 DCHECK_NE(kStopped, state_); 1148 DCHECK_NE(kStopped, state_);
1186 1149
1187 // We're either... 1150 // We're either...
1188 // 1) ...tearing down due to Stop() (it doesn't set tearing_down_) 1151 // 1) ...tearing down due to Stop() (it doesn't set tearing_down_)
1189 // 2) ...tearing down due to an error (it does set tearing_down_) 1152 // 2) ...tearing down due to an error (it does set tearing_down_)
1190 // 3) ...tearing down due to an error and Stop() was called during that time 1153 // 3) ...tearing down due to an error and Stop() was called during that time
1191 DCHECK(!tearing_down_ || 1154 DCHECK(!tearing_down_ ||
1192 (tearing_down_ && error_caused_teardown_) || 1155 (tearing_down_ && status_ != PIPELINE_OK) ||
1193 (tearing_down_ && !stop_cb_.is_null())); 1156 (tearing_down_ && !stop_cb_.is_null()));
1194 1157
1195 // Mark that we already start tearing down operation. 1158 // Mark that we already start tearing down operation.
1196 tearing_down_ = true; 1159 tearing_down_ = true;
1197 1160
1198 // Cancel any pending operation so we can proceed with teardown. 1161 // Cancel any pending operation so we can proceed with teardown.
1199 pending_callbacks_.reset(); 1162 pending_callbacks_.reset();
1200 1163
1201 switch (state_) { 1164 switch (state_) {
1202 case kCreated: 1165 case kCreated:
1203 case kError:
1204 SetState(kStopped); 1166 SetState(kStopped);
1205 // Need to put this in the message loop to make sure that it comes 1167 // Need to put this in the message loop to make sure that it comes
1206 // after any pending callback tasks that are already queued. 1168 // after any pending callback tasks that are already queued.
1207 message_loop_->PostTask(FROM_HERE, base::Bind( 1169 message_loop_->PostTask(FROM_HERE, base::Bind(
1208 &Pipeline::FinishDestroyingFiltersTask, this)); 1170 &Pipeline::FinishDestroyingFiltersTask, this));
1209 break; 1171 break;
1210 1172
1211 case kInitDemuxer: 1173 case kInitDemuxer:
1212 case kInitAudioDecoder: 1174 case kInitAudioDecoder:
1213 case kInitAudioRenderer: 1175 case kInitAudioRenderer:
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1293 void Pipeline::StartClockIfWaitingForTimeUpdate_Locked() { 1255 void Pipeline::StartClockIfWaitingForTimeUpdate_Locked() {
1294 lock_.AssertAcquired(); 1256 lock_.AssertAcquired();
1295 if (!waiting_for_clock_update_) 1257 if (!waiting_for_clock_update_)
1296 return; 1258 return;
1297 1259
1298 waiting_for_clock_update_ = false; 1260 waiting_for_clock_update_ = false;
1299 clock_->Play(); 1261 clock_->Play();
1300 } 1262 }
1301 1263
1302 } // namespace media 1264 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698