OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_GLUE_MEDIA_BUFFERED_RESOURCE_LOADER_H_ | 5 #ifndef WEBKIT_GLUE_MEDIA_BUFFERED_RESOURCE_LOADER_H_ |
6 #define WEBKIT_GLUE_MEDIA_BUFFERED_RESOURCE_LOADER_H_ | 6 #define WEBKIT_GLUE_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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 kThresholdDefer, | 49 kThresholdDefer, |
50 }; | 50 }; |
51 | 51 |
52 typedef Callback0::Type NetworkEventCallback; | 52 typedef Callback0::Type NetworkEventCallback; |
53 | 53 |
54 // |url| - URL for the resource to be loaded. | 54 // |url| - URL for the resource to be loaded. |
55 // |first_byte_position| - First byte to start loading from, | 55 // |first_byte_position| - First byte to start loading from, |
56 // |kPositionNotSpecified| for not specified. | 56 // |kPositionNotSpecified| for not specified. |
57 // |last_byte_position| - Last byte to be loaded, | 57 // |last_byte_position| - Last byte to be loaded, |
58 // |kPositionNotSpecified| for not specified. | 58 // |kPositionNotSpecified| for not specified. |
| 59 // |strategy| is the initial loading strategy to use. |
| 60 // |bitrate| is the bitrate of the media, 0 if unknown. |
| 61 // |playback_rate| is the current playback rate of the media. |
59 BufferedResourceLoader(const GURL& url, | 62 BufferedResourceLoader(const GURL& url, |
60 int64 first_byte_position, | 63 int64 first_byte_position, |
61 int64 last_byte_position, | 64 int64 last_byte_position, |
| 65 DeferStrategy strategy, |
| 66 int bitrate, |
| 67 float playback_rate, |
62 media::MediaLog* media_log); | 68 media::MediaLog* media_log); |
63 | 69 |
64 // Start the resource loading with the specified URL and range. | 70 // Start the resource loading with the specified URL and range. |
65 // This method operates in asynchronous mode. Once there's a response from the | 71 // This method operates in asynchronous mode. Once there's a response from the |
66 // server, success or fail |callback| is called with the result. | 72 // server, success or fail |callback| is called with the result. |
67 // |callback| is called with the following values: | 73 // |callback| is called with the following values: |
68 // - net::OK | 74 // - net::OK |
69 // The request has started successfully. | 75 // The request has started successfully. |
70 // - net::ERR_FAILED | 76 // - net::ERR_FAILED |
71 // The request has failed because of an error with the network. | 77 // The request has failed because of an error with the network. |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 double finishTime); | 155 double finishTime); |
150 virtual void didFail( | 156 virtual void didFail( |
151 WebKit::WebURLLoader* loader, | 157 WebKit::WebURLLoader* loader, |
152 const WebKit::WebURLError&); | 158 const WebKit::WebURLError&); |
153 | 159 |
154 bool HasSingleOrigin() const; | 160 bool HasSingleOrigin() const; |
155 | 161 |
156 // Sets the defer strategy to the given value. | 162 // Sets the defer strategy to the given value. |
157 void UpdateDeferStrategy(DeferStrategy strategy); | 163 void UpdateDeferStrategy(DeferStrategy strategy); |
158 | 164 |
| 165 // Sets the playback rate to the given value and updates buffer window |
| 166 // accordingly. |
| 167 void SetPlaybackRate(float playback_rate); |
| 168 |
| 169 // Sets the bitrate to the given value and updates buffer window |
| 170 // accordingly. |
| 171 void SetBitrate(int bitrate); |
| 172 |
159 protected: | 173 protected: |
160 friend class base::RefCountedThreadSafe<BufferedResourceLoader>; | 174 friend class base::RefCountedThreadSafe<BufferedResourceLoader>; |
161 virtual ~BufferedResourceLoader(); | 175 virtual ~BufferedResourceLoader(); |
162 | 176 |
163 private: | 177 private: |
| 178 friend class BufferedDataSourceTest2; |
164 friend class BufferedResourceLoaderTest; | 179 friend class BufferedResourceLoaderTest; |
165 | 180 |
| 181 // Updates the |buffer_|'s forward and backward capacities. |
| 182 void UpdateBufferWindow(); |
| 183 |
166 // Toggles whether the resource loading is deferred or not. | 184 // Toggles whether the resource loading is deferred or not. |
167 // Returns true if a network event was fired. | 185 // Returns true if a network event was fired. |
168 bool ToggleDeferring(); | 186 bool ToggleDeferring(); |
169 | 187 |
170 // Returns true if we should defer resource loading, based | 188 // Returns true if we should defer resource loading, based |
171 // on current buffering scheme. | 189 // on current buffering scheme. |
172 bool ShouldEnableDefer(); | 190 bool ShouldEnableDefer(); |
173 | 191 |
174 // Returns true if we should enable resource loading, based | 192 // Returns true if we should enable resource loading, based |
175 // on current buffering scheme. | 193 // on current buffering scheme. |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 uint8* read_buffer_; | 283 uint8* read_buffer_; |
266 | 284 |
267 // Offsets of the requested first byte and last byte in |buffer_|. They are | 285 // Offsets of the requested first byte and last byte in |buffer_|. They are |
268 // written by Read(). | 286 // written by Read(). |
269 int first_offset_; | 287 int first_offset_; |
270 int last_offset_; | 288 int last_offset_; |
271 | 289 |
272 // Used to ensure mocks for unittests are used instead of reset in Start(). | 290 // Used to ensure mocks for unittests are used instead of reset in Start(). |
273 bool keep_test_loader_; | 291 bool keep_test_loader_; |
274 | 292 |
| 293 // Bitrate of the media. Set to 0 if unknown. |
| 294 int bitrate_; |
| 295 |
| 296 // Playback rate of the media. |
| 297 float playback_rate_; |
| 298 |
275 scoped_refptr<media::MediaLog> media_log_; | 299 scoped_refptr<media::MediaLog> media_log_; |
276 | 300 |
277 DISALLOW_COPY_AND_ASSIGN(BufferedResourceLoader); | 301 DISALLOW_COPY_AND_ASSIGN(BufferedResourceLoader); |
278 }; | 302 }; |
279 | 303 |
280 } // namespace webkit_glue | 304 } // namespace webkit_glue |
281 | 305 |
282 #endif // WEBKIT_GLUE_MEDIA_BUFFERED_RESOURCE_LOADER_H_ | 306 #endif // WEBKIT_GLUE_MEDIA_BUFFERED_RESOURCE_LOADER_H_ |
OLD | NEW |