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/scoped_ptr.h" | 11 #include "base/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 "webkit/glue/media/buffered_resource_loader.h" | 15 #include "webkit/glue/media/buffered_resource_loader.h" |
15 | 16 |
16 namespace webkit_glue { | 17 namespace webkit_glue { |
17 | 18 |
18 class BufferedDataSource : public WebDataSource { | 19 class BufferedDataSource : public WebDataSource { |
19 public: | 20 public: |
20 // Creates a DataSourceFactory for building BufferedDataSource objects. | 21 // Creates a DataSourceFactory for building BufferedDataSource objects. |
21 static media::DataSourceFactory* CreateFactory( | 22 static media::DataSourceFactory* CreateFactory( |
22 MessageLoop* render_loop, | 23 MessageLoop* render_loop, |
23 WebKit::WebFrame* frame, | 24 WebKit::WebFrame* frame, |
24 WebDataSourceBuildObserverHack* build_observer); | 25 WebDataSourceBuildObserverHack* build_observer); |
25 | 26 |
26 BufferedDataSource(MessageLoop* render_loop, | 27 BufferedDataSource(MessageLoop* render_loop, |
27 WebKit::WebFrame* frame); | 28 WebKit::WebFrame* frame); |
28 | 29 |
29 virtual ~BufferedDataSource(); | 30 virtual ~BufferedDataSource(); |
30 | 31 |
31 // media::Filter implementation. | 32 // media::Filter implementation. |
32 virtual void set_host(media::FilterHost* host); | 33 virtual void set_host(media::FilterHost* host); |
33 virtual void Stop(media::FilterCallback* callback); | 34 virtual void Stop(media::FilterCallback* callback); |
34 virtual void SetPlaybackRate(float playback_rate); | 35 virtual void SetPlaybackRate(float playback_rate); |
| 36 virtual void SetPreload(media::Preload preload); |
| 37 |
| 38 // Decides which DeferStrategy to used based on the current state of the |
| 39 // BufferedDataSource. |
| 40 DeferStrategy* ChooseDeferStrategy(); |
35 | 41 |
36 // media::DataSource implementation. | 42 // media::DataSource implementation. |
37 // Called from demuxer thread. | 43 // Called from demuxer thread. |
38 virtual void Read(int64 position, size_t size, | 44 virtual void Read(int64 position, size_t size, |
39 uint8* data, | 45 uint8* data, |
40 media::DataSource::ReadCallback* read_callback); | 46 media::DataSource::ReadCallback* read_callback); |
41 virtual bool GetSize(int64* size_out); | 47 virtual bool GetSize(int64* size_out); |
42 virtual bool IsStreaming(); | 48 virtual bool IsStreaming(); |
43 | 49 |
44 const media::MediaFormat& media_format() { | 50 const media::MediaFormat& media_format() { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 | 88 |
83 // This task monitors the current active read request. If the current read | 89 // This task monitors the current active read request. If the current read |
84 // request has timed out, this task will destroy the current loader and | 90 // request has timed out, this task will destroy the current loader and |
85 // creates a new one to accommodate the read request. | 91 // creates a new one to accommodate the read request. |
86 void WatchDogTask(); | 92 void WatchDogTask(); |
87 | 93 |
88 // This task uses the current playback rate with the previous playback rate | 94 // This task uses the current playback rate with the previous playback rate |
89 // to determine whether we are going from pause to play and play to pause, | 95 // to determine whether we are going from pause to play and play to pause, |
90 // and signals the buffered resource loader accordingly. | 96 // and signals the buffered resource loader accordingly. |
91 void SetPlaybackRateTask(float playback_rate); | 97 void SetPlaybackRateTask(float playback_rate); |
| 98 void SetPreloadTask(media::Preload preload); |
92 | 99 |
93 // The method that performs actual read. This method can only be executed on | 100 // The method that performs actual read. This method can only be executed on |
94 // the render thread. | 101 // the render thread. |
95 void ReadInternal(); | 102 void ReadInternal(); |
96 | 103 |
97 // Calls |read_callback_| and reset all read parameters. | 104 // Calls |read_callback_| and reset all read parameters. |
98 void DoneRead_Locked(int error); | 105 void DoneRead_Locked(int error); |
99 | 106 |
100 // Calls |initialize_callback_| and reset it. | 107 // Calls |initialize_callback_| and reset it. |
101 void DoneInitialization_Locked(media::PipelineStatus status); | 108 void DoneInitialization_Locked(media::PipelineStatus status); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 bool stop_signal_received_; | 196 bool stop_signal_received_; |
190 | 197 |
191 // This variable is set by CleanupTask() that indicates this object is stopped | 198 // This variable is set by CleanupTask() that indicates this object is stopped |
192 // on the render thread and work should no longer progress. | 199 // on the render thread and work should no longer progress. |
193 bool stopped_on_render_loop_; | 200 bool stopped_on_render_loop_; |
194 | 201 |
195 // This variable is true when we are in a paused state and false when we | 202 // This variable is true when we are in a paused state and false when we |
196 // are in a playing state. | 203 // are in a playing state. |
197 bool media_is_paused_; | 204 bool media_is_paused_; |
198 | 205 |
| 206 // This variable is true when the user has requested the video to play at |
| 207 // least once. |
| 208 bool media_has_played_; |
| 209 |
| 210 // This variable holds the value of the preload attribute for the video |
| 211 // element. |
| 212 media::Preload preload_; |
| 213 |
199 // This timer is to run the WatchDogTask repeatedly. We use a timer instead | 214 // This timer is to run the WatchDogTask repeatedly. We use a timer instead |
200 // of doing PostDelayedTask() reduce the extra reference held by the message | 215 // of doing PostDelayedTask() reduce the extra reference held by the message |
201 // loop. The RepeatingTimer does PostDelayedTask() internally, by using it | 216 // loop. The RepeatingTimer does PostDelayedTask() internally, by using it |
202 // the message loop doesn't hold a reference for the watch dog task. | 217 // the message loop doesn't hold a reference for the watch dog task. |
203 base::RepeatingTimer<BufferedDataSource> watch_dog_timer_; | 218 base::RepeatingTimer<BufferedDataSource> watch_dog_timer_; |
204 | 219 |
205 // Keeps track of whether we used a Range header in the initialization | 220 // Keeps track of whether we used a Range header in the initialization |
206 // request. | 221 // request. |
207 bool using_range_request_; | 222 bool using_range_request_; |
208 | 223 |
209 DISALLOW_COPY_AND_ASSIGN(BufferedDataSource); | 224 DISALLOW_COPY_AND_ASSIGN(BufferedDataSource); |
210 }; | 225 }; |
211 | 226 |
212 } // namespace webkit_glue | 227 } // namespace webkit_glue |
213 | 228 |
214 #endif // WEBKIT_GLUE_MEDIA_BUFFERED_DATA_SOURCE_H_ | 229 #endif // WEBKIT_GLUE_MEDIA_BUFFERED_DATA_SOURCE_H_ |
OLD | NEW |