2 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
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.
12 #include "third_party/googletest/src/googletest/include/gtest/gtest.h"
14 #include "test/codec_factory.h"
15 #include "test/decode_test_driver.h"
16 #include "test/register_state_check.h"
17 #include "test/video_source.h"
19 namespace libaom_test
{
21 const char kAV1Name
[] = "AOMedia Project AV1 Decoder";
23 aom_codec_err_t
Decoder::PeekStream(const uint8_t *cxdata
, size_t size
,
24 aom_codec_stream_info_t
*stream_info
) {
25 return aom_codec_peek_stream_info(CodecInterface(), cxdata
, size
,
29 aom_codec_err_t
Decoder::DecodeFrame(const uint8_t *cxdata
, size_t size
) {
30 return DecodeFrame(cxdata
, size
, NULL
);
33 aom_codec_err_t
Decoder::DecodeFrame(const uint8_t *cxdata
, size_t size
,
35 aom_codec_err_t res_dec
;
37 API_REGISTER_STATE_CHECK(
38 res_dec
= aom_codec_decode(&decoder_
, cxdata
, size
, user_priv
));
42 bool Decoder::IsAV1() const {
43 const char *codec_name
= GetDecoderName();
44 return strncmp(kAV1Name
, codec_name
, sizeof(kAV1Name
) - 1) == 0;
47 void DecoderTest::HandlePeekResult(Decoder
*const /*decoder*/,
48 CompressedVideoSource
* /*video*/,
49 const aom_codec_err_t res_peek
) {
50 /* The Av1 implementation of PeekStream returns an error only if the
51 * data passed to it isn't a valid Av1 chunk. */
52 ASSERT_EQ(AOM_CODEC_OK
, res_peek
)
53 << "Peek return failed: " << aom_codec_err_to_string(res_peek
);
56 void DecoderTest::RunLoop(CompressedVideoSource
*video
,
57 const aom_codec_dec_cfg_t
&dec_cfg
) {
58 Decoder
*const decoder
= codec_
->CreateDecoder(dec_cfg
, flags_
);
59 ASSERT_TRUE(decoder
!= NULL
);
60 bool end_of_file
= false;
61 bool peeked_stream
= false;
64 for (video
->Begin(); !::testing::Test::HasFailure() && !end_of_file
;
66 PreDecodeFrameHook(*video
, decoder
);
68 aom_codec_stream_info_t stream_info
;
69 stream_info
.is_annexb
= 0;
71 if (video
->cxdata() != NULL
) {
73 // TODO(yaowu): PeekStream returns error for non-sequence_header_obu,
74 // therefore should only be tried once per sequence, this shall be fixed
75 // once PeekStream is updated to properly operate on other obus.
76 const aom_codec_err_t res_peek
= decoder
->PeekStream(
77 video
->cxdata(), video
->frame_size(), &stream_info
);
78 HandlePeekResult(decoder
, video
, res_peek
);
79 ASSERT_FALSE(::testing::Test::HasFailure());
83 aom_codec_err_t res_dec
=
84 decoder
->DecodeFrame(video
->cxdata(), video
->frame_size());
85 if (!HandleDecodeResult(res_dec
, *video
, decoder
)) break;
87 // Signal end of the file to the decoder.
88 const aom_codec_err_t res_dec
= decoder
->DecodeFrame(NULL
, 0);
89 ASSERT_EQ(AOM_CODEC_OK
, res_dec
) << decoder
->DecodeError();
93 DxDataIterator dec_iter
= decoder
->GetDxData();
94 const aom_image_t
*img
= NULL
;
96 // Get decompressed data
97 while (!::testing::Test::HasFailure() && (img
= dec_iter
.Next()))
98 DecompressedFrameHook(*img
, video
->frame_number());
103 void DecoderTest::RunLoop(CompressedVideoSource
*video
) {
104 aom_codec_dec_cfg_t dec_cfg
= aom_codec_dec_cfg_t();
105 RunLoop(video
, dec_cfg
);
108 void DecoderTest::set_cfg(const aom_codec_dec_cfg_t
&dec_cfg
) {
109 memcpy(&cfg_
, &dec_cfg
, sizeof(cfg_
));
112 void DecoderTest::set_flags(const aom_codec_flags_t flags
) { flags_
= flags
; }
114 } // namespace libaom_test