blob: c6743398d8ea22854cbe230ff4edffad5b4b6486 [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
14#include "system_wrappers/interface/aligned_malloc.h"
15#include "typedefs.h" //NOLINT
16
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.
28 // Return value: 0 on success ,-1 on error.
29 int CreateEmptyPlane(int allocated_size, int stride, int plane_size);
30
31 // Copy the entire plane data.
32 // Return value: 0 on success ,-1 on error.
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.
37 // Return value: 0 on success ,-1 on error.
38 int Copy(int size, int stride, const uint8_t* buffer);
39
40 // Swap plane data.
41 void Swap(Plane& plane);
42
43 // Get allocated size.
44 int allocated_size() const {return allocated_size_;}
45
46 // Set actual size.
47 void ResetSize() {plane_size_ = 0;};
48
49 // Return true is plane size is zero, false if not.
50 bool IsZeroSize() {return plane_size_ == 0;};
51
52 // Get stride value.
53 int stride() const {return stride_;}
54
55 // Return data pointer.
56 const uint8_t* buffer() const {return buffer_.get();}
57 // Overloading with non-const.
58 uint8_t* buffer() {return buffer_.get();}
59
60 private:
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);
65
66 Allocator<uint8_t>::scoped_ptr_aligned buffer_;
67 int allocated_size_;
68 int plane_size_;
69 int stride_;
70}; // Plane
71
72} // namespace webrtc
73
74#endif // COMMON_VIDEO_PLANE_H