6 #include <schroedinger/schro.h>
7 #include <schroedinger/schrobitstream.h>
8 #include <schroedinger/schrounpack.h>
13 /* Used for checking bitstream bugs */
16 g_print(" marker: %d\n", schro_unpack_decode_uint(&unpack)); \
22 static void handle_packet(unsigned char *data
, int size
);
24 char *fn
= "output.drc";
27 main (int argc
, char *argv
[])
35 file
= fopen (fn
, "r");
37 printf("cannot open %s\n", fn
);
42 unsigned char *packet
;
43 unsigned char header
[13];
47 n
= fread (header
, 1, 13, file
);
52 printf("truncated header\n");
56 if (header
[0] != 'B' || header
[1] != 'B' || header
[2] != 'C' ||
58 printf("expected BBCD header\n");
62 size
= (header
[5]<<24) | (header
[6]<<16) | (header
[7]<<8) | (header
[8]);
67 printf("packet too small (%d < 13)\n", size
);
70 if (size
> 16*1024*1024) {
71 printf("packet too large? (%d > 16777216)\n", size
);
75 packet
= malloc (size
);
76 memcpy (packet
, header
, 13);
77 n
= fread (packet
+ 13, 1, size
- 13, file
);
79 printf("truncated packet (%d < %d)\n", n
, size
-13);
83 handle_packet (packet
, size
);
92 dump_hex (unsigned char *data
, int length
, char *prefix
)
95 for(i
=0;i
<length
;i
++){
97 printf("%s0x%04x: ", prefix
, i
);
99 printf("%02x ", data
[i
]);
100 if ((i
&0xf) == 0xf) {
104 if ((i
&0xf) != 0xf) {
110 handle_packet(unsigned char *data
, int size
)
113 const char *parse_code
;
117 if (memcmp (data
, "KW-DIRAC", 8) == 0) {
118 printf("KW-DIRAC header\n");
121 if (memcmp (data
, "BBCD", 4) != 0) {
122 printf("non-Dirac packet\n");
123 dump_hex (data
, MIN(size
, 100), " ");
128 case SCHRO_PARSE_CODE_SEQUENCE_HEADER
:
129 parse_code
= "access unit header";
131 case SCHRO_PARSE_CODE_AUXILIARY_DATA
:
132 parse_code
= "auxiliary data";
134 case SCHRO_PARSE_CODE_INTRA_REF
:
135 parse_code
= "intra ref";
137 case SCHRO_PARSE_CODE_INTRA_NON_REF
:
138 parse_code
= "intra non-ref";
140 case SCHRO_PARSE_CODE_INTER_REF_1
:
141 parse_code
= "inter ref 1";
143 case SCHRO_PARSE_CODE_INTER_REF_2
:
144 parse_code
= "inter ref 2";
146 case SCHRO_PARSE_CODE_INTER_NON_REF_1
:
147 parse_code
= "inter non-ref 1";
149 case SCHRO_PARSE_CODE_INTER_NON_REF_2
:
150 parse_code
= "inter non-ref 2";
152 case SCHRO_PARSE_CODE_END_OF_SEQUENCE
:
153 parse_code
= "end of sequence";
155 case SCHRO_PARSE_CODE_LD_INTRA_REF
:
156 parse_code
= "low-delay intra ref";
158 case SCHRO_PARSE_CODE_LD_INTRA_NON_REF
:
159 parse_code
= "low-delay intra non-ref";
161 case SCHRO_PARSE_CODE_INTRA_REF_NOARITH
:
162 parse_code
= "intra ref noarith";
164 case SCHRO_PARSE_CODE_INTRA_NON_REF_NOARITH
:
165 parse_code
= "intra non-ref noarith";
167 case SCHRO_PARSE_CODE_INTER_REF_1_NOARITH
:
168 parse_code
= "inter ref 1 noarith";
170 case SCHRO_PARSE_CODE_INTER_REF_2_NOARITH
:
171 parse_code
= "inter ref 2 noarith";
173 case SCHRO_PARSE_CODE_INTER_NON_REF_1_NOARITH
:
174 parse_code
= "inter non-ref 1 noarith";
176 case SCHRO_PARSE_CODE_INTER_NON_REF_2_NOARITH
:
177 parse_code
= "inter non-ref 2 noarith";
179 case SCHRO_PARSE_CODE_PADDING
:
180 parse_code
= "padding";
183 parse_code
= "unknown";
186 printf("Parse code: %s (0x%02x)\n", parse_code
, data
[4]);
188 schro_unpack_init_with_data (&unpack
, data
+ 5, size
- 5, 1);
190 next
= schro_unpack_decode_bits (&unpack
, 32);
191 prev
= schro_unpack_decode_bits (&unpack
, 32);
193 printf(" offset to next: %d\n", next
);
194 printf(" offset to prev: %d\n", prev
);
196 if (data
[4] == SCHRO_PARSE_CODE_SEQUENCE_HEADER
) {
199 /* parse parameters */
200 printf(" version.major: %d\n", schro_unpack_decode_uint(&unpack
));
201 printf(" version.minor: %d\n", schro_unpack_decode_uint(&unpack
));
202 printf(" profile: %d\n", schro_unpack_decode_uint(&unpack
));
203 printf(" level: %d\n", schro_unpack_decode_uint(&unpack
));
205 /* sequence parameters */
206 printf(" video_format: %d\n", schro_unpack_decode_uint(&unpack
));
208 bit
= schro_unpack_decode_bit(&unpack
);
209 printf(" custom dimensions flag: %s\n", bit
? "yes" : "no");
211 printf(" width: %d\n", schro_unpack_decode_uint(&unpack
));
212 printf(" height: %d\n", schro_unpack_decode_uint(&unpack
));
215 bit
= schro_unpack_decode_bit(&unpack
);
216 printf(" chroma format flag: %s\n", bit
? "yes" : "no");
218 printf(" chroma format: %d\n", schro_unpack_decode_uint(&unpack
));
221 bit
= schro_unpack_decode_bit(&unpack
);
222 printf(" custom_scan_format_flag: %s\n", bit
? "yes" : "no");
224 printf(" source sampling: %d\n", schro_unpack_decode_uint(&unpack
));
229 bit
= schro_unpack_decode_bit(&unpack
);
230 printf(" frame rate flag: %s\n", bit
? "yes" : "no");
232 int index
= schro_unpack_decode_uint(&unpack
);
233 printf(" frame rate index: %d\n", index
);
235 printf(" frame rate numerator: %d\n",
236 schro_unpack_decode_uint(&unpack
));
237 printf(" frame rate demoninator: %d\n",
238 schro_unpack_decode_uint(&unpack
));
244 bit
= schro_unpack_decode_bit(&unpack
);
245 printf(" aspect ratio flag: %s\n", bit
? "yes" : "no");
247 int index
= schro_unpack_decode_uint(&unpack
);
248 printf(" aspect ratio index: %d\n", index
);
250 printf(" aspect ratio numerator: %d\n",
251 schro_unpack_decode_uint(&unpack
));
252 printf(" aspect ratio demoninator: %d\n",
253 schro_unpack_decode_uint(&unpack
));
259 bit
= schro_unpack_decode_bit(&unpack
);
260 printf(" clean area flag: %s\n", bit
? "yes" : "no");
262 printf(" clean width: %d\n", schro_unpack_decode_uint(&unpack
));
263 printf(" clean height: %d\n", schro_unpack_decode_uint(&unpack
));
264 printf(" left offset: %d\n", schro_unpack_decode_uint(&unpack
));
265 printf(" top offset: %d\n", schro_unpack_decode_uint(&unpack
));
270 bit
= schro_unpack_decode_bit(&unpack
);
271 printf(" signal range flag: %s\n", bit
? "yes" : "no");
273 int index
= schro_unpack_decode_uint(&unpack
);
274 printf(" signal range index: %d\n", index
);
276 printf(" luma offset: %d\n", schro_unpack_decode_uint(&unpack
));
277 printf(" luma excursion: %d\n", schro_unpack_decode_uint(&unpack
));
278 printf(" chroma offset: %d\n", schro_unpack_decode_uint(&unpack
));
279 printf(" chroma excursion: %d\n", schro_unpack_decode_uint(&unpack
));
285 bit
= schro_unpack_decode_bit(&unpack
);
286 printf(" colour spec flag: %s\n", bit
? "yes" : "no");
288 int index
= schro_unpack_decode_uint(&unpack
);
289 printf(" colour spec index: %d\n", index
);
291 bit
= schro_unpack_decode_bit(&unpack
);
292 printf(" colour primaries flag: %s\n", bit
? "yes" : "no");
294 printf(" colour primaries: %d\n",
295 schro_unpack_decode_uint(&unpack
));
297 bit
= schro_unpack_decode_bit(&unpack
);
298 printf(" colour matrix flag: %s\n", bit
? "yes" : "no");
300 printf(" colour matrix: %d\n", schro_unpack_decode_uint(&unpack
));
302 bit
= schro_unpack_decode_bit(&unpack
);
303 printf(" transfer function flag: %s\n", bit
? "yes" : "no");
305 printf(" transfer function: %d\n",
306 schro_unpack_decode_uint(&unpack
));
311 printf(" interlaced_coding: %d\n", schro_unpack_decode_uint(&unpack
));
315 } else if (SCHRO_PARSE_CODE_IS_PICTURE(data
[4])) {
316 int num_refs
= SCHRO_PARSE_CODE_NUM_REFS(data
[4]);
320 int lowdelay
= SCHRO_PARSE_CODE_IS_LOW_DELAY(data
[4]);
322 printf(" num refs: %d\n", num_refs
);
324 schro_unpack_byte_sync(&unpack
);
325 printf(" picture_number: %u\n", schro_unpack_decode_bits(&unpack
, 32));
327 printf(" ref1_offset: %d\n", schro_unpack_decode_sint(&unpack
));
330 printf(" ref2_offset: %d\n", schro_unpack_decode_sint(&unpack
));
332 if (SCHRO_PARSE_CODE_IS_REFERENCE(data
[4])) {
333 int r
= schro_unpack_decode_sint(&unpack
);
335 printf(" retire: none\n");
337 printf(" retire: %d\n", r
);
344 schro_unpack_byte_sync(&unpack
);
345 index
= schro_unpack_decode_uint(&unpack
);
347 printf(" block parameters index: %d\n", index
);
349 printf(" luma block width: %d\n", schro_unpack_decode_uint(&unpack
));
350 printf(" luma block height: %d\n", schro_unpack_decode_uint(&unpack
));
351 printf(" horiz luma block sep: %d\n", schro_unpack_decode_uint(&unpack
));
352 printf(" vert luma block sep: %d\n", schro_unpack_decode_uint(&unpack
));
357 printf(" motion vector precision bits: %d\n", schro_unpack_decode_uint(&unpack
));
361 bit
= schro_unpack_decode_bit(&unpack
);
362 printf(" using global motion flag: %s\n", bit
? "yes" : "no");
364 for(i
=0;i
<num_refs
;i
++){
365 printf(" global motion ref%d:\n", i
+1);
366 bit
= schro_unpack_decode_bit(&unpack
);
367 printf(" non-zero pan/tilt flag: %s\n", bit
? "yes" : "no");
369 printf(" pan %d\n", schro_unpack_decode_sint(&unpack
));
370 printf(" tilt %d\n", schro_unpack_decode_sint(&unpack
));
372 bit
= schro_unpack_decode_bit(&unpack
);
373 printf(" non-zero zoom rot shear flag: %s\n", bit
? "yes" : "no");
375 printf(" exponent %d\n", schro_unpack_decode_uint(&unpack
));
376 printf(" A11 %d\n", schro_unpack_decode_sint(&unpack
));
377 printf(" A12 %d\n", schro_unpack_decode_sint(&unpack
));
378 printf(" A21 %d\n", schro_unpack_decode_sint(&unpack
));
379 printf(" A22 %d\n", schro_unpack_decode_sint(&unpack
));
381 bit
= schro_unpack_decode_bit(&unpack
);
382 printf(" non-zero perspective flag: %s\n", bit
? "yes" : "no");
384 printf(" exponent %d\n", schro_unpack_decode_uint(&unpack
));
385 printf(" perspective_x %d\n", schro_unpack_decode_sint(&unpack
));
386 printf(" perspective_y %d\n", schro_unpack_decode_sint(&unpack
));
393 printf(" picture prediction mode: %d\n", schro_unpack_decode_uint(&unpack
));
395 bit
= schro_unpack_decode_bit(&unpack
);
396 printf(" non-default weights flag: %s\n", bit
? "yes" : "no");
398 printf(" picture weight precision: %d\n",
399 schro_unpack_decode_uint(&unpack
));
400 for(i
=0;i
<num_refs
;i
++){
401 printf(" picture weight ref%d: %d\n", i
+1,
402 schro_unpack_decode_sint(&unpack
));
408 schro_unpack_byte_sync(&unpack
);
410 n
= schro_unpack_decode_uint(&unpack
);
411 printf(" superblock split data length: %d\n", n
);
412 schro_unpack_byte_sync (&unpack
);
413 schro_unpack_skip_bits (&unpack
, n
*8);
415 n
= schro_unpack_decode_uint(&unpack
);
416 printf(" prediction modes data length: %d\n", n
);
417 schro_unpack_byte_sync (&unpack
);
418 schro_unpack_skip_bits (&unpack
, n
*8);
420 n
= schro_unpack_decode_uint(&unpack
);
421 printf(" vector data (ref1,x) length: %d\n", n
);
422 schro_unpack_byte_sync (&unpack
);
423 schro_unpack_skip_bits (&unpack
, n
*8);
425 n
= schro_unpack_decode_uint(&unpack
);
426 printf(" vector data (ref1,y) length: %d\n", n
);
427 schro_unpack_byte_sync (&unpack
);
428 schro_unpack_skip_bits (&unpack
, n
*8);
431 n
= schro_unpack_decode_uint(&unpack
);
432 printf(" vector data (ref2,x) length: %d\n", n
);
433 schro_unpack_byte_sync (&unpack
);
434 schro_unpack_skip_bits (&unpack
, n
*8);
436 n
= schro_unpack_decode_uint(&unpack
);
437 printf(" vector data (ref2,y) length: %d\n", n
);
438 schro_unpack_byte_sync (&unpack
);
439 schro_unpack_skip_bits (&unpack
, n
*8);
442 n
= schro_unpack_decode_uint(&unpack
);
443 printf(" DC data (y) length: %d\n", n
);
444 schro_unpack_byte_sync (&unpack
);
445 schro_unpack_skip_bits (&unpack
, n
*8);
447 n
= schro_unpack_decode_uint(&unpack
);
448 printf(" DC data (u) length: %d\n", n
);
449 schro_unpack_byte_sync (&unpack
);
450 schro_unpack_skip_bits (&unpack
, n
*8);
452 n
= schro_unpack_decode_uint(&unpack
);
453 printf(" DC data (v) length: %d\n", n
);
454 schro_unpack_byte_sync (&unpack
);
455 schro_unpack_skip_bits (&unpack
, n
*8);
459 schro_unpack_byte_sync (&unpack
);
463 bit
= schro_unpack_decode_bit (&unpack
);
464 printf(" zero residual: %s\n", bit
? "yes" : "no");
470 printf(" wavelet index: %d\n", schro_unpack_decode_uint(&unpack
));
472 depth
= schro_unpack_decode_uint(&unpack
);
473 printf(" transform depth: %d\n", depth
);
476 bit
= schro_unpack_decode_bit (&unpack
);
477 printf(" spatial partition flag: %s\n", bit
? "yes" : "no");
479 for(i
=0;i
<depth
+1;i
++){
480 printf(" number of codeblocks depth=%d\n", i
);
481 printf(" horizontal codeblocks: %d\n",
482 schro_unpack_decode_uint(&unpack
));
483 printf(" vertical codeblocks: %d\n",
484 schro_unpack_decode_uint(&unpack
));
486 printf(" codeblock mode index: %d\n", schro_unpack_decode_uint(&unpack
));
489 schro_unpack_byte_sync (&unpack
);
491 printf(" component %d:\n",j
);
492 printf(" comp subband length quantiser_index\n");
493 for(i
=0;i
<1+depth
*3;i
++){
497 printf(" PAST END\n");
501 length
= schro_unpack_decode_uint(&unpack
);
503 printf(" %4d %4d: %6d %3d\n", j
, i
, length
,
504 schro_unpack_decode_uint(&unpack
));
505 schro_unpack_byte_sync(&unpack
);
506 schro_unpack_skip_bits (&unpack
, length
*8);
508 printf(" %4d %4d: %6d\n", j
, i
, length
);
509 schro_unpack_byte_sync(&unpack
);
516 int slice_bytes_numerator
;
517 int slice_bytes_denominator
;
519 slice_x
= schro_unpack_decode_uint(&unpack
);
520 slice_y
= schro_unpack_decode_uint(&unpack
);
521 slice_bytes_numerator
= schro_unpack_decode_uint(&unpack
);
522 slice_bytes_denominator
= schro_unpack_decode_uint(&unpack
);
524 printf(" n_horiz_slices: %d\n", slice_x
);
525 printf(" n_horiz_slices: %d\n", slice_y
);
526 printf(" slice_bytes_numerator: %d\n", slice_bytes_numerator
);
527 printf(" slice_bytes_denominator: %d\n", slice_bytes_denominator
);
529 bit
= schro_unpack_decode_bit (&unpack
);
530 printf(" encode_quant_matrix: %s\n", bit
? "yes" : "no");
532 for(i
=0;i
<1+depth
*3;i
++){
533 printf(" %2d: %d\n", i
, schro_unpack_decode_uint(&unpack
));
537 schro_unpack_byte_sync (&unpack
);
540 } else if (data
[4] == SCHRO_PARSE_CODE_AUXILIARY_DATA
) {
541 int length
= next
- 14;
545 printf(" code: 0 (invalid)\n");
548 printf(" code: 1 (encoder implementation/version)\n");
549 printf(" string: %.*s\n", length
, data
+ 14);
552 printf(" code: 2 (SMPTE 12M timecode)\n");
557 printf(" code: 3 (MD5 checksum)\n");
558 printf(" checksum: ");
560 printf("%02x", data
[14+i
]);
568 printf(" code: %d (bitrate)\n", code
);
569 bitrate
= (data
[14]<<24);
570 bitrate
|= (data
[15]<<16);
571 bitrate
|= (data
[16]<<8);
572 bitrate
|= (data
[17]<<0);
573 printf(" bitrate: %d\n", bitrate
);
577 printf(" code: %d (unknown)\n", code
);
578 dump_hex (data
+ 14, length
, " ");
582 schro_unpack_skip_bits (&unpack
, (1 + length
)*8);
583 } else if (data
[4] == SCHRO_PARSE_CODE_PADDING
) {
584 int length
= next
- 13;
585 schro_unpack_skip_bits (&unpack
, length
*8);
588 schro_unpack_byte_sync (&unpack
);
590 printf("offset %d\n", schro_unpack_get_bits_read (&unpack
)/8);
591 dump_hex (unpack
.data
, MIN(data
+ size
- unpack
.data
, 100), " ");