- add third_party src.
[platform/framework/web/crosswalk.git] / src / third_party / webrtc / common_video / interface / i420_video_frame.h
1 /*
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 "webrtc/common_video/plane.h"
19 #include "webrtc/system_wrappers/interface/scoped_refptr.h"
20 #include "webrtc/typedefs.h"
21
22 /*
23  *  I420VideoFrame includes support for a reference counted impl.
24  */
25
26 namespace webrtc {
27
28 enum PlaneType {
29   kYPlane = 0,
30   kUPlane = 1,
31   kVPlane = 2,
32   kNumOfPlanes = 3
33 };
34
35 class I420VideoFrame {
36  public:
37   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;}
47
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);
55
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);
64
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);
69
70   // Swap Frame.
71   virtual void SwapFrame(I420VideoFrame* videoFrame);
72
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;
77
78   // Get allocated size per plane.
79   virtual int allocated_size(PlaneType type) const;
80
81   // Get allocated stride per plane.
82   virtual int stride(PlaneType type) const;
83
84   // Set frame width.
85   virtual int set_width(int width);
86
87   // Set frame height.
88   virtual int set_height(int height);
89
90   // Get frame width.
91   virtual int width() const {return width_;}
92
93   // Get frame height.
94   virtual int height() const {return height_;}
95
96   // Set frame timestamp (90kHz).
97   virtual void set_timestamp(uint32_t timestamp) {timestamp_ = timestamp;}
98
99   // Get frame timestamp (90kHz).
100   virtual uint32_t timestamp() const {return timestamp_;}
101
102   // Set render time in miliseconds.
103   virtual void set_render_time_ms(int64_t render_time_ms) {render_time_ms_ =
104                                                    render_time_ms;}
105
106   // Get render time in miliseconds.
107   virtual int64_t render_time_ms() const {return render_time_ms_;}
108
109   // Return true if underlying plane buffers are of zero size, false if not.
110   virtual bool IsZeroSize() const;
111
112   // Reset underlying plane buffers sizes to 0. This function doesn't
113   // clear memory.
114   virtual void ResetSize();
115
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;
120
121  protected:
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);
126
127  private:
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);
132
133   Plane y_plane_;
134   Plane u_plane_;
135   Plane v_plane_;
136   int width_;
137   int height_;
138   uint32_t timestamp_;
139   int64_t render_time_ms_;
140 };  // I420VideoFrame
141
142 }  // namespace webrtc
143
144 #endif  // COMMON_VIDEO_INTERFACE_I420_VIDEO_FRAME_H