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

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

Powered by Google App Engine
This is Rietveld 408576698