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

Side by Side Diff: source/libvpx/test/external_frame_buffer_test.cc

Issue 111463005: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 7 years 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 | « source/libvpx/test/error_resilience_test.cc ('k') | source/libvpx/test/fdct4x4_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2013 The WebM project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include <string>
12
13 #include "test/codec_factory.h"
14 #include "test/decode_test_driver.h"
15 #include "test/ivf_video_source.h"
16 #include "test/md5_helper.h"
17 #include "test/test_vectors.h"
18 #include "test/util.h"
19 #include "test/webm_video_source.h"
20
21 namespace {
22
23 const int kVideoNameParam = 1;
24 const char kVP9TestFile[] = "vp90-2-02-size-lf-1920x1080.webm";
25
26 // Callback used by libvpx to request the application to allocate a frame
27 // buffer of at least |new_size| in bytes.
28 int realloc_vp9_frame_buffer(void *user_priv, size_t new_size,
29 vpx_codec_frame_buffer_t *fb) {
30 (void)user_priv;
31 if (fb == NULL)
32 return -1;
33
34 delete [] fb->data;
35 fb->data = new uint8_t[new_size];
36 fb->size = new_size;
37 return 0;
38 }
39
40 // Callback will not allocate data for frame buffer.
41 int zero_realloc_vp9_frame_buffer(void *user_priv, size_t new_size,
42 vpx_codec_frame_buffer_t *fb) {
43 (void)user_priv;
44 if (fb == NULL)
45 return -1;
46
47 delete [] fb->data;
48 fb->data = NULL;
49 fb->size = new_size;
50 return 0;
51 }
52
53 // Callback will allocate one less byte.
54 int one_less_byte_realloc_vp9_frame_buffer(void *user_priv, size_t new_size,
55 vpx_codec_frame_buffer_t *fb) {
56 (void)user_priv;
57 if (fb == NULL)
58 return -1;
59
60 delete [] fb->data;
61
62 const size_t error_size = new_size - 1;
63 fb->data = new uint8_t[error_size];
64 fb->size = error_size;
65 return 0;
66 }
67
68 // Class for testing passing in external frame buffers to libvpx.
69 class ExternalFrameBufferMD5Test
70 : public ::libvpx_test::DecoderTest,
71 public ::libvpx_test::CodecTestWithParam<const char*> {
72 protected:
73 ExternalFrameBufferMD5Test()
74 : DecoderTest(GET_PARAM(::libvpx_test::kCodecFactoryParam)),
75 md5_file_(NULL),
76 num_buffers_(0),
77 frame_buffers_(NULL) {}
78
79 virtual ~ExternalFrameBufferMD5Test() {
80 for (int i = 0; i < num_buffers_; ++i) {
81 delete [] frame_buffers_[i].data;
82 }
83 delete [] frame_buffers_;
84
85 if (md5_file_ != NULL)
86 fclose(md5_file_);
87 }
88
89 virtual void PreDecodeFrameHook(
90 const libvpx_test::CompressedVideoSource &video,
91 libvpx_test::Decoder *decoder) {
92 if (num_buffers_ > 0 && video.frame_number() == 0) {
93 // Have libvpx use frame buffers we create.
94 frame_buffers_ = new vpx_codec_frame_buffer_t[num_buffers_];
95 memset(frame_buffers_, 0, sizeof(frame_buffers_[0]) * num_buffers_);
96
97 ASSERT_EQ(VPX_CODEC_OK,
98 decoder->SetExternalFrameBuffers(
99 frame_buffers_, num_buffers_,
100 realloc_vp9_frame_buffer, NULL));
101 }
102 }
103
104 void OpenMD5File(const std::string &md5_file_name_) {
105 md5_file_ = libvpx_test::OpenTestDataFile(md5_file_name_);
106 ASSERT_TRUE(md5_file_ != NULL) << "Md5 file open failed. Filename: "
107 << md5_file_name_;
108 }
109
110 virtual void DecompressedFrameHook(const vpx_image_t &img,
111 const unsigned int frame_number) {
112 ASSERT_TRUE(md5_file_ != NULL);
113 char expected_md5[33];
114 char junk[128];
115
116 // Read correct md5 checksums.
117 const int res = fscanf(md5_file_, "%s %s", expected_md5, junk);
118 ASSERT_NE(EOF, res) << "Read md5 data failed";
119 expected_md5[32] = '\0';
120
121 ::libvpx_test::MD5 md5_res;
122 md5_res.Add(&img);
123 const char *const actual_md5 = md5_res.Get();
124
125 // Check md5 match.
126 ASSERT_STREQ(expected_md5, actual_md5)
127 << "Md5 checksums don't match: frame number = " << frame_number;
128 }
129
130 void set_num_buffers(int num_buffers) { num_buffers_ = num_buffers; }
131 int num_buffers() const { return num_buffers_; }
132
133 private:
134 FILE *md5_file_;
135 int num_buffers_;
136 vpx_codec_frame_buffer_t *frame_buffers_;
137 };
138
139 class ExternalFrameBufferTest : public ::testing::Test {
140 protected:
141 ExternalFrameBufferTest()
142 : video_(NULL),
143 decoder_(NULL),
144 num_buffers_(0),
145 frame_buffers_(NULL) {}
146
147 virtual void SetUp() {
148 video_ = new libvpx_test::WebMVideoSource(kVP9TestFile);
149 video_->Init();
150 video_->Begin();
151
152 vpx_codec_dec_cfg_t cfg = {0};
153 decoder_ = new libvpx_test::VP9Decoder(cfg, 0);
154 }
155
156 virtual void TearDown() {
157 for (int i = 0; i < num_buffers_; ++i) {
158 delete [] frame_buffers_[i].data;
159 }
160 delete [] frame_buffers_;
161 delete decoder_;
162 delete video_;
163 }
164
165 // Passes the external frame buffer information to libvpx.
166 vpx_codec_err_t SetExternalFrameBuffers(
167 int num_buffers,
168 vpx_realloc_frame_buffer_cb_fn_t cb) {
169 if (num_buffers > 0) {
170 num_buffers_ = num_buffers;
171
172 // Have libvpx use frame buffers we create.
173 frame_buffers_ = new vpx_codec_frame_buffer_t[num_buffers_];
174 memset(frame_buffers_, 0, sizeof(frame_buffers_[0]) * num_buffers_);
175 }
176
177 return decoder_->SetExternalFrameBuffers(frame_buffers_, num_buffers_,
178 cb, NULL);
179 }
180
181 // Pass Null frame buffer list to libvpx.
182 vpx_codec_err_t SetNullFrameBuffers(
183 int num_buffers,
184 vpx_realloc_frame_buffer_cb_fn_t cb) {
185 return decoder_->SetExternalFrameBuffers(NULL, num_buffers,
186 cb, NULL);
187 }
188
189 vpx_codec_err_t DecodeOneFrame() {
190 const vpx_codec_err_t res =
191 decoder_->DecodeFrame(video_->cxdata(), video_->frame_size());
192 if (res == VPX_CODEC_OK)
193 video_->Next();
194 return res;
195 }
196
197 vpx_codec_err_t DecodeRemainingFrames() {
198 for (; video_->cxdata(); video_->Next()) {
199 const vpx_codec_err_t res =
200 decoder_->DecodeFrame(video_->cxdata(), video_->frame_size());
201 if (res != VPX_CODEC_OK)
202 return res;
203
204 libvpx_test::DxDataIterator dec_iter = decoder_->GetDxData();
205 const vpx_image_t *img = NULL;
206
207 // Get decompressed data
208 while ((img = dec_iter.Next())) {
209 }
210 }
211 return VPX_CODEC_OK;
212 }
213
214 libvpx_test::WebMVideoSource *video_;
215 libvpx_test::VP9Decoder *decoder_;
216 int num_buffers_;
217 vpx_codec_frame_buffer_t *frame_buffers_;
218 };
219
220
221 // This test runs through the set of test vectors, and decodes them.
222 // Libvpx will call into the application to allocate a frame buffer when
223 // needed. The md5 checksums are computed for each frame in the video file.
224 // If md5 checksums match the correct md5 data, then the test is passed.
225 // Otherwise, the test failed.
226 TEST_P(ExternalFrameBufferMD5Test, ExtFBMD5Match) {
227 const std::string filename = GET_PARAM(kVideoNameParam);
228 libvpx_test::CompressedVideoSource *video = NULL;
229
230 // Number of buffers equals number of possible reference buffers(8), plus
231 // one working buffer, plus four jitter buffers.
232 const int num_buffers = 13;
233 set_num_buffers(num_buffers);
234
235 // Tell compiler we are not using kVP8TestVectors.
236 (void)libvpx_test::kVP8TestVectors;
237
238 // Open compressed video file.
239 if (filename.substr(filename.length() - 3, 3) == "ivf") {
240 video = new libvpx_test::IVFVideoSource(filename);
241 } else if (filename.substr(filename.length() - 4, 4) == "webm") {
242 video = new libvpx_test::WebMVideoSource(filename);
243 }
244 video->Init();
245
246 // Construct md5 file name.
247 const std::string md5_filename = filename + ".md5";
248 OpenMD5File(md5_filename);
249
250 // Decode frame, and check the md5 matching.
251 ASSERT_NO_FATAL_FAILURE(RunLoop(video));
252 delete video;
253 }
254
255 TEST_F(ExternalFrameBufferTest, EightFrameBuffers) {
256 // Minimum number of reference buffers for VP9 is 8.
257 const int num_buffers = 8;
258 ASSERT_EQ(VPX_CODEC_OK,
259 SetExternalFrameBuffers(num_buffers, realloc_vp9_frame_buffer));
260 ASSERT_EQ(VPX_CODEC_OK, DecodeRemainingFrames());
261 }
262
263 TEST_F(ExternalFrameBufferTest, EightJitterBuffers) {
264 // Number of buffers equals number of possible reference buffers(8), plus
265 // one working buffer, plus eight jitter buffers.
266 const int num_buffers = 17;
267 ASSERT_EQ(VPX_CODEC_OK,
268 SetExternalFrameBuffers(num_buffers, realloc_vp9_frame_buffer));
269 ASSERT_EQ(VPX_CODEC_OK, DecodeRemainingFrames());
270 }
271
272 TEST_F(ExternalFrameBufferTest, NotEnoughBuffers) {
273 // Minimum number of reference buffers for VP9 is 8.
274 const int num_buffers = 7;
275 ASSERT_EQ(VPX_CODEC_INVALID_PARAM,
276 SetExternalFrameBuffers(num_buffers, realloc_vp9_frame_buffer));
277 }
278
279 TEST_F(ExternalFrameBufferTest, NullFrameBufferList) {
280 // Number of buffers equals number of possible reference buffers(8), plus
281 // one working buffer, plus four jitter buffers.
282 const int num_buffers = 13;
283 ASSERT_EQ(VPX_CODEC_INVALID_PARAM,
284 SetNullFrameBuffers(num_buffers, realloc_vp9_frame_buffer));
285 }
286
287 TEST_F(ExternalFrameBufferTest, NullRealloc) {
288 // Number of buffers equals number of possible reference buffers(8), plus
289 // one working buffer, plus four jitter buffers.
290 const int num_buffers = 13;
291 ASSERT_EQ(VPX_CODEC_OK,
292 SetExternalFrameBuffers(num_buffers,
293 zero_realloc_vp9_frame_buffer));
294 ASSERT_EQ(VPX_CODEC_MEM_ERROR, DecodeOneFrame());
295 }
296
297 TEST_F(ExternalFrameBufferTest, ReallocOneLessByte) {
298 // Number of buffers equals number of possible reference buffers(8), plus
299 // one working buffer, plus four jitter buffers.
300 const int num_buffers = 13;
301 ASSERT_EQ(VPX_CODEC_OK,
302 SetExternalFrameBuffers(num_buffers,
303 one_less_byte_realloc_vp9_frame_buffer));
304 ASSERT_EQ(VPX_CODEC_MEM_ERROR, DecodeOneFrame());
305 }
306
307 VP9_INSTANTIATE_TEST_CASE(ExternalFrameBufferMD5Test,
308 ::testing::ValuesIn(libvpx_test::kVP9TestVectors));
309 } // namespace
OLDNEW
« no previous file with comments | « source/libvpx/test/error_resilience_test.cc ('k') | source/libvpx/test/fdct4x4_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698