1 /* conform.c, conformance checks */
3 /* Copyright (C) 1996, MPEG Software Simulation Group. All Rights Reserved. */
6 * Disclaimer of Warranty
8 * These software programs are available to the user without any license fee or
9 * royalty on an "as is" basis. The MPEG Software Simulation Group disclaims
10 * any and all warranties, whether express, implied, or statuary, including any
11 * implied warranties or merchantability or of fitness for a particular
12 * purpose. In no event shall the copyright-holder be liable for any
13 * incidental, punitive, or consequential damages of any kind whatsoever
14 * arising from the use of these programs.
16 * This disclaimer of warranty extends to the user of these programs and user's
17 * customers, employees, agents, transferees, successors, and assigns.
19 * The MPEG Software Simulation Group does not represent or warrant that the
20 * programs furnished hereunder are free of infringement of any third-party
23 * Commercial implementations of MPEG-1 and MPEG-2 video, including shareware,
24 * are subject to royalty fees to patent holders. Many of these patents are
25 * general enough such that they are unavoidable regardless of implementation
36 /* check for (level independent) parameter limits */
41 /* range and value checks */
43 if (horizontal_size<1 || horizontal_size>16383)
44 error("horizontal_size must be between 1 and 16383");
45 if (mpeg1 && horizontal_size>4095)
46 error("horizontal_size must be less than 4096 (MPEG-1)");
47 if ((horizontal_size&4095)==0)
48 error("horizontal_size must not be a multiple of 4096");
49 if (chroma_format!=CHROMA444 && horizontal_size%2 != 0)
50 error("horizontal_size must be a even (4:2:0 / 4:2:2)");
52 if (vertical_size<1 || vertical_size>16383)
53 error("vertical_size must be between 1 and 16383");
54 if (mpeg1 && vertical_size>4095)
55 error("vertical size must be less than 4096 (MPEG-1)");
56 if ((vertical_size&4095)==0)
57 error("vertical_size must not be a multiple of 4096");
58 if (chroma_format==CHROMA420 && vertical_size%2 != 0)
59 error("vertical_size must be a even (4:2:0)");
62 if (vertical_size%2 != 0)
63 error("vertical_size must be a even (field pictures)");
64 if (chroma_format==CHROMA420 && vertical_size%4 != 0)
65 error("vertical_size must be a multiple of 4 (4:2:0 field pictures)");
70 if (aspectratio<1 || aspectratio>14)
71 error("pel_aspect_ratio must be between 1 and 14 (MPEG-1)");
75 if (aspectratio<1 || aspectratio>4)
76 error("aspect_ratio_information must be 1, 2, 3 or 4");
79 if (frame_rate_code<1 || frame_rate_code>8)
80 error("frame_rate code must be between 1 and 8");
83 error("bit_rate must be positive");
84 if (bit_rate > ((1<<30)-1)*400.0)
85 error("bit_rate must be less than 429 Gbit/s");
86 if (mpeg1 && bit_rate > ((1<<18)-1)*400.0)
87 error("bit_rate must be less than 104 Mbit/s (MPEG-1)");
89 if (vbv_buffer_size<1 || vbv_buffer_size>0x3ffff)
90 error("vbv_buffer_size must be in range 1..(2^18-1)");
91 if (mpeg1 && vbv_buffer_size>=1024)
92 error("vbv_buffer_size must be less than 1024 (MPEG-1)");
94 if (chroma_format<CHROMA420 || chroma_format>CHROMA444)
95 error("chroma_format must be in range 1...3");
97 if (video_format<0 || video_format>4)
98 error("video_format must be in range 0...4");
100 if (color_primaries<1 || color_primaries>7 || color_primaries==3)
101 error("color_primaries must be in range 1...2 or 4...7");
103 if (transfer_characteristics<1 || transfer_characteristics>7
104 || transfer_characteristics==3)
105 error("transfer_characteristics must be in range 1...2 or 4...7");
107 if (matrix_coefficients<1 || matrix_coefficients>7 || matrix_coefficients==3)
108 error("matrix_coefficients must be in range 1...2 or 4...7");
110 if (display_horizontal_size<0 || display_horizontal_size>16383)
111 error("display_horizontal_size must be in range 0...16383");
112 if (display_vertical_size<0 || display_vertical_size>16383)
113 error("display_vertical_size must be in range 0...16383");
115 if (dc_prec<0 || dc_prec>3)
116 error("intra_dc_precision must be in range 0...3");
120 if (motion_data[i].forw_hor_f_code<1 || motion_data[i].forw_hor_f_code>9)
121 error("f_code must be between 1 and 9");
122 if (motion_data[i].forw_vert_f_code<1 || motion_data[i].forw_vert_f_code>9)
123 error("f_code must be between 1 and 9");
124 if (mpeg1 && motion_data[i].forw_hor_f_code>7)
125 error("f_code must be le less than 8");
126 if (mpeg1 && motion_data[i].forw_vert_f_code>7)
127 error("f_code must be le less than 8");
128 if (motion_data[i].sxf<=0)
129 error("search window must be positive"); /* doesn't belong here */
130 if (motion_data[i].syf<=0)
131 error("search window must be positive");
134 if (motion_data[i].back_hor_f_code<1 || motion_data[i].back_hor_f_code>9)
135 error("f_code must be between 1 and 9");
136 if (motion_data[i].back_vert_f_code<1 || motion_data[i].back_vert_f_code>9)
137 error("f_code must be between 1 and 9");
138 if (mpeg1 && motion_data[i].back_hor_f_code>7)
139 error("f_code must be le less than 8");
140 if (mpeg1 && motion_data[i].back_vert_f_code>7)
141 error("f_code must be le less than 8");
142 if (motion_data[i].sxb<=0)
143 error("search window must be positive");
144 if (motion_data[i].syb<=0)
145 error("search window must be positive");
150 /* identifies valid profile / level combinations */
151 static char profile_level_defined[5][4] =
154 {1, 1, 1, 0}, /* HP */
155 {0, 1, 0, 0}, /* Spat */
156 {0, 0, 1, 1}, /* SNR */
157 {1, 1, 1, 1}, /* MP */
158 {0, 0, 1, 0} /* SP */
161 static struct level_limits {
167 int bit_rate; /* Mbit/s */
168 int vbv_buffer_size; /* 16384 bit steps */
171 {9, 5, 1920, 1152, 62668800, 80, 597}, /* HL */
172 {9, 5, 1440, 1152, 47001600, 60, 448}, /* H-14 */
173 {8, 5, 720, 576, 10368000, 15, 112}, /* ML */
174 {7, 4, 352, 288, 3041280, 4, 29} /* LL */
188 void profile_and_level_checks()
191 struct level_limits *maxval;
193 if (profile<0 || profile>15)
194 error("profile must be between 0 and 15");
196 if (level<0 || level>15)
197 error("level must be between 0 and 15");
202 fprintf(stderr,"Warning: profile uses a reserved value, conformance checks skipped\n");
206 if (profile<HP || profile>SP)
207 error("undefined Profile");
209 if (profile==SNR || profile==SPAT)
210 error("This encoder currently generates no scalable bitstreams");
212 if (level<HL || level>LL || level&1)
213 error("undefined Level");
215 maxval = &maxval_tab[(level-4) >> 1];
217 /* check profile@level combination */
218 if(!profile_level_defined[profile-1][(level-4) >> 1])
219 error("undefined profile@level combination");
222 /* profile (syntax) constraints */
224 if (profile==SP && M!=1)
225 error("Simple Profile does not allow B pictures");
227 if (profile!=HP && chroma_format!=CHROMA420)
228 error("chroma format must be 4:2:0 in specified Profile");
230 if (profile==HP && chroma_format==CHROMA444)
231 error("chroma format must be 4:2:0 or 4:2:2 in High Profile");
233 if (profile>=MP) /* SP, MP: constrained repeat_first_field */
235 if (frame_rate_code<=2 && repeatfirst)
236 error("repeat_first_first must be zero");
237 if (frame_rate_code<=6 && prog_seq && repeatfirst)
238 error("repeat_first_first must be zero");
241 if (profile!=HP && dc_prec==3)
242 error("11 bit DC precision only allowed in High Profile");
245 /* level (parameter value) constraints */
248 if (frame_rate_code>5 && level>=ML)
249 error("Picture rate greater than permitted in specified Level");
253 if (motion_data[i].forw_hor_f_code > maxval->hor_f_code)
254 error("forward horizontal f_code greater than permitted in specified Level");
256 if (motion_data[i].forw_vert_f_code > maxval->vert_f_code)
257 error("forward vertical f_code greater than permitted in specified Level");
261 if (motion_data[i].back_hor_f_code > maxval->hor_f_code)
262 error("backward horizontal f_code greater than permitted in specified Level");
264 if (motion_data[i].back_vert_f_code > maxval->vert_f_code)
265 error("backward vertical f_code greater than permitted in specified Level");
270 if (horizontal_size > maxval->hor_size)
271 error("Horizontal size is greater than permitted in specified Level");
273 if (vertical_size > maxval->vert_size)
274 error("Horizontal size is greater than permitted in specified Level");
277 if (horizontal_size*vertical_size*frame_rate > maxval->sample_rate)
278 error("Sample rate is greater than permitted in specified Level");
281 if (bit_rate> 1.0e6 * maxval->bit_rate)
282 error("Bit rate is greater than permitted in specified Level");
285 if (vbv_buffer_size > maxval->vbv_buffer_size)
286 error("vbv_buffer_size exceeds High Level limit");