mikhal@webrtc.org | 043ed9e | 2012-09-18 16:14:26 +0000 | [diff] [blame] | 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 | |
mikhal@webrtc.org | e239bf0 | 2012-12-19 00:07:57 +0000 | [diff] [blame^] | 18 | #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.org | 043ed9e | 2012-09-18 16:14:26 +0000 | [diff] [blame] | 24 | |
| 25 | namespace webrtc { |
| 26 | |
| 27 | enum PlaneType { |
| 28 | kYPlane = 0, |
| 29 | kUPlane = 1, |
mikhal@webrtc.org | 0e6f597 | 2012-09-24 20:35:40 +0000 | [diff] [blame] | 30 | kVPlane = 2, |
mikhal@webrtc.org | 9fedff7 | 2012-10-24 18:33:04 +0000 | [diff] [blame] | 31 | kNumOfPlanes = 3 |
mikhal@webrtc.org | 043ed9e | 2012-09-18 16:14:26 +0000 | [diff] [blame] | 32 | }; |
| 33 | |
| 34 | class I420VideoFrame { |
| 35 | public: |
| 36 | I420VideoFrame(); |
mikhal@webrtc.org | e239bf0 | 2012-12-19 00:07:57 +0000 | [diff] [blame^] | 37 | 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.org | 043ed9e | 2012-09-18 16:14:26 +0000 | [diff] [blame] | 46 | |
| 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.org | 60ac6a6 | 2012-10-03 16:24:14 +0000 | [diff] [blame] | 58 | 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.org | 043ed9e | 2012-09-18 16:14:26 +0000 | [diff] [blame] | 61 | 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.org | 60ac6a6 | 2012-10-03 16:24:14 +0000 | [diff] [blame] | 73 | uint8_t* buffer(PlaneType type); |
| 74 | // Overloading with const. |
mikhal@webrtc.org | 043ed9e | 2012-09-18 16:14:26 +0000 | [diff] [blame] | 75 | const uint8_t* buffer(PlaneType type) const; |
| 76 | |
| 77 | // Get allocated size per plane. |
mikhal@webrtc.org | dfc6b57 | 2012-10-15 16:12:09 +0000 | [diff] [blame] | 78 | int allocated_size(PlaneType type) const; |
mikhal@webrtc.org | 043ed9e | 2012-09-18 16:14:26 +0000 | [diff] [blame] | 79 | |
| 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.org | dfc6b57 | 2012-10-15 16:12:09 +0000 | [diff] [blame] | 108 | // Return true if underlying plane buffers are of zero size, false if not. |
mikhal@webrtc.org | 9fedff7 | 2012-10-24 18:33:04 +0000 | [diff] [blame] | 109 | bool IsZeroSize() const; |
mikhal@webrtc.org | dfc6b57 | 2012-10-15 16:12:09 +0000 | [diff] [blame] | 110 | |
| 111 | // Reset underlying plane buffers sizes to 0. This function doesn't |
| 112 | // clear memory. |
| 113 | void ResetSize(); |
| 114 | |
mikhal@webrtc.org | 043ed9e | 2012-09-18 16:14:26 +0000 | [diff] [blame] | 115 | 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.org | 60ac6a6 | 2012-10-03 16:24:14 +0000 | [diff] [blame] | 122 | // Overloading with non-const. |
| 123 | Plane* GetPlane(PlaneType type); |
mikhal@webrtc.org | 043ed9e | 2012-09-18 16:14:26 +0000 | [diff] [blame] | 124 | |
| 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 | |