blob: 1b74f37ec05e2a40e77970aa183e3a19c74123be [file] [log] [blame]
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +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.org026d1ce2013-06-04 09:02:37 +000014#include "webrtc/system_wrappers/interface/aligned_malloc.h"
15#include "webrtc/typedefs.h"
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000016
17namespace webrtc {
18
19// Helper class for I420VideoFrame: Store plane data and perform basic plane
20// operations.
21class 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.orgaf92d3e2013-10-31 23:41:04 +000028 // Return value: 0 on success ,-1 on error.
sheu@chromium.org6baaf302013-10-31 21:20:15 +000029 int CreateEmptyPlane(int allocated_size, int stride, int plane_size);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000030
31 // Copy the entire plane data.
sheu@chromium.orgaf92d3e2013-10-31 23:41:04 +000032 // Return value: 0 on success ,-1 on error.
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000033 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.orgaf92d3e2013-10-31 23:41:04 +000037 // Return value: 0 on success ,-1 on error.
sheu@chromium.org6baaf302013-10-31 21:20:15 +000038 int Copy(int size, int stride, const uint8_t* buffer);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000039
40 // Swap plane data.
41 void Swap(Plane& plane);
42
43 // Get allocated size.
sheu@chromium.orgaf92d3e2013-10-31 23:41:04 +000044 int allocated_size() const {return allocated_size_;}
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000045
46 // Set actual size.
mikhal@webrtc.org3bbed742012-10-24 18:33:04 +000047 void ResetSize() {plane_size_ = 0;}
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000048
49 // Return true is plane size is zero, false if not.
mikhal@webrtc.org3bbed742012-10-24 18:33:04 +000050 bool IsZeroSize() const {return plane_size_ == 0;}
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000051
52 // Get stride value.
sheu@chromium.orgaf92d3e2013-10-31 23:41:04 +000053 int stride() const {return stride_;}
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000054
55 // Return data pointer.
sheu@chromium.orgaf92d3e2013-10-31 23:41:04 +000056 const uint8_t* buffer() const {return buffer_.get();}
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000057 // Overloading with non-const.
sheu@chromium.orgaf92d3e2013-10-31 23:41:04 +000058 uint8_t* buffer() {return buffer_.get();}
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000059
60 private:
sheu@chromium.orgaf92d3e2013-10-31 23:41:04 +000061 // 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.orgb015cbe2012-10-22 18:19:23 +000065
sheu@chromium.orgaf92d3e2013-10-31 23:41:04 +000066 Allocator<uint8_t>::scoped_ptr_aligned buffer_;
sheu@chromium.org6baaf302013-10-31 21:20:15 +000067 int allocated_size_;
68 int plane_size_;
69 int stride_;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000070}; // Plane
71
72} // namespace webrtc
73
74#endif // COMMON_VIDEO_PLANE_H