OLD | NEW |
---|---|
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 | |
darin (slow to review)
2008/12/08 20:40:47
nice!
| |
6 // data between filters. Every buffer contains a timestamp in microseconds | |
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 | |
9 // rendered. | |
10 // | |
11 // Timestamps are derived directly from the encoded media file and are commonly | |
12 // known as the presentation timestamp (PTS). Durations are a best-guess and | |
13 // are usually derived from the sample/frame rate of the media file. | |
14 // | |
15 // Due to encoding and transmission errors, it is not guaranteed that timestamps | |
16 // arrive in a monotonically increasing order nor that the next timestamp will | |
17 // be equal to the previous timestamp plus the duration. | |
18 // | |
19 // In the ideal scenario for a 25fps movie, buffers are timestamped as followed: | |
20 // | |
21 // Buffer0 Buffer1 Buffer2 ... BufferN | |
22 // Timestamp: 0us 40000us 80000us ... (N*40000)us | |
23 // Duration*: 40000us 40000us 40000us ... 40000us | |
24 // | |
25 // *25fps = 0.04s per frame = 40000us per frame | |
26 | |
5 #ifndef MEDIA_BASE_BUFFERS_H_ | 27 #ifndef MEDIA_BASE_BUFFERS_H_ |
6 #define MEDIA_BASE_BUFFERS_H_ | 28 #define MEDIA_BASE_BUFFERS_H_ |
7 | 29 |
8 #include "base/basictypes.h" | |
9 #include "base/ref_counted.h" | 30 #include "base/ref_counted.h" |
10 | 31 |
11 namespace media { | 32 namespace media { |
12 | 33 |
13 // NOTE: this isn't a true interface since RefCountedThreadSafe has non-virtual | |
14 // members, therefore implementors should NOT subclass RefCountedThreadSafe. | |
15 // | |
16 // If you do, AddRef/Release will have different outcomes depending on the | |
17 // current type of the pointer (StreamSampleInterface vs. SomeImplementation). | |
18 class StreamSampleInterface : | 34 class StreamSampleInterface : |
19 public base::RefCountedThreadSafe<StreamSampleInterface> { | 35 public base::RefCountedThreadSafe<StreamSampleInterface> { |
20 public: | 36 public: |
37 // Returns the timestamp of this buffer in microseconds. | |
38 virtual int64 GetTimestamp() = 0; | |
39 | |
40 // Returns the duration of this buffer in microseconds. | |
41 virtual int64 GetDuration() = 0; | |
42 | |
43 // Sets the timestamp of this buffer in microseconds. | |
44 virtual void SetTimestamp(int64 timestamp) = 0; | |
45 | |
46 // Sets the duration of this buffer in microseconds. | |
47 virtual void SetDuration(int64 duration) = 0; | |
48 | |
49 protected: | |
50 friend class base::RefCountedThreadSafe<StreamSampleInterface>; | |
21 virtual ~StreamSampleInterface() {} | 51 virtual ~StreamSampleInterface() {} |
22 | |
23 virtual int64 GetTimestamp() = 0; | |
24 virtual int64 GetDuration() = 0; | |
25 virtual void SetTimestamp(int64 timestamp) = 0; | |
26 virtual void SetDuration(int64 duration) = 0; | |
27 }; | 52 }; |
28 | 53 |
29 | 54 |
30 class BufferInterface : public StreamSampleInterface { | 55 class BufferInterface : public StreamSampleInterface { |
31 public: | 56 public: |
32 virtual ~BufferInterface() {} | |
33 | |
34 // Returns a read only pointer to the buffer data. | 57 // Returns a read only pointer to the buffer data. |
35 virtual const char* GetData() = 0; | 58 virtual const char* GetData() = 0; |
36 | 59 |
37 // Returns the size of valid data in bytes. | 60 // Returns the size of valid data in bytes. |
38 virtual size_t GetDataSize() = 0; | 61 virtual size_t GetDataSize() = 0; |
39 }; | 62 }; |
40 | 63 |
41 | 64 |
42 class WritableBufferInterface : public BufferInterface { | 65 class WritableBufferInterface : public BufferInterface { |
43 public: | 66 public: |
44 virtual ~WritableBufferInterface() {} | |
45 | |
46 // Returns a read-write pointer to the buffer data. | 67 // Returns a read-write pointer to the buffer data. |
47 virtual char* GetWritableData() = 0; | 68 virtual char* GetWritableData() = 0; |
48 | 69 |
49 // Updates the size of valid data in bytes, which must be less than or equal | 70 // Updates the size of valid data in bytes, which must be less than or equal |
50 // to GetBufferSize. | 71 // to GetBufferSize. |
51 virtual void SetDataSize(size_t data_size) = 0; | 72 virtual void SetDataSize(size_t data_size) = 0; |
52 | 73 |
53 // Returns the maximum allocated size for this buffer. | 74 // Returns the maximum allocated size for this buffer. |
54 virtual size_t GetBufferSize() = 0; | 75 virtual size_t GetBufferSize() = 0; |
55 }; | 76 }; |
(...skipping 30 matching lines...) Expand all Loading... | |
86 // of the surface divided by the horizontal sampling period. | 107 // of the surface divided by the horizontal sampling period. |
87 size_t strides[kMaxPlanes]; | 108 size_t strides[kMaxPlanes]; |
88 | 109 |
89 // Array of data pointers to each plane. | 110 // Array of data pointers to each plane. |
90 char* data[kMaxPlanes]; | 111 char* data[kMaxPlanes]; |
91 }; | 112 }; |
92 | 113 |
93 | 114 |
94 class VideoFrameInterface : public StreamSampleInterface { | 115 class VideoFrameInterface : public StreamSampleInterface { |
95 public: | 116 public: |
96 virtual ~VideoFrameInterface() {} | |
97 | |
98 // Locks the underlying surface and fills out the given VideoSurface and | 117 // Locks the underlying surface and fills out the given VideoSurface and |
99 // returns true if successful, false otherwise. | 118 // returns true if successful, false otherwise. Any additional calls to Lock |
119 // will fail. | |
100 virtual bool Lock(VideoSurface* surface) = 0; | 120 virtual bool Lock(VideoSurface* surface) = 0; |
101 | 121 |
102 // Unlocks the underlying surface, any previous VideoSurfaces are no longer | 122 // Unlocks the underlying surface, the VideoSurface acquired from Lock is no |
103 // guaranteed to be valid. | 123 // longer guaranteed to be valid. |
104 virtual void Unlock() = 0; | 124 virtual void Unlock() = 0; |
105 }; | 125 }; |
106 | 126 |
107 | 127 |
108 template <class BufferType> | 128 template <class BufferType> |
109 class AssignableInterface { | 129 class AssignableInterface { |
110 public: | 130 public: |
111 virtual ~AssignableInterface() {} | |
112 | |
113 // Assigns a buffer to the owner. | 131 // Assigns a buffer to the owner. |
114 virtual void SetBuffer(BufferType* buffer) = 0; | 132 virtual void SetBuffer(BufferType* buffer) = 0; |
115 | 133 |
116 // Notifies the owner that an assignment has been completed. | 134 // Notifies the owner that an assignment has been completed. |
117 virtual void OnAssignment() = 0; | 135 virtual void OnAssignment() = 0; |
118 }; | 136 }; |
119 | 137 |
120 | 138 |
121 // Template for easily creating AssignableInterface buffers. Pass in the | 139 // Template for easily creating AssignableInterface buffers. Pass in the |
122 // pointer of the object to receive the OnAssignment callback. | 140 // pointer of the object to receive the OnAssignment callback. |
123 template <class OwnerType, class BufferType> | 141 template <class OwnerType, class BufferType> |
124 class AssignableBuffer : public AssignableInterface<BufferType>, | 142 class AssignableBuffer : public AssignableInterface<BufferType>, |
125 public base::RefCountedThreadSafe<AssignableBuffer<OwnerType, BufferType> > { | 143 public base::RefCountedThreadSafe<AssignableBuffer<OwnerType, BufferType> > { |
126 public: | 144 public: |
127 explicit AssignableBuffer(OwnerType* owner) | 145 explicit AssignableBuffer(OwnerType* owner) |
128 : owner_(owner), | 146 : owner_(owner), |
129 buffer_(NULL) { | 147 buffer_(NULL) { |
130 DCHECK(owner_); | 148 DCHECK(owner_); |
131 } | 149 } |
132 virtual ~AssignableBuffer() {} | |
133 | 150 |
134 // AssignableBufferInterface<BufferType> | 151 // AssignableBufferInterface<BufferType> |
135 virtual void SetBuffer(BufferType* buffer) { | 152 virtual void SetBuffer(BufferType* buffer) { |
136 buffer_ = buffer; | 153 buffer_ = buffer; |
137 } | 154 } |
138 | 155 |
139 virtual void OnAssignment() { | 156 virtual void OnAssignment() { |
140 owner_->OnAssignment(buffer_.get()); | 157 owner_->OnAssignment(buffer_.get()); |
141 } | 158 } |
142 | 159 |
143 private: | 160 private: |
144 OwnerType* owner_; | 161 OwnerType* owner_; |
145 scoped_refptr<BufferType> buffer_; | 162 scoped_refptr<BufferType> buffer_; |
146 | 163 |
147 DISALLOW_COPY_AND_ASSIGN(AssignableBuffer); | 164 DISALLOW_COPY_AND_ASSIGN(AssignableBuffer); |
148 }; | 165 }; |
149 | 166 |
150 } // namespace media | 167 } // namespace media |
151 | 168 |
152 #endif // MEDIA_BASE_BUFFERS_H_ | 169 #endif // MEDIA_BASE_BUFFERS_H_ |
OLD | NEW |