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

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

Issue 11148011: Move audio decoder initialization to AudioRendererImpl. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: nits Created 8 years, 2 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
« no previous file with comments | « media/base/pipeline.h ('k') | media/base/pipeline_unittest.cc » ('j') | 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"
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 state_ = next_state; 257 state_ = next_state;
258 media_log_->AddEvent(media_log_->CreatePipelineStateChangedEvent(next_state)); 258 media_log_->AddEvent(media_log_->CreatePipelineStateChangedEvent(next_state));
259 } 259 }
260 260
261 #define RETURN_STRING(state) case state: return #state; 261 #define RETURN_STRING(state) case state: return #state;
262 262
263 const char* Pipeline::GetStateString(State state) { 263 const char* Pipeline::GetStateString(State state) {
264 switch (state) { 264 switch (state) {
265 RETURN_STRING(kCreated); 265 RETURN_STRING(kCreated);
266 RETURN_STRING(kInitDemuxer); 266 RETURN_STRING(kInitDemuxer);
267 RETURN_STRING(kInitAudioDecoder);
268 RETURN_STRING(kInitAudioRenderer); 267 RETURN_STRING(kInitAudioRenderer);
269 RETURN_STRING(kInitVideoRenderer); 268 RETURN_STRING(kInitVideoRenderer);
270 RETURN_STRING(kInitPrerolling); 269 RETURN_STRING(kInitPrerolling);
271 RETURN_STRING(kSeeking); 270 RETURN_STRING(kSeeking);
272 RETURN_STRING(kStarting); 271 RETURN_STRING(kStarting);
273 RETURN_STRING(kStarted); 272 RETURN_STRING(kStarted);
274 RETURN_STRING(kStopping); 273 RETURN_STRING(kStopping);
275 RETURN_STRING(kStopped); 274 RETURN_STRING(kStopped);
276 } 275 }
277 NOTREACHED(); 276 NOTREACHED();
278 return "INVALID"; 277 return "INVALID";
279 } 278 }
280 279
281 #undef RETURN_STRING 280 #undef RETURN_STRING
282 281
283 Pipeline::State Pipeline::GetNextState() const { 282 Pipeline::State Pipeline::GetNextState() const {
284 DCHECK(message_loop_->BelongsToCurrentThread()); 283 DCHECK(message_loop_->BelongsToCurrentThread());
285 DCHECK(stop_cb_.is_null()) 284 DCHECK(stop_cb_.is_null())
286 << "State transitions don't happen when stopping"; 285 << "State transitions don't happen when stopping";
287 DCHECK_EQ(status_, PIPELINE_OK) 286 DCHECK_EQ(status_, PIPELINE_OK)
288 << "State transitions don't happen when there's an error: " << status_; 287 << "State transitions don't happen when there's an error: " << status_;
289 288
290 switch (state_) { 289 switch (state_) {
291 case kCreated: 290 case kCreated:
292 return kInitDemuxer; 291 return kInitDemuxer;
293 292
294 case kInitDemuxer: 293 case kInitDemuxer:
295 if (demuxer_->GetStream(DemuxerStream::AUDIO)) 294 if (demuxer_->GetStream(DemuxerStream::AUDIO))
296 return kInitAudioDecoder; 295 return kInitAudioRenderer;
297 if (demuxer_->GetStream(DemuxerStream::VIDEO)) 296 if (demuxer_->GetStream(DemuxerStream::VIDEO))
298 return kInitVideoRenderer; 297 return kInitVideoRenderer;
299 return kInitPrerolling; 298 return kInitPrerolling;
300 299
301 case kInitAudioDecoder:
302 return kInitAudioRenderer;
303
304 case kInitAudioRenderer: 300 case kInitAudioRenderer:
305 if (demuxer_->GetStream(DemuxerStream::VIDEO)) 301 if (demuxer_->GetStream(DemuxerStream::VIDEO))
306 return kInitVideoRenderer; 302 return kInitVideoRenderer;
307 return kInitPrerolling; 303 return kInitPrerolling;
308 304
309 case kInitVideoRenderer: 305 case kInitVideoRenderer:
310 return kInitPrerolling; 306 return kInitPrerolling;
311 307
312 case kInitPrerolling: 308 case kInitPrerolling:
313 return kStarting; 309 return kStarting;
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 pending_callbacks_.reset(); 453 pending_callbacks_.reset();
458 454
459 PipelineStatusCB done_cb = base::Bind(&Pipeline::OnStateTransition, this); 455 PipelineStatusCB done_cb = base::Bind(&Pipeline::OnStateTransition, this);
460 456
461 // Switch states, performing any entrance actions for the new state as well. 457 // Switch states, performing any entrance actions for the new state as well.
462 SetState(GetNextState()); 458 SetState(GetNextState());
463 switch (state_) { 459 switch (state_) {
464 case kInitDemuxer: 460 case kInitDemuxer:
465 return InitializeDemuxer(done_cb); 461 return InitializeDemuxer(done_cb);
466 462
467 case kInitAudioDecoder:
468 return InitializeAudioDecoder(done_cb);
469
470 case kInitAudioRenderer: 463 case kInitAudioRenderer:
471 return InitializeAudioRenderer(done_cb); 464 return InitializeAudioRenderer(done_cb);
472 465
473 case kInitVideoRenderer: 466 case kInitVideoRenderer:
474 return InitializeVideoRenderer(done_cb); 467 return InitializeVideoRenderer(done_cb);
475 468
476 case kInitPrerolling: 469 case kInitPrerolling:
477 filter_collection_.reset(); 470 filter_collection_.reset();
478 { 471 {
479 base::AutoLock l(lock_); 472 base::AutoLock l(lock_);
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 DCHECK(message_loop_->BelongsToCurrentThread()); 619 DCHECK(message_loop_->BelongsToCurrentThread());
627 DCHECK_EQ(state_, kStopping); 620 DCHECK_EQ(state_, kStopping);
628 { 621 {
629 base::AutoLock l(lock_); 622 base::AutoLock l(lock_);
630 running_ = false; 623 running_ = false;
631 } 624 }
632 625
633 SetState(kStopped); 626 SetState(kStopped);
634 pending_callbacks_.reset(); 627 pending_callbacks_.reset();
635 filter_collection_.reset(); 628 filter_collection_.reset();
636 audio_decoder_ = NULL;
637 audio_renderer_ = NULL; 629 audio_renderer_ = NULL;
638 video_renderer_ = NULL; 630 video_renderer_ = NULL;
639 demuxer_ = NULL; 631 demuxer_ = NULL;
640 632
641 // If we stop during initialization/seeking we want to run |seek_cb_| 633 // If we stop during initialization/seeking we want to run |seek_cb_|
642 // followed by |stop_cb_| so we don't leave outstanding callbacks around. 634 // followed by |stop_cb_| so we don't leave outstanding callbacks around.
643 if (!seek_cb_.is_null()) { 635 if (!seek_cb_.is_null()) {
644 base::ResetAndReturn(&seek_cb_).Run(status_); 636 base::ResetAndReturn(&seek_cb_).Run(status_);
645 error_cb_.Reset(); 637 error_cb_.Reset();
646 } 638 }
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
879 StartClockIfWaitingForTimeUpdate_Locked(); 871 StartClockIfWaitingForTimeUpdate_Locked();
880 } 872 }
881 873
882 void Pipeline::InitializeDemuxer(const PipelineStatusCB& done_cb) { 874 void Pipeline::InitializeDemuxer(const PipelineStatusCB& done_cb) {
883 DCHECK(message_loop_->BelongsToCurrentThread()); 875 DCHECK(message_loop_->BelongsToCurrentThread());
884 876
885 demuxer_ = filter_collection_->GetDemuxer(); 877 demuxer_ = filter_collection_->GetDemuxer();
886 demuxer_->Initialize(this, done_cb); 878 demuxer_->Initialize(this, done_cb);
887 } 879 }
888 880
889 void Pipeline::InitializeAudioDecoder(const PipelineStatusCB& done_cb) { 881 void Pipeline::InitializeAudioRenderer(const PipelineStatusCB& done_cb) {
890 DCHECK(message_loop_->BelongsToCurrentThread()); 882 DCHECK(message_loop_->BelongsToCurrentThread());
891 883
892 scoped_refptr<DemuxerStream> stream = 884 scoped_refptr<DemuxerStream> stream =
893 demuxer_->GetStream(DemuxerStream::AUDIO); 885 demuxer_->GetStream(DemuxerStream::AUDIO);
894 DCHECK(stream); 886 DCHECK(stream);
895 887
896 filter_collection_->SelectAudioDecoder(&audio_decoder_);
897 audio_decoder_->Initialize(
898 stream, done_cb, base::Bind(&Pipeline::OnUpdateStatistics, this));
899 }
900
901 void Pipeline::InitializeAudioRenderer(const PipelineStatusCB& done_cb) {
902 DCHECK(message_loop_->BelongsToCurrentThread());
903 DCHECK(audio_decoder_);
904
905 filter_collection_->SelectAudioRenderer(&audio_renderer_); 888 filter_collection_->SelectAudioRenderer(&audio_renderer_);
906 audio_renderer_->Initialize( 889 audio_renderer_->Initialize(
907 audio_decoder_, 890 stream,
891 *filter_collection_->GetAudioDecoders(),
908 done_cb, 892 done_cb,
893 base::Bind(&Pipeline::OnUpdateStatistics, this),
909 base::Bind(&Pipeline::OnAudioUnderflow, this), 894 base::Bind(&Pipeline::OnAudioUnderflow, this),
910 base::Bind(&Pipeline::OnAudioTimeUpdate, this), 895 base::Bind(&Pipeline::OnAudioTimeUpdate, this),
911 base::Bind(&Pipeline::OnAudioRendererEnded, this), 896 base::Bind(&Pipeline::OnAudioRendererEnded, this),
912 base::Bind(&Pipeline::OnAudioDisabled, this), 897 base::Bind(&Pipeline::OnAudioDisabled, this),
913 base::Bind(&Pipeline::SetError, this)); 898 base::Bind(&Pipeline::SetError, this));
899 filter_collection_->GetAudioDecoders()->clear();
914 } 900 }
915 901
916 void Pipeline::InitializeVideoRenderer(const PipelineStatusCB& done_cb) { 902 void Pipeline::InitializeVideoRenderer(const PipelineStatusCB& done_cb) {
917 DCHECK(message_loop_->BelongsToCurrentThread()); 903 DCHECK(message_loop_->BelongsToCurrentThread());
918 904
919 scoped_refptr<DemuxerStream> stream = 905 scoped_refptr<DemuxerStream> stream =
920 demuxer_->GetStream(DemuxerStream::VIDEO); 906 demuxer_->GetStream(DemuxerStream::VIDEO);
921 DCHECK(stream); 907 DCHECK(stream);
922 908
923 { 909 {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
959 void Pipeline::StartClockIfWaitingForTimeUpdate_Locked() { 945 void Pipeline::StartClockIfWaitingForTimeUpdate_Locked() {
960 lock_.AssertAcquired(); 946 lock_.AssertAcquired();
961 if (!waiting_for_clock_update_) 947 if (!waiting_for_clock_update_)
962 return; 948 return;
963 949
964 waiting_for_clock_update_ = false; 950 waiting_for_clock_update_ = false;
965 clock_->Play(); 951 clock_->Play();
966 } 952 }
967 953
968 } // namespace media 954 } // namespace media
OLDNEW
« no previous file with comments | « media/base/pipeline.h ('k') | media/base/pipeline_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698