| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 | 43 |
| 44 // A data source capable of loading URLs and buffering the data using an | 44 // A data source capable of loading URLs and buffering the data using an |
| 45 // in-memory sliding window. | 45 // in-memory sliding window. |
| 46 // | 46 // |
| 47 // BufferedDataSource must be created and initialized on the render thread | 47 // BufferedDataSource must be created and initialized on the render thread |
| 48 // before being passed to other threads. It may be deleted on any thread. | 48 // before being passed to other threads. It may be deleted on any thread. |
| 49 class CONTENT_EXPORT BufferedDataSource : public media::DataSource { | 49 class CONTENT_EXPORT BufferedDataSource : public media::DataSource { |
| 50 public: | 50 public: |
| 51 typedef base::Callback<void(bool)> DownloadingCB; | 51 typedef base::Callback<void(bool)> DownloadingCB; |
| 52 | 52 |
| 53 // Buffered byte range changes will be reported to |host|. |downloading_cb| | 53 // |url| and |cors_mode| are passed to the object. Buffered byte range changes |
| 54 // will be called whenever the downloading/paused state of the source changes. | 54 // will be reported to |host|. |downloading_cb| will be called whenever the |
| 55 BufferedDataSource(const scoped_refptr<base::MessageLoopProxy>& render_loop, | 55 // downloading/paused state of the source changes. |
| 56 BufferedDataSource(const GURL& url, |
| 57 BufferedResourceLoader::CORSMode cors_mode, |
| 58 const scoped_refptr<base::MessageLoopProxy>& render_loop, |
| 56 blink::WebFrame* frame, | 59 blink::WebFrame* frame, |
| 57 media::MediaLog* media_log, | 60 media::MediaLog* media_log, |
| 58 BufferedDataSourceHost* host, | 61 BufferedDataSourceHost* host, |
| 59 const DownloadingCB& downloading_cb); | 62 const DownloadingCB& downloading_cb); |
| 60 virtual ~BufferedDataSource(); | 63 virtual ~BufferedDataSource(); |
| 61 | 64 |
| 62 // Initialize this object using |url| and |cors_mode|, executing |init_cb| | 65 // Executes |init_cb| with the result of initialization when it has completed. |
| 63 // with the result of initialization when it has completed. | |
| 64 // | 66 // |
| 65 // Method called on the render thread. | 67 // Method called on the render thread. |
| 66 typedef base::Callback<void(bool)> InitializeCB; | 68 typedef base::Callback<void(bool)> InitializeCB; |
| 67 void Initialize( | 69 void Initialize(const InitializeCB& init_cb); |
| 68 const GURL& url, | |
| 69 BufferedResourceLoader::CORSMode cors_mode, | |
| 70 const InitializeCB& init_cb); | |
| 71 | 70 |
| 72 // Adjusts the buffering algorithm based on the given preload value. | 71 // Adjusts the buffering algorithm based on the given preload value. |
| 73 void SetPreload(Preload preload); | 72 void SetPreload(Preload preload); |
| 74 | 73 |
| 75 // Returns true if the media resource has a single origin, false otherwise. | 74 // Returns true if the media resource has a single origin, false otherwise. |
| 76 // Only valid to call after Initialize() has completed. | 75 // Only valid to call after Initialize() has completed. |
| 77 // | 76 // |
| 78 // Method called on the render thread. | 77 // Method called on the render thread. |
| 79 bool HasSingleOrigin(); | 78 bool HasSingleOrigin(); |
| 80 | 79 |
| 81 // Returns true if the media resource passed a CORS access control check. | 80 // Returns true if the media resource passed a CORS access control check. |
| 82 bool DidPassCORSAccessCheck() const; | 81 bool DidPassCORSAccessCheck() const; |
| 83 | 82 |
| 84 // Cancels initialization, any pending loaders, and any pending read calls | 83 // Cancels initialization, any pending loaders, and any pending read calls |
| 85 // from the demuxer. The caller is expected to release its reference to this | 84 // from the demuxer. The caller is expected to release its reference to this |
| 86 // object and never call it again. | 85 // object and never call it again. |
| 87 // | 86 // |
| 88 // Method called on the render thread. | 87 // Method called on the render thread. |
| 89 void Abort(); | 88 void Abort(); |
| 90 | 89 |
| 91 // Notifies changes in playback state for controlling media buffering | 90 // Notifies changes in playback state for controlling media buffering |
| 92 // behavior. | 91 // behavior. |
| 93 void MediaPlaybackRateChanged(float playback_rate); | 92 void MediaPlaybackRateChanged(float playback_rate); |
| 94 void MediaIsPlaying(); | 93 void MediaIsPlaying(); |
| 95 void MediaIsPaused(); | 94 void MediaIsPaused(); |
| 96 | 95 |
| 96 // Returns true if the resource is local. |
| 97 bool assume_fully_buffered() { return !url_.SchemeIsHTTPOrHTTPS(); } |
| 98 |
| 97 // media::DataSource implementation. | 99 // media::DataSource implementation. |
| 98 // Called from demuxer thread. | 100 // Called from demuxer thread. |
| 99 virtual void Stop(const base::Closure& closure) OVERRIDE; | 101 virtual void Stop(const base::Closure& closure) OVERRIDE; |
| 100 | 102 |
| 101 virtual void Read(int64 position, int size, uint8* data, | 103 virtual void Read(int64 position, int size, uint8* data, |
| 102 const media::DataSource::ReadCB& read_cb) OVERRIDE; | 104 const media::DataSource::ReadCB& read_cb) OVERRIDE; |
| 103 virtual bool GetSize(int64* size_out) OVERRIDE; | 105 virtual bool GetSize(int64* size_out) OVERRIDE; |
| 104 virtual bool IsStreaming() OVERRIDE; | 106 virtual bool IsStreaming() OVERRIDE; |
| 105 virtual void SetBitrate(int bitrate) OVERRIDE; | 107 virtual void SetBitrate(int bitrate) OVERRIDE; |
| 106 | 108 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 // URL of the resource requested. | 152 // URL of the resource requested. |
| 151 GURL url_; | 153 GURL url_; |
| 152 // crossorigin attribute on the corresponding HTML media element, if any. | 154 // crossorigin attribute on the corresponding HTML media element, if any. |
| 153 BufferedResourceLoader::CORSMode cors_mode_; | 155 BufferedResourceLoader::CORSMode cors_mode_; |
| 154 | 156 |
| 155 // The total size of the resource. Set during StartCallback() if the size is | 157 // The total size of the resource. Set during StartCallback() if the size is |
| 156 // known, otherwise it will remain kPositionNotSpecified until the size is | 158 // known, otherwise it will remain kPositionNotSpecified until the size is |
| 157 // determined by reaching EOF. | 159 // determined by reaching EOF. |
| 158 int64 total_bytes_; | 160 int64 total_bytes_; |
| 159 | 161 |
| 160 // Some resources are assumed to be fully buffered (i.e., file://) so we don't | |
| 161 // need to report what |loader_| has buffered. | |
| 162 bool assume_fully_buffered_; | |
| 163 | |
| 164 // This value will be true if this data source can only support streaming. | 162 // This value will be true if this data source can only support streaming. |
| 165 // i.e. range request is not supported. | 163 // i.e. range request is not supported. |
| 166 bool streaming_; | 164 bool streaming_; |
| 167 | 165 |
| 168 // A webframe for loading. | 166 // A webframe for loading. |
| 169 blink::WebFrame* frame_; | 167 blink::WebFrame* frame_; |
| 170 | 168 |
| 171 // A resource loader for the media resource. | 169 // A resource loader for the media resource. |
| 172 scoped_ptr<BufferedResourceLoader> loader_; | 170 scoped_ptr<BufferedResourceLoader> loader_; |
| 173 | 171 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 | 222 |
| 225 // NOTE: Weak pointers must be invalidated before all other member variables. | 223 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 226 base::WeakPtrFactory<BufferedDataSource> weak_factory_; | 224 base::WeakPtrFactory<BufferedDataSource> weak_factory_; |
| 227 | 225 |
| 228 DISALLOW_COPY_AND_ASSIGN(BufferedDataSource); | 226 DISALLOW_COPY_AND_ASSIGN(BufferedDataSource); |
| 229 }; | 227 }; |
| 230 | 228 |
| 231 } // namespace content | 229 } // namespace content |
| 232 | 230 |
| 233 #endif // CONTENT_RENDERER_MEDIA_BUFFERED_DATA_SOURCE_H_ | 231 #endif // CONTENT_RENDERER_MEDIA_BUFFERED_DATA_SOURCE_H_ |
| OLD | NEW |