xref: /aosp_15_r20/external/libwebm/webm_parser/tests/track_entry_parser_test.cc (revision 103e46e4cd4b6efcf6001f23fa8665fb110abf8d)
1 // Copyright (c) 2016 The WebM project authors. All Rights Reserved.
2 //
3 // Use of this source code is governed by a BSD-style license
4 // that can be found in the LICENSE file in the root of the source
5 // tree. An additional intellectual property rights grant can be found
6 // in the file PATENTS.  All contributing project authors may
7 // be found in the AUTHORS file in the root of the source tree.
8 #include "src/track_entry_parser.h"
9 
10 #include <cstdint>
11 
12 #include "gmock/gmock.h"
13 #include "gtest/gtest.h"
14 
15 #include "test_utils/element_parser_test.h"
16 #include "webm/id.h"
17 
18 using webm::Audio;
19 using webm::ContentEncoding;
20 using webm::ContentEncodings;
21 using webm::DisplayUnit;
22 using webm::ElementParserTest;
23 using webm::Id;
24 using webm::TrackEntry;
25 using webm::TrackEntryParser;
26 using webm::TrackType;
27 using webm::Video;
28 
29 namespace {
30 
31 class TrackEntryParserTest
32     : public ElementParserTest<TrackEntryParser, Id::kTrackEntry> {};
33 
TEST_F(TrackEntryParserTest,DefaultParse)34 TEST_F(TrackEntryParserTest, DefaultParse) {
35   EXPECT_CALL(callback_, OnTrackEntry(metadata_, TrackEntry{})).Times(1);
36 
37   ParseAndVerify();
38 }
39 
TEST_F(TrackEntryParserTest,DefaultValues)40 TEST_F(TrackEntryParserTest, DefaultValues) {
41   SetReaderData({
42       0xD7,  // ID = 0xD7 (TrackNumber).
43       0x20, 0x00, 0x00,  // Size = 0.
44 
45       0x73, 0xC5,  // ID = 0x73C5 (TrackUID).
46       0x20, 0x00, 0x00,  // Size = 0.
47 
48       0x83,  // ID = 0x83 (TrackType).
49       0x20, 0x00, 0x00,  // Size = 0.
50 
51       0xB9,  // ID = 0xB9 (FlagEnabled).
52       0x20, 0x00, 0x00,  // Size = 0.
53 
54       0x88,  // ID = 0x88 (FlagDefault).
55       0x20, 0x00, 0x00,  // Size = 0.
56 
57       0x55, 0xAA,  // ID = 0x55AA (FlagForced).
58       0x20, 0x00, 0x00,  // Size = 0.
59 
60       0x9C,  // ID = 0x9C (FlagLacing).
61       0x20, 0x00, 0x00,  // Size = 0.
62 
63       0x23, 0xE3, 0x83,  // ID = 0x23E383 (DefaultDuration).
64       0x80,  // Size = 0.
65 
66       0x53, 0x6E,  // ID = 0x536E (Name).
67       0x20, 0x00, 0x00,  // Size = 0.
68 
69       0x22, 0xB5, 0x9C,  // ID = 0x22B59C (Language).
70       0x80,  // Size = 0.
71 
72       0x86,  // ID = 0x86 (CodecID).
73       0x20, 0x00, 0x00,  // Size = 0.
74 
75       0x63, 0xA2,  // ID = 0x63A2 (CodecPrivate).
76       0x20, 0x00, 0x00,  // Size = 0.
77 
78       0x25, 0x86, 0x88,  // ID = 0x258688 (CodecName).
79       0x80,  // Size = 0.
80 
81       0x56, 0xAA,  // ID = 0x56AA (CodecDelay).
82       0x20, 0x00, 0x00,  // Size = 0.
83 
84       0x56, 0xBB,  // ID = 0x56BB (SeekPreRoll).
85       0x20, 0x00, 0x00,  // Size = 0.
86 
87       0xE0,  // ID = 0xE0 (Video).
88       0x20, 0x00, 0x00,  // Size = 0.
89 
90       0xE1,  // ID = 0xE1 (Audio).
91       0x20, 0x00, 0x00,  // Size = 0.
92 
93       0x6D, 0x80,  // ID = 0x6D80 (ContentEncodings).
94       0x20, 0x00, 0x00,  // Size = 0.
95   });
96 
97   TrackEntry track_entry;
98   track_entry.track_number.Set(0, true);
99   track_entry.track_uid.Set(0, true);
100   track_entry.track_type.Set(TrackType{}, true);
101   track_entry.is_enabled.Set(true, true);
102   track_entry.is_default.Set(true, true);
103   track_entry.is_forced.Set(false, true);
104   track_entry.uses_lacing.Set(true, true);
105   track_entry.default_duration.Set(0, true);
106   track_entry.name.Set("", true);
107   track_entry.language.Set("eng", true);
108   track_entry.codec_id.Set("", true);
109   track_entry.codec_private.Set(std::vector<std::uint8_t>{}, true);
110   track_entry.codec_name.Set("", true);
111   track_entry.codec_delay.Set(0, true);
112   track_entry.seek_pre_roll.Set(0, true);
113   track_entry.video.Set(Video{}, true);
114   track_entry.audio.Set(Audio{}, true);
115   track_entry.content_encodings.Set(ContentEncodings{}, true);
116 
117   EXPECT_CALL(callback_, OnTrackEntry(metadata_, track_entry)).Times(1);
118 
119   ParseAndVerify();
120 }
121 
TEST_F(TrackEntryParserTest,CustomValues)122 TEST_F(TrackEntryParserTest, CustomValues) {
123   SetReaderData({
124       0xD7,  // ID = 0xD7 (TrackNumber).
125       0x20, 0x00, 0x01,  // Size = 1.
126       0x01,  // Body (value = 1).
127 
128       0x73, 0xC5,  // ID = 0x73C5 (TrackUID).
129       0x20, 0x00, 0x01,  // Size = 1.
130       0x02,  // Body (value = 2).
131 
132       0x83,  // ID = 0x83 (TrackType).
133       0x20, 0x00, 0x01,  // Size = 1.
134       0x03,  // Body (value = complex).
135 
136       0xB9,  // ID = 0xB9 (FlagEnabled).
137       0x20, 0x00, 0x01,  // Size = 1.
138       0x00,  // Body (value = 0).
139 
140       0x88,  // ID = 0x88 (FlagDefault).
141       0x20, 0x00, 0x01,  // Size = 1.
142       0x00,  // Body (value = 0).
143 
144       0x55, 0xAA,  // ID = 0x55AA (FlagForced).
145       0x20, 0x00, 0x01,  // Size = 1.
146       0x01,  // Body (value = 1).
147 
148       0x9C,  // ID = 0x9C (FlagLacing).
149       0x20, 0x00, 0x01,  // Size = 1.
150       0x00,  // Body (value = 0).
151 
152       0x23, 0xE3, 0x83,  // ID = 0x23E383 (DefaultDuration).
153       0x81,  // Size = 1.
154       0x04,  // Body (value = 4).
155 
156       0x53, 0x6E,  // ID = 0x536E (Name).
157       0x20, 0x00, 0x01,  // Size = 1.
158       0x41,  // Body (value = "A").
159 
160       0x22, 0xB5, 0x9C,  // ID = 0x22B59C (Language).
161       0x81,  // Size = 1.
162       0x42,  // Body (value = "B").
163 
164       0x86,  // ID = 0x86 (CodecID).
165       0x20, 0x00, 0x01,  // Size = 1.
166       0x43,  // Body (value = "C").
167 
168       0x63, 0xA2,  // ID = 0x63A2 (CodecPrivate).
169       0x20, 0x00, 0x01,  // Size = 1.
170       0x00,  // Body.
171 
172       0x25, 0x86, 0x88,  // ID = 0x258688 (CodecName).
173       0x81,  // Size = 1.
174       0x44,  // Body (value = "D").
175 
176       0x56, 0xAA,  // ID = 0x56AA (CodecDelay).
177       0x20, 0x00, 0x01,  // Size = 1.
178       0x05,  // Body (value = 5).
179 
180       0x56, 0xBB,  // ID = 0x56BB (SeekPreRoll).
181       0x20, 0x00, 0x01,  // Size = 1.
182       0x06,  // Body (value = 6).
183 
184       0xE0,  // ID = 0xE0 (Video).
185       0x20, 0x00, 0x06,  // Size = 6.
186 
187       0x54, 0xB2,  //   ID = 0x54B2 (DisplayUnit).
188       0x20, 0x00, 0x01,  //   Size = 1.
189       0x03,  //   Body (value = display aspect ratio).
190 
191       0xE1,  // ID = 0xE1 (Audio).
192       0x20, 0x00, 0x05,  // Size = 5.
193 
194       0x9F,  //   ID = 0x9F (Channels).
195       0x20, 0x00, 0x01,  //   Size = 1.
196       0x08,  //   Body (value = 8).
197 
198       0x6D, 0x80,  // ID = 0x6D80 (ContentEncodings).
199       0x20, 0x00, 0x0B,  // Size = 11.
200 
201       0x62, 0x40,  //   ID = 0x6240 (ContentEncoding).
202       0x20, 0x00, 0x06,  //   Size = 6.
203 
204       0x50, 0x31,  //     ID = 0x5031 (ContentEncodingOrder).
205       0x20, 0x00, 0x01,  //     Size = 1.
206       0x01,  //     Body (value = 1).
207   });
208 
209   TrackEntry track_entry;
210   track_entry.track_number.Set(1, true);
211   track_entry.track_uid.Set(2, true);
212   track_entry.track_type.Set(TrackType::kComplex, true);
213   track_entry.is_enabled.Set(false, true);
214   track_entry.is_default.Set(false, true);
215   track_entry.is_forced.Set(true, true);
216   track_entry.uses_lacing.Set(false, true);
217   track_entry.default_duration.Set(4, true);
218   track_entry.name.Set("A", true);
219   track_entry.language.Set("B", true);
220   track_entry.codec_id.Set("C", true);
221   track_entry.codec_private.Set(std::vector<std::uint8_t>{0x00}, true);
222   track_entry.codec_name.Set("D", true);
223   track_entry.codec_delay.Set(5, true);
224   track_entry.seek_pre_roll.Set(6, true);
225 
226   Video expected_video;
227   expected_video.display_unit.Set(DisplayUnit::kDisplayAspectRatio, true);
228   track_entry.video.Set(expected_video, true);
229 
230   Audio expected_audio;
231   expected_audio.channels.Set(8, true);
232   track_entry.audio.Set(expected_audio, true);
233 
234   ContentEncoding expected_encoding;
235   expected_encoding.order.Set(1, true);
236   ContentEncodings expected_encodings;
237   expected_encodings.encodings.emplace_back(expected_encoding, true);
238   track_entry.content_encodings.Set(expected_encodings, true);
239 
240   EXPECT_CALL(callback_, OnTrackEntry(metadata_, track_entry)).Times(1);
241 
242   ParseAndVerify();
243 }
244 
245 }  // namespace
246