OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "media/base/video_frame.h" | 5 #include "media/base/video_frame.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 | 8 |
9 namespace media { | 9 namespace media { |
10 | 10 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
111 DCHECK(format_ == VideoFrame::YV12 || format_ == VideoFrame::YV16); | 111 DCHECK(format_ == VideoFrame::YV12 || format_ == VideoFrame::YV16); |
112 // Align Y rows at 32-bit (4 byte) boundaries. The stride for both YV12 and | 112 // Align Y rows at 32-bit (4 byte) boundaries. The stride for both YV12 and |
113 // YV16 is 1/2 of the stride of Y. For YV12, every row of bytes for U and V | 113 // YV16 is 1/2 of the stride of Y. For YV12, every row of bytes for U and V |
114 // applies to two rows of Y (one byte of UV for 4 bytes of Y), so in the | 114 // applies to two rows of Y (one byte of UV for 4 bytes of Y), so in the |
115 // case of YV12 the strides are identical for the same width surface, but the | 115 // case of YV12 the strides are identical for the same width surface, but the |
116 // number of bytes allocated for YV12 is 1/2 the amount for U & V as YV16. | 116 // number of bytes allocated for YV12 is 1/2 the amount for U & V as YV16. |
117 // We also round the height of the surface allocated to be an even number | 117 // We also round the height of the surface allocated to be an even number |
118 // to avoid any potential of faulting by code that attempts to access the Y | 118 // to avoid any potential of faulting by code that attempts to access the Y |
119 // values of the final row, but assumes that the last row of U & V applies to | 119 // values of the final row, but assumes that the last row of U & V applies to |
120 // a full two rows of Y. | 120 // a full two rows of Y. |
121 size_t y_height = RoundUp(rows(VideoFrame::kYPlane), 2); | 121 size_t y_height = rows(VideoFrame::kYPlane); |
scherkus (not reviewing)
2011/11/10 04:09:41
this change looks OK and avoids over-allocating on
| |
122 size_t y_stride = RoundUp(row_bytes(VideoFrame::kYPlane), 4); | 122 size_t y_stride = RoundUp(row_bytes(VideoFrame::kYPlane), 4); |
123 size_t uv_stride = RoundUp(row_bytes(VideoFrame::kUPlane), 4); | 123 size_t uv_stride = RoundUp(row_bytes(VideoFrame::kUPlane), 4); |
124 size_t uv_height = RoundUp(rows(VideoFrame::kUPlane), 2); | 124 size_t uv_height = rows(VideoFrame::kUPlane); |
125 size_t y_bytes = y_height * y_stride; | 125 size_t y_bytes = y_height * y_stride; |
126 size_t uv_bytes = uv_height * uv_stride; | 126 size_t uv_bytes = uv_height * uv_stride; |
127 | 127 |
128 uint8* data = new uint8[y_bytes + (uv_bytes * 2) + kFramePadBytes]; | 128 uint8* data = new uint8[y_bytes + (uv_bytes * 2) + kFramePadBytes]; |
129 planes_ = VideoFrame::kNumYUVPlanes; | 129 planes_ = VideoFrame::kNumYUVPlanes; |
130 COMPILE_ASSERT(0 == VideoFrame::kYPlane, y_plane_data_must_be_index_0); | 130 COMPILE_ASSERT(0 == VideoFrame::kYPlane, y_plane_data_must_be_index_0); |
131 data_[VideoFrame::kYPlane] = data; | 131 data_[VideoFrame::kYPlane] = data; |
132 data_[VideoFrame::kUPlane] = data + y_bytes; | 132 data_[VideoFrame::kUPlane] = data + y_bytes; |
133 data_[VideoFrame::kVPlane] = data + y_bytes + uv_bytes; | 133 data_[VideoFrame::kVPlane] = data + y_bytes + uv_bytes; |
134 strides_[VideoFrame::kYPlane] = y_stride; | 134 strides_[VideoFrame::kYPlane] = y_stride; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
188 case RGB565: | 188 case RGB565: |
189 case RGB24: | 189 case RGB24: |
190 case RGB32: | 190 case RGB32: |
191 case RGBA: | 191 case RGBA: |
192 return width_; | 192 return width_; |
193 | 193 |
194 case YV12: | 194 case YV12: |
195 case YV16: | 195 case YV16: |
196 if (plane == kYPlane) | 196 if (plane == kYPlane) |
197 return width_; | 197 return width_; |
198 return width_ / 2; | 198 return RoundUp(width_, 2) / 2; |
scherkus (not reviewing)
2011/11/10 04:09:41
so we're always rounding up post-divide?
i.e., th
Chris Evans
2011/11/10 06:32:38
The intent is to round up pre-divide -- the divide
| |
199 | 199 |
200 default: | 200 default: |
201 break; | 201 break; |
202 } | 202 } |
203 | 203 |
204 // Intentionally leave out non-production formats. | 204 // Intentionally leave out non-production formats. |
205 NOTREACHED() << "Unsupported video frame format: " << format_; | 205 NOTREACHED() << "Unsupported video frame format: " << format_; |
206 return 0; | 206 return 0; |
207 } | 207 } |
208 | 208 |
209 int VideoFrame::rows(size_t plane) const { | 209 int VideoFrame::rows(size_t plane) const { |
210 DCHECK(IsValidPlane(plane)); | 210 DCHECK(IsValidPlane(plane)); |
211 switch (format_) { | 211 switch (format_) { |
212 case RGB555: | 212 case RGB555: |
213 case RGB565: | 213 case RGB565: |
214 case RGB24: | 214 case RGB24: |
215 case RGB32: | 215 case RGB32: |
216 case RGBA: | 216 case RGBA: |
217 case YV16: | 217 case YV16: |
218 return height_; | 218 return height_; |
219 | 219 |
220 case YV12: | 220 case YV12: |
221 if (plane == kYPlane) | 221 if (plane == kYPlane) |
222 return height_; | 222 return height_; |
223 return height_ / 2; | 223 return RoundUp(height_, 2) / 2; |
224 | 224 |
225 default: | 225 default: |
226 break; | 226 break; |
227 } | 227 } |
228 | 228 |
229 // Intentionally leave out non-production formats. | 229 // Intentionally leave out non-production formats. |
230 NOTREACHED() << "Unsupported video frame format: " << format_; | 230 NOTREACHED() << "Unsupported video frame format: " << format_; |
231 return 0; | 231 return 0; |
232 } | 232 } |
233 | 233 |
234 uint8* VideoFrame::data(size_t plane) const { | 234 uint8* VideoFrame::data(size_t plane) const { |
235 DCHECK(IsValidPlane(plane)); | 235 DCHECK(IsValidPlane(plane)); |
236 return data_[plane]; | 236 return data_[plane]; |
237 } | 237 } |
238 | 238 |
239 bool VideoFrame::IsEndOfStream() const { | 239 bool VideoFrame::IsEndOfStream() const { |
240 return format_ == VideoFrame::EMPTY; | 240 return format_ == VideoFrame::EMPTY; |
241 } | 241 } |
242 | 242 |
243 } // namespace media | 243 } // namespace media |
OLD | NEW |