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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
92 return frame; | 92 return frame; |
93 } | 93 } |
94 | 94 |
95 static inline size_t RoundUp(size_t value, size_t alignment) { | 95 static inline size_t RoundUp(size_t value, size_t alignment) { |
96 // Check that |alignment| is a power of 2. | 96 // Check that |alignment| is a power of 2. |
97 DCHECK((alignment + (alignment - 1)) == (alignment | (alignment - 1))); | 97 DCHECK((alignment + (alignment - 1)) == (alignment | (alignment - 1))); |
98 return ((value + (alignment - 1)) & ~(alignment-1)); | 98 return ((value + (alignment - 1)) & ~(alignment-1)); |
99 } | 99 } |
100 | 100 |
101 static const int kFrameSizeAlignment = 16; | 101 static const int kFrameSizeAlignment = 16; |
102 // Allows faster SIMD YUV convert. Also, FFmpeg overreads/-writes occasionally. | |
103 static const int kFramePadBytes = 15; | |
102 | 104 |
103 void VideoFrame::AllocateRGB(size_t bytes_per_pixel) { | 105 void VideoFrame::AllocateRGB(size_t bytes_per_pixel) { |
104 // Round up to align at least at a 16-byte boundary for each row. | 106 // Round up to align at least at a 16-byte boundary for each row. |
105 // This is sufficient for MMX and SSE2 reads (movq/movdqa). | 107 // This is sufficient for MMX and SSE2 reads (movq/movdqa). |
106 size_t bytes_per_row = RoundUp(width_, kFrameSizeAlignment) * bytes_per_pixel; | 108 size_t bytes_per_row = RoundUp(width_, kFrameSizeAlignment) * bytes_per_pixel; |
107 size_t aligned_height = RoundUp(height_, kFrameSizeAlignment); | 109 size_t aligned_height = RoundUp(height_, kFrameSizeAlignment); |
108 strides_[VideoFrame::kRGBPlane] = bytes_per_row; | 110 strides_[VideoFrame::kRGBPlane] = bytes_per_row; |
109 #if !defined(OS_ANDROID) | 111 #if !defined(OS_ANDROID) |
110 // TODO(dalecurtis): use DataAligned or so, so this #ifdef hackery | 112 // TODO(dalecurtis): use DataAligned or so, so this #ifdef hackery |
111 // doesn't need to be repeated in every single user of aligned data. | 113 // doesn't need to be repeated in every single user of aligned data. |
112 data_[VideoFrame::kRGBPlane] = reinterpret_cast<uint8*>( | 114 data_[VideoFrame::kRGBPlane] = reinterpret_cast<uint8*>( |
113 av_malloc(bytes_per_row * aligned_height)); | 115 av_malloc(bytes_per_row * aligned_height + kFramePadBytes)); |
DaleCurtis
2012/07/09 23:25:51
FF_INPUT_BUFFER_PADDING_SIZE instead ?
| |
114 #else | 116 #else |
115 data_[VideoFrame::kRGBPlane] = new uint8_t[bytes_per_row * aligned_height]; | 117 data_[VideoFrame::kRGBPlane] = new uint8_t[bytes_per_row * aligned_height]; |
116 #endif | 118 #endif |
117 DCHECK(!(reinterpret_cast<intptr_t>(data_[VideoFrame::kRGBPlane]) & 7)); | 119 DCHECK(!(reinterpret_cast<intptr_t>(data_[VideoFrame::kRGBPlane]) & 7)); |
118 COMPILE_ASSERT(0 == VideoFrame::kRGBPlane, RGB_data_must_be_index_0); | 120 COMPILE_ASSERT(0 == VideoFrame::kRGBPlane, RGB_data_must_be_index_0); |
119 } | 121 } |
120 | 122 |
121 void VideoFrame::AllocateYUV() { | 123 void VideoFrame::AllocateYUV() { |
122 DCHECK(format_ == VideoFrame::YV12 || format_ == VideoFrame::YV16); | 124 DCHECK(format_ == VideoFrame::YV12 || format_ == VideoFrame::YV16); |
123 // Align Y rows at least at 16 byte boundaries. The stride for both | 125 // Align Y rows at least at 16 byte boundaries. The stride for both |
(...skipping 11 matching lines...) Expand all Loading... | |
135 kFrameSizeAlignment); | 137 kFrameSizeAlignment); |
136 size_t y_height = RoundUp(height_, kFrameSizeAlignment); | 138 size_t y_height = RoundUp(height_, kFrameSizeAlignment); |
137 size_t uv_height = format_ == VideoFrame::YV12 ? y_height / 2 : y_height; | 139 size_t uv_height = format_ == VideoFrame::YV12 ? y_height / 2 : y_height; |
138 size_t y_bytes = y_height * y_stride; | 140 size_t y_bytes = y_height * y_stride; |
139 size_t uv_bytes = uv_height * uv_stride; | 141 size_t uv_bytes = uv_height * uv_stride; |
140 | 142 |
141 #if !defined(OS_ANDROID) | 143 #if !defined(OS_ANDROID) |
142 // TODO(dalecurtis): use DataAligned or so, so this #ifdef hackery | 144 // TODO(dalecurtis): use DataAligned or so, so this #ifdef hackery |
143 // doesn't need to be repeated in every single user of aligned data. | 145 // doesn't need to be repeated in every single user of aligned data. |
144 uint8* data = reinterpret_cast<uint8*>( | 146 uint8* data = reinterpret_cast<uint8*>( |
145 av_malloc(y_bytes + (uv_bytes * 2))); | 147 av_malloc(y_bytes + (uv_bytes * 2) + kFramePadBytes)); |
146 #else | 148 #else |
147 uint8* data = new uint8_t[y_bytes + (uv_bytes * 2)]; | 149 uint8* data = new uint8_t[y_bytes + (uv_bytes * 2)]; |
148 #endif | 150 #endif |
149 COMPILE_ASSERT(0 == VideoFrame::kYPlane, y_plane_data_must_be_index_0); | 151 COMPILE_ASSERT(0 == VideoFrame::kYPlane, y_plane_data_must_be_index_0); |
150 data_[VideoFrame::kYPlane] = data; | 152 data_[VideoFrame::kYPlane] = data; |
151 data_[VideoFrame::kUPlane] = data + y_bytes; | 153 data_[VideoFrame::kUPlane] = data + y_bytes; |
152 data_[VideoFrame::kVPlane] = data + y_bytes + uv_bytes; | 154 data_[VideoFrame::kVPlane] = data + y_bytes + uv_bytes; |
153 strides_[VideoFrame::kYPlane] = y_stride; | 155 strides_[VideoFrame::kYPlane] = y_stride; |
154 strides_[VideoFrame::kUPlane] = uv_stride; | 156 strides_[VideoFrame::kUPlane] = uv_stride; |
155 strides_[VideoFrame::kVPlane] = uv_stride; | 157 strides_[VideoFrame::kVPlane] = uv_stride; |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
285 break; | 287 break; |
286 for(int row = 0; row < rows(plane); row++) { | 288 for(int row = 0; row < rows(plane); row++) { |
287 base::MD5Update(context, base::StringPiece( | 289 base::MD5Update(context, base::StringPiece( |
288 reinterpret_cast<char*>(data(plane) + stride(plane) * row), | 290 reinterpret_cast<char*>(data(plane) + stride(plane) * row), |
289 row_bytes(plane))); | 291 row_bytes(plane))); |
290 } | 292 } |
291 } | 293 } |
292 } | 294 } |
293 | 295 |
294 } // namespace media | 296 } // namespace media |
OLD | NEW |