blob: 35c28eafd5c29997254cc06a90934dab4b578491 [file] [log] [blame]
Yaowu Xuc953aea2012-08-30 13:43:15 -07001/*
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Yaowu Xuc953aea2012-08-30 13:43:15 -07003 *
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07004 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10*/
Jingning Han097d59c2015-07-29 14:51:36 -070011
Tom Finegan7a07ece2017-02-07 17:14:05 -080012#include "third_party/googletest/src/googletest/include/gtest/gtest.h"
Jingning Han097d59c2015-07-29 14:51:36 -070013
John Koleszar706cafe2013-01-18 11:51:12 -080014#include "test/codec_factory.h"
Yaowu Xuc953aea2012-08-30 13:43:15 -070015#include "test/decode_test_driver.h"
James Zerneebb6482012-11-27 13:08:05 -080016#include "test/register_state_check.h"
Yunqing Wang15dffcf2012-10-04 12:59:36 -070017#include "test/video_source.h"
Yaowu Xuc953aea2012-08-30 13:43:15 -070018
Yaowu Xuc27fc142016-08-22 16:08:15 -070019namespace libaom_test {
Yaowu Xuc953aea2012-08-30 13:43:15 -070020
Jim Bankoski96727b92014-06-23 08:37:18 -070021const char kVP8Name[] = "WebM Project VP8";
Peter de Rivaz105fa6d2016-09-27 15:24:03 +010022const char kAV1Name[] = "AOMedia Project AV1 Decoder";
Jim Bankoski96727b92014-06-23 08:37:18 -070023
Yaowu Xuf883b422016-08-30 14:01:10 -070024aom_codec_err_t Decoder::PeekStream(const uint8_t *cxdata, size_t size,
25 aom_codec_stream_info_t *stream_info) {
26 return aom_codec_peek_stream_info(
clang-format3a826f12016-08-11 17:46:05 -070027 CodecInterface(), cxdata, static_cast<unsigned int>(size), stream_info);
Jim Bankoski96727b92014-06-23 08:37:18 -070028}
29
Yaowu Xuf883b422016-08-30 14:01:10 -070030aom_codec_err_t Decoder::DecodeFrame(const uint8_t *cxdata, size_t size) {
hkuang5e7242d2014-06-23 14:59:20 -070031 return DecodeFrame(cxdata, size, NULL);
32}
33
Yaowu Xuf883b422016-08-30 14:01:10 -070034aom_codec_err_t Decoder::DecodeFrame(const uint8_t *cxdata, size_t size,
hkuang5e7242d2014-06-23 14:59:20 -070035 void *user_priv) {
Yaowu Xuf883b422016-08-30 14:01:10 -070036 aom_codec_err_t res_dec;
John Koleszar771fc832013-03-27 10:41:29 -070037 InitOnce();
James Zern29e1b1a2014-07-09 21:02:02 -070038 API_REGISTER_STATE_CHECK(
Yaowu Xuf883b422016-08-30 14:01:10 -070039 res_dec = aom_codec_decode(
clang-format3a826f12016-08-11 17:46:05 -070040 &decoder_, cxdata, static_cast<unsigned int>(size), user_priv, 0));
Dmitry Kovalev26cec5c2013-03-15 18:21:55 -070041 return res_dec;
Yaowu Xuc953aea2012-08-30 13:43:15 -070042}
Yunqing Wang15dffcf2012-10-04 12:59:36 -070043
Deb Mukherjeec447a502014-07-15 01:54:29 -070044bool Decoder::IsVP8() const {
45 const char *codec_name = GetDecoderName();
46 return strncmp(kVP8Name, codec_name, sizeof(kVP8Name) - 1) == 0;
47}
48
Yaowu Xuf883b422016-08-30 14:01:10 -070049bool Decoder::IsAV1() const {
Yunqing Wang8e5e3382016-05-05 16:42:57 -070050 const char *codec_name = GetDecoderName();
Yaowu Xuf883b422016-08-30 14:01:10 -070051 return strncmp(kAV1Name, codec_name, sizeof(kAV1Name) - 1) == 0;
Yunqing Wang8e5e3382016-05-05 16:42:57 -070052}
53
Deb Mukherjeec447a502014-07-15 01:54:29 -070054void DecoderTest::HandlePeekResult(Decoder *const decoder,
55 CompressedVideoSource *video,
Yaowu Xuf883b422016-08-30 14:01:10 -070056 const aom_codec_err_t res_peek) {
Deb Mukherjeec447a502014-07-15 01:54:29 -070057 const bool is_vp8 = decoder->IsVP8();
58 if (is_vp8) {
59 /* Vp8's implementation of PeekStream returns an error if the frame you
Yaowu Xuf883b422016-08-30 14:01:10 -070060 * pass it is not a keyframe, so we only expect AOM_CODEC_OK on the first
Deb Mukherjeec447a502014-07-15 01:54:29 -070061 * frame, which must be a keyframe. */
62 if (video->frame_number() == 0)
Yaowu Xuf883b422016-08-30 14:01:10 -070063 ASSERT_EQ(AOM_CODEC_OK, res_peek) << "Peek return failed: "
64 << aom_codec_err_to_string(res_peek);
Deb Mukherjeec447a502014-07-15 01:54:29 -070065 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -070066 /* The Av1 implementation of PeekStream returns an error only if the
67 * data passed to it isn't a valid Av1 chunk. */
68 ASSERT_EQ(AOM_CODEC_OK, res_peek) << "Peek return failed: "
69 << aom_codec_err_to_string(res_peek);
Deb Mukherjeec447a502014-07-15 01:54:29 -070070 }
71}
72
hkuangc147cf32014-07-01 16:04:53 -070073void DecoderTest::RunLoop(CompressedVideoSource *video,
Yaowu Xuf883b422016-08-30 14:01:10 -070074 const aom_codec_dec_cfg_t &dec_cfg) {
James Zern3b96b762017-03-24 17:12:19 -070075 Decoder *const decoder = codec_->CreateDecoder(dec_cfg, flags_);
John Koleszar706cafe2013-01-18 11:51:12 -080076 ASSERT_TRUE(decoder != NULL);
Hangyu Kuang70500742014-07-31 19:04:35 -070077 bool end_of_file = false;
Yunqing Wang15dffcf2012-10-04 12:59:36 -070078
79 // Decode frames.
Hangyu Kuang70500742014-07-31 19:04:35 -070080 for (video->Begin(); !::testing::Test::HasFailure() && !end_of_file;
James Zern8f5b81f2014-06-21 19:04:12 -070081 video->Next()) {
Frank Galliganf9d69bd2013-12-09 17:07:10 -080082 PreDecodeFrameHook(*video, decoder);
Jim Bankoski96727b92014-06-23 08:37:18 -070083
Yaowu Xuf883b422016-08-30 14:01:10 -070084 aom_codec_stream_info_t stream_info;
Jim Bankoski96727b92014-06-23 08:37:18 -070085 stream_info.sz = sizeof(stream_info);
Jim Bankoski96727b92014-06-23 08:37:18 -070086
Hangyu Kuang70500742014-07-31 19:04:35 -070087 if (video->cxdata() != NULL) {
Yaowu Xuf883b422016-08-30 14:01:10 -070088 const aom_codec_err_t res_peek = decoder->PeekStream(
clang-format3a826f12016-08-11 17:46:05 -070089 video->cxdata(), video->frame_size(), &stream_info);
Hangyu Kuang70500742014-07-31 19:04:35 -070090 HandlePeekResult(decoder, video, res_peek);
91 ASSERT_FALSE(::testing::Test::HasFailure());
92
Yaowu Xuf883b422016-08-30 14:01:10 -070093 aom_codec_err_t res_dec =
clang-format3a826f12016-08-11 17:46:05 -070094 decoder->DecodeFrame(video->cxdata(), video->frame_size());
Urvang Joshid71a2312016-07-14 12:33:48 -070095 if (!HandleDecodeResult(res_dec, decoder)) break;
Hangyu Kuang70500742014-07-31 19:04:35 -070096 } else {
97 // Signal end of the file to the decoder.
Yaowu Xuf883b422016-08-30 14:01:10 -070098 const aom_codec_err_t res_dec = decoder->DecodeFrame(NULL, 0);
99 ASSERT_EQ(AOM_CODEC_OK, res_dec) << decoder->DecodeError();
Hangyu Kuang70500742014-07-31 19:04:35 -0700100 end_of_file = true;
101 }
Yunqing Wang15dffcf2012-10-04 12:59:36 -0700102
John Koleszar706cafe2013-01-18 11:51:12 -0800103 DxDataIterator dec_iter = decoder->GetDxData();
Yaowu Xuf883b422016-08-30 14:01:10 -0700104 const aom_image_t *img = NULL;
Yunqing Wang15dffcf2012-10-04 12:59:36 -0700105
106 // Get decompressed data
107 while ((img = dec_iter.Next()))
108 DecompressedFrameHook(*img, video->frame_number());
109 }
John Koleszar706cafe2013-01-18 11:51:12 -0800110 delete decoder;
Yunqing Wang15dffcf2012-10-04 12:59:36 -0700111}
hkuangc147cf32014-07-01 16:04:53 -0700112
113void DecoderTest::RunLoop(CompressedVideoSource *video) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700114 aom_codec_dec_cfg_t dec_cfg = aom_codec_dec_cfg_t();
hkuangc147cf32014-07-01 16:04:53 -0700115 RunLoop(video, dec_cfg);
116}
117
Yaowu Xuf883b422016-08-30 14:01:10 -0700118void DecoderTest::set_cfg(const aom_codec_dec_cfg_t &dec_cfg) {
hkuang93536072014-11-20 15:39:56 -0800119 memcpy(&cfg_, &dec_cfg, sizeof(cfg_));
120}
121
Yaowu Xuf883b422016-08-30 14:01:10 -0700122void DecoderTest::set_flags(const aom_codec_flags_t flags) { flags_ = flags; }
hkuang93536072014-11-20 15:39:56 -0800123
Yaowu Xuc27fc142016-08-22 16:08:15 -0700124} // namespace libaom_test