Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(134)

Side by Side Diff: webrtc/common_video/include/video_frame_buffer.h

Issue 1878623002: Added new VideoFrameBuffer methods Data[YUV]() etc. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebase. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 // Underlying refcount access, used to implement IsMutable. 43 // Underlying refcount access, used to implement IsMutable.
44 // TODO(nisse): Demote to protected, as soon as Chrome is changed to 44 // TODO(nisse): Demote to protected, as soon as Chrome is changed to
45 // use IsMutable. 45 // use IsMutable.
46 virtual bool HasOneRef() const = 0; 46 virtual bool HasOneRef() const = 0;
47 47
48 // The resolution of the frame in pixels. For formats where some planes are 48 // The resolution of the frame in pixels. For formats where some planes are
49 // subsampled, this is the highest-resolution plane. 49 // subsampled, this is the highest-resolution plane.
50 virtual int width() const = 0; 50 virtual int width() const = 0;
51 virtual int height() const = 0; 51 virtual int height() const = 0;
52 52
53 // TODO(nisse): For the transition, we use default implementations
54 // of the stride and data methods where the new methods calls the
55 // old method, and the old method calls the new methods. Subclasses
56 // must override either the new methods or the old method, to break
57 // infinite recursion. And similarly for the strides. When
58 // applications, in particular Chrome, are updated, delete the old
59 // method and delete the default implementation of the new methods.
60
53 // Returns pointer to the pixel data for a given plane. The memory is owned by 61 // Returns pointer to the pixel data for a given plane. The memory is owned by
54 // the VideoFrameBuffer object and must not be freed by the caller. 62 // the VideoFrameBuffer object and must not be freed by the caller.
55 virtual const uint8_t* data(PlaneType type) const = 0; 63 virtual const uint8_t* DataY() const;
64 virtual const uint8_t* DataU() const;
65 virtual const uint8_t* DataV() const;
66 // Deprecated method.
67 // TODO(nisse): Delete after all users are updated.
68 virtual const uint8_t* data(PlaneType type) const;
56 69
57 // Non-const data access is disallowed by default. You need to make sure you 70 // Non-const data access is allowed only if HasOneRef() is true.
58 // have exclusive access and a writable buffer before calling this function. 71 virtual uint8_t* MutableDataY();
72 virtual uint8_t* MutableDataU();
73 virtual uint8_t* MutableDataV();
74 // Deprecated method. TODO(nisse): Delete after all users are updated.
59 virtual uint8_t* MutableData(PlaneType type); 75 virtual uint8_t* MutableData(PlaneType type);
60 76
61 // Returns the number of bytes between successive rows for a given plane. 77 // Returns the number of bytes between successive rows for a given plane.
62 virtual int stride(PlaneType type) const = 0; 78 virtual int StrideY() const;
79 virtual int StrideU() const;
80 virtual int StrideV() const;
81 // Deprecated method. TODO(nisse): Delete after all users are updated.
82 virtual int stride(PlaneType type) const;
63 83
64 // Return the handle of the underlying video frame. This is used when the 84 // Return the handle of the underlying video frame. This is used when the
65 // frame is backed by a texture. 85 // frame is backed by a texture.
66 virtual void* native_handle() const = 0; 86 virtual void* native_handle() const = 0;
67 87
68 // Returns a new memory-backed frame buffer converted from this buffer's 88 // Returns a new memory-backed frame buffer converted from this buffer's
69 // native handle. 89 // native handle.
70 virtual rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() = 0; 90 virtual rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() = 0;
71 91
72 protected: 92 protected:
73 virtual ~VideoFrameBuffer(); 93 virtual ~VideoFrameBuffer();
74 }; 94 };
75 95
76 // Plain I420 buffer in standard memory. 96 // Plain I420 buffer in standard memory.
77 class I420Buffer : public VideoFrameBuffer { 97 class I420Buffer : public VideoFrameBuffer {
78 public: 98 public:
79 I420Buffer(int width, int height); 99 I420Buffer(int width, int height);
80 I420Buffer(int width, int height, int stride_y, int stride_u, int stride_v); 100 I420Buffer(int width, int height, int stride_y, int stride_u, int stride_v);
81 void InitializeData(); 101 void InitializeData();
82 102
83 int width() const override; 103 int width() const override;
84 int height() const override; 104 int height() const override;
85 const uint8_t* data(PlaneType type) const override; 105 const uint8_t* DataY() const override;
86 // Non-const data access is only allowed if HasOneRef() is true to protect 106 const uint8_t* DataU() const override;
107 const uint8_t* DataV() const override;
108 // Non-const data access is only allowed if IsMutable() is true, to protect
87 // against unexpected overwrites. 109 // against unexpected overwrites.
88 bool IsMutable() override; 110 bool IsMutable() override;
89 uint8_t* MutableData(PlaneType type) override; 111 uint8_t* MutableDataY() override;
90 int stride(PlaneType type) const override; 112 uint8_t* MutableDataU() override;
113 uint8_t* MutableDataV() override;
114 int StrideY() const override;
115 int StrideU() const override;
116 int StrideV() const override;
117
91 void* native_handle() const override; 118 void* native_handle() const override;
92 rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override; 119 rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override;
93 120
94 // Create a new buffer and copy the pixel data. 121 // Create a new buffer and copy the pixel data.
95 static rtc::scoped_refptr<I420Buffer> Copy( 122 static rtc::scoped_refptr<I420Buffer> Copy(
96 const rtc::scoped_refptr<VideoFrameBuffer>& buffer); 123 const rtc::scoped_refptr<VideoFrameBuffer>& buffer);
97 124
98 protected: 125 protected:
99 ~I420Buffer() override; 126 ~I420Buffer() override;
100 127
101 private: 128 private:
102 const int width_; 129 const int width_;
103 const int height_; 130 const int height_;
104 const int stride_y_; 131 const int stride_y_;
105 const int stride_u_; 132 const int stride_u_;
106 const int stride_v_; 133 const int stride_v_;
107 const std::unique_ptr<uint8_t, AlignedFreeDeleter> data_; 134 const std::unique_ptr<uint8_t, AlignedFreeDeleter> data_;
108 }; 135 };
109 136
110 // Base class for native-handle buffer is a wrapper around a |native_handle|. 137 // Base class for native-handle buffer is a wrapper around a |native_handle|.
111 // This is used for convenience as most native-handle implementations can share 138 // This is used for convenience as most native-handle implementations can share
112 // many VideoFrame implementations, but need to implement a few others (such 139 // many VideoFrame implementations, but need to implement a few others (such
113 // as their own destructors or conversion methods back to software I420). 140 // as their own destructors or conversion methods back to software I420).
114 class NativeHandleBuffer : public VideoFrameBuffer { 141 class NativeHandleBuffer : public VideoFrameBuffer {
115 public: 142 public:
116 NativeHandleBuffer(void* native_handle, int width, int height); 143 NativeHandleBuffer(void* native_handle, int width, int height);
117 144
118 int width() const override; 145 int width() const override;
119 int height() const override; 146 int height() const override;
120 const uint8_t* data(PlaneType type) const override; 147 const uint8_t* DataY() const override;
121 int stride(PlaneType type) const override; 148 const uint8_t* DataU() const override;
149 const uint8_t* DataV() const override;
150 int StrideY() const override;
151 int StrideU() const override;
152 int StrideV() const override;
153
122 void* native_handle() const override; 154 void* native_handle() const override;
123 bool IsMutable() override; 155 bool IsMutable() override;
124 156
125 protected: 157 protected:
126 void* native_handle_; 158 void* native_handle_;
127 const int width_; 159 const int width_;
128 const int height_; 160 const int height_;
129 }; 161 };
130 162
131 class WrappedI420Buffer : public webrtc::VideoFrameBuffer { 163 class WrappedI420Buffer : public webrtc::VideoFrameBuffer {
132 public: 164 public:
133 WrappedI420Buffer(int width, 165 WrappedI420Buffer(int width,
134 int height, 166 int height,
135 const uint8_t* y_plane, 167 const uint8_t* y_plane,
136 int y_stride, 168 int y_stride,
137 const uint8_t* u_plane, 169 const uint8_t* u_plane,
138 int u_stride, 170 int u_stride,
139 const uint8_t* v_plane, 171 const uint8_t* v_plane,
140 int v_stride, 172 int v_stride,
141 const rtc::Callback0<void>& no_longer_used); 173 const rtc::Callback0<void>& no_longer_used);
142 int width() const override; 174 int width() const override;
143 int height() const override; 175 int height() const override;
144 176
145 bool IsMutable() override; 177 bool IsMutable() override;
146 178
147 const uint8_t* data(PlaneType type) const override; 179 const uint8_t* DataY() const override;
180 const uint8_t* DataU() const override;
181 const uint8_t* DataV() const override;
182 int StrideY() const override;
183 int StrideU() const override;
184 int StrideV() const override;
148 185
149 int stride(PlaneType type) const override;
150 void* native_handle() const override; 186 void* native_handle() const override;
151 187
152 rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override; 188 rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override;
153 189
154 private: 190 private:
155 friend class rtc::RefCountedObject<WrappedI420Buffer>; 191 friend class rtc::RefCountedObject<WrappedI420Buffer>;
156 ~WrappedI420Buffer() override; 192 ~WrappedI420Buffer() override;
157 193
158 const int width_; 194 const int width_;
159 const int height_; 195 const int height_;
160 const uint8_t* const y_plane_; 196 const uint8_t* const y_plane_;
161 const uint8_t* const u_plane_; 197 const uint8_t* const u_plane_;
162 const uint8_t* const v_plane_; 198 const uint8_t* const v_plane_;
163 const int y_stride_; 199 const int y_stride_;
164 const int u_stride_; 200 const int u_stride_;
165 const int v_stride_; 201 const int v_stride_;
166 rtc::Callback0<void> no_longer_used_cb_; 202 rtc::Callback0<void> no_longer_used_cb_;
167 }; 203 };
168 204
169 // Helper function to crop |buffer| without making a deep copy. May only be used 205 // Helper function to crop |buffer| without making a deep copy. May only be used
170 // for non-native frames. 206 // for non-native frames.
171 rtc::scoped_refptr<VideoFrameBuffer> ShallowCenterCrop( 207 rtc::scoped_refptr<VideoFrameBuffer> ShallowCenterCrop(
172 const rtc::scoped_refptr<VideoFrameBuffer>& buffer, 208 const rtc::scoped_refptr<VideoFrameBuffer>& buffer,
173 int cropped_width, 209 int cropped_width,
174 int cropped_height); 210 int cropped_height);
175 211
176 } // namespace webrtc 212 } // namespace webrtc
177 213
178 #endif // WEBRTC_COMMON_VIDEO_INCLUDE_VIDEO_FRAME_BUFFER_H_ 214 #endif // WEBRTC_COMMON_VIDEO_INCLUDE_VIDEO_FRAME_BUFFER_H_
OLDNEW
« no previous file with comments | « webrtc/common_video/i420_video_frame_unittest.cc ('k') | webrtc/common_video/video_frame_buffer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698