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

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

Issue 10918022: Move AudioDecoder initialization into AudioRenderer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 state_ = next_state; 253 state_ = next_state;
254 media_log_->AddEvent(media_log_->CreatePipelineStateChangedEvent(next_state)); 254 media_log_->AddEvent(media_log_->CreatePipelineStateChangedEvent(next_state));
255 } 255 }
256 256
257 #define RETURN_STRING(state) case state: return #state; 257 #define RETURN_STRING(state) case state: return #state;
258 258
259 const char* Pipeline::GetStateString(State state) { 259 const char* Pipeline::GetStateString(State state) {
260 switch (state) { 260 switch (state) {
261 RETURN_STRING(kCreated); 261 RETURN_STRING(kCreated);
262 RETURN_STRING(kInitDemuxer); 262 RETURN_STRING(kInitDemuxer);
263 RETURN_STRING(kInitAudioDecoder);
264 RETURN_STRING(kInitAudioRenderer); 263 RETURN_STRING(kInitAudioRenderer);
265 RETURN_STRING(kInitVideoRenderer); 264 RETURN_STRING(kInitVideoRenderer);
266 RETURN_STRING(kInitPrerolling); 265 RETURN_STRING(kInitPrerolling);
267 RETURN_STRING(kSeeking); 266 RETURN_STRING(kSeeking);
268 RETURN_STRING(kStarting); 267 RETURN_STRING(kStarting);
269 RETURN_STRING(kStarted); 268 RETURN_STRING(kStarted);
270 RETURN_STRING(kStopping); 269 RETURN_STRING(kStopping);
271 RETURN_STRING(kStopped); 270 RETURN_STRING(kStopped);
272 } 271 }
273 NOTREACHED(); 272 NOTREACHED();
274 return "INVALID"; 273 return "INVALID";
275 } 274 }
276 275
277 #undef RETURN_STRING 276 #undef RETURN_STRING
278 277
279 Pipeline::State Pipeline::GetNextState() const { 278 Pipeline::State Pipeline::GetNextState() const {
280 DCHECK(message_loop_->BelongsToCurrentThread()); 279 DCHECK(message_loop_->BelongsToCurrentThread());
281 DCHECK(stop_cb_.is_null()) 280 DCHECK(stop_cb_.is_null())
282 << "State transitions don't happen when stopping"; 281 << "State transitions don't happen when stopping";
283 DCHECK_EQ(status_, PIPELINE_OK) 282 DCHECK_EQ(status_, PIPELINE_OK)
284 << "State transitions don't happen when there's an error: " << status_; 283 << "State transitions don't happen when there's an error: " << status_;
285 284
286 switch (state_) { 285 switch (state_) {
287 case kCreated: 286 case kCreated:
288 return kInitDemuxer; 287 return kInitDemuxer;
289 288
290 case kInitDemuxer: 289 case kInitDemuxer:
291 if (demuxer_->GetStream(DemuxerStream::AUDIO)) 290 if (demuxer_->GetStream(DemuxerStream::AUDIO))
292 return kInitAudioDecoder; 291 return kInitAudioRenderer;
293 if (demuxer_->GetStream(DemuxerStream::VIDEO)) 292 if (demuxer_->GetStream(DemuxerStream::VIDEO))
294 return kInitVideoRenderer; 293 return kInitVideoRenderer;
295 return kInitPrerolling; 294 return kInitPrerolling;
296 295
297 case kInitAudioDecoder:
298 return kInitAudioRenderer;
299
300 case kInitAudioRenderer: 296 case kInitAudioRenderer:
301 if (demuxer_->GetStream(DemuxerStream::VIDEO)) 297 if (demuxer_->GetStream(DemuxerStream::VIDEO))
302 return kInitVideoRenderer; 298 return kInitVideoRenderer;
303 return kInitPrerolling; 299 return kInitPrerolling;
304 300
305 case kInitVideoRenderer: 301 case kInitVideoRenderer:
306 return kInitPrerolling; 302 return kInitPrerolling;
307 303
308 case kInitPrerolling: 304 case kInitPrerolling:
309 return kStarting; 305 return kStarting;
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 pending_callbacks_.reset(); 445 pending_callbacks_.reset();
450 446
451 PipelineStatusCB done_cb = base::Bind(&Pipeline::OnStateTransition, this); 447 PipelineStatusCB done_cb = base::Bind(&Pipeline::OnStateTransition, this);
452 448
453 // Switch states, performing any entrance actions for the new state as well. 449 // Switch states, performing any entrance actions for the new state as well.
454 SetState(GetNextState()); 450 SetState(GetNextState());
455 switch (state_) { 451 switch (state_) {
456 case kInitDemuxer: 452 case kInitDemuxer:
457 return InitializeDemuxer(done_cb); 453 return InitializeDemuxer(done_cb);
458 454
459 case kInitAudioDecoder:
460 return InitializeAudioDecoder(done_cb);
461
462 case kInitAudioRenderer: 455 case kInitAudioRenderer:
463 return InitializeAudioRenderer(done_cb); 456 return InitializeAudioRenderer(done_cb);
464 457
465 case kInitVideoRenderer: 458 case kInitVideoRenderer:
466 return InitializeVideoRenderer(done_cb); 459 return InitializeVideoRenderer(done_cb);
467 460
468 case kInitPrerolling: 461 case kInitPrerolling:
469 filter_collection_.reset(); 462 filter_collection_.reset();
470 { 463 {
471 base::AutoLock l(lock_); 464 base::AutoLock l(lock_);
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 DCHECK(message_loop_->BelongsToCurrentThread()); 611 DCHECK(message_loop_->BelongsToCurrentThread());
619 DCHECK_EQ(state_, kStopping); 612 DCHECK_EQ(state_, kStopping);
620 { 613 {
621 base::AutoLock l(lock_); 614 base::AutoLock l(lock_);
622 running_ = false; 615 running_ = false;
623 } 616 }
624 617
625 SetState(kStopped); 618 SetState(kStopped);
626 pending_callbacks_.reset(); 619 pending_callbacks_.reset();
627 filter_collection_.reset(); 620 filter_collection_.reset();
628 audio_decoder_ = NULL;
629 audio_renderer_ = NULL; 621 audio_renderer_ = NULL;
630 video_renderer_ = NULL; 622 video_renderer_ = NULL;
631 demuxer_ = NULL; 623 demuxer_ = NULL;
632 624
633 // If we stop during initialization/seeking we want to run |seek_cb_| 625 // If we stop during initialization/seeking we want to run |seek_cb_|
634 // followed by |stop_cb_| so we don't leave outstanding callbacks around. 626 // followed by |stop_cb_| so we don't leave outstanding callbacks around.
635 if (!seek_cb_.is_null()) { 627 if (!seek_cb_.is_null()) {
636 base::ResetAndReturn(&seek_cb_).Run(status_); 628 base::ResetAndReturn(&seek_cb_).Run(status_);
637 error_cb_.Reset(); 629 error_cb_.Reset();
638 } 630 }
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 StartClockIfWaitingForTimeUpdate_Locked(); 868 StartClockIfWaitingForTimeUpdate_Locked();
877 } 869 }
878 870
879 void Pipeline::InitializeDemuxer(const PipelineStatusCB& done_cb) { 871 void Pipeline::InitializeDemuxer(const PipelineStatusCB& done_cb) {
880 DCHECK(message_loop_->BelongsToCurrentThread()); 872 DCHECK(message_loop_->BelongsToCurrentThread());
881 873
882 demuxer_ = filter_collection_->GetDemuxer(); 874 demuxer_ = filter_collection_->GetDemuxer();
883 demuxer_->Initialize(this, done_cb); 875 demuxer_->Initialize(this, done_cb);
884 } 876 }
885 877
886 void Pipeline::InitializeAudioDecoder(const PipelineStatusCB& done_cb) { 878 void Pipeline::InitializeAudioRenderer(const PipelineStatusCB& done_cb) {
887 DCHECK(message_loop_->BelongsToCurrentThread()); 879 DCHECK(message_loop_->BelongsToCurrentThread());
888 880
889 scoped_refptr<DemuxerStream> stream = 881 scoped_refptr<DemuxerStream> stream =
890 demuxer_->GetStream(DemuxerStream::AUDIO); 882 demuxer_->GetStream(DemuxerStream::AUDIO);
891 DCHECK(stream); 883 DCHECK(stream);
892 884
893 filter_collection_->SelectAudioDecoder(&audio_decoder_);
894 audio_decoder_->Initialize(
895 stream, done_cb, base::Bind(&Pipeline::OnUpdateStatistics, this));
896 }
897
898 void Pipeline::InitializeAudioRenderer(const PipelineStatusCB& done_cb) {
899 DCHECK(message_loop_->BelongsToCurrentThread());
900 DCHECK(audio_decoder_);
901
902 filter_collection_->SelectAudioRenderer(&audio_renderer_); 885 filter_collection_->SelectAudioRenderer(&audio_renderer_);
903 audio_renderer_->Initialize( 886 audio_renderer_->Initialize(
904 audio_decoder_, 887 stream,
888 *filter_collection_->GetAudioDecoders(),
905 done_cb, 889 done_cb,
890 base::Bind(&Pipeline::OnUpdateStatistics, this),
906 base::Bind(&Pipeline::OnAudioUnderflow, this), 891 base::Bind(&Pipeline::OnAudioUnderflow, this),
907 base::Bind(&Pipeline::OnAudioTimeUpdate, this), 892 base::Bind(&Pipeline::OnAudioTimeUpdate, this),
908 base::Bind(&Pipeline::OnAudioRendererEnded, this), 893 base::Bind(&Pipeline::OnAudioRendererEnded, this),
909 base::Bind(&Pipeline::OnAudioDisabled, this), 894 base::Bind(&Pipeline::OnAudioDisabled, this),
910 base::Bind(&Pipeline::SetError, this)); 895 base::Bind(&Pipeline::SetError, this));
896 filter_collection_->GetAudioDecoders()->clear();
911 } 897 }
912 898
913 void Pipeline::InitializeVideoRenderer(const PipelineStatusCB& done_cb) { 899 void Pipeline::InitializeVideoRenderer(const PipelineStatusCB& done_cb) {
914 DCHECK(message_loop_->BelongsToCurrentThread()); 900 DCHECK(message_loop_->BelongsToCurrentThread());
915 901
916 scoped_refptr<DemuxerStream> stream = 902 scoped_refptr<DemuxerStream> stream =
917 demuxer_->GetStream(DemuxerStream::VIDEO); 903 demuxer_->GetStream(DemuxerStream::VIDEO);
918 DCHECK(stream); 904 DCHECK(stream);
919 905
920 { 906 {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
956 void Pipeline::StartClockIfWaitingForTimeUpdate_Locked() { 942 void Pipeline::StartClockIfWaitingForTimeUpdate_Locked() {
957 lock_.AssertAcquired(); 943 lock_.AssertAcquired();
958 if (!waiting_for_clock_update_) 944 if (!waiting_for_clock_update_)
959 return; 945 return;
960 946
961 waiting_for_clock_update_ = false; 947 waiting_for_clock_update_ = false;
962 clock_->Play(); 948 clock_->Play();
963 } 949 }
964 950
965 } // namespace media 951 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698