Chromium Code Reviews| 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/buffered_data_source.h" | 5 #include "content/renderer/media/buffered_data_source.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
| 9 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
| 10 #include "media/base/media_log.h" | 10 #include "media/base/media_log.h" |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 137 void BufferedDataSource::Initialize( | 137 void BufferedDataSource::Initialize( |
| 138 const GURL& url, | 138 const GURL& url, |
| 139 BufferedResourceLoader::CORSMode cors_mode, | 139 BufferedResourceLoader::CORSMode cors_mode, |
| 140 const InitializeCB& init_cb) { | 140 const InitializeCB& init_cb) { |
| 141 DCHECK(render_loop_->BelongsToCurrentThread()); | 141 DCHECK(render_loop_->BelongsToCurrentThread()); |
| 142 DCHECK(!init_cb.is_null()); | 142 DCHECK(!init_cb.is_null()); |
| 143 DCHECK(!loader_.get()); | 143 DCHECK(!loader_.get()); |
| 144 url_ = url; | 144 url_ = url; |
| 145 cors_mode_ = cors_mode; | 145 cors_mode_ = cors_mode; |
| 146 | 146 |
| 147 init_cb_ = init_cb; | 147 init_cb_ = CreateInitializeCB(media_log_, init_cb); |
| 148 | 148 |
| 149 if (url_.SchemeIs(kHttpScheme) || url_.SchemeIs(kHttpsScheme)) { | 149 if (url_.SchemeIs(kHttpScheme) || url_.SchemeIs(kHttpsScheme)) { |
| 150 // Do an unbounded range request starting at the beginning. If the server | 150 // Do an unbounded range request starting at the beginning. If the server |
| 151 // responds with 200 instead of 206 we'll fall back into a streaming mode. | 151 // responds with 200 instead of 206 we'll fall back into a streaming mode. |
| 152 loader_.reset(CreateResourceLoader(0, kPositionNotSpecified)); | 152 loader_.reset(CreateResourceLoader(0, kPositionNotSpecified)); |
| 153 } else { | 153 } else { |
| 154 // For all other protocols, assume they support range request. We fetch | 154 // For all other protocols, assume they support range request. We fetch |
| 155 // the full range of the resource to obtain the instance size because | 155 // the full range of the resource to obtain the instance size because |
| 156 // we won't be served HTTP headers. | 156 // we won't be served HTTP headers. |
| 157 loader_.reset(CreateResourceLoader(kPositionNotSpecified, | 157 loader_.reset(CreateResourceLoader(kPositionNotSpecified, |
| 158 kPositionNotSpecified)); | 158 kPositionNotSpecified)); |
| 159 assume_fully_buffered_ = true; | 159 assume_fully_buffered_ = true; |
| 160 } | 160 } |
| 161 | 161 |
| 162 loader_->Start( | 162 loader_->Start( |
| 163 base::Bind(&BufferedDataSource::StartCallback, weak_this_), | 163 base::Bind(&BufferedDataSource::StartCallback, weak_this_), |
| 164 base::Bind(&BufferedDataSource::LoadingStateChangedCallback, weak_this_), | 164 base::Bind(&BufferedDataSource::LoadingStateChangedCallback, weak_this_), |
| 165 base::Bind(&BufferedDataSource::ProgressCallback, weak_this_), | 165 base::Bind(&BufferedDataSource::ProgressCallback, weak_this_), |
| 166 frame_); | 166 frame_); |
| 167 } | 167 } |
| 168 | 168 |
| 169 // TODO(tyoverby): remove this typedef | |
| 170 typedef base::Callback<void(bool)> InitializeCB; | |
|
Ty Overby
2013/08/20 23:06:38
scherkus@: How do I get rid of this line? I threw
| |
| 171 | |
| 172 // The reason that we need to stitch this into the normal callback | |
| 173 // is because the methods that are called require Initialize() to be called | |
| 174 // before they can be called. | |
| 175 static void OnInit(const scoped_refptr<media::MediaLog>& media_log, | |
| 176 BufferedDataSource* data_source, | |
| 177 const InitializeCB& init_cb, | |
| 178 bool success) { | |
| 179 media_log->SetBooleanProperty("single_origin", | |
| 180 data_source->HasSingleOrigin()); | |
| 181 media_log->SetBooleanProperty("pass_cors_access_check", | |
| 182 data_source->DidPassCORSAccessCheck()); | |
| 183 | |
| 184 init_cb.Run(success); | |
| 185 } | |
| 186 | |
| 187 InitializeCB BufferedDataSource::CreateInitializeCB( | |
| 188 const scoped_refptr<media::MediaLog>& media_log, | |
| 189 const InitializeCB& init_cb) { | |
| 190 | |
| 191 return base::Bind(&OnInit, media_log, this, init_cb); | |
| 192 } | |
| 193 | |
| 169 void BufferedDataSource::SetPreload(Preload preload) { | 194 void BufferedDataSource::SetPreload(Preload preload) { |
| 170 DCHECK(render_loop_->BelongsToCurrentThread()); | 195 DCHECK(render_loop_->BelongsToCurrentThread()); |
| 171 preload_ = preload; | 196 preload_ = preload; |
| 172 } | 197 } |
| 173 | 198 |
| 174 bool BufferedDataSource::HasSingleOrigin() { | 199 bool BufferedDataSource::HasSingleOrigin() { |
| 175 DCHECK(render_loop_->BelongsToCurrentThread()); | 200 DCHECK(render_loop_->BelongsToCurrentThread()); |
| 176 DCHECK(init_cb_.is_null() && loader_.get()) | 201 DCHECK(init_cb_.is_null() && loader_.get()) |
| 177 << "Initialize() must complete before calling HasSingleOrigin()"; | 202 << "Initialize() must complete before calling HasSingleOrigin()"; |
|
scherkus (not reviewing)
2013/08/21 20:31:12
if you're worried about the DCHECKs() for logging
Ty Overby
2013/08/21 22:19:52
Option 1 worked
Done.
| |
| 178 return loader_->HasSingleOrigin(); | 203 return loader_->HasSingleOrigin(); |
| 179 } | 204 } |
| 180 | 205 |
| 181 bool BufferedDataSource::DidPassCORSAccessCheck() const { | 206 bool BufferedDataSource::DidPassCORSAccessCheck() const { |
| 182 return loader_.get() && loader_->DidPassCORSAccessCheck(); | 207 return loader_.get() && loader_->DidPassCORSAccessCheck(); |
| 183 } | 208 } |
| 184 | 209 |
| 185 void BufferedDataSource::Abort() { | 210 void BufferedDataSource::Abort() { |
| 186 DCHECK(render_loop_->BelongsToCurrentThread()); | 211 DCHECK(render_loop_->BelongsToCurrentThread()); |
| 187 { | 212 { |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 364 // All responses must be successful. Resources that are assumed to be fully | 389 // All responses must be successful. Resources that are assumed to be fully |
| 365 // buffered must have a known content length. | 390 // buffered must have a known content length. |
| 366 bool success = status == BufferedResourceLoader::kOk && | 391 bool success = status == BufferedResourceLoader::kOk && |
| 367 (!assume_fully_buffered_ || | 392 (!assume_fully_buffered_ || |
| 368 loader_->instance_size() != kPositionNotSpecified); | 393 loader_->instance_size() != kPositionNotSpecified); |
| 369 | 394 |
| 370 if (success) { | 395 if (success) { |
| 371 total_bytes_ = loader_->instance_size(); | 396 total_bytes_ = loader_->instance_size(); |
| 372 streaming_ = !assume_fully_buffered_ && | 397 streaming_ = !assume_fully_buffered_ && |
| 373 (total_bytes_ == kPositionNotSpecified || !loader_->range_supported()); | 398 (total_bytes_ == kPositionNotSpecified || !loader_->range_supported()); |
| 399 | |
| 400 media_log_->SetIntegerProperty("total_bytes", total_bytes_); | |
|
scherkus (not reviewing)
2013/08/21 20:28:41
note that total_bytes_ might be -1 (kPositionNotSp
Ty Overby
2013/08/21 22:19:52
That's right; I forgot that we already had it from
Ty Overby
2013/08/21 22:19:52
Done.
| |
| 374 } else { | 401 } else { |
| 375 loader_->Stop(); | 402 loader_->Stop(); |
| 376 } | 403 } |
| 377 | 404 |
| 405 // HTTP range header | |
| 406 media_log_->SetBooleanProperty("range_supported", loader_->range_supported()); | |
| 407 | |
| 378 // TODO(scherkus): we shouldn't have to lock to signal host(), see | 408 // TODO(scherkus): we shouldn't have to lock to signal host(), see |
| 379 // http://crbug.com/113712 for details. | 409 // http://crbug.com/113712 for details. |
| 380 base::AutoLock auto_lock(lock_); | 410 base::AutoLock auto_lock(lock_); |
| 381 if (stop_signal_received_) | 411 if (stop_signal_received_) |
| 382 return; | 412 return; |
| 383 | 413 |
| 384 if (success) | 414 if (success) |
| 385 UpdateHostState_Locked(); | 415 UpdateHostState_Locked(); |
|
scherkus (not reviewing)
2013/08/21 20:28:41
similar to GpuVideoDecoder, I'd do away w/ wrappin
Ty Overby
2013/08/21 22:19:52
Ok, I'll see if I can avoid the DCHECK and put it
Ty Overby
2013/08/21 22:19:52
Done.
| |
| 386 | 416 |
| 387 base::ResetAndReturn(&init_cb_).Run(success); | 417 base::ResetAndReturn(&init_cb_).Run(success); |
| 388 } | 418 } |
| 389 | 419 |
| 390 void BufferedDataSource::PartialReadStartCallback( | 420 void BufferedDataSource::PartialReadStartCallback( |
| 391 BufferedResourceLoader::Status status) { | 421 BufferedResourceLoader::Status status) { |
| 392 DCHECK(render_loop_->BelongsToCurrentThread()); | 422 DCHECK(render_loop_->BelongsToCurrentThread()); |
| 393 DCHECK(loader_.get()); | 423 DCHECK(loader_.get()); |
| 394 | 424 |
| 395 if (status == BufferedResourceLoader::kOk) { | 425 if (status == BufferedResourceLoader::kOk) { |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 422 return; | 452 return; |
| 423 | 453 |
| 424 if (status != BufferedResourceLoader::kOk) { | 454 if (status != BufferedResourceLoader::kOk) { |
| 425 // Stop the resource load if it failed. | 455 // Stop the resource load if it failed. |
| 426 loader_->Stop(); | 456 loader_->Stop(); |
| 427 | 457 |
| 428 if (status == BufferedResourceLoader::kCacheMiss && | 458 if (status == BufferedResourceLoader::kCacheMiss && |
| 429 read_op_->retries() < kNumCacheMissRetries) { | 459 read_op_->retries() < kNumCacheMissRetries) { |
| 430 read_op_->IncrementRetries(); | 460 read_op_->IncrementRetries(); |
| 431 | 461 |
| 462 media_log_->SetIntegerProperty("read_retries", read_op_->retries()); | |
|
scherkus (not reviewing)
2013/08/21 20:28:41
I wouldn't bother with this one -- ReadCallback()
Ty Overby
2013/08/21 22:19:52
It's only called if there is a miss I believe, and
| |
| 463 | |
| 432 // Recreate a loader starting from where we last left off until the | 464 // Recreate a loader starting from where we last left off until the |
| 433 // end of the resource. | 465 // end of the resource. |
| 434 loader_.reset(CreateResourceLoader( | 466 loader_.reset(CreateResourceLoader( |
| 435 read_op_->position(), kPositionNotSpecified)); | 467 read_op_->position(), kPositionNotSpecified)); |
| 436 loader_->Start( | 468 loader_->Start( |
| 437 base::Bind(&BufferedDataSource::PartialReadStartCallback, weak_this_), | 469 base::Bind(&BufferedDataSource::PartialReadStartCallback, weak_this_), |
| 438 base::Bind(&BufferedDataSource::LoadingStateChangedCallback, | 470 base::Bind(&BufferedDataSource::LoadingStateChangedCallback, |
| 439 weak_this_), | 471 weak_this_), |
| 440 base::Bind(&BufferedDataSource::ProgressCallback, weak_this_), | 472 base::Bind(&BufferedDataSource::ProgressCallback, weak_this_), |
| 441 frame_); | 473 frame_); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 529 if (total_bytes_ == kPositionNotSpecified) | 561 if (total_bytes_ == kPositionNotSpecified) |
| 530 return; | 562 return; |
| 531 | 563 |
| 532 host()->SetTotalBytes(total_bytes_); | 564 host()->SetTotalBytes(total_bytes_); |
| 533 | 565 |
| 534 if (assume_fully_buffered_) | 566 if (assume_fully_buffered_) |
| 535 host()->AddBufferedByteRange(0, total_bytes_); | 567 host()->AddBufferedByteRange(0, total_bytes_); |
| 536 } | 568 } |
| 537 | 569 |
| 538 } // namespace content | 570 } // namespace content |
| OLD | NEW |