Chromium Code Reviews| 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. |
|
scherkus (not reviewing)
2014/03/28 20:54:09
want to a TODO(sandersd) saying how |host| should
sandersd (OOO until July 31)
2014/03/28 21:14:28
Done.
| |
| 41 BufferedDataSource(const scoped_refptr<base::MessageLoopProxy>& render_loop, | 41 BufferedDataSource(const scoped_refptr<base::MessageLoopProxy>& render_loop, |
| 42 blink::WebFrame* frame, | 42 blink::WebFrame* frame, |
| 43 media::MediaLog* media_log, | 43 media::MediaLog* media_log, |
| 44 media::DataSourceHost* host, | |
| 44 const DownloadingCB& downloading_cb); | 45 const DownloadingCB& downloading_cb); |
| 45 virtual ~BufferedDataSource(); | 46 virtual ~BufferedDataSource(); |
| 46 | 47 |
| 47 // Initialize this object using |url| and |cors_mode|, executing |init_cb| | 48 // Initialize this object using |url| and |cors_mode|, executing |init_cb| |
| 48 // with the result of initialization when it has completed. | 49 // with the result of initialization when it has completed. |
| 49 // | 50 // |
| 50 // Method called on the render thread. | 51 // Method called on the render thread. |
| 51 typedef base::Callback<void(bool)> InitializeCB; | 52 typedef base::Callback<void(bool)> InitializeCB; |
| 52 void Initialize( | 53 void Initialize( |
| 53 const GURL& url, | 54 const GURL& url, |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 74 void Abort(); | 75 void Abort(); |
| 75 | 76 |
| 76 // Notifies changes in playback state for controlling media buffering | 77 // Notifies changes in playback state for controlling media buffering |
| 77 // behavior. | 78 // behavior. |
| 78 void MediaPlaybackRateChanged(float playback_rate); | 79 void MediaPlaybackRateChanged(float playback_rate); |
| 79 void MediaIsPlaying(); | 80 void MediaIsPlaying(); |
| 80 void MediaIsPaused(); | 81 void MediaIsPaused(); |
| 81 | 82 |
| 82 // media::DataSource implementation. | 83 // media::DataSource implementation. |
| 83 // Called from demuxer thread. | 84 // Called from demuxer thread. |
| 84 virtual void set_host(media::DataSourceHost* host) OVERRIDE; | |
| 85 virtual void Stop(const base::Closure& closure) OVERRIDE; | 85 virtual void Stop(const base::Closure& closure) OVERRIDE; |
| 86 | 86 |
| 87 virtual void Read(int64 position, int size, uint8* data, | 87 virtual void Read(int64 position, int size, uint8* data, |
| 88 const media::DataSource::ReadCB& read_cb) OVERRIDE; | 88 const media::DataSource::ReadCB& read_cb) OVERRIDE; |
| 89 virtual bool GetSize(int64* size_out) OVERRIDE; | 89 virtual bool GetSize(int64* size_out) OVERRIDE; |
| 90 virtual bool IsStreaming() OVERRIDE; | 90 virtual bool IsStreaming() OVERRIDE; |
| 91 virtual void SetBitrate(int bitrate) OVERRIDE; | 91 virtual void SetBitrate(int bitrate) OVERRIDE; |
| 92 | 92 |
| 93 protected: | 93 protected: |
| 94 // A factory method to create a BufferedResourceLoader based on the read | 94 // A factory method to create a BufferedResourceLoader based on the read |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 122 | 122 |
| 123 // BufferedResourceLoader::Start() callback for subsequent loads (i.e., | 123 // BufferedResourceLoader::Start() callback for subsequent loads (i.e., |
| 124 // when accessing ranges that are outside initial buffered region). | 124 // when accessing ranges that are outside initial buffered region). |
| 125 void PartialReadStartCallback(BufferedResourceLoader::Status status); | 125 void PartialReadStartCallback(BufferedResourceLoader::Status status); |
| 126 | 126 |
| 127 // BufferedResourceLoader callbacks. | 127 // BufferedResourceLoader callbacks. |
| 128 void ReadCallback(BufferedResourceLoader::Status status, int bytes_read); | 128 void ReadCallback(BufferedResourceLoader::Status status, int bytes_read); |
| 129 void LoadingStateChangedCallback(BufferedResourceLoader::LoadingState state); | 129 void LoadingStateChangedCallback(BufferedResourceLoader::LoadingState state); |
| 130 void ProgressCallback(int64 position); | 130 void ProgressCallback(int64 position); |
| 131 | 131 |
| 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 | 132 // Update |loader_|'s deferring strategy in response to a play/pause, or |
| 139 // change in playback rate. | 133 // change in playback rate. |
| 140 void UpdateDeferStrategy(bool paused); | 134 void UpdateDeferStrategy(bool paused); |
| 141 | 135 |
| 142 // URL of the resource requested. | 136 // URL of the resource requested. |
| 143 GURL url_; | 137 GURL url_; |
| 144 // crossorigin attribute on the corresponding HTML media element, if any. | 138 // crossorigin attribute on the corresponding HTML media element, if any. |
| 145 BufferedResourceLoader::CORSMode cors_mode_; | 139 BufferedResourceLoader::CORSMode cors_mode_; |
| 146 | 140 |
| 147 // The total size of the resource. Set during StartCallback() if the size is | 141 // 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 | 194 // This variable holds the value of the preload attribute for the video |
| 201 // element. | 195 // element. |
| 202 Preload preload_; | 196 Preload preload_; |
| 203 | 197 |
| 204 // Bitrate of the content, 0 if unknown. | 198 // Bitrate of the content, 0 if unknown. |
| 205 int bitrate_; | 199 int bitrate_; |
| 206 | 200 |
| 207 // Current playback rate. | 201 // Current playback rate. |
| 208 float playback_rate_; | 202 float playback_rate_; |
| 209 | 203 |
| 210 // Buffered byte ranges awaiting set_host() being called to report to host(). | 204 scoped_refptr<media::MediaLog> media_log_; |
| 211 media::Ranges<int64> queued_buffered_byte_ranges_; | |
| 212 | 205 |
| 213 scoped_refptr<media::MediaLog> media_log_; | 206 // Host object to report buffered byte range changes to. |
| 207 media::DataSourceHost* host_; | |
| 214 | 208 |
| 215 DownloadingCB downloading_cb_; | 209 DownloadingCB downloading_cb_; |
| 216 | 210 |
| 217 // NOTE: Weak pointers must be invalidated before all other member variables. | 211 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 218 base::WeakPtrFactory<BufferedDataSource> weak_factory_; | 212 base::WeakPtrFactory<BufferedDataSource> weak_factory_; |
| 219 | 213 |
| 220 DISALLOW_COPY_AND_ASSIGN(BufferedDataSource); | 214 DISALLOW_COPY_AND_ASSIGN(BufferedDataSource); |
| 221 }; | 215 }; |
| 222 | 216 |
| 223 } // namespace content | 217 } // namespace content |
| 224 | 218 |
| 225 #endif // CONTENT_RENDERER_MEDIA_BUFFERED_DATA_SOURCE_H_ | 219 #endif // CONTENT_RENDERER_MEDIA_BUFFERED_DATA_SOURCE_H_ |
| OLD | NEW |