Yaowu Xu | c953aea | 2012-08-30 13:43:15 -0700 | [diff] [blame] | 1 | /* |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
Yaowu Xu | c953aea | 2012-08-30 13:43:15 -0700 | [diff] [blame] | 3 | * |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 4 | * 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. |
Johann | 123e8a6 | 2017-12-28 14:40:49 -0800 | [diff] [blame^] | 10 | */ |
Jingning Han | 097d59c | 2015-07-29 14:51:36 -0700 | [diff] [blame] | 11 | |
Tom Finegan | 7a07ece | 2017-02-07 17:14:05 -0800 | [diff] [blame] | 12 | #include "third_party/googletest/src/googletest/include/gtest/gtest.h" |
Jingning Han | 097d59c | 2015-07-29 14:51:36 -0700 | [diff] [blame] | 13 | |
John Koleszar | 706cafe | 2013-01-18 11:51:12 -0800 | [diff] [blame] | 14 | #include "test/codec_factory.h" |
Yaowu Xu | c953aea | 2012-08-30 13:43:15 -0700 | [diff] [blame] | 15 | #include "test/decode_test_driver.h" |
James Zern | eebb648 | 2012-11-27 13:08:05 -0800 | [diff] [blame] | 16 | #include "test/register_state_check.h" |
Yunqing Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 17 | #include "test/video_source.h" |
Yaowu Xu | c953aea | 2012-08-30 13:43:15 -0700 | [diff] [blame] | 18 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 19 | namespace libaom_test { |
Yaowu Xu | c953aea | 2012-08-30 13:43:15 -0700 | [diff] [blame] | 20 | |
Jim Bankoski | 96727b9 | 2014-06-23 08:37:18 -0700 | [diff] [blame] | 21 | const char kVP8Name[] = "WebM Project VP8"; |
Peter de Rivaz | 105fa6d | 2016-09-27 15:24:03 +0100 | [diff] [blame] | 22 | const char kAV1Name[] = "AOMedia Project AV1 Decoder"; |
Jim Bankoski | 96727b9 | 2014-06-23 08:37:18 -0700 | [diff] [blame] | 23 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 24 | aom_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-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 27 | CodecInterface(), cxdata, static_cast<unsigned int>(size), stream_info); |
Jim Bankoski | 96727b9 | 2014-06-23 08:37:18 -0700 | [diff] [blame] | 28 | } |
| 29 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 30 | aom_codec_err_t Decoder::DecodeFrame(const uint8_t *cxdata, size_t size) { |
hkuang | 5e7242d | 2014-06-23 14:59:20 -0700 | [diff] [blame] | 31 | return DecodeFrame(cxdata, size, NULL); |
| 32 | } |
| 33 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 34 | aom_codec_err_t Decoder::DecodeFrame(const uint8_t *cxdata, size_t size, |
hkuang | 5e7242d | 2014-06-23 14:59:20 -0700 | [diff] [blame] | 35 | void *user_priv) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 36 | aom_codec_err_t res_dec; |
John Koleszar | 771fc83 | 2013-03-27 10:41:29 -0700 | [diff] [blame] | 37 | InitOnce(); |
James Zern | 29e1b1a | 2014-07-09 21:02:02 -0700 | [diff] [blame] | 38 | API_REGISTER_STATE_CHECK( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 39 | res_dec = aom_codec_decode( |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 40 | &decoder_, cxdata, static_cast<unsigned int>(size), user_priv, 0)); |
Dmitry Kovalev | 26cec5c | 2013-03-15 18:21:55 -0700 | [diff] [blame] | 41 | return res_dec; |
Yaowu Xu | c953aea | 2012-08-30 13:43:15 -0700 | [diff] [blame] | 42 | } |
Yunqing Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 43 | |
Deb Mukherjee | c447a50 | 2014-07-15 01:54:29 -0700 | [diff] [blame] | 44 | bool Decoder::IsVP8() const { |
| 45 | const char *codec_name = GetDecoderName(); |
| 46 | return strncmp(kVP8Name, codec_name, sizeof(kVP8Name) - 1) == 0; |
| 47 | } |
| 48 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 49 | bool Decoder::IsAV1() const { |
Yunqing Wang | 8e5e338 | 2016-05-05 16:42:57 -0700 | [diff] [blame] | 50 | const char *codec_name = GetDecoderName(); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 51 | return strncmp(kAV1Name, codec_name, sizeof(kAV1Name) - 1) == 0; |
Yunqing Wang | 8e5e338 | 2016-05-05 16:42:57 -0700 | [diff] [blame] | 52 | } |
| 53 | |
Deb Mukherjee | c447a50 | 2014-07-15 01:54:29 -0700 | [diff] [blame] | 54 | void DecoderTest::HandlePeekResult(Decoder *const decoder, |
| 55 | CompressedVideoSource *video, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 56 | const aom_codec_err_t res_peek) { |
Deb Mukherjee | c447a50 | 2014-07-15 01:54:29 -0700 | [diff] [blame] | 57 | const bool is_vp8 = decoder->IsVP8(); |
| 58 | if (is_vp8) { |
| 59 | /* Vp8's implementation of PeekStream returns an error if the frame you |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 60 | * pass it is not a keyframe, so we only expect AOM_CODEC_OK on the first |
Deb Mukherjee | c447a50 | 2014-07-15 01:54:29 -0700 | [diff] [blame] | 61 | * frame, which must be a keyframe. */ |
Sebastien Alaiwan | 7d70168 | 2017-10-04 10:07:24 +0200 | [diff] [blame] | 62 | if (video->frame_number() == 0) { |
clang-format | 4eafefe | 2017-09-04 12:51:20 -0700 | [diff] [blame] | 63 | ASSERT_EQ(AOM_CODEC_OK, res_peek) |
| 64 | << "Peek return failed: " << aom_codec_err_to_string(res_peek); |
Sebastien Alaiwan | 7d70168 | 2017-10-04 10:07:24 +0200 | [diff] [blame] | 65 | } |
Deb Mukherjee | c447a50 | 2014-07-15 01:54:29 -0700 | [diff] [blame] | 66 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 67 | /* The Av1 implementation of PeekStream returns an error only if the |
| 68 | * data passed to it isn't a valid Av1 chunk. */ |
clang-format | 4eafefe | 2017-09-04 12:51:20 -0700 | [diff] [blame] | 69 | ASSERT_EQ(AOM_CODEC_OK, res_peek) |
| 70 | << "Peek return failed: " << aom_codec_err_to_string(res_peek); |
Deb Mukherjee | c447a50 | 2014-07-15 01:54:29 -0700 | [diff] [blame] | 71 | } |
| 72 | } |
| 73 | |
hkuang | c147cf3 | 2014-07-01 16:04:53 -0700 | [diff] [blame] | 74 | void DecoderTest::RunLoop(CompressedVideoSource *video, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 75 | const aom_codec_dec_cfg_t &dec_cfg) { |
James Zern | 3b96b76 | 2017-03-24 17:12:19 -0700 | [diff] [blame] | 76 | Decoder *const decoder = codec_->CreateDecoder(dec_cfg, flags_); |
John Koleszar | 706cafe | 2013-01-18 11:51:12 -0800 | [diff] [blame] | 77 | ASSERT_TRUE(decoder != NULL); |
Hangyu Kuang | 7050074 | 2014-07-31 19:04:35 -0700 | [diff] [blame] | 78 | bool end_of_file = false; |
Yunqing Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 79 | |
| 80 | // Decode frames. |
Hangyu Kuang | 7050074 | 2014-07-31 19:04:35 -0700 | [diff] [blame] | 81 | for (video->Begin(); !::testing::Test::HasFailure() && !end_of_file; |
James Zern | 8f5b81f | 2014-06-21 19:04:12 -0700 | [diff] [blame] | 82 | video->Next()) { |
Frank Galligan | f9d69bd | 2013-12-09 17:07:10 -0800 | [diff] [blame] | 83 | PreDecodeFrameHook(*video, decoder); |
Jim Bankoski | 96727b9 | 2014-06-23 08:37:18 -0700 | [diff] [blame] | 84 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 85 | aom_codec_stream_info_t stream_info; |
Hangyu Kuang | 7050074 | 2014-07-31 19:04:35 -0700 | [diff] [blame] | 86 | if (video->cxdata() != NULL) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 87 | const aom_codec_err_t res_peek = decoder->PeekStream( |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 88 | video->cxdata(), video->frame_size(), &stream_info); |
Hangyu Kuang | 7050074 | 2014-07-31 19:04:35 -0700 | [diff] [blame] | 89 | HandlePeekResult(decoder, video, res_peek); |
| 90 | ASSERT_FALSE(::testing::Test::HasFailure()); |
| 91 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 92 | aom_codec_err_t res_dec = |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 93 | decoder->DecodeFrame(video->cxdata(), video->frame_size()); |
Urvang Joshi | d71a231 | 2016-07-14 12:33:48 -0700 | [diff] [blame] | 94 | if (!HandleDecodeResult(res_dec, decoder)) break; |
Hangyu Kuang | 7050074 | 2014-07-31 19:04:35 -0700 | [diff] [blame] | 95 | } else { |
| 96 | // Signal end of the file to the decoder. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 97 | const aom_codec_err_t res_dec = decoder->DecodeFrame(NULL, 0); |
| 98 | ASSERT_EQ(AOM_CODEC_OK, res_dec) << decoder->DecodeError(); |
Hangyu Kuang | 7050074 | 2014-07-31 19:04:35 -0700 | [diff] [blame] | 99 | end_of_file = true; |
| 100 | } |
Yunqing Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 101 | |
John Koleszar | 706cafe | 2013-01-18 11:51:12 -0800 | [diff] [blame] | 102 | DxDataIterator dec_iter = decoder->GetDxData(); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 103 | const aom_image_t *img = NULL; |
Yunqing Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 104 | |
| 105 | // Get decompressed data |
| 106 | while ((img = dec_iter.Next())) |
| 107 | DecompressedFrameHook(*img, video->frame_number()); |
| 108 | } |
John Koleszar | 706cafe | 2013-01-18 11:51:12 -0800 | [diff] [blame] | 109 | delete decoder; |
Yunqing Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 110 | } |
hkuang | c147cf3 | 2014-07-01 16:04:53 -0700 | [diff] [blame] | 111 | |
| 112 | void DecoderTest::RunLoop(CompressedVideoSource *video) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 113 | aom_codec_dec_cfg_t dec_cfg = aom_codec_dec_cfg_t(); |
hkuang | c147cf3 | 2014-07-01 16:04:53 -0700 | [diff] [blame] | 114 | RunLoop(video, dec_cfg); |
| 115 | } |
| 116 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 117 | void DecoderTest::set_cfg(const aom_codec_dec_cfg_t &dec_cfg) { |
hkuang | 9353607 | 2014-11-20 15:39:56 -0800 | [diff] [blame] | 118 | memcpy(&cfg_, &dec_cfg, sizeof(cfg_)); |
| 119 | } |
| 120 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 121 | void DecoderTest::set_flags(const aom_codec_flags_t flags) { flags_ = flags; } |
hkuang | 9353607 | 2014-11-20 15:39:56 -0800 | [diff] [blame] | 122 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 123 | } // namespace libaom_test |