| 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 MEDIA_FILTERS_FILE_DATA_SOURCE_H_ | 5 #ifndef MEDIA_FILTERS_FILE_DATA_SOURCE_H_ |
| 6 #define MEDIA_FILTERS_FILE_DATA_SOURCE_H_ | 6 #define MEDIA_FILTERS_FILE_DATA_SOURCE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/gtest_prod_util.h" | |
| 11 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
| 12 #include "media/base/data_source.h" | 11 #include "media/base/data_source.h" |
| 13 | 12 |
| 14 namespace media { | 13 namespace media { |
| 15 | 14 |
| 16 // Basic data source that treats the URL as a file path, and uses the file | 15 // Basic data source that treats the URL as a file path, and uses the file |
| 17 // system to read data for a media pipeline. | 16 // system to read data for a media pipeline. |
| 18 class MEDIA_EXPORT FileDataSource : public DataSource { | 17 class MEDIA_EXPORT FileDataSource : public DataSource { |
| 19 public: | 18 public: |
| 20 FileDataSource(); | 19 FileDataSource(); |
| 21 FileDataSource(bool disable_file_size); | |
| 22 | 20 |
| 23 bool Initialize(const std::string& url); | 21 bool Initialize(const std::string& url); |
| 24 | 22 |
| 25 // Implementation of DataSource. | 23 // Implementation of DataSource. |
| 26 virtual void set_host(DataSourceHost* host) OVERRIDE; | 24 virtual void set_host(DataSourceHost* host) OVERRIDE; |
| 27 virtual void Stop(const base::Closure& callback) OVERRIDE; | 25 virtual void Stop(const base::Closure& callback) OVERRIDE; |
| 28 virtual void Read(int64 position, int size, uint8* data, | 26 virtual void Read(int64 position, int size, uint8* data, |
| 29 const DataSource::ReadCB& read_cb) OVERRIDE; | 27 const DataSource::ReadCB& read_cb) OVERRIDE; |
| 30 virtual bool GetSize(int64* size_out) OVERRIDE; | 28 virtual bool GetSize(int64* size_out) OVERRIDE; |
| 31 virtual bool IsStreaming() OVERRIDE; | 29 virtual bool IsStreaming() OVERRIDE; |
| 32 virtual void SetBitrate(int bitrate) OVERRIDE; | 30 virtual void SetBitrate(int bitrate) OVERRIDE; |
| 33 | 31 |
| 32 // Unit test helpers. Recreate the object if you want the default behaviour. |
| 33 void force_read_errors_for_testing() { force_read_errors_ = true; } |
| 34 void force_streaming_for_testing() { force_streaming_ = true; } |
| 35 |
| 34 protected: | 36 protected: |
| 35 virtual ~FileDataSource(); | 37 virtual ~FileDataSource(); |
| 36 | 38 |
| 37 private: | 39 private: |
| 38 // Informs the host of changes in total and buffered bytes. | 40 // Informs the host of changes in total and buffered bytes. |
| 39 void UpdateHostBytes(); | 41 void UpdateHostBytes(); |
| 40 | 42 |
| 41 // File handle. NULL if not initialized or an error occurs. | 43 // File handle. NULL if not initialized or an error occurs. |
| 42 FILE* file_; | 44 FILE* file_; |
| 43 | 45 |
| 44 // Size of the file in bytes. | 46 // Size of the file in bytes. |
| 45 int64 file_size_; | 47 int64 file_size_; |
| 46 | 48 |
| 47 // True if the FileDataSource should ignore its set file size, false | 49 // Serialize all operations to prevent stopping during reads. |
| 48 // otherwise. | 50 base::Lock lock_; |
| 49 bool disable_file_size_; | |
| 50 | 51 |
| 51 // Critical section that protects all of the DataSource methods to prevent | 52 bool force_read_errors_; |
| 52 // a Stop from happening while in the middle of a file I/O operation. | 53 bool force_streaming_; |
| 53 // TODO(ralphl): Ideally this would use asynchronous I/O or we will know | |
| 54 // that we will block for a short period of time in reads. Otherwise, we can | |
| 55 // hang the pipeline Stop. | |
| 56 base::Lock lock_; | |
| 57 | 54 |
| 58 DISALLOW_COPY_AND_ASSIGN(FileDataSource); | 55 DISALLOW_COPY_AND_ASSIGN(FileDataSource); |
| 59 }; | 56 }; |
| 60 | 57 |
| 61 } // namespace media | 58 } // namespace media |
| 62 | 59 |
| 63 #endif // MEDIA_FILTERS_FILE_DATA_SOURCE_H_ | 60 #endif // MEDIA_FILTERS_FILE_DATA_SOURCE_H_ |
| OLD | NEW |