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