File: multilayer_metadata_test.cc

package info (click to toggle)
aom 3.13.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 38,340 kB
  • sloc: ansic: 415,031; cpp: 210,937; asm: 9,453; python: 4,479; perl: 2,339; sh: 1,878; pascal: 345; makefile: 57; javascript: 32
file content (232 lines) | stat: -rw-r--r-- 7,596 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
/*
 * Copyright (c) 2024, Alliance for Open Media. All rights reserved.
 *
 * This source code is subject to the terms of the BSD 2 Clause License and
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
 * was not distributed with this source code in the LICENSE file, you can
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
 * Media Patent License 1.0 was not distributed with this source code in the
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
 */

#include <cmath>

#include "gtest/gtest.h"

#include "examples/multilayer_metadata.h"
#include "test/video_source.h"

namespace libaom_examples {
namespace {

TEST(MultilayerMetadataTest, ParseAlpha) {
  const std::string metadata = R"(

use_case: 1 # global alpha
layers:
  - layer_type: 5 # alpha
    luma_plane_only_flag: 1
    layer_metadata_scope: 2 # global
    alpha:
      alpha_use_idc: 1 # premultiplied
      alpha_bit_depth: 8
      alpha_transparent_value: 0
      alpha_opaque_value: 4

  - layer_type: 1 # texture
    luma_plane_only_flag: 0
    layer_metadata_scope: 2 # global
    layer_color_description:
      color_range: 1
      color_primaries: 1
      transfer_characteristics: 13
      matrix_coefficients: 6

    )";
  libaom_test::TempOutFile tmp_file(/*text_mode=*/true);
  fprintf(tmp_file.file(), "%s", metadata.c_str());
  fflush(tmp_file.file());

  MultilayerMetadata multilayer;
  EXPECT_TRUE(parse_multilayer_file(tmp_file.file_name().c_str(), &multilayer));

  EXPECT_EQ(multilayer.use_case, 1);
  ASSERT_EQ(multilayer.layers.size(), 2);
  EXPECT_EQ(multilayer.layers[0].layer_type, 5);
  EXPECT_EQ(multilayer.layers[0].luma_plane_only_flag, 1);
  EXPECT_EQ(multilayer.layers[0].layer_metadata_scope, 2);
  EXPECT_EQ(multilayer.layers[0].global_alpha_info.alpha_use_idc, 1);
  EXPECT_EQ(multilayer.layers[0].global_alpha_info.alpha_bit_depth, 8);
  EXPECT_EQ(multilayer.layers[0].global_alpha_info.alpha_transparent_value, 0);
  EXPECT_EQ(multilayer.layers[0].global_alpha_info.alpha_opaque_value, 4);
  EXPECT_EQ(multilayer.layers[1].layer_type, 1);
  EXPECT_EQ(multilayer.layers[1].luma_plane_only_flag, 0);
  EXPECT_EQ(multilayer.layers[1].layer_metadata_scope, 2);
  EXPECT_TRUE(multilayer.layers[1].layer_color_description.second);
  EXPECT_EQ(multilayer.layers[1].layer_color_description.first.color_range, 1);
  EXPECT_EQ(multilayer.layers[1].layer_color_description.first.color_primaries,
            1);
  EXPECT_EQ(multilayer.layers[1]
                .layer_color_description.first.transfer_characteristics,
            13);
  EXPECT_EQ(
      multilayer.layers[1].layer_color_description.first.matrix_coefficients,
      6);
}

TEST(MultilayerMetadataTest, ParseDepth) {
  const std::string metadata = R"(
use_case: 2 # global depth
layers:
  - layer_type: 6 # depth
    luma_plane_only_flag: 1
    layer_metadata_scope: 2 # global
    depth:
      z_near: 1.456
      z_far: 9.786
      depth_representation_type: 2

  - layer_type: 1 # texture
    luma_plane_only_flag: 0
    layer_metadata_scope: 2 # global
    layer_color_description:
      color_range: 1
      color_primaries: 1
      transfer_characteristics: 13
      matrix_coefficients: 6

    )";
  libaom_test::TempOutFile tmp_file(/*text_mode=*/true);
  fprintf(tmp_file.file(), "%s", metadata.c_str());
  fflush(tmp_file.file());

  MultilayerMetadata multilayer;
  EXPECT_TRUE(parse_multilayer_file(tmp_file.file_name().c_str(), &multilayer));
  EXPECT_EQ(multilayer.use_case, 2);
  ASSERT_EQ(multilayer.layers.size(), 2);
  EXPECT_EQ(multilayer.layers[0].layer_type, 6);
  EXPECT_EQ(multilayer.layers[0].luma_plane_only_flag, 1);
  EXPECT_EQ(multilayer.layers[0].layer_metadata_scope, 2);
  EXPECT_TRUE(multilayer.layers[0].global_depth_info.z_near.second);
  EXPECT_NEAR(depth_representation_element_to_double(
                  multilayer.layers[0].global_depth_info.z_near.first),
              1.456, 0.00001);
  EXPECT_TRUE(multilayer.layers[0].global_depth_info.z_far.second);
  EXPECT_NEAR(depth_representation_element_to_double(
                  multilayer.layers[0].global_depth_info.z_far.first),
              9.786, 0.00001);
  EXPECT_EQ(multilayer.layers[0].global_depth_info.depth_representation_type,
            2);
  EXPECT_EQ(multilayer.layers[1].layer_type, 1);
  EXPECT_EQ(multilayer.layers[1].luma_plane_only_flag, 0);
  EXPECT_EQ(multilayer.layers[1].layer_metadata_scope, 2);
  EXPECT_TRUE(multilayer.layers[1].layer_color_description.second);
  EXPECT_EQ(multilayer.layers[1].layer_color_description.first.color_range, 1);
  EXPECT_EQ(multilayer.layers[1].layer_color_description.first.color_primaries,
            1);
  EXPECT_EQ(multilayer.layers[1]
                .layer_color_description.first.transfer_characteristics,
            13);
  EXPECT_EQ(
      multilayer.layers[1].layer_color_description.first.matrix_coefficients,
      6);
}

TEST(MultilayerMetadataTest, ParseInvalid) {
  const std::string metadata = R"(

use_case: 1 # global alpha
layers:
  - layer_type: 5 # alpha
    luma_plane_only_flag: 1
    layer_metadata_scope: 2 # global

  - layer_type: 1 # texture
    luma_plane_only_flag: 0
    layer_metadata_scope: 2 # global

  - layer_type: 6 # depth => bad layer type
    luma_plane_only_flag: 1
    layer_metadata_scope: 2 # global
    )";
  libaom_test::TempOutFile tmp_file(/*text_mode=*/true);
  fprintf(tmp_file.file(), "%s", metadata.c_str());
  fflush(tmp_file.file());

  MultilayerMetadata multilayer;
  // Invalid: has a depth layer even though use_case is alpha
  EXPECT_FALSE(
      parse_multilayer_file(tmp_file.file_name().c_str(), &multilayer));
}

TEST(MultilayerMetadataTest, ParseBadIndent) {
  const std::string metadata = R"(

use_case: 1 # global alpha
layers:
  - layer_type: 5 # alpha
    luma_plane_only_flag: 1
      layer_metadata_scope: 2 # global

  - layer_type: 1 # texture
    luma_plane_only_flag: 0
    layer_metadata_scope: 2 # global
    )";
  libaom_test::TempOutFile tmp_file(/*text_mode=*/true);
  fprintf(tmp_file.file(), "%s", metadata.c_str());
  fflush(tmp_file.file());

  MultilayerMetadata multilayer;
  // Invalid indentation.
  EXPECT_FALSE(
      parse_multilayer_file(tmp_file.file_name().c_str(), &multilayer));
}

TEST(MultilayerMetadataTest, ParseUnknownField) {
  const std::string metadata = R"(

use_case: 1 # global alpha
layers:
  - layer_type: 5 # alpha
    luma_plane_only_flag: 1
    layer_metadata_scope: 2 # global
    foobar: 42

  - layer_type: 1 # texture
    luma_plane_only_flag: 0
    layer_metadata_scope: 2 # global
    )";
  libaom_test::TempOutFile tmp_file(/*text_mode=*/true);
  fprintf(tmp_file.file(), "%s", metadata.c_str());
  fflush(tmp_file.file());

  MultilayerMetadata multilayer;
  // Unkonwn field 'foobar'.
  EXPECT_FALSE(
      parse_multilayer_file(tmp_file.file_name().c_str(), &multilayer));
}

void TestConversion(double v) {
  DepthRepresentationElement e;
  ASSERT_TRUE(double_to_depth_representation_element(v, &e)) << v;
  EXPECT_NEAR(depth_representation_element_to_double(e), v, 0.000000001);
}

TEST(MultilayerMetadataTest, DoubleConversion) {
  TestConversion(0.0);
  TestConversion(1.789456e-5);
  TestConversion(-1.789456e-5);
  TestConversion(42);
  TestConversion(6.7894564456);
  TestConversion(6.7894564456e10);
  TestConversion(-6.7894564456e10);

  DepthRepresentationElement e;
  // Too small.
  ASSERT_FALSE(double_to_depth_representation_element(1e-10, &e));
  // Too big.
  ASSERT_FALSE(double_to_depth_representation_element(1e+30, &e));
}

}  // namespace
}  // namespace libaom_examples