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

Side by Side Diff: media/base/video_frame.cc

Issue 2337001: pad yuv additional 15 bytes to allow 16 pixels at a time to be processed with... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 namespace media { 7 namespace media {
8 8
9 // static 9 // static
10 void VideoFrame::CreateFrame(VideoFrame::Format format, 10 void VideoFrame::CreateFrame(VideoFrame::Format format,
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 size_t bytes_per_row = RoundUp(width_ * bytes_per_pixel, 8); 123 size_t bytes_per_row = RoundUp(width_ * bytes_per_pixel, 8);
124 planes_ = VideoFrame::kNumRGBPlanes; 124 planes_ = VideoFrame::kNumRGBPlanes;
125 strides_[VideoFrame::kRGBPlane] = bytes_per_row; 125 strides_[VideoFrame::kRGBPlane] = bytes_per_row;
126 data_[VideoFrame::kRGBPlane] = new uint8[bytes_per_row * height_]; 126 data_[VideoFrame::kRGBPlane] = new uint8[bytes_per_row * height_];
127 DCHECK(data_[VideoFrame::kRGBPlane]); 127 DCHECK(data_[VideoFrame::kRGBPlane]);
128 DCHECK(!(reinterpret_cast<intptr_t>(data_[VideoFrame::kRGBPlane]) & 7)); 128 DCHECK(!(reinterpret_cast<intptr_t>(data_[VideoFrame::kRGBPlane]) & 7));
129 COMPILE_ASSERT(0 == VideoFrame::kRGBPlane, RGB_data_must_be_index_0); 129 COMPILE_ASSERT(0 == VideoFrame::kRGBPlane, RGB_data_must_be_index_0);
130 return (NULL != data_[VideoFrame::kRGBPlane]); 130 return (NULL != data_[VideoFrame::kRGBPlane]);
131 } 131 }
132 132
133 static const int kFramePadBytes = 15; // allows faster SIMD YUV convert
134
133 bool VideoFrame::AllocateYUV() { 135 bool VideoFrame::AllocateYUV() {
134 DCHECK(format_ == VideoFrame::YV12 || 136 DCHECK(format_ == VideoFrame::YV12 ||
135 format_ == VideoFrame::YV16); 137 format_ == VideoFrame::YV16);
136 // Align Y rows at 32-bit (4 byte) boundaries. The stride for both YV12 and 138 // Align Y rows at 32-bit (4 byte) boundaries. The stride for both YV12 and
137 // YV16 is 1/2 of the stride of Y. For YV12, every row of bytes for U and V 139 // YV16 is 1/2 of the stride of Y. For YV12, every row of bytes for U and V
138 // applies to two rows of Y (one byte of UV for 4 bytes of Y), so in the 140 // applies to two rows of Y (one byte of UV for 4 bytes of Y), so in the
139 // case of YV12 the strides are identical for the same width surface, but the 141 // case of YV12 the strides are identical for the same width surface, but the
140 // number of bytes allocated for YV12 is 1/2 the amount for U & V as YV16. 142 // number of bytes allocated for YV12 is 1/2 the amount for U & V as YV16.
141 // We also round the height of the surface allocated to be an even number 143 // We also round the height of the surface allocated to be an even number
142 // to avoid any potential of faulting by code that attempts to access the Y 144 // to avoid any potential of faulting by code that attempts to access the Y
143 // values of the final row, but assumes that the last row of U & V applies to 145 // values of the final row, but assumes that the last row of U & V applies to
144 // a full two rows of Y. 146 // a full two rows of Y.
145 size_t alloc_height = RoundUp(height_, 2); 147 size_t alloc_height = RoundUp(height_, 2);
146 size_t y_bytes_per_row = RoundUp(width_, 4); 148 size_t y_bytes_per_row = RoundUp(width_, 4);
147 size_t uv_stride = RoundUp(y_bytes_per_row / 2, 4); 149 size_t uv_stride = RoundUp(y_bytes_per_row / 2, 4);
148 size_t y_bytes = alloc_height * y_bytes_per_row; 150 size_t y_bytes = alloc_height * y_bytes_per_row;
149 size_t uv_bytes = alloc_height * uv_stride; 151 size_t uv_bytes = alloc_height * uv_stride;
150 if (format_ == VideoFrame::YV12) { 152 if (format_ == VideoFrame::YV12) {
151 uv_bytes /= 2; 153 uv_bytes /= 2;
152 } 154 }
153 uint8* data = new uint8[y_bytes + (uv_bytes * 2)]; 155 uint8* data = new uint8[y_bytes + (uv_bytes * 2) + kFramePadBytes];
154 if (data) { 156 if (data) {
155 planes_ = VideoFrame::kNumYUVPlanes; 157 planes_ = VideoFrame::kNumYUVPlanes;
156 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);
157 data_[VideoFrame::kYPlane] = data; 159 data_[VideoFrame::kYPlane] = data;
158 data_[VideoFrame::kUPlane] = data + y_bytes; 160 data_[VideoFrame::kUPlane] = data + y_bytes;
159 data_[VideoFrame::kVPlane] = data + y_bytes + uv_bytes; 161 data_[VideoFrame::kVPlane] = data + y_bytes + uv_bytes;
160 strides_[VideoFrame::kYPlane] = y_bytes_per_row; 162 strides_[VideoFrame::kYPlane] = y_bytes_per_row;
161 strides_[VideoFrame::kUPlane] = uv_stride; 163 strides_[VideoFrame::kUPlane] = uv_stride;
162 strides_[VideoFrame::kVPlane] = uv_stride; 164 strides_[VideoFrame::kVPlane] = uv_stride;
163 return true; 165 return true;
(...skipping 21 matching lines...) Expand all
185 // on the heap, and other |data| pointers point inside the same, single block 187 // on the heap, and other |data| pointers point inside the same, single block
186 // so just delete index 0. 188 // so just delete index 0.
187 delete[] data_[0]; 189 delete[] data_[0];
188 } 190 }
189 191
190 bool VideoFrame::IsEndOfStream() const { 192 bool VideoFrame::IsEndOfStream() const {
191 return format_ == VideoFrame::EMPTY; 193 return format_ == VideoFrame::EMPTY;
192 } 194 }
193 195
194 } // namespace media 196 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698