Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1140)

Side by Side Diff: webkit/glue/media/buffered_data_source.h

Issue 159382: Retry requests that has timed out in BufferedDataSource (Closed)
Patch Set: done again Created 11 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | webkit/glue/media/buffered_data_source.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this
2 // source code is governed by a BSD-style license that can be found in the 2 // source code is governed by a BSD-style license that can be found in the
3 // LICENSE file. 3 // 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/lock.h" 10 #include "base/lock.h"
11 #include "base/scoped_ptr.h" 11 #include "base/scoped_ptr.h"
12 #include "base/timer.h"
12 #include "base/condition_variable.h" 13 #include "base/condition_variable.h"
13 #include "googleurl/src/gurl.h" 14 #include "googleurl/src/gurl.h"
14 #include "media/base/factory.h" 15 #include "media/base/factory.h"
15 #include "media/base/filters.h" 16 #include "media/base/filters.h"
16 #include "media/base/media_format.h" 17 #include "media/base/media_format.h"
17 #include "media/base/pipeline.h" 18 #include "media/base/pipeline.h"
18 #include "media/base/seekable_buffer.h" 19 #include "media/base/seekable_buffer.h"
19 #include "net/base/completion_callback.h" 20 #include "net/base/completion_callback.h"
20 #include "net/base/file_stream.h" 21 #include "net/base/file_stream.h"
21 #include "webkit/glue/media/media_resource_loader_bridge_factory.h" 22 #include "webkit/glue/media/media_resource_loader_bridge_factory.h"
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 MessageLoop* render_loop, 177 MessageLoop* render_loop,
177 webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory); 178 webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory);
178 virtual ~BufferedDataSource(); 179 virtual ~BufferedDataSource();
179 180
180 // A factory method to create a BufferedResourceLoader based on the read 181 // A factory method to create a BufferedResourceLoader based on the read
181 // parameters. We can override this file to object a mock 182 // parameters. We can override this file to object a mock
182 // BufferedResourceLoader for testing. 183 // BufferedResourceLoader for testing.
183 virtual BufferedResourceLoader* CreateLoader(int64 first_byte_position, 184 virtual BufferedResourceLoader* CreateLoader(int64 first_byte_position,
184 int64 last_byte_position); 185 int64 last_byte_position);
185 186
187 // Gets the number of milliseconds to declare a request timeout since
188 // the request was made. This method is made virtual so as to inject a
189 // different number for testing purpose.
190 virtual base::TimeDelta GetTimeoutMilliseconds();
191
186 private: 192 private:
187 friend class media::FilterFactoryImpl2< 193 friend class media::FilterFactoryImpl2<
188 BufferedDataSource, 194 BufferedDataSource,
189 MessageLoop*, 195 MessageLoop*,
190 webkit_glue::MediaResourceLoaderBridgeFactory*>; 196 webkit_glue::MediaResourceLoaderBridgeFactory*>;
191 197
192 // Posted to perform initialization on render thread. 198 // Posted to perform initialization on render thread.
193 void InitializeTask(); 199 void InitializeTask();
194 200
195 // Task posted to perform resource loading and actual reading on the render 201 // Task posted to perform resource loading and actual reading on the render
196 // thread. 202 // thread.
197 void ReadTask(int64 position, int read_size, 203 void ReadTask(int64 position, int read_size,
198 uint8* read_buffer, 204 uint8* read_buffer,
199 media::DataSource::ReadCallback* read_callback); 205 media::DataSource::ReadCallback* read_callback);
200 206
201 // Task posted when Stop() is called. 207 // Task posted when Stop() is called.
202 void StopTask(); 208 void StopTask();
203 209
204 // Reset |loader_| with |loader| and starts it. This task is posted from 210 // Reset |loader_| with |loader| and starts it. This task is posted from
205 // callback method from the current buffered resource loader. 211 // callback method from the current buffered resource loader.
206 void SwapLoaderTask(BufferedResourceLoader* loader); 212 void SwapLoaderTask(BufferedResourceLoader* loader);
207 213
214 // This task monitors the current active read request. If the current read
215 // request has timed out, this task will destroy the current loader and
216 // creates a new to accomodate the read request.
217 void WatchDogTask();
218
208 // The method that performs actual read. This method can only be executed on 219 // The method that performs actual read. This method can only be executed on
209 // the render thread. 220 // the render thread.
210 void ReadInternal(); 221 void ReadInternal();
211 222
212 // Calls |read_callback_| and reset all read parameters. 223 // Calls |read_callback_| and reset all read parameters.
213 void DoneRead(int error); 224 void DoneRead(int error);
214 225
215 // Calls |initialize_callback_| and reset it. 226 // Calls |initialize_callback_| and reset it.
216 void DoneInitialization(); 227 void DoneInitialization();
217 228
(...skipping 27 matching lines...) Expand all
245 scoped_ptr<webkit_glue::MediaResourceLoaderBridgeFactory> bridge_factory_; 256 scoped_ptr<webkit_glue::MediaResourceLoaderBridgeFactory> bridge_factory_;
246 257
247 // A downloader object for loading the media resource. 258 // A downloader object for loading the media resource.
248 scoped_ptr<BufferedResourceLoader> loader_; 259 scoped_ptr<BufferedResourceLoader> loader_;
249 260
250 // Read parameters received from the Read() method call. 261 // Read parameters received from the Read() method call.
251 scoped_ptr<media::DataSource::ReadCallback> read_callback_; 262 scoped_ptr<media::DataSource::ReadCallback> read_callback_;
252 int64 read_position_; 263 int64 read_position_;
253 int read_size_; 264 int read_size_;
254 uint8* read_buffer_; 265 uint8* read_buffer_;
266 base::Time read_submitted_time_;
267 int read_attempts_;
255 268
256 // This buffer is intermediate, we use it for BufferedResourceLoader to write 269 // This buffer is intermediate, we use it for BufferedResourceLoader to write
257 // to. And when read in BufferedResourceLoader is done, we copy data from 270 // to. And when read in BufferedResourceLoader is done, we copy data from
258 // this buffer to |read_buffer_|. The reason for an additional copy is that 271 // this buffer to |read_buffer_|. The reason for an additional copy is that
259 // we don't own |read_buffer_|. But since the read operation is asynchronous, 272 // we don't own |read_buffer_|. But since the read operation is asynchronous,
260 // |read_buffer| can be destroyed at any time, so we only copy into 273 // |read_buffer| can be destroyed at any time, so we only copy into
261 // |read_buffer| in the final step when it is safe. 274 // |read_buffer| in the final step when it is safe.
262 // Memory is allocated for this member during initialization of this object 275 // Memory is allocated for this member during initialization of this object
263 // because we want buffer to be passed into BufferedResourceLoader to be 276 // because we want buffer to be passed into BufferedResourceLoader to be
264 // always non-null. And by initializing this member with a default size we can 277 // always non-null. And by initializing this member with a default size we can
265 // avoid creating zero-sized buffered if the first read has zero size. 278 // avoid creating zero-sized buffered if the first read has zero size.
266 scoped_array<uint8> intermediate_read_buffer_; 279 scoped_array<uint8> intermediate_read_buffer_;
267 int intermediate_read_buffer_size_; 280 int intermediate_read_buffer_size_;
268 281
269 // The message loop of the render thread. 282 // The message loop of the render thread.
270 MessageLoop* render_loop_; 283 MessageLoop* render_loop_;
271 284
272 // Filter callbacks. 285 // Filter callbacks.
273 scoped_ptr<media::FilterCallback> initialize_callback_; 286 scoped_ptr<media::FilterCallback> initialize_callback_;
274 287
275 // Protects |stopped_|. 288 // Protects |stopped_|.
276 Lock lock_; 289 Lock lock_;
277 290
278 // Stop signal to suppressing activities. 291 // Stop signal to suppressing activities.
279 bool stopped_; 292 bool stopped_;
280 293
294 // This timer is to run the WatchDogTask repeatedly. We use a timer instead
295 // of doing PostDelayedTask() reduce the extra reference held by the message
296 // loop. The RepeatingTimer does PostDelayedTask() internally, by using it
297 // the message loop doesn't hold a reference for the watch dog task.
298 base::RepeatingTimer<BufferedDataSource> watch_dog_timer_;
299
281 DISALLOW_COPY_AND_ASSIGN(BufferedDataSource); 300 DISALLOW_COPY_AND_ASSIGN(BufferedDataSource);
282 }; 301 };
283 302
284 } // namespace webkit_glue 303 } // namespace webkit_glue
285 304
286 #endif // WEBKIT_GLUE_MEDIA_BUFFERED_DATA_SOURCE_H_ 305 #endif // WEBKIT_GLUE_MEDIA_BUFFERED_DATA_SOURCE_H_
OLDNEW
« no previous file with comments | « no previous file | webkit/glue/media/buffered_data_source.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698