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
|
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "media/base/video_codecs.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace media {
#if BUILDFLAG(ENABLE_HEVC_DEMUXING)
TEST(ParseHEVCCodecIdTest, InvalidHEVCCodecIds) {
VideoCodecProfile profile = VIDEO_CODEC_PROFILE_UNKNOWN;
uint8_t level_idc = 0;
// Both hev1 and hvc1 should be supported
EXPECT_TRUE(ParseHEVCCodecId("hev1.1.6.L93.B0", &profile, &level_idc));
EXPECT_EQ(profile, HEVCPROFILE_MAIN);
EXPECT_EQ(level_idc, 93);
EXPECT_TRUE(ParseHEVCCodecId("hvc1.1.6.L93.B0", &profile, &level_idc));
EXPECT_EQ(profile, HEVCPROFILE_MAIN);
EXPECT_EQ(level_idc, 93);
// Check that codec id string with insufficient number of dot-separated
// elements are rejected. There must be at least 4 elements: hev1/hvc1 prefix,
// profile, profile_compatibility, tier+level.
EXPECT_TRUE(ParseHEVCCodecId("hvc1.1.6.L93", &profile, &level_idc));
EXPECT_EQ(profile, HEVCPROFILE_MAIN);
EXPECT_EQ(level_idc, 93);
EXPECT_FALSE(ParseHEVCCodecId("hvc1", &profile, &level_idc));
EXPECT_FALSE(ParseHEVCCodecId("hev1", &profile, &level_idc));
EXPECT_FALSE(ParseHEVCCodecId("hvc1.", &profile, &level_idc));
EXPECT_FALSE(ParseHEVCCodecId("hvc1..", &profile, &level_idc));
EXPECT_FALSE(ParseHEVCCodecId("hvc1...", &profile, &level_idc));
EXPECT_FALSE(ParseHEVCCodecId("hvc1....", &profile, &level_idc));
EXPECT_FALSE(ParseHEVCCodecId("hvc1.1", &profile, &level_idc));
EXPECT_FALSE(ParseHEVCCodecId("hvc1.1.", &profile, &level_idc));
EXPECT_FALSE(ParseHEVCCodecId("hvc1.1..", &profile, &level_idc));
EXPECT_FALSE(ParseHEVCCodecId("hvc1.1...", &profile, &level_idc));
EXPECT_FALSE(ParseHEVCCodecId("hvc1.1.6", &profile, &level_idc));
EXPECT_FALSE(ParseHEVCCodecId("hvc1.1.6.", &profile, &level_idc));
EXPECT_FALSE(ParseHEVCCodecId("hvc1.1.6..", &profile, &level_idc));
EXPECT_FALSE(ParseHEVCCodecId("hvc1.1.6...", &profile, &level_idc));
EXPECT_FALSE(ParseHEVCCodecId("hvc1.1..L93", &profile, &level_idc));
EXPECT_FALSE(ParseHEVCCodecId("hvc1.1..L93.", &profile, &level_idc));
EXPECT_FALSE(ParseHEVCCodecId("hvc1.1..L93..", &profile, &level_idc));
EXPECT_FALSE(ParseHEVCCodecId("hvc1..6", &profile, &level_idc));
EXPECT_FALSE(ParseHEVCCodecId("hvc1..6.", &profile, &level_idc));
EXPECT_FALSE(ParseHEVCCodecId("hvc1..6..", &profile, &level_idc));
EXPECT_FALSE(ParseHEVCCodecId("hvc1..6...", &profile, &level_idc));
EXPECT_FALSE(ParseHEVCCodecId("hvc1..6.L93", &profile, &level_idc));
EXPECT_FALSE(ParseHEVCCodecId("hvc1..6.L93.", &profile, &level_idc));
EXPECT_FALSE(ParseHEVCCodecId("hvc1..6.L93..", &profile, &level_idc));
// Check that codec ids with empty constraint bytes are rejected.
EXPECT_FALSE(ParseHEVCCodecId("hvc1.1.6.L93.", &profile, &level_idc));
EXPECT_FALSE(ParseHEVCCodecId("hvc1.1.6.L93..", &profile, &level_idc));
EXPECT_FALSE(ParseHEVCCodecId("hvc1.1.6.L93...", &profile, &level_idc));
EXPECT_FALSE(ParseHEVCCodecId("hvc1.1.6.L93....", &profile, &level_idc));
EXPECT_FALSE(ParseHEVCCodecId("hvc1.1.6.L93.....", &profile, &level_idc));
EXPECT_FALSE(ParseHEVCCodecId("hvc1.1.6.L93......", &profile, &level_idc));
EXPECT_FALSE(ParseHEVCCodecId("hvc1.1.6.L93.......", &profile, &level_idc));
EXPECT_FALSE(ParseHEVCCodecId("hvc1.1.6.L93.......0", &profile, &level_idc));
EXPECT_FALSE(ParseHEVCCodecId("hvc1.1.6.L93.0.", &profile, &level_idc));
EXPECT_FALSE(ParseHEVCCodecId("hvc1.1.6.L93.0..", &profile, &level_idc));
EXPECT_FALSE(ParseHEVCCodecId("hvc1.1.6.L93.0..0", &profile, &level_idc));
EXPECT_FALSE(
ParseHEVCCodecId("hvc1.1.6.L93.0..0.0.0.0.0", &profile, &level_idc));
EXPECT_FALSE(
ParseHEVCCodecId("hvc1.1.6.L93.0.0.0.0.0.0.", &profile, &level_idc));
// Different variations of general_profile_space (empty, 'A', 'B', 'C')
EXPECT_TRUE(ParseHEVCCodecId("hvc1.1.6.L93.B0", &profile, &level_idc));
EXPECT_TRUE(ParseHEVCCodecId("hvc1.A1.6.L93.B0", &profile, &level_idc));
EXPECT_TRUE(ParseHEVCCodecId("hvc1.B1.6.L93.B0", &profile, &level_idc));
EXPECT_TRUE(ParseHEVCCodecId("hvc1.C1.6.L93.B0", &profile, &level_idc));
EXPECT_FALSE(ParseHEVCCodecId("hvc1.D1.6.L93.B0", &profile, &level_idc));
// general_profile_idc (the number after the first dot) must be a 5-bit
// decimal-encoded number (between 0 and 31)
EXPECT_TRUE(ParseHEVCCodecId("hvc1.0.6.L93.B0", &profile, &level_idc));
EXPECT_TRUE(ParseHEVCCodecId("hvc1.31.6.L93.B0", &profile, &level_idc));
EXPECT_TRUE(ParseHEVCCodecId("hvc1.1.6.L93.B0", &profile, &level_idc));
EXPECT_EQ(profile, HEVCPROFILE_MAIN);
EXPECT_TRUE(ParseHEVCCodecId("hvc1.2.2.L93.B0", &profile, &level_idc));
EXPECT_EQ(profile, HEVCPROFILE_MAIN10);
EXPECT_TRUE(ParseHEVCCodecId("hvc1.3.4.L93.B0", &profile, &level_idc));
EXPECT_EQ(profile, HEVCPROFILE_MAIN_STILL_PICTURE);
EXPECT_FALSE(ParseHEVCCodecId("hvc1.-1.6.L93.B0", &profile, &level_idc));
EXPECT_FALSE(ParseHEVCCodecId("hvc1.32.6.L93.B0", &profile, &level_idc));
EXPECT_FALSE(ParseHEVCCodecId("hvc1.999.6.L93.B0", &profile, &level_idc));
EXPECT_FALSE(ParseHEVCCodecId("hvc1.A.6.L93.B0", &profile, &level_idc));
EXPECT_FALSE(ParseHEVCCodecId("hvc1.1F.6.L93.B0", &profile, &level_idc));
// general_profile_compatibility_flags is a 32-bit hex number
EXPECT_TRUE(ParseHEVCCodecId("hvc1.1.0.L93.B0", &profile, &level_idc));
EXPECT_TRUE(ParseHEVCCodecId("hvc1.1.FF.L93.B0", &profile, &level_idc));
EXPECT_TRUE(ParseHEVCCodecId("hvc1.1.FFFF.L93.B0", &profile, &level_idc));
EXPECT_TRUE(ParseHEVCCodecId("hvc1.1.FFFFFFFF.L93.B0", &profile, &level_idc));
EXPECT_FALSE(
ParseHEVCCodecId("hvc1.1.100000000.L93.B0", &profile, &level_idc));
EXPECT_FALSE(
ParseHEVCCodecId("hvc1.1.FFFFFFFFF.L93.B0", &profile, &level_idc));
EXPECT_FALSE(ParseHEVCCodecId("hvc1.1.-1.L93.B0", &profile, &level_idc));
EXPECT_FALSE(ParseHEVCCodecId("hvc1.1.0G.L93.B0", &profile, &level_idc));
// general_tier_flag is encoded as either character 'L' (general_tier_flag==0)
// or character 'H' (general_tier_flag==1) in the fourth element of the string
EXPECT_TRUE(ParseHEVCCodecId("hvc1.1.6.L93.B0", &profile, &level_idc));
EXPECT_TRUE(ParseHEVCCodecId("hvc1.1.0.H93.B0", &profile, &level_idc));
EXPECT_FALSE(ParseHEVCCodecId("hvc1.1.0.93.B0", &profile, &level_idc));
EXPECT_FALSE(ParseHEVCCodecId("hvc1.1.0.A93.B0", &profile, &level_idc));
// general_level_idc is 8-bit decimal-encoded number after general_tier_flag.
EXPECT_TRUE(ParseHEVCCodecId("hvc1.1.6.L0.B0", &profile, &level_idc));
EXPECT_EQ(level_idc, 0);
EXPECT_TRUE(ParseHEVCCodecId("hvc1.1.6.L1.B0", &profile, &level_idc));
EXPECT_EQ(level_idc, 1);
// Level 3.1 (93 == 3.1 * 30)
EXPECT_TRUE(ParseHEVCCodecId("hvc1.1.6.L93.B0", &profile, &level_idc));
EXPECT_EQ(level_idc, 93);
// Level 5 (150 == 5 * 30)
EXPECT_TRUE(ParseHEVCCodecId("hvc1.1.6.L150.B0", &profile, &level_idc));
EXPECT_EQ(level_idc, 150);
EXPECT_TRUE(ParseHEVCCodecId("hvc1.1.6.L255.B0", &profile, &level_idc));
EXPECT_EQ(level_idc, 255);
EXPECT_FALSE(ParseHEVCCodecId("hvc1.1.6.L256.B0", &profile, &level_idc));
EXPECT_FALSE(ParseHEVCCodecId("hvc1.1.6.L999.B0", &profile, &level_idc));
EXPECT_FALSE(ParseHEVCCodecId("hvc1.1.6.L-1.B0", &profile, &level_idc));
// The elements after the fourth dot are hex-encoded bytes containing
// constraint flags (up to 6 bytes), trailing zero bytes may be omitted
EXPECT_TRUE(
ParseHEVCCodecId("hvc1.1.6.L0.0.0.0.0.0.0", &profile, &level_idc));
EXPECT_TRUE(
ParseHEVCCodecId("hvc1.1.6.L0.00.00.00.00.00.00", &profile, &level_idc));
EXPECT_TRUE(ParseHEVCCodecId("hvc1.1.6.L0.12", &profile, &level_idc));
EXPECT_TRUE(ParseHEVCCodecId("hvc1.1.6.L0.12.34.56", &profile, &level_idc));
EXPECT_TRUE(
ParseHEVCCodecId("hvc1.1.6.L0.12.34.56.78.9A.BC", &profile, &level_idc));
EXPECT_TRUE(
ParseHEVCCodecId("hvc1.1.6.L0.FF.FF.FF.FF.FF.FF", &profile, &level_idc));
EXPECT_FALSE(ParseHEVCCodecId("hvc1.1.6.L0.FF.FF.FF.FF.FF.FF.0", &profile,
&level_idc));
EXPECT_FALSE(ParseHEVCCodecId("hvc1.1.6.L0.100", &profile, &level_idc));
EXPECT_FALSE(ParseHEVCCodecId("hvc1.1.6.L0.1FF", &profile, &level_idc));
EXPECT_FALSE(ParseHEVCCodecId("hvc1.1.6.L0.-1", &profile, &level_idc));
}
#endif
#if BUILDFLAG(ENABLE_DOLBY_VISION_DEMUXING)
TEST(ParseDolbyVisionCodecIdTest, InvalidDolbyVisionCodecIds) {
VideoCodecProfile profile = VIDEO_CODEC_PROFILE_UNKNOWN;
uint8_t level_id = 0;
// Codec dvav/dva1 should only contain profile 0.
EXPECT_TRUE(ParseDolbyVisionCodecId("dvav.00.07", &profile, &level_id));
EXPECT_EQ(profile, DOLBYVISION_PROFILE0);
EXPECT_EQ(level_id, 7);
EXPECT_TRUE(ParseDolbyVisionCodecId("dva1.00.07", &profile, &level_id));
EXPECT_EQ(profile, DOLBYVISION_PROFILE0);
EXPECT_EQ(level_id, 7);
EXPECT_FALSE(ParseDolbyVisionCodecId("dvav.04.07", &profile, &level_id));
EXPECT_FALSE(ParseDolbyVisionCodecId("dva1.04.07", &profile, &level_id));
EXPECT_FALSE(ParseDolbyVisionCodecId("dvav.05.07", &profile, &level_id));
EXPECT_FALSE(ParseDolbyVisionCodecId("dva1.05.07", &profile, &level_id));
EXPECT_FALSE(ParseDolbyVisionCodecId("dvav.07.07", &profile, &level_id));
EXPECT_FALSE(ParseDolbyVisionCodecId("dva1.07.07", &profile, &level_id));
#if BUILDFLAG(ENABLE_HEVC_DEMUXING)
// Codec dvhe/dvh1 should only contain profile 4, 5, and 7.
EXPECT_TRUE(ParseDolbyVisionCodecId("dvhe.04.07", &profile, &level_id));
EXPECT_EQ(profile, DOLBYVISION_PROFILE4);
EXPECT_EQ(level_id, 7);
EXPECT_TRUE(ParseDolbyVisionCodecId("dvhe.05.07", &profile, &level_id));
EXPECT_EQ(profile, DOLBYVISION_PROFILE5);
EXPECT_EQ(level_id, 7);
EXPECT_TRUE(ParseDolbyVisionCodecId("dvh1.05.07", &profile, &level_id));
EXPECT_EQ(profile, DOLBYVISION_PROFILE5);
EXPECT_EQ(level_id, 7);
EXPECT_TRUE(ParseDolbyVisionCodecId("dvhe.07.07", &profile, &level_id));
EXPECT_EQ(profile, DOLBYVISION_PROFILE7);
EXPECT_EQ(level_id, 7);
EXPECT_FALSE(ParseDolbyVisionCodecId("dvhe.00.07", &profile, &level_id));
EXPECT_FALSE(ParseDolbyVisionCodecId("dvh1.00.07", &profile, &level_id));
// Profiles 1, 2, 3 and 6 are deprecated.
EXPECT_FALSE(ParseDolbyVisionCodecId("dvav.01.07", &profile, &level_id));
EXPECT_FALSE(ParseDolbyVisionCodecId("dvhe.02.07", &profile, &level_id));
EXPECT_FALSE(ParseDolbyVisionCodecId("dvhe.03.07", &profile, &level_id));
EXPECT_FALSE(ParseDolbyVisionCodecId("dvhe.06.07", &profile, &level_id));
// Level should be numbers between 1 and 9.
EXPECT_FALSE(ParseDolbyVisionCodecId("dvhe.04.00", &profile, &level_id));
EXPECT_FALSE(ParseDolbyVisionCodecId("dvhe.04.10", &profile, &level_id));
EXPECT_FALSE(ParseDolbyVisionCodecId("dvhe.04.20", &profile, &level_id));
EXPECT_FALSE(ParseDolbyVisionCodecId("dvhe.04.99", &profile, &level_id));
// Valid codec string is <FourCC>.<two digits profile>.<two digits level>.
EXPECT_FALSE(ParseDolbyVisionCodecId("dvhe", &profile, &level_id));
EXPECT_FALSE(ParseDolbyVisionCodecId("dvhe.", &profile, &level_id));
EXPECT_FALSE(ParseDolbyVisionCodecId("dvhe..", &profile, &level_id));
EXPECT_FALSE(ParseDolbyVisionCodecId("dvhe...", &profile, &level_id));
EXPECT_FALSE(ParseDolbyVisionCodecId("dvhe....", &profile, &level_id));
EXPECT_FALSE(ParseDolbyVisionCodecId("dvhe.5", &profile, &level_id));
EXPECT_FALSE(ParseDolbyVisionCodecId("dvhe.5.", &profile, &level_id));
EXPECT_FALSE(ParseDolbyVisionCodecId("dvhe.5..", &profile, &level_id));
EXPECT_FALSE(ParseDolbyVisionCodecId("dvhe.5...", &profile, &level_id));
EXPECT_FALSE(ParseDolbyVisionCodecId("dvhe.5.7", &profile, &level_id));
EXPECT_FALSE(ParseDolbyVisionCodecId("dvhe.5.7.", &profile, &level_id));
EXPECT_FALSE(ParseDolbyVisionCodecId("dvhe.5.7..", &profile, &level_id));
EXPECT_FALSE(ParseDolbyVisionCodecId("dvhe.5.7...", &profile, &level_id));
EXPECT_FALSE(ParseDolbyVisionCodecId("dvhe..5", &profile, &level_id));
#endif
}
#endif
} // namespace media
|