blob: 4031e03b4cea4b51eb1a6f0b64ddd828dda1510b [file] [log] [blame]
mikhal@webrtc.org043ed9e2012-09-18 16:14:26 +00001/*
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.orgc69ae692013-06-04 09:02:37 +000014#include "webrtc/system_wrappers/interface/aligned_malloc.h"
andrew@webrtc.orgd617a442014-02-20 21:08:36 +000015#include "webrtc/system_wrappers/interface/scoped_ptr.h"
pbos@webrtc.orgc69ae692013-06-04 09:02:37 +000016#include "webrtc/typedefs.h"
mikhal@webrtc.org043ed9e2012-09-18 16:14:26 +000017
18namespace webrtc {
19
20// Helper class for I420VideoFrame: Store plane data and perform basic plane
21// operations.
22class 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.org5dd2ecb2013-10-31 23:41:04 +000029 // Return value: 0 on success ,-1 on error.
sheu@chromium.orgd7056492013-10-31 21:20:15 +000030 int CreateEmptyPlane(int allocated_size, int stride, int plane_size);
mikhal@webrtc.org043ed9e2012-09-18 16:14:26 +000031
32 // Copy the entire plane data.
sheu@chromium.org5dd2ecb2013-10-31 23:41:04 +000033 // Return value: 0 on success ,-1 on error.
mikhal@webrtc.org043ed9e2012-09-18 16:14:26 +000034 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.org5dd2ecb2013-10-31 23:41:04 +000038 // Return value: 0 on success ,-1 on error.
sheu@chromium.orgd7056492013-10-31 21:20:15 +000039 int Copy(int size, int stride, const uint8_t* buffer);
mikhal@webrtc.org043ed9e2012-09-18 16:14:26 +000040
41 // Swap plane data.
42 void Swap(Plane& plane);
43
44 // Get allocated size.
sheu@chromium.org5dd2ecb2013-10-31 23:41:04 +000045 int allocated_size() const {return allocated_size_;}
mikhal@webrtc.org043ed9e2012-09-18 16:14:26 +000046
mikhal@webrtc.orgdfc6b572012-10-15 16:12:09 +000047 // Set actual size.
mikhal@webrtc.org9fedff72012-10-24 18:33:04 +000048 void ResetSize() {plane_size_ = 0;}
mikhal@webrtc.orgdfc6b572012-10-15 16:12:09 +000049
50 // Return true is plane size is zero, false if not.
mikhal@webrtc.org9fedff72012-10-24 18:33:04 +000051 bool IsZeroSize() const {return plane_size_ == 0;}
mikhal@webrtc.orgdfc6b572012-10-15 16:12:09 +000052
mikhal@webrtc.org043ed9e2012-09-18 16:14:26 +000053 // Get stride value.
sheu@chromium.org5dd2ecb2013-10-31 23:41:04 +000054 int stride() const {return stride_;}
mikhal@webrtc.org043ed9e2012-09-18 16:14:26 +000055
56 // Return data pointer.
sheu@chromium.org5dd2ecb2013-10-31 23:41:04 +000057 const uint8_t* buffer() const {return buffer_.get();}
mikhal@webrtc.org60ac6a62012-10-03 16:24:14 +000058 // Overloading with non-const.
sheu@chromium.org5dd2ecb2013-10-31 23:41:04 +000059 uint8_t* buffer() {return buffer_.get();}
mikhal@webrtc.org043ed9e2012-09-18 16:14:26 +000060
61 private:
sheu@chromium.org5dd2ecb2013-10-31 23:41:04 +000062 // 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.org043ed9e2012-09-18 16:14:26 +000066
andrew@webrtc.orgd617a442014-02-20 21:08:36 +000067 scoped_ptr<uint8_t, AlignedFreeDeleter> buffer_;
sheu@chromium.orgd7056492013-10-31 21:20:15 +000068 int allocated_size_;
69 int plane_size_;
70 int stride_;
mikhal@webrtc.org043ed9e2012-09-18 16:14:26 +000071}; // Plane
72
73} // namespace webrtc
74
75#endif // COMMON_VIDEO_PLANE_H