Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: talk/media/base/videoframe.h

Issue 1587193006: Move talk/media to webrtc/media (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rename back test to libjingle_media_unittest Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * libjingle
3 * Copyright 2004 Google Inc.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #ifndef TALK_MEDIA_BASE_VIDEOFRAME_H_
29 #define TALK_MEDIA_BASE_VIDEOFRAME_H_
30
31 #include "webrtc/base/basictypes.h"
32 #include "webrtc/base/stream.h"
33 #include "webrtc/common_video/include/video_frame_buffer.h"
34 #include "webrtc/common_video/rotation.h"
35
36 namespace cricket {
37
38 // Represents a YUV420 (a.k.a. I420) video frame.
39 class VideoFrame {
40 public:
41 VideoFrame() {}
42 virtual ~VideoFrame() {}
43
44 virtual bool InitToBlack(int w, int h, int64_t time_stamp) = 0;
45
46 // TODO(nisse): Old signature. Delete after chrome is updated.
47 virtual bool InitToBlack(int w, int h, size_t pixel_width,
48 size_t pixel_height, int64_t time_stamp) {
49 return InitToBlack(w, h, time_stamp);
50 }
51 // Creates a frame from a raw sample with FourCC |format| and size |w| x |h|.
52 // |h| can be negative indicating a vertically flipped image.
53 // |dw| is destination width; can be less than |w| if cropping is desired.
54 // |dh| is destination height, like |dw|, but must be a positive number.
55 // Returns whether the function succeeded or failed.
56
57 virtual bool Reset(uint32_t fourcc,
58 int w,
59 int h,
60 int dw,
61 int dh,
62 uint8_t* sample,
63 size_t sample_size,
64 int64_t time_stamp,
65 webrtc::VideoRotation rotation,
66 bool apply_rotation) = 0;
67
68 // Basic accessors.
69 // Note this is the width and height without rotation applied.
70 virtual size_t GetWidth() const = 0;
71 virtual size_t GetHeight() const = 0;
72
73 size_t GetChromaWidth() const { return (GetWidth() + 1) / 2; }
74 size_t GetChromaHeight() const { return (GetHeight() + 1) / 2; }
75 size_t GetChromaSize() const { return GetUPitch() * GetChromaHeight(); }
76 // These can return NULL if the object is not backed by a buffer.
77 virtual const uint8_t* GetYPlane() const = 0;
78 virtual const uint8_t* GetUPlane() const = 0;
79 virtual const uint8_t* GetVPlane() const = 0;
80 virtual uint8_t* GetYPlane() = 0;
81 virtual uint8_t* GetUPlane() = 0;
82 virtual uint8_t* GetVPlane() = 0;
83
84 virtual int32_t GetYPitch() const = 0;
85 virtual int32_t GetUPitch() const = 0;
86 virtual int32_t GetVPitch() const = 0;
87
88 // Returns the handle of the underlying video frame. This is used when the
89 // frame is backed by a texture. The object should be destroyed when it is no
90 // longer in use, so the underlying resource can be freed.
91 virtual void* GetNativeHandle() const = 0;
92
93 // Returns the underlying video frame buffer. This function is ok to call
94 // multiple times, but the returned object will refer to the same memory.
95 virtual rtc::scoped_refptr<webrtc::VideoFrameBuffer> GetVideoFrameBuffer()
96 const = 0;
97
98 virtual int64_t GetTimeStamp() const = 0;
99 virtual void SetTimeStamp(int64_t time_stamp) = 0;
100
101 // Indicates the rotation angle in degrees.
102 // TODO(guoweis): Remove this function, rename GetVideoRotation and remove the
103 // skeleton implementation of GetRotation once chrome is updated.
104 virtual int GetRotation() const { return GetVideoRotation(); }
105 virtual webrtc::VideoRotation GetVideoRotation() const {
106 return webrtc::kVideoRotation_0;
107 }
108
109 // Make a shallow copy of the frame. The frame buffer itself is not copied.
110 // Both the current and new VideoFrame will share a single reference-counted
111 // frame buffer.
112 virtual VideoFrame *Copy() const = 0;
113
114 // Since VideoFrame supports shallow copy and the internal frame buffer might
115 // be shared, this function can be used to check exclusive ownership.
116 virtual bool IsExclusive() const = 0;
117
118 // In case VideoFrame needs exclusive access of the frame buffer, user can
119 // call MakeExclusive() to make sure the frame buffer is exclusively
120 // accessible to the current object. This might mean a deep copy of the frame
121 // buffer if it is currently shared by other objects.
122 virtual bool MakeExclusive() = 0;
123
124 // Writes the frame into the given frame buffer, provided that it is of
125 // sufficient size. Returns the frame's actual size, regardless of whether
126 // it was written or not (like snprintf). If there is insufficient space,
127 // nothing is written.
128 virtual size_t CopyToBuffer(uint8_t* buffer, size_t size) const;
129
130 // Writes the frame into the given planes, stretched to the given width and
131 // height. The parameter "interpolate" controls whether to interpolate or just
132 // take the nearest-point. The parameter "crop" controls whether to crop this
133 // frame to the aspect ratio of the given dimensions before stretching.
134 virtual bool CopyToPlanes(uint8_t* dst_y,
135 uint8_t* dst_u,
136 uint8_t* dst_v,
137 int32_t dst_pitch_y,
138 int32_t dst_pitch_u,
139 int32_t dst_pitch_v) const;
140
141 // Writes the frame into the target VideoFrame.
142 virtual void CopyToFrame(VideoFrame* target) const;
143
144 // Return a copy of frame which has its pending rotation applied. The
145 // ownership of the returned frame is held by this frame.
146 virtual const VideoFrame* GetCopyWithRotationApplied() const = 0;
147
148 // Writes the frame into the given stream and returns the StreamResult.
149 // See webrtc/base/stream.h for a description of StreamResult and error.
150 // Error may be NULL. If a non-success value is returned from
151 // StreamInterface::Write(), we immediately return with that value.
152 virtual rtc::StreamResult Write(rtc::StreamInterface* stream,
153 int* error) const;
154
155 // Converts the I420 data to RGB of a certain type such as ARGB and ABGR.
156 // Returns the frame's actual size, regardless of whether it was written or
157 // not (like snprintf). Parameters size and stride_rgb are in units of bytes.
158 // If there is insufficient space, nothing is written.
159 virtual size_t ConvertToRgbBuffer(uint32_t to_fourcc,
160 uint8_t* buffer,
161 size_t size,
162 int stride_rgb) const;
163
164 // Writes the frame into the given planes, stretched to the given width and
165 // height. The parameter "interpolate" controls whether to interpolate or just
166 // take the nearest-point. The parameter "crop" controls whether to crop this
167 // frame to the aspect ratio of the given dimensions before stretching.
168 virtual void StretchToPlanes(uint8_t* y,
169 uint8_t* u,
170 uint8_t* v,
171 int32_t pitchY,
172 int32_t pitchU,
173 int32_t pitchV,
174 size_t width,
175 size_t height,
176 bool interpolate,
177 bool crop) const;
178
179 // Writes the frame into the target VideoFrame, stretched to the size of that
180 // frame. The parameter "interpolate" controls whether to interpolate or just
181 // take the nearest-point. The parameter "crop" controls whether to crop this
182 // frame to the aspect ratio of the target frame before stretching.
183 virtual void StretchToFrame(VideoFrame *target, bool interpolate,
184 bool crop) const;
185
186 // Stretches the frame to the given size, creating a new VideoFrame object to
187 // hold it. The parameter "interpolate" controls whether to interpolate or
188 // just take the nearest-point. The parameter "crop" controls whether to crop
189 // this frame to the aspect ratio of the given dimensions before stretching.
190 virtual VideoFrame *Stretch(size_t w, size_t h, bool interpolate,
191 bool crop) const;
192
193 // Sets the video frame to black.
194 virtual bool SetToBlack();
195
196 // Tests if sample is valid. Returns true if valid.
197 static bool Validate(uint32_t fourcc,
198 int w,
199 int h,
200 const uint8_t* sample,
201 size_t sample_size);
202
203 // Size of an I420 image of given dimensions when stored as a frame buffer.
204 static size_t SizeOf(size_t w, size_t h) {
205 return w * h + ((w + 1) / 2) * ((h + 1) / 2) * 2;
206 }
207
208 protected:
209 // Creates an empty frame.
210 virtual VideoFrame *CreateEmptyFrame(int w, int h,
211 int64_t time_stamp) const = 0;
212 virtual void SetRotation(webrtc::VideoRotation rotation) = 0;
213 };
214
215 } // namespace cricket
216
217 #endif // TALK_MEDIA_BASE_VIDEOFRAME_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698