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

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

Issue 182010: Fix memory leask in media yuv_convert unit tests. Replace pointers init'd by ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 3 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "base/base_paths.h" 5 #include "base/base_paths.h"
6 #include "base/file_util.h" 6 #include "base/file_util.h"
7 #include "media/base/yuv_convert.h" 7 #include "media/base/yuv_convert.h"
8 #include "media/base/yuv_row.h" 8 #include "media/base/yuv_row.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 132
133 TEST(YuvScaleTest, YV12) { 133 TEST(YuvScaleTest, YV12) {
134 // Read YUV reference data from file. 134 // Read YUV reference data from file.
135 FilePath yuv_url; 135 FilePath yuv_url;
136 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &yuv_url)); 136 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &yuv_url));
137 yuv_url = yuv_url.Append(FILE_PATH_LITERAL("media")) 137 yuv_url = yuv_url.Append(FILE_PATH_LITERAL("media"))
138 .Append(FILE_PATH_LITERAL("test")) 138 .Append(FILE_PATH_LITERAL("test"))
139 .Append(FILE_PATH_LITERAL("data")) 139 .Append(FILE_PATH_LITERAL("data"))
140 .Append(FILE_PATH_LITERAL("bali.yv12.640_360.yuv")); 140 .Append(FILE_PATH_LITERAL("bali.yv12.640_360.yuv"));
141 const size_t size_of_yuv = kWidth * kHeight * 12 / 8; // 12 bpp. 141 const size_t size_of_yuv = kWidth * kHeight * 12 / 8; // 12 bpp.
142 uint8* yuv_bytes = new uint8[size_of_yuv]; 142 scoped_array<uint8> yuv_bytes(new uint8[size_of_yuv]);
fbarchard 2009/08/28 16:56:02 doh! How quaint. This was the first unit test I
143 EXPECT_EQ(static_cast<int>(size_of_yuv), 143 EXPECT_EQ(static_cast<int>(size_of_yuv),
144 file_util::ReadFile(yuv_url, 144 file_util::ReadFile(yuv_url,
145 reinterpret_cast<char*>(yuv_bytes), 145 reinterpret_cast<char*>(yuv_bytes.get()),
146 static_cast<int>(size_of_yuv))); 146 static_cast<int>(size_of_yuv)));
147 147
148 // Scale a frame of YUV to 32 bit ARGB. 148 // Scale a frame of YUV to 32 bit ARGB.
149 const size_t size_of_rgb_scaled = kScaledWidth * kScaledHeight * kBpp; 149 const size_t size_of_rgb_scaled = kScaledWidth * kScaledHeight * kBpp;
150 uint8* rgb_scaled_bytes = new uint8[size_of_rgb_scaled]; 150 scoped_array<uint8> rgb_scaled_bytes(new uint8[size_of_rgb_scaled]);
151 151
152 media::ScaleYUVToRGB32(yuv_bytes, // Y plane 152 media::ScaleYUVToRGB32(yuv_bytes.get(), // Y
153 yuv_bytes + kWidth * kHeight, // U plane 153 yuv_bytes.get() + kWidth * kHeight, // U
154 yuv_bytes + kWidth * kHeight * 5 / 4, // V plane 154 yuv_bytes.get() + kWidth * kHeight * 5 / 4, // V
fbarchard 2009/08/28 16:56:02 kinda silly that 80 columns forces tiny comments,
155 rgb_scaled_bytes, // Rgb output 155 rgb_scaled_bytes.get(), // Rgb output
156 kWidth, kHeight, // Dimensions 156 kWidth, kHeight, // Dimensions
157 kScaledWidth, kScaledHeight, // Dimensions 157 kScaledWidth, kScaledHeight, // Dimensions
158 kWidth, // YStride 158 kWidth, // YStride
159 kWidth / 2, // UvStride 159 kWidth / 2, // UvStride
160 kScaledWidth * kBpp, // RgbStride 160 kScaledWidth * kBpp, // RgbStride
161 media::YV12, 161 media::YV12,
162 media::ROTATE_0); 162 media::ROTATE_0);
163 163
164 unsigned int rgb_hash = hash(rgb_scaled_bytes, size_of_rgb_scaled); 164 unsigned int rgb_hash = hash(rgb_scaled_bytes.get(), size_of_rgb_scaled);
165 165
166 // To get this hash value, run once and examine the following EXPECT_EQ. 166 // To get this hash value, run once and examine the following EXPECT_EQ.
167 // Then plug new hash value into EXPECT_EQ statements. 167 // Then plug new hash value into EXPECT_EQ statements.
168 168
169 // TODO(fbarchard): Make reference code mimic MMX exactly 169 // TODO(fbarchard): Make reference code mimic MMX exactly
170 #if USE_MMX 170 #if USE_MMX
171 EXPECT_EQ(4259656254u, rgb_hash); 171 EXPECT_EQ(4259656254u, rgb_hash);
172 #else 172 #else
173 EXPECT_EQ(197274901u, rgb_hash); 173 EXPECT_EQ(197274901u, rgb_hash);
174 #endif 174 #endif
175 } 175 }
176 176
177 TEST(YuvScaleTest, YV16) { 177 TEST(YuvScaleTest, YV16) {
178 // Read YV16 reference data from file. 178 // Read YV16 reference data from file.
179 FilePath yuv_url; 179 FilePath yuv_url;
180 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &yuv_url)); 180 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &yuv_url));
181 yuv_url = yuv_url.Append(FILE_PATH_LITERAL("media")) 181 yuv_url = yuv_url.Append(FILE_PATH_LITERAL("media"))
182 .Append(FILE_PATH_LITERAL("test")) 182 .Append(FILE_PATH_LITERAL("test"))
183 .Append(FILE_PATH_LITERAL("data")) 183 .Append(FILE_PATH_LITERAL("data"))
184 .Append(FILE_PATH_LITERAL("bali.yv16.640_360.yuv")); 184 .Append(FILE_PATH_LITERAL("bali.yv16.640_360.yuv"));
185 const size_t size_of_yuv = kWidth * kHeight * 16 / 8; // 16 bpp. 185 const size_t size_of_yuv = kWidth * kHeight * 16 / 8; // 16 bpp.
186 uint8* yuv_bytes = new uint8[size_of_yuv]; 186 scoped_array<uint8> yuv_bytes(new uint8[size_of_yuv]);
187 EXPECT_EQ(static_cast<int>(size_of_yuv), 187 EXPECT_EQ(static_cast<int>(size_of_yuv),
188 file_util::ReadFile(yuv_url, 188 file_util::ReadFile(yuv_url,
189 reinterpret_cast<char*>(yuv_bytes), 189 reinterpret_cast<char*>(yuv_bytes.get()),
190 static_cast<int>(size_of_yuv))); 190 static_cast<int>(size_of_yuv)));
191 191
192 // Scale a frame of YUV to 32 bit ARGB. 192 // Scale a frame of YUV to 32 bit ARGB.
193 const size_t size_of_rgb_scaled = kScaledWidth * kScaledHeight * kBpp; 193 const size_t size_of_rgb_scaled = kScaledWidth * kScaledHeight * kBpp;
194 uint8* rgb_scaled_bytes = new uint8[size_of_rgb_scaled]; 194 scoped_array<uint8> rgb_scaled_bytes(new uint8[size_of_rgb_scaled]);
195 195
196 media::ScaleYUVToRGB32(yuv_bytes, // Y plane 196 media::ScaleYUVToRGB32(yuv_bytes.get(), // Y
197 yuv_bytes + kWidth * kHeight, // U plane 197 yuv_bytes.get() + kWidth * kHeight, // U
198 yuv_bytes + kWidth * kHeight * 3 / 2, // V plane 198 yuv_bytes.get() + kWidth * kHeight * 3 / 2, // V
199 rgb_scaled_bytes, // Rgb output 199 rgb_scaled_bytes.get(), // Rgb output
200 kWidth, kHeight, // Dimensions 200 kWidth, kHeight, // Dimensions
201 kScaledWidth, kScaledHeight, // Dimensions 201 kScaledWidth, kScaledHeight, // Dimensions
202 kWidth, // YStride 202 kWidth, // YStride
203 kWidth / 2, // UvStride 203 kWidth / 2, // UvStride
204 kScaledWidth * kBpp, // RgbStride 204 kScaledWidth * kBpp, // RgbStride
205 media::YV16, 205 media::YV16,
206 media::ROTATE_0); 206 media::ROTATE_0);
207 207
208 unsigned int rgb_hash = hash(rgb_scaled_bytes, size_of_rgb_scaled); 208 unsigned int rgb_hash = hash(rgb_scaled_bytes.get(), size_of_rgb_scaled);
209 209
210 // To get this hash value, run once and examine the following EXPECT_EQ. 210 // To get this hash value, run once and examine the following EXPECT_EQ.
211 // Then plug new hash value into EXPECT_EQ statements. 211 // Then plug new hash value into EXPECT_EQ statements.
212 212
213 // TODO(fbarchard): Make reference code mimic MMX exactly 213 // TODO(fbarchard): Make reference code mimic MMX exactly
214 #if USE_MMX 214 #if USE_MMX
215 EXPECT_EQ(974965419u, rgb_hash); 215 EXPECT_EQ(974965419u, rgb_hash);
216 #else 216 #else
217 EXPECT_EQ(2946450771u, rgb_hash); 217 EXPECT_EQ(2946450771u, rgb_hash);
218 #endif 218 #endif
(...skipping 28 matching lines...) Expand all
247 1, 1, // Dimensions 247 1, 1, // Dimensions
248 0, // YStride 248 0, // YStride
249 0, // UVStride 249 0, // UVStride
250 0, // RGBStride 250 0, // RGBStride
251 media::YV12); 251 media::YV12);
252 252
253 int expected_test = memcmp(rgb, expected, sizeof(expected)); 253 int expected_test = memcmp(rgb, expected, sizeof(expected));
254 EXPECT_EQ(0, expected_test); 254 EXPECT_EQ(0, expected_test);
255 } 255 }
256 256
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