OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "base/string_piece.h" | 8 #include "base/string_piece.h" |
9 #include "media/base/limits.h" | 9 #include "media/base/limits.h" |
10 #include "media/base/video_util.h" | 10 #include "media/base/video_util.h" |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 // the case of YV12 the strides are identical for the same width surface, but | 128 // the case of YV12 the strides are identical for the same width surface, but |
129 // the number of bytes allocated for YV12 is 1/2 the amount for U & V as | 129 // the number of bytes allocated for YV12 is 1/2 the amount for U & V as |
130 // YV16. We also round the height of the surface allocated to be an even | 130 // YV16. We also round the height of the surface allocated to be an even |
131 // number to avoid any potential of faulting by code that attempts to access | 131 // number to avoid any potential of faulting by code that attempts to access |
132 // the Y values of the final row, but assumes that the last row of U & V | 132 // the Y values of the final row, but assumes that the last row of U & V |
133 // applies to a full two rows of Y. | 133 // applies to a full two rows of Y. |
134 size_t y_stride = RoundUp(row_bytes(VideoFrame::kYPlane), | 134 size_t y_stride = RoundUp(row_bytes(VideoFrame::kYPlane), |
135 kFrameSizeAlignment); | 135 kFrameSizeAlignment); |
136 size_t uv_stride = RoundUp(row_bytes(VideoFrame::kUPlane), | 136 size_t uv_stride = RoundUp(row_bytes(VideoFrame::kUPlane), |
137 kFrameSizeAlignment); | 137 kFrameSizeAlignment); |
138 size_t y_height = RoundUp(height_, kFrameSizeAlignment); | 138 // the *2 here is because some formats (e.g. h264) allow interlaced coding, |
139 // and then the size needs to be a multiple of two macroblocks (vertically). | |
140 size_t y_height = RoundUp(height_, kFrameSizeAlignment * 2); | |
DaleCurtis
2012/07/11 20:11:05
The code you reference below adds 2 to the height
| |
139 size_t uv_height = format_ == VideoFrame::YV12 ? y_height / 2 : y_height; | 141 size_t uv_height = format_ == VideoFrame::YV12 ? y_height / 2 : y_height; |
140 size_t y_bytes = y_height * y_stride; | 142 size_t y_bytes = y_height * y_stride; |
141 size_t uv_bytes = uv_height * uv_stride; | 143 size_t uv_bytes = uv_height * uv_stride; |
142 | 144 |
143 #if !defined(OS_ANDROID) | 145 #if !defined(OS_ANDROID) |
144 // TODO(dalecurtis): use DataAligned or so, so this #ifdef hackery | 146 // TODO(dalecurtis): use DataAligned or so, so this #ifdef hackery |
145 // doesn't need to be repeated in every single user of aligned data. | 147 // doesn't need to be repeated in every single user of aligned data. |
148 // The extra line of UV being allocates is because h264 chroma MC | |
149 // overreads by one line in some cases, see libavcodec/utils.c:244 or | |
150 // libavcodec/x86/h264_chromamc.asm:637). | |
146 uint8* data = reinterpret_cast<uint8*>( | 151 uint8* data = reinterpret_cast<uint8*>( |
147 av_malloc(y_bytes + (uv_bytes * 2) + kFramePadBytes)); | 152 av_malloc(y_bytes + (uv_bytes * 2 + uv_stride) + kFramePadBytes)); |
148 #else | 153 #else |
149 uint8* data = new uint8_t[y_bytes + (uv_bytes * 2)]; | 154 uint8* data = new uint8_t[y_bytes + (uv_bytes * 2)]; |
150 #endif | 155 #endif |
151 COMPILE_ASSERT(0 == VideoFrame::kYPlane, y_plane_data_must_be_index_0); | 156 COMPILE_ASSERT(0 == VideoFrame::kYPlane, y_plane_data_must_be_index_0); |
152 data_[VideoFrame::kYPlane] = data; | 157 data_[VideoFrame::kYPlane] = data; |
153 data_[VideoFrame::kUPlane] = data + y_bytes; | 158 data_[VideoFrame::kUPlane] = data + y_bytes; |
154 data_[VideoFrame::kVPlane] = data + y_bytes + uv_bytes; | 159 data_[VideoFrame::kVPlane] = data + y_bytes + uv_bytes; |
155 strides_[VideoFrame::kYPlane] = y_stride; | 160 strides_[VideoFrame::kYPlane] = y_stride; |
156 strides_[VideoFrame::kUPlane] = uv_stride; | 161 strides_[VideoFrame::kUPlane] = uv_stride; |
157 strides_[VideoFrame::kVPlane] = uv_stride; | 162 strides_[VideoFrame::kVPlane] = uv_stride; |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
287 break; | 292 break; |
288 for(int row = 0; row < rows(plane); row++) { | 293 for(int row = 0; row < rows(plane); row++) { |
289 base::MD5Update(context, base::StringPiece( | 294 base::MD5Update(context, base::StringPiece( |
290 reinterpret_cast<char*>(data(plane) + stride(plane) * row), | 295 reinterpret_cast<char*>(data(plane) + stride(plane) * row), |
291 row_bytes(plane))); | 296 row_bytes(plane))); |
292 } | 297 } |
293 } | 298 } |
294 } | 299 } |
295 | 300 |
296 } // namespace media | 301 } // namespace media |
OLD | NEW |