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" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
13 #include "media/base/filter_factories.h" | 13 #include "media/base/filter_factories.h" |
14 #include "media/base/filters.h" | 14 #include "media/base/filters.h" |
15 #include "webkit/glue/media/buffered_resource_loader.h" | 15 #include "webkit/glue/media/buffered_resource_loader.h" |
16 | 16 |
17 namespace media { | 17 namespace media { |
18 class MediaLog; | 18 class MediaLog; |
19 } | 19 } |
20 | 20 |
21 namespace webkit_glue { | 21 namespace webkit_glue { |
22 | 22 |
| 23 // This class may be created on any thread, and is callable from the render |
| 24 // thread as well as media-specific threads. |
23 class BufferedDataSource : public WebDataSource { | 25 class BufferedDataSource : public WebDataSource { |
24 public: | 26 public: |
25 // Creates a DataSourceFactory for building BufferedDataSource objects. | 27 // Creates a DataSourceFactory for building BufferedDataSource objects. |
26 static media::DataSourceFactory* CreateFactory( | 28 static media::DataSourceFactory* CreateFactory( |
27 MessageLoop* render_loop, | 29 MessageLoop* render_loop, |
28 WebKit::WebFrame* frame, | 30 WebKit::WebFrame* frame, |
29 media::MediaLog* media_log, | 31 media::MediaLog* media_log, |
30 WebDataSourceBuildObserverHack* build_observer); | 32 WebDataSourceBuildObserverHack* build_observer); |
31 | 33 |
32 BufferedDataSource(MessageLoop* render_loop, | 34 BufferedDataSource(MessageLoop* render_loop, |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 void PartialReadStartCallback(int error); | 120 void PartialReadStartCallback(int error); |
119 | 121 |
120 // Callback method for making a read request to BufferedResourceLoader. | 122 // Callback method for making a read request to BufferedResourceLoader. |
121 // If data arrives or the request has failed, this method is called with | 123 // If data arrives or the request has failed, this method is called with |
122 // the error code or the number of bytes read. | 124 // the error code or the number of bytes read. |
123 void ReadCallback(int error); | 125 void ReadCallback(int error); |
124 | 126 |
125 // Callback method when a network event is received. | 127 // Callback method when a network event is received. |
126 void NetworkEventCallback(); | 128 void NetworkEventCallback(); |
127 | 129 |
128 void UpdateHostState(); | 130 void UpdateHostState_Locked(); |
129 | 131 |
130 // URL of the resource requested. | 132 // URL of the resource requested. |
131 GURL url_; | 133 GURL url_; |
132 | 134 |
133 // Members for total bytes of the requested object. It is written once on | 135 // Members for total bytes of the requested object. It is written once on |
134 // render thread but may be read from any thread. However reading of this | 136 // render thread but may be read from any thread. However reading of this |
135 // member is guaranteed to happen after it is first written, so we don't | 137 // member is guaranteed to happen after it is first written, so we don't |
136 // need to protect it. | 138 // need to protect it. |
137 int64 total_bytes_; | 139 int64 total_bytes_; |
138 int64 buffered_bytes_; | 140 int64 buffered_bytes_; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 // Memory is allocated for this member during initialization of this object | 173 // Memory is allocated for this member during initialization of this object |
172 // because we want buffer to be passed into BufferedResourceLoader to be | 174 // because we want buffer to be passed into BufferedResourceLoader to be |
173 // always non-null. And by initializing this member with a default size we can | 175 // always non-null. And by initializing this member with a default size we can |
174 // avoid creating zero-sized buffered if the first read has zero size. | 176 // avoid creating zero-sized buffered if the first read has zero size. |
175 scoped_array<uint8> intermediate_read_buffer_; | 177 scoped_array<uint8> intermediate_read_buffer_; |
176 int intermediate_read_buffer_size_; | 178 int intermediate_read_buffer_size_; |
177 | 179 |
178 // The message loop of the render thread. | 180 // The message loop of the render thread. |
179 MessageLoop* render_loop_; | 181 MessageLoop* render_loop_; |
180 | 182 |
181 // Protects |stopped_|. | 183 // Protects |stop_signal_received_|, |stopped_on_render_loop_| and |
| 184 // |initialize_cb_|. |
182 base::Lock lock_; | 185 base::Lock lock_; |
183 | 186 |
184 // Stop signal to suppressing activities. This variable is set on the pipeline | 187 // Stop signal to suppressing activities. This variable is set on the pipeline |
185 // thread and read from the render thread. | 188 // thread and read from the render thread. |
186 bool stop_signal_received_; | 189 bool stop_signal_received_; |
187 | 190 |
188 // This variable is set by CleanupTask() that indicates this object is stopped | 191 // This variable is set by CleanupTask() that indicates this object is stopped |
189 // on the render thread and work should no longer progress. | 192 // on the render thread and work should no longer progress. |
190 bool stopped_on_render_loop_; | 193 bool stopped_on_render_loop_; |
191 | 194 |
(...skipping 17 matching lines...) Expand all Loading... |
209 int cache_miss_retries_left_; | 212 int cache_miss_retries_left_; |
210 | 213 |
211 scoped_refptr<media::MediaLog> media_log_; | 214 scoped_refptr<media::MediaLog> media_log_; |
212 | 215 |
213 DISALLOW_COPY_AND_ASSIGN(BufferedDataSource); | 216 DISALLOW_COPY_AND_ASSIGN(BufferedDataSource); |
214 }; | 217 }; |
215 | 218 |
216 } // namespace webkit_glue | 219 } // namespace webkit_glue |
217 | 220 |
218 #endif // WEBKIT_GLUE_MEDIA_BUFFERED_DATA_SOURCE_H_ | 221 #endif // WEBKIT_GLUE_MEDIA_BUFFERED_DATA_SOURCE_H_ |
OLD | NEW |