2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
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.
11 #ifndef COMMON_VIDEO_INTERFACE_I420_VIDEO_FRAME_H
12 #define COMMON_VIDEO_INTERFACE_I420_VIDEO_FRAME_H
14 // I420VideoFrame class
16 // Storing and handling of YUV (I420) video frames.
18 #include "webrtc/common_video/plane.h"
19 #include "webrtc/system_wrappers/interface/scoped_refptr.h"
20 #include "webrtc/typedefs.h"
23 * I420VideoFrame includes support for a reference counted impl.
35 class I420VideoFrame {
38 virtual ~I420VideoFrame();
39 // Infrastructure for refCount implementation.
40 // Implements dummy functions for reference counting so that non reference
41 // counted instantiation can be done. These functions should not be called
42 // when creating the frame with new I420VideoFrame().
43 // Note: do not pass a I420VideoFrame created with new I420VideoFrame() or
44 // equivalent to a scoped_refptr or memory leak will occur.
45 virtual int32_t AddRef() {assert(false); return -1;}
46 virtual int32_t Release() {assert(false); return -1;}
48 // CreateEmptyFrame: Sets frame dimensions and allocates buffers based
49 // on set dimensions - height and plane stride.
50 // If required size is bigger than the allocated one, new buffers of adequate
51 // size will be allocated.
52 // Return value: 0 on success ,-1 on error.
53 virtual int CreateEmptyFrame(int width, int height,
54 int stride_y, int stride_u, int stride_v);
56 // CreateFrame: Sets the frame's members and buffers. If required size is
57 // bigger than allocated one, new buffers of adequate size will be allocated.
58 // Return value: 0 on success ,-1 on error.
59 virtual int CreateFrame(int size_y, const uint8_t* buffer_y,
60 int size_u, const uint8_t* buffer_u,
61 int size_v, const uint8_t* buffer_v,
62 int width, int height,
63 int stride_y, int stride_u, int stride_v);
65 // Copy frame: If required size is bigger than allocated one, new buffers of
66 // adequate size will be allocated.
67 // Return value: 0 on success ,-1 on error.
68 virtual int CopyFrame(const I420VideoFrame& videoFrame);
71 virtual void SwapFrame(I420VideoFrame* videoFrame);
73 // Get pointer to buffer per plane.
74 virtual uint8_t* buffer(PlaneType type);
75 // Overloading with const.
76 virtual const uint8_t* buffer(PlaneType type) const;
78 // Get allocated size per plane.
79 virtual int allocated_size(PlaneType type) const;
81 // Get allocated stride per plane.
82 virtual int stride(PlaneType type) const;
85 virtual int set_width(int width);
88 virtual int set_height(int height);
91 virtual int width() const {return width_;}
94 virtual int height() const {return height_;}
96 // Set frame timestamp (90kHz).
97 virtual void set_timestamp(uint32_t timestamp) {timestamp_ = timestamp;}
99 // Get frame timestamp (90kHz).
100 virtual uint32_t timestamp() const {return timestamp_;}
102 // Set render time in miliseconds.
103 virtual void set_render_time_ms(int64_t render_time_ms) {render_time_ms_ =
106 // Get render time in miliseconds.
107 virtual int64_t render_time_ms() const {return render_time_ms_;}
109 // Return true if underlying plane buffers are of zero size, false if not.
110 virtual bool IsZeroSize() const;
112 // Reset underlying plane buffers sizes to 0. This function doesn't
114 virtual void ResetSize();
116 // Return the handle of the underlying video frame. This is used when the
117 // frame is backed by a texture. The object should be destroyed when it is no
118 // longer in use, so the underlying resource can be freed.
119 virtual void* native_handle() const;
122 // Verifies legality of parameters.
123 // Return value: 0 on success, -1 on error.
124 virtual int CheckDimensions(int width, int height,
125 int stride_y, int stride_u, int stride_v);
128 // Get the pointer to a specific plane.
129 const Plane* GetPlane(PlaneType type) const;
130 // Overloading with non-const.
131 Plane* GetPlane(PlaneType type);
139 int64_t render_time_ms_;
142 } // namespace webrtc
144 #endif // COMMON_VIDEO_INTERFACE_I420_VIDEO_FRAME_H