OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2004 Google Inc. | 3 * Copyright 2004 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 virtual ~VideoFrame() {} | 42 virtual ~VideoFrame() {} |
43 | 43 |
44 virtual bool InitToBlack(int w, int h, size_t pixel_width, | 44 virtual bool InitToBlack(int w, int h, size_t pixel_width, |
45 size_t pixel_height, int64_t time_stamp) = 0; | 45 size_t pixel_height, int64_t time_stamp) = 0; |
46 // Creates a frame from a raw sample with FourCC |format| and size |w| x |h|. | 46 // Creates a frame from a raw sample with FourCC |format| and size |w| x |h|. |
47 // |h| can be negative indicating a vertically flipped image. | 47 // |h| can be negative indicating a vertically flipped image. |
48 // |dw| is destination width; can be less than |w| if cropping is desired. | 48 // |dw| is destination width; can be less than |w| if cropping is desired. |
49 // |dh| is destination height, like |dw|, but must be a positive number. | 49 // |dh| is destination height, like |dw|, but must be a positive number. |
50 // Returns whether the function succeeded or failed. | 50 // Returns whether the function succeeded or failed. |
51 | 51 |
52 virtual bool Reset(uint32 fourcc, | 52 virtual bool Reset(uint32_t fourcc, |
53 int w, | 53 int w, |
54 int h, | 54 int h, |
55 int dw, | 55 int dw, |
56 int dh, | 56 int dh, |
57 uint8* sample, | 57 uint8_t* sample, |
58 size_t sample_size, | 58 size_t sample_size, |
59 size_t pixel_width, | 59 size_t pixel_width, |
60 size_t pixel_height, | 60 size_t pixel_height, |
61 int64_t time_stamp, | 61 int64_t time_stamp, |
62 webrtc::VideoRotation rotation, | 62 webrtc::VideoRotation rotation, |
63 bool apply_rotation) = 0; | 63 bool apply_rotation) = 0; |
64 | 64 |
65 // TODO(guoweis): Remove this once all external implementations are updated. | 65 // TODO(guoweis): Remove this once all external implementations are updated. |
66 virtual bool Reset(uint32 fourcc, | 66 virtual bool Reset(uint32_t fourcc, |
67 int w, | 67 int w, |
68 int h, | 68 int h, |
69 int dw, | 69 int dw, |
70 int dh, | 70 int dh, |
71 uint8* sample, | 71 uint8_t* sample, |
72 size_t sample_size, | 72 size_t sample_size, |
73 size_t pixel_width, | 73 size_t pixel_width, |
74 size_t pixel_height, | 74 size_t pixel_height, |
75 int64_t time_stamp, | 75 int64_t time_stamp, |
76 int rotation) { | 76 int rotation) { |
77 return Reset(fourcc, w, h, dw, dh, sample, sample_size, pixel_width, | 77 return Reset(fourcc, w, h, dw, dh, sample, sample_size, pixel_width, |
78 pixel_height, time_stamp, | 78 pixel_height, time_stamp, |
79 static_cast<webrtc::VideoRotation>(rotation), true); | 79 static_cast<webrtc::VideoRotation>(rotation), true); |
80 } | 80 } |
81 | 81 |
82 // Basic accessors. | 82 // Basic accessors. |
83 // Note this is the width and height without rotation applied. | 83 // Note this is the width and height without rotation applied. |
84 virtual size_t GetWidth() const = 0; | 84 virtual size_t GetWidth() const = 0; |
85 virtual size_t GetHeight() const = 0; | 85 virtual size_t GetHeight() const = 0; |
86 | 86 |
87 size_t GetChromaWidth() const { return (GetWidth() + 1) / 2; } | 87 size_t GetChromaWidth() const { return (GetWidth() + 1) / 2; } |
88 size_t GetChromaHeight() const { return (GetHeight() + 1) / 2; } | 88 size_t GetChromaHeight() const { return (GetHeight() + 1) / 2; } |
89 size_t GetChromaSize() const { return GetUPitch() * GetChromaHeight(); } | 89 size_t GetChromaSize() const { return GetUPitch() * GetChromaHeight(); } |
90 // These can return NULL if the object is not backed by a buffer. | 90 // These can return NULL if the object is not backed by a buffer. |
91 virtual const uint8 *GetYPlane() const = 0; | 91 virtual const uint8_t* GetYPlane() const = 0; |
92 virtual const uint8 *GetUPlane() const = 0; | 92 virtual const uint8_t* GetUPlane() const = 0; |
93 virtual const uint8 *GetVPlane() const = 0; | 93 virtual const uint8_t* GetVPlane() const = 0; |
94 virtual uint8 *GetYPlane() = 0; | 94 virtual uint8_t* GetYPlane() = 0; |
95 virtual uint8 *GetUPlane() = 0; | 95 virtual uint8_t* GetUPlane() = 0; |
96 virtual uint8 *GetVPlane() = 0; | 96 virtual uint8_t* GetVPlane() = 0; |
97 | 97 |
98 virtual int32 GetYPitch() const = 0; | 98 virtual int32_t GetYPitch() const = 0; |
99 virtual int32 GetUPitch() const = 0; | 99 virtual int32_t GetUPitch() const = 0; |
100 virtual int32 GetVPitch() const = 0; | 100 virtual int32_t GetVPitch() const = 0; |
101 | 101 |
102 // Returns the handle of the underlying video frame. This is used when the | 102 // Returns the handle of the underlying video frame. This is used when the |
103 // frame is backed by a texture. The object should be destroyed when it is no | 103 // frame is backed by a texture. The object should be destroyed when it is no |
104 // longer in use, so the underlying resource can be freed. | 104 // longer in use, so the underlying resource can be freed. |
105 virtual void* GetNativeHandle() const = 0; | 105 virtual void* GetNativeHandle() const = 0; |
106 | 106 |
107 // Returns the underlying video frame buffer. This function is ok to call | 107 // Returns the underlying video frame buffer. This function is ok to call |
108 // multiple times, but the returned object will refer to the same memory. | 108 // multiple times, but the returned object will refer to the same memory. |
109 virtual rtc::scoped_refptr<webrtc::VideoFrameBuffer> GetVideoFrameBuffer() | 109 virtual rtc::scoped_refptr<webrtc::VideoFrameBuffer> GetVideoFrameBuffer() |
110 const = 0; | 110 const = 0; |
(...skipping 26 matching lines...) Expand all Loading... |
137 // In case VideoFrame needs exclusive access of the frame buffer, user can | 137 // In case VideoFrame needs exclusive access of the frame buffer, user can |
138 // call MakeExclusive() to make sure the frame buffer is exclusively | 138 // call MakeExclusive() to make sure the frame buffer is exclusively |
139 // accessible to the current object. This might mean a deep copy of the frame | 139 // accessible to the current object. This might mean a deep copy of the frame |
140 // buffer if it is currently shared by other objects. | 140 // buffer if it is currently shared by other objects. |
141 virtual bool MakeExclusive() = 0; | 141 virtual bool MakeExclusive() = 0; |
142 | 142 |
143 // Writes the frame into the given frame buffer, provided that it is of | 143 // Writes the frame into the given frame buffer, provided that it is of |
144 // sufficient size. Returns the frame's actual size, regardless of whether | 144 // sufficient size. Returns the frame's actual size, regardless of whether |
145 // it was written or not (like snprintf). If there is insufficient space, | 145 // it was written or not (like snprintf). If there is insufficient space, |
146 // nothing is written. | 146 // nothing is written. |
147 virtual size_t CopyToBuffer(uint8 *buffer, size_t size) const; | 147 virtual size_t CopyToBuffer(uint8_t* buffer, size_t size) const; |
148 | 148 |
149 // Writes the frame into the given planes, stretched to the given width and | 149 // Writes the frame into the given planes, stretched to the given width and |
150 // height. The parameter "interpolate" controls whether to interpolate or just | 150 // height. The parameter "interpolate" controls whether to interpolate or just |
151 // take the nearest-point. The parameter "crop" controls whether to crop this | 151 // take the nearest-point. The parameter "crop" controls whether to crop this |
152 // frame to the aspect ratio of the given dimensions before stretching. | 152 // frame to the aspect ratio of the given dimensions before stretching. |
153 virtual bool CopyToPlanes( | 153 virtual bool CopyToPlanes(uint8_t* dst_y, |
154 uint8* dst_y, uint8* dst_u, uint8* dst_v, | 154 uint8_t* dst_u, |
155 int32 dst_pitch_y, int32 dst_pitch_u, int32 dst_pitch_v) const; | 155 uint8_t* dst_v, |
| 156 int32_t dst_pitch_y, |
| 157 int32_t dst_pitch_u, |
| 158 int32_t dst_pitch_v) const; |
156 | 159 |
157 // Writes the frame into the target VideoFrame. | 160 // Writes the frame into the target VideoFrame. |
158 virtual void CopyToFrame(VideoFrame* target) const; | 161 virtual void CopyToFrame(VideoFrame* target) const; |
159 | 162 |
160 // Return a copy of frame which has its pending rotation applied. The | 163 // Return a copy of frame which has its pending rotation applied. The |
161 // ownership of the returned frame is held by this frame. | 164 // ownership of the returned frame is held by this frame. |
162 virtual const VideoFrame* GetCopyWithRotationApplied() const = 0; | 165 virtual const VideoFrame* GetCopyWithRotationApplied() const = 0; |
163 | 166 |
164 // Writes the frame into the given stream and returns the StreamResult. | 167 // Writes the frame into the given stream and returns the StreamResult. |
165 // See webrtc/base/stream.h for a description of StreamResult and error. | 168 // See webrtc/base/stream.h for a description of StreamResult and error. |
166 // Error may be NULL. If a non-success value is returned from | 169 // Error may be NULL. If a non-success value is returned from |
167 // StreamInterface::Write(), we immediately return with that value. | 170 // StreamInterface::Write(), we immediately return with that value. |
168 virtual rtc::StreamResult Write(rtc::StreamInterface* stream, | 171 virtual rtc::StreamResult Write(rtc::StreamInterface* stream, |
169 int* error) const; | 172 int* error) const; |
170 | 173 |
171 // Converts the I420 data to RGB of a certain type such as ARGB and ABGR. | 174 // Converts the I420 data to RGB of a certain type such as ARGB and ABGR. |
172 // Returns the frame's actual size, regardless of whether it was written or | 175 // Returns the frame's actual size, regardless of whether it was written or |
173 // not (like snprintf). Parameters size and stride_rgb are in units of bytes. | 176 // not (like snprintf). Parameters size and stride_rgb are in units of bytes. |
174 // If there is insufficient space, nothing is written. | 177 // If there is insufficient space, nothing is written. |
175 virtual size_t ConvertToRgbBuffer(uint32 to_fourcc, uint8 *buffer, | 178 virtual size_t ConvertToRgbBuffer(uint32_t to_fourcc, |
176 size_t size, int stride_rgb) const; | 179 uint8_t* buffer, |
| 180 size_t size, |
| 181 int stride_rgb) const; |
177 | 182 |
178 // Writes the frame into the given planes, stretched to the given width and | 183 // Writes the frame into the given planes, stretched to the given width and |
179 // height. The parameter "interpolate" controls whether to interpolate or just | 184 // height. The parameter "interpolate" controls whether to interpolate or just |
180 // take the nearest-point. The parameter "crop" controls whether to crop this | 185 // take the nearest-point. The parameter "crop" controls whether to crop this |
181 // frame to the aspect ratio of the given dimensions before stretching. | 186 // frame to the aspect ratio of the given dimensions before stretching. |
182 virtual void StretchToPlanes( | 187 virtual void StretchToPlanes(uint8_t* y, |
183 uint8 *y, uint8 *u, uint8 *v, int32 pitchY, int32 pitchU, int32 pitchV, | 188 uint8_t* u, |
184 size_t width, size_t height, bool interpolate, bool crop) const; | 189 uint8_t* v, |
| 190 int32_t pitchY, |
| 191 int32_t pitchU, |
| 192 int32_t pitchV, |
| 193 size_t width, |
| 194 size_t height, |
| 195 bool interpolate, |
| 196 bool crop) const; |
185 | 197 |
186 // Writes the frame into the target VideoFrame, stretched to the size of that | 198 // Writes the frame into the target VideoFrame, stretched to the size of that |
187 // frame. The parameter "interpolate" controls whether to interpolate or just | 199 // frame. The parameter "interpolate" controls whether to interpolate or just |
188 // take the nearest-point. The parameter "crop" controls whether to crop this | 200 // take the nearest-point. The parameter "crop" controls whether to crop this |
189 // frame to the aspect ratio of the target frame before stretching. | 201 // frame to the aspect ratio of the target frame before stretching. |
190 virtual void StretchToFrame(VideoFrame *target, bool interpolate, | 202 virtual void StretchToFrame(VideoFrame *target, bool interpolate, |
191 bool crop) const; | 203 bool crop) const; |
192 | 204 |
193 // Stretches the frame to the given size, creating a new VideoFrame object to | 205 // Stretches the frame to the given size, creating a new VideoFrame object to |
194 // hold it. The parameter "interpolate" controls whether to interpolate or | 206 // hold it. The parameter "interpolate" controls whether to interpolate or |
195 // just take the nearest-point. The parameter "crop" controls whether to crop | 207 // just take the nearest-point. The parameter "crop" controls whether to crop |
196 // this frame to the aspect ratio of the given dimensions before stretching. | 208 // this frame to the aspect ratio of the given dimensions before stretching. |
197 virtual VideoFrame *Stretch(size_t w, size_t h, bool interpolate, | 209 virtual VideoFrame *Stretch(size_t w, size_t h, bool interpolate, |
198 bool crop) const; | 210 bool crop) const; |
199 | 211 |
200 // Sets the video frame to black. | 212 // Sets the video frame to black. |
201 virtual bool SetToBlack(); | 213 virtual bool SetToBlack(); |
202 | 214 |
203 // Tests if sample is valid. Returns true if valid. | 215 // Tests if sample is valid. Returns true if valid. |
204 static bool Validate(uint32 fourcc, int w, int h, const uint8 *sample, | 216 static bool Validate(uint32_t fourcc, |
| 217 int w, |
| 218 int h, |
| 219 const uint8_t* sample, |
205 size_t sample_size); | 220 size_t sample_size); |
206 | 221 |
207 // Size of an I420 image of given dimensions when stored as a frame buffer. | 222 // Size of an I420 image of given dimensions when stored as a frame buffer. |
208 static size_t SizeOf(size_t w, size_t h) { | 223 static size_t SizeOf(size_t w, size_t h) { |
209 return w * h + ((w + 1) / 2) * ((h + 1) / 2) * 2; | 224 return w * h + ((w + 1) / 2) * ((h + 1) / 2) * 2; |
210 } | 225 } |
211 | 226 |
212 protected: | 227 protected: |
213 // Creates an empty frame. | 228 // Creates an empty frame. |
214 virtual VideoFrame *CreateEmptyFrame(int w, int h, size_t pixel_width, | 229 virtual VideoFrame *CreateEmptyFrame(int w, int h, size_t pixel_width, |
215 size_t pixel_height, | 230 size_t pixel_height, |
216 int64_t time_stamp) const = 0; | 231 int64_t time_stamp) const = 0; |
217 virtual void SetRotation(webrtc::VideoRotation rotation) = 0; | 232 virtual void SetRotation(webrtc::VideoRotation rotation) = 0; |
218 }; | 233 }; |
219 | 234 |
220 } // namespace cricket | 235 } // namespace cricket |
221 | 236 |
222 #endif // TALK_MEDIA_BASE_VIDEOFRAME_H_ | 237 #endif // TALK_MEDIA_BASE_VIDEOFRAME_H_ |
OLD | NEW |