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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 buffered_(pipeline_), |
170 compositor_( // Threaded compositing isn't enabled universally yet. | 171 compositor_( // Threaded compositing isn't enabled universally yet. |
171 (RenderThreadImpl::current()->compositor_message_loop_proxy() | 172 (RenderThreadImpl::current()->compositor_message_loop_proxy() |
172 ? RenderThreadImpl::current()->compositor_message_loop_proxy() | 173 ? RenderThreadImpl::current()->compositor_message_loop_proxy() |
173 : base::MessageLoopProxy::current()), | 174 : base::MessageLoopProxy::current()), |
174 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnNaturalSizeChange)), | 175 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnNaturalSizeChange)), |
175 text_track_index_(0), | 176 text_track_index_(0), |
176 web_cdm_(NULL) { | 177 web_cdm_(NULL) { |
177 media_log_->AddEvent( | 178 media_log_->AddEvent( |
178 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_CREATED)); | 179 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_CREATED)); |
179 | 180 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 media_log_->AddEvent(media_log_->CreateLoadEvent(url.spec())); | 302 media_log_->AddEvent(media_log_->CreateLoadEvent(url.spec())); |
302 | 303 |
303 // Media source pipelines can start immediately. | 304 // Media source pipelines can start immediately. |
304 if (load_type == LoadTypeMediaSource) { | 305 if (load_type == LoadTypeMediaSource) { |
305 supports_save_ = false; | 306 supports_save_ = false; |
306 StartPipeline(); | 307 StartPipeline(); |
307 return; | 308 return; |
308 } | 309 } |
309 | 310 |
310 // Otherwise it's a regular request which requires resolving the URL first. | 311 // 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( | 312 data_source_.reset(new BufferedDataSource( |
314 main_loop_, | 313 main_loop_, |
315 frame_, | 314 frame_, |
316 media_log_.get(), | 315 media_log_.get(), |
317 &pipeline_, | 316 &buffered_, |
318 base::Bind(&WebMediaPlayerImpl::NotifyDownloading, AsWeakPtr()))); | 317 base::Bind(&WebMediaPlayerImpl::NotifyDownloading, AsWeakPtr()))); |
319 data_source_->Initialize( | 318 data_source_->Initialize( |
320 url, static_cast<BufferedResourceLoader::CORSMode>(cors_mode), | 319 url, static_cast<BufferedResourceLoader::CORSMode>(cors_mode), |
321 base::Bind( | 320 base::Bind( |
322 &WebMediaPlayerImpl::DataSourceInitialized, | 321 &WebMediaPlayerImpl::DataSourceInitialized, |
323 AsWeakPtr(), gurl)); | 322 AsWeakPtr(), gurl)); |
324 | 323 |
325 is_local_source_ = !gurl.SchemeIsHTTPOrHTTPS(); | 324 is_local_source_ = !gurl.SchemeIsHTTPOrHTTPS(); |
326 } | 325 } |
327 | 326 |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 WebMediaPlayer::NetworkState WebMediaPlayerImpl::networkState() const { | 487 WebMediaPlayer::NetworkState WebMediaPlayerImpl::networkState() const { |
489 DCHECK(main_loop_->BelongsToCurrentThread()); | 488 DCHECK(main_loop_->BelongsToCurrentThread()); |
490 return network_state_; | 489 return network_state_; |
491 } | 490 } |
492 | 491 |
493 WebMediaPlayer::ReadyState WebMediaPlayerImpl::readyState() const { | 492 WebMediaPlayer::ReadyState WebMediaPlayerImpl::readyState() const { |
494 DCHECK(main_loop_->BelongsToCurrentThread()); | 493 DCHECK(main_loop_->BelongsToCurrentThread()); |
495 return ready_state_; | 494 return ready_state_; |
496 } | 495 } |
497 | 496 |
| 497 static base::TimeDelta TimeForByteOffset( |
| 498 int64 byte_offset, int64 total_bytes, base::TimeDelta duration) { |
| 499 double position = static_cast<double>(byte_offset) / total_bytes; |
| 500 // Snap to the beginning/end where the approximation can look especially bad. |
| 501 if (position < 0.01) |
| 502 return base::TimeDelta(); |
| 503 if (position > 0.99) |
| 504 return duration; |
| 505 return base::TimeDelta::FromMilliseconds( |
| 506 static_cast<int64>(position * duration.InMilliseconds())); |
| 507 } |
| 508 |
498 const blink::WebTimeRanges& WebMediaPlayerImpl::buffered() { | 509 const blink::WebTimeRanges& WebMediaPlayerImpl::buffered() { |
499 DCHECK(main_loop_->BelongsToCurrentThread()); | 510 DCHECK(main_loop_->BelongsToCurrentThread()); |
500 blink::WebTimeRanges web_ranges( | 511 return buffered_.BufferedTimeRanges(); |
501 ConvertToWebTimeRanges(pipeline_.GetBufferedTimeRanges())); | |
502 buffered_.swap(web_ranges); | |
503 return buffered_; | |
504 } | 512 } |
505 | 513 |
506 double WebMediaPlayerImpl::maxTimeSeekable() const { | 514 double WebMediaPlayerImpl::maxTimeSeekable() const { |
507 DCHECK(main_loop_->BelongsToCurrentThread()); | 515 DCHECK(main_loop_->BelongsToCurrentThread()); |
508 | 516 |
509 // If we haven't even gotten to ReadyStateHaveMetadata yet then just | 517 // If we haven't even gotten to ReadyStateHaveMetadata yet then just |
510 // return 0 so that the seekable range is empty. | 518 // return 0 so that the seekable range is empty. |
511 if (ready_state_ < WebMediaPlayer::ReadyStateHaveMetadata) | 519 if (ready_state_ < WebMediaPlayer::ReadyStateHaveMetadata) |
512 return 0.0; | 520 return 0.0; |
513 | 521 |
514 // We don't support seeking in streaming media. | 522 // We don't support seeking in streaming media. |
515 if (data_source_ && data_source_->IsStreaming()) | 523 if (data_source_ && data_source_->IsStreaming()) |
516 return 0.0; | 524 return 0.0; |
517 return duration(); | 525 return duration(); |
518 } | 526 } |
519 | 527 |
520 bool WebMediaPlayerImpl::didLoadingProgress() const { | 528 bool WebMediaPlayerImpl::didLoadingProgress() const { |
521 DCHECK(main_loop_->BelongsToCurrentThread()); | 529 DCHECK(main_loop_->BelongsToCurrentThread()); |
522 | 530 return buffered_.DidLoadingProgress(); |
523 return pipeline_.DidLoadingProgress(); | |
524 } | 531 } |
525 | 532 |
526 void WebMediaPlayerImpl::paint(WebCanvas* canvas, | 533 void WebMediaPlayerImpl::paint(WebCanvas* canvas, |
527 const WebRect& rect, | 534 const WebRect& rect, |
528 unsigned char alpha) { | 535 unsigned char alpha) { |
529 DCHECK(main_loop_->BelongsToCurrentThread()); | 536 DCHECK(main_loop_->BelongsToCurrentThread()); |
530 | 537 |
531 if (!accelerated_compositing_reported_) { | 538 if (!accelerated_compositing_reported_) { |
532 accelerated_compositing_reported_ = true; | 539 accelerated_compositing_reported_ = true; |
533 // Normally paint() is only called in non-accelerated rendering, but there | 540 // 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 | 1327 |
1321 if (web_cdm_) { | 1328 if (web_cdm_) { |
1322 decryptor_ready_cb.Run(web_cdm_->GetDecryptor()); | 1329 decryptor_ready_cb.Run(web_cdm_->GetDecryptor()); |
1323 return; | 1330 return; |
1324 } | 1331 } |
1325 | 1332 |
1326 decryptor_ready_cb_ = decryptor_ready_cb; | 1333 decryptor_ready_cb_ = decryptor_ready_cb; |
1327 } | 1334 } |
1328 | 1335 |
1329 } // namespace content | 1336 } // namespace content |
OLD | NEW |