blob: 09ee9d0386c822fe069f5aea808294b9b9db0a10 [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
mikhal@webrtc.orge239bf02012-12-19 00:07:57 +000018#include "webrtc/common_video/plane.h"
19#include "webrtc/typedefs.h"
20
21/*
22 * I420VideoFrame includes support for a reference counted impl.
23 */
mikhal@webrtc.org043ed9e2012-09-18 16:14:26 +000024
25namespace webrtc {
26
27enum PlaneType {
28 kYPlane = 0,
29 kUPlane = 1,
mikhal@webrtc.org0e6f5972012-09-24 20:35:40 +000030 kVPlane = 2,
mikhal@webrtc.org9fedff72012-10-24 18:33:04 +000031 kNumOfPlanes = 3
mikhal@webrtc.org043ed9e2012-09-18 16:14:26 +000032};
33
34class I420VideoFrame {
35 public:
36 I420VideoFrame();
mikhal@webrtc.orge239bf02012-12-19 00:07:57 +000037 virtual ~I420VideoFrame();
38 // Infrastructure for refCount implementation.
39 // Implements dummy functions for reference counting so that non reference
40 // counted instantiation can be done. These functions should not be called
41 // when creating the frame with new I420VideoFrame().
42 // Note: do not pass a I420VideoFrame created with new I420VideoFrame() or
43 // equivalent to a scoped_refptr or memory leak will occur.
44 virtual int32_t AddRef() {assert(false); return -1;}
45 virtual int32_t Release() {assert(false); return -1;}
mikhal@webrtc.org043ed9e2012-09-18 16:14:26 +000046
47 // CreateEmptyFrame: Sets frame dimensions and allocates buffers based
48 // on set dimensions - height and plane stride.
49 // If required size is bigger than the allocated one, new buffers of adequate
50 // size will be allocated.
51 // Return value: 0 on success ,-1 on error.
52 int CreateEmptyFrame(int width, int height,
53 int stride_y, int stride_u, int stride_v);
54
55 // CreateFrame: Sets the frame's members and buffers. If required size is
56 // bigger than allocated one, new buffers of adequate size will be allocated.
57 // Return value: 0 on success ,-1 on error.
mikhal@webrtc.org60ac6a62012-10-03 16:24:14 +000058 int CreateFrame(int size_y, const uint8_t* buffer_y,
59 int size_u, const uint8_t* buffer_u,
60 int size_v, const uint8_t* buffer_v,
mikhal@webrtc.org043ed9e2012-09-18 16:14:26 +000061 int width, int height,
62 int stride_y, int stride_u, int stride_v);
63
64 // Copy frame: If required size is bigger than allocated one, new buffers of
65 // adequate size will be allocated.
66 // Return value: 0 on success ,-1 on error.
67 int CopyFrame(const I420VideoFrame& videoFrame);
68
69 // Swap Frame.
70 void SwapFrame(I420VideoFrame* videoFrame);
71
72 // Get pointer to buffer per plane.
mikhal@webrtc.org60ac6a62012-10-03 16:24:14 +000073 uint8_t* buffer(PlaneType type);
74 // Overloading with const.
mikhal@webrtc.org043ed9e2012-09-18 16:14:26 +000075 const uint8_t* buffer(PlaneType type) const;
76
77 // Get allocated size per plane.
mikhal@webrtc.orgdfc6b572012-10-15 16:12:09 +000078 int allocated_size(PlaneType type) const;
mikhal@webrtc.org043ed9e2012-09-18 16:14:26 +000079
80 // Get allocated stride per plane.
81 int stride(PlaneType type) const;
82
83 // Set frame width.
84 int set_width(int width);
85
86 // Set frame height.
87 int set_height(int height);
88
89 // Get frame width.
90 int width() const {return width_;}
91
92 // Get frame height.
93 int height() const {return height_;}
94
95 // Set frame timestamp (90kHz).
96 void set_timestamp(const uint32_t timestamp) {timestamp_ = timestamp;}
97
98 // Get frame timestamp (90kHz).
99 uint32_t timestamp() const {return timestamp_;}
100
101 // Set render time in miliseconds.
102 void set_render_time_ms(int64_t render_time_ms) {render_time_ms_ =
103 render_time_ms;}
104
105 // Get render time in miliseconds.
106 int64_t render_time_ms() const {return render_time_ms_;}
107
mikhal@webrtc.orgdfc6b572012-10-15 16:12:09 +0000108 // Return true if underlying plane buffers are of zero size, false if not.
mikhal@webrtc.org9fedff72012-10-24 18:33:04 +0000109 bool IsZeroSize() const;
mikhal@webrtc.orgdfc6b572012-10-15 16:12:09 +0000110
111 // Reset underlying plane buffers sizes to 0. This function doesn't
112 // clear memory.
113 void ResetSize();
114
mikhal@webrtc.org043ed9e2012-09-18 16:14:26 +0000115 private:
116 // Verifies legality of parameters.
117 // Return value: 0 on success ,-1 on error.
118 int CheckDimensions(int width, int height,
119 int stride_y, int stride_u, int stride_v);
120 // Get the pointer to a specific plane.
121 const Plane* GetPlane(PlaneType type) const;
mikhal@webrtc.org60ac6a62012-10-03 16:24:14 +0000122 // Overloading with non-const.
123 Plane* GetPlane(PlaneType type);
mikhal@webrtc.org043ed9e2012-09-18 16:14:26 +0000124
125 Plane y_plane_;
126 Plane u_plane_;
127 Plane v_plane_;
128 int width_;
129 int height_;
130 uint32_t timestamp_;
131 int64_t render_time_ms_;
132}; // I420VideoFrame
133
134} // namespace webrtc
135
136#endif // COMMON_VIDEO_INTERFACE_I420_VIDEO_FRAME_H
137