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

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

Issue 8786013: Replace media::Limits struct with media::limits namespace and update documentation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixes 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 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 return; 512 return;
513 } 513 }
514 if (format_context_->duration != static_cast<int64_t>(AV_NOPTS_VALUE)) { 514 if (format_context_->duration != static_cast<int64_t>(AV_NOPTS_VALUE)) {
515 // If there is a duration value in the container use that to find the 515 // If there is a duration value in the container use that to find the
516 // maximum between it and the duration from A/V streams. 516 // maximum between it and the duration from A/V streams.
517 const AVRational av_time_base = {1, AV_TIME_BASE}; 517 const AVRational av_time_base = {1, AV_TIME_BASE};
518 max_duration = 518 max_duration =
519 std::max(max_duration, 519 std::max(max_duration,
520 ConvertFromTimeBase(av_time_base, format_context_->duration)); 520 ConvertFromTimeBase(av_time_base, format_context_->duration));
521 } else { 521 } else {
522 // The duration is not a valid value. Assume that this is a live stream 522 // The duration is unknown, in which case this is likely a live stream.
523 // and set duration to the maximum int64 number to represent infinity. 523 max_duration = base::TimeDelta::FromMicroseconds(limits::kInfiniteDuration);
524 max_duration = base::TimeDelta::FromMicroseconds(
525 Limits::kMaxTimeInMicroseconds);
526 } 524 }
527 525
528 // Some demuxers, like WAV, do not put timestamps on their frames. We 526 // Some demuxers, like WAV, do not put timestamps on their frames. We
529 // assume the the start time is 0. 527 // assume the the start time is 0.
530 if (start_time_ == kNoTimestamp) 528 if (start_time_ == kNoTimestamp)
531 start_time_ = base::TimeDelta(); 529 start_time_ = base::TimeDelta();
532 530
533 // Good to go: set the duration and bitrate and notify we're done 531 // Good to go: set the duration and bitrate and notify we're done
534 // initializing. 532 // initializing.
535 if (host()) 533 if (host())
(...skipping 16 matching lines...) Expand all
552 550
553 // Then try to sum the bitrates individually per stream. 551 // Then try to sum the bitrates individually per stream.
554 int bitrate = 0; 552 int bitrate = 0;
555 for (size_t i = 0; i < format_context_->nb_streams; ++i) { 553 for (size_t i = 0; i < format_context_->nb_streams; ++i) {
556 AVCodecContext* codec_context = format_context_->streams[i]->codec; 554 AVCodecContext* codec_context = format_context_->streams[i]->codec;
557 bitrate += codec_context->bit_rate; 555 bitrate += codec_context->bit_rate;
558 } 556 }
559 if (bitrate > 0) 557 if (bitrate > 0)
560 return bitrate; 558 return bitrate;
561 559
562 // If there isn't a bitrate set in the container or streams, but there is a 560 // See if we can approximate the bitrate as long as we have a filesize and
563 // valid duration, approximate the bitrate using the duration. 561 // valid duration.
564 if (max_duration_.InMilliseconds() > 0 && 562 int64 filesize_in_bytes;
565 max_duration_.InMicroseconds() < Limits::kMaxTimeInMicroseconds) { 563 if (max_duration_.InMicroseconds() <= 0 ||
566 int64 filesize_in_bytes; 564 max_duration_.InMicroseconds() == limits::kInfiniteDuration ||
567 if (GetSize(&filesize_in_bytes)) 565 !GetSize(&filesize_in_bytes))
568 return 8000 * filesize_in_bytes / max_duration_.InMilliseconds(); 566 return 0;
Ami GONE FROM CHROMIUM 2011/12/07 01:04:48 Need braces.
scherkus (not reviewing) 2011/12/07 05:56:56 Done.
569 }
570 567
571 // Bitrate could not be determined. 568 // Do math in floating point as we'd overflow an int64 if the filesize was
572 return 0; 569 // larger than ~1073GB.
570 double bytes = filesize_in_bytes;
571 double duration = max_duration_.InMicroseconds();
572 return bytes * 8000000.0 / duration;
Ami GONE FROM CHROMIUM 2011/12/07 01:04:48 Personally I prefer 8e6 to counting zeros, but I d
scherkus (not reviewing) 2011/12/07 05:56:56 I like my zeros! also my efforts to prevent overf
573 } 573 }
574 574
575 bool FFmpegDemuxer::IsLocalSource() { 575 bool FFmpegDemuxer::IsLocalSource() {
576 return local_source_; 576 return local_source_;
577 } 577 }
578 578
579 bool FFmpegDemuxer::IsSeekable() { 579 bool FFmpegDemuxer::IsSeekable() {
580 return !IsStreaming(); 580 return !IsStreaming();
581 } 581 }
582 582
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 read_event_.Wait(); 732 read_event_.Wait();
733 return last_read_bytes_; 733 return last_read_bytes_;
734 } 734 }
735 735
736 void FFmpegDemuxer::SignalReadCompleted(size_t size) { 736 void FFmpegDemuxer::SignalReadCompleted(size_t size) {
737 last_read_bytes_ = size; 737 last_read_bytes_ = size;
738 read_event_.Signal(); 738 read_event_.Signal();
739 } 739 }
740 740
741 } // namespace media 741 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698