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

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

Issue 9864022: Move DataSource::SetPreload() to BufferedDataSource. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src
Patch Set: Created 8 years, 8 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 | Annotate | Revision Log
OLDNEW
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_DATA_SOURCE_H_ 5 #ifndef WEBKIT_MEDIA_BUFFERED_DATA_SOURCE_H_
6 #define WEBKIT_MEDIA_BUFFERED_DATA_SOURCE_H_ 6 #define WEBKIT_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 "googleurl/src/gurl.h" 13 #include "googleurl/src/gurl.h"
14 #include "media/base/data_source.h" 14 #include "media/base/data_source.h"
15 #include "media/base/pipeline_status.h" 15 #include "media/base/pipeline_status.h"
16 #include "webkit/media/buffered_resource_loader.h" 16 #include "webkit/media/buffered_resource_loader.h"
17 #include "webkit/media/preload.h"
17 18
18 class MessageLoop; 19 class MessageLoop;
19 20
20 namespace media { 21 namespace media {
21 class MediaLog; 22 class MediaLog;
22 } 23 }
23 24
24 namespace webkit_media { 25 namespace webkit_media {
25 26
26 // A data source capable of loading URLs and buffering the data using an 27 // A data source capable of loading URLs and buffering the data using an
27 // in-memory sliding window. 28 // in-memory sliding window.
28 class BufferedDataSource : public media::DataSource { 29 class BufferedDataSource : public media::DataSource {
29 public: 30 public:
30 BufferedDataSource(MessageLoop* render_loop, 31 BufferedDataSource(MessageLoop* render_loop,
31 WebKit::WebFrame* frame, 32 WebKit::WebFrame* frame,
32 media::MediaLog* media_log); 33 media::MediaLog* media_log);
33 34
34 virtual ~BufferedDataSource(); 35 virtual ~BufferedDataSource();
35 36
36 // Initialize this object using |url|. This object calls |status_cb| when 37 // Initialize this object using |url|. This object calls |status_cb| when
37 // initialization has completed. 38 // initialization has completed.
38 // 39 //
39 // Method called on the render thread. 40 // Method called on the render thread.
40 void Initialize(const GURL& url, 41 void Initialize(const GURL& url,
41 const media::PipelineStatusCB& status_cb); 42 const media::PipelineStatusCB& status_cb);
42 43
44 // Adjusts the buffering algorithm based on the given preload value.
45 void SetPreload(Preload preload);
46
43 // Returns true if the media resource has a single origin, false otherwise. 47 // Returns true if the media resource has a single origin, false otherwise.
44 // 48 //
45 // Method called on the render thread. 49 // Method called on the render thread.
46 bool HasSingleOrigin(); 50 bool HasSingleOrigin();
47 51
48 // Cancels initialization, any pending loaders, and any pending read calls 52 // Cancels initialization, any pending loaders, and any pending read calls
49 // from the demuxer. The caller is expected to release its reference to this 53 // from the demuxer. The caller is expected to release its reference to this
50 // object and never call it again. 54 // object and never call it again.
51 // 55 //
52 // Method called on the render thread. 56 // Method called on the render thread.
53 void Abort(); 57 void Abort();
54 58
55 // media::DataSource implementation. 59 // media::DataSource implementation.
56 // Called from demuxer thread. 60 // Called from demuxer thread.
57 virtual void set_host(media::DataSourceHost* host) OVERRIDE; 61 virtual void set_host(media::DataSourceHost* host) OVERRIDE;
58 virtual void Stop(const base::Closure& closure) OVERRIDE; 62 virtual void Stop(const base::Closure& closure) OVERRIDE;
59 virtual void SetPlaybackRate(float playback_rate) OVERRIDE; 63 virtual void SetPlaybackRate(float playback_rate) OVERRIDE;
60 64
61 virtual void Read( 65 virtual void Read(
62 int64 position, 66 int64 position,
63 size_t size, 67 size_t size,
64 uint8* data, 68 uint8* data,
65 const media::DataSource::ReadCB& read_cb) OVERRIDE; 69 const media::DataSource::ReadCB& read_cb) OVERRIDE;
66 virtual bool GetSize(int64* size_out) OVERRIDE; 70 virtual bool GetSize(int64* size_out) OVERRIDE;
67 virtual bool IsStreaming() OVERRIDE; 71 virtual bool IsStreaming() OVERRIDE;
68 virtual void SetPreload(media::Preload preload) OVERRIDE;
69 virtual void SetBitrate(int bitrate) OVERRIDE; 72 virtual void SetBitrate(int bitrate) OVERRIDE;
70 73
71 protected: 74 protected:
72 // A factory method to create a BufferedResourceLoader based on the read 75 // A factory method to create a BufferedResourceLoader based on the read
73 // parameters. We can override this file to object a mock 76 // parameters. We can override this file to object a mock
74 // BufferedResourceLoader for testing. 77 // BufferedResourceLoader for testing.
75 virtual BufferedResourceLoader* CreateResourceLoader( 78 virtual BufferedResourceLoader* CreateResourceLoader(
76 int64 first_byte_position, int64 last_byte_position); 79 int64 first_byte_position, int64 last_byte_position);
77 80
78 private: 81 private:
79 friend class BufferedDataSourceTest; 82 friend class BufferedDataSourceTest;
80 83
81 // Task posted to perform actual reading on the render thread. 84 // Task posted to perform actual reading on the render thread.
82 void ReadTask(int64 position, int read_size, uint8* read_buffer); 85 void ReadTask(int64 position, int read_size, uint8* read_buffer);
83 86
84 // Task posted when Stop() is called. Stops |watch_dog_timer_| and 87 // Task posted when Stop() is called. Stops |watch_dog_timer_| and
85 // |loader_|, reset Read() variables, and set |stopped_on_render_loop_| 88 // |loader_|, reset Read() variables, and set |stopped_on_render_loop_|
86 // to signal any remaining tasks to stop. 89 // to signal any remaining tasks to stop.
87 void CleanupTask(); 90 void CleanupTask();
88 91
89 // Restart resource loading on render thread. 92 // Restart resource loading on render thread.
90 void RestartLoadingTask(); 93 void RestartLoadingTask();
91 94
92 // This task uses the current playback rate with the previous playback rate 95 // This task uses the current playback rate with the previous playback rate
93 // to determine whether we are going from pause to play and play to pause, 96 // to determine whether we are going from pause to play and play to pause,
94 // and signals the buffered resource loader accordingly. 97 // and signals the buffered resource loader accordingly.
95 void SetPlaybackRateTask(float playback_rate); 98 void SetPlaybackRateTask(float playback_rate);
96 99
97 // This task saves the preload value for the media.
98 void SetPreloadTask(media::Preload preload);
99
100 // Tells |loader_| the bitrate of the media. 100 // Tells |loader_| the bitrate of the media.
101 void SetBitrateTask(int bitrate); 101 void SetBitrateTask(int bitrate);
102 102
103 // Decides which DeferStrategy to used based on the current state of the 103 // Decides which DeferStrategy to used based on the current state of the
104 // BufferedDataSource. 104 // BufferedDataSource.
105 BufferedResourceLoader::DeferStrategy ChooseDeferStrategy(); 105 BufferedResourceLoader::DeferStrategy ChooseDeferStrategy();
106 106
107 // The method that performs actual read. This method can only be executed on 107 // The method that performs actual read. This method can only be executed on
108 // the render thread. 108 // the render thread.
109 void ReadInternal(); 109 void ReadInternal();
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 // This variable is true when we are in a paused state and false when we 203 // This variable is true when we are in a paused state and false when we
204 // are in a playing state. 204 // are in a playing state.
205 bool media_is_paused_; 205 bool media_is_paused_;
206 206
207 // This variable is true when the user has requested the video to play at 207 // This variable is true when the user has requested the video to play at
208 // least once. 208 // least once.
209 bool media_has_played_; 209 bool media_has_played_;
210 210
211 // This variable holds the value of the preload attribute for the video 211 // This variable holds the value of the preload attribute for the video
212 // element. 212 // element.
213 media::Preload preload_; 213 Preload preload_;
214 214
215 // Number of cache miss retries left. 215 // Number of cache miss retries left.
216 int cache_miss_retries_left_; 216 int cache_miss_retries_left_;
217 217
218 // Bitrate of the content, 0 if unknown. 218 // Bitrate of the content, 0 if unknown.
219 int bitrate_; 219 int bitrate_;
220 220
221 // Current playback rate. 221 // Current playback rate.
222 float playback_rate_; 222 float playback_rate_;
223 223
224 scoped_refptr<media::MediaLog> media_log_; 224 scoped_refptr<media::MediaLog> media_log_;
225 225
226 DISALLOW_COPY_AND_ASSIGN(BufferedDataSource); 226 DISALLOW_COPY_AND_ASSIGN(BufferedDataSource);
227 }; 227 };
228 228
229 } // namespace webkit_media 229 } // namespace webkit_media
230 230
231 #endif // WEBKIT_MEDIA_BUFFERED_DATA_SOURCE_H_ 231 #endif // WEBKIT_MEDIA_BUFFERED_DATA_SOURCE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698