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

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

Issue 10823222: Inline media::Pipeline::ResetState() into initializer list. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src
Patch Set: forgot .h 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
« no previous file with comments | « media/base/pipeline.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 (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"
11 #include "base/callback_helpers.h" 11 #include "base/callback_helpers.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
14 #include "base/message_loop.h" 14 #include "base/message_loop.h"
15 #include "base/stl_util.h" 15 #include "base/stl_util.h"
16 #include "base/string_util.h" 16 #include "base/string_util.h"
17 #include "base/synchronization/condition_variable.h" 17 #include "base/synchronization/condition_variable.h"
18 #include "media/base/audio_decoder.h" 18 #include "media/base/audio_decoder.h"
19 #include "media/base/audio_renderer.h" 19 #include "media/base/audio_renderer.h"
20 #include "media/base/buffers.h"
scherkus (not reviewing) 2012/08/08 01:05:30 for kNoTimestamp() which surprisingly enough isn't
20 #include "media/base/clock.h" 21 #include "media/base/clock.h"
21 #include "media/base/filter_collection.h" 22 #include "media/base/filter_collection.h"
22 #include "media/base/media_log.h" 23 #include "media/base/media_log.h"
23 #include "media/base/video_decoder.h" 24 #include "media/base/video_decoder.h"
24 #include "media/base/video_renderer.h" 25 #include "media/base/video_renderer.h"
25 26
26 using base::TimeDelta; 27 using base::TimeDelta;
27 28
28 namespace media { 29 namespace media {
29 30
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 } 62 }
62 63
63 struct Pipeline::PipelineInitState { 64 struct Pipeline::PipelineInitState {
64 scoped_refptr<AudioDecoder> audio_decoder; 65 scoped_refptr<AudioDecoder> audio_decoder;
65 scoped_refptr<VideoDecoder> video_decoder; 66 scoped_refptr<VideoDecoder> video_decoder;
66 }; 67 };
67 68
68 Pipeline::Pipeline(MessageLoop* message_loop, MediaLog* media_log) 69 Pipeline::Pipeline(MessageLoop* message_loop, MediaLog* media_log)
69 : message_loop_(message_loop->message_loop_proxy()), 70 : message_loop_(message_loop->message_loop_proxy()),
70 media_log_(media_log), 71 media_log_(media_log),
72 running_(false),
73 seek_pending_(false),
acolwell GONE FROM CHROMIUM 2012/08/08 17:17:28 This is probably best left for a different CL, but
scherkus (not reviewing) 2012/08/08 17:26:59 Yeah I have parts of that done in my yet-to-be-ful
74 stop_pending_(false),
75 tearing_down_(false),
76 error_caused_teardown_(false),
77 playback_rate_change_pending_(false),
78 did_loading_progress_(false),
79 total_bytes_(0),
80 natural_size_(0, 0),
81 volume_(1.0f),
82 playback_rate_(0.0f),
83 pending_playback_rate_(0.0f),
71 clock_(new Clock(&base::Time::Now)), 84 clock_(new Clock(&base::Time::Now)),
72 waiting_for_clock_update_(false), 85 waiting_for_clock_update_(false),
86 status_(PIPELINE_OK),
87 has_audio_(false),
88 has_video_(false),
73 state_(kCreated), 89 state_(kCreated),
90 seek_timestamp_(kNoTimestamp()),
91 audio_disabled_(false),
74 creation_time_(base::Time::Now()) { 92 creation_time_(base::Time::Now()) {
75 media_log_->AddEvent(media_log_->CreatePipelineStateChangedEvent(kCreated)); 93 media_log_->AddEvent(media_log_->CreatePipelineStateChangedEvent(kCreated));
76 ResetState();
77 media_log_->AddEvent( 94 media_log_->AddEvent(
78 media_log_->CreateEvent(MediaLogEvent::PIPELINE_CREATED)); 95 media_log_->CreateEvent(MediaLogEvent::PIPELINE_CREATED));
79 } 96 }
80 97
81 Pipeline::~Pipeline() { 98 Pipeline::~Pipeline() {
82 base::AutoLock auto_lock(lock_); 99 base::AutoLock auto_lock(lock_);
83 DCHECK(!running_) << "Stop() must complete before destroying object"; 100 DCHECK(!running_) << "Stop() must complete before destroying object";
84 DCHECK(!stop_pending_); 101 DCHECK(!stop_pending_);
85 DCHECK(!seek_pending_); 102 DCHECK(!seek_pending_);
86 103
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 252
236 PipelineStatistics Pipeline::GetStatistics() const { 253 PipelineStatistics Pipeline::GetStatistics() const {
237 base::AutoLock auto_lock(lock_); 254 base::AutoLock auto_lock(lock_);
238 return statistics_; 255 return statistics_;
239 } 256 }
240 257
241 void Pipeline::SetClockForTesting(Clock* clock) { 258 void Pipeline::SetClockForTesting(Clock* clock) {
242 clock_.reset(clock); 259 clock_.reset(clock);
243 } 260 }
244 261
245 void Pipeline::ResetState() {
246 base::AutoLock auto_lock(lock_);
247 const TimeDelta kZero;
248 running_ = false;
249 stop_pending_ = false;
250 seek_pending_ = false;
251 tearing_down_ = false;
252 error_caused_teardown_ = false;
253 playback_rate_change_pending_ = false;
254 buffered_byte_ranges_.clear();
255 did_loading_progress_ = false;
256 total_bytes_ = 0;
257 natural_size_.SetSize(0, 0);
258 volume_ = 1.0f;
259 playback_rate_ = 0.0f;
260 pending_playback_rate_ = 0.0f;
261 status_ = PIPELINE_OK;
262 has_audio_ = false;
263 has_video_ = false;
264 waiting_for_clock_update_ = false;
265 audio_disabled_ = false;
266 clock_->Reset();
267 }
268
269 void Pipeline::SetState(State next_state) { 262 void Pipeline::SetState(State next_state) {
270 if (state_ != kStarted && next_state == kStarted && 263 if (state_ != kStarted && next_state == kStarted &&
271 !creation_time_.is_null()) { 264 !creation_time_.is_null()) {
272 UMA_HISTOGRAM_TIMES( 265 UMA_HISTOGRAM_TIMES(
273 "Media.TimeToPipelineStarted", base::Time::Now() - creation_time_); 266 "Media.TimeToPipelineStarted", base::Time::Now() - creation_time_);
274 creation_time_ = base::Time(); 267 creation_time_ = base::Time();
275 } 268 }
276 state_ = next_state; 269 state_ = next_state;
277 media_log_->AddEvent(media_log_->CreatePipelineStateChangedEvent(next_state)); 270 media_log_->AddEvent(media_log_->CreatePipelineStateChangedEvent(next_state));
278 } 271 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 cb.Run(status); 307 cb.Run(status);
315 // Prevent double-reporting of errors to clients. 308 // Prevent double-reporting of errors to clients.
316 if (status != PIPELINE_OK) 309 if (status != PIPELINE_OK)
317 error_cb_.Reset(); 310 error_cb_.Reset();
318 } 311 }
319 312
320 void Pipeline::FinishInitialization() { 313 void Pipeline::FinishInitialization() {
321 DCHECK(message_loop_->BelongsToCurrentThread()); 314 DCHECK(message_loop_->BelongsToCurrentThread());
322 // Execute the seek callback, if present. Note that this might be the 315 // Execute the seek callback, if present. Note that this might be the
323 // initial callback passed into Start(). 316 // initial callback passed into Start().
324 ReportStatus(seek_cb_, status_); 317 ReportStatus(seek_cb_, status_);
acolwell GONE FROM CHROMIUM 2012/08/08 17:17:28 seek_timestamp_ = kNoTimestamp()?
scherkus (not reviewing) 2012/08/08 17:26:59 Done.
325 seek_cb_.Reset(); 318 seek_cb_.Reset();
326 } 319 }
327 320
328 // static 321 // static
329 bool Pipeline::TransientState(State state) { 322 bool Pipeline::TransientState(State state) {
330 return state == kPausing || 323 return state == kPausing ||
331 state == kFlushing || 324 state == kFlushing ||
332 state == kSeeking || 325 state == kSeeking ||
333 state == kStarting || 326 state == kStarting ||
334 state == kStopping; 327 state == kStopping;
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after
907 NOTREACHED() << "Invalid current state: " << state_; 900 NOTREACHED() << "Invalid current state: " << state_;
908 SetError(PIPELINE_ERROR_ABORT); 901 SetError(PIPELINE_ERROR_ABORT);
909 return; 902 return;
910 } 903 }
911 904
912 // Decrement the number of remaining transitions, making sure to transition 905 // Decrement the number of remaining transitions, making sure to transition
913 // to the next state if needed. 906 // to the next state if needed.
914 SetState(FindNextState(state_)); 907 SetState(FindNextState(state_));
915 if (state_ == kSeeking) { 908 if (state_ == kSeeking) {
916 base::AutoLock auto_lock(lock_); 909 base::AutoLock auto_lock(lock_);
917 clock_->SetTime(seek_timestamp_, seek_timestamp_); 910 clock_->SetTime(seek_timestamp_, seek_timestamp_);
acolwell GONE FROM CHROMIUM 2012/08/08 17:17:28 DCHECK(seek_timestamp_ != kNoTimestamp());
scherkus (not reviewing) 2012/08/08 17:26:59 Done.
918 } 911 }
919 912
920 // Carry out the action for the current state. 913 // Carry out the action for the current state.
921 if (TransientState(state_)) { 914 if (TransientState(state_)) {
922 if (state_ == kPausing) { 915 if (state_ == kPausing) {
923 DoPause(base::Bind(&Pipeline::OnFilterStateTransition, this)); 916 DoPause(base::Bind(&Pipeline::OnFilterStateTransition, this));
924 } else if (state_ == kFlushing) { 917 } else if (state_ == kFlushing) {
925 DoFlush(base::Bind(&Pipeline::OnFilterStateTransition, this)); 918 DoFlush(base::Bind(&Pipeline::OnFilterStateTransition, this));
926 } else if (state_ == kSeeking) { 919 } else if (state_ == kSeeking) {
927 DoSeek(seek_timestamp_, false, 920 DoSeek(seek_timestamp_, false,
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1009 1002
1010 audio_renderer_ = NULL; 1003 audio_renderer_ = NULL;
1011 video_renderer_ = NULL; 1004 video_renderer_ = NULL;
1012 demuxer_ = NULL; 1005 demuxer_ = NULL;
1013 1006
1014 if (error_caused_teardown_ && !IsPipelineOk() && !error_cb_.is_null()) 1007 if (error_caused_teardown_ && !IsPipelineOk() && !error_cb_.is_null())
1015 error_cb_.Run(status_); 1008 error_cb_.Run(status_);
1016 1009
1017 if (stop_pending_) { 1010 if (stop_pending_) {
1018 stop_pending_ = false; 1011 stop_pending_ = false;
1019 ResetState(); 1012 {
1013 base::AutoLock l(lock_);
1014 running_ = false;
1015 }
1016
1020 // Notify the client that stopping has finished. 1017 // Notify the client that stopping has finished.
1021 base::ResetAndReturn(&stop_cb_).Run(); 1018 base::ResetAndReturn(&stop_cb_).Run();
1022 } 1019 }
1023 1020
1024 tearing_down_ = false; 1021 tearing_down_ = false;
1025 error_caused_teardown_ = false; 1022 error_caused_teardown_ = false;
1026 } 1023 }
1027 1024
1028 void Pipeline::InitializeDemuxer() { 1025 void Pipeline::InitializeDemuxer() {
1029 DCHECK(message_loop_->BelongsToCurrentThread()); 1026 DCHECK(message_loop_->BelongsToCurrentThread());
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
1276 void Pipeline::StartClockIfWaitingForTimeUpdate_Locked() { 1273 void Pipeline::StartClockIfWaitingForTimeUpdate_Locked() {
1277 lock_.AssertAcquired(); 1274 lock_.AssertAcquired();
1278 if (!waiting_for_clock_update_) 1275 if (!waiting_for_clock_update_)
1279 return; 1276 return;
1280 1277
1281 waiting_for_clock_update_ = false; 1278 waiting_for_clock_update_ = false;
1282 clock_->Play(); 1279 clock_->Play();
1283 } 1280 }
1284 1281
1285 } // namespace media 1282 } // namespace media
OLDNEW
« no previous file with comments | « media/base/pipeline.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698