1*77c1e3ccSAndroid Build Coastguard Worker /*
2*77c1e3ccSAndroid Build Coastguard Worker * Copyright (c) 2019, Alliance for Open Media. All rights reserved.
3*77c1e3ccSAndroid Build Coastguard Worker *
4*77c1e3ccSAndroid Build Coastguard Worker * This source code is subject to the terms of the BSD 2 Clause License and
5*77c1e3ccSAndroid Build Coastguard Worker * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6*77c1e3ccSAndroid Build Coastguard Worker * was not distributed with this source code in the LICENSE file, you can
7*77c1e3ccSAndroid Build Coastguard Worker * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8*77c1e3ccSAndroid Build Coastguard Worker * Media Patent License 1.0 was not distributed with this source code in the
9*77c1e3ccSAndroid Build Coastguard Worker * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10*77c1e3ccSAndroid Build Coastguard Worker */
11*77c1e3ccSAndroid Build Coastguard Worker
12*77c1e3ccSAndroid Build Coastguard Worker #include "gtest/gtest.h"
13*77c1e3ccSAndroid Build Coastguard Worker
14*77c1e3ccSAndroid Build Coastguard Worker #include "aom/aom_codec.h"
15*77c1e3ccSAndroid Build Coastguard Worker #include "aom/aom_image.h"
16*77c1e3ccSAndroid Build Coastguard Worker #include "aom/internal/aom_image_internal.h"
17*77c1e3ccSAndroid Build Coastguard Worker #include "aom_scale/yv12config.h"
18*77c1e3ccSAndroid Build Coastguard Worker #include "test/codec_factory.h"
19*77c1e3ccSAndroid Build Coastguard Worker #include "test/encode_test_driver.h"
20*77c1e3ccSAndroid Build Coastguard Worker #include "test/i420_video_source.h"
21*77c1e3ccSAndroid Build Coastguard Worker #include "test/util.h"
22*77c1e3ccSAndroid Build Coastguard Worker #include "test/video_source.h"
23*77c1e3ccSAndroid Build Coastguard Worker
24*77c1e3ccSAndroid Build Coastguard Worker namespace {
25*77c1e3ccSAndroid Build Coastguard Worker const size_t kMetadataPayloadSizeT35 = 24;
26*77c1e3ccSAndroid Build Coastguard Worker // 0xB5 stands for the itut t35 metadata country code for the Unites States
27*77c1e3ccSAndroid Build Coastguard Worker const uint8_t kMetadataPayloadT35[kMetadataPayloadSizeT35] = {
28*77c1e3ccSAndroid Build Coastguard Worker 0xB5, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B,
29*77c1e3ccSAndroid Build Coastguard Worker 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17
30*77c1e3ccSAndroid Build Coastguard Worker };
31*77c1e3ccSAndroid Build Coastguard Worker
32*77c1e3ccSAndroid Build Coastguard Worker #if !CONFIG_REALTIME_ONLY
33*77c1e3ccSAndroid Build Coastguard Worker const size_t kMetadataPayloadSizeCll = 4;
34*77c1e3ccSAndroid Build Coastguard Worker const uint8_t kMetadataPayloadCll[kMetadataPayloadSizeCll] = { 0xB5, 0x01, 0x02,
35*77c1e3ccSAndroid Build Coastguard Worker 0x03 };
36*77c1e3ccSAndroid Build Coastguard Worker
37*77c1e3ccSAndroid Build Coastguard Worker const size_t kMetadataObuSizeT35 = 28;
38*77c1e3ccSAndroid Build Coastguard Worker const uint8_t kMetadataObuT35[kMetadataObuSizeT35] = {
39*77c1e3ccSAndroid Build Coastguard Worker 0x2A, 0x1A, 0x02, 0xB5, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
40*77c1e3ccSAndroid Build Coastguard Worker 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10,
41*77c1e3ccSAndroid Build Coastguard Worker 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x80
42*77c1e3ccSAndroid Build Coastguard Worker };
43*77c1e3ccSAndroid Build Coastguard Worker const size_t kMetadataObuSizeMdcv = 28;
44*77c1e3ccSAndroid Build Coastguard Worker const uint8_t kMetadataObuMdcv[kMetadataObuSizeMdcv] = {
45*77c1e3ccSAndroid Build Coastguard Worker 0x2A, 0x1A, 0x02, 0xB5, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
46*77c1e3ccSAndroid Build Coastguard Worker 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10,
47*77c1e3ccSAndroid Build Coastguard Worker 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x80
48*77c1e3ccSAndroid Build Coastguard Worker };
49*77c1e3ccSAndroid Build Coastguard Worker const size_t kMetadataObuSizeCll = 8;
50*77c1e3ccSAndroid Build Coastguard Worker const uint8_t kMetadataObuCll[kMetadataObuSizeCll] = { 0x2A, 0x06, 0x01, 0xB5,
51*77c1e3ccSAndroid Build Coastguard Worker 0x01, 0x02, 0x03, 0x80 };
52*77c1e3ccSAndroid Build Coastguard Worker
53*77c1e3ccSAndroid Build Coastguard Worker class MetadataEncodeTest
54*77c1e3ccSAndroid Build Coastguard Worker : public ::libaom_test::CodecTestWithParam<libaom_test::TestMode>,
55*77c1e3ccSAndroid Build Coastguard Worker public ::libaom_test::EncoderTest {
56*77c1e3ccSAndroid Build Coastguard Worker protected:
MetadataEncodeTest()57*77c1e3ccSAndroid Build Coastguard Worker MetadataEncodeTest() : EncoderTest(GET_PARAM(0)) {}
58*77c1e3ccSAndroid Build Coastguard Worker
59*77c1e3ccSAndroid Build Coastguard Worker ~MetadataEncodeTest() override = default;
60*77c1e3ccSAndroid Build Coastguard Worker
SetUp()61*77c1e3ccSAndroid Build Coastguard Worker void SetUp() override { InitializeConfig(GET_PARAM(1)); }
62*77c1e3ccSAndroid Build Coastguard Worker
PreEncodeFrameHook(::libaom_test::VideoSource * video,::libaom_test::Encoder *)63*77c1e3ccSAndroid Build Coastguard Worker void PreEncodeFrameHook(::libaom_test::VideoSource *video,
64*77c1e3ccSAndroid Build Coastguard Worker ::libaom_test::Encoder * /*encoder*/) override {
65*77c1e3ccSAndroid Build Coastguard Worker aom_image_t *current_frame = video->img();
66*77c1e3ccSAndroid Build Coastguard Worker if (current_frame) {
67*77c1e3ccSAndroid Build Coastguard Worker if (current_frame->metadata) aom_img_remove_metadata(current_frame);
68*77c1e3ccSAndroid Build Coastguard Worker ASSERT_EQ(aom_img_add_metadata(current_frame, OBU_METADATA_TYPE_ITUT_T35,
69*77c1e3ccSAndroid Build Coastguard Worker kMetadataPayloadT35, 0, AOM_MIF_ANY_FRAME),
70*77c1e3ccSAndroid Build Coastguard Worker -1);
71*77c1e3ccSAndroid Build Coastguard Worker ASSERT_EQ(aom_img_add_metadata(current_frame, OBU_METADATA_TYPE_ITUT_T35,
72*77c1e3ccSAndroid Build Coastguard Worker nullptr, kMetadataPayloadSizeT35,
73*77c1e3ccSAndroid Build Coastguard Worker AOM_MIF_ANY_FRAME),
74*77c1e3ccSAndroid Build Coastguard Worker -1);
75*77c1e3ccSAndroid Build Coastguard Worker ASSERT_EQ(aom_img_add_metadata(current_frame, OBU_METADATA_TYPE_ITUT_T35,
76*77c1e3ccSAndroid Build Coastguard Worker nullptr, 0, AOM_MIF_ANY_FRAME),
77*77c1e3ccSAndroid Build Coastguard Worker -1);
78*77c1e3ccSAndroid Build Coastguard Worker ASSERT_EQ(
79*77c1e3ccSAndroid Build Coastguard Worker aom_img_add_metadata(current_frame, OBU_METADATA_TYPE_ITUT_T35,
80*77c1e3ccSAndroid Build Coastguard Worker kMetadataPayloadT35, kMetadataPayloadSizeT35,
81*77c1e3ccSAndroid Build Coastguard Worker AOM_MIF_ANY_FRAME),
82*77c1e3ccSAndroid Build Coastguard Worker 0);
83*77c1e3ccSAndroid Build Coastguard Worker
84*77c1e3ccSAndroid Build Coastguard Worker ASSERT_EQ(
85*77c1e3ccSAndroid Build Coastguard Worker aom_img_add_metadata(current_frame, OBU_METADATA_TYPE_HDR_MDCV,
86*77c1e3ccSAndroid Build Coastguard Worker kMetadataPayloadT35, kMetadataPayloadSizeT35,
87*77c1e3ccSAndroid Build Coastguard Worker AOM_MIF_KEY_FRAME),
88*77c1e3ccSAndroid Build Coastguard Worker 0);
89*77c1e3ccSAndroid Build Coastguard Worker
90*77c1e3ccSAndroid Build Coastguard Worker ASSERT_EQ(
91*77c1e3ccSAndroid Build Coastguard Worker aom_img_add_metadata(current_frame, OBU_METADATA_TYPE_HDR_CLL,
92*77c1e3ccSAndroid Build Coastguard Worker kMetadataPayloadCll, kMetadataPayloadSizeCll,
93*77c1e3ccSAndroid Build Coastguard Worker AOM_MIF_KEY_FRAME),
94*77c1e3ccSAndroid Build Coastguard Worker 0);
95*77c1e3ccSAndroid Build Coastguard Worker }
96*77c1e3ccSAndroid Build Coastguard Worker }
97*77c1e3ccSAndroid Build Coastguard Worker
FramePktHook(const aom_codec_cx_pkt_t * pkt)98*77c1e3ccSAndroid Build Coastguard Worker void FramePktHook(const aom_codec_cx_pkt_t *pkt) override {
99*77c1e3ccSAndroid Build Coastguard Worker if (pkt->kind == AOM_CODEC_CX_FRAME_PKT) {
100*77c1e3ccSAndroid Build Coastguard Worker const size_t bitstream_size = pkt->data.frame.sz;
101*77c1e3ccSAndroid Build Coastguard Worker const uint8_t *bitstream =
102*77c1e3ccSAndroid Build Coastguard Worker static_cast<const uint8_t *>(pkt->data.frame.buf);
103*77c1e3ccSAndroid Build Coastguard Worker // look for valid metadatas in bitstream
104*77c1e3ccSAndroid Build Coastguard Worker bool itut_t35_metadata_found = false;
105*77c1e3ccSAndroid Build Coastguard Worker if (bitstream_size >= kMetadataObuSizeT35) {
106*77c1e3ccSAndroid Build Coastguard Worker for (size_t i = 0; i <= bitstream_size - kMetadataObuSizeT35; ++i) {
107*77c1e3ccSAndroid Build Coastguard Worker if (memcmp(bitstream + i, kMetadataObuT35, kMetadataObuSizeT35) ==
108*77c1e3ccSAndroid Build Coastguard Worker 0) {
109*77c1e3ccSAndroid Build Coastguard Worker itut_t35_metadata_found = true;
110*77c1e3ccSAndroid Build Coastguard Worker }
111*77c1e3ccSAndroid Build Coastguard Worker }
112*77c1e3ccSAndroid Build Coastguard Worker }
113*77c1e3ccSAndroid Build Coastguard Worker ASSERT_EQ(itut_t35_metadata_found, 1u);
114*77c1e3ccSAndroid Build Coastguard Worker
115*77c1e3ccSAndroid Build Coastguard Worker // Testing for HDR MDCV metadata
116*77c1e3ccSAndroid Build Coastguard Worker bool hdr_mdcv_metadata_found = false;
117*77c1e3ccSAndroid Build Coastguard Worker if (bitstream_size >= kMetadataObuSizeMdcv) {
118*77c1e3ccSAndroid Build Coastguard Worker for (size_t i = 0; i <= bitstream_size - kMetadataObuSizeMdcv; ++i) {
119*77c1e3ccSAndroid Build Coastguard Worker if (memcmp(bitstream + i, kMetadataObuMdcv, kMetadataObuSizeMdcv) ==
120*77c1e3ccSAndroid Build Coastguard Worker 0) {
121*77c1e3ccSAndroid Build Coastguard Worker hdr_mdcv_metadata_found = true;
122*77c1e3ccSAndroid Build Coastguard Worker }
123*77c1e3ccSAndroid Build Coastguard Worker }
124*77c1e3ccSAndroid Build Coastguard Worker }
125*77c1e3ccSAndroid Build Coastguard Worker ASSERT_TRUE(hdr_mdcv_metadata_found);
126*77c1e3ccSAndroid Build Coastguard Worker
127*77c1e3ccSAndroid Build Coastguard Worker // Testing for HDR CLL metadata
128*77c1e3ccSAndroid Build Coastguard Worker bool hdr_cll_metadata_found = false;
129*77c1e3ccSAndroid Build Coastguard Worker if (bitstream_size >= kMetadataObuSizeCll) {
130*77c1e3ccSAndroid Build Coastguard Worker for (size_t i = 0; i <= bitstream_size - kMetadataObuSizeCll; ++i) {
131*77c1e3ccSAndroid Build Coastguard Worker if (memcmp(bitstream + i, kMetadataObuCll, kMetadataObuSizeCll) ==
132*77c1e3ccSAndroid Build Coastguard Worker 0) {
133*77c1e3ccSAndroid Build Coastguard Worker hdr_cll_metadata_found = true;
134*77c1e3ccSAndroid Build Coastguard Worker }
135*77c1e3ccSAndroid Build Coastguard Worker }
136*77c1e3ccSAndroid Build Coastguard Worker }
137*77c1e3ccSAndroid Build Coastguard Worker ASSERT_TRUE(hdr_cll_metadata_found);
138*77c1e3ccSAndroid Build Coastguard Worker }
139*77c1e3ccSAndroid Build Coastguard Worker }
140*77c1e3ccSAndroid Build Coastguard Worker
DecompressedFrameHook(const aom_image_t & img,aom_codec_pts_t)141*77c1e3ccSAndroid Build Coastguard Worker void DecompressedFrameHook(const aom_image_t &img,
142*77c1e3ccSAndroid Build Coastguard Worker aom_codec_pts_t /*pts*/) override {
143*77c1e3ccSAndroid Build Coastguard Worker ASSERT_NE(img.metadata, nullptr);
144*77c1e3ccSAndroid Build Coastguard Worker
145*77c1e3ccSAndroid Build Coastguard Worker ASSERT_EQ(img.metadata->sz, 3u);
146*77c1e3ccSAndroid Build Coastguard Worker
147*77c1e3ccSAndroid Build Coastguard Worker for (size_t i = 0; i < img.metadata->sz - 1; ++i) {
148*77c1e3ccSAndroid Build Coastguard Worker ASSERT_EQ(kMetadataPayloadSizeT35, img.metadata->metadata_array[i]->sz);
149*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(
150*77c1e3ccSAndroid Build Coastguard Worker memcmp(kMetadataPayloadT35, img.metadata->metadata_array[i]->payload,
151*77c1e3ccSAndroid Build Coastguard Worker kMetadataPayloadSizeT35),
152*77c1e3ccSAndroid Build Coastguard Worker 0);
153*77c1e3ccSAndroid Build Coastguard Worker }
154*77c1e3ccSAndroid Build Coastguard Worker
155*77c1e3ccSAndroid Build Coastguard Worker ASSERT_EQ(kMetadataPayloadSizeCll, img.metadata->metadata_array[2]->sz);
156*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(
157*77c1e3ccSAndroid Build Coastguard Worker memcmp(kMetadataPayloadCll, img.metadata->metadata_array[2]->payload,
158*77c1e3ccSAndroid Build Coastguard Worker kMetadataPayloadSizeCll),
159*77c1e3ccSAndroid Build Coastguard Worker 0);
160*77c1e3ccSAndroid Build Coastguard Worker }
161*77c1e3ccSAndroid Build Coastguard Worker };
162*77c1e3ccSAndroid Build Coastguard Worker
TEST_P(MetadataEncodeTest,TestMetadataEncoding)163*77c1e3ccSAndroid Build Coastguard Worker TEST_P(MetadataEncodeTest, TestMetadataEncoding) {
164*77c1e3ccSAndroid Build Coastguard Worker ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
165*77c1e3ccSAndroid Build Coastguard Worker 30, 1, 0, 5);
166*77c1e3ccSAndroid Build Coastguard Worker init_flags_ = AOM_CODEC_USE_PSNR;
167*77c1e3ccSAndroid Build Coastguard Worker
168*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_w = 352;
169*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_h = 288;
170*77c1e3ccSAndroid Build Coastguard Worker
171*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_buf_initial_sz = 500;
172*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_buf_optimal_sz = 600;
173*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_buf_sz = 1000;
174*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_min_quantizer = 2;
175*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_max_quantizer = 56;
176*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_undershoot_pct = 50;
177*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_overshoot_pct = 50;
178*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_end_usage = AOM_CBR;
179*77c1e3ccSAndroid Build Coastguard Worker cfg_.kf_mode = AOM_KF_AUTO;
180*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_lag_in_frames = 1;
181*77c1e3ccSAndroid Build Coastguard Worker cfg_.kf_min_dist = cfg_.kf_max_dist = 3000;
182*77c1e3ccSAndroid Build Coastguard Worker // Enable dropped frames.
183*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_dropframe_thresh = 1;
184*77c1e3ccSAndroid Build Coastguard Worker // Disable error_resilience mode.
185*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_error_resilient = 0;
186*77c1e3ccSAndroid Build Coastguard Worker // Run at low bitrate.
187*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_target_bitrate = 40;
188*77c1e3ccSAndroid Build Coastguard Worker
189*77c1e3ccSAndroid Build Coastguard Worker ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
190*77c1e3ccSAndroid Build Coastguard Worker }
191*77c1e3ccSAndroid Build Coastguard Worker
192*77c1e3ccSAndroid Build Coastguard Worker AV1_INSTANTIATE_TEST_SUITE(MetadataEncodeTest,
193*77c1e3ccSAndroid Build Coastguard Worker ::testing::Values(::libaom_test::kOnePassGood));
194*77c1e3ccSAndroid Build Coastguard Worker #endif // !CONFIG_REALTIME_ONLY
195*77c1e3ccSAndroid Build Coastguard Worker } // namespace
196*77c1e3ccSAndroid Build Coastguard Worker
TEST(MetadataTest,MetadataAllocation)197*77c1e3ccSAndroid Build Coastguard Worker TEST(MetadataTest, MetadataAllocation) {
198*77c1e3ccSAndroid Build Coastguard Worker aom_metadata_t *metadata =
199*77c1e3ccSAndroid Build Coastguard Worker aom_img_metadata_alloc(OBU_METADATA_TYPE_ITUT_T35, kMetadataPayloadT35,
200*77c1e3ccSAndroid Build Coastguard Worker kMetadataPayloadSizeT35, AOM_MIF_ANY_FRAME);
201*77c1e3ccSAndroid Build Coastguard Worker ASSERT_NE(metadata, nullptr);
202*77c1e3ccSAndroid Build Coastguard Worker aom_img_metadata_free(metadata);
203*77c1e3ccSAndroid Build Coastguard Worker }
204*77c1e3ccSAndroid Build Coastguard Worker
TEST(MetadataTest,MetadataArrayAllocation)205*77c1e3ccSAndroid Build Coastguard Worker TEST(MetadataTest, MetadataArrayAllocation) {
206*77c1e3ccSAndroid Build Coastguard Worker aom_metadata_array_t *metadata_array = aom_img_metadata_array_alloc(2);
207*77c1e3ccSAndroid Build Coastguard Worker ASSERT_NE(metadata_array, nullptr);
208*77c1e3ccSAndroid Build Coastguard Worker
209*77c1e3ccSAndroid Build Coastguard Worker metadata_array->metadata_array[0] =
210*77c1e3ccSAndroid Build Coastguard Worker aom_img_metadata_alloc(OBU_METADATA_TYPE_ITUT_T35, kMetadataPayloadT35,
211*77c1e3ccSAndroid Build Coastguard Worker kMetadataPayloadSizeT35, AOM_MIF_ANY_FRAME);
212*77c1e3ccSAndroid Build Coastguard Worker metadata_array->metadata_array[1] =
213*77c1e3ccSAndroid Build Coastguard Worker aom_img_metadata_alloc(OBU_METADATA_TYPE_ITUT_T35, kMetadataPayloadT35,
214*77c1e3ccSAndroid Build Coastguard Worker kMetadataPayloadSizeT35, AOM_MIF_ANY_FRAME);
215*77c1e3ccSAndroid Build Coastguard Worker
216*77c1e3ccSAndroid Build Coastguard Worker aom_img_metadata_array_free(metadata_array);
217*77c1e3ccSAndroid Build Coastguard Worker }
218*77c1e3ccSAndroid Build Coastguard Worker
TEST(MetadataTest,AddMetadataToImage)219*77c1e3ccSAndroid Build Coastguard Worker TEST(MetadataTest, AddMetadataToImage) {
220*77c1e3ccSAndroid Build Coastguard Worker aom_image_t image;
221*77c1e3ccSAndroid Build Coastguard Worker image.metadata = nullptr;
222*77c1e3ccSAndroid Build Coastguard Worker
223*77c1e3ccSAndroid Build Coastguard Worker ASSERT_EQ(aom_img_add_metadata(&image, OBU_METADATA_TYPE_ITUT_T35,
224*77c1e3ccSAndroid Build Coastguard Worker kMetadataPayloadT35, kMetadataPayloadSizeT35,
225*77c1e3ccSAndroid Build Coastguard Worker AOM_MIF_ANY_FRAME),
226*77c1e3ccSAndroid Build Coastguard Worker 0);
227*77c1e3ccSAndroid Build Coastguard Worker aom_img_metadata_array_free(image.metadata);
228*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(aom_img_add_metadata(nullptr, OBU_METADATA_TYPE_ITUT_T35,
229*77c1e3ccSAndroid Build Coastguard Worker kMetadataPayloadT35, kMetadataPayloadSizeT35,
230*77c1e3ccSAndroid Build Coastguard Worker AOM_MIF_ANY_FRAME),
231*77c1e3ccSAndroid Build Coastguard Worker -1);
232*77c1e3ccSAndroid Build Coastguard Worker }
233*77c1e3ccSAndroid Build Coastguard Worker
TEST(MetadataTest,RemoveMetadataFromImage)234*77c1e3ccSAndroid Build Coastguard Worker TEST(MetadataTest, RemoveMetadataFromImage) {
235*77c1e3ccSAndroid Build Coastguard Worker aom_image_t image;
236*77c1e3ccSAndroid Build Coastguard Worker image.metadata = nullptr;
237*77c1e3ccSAndroid Build Coastguard Worker
238*77c1e3ccSAndroid Build Coastguard Worker ASSERT_EQ(aom_img_add_metadata(&image, OBU_METADATA_TYPE_ITUT_T35,
239*77c1e3ccSAndroid Build Coastguard Worker kMetadataPayloadT35, kMetadataPayloadSizeT35,
240*77c1e3ccSAndroid Build Coastguard Worker AOM_MIF_ANY_FRAME),
241*77c1e3ccSAndroid Build Coastguard Worker 0);
242*77c1e3ccSAndroid Build Coastguard Worker aom_img_remove_metadata(&image);
243*77c1e3ccSAndroid Build Coastguard Worker aom_img_remove_metadata(nullptr);
244*77c1e3ccSAndroid Build Coastguard Worker }
245*77c1e3ccSAndroid Build Coastguard Worker
TEST(MetadataTest,CopyMetadataToFrameBuffer)246*77c1e3ccSAndroid Build Coastguard Worker TEST(MetadataTest, CopyMetadataToFrameBuffer) {
247*77c1e3ccSAndroid Build Coastguard Worker YV12_BUFFER_CONFIG yvBuf;
248*77c1e3ccSAndroid Build Coastguard Worker yvBuf.metadata = nullptr;
249*77c1e3ccSAndroid Build Coastguard Worker
250*77c1e3ccSAndroid Build Coastguard Worker aom_metadata_array_t *metadata_array = aom_img_metadata_array_alloc(1);
251*77c1e3ccSAndroid Build Coastguard Worker ASSERT_NE(metadata_array, nullptr);
252*77c1e3ccSAndroid Build Coastguard Worker
253*77c1e3ccSAndroid Build Coastguard Worker metadata_array->metadata_array[0] =
254*77c1e3ccSAndroid Build Coastguard Worker aom_img_metadata_alloc(OBU_METADATA_TYPE_ITUT_T35, kMetadataPayloadT35,
255*77c1e3ccSAndroid Build Coastguard Worker kMetadataPayloadSizeT35, AOM_MIF_ANY_FRAME);
256*77c1e3ccSAndroid Build Coastguard Worker
257*77c1e3ccSAndroid Build Coastguard Worker // Metadata_array
258*77c1e3ccSAndroid Build Coastguard Worker int status = aom_copy_metadata_to_frame_buffer(&yvBuf, metadata_array);
259*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(status, 0);
260*77c1e3ccSAndroid Build Coastguard Worker status = aom_copy_metadata_to_frame_buffer(nullptr, metadata_array);
261*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(status, -1);
262*77c1e3ccSAndroid Build Coastguard Worker aom_img_metadata_array_free(metadata_array);
263*77c1e3ccSAndroid Build Coastguard Worker
264*77c1e3ccSAndroid Build Coastguard Worker // Metadata_array_2
265*77c1e3ccSAndroid Build Coastguard Worker aom_metadata_array_t *metadata_array_2 = aom_img_metadata_array_alloc(0);
266*77c1e3ccSAndroid Build Coastguard Worker ASSERT_NE(metadata_array_2, nullptr);
267*77c1e3ccSAndroid Build Coastguard Worker status = aom_copy_metadata_to_frame_buffer(&yvBuf, metadata_array_2);
268*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(status, -1);
269*77c1e3ccSAndroid Build Coastguard Worker aom_img_metadata_array_free(metadata_array_2);
270*77c1e3ccSAndroid Build Coastguard Worker
271*77c1e3ccSAndroid Build Coastguard Worker // YV12_BUFFER_CONFIG
272*77c1e3ccSAndroid Build Coastguard Worker status = aom_copy_metadata_to_frame_buffer(&yvBuf, nullptr);
273*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(status, -1);
274*77c1e3ccSAndroid Build Coastguard Worker aom_remove_metadata_from_frame_buffer(&yvBuf);
275*77c1e3ccSAndroid Build Coastguard Worker aom_remove_metadata_from_frame_buffer(nullptr);
276*77c1e3ccSAndroid Build Coastguard Worker }
277*77c1e3ccSAndroid Build Coastguard Worker
TEST(MetadataTest,GetMetadataFromImage)278*77c1e3ccSAndroid Build Coastguard Worker TEST(MetadataTest, GetMetadataFromImage) {
279*77c1e3ccSAndroid Build Coastguard Worker aom_image_t image;
280*77c1e3ccSAndroid Build Coastguard Worker image.metadata = nullptr;
281*77c1e3ccSAndroid Build Coastguard Worker
282*77c1e3ccSAndroid Build Coastguard Worker ASSERT_EQ(aom_img_add_metadata(&image, OBU_METADATA_TYPE_ITUT_T35,
283*77c1e3ccSAndroid Build Coastguard Worker kMetadataPayloadT35, kMetadataPayloadSizeT35,
284*77c1e3ccSAndroid Build Coastguard Worker AOM_MIF_ANY_FRAME),
285*77c1e3ccSAndroid Build Coastguard Worker 0);
286*77c1e3ccSAndroid Build Coastguard Worker
287*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(aom_img_get_metadata(nullptr, 0), nullptr);
288*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(aom_img_get_metadata(&image, 1u), nullptr);
289*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(aom_img_get_metadata(&image, 10u), nullptr);
290*77c1e3ccSAndroid Build Coastguard Worker
291*77c1e3ccSAndroid Build Coastguard Worker const aom_metadata_t *metadata = aom_img_get_metadata(&image, 0);
292*77c1e3ccSAndroid Build Coastguard Worker ASSERT_NE(metadata, nullptr);
293*77c1e3ccSAndroid Build Coastguard Worker ASSERT_EQ(metadata->sz, kMetadataPayloadSizeT35);
294*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(
295*77c1e3ccSAndroid Build Coastguard Worker memcmp(kMetadataPayloadT35, metadata->payload, kMetadataPayloadSizeT35),
296*77c1e3ccSAndroid Build Coastguard Worker 0);
297*77c1e3ccSAndroid Build Coastguard Worker
298*77c1e3ccSAndroid Build Coastguard Worker aom_img_metadata_array_free(image.metadata);
299*77c1e3ccSAndroid Build Coastguard Worker }
300*77c1e3ccSAndroid Build Coastguard Worker
TEST(MetadataTest,ReadMetadatasFromImage)301*77c1e3ccSAndroid Build Coastguard Worker TEST(MetadataTest, ReadMetadatasFromImage) {
302*77c1e3ccSAndroid Build Coastguard Worker aom_image_t image;
303*77c1e3ccSAndroid Build Coastguard Worker image.metadata = nullptr;
304*77c1e3ccSAndroid Build Coastguard Worker
305*77c1e3ccSAndroid Build Coastguard Worker uint32_t types[3];
306*77c1e3ccSAndroid Build Coastguard Worker types[0] = OBU_METADATA_TYPE_ITUT_T35;
307*77c1e3ccSAndroid Build Coastguard Worker types[1] = OBU_METADATA_TYPE_HDR_CLL;
308*77c1e3ccSAndroid Build Coastguard Worker types[2] = OBU_METADATA_TYPE_HDR_MDCV;
309*77c1e3ccSAndroid Build Coastguard Worker
310*77c1e3ccSAndroid Build Coastguard Worker ASSERT_EQ(aom_img_add_metadata(&image, types[0], kMetadataPayloadT35,
311*77c1e3ccSAndroid Build Coastguard Worker kMetadataPayloadSizeT35, AOM_MIF_ANY_FRAME),
312*77c1e3ccSAndroid Build Coastguard Worker 0);
313*77c1e3ccSAndroid Build Coastguard Worker ASSERT_EQ(aom_img_add_metadata(&image, types[1], kMetadataPayloadT35,
314*77c1e3ccSAndroid Build Coastguard Worker kMetadataPayloadSizeT35, AOM_MIF_KEY_FRAME),
315*77c1e3ccSAndroid Build Coastguard Worker 0);
316*77c1e3ccSAndroid Build Coastguard Worker ASSERT_EQ(aom_img_add_metadata(&image, types[2], kMetadataPayloadT35,
317*77c1e3ccSAndroid Build Coastguard Worker kMetadataPayloadSizeT35, AOM_MIF_KEY_FRAME),
318*77c1e3ccSAndroid Build Coastguard Worker 0);
319*77c1e3ccSAndroid Build Coastguard Worker
320*77c1e3ccSAndroid Build Coastguard Worker size_t number_metadata = aom_img_num_metadata(&image);
321*77c1e3ccSAndroid Build Coastguard Worker ASSERT_EQ(number_metadata, 3u);
322*77c1e3ccSAndroid Build Coastguard Worker for (size_t i = 0; i < number_metadata; ++i) {
323*77c1e3ccSAndroid Build Coastguard Worker const aom_metadata_t *metadata = aom_img_get_metadata(&image, i);
324*77c1e3ccSAndroid Build Coastguard Worker ASSERT_NE(metadata, nullptr);
325*77c1e3ccSAndroid Build Coastguard Worker ASSERT_EQ(metadata->type, types[i]);
326*77c1e3ccSAndroid Build Coastguard Worker ASSERT_EQ(metadata->sz, kMetadataPayloadSizeT35);
327*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(
328*77c1e3ccSAndroid Build Coastguard Worker memcmp(kMetadataPayloadT35, metadata->payload, kMetadataPayloadSizeT35),
329*77c1e3ccSAndroid Build Coastguard Worker 0);
330*77c1e3ccSAndroid Build Coastguard Worker }
331*77c1e3ccSAndroid Build Coastguard Worker aom_img_metadata_array_free(image.metadata);
332*77c1e3ccSAndroid Build Coastguard Worker }
333