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

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 existing unit tests. 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
« no previous file with comments | « media/base/video_decoder_config.cc ('k') | media/ffmpeg/ffmpeg_common.h » ('j') | 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) 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 y_height = RoundUp(rows(VideoFrame::kYPlane), 2);
119 size_t y_bytes_per_row = RoundUp(width_, 4); 122 size_t y_stride = RoundUp(row_bytes(VideoFrame::kYPlane), 4);
120 size_t uv_stride = RoundUp(y_bytes_per_row / 2, 4); 123 size_t uv_stride = RoundUp(row_bytes(VideoFrame::kUPlane), 4);
121 size_t y_bytes = alloc_height * y_bytes_per_row; 124 size_t uv_height = RoundUp(rows(VideoFrame::kUPlane), 2);
122 size_t uv_bytes = alloc_height * uv_stride; 125 size_t y_bytes = y_height * y_stride;
123 if (format_ == VideoFrame::YV12) { 126 size_t uv_bytes = uv_height * uv_stride;
124 uv_bytes /= 2; 127
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_stride;
fbarchard 2011/10/05 01:38:46 FYI I'd suggest using 'stride' terminology consist
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 }
136 138
137 VideoFrame::VideoFrame(VideoFrame::Format format, 139 VideoFrame::VideoFrame(VideoFrame::Format format,
138 size_t width, 140 size_t width,
139 size_t height) 141 size_t height)
140 : format_(format), 142 : format_(format),
141 width_(width), 143 width_(width),
142 height_(height), 144 height_(height),
(...skipping 89 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
« no previous file with comments | « media/base/video_decoder_config.cc ('k') | media/ffmpeg/ffmpeg_common.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698