andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +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_PLANE_H |
| 12 | #define COMMON_VIDEO_PLANE_H |
| 13 | |
pbos@webrtc.org | 026d1ce | 2013-06-04 09:02:37 +0000 | [diff] [blame] | 14 | #include "webrtc/system_wrappers/interface/aligned_malloc.h" |
| 15 | #include "webrtc/typedefs.h" |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 16 | |
| 17 | namespace webrtc { |
| 18 | |
| 19 | // Helper class for I420VideoFrame: Store plane data and perform basic plane |
| 20 | // operations. |
| 21 | class Plane { |
| 22 | public: |
| 23 | Plane(); |
| 24 | ~Plane(); |
| 25 | // CreateEmptyPlane - set allocated size, actual plane size and stride: |
| 26 | // If current size is smaller than current size, then a buffer of sufficient |
| 27 | // size will be allocated. |
sheu@chromium.org | af92d3e | 2013-10-31 23:41:04 +0000 | [diff] [blame] | 28 | // Return value: 0 on success ,-1 on error. |
sheu@chromium.org | 6baaf30 | 2013-10-31 21:20:15 +0000 | [diff] [blame] | 29 | int CreateEmptyPlane(int allocated_size, int stride, int plane_size); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 30 | |
| 31 | // Copy the entire plane data. |
sheu@chromium.org | af92d3e | 2013-10-31 23:41:04 +0000 | [diff] [blame] | 32 | // Return value: 0 on success ,-1 on error. |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 33 | int Copy(const Plane& plane); |
| 34 | |
| 35 | // Copy buffer: If current size is smaller |
| 36 | // than current size, then a buffer of sufficient size will be allocated. |
sheu@chromium.org | af92d3e | 2013-10-31 23:41:04 +0000 | [diff] [blame] | 37 | // Return value: 0 on success ,-1 on error. |
sheu@chromium.org | 6baaf30 | 2013-10-31 21:20:15 +0000 | [diff] [blame] | 38 | int Copy(int size, int stride, const uint8_t* buffer); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 39 | |
| 40 | // Swap plane data. |
| 41 | void Swap(Plane& plane); |
| 42 | |
| 43 | // Get allocated size. |
sheu@chromium.org | af92d3e | 2013-10-31 23:41:04 +0000 | [diff] [blame] | 44 | int allocated_size() const {return allocated_size_;} |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 45 | |
| 46 | // Set actual size. |
mikhal@webrtc.org | 3bbed74 | 2012-10-24 18:33:04 +0000 | [diff] [blame] | 47 | void ResetSize() {plane_size_ = 0;} |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 48 | |
| 49 | // Return true is plane size is zero, false if not. |
mikhal@webrtc.org | 3bbed74 | 2012-10-24 18:33:04 +0000 | [diff] [blame] | 50 | bool IsZeroSize() const {return plane_size_ == 0;} |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 51 | |
| 52 | // Get stride value. |
sheu@chromium.org | af92d3e | 2013-10-31 23:41:04 +0000 | [diff] [blame] | 53 | int stride() const {return stride_;} |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 54 | |
| 55 | // Return data pointer. |
sheu@chromium.org | af92d3e | 2013-10-31 23:41:04 +0000 | [diff] [blame] | 56 | const uint8_t* buffer() const {return buffer_.get();} |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 57 | // Overloading with non-const. |
sheu@chromium.org | af92d3e | 2013-10-31 23:41:04 +0000 | [diff] [blame] | 58 | uint8_t* buffer() {return buffer_.get();} |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 59 | |
| 60 | private: |
sheu@chromium.org | af92d3e | 2013-10-31 23:41:04 +0000 | [diff] [blame] | 61 | // Resize when needed: If current allocated size is less than new_size, buffer |
| 62 | // will be updated. Old data will be copied to new buffer. |
| 63 | // Return value: 0 on success ,-1 on error. |
| 64 | int MaybeResize(int new_size); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 65 | |
sheu@chromium.org | af92d3e | 2013-10-31 23:41:04 +0000 | [diff] [blame] | 66 | Allocator<uint8_t>::scoped_ptr_aligned buffer_; |
sheu@chromium.org | 6baaf30 | 2013-10-31 21:20:15 +0000 | [diff] [blame] | 67 | int allocated_size_; |
| 68 | int plane_size_; |
| 69 | int stride_; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 70 | }; // Plane |
| 71 | |
| 72 | } // namespace webrtc |
| 73 | |
| 74 | #endif // COMMON_VIDEO_PLANE_H |