blob: 4d5e8f7d4ad0d507941ea1826a2399c748fae79e [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.
Johann123e8a62017-12-28 14:40:49 -080010 */
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. */
Sebastien Alaiwan7d701682017-10-04 10:07:24 +020062 if (video->frame_number() == 0) {
clang-format4eafefe2017-09-04 12:51:20 -070063 ASSERT_EQ(AOM_CODEC_OK, res_peek)
64 << "Peek return failed: " << aom_codec_err_to_string(res_peek);
Sebastien Alaiwan7d701682017-10-04 10:07:24 +020065 }
Deb Mukherjeec447a502014-07-15 01:54:29 -070066 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -070067 /* The Av1 implementation of PeekStream returns an error only if the
68 * data passed to it isn't a valid Av1 chunk. */
clang-format4eafefe2017-09-04 12:51:20 -070069 ASSERT_EQ(AOM_CODEC_OK, res_peek)
70 << "Peek return failed: " << aom_codec_err_to_string(res_peek);
Deb Mukherjeec447a502014-07-15 01:54:29 -070071 }
72}
73
hkuangc147cf32014-07-01 16:04:53 -070074void DecoderTest::RunLoop(CompressedVideoSource *video,
Yaowu Xuf883b422016-08-30 14:01:10 -070075 const aom_codec_dec_cfg_t &dec_cfg) {
James Zern3b96b762017-03-24 17:12:19 -070076 Decoder *const decoder = codec_->CreateDecoder(dec_cfg, flags_);
John Koleszar706cafe2013-01-18 11:51:12 -080077 ASSERT_TRUE(decoder != NULL);
Hangyu Kuang70500742014-07-31 19:04:35 -070078 bool end_of_file = false;
Yunqing Wang15dffcf2012-10-04 12:59:36 -070079
80 // Decode frames.
Hangyu Kuang70500742014-07-31 19:04:35 -070081 for (video->Begin(); !::testing::Test::HasFailure() && !end_of_file;
James Zern8f5b81f2014-06-21 19:04:12 -070082 video->Next()) {
Frank Galliganf9d69bd2013-12-09 17:07:10 -080083 PreDecodeFrameHook(*video, decoder);
Jim Bankoski96727b92014-06-23 08:37:18 -070084
Yaowu Xuf883b422016-08-30 14:01:10 -070085 aom_codec_stream_info_t stream_info;
Hangyu Kuang70500742014-07-31 19:04:35 -070086 if (video->cxdata() != NULL) {
Yaowu Xuf883b422016-08-30 14:01:10 -070087 const aom_codec_err_t res_peek = decoder->PeekStream(
clang-format3a826f12016-08-11 17:46:05 -070088 video->cxdata(), video->frame_size(), &stream_info);
Hangyu Kuang70500742014-07-31 19:04:35 -070089 HandlePeekResult(decoder, video, res_peek);
90 ASSERT_FALSE(::testing::Test::HasFailure());
91
Yaowu Xuf883b422016-08-30 14:01:10 -070092 aom_codec_err_t res_dec =
clang-format3a826f12016-08-11 17:46:05 -070093 decoder->DecodeFrame(video->cxdata(), video->frame_size());
Urvang Joshid71a2312016-07-14 12:33:48 -070094 if (!HandleDecodeResult(res_dec, decoder)) break;
Hangyu Kuang70500742014-07-31 19:04:35 -070095 } else {
96 // Signal end of the file to the decoder.
Yaowu Xuf883b422016-08-30 14:01:10 -070097 const aom_codec_err_t res_dec = decoder->DecodeFrame(NULL, 0);
98 ASSERT_EQ(AOM_CODEC_OK, res_dec) << decoder->DecodeError();
Hangyu Kuang70500742014-07-31 19:04:35 -070099 end_of_file = true;
100 }
Yunqing Wang15dffcf2012-10-04 12:59:36 -0700101
John Koleszar706cafe2013-01-18 11:51:12 -0800102 DxDataIterator dec_iter = decoder->GetDxData();
Yaowu Xuf883b422016-08-30 14:01:10 -0700103 const aom_image_t *img = NULL;
Yunqing Wang15dffcf2012-10-04 12:59:36 -0700104
105 // Get decompressed data
106 while ((img = dec_iter.Next()))
107 DecompressedFrameHook(*img, video->frame_number());
108 }
John Koleszar706cafe2013-01-18 11:51:12 -0800109 delete decoder;
Yunqing Wang15dffcf2012-10-04 12:59:36 -0700110}
hkuangc147cf32014-07-01 16:04:53 -0700111
112void DecoderTest::RunLoop(CompressedVideoSource *video) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700113 aom_codec_dec_cfg_t dec_cfg = aom_codec_dec_cfg_t();
hkuangc147cf32014-07-01 16:04:53 -0700114 RunLoop(video, dec_cfg);
115}
116
Yaowu Xuf883b422016-08-30 14:01:10 -0700117void DecoderTest::set_cfg(const aom_codec_dec_cfg_t &dec_cfg) {
hkuang93536072014-11-20 15:39:56 -0800118 memcpy(&cfg_, &dec_cfg, sizeof(cfg_));
119}
120
Yaowu Xuf883b422016-08-30 14:01:10 -0700121void DecoderTest::set_flags(const aom_codec_flags_t flags) { flags_ = flags; }
hkuang93536072014-11-20 15:39:56 -0800122
Yaowu Xuc27fc142016-08-22 16:08:15 -0700123} // namespace libaom_test