OLD | NEW |
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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 const double kMinRate = 0.0625; | 114 const double kMinRate = 0.0625; |
115 const double kMaxRate = 16.0; | 115 const double kMaxRate = 16.0; |
116 | 116 |
117 // Prefix for histograms related to Encrypted Media Extensions. | 117 // Prefix for histograms related to Encrypted Media Extensions. |
118 const char* kMediaEme = "Media.EME."; | 118 const char* kMediaEme = "Media.EME."; |
119 | 119 |
120 } // namespace | 120 } // namespace |
121 | 121 |
122 namespace content { | 122 namespace content { |
123 | 123 |
| 124 class BufferedDataSourceHostImpl; |
| 125 |
124 #define COMPILE_ASSERT_MATCHING_ENUM(name) \ | 126 #define COMPILE_ASSERT_MATCHING_ENUM(name) \ |
125 COMPILE_ASSERT(static_cast<int>(WebMediaPlayer::CORSMode ## name) == \ | 127 COMPILE_ASSERT(static_cast<int>(WebMediaPlayer::CORSMode ## name) == \ |
126 static_cast<int>(BufferedResourceLoader::k ## name), \ | 128 static_cast<int>(BufferedResourceLoader::k ## name), \ |
127 mismatching_enums) | 129 mismatching_enums) |
128 COMPILE_ASSERT_MATCHING_ENUM(Unspecified); | 130 COMPILE_ASSERT_MATCHING_ENUM(Unspecified); |
129 COMPILE_ASSERT_MATCHING_ENUM(Anonymous); | 131 COMPILE_ASSERT_MATCHING_ENUM(Anonymous); |
130 COMPILE_ASSERT_MATCHING_ENUM(UseCredentials); | 132 COMPILE_ASSERT_MATCHING_ENUM(UseCredentials); |
131 #undef COMPILE_ASSERT_MATCHING_ENUM | 133 #undef COMPILE_ASSERT_MATCHING_ENUM |
132 | 134 |
133 #define BIND_TO_RENDER_LOOP(function) \ | 135 #define BIND_TO_RENDER_LOOP(function) \ |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 &buffered_data_source_host_, |
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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 const blink::WebTimeRanges& WebMediaPlayerImpl::buffered() { | 498 const blink::WebTimeRanges& WebMediaPlayerImpl::buffered() { |
499 DCHECK(main_loop_->BelongsToCurrentThread()); | 499 DCHECK(main_loop_->BelongsToCurrentThread()); |
500 blink::WebTimeRanges web_ranges( | 500 media::Ranges<base::TimeDelta> buffered_time_ranges = |
501 ConvertToWebTimeRanges(pipeline_.GetBufferedTimeRanges())); | 501 pipeline_.GetBufferedTimeRanges(); |
502 buffered_.swap(web_ranges); | 502 buffered_data_source_host_.AddBufferedTimeRanges( |
503 return buffered_; | 503 &buffered_time_ranges, pipeline_.GetMediaDuration()); |
| 504 blink::WebTimeRanges buffered_web_time_ranges( |
| 505 ConvertToWebTimeRanges(buffered_time_ranges)); |
| 506 buffered_web_time_ranges_.swap(buffered_web_time_ranges); |
| 507 return buffered_web_time_ranges_; |
504 } | 508 } |
505 | 509 |
506 double WebMediaPlayerImpl::maxTimeSeekable() const { | 510 double WebMediaPlayerImpl::maxTimeSeekable() const { |
507 DCHECK(main_loop_->BelongsToCurrentThread()); | 511 DCHECK(main_loop_->BelongsToCurrentThread()); |
508 | 512 |
509 // If we haven't even gotten to ReadyStateHaveMetadata yet then just | 513 // If we haven't even gotten to ReadyStateHaveMetadata yet then just |
510 // return 0 so that the seekable range is empty. | 514 // return 0 so that the seekable range is empty. |
511 if (ready_state_ < WebMediaPlayer::ReadyStateHaveMetadata) | 515 if (ready_state_ < WebMediaPlayer::ReadyStateHaveMetadata) |
512 return 0.0; | 516 return 0.0; |
513 | 517 |
514 // We don't support seeking in streaming media. | 518 // We don't support seeking in streaming media. |
515 if (data_source_ && data_source_->IsStreaming()) | 519 if (data_source_ && data_source_->IsStreaming()) |
516 return 0.0; | 520 return 0.0; |
517 return duration(); | 521 return duration(); |
518 } | 522 } |
519 | 523 |
520 bool WebMediaPlayerImpl::didLoadingProgress() const { | 524 bool WebMediaPlayerImpl::didLoadingProgress() const { |
521 DCHECK(main_loop_->BelongsToCurrentThread()); | 525 DCHECK(main_loop_->BelongsToCurrentThread()); |
522 | 526 bool pipeline_progress = pipeline_.DidLoadingProgress(); |
523 return pipeline_.DidLoadingProgress(); | 527 bool data_progress = buffered_data_source_host_.DidLoadingProgress(); |
| 528 return pipeline_progress || data_progress; |
524 } | 529 } |
525 | 530 |
526 void WebMediaPlayerImpl::paint(WebCanvas* canvas, | 531 void WebMediaPlayerImpl::paint(WebCanvas* canvas, |
527 const WebRect& rect, | 532 const WebRect& rect, |
528 unsigned char alpha) { | 533 unsigned char alpha) { |
529 DCHECK(main_loop_->BelongsToCurrentThread()); | 534 DCHECK(main_loop_->BelongsToCurrentThread()); |
530 | 535 |
531 if (!accelerated_compositing_reported_) { | 536 if (!accelerated_compositing_reported_) { |
532 accelerated_compositing_reported_ = true; | 537 accelerated_compositing_reported_ = true; |
533 // Normally paint() is only called in non-accelerated rendering, but there | 538 // Normally paint() is only called in non-accelerated rendering, but there |
(...skipping 786 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1320 | 1325 |
1321 if (web_cdm_) { | 1326 if (web_cdm_) { |
1322 decryptor_ready_cb.Run(web_cdm_->GetDecryptor()); | 1327 decryptor_ready_cb.Run(web_cdm_->GetDecryptor()); |
1323 return; | 1328 return; |
1324 } | 1329 } |
1325 | 1330 |
1326 decryptor_ready_cb_ = decryptor_ready_cb; | 1331 decryptor_ready_cb_ = decryptor_ready_cb; |
1327 } | 1332 } |
1328 | 1333 |
1329 } // namespace content | 1334 } // namespace content |
OLD | NEW |