Mercurial > mplayer.hg
comparison libmpeg2/stats.c @ 1:3b5f5d1c5041
Initial revision
author | arpi_esp |
---|---|
date | Sat, 24 Feb 2001 20:28:24 +0000 |
parents | |
children | 846535ace7a2 |
comparison
equal
deleted
inserted
replaced
0:c1bb2c071d63 | 1:3b5f5d1c5041 |
---|---|
1 /* | |
2 * stats.c | |
3 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca> | |
4 * | |
5 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder. | |
6 * | |
7 * mpeg2dec is free software; you can redistribute it and/or modify | |
8 * it under the terms of the GNU General Public License as published by | |
9 * the Free Software Foundation; either version 2 of the License, or | |
10 * (at your option) any later version. | |
11 * | |
12 * mpeg2dec is distributed in the hope that it will be useful, | |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 * GNU General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU General Public License | |
18 * along with this program; if not, write to the Free Software | |
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
20 */ | |
21 | |
22 #include "config.h" | |
23 | |
24 #include <stdio.h> | |
25 #include <stdlib.h> | |
26 #include <inttypes.h> | |
27 | |
28 #include "mpeg2_internal.h" | |
29 | |
30 static int debug_level = -1; | |
31 | |
32 // Determine is debug output is required. | |
33 // We could potentially have multiple levels of debug info | |
34 static int debug_is_on (void) | |
35 { | |
36 char * env_var; | |
37 | |
38 if (debug_level < 0) { | |
39 env_var = getenv ("MPEG2_DEBUG"); | |
40 | |
41 if (env_var) | |
42 debug_level = 1; | |
43 else | |
44 debug_level = 0; | |
45 } | |
46 | |
47 return debug_level; | |
48 } | |
49 | |
50 static void stats_picture (uint8_t * buffer) | |
51 { | |
52 static char * picture_coding_type_str [8] = { | |
53 "Invalid picture type", | |
54 "I-type", | |
55 "P-type", | |
56 "B-type", | |
57 "D (very bad)", | |
58 "Invalid","Invalid","Invalid" | |
59 }; | |
60 | |
61 int picture_coding_type; | |
62 int temporal_reference; | |
63 int vbv_delay; | |
64 | |
65 temporal_reference = (buffer[0] << 2) | (buffer[1] >> 6); | |
66 picture_coding_type = (buffer [1] >> 3) & 7; | |
67 vbv_delay = ((buffer[1] << 13) | (buffer[2] << 5) | | |
68 (buffer[3] >> 3)) & 0xffff; | |
69 | |
70 fprintf (stderr, " (picture) %s temporal_reference %d, vbv_delay %d\n", | |
71 picture_coding_type_str [picture_coding_type], | |
72 temporal_reference, vbv_delay); | |
73 } | |
74 | |
75 static void stats_user_data (uint8_t * buffer) | |
76 { | |
77 fprintf (stderr, " (user_data)\n"); | |
78 } | |
79 | |
80 static void stats_sequence (uint8_t * buffer) | |
81 { | |
82 static char * aspect_ratio_information_str[8] = { | |
83 "Invalid Aspect Ratio", | |
84 "1:1", | |
85 "4:3", | |
86 "16:9", | |
87 "2.21:1", | |
88 "Invalid Aspect Ratio", | |
89 "Invalid Aspect Ratio", | |
90 "Invalid Aspect Ratio" | |
91 }; | |
92 static char * frame_rate_str[16] = { | |
93 "Invalid frame_rate_code", | |
94 "23.976", "24", "25" , "29.97", | |
95 "30" , "50", "59.94", "60" , | |
96 "Invalid frame_rate_code", "Invalid frame_rate_code", | |
97 "Invalid frame_rate_code", "Invalid frame_rate_code", | |
98 "Invalid frame_rate_code", "Invalid frame_rate_code", | |
99 "Invalid frame_rate_code" | |
100 }; | |
101 | |
102 int horizontal_size; | |
103 int vertical_size; | |
104 int aspect_ratio_information; | |
105 int frame_rate_code; | |
106 int bit_rate_value; | |
107 int vbv_buffer_size_value; | |
108 int constrained_parameters_flag; | |
109 int load_intra_quantizer_matrix; | |
110 int load_non_intra_quantizer_matrix; | |
111 | |
112 vertical_size = (buffer[0] << 16) | (buffer[1] << 8) | buffer[2]; | |
113 horizontal_size = vertical_size >> 12; | |
114 vertical_size &= 0xfff; | |
115 aspect_ratio_information = buffer[3] >> 4; | |
116 frame_rate_code = buffer[3] & 15; | |
117 bit_rate_value = (buffer[4] << 10) | (buffer[5] << 2) | (buffer[6] >> 6); | |
118 vbv_buffer_size_value = ((buffer[6] << 5) | (buffer[7] >> 3)) & 0x3ff; | |
119 constrained_parameters_flag = buffer[7] & 4; | |
120 load_intra_quantizer_matrix = buffer[7] & 2; | |
121 if (load_intra_quantizer_matrix) | |
122 buffer += 64; | |
123 load_non_intra_quantizer_matrix = buffer[7] & 1; | |
124 | |
125 fprintf (stderr, " (seq) %dx%d %s, %s fps, %5.0f kbps, VBV %d kB%s%s%s\n", | |
126 horizontal_size, vertical_size, | |
127 aspect_ratio_information_str [aspect_ratio_information], | |
128 frame_rate_str [frame_rate_code], | |
129 bit_rate_value * 400.0 / 1000.0, | |
130 2 * vbv_buffer_size_value, | |
131 constrained_parameters_flag ? " , CP":"", | |
132 load_intra_quantizer_matrix ? " , Custom Intra Matrix":"", | |
133 load_non_intra_quantizer_matrix ? " , Custom Non-Intra Matrix":""); | |
134 } | |
135 | |
136 static void stats_sequence_error (uint8_t * buffer) | |
137 { | |
138 fprintf (stderr, " (sequence_error)\n"); | |
139 } | |
140 | |
141 static void stats_sequence_end (uint8_t * buffer) | |
142 { | |
143 fprintf (stderr, " (sequence_end)\n"); | |
144 } | |
145 | |
146 static void stats_group (uint8_t * buffer) | |
147 { | |
148 fprintf (stderr, " (group)%s%s\n", | |
149 (buffer[4] & 0x40) ? " closed_gop" : "", | |
150 (buffer[4] & 0x20) ? " broken_link" : ""); | |
151 } | |
152 | |
153 static void stats_slice (uint8_t code, uint8_t * buffer) | |
154 { | |
155 //fprintf (stderr, " (slice %d)\n", code); | |
156 } | |
157 | |
158 static void stats_sequence_extension (uint8_t * buffer) | |
159 { | |
160 static char * chroma_format_str[4] = { | |
161 "Invalid Chroma Format", | |
162 "4:2:0 Chroma", | |
163 "4:2:2 Chroma", | |
164 "4:4:4 Chroma" | |
165 }; | |
166 | |
167 int progressive_sequence; | |
168 int chroma_format; | |
169 | |
170 progressive_sequence = (buffer[1] >> 3) & 1; | |
171 chroma_format = (buffer[1] >> 1) & 3; | |
172 | |
173 fprintf (stderr, " (seq_ext) progressive_sequence %d, %s\n", | |
174 progressive_sequence, chroma_format_str [chroma_format]); | |
175 } | |
176 | |
177 static void stats_sequence_display_extension (uint8_t * buffer) | |
178 { | |
179 fprintf (stderr, " (sequence_display_extension)\n"); | |
180 } | |
181 | |
182 static void stats_quant_matrix_extension (uint8_t * buffer) | |
183 { | |
184 fprintf (stderr, " (quant_matrix_extension)\n"); | |
185 } | |
186 | |
187 static void stats_copyright_extension (uint8_t * buffer) | |
188 { | |
189 fprintf (stderr, " (copyright_extension)\n"); | |
190 } | |
191 | |
192 | |
193 static void stats_sequence_scalable_extension (uint8_t * buffer) | |
194 { | |
195 fprintf (stderr, " (sequence_scalable_extension)\n"); | |
196 } | |
197 | |
198 static void stats_picture_display_extension (uint8_t * buffer) | |
199 { | |
200 fprintf (stderr, " (picture_display_extension)\n"); | |
201 } | |
202 | |
203 static void stats_picture_coding_extension (uint8_t * buffer) | |
204 { | |
205 static char * picture_structure_str[4] = { | |
206 "Invalid Picture Structure", | |
207 "Top field", | |
208 "Bottom field", | |
209 "Frame Picture" | |
210 }; | |
211 | |
212 int f_code[2][2]; | |
213 int intra_dc_precision; | |
214 int picture_structure; | |
215 int top_field_first; | |
216 int frame_pred_frame_dct; | |
217 int concealment_motion_vectors; | |
218 int q_scale_type; | |
219 int intra_vlc_format; | |
220 int alternate_scan; | |
221 int repeat_first_field; | |
222 int progressive_frame; | |
223 | |
224 f_code[0][0] = buffer[0] & 15; | |
225 f_code[0][1] = buffer[1] >> 4; | |
226 f_code[1][0] = buffer[1] & 15; | |
227 f_code[1][1] = buffer[2] >> 4; | |
228 intra_dc_precision = (buffer[2] >> 2) & 3; | |
229 picture_structure = buffer[2] & 3; | |
230 top_field_first = buffer[3] >> 7; | |
231 frame_pred_frame_dct = (buffer[3] >> 6) & 1; | |
232 concealment_motion_vectors = (buffer[3] >> 5) & 1; | |
233 q_scale_type = (buffer[3] >> 4) & 1; | |
234 intra_vlc_format = (buffer[3] >> 3) & 1; | |
235 alternate_scan = (buffer[3] >> 2) & 1; | |
236 repeat_first_field = (buffer[3] >> 1) & 1; | |
237 progressive_frame = buffer[4] >> 7; | |
238 | |
239 fprintf (stderr, | |
240 " (pic_ext) %s\n", picture_structure_str [picture_structure]); | |
241 fprintf (stderr, | |
242 " (pic_ext) forward horizontal f_code % d, forward vertical f_code % d\n", | |
243 f_code[0][0], f_code[0][1]); | |
244 fprintf (stderr, | |
245 " (pic_ext) backward horizontal f_code % d, backward vertical f_code % d\n", | |
246 f_code[1][0], f_code[1][1]); | |
247 fprintf (stderr, | |
248 " (pic_ext) intra_dc_precision %d, top_field_first %d, frame_pred_frame_dct %d\n", | |
249 intra_dc_precision, top_field_first, frame_pred_frame_dct); | |
250 fprintf (stderr, | |
251 " (pic_ext) concealment_motion_vectors %d, q_scale_type %d, intra_vlc_format %d\n", | |
252 concealment_motion_vectors, q_scale_type, intra_vlc_format); | |
253 fprintf (stderr, | |
254 " (pic_ext) alternate_scan %d, repeat_first_field %d, progressive_frame %d\n", | |
255 alternate_scan, repeat_first_field, progressive_frame); | |
256 } | |
257 | |
258 void stats_header (uint8_t code, uint8_t * buffer) | |
259 { | |
260 if (! (debug_is_on ())) | |
261 return; | |
262 | |
263 switch (code) { | |
264 case 0x00: | |
265 stats_picture (buffer); | |
266 break; | |
267 case 0xb2: | |
268 stats_user_data (buffer); | |
269 break; | |
270 case 0xb3: | |
271 stats_sequence (buffer); | |
272 break; | |
273 case 0xb4: | |
274 stats_sequence_error (buffer); | |
275 break; | |
276 case 0xb5: | |
277 //stats_extension (buffer); | |
278 switch (buffer[0] >> 4) { | |
279 case 1: | |
280 stats_sequence_extension (buffer); | |
281 break; | |
282 case 2: | |
283 stats_sequence_display_extension (buffer); | |
284 break; | |
285 case 3: | |
286 stats_quant_matrix_extension (buffer); | |
287 break; | |
288 case 4: | |
289 stats_copyright_extension (buffer); | |
290 break; | |
291 case 5: | |
292 stats_sequence_scalable_extension (buffer); | |
293 break; | |
294 case 7: | |
295 stats_picture_display_extension (buffer); | |
296 break; | |
297 case 8: | |
298 stats_picture_coding_extension (buffer); | |
299 break; | |
300 default: | |
301 fprintf (stderr, " (unknown extension %#x)\n", buffer[0] >> 4); | |
302 } | |
303 break; | |
304 case 0xb7: | |
305 stats_sequence_end (buffer); | |
306 break; | |
307 case 0xb8: | |
308 stats_group (buffer); | |
309 break; | |
310 default: | |
311 if (code < 0xb0) | |
312 stats_slice (code, buffer); | |
313 else | |
314 fprintf (stderr, " (unknown start code %#02x)\n", code); | |
315 } | |
316 } |