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

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

Issue 8661002: Fire CanPlayThrough immediately for local and streaming media files (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix media/event-attributes.html Created 9 years 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/callback.h" 6 #include "base/callback.h"
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 FFmpegDemuxer::FFmpegDemuxer(MessageLoop* message_loop) 280 FFmpegDemuxer::FFmpegDemuxer(MessageLoop* message_loop)
281 : message_loop_(message_loop), 281 : message_loop_(message_loop),
282 format_context_(NULL), 282 format_context_(NULL),
283 read_event_(false, false), 283 read_event_(false, false),
284 read_has_failed_(false), 284 read_has_failed_(false),
285 last_read_bytes_(0), 285 last_read_bytes_(0),
286 read_position_(0), 286 read_position_(0),
287 max_duration_(base::TimeDelta::FromMicroseconds(-1)), 287 max_duration_(base::TimeDelta::FromMicroseconds(-1)),
288 deferred_status_(PIPELINE_OK), 288 deferred_status_(PIPELINE_OK),
289 first_seek_hack_(true), 289 first_seek_hack_(true),
290 start_time_(kNoTimestamp) { 290 start_time_(kNoTimestamp),
291 local_source_(false) {
291 DCHECK(message_loop_); 292 DCHECK(message_loop_);
292 } 293 }
293 294
294 FFmpegDemuxer::~FFmpegDemuxer() { 295 FFmpegDemuxer::~FFmpegDemuxer() {
295 // In this destructor, we clean up resources held by FFmpeg. It is ugly to 296 // In this destructor, we clean up resources held by FFmpeg. It is ugly to
296 // close the codec contexts here because the corresponding codecs are opened 297 // close the codec contexts here because the corresponding codecs are opened
297 // in the decoder filters. By reaching this point, all filters should have 298 // in the decoder filters. By reaching this point, all filters should have
298 // stopped, so this is the only safe place to do the global clean up. 299 // stopped, so this is the only safe place to do the global clean up.
299 // TODO(hclam): close the codecs in the corresponding decoders. 300 // TODO(hclam): close the codecs in the corresponding decoders.
300 if (!format_context_) 301 if (!format_context_)
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 // Good to go: set the duration and bitrate and notify we're done 533 // Good to go: set the duration and bitrate and notify we're done
533 // initializing. 534 // initializing.
534 if (host()) 535 if (host())
535 host()->SetDuration(max_duration); 536 host()->SetDuration(max_duration);
536 max_duration_ = max_duration; 537 max_duration_ = max_duration;
537 538
538 int bitrate = GetBitrate(); 539 int bitrate = GetBitrate();
539 if (bitrate > 0) 540 if (bitrate > 0)
540 data_source_->SetBitrate(bitrate); 541 data_source_->SetBitrate(bitrate);
541 542
543 local_source_ = data_source_->IsLocalSource();
544
542 callback.Run(PIPELINE_OK); 545 callback.Run(PIPELINE_OK);
543 } 546 }
544 547
545 int FFmpegDemuxer::GetBitrate() { 548 int FFmpegDemuxer::GetBitrate() {
546 DCHECK(format_context_); 549 DCHECK(format_context_);
547 550
548 // If there is a bitrate set on the container, use it. 551 // If there is a bitrate set on the container, use it.
549 if (format_context_->bit_rate > 0) 552 if (format_context_->bit_rate > 0)
550 return format_context_->bit_rate; 553 return format_context_->bit_rate;
551 554
(...skipping 12 matching lines...) Expand all
564 max_duration_.InMicroseconds() < Limits::kMaxTimeInMicroseconds) { 567 max_duration_.InMicroseconds() < Limits::kMaxTimeInMicroseconds) {
565 int64 filesize_in_bytes; 568 int64 filesize_in_bytes;
566 if (GetSize(&filesize_in_bytes)) 569 if (GetSize(&filesize_in_bytes))
567 return 8000 * filesize_in_bytes / max_duration_.InMilliseconds(); 570 return 8000 * filesize_in_bytes / max_duration_.InMilliseconds();
568 } 571 }
569 572
570 // Bitrate could not be determined. 573 // Bitrate could not be determined.
571 return 0; 574 return 0;
572 } 575 }
573 576
577 bool FFmpegDemuxer::IsLocalSource() {
578 return local_source_;
579 }
580
574 void FFmpegDemuxer::SeekTask(base::TimeDelta time, const FilterStatusCB& cb) { 581 void FFmpegDemuxer::SeekTask(base::TimeDelta time, const FilterStatusCB& cb) {
575 DCHECK_EQ(MessageLoop::current(), message_loop_); 582 DCHECK_EQ(MessageLoop::current(), message_loop_);
576 583
577 // TODO(scherkus): remove this by separating Seek() from Flush() from 584 // TODO(scherkus): remove this by separating Seek() from Flush() from
578 // Preroll() states (i.e., the implicit Seek(0) should really be a Preroll()). 585 // Preroll() states (i.e., the implicit Seek(0) should really be a Preroll()).
579 if (first_seek_hack_) { 586 if (first_seek_hack_) {
580 first_seek_hack_ = false; 587 first_seek_hack_ = false;
581 588
582 if (time == start_time_) { 589 if (time == start_time_) {
583 cb.Run(PIPELINE_OK); 590 cb.Run(PIPELINE_OK);
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 read_event_.Wait(); 730 read_event_.Wait();
724 return last_read_bytes_; 731 return last_read_bytes_;
725 } 732 }
726 733
727 void FFmpegDemuxer::SignalReadCompleted(size_t size) { 734 void FFmpegDemuxer::SignalReadCompleted(size_t size) {
728 last_read_bytes_ = size; 735 last_read_bytes_ = size;
729 read_event_.Signal(); 736 read_event_.Signal();
730 } 737 }
731 738
732 } // namespace media 739 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698