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);
19 void quicktime_delete_esds(quicktime_esds_t
*esds
)
21 if(esds
->mpeg4_header
) free(esds
->mpeg4_header
);
24 void quicktime_esds_samplerate(quicktime_stsd_table_t
*table
,
25 quicktime_esds_t
*esds
)
27 // Straight out of ffmpeg
28 if(esds
->mpeg4_header_size
> 1 &&
29 quicktime_match_32(table
->format
, QUICKTIME_MP4A
))
31 static int samplerate_table
[] =
33 96000, 88200, 64000, 48000, 44100, 32000,
34 24000, 22050, 16000, 12000, 11025, 8000,
38 unsigned char *ptr
= esds
->mpeg4_header
;
39 int samplerate_index
= ((ptr
[0] & 7) << 1) + ((ptr
[1] >> 7) & 1);
40 table
->channels
= (ptr
[1] >> 3) & 0xf;
42 samplerate_table
[samplerate_index
];
43 // Faad decodes 1/2 the requested samplerate if the samplerate is <= 22050.
47 void quicktime_read_esds(quicktime_t
*file
,
48 quicktime_atom_t
*parent_atom
,
49 quicktime_esds_t
*esds
)
53 quicktime_read_char(file
);
55 quicktime_read_int24(file
);
56 // elementary stream descriptor tag
58 if(quicktime_read_char(file
) == 0x3)
60 int len
= decode_length(file
);
61 // elementary stream id
62 quicktime_read_int16(file
);
64 quicktime_read_char(file
);
65 // decoder configuration descripton tab
66 if(quicktime_read_char(file
) == 0x4)
68 int len2
= decode_length(file
);
70 quicktime_read_char(file
);
72 quicktime_read_char(file
);
74 quicktime_read_int24(file
);
76 quicktime_read_int32(file
);
78 quicktime_read_int32(file
);
80 // decoder specific description tag
81 if(quicktime_read_char(file
) == 0x5)
83 esds
->mpeg4_header_size
= decode_length(file
);
84 if(!esds
->mpeg4_header_size
) return;
86 // Need padding for FFMPEG
87 esds
->mpeg4_header
= calloc(1,
88 esds
->mpeg4_header_size
+ 1024);
89 // Get extra data for decoder
90 quicktime_read_data(file
,
92 esds
->mpeg4_header_size
);
95 quicktime_atom_skip(file
, parent_atom
);
101 quicktime_atom_skip(file
, parent_atom
);
108 quicktime_atom_skip(file
, parent_atom
);
115 quicktime_atom_skip(file
, parent_atom
);
122 void quicktime_write_esds(quicktime_t
*file
,
123 quicktime_esds_t
*esds
,
127 quicktime_atom_t atom
;
128 quicktime_atom_write_header(file
, &atom
, "esds");
130 quicktime_write_char(file
, 0);
132 quicktime_write_int24(file
, 0);
134 // elementary stream descriptor tag
135 quicktime_write_char(file
, 0x3);
137 // length placeholder
138 int64_t length1
= quicktime_position(file
);
139 // quicktime_write_int32(file, 0x80808080);
140 quicktime_write_char(file
, 0x00);
142 // elementary stream id
143 quicktime_write_int16(file
, 0x1);
148 * quicktime_write_char(file, 0x1f);
151 quicktime_write_char(file
, 0);
154 // decoder configuration description tab
155 quicktime_write_char(file
, 0x4);
156 // length placeholder
157 int64_t length2
= quicktime_position(file
);
158 // quicktime_write_int32(file, 0x80808080);
159 quicktime_write_char(file
, 0x00);
165 quicktime_write_char(file
, 0x20);
167 quicktime_write_char(file
, 0x11);
169 // quicktime_write_int24(file, 0x007b00);
170 quicktime_write_int24(file
, 0x000000);
172 // quicktime_write_int32(file, 0x00014800);
173 quicktime_write_int32(file
, 0x000030d40);
175 // quicktime_write_int32(file, 0x00014800);
176 quicktime_write_int32(file
, 0x00000000);
181 quicktime_write_char(file
, 0x40);
183 quicktime_write_char(file
, 0x15);
185 quicktime_write_int24(file
, 0x001800);
187 quicktime_write_int32(file
, 0x00004e20);
189 quicktime_write_int32(file
, 0x00003e80);
192 // decoder specific description tag
193 quicktime_write_char(file
, 0x05);
194 // length placeholder
195 int64_t length3
= quicktime_position(file
);
196 // quicktime_write_int32(file, 0x80808080);
197 quicktime_write_char(file
, 0x00);
199 // mpeg4 sequence header
200 quicktime_write_data(file
, esds
->mpeg4_header
, esds
->mpeg4_header_size
);
203 int64_t current_length2
= quicktime_position(file
) - length2
- 1;
204 int64_t current_length3
= quicktime_position(file
) - length3
- 1;
206 // unknown tag, length and data
207 quicktime_write_char(file
, 0x06);
208 // quicktime_write_int32(file, 0x80808001);
209 quicktime_write_char(file
, 0x01);
210 quicktime_write_char(file
, 0x02);
214 int64_t current_length1
= quicktime_position(file
) - length1
- 1;
215 quicktime_atom_write_footer(file
, &atom
);
216 int64_t current_position
= quicktime_position(file
);
217 // quicktime_set_position(file, length1 + 3);
218 quicktime_set_position(file
, length1
);
219 quicktime_write_char(file
, current_length1
);
220 // quicktime_set_position(file, length2 + 3);
221 quicktime_set_position(file
, length2
);
222 quicktime_write_char(file
, current_length2
);
223 // quicktime_set_position(file, length3 + 3);
224 quicktime_set_position(file
, length3
);
225 quicktime_write_char(file
, current_length3
);
226 quicktime_set_position(file
, current_position
);
229 void quicktime_esds_dump(quicktime_esds_t
*esds
)
231 printf(" elementary stream description\n");
232 printf(" mpeg4_header_size=0x%x\n", esds
->mpeg4_header_size
);
233 printf(" mpeg4_header=");
235 for(i
= 0; i
< esds
->mpeg4_header_size
; i
++)
236 printf("%02x ", (unsigned char)esds
->mpeg4_header
[i
]);