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 "media/blink/multibuffer_data_source.h" | 5 #include "media/blink/multibuffer_data_source.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 : cors_mode_(cors_mode), | 115 : cors_mode_(cors_mode), |
116 total_bytes_(kPositionNotSpecified), | 116 total_bytes_(kPositionNotSpecified), |
117 streaming_(false), | 117 streaming_(false), |
118 loading_(false), | 118 loading_(false), |
119 failed_(false), | 119 failed_(false), |
120 render_task_runner_(task_runner), | 120 render_task_runner_(task_runner), |
121 url_index_(url_index), | 121 url_index_(url_index), |
122 frame_(frame), | 122 frame_(frame), |
123 stop_signal_received_(false), | 123 stop_signal_received_(false), |
124 media_has_played_(false), | 124 media_has_played_(false), |
125 buffering_strategy_(BUFFERING_STRATEGY_NORMAL), | |
126 single_origin_(true), | 125 single_origin_(true), |
127 cancel_on_defer_(false), | 126 cancel_on_defer_(false), |
128 preload_(AUTO), | 127 preload_(AUTO), |
129 bitrate_(0), | 128 bitrate_(0), |
130 playback_rate_(0.0), | 129 playback_rate_(0.0), |
131 media_log_(media_log), | 130 media_log_(media_log), |
132 host_(host), | 131 host_(host), |
133 downloading_cb_(downloading_cb), | 132 downloading_cb_(downloading_cb), |
134 weak_factory_(this) { | 133 weak_factory_(this) { |
135 weak_ptr_ = weak_factory_.GetWeakPtr(); | 134 weak_ptr_ = weak_factory_.GetWeakPtr(); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 } | 241 } |
243 } | 242 } |
244 | 243 |
245 void MultibufferDataSource::SetPreload(Preload preload) { | 244 void MultibufferDataSource::SetPreload(Preload preload) { |
246 DVLOG(1) << __func__ << "(" << preload << ")"; | 245 DVLOG(1) << __func__ << "(" << preload << ")"; |
247 DCHECK(render_task_runner_->BelongsToCurrentThread()); | 246 DCHECK(render_task_runner_->BelongsToCurrentThread()); |
248 preload_ = preload; | 247 preload_ = preload; |
249 UpdateBufferSizes(); | 248 UpdateBufferSizes(); |
250 } | 249 } |
251 | 250 |
252 void MultibufferDataSource::SetBufferingStrategy( | |
253 BufferingStrategy buffering_strategy) { | |
254 DCHECK(render_task_runner_->BelongsToCurrentThread()); | |
255 buffering_strategy_ = buffering_strategy; | |
256 UpdateBufferSizes(); | |
257 } | |
258 | |
259 bool MultibufferDataSource::HasSingleOrigin() { | 251 bool MultibufferDataSource::HasSingleOrigin() { |
260 DCHECK(render_task_runner_->BelongsToCurrentThread()); | 252 DCHECK(render_task_runner_->BelongsToCurrentThread()); |
261 // Before initialization completes there is no risk of leaking data. Callers | 253 // Before initialization completes there is no risk of leaking data. Callers |
262 // are required to order checks such that this isn't a race. | 254 // are required to order checks such that this isn't a race. |
263 return single_origin_; | 255 return single_origin_; |
264 } | 256 } |
265 | 257 |
266 bool MultibufferDataSource::DidPassCORSAccessCheck() const { | 258 bool MultibufferDataSource::DidPassCORSAccessCheck() const { |
267 if (cors_mode_ == UrlData::CORS_UNSPECIFIED) | 259 if (cors_mode_ == UrlData::CORS_UNSPECIFIED) |
268 return false; | 260 return false; |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 uint64_t pos = reader_->Tell(); | 565 uint64_t pos = reader_->Tell(); |
574 ProgressCallback(pos, pos + available); | 566 ProgressCallback(pos, pos + available); |
575 } | 567 } |
576 } | 568 } |
577 | 569 |
578 void MultibufferDataSource::UpdateBufferSizes() { | 570 void MultibufferDataSource::UpdateBufferSizes() { |
579 DVLOG(1) << __func__; | 571 DVLOG(1) << __func__; |
580 if (!reader_) | 572 if (!reader_) |
581 return; | 573 return; |
582 | 574 |
583 if (!assume_fully_buffered()) { | |
584 // If the playback has started and the strategy is aggressive, then try to | |
585 // load as much as possible, assuming that the file is cacheable. (If not, | |
586 // why bother?) | |
587 bool aggressive = (buffering_strategy_ == BUFFERING_STRATEGY_AGGRESSIVE); | |
588 if (media_has_played_ && aggressive && url_data_ && | |
589 url_data_->range_supported() && url_data_->cacheable()) { | |
590 reader_->SetPreload(1LL << 40, 1LL << 40); // 1 Tb | |
591 return; | |
592 } | |
593 } | |
594 | |
595 // Use a default bit rate if unknown and clamp to prevent overflow. | 575 // Use a default bit rate if unknown and clamp to prevent overflow. |
596 int64_t bitrate = clamp<int64_t>(bitrate_, 0, kMaxBitrate); | 576 int64_t bitrate = clamp<int64_t>(bitrate_, 0, kMaxBitrate); |
597 if (bitrate == 0) | 577 if (bitrate == 0) |
598 bitrate = kDefaultBitrate; | 578 bitrate = kDefaultBitrate; |
599 | 579 |
600 // Only scale the buffer window for playback rates greater than 1.0 in | 580 // Only scale the buffer window for playback rates greater than 1.0 in |
601 // magnitude and clamp to prevent overflow. | 581 // magnitude and clamp to prevent overflow. |
602 double playback_rate = playback_rate_; | 582 double playback_rate = playback_rate_; |
603 | 583 |
604 playback_rate = std::max(playback_rate, 1.0); | 584 playback_rate = std::max(playback_rate, 1.0); |
(...skipping 29 matching lines...) Expand all Loading... |
634 reader_->SetPinRange(pin_backward, pin_forward); | 614 reader_->SetPinRange(pin_backward, pin_forward); |
635 | 615 |
636 if (preload_ == METADATA) { | 616 if (preload_ == METADATA) { |
637 reader_->SetPreload(0, 0); | 617 reader_->SetPreload(0, 0); |
638 } else { | 618 } else { |
639 reader_->SetPreload(preload_high, preload); | 619 reader_->SetPreload(preload_high, preload); |
640 } | 620 } |
641 } | 621 } |
642 | 622 |
643 } // namespace media | 623 } // namespace media |
OLD | NEW |