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

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

Issue 8052002: Fix support for yuv_422 pixel format. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Fixed lint errors. Created 9 years, 2 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
OLDNEW
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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 // Fill the Y plane. 68 // Fill the Y plane.
69 uint8* y_plane = frame->data(VideoFrame::kYPlane); 69 uint8* y_plane = frame->data(VideoFrame::kYPlane);
70 for (size_t i = 0; i < frame->height_; ++i) { 70 for (size_t i = 0; i < frame->height_; ++i) {
71 memset(y_plane, kBlackY, frame->width_); 71 memset(y_plane, kBlackY, frame->width_);
72 y_plane += frame->stride(VideoFrame::kYPlane); 72 y_plane += frame->stride(VideoFrame::kYPlane);
73 } 73 }
74 74
75 // Fill the U and V planes. 75 // Fill the U and V planes.
76 uint8* u_plane = frame->data(VideoFrame::kUPlane); 76 uint8* u_plane = frame->data(VideoFrame::kUPlane);
77 uint8* v_plane = frame->data(VideoFrame::kVPlane); 77 uint8* v_plane = frame->data(VideoFrame::kVPlane);
78 for (size_t i = 0; i < (frame->height_ / 2); ++i) { 78 int uv_rows = frame->rows(VideoFrame::kUPlane);
79 memset(u_plane, kBlackUV, frame->width_ / 2); 79 int u_row_bytes = frame->row_bytes(VideoFrame::kUPlane);
80 memset(v_plane, kBlackUV, frame->width_ / 2); 80 int v_row_bytes = frame->row_bytes(VideoFrame::kVPlane);
81 for (size_t i = 0; i < (size_t)uv_rows; ++i) {
82 memset(u_plane, kBlackUV, u_row_bytes);
83 memset(v_plane, kBlackUV, v_row_bytes);
81 u_plane += frame->stride(VideoFrame::kUPlane); 84 u_plane += frame->stride(VideoFrame::kUPlane);
82 v_plane += frame->stride(VideoFrame::kVPlane); 85 v_plane += frame->stride(VideoFrame::kVPlane);
83 } 86 }
84 87
85 return frame; 88 return frame;
86 } 89 }
87 90
88 static inline size_t RoundUp(size_t value, size_t alignment) { 91 static inline size_t RoundUp(size_t value, size_t alignment) {
89 // Check that |alignment| is a power of 2. 92 // Check that |alignment| is a power of 2.
90 DCHECK((alignment + (alignment - 1)) == (alignment | (alignment - 1))); 93 DCHECK((alignment + (alignment - 1)) == (alignment | (alignment - 1)));
(...skipping 17 matching lines...) Expand all
108 DCHECK(format_ == VideoFrame::YV12 || format_ == VideoFrame::YV16); 111 DCHECK(format_ == VideoFrame::YV12 || format_ == VideoFrame::YV16);
109 // 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
110 // 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
111 // 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
112 // 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
113 // 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.
114 // 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
115 // 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
116 // 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
117 // a full two rows of Y. 120 // a full two rows of Y.
118 size_t alloc_height = RoundUp(height_, 2); 121 size_t alloc_height = RoundUp(height_, 2);
scherkus (not reviewing) 2011/09/28 17:32:17 want to fix this up to be "y_height" and use rows(
shadi1 2011/09/29 18:31:03 Done.
119 size_t y_bytes_per_row = RoundUp(width_, 4); 122 size_t y_bytes_per_row = RoundUp(width_, 4);
scherkus (not reviewing) 2011/09/28 17:32:17 ditto and maybe rename y_stride to be consistent w
shadi1 2011/09/29 18:31:03 Done.
120 size_t uv_stride = RoundUp(y_bytes_per_row / 2, 4); 123 size_t uv_stride = RoundUp(row_bytes(VideoFrame::kUPlane), 4);
124 size_t uv_height = RoundUp(rows(VideoFrame::kUPlane), 2);
121 size_t y_bytes = alloc_height * y_bytes_per_row; 125 size_t y_bytes = alloc_height * y_bytes_per_row;
122 size_t uv_bytes = alloc_height * uv_stride; 126 size_t uv_bytes = uv_height * uv_stride;
123 if (format_ == VideoFrame::YV12) { 127
124 uv_bytes /= 2;
125 }
126 uint8* data = new uint8[y_bytes + (uv_bytes * 2) + kFramePadBytes]; 128 uint8* data = new uint8[y_bytes + (uv_bytes * 2) + kFramePadBytes];
127 planes_ = VideoFrame::kNumYUVPlanes; 129 planes_ = VideoFrame::kNumYUVPlanes;
128 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);
129 data_[VideoFrame::kYPlane] = data; 131 data_[VideoFrame::kYPlane] = data;
130 data_[VideoFrame::kUPlane] = data + y_bytes; 132 data_[VideoFrame::kUPlane] = data + y_bytes;
131 data_[VideoFrame::kVPlane] = data + y_bytes + uv_bytes; 133 data_[VideoFrame::kVPlane] = data + y_bytes + uv_bytes;
132 strides_[VideoFrame::kYPlane] = y_bytes_per_row; 134 strides_[VideoFrame::kYPlane] = y_bytes_per_row;
133 strides_[VideoFrame::kUPlane] = uv_stride; 135 strides_[VideoFrame::kUPlane] = uv_stride;
134 strides_[VideoFrame::kVPlane] = uv_stride; 136 strides_[VideoFrame::kVPlane] = uv_stride;
135 } 137 }
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 uint8* VideoFrame::data(size_t plane) const { 234 uint8* VideoFrame::data(size_t plane) const {
233 DCHECK(IsValidPlane(plane)); 235 DCHECK(IsValidPlane(plane));
234 return data_[plane]; 236 return data_[plane];
235 } 237 }
236 238
237 bool VideoFrame::IsEndOfStream() const { 239 bool VideoFrame::IsEndOfStream() const {
238 return format_ == VideoFrame::EMPTY; 240 return format_ == VideoFrame::EMPTY;
239 } 241 }
240 242
241 } // namespace media 243 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698