6 #include <schroedinger/schro.h>
7 #include <schroedinger/schrobitstream.h>
8 #include <schroedinger/schrounpack.h>
13 /* Used for checking bitstream bugs */
16 printf(" marker: %d\n", schro_unpack_decode_uint(&unpack)); \
23 static void handle_packet(unsigned char *data
, int size
);
25 char *fn
= "output.drc";
28 main (int argc
, char *argv
[])
36 file
= fopen (fn
, "r");
38 printf("cannot open %s\n", fn
);
43 unsigned char *packet
;
44 unsigned char header
[13];
48 n
= fread (header
, 1, 13, file
);
53 printf("truncated header\n");
57 if (header
[0] != 'B' || header
[1] != 'B' || header
[2] != 'C' ||
59 printf("expected BBCD header\n");
63 size
= (header
[5]<<24) | (header
[6]<<16) | (header
[7]<<8) | (header
[8]);
68 printf("packet too small (%d < 13)\n", size
);
71 if (size
> 16*1024*1024) {
72 printf("packet too large? (%d > 16777216)\n", size
);
76 packet
= malloc (size
);
77 memcpy (packet
, header
, 13);
78 n
= fread (packet
+ 13, 1, size
- 13, file
);
80 printf("truncated packet (%d < %d)\n", n
, size
-13);
84 handle_packet (packet
, size
);
93 dump_hex (unsigned char *data
, int length
, char *prefix
)
96 for(i
=0;i
<length
;i
++){
98 printf("%s0x%04x: ", prefix
, i
);
100 printf("%02x ", data
[i
]);
101 if ((i
&0xf) == 0xf) {
105 if ((i
&0xf) != 0xf) {
111 handle_packet (unsigned char *data
, int size
)
114 const char *parse_code
;
118 if (memcmp (data
, "BBCD", 4) != 0) {
119 printf("non-Dirac packet\n");
120 dump_hex (data
, MIN(size
, 100), " ");
125 case SCHRO_PARSE_CODE_SEQUENCE_HEADER
:
126 parse_code
= "access unit header";
128 case SCHRO_PARSE_CODE_AUXILIARY_DATA
:
129 parse_code
= "auxiliary data";
131 case SCHRO_PARSE_CODE_INTRA_REF
:
132 parse_code
= "intra ref";
134 case SCHRO_PARSE_CODE_INTRA_NON_REF
:
135 parse_code
= "intra non-ref";
137 case SCHRO_PARSE_CODE_INTER_REF_1
:
138 parse_code
= "inter ref 1";
140 case SCHRO_PARSE_CODE_INTER_REF_2
:
141 parse_code
= "inter ref 2";
143 case SCHRO_PARSE_CODE_INTER_NON_REF_1
:
144 parse_code
= "inter non-ref 1";
146 case SCHRO_PARSE_CODE_INTER_NON_REF_2
:
147 parse_code
= "inter non-ref 2";
149 case SCHRO_PARSE_CODE_END_OF_SEQUENCE
:
150 parse_code
= "end of sequence";
152 case SCHRO_PARSE_CODE_LD_INTRA_REF
:
153 parse_code
= "low-delay intra ref";
155 case SCHRO_PARSE_CODE_LD_INTRA_NON_REF
:
156 parse_code
= "low-delay intra non-ref";
158 case SCHRO_PARSE_CODE_INTRA_REF_NOARITH
:
159 parse_code
= "intra ref noarith";
161 case SCHRO_PARSE_CODE_INTRA_NON_REF_NOARITH
:
162 parse_code
= "intra non-ref noarith";
164 case SCHRO_PARSE_CODE_INTER_REF_1_NOARITH
:
165 parse_code
= "inter ref 1 noarith";
167 case SCHRO_PARSE_CODE_INTER_REF_2_NOARITH
:
168 parse_code
= "inter ref 2 noarith";
170 case SCHRO_PARSE_CODE_INTER_NON_REF_1_NOARITH
:
171 parse_code
= "inter non-ref 1 noarith";
173 case SCHRO_PARSE_CODE_INTER_NON_REF_2_NOARITH
:
174 parse_code
= "inter non-ref 2 noarith";
177 parse_code
= "unknown";
180 schro_unpack_init_with_data (&unpack
, data
+ 5, size
- 5, 1);
182 next
= schro_unpack_decode_bits (&unpack
, 32);
183 prev
= schro_unpack_decode_bits (&unpack
, 32);
185 if (data
[4] == SCHRO_PARSE_CODE_SEQUENCE_HEADER
) {
194 } else if (SCHRO_PARSE_CODE_IS_PICTURE(data
[4])) {
195 int num_refs
= SCHRO_PARSE_CODE_NUM_REFS(data
[4]);
197 char ref_chars
[3] = { 'I', 'P', 'B' };
199 schro_unpack_byte_sync(&unpack
);
200 pic_num
= schro_unpack_decode_bits(&unpack
, 32);
201 printf("%6d: ", pic_num
);
202 if (SCHRO_PARSE_CODE_IS_REFERENCE(data
[4])) {
208 printf("%c ", ref_chars
[num_refs
]);
211 printf("%6d ", pic_num
+ schro_unpack_decode_sint(&unpack
));
216 printf("%6d ", pic_num
+ schro_unpack_decode_sint(&unpack
));
221 if (SCHRO_PARSE_CODE_IS_REFERENCE(data
[4])) {
222 int r
= schro_unpack_decode_sint(&unpack
);
226 printf("%6d ", pic_num
+ r
);
231 printf(" %8d\n", next
);
232 } else if (data
[4] == SCHRO_PARSE_CODE_AUXILIARY_DATA
) {
235 schro_unpack_byte_sync (&unpack
);