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

Side by Side 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, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/media/webmediaplayer_impl.h" 5 #include "content/renderer/media/webmediaplayer_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 client_(client), 160 client_(client),
161 delegate_(delegate), 161 delegate_(delegate),
162 defer_load_cb_(params.defer_load_cb()), 162 defer_load_cb_(params.defer_load_cb()),
163 accelerated_compositing_reported_(false), 163 accelerated_compositing_reported_(false),
164 incremented_externally_allocated_memory_(false), 164 incremented_externally_allocated_memory_(false),
165 gpu_factories_(RenderThreadImpl::current()->GetGpuFactories()), 165 gpu_factories_(RenderThreadImpl::current()->GetGpuFactories()),
166 is_local_source_(false), 166 is_local_source_(false),
167 supports_save_(true), 167 supports_save_(true),
168 starting_(false), 168 starting_(false),
169 chunk_demuxer_(NULL), 169 chunk_demuxer_(NULL),
170 total_bytes_(0),
171 did_loading_progress_(false),
170 compositor_( // Threaded compositing isn't enabled universally yet. 172 compositor_( // Threaded compositing isn't enabled universally yet.
171 (RenderThreadImpl::current()->compositor_message_loop_proxy() 173 (RenderThreadImpl::current()->compositor_message_loop_proxy()
172 ? RenderThreadImpl::current()->compositor_message_loop_proxy() 174 ? RenderThreadImpl::current()->compositor_message_loop_proxy()
173 : base::MessageLoopProxy::current()), 175 : base::MessageLoopProxy::current()),
174 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnNaturalSizeChange)), 176 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnNaturalSizeChange)),
175 text_track_index_(0), 177 text_track_index_(0),
176 web_cdm_(NULL) { 178 web_cdm_(NULL) {
177 media_log_->AddEvent( 179 media_log_->AddEvent(
178 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_CREATED)); 180 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_CREATED));
179 181
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 media_log_->AddEvent(media_log_->CreateLoadEvent(url.spec())); 303 media_log_->AddEvent(media_log_->CreateLoadEvent(url.spec()));
302 304
303 // Media source pipelines can start immediately. 305 // Media source pipelines can start immediately.
304 if (load_type == LoadTypeMediaSource) { 306 if (load_type == LoadTypeMediaSource) {
305 supports_save_ = false; 307 supports_save_ = false;
306 StartPipeline(); 308 StartPipeline();
307 return; 309 return;
308 } 310 }
309 311
310 // Otherwise it's a regular request which requires resolving the URL first. 312 // Otherwise it's a regular request which requires resolving the URL first.
311 // TODO(sandersd): Make WMPI a DataSourceHost and pass |this| instead of
312 // |&pipeline_|.
313 data_source_.reset(new BufferedDataSource( 313 data_source_.reset(new BufferedDataSource(
314 main_loop_, 314 main_loop_,
315 frame_, 315 frame_,
316 media_log_.get(), 316 media_log_.get(),
317 &pipeline_, 317 this,
318 base::Bind(&WebMediaPlayerImpl::NotifyDownloading, AsWeakPtr()))); 318 base::Bind(&WebMediaPlayerImpl::NotifyDownloading, AsWeakPtr())));
319 data_source_->Initialize( 319 data_source_->Initialize(
320 url, static_cast<BufferedResourceLoader::CORSMode>(cors_mode), 320 url, static_cast<BufferedResourceLoader::CORSMode>(cors_mode),
321 base::Bind( 321 base::Bind(
322 &WebMediaPlayerImpl::DataSourceInitialized, 322 &WebMediaPlayerImpl::DataSourceInitialized,
323 AsWeakPtr(), gurl)); 323 AsWeakPtr(), gurl));
324 324
325 is_local_source_ = !gurl.SchemeIsHTTPOrHTTPS(); 325 is_local_source_ = !gurl.SchemeIsHTTPOrHTTPS();
326 } 326 }
327 327
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 WebMediaPlayer::NetworkState WebMediaPlayerImpl::networkState() const { 488 WebMediaPlayer::NetworkState WebMediaPlayerImpl::networkState() const {
489 DCHECK(main_loop_->BelongsToCurrentThread()); 489 DCHECK(main_loop_->BelongsToCurrentThread());
490 return network_state_; 490 return network_state_;
491 } 491 }
492 492
493 WebMediaPlayer::ReadyState WebMediaPlayerImpl::readyState() const { 493 WebMediaPlayer::ReadyState WebMediaPlayerImpl::readyState() const {
494 DCHECK(main_loop_->BelongsToCurrentThread()); 494 DCHECK(main_loop_->BelongsToCurrentThread());
495 return ready_state_; 495 return ready_state_;
496 } 496 }
497 497
498 static base::TimeDelta TimeForByteOffset(
499 int64 byte_offset, int64 total_bytes, base::TimeDelta duration) {
500 double position = static_cast<double>(byte_offset) / total_bytes;
501 // Snap to the beginning/end where the approximation can look especially bad.
502 if (position < 0.01)
503 return base::TimeDelta();
504 if (position > 0.99)
505 return duration;
506 return base::TimeDelta::FromMilliseconds(
507 static_cast<int64>(position * duration.InMilliseconds()));
508 }
509
498 const blink::WebTimeRanges& WebMediaPlayerImpl::buffered() { 510 const blink::WebTimeRanges& WebMediaPlayerImpl::buffered() {
499 DCHECK(main_loop_->BelongsToCurrentThread()); 511 DCHECK(main_loop_->BelongsToCurrentThread());
500 blink::WebTimeRanges web_ranges( 512 media::Ranges<base::TimeDelta> buffered_time_ranges =
501 ConvertToWebTimeRanges(pipeline_.GetBufferedTimeRanges())); 513 pipeline_.GetBufferedTimeRanges();
502 buffered_.swap(web_ranges); 514 if (total_bytes_ && buffered_byte_ranges_.size()) {
515 base::TimeDelta duration = pipeline_.GetMediaDuration();
516 for (size_t i = 0; i < buffered_byte_ranges_.size(); ++i) {
517 int64 start = buffered_byte_ranges_.start(i);
518 int64 end = buffered_byte_ranges_.end(i);
519 buffered_time_ranges.Add(TimeForByteOffset(start, total_bytes_, duration),
520 TimeForByteOffset(end, total_bytes_, duration));
521 }
522 }
523 blink::WebTimeRanges buffered(ConvertToWebTimeRanges(buffered_time_ranges));
524 buffered_.swap(buffered);
503 return buffered_; 525 return buffered_;
504 } 526 }
505 527
506 double WebMediaPlayerImpl::maxTimeSeekable() const { 528 double WebMediaPlayerImpl::maxTimeSeekable() const {
507 DCHECK(main_loop_->BelongsToCurrentThread()); 529 DCHECK(main_loop_->BelongsToCurrentThread());
508 530
509 // If we haven't even gotten to ReadyStateHaveMetadata yet then just 531 // If we haven't even gotten to ReadyStateHaveMetadata yet then just
510 // return 0 so that the seekable range is empty. 532 // return 0 so that the seekable range is empty.
511 if (ready_state_ < WebMediaPlayer::ReadyStateHaveMetadata) 533 if (ready_state_ < WebMediaPlayer::ReadyStateHaveMetadata)
512 return 0.0; 534 return 0.0;
513 535
514 // We don't support seeking in streaming media. 536 // We don't support seeking in streaming media.
515 if (data_source_ && data_source_->IsStreaming()) 537 if (data_source_ && data_source_->IsStreaming())
516 return 0.0; 538 return 0.0;
517 return duration(); 539 return duration();
518 } 540 }
519 541
542 // 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
520 bool WebMediaPlayerImpl::didLoadingProgress() const { 543 bool WebMediaPlayerImpl::didLoadingProgress() const {
521 DCHECK(main_loop_->BelongsToCurrentThread()); 544 DCHECK(main_loop_->BelongsToCurrentThread());
522 545 bool merged = pipeline_.DidLoadingProgress() || did_loading_progress_;
523 return pipeline_.DidLoadingProgress(); 546 did_loading_progress_ = false;
547 return merged;
524 } 548 }
525 549
526 void WebMediaPlayerImpl::paint(WebCanvas* canvas, 550 void WebMediaPlayerImpl::paint(WebCanvas* canvas,
527 const WebRect& rect, 551 const WebRect& rect,
528 unsigned char alpha) { 552 unsigned char alpha) {
529 DCHECK(main_loop_->BelongsToCurrentThread()); 553 DCHECK(main_loop_->BelongsToCurrentThread());
530 554
531 if (!accelerated_compositing_reported_) { 555 if (!accelerated_compositing_reported_) {
532 accelerated_compositing_reported_ = true; 556 accelerated_compositing_reported_ = true;
533 // Normally paint() is only called in non-accelerated rendering, but there 557 // Normally paint() is only called in non-accelerated rendering, but there
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
898 // TODO(xhwang): Support setMediaKeys(0) if necessary: http://crbug.com/330324 922 // TODO(xhwang): Support setMediaKeys(0) if necessary: http://crbug.com/330324
899 if (!cdm) 923 if (!cdm)
900 return; 924 return;
901 925
902 web_cdm_ = ToWebContentDecryptionModuleImpl(cdm); 926 web_cdm_ = ToWebContentDecryptionModuleImpl(cdm);
903 927
904 if (web_cdm_ && !decryptor_ready_cb_.is_null()) 928 if (web_cdm_ && !decryptor_ready_cb_.is_null())
905 base::ResetAndReturn(&decryptor_ready_cb_).Run(web_cdm_->GetDecryptor()); 929 base::ResetAndReturn(&decryptor_ready_cb_).Run(web_cdm_->GetDecryptor());
906 } 930 }
907 931
932 void WebMediaPlayerImpl::SetTotalBytes(int64 total_bytes) {
933 DCHECK(main_loop_->BelongsToCurrentThread());
934 total_bytes_ = total_bytes;
935 }
936
937 void WebMediaPlayerImpl::AddBufferedByteRange(int64 start, int64 end) {
938 DCHECK(main_loop_->BelongsToCurrentThread());
939 buffered_byte_ranges_.Add(start, end);
940 did_loading_progress_ = true;
941 }
942
908 void WebMediaPlayerImpl::InvalidateOnMainThread() { 943 void WebMediaPlayerImpl::InvalidateOnMainThread() {
909 DCHECK(main_loop_->BelongsToCurrentThread()); 944 DCHECK(main_loop_->BelongsToCurrentThread());
910 TRACE_EVENT0("media", "WebMediaPlayerImpl::InvalidateOnMainThread"); 945 TRACE_EVENT0("media", "WebMediaPlayerImpl::InvalidateOnMainThread");
911 946
912 client_->repaint(); 947 client_->repaint();
913 } 948 }
914 949
915 void WebMediaPlayerImpl::OnPipelineSeek(PipelineStatus status) { 950 void WebMediaPlayerImpl::OnPipelineSeek(PipelineStatus status) {
916 DCHECK(main_loop_->BelongsToCurrentThread()); 951 DCHECK(main_loop_->BelongsToCurrentThread());
917 starting_ = false; 952 starting_ = false;
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
1320 1355
1321 if (web_cdm_) { 1356 if (web_cdm_) {
1322 decryptor_ready_cb.Run(web_cdm_->GetDecryptor()); 1357 decryptor_ready_cb.Run(web_cdm_->GetDecryptor());
1323 return; 1358 return;
1324 } 1359 }
1325 1360
1326 decryptor_ready_cb_ = decryptor_ready_cb; 1361 decryptor_ready_cb_ = decryptor_ready_cb;
1327 } 1362 }
1328 1363
1329 } // namespace content 1364 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698