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

Unified Diff: media/filters/ffmpeg_demuxer.cc

Issue 8294025: Merge 105121 - Numerous fixes to audio/video buffered resource loading. (Closed) Base URL: svn://svn.chromium.org/chrome/branches/874/src/
Patch Set: '' Created 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/filters/ffmpeg_demuxer.h ('k') | media/filters/ffmpeg_demuxer_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/filters/ffmpeg_demuxer.cc
===================================================================
--- media/filters/ffmpeg_demuxer.cc (revision 105891)
+++ media/filters/ffmpeg_demuxer.cc (working copy)
@@ -507,8 +507,8 @@
std::max(max_duration,
ConvertFromTimeBase(av_time_base, format_context_->duration));
} else {
- // If the duration is not a valid value. Assume that this is a live stream
- // and we set duration to the maximum int64 number to represent infinity.
+ // 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);
}
@@ -518,13 +518,48 @@
if (start_time_ == kNoTimestamp)
start_time_ = base::TimeDelta();
- // Good to go: set the duration and notify we're done initializing.
+ // Good to go: set the duration and bitrate and notify we're done
+ // initializing.
if (host())
host()->SetDuration(max_duration);
max_duration_ = max_duration;
+
+ int bitrate = GetBitrate();
+ if (bitrate > 0)
+ data_source_->SetBitrate(bitrate);
+
callback.Run(PIPELINE_OK);
}
+int FFmpegDemuxer::GetBitrate() {
+ DCHECK(format_context_);
+
+ // If there is a bitrate set on the container, use it.
+ if (format_context_->bit_rate > 0)
+ return format_context_->bit_rate;
+
+ // Then try to sum the bitrates individually per stream.
+ int bitrate = 0;
+ for (size_t i = 0; i < format_context_->nb_streams; ++i) {
+ AVCodecContext* codec_context = format_context_->streams[i]->codec;
+ bitrate += codec_context->bit_rate;
+ }
+ 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();
+ }
+
+ // Bitrate could not be determined.
+ return 0;
+}
+
void FFmpegDemuxer::SeekTask(base::TimeDelta time, const FilterStatusCB& cb) {
DCHECK_EQ(MessageLoop::current(), message_loop_);
« no previous file with comments | « media/filters/ffmpeg_demuxer.h ('k') | media/filters/ffmpeg_demuxer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698