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