1 #include "funcprotos.h"
5 static int decode_length(quicktime_t
*file
)
12 byte
= quicktime_read_char(file
);
13 result
= (result
<< 7) + (byte
& 0x7f);
15 }while((byte
& 0x80) && bytes
< 4);
20 void quicktime_read_esds(quicktime_t
*file
,
21 quicktime_atom_t
*parent_atom
,
22 quicktime_stsd_table_t
*table
)
25 quicktime_read_char(file
);
27 quicktime_read_int24(file
);
28 // elementary stream descriptor tag
30 if(quicktime_read_char(file
) == 0x3)
32 int len
= decode_length(file
);
33 // elementary stream id
34 quicktime_read_int16(file
);
36 quicktime_read_char(file
);
37 // decoder configuration descripton tab
38 if(quicktime_read_char(file
) == 0x4)
40 int len2
= decode_length(file
);
42 quicktime_read_char(file
);
44 quicktime_read_char(file
);
46 quicktime_read_int24(file
);
48 quicktime_read_int32(file
);
50 quicktime_read_int32(file
);
52 // decoder specific description tag
53 if(quicktime_read_char(file
) == 0x5)
55 table
->mpeg4_header_size
= decode_length(file
);
56 if(!table
->mpeg4_header_size
) return;
58 table
->mpeg4_header
= calloc(1, table
->mpeg4_header_size
);
59 // Get mpeg4 sequence header
60 quicktime_read_data(file
,
62 table
->mpeg4_header_size
);
64 quicktime_atom_skip(file
, parent_atom
);
70 quicktime_atom_skip(file
, parent_atom
);
77 quicktime_atom_skip(file
, parent_atom
);
84 quicktime_atom_skip(file
, parent_atom
);
91 void quicktime_write_esds(quicktime_t
*file
,
92 quicktime_stsd_table_t
*table
,
96 quicktime_atom_t atom
;
97 quicktime_atom_write_header(file
, &atom
, "esds");
99 quicktime_write_char(file
, 0);
101 quicktime_write_int24(file
, 0);
103 // elementary stream descriptor tag
104 quicktime_write_char(file
, 0x3);
106 // length placeholder
107 int64_t length1
= quicktime_position(file
);
108 // quicktime_write_int32(file, 0x80808080);
109 quicktime_write_char(file
, 0x00);
111 // elementary stream id
112 quicktime_write_int16(file
, 0);
115 quicktime_write_char(file
, 0x1f);
117 quicktime_write_char(file
, 0);
120 // decoder configuration description tab
121 quicktime_write_char(file
, 0x4);
122 // length placeholder
123 int64_t length2
= quicktime_position(file
);
124 // quicktime_write_int32(file, 0x80808080);
125 quicktime_write_char(file
, 0x00);
131 quicktime_write_char(file
, 0x20);
133 quicktime_write_char(file
, 0x11);
135 quicktime_write_int24(file
, 0x007b00);
137 quicktime_write_int32(file
, 0x00014800);
139 quicktime_write_int32(file
, 0x00014800);
144 quicktime_write_char(file
, 0x40);
146 quicktime_write_char(file
, 0x15);
148 quicktime_write_int24(file
, 0x001800);
150 quicktime_write_int32(file
, 0x00004e20);
152 quicktime_write_int32(file
, 0x00003e80);
155 // decoder specific description tag
156 quicktime_write_char(file
, 0x05);
157 // length placeholder
158 int64_t length3
= quicktime_position(file
);
159 // quicktime_write_int32(file, 0x80808080);
160 quicktime_write_char(file
, 0x00);
162 // mpeg4 sequence header
163 quicktime_write_data(file
, table
->mpeg4_header
, table
->mpeg4_header_size
);
166 int64_t current_length2
= quicktime_position(file
) - length2
- 4;
167 int64_t current_length3
= quicktime_position(file
) - length3
- 4;
169 // unknown tag, length and data
170 quicktime_write_char(file
, 0x06);
171 // quicktime_write_int32(file, 0x80808001);
172 quicktime_write_char(file
, 0x01);
173 quicktime_write_char(file
, 0x02);
177 int64_t current_length1
= quicktime_position(file
) - length1
- 4;
178 quicktime_atom_write_footer(file
, &atom
);
179 int64_t current_position
= quicktime_position(file
);
180 // quicktime_set_position(file, length1 + 3);
181 quicktime_set_position(file
, length1
);
182 quicktime_write_char(file
, current_length1
);
183 // quicktime_set_position(file, length2 + 3);
184 quicktime_set_position(file
, length2
);
185 quicktime_write_char(file
, current_length2
);
186 // quicktime_set_position(file, length3 + 3);
187 quicktime_set_position(file
, length3
);
188 quicktime_write_char(file
, current_length3
);
189 quicktime_set_position(file
, current_position
);