| 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 MEDIA_BLINK_BUFFERED_DATA_SOURCE_H_ | 5 #ifndef MEDIA_BLINK_BUFFERED_DATA_SOURCE_H_ |
| 6 #define MEDIA_BLINK_BUFFERED_DATA_SOURCE_H_ | 6 #define MEDIA_BLINK_BUFFERED_DATA_SOURCE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
| 15 #include "media/base/data_source.h" | 15 #include "media/base/data_source.h" |
| 16 #include "media/base/media_export.h" | |
| 17 #include "media/base/ranges.h" | 16 #include "media/base/ranges.h" |
| 18 #include "media/blink/buffered_resource_loader.h" | 17 #include "media/blink/buffered_resource_loader.h" |
| 18 #include "media/blink/media_blink_export.h" |
| 19 #include "url/gurl.h" | 19 #include "url/gurl.h" |
| 20 | 20 |
| 21 namespace base { | 21 namespace base { |
| 22 class SingleThreadTaskRunner; | 22 class SingleThreadTaskRunner; |
| 23 } | 23 } |
| 24 | 24 |
| 25 namespace media { | 25 namespace media { |
| 26 class MediaLog; | 26 class MediaLog; |
| 27 | 27 |
| 28 class MEDIA_EXPORT BufferedDataSourceHost { | 28 class MEDIA_BLINK_EXPORT BufferedDataSourceHost { |
| 29 public: | 29 public: |
| 30 // Notify the host of the total size of the media file. | 30 // Notify the host of the total size of the media file. |
| 31 virtual void SetTotalBytes(int64 total_bytes) = 0; | 31 virtual void SetTotalBytes(int64 total_bytes) = 0; |
| 32 | 32 |
| 33 // Notify the host that byte range [start,end] has been buffered. | 33 // Notify the host that byte range [start,end] has been buffered. |
| 34 // TODO(fischman): remove this method when demuxing is push-based instead of | 34 // TODO(fischman): remove this method when demuxing is push-based instead of |
| 35 // pull-based. http://crbug.com/131444 | 35 // pull-based. http://crbug.com/131444 |
| 36 virtual void AddBufferedByteRange(int64 start, int64 end) = 0; | 36 virtual void AddBufferedByteRange(int64 start, int64 end) = 0; |
| 37 | 37 |
| 38 protected: | 38 protected: |
| 39 virtual ~BufferedDataSourceHost() {} | 39 virtual ~BufferedDataSourceHost() {} |
| 40 }; | 40 }; |
| 41 | 41 |
| 42 // A data source capable of loading URLs and buffering the data using an | 42 // This interface is temporary and will go away once MultibufferDataSource |
| 43 // in-memory sliding window. | 43 // has been fully evaluated. |
| 44 // | 44 class BufferedDataSourceInterface : public DataSource { |
| 45 // BufferedDataSource must be created and destroyed on the thread associated | |
| 46 // with the |task_runner| passed in the constructor. | |
| 47 class MEDIA_EXPORT BufferedDataSource : public DataSource { | |
| 48 public: | 45 public: |
| 49 // Used to specify video preload states. They are "hints" to the browser about | 46 // Used to specify video preload states. They are "hints" to the browser about |
| 50 // how aggressively the browser should load and buffer data. | 47 // how aggressively the browser should load and buffer data. |
| 51 // Please see the HTML5 spec for the descriptions of these values: | 48 // Please see the HTML5 spec for the descriptions of these values: |
| 52 // http://www.w3.org/TR/html5/video.html#attr-media-preload | 49 // http://www.w3.org/TR/html5/video.html#attr-media-preload |
| 53 // | 50 // |
| 54 // Enum values must match the values in blink::WebMediaPlayer::Preload and | 51 // Enum values must match the values in blink::WebMediaPlayer::Preload and |
| 55 // there will be assertions at compile time if they do not match. | 52 // there will be assertions at compile time if they do not match. |
| 56 enum Preload { | 53 enum Preload { |
| 57 NONE, | 54 NONE, |
| 58 METADATA, | 55 METADATA, |
| 59 AUTO, | 56 AUTO, |
| 60 }; | 57 }; |
| 58 |
| 59 // Executes |init_cb| with the result of initialization when it has completed. |
| 60 // |
| 61 // Method called on the render thread. |
| 62 typedef base::Callback<void(bool)> InitializeCB; |
| 63 virtual void Initialize(const InitializeCB& init_cb) = 0; |
| 64 |
| 65 // Adjusts the buffering algorithm based on the given preload value. |
| 66 virtual void SetPreload(Preload preload) = 0; |
| 67 |
| 68 // Returns true if the media resource has a single origin, false otherwise. |
| 69 // Only valid to call after Initialize() has completed. |
| 70 // |
| 71 // Method called on the render thread. |
| 72 virtual bool HasSingleOrigin() = 0; |
| 73 |
| 74 // Returns true if the media resource passed a CORS access control check. |
| 75 virtual bool DidPassCORSAccessCheck() const = 0; |
| 76 |
| 77 // Cancels initialization, any pending loaders, and any pending read calls |
| 78 // from the demuxer. The caller is expected to release its reference to this |
| 79 // object and never call it again. |
| 80 // |
| 81 // Method called on the render thread. |
| 82 virtual void Abort() = 0; |
| 83 |
| 84 // Notifies changes in playback state for controlling media buffering |
| 85 // behavior. |
| 86 virtual void MediaPlaybackRateChanged(double playback_rate) = 0; |
| 87 virtual void MediaIsPlaying() = 0; |
| 88 virtual void MediaIsPaused() = 0; |
| 89 virtual bool media_has_played() const = 0; |
| 90 |
| 91 // Returns true if the resource is local. |
| 92 virtual bool assume_fully_buffered() = 0; |
| 93 |
| 94 // Cancels any open network connections once reaching the deferred state for |
| 95 // preload=metadata, non-streaming resources that have not started playback. |
| 96 // If already deferred, connections will be immediately closed. |
| 97 virtual void OnBufferingHaveEnough() = 0; |
| 98 }; |
| 99 |
| 100 // A data source capable of loading URLs and buffering the data using an |
| 101 // in-memory sliding window. |
| 102 // |
| 103 // BufferedDataSource must be created and destroyed on the thread associated |
| 104 // with the |task_runner| passed in the constructor. |
| 105 class MEDIA_BLINK_EXPORT BufferedDataSource |
| 106 : NON_EXPORTED_BASE(public BufferedDataSourceInterface) { |
| 107 public: |
| 61 typedef base::Callback<void(bool)> DownloadingCB; | 108 typedef base::Callback<void(bool)> DownloadingCB; |
| 62 | 109 |
| 63 // |url| and |cors_mode| are passed to the object. Buffered byte range changes | 110 // |url| and |cors_mode| are passed to the object. Buffered byte range changes |
| 64 // will be reported to |host|. |downloading_cb| will be called whenever the | 111 // will be reported to |host|. |downloading_cb| will be called whenever the |
| 65 // downloading/paused state of the source changes. | 112 // downloading/paused state of the source changes. |
| 66 BufferedDataSource( | 113 BufferedDataSource( |
| 67 const GURL& url, | 114 const GURL& url, |
| 68 BufferedResourceLoader::CORSMode cors_mode, | 115 BufferedResourceLoader::CORSMode cors_mode, |
| 69 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 116 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 70 blink::WebFrame* frame, | 117 blink::WebFrame* frame, |
| 71 MediaLog* media_log, | 118 MediaLog* media_log, |
| 72 BufferedDataSourceHost* host, | 119 BufferedDataSourceHost* host, |
| 73 const DownloadingCB& downloading_cb); | 120 const DownloadingCB& downloading_cb); |
| 74 ~BufferedDataSource() override; | 121 ~BufferedDataSource() override; |
| 75 | 122 |
| 76 // Executes |init_cb| with the result of initialization when it has completed. | 123 // Executes |init_cb| with the result of initialization when it has completed. |
| 77 // | 124 // |
| 78 // Method called on the render thread. | 125 // Method called on the render thread. |
| 79 typedef base::Callback<void(bool)> InitializeCB; | 126 typedef base::Callback<void(bool)> InitializeCB; |
| 80 void Initialize(const InitializeCB& init_cb); | 127 void Initialize(const InitializeCB& init_cb) override; |
| 81 | 128 |
| 82 // Adjusts the buffering algorithm based on the given preload value. | 129 // Adjusts the buffering algorithm based on the given preload value. |
| 83 void SetPreload(Preload preload); | 130 void SetPreload(Preload preload) override; |
| 84 | 131 |
| 85 // Returns true if the media resource has a single origin, false otherwise. | 132 // Returns true if the media resource has a single origin, false otherwise. |
| 86 // Only valid to call after Initialize() has completed. | 133 // Only valid to call after Initialize() has completed. |
| 87 // | 134 // |
| 88 // Method called on the render thread. | 135 // Method called on the render thread. |
| 89 bool HasSingleOrigin(); | 136 bool HasSingleOrigin() override; |
| 90 | 137 |
| 91 // Returns true if the media resource passed a CORS access control check. | 138 // Returns true if the media resource passed a CORS access control check. |
| 92 bool DidPassCORSAccessCheck() const; | 139 bool DidPassCORSAccessCheck() const override; |
| 93 | 140 |
| 94 // Cancels initialization, any pending loaders, and any pending read calls | 141 // Cancels initialization, any pending loaders, and any pending read calls |
| 95 // from the demuxer. The caller is expected to release its reference to this | 142 // from the demuxer. The caller is expected to release its reference to this |
| 96 // object and never call it again. | 143 // object and never call it again. |
| 97 // | 144 // |
| 98 // Method called on the render thread. | 145 // Method called on the render thread. |
| 99 void Abort(); | 146 void Abort() override; |
| 100 | 147 |
| 101 // Notifies changes in playback state for controlling media buffering | 148 // Notifies changes in playback state for controlling media buffering |
| 102 // behavior. | 149 // behavior. |
| 103 void MediaPlaybackRateChanged(double playback_rate); | 150 void MediaPlaybackRateChanged(double playback_rate) override; |
| 104 void MediaIsPlaying(); | 151 void MediaIsPlaying() override; |
| 105 void MediaIsPaused(); | 152 void MediaIsPaused() override; |
| 106 bool media_has_played() const { return media_has_played_; } | 153 bool media_has_played() const override; |
| 107 | 154 |
| 108 // Returns true if the resource is local. | 155 // Returns true if the resource is local. |
| 109 bool assume_fully_buffered() { return !url_.SchemeIsHTTPOrHTTPS(); } | 156 bool assume_fully_buffered() override; |
| 110 | 157 |
| 111 // Cancels any open network connections once reaching the deferred state for | 158 // Cancels any open network connections once reaching the deferred state for |
| 112 // preload=metadata, non-streaming resources that have not started playback. | 159 // preload=metadata, non-streaming resources that have not started playback. |
| 113 // If already deferred, connections will be immediately closed. | 160 // If already deferred, connections will be immediately closed. |
| 114 void OnBufferingHaveEnough(); | 161 void OnBufferingHaveEnough() override; |
| 115 | 162 |
| 116 // DataSource implementation. | 163 // DataSource implementation. |
| 117 // Called from demuxer thread. | 164 // Called from demuxer thread. |
| 118 void Stop() override; | 165 void Stop() override; |
| 119 | 166 |
| 120 void Read(int64 position, | 167 void Read(int64 position, |
| 121 int size, | 168 int size, |
| 122 uint8* data, | 169 uint8* data, |
| 123 const DataSource::ReadCB& read_cb) override; | 170 const DataSource::ReadCB& read_cb) override; |
| 124 bool GetSize(int64* size_out) override; | 171 bool GetSize(int64* size_out) override; |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 // reaching into this class from multiple threads to attain a WeakPtr. | 300 // reaching into this class from multiple threads to attain a WeakPtr. |
| 254 base::WeakPtr<BufferedDataSource> weak_ptr_; | 301 base::WeakPtr<BufferedDataSource> weak_ptr_; |
| 255 base::WeakPtrFactory<BufferedDataSource> weak_factory_; | 302 base::WeakPtrFactory<BufferedDataSource> weak_factory_; |
| 256 | 303 |
| 257 DISALLOW_COPY_AND_ASSIGN(BufferedDataSource); | 304 DISALLOW_COPY_AND_ASSIGN(BufferedDataSource); |
| 258 }; | 305 }; |
| 259 | 306 |
| 260 } // namespace media | 307 } // namespace media |
| 261 | 308 |
| 262 #endif // MEDIA_BLINK_BUFFERED_DATA_SOURCE_H_ | 309 #endif // MEDIA_BLINK_BUFFERED_DATA_SOURCE_H_ |
| OLD | NEW |