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