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

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

Issue 9860027: Remove DemuxerFactory and URL parameter from Pipeline. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src
Patch Set: fix prerender Created 8 years, 8 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/filters/chunk_demuxer.h" 5 #include "media/filters/chunk_demuxer.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "media/base/audio_decoder_config.h" 10 #include "media/base/audio_decoder_config.h"
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 read_cbs_.pop_front(); 328 read_cbs_.pop_front();
329 } 329 }
330 330
331 ChangeState_Locked(RETURNING_EOS_FOR_READS); 331 ChangeState_Locked(RETURNING_EOS_FOR_READS);
332 } 332 }
333 333
334 ChunkDemuxer::ChunkDemuxer(ChunkDemuxerClient* client) 334 ChunkDemuxer::ChunkDemuxer(ChunkDemuxerClient* client)
335 : state_(WAITING_FOR_INIT), 335 : state_(WAITING_FOR_INIT),
336 client_(client), 336 client_(client),
337 buffered_bytes_(0), 337 buffered_bytes_(0),
338 seek_waits_for_data_(true), 338 seek_waits_for_data_(true) {
339 deferred_error_(PIPELINE_OK) {
340 DCHECK(client); 339 DCHECK(client);
341 } 340 }
342 341
343 ChunkDemuxer::~ChunkDemuxer() { 342 ChunkDemuxer::~ChunkDemuxer() {
344 DCHECK_NE(state_, INITIALIZED); 343 DCHECK_NE(state_, INITIALIZED);
345 } 344 }
346 345
347 void ChunkDemuxer::Init(const PipelineStatusCB& cb) { 346 void ChunkDemuxer::Initialize(const PipelineStatusCB& cb) {
348 DVLOG(1) << "Init()"; 347 DVLOG(1) << "Init()";
349 { 348 {
350 base::AutoLock auto_lock(lock_); 349 base::AutoLock auto_lock(lock_);
351 DCHECK_EQ(state_, WAITING_FOR_INIT); 350 DCHECK_EQ(state_, WAITING_FOR_INIT);
352 351
353 ChangeState_Locked(INITIALIZING); 352 ChangeState_Locked(INITIALIZING);
354 init_cb_ = cb; 353 init_cb_ = cb;
355 stream_parser_.reset(new WebMStreamParser()); 354 stream_parser_.reset(new WebMStreamParser());
356 355
357 stream_parser_->Init( 356 stream_parser_->Init(
358 base::Bind(&ChunkDemuxer::OnStreamParserInitDone, this), 357 base::Bind(&ChunkDemuxer::OnStreamParserInitDone, this),
359 this); 358 this);
360 } 359 }
361 360
362 client_->DemuxerOpened(this); 361 client_->DemuxerOpened(this);
363 } 362 }
364 363
365 void ChunkDemuxer::set_host(DemuxerHost* host) {
366 DCHECK(state_ == INITIALIZED || state_ == PARSE_ERROR);
367 Demuxer::set_host(host);
368 host->SetDuration(duration_);
369 host->SetCurrentReadPosition(0);
370 if (deferred_error_ != PIPELINE_OK) {
371 host->OnDemuxerError(deferred_error_);
372 deferred_error_ = PIPELINE_OK;
373 }
374 }
375
376 void ChunkDemuxer::Stop(const base::Closure& callback) { 364 void ChunkDemuxer::Stop(const base::Closure& callback) {
377 DVLOG(1) << "Stop()"; 365 DVLOG(1) << "Stop()";
378 Shutdown(); 366 Shutdown();
379 callback.Run(); 367 callback.Run();
380 } 368 }
381 369
382 void ChunkDemuxer::Seek(base::TimeDelta time, const PipelineStatusCB& cb) { 370 void ChunkDemuxer::Seek(base::TimeDelta time, const PipelineStatusCB& cb) {
383 DVLOG(1) << "Seek(" << time.InSecondsF() << ")"; 371 DVLOG(1) << "Seek(" << time.InSecondsF() << ")";
384 372
385 PipelineStatus status = PIPELINE_ERROR_INVALID_STATE; 373 PipelineStatus status = PIPELINE_ERROR_INVALID_STATE;
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 530
543 if (video_.get() && video_->GetLastBufferTimestamp(&tmp) && 531 if (video_.get() && video_->GetLastBufferTimestamp(&tmp) &&
544 tmp > buffered_ts) { 532 tmp > buffered_ts) {
545 buffered_ts = tmp; 533 buffered_ts = tmp;
546 } 534 }
547 535
548 buffered_bytes = buffered_bytes_; 536 buffered_bytes = buffered_bytes_;
549 } 537 }
550 538
551 // Notify the host of 'network activity' because we got data. 539 // Notify the host of 'network activity' because we got data.
552 if (host()) { 540 host()->SetBufferedBytes(buffered_bytes);
553 host()->SetBufferedBytes(buffered_bytes);
554 541
555 if (buffered_ts.InSeconds() >= 0) { 542 if (buffered_ts.InSeconds() >= 0) {
556 host()->SetBufferedTime(buffered_ts); 543 host()->SetBufferedTime(buffered_ts);
557 } 544 }
558 545
559 host()->SetNetworkActivity(true); 546 host()->SetNetworkActivity(true);
560 }
561 547
562 if (!cb.is_null()) 548 if (!cb.is_null())
563 cb.Run(PIPELINE_OK); 549 cb.Run(PIPELINE_OK);
564 550
565 return true; 551 return true;
566 } 552 }
567 553
568 void ChunkDemuxer::EndOfStream(PipelineStatus status) { 554 void ChunkDemuxer::EndOfStream(PipelineStatus status) {
569 DVLOG(1) << "EndOfStream(" << status << ")"; 555 DVLOG(1) << "EndOfStream(" << status << ")";
570 base::AutoLock auto_lock(lock_); 556 base::AutoLock auto_lock(lock_);
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 if (video_.get()) 641 if (video_.get())
656 video_->Shutdown(); 642 video_->Shutdown();
657 } 643 }
658 644
659 if (!cb.is_null()) { 645 if (!cb.is_null()) {
660 base::AutoUnlock auto_unlock(lock_); 646 base::AutoUnlock auto_unlock(lock_);
661 cb.Run(error); 647 cb.Run(error);
662 return; 648 return;
663 } 649 }
664 650
665 DemuxerHost* demuxer_host = host(); 651 base::AutoUnlock auto_unlock(lock_);
666 if (demuxer_host) { 652 host()->OnDemuxerError(error);
667 base::AutoUnlock auto_unlock(lock_);
668 demuxer_host->OnDemuxerError(error);
669 return;
670 }
671
672 deferred_error_ = error;
673 } 653 }
674 654
675 void ChunkDemuxer::OnStreamParserInitDone(bool success, 655 void ChunkDemuxer::OnStreamParserInitDone(bool success,
676 base::TimeDelta duration) { 656 base::TimeDelta duration) {
677 lock_.AssertAcquired(); 657 lock_.AssertAcquired();
678 DCHECK_EQ(state_, INITIALIZING); 658 DCHECK_EQ(state_, INITIALIZING);
679 if (!success || (!audio_.get() && !video_.get())) { 659 if (!success || (!audio_.get() && !video_.get())) {
680 ReportError_Locked(DEMUXER_ERROR_COULD_NOT_OPEN); 660 ReportError_Locked(DEMUXER_ERROR_COULD_NOT_OPEN);
681 return; 661 return;
682 } 662 }
683 663
684 duration_ = duration; 664 duration_ = duration;
665 host()->SetDuration(duration_);
666 host()->SetCurrentReadPosition(0);
685 667
686 ChangeState_Locked(INITIALIZED); 668 ChangeState_Locked(INITIALIZED);
687 PipelineStatusCB cb; 669 PipelineStatusCB cb;
688 std::swap(cb, init_cb_); 670 std::swap(cb, init_cb_);
689 cb.Run(PIPELINE_OK); 671 cb.Run(PIPELINE_OK);
690 } 672 }
691 673
692 bool ChunkDemuxer::OnNewAudioConfig(const AudioDecoderConfig& config) { 674 bool ChunkDemuxer::OnNewAudioConfig(const AudioDecoderConfig& config) {
693 lock_.AssertAcquired(); 675 lock_.AssertAcquired();
694 // Only allow a single audio config for now. 676 // Only allow a single audio config for now.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 if (!video_->CanAddBuffers(buffers)) 711 if (!video_->CanAddBuffers(buffers))
730 return false; 712 return false;
731 713
732 video_->AddBuffers(buffers); 714 video_->AddBuffers(buffers);
733 seek_waits_for_data_ = false; 715 seek_waits_for_data_ = false;
734 716
735 return true; 717 return true;
736 } 718 }
737 719
738 } // namespace media 720 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698