OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "webkit/media/buffered_data_source.h" | 5 #include "webkit/media/buffered_data_source.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "media/base/media_log.h" | 9 #include "media/base/media_log.h" |
10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 | 65 |
66 // A factory method to create BufferedResourceLoader using the read parameters. | 66 // A factory method to create BufferedResourceLoader using the read parameters. |
67 // This method can be overridden to inject mock BufferedResourceLoader object | 67 // This method can be overridden to inject mock BufferedResourceLoader object |
68 // for testing purpose. | 68 // for testing purpose. |
69 BufferedResourceLoader* BufferedDataSource::CreateResourceLoader( | 69 BufferedResourceLoader* BufferedDataSource::CreateResourceLoader( |
70 int64 first_byte_position, int64 last_byte_position) { | 70 int64 first_byte_position, int64 last_byte_position) { |
71 DCHECK(MessageLoop::current() == render_loop_); | 71 DCHECK(MessageLoop::current() == render_loop_); |
72 | 72 |
73 BufferedResourceLoader::DeferStrategy strategy = preload_ == METADATA ? | 73 BufferedResourceLoader::DeferStrategy strategy = preload_ == METADATA ? |
74 BufferedResourceLoader::kReadThenDefer : | 74 BufferedResourceLoader::kReadThenDefer : |
75 BufferedResourceLoader::kThresholdDefer; | 75 BufferedResourceLoader::kCapacityDefer; |
76 | 76 |
77 return new BufferedResourceLoader(url_, | 77 return new BufferedResourceLoader(url_, |
78 cors_mode_, | 78 cors_mode_, |
79 first_byte_position, | 79 first_byte_position, |
80 last_byte_position, | 80 last_byte_position, |
81 strategy, | 81 strategy, |
82 bitrate_, | 82 bitrate_, |
83 playback_rate_, | 83 playback_rate_, |
84 media_log_); | 84 media_log_); |
85 } | 85 } |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 if (playback_rate != 0) | 302 if (playback_rate != 0) |
303 media_has_played_ = true; | 303 media_has_played_ = true; |
304 | 304 |
305 playback_rate_ = playback_rate; | 305 playback_rate_ = playback_rate; |
306 loader_->SetPlaybackRate(playback_rate); | 306 loader_->SetPlaybackRate(playback_rate); |
307 | 307 |
308 if (!loader_->range_supported()) { | 308 if (!loader_->range_supported()) { |
309 // 200 responses end up not being reused to satisfy future range requests, | 309 // 200 responses end up not being reused to satisfy future range requests, |
310 // and we don't want to get too far ahead of the read-head (and thus require | 310 // and we don't want to get too far ahead of the read-head (and thus require |
311 // a restart), so keep to the thresholds. | 311 // a restart), so keep to the thresholds. |
312 loader_->UpdateDeferStrategy(BufferedResourceLoader::kThresholdDefer); | 312 loader_->UpdateDeferStrategy(BufferedResourceLoader::kCapacityDefer); |
313 } else if (media_has_played_ && playback_rate == 0) { | 313 } else if (media_has_played_ && playback_rate == 0) { |
314 // If the playback has started (at which point the preload value is ignored) | 314 // If the playback has started (at which point the preload value is ignored) |
315 // and we're paused, then try to load as much as possible (the loader will | 315 // and we're paused, then try to load as much as possible (the loader will |
316 // fall back to kThresholdDefer if it knows the current response won't be | 316 // fall back to kCapacityDefer if it knows the current response won't be |
317 // useful from the cache in the future). | 317 // useful from the cache in the future). |
318 loader_->UpdateDeferStrategy(BufferedResourceLoader::kNeverDefer); | 318 loader_->UpdateDeferStrategy(BufferedResourceLoader::kNeverDefer); |
319 } else { | 319 } else { |
320 // If media is currently playing or the page indicated preload=auto, | 320 // If media is currently playing or the page indicated preload=auto, |
321 // use threshold strategy to enable/disable deferring when the buffer | 321 // use threshold strategy to enable/disable deferring when the buffer |
322 // is full/depleted. | 322 // is full/depleted. |
323 loader_->UpdateDeferStrategy(BufferedResourceLoader::kThresholdDefer); | 323 loader_->UpdateDeferStrategy(BufferedResourceLoader::kCapacityDefer); |
324 } | 324 } |
325 } | 325 } |
326 | 326 |
327 void BufferedDataSource::SetBitrateTask(int bitrate) { | 327 void BufferedDataSource::SetBitrateTask(int bitrate) { |
328 DCHECK(MessageLoop::current() == render_loop_); | 328 DCHECK(MessageLoop::current() == render_loop_); |
329 DCHECK(loader_.get()); | 329 DCHECK(loader_.get()); |
330 | 330 |
331 bitrate_ = bitrate; | 331 bitrate_ = bitrate; |
332 loader_->SetBitrate(bitrate); | 332 loader_->SetBitrate(bitrate); |
333 } | 333 } |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
608 return; | 608 return; |
609 | 609 |
610 if (total_bytes_ != kPositionNotSpecified) | 610 if (total_bytes_ != kPositionNotSpecified) |
611 host()->SetTotalBytes(total_bytes_); | 611 host()->SetTotalBytes(total_bytes_); |
612 int64 start = loader_->first_byte_position(); | 612 int64 start = loader_->first_byte_position(); |
613 if (buffered_bytes_ > start) | 613 if (buffered_bytes_ > start) |
614 host()->AddBufferedByteRange(start, buffered_bytes_); | 614 host()->AddBufferedByteRange(start, buffered_bytes_); |
615 } | 615 } |
616 | 616 |
617 } // namespace webkit_media | 617 } // namespace webkit_media |
OLD | NEW |