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_DATA_SOURCE_H_ | 5 #ifndef WEBKIT_GLUE_MEDIA_BUFFERED_DATA_SOURCE_H_ |
6 #define WEBKIT_GLUE_MEDIA_BUFFERED_DATA_SOURCE_H_ | 6 #define WEBKIT_GLUE_MEDIA_BUFFERED_DATA_SOURCE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 virtual void SetPlaybackRate(float playback_rate); | 43 virtual void SetPlaybackRate(float playback_rate); |
44 | 44 |
45 // media::DataSource implementation. | 45 // media::DataSource implementation. |
46 // Called from demuxer thread. | 46 // Called from demuxer thread. |
47 virtual void Read(int64 position, size_t size, | 47 virtual void Read(int64 position, size_t size, |
48 uint8* data, | 48 uint8* data, |
49 media::DataSource::ReadCallback* read_callback); | 49 media::DataSource::ReadCallback* read_callback); |
50 virtual bool GetSize(int64* size_out); | 50 virtual bool GetSize(int64* size_out); |
51 virtual bool IsStreaming(); | 51 virtual bool IsStreaming(); |
52 virtual void SetPreload(media::Preload preload); | 52 virtual void SetPreload(media::Preload preload); |
| 53 virtual void SetBitrate(int bitrate); |
53 | 54 |
54 // webkit_glue::WebDataSource implementation. | 55 // webkit_glue::WebDataSource implementation. |
55 virtual void Initialize(const std::string& url, | 56 virtual void Initialize(const std::string& url, |
56 const media::PipelineStatusCB& callback); | 57 const media::PipelineStatusCB& callback); |
57 virtual void CancelInitialize(); | 58 virtual void CancelInitialize(); |
58 virtual bool HasSingleOrigin(); | 59 virtual bool HasSingleOrigin(); |
59 virtual void Abort(); | 60 virtual void Abort(); |
60 | 61 |
61 protected: | 62 protected: |
62 // A factory method to create a BufferedResourceLoader based on the read | 63 // A factory method to create a BufferedResourceLoader based on the read |
63 // parameters. We can override this file to object a mock | 64 // parameters. We can override this file to object a mock |
64 // BufferedResourceLoader for testing. | 65 // BufferedResourceLoader for testing. |
65 virtual BufferedResourceLoader* CreateResourceLoader( | 66 virtual BufferedResourceLoader* CreateResourceLoader( |
66 int64 first_byte_position, int64 last_byte_position); | 67 int64 first_byte_position, int64 last_byte_position); |
67 | 68 |
68 private: | 69 private: |
| 70 friend class BufferedDataSourceTest2; |
| 71 |
69 // Posted to perform initialization on render thread and start resource | 72 // Posted to perform initialization on render thread and start resource |
70 // loading. | 73 // loading. |
71 void InitializeTask(); | 74 void InitializeTask(); |
72 | 75 |
73 // Task posted to perform actual reading on the render thread. | 76 // Task posted to perform actual reading on the render thread. |
74 void ReadTask(int64 position, int read_size, uint8* read_buffer); | 77 void ReadTask(int64 position, int read_size, uint8* read_buffer); |
75 | 78 |
76 // Task posted when Stop() is called. Stops |watch_dog_timer_| and | 79 // Task posted when Stop() is called. Stops |watch_dog_timer_| and |
77 // |loader_|, reset Read() variables, and set |stopped_on_render_loop_| | 80 // |loader_|, reset Read() variables, and set |stopped_on_render_loop_| |
78 // to signal any remaining tasks to stop. | 81 // to signal any remaining tasks to stop. |
79 void CleanupTask(); | 82 void CleanupTask(); |
80 | 83 |
81 // Restart resource loading on render thread. | 84 // Restart resource loading on render thread. |
82 void RestartLoadingTask(); | 85 void RestartLoadingTask(); |
83 | 86 |
84 // This task uses the current playback rate with the previous playback rate | 87 // This task uses the current playback rate with the previous playback rate |
85 // to determine whether we are going from pause to play and play to pause, | 88 // to determine whether we are going from pause to play and play to pause, |
86 // and signals the buffered resource loader accordingly. | 89 // and signals the buffered resource loader accordingly. |
87 void SetPlaybackRateTask(float playback_rate); | 90 void SetPlaybackRateTask(float playback_rate); |
88 | 91 |
89 // This task saves the preload value for the media. | 92 // This task saves the preload value for the media. |
90 void SetPreloadTask(media::Preload preload); | 93 void SetPreloadTask(media::Preload preload); |
91 | 94 |
| 95 // Tells |loader_| the bitrate of the media. |
| 96 void SetBitrateTask(int bitrate); |
| 97 |
92 // Decides which DeferStrategy to used based on the current state of the | 98 // Decides which DeferStrategy to used based on the current state of the |
93 // BufferedDataSource. | 99 // BufferedDataSource. |
94 BufferedResourceLoader::DeferStrategy ChooseDeferStrategy(); | 100 BufferedResourceLoader::DeferStrategy ChooseDeferStrategy(); |
95 | 101 |
96 // The method that performs actual read. This method can only be executed on | 102 // The method that performs actual read. This method can only be executed on |
97 // the render thread. | 103 // the render thread. |
98 void ReadInternal(); | 104 void ReadInternal(); |
99 | 105 |
100 // Calls |read_callback_| and reset all read parameters. | 106 // Calls |read_callback_| and reset all read parameters. |
101 void DoneRead_Locked(int error); | 107 void DoneRead_Locked(int error); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 // element. | 210 // element. |
205 media::Preload preload_; | 211 media::Preload preload_; |
206 | 212 |
207 // Keeps track of whether we used a Range header in the initialization | 213 // Keeps track of whether we used a Range header in the initialization |
208 // request. | 214 // request. |
209 bool using_range_request_; | 215 bool using_range_request_; |
210 | 216 |
211 // Number of cache miss retries left. | 217 // Number of cache miss retries left. |
212 int cache_miss_retries_left_; | 218 int cache_miss_retries_left_; |
213 | 219 |
| 220 // Bitrate of the content, 0 if unknown. |
| 221 int bitrate_; |
| 222 |
| 223 // Current playback rate. |
| 224 float playback_rate_; |
| 225 |
214 scoped_refptr<media::MediaLog> media_log_; | 226 scoped_refptr<media::MediaLog> media_log_; |
215 | 227 |
216 DISALLOW_COPY_AND_ASSIGN(BufferedDataSource); | 228 DISALLOW_COPY_AND_ASSIGN(BufferedDataSource); |
217 }; | 229 }; |
218 | 230 |
219 } // namespace webkit_glue | 231 } // namespace webkit_glue |
220 | 232 |
221 #endif // WEBKIT_GLUE_MEDIA_BUFFERED_DATA_SOURCE_H_ | 233 #endif // WEBKIT_GLUE_MEDIA_BUFFERED_DATA_SOURCE_H_ |
OLD | NEW |