OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef MEDIA_BASE_DATA_SOURCE_H_ |
| 6 #define MEDIA_BASE_DATA_SOURCE_H_ |
| 7 |
| 8 #include "base/callback.h" |
| 9 #include "base/memory/ref_counted.h" |
| 10 #include "media/base/media_export.h" |
| 11 #include "media/base/preload.h" |
| 12 |
| 13 namespace media { |
| 14 |
| 15 class MEDIA_EXPORT DataSourceHost { |
| 16 public: |
| 17 virtual ~DataSourceHost(); |
| 18 |
| 19 // Set the total size of the media file. |
| 20 virtual void SetTotalBytes(int64 total_bytes) = 0; |
| 21 |
| 22 // Sets the total number of bytes that are buffered on the client and ready to |
| 23 // be played. |
| 24 virtual void SetBufferedBytes(int64 buffered_bytes) = 0; |
| 25 |
| 26 // Sets the flag to indicate current network activity. |
| 27 virtual void SetNetworkActivity(bool is_downloading_data) = 0; |
| 28 }; |
| 29 |
| 30 class MEDIA_EXPORT DataSource : public base::RefCountedThreadSafe<DataSource> { |
| 31 public: |
| 32 typedef base::Callback<void(int64, int64)> StatusCallback; |
| 33 typedef base::Callback<void(size_t)> ReadCallback; |
| 34 static const size_t kReadError; |
| 35 |
| 36 DataSource(); |
| 37 |
| 38 virtual void set_host(DataSourceHost* host); |
| 39 |
| 40 // Reads |size| bytes from |position| into |data|. And when the read is done |
| 41 // or failed, |read_callback| is called with the number of bytes read or |
| 42 // kReadError in case of error. |
| 43 // TODO(hclam): should change |size| to int! It makes the code so messy |
| 44 // with size_t and int all over the place.. |
| 45 virtual void Read(int64 position, size_t size, |
| 46 uint8* data, |
| 47 const DataSource::ReadCallback& read_callback) = 0; |
| 48 |
| 49 // Notifies the DataSource of a change in the current playback rate. |
| 50 virtual void SetPlaybackRate(float playback_rate); |
| 51 |
| 52 // Stops the DataSource. Once this is called all future Read() calls will |
| 53 // return an error. |
| 54 virtual void Stop(const base::Closure& callback) = 0; |
| 55 |
| 56 // Returns true and the file size, false if the file size could not be |
| 57 // retrieved. |
| 58 virtual bool GetSize(int64* size_out) = 0; |
| 59 |
| 60 // Returns true if we are performing streaming. In this case seeking is |
| 61 // not possible. |
| 62 virtual bool IsStreaming() = 0; |
| 63 |
| 64 // Alert the DataSource that the video preload value has been changed. |
| 65 virtual void SetPreload(Preload preload) = 0; |
| 66 |
| 67 // Notify the DataSource of the bitrate of the media. |
| 68 // Values of |bitrate| <= 0 are invalid and should be ignored. |
| 69 virtual void SetBitrate(int bitrate) = 0; |
| 70 |
| 71 protected: |
| 72 // Only allow scoped_refptr<> to delete DataSource. |
| 73 friend class base::RefCountedThreadSafe<DataSource>; |
| 74 virtual ~DataSource(); |
| 75 |
| 76 DataSourceHost* host(); |
| 77 |
| 78 private: |
| 79 DataSourceHost* host_; |
| 80 |
| 81 DISALLOW_COPY_AND_ASSIGN(DataSource); |
| 82 }; |
| 83 |
| 84 } // namespace media |
| 85 |
| 86 #endif // MEDIA_BASE_DATA_SOURCE_H_ |
OLD | NEW |