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

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: Rebased to b647aca12a884a13c1728118586245399b55fa3d (#11493) Created 4 years, 10 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
« no previous file with comments | « talk/media/base/videoengine_unittest.h ('k') | talk/media/base/videoframe.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // 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.
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.
50 // Returns whether the function succeeded or failed.
51
52 virtual bool Reset(uint32_t fourcc,
53 int w,
54 int h,
55 int dw,
56 int dh,
57 uint8_t* sample,
58 size_t sample_size,
59 int64_t time_stamp,
60 webrtc::VideoRotation rotation,
61 bool apply_rotation) = 0;
62
63 // Basic accessors.
64 // Note this is the width and height without rotation applied.
65 virtual size_t GetWidth() const = 0;
66 virtual size_t GetHeight() const = 0;
67
68 size_t GetChromaWidth() const { return (GetWidth() + 1) / 2; }
69 size_t GetChromaHeight() const { return (GetHeight() + 1) / 2; }
70 size_t GetChromaSize() const { return GetUPitch() * GetChromaHeight(); }
71 // These can return NULL if the object is not backed by a buffer.
72 virtual const uint8_t* GetYPlane() const = 0;
73 virtual const uint8_t* GetUPlane() const = 0;
74 virtual const uint8_t* GetVPlane() const = 0;
75 virtual uint8_t* GetYPlane() = 0;
76 virtual uint8_t* GetUPlane() = 0;
77 virtual uint8_t* GetVPlane() = 0;
78
79 virtual int32_t GetYPitch() const = 0;
80 virtual int32_t GetUPitch() const = 0;
81 virtual int32_t GetVPitch() const = 0;
82
83 // Returns the handle of the underlying video frame. This is used when the
84 // frame is backed by a texture. The object should be destroyed when it is no
85 // longer in use, so the underlying resource can be freed.
86 virtual void* GetNativeHandle() const = 0;
87
88 // Returns the underlying video frame buffer. This function is ok to call
89 // multiple times, but the returned object will refer to the same memory.
90 virtual rtc::scoped_refptr<webrtc::VideoFrameBuffer> GetVideoFrameBuffer()
91 const = 0;
92
93 virtual int64_t GetTimeStamp() const = 0;
94 virtual void SetTimeStamp(int64_t time_stamp) = 0;
95
96 // Indicates the rotation angle in degrees.
97 // TODO(guoweis): Remove this function, rename GetVideoRotation and remove the
98 // skeleton implementation of GetRotation once chrome is updated.
99 virtual int GetRotation() const { return GetVideoRotation(); }
100 virtual webrtc::VideoRotation GetVideoRotation() const {
101 return webrtc::kVideoRotation_0;
102 }
103
104 // Make a shallow copy of the frame. The frame buffer itself is not copied.
105 // Both the current and new VideoFrame will share a single reference-counted
106 // frame buffer.
107 virtual VideoFrame *Copy() const = 0;
108
109 // Since VideoFrame supports shallow copy and the internal frame buffer might
110 // be shared, this function can be used to check exclusive ownership.
111 virtual bool IsExclusive() const = 0;
112
113 // In case VideoFrame needs exclusive access of the frame buffer, user can
114 // call MakeExclusive() to make sure the frame buffer is exclusively
115 // accessible to the current object. This might mean a deep copy of the frame
116 // buffer if it is currently shared by other objects.
117 virtual bool MakeExclusive() = 0;
118
119 // Writes the frame into the given frame buffer, provided that it is of
120 // sufficient size. Returns the frame's actual size, regardless of whether
121 // it was written or not (like snprintf). If there is insufficient space,
122 // nothing is written.
123 virtual size_t CopyToBuffer(uint8_t* buffer, size_t size) const;
124
125 // Writes the frame into the given planes, stretched to the given width and
126 // height. The parameter "interpolate" controls whether to interpolate or just
127 // take the nearest-point. The parameter "crop" controls whether to crop this
128 // frame to the aspect ratio of the given dimensions before stretching.
129 virtual bool CopyToPlanes(uint8_t* dst_y,
130 uint8_t* dst_u,
131 uint8_t* dst_v,
132 int32_t dst_pitch_y,
133 int32_t dst_pitch_u,
134 int32_t dst_pitch_v) const;
135
136 // Writes the frame into the target VideoFrame.
137 virtual void CopyToFrame(VideoFrame* target) const;
138
139 // Return a copy of frame which has its pending rotation applied. The
140 // ownership of the returned frame is held by this frame.
141 virtual const VideoFrame* GetCopyWithRotationApplied() const = 0;
142
143 // Writes the frame into the given stream and returns the StreamResult.
144 // See webrtc/base/stream.h for a description of StreamResult and error.
145 // Error may be NULL. If a non-success value is returned from
146 // StreamInterface::Write(), we immediately return with that value.
147 virtual rtc::StreamResult Write(rtc::StreamInterface* stream,
148 int* error) const;
149
150 // Converts the I420 data to RGB of a certain type such as ARGB and ABGR.
151 // Returns the frame's actual size, regardless of whether it was written or
152 // not (like snprintf). Parameters size and stride_rgb are in units of bytes.
153 // If there is insufficient space, nothing is written.
154 virtual size_t ConvertToRgbBuffer(uint32_t to_fourcc,
155 uint8_t* buffer,
156 size_t size,
157 int stride_rgb) const;
158
159 // Writes the frame into the given planes, stretched to the given width and
160 // height. The parameter "interpolate" controls whether to interpolate or just
161 // take the nearest-point. The parameter "crop" controls whether to crop this
162 // frame to the aspect ratio of the given dimensions before stretching.
163 virtual void StretchToPlanes(uint8_t* y,
164 uint8_t* u,
165 uint8_t* v,
166 int32_t pitchY,
167 int32_t pitchU,
168 int32_t pitchV,
169 size_t width,
170 size_t height,
171 bool interpolate,
172 bool crop) const;
173
174 // Writes the frame into the target VideoFrame, stretched to the size of that
175 // frame. The parameter "interpolate" controls whether to interpolate or just
176 // take the nearest-point. The parameter "crop" controls whether to crop this
177 // frame to the aspect ratio of the target frame before stretching.
178 virtual void StretchToFrame(VideoFrame *target, bool interpolate,
179 bool crop) const;
180
181 // Stretches the frame to the given size, creating a new VideoFrame object to
182 // hold it. The parameter "interpolate" controls whether to interpolate or
183 // just take the nearest-point. The parameter "crop" controls whether to crop
184 // this frame to the aspect ratio of the given dimensions before stretching.
185 virtual VideoFrame *Stretch(size_t w, size_t h, bool interpolate,
186 bool crop) const;
187
188 // Sets the video frame to black.
189 virtual bool SetToBlack();
190
191 // Tests if sample is valid. Returns true if valid.
192 static bool Validate(uint32_t fourcc,
193 int w,
194 int h,
195 const uint8_t* sample,
196 size_t sample_size);
197
198 // Size of an I420 image of given dimensions when stored as a frame buffer.
199 static size_t SizeOf(size_t w, size_t h) {
200 return w * h + ((w + 1) / 2) * ((h + 1) / 2) * 2;
201 }
202
203 protected:
204 // Creates an empty frame.
205 virtual VideoFrame *CreateEmptyFrame(int w, int h,
206 int64_t time_stamp) const = 0;
207 virtual void SetRotation(webrtc::VideoRotation rotation) = 0;
208 };
209
210 } // namespace cricket
211
212 #endif // TALK_MEDIA_BASE_VIDEOFRAME_H_
OLDNEW
« no previous file with comments | « talk/media/base/videoengine_unittest.h ('k') | talk/media/base/videoframe.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698