Index: media/blink/multibuffer_data_source.h |
diff --git a/media/blink/buffered_data_source.h b/media/blink/multibuffer_data_source.h |
similarity index 54% |
copy from media/blink/buffered_data_source.h |
copy to media/blink/multibuffer_data_source.h |
index fd85b7cc524e3e79395313e3e59ed33015bcf250..26ca6a5993b35c75d6004878d283c945cd9c9fd7 100644 |
--- a/media/blink/buffered_data_source.h |
+++ b/media/blink/multibuffer_data_source.h |
@@ -2,8 +2,8 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#ifndef MEDIA_BLINK_BUFFERED_DATA_SOURCE_H_ |
-#define MEDIA_BLINK_BUFFERED_DATA_SOURCE_H_ |
+#ifndef MEDIA_BLINK_MULTIBUFFER_DATA_SOURCE_H_ |
+#define MEDIA_BLINK_MULTIBUFFER_DATA_SOURCE_H_ |
#include <string> |
#include <vector> |
@@ -15,7 +15,8 @@ |
#include "media/base/data_source.h" |
#include "media/base/media_export.h" |
#include "media/base/ranges.h" |
-#include "media/blink/buffered_resource_loader.h" |
+#include "media/blink/buffered_data_source.h" |
+#include "media/blink/multibuffer_resource_loader.h" |
#include "url/gurl.h" |
namespace base { |
@@ -24,94 +25,69 @@ class SingleThreadTaskRunner; |
namespace media { |
class MediaLog; |
- |
-class MEDIA_EXPORT BufferedDataSourceHost { |
- public: |
- // Notify the host of the total size of the media file. |
- virtual void SetTotalBytes(int64 total_bytes) = 0; |
- |
- // Notify the host that byte range [start,end] has been buffered. |
- // TODO(fischman): remove this method when demuxing is push-based instead of |
- // pull-based. http://crbug.com/131444 |
- virtual void AddBufferedByteRange(int64 start, int64 end) = 0; |
- |
- protected: |
- virtual ~BufferedDataSourceHost() {} |
-}; |
+class MultiBufferReader; |
// A data source capable of loading URLs and buffering the data using an |
// in-memory sliding window. |
// |
-// BufferedDataSource must be created and destroyed on the thread associated |
+// MultibufferDataSource must be created and destroyed on the thread associated |
// with the |task_runner| passed in the constructor. |
-class MEDIA_EXPORT BufferedDataSource : public DataSource { |
+class MEDIA_EXPORT MultibufferDataSource : public BufferedDataSourceInterface { |
public: |
- // Used to specify video preload states. They are "hints" to the browser about |
- // how aggressively the browser should load and buffer data. |
- // Please see the HTML5 spec for the descriptions of these values: |
- // http://www.w3.org/TR/html5/video.html#attr-media-preload |
- // |
- // Enum values must match the values in blink::WebMediaPlayer::Preload and |
- // there will be assertions at compile time if they do not match. |
- enum Preload { |
- NONE, |
- METADATA, |
- AUTO, |
- }; |
typedef base::Callback<void(bool)> DownloadingCB; |
// |url| and |cors_mode| are passed to the object. Buffered byte range changes |
// will be reported to |host|. |downloading_cb| will be called whenever the |
// downloading/paused state of the source changes. |
- BufferedDataSource( |
+ MultibufferDataSource( |
const GURL& url, |
- BufferedResourceLoader::CORSMode cors_mode, |
+ UrlData::CORSMode cors_mode, |
const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
+ ResourceMultiBuffer* multibuffer, |
blink::WebFrame* frame, |
MediaLog* media_log, |
BufferedDataSourceHost* host, |
const DownloadingCB& downloading_cb); |
- ~BufferedDataSource() override; |
+ ~MultibufferDataSource() override; |
// Executes |init_cb| with the result of initialization when it has completed. |
// |
// Method called on the render thread. |
- typedef base::Callback<void(bool)> InitializeCB; |
- void Initialize(const InitializeCB& init_cb); |
+ void Initialize(const InitializeCB& init_cb) override; |
// Adjusts the buffering algorithm based on the given preload value. |
- void SetPreload(Preload preload); |
+ void SetPreload(Preload preload) override; |
// Returns true if the media resource has a single origin, false otherwise. |
// Only valid to call after Initialize() has completed. |
// |
// Method called on the render thread. |
- bool HasSingleOrigin(); |
+ bool HasSingleOrigin() override; |
// Returns true if the media resource passed a CORS access control check. |
- bool DidPassCORSAccessCheck() const; |
+ bool DidPassCORSAccessCheck() const override; |
// Cancels initialization, any pending loaders, and any pending read calls |
// from the demuxer. The caller is expected to release its reference to this |
// object and never call it again. |
// |
// Method called on the render thread. |
- void Abort(); |
+ void Abort() override; |
// Notifies changes in playback state for controlling media buffering |
// behavior. |
- void MediaPlaybackRateChanged(double playback_rate); |
- void MediaIsPlaying(); |
- void MediaIsPaused(); |
- bool media_has_played() const { return media_has_played_; } |
+ void MediaPlaybackRateChanged(double playback_rate) override; |
+ void MediaIsPlaying() override; |
+ void MediaIsPaused() override; |
+ bool media_has_played() const override; |
// Returns true if the resource is local. |
- bool assume_fully_buffered() { return !url_.SchemeIsHTTPOrHTTPS(); } |
+ bool assume_fully_buffered() override; |
// Cancels any open network connections once reaching the deferred state for |
// preload=metadata, non-streaming resources that have not started playback. |
// If already deferred, connections will be immediately closed. |
- void OnBufferingHaveEnough(); |
+ void OnBufferingHaveEnough() override; |
// DataSource implementation. |
// Called from demuxer thread. |
@@ -127,13 +103,11 @@ class MEDIA_EXPORT BufferedDataSource : public DataSource { |
protected: |
// A factory method to create a BufferedResourceLoader based on the read |
- // parameters. We can override this file to object a mock |
- // BufferedResourceLoader for testing. |
- virtual BufferedResourceLoader* CreateResourceLoader( |
- int64 first_byte_position, int64 last_byte_position); |
+ // parameters. |
+ void CreateResourceLoader(int64 first_byte_position, |
+ int64 last_byte_position); |
- private: |
- friend class BufferedDataSourceTest; |
+ friend class MultibufferDataSourceTest; |
// Task posted to perform actual reading on the render thread. |
void ReadTask(); |
@@ -148,33 +122,27 @@ class MEDIA_EXPORT BufferedDataSource : public DataSource { |
// Tells |loader_| the bitrate of the media. |
void SetBitrateTask(int bitrate); |
- // The method that performs actual read. This method can only be executed on |
- // the render thread. |
- void ReadInternal(); |
- |
// BufferedResourceLoader::Start() callback for initial load. |
- void StartCallback(BufferedResourceLoader::Status status); |
+ void StartCallback(); |
- // BufferedResourceLoader::Start() callback for subsequent loads (i.e., |
- // when accessing ranges that are outside initial buffered region). |
- void PartialReadStartCallback(BufferedResourceLoader::Status status); |
+ // Check if we've moved to a new url and update has_signgle_origin_. |
liberato (no reviews please)
2015/10/16 21:50:36
s/igng/ing/
|
+ void UpdateSingleOrigin(); |
- // Returns true if we can accept the new partial response. |
- bool CheckPartialResponseURL(const GURL& partial_response_original_url) const; |
+ // MultiBufferReader progress callback. |
+ void ProgressCallback(int64 begin, int64 end); |
- // BufferedResourceLoader callbacks. |
- void ReadCallback(BufferedResourceLoader::Status status, int bytes_read); |
- void LoadingStateChangedCallback(BufferedResourceLoader::LoadingState state); |
- void ProgressCallback(int64 position); |
+ // call downloading_cb_ if needed. |
+ void UpdateLoadingState(); |
- // Update |loader_|'s deferring strategy in response to a play/pause, or |
- // change in playback rate. |
- void UpdateDeferStrategy(bool paused); |
+ // Update |loader_|'s preload and buffer settings. |
+ void UpdateBufferSizes(); |
- // URL of the resource requested. |
- GURL url_; |
// crossorigin attribute on the corresponding HTML media element, if any. |
- BufferedResourceLoader::CORSMode cors_mode_; |
+ UrlData::CORSMode cors_mode_; |
+ |
+ // URL of the resource requested. |
+ scoped_refptr<UrlData> url_data_; |
+ scoped_refptr<UrlData> destination_url_data_; |
// The total size of the resource. Set during StartCallback() if the size is |
// known, otherwise it will remain kPositionNotSpecified until the size is |
@@ -185,11 +153,19 @@ class MEDIA_EXPORT BufferedDataSource : public DataSource { |
// i.e. range request is not supported. |
bool streaming_; |
+ bool loading_; |
+ |
+ // The task runner of the render thread. |
+ const scoped_refptr<base::SingleThreadTaskRunner> render_task_runner_; |
+ |
+ // Shared buffer. |
+ ResourceMultiBuffer* multibuffer_; |
+ |
// A webframe for loading. |
blink::WebFrame* frame_; |
- // A resource loader for the media resource. |
- scoped_ptr<BufferedResourceLoader> loader_; |
+ // A resource reader for the media resource. |
+ scoped_ptr<MultiBufferReader> loader_; |
liberato (no reviews please)
2015/10/16 21:50:36
|reader_|?
hubbe
2015/10/16 23:47:05
Done.
|
// Callback method from the pipeline for initialization. |
InitializeCB init_cb_; |
@@ -199,21 +175,6 @@ class MEDIA_EXPORT BufferedDataSource : public DataSource { |
class ReadOperation; |
scoped_ptr<ReadOperation> read_op_; |
- // This buffer is intermediate, we use it for BufferedResourceLoader to write |
- // to. And when read in BufferedResourceLoader is done, we copy data from |
- // this buffer to |read_buffer_|. The reason for an additional copy is that |
- // we don't own |read_buffer_|. But since the read operation is asynchronous, |
- // |read_buffer| can be destroyed at any time, so we only copy into |
- // |read_buffer| in the final step when it is safe. |
- // Memory is allocated for this member during initialization of this object |
- // because we want buffer to be passed into BufferedResourceLoader to be |
- // always non-null. And by initializing this member with a default size we can |
- // avoid creating zero-sized buffered if the first read has zero size. |
- std::vector<uint8> intermediate_read_buffer_; |
- |
- // The task runner of the render thread. |
- const scoped_refptr<base::SingleThreadTaskRunner> render_task_runner_; |
- |
// Protects |stop_signal_received_| and |read_op_|. |
base::Lock lock_; |
@@ -224,6 +185,16 @@ class MEDIA_EXPORT BufferedDataSource : public DataSource { |
// least once. |
bool media_has_played_; |
+ // Are we currently paused. |
+ bool paused_; |
+ |
+ // As we follow redirects, we set this variable to false if redirects |
+ // go between different origins. |
+ bool single_origin_; |
+ |
+ // Close the connection when we have enough data. |
+ bool cancel_on_defer_; |
+ |
// This variable holds the value of the preload attribute for the video |
// element. |
Preload preload_; |
@@ -243,20 +214,21 @@ class MEDIA_EXPORT BufferedDataSource : public DataSource { |
// The original URL of the first response. If the request is redirected to |
// another URL it is the URL after redirected. If the response is generated in |
- // a Service Worker this URL is empty. BufferedDataSource checks the original |
- // URL of each successive response. If the origin URL of it is different from |
- // the original URL of the first response, it is treated as an error. |
+ // a Service Worker this URL is empty. MultibufferDataSource checks the |
+ // original URL of each successive response. If the origin URL of it is |
+ // different from the original URL of the first response, it is treated |
+ // as an error. |
GURL response_original_url_; |
// Disallow rebinding WeakReference ownership to a different thread by keeping |
// a persistent reference. This avoids problems with the thread-safety of |
// reaching into this class from multiple threads to attain a WeakPtr. |
- base::WeakPtr<BufferedDataSource> weak_ptr_; |
- base::WeakPtrFactory<BufferedDataSource> weak_factory_; |
+ base::WeakPtr<MultibufferDataSource> weak_ptr_; |
+ base::WeakPtrFactory<MultibufferDataSource> weak_factory_; |
- DISALLOW_COPY_AND_ASSIGN(BufferedDataSource); |
+ DISALLOW_COPY_AND_ASSIGN(MultibufferDataSource); |
}; |
} // namespace media |
-#endif // MEDIA_BLINK_BUFFERED_DATA_SOURCE_H_ |
+#endif // MEDIA_BLINK_MULTIBUFFER_DATA_SOURCE_H_ |