OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 CONTENT_RENDERER_MEDIA_BUFFERED_DATA_SOURCE_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_BUFFERED_DATA_SOURCE_H_ |
6 #define CONTENT_RENDERER_MEDIA_BUFFERED_DATA_SOURCE_H_ | 6 #define CONTENT_RENDERER_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 18 matching lines...) Expand all Loading... | |
29 | 29 |
30 // A data source capable of loading URLs and buffering the data using an | 30 // A data source capable of loading URLs and buffering the data using an |
31 // in-memory sliding window. | 31 // in-memory sliding window. |
32 // | 32 // |
33 // BufferedDataSource must be created and initialized on the render thread | 33 // BufferedDataSource must be created and initialized on the render thread |
34 // before being passed to other threads. It may be deleted on any thread. | 34 // before being passed to other threads. It may be deleted on any thread. |
35 class CONTENT_EXPORT BufferedDataSource : public media::DataSource { | 35 class CONTENT_EXPORT BufferedDataSource : public media::DataSource { |
36 public: | 36 public: |
37 typedef base::Callback<void(bool)> DownloadingCB; | 37 typedef base::Callback<void(bool)> DownloadingCB; |
38 | 38 |
39 // |downloading_cb| will be called whenever the downloading/paused state of | 39 // Buffered byte range changes will be reported to |host|. |downloading_cb| |
40 // the source changes. | 40 // will be called whenever the downloading/paused state of the source changes. |
41 // TODO(sandersd): Move |media::DataSourceHost| to | |
scherkus (not reviewing)
2014/03/28 21:19:56
nit: we |variables| but not namespace::FooBar
sandersd (OOO until July 31)
2014/03/29 01:15:07
Done.
| |
42 // |content::BufferedDataSourceHost|. | |
41 BufferedDataSource(const scoped_refptr<base::MessageLoopProxy>& render_loop, | 43 BufferedDataSource(const scoped_refptr<base::MessageLoopProxy>& render_loop, |
42 blink::WebFrame* frame, | 44 blink::WebFrame* frame, |
43 media::MediaLog* media_log, | 45 media::MediaLog* media_log, |
46 media::DataSourceHost* host, | |
44 const DownloadingCB& downloading_cb); | 47 const DownloadingCB& downloading_cb); |
45 virtual ~BufferedDataSource(); | 48 virtual ~BufferedDataSource(); |
46 | 49 |
47 // Initialize this object using |url| and |cors_mode|, executing |init_cb| | 50 // Initialize this object using |url| and |cors_mode|, executing |init_cb| |
48 // with the result of initialization when it has completed. | 51 // with the result of initialization when it has completed. |
49 // | 52 // |
50 // Method called on the render thread. | 53 // Method called on the render thread. |
51 typedef base::Callback<void(bool)> InitializeCB; | 54 typedef base::Callback<void(bool)> InitializeCB; |
52 void Initialize( | 55 void Initialize( |
53 const GURL& url, | 56 const GURL& url, |
(...skipping 20 matching lines...) Expand all Loading... | |
74 void Abort(); | 77 void Abort(); |
75 | 78 |
76 // Notifies changes in playback state for controlling media buffering | 79 // Notifies changes in playback state for controlling media buffering |
77 // behavior. | 80 // behavior. |
78 void MediaPlaybackRateChanged(float playback_rate); | 81 void MediaPlaybackRateChanged(float playback_rate); |
79 void MediaIsPlaying(); | 82 void MediaIsPlaying(); |
80 void MediaIsPaused(); | 83 void MediaIsPaused(); |
81 | 84 |
82 // media::DataSource implementation. | 85 // media::DataSource implementation. |
83 // Called from demuxer thread. | 86 // Called from demuxer thread. |
84 virtual void set_host(media::DataSourceHost* host) OVERRIDE; | |
85 virtual void Stop(const base::Closure& closure) OVERRIDE; | 87 virtual void Stop(const base::Closure& closure) OVERRIDE; |
86 | 88 |
87 virtual void Read(int64 position, int size, uint8* data, | 89 virtual void Read(int64 position, int size, uint8* data, |
88 const media::DataSource::ReadCB& read_cb) OVERRIDE; | 90 const media::DataSource::ReadCB& read_cb) OVERRIDE; |
89 virtual bool GetSize(int64* size_out) OVERRIDE; | 91 virtual bool GetSize(int64* size_out) OVERRIDE; |
90 virtual bool IsStreaming() OVERRIDE; | 92 virtual bool IsStreaming() OVERRIDE; |
91 virtual void SetBitrate(int bitrate) OVERRIDE; | 93 virtual void SetBitrate(int bitrate) OVERRIDE; |
92 | 94 |
93 protected: | 95 protected: |
94 // A factory method to create a BufferedResourceLoader based on the read | 96 // A factory method to create a BufferedResourceLoader based on the read |
(...skipping 27 matching lines...) Expand all Loading... | |
122 | 124 |
123 // BufferedResourceLoader::Start() callback for subsequent loads (i.e., | 125 // BufferedResourceLoader::Start() callback for subsequent loads (i.e., |
124 // when accessing ranges that are outside initial buffered region). | 126 // when accessing ranges that are outside initial buffered region). |
125 void PartialReadStartCallback(BufferedResourceLoader::Status status); | 127 void PartialReadStartCallback(BufferedResourceLoader::Status status); |
126 | 128 |
127 // BufferedResourceLoader callbacks. | 129 // BufferedResourceLoader callbacks. |
128 void ReadCallback(BufferedResourceLoader::Status status, int bytes_read); | 130 void ReadCallback(BufferedResourceLoader::Status status, int bytes_read); |
129 void LoadingStateChangedCallback(BufferedResourceLoader::LoadingState state); | 131 void LoadingStateChangedCallback(BufferedResourceLoader::LoadingState state); |
130 void ProgressCallback(int64 position); | 132 void ProgressCallback(int64 position); |
131 | 133 |
132 // Report a buffered byte range [start,end] or queue it for later | |
133 // reporting if set_host() hasn't been called yet. | |
134 void ReportOrQueueBufferedBytes(int64 start, int64 end); | |
135 | |
136 void UpdateHostState_Locked(); | |
137 | |
138 // Update |loader_|'s deferring strategy in response to a play/pause, or | 134 // Update |loader_|'s deferring strategy in response to a play/pause, or |
139 // change in playback rate. | 135 // change in playback rate. |
140 void UpdateDeferStrategy(bool paused); | 136 void UpdateDeferStrategy(bool paused); |
141 | 137 |
142 // URL of the resource requested. | 138 // URL of the resource requested. |
143 GURL url_; | 139 GURL url_; |
144 // crossorigin attribute on the corresponding HTML media element, if any. | 140 // crossorigin attribute on the corresponding HTML media element, if any. |
145 BufferedResourceLoader::CORSMode cors_mode_; | 141 BufferedResourceLoader::CORSMode cors_mode_; |
146 | 142 |
147 // The total size of the resource. Set during StartCallback() if the size is | 143 // The total size of the resource. Set during StartCallback() if the size is |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
200 // This variable holds the value of the preload attribute for the video | 196 // This variable holds the value of the preload attribute for the video |
201 // element. | 197 // element. |
202 Preload preload_; | 198 Preload preload_; |
203 | 199 |
204 // Bitrate of the content, 0 if unknown. | 200 // Bitrate of the content, 0 if unknown. |
205 int bitrate_; | 201 int bitrate_; |
206 | 202 |
207 // Current playback rate. | 203 // Current playback rate. |
208 float playback_rate_; | 204 float playback_rate_; |
209 | 205 |
210 // Buffered byte ranges awaiting set_host() being called to report to host(). | 206 scoped_refptr<media::MediaLog> media_log_; |
211 media::Ranges<int64> queued_buffered_byte_ranges_; | |
212 | 207 |
213 scoped_refptr<media::MediaLog> media_log_; | 208 // Host object to report buffered byte range changes to. |
209 media::DataSourceHost* host_; | |
214 | 210 |
215 DownloadingCB downloading_cb_; | 211 DownloadingCB downloading_cb_; |
216 | 212 |
217 // NOTE: Weak pointers must be invalidated before all other member variables. | 213 // NOTE: Weak pointers must be invalidated before all other member variables. |
218 base::WeakPtrFactory<BufferedDataSource> weak_factory_; | 214 base::WeakPtrFactory<BufferedDataSource> weak_factory_; |
219 | 215 |
220 DISALLOW_COPY_AND_ASSIGN(BufferedDataSource); | 216 DISALLOW_COPY_AND_ASSIGN(BufferedDataSource); |
221 }; | 217 }; |
222 | 218 |
223 } // namespace content | 219 } // namespace content |
224 | 220 |
225 #endif // CONTENT_RENDERER_MEDIA_BUFFERED_DATA_SOURCE_H_ | 221 #endif // CONTENT_RENDERER_MEDIA_BUFFERED_DATA_SOURCE_H_ |
OLD | NEW |