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 // See libavcodec/utils.c:avcodec_align_dimensions2(). |
| 141 size_t y_height = RoundUp(height_, kFrameSizeAlignment * 2); |
139 size_t uv_height = format_ == VideoFrame::YV12 ? y_height / 2 : y_height; | 142 size_t uv_height = format_ == VideoFrame::YV12 ? y_height / 2 : y_height; |
140 size_t y_bytes = y_height * y_stride; | 143 size_t y_bytes = y_height * y_stride; |
141 size_t uv_bytes = uv_height * uv_stride; | 144 size_t uv_bytes = uv_height * uv_stride; |
142 | 145 |
143 #if !defined(OS_ANDROID) | 146 #if !defined(OS_ANDROID) |
144 // TODO(dalecurtis): use DataAligned or so, so this #ifdef hackery | 147 // TODO(dalecurtis): use DataAligned or so, so this #ifdef hackery |
145 // doesn't need to be repeated in every single user of aligned data. | 148 // doesn't need to be repeated in every single user of aligned data. |
| 149 // The extra line of UV being allocated is because h264 chroma MC |
| 150 // overreads by one line in some cases, see libavcodec/utils.c: |
| 151 // avcodec_align_dimensions2() and libavcodec/x86/h264_chromamc.asm: |
| 152 // put_h264_chroma_mc4_ssse3(). |
146 uint8* data = reinterpret_cast<uint8*>( | 153 uint8* data = reinterpret_cast<uint8*>( |
147 av_malloc(y_bytes + (uv_bytes * 2) + kFramePadBytes)); | 154 av_malloc(y_bytes + (uv_bytes * 2 + uv_stride) + kFramePadBytes)); |
148 #else | 155 #else |
149 uint8* data = new uint8_t[y_bytes + (uv_bytes * 2)]; | 156 uint8* data = new uint8_t[y_bytes + (uv_bytes * 2)]; |
150 #endif | 157 #endif |
151 COMPILE_ASSERT(0 == VideoFrame::kYPlane, y_plane_data_must_be_index_0); | 158 COMPILE_ASSERT(0 == VideoFrame::kYPlane, y_plane_data_must_be_index_0); |
152 data_[VideoFrame::kYPlane] = data; | 159 data_[VideoFrame::kYPlane] = data; |
153 data_[VideoFrame::kUPlane] = data + y_bytes; | 160 data_[VideoFrame::kUPlane] = data + y_bytes; |
154 data_[VideoFrame::kVPlane] = data + y_bytes + uv_bytes; | 161 data_[VideoFrame::kVPlane] = data + y_bytes + uv_bytes; |
155 strides_[VideoFrame::kYPlane] = y_stride; | 162 strides_[VideoFrame::kYPlane] = y_stride; |
156 strides_[VideoFrame::kUPlane] = uv_stride; | 163 strides_[VideoFrame::kUPlane] = uv_stride; |
157 strides_[VideoFrame::kVPlane] = uv_stride; | 164 strides_[VideoFrame::kVPlane] = uv_stride; |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 break; | 294 break; |
288 for(int row = 0; row < rows(plane); row++) { | 295 for(int row = 0; row < rows(plane); row++) { |
289 base::MD5Update(context, base::StringPiece( | 296 base::MD5Update(context, base::StringPiece( |
290 reinterpret_cast<char*>(data(plane) + stride(plane) * row), | 297 reinterpret_cast<char*>(data(plane) + stride(plane) * row), |
291 row_bytes(plane))); | 298 row_bytes(plane))); |
292 } | 299 } |
293 } | 300 } |
294 } | 301 } |
295 | 302 |
296 } // namespace media | 303 } // namespace media |
OLD | NEW |