OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 24 matching lines...) Expand all Loading... |
35 | 35 |
36 // The resolution of the frame in pixels. For formats where some planes are | 36 // The resolution of the frame in pixels. For formats where some planes are |
37 // subsampled, this is the highest-resolution plane. | 37 // subsampled, this is the highest-resolution plane. |
38 virtual int width() const = 0; | 38 virtual int width() const = 0; |
39 virtual int height() const = 0; | 39 virtual int height() const = 0; |
40 | 40 |
41 // Returns pointer to the pixel data for a given plane. The memory is owned by | 41 // Returns pointer to the pixel data for a given plane. The memory is owned by |
42 // the VideoFrameBuffer object and must not be freed by the caller. | 42 // the VideoFrameBuffer object and must not be freed by the caller. |
43 virtual const uint8_t* data(PlaneType type) const = 0; | 43 virtual const uint8_t* data(PlaneType type) const = 0; |
44 | 44 |
45 // Non-const data access is only allowed if |HasOneRef| is true. | 45 // Non-const data access is disallowed by default. You need to make sure you |
46 virtual uint8_t* data(PlaneType type) = 0; | 46 // have exclusive access and a writable buffer before calling this function. |
| 47 virtual uint8_t* MutableData(PlaneType type); |
47 | 48 |
48 // Returns the number of bytes between successive rows for a given plane. | 49 // Returns the number of bytes between successive rows for a given plane. |
49 virtual int stride(PlaneType type) const = 0; | 50 virtual int stride(PlaneType type) const = 0; |
50 | 51 |
51 // Return the handle of the underlying video frame. This is used when the | 52 // Return the handle of the underlying video frame. This is used when the |
52 // frame is backed by a texture. | 53 // frame is backed by a texture. |
53 virtual void* native_handle() const = 0; | 54 virtual void* native_handle() const = 0; |
54 | 55 |
55 // Returns a new memory-backed frame buffer converted from this buffer's | 56 // Returns a new memory-backed frame buffer converted from this buffer's |
56 // native handle. | 57 // native handle. |
57 virtual rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() = 0; | 58 virtual rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() = 0; |
58 | 59 |
59 protected: | 60 protected: |
60 virtual ~VideoFrameBuffer(); | 61 virtual ~VideoFrameBuffer(); |
61 }; | 62 }; |
62 | 63 |
63 // Plain I420 buffer in standard memory. | 64 // Plain I420 buffer in standard memory. |
64 class I420Buffer : public VideoFrameBuffer { | 65 class I420Buffer : public VideoFrameBuffer { |
65 public: | 66 public: |
66 I420Buffer(int width, int height); | 67 I420Buffer(int width, int height); |
67 I420Buffer(int width, int height, int stride_y, int stride_u, int stride_v); | 68 I420Buffer(int width, int height, int stride_y, int stride_u, int stride_v); |
68 | 69 |
69 int width() const override; | 70 int width() const override; |
70 int height() const override; | 71 int height() const override; |
71 const uint8_t* data(PlaneType type) const override; | 72 const uint8_t* data(PlaneType type) const override; |
72 uint8_t* data(PlaneType type) override; | 73 // Non-const data access is only allowed if HasOneRef() is true to protect |
| 74 // against unexpected overwrites. |
| 75 uint8_t* MutableData(PlaneType type) override; |
73 int stride(PlaneType type) const override; | 76 int stride(PlaneType type) const override; |
74 void* native_handle() const override; | 77 void* native_handle() const override; |
75 rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override; | 78 rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override; |
76 | 79 |
77 protected: | 80 protected: |
78 ~I420Buffer() override; | 81 ~I420Buffer() override; |
79 | 82 |
80 private: | 83 private: |
81 const int width_; | 84 const int width_; |
82 const int height_; | 85 const int height_; |
83 const int stride_y_; | 86 const int stride_y_; |
84 const int stride_u_; | 87 const int stride_u_; |
85 const int stride_v_; | 88 const int stride_v_; |
86 const rtc::scoped_ptr<uint8_t, AlignedFreeDeleter> data_; | 89 const rtc::scoped_ptr<uint8_t, AlignedFreeDeleter> data_; |
87 }; | 90 }; |
88 | 91 |
89 // Base class for native-handle buffer is a wrapper around a |native_handle|. | 92 // Base class for native-handle buffer is a wrapper around a |native_handle|. |
90 // This is used for convenience as most native-handle implementations can share | 93 // This is used for convenience as most native-handle implementations can share |
91 // many VideoFrame implementations, but need to implement a few others (such | 94 // many VideoFrame implementations, but need to implement a few others (such |
92 // as their own destructors or conversion methods back to software I420). | 95 // as their own destructors or conversion methods back to software I420). |
93 class NativeHandleBuffer : public VideoFrameBuffer { | 96 class NativeHandleBuffer : public VideoFrameBuffer { |
94 public: | 97 public: |
95 NativeHandleBuffer(void* native_handle, int width, int height); | 98 NativeHandleBuffer(void* native_handle, int width, int height); |
96 | 99 |
97 int width() const override; | 100 int width() const override; |
98 int height() const override; | 101 int height() const override; |
99 const uint8_t* data(PlaneType type) const override; | 102 const uint8_t* data(PlaneType type) const override; |
100 uint8_t* data(PlaneType type) override; | |
101 int stride(PlaneType type) const override; | 103 int stride(PlaneType type) const override; |
102 void* native_handle() const override; | 104 void* native_handle() const override; |
103 | 105 |
104 protected: | 106 protected: |
105 void* native_handle_; | 107 void* native_handle_; |
106 const int width_; | 108 const int width_; |
107 const int height_; | 109 const int height_; |
108 }; | 110 }; |
109 | 111 |
110 class WrappedI420Buffer : public webrtc::VideoFrameBuffer { | 112 class WrappedI420Buffer : public webrtc::VideoFrameBuffer { |
111 public: | 113 public: |
112 WrappedI420Buffer(int width, | 114 WrappedI420Buffer(int width, |
113 int height, | 115 int height, |
114 const uint8_t* y_plane, | 116 const uint8_t* y_plane, |
115 int y_stride, | 117 int y_stride, |
116 const uint8_t* u_plane, | 118 const uint8_t* u_plane, |
117 int u_stride, | 119 int u_stride, |
118 const uint8_t* v_plane, | 120 const uint8_t* v_plane, |
119 int v_stride, | 121 int v_stride, |
120 const rtc::Callback0<void>& no_longer_used); | 122 const rtc::Callback0<void>& no_longer_used); |
121 int width() const override; | 123 int width() const override; |
122 int height() const override; | 124 int height() const override; |
123 | 125 |
124 const uint8_t* data(PlaneType type) const override; | 126 const uint8_t* data(PlaneType type) const override; |
125 uint8_t* data(PlaneType type) override; | |
126 | 127 |
127 int stride(PlaneType type) const override; | 128 int stride(PlaneType type) const override; |
128 void* native_handle() const override; | 129 void* native_handle() const override; |
129 | 130 |
130 rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override; | 131 rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override; |
131 | 132 |
132 private: | 133 private: |
133 friend class rtc::RefCountedObject<WrappedI420Buffer>; | 134 friend class rtc::RefCountedObject<WrappedI420Buffer>; |
134 ~WrappedI420Buffer() override; | 135 ~WrappedI420Buffer() override; |
135 | 136 |
(...skipping 11 matching lines...) Expand all Loading... |
147 // Helper function to crop |buffer| without making a deep copy. May only be used | 148 // Helper function to crop |buffer| without making a deep copy. May only be used |
148 // for non-native frames. | 149 // for non-native frames. |
149 rtc::scoped_refptr<VideoFrameBuffer> ShallowCenterCrop( | 150 rtc::scoped_refptr<VideoFrameBuffer> ShallowCenterCrop( |
150 const rtc::scoped_refptr<VideoFrameBuffer>& buffer, | 151 const rtc::scoped_refptr<VideoFrameBuffer>& buffer, |
151 int cropped_width, | 152 int cropped_width, |
152 int cropped_height); | 153 int cropped_height); |
153 | 154 |
154 } // namespace webrtc | 155 } // namespace webrtc |
155 | 156 |
156 #endif // WEBRTC_VIDEO_FRAME_BUFFER_H_ | 157 #endif // WEBRTC_VIDEO_FRAME_BUFFER_H_ |
OLD | NEW |