| 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 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 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_BLINK_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_t 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_t start, int64_t end) = 0; |
| 37 | 37 |
| 38 protected: | 38 protected: |
| 39 virtual ~BufferedDataSourceHost() {} | 39 virtual ~BufferedDataSourceHost() {} |
| 40 }; | 40 }; |
| 41 | 41 |
| 42 // This interface is temporary and will go away once MultibufferDataSource | 42 // This interface is temporary and will go away once MultibufferDataSource |
| 43 // has been fully evaluated. | 43 // has been fully evaluated. |
| 44 class BufferedDataSourceInterface : public DataSource { | 44 class BufferedDataSourceInterface : public DataSource { |
| 45 public: | 45 public: |
| 46 // 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 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 // If already deferred, connections will be immediately closed. | 177 // If already deferred, connections will be immediately closed. |
| 178 void OnBufferingHaveEnough() override; | 178 void OnBufferingHaveEnough() override; |
| 179 | 179 |
| 180 // Returns an estimate of the number of bytes held by the data source. | 180 // Returns an estimate of the number of bytes held by the data source. |
| 181 int64_t GetMemoryUsage() const override; | 181 int64_t GetMemoryUsage() const override; |
| 182 | 182 |
| 183 // DataSource implementation. | 183 // DataSource implementation. |
| 184 // Called from demuxer thread. | 184 // Called from demuxer thread. |
| 185 void Stop() override; | 185 void Stop() override; |
| 186 | 186 |
| 187 void Read(int64 position, | 187 void Read(int64_t position, |
| 188 int size, | 188 int size, |
| 189 uint8* data, | 189 uint8_t* data, |
| 190 const DataSource::ReadCB& read_cb) override; | 190 const DataSource::ReadCB& read_cb) override; |
| 191 bool GetSize(int64* size_out) override; | 191 bool GetSize(int64_t* size_out) override; |
| 192 bool IsStreaming() override; | 192 bool IsStreaming() override; |
| 193 void SetBitrate(int bitrate) override; | 193 void SetBitrate(int bitrate) override; |
| 194 | 194 |
| 195 protected: | 195 protected: |
| 196 // A factory method to create a BufferedResourceLoader based on the read | 196 // A factory method to create a BufferedResourceLoader based on the read |
| 197 // parameters. We can override this file to object a mock | 197 // parameters. We can override this file to object a mock |
| 198 // BufferedResourceLoader for testing. | 198 // BufferedResourceLoader for testing. |
| 199 virtual BufferedResourceLoader* CreateResourceLoader( | 199 virtual BufferedResourceLoader* CreateResourceLoader( |
| 200 int64 first_byte_position, int64 last_byte_position); | 200 int64_t first_byte_position, |
| 201 int64_t last_byte_position); |
| 201 | 202 |
| 202 private: | 203 private: |
| 203 friend class BufferedDataSourceTest; | 204 friend class BufferedDataSourceTest; |
| 204 | 205 |
| 205 // Task posted to perform actual reading on the render thread. | 206 // Task posted to perform actual reading on the render thread. |
| 206 void ReadTask(); | 207 void ReadTask(); |
| 207 | 208 |
| 208 // Cancels oustanding callbacks and sets |stop_signal_received_|. Safe to call | 209 // Cancels oustanding callbacks and sets |stop_signal_received_|. Safe to call |
| 209 // from any thread. | 210 // from any thread. |
| 210 void StopInternal_Locked(); | 211 void StopInternal_Locked(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 225 // BufferedResourceLoader::Start() callback for subsequent loads (i.e., | 226 // BufferedResourceLoader::Start() callback for subsequent loads (i.e., |
| 226 // when accessing ranges that are outside initial buffered region). | 227 // when accessing ranges that are outside initial buffered region). |
| 227 void PartialReadStartCallback(BufferedResourceLoader::Status status); | 228 void PartialReadStartCallback(BufferedResourceLoader::Status status); |
| 228 | 229 |
| 229 // Returns true if we can accept the new partial response. | 230 // Returns true if we can accept the new partial response. |
| 230 bool CheckPartialResponseURL(const GURL& partial_response_original_url) const; | 231 bool CheckPartialResponseURL(const GURL& partial_response_original_url) const; |
| 231 | 232 |
| 232 // BufferedResourceLoader callbacks. | 233 // BufferedResourceLoader callbacks. |
| 233 void ReadCallback(BufferedResourceLoader::Status status, int bytes_read); | 234 void ReadCallback(BufferedResourceLoader::Status status, int bytes_read); |
| 234 void LoadingStateChangedCallback(BufferedResourceLoader::LoadingState state); | 235 void LoadingStateChangedCallback(BufferedResourceLoader::LoadingState state); |
| 235 void ProgressCallback(int64 position); | 236 void ProgressCallback(int64_t position); |
| 236 | 237 |
| 237 // Update |loader_|'s deferring strategy. | 238 // Update |loader_|'s deferring strategy. |
| 238 void UpdateDeferStrategy(); | 239 void UpdateDeferStrategy(); |
| 239 | 240 |
| 240 // URL of the resource requested. | 241 // URL of the resource requested. |
| 241 GURL url_; | 242 GURL url_; |
| 242 // crossorigin attribute on the corresponding HTML media element, if any. | 243 // crossorigin attribute on the corresponding HTML media element, if any. |
| 243 BufferedResourceLoader::CORSMode cors_mode_; | 244 BufferedResourceLoader::CORSMode cors_mode_; |
| 244 | 245 |
| 245 // The total size of the resource. Set during StartCallback() if the size is | 246 // The total size of the resource. Set during StartCallback() if the size is |
| 246 // known, otherwise it will remain kPositionNotSpecified until the size is | 247 // known, otherwise it will remain kPositionNotSpecified until the size is |
| 247 // determined by reaching EOF. | 248 // determined by reaching EOF. |
| 248 int64 total_bytes_; | 249 int64_t total_bytes_; |
| 249 | 250 |
| 250 // This value will be true if this data source can only support streaming. | 251 // This value will be true if this data source can only support streaming. |
| 251 // i.e. range request is not supported. | 252 // i.e. range request is not supported. |
| 252 bool streaming_; | 253 bool streaming_; |
| 253 | 254 |
| 254 // A webframe for loading. | 255 // A webframe for loading. |
| 255 blink::WebFrame* frame_; | 256 blink::WebFrame* frame_; |
| 256 | 257 |
| 257 // A resource loader for the media resource. | 258 // A resource loader for the media resource. |
| 258 scoped_ptr<BufferedResourceLoader> loader_; | 259 scoped_ptr<BufferedResourceLoader> loader_; |
| 259 | 260 |
| 260 // Callback method from the pipeline for initialization. | 261 // Callback method from the pipeline for initialization. |
| 261 InitializeCB init_cb_; | 262 InitializeCB init_cb_; |
| 262 | 263 |
| 263 // Read parameters received from the Read() method call. Must be accessed | 264 // Read parameters received from the Read() method call. Must be accessed |
| 264 // under |lock_|. | 265 // under |lock_|. |
| 265 class ReadOperation; | 266 class ReadOperation; |
| 266 scoped_ptr<ReadOperation> read_op_; | 267 scoped_ptr<ReadOperation> read_op_; |
| 267 | 268 |
| 268 // This buffer is intermediate, we use it for BufferedResourceLoader to write | 269 // This buffer is intermediate, we use it for BufferedResourceLoader to write |
| 269 // to. And when read in BufferedResourceLoader is done, we copy data from | 270 // to. And when read in BufferedResourceLoader is done, we copy data from |
| 270 // this buffer to |read_buffer_|. The reason for an additional copy is that | 271 // this buffer to |read_buffer_|. The reason for an additional copy is that |
| 271 // we don't own |read_buffer_|. But since the read operation is asynchronous, | 272 // we don't own |read_buffer_|. But since the read operation is asynchronous, |
| 272 // |read_buffer| can be destroyed at any time, so we only copy into | 273 // |read_buffer| can be destroyed at any time, so we only copy into |
| 273 // |read_buffer| in the final step when it is safe. | 274 // |read_buffer| in the final step when it is safe. |
| 274 // Memory is allocated for this member during initialization of this object | 275 // Memory is allocated for this member during initialization of this object |
| 275 // because we want buffer to be passed into BufferedResourceLoader to be | 276 // because we want buffer to be passed into BufferedResourceLoader to be |
| 276 // always non-null. And by initializing this member with a default size we can | 277 // always non-null. And by initializing this member with a default size we can |
| 277 // avoid creating zero-sized buffered if the first read has zero size. | 278 // avoid creating zero-sized buffered if the first read has zero size. |
| 278 std::vector<uint8> intermediate_read_buffer_; | 279 std::vector<uint8_t> intermediate_read_buffer_; |
| 279 | 280 |
| 280 // The task runner of the render thread. | 281 // The task runner of the render thread. |
| 281 const scoped_refptr<base::SingleThreadTaskRunner> render_task_runner_; | 282 const scoped_refptr<base::SingleThreadTaskRunner> render_task_runner_; |
| 282 | 283 |
| 283 // Protects |stop_signal_received_| and |read_op_|. | 284 // Protects |stop_signal_received_| and |read_op_|. |
| 284 base::Lock lock_; | 285 base::Lock lock_; |
| 285 | 286 |
| 286 // Whether we've been told to stop via Abort() or Stop(). | 287 // Whether we've been told to stop via Abort() or Stop(). |
| 287 bool stop_signal_received_; | 288 bool stop_signal_received_; |
| 288 | 289 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 // reaching into this class from multiple threads to attain a WeakPtr. | 323 // reaching into this class from multiple threads to attain a WeakPtr. |
| 323 base::WeakPtr<BufferedDataSource> weak_ptr_; | 324 base::WeakPtr<BufferedDataSource> weak_ptr_; |
| 324 base::WeakPtrFactory<BufferedDataSource> weak_factory_; | 325 base::WeakPtrFactory<BufferedDataSource> weak_factory_; |
| 325 | 326 |
| 326 DISALLOW_COPY_AND_ASSIGN(BufferedDataSource); | 327 DISALLOW_COPY_AND_ASSIGN(BufferedDataSource); |
| 327 }; | 328 }; |
| 328 | 329 |
| 329 } // namespace media | 330 } // namespace media |
| 330 | 331 |
| 331 #endif // MEDIA_BLINK_BUFFERED_DATA_SOURCE_H_ | 332 #endif // MEDIA_BLINK_BUFFERED_DATA_SOURCE_H_ |
| OLD | NEW |