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

Unified Diff: media/base/download_rate_monitor.cc

Issue 8661002: Fire CanPlayThrough immediately for local and streaming media files (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month 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
Index: media/base/download_rate_monitor.cc
diff --git a/media/base/download_rate_monitor.cc b/media/base/download_rate_monitor.cc
index 88916e4b57a4b3f27f69c71a57b756e85d7869c6..b561fa59b62d21a89a0db7ac93ef3642dfbadcd8 100644
--- a/media/base/download_rate_monitor.cc
+++ b/media/base/download_rate_monitor.cc
@@ -142,6 +142,8 @@ void DownloadRateMonitor::Reset() {
loaded_ = false;
bitrate_ = 0;
stopped_ = true;
+ media_stream_ = false;
+ streaming_ = false;
}
DownloadRateMonitor::~DownloadRateMonitor() { }
@@ -198,14 +200,25 @@ bool DownloadRateMonitor::ShouldNotifyCanPlayThrough() {
if (has_notified_can_play_through_)
return false;
- // If the media is from a local file (|loaded_|) or if all bytes are
- // buffered, fire CanPlayThrough.
- if (loaded_ || buffered_bytes_ == total_bytes_)
+ // Fire CanPlayThrough immediately if the source is loaded or streaming.
+ //
+ // NOTE: It is a requirement for CanPlayThrough to fire immediately if the
+ // source is |loaded_|, but the choice to fire the event for any streaming
+ // element is an optimistic design decision that may need to be tweaked. The
+ // only streaming element that *must* fire CanPlayThrough immediately is a
+ // media_stream_ whose source is local, such as from a webcam.
+ if (loaded_ || streaming_ || media_stream_)
wjia(left Chromium) 2011/11/22 23:01:17 should it be: if (loaded_ || !streaming_ || media_
vrk (LEFT CHROMIUM) 2011/11/23 21:29:45 So to be clear, the DownloadRateMonitor does not d
+ return true;
+
+ // If all bytes are buffered, fire CanPlayThrough.
+ if (buffered_bytes_ == total_bytes_)
return true;
- // Cannot approximate when the media can play through if bitrate is unknown.
+ // If bitrate is unknown, optimistically fire CanPlayThrough immediately.
+ // This is so a video with an unknown bitrate with the "autoplay" attribute
+ // will not wait until the entire file is downloaded before playback begins.
if (bitrate_ <= 0)
- return false;
+ return true;
float bytes_needed_per_second = bitrate_ / 8;
float download_rate = ApproximateDownloadByteRate();

Powered by Google App Engine
This is Rietveld 408576698