Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(435)

Side by Side Diff: media/blink/buffered_data_source.h

Issue 1399603003: Tie multibuffers to URLs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@media_cache
Patch Set: compile fixes Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
(...skipping 21 matching lines...) Expand all
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_EXPORT BufferedDataSource : public BufferedDataSourceInterface {
106 public:
61 typedef base::Callback<void(bool)> DownloadingCB; 107 typedef base::Callback<void(bool)> DownloadingCB;
62 108
63 // |url| and |cors_mode| are passed to the object. Buffered byte range changes 109 // |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 110 // will be reported to |host|. |downloading_cb| will be called whenever the
65 // downloading/paused state of the source changes. 111 // downloading/paused state of the source changes.
66 BufferedDataSource( 112 BufferedDataSource(
67 const GURL& url, 113 const GURL& url,
68 BufferedResourceLoader::CORSMode cors_mode, 114 BufferedResourceLoader::CORSMode cors_mode,
69 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, 115 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
70 blink::WebFrame* frame, 116 blink::WebFrame* frame,
71 MediaLog* media_log, 117 MediaLog* media_log,
72 BufferedDataSourceHost* host, 118 BufferedDataSourceHost* host,
73 const DownloadingCB& downloading_cb); 119 const DownloadingCB& downloading_cb);
74 ~BufferedDataSource() override; 120 ~BufferedDataSource() override;
75 121
76 // Executes |init_cb| with the result of initialization when it has completed. 122 // Executes |init_cb| with the result of initialization when it has completed.
77 // 123 //
78 // Method called on the render thread. 124 // Method called on the render thread.
79 typedef base::Callback<void(bool)> InitializeCB; 125 typedef base::Callback<void(bool)> InitializeCB;
80 void Initialize(const InitializeCB& init_cb); 126 void Initialize(const InitializeCB& init_cb) override;
81 127
82 // Adjusts the buffering algorithm based on the given preload value. 128 // Adjusts the buffering algorithm based on the given preload value.
83 void SetPreload(Preload preload); 129 void SetPreload(Preload preload) override;
84 130
85 // Returns true if the media resource has a single origin, false otherwise. 131 // Returns true if the media resource has a single origin, false otherwise.
86 // Only valid to call after Initialize() has completed. 132 // Only valid to call after Initialize() has completed.
87 // 133 //
88 // Method called on the render thread. 134 // Method called on the render thread.
89 bool HasSingleOrigin(); 135 bool HasSingleOrigin() override;
90 136
91 // Returns true if the media resource passed a CORS access control check. 137 // Returns true if the media resource passed a CORS access control check.
92 bool DidPassCORSAccessCheck() const; 138 bool DidPassCORSAccessCheck() const override;
93 139
94 // Cancels initialization, any pending loaders, and any pending read calls 140 // Cancels initialization, any pending loaders, and any pending read calls
95 // from the demuxer. The caller is expected to release its reference to this 141 // from the demuxer. The caller is expected to release its reference to this
96 // object and never call it again. 142 // object and never call it again.
97 // 143 //
98 // Method called on the render thread. 144 // Method called on the render thread.
99 void Abort(); 145 void Abort() override;
100 146
101 // Notifies changes in playback state for controlling media buffering 147 // Notifies changes in playback state for controlling media buffering
102 // behavior. 148 // behavior.
103 void MediaPlaybackRateChanged(double playback_rate); 149 void MediaPlaybackRateChanged(double playback_rate) override;
104 void MediaIsPlaying(); 150 void MediaIsPlaying() override;
105 void MediaIsPaused(); 151 void MediaIsPaused() override;
106 bool media_has_played() const { return media_has_played_; } 152 bool media_has_played() const override;
107 153
108 // Returns true if the resource is local. 154 // Returns true if the resource is local.
109 bool assume_fully_buffered() { return !url_.SchemeIsHTTPOrHTTPS(); } 155 bool assume_fully_buffered() override;
110 156
111 // Cancels any open network connections once reaching the deferred state for 157 // Cancels any open network connections once reaching the deferred state for
112 // preload=metadata, non-streaming resources that have not started playback. 158 // preload=metadata, non-streaming resources that have not started playback.
113 // If already deferred, connections will be immediately closed. 159 // If already deferred, connections will be immediately closed.
114 void OnBufferingHaveEnough(); 160 void OnBufferingHaveEnough() override;
115 161
116 // DataSource implementation. 162 // DataSource implementation.
117 // Called from demuxer thread. 163 // Called from demuxer thread.
118 void Stop() override; 164 void Stop() override;
119 165
120 void Read(int64 position, 166 void Read(int64 position,
121 int size, 167 int size,
122 uint8* data, 168 uint8* data,
123 const DataSource::ReadCB& read_cb) override; 169 const DataSource::ReadCB& read_cb) override;
124 bool GetSize(int64* size_out) override; 170 bool GetSize(int64* size_out) override;
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 // reaching into this class from multiple threads to attain a WeakPtr. 299 // reaching into this class from multiple threads to attain a WeakPtr.
254 base::WeakPtr<BufferedDataSource> weak_ptr_; 300 base::WeakPtr<BufferedDataSource> weak_ptr_;
255 base::WeakPtrFactory<BufferedDataSource> weak_factory_; 301 base::WeakPtrFactory<BufferedDataSource> weak_factory_;
256 302
257 DISALLOW_COPY_AND_ASSIGN(BufferedDataSource); 303 DISALLOW_COPY_AND_ASSIGN(BufferedDataSource);
258 }; 304 };
259 305
260 } // namespace media 306 } // namespace media
261 307
262 #endif // MEDIA_BLINK_BUFFERED_DATA_SOURCE_H_ 308 #endif // MEDIA_BLINK_BUFFERED_DATA_SOURCE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698