| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 // for testing purpose. | 55 // for testing purpose. |
| 56 BufferedResourceLoader* BufferedDataSource::CreateResourceLoader( | 56 BufferedResourceLoader* BufferedDataSource::CreateResourceLoader( |
| 57 int64 first_byte_position, int64 last_byte_position) { | 57 int64 first_byte_position, int64 last_byte_position) { |
| 58 DCHECK(MessageLoop::current() == render_loop_); | 58 DCHECK(MessageLoop::current() == render_loop_); |
| 59 | 59 |
| 60 BufferedResourceLoader::DeferStrategy strategy = preload_ == METADATA ? | 60 BufferedResourceLoader::DeferStrategy strategy = preload_ == METADATA ? |
| 61 BufferedResourceLoader::kReadThenDefer : | 61 BufferedResourceLoader::kReadThenDefer : |
| 62 BufferedResourceLoader::kThresholdDefer; | 62 BufferedResourceLoader::kThresholdDefer; |
| 63 | 63 |
| 64 return new BufferedResourceLoader(url_, | 64 return new BufferedResourceLoader(url_, |
| 65 cors_mode_, |
| 65 first_byte_position, | 66 first_byte_position, |
| 66 last_byte_position, | 67 last_byte_position, |
| 67 strategy, | 68 strategy, |
| 68 bitrate_, | 69 bitrate_, |
| 69 playback_rate_, | 70 playback_rate_, |
| 70 media_log_); | 71 media_log_); |
| 71 } | 72 } |
| 72 | 73 |
| 73 void BufferedDataSource::set_host(media::DataSourceHost* host) { | 74 void BufferedDataSource::set_host(media::DataSourceHost* host) { |
| 74 DataSource::set_host(host); | 75 DataSource::set_host(host); |
| 75 | 76 |
| 76 if (loader_.get()) { | 77 if (loader_.get()) { |
| 77 base::AutoLock auto_lock(lock_); | 78 base::AutoLock auto_lock(lock_); |
| 78 UpdateHostState_Locked(); | 79 UpdateHostState_Locked(); |
| 79 } | 80 } |
| 80 } | 81 } |
| 81 | 82 |
| 82 void BufferedDataSource::Initialize( | 83 void BufferedDataSource::Initialize( |
| 83 const GURL& url, | 84 const GURL& url, |
| 85 BufferedResourceLoader::CORSMode cors_mode, |
| 84 const media::PipelineStatusCB& initialize_cb) { | 86 const media::PipelineStatusCB& initialize_cb) { |
| 85 DCHECK(MessageLoop::current() == render_loop_); | 87 DCHECK(MessageLoop::current() == render_loop_); |
| 86 DCHECK(!initialize_cb.is_null()); | 88 DCHECK(!initialize_cb.is_null()); |
| 87 DCHECK(!loader_.get()); | 89 DCHECK(!loader_.get()); |
| 88 url_ = url; | 90 url_ = url; |
| 91 cors_mode_ = cors_mode; |
| 89 | 92 |
| 90 initialize_cb_ = initialize_cb; | 93 initialize_cb_ = initialize_cb; |
| 91 | 94 |
| 92 if (url_.SchemeIs(kHttpScheme) || url_.SchemeIs(kHttpsScheme)) { | 95 if (url_.SchemeIs(kHttpScheme) || url_.SchemeIs(kHttpsScheme)) { |
| 93 // Do an unbounded range request starting at the beginning. If the server | 96 // Do an unbounded range request starting at the beginning. If the server |
| 94 // responds with 200 instead of 206 we'll fall back into a streaming mode. | 97 // responds with 200 instead of 206 we'll fall back into a streaming mode. |
| 95 loader_.reset(CreateResourceLoader(0, kPositionNotSpecified)); | 98 loader_.reset(CreateResourceLoader(0, kPositionNotSpecified)); |
| 96 loader_->Start( | 99 loader_->Start( |
| 97 base::Bind(&BufferedDataSource::HttpInitialStartCallback, this), | 100 base::Bind(&BufferedDataSource::HttpInitialStartCallback, this), |
| 98 base::Bind(&BufferedDataSource::NetworkEventCallback, this), | 101 base::Bind(&BufferedDataSource::NetworkEventCallback, this), |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 return; | 583 return; |
| 581 | 584 |
| 582 if (total_bytes_ != kPositionNotSpecified) | 585 if (total_bytes_ != kPositionNotSpecified) |
| 583 host()->SetTotalBytes(total_bytes_); | 586 host()->SetTotalBytes(total_bytes_); |
| 584 int64 start = loader_->first_byte_position(); | 587 int64 start = loader_->first_byte_position(); |
| 585 if (buffered_bytes_ > start) | 588 if (buffered_bytes_ > start) |
| 586 host()->AddBufferedByteRange(start, buffered_bytes_); | 589 host()->AddBufferedByteRange(start, buffered_bytes_); |
| 587 } | 590 } |
| 588 | 591 |
| 589 } // namespace webkit_media | 592 } // namespace webkit_media |
| OLD | NEW |