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 25 matching lines...) Expand all Loading... | |
36 // Returns true if this buffer has a single exclusive owner. | 36 // Returns true if this buffer has a single exclusive owner. |
37 virtual bool HasOneRef() const = 0; | 37 virtual bool HasOneRef() const = 0; |
38 | 38 |
39 // The resolution of the frame in pixels. For formats where some planes are | 39 // The resolution of the frame in pixels. For formats where some planes are |
40 // subsampled, this is the highest-resolution plane. | 40 // subsampled, this is the highest-resolution plane. |
41 virtual int width() const = 0; | 41 virtual int width() const = 0; |
42 virtual int height() const = 0; | 42 virtual int height() const = 0; |
43 | 43 |
44 // Returns pointer to the pixel data for a given plane. The memory is owned by | 44 // Returns pointer to the pixel data for a given plane. The memory is owned by |
45 // the VideoFrameBuffer object and must not be freed by the caller. | 45 // the VideoFrameBuffer object and must not be freed by the caller. |
46 virtual const uint8_t* data(PlaneType type) const = 0; | 46 virtual const uint8_t* DataY() const = 0; |
47 virtual const uint8_t* DataU() const = 0; | |
48 virtual const uint8_t* DataV() const = 0; | |
49 // Deprecated method. Use virtual final, to ensure we get warnings | |
pbos-webrtc
2016/04/14 13:06:39
Should this use RTC_DEPRECATED instead? (webrtc/ba
nisse-webrtc
2016/04/14 14:08:47
That will break Chrome, if it uses them. So I thin
| |
50 // if any subclass tries to override it. cpplint thinks virtual is | |
51 // redundant, but it isn't, since this is the base class. Hence the | |
52 // use of NOLINT. | |
53 // TODO(nisse): Delete after all users are updated. | |
54 virtual const uint8_t* data(PlaneType type) const final; // NOLINT | |
47 | 55 |
48 // Non-const data access is disallowed by default. You need to make sure you | 56 // Non-const data access is allowed only if HasOneRef() is true. |
49 // have exclusive access and a writable buffer before calling this function. | 57 virtual uint8_t* MutableDataY(); |
50 virtual uint8_t* MutableData(PlaneType type); | 58 virtual uint8_t* MutableDataU(); |
59 virtual uint8_t* MutableDataV(); | |
60 // Deprecated method. TODO(nisse): Delete after all users are updated. | |
61 virtual uint8_t* MutableData(PlaneType type) final; // NOLINT | |
51 | 62 |
52 // Returns the number of bytes between successive rows for a given plane. | 63 // Returns the number of bytes between successive rows for a given plane. |
53 virtual int stride(PlaneType type) const = 0; | 64 virtual int StrideY() const = 0; |
65 virtual int StrideU() const = 0; | |
66 virtual int StrideV() const = 0; | |
67 // Deprecated method. TODO(nisse): Delete after all users are updated. | |
68 virtual int stride(PlaneType type) const final; // NOLINT | |
54 | 69 |
55 // Return the handle of the underlying video frame. This is used when the | 70 // Return the handle of the underlying video frame. This is used when the |
56 // frame is backed by a texture. | 71 // frame is backed by a texture. |
57 virtual void* native_handle() const = 0; | 72 virtual void* native_handle() const = 0; |
58 | 73 |
59 // Returns a new memory-backed frame buffer converted from this buffer's | 74 // Returns a new memory-backed frame buffer converted from this buffer's |
60 // native handle. | 75 // native handle. |
61 virtual rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() = 0; | 76 virtual rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() = 0; |
62 | 77 |
63 protected: | 78 protected: |
64 virtual ~VideoFrameBuffer(); | 79 virtual ~VideoFrameBuffer(); |
65 }; | 80 }; |
66 | 81 |
67 // Plain I420 buffer in standard memory. | 82 // Plain I420 buffer in standard memory. |
68 class I420Buffer : public VideoFrameBuffer { | 83 class I420Buffer : public VideoFrameBuffer { |
69 public: | 84 public: |
70 I420Buffer(int width, int height); | 85 I420Buffer(int width, int height); |
71 I420Buffer(int width, int height, int stride_y, int stride_u, int stride_v); | 86 I420Buffer(int width, int height, int stride_y, int stride_u, int stride_v); |
72 void InitializeData(); | 87 void InitializeData(); |
73 | 88 |
74 int width() const override; | 89 int width() const override; |
75 int height() const override; | 90 int height() const override; |
76 const uint8_t* data(PlaneType type) const override; | 91 const uint8_t* DataY() const override; |
92 const uint8_t* DataU() const override; | |
93 const uint8_t* DataV() const override; | |
77 // Non-const data access is only allowed if HasOneRef() is true to protect | 94 // Non-const data access is only allowed if HasOneRef() is true to protect |
78 // against unexpected overwrites. | 95 // against unexpected overwrites. |
79 uint8_t* MutableData(PlaneType type) override; | 96 uint8_t* MutableDataY() override; |
80 int stride(PlaneType type) const override; | 97 uint8_t* MutableDataU() override; |
98 uint8_t* MutableDataV() override; | |
99 int StrideY() const override; | |
100 int StrideU() const override; | |
101 int StrideV() const override; | |
102 | |
81 void* native_handle() const override; | 103 void* native_handle() const override; |
82 rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override; | 104 rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override; |
83 | 105 |
84 // Create a new buffer and copy the pixel data. | 106 // Create a new buffer and copy the pixel data. |
85 static rtc::scoped_refptr<I420Buffer> Copy( | 107 static rtc::scoped_refptr<I420Buffer> Copy( |
86 const rtc::scoped_refptr<VideoFrameBuffer>& buffer); | 108 const rtc::scoped_refptr<VideoFrameBuffer>& buffer); |
87 | 109 |
88 protected: | 110 protected: |
89 ~I420Buffer() override; | 111 ~I420Buffer() override; |
90 | 112 |
91 private: | 113 private: |
92 const int width_; | 114 const int width_; |
93 const int height_; | 115 const int height_; |
94 const int stride_y_; | 116 const int stride_y_; |
95 const int stride_u_; | 117 const int stride_u_; |
96 const int stride_v_; | 118 const int stride_v_; |
97 const std::unique_ptr<uint8_t, AlignedFreeDeleter> data_; | 119 const std::unique_ptr<uint8_t, AlignedFreeDeleter> data_; |
98 }; | 120 }; |
99 | 121 |
100 // Base class for native-handle buffer is a wrapper around a |native_handle|. | 122 // Base class for native-handle buffer is a wrapper around a |native_handle|. |
101 // This is used for convenience as most native-handle implementations can share | 123 // This is used for convenience as most native-handle implementations can share |
102 // many VideoFrame implementations, but need to implement a few others (such | 124 // many VideoFrame implementations, but need to implement a few others (such |
103 // as their own destructors or conversion methods back to software I420). | 125 // as their own destructors or conversion methods back to software I420). |
104 class NativeHandleBuffer : public VideoFrameBuffer { | 126 class NativeHandleBuffer : public VideoFrameBuffer { |
105 public: | 127 public: |
106 NativeHandleBuffer(void* native_handle, int width, int height); | 128 NativeHandleBuffer(void* native_handle, int width, int height); |
107 | 129 |
108 int width() const override; | 130 int width() const override; |
109 int height() const override; | 131 int height() const override; |
110 const uint8_t* data(PlaneType type) const override; | 132 const uint8_t* DataY() const override; |
111 int stride(PlaneType type) const override; | 133 const uint8_t* DataU() const override; |
134 const uint8_t* DataV() const override; | |
135 int StrideY() const override; | |
136 int StrideU() const override; | |
137 int StrideV() const override; | |
138 | |
112 void* native_handle() const override; | 139 void* native_handle() const override; |
113 | 140 |
114 protected: | 141 protected: |
115 void* native_handle_; | 142 void* native_handle_; |
116 const int width_; | 143 const int width_; |
117 const int height_; | 144 const int height_; |
118 }; | 145 }; |
119 | 146 |
120 class WrappedI420Buffer : public webrtc::VideoFrameBuffer { | 147 class WrappedI420Buffer : public webrtc::VideoFrameBuffer { |
121 public: | 148 public: |
122 WrappedI420Buffer(int width, | 149 WrappedI420Buffer(int width, |
123 int height, | 150 int height, |
124 const uint8_t* y_plane, | 151 const uint8_t* y_plane, |
125 int y_stride, | 152 int y_stride, |
126 const uint8_t* u_plane, | 153 const uint8_t* u_plane, |
127 int u_stride, | 154 int u_stride, |
128 const uint8_t* v_plane, | 155 const uint8_t* v_plane, |
129 int v_stride, | 156 int v_stride, |
130 const rtc::Callback0<void>& no_longer_used); | 157 const rtc::Callback0<void>& no_longer_used); |
131 int width() const override; | 158 int width() const override; |
132 int height() const override; | 159 int height() const override; |
133 | 160 |
134 const uint8_t* data(PlaneType type) const override; | 161 const uint8_t* DataY() const override; |
162 const uint8_t* DataU() const override; | |
163 const uint8_t* DataV() const override; | |
164 int StrideY() const override; | |
165 int StrideU() const override; | |
166 int StrideV() const override; | |
135 | 167 |
136 int stride(PlaneType type) const override; | |
137 void* native_handle() const override; | 168 void* native_handle() const override; |
138 | 169 |
139 rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override; | 170 rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override; |
140 | 171 |
141 private: | 172 private: |
142 friend class rtc::RefCountedObject<WrappedI420Buffer>; | 173 friend class rtc::RefCountedObject<WrappedI420Buffer>; |
143 ~WrappedI420Buffer() override; | 174 ~WrappedI420Buffer() override; |
144 | 175 |
145 const int width_; | 176 const int width_; |
146 const int height_; | 177 const int height_; |
147 const uint8_t* const y_plane_; | 178 const uint8_t* const y_plane_; |
148 const uint8_t* const u_plane_; | 179 const uint8_t* const u_plane_; |
149 const uint8_t* const v_plane_; | 180 const uint8_t* const v_plane_; |
150 const int y_stride_; | 181 const int y_stride_; |
151 const int u_stride_; | 182 const int u_stride_; |
152 const int v_stride_; | 183 const int v_stride_; |
153 rtc::Callback0<void> no_longer_used_cb_; | 184 rtc::Callback0<void> no_longer_used_cb_; |
154 }; | 185 }; |
155 | 186 |
156 // Helper function to crop |buffer| without making a deep copy. May only be used | 187 // Helper function to crop |buffer| without making a deep copy. May only be used |
157 // for non-native frames. | 188 // for non-native frames. |
158 rtc::scoped_refptr<VideoFrameBuffer> ShallowCenterCrop( | 189 rtc::scoped_refptr<VideoFrameBuffer> ShallowCenterCrop( |
159 const rtc::scoped_refptr<VideoFrameBuffer>& buffer, | 190 const rtc::scoped_refptr<VideoFrameBuffer>& buffer, |
160 int cropped_width, | 191 int cropped_width, |
161 int cropped_height); | 192 int cropped_height); |
162 | 193 |
163 } // namespace webrtc | 194 } // namespace webrtc |
164 | 195 |
165 #endif // WEBRTC_COMMON_VIDEO_INCLUDE_VIDEO_FRAME_BUFFER_H_ | 196 #endif // WEBRTC_COMMON_VIDEO_INCLUDE_VIDEO_FRAME_BUFFER_H_ |
OLD | NEW |