| 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 #ifndef WEBKIT_MEDIA_BUFFERED_RESOURCE_LOADER_H_ | 5 #ifndef WEBKIT_MEDIA_BUFFERED_RESOURCE_LOADER_H_ |
| 6 #define WEBKIT_MEDIA_BUFFERED_RESOURCE_LOADER_H_ | 6 #define WEBKIT_MEDIA_BUFFERED_RESOURCE_LOADER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 } | 24 } |
| 25 | 25 |
| 26 namespace webkit_media { | 26 namespace webkit_media { |
| 27 | 27 |
| 28 const int64 kPositionNotSpecified = -1; | 28 const int64 kPositionNotSpecified = -1; |
| 29 | 29 |
| 30 const char kHttpScheme[] = "http"; | 30 const char kHttpScheme[] = "http"; |
| 31 const char kHttpsScheme[] = "https"; | 31 const char kHttpsScheme[] = "https"; |
| 32 const char kDataScheme[] = "data"; | 32 const char kDataScheme[] = "data"; |
| 33 | 33 |
| 34 // This class works inside demuxer thread and render thread. It contains a | 34 // Wraps a WebURLLoader to maintain an in-memory buffer of downloaded |
| 35 // WebURLLoader and does the actual resource loading. This object does | 35 // data according to the current defer strategy. |
| 36 // buffering internally, it defers the resource loading if buffer is full | |
| 37 // and un-defers the resource loading if it is under buffered. | |
| 38 class BufferedResourceLoader : public WebKit::WebURLLoaderClient { | 36 class BufferedResourceLoader : public WebKit::WebURLLoaderClient { |
| 39 public: | 37 public: |
| 40 // kNeverDefer - Aggresively buffer; never defer loading while paused. | 38 // kNeverDefer - Aggresively buffer; never defer loading while paused. |
| 41 // kReadThenDefer - Request only enough data to fulfill read requests. | 39 // kReadThenDefer - Request only enough data to fulfill read requests. |
| 42 // kThresholdDefer - Try to keep amount of buffered data at a threshold. | 40 // kCapacityDefer - Try to keep amount of buffered data at capacity. |
| 43 enum DeferStrategy { | 41 enum DeferStrategy { |
| 44 kNeverDefer, | 42 kNeverDefer, |
| 45 kReadThenDefer, | 43 kReadThenDefer, |
| 46 kThresholdDefer, | 44 kCapacityDefer, |
| 47 }; | 45 }; |
| 48 | 46 |
| 49 // Status codes for start/read operations on BufferedResourceLoader. | 47 // Status codes for start/read operations on BufferedResourceLoader. |
| 50 enum Status { | 48 enum Status { |
| 51 // Everything went as planned. | 49 // Everything went as planned. |
| 52 kOk, | 50 kOk, |
| 53 | 51 |
| 54 // The operation failed, which may have been due to: | 52 // The operation failed, which may have been due to: |
| 55 // - Page navigation | 53 // - Page navigation |
| 56 // - Server replied 4xx/5xx | 54 // - Server replied 4xx/5xx |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 | 170 |
| 173 // Returns true if the media resource has a single origin, false otherwise. | 171 // Returns true if the media resource has a single origin, false otherwise. |
| 174 // Only valid to call after Start() has completed. | 172 // Only valid to call after Start() has completed. |
| 175 bool HasSingleOrigin() const; | 173 bool HasSingleOrigin() const; |
| 176 | 174 |
| 177 // Returns true if the media resource passed a CORS access control check. | 175 // Returns true if the media resource passed a CORS access control check. |
| 178 // Only valid to call after Start() has completed. | 176 // Only valid to call after Start() has completed. |
| 179 bool DidPassCORSAccessCheck() const; | 177 bool DidPassCORSAccessCheck() const; |
| 180 | 178 |
| 181 // Sets the defer strategy to the given value unless it seems unwise. | 179 // Sets the defer strategy to the given value unless it seems unwise. |
| 182 // Specifically downgrade kNeverDefer to kThresholdDefer if we know the | 180 // Specifically downgrade kNeverDefer to kCapacityDefer if we know the |
| 183 // current response will not be used to satisfy future requests (the cache | 181 // current response will not be used to satisfy future requests (the cache |
| 184 // won't help us). | 182 // won't help us). |
| 185 void UpdateDeferStrategy(DeferStrategy strategy); | 183 void UpdateDeferStrategy(DeferStrategy strategy); |
| 186 | 184 |
| 187 // Sets the playback rate to the given value and updates buffer window | 185 // Sets the playback rate to the given value and updates buffer window |
| 188 // accordingly. | 186 // accordingly. |
| 189 void SetPlaybackRate(float playback_rate); | 187 void SetPlaybackRate(float playback_rate); |
| 190 | 188 |
| 191 // Sets the bitrate to the given value and updates buffer window | 189 // Sets the bitrate to the given value and updates buffer window |
| 192 // accordingly. | 190 // accordingly. |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 float playback_rate_; | 328 float playback_rate_; |
| 331 | 329 |
| 332 scoped_refptr<media::MediaLog> media_log_; | 330 scoped_refptr<media::MediaLog> media_log_; |
| 333 | 331 |
| 334 DISALLOW_COPY_AND_ASSIGN(BufferedResourceLoader); | 332 DISALLOW_COPY_AND_ASSIGN(BufferedResourceLoader); |
| 335 }; | 333 }; |
| 336 | 334 |
| 337 } // namespace webkit_media | 335 } // namespace webkit_media |
| 338 | 336 |
| 339 #endif // WEBKIT_MEDIA_BUFFERED_RESOURCE_LOADER_H_ | 337 #endif // WEBKIT_MEDIA_BUFFERED_RESOURCE_LOADER_H_ |
| OLD | NEW |