| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 WEBKIT_MEDIA_BUFFERED_DATA_SOURCE_H_ | 5 #ifndef WEBKIT_MEDIA_BUFFERED_DATA_SOURCE_H_ |
| 6 #define WEBKIT_MEDIA_BUFFERED_DATA_SOURCE_H_ | 6 #define WEBKIT_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" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
| 13 #include "googleurl/src/gurl.h" | 13 #include "googleurl/src/gurl.h" |
| 14 #include "media/base/data_source.h" | 14 #include "media/base/data_source.h" |
| 15 #include "media/base/ranges.h" | 15 #include "media/base/ranges.h" |
| 16 #include "webkit/media/buffered_resource_loader.h" | 16 #include "webkit/media/buffered_resource_loader.h" |
| 17 #include "webkit/media/preload.h" | 17 #include "webkit/media/preload.h" |
| 18 | 18 |
| 19 class MessageLoop; | 19 namespace base { |
| 20 class MessageLoopProxy; |
| 21 } |
| 20 | 22 |
| 21 namespace media { | 23 namespace media { |
| 22 class MediaLog; | 24 class MediaLog; |
| 23 } | 25 } |
| 24 | 26 |
| 25 namespace webkit_media { | 27 namespace webkit_media { |
| 26 | 28 |
| 27 // A data source capable of loading URLs and buffering the data using an | 29 // A data source capable of loading URLs and buffering the data using an |
| 28 // in-memory sliding window. | 30 // in-memory sliding window. |
| 29 // | 31 // |
| 30 // BufferedDataSource must be created and initialized on the render thread | 32 // BufferedDataSource must be created and initialized on the render thread |
| 31 // before being passed to other threads. It may be deleted on any thread. | 33 // before being passed to other threads. It may be deleted on any thread. |
| 32 class BufferedDataSource : public media::DataSource { | 34 class BufferedDataSource : public media::DataSource { |
| 33 public: | 35 public: |
| 34 typedef base::Callback<void(bool)> DownloadingCB; | 36 typedef base::Callback<void(bool)> DownloadingCB; |
| 35 | 37 |
| 36 // |downloading_cb| will be called whenever the downloading/paused state of | 38 // |downloading_cb| will be called whenever the downloading/paused state of |
| 37 // the source changes. | 39 // the source changes. |
| 38 BufferedDataSource(MessageLoop* render_loop, | 40 BufferedDataSource(const scoped_refptr<base::MessageLoopProxy>& render_loop, |
| 39 WebKit::WebFrame* frame, | 41 WebKit::WebFrame* frame, |
| 40 media::MediaLog* media_log, | 42 media::MediaLog* media_log, |
| 41 const DownloadingCB& downloading_cb); | 43 const DownloadingCB& downloading_cb); |
| 42 | 44 |
| 43 // Initialize this object using |url| and |cors_mode|, executing |init_cb| | 45 // Initialize this object using |url| and |cors_mode|, executing |init_cb| |
| 44 // with the result of initialization when it has completed. | 46 // with the result of initialization when it has completed. |
| 45 // | 47 // |
| 46 // Method called on the render thread. | 48 // Method called on the render thread. |
| 47 typedef base::Callback<void(bool)> InitializeCB; | 49 typedef base::Callback<void(bool)> InitializeCB; |
| 48 void Initialize( | 50 void Initialize( |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 // |read_buffer| can be destroyed at any time, so we only copy into | 174 // |read_buffer| can be destroyed at any time, so we only copy into |
| 173 // |read_buffer| in the final step when it is safe. | 175 // |read_buffer| in the final step when it is safe. |
| 174 // Memory is allocated for this member during initialization of this object | 176 // Memory is allocated for this member during initialization of this object |
| 175 // because we want buffer to be passed into BufferedResourceLoader to be | 177 // because we want buffer to be passed into BufferedResourceLoader to be |
| 176 // always non-null. And by initializing this member with a default size we can | 178 // always non-null. And by initializing this member with a default size we can |
| 177 // avoid creating zero-sized buffered if the first read has zero size. | 179 // avoid creating zero-sized buffered if the first read has zero size. |
| 178 scoped_array<uint8> intermediate_read_buffer_; | 180 scoped_array<uint8> intermediate_read_buffer_; |
| 179 int intermediate_read_buffer_size_; | 181 int intermediate_read_buffer_size_; |
| 180 | 182 |
| 181 // The message loop of the render thread. | 183 // The message loop of the render thread. |
| 182 MessageLoop* render_loop_; | 184 const scoped_refptr<base::MessageLoopProxy> render_loop_; |
| 183 | 185 |
| 184 // Protects |stop_signal_received_| and |read_op_|. | 186 // Protects |stop_signal_received_| and |read_op_|. |
| 185 base::Lock lock_; | 187 base::Lock lock_; |
| 186 | 188 |
| 187 // Whether we've been told to stop via Abort() or Stop(). | 189 // Whether we've been told to stop via Abort() or Stop(). |
| 188 bool stop_signal_received_; | 190 bool stop_signal_received_; |
| 189 | 191 |
| 190 // This variable is true when the user has requested the video to play at | 192 // This variable is true when the user has requested the video to play at |
| 191 // least once. | 193 // least once. |
| 192 bool media_has_played_; | 194 bool media_has_played_; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 207 scoped_refptr<media::MediaLog> media_log_; | 209 scoped_refptr<media::MediaLog> media_log_; |
| 208 | 210 |
| 209 DownloadingCB downloading_cb_; | 211 DownloadingCB downloading_cb_; |
| 210 | 212 |
| 211 DISALLOW_COPY_AND_ASSIGN(BufferedDataSource); | 213 DISALLOW_COPY_AND_ASSIGN(BufferedDataSource); |
| 212 }; | 214 }; |
| 213 | 215 |
| 214 } // namespace webkit_media | 216 } // namespace webkit_media |
| 215 | 217 |
| 216 #endif // WEBKIT_MEDIA_BUFFERED_DATA_SOURCE_H_ | 218 #endif // WEBKIT_MEDIA_BUFFERED_DATA_SOURCE_H_ |
| OLD | NEW |