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 "media/base/media_log.h" | 8 #include "media/base/media_log.h" |
9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
10 | 10 |
(...skipping 24 matching lines...) Expand all Loading... |
35 read_size_(0), | 35 read_size_(0), |
36 read_buffer_(NULL), | 36 read_buffer_(NULL), |
37 intermediate_read_buffer_(new uint8[kInitialReadBufferSize]), | 37 intermediate_read_buffer_(new uint8[kInitialReadBufferSize]), |
38 intermediate_read_buffer_size_(kInitialReadBufferSize), | 38 intermediate_read_buffer_size_(kInitialReadBufferSize), |
39 render_loop_(render_loop), | 39 render_loop_(render_loop), |
40 stop_signal_received_(false), | 40 stop_signal_received_(false), |
41 stopped_on_render_loop_(false), | 41 stopped_on_render_loop_(false), |
42 media_is_paused_(true), | 42 media_is_paused_(true), |
43 media_has_played_(false), | 43 media_has_played_(false), |
44 preload_(media::AUTO), | 44 preload_(media::AUTO), |
45 using_range_request_(true), | |
46 cache_miss_retries_left_(kNumCacheMissRetries), | 45 cache_miss_retries_left_(kNumCacheMissRetries), |
47 bitrate_(0), | 46 bitrate_(0), |
48 playback_rate_(0.0), | 47 playback_rate_(0.0), |
49 media_log_(media_log) { | 48 media_log_(media_log) { |
50 } | 49 } |
51 | 50 |
52 BufferedDataSource::~BufferedDataSource() {} | 51 BufferedDataSource::~BufferedDataSource() {} |
53 | 52 |
54 // A factory method to create BufferedResourceLoader using the read parameters. | 53 // A factory method to create BufferedResourceLoader using the read parameters. |
55 // This method can be overrided to inject mock BufferedResourceLoader object | 54 // This method can be overrided to inject mock BufferedResourceLoader object |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 // TODO(hclam): Needs more thinking about supporting servers without range | 384 // TODO(hclam): Needs more thinking about supporting servers without range |
386 // request or their partial response is not complete. | 385 // request or their partial response is not complete. |
387 total_bytes_ = instance_size; | 386 total_bytes_ = instance_size; |
388 streaming_ = (instance_size == kPositionNotSpecified) || | 387 streaming_ = (instance_size == kPositionNotSpecified) || |
389 !loader_->range_supported(); | 388 !loader_->range_supported(); |
390 } else { | 389 } else { |
391 // TODO(hclam): In case of failure, we can retry several times. | 390 // TODO(hclam): In case of failure, we can retry several times. |
392 loader_->Stop(); | 391 loader_->Stop(); |
393 } | 392 } |
394 | 393 |
395 if (error == net::ERR_INVALID_RESPONSE && using_range_request_) { | |
396 // Assuming that the Range header was causing the problem. Retry without | |
397 // the Range header. | |
398 using_range_request_ = false; | |
399 loader_.reset(CreateResourceLoader(kPositionNotSpecified, | |
400 kPositionNotSpecified)); | |
401 loader_->Start( | |
402 base::Bind(&BufferedDataSource::HttpInitialStartCallback, this), | |
403 base::Bind(&BufferedDataSource::NetworkEventCallback, this), | |
404 frame_); | |
405 return; | |
406 } | |
407 | |
408 // Reference to prevent destruction while inside the |initialize_cb_| | 394 // Reference to prevent destruction while inside the |initialize_cb_| |
409 // call. This is a temporary fix to prevent crashes caused by holding the | 395 // call. This is a temporary fix to prevent crashes caused by holding the |
410 // lock and running the destructor. | 396 // lock and running the destructor. |
411 // TODO: Review locking in this class and figure out a way to run the callback | 397 // TODO: Review locking in this class and figure out a way to run the callback |
412 // w/o the lock. | 398 // w/o the lock. |
413 scoped_refptr<BufferedDataSource> destruction_guard(this); | 399 scoped_refptr<BufferedDataSource> destruction_guard(this); |
414 { | 400 { |
415 // We need to prevent calling to filter host and running the callback if | 401 // We need to prevent calling to filter host and running the callback if |
416 // we have received the stop signal. We need to lock down the whole callback | 402 // we have received the stop signal. We need to lock down the whole callback |
417 // method to prevent bad things from happening. The reason behind this is | 403 // method to prevent bad things from happening. The reason behind this is |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 | 593 |
608 if (!host()) | 594 if (!host()) |
609 return; | 595 return; |
610 | 596 |
611 if (total_bytes_ != kPositionNotSpecified) | 597 if (total_bytes_ != kPositionNotSpecified) |
612 host()->SetTotalBytes(total_bytes_); | 598 host()->SetTotalBytes(total_bytes_); |
613 host()->SetBufferedBytes(buffered_bytes_); | 599 host()->SetBufferedBytes(buffered_bytes_); |
614 } | 600 } |
615 | 601 |
616 } // namespace webkit_media | 602 } // namespace webkit_media |
OLD | NEW |