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

Unified 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: fix logic 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/base/video_decoder_config.cc ('k') | media/filters/video_renderer_base.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/filters/ffmpeg_demuxer.cc
diff --git a/media/filters/ffmpeg_demuxer.cc b/media/filters/ffmpeg_demuxer.cc
index e33bada6f1b74043169fdedf0510b91856949267..c1a056cdbb8f2dc4cc86b43b183725e6ee859547 100644
--- a/media/filters/ffmpeg_demuxer.cc
+++ b/media/filters/ffmpeg_demuxer.cc
@@ -519,10 +519,8 @@ void FFmpegDemuxer::InitializeTask(DataSource* data_source,
std::max(max_duration,
ConvertFromTimeBase(av_time_base, format_context_->duration));
} else {
- // The duration is not a valid value. Assume that this is a live stream
- // and set duration to the maximum int64 number to represent infinity.
- max_duration = base::TimeDelta::FromMicroseconds(
- Limits::kMaxTimeInMicroseconds);
+ // The duration is unknown, in which case this is likely a live stream.
+ max_duration = kInfiniteDuration;
}
// Some demuxers, like WAV, do not put timestamps on their frames. We
@@ -559,17 +557,20 @@ int FFmpegDemuxer::GetBitrate() {
if (bitrate > 0)
return bitrate;
- // If there isn't a bitrate set in the container or streams, but there is a
- // valid duration, approximate the bitrate using the duration.
- if (max_duration_.InMilliseconds() > 0 &&
- max_duration_.InMicroseconds() < Limits::kMaxTimeInMicroseconds) {
- int64 filesize_in_bytes;
- if (GetSize(&filesize_in_bytes))
- return 8000 * filesize_in_bytes / max_duration_.InMilliseconds();
+ // See if we can approximate the bitrate as long as we have a filesize and
+ // valid duration.
+ int64 filesize_in_bytes;
+ if (max_duration_.InMicroseconds() <= 0 ||
+ max_duration_ == kInfiniteDuration ||
+ !GetSize(&filesize_in_bytes)) {
+ return 0;
}
- // Bitrate could not be determined.
- return 0;
+ // Do math in floating point as we'd overflow an int64 if the filesize was
+ // larger than ~1073GB.
+ double bytes = filesize_in_bytes;
+ double duration = max_duration_.InMicroseconds();
+ return bytes * 8000000.0 / duration;
}
bool FFmpegDemuxer::IsLocalSource() {
« no previous file with comments | « media/base/video_decoder_config.cc ('k') | media/filters/video_renderer_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698