blob: 4193390a8a9aedad5081d99e5d7ddd4d128113d5 [file] [log] [blame]
pbos@webrtc.orgab990ae2014-09-17 09:02:25 +00001/*
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#ifndef WEBRTC_VIDEO_FRAME_H_
12#define WEBRTC_VIDEO_FRAME_H_
13
magjed@webrtc.orgc8895aa2015-03-03 21:21:28 +000014#include "webrtc/base/scoped_ref_ptr.h"
15#include "webrtc/common_video/interface/video_frame_buffer.h"
pbos@webrtc.orgab990ae2014-09-17 09:02:25 +000016#include "webrtc/typedefs.h"
guoweis@webrtc.org1226e922015-02-11 18:37:54 +000017#include "webrtc/common_video/rotation.h"
pbos@webrtc.orgab990ae2014-09-17 09:02:25 +000018
19namespace webrtc {
20
pbos@webrtc.orgab990ae2014-09-17 09:02:25 +000021class I420VideoFrame {
22 public:
23 I420VideoFrame();
magjed@webrtc.orgc8895aa2015-03-03 21:21:28 +000024 I420VideoFrame(const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& buffer,
25 uint32_t timestamp,
26 int64_t render_time_ms,
27 VideoRotation rotation);
pbos@webrtc.orgab990ae2014-09-17 09:02:25 +000028 virtual ~I420VideoFrame();
pbos@webrtc.orgab990ae2014-09-17 09:02:25 +000029
30 // CreateEmptyFrame: Sets frame dimensions and allocates buffers based
31 // on set dimensions - height and plane stride.
32 // If required size is bigger than the allocated one, new buffers of adequate
33 // size will be allocated.
34 // Return value: 0 on success, -1 on error.
35 virtual int CreateEmptyFrame(int width,
36 int height,
37 int stride_y,
38 int stride_u,
39 int stride_v);
40
41 // CreateFrame: Sets the frame's members and buffers. If required size is
42 // bigger than allocated one, new buffers of adequate size will be allocated.
43 // Return value: 0 on success, -1 on error.
magjed@webrtc.orgc8895aa2015-03-03 21:21:28 +000044 // TODO(magjed): Remove unnecessary buffer size arguments.
pbos@webrtc.orgab990ae2014-09-17 09:02:25 +000045 virtual int CreateFrame(int size_y,
46 const uint8_t* buffer_y,
47 int size_u,
48 const uint8_t* buffer_u,
49 int size_v,
50 const uint8_t* buffer_v,
51 int width,
52 int height,
53 int stride_y,
54 int stride_u,
55 int stride_v);
56
guoweis@webrtc.org1226e922015-02-11 18:37:54 +000057 // TODO(guoweis): remove the previous CreateFrame when chromium has this code.
58 virtual int CreateFrame(int size_y,
59 const uint8_t* buffer_y,
60 int size_u,
61 const uint8_t* buffer_u,
62 int size_v,
63 const uint8_t* buffer_v,
64 int width,
65 int height,
66 int stride_y,
67 int stride_u,
68 int stride_v,
69 VideoRotation rotation);
70
pbos@webrtc.orgab990ae2014-09-17 09:02:25 +000071 // Copy frame: If required size is bigger than allocated one, new buffers of
72 // adequate size will be allocated.
73 // Return value: 0 on success, -1 on error.
74 virtual int CopyFrame(const I420VideoFrame& videoFrame);
75
76 // Make a copy of |this|. The caller owns the returned frame.
77 // Return value: a new frame on success, NULL on error.
78 virtual I420VideoFrame* CloneFrame() const;
79
80 // Swap Frame.
81 virtual void SwapFrame(I420VideoFrame* videoFrame);
82
83 // Get pointer to buffer per plane.
84 virtual uint8_t* buffer(PlaneType type);
85 // Overloading with const.
86 virtual const uint8_t* buffer(PlaneType type) const;
87
88 // Get allocated size per plane.
89 virtual int allocated_size(PlaneType type) const;
90
91 // Get allocated stride per plane.
92 virtual int stride(PlaneType type) const;
93
pbos@webrtc.orgab990ae2014-09-17 09:02:25 +000094 // Get frame width.
magjed@webrtc.orgc8895aa2015-03-03 21:21:28 +000095 virtual int width() const;
pbos@webrtc.orgab990ae2014-09-17 09:02:25 +000096
97 // Get frame height.
magjed@webrtc.orgc8895aa2015-03-03 21:21:28 +000098 virtual int height() const;
pbos@webrtc.orgab990ae2014-09-17 09:02:25 +000099
100 // Set frame timestamp (90kHz).
101 virtual void set_timestamp(uint32_t timestamp) { timestamp_ = timestamp; }
102
103 // Get frame timestamp (90kHz).
104 virtual uint32_t timestamp() const { return timestamp_; }
105
106 // Set capture ntp time in miliseconds.
107 virtual void set_ntp_time_ms(int64_t ntp_time_ms) {
108 ntp_time_ms_ = ntp_time_ms;
109 }
110
111 // Get capture ntp time in miliseconds.
112 virtual int64_t ntp_time_ms() const { return ntp_time_ms_; }
113
guoweis@webrtc.org1226e922015-02-11 18:37:54 +0000114 // Naming convention for Coordination of Video Orientation. Please see
115 // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/ts_126114v120700p.pdf
116 //
117 // "pending rotation" or "pending" = a frame that has a VideoRotation > 0.
118 //
119 // "not pending" = a frame that has a VideoRotation == 0.
120 //
121 // "apply rotation" = modify a frame from being "pending" to being "not
122 // pending" rotation (a no-op for "unrotated").
123 //
124 virtual VideoRotation rotation() const { return rotation_; }
125 virtual void set_rotation(VideoRotation rotation) {
126 rotation_ = rotation;
127 }
128
pbos@webrtc.orgab990ae2014-09-17 09:02:25 +0000129 // Set render time in miliseconds.
130 virtual void set_render_time_ms(int64_t render_time_ms) {
131 render_time_ms_ = render_time_ms;
132 }
133
134 // Get render time in miliseconds.
135 virtual int64_t render_time_ms() const { return render_time_ms_; }
136
137 // Return true if underlying plane buffers are of zero size, false if not.
138 virtual bool IsZeroSize() const;
139
pbos@webrtc.orgab990ae2014-09-17 09:02:25 +0000140 // Return the handle of the underlying video frame. This is used when the
141 // frame is backed by a texture. The object should be destroyed when it is no
142 // longer in use, so the underlying resource can be freed.
143 virtual void* native_handle() const;
144
magjed@webrtc.orgc8895aa2015-03-03 21:21:28 +0000145 // Return the underlying buffer.
146 virtual rtc::scoped_refptr<webrtc::VideoFrameBuffer> video_frame_buffer()
147 const;
pbos@webrtc.orgab990ae2014-09-17 09:02:25 +0000148
149 private:
magjed@webrtc.orgc8895aa2015-03-03 21:21:28 +0000150 // An opaque reference counted handle that stores the pixel data.
151 rtc::scoped_refptr<webrtc::VideoFrameBuffer> video_frame_buffer_;
pbos@webrtc.orgab990ae2014-09-17 09:02:25 +0000152 uint32_t timestamp_;
153 int64_t ntp_time_ms_;
154 int64_t render_time_ms_;
guoweis@webrtc.org1226e922015-02-11 18:37:54 +0000155 VideoRotation rotation_;
pbos@webrtc.orgab990ae2014-09-17 09:02:25 +0000156};
157
158enum VideoFrameType {
159 kKeyFrame = 0,
160 kDeltaFrame = 1,
161 kGoldenFrame = 2,
162 kAltRefFrame = 3,
163 kSkipFrame = 4
164};
165
166// TODO(pbos): Rename EncodedFrame and reformat this class' members.
167class EncodedImage {
168 public:
169 EncodedImage()
170 : _encodedWidth(0),
171 _encodedHeight(0),
172 _timeStamp(0),
173 capture_time_ms_(0),
174 _frameType(kDeltaFrame),
175 _buffer(NULL),
176 _length(0),
177 _size(0),
178 _completeFrame(false) {}
179
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000180 EncodedImage(uint8_t* buffer, size_t length, size_t size)
pbos@webrtc.orgab990ae2014-09-17 09:02:25 +0000181 : _encodedWidth(0),
182 _encodedHeight(0),
183 _timeStamp(0),
184 ntp_time_ms_(0),
185 capture_time_ms_(0),
186 _frameType(kDeltaFrame),
187 _buffer(buffer),
188 _length(length),
189 _size(size),
190 _completeFrame(false) {}
191
192 uint32_t _encodedWidth;
193 uint32_t _encodedHeight;
194 uint32_t _timeStamp;
195 // NTP time of the capture time in local timebase in milliseconds.
196 int64_t ntp_time_ms_;
197 int64_t capture_time_ms_;
pbos@webrtc.org273a4142014-12-01 15:23:21 +0000198 // TODO(pbos): Use webrtc::FrameType directly (and remove VideoFrameType).
pbos@webrtc.orgab990ae2014-09-17 09:02:25 +0000199 VideoFrameType _frameType;
200 uint8_t* _buffer;
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000201 size_t _length;
202 size_t _size;
pbos@webrtc.orgab990ae2014-09-17 09:02:25 +0000203 bool _completeFrame;
204};
205
206} // namespace webrtc
207#endif // WEBRTC_VIDEO_FRAME_H_
208