blob: 0e528c1e4f6bc59ab72b05536c537395b3ef56ab [file] [log] [blame]
mikhal@webrtc.org043ed9e2012-09-18 16:14:26 +00001/*
2 * Copyright (c) 2012 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 COMMON_VIDEO_INTERFACE_I420_VIDEO_FRAME_H
12#define COMMON_VIDEO_INTERFACE_I420_VIDEO_FRAME_H
13
14// I420VideoFrame class
15//
16// Storing and handling of YUV (I420) video frames.
17
18#include "common_video/plane.h"
19#include "typedefs.h" //NOLINT
20
21namespace webrtc {
22
23enum PlaneType {
24 kYPlane = 0,
25 kUPlane = 1,
mikhal@webrtc.org0e6f5972012-09-24 20:35:40 +000026 kVPlane = 2,
mikhal@webrtc.org9fedff72012-10-24 18:33:04 +000027 kNumOfPlanes = 3
mikhal@webrtc.org043ed9e2012-09-18 16:14:26 +000028};
29
30class I420VideoFrame {
31 public:
32 I420VideoFrame();
33 ~I420VideoFrame();
34
35 // CreateEmptyFrame: Sets frame dimensions and allocates buffers based
36 // on set dimensions - height and plane stride.
37 // If required size is bigger than the allocated one, new buffers of adequate
38 // size will be allocated.
39 // Return value: 0 on success ,-1 on error.
40 int CreateEmptyFrame(int width, int height,
41 int stride_y, int stride_u, int stride_v);
42
43 // CreateFrame: Sets the frame's members and buffers. If required size is
44 // bigger than allocated one, new buffers of adequate size will be allocated.
45 // Return value: 0 on success ,-1 on error.
mikhal@webrtc.org60ac6a62012-10-03 16:24:14 +000046 int CreateFrame(int size_y, const uint8_t* buffer_y,
47 int size_u, const uint8_t* buffer_u,
48 int size_v, const uint8_t* buffer_v,
mikhal@webrtc.org043ed9e2012-09-18 16:14:26 +000049 int width, int height,
50 int stride_y, int stride_u, int stride_v);
51
52 // Copy frame: If required size is bigger than allocated one, new buffers of
53 // adequate size will be allocated.
54 // Return value: 0 on success ,-1 on error.
55 int CopyFrame(const I420VideoFrame& videoFrame);
56
57 // Swap Frame.
58 void SwapFrame(I420VideoFrame* videoFrame);
59
60 // Get pointer to buffer per plane.
mikhal@webrtc.org60ac6a62012-10-03 16:24:14 +000061 uint8_t* buffer(PlaneType type);
62 // Overloading with const.
mikhal@webrtc.org043ed9e2012-09-18 16:14:26 +000063 const uint8_t* buffer(PlaneType type) const;
64
65 // Get allocated size per plane.
mikhal@webrtc.orgdfc6b572012-10-15 16:12:09 +000066 int allocated_size(PlaneType type) const;
mikhal@webrtc.org043ed9e2012-09-18 16:14:26 +000067
68 // Get allocated stride per plane.
69 int stride(PlaneType type) const;
70
71 // Set frame width.
72 int set_width(int width);
73
74 // Set frame height.
75 int set_height(int height);
76
77 // Get frame width.
78 int width() const {return width_;}
79
80 // Get frame height.
81 int height() const {return height_;}
82
83 // Set frame timestamp (90kHz).
84 void set_timestamp(const uint32_t timestamp) {timestamp_ = timestamp;}
85
86 // Get frame timestamp (90kHz).
87 uint32_t timestamp() const {return timestamp_;}
88
89 // Set render time in miliseconds.
90 void set_render_time_ms(int64_t render_time_ms) {render_time_ms_ =
91 render_time_ms;}
92
93 // Get render time in miliseconds.
94 int64_t render_time_ms() const {return render_time_ms_;}
95
mikhal@webrtc.orgdfc6b572012-10-15 16:12:09 +000096 // Return true if underlying plane buffers are of zero size, false if not.
mikhal@webrtc.org9fedff72012-10-24 18:33:04 +000097 bool IsZeroSize() const;
mikhal@webrtc.orgdfc6b572012-10-15 16:12:09 +000098
99 // Reset underlying plane buffers sizes to 0. This function doesn't
100 // clear memory.
101 void ResetSize();
102
mikhal@webrtc.org043ed9e2012-09-18 16:14:26 +0000103 private:
104 // Verifies legality of parameters.
105 // Return value: 0 on success ,-1 on error.
106 int CheckDimensions(int width, int height,
107 int stride_y, int stride_u, int stride_v);
108 // Get the pointer to a specific plane.
109 const Plane* GetPlane(PlaneType type) const;
mikhal@webrtc.org60ac6a62012-10-03 16:24:14 +0000110 // Overloading with non-const.
111 Plane* GetPlane(PlaneType type);
mikhal@webrtc.org043ed9e2012-09-18 16:14:26 +0000112
113 Plane y_plane_;
114 Plane u_plane_;
115 Plane v_plane_;
116 int width_;
117 int height_;
118 uint32_t timestamp_;
119 int64_t render_time_ms_;
120}; // I420VideoFrame
121
122} // namespace webrtc
123
124#endif // COMMON_VIDEO_INTERFACE_I420_VIDEO_FRAME_H
125