| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2008-2009 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 // Defines various types of timestamped media buffers used for transporting | 5 // Defines various types of timestamped media buffers used for transporting |
| 6 // data between filters. Every buffer contains a timestamp in microseconds | 6 // data between filters. Every buffer contains a timestamp in microseconds |
| 7 // describing the relative position of the buffer within the media stream, and | 7 // describing the relative position of the buffer within the media stream, and |
| 8 // the duration in microseconds for the length of time the buffer will be | 8 // the duration in microseconds for the length of time the buffer will be |
| 9 // rendered. | 9 // rendered. |
| 10 // | 10 // |
| 11 // Timestamps are derived directly from the encoded media file and are commonly | 11 // Timestamps are derived directly from the encoded media file and are commonly |
| (...skipping 17 matching lines...) Expand all Loading... |
| 29 | 29 |
| 30 #include "base/logging.h" | 30 #include "base/logging.h" |
| 31 #include "base/ref_counted.h" | 31 #include "base/ref_counted.h" |
| 32 #include "base/time.h" | 32 #include "base/time.h" |
| 33 | 33 |
| 34 namespace media { | 34 namespace media { |
| 35 | 35 |
| 36 class StreamSample : public base::RefCountedThreadSafe<StreamSample> { | 36 class StreamSample : public base::RefCountedThreadSafe<StreamSample> { |
| 37 public: | 37 public: |
| 38 // Returns the timestamp of this buffer in microseconds. | 38 // Returns the timestamp of this buffer in microseconds. |
| 39 virtual base::TimeDelta GetTimestamp() const = 0; | 39 base::TimeDelta GetTimestamp() const { |
| 40 return timestamp_; |
| 41 } |
| 40 | 42 |
| 41 // Returns the duration of this buffer in microseconds. | 43 // Returns the duration of this buffer in microseconds. |
| 42 virtual base::TimeDelta GetDuration() const = 0; | 44 base::TimeDelta GetDuration() const { |
| 45 return duration_; |
| 46 } |
| 47 |
| 48 // Indicates that the sample is the last one in the stream. |
| 49 bool IsEndOfStream() const { |
| 50 return end_of_stream_; |
| 51 } |
| 52 |
| 53 // Indicates that this sample is discontinuous from the previous one, for |
| 54 // example, following a seek. |
| 55 bool IsDiscontinuous() const { |
| 56 return discontinuous_; |
| 57 } |
| 43 | 58 |
| 44 // Sets the timestamp of this buffer in microseconds. | 59 // Sets the timestamp of this buffer in microseconds. |
| 45 virtual void SetTimestamp(const base::TimeDelta& timestamp) = 0; | 60 void SetTimestamp(const base::TimeDelta& timestamp) { |
| 61 timestamp_ = timestamp; |
| 62 } |
| 46 | 63 |
| 47 // Sets the duration of this buffer in microseconds. | 64 // Sets the duration of this buffer in microseconds. |
| 48 virtual void SetDuration(const base::TimeDelta& duration) = 0; | 65 void SetDuration(const base::TimeDelta& duration) { |
| 66 duration_ = duration; |
| 67 } |
| 68 |
| 69 // Sets the value returned by IsEndOfStream(). |
| 70 void SetEndOfStream(bool end_of_stream) { |
| 71 end_of_stream_ = end_of_stream; |
| 72 } |
| 73 |
| 74 // Sets the value returned by IsDiscontinuous(). |
| 75 void SetDiscontinuous(bool discontinuous) { |
| 76 discontinuous_ = discontinuous; |
| 77 } |
| 49 | 78 |
| 50 protected: | 79 protected: |
| 51 friend class base::RefCountedThreadSafe<StreamSample>; | 80 friend class base::RefCountedThreadSafe<StreamSample>; |
| 81 StreamSample() |
| 82 : end_of_stream_(false), |
| 83 discontinuous_(false) { |
| 84 } |
| 52 virtual ~StreamSample() {} | 85 virtual ~StreamSample() {} |
| 86 |
| 87 base::TimeDelta timestamp_; |
| 88 base::TimeDelta duration_; |
| 89 bool end_of_stream_; |
| 90 bool discontinuous_; |
| 91 |
| 92 private: |
| 93 DISALLOW_COPY_AND_ASSIGN(StreamSample); |
| 53 }; | 94 }; |
| 54 | 95 |
| 55 | 96 |
| 56 class Buffer : public StreamSample { | 97 class Buffer : public StreamSample { |
| 57 public: | 98 public: |
| 58 // Returns a read only pointer to the buffer data. | 99 // Returns a read only pointer to the buffer data. |
| 59 virtual const char* GetData() const = 0; | 100 virtual const char* GetData() const = 0; |
| 60 | 101 |
| 61 // Returns the size of valid data in bytes. | 102 // Returns the size of valid data in bytes. |
| 62 virtual size_t GetDataSize() const = 0; | 103 virtual size_t GetDataSize() const = 0; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 | 168 |
| 128 | 169 |
| 129 // An interface for receiving the results of an asynchronous read. Downstream | 170 // An interface for receiving the results of an asynchronous read. Downstream |
| 130 // filters typically implement this interface or use AssignableBuffer and | 171 // filters typically implement this interface or use AssignableBuffer and |
| 131 // provide it to upstream filters as a read request. When the upstream filter | 172 // provide it to upstream filters as a read request. When the upstream filter |
| 132 // has completed the read, they call SetBuffer/OnAssignment to notify the | 173 // has completed the read, they call SetBuffer/OnAssignment to notify the |
| 133 // downstream filter. | 174 // downstream filter. |
| 134 // | 175 // |
| 135 // TODO(scherkus): rethink the Assignable interface -- it's a bit kludgy. | 176 // TODO(scherkus): rethink the Assignable interface -- it's a bit kludgy. |
| 136 template <class BufferType> | 177 template <class BufferType> |
| 137 class Assignable : | 178 class Assignable |
| 138 public base::RefCountedThreadSafe< Assignable<BufferType> > { | 179 : public base::RefCountedThreadSafe< Assignable<BufferType> > { |
| 139 public: | 180 public: |
| 140 // Assigns a buffer to the owner. | 181 // Assigns a buffer to the owner. |
| 141 virtual void SetBuffer(BufferType* buffer) = 0; | 182 virtual void SetBuffer(BufferType* buffer) = 0; |
| 142 | 183 |
| 143 // Notifies the owner that an assignment has been completed. | 184 // Notifies the owner that an assignment has been completed. |
| 144 virtual void OnAssignment() = 0; | 185 virtual void OnAssignment() = 0; |
| 145 | 186 |
| 146 // TODO(scherkus): figure out a solution to friending a template. | 187 // TODO(scherkus): figure out a solution to friending a template. |
| 147 // See http://www.comeaucomputing.com/techtalk/templates/#friendclassT for | 188 // See http://www.comeaucomputing.com/techtalk/templates/#friendclassT for |
| 148 // an explanation. | 189 // an explanation. |
| 149 //protected: | 190 // protected: |
| 150 // friend class base::RefCountedThreadSafe< Assignable<class T> >; | 191 // friend class base::RefCountedThreadSafe< Assignable<class T> >; |
| 151 virtual ~Assignable() {} | 192 virtual ~Assignable() {} |
| 152 }; | 193 }; |
| 153 | 194 |
| 154 | 195 |
| 155 // Template for easily creating Assignable buffers. Pass in the pointer of the | 196 // Template for easily creating Assignable buffers. Pass in the pointer of the |
| 156 // object to receive the OnAssignment callback. | 197 // object to receive the OnAssignment callback. |
| 157 template <class OwnerType, class BufferType> | 198 template <class OwnerType, class BufferType> |
| 158 class AssignableBuffer : public Assignable<BufferType> { | 199 class AssignableBuffer : public Assignable<BufferType> { |
| 159 public: | 200 public: |
| (...skipping 15 matching lines...) Expand all Loading... |
| 175 private: | 216 private: |
| 176 OwnerType* owner_; | 217 OwnerType* owner_; |
| 177 scoped_refptr<BufferType> buffer_; | 218 scoped_refptr<BufferType> buffer_; |
| 178 | 219 |
| 179 DISALLOW_COPY_AND_ASSIGN(AssignableBuffer); | 220 DISALLOW_COPY_AND_ASSIGN(AssignableBuffer); |
| 180 }; | 221 }; |
| 181 | 222 |
| 182 } // namespace media | 223 } // namespace media |
| 183 | 224 |
| 184 #endif // MEDIA_BASE_BUFFERS_H_ | 225 #endif // MEDIA_BASE_BUFFERS_H_ |
| OLD | NEW |