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

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: Rebase ToT 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..f27b2e8059223c6425ba1f3b5c0651e5e19e59d5 100644
--- a/media/base/download_rate_monitor.cc
+++ b/media/base/download_rate_monitor.cc
@@ -73,8 +73,11 @@ DownloadRateMonitor::DownloadRateMonitor() {
}
void DownloadRateMonitor::Start(
- const base::Closure& canplaythrough_cb, int media_bitrate) {
+ const base::Closure& canplaythrough_cb, int media_bitrate,
+ bool streaming, bool local_source) {
canplaythrough_cb_ = canplaythrough_cb;
+ streaming_ = streaming;
+ local_source_ = local_source;
stopped_ = false;
bitrate_ = media_bitrate;
current_sample_.Reset();
@@ -139,9 +142,10 @@ void DownloadRateMonitor::Reset() {
is_downloading_data_ = false;
total_bytes_ = -1;
buffered_bytes_ = 0;
- loaded_ = false;
+ local_source_ = false;
bitrate_ = 0;
stopped_ = true;
+ streaming_ = false;
}
DownloadRateMonitor::~DownloadRateMonitor() { }
@@ -198,14 +202,23 @@ 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 local or streaming.
+ //
+ // NOTE: It is a requirement for CanPlayThrough to fire immediately if the
+ // source is local, but the choice to optimistically fire the event for any
+ // streaming media element is a design decision that may need to be tweaked.
+ if (local_source_ || streaming_)
+ 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