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

Unified Diff: content/renderer/media/webmediaplayer_impl.cc

Issue 224093011: Move DataSourceHost to BufferedDataSourceHost. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update existing tests. Created 6 years, 9 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
Index: content/renderer/media/webmediaplayer_impl.cc
diff --git a/content/renderer/media/webmediaplayer_impl.cc b/content/renderer/media/webmediaplayer_impl.cc
index 451317ee6cc0cd45371c8d257c570dd4e5af54ae..bfbf939370c78a6247d65138ca47ef95d7948910 100644
--- a/content/renderer/media/webmediaplayer_impl.cc
+++ b/content/renderer/media/webmediaplayer_impl.cc
@@ -167,6 +167,8 @@ WebMediaPlayerImpl::WebMediaPlayerImpl(
supports_save_(true),
starting_(false),
chunk_demuxer_(NULL),
+ total_bytes_(0),
+ did_loading_progress_(false),
compositor_( // Threaded compositing isn't enabled universally yet.
(RenderThreadImpl::current()->compositor_message_loop_proxy()
? RenderThreadImpl::current()->compositor_message_loop_proxy()
@@ -308,13 +310,11 @@ void WebMediaPlayerImpl::DoLoad(LoadType load_type,
}
// Otherwise it's a regular request which requires resolving the URL first.
- // TODO(sandersd): Make WMPI a DataSourceHost and pass |this| instead of
- // |&pipeline_|.
data_source_.reset(new BufferedDataSource(
main_loop_,
frame_,
media_log_.get(),
- &pipeline_,
+ this,
base::Bind(&WebMediaPlayerImpl::NotifyDownloading, AsWeakPtr())));
data_source_->Initialize(
url, static_cast<BufferedResourceLoader::CORSMode>(cors_mode),
@@ -495,11 +495,33 @@ WebMediaPlayer::ReadyState WebMediaPlayerImpl::readyState() const {
return ready_state_;
}
+static base::TimeDelta TimeForByteOffset(
+ int64 byte_offset, int64 total_bytes, base::TimeDelta duration) {
+ double position = static_cast<double>(byte_offset) / total_bytes;
+ // Snap to the beginning/end where the approximation can look especially bad.
+ if (position < 0.01)
+ return base::TimeDelta();
+ if (position > 0.99)
+ return duration;
+ return base::TimeDelta::FromMilliseconds(
+ static_cast<int64>(position * duration.InMilliseconds()));
+}
+
const blink::WebTimeRanges& WebMediaPlayerImpl::buffered() {
DCHECK(main_loop_->BelongsToCurrentThread());
- blink::WebTimeRanges web_ranges(
- ConvertToWebTimeRanges(pipeline_.GetBufferedTimeRanges()));
- buffered_.swap(web_ranges);
+ media::Ranges<base::TimeDelta> buffered_time_ranges =
+ pipeline_.GetBufferedTimeRanges();
+ if (total_bytes_ && buffered_byte_ranges_.size()) {
+ base::TimeDelta duration = pipeline_.GetMediaDuration();
+ for (size_t i = 0; i < buffered_byte_ranges_.size(); ++i) {
+ int64 start = buffered_byte_ranges_.start(i);
+ int64 end = buffered_byte_ranges_.end(i);
+ buffered_time_ranges.Add(TimeForByteOffset(start, total_bytes_, duration),
+ TimeForByteOffset(end, total_bytes_, duration));
+ }
+ }
+ blink::WebTimeRanges buffered(ConvertToWebTimeRanges(buffered_time_ranges));
+ buffered_.swap(buffered);
return buffered_;
}
@@ -517,10 +539,12 @@ double WebMediaPlayerImpl::maxTimeSeekable() const {
return duration();
}
+// TODO(sandersd): Why is this const!?
scherkus (not reviewing) 2014/04/05 00:00:02 remove this TODO as you now have it in the .h file
bool WebMediaPlayerImpl::didLoadingProgress() const {
DCHECK(main_loop_->BelongsToCurrentThread());
-
- return pipeline_.DidLoadingProgress();
+ bool merged = pipeline_.DidLoadingProgress() || did_loading_progress_;
+ did_loading_progress_ = false;
+ return merged;
}
void WebMediaPlayerImpl::paint(WebCanvas* canvas,
@@ -905,6 +929,17 @@ void WebMediaPlayerImpl::setContentDecryptionModule(
base::ResetAndReturn(&decryptor_ready_cb_).Run(web_cdm_->GetDecryptor());
}
+void WebMediaPlayerImpl::SetTotalBytes(int64 total_bytes) {
+ DCHECK(main_loop_->BelongsToCurrentThread());
+ total_bytes_ = total_bytes;
+}
+
+void WebMediaPlayerImpl::AddBufferedByteRange(int64 start, int64 end) {
+ DCHECK(main_loop_->BelongsToCurrentThread());
+ buffered_byte_ranges_.Add(start, end);
+ did_loading_progress_ = true;
+}
+
void WebMediaPlayerImpl::InvalidateOnMainThread() {
DCHECK(main_loop_->BelongsToCurrentThread());
TRACE_EVENT0("media", "WebMediaPlayerImpl::InvalidateOnMainThread");

Powered by Google App Engine
This is Rietveld 408576698