2015-01-27 21:26:28 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2014 The WebM project authors. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <cstdio>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <string>
|
|
|
|
#include "third_party/googletest/src/include/gtest/gtest.h"
|
|
|
|
#include "./vpx_config.h"
|
|
|
|
#include "test/codec_factory.h"
|
|
|
|
#include "test/decode_test_driver.h"
|
|
|
|
#include "test/ivf_video_source.h"
|
|
|
|
#include "test/md5_helper.h"
|
|
|
|
#include "test/util.h"
|
|
|
|
#if CONFIG_WEBM_IO
|
|
|
|
#include "test/webm_video_source.h"
|
|
|
|
#endif
|
|
|
|
#include "vpx_mem/vpx_mem.h"
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
using std::string;
|
|
|
|
|
|
|
|
#if CONFIG_WEBM_IO
|
|
|
|
|
2015-03-27 01:37:17 +01:00
|
|
|
struct PauseFileList {
|
2015-01-27 21:26:28 +01:00
|
|
|
const char *name;
|
|
|
|
// md5 sum for decoded frames which does not include skipped frames.
|
|
|
|
const char *expected_md5;
|
|
|
|
const int pause_frame_num;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Decodes |filename| with |num_threads|. Pause at the specified frame_num,
|
|
|
|
// seek to next key frame and then continue decoding until the end. Return
|
|
|
|
// the md5 of the decoded frames which does not include skipped frames.
|
2015-03-27 01:37:17 +01:00
|
|
|
string DecodeFileWithPause(const string &filename, int num_threads,
|
|
|
|
int pause_num) {
|
2015-01-27 21:26:28 +01:00
|
|
|
libvpx_test::WebMVideoSource video(filename);
|
|
|
|
video.Init();
|
|
|
|
int in_frames = 0;
|
|
|
|
int out_frames = 0;
|
|
|
|
|
2016-09-15 21:19:25 +02:00
|
|
|
vpx_codec_dec_cfg_t cfg = vpx_codec_dec_cfg_t();
|
2015-01-27 21:26:28 +01:00
|
|
|
cfg.threads = num_threads;
|
|
|
|
vpx_codec_flags_t flags = 0;
|
|
|
|
flags |= VPX_CODEC_USE_FRAME_THREADING;
|
2016-08-05 08:11:26 +02:00
|
|
|
libvpx_test::VP9Decoder decoder(cfg, flags);
|
2015-01-27 21:26:28 +01:00
|
|
|
|
|
|
|
libvpx_test::MD5 md5;
|
|
|
|
video.Begin();
|
|
|
|
|
|
|
|
do {
|
|
|
|
++in_frames;
|
|
|
|
const vpx_codec_err_t res =
|
|
|
|
decoder.DecodeFrame(video.cxdata(), video.frame_size());
|
|
|
|
if (res != VPX_CODEC_OK) {
|
|
|
|
EXPECT_EQ(VPX_CODEC_OK, res) << decoder.DecodeError();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pause at specified frame number.
|
|
|
|
if (in_frames == pause_num) {
|
|
|
|
// Flush the decoder and then seek to next key frame.
|
|
|
|
decoder.DecodeFrame(NULL, 0);
|
|
|
|
video.SeekToNextKeyFrame();
|
|
|
|
} else {
|
|
|
|
video.Next();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Flush the decoder at the end of the video.
|
2016-07-26 07:50:48 +02:00
|
|
|
if (!video.cxdata()) decoder.DecodeFrame(NULL, 0);
|
2015-01-27 21:26:28 +01:00
|
|
|
|
|
|
|
libvpx_test::DxDataIterator dec_iter = decoder.GetDxData();
|
|
|
|
const vpx_image_t *img;
|
|
|
|
|
|
|
|
// Get decompressed data
|
|
|
|
while ((img = dec_iter.Next())) {
|
|
|
|
++out_frames;
|
|
|
|
md5.Add(img);
|
|
|
|
}
|
|
|
|
} while (video.cxdata() != NULL);
|
|
|
|
|
2016-07-26 07:50:48 +02:00
|
|
|
EXPECT_EQ(in_frames, out_frames)
|
|
|
|
<< "Input frame count does not match output frame count";
|
2015-01-27 21:26:28 +01:00
|
|
|
|
|
|
|
return string(md5.Get());
|
|
|
|
}
|
|
|
|
|
2015-03-27 01:37:17 +01:00
|
|
|
void DecodeFilesWithPause(const PauseFileList files[]) {
|
|
|
|
for (const PauseFileList *iter = files; iter->name != NULL; ++iter) {
|
2015-01-27 21:26:28 +01:00
|
|
|
SCOPED_TRACE(iter->name);
|
|
|
|
for (int t = 2; t <= 8; ++t) {
|
|
|
|
EXPECT_EQ(iter->expected_md5,
|
2015-03-27 01:37:17 +01:00
|
|
|
DecodeFileWithPause(iter->name, t, iter->pause_frame_num))
|
2015-01-27 21:26:28 +01:00
|
|
|
<< "threads = " << t;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-16 21:56:04 +01:00
|
|
|
TEST(DISABLED_VP9MultiThreadedFrameParallel, PauseSeekResume) {
|
2015-01-27 21:26:28 +01:00
|
|
|
// vp90-2-07-frame_parallel-1.webm is a 40 frame video file with
|
|
|
|
// one key frame for every ten frames.
|
2015-03-27 01:37:17 +01:00
|
|
|
static const PauseFileList files[] = {
|
2016-07-26 07:50:48 +02:00
|
|
|
{ "vp90-2-07-frame_parallel-1.webm", "6ea7c3875d67252e7caf2bc6e75b36b1",
|
|
|
|
6 },
|
|
|
|
{ "vp90-2-07-frame_parallel-1.webm", "4bb634160c7356a8d7d4299b6dc83a45",
|
|
|
|
12 },
|
|
|
|
{ "vp90-2-07-frame_parallel-1.webm", "89772591e6ef461f9fa754f916c78ed8",
|
|
|
|
26 },
|
2015-03-27 01:37:17 +01:00
|
|
|
{ NULL, NULL, 0 },
|
2015-01-27 21:26:28 +01:00
|
|
|
};
|
2015-03-27 01:37:17 +01:00
|
|
|
DecodeFilesWithPause(files);
|
2015-01-27 21:26:28 +01:00
|
|
|
}
|
|
|
|
|
2015-03-27 01:37:17 +01:00
|
|
|
struct FileList {
|
2015-01-27 21:26:28 +01:00
|
|
|
const char *name;
|
|
|
|
// md5 sum for decoded frames which does not include corrupted frames.
|
|
|
|
const char *expected_md5;
|
|
|
|
// Expected number of decoded frames which does not include corrupted frames.
|
|
|
|
const int expected_frame_count;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Decodes |filename| with |num_threads|. Return the md5 of the decoded
|
|
|
|
// frames which does not include corrupted frames.
|
2015-03-27 01:37:17 +01:00
|
|
|
string DecodeFile(const string &filename, int num_threads,
|
|
|
|
int expected_frame_count) {
|
2015-01-27 21:26:28 +01:00
|
|
|
libvpx_test::WebMVideoSource video(filename);
|
|
|
|
video.Init();
|
|
|
|
|
|
|
|
vpx_codec_dec_cfg_t cfg = vpx_codec_dec_cfg_t();
|
|
|
|
cfg.threads = num_threads;
|
|
|
|
const vpx_codec_flags_t flags = VPX_CODEC_USE_FRAME_THREADING;
|
2016-08-05 08:11:26 +02:00
|
|
|
libvpx_test::VP9Decoder decoder(cfg, flags);
|
2015-01-27 21:26:28 +01:00
|
|
|
|
|
|
|
libvpx_test::MD5 md5;
|
|
|
|
video.Begin();
|
|
|
|
|
|
|
|
int out_frames = 0;
|
|
|
|
do {
|
|
|
|
const vpx_codec_err_t res =
|
|
|
|
decoder.DecodeFrame(video.cxdata(), video.frame_size());
|
|
|
|
// TODO(hkuang): frame parallel mode should return an error on corruption.
|
|
|
|
if (res != VPX_CODEC_OK) {
|
|
|
|
EXPECT_EQ(VPX_CODEC_OK, res) << decoder.DecodeError();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
video.Next();
|
|
|
|
|
|
|
|
// Flush the decoder at the end of the video.
|
2016-07-26 07:50:48 +02:00
|
|
|
if (!video.cxdata()) decoder.DecodeFrame(NULL, 0);
|
2015-01-27 21:26:28 +01:00
|
|
|
|
|
|
|
libvpx_test::DxDataIterator dec_iter = decoder.GetDxData();
|
|
|
|
const vpx_image_t *img;
|
|
|
|
|
|
|
|
// Get decompressed data
|
|
|
|
while ((img = dec_iter.Next())) {
|
|
|
|
++out_frames;
|
|
|
|
md5.Add(img);
|
|
|
|
}
|
|
|
|
} while (video.cxdata() != NULL);
|
|
|
|
|
2016-07-26 07:50:48 +02:00
|
|
|
EXPECT_EQ(expected_frame_count, out_frames)
|
|
|
|
<< "Input frame count does not match expected output frame count";
|
2015-01-27 21:26:28 +01:00
|
|
|
|
|
|
|
return string(md5.Get());
|
|
|
|
}
|
|
|
|
|
2015-03-27 01:37:17 +01:00
|
|
|
void DecodeFiles(const FileList files[]) {
|
|
|
|
for (const FileList *iter = files; iter->name != NULL; ++iter) {
|
2015-01-27 21:26:28 +01:00
|
|
|
SCOPED_TRACE(iter->name);
|
|
|
|
for (int t = 2; t <= 8; ++t) {
|
|
|
|
EXPECT_EQ(iter->expected_md5,
|
2015-03-27 01:37:17 +01:00
|
|
|
DecodeFile(iter->name, t, iter->expected_frame_count))
|
2015-01-27 21:26:28 +01:00
|
|
|
<< "threads = " << t;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-16 21:56:04 +01:00
|
|
|
TEST(DISABLED_VP9MultiThreadedFrameParallel, InvalidFileTest) {
|
2015-03-27 01:37:17 +01:00
|
|
|
static const FileList files[] = {
|
2015-01-27 21:26:28 +01:00
|
|
|
// invalid-vp90-2-07-frame_parallel-1.webm is a 40 frame video file with
|
|
|
|
// one key frame for every ten frames. The 11th frame has corrupted data.
|
|
|
|
{ "invalid-vp90-2-07-frame_parallel-1.webm",
|
2015-03-27 01:37:17 +01:00
|
|
|
"0549d0f45f60deaef8eb708e6c0eb6cb", 30 },
|
2015-01-27 21:26:28 +01:00
|
|
|
// invalid-vp90-2-07-frame_parallel-2.webm is a 40 frame video file with
|
|
|
|
// one key frame for every ten frames. The 1st and 31st frames have
|
|
|
|
// corrupted data.
|
|
|
|
{ "invalid-vp90-2-07-frame_parallel-2.webm",
|
2015-03-27 01:37:17 +01:00
|
|
|
"6a1f3cf6f9e7a364212fadb9580d525e", 20 },
|
2015-01-27 21:26:28 +01:00
|
|
|
// invalid-vp90-2-07-frame_parallel-3.webm is a 40 frame video file with
|
|
|
|
// one key frame for every ten frames. The 5th and 13th frames have
|
|
|
|
// corrupted data.
|
|
|
|
{ "invalid-vp90-2-07-frame_parallel-3.webm",
|
2015-03-27 01:37:17 +01:00
|
|
|
"8256544308de926b0681e04685b98677", 27 },
|
|
|
|
{ NULL, NULL, 0 },
|
2015-01-27 21:26:28 +01:00
|
|
|
};
|
2015-03-27 01:37:17 +01:00
|
|
|
DecodeFiles(files);
|
2015-01-27 21:26:28 +01:00
|
|
|
}
|
|
|
|
|
2017-02-16 21:56:04 +01:00
|
|
|
TEST(DISABLED_VP9MultiThreadedFrameParallel, ValidFileTest) {
|
2015-03-27 01:37:17 +01:00
|
|
|
static const FileList files[] = {
|
|
|
|
#if CONFIG_VP9_HIGHBITDEPTH
|
2016-07-26 07:50:48 +02:00
|
|
|
{ "vp92-2-20-10bit-yuv420.webm", "a16b99df180c584e8db2ffeda987d293", 10 },
|
2015-03-27 01:37:17 +01:00
|
|
|
#endif
|
|
|
|
{ NULL, NULL, 0 },
|
|
|
|
};
|
|
|
|
DecodeFiles(files);
|
|
|
|
}
|
2015-01-27 21:26:28 +01:00
|
|
|
#endif // CONFIG_WEBM_IO
|
|
|
|
} // namespace
|