r563: Ogg theora+vorbis export added
[cinelerra_cv/mob.git] / quicktime / esds.c
blob86b559f0da8d076b8c50365757bbd2a12d131137
1 #include "funcprotos.h"
2 #include "quicktime.h"
5 static int decode_length(quicktime_t *file)
7 int bytes = 0;
8 int result = 0;
9 int byte;
12 byte = quicktime_read_char(file);
13 result = (result << 7) + (byte & 0x7f);
14 bytes++;
15 }while((byte & 0x80) && bytes < 4);
16 return result;
20 void quicktime_read_esds(quicktime_t *file,
21 quicktime_atom_t *parent_atom,
22 quicktime_stsd_table_t *table)
24 // version
25 quicktime_read_char(file);
26 // flags
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);
35 // stream priority
36 quicktime_read_char(file);
37 // decoder configuration descripton tab
38 if(quicktime_read_char(file) == 0x4)
40 int len2 = decode_length(file);
41 // object type id
42 quicktime_read_char(file);
43 // stream type
44 quicktime_read_char(file);
45 // buffer size
46 quicktime_read_int24(file);
47 // max bitrate
48 quicktime_read_int32(file);
49 // average bitrate
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,
61 table->mpeg4_header,
62 table->mpeg4_header_size);
63 // skip rest
64 quicktime_atom_skip(file, parent_atom);
65 return;
67 else
69 // error
70 quicktime_atom_skip(file, parent_atom);
71 return;
74 else
76 // error
77 quicktime_atom_skip(file, parent_atom);
78 return;
81 else
83 // error
84 quicktime_atom_skip(file, parent_atom);
85 return;
91 void quicktime_write_esds(quicktime_t *file,
92 quicktime_stsd_table_t *table,
93 int do_video,
94 int do_audio)
96 quicktime_atom_t atom;
97 quicktime_atom_write_header(file, &atom, "esds");
98 // version
99 quicktime_write_char(file, 0);
100 // flags
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);
113 // stream priority
114 if(do_video)
115 quicktime_write_char(file, 0x1f);
116 else
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);
127 // video
128 if(do_video)
130 // object type id
131 quicktime_write_char(file, 0x20);
132 // stream type
133 quicktime_write_char(file, 0x11);
134 // buffer size
135 quicktime_write_int24(file, 0x007b00);
136 // max bitrate
137 quicktime_write_int32(file, 0x00014800);
138 // average bitrate
139 quicktime_write_int32(file, 0x00014800);
141 else
143 // object type id
144 quicktime_write_char(file, 0x40);
145 // stream type
146 quicktime_write_char(file, 0x15);
147 // buffer size
148 quicktime_write_int24(file, 0x001800);
149 // max bitrate
150 quicktime_write_int32(file, 0x00004e20);
151 // average bitrate
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);
176 // write lengths
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);