Mercurial > audlegacy
annotate Plugins/Input/wma/libffwma/asf.c @ 218:0bea7509d6ba trunk
[svn] Working WMA support. I never said it would be pretty, neno, I should said it would play.
author | chainsaw |
---|---|
date | Mon, 21 Nov 2005 14:59:13 -0800 |
parents | 12004b385a96 |
children | ad1e65c6a854 |
rev | line source |
---|---|
137 | 1 /* |
2 * ASF compatible encoder and decoder. | |
3 * Copyright (c) 2000, 2001 Fabrice Bellard. | |
4 * | |
5 * This library is free software; you can redistribute it and/or | |
6 * modify it under the terms of the GNU Lesser General Public | |
7 * License as published by the Free Software Foundation; either | |
8 * version 2 of the License, or (at your option) any later version. | |
9 * | |
10 * This library is distributed in the hope that it will be useful, | |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 * Lesser General Public License for more details. | |
14 * | |
15 * You should have received a copy of the GNU Lesser General Public | |
16 * License along with this library; if not, write to the Free Software | |
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 */ | |
218
0bea7509d6ba
[svn] Working WMA support. I never said it would be pretty, neno, I should said it would play.
chainsaw
parents:
210
diff
changeset
|
19 #include "avcodec.h" |
210
12004b385a96
[svn] Sync with xmms-wma instead of bmp-wma & GThreadify. Does not explode, but does not play either.
chainsaw
parents:
142
diff
changeset
|
20 #include "avformat.h" |
12004b385a96
[svn] Sync with xmms-wma instead of bmp-wma & GThreadify. Does not explode, but does not play either.
chainsaw
parents:
142
diff
changeset
|
21 #include "avi.h" |
137 | 22 |
23 #include <assert.h> | |
24 #define MPA_FRAME_SIZE 1152 | |
25 #define PACKET_SIZE 3200 | |
26 #define PACKET_HEADER_SIZE 12 | |
27 #define FRAME_HEADER_SIZE 17 | |
28 | |
29 typedef struct { | |
30 int num; | |
31 int seq; | |
32 /* use for reading */ | |
33 AVPacket pkt; | |
34 int frag_offset; | |
35 int timestamp; | |
36 int64_t duration; | |
37 | |
38 int ds_span; /* descrambling */ | |
39 int ds_packet_size; | |
40 int ds_chunk_size; | |
41 int ds_data_size; | |
42 int ds_silence_data; | |
43 | |
44 int packet_pos; | |
45 | |
46 } ASFStream; | |
47 | |
48 typedef struct { | |
49 uint32_t v1; | |
50 uint16_t v2; | |
51 uint16_t v3; | |
52 uint8_t v4[8]; | |
53 } GUID; | |
54 | |
55 typedef struct { | |
56 GUID guid; // generated by client computer | |
57 uint64_t file_size; // in bytes | |
58 // invalid if broadcasting | |
59 uint64_t create_time; // time of creation, in 100-nanosecond units since 1.1.1601 | |
60 // invalid if broadcasting | |
61 uint64_t packets_count; // how many packets are there in the file | |
62 // invalid if broadcasting | |
63 uint64_t play_time; // play time, in 100-nanosecond units | |
64 // invalid if broadcasting | |
65 uint64_t send_time; // time to send file, in 100-nanosecond units | |
66 // invalid if broadcasting (could be ignored) | |
67 uint32_t preroll; // timestamp of the first packet, in milliseconds | |
68 // if nonzero - substract from time | |
69 uint32_t ignore; // preroll is 64bit - but let's just ignore it | |
70 uint32_t flags; // 0x01 - broadcast | |
71 // 0x02 - seekable | |
72 // rest is reserved should be 0 | |
73 uint32_t min_pktsize; // size of a data packet | |
74 // invalid if broadcasting | |
75 uint32_t max_pktsize; // shall be the same as for min_pktsize | |
76 // invalid if broadcasting | |
77 uint32_t max_bitrate; // bandwith of stream in bps | |
78 // should be the sum of bitrates of the | |
79 // individual media streams | |
80 } ASFMainHeader; | |
81 | |
82 | |
83 typedef struct { | |
84 int seqno; | |
85 int packet_size; | |
86 int is_streamed; | |
87 int asfid2avid[128]; /* conversion table from asf ID 2 AVStream ID */ | |
88 ASFStream streams[128]; /* it's max number and it's not that big */ | |
89 /* non streamed additonnal info */ | |
90 int64_t nb_packets; | |
91 int64_t duration; /* in 100ns units */ | |
92 /* packet filling */ | |
93 int packet_size_left; | |
94 int packet_timestamp_start; | |
95 int packet_timestamp_end; | |
96 int packet_nb_frames; | |
97 uint8_t packet_buf[PACKET_SIZE]; | |
98 ByteIOContext pb; | |
99 /* only for reading */ | |
100 uint64_t data_offset; /* begining of the first data packet */ | |
101 | |
102 ASFMainHeader hdr; | |
103 | |
104 int packet_flags; | |
105 int packet_property; | |
106 int packet_timestamp; | |
107 int packet_segsizetype; | |
108 int packet_segments; | |
109 int packet_seq; | |
110 int packet_replic_size; | |
111 int packet_key_frame; | |
112 int packet_padsize; | |
113 int packet_frag_offset; | |
114 int packet_frag_size; | |
115 int packet_frag_timestamp; | |
116 int packet_multi_size; | |
117 int packet_obj_size; | |
118 int packet_time_delta; | |
119 int packet_time_start; | |
120 int packet_pos; | |
121 | |
122 int stream_index; | |
123 ASFStream* asf_st; /* currently decoded stream */ | |
124 } ASFContext; | |
125 | |
126 static const GUID asf_header = { | |
127 0x75B22630, 0x668E, 0x11CF, { 0xA6, 0xD9, 0x00, 0xAA, 0x00, 0x62, 0xCE, 0x6C }, | |
128 }; | |
129 | |
130 static const GUID file_header = { | |
131 0x8CABDCA1, 0xA947, 0x11CF, { 0x8E, 0xE4, 0x00, 0xC0, 0x0C, 0x20, 0x53, 0x65 }, | |
132 }; | |
133 | |
134 static const GUID stream_header = { | |
135 0xB7DC0791, 0xA9B7, 0x11CF, { 0x8E, 0xE6, 0x00, 0xC0, 0x0C, 0x20, 0x53, 0x65 }, | |
136 }; | |
137 | |
138 static const GUID audio_stream = { | |
139 0xF8699E40, 0x5B4D, 0x11CF, { 0xA8, 0xFD, 0x00, 0x80, 0x5F, 0x5C, 0x44, 0x2B }, | |
140 }; | |
141 | |
142 static const GUID audio_conceal_none = { | |
143 // 0x49f1a440, 0x4ece, 0x11d0, { 0xa3, 0xac, 0x00, 0xa0, 0xc9, 0x03, 0x48, 0xf6 }, | |
144 // New value lifted from avifile | |
145 0x20fb5700, 0x5b55, 0x11cf, { 0xa8, 0xfd, 0x00, 0x80, 0x5f, 0x5c, 0x44, 0x2b }, | |
146 }; | |
147 | |
148 | |
149 static const GUID comment_header = { | |
150 0x75b22633, 0x668e, 0x11cf, { 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c }, | |
151 }; | |
152 | |
153 static const GUID codec_comment_header = { | |
154 0x86D15240, 0x311D, 0x11D0, { 0xA3, 0xA4, 0x00, 0xA0, 0xC9, 0x03, 0x48, 0xF6 }, | |
155 }; | |
156 static const GUID codec_comment1_header = { | |
157 0x86d15241, 0x311d, 0x11d0, { 0xa3, 0xa4, 0x00, 0xa0, 0xc9, 0x03, 0x48, 0xf6 }, | |
158 }; | |
159 | |
160 static const GUID data_header = { | |
161 0x75b22636, 0x668e, 0x11cf, { 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c }, | |
162 }; | |
163 | |
164 static const GUID index_guid = { | |
165 0x33000890, 0xe5b1, 0x11cf, { 0x89, 0xf4, 0x00, 0xa0, 0xc9, 0x03, 0x49, 0xcb }, | |
166 }; | |
167 | |
168 static const GUID head1_guid = { | |
169 0x5fbf03b5, 0xa92e, 0x11cf, { 0x8e, 0xe3, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65 }, | |
170 }; | |
171 | |
172 static const GUID head2_guid = { | |
173 0xabd3d211, 0xa9ba, 0x11cf, { 0x8e, 0xe6, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65 }, | |
174 }; | |
175 | |
176 static const GUID extended_content_header = { | |
177 0xD2D0A440, 0xE307, 0x11D2, { 0x97, 0xF0, 0x00, 0xA0, 0xC9, 0x5E, 0xA8, 0x50 }, | |
178 }; | |
179 | |
180 /* I am not a number !!! This GUID is the one found on the PC used to | |
181 generate the stream */ | |
182 static const GUID my_guid = { | |
183 0, 0, 0, { 0, 0, 0, 0, 0, 0, 0, 0 }, | |
184 }; | |
185 | |
186 const CodecTag codec_wav_tags[] = { | |
218
0bea7509d6ba
[svn] Working WMA support. I never said it would be pretty, neno, I should said it would play.
chainsaw
parents:
210
diff
changeset
|
187 /* { CODEC_ID_MP2, 0x50 }, |
137 | 188 { CODEC_ID_MP3, 0x55 }, |
189 { CODEC_ID_AC3, 0x2000 }, | |
190 { CODEC_ID_PCM_S16LE, 0x01 }, | |
218
0bea7509d6ba
[svn] Working WMA support. I never said it would be pretty, neno, I should said it would play.
chainsaw
parents:
210
diff
changeset
|
191 { CODEC_ID_PCM_U8, 0x01 }, |
137 | 192 { CODEC_ID_PCM_ALAW, 0x06 }, |
193 { CODEC_ID_PCM_MULAW, 0x07 }, | |
194 { CODEC_ID_ADPCM_MS, 0x02 }, | |
195 { CODEC_ID_ADPCM_IMA_WAV, 0x11 }, | |
218
0bea7509d6ba
[svn] Working WMA support. I never said it would be pretty, neno, I should said it would play.
chainsaw
parents:
210
diff
changeset
|
196 { CODEC_ID_ADPCM_IMA_DK4, 0x61 }, |
0bea7509d6ba
[svn] Working WMA support. I never said it would be pretty, neno, I should said it would play.
chainsaw
parents:
210
diff
changeset
|
197 { CODEC_ID_ADPCM_IMA_DK3, 0x62 },*/ |
137 | 198 { CODEC_ID_WMAV1, 0x160 }, |
199 { CODEC_ID_WMAV2, 0x161 }, | |
200 { 0, 0 }, | |
201 }; | |
202 | |
203 enum CodecID codec_get_id(const CodecTag *tags, unsigned int tag) | |
204 { | |
205 while (tags->id != 0) { | |
206 if( toupper((tag >> 0)&0xFF) == toupper((tags->tag >> 0)&0xFF) | |
207 && toupper((tag >> 8)&0xFF) == toupper((tags->tag >> 8)&0xFF) | |
208 && toupper((tag >>16)&0xFF) == toupper((tags->tag >>16)&0xFF) | |
209 && toupper((tag >>24)&0xFF) == toupper((tags->tag >>24)&0xFF)) | |
210 return tags->id; | |
211 tags++; | |
212 } | |
213 return CODEC_ID_NONE; | |
214 } | |
215 | |
216 int wav_codec_get_id(unsigned int tag, int bps) | |
217 { | |
218 int id; | |
219 id = codec_get_id(codec_wav_tags, tag); | |
220 if (id <= 0) | |
221 return id; | |
222 /* handle specific u8 codec */ | |
223 if (id == CODEC_ID_PCM_S16LE && bps == 8) | |
224 id = CODEC_ID_PCM_U8; | |
225 return id; | |
226 } | |
227 | |
228 void get_wav_header(ByteIOContext *pb, AVCodecContext *codec, int size) | |
229 { | |
230 int id; | |
231 | |
232 id = get_le16(pb); | |
233 codec->codec_type = CODEC_TYPE_AUDIO; | |
234 codec->codec_tag = id; | |
235 codec->channels = get_le16(pb); | |
236 codec->sample_rate = get_le32(pb); | |
237 codec->bit_rate = get_le32(pb) * 8; | |
238 codec->block_align = get_le16(pb); | |
239 if (size == 14) { /* We're dealing with plain vanilla WAVEFORMAT */ | |
240 codec->bits_per_sample = 8; | |
241 }else | |
242 codec->bits_per_sample = get_le16(pb); | |
243 codec->codec_id = wav_codec_get_id(id, codec->bits_per_sample); | |
244 | |
245 if (size > 16) { /* We're obviously dealing with WAVEFORMATEX */ | |
246 codec->extradata_size = get_le16(pb); | |
247 if (codec->extradata_size > 0) { | |
248 if (codec->extradata_size > size - 18) | |
249 codec->extradata_size = size - 18; | |
210
12004b385a96
[svn] Sync with xmms-wma instead of bmp-wma & GThreadify. Does not explode, but does not play either.
chainsaw
parents:
142
diff
changeset
|
250 codec->extradata = av_mallocz(codec->extradata_size); |
137 | 251 get_buffer(pb, codec->extradata, codec->extradata_size); |
252 } else | |
253 codec->extradata_size = 0; | |
254 | |
255 /* It is possible for the chunk to contain garbage at the end */ | |
256 if (size - codec->extradata_size - 18 > 0) | |
257 url_fskip(pb, size - codec->extradata_size - 18); | |
258 } | |
259 } | |
260 | |
261 /**********************************/ | |
262 /* decoding */ | |
263 | |
264 #ifdef DEBUG | |
265 #define PRINT_IF_GUID(g,cmp) \ | |
266 if (!memcmp(g, &cmp, sizeof(GUID))) \ | |
267 printf("(GUID: %s) ", #cmp) | |
268 | |
269 static void print_guid(const GUID *g) | |
270 { | |
271 int i; | |
272 PRINT_IF_GUID(g, asf_header); | |
273 else PRINT_IF_GUID(g, file_header); | |
274 else PRINT_IF_GUID(g, stream_header); | |
275 else PRINT_IF_GUID(g, audio_stream); | |
276 else PRINT_IF_GUID(g, audio_conceal_none); | |
277 else PRINT_IF_GUID(g, comment_header); | |
278 else PRINT_IF_GUID(g, codec_comment_header); | |
279 else PRINT_IF_GUID(g, codec_comment1_header); | |
280 else PRINT_IF_GUID(g, data_header); | |
281 else PRINT_IF_GUID(g, index_guid); | |
282 else PRINT_IF_GUID(g, head1_guid); | |
283 else PRINT_IF_GUID(g, head2_guid); | |
284 else PRINT_IF_GUID(g, my_guid); | |
285 else | |
286 printf("(GUID: unknown) "); | |
287 printf("0x%08x, 0x%04x, 0x%04x, {", g->v1, g->v2, g->v3); | |
288 for(i=0;i<8;i++) | |
289 printf(" 0x%02x,", g->v4[i]); | |
290 printf("}\n"); | |
291 } | |
210
12004b385a96
[svn] Sync with xmms-wma instead of bmp-wma & GThreadify. Does not explode, but does not play either.
chainsaw
parents:
142
diff
changeset
|
292 #undef PRINT_IF_GUID(g,cmp) |
137 | 293 #endif |
294 | |
295 static void get_guid(ByteIOContext *s, GUID *g) | |
296 { | |
297 int i; | |
298 | |
299 g->v1 = get_le32(s); | |
300 g->v2 = get_le16(s); | |
301 g->v3 = get_le16(s); | |
302 for(i=0;i<8;i++) | |
303 g->v4[i] = get_byte(s); | |
304 } | |
305 | |
306 static void get_str16_nolen(ByteIOContext *pb, int len, char *buf, int buf_size) | |
307 { | |
218
0bea7509d6ba
[svn] Working WMA support. I never said it would be pretty, neno, I should said it would play.
chainsaw
parents:
210
diff
changeset
|
308 int c; |
137 | 309 char *q; |
310 | |
311 q = buf; | |
312 while (len > 0) { | |
218
0bea7509d6ba
[svn] Working WMA support. I never said it would be pretty, neno, I should said it would play.
chainsaw
parents:
210
diff
changeset
|
313 c = get_le16(pb); |
0bea7509d6ba
[svn] Working WMA support. I never said it would be pretty, neno, I should said it would play.
chainsaw
parents:
210
diff
changeset
|
314 if ((q - buf) < buf_size - 1) |
0bea7509d6ba
[svn] Working WMA support. I never said it would be pretty, neno, I should said it would play.
chainsaw
parents:
210
diff
changeset
|
315 *q++ = c; |
0bea7509d6ba
[svn] Working WMA support. I never said it would be pretty, neno, I should said it would play.
chainsaw
parents:
210
diff
changeset
|
316 len-=2; |
0bea7509d6ba
[svn] Working WMA support. I never said it would be pretty, neno, I should said it would play.
chainsaw
parents:
210
diff
changeset
|
317 } |
0bea7509d6ba
[svn] Working WMA support. I never said it would be pretty, neno, I should said it would play.
chainsaw
parents:
210
diff
changeset
|
318 *q = '\0'; |
137 | 319 } |
320 | |
321 static int asf_probe(AVProbeData *pd) | |
322 { | |
323 GUID g; | |
324 const unsigned char *p; | |
325 int i; | |
326 | |
327 /* check file header */ | |
328 if (pd->buf_size <= 32) | |
329 return 0; | |
330 p = pd->buf; | |
331 g.v1 = p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24); | |
332 p += 4; | |
333 g.v2 = p[0] | (p[1] << 8); | |
334 p += 2; | |
335 g.v3 = p[0] | (p[1] << 8); | |
336 p += 2; | |
337 for(i=0;i<8;i++) | |
338 g.v4[i] = *p++; | |
339 | |
340 if (!memcmp(&g, &asf_header, sizeof(GUID))) | |
341 return AVPROBE_SCORE_MAX; | |
342 else | |
343 return 0; | |
344 } | |
345 | |
346 static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap) | |
347 { | |
348 ASFContext *asf = s->priv_data; | |
349 GUID g; | |
350 ByteIOContext *pb = &s->pb; | |
351 AVStream *st; | |
352 ASFStream *asf_st; | |
353 //int size, i; | |
354 int i; | |
355 int64_t gsize; | |
356 | |
357 av_set_pts_info(s, 32, 1, 1000); /* 32 bit pts in ms */ | |
358 | |
359 get_guid(pb, &g); | |
360 if (memcmp(&g, &asf_header, sizeof(GUID))) | |
361 goto fail; | |
362 get_le64(pb); | |
363 get_le32(pb); | |
364 get_byte(pb); | |
365 get_byte(pb); | |
366 memset(&asf->asfid2avid, -1, sizeof(asf->asfid2avid)); | |
367 for(;;) { | |
368 get_guid(pb, &g); | |
369 gsize = get_le64(pb); | |
370 #ifdef DEBUG | |
371 printf("%08Lx: ", url_ftell(pb) - 24); | |
372 print_guid(&g); | |
373 printf(" size=0x%Lx\n", gsize); | |
374 #endif | |
375 if (gsize < 24) | |
376 goto fail; | |
377 if (!memcmp(&g, &file_header, sizeof(GUID))) { | |
378 get_guid(pb, &asf->hdr.guid); | |
379 asf->hdr.file_size = get_le64(pb); | |
380 asf->hdr.create_time = get_le64(pb); | |
381 asf->hdr.packets_count = get_le64(pb); | |
382 asf->hdr.play_time = get_le64(pb); | |
383 asf->hdr.send_time = get_le64(pb); | |
384 asf->hdr.preroll = get_le32(pb); | |
385 asf->hdr.ignore = get_le32(pb); | |
386 asf->hdr.flags = get_le32(pb); | |
387 asf->hdr.min_pktsize = get_le32(pb); | |
388 asf->hdr.max_pktsize = get_le32(pb); | |
389 asf->hdr.max_bitrate = get_le32(pb); | |
390 asf->packet_size = asf->hdr.max_pktsize; | |
391 asf->nb_packets = asf->hdr.packets_count; | |
392 } else if (!memcmp(&g, &stream_header, sizeof(GUID))) { | |
393 int type, total_size, type_specific_size; | |
394 //unsigned int tag1; | |
395 int64_t pos1, pos2; | |
396 | |
397 pos1 = url_ftell(pb); | |
398 | |
399 st = av_new_stream(s, 0); | |
400 if (!st) | |
401 goto fail; | |
210
12004b385a96
[svn] Sync with xmms-wma instead of bmp-wma & GThreadify. Does not explode, but does not play either.
chainsaw
parents:
142
diff
changeset
|
402 asf_st = av_mallocz(sizeof(ASFStream)); |
137 | 403 if (!asf_st) |
404 goto fail; | |
405 st->priv_data = asf_st; | |
406 st->start_time = asf->hdr.preroll / (10000000 / AV_TIME_BASE); | |
407 st->duration = (asf->hdr.send_time - asf->hdr.preroll) / | |
408 (10000000 / AV_TIME_BASE); | |
409 get_guid(pb, &g); | |
410 if (!memcmp(&g, &audio_stream, sizeof(GUID))) { | |
411 type = CODEC_TYPE_AUDIO; | |
412 } else { | |
413 goto fail; | |
414 } | |
415 get_guid(pb, &g); | |
416 total_size = get_le64(pb); | |
417 type_specific_size = get_le32(pb); | |
418 get_le32(pb); | |
419 st->id = get_le16(pb) & 0x7f; /* stream id */ | |
420 // mapping of asf ID to AV stream ID; | |
421 asf->asfid2avid[st->id] = s->nb_streams - 1; | |
422 | |
423 get_le32(pb); | |
424 st->codec.codec_type = type; | |
425 /* 1 fps default (XXX: put 0 fps instead) */ | |
426 st->codec.frame_rate = 1; | |
427 st->codec.frame_rate_base = 1; | |
428 if (type == CODEC_TYPE_AUDIO) { | |
429 get_wav_header(pb, &st->codec, type_specific_size); | |
430 st->need_parsing = 1; | |
431 /* We have to init the frame size at some point .... */ | |
432 pos2 = url_ftell(pb); | |
433 if (gsize > (pos2 + 8 - pos1 + 24)) { | |
434 asf_st->ds_span = get_byte(pb); | |
435 asf_st->ds_packet_size = get_le16(pb); | |
436 asf_st->ds_chunk_size = get_le16(pb); | |
437 asf_st->ds_data_size = get_le16(pb); | |
438 asf_st->ds_silence_data = get_byte(pb); | |
439 } | |
440 //printf("Descrambling: ps:%d cs:%d ds:%d s:%d sd:%d\n", | |
441 // asf_st->ds_packet_size, asf_st->ds_chunk_size, | |
442 // asf_st->ds_data_size, asf_st->ds_span, asf_st->ds_silence_data); | |
443 if (asf_st->ds_span > 1) { | |
444 if (!asf_st->ds_chunk_size | |
445 || (asf_st->ds_packet_size/asf_st->ds_chunk_size <= 1)) | |
446 asf_st->ds_span = 0; // disable descrambling | |
447 } | |
448 switch (st->codec.codec_id) { | |
449 case CODEC_ID_PCM_S16LE: | |
450 case CODEC_ID_PCM_S16BE: | |
451 case CODEC_ID_PCM_U16LE: | |
452 case CODEC_ID_PCM_U16BE: | |
453 case CODEC_ID_PCM_S8: | |
454 case CODEC_ID_PCM_U8: | |
455 case CODEC_ID_PCM_ALAW: | |
456 case CODEC_ID_PCM_MULAW: | |
457 st->codec.frame_size = 1; | |
458 break; | |
459 default: | |
460 /* This is probably wrong, but it prevents a crash later */ | |
461 st->codec.frame_size = 1; | |
462 break; | |
463 } | |
464 } | |
465 pos2 = url_ftell(pb); | |
466 url_fskip(pb, gsize - (pos2 - pos1 + 24)); | |
467 } else if (!memcmp(&g, &data_header, sizeof(GUID))) { | |
468 break; | |
469 } else if (!memcmp(&g, &comment_header, sizeof(GUID))) { | |
470 int len1, len2, len3, len4, len5; | |
471 | |
472 len1 = get_le16(pb); | |
473 len2 = get_le16(pb); | |
474 len3 = get_le16(pb); | |
475 len4 = get_le16(pb); | |
476 len5 = get_le16(pb); | |
477 get_str16_nolen(pb, len1, s->title, sizeof(s->title)); | |
478 get_str16_nolen(pb, len2, s->author, sizeof(s->author)); | |
479 get_str16_nolen(pb, len3, s->copyright, sizeof(s->copyright)); | |
480 get_str16_nolen(pb, len4, s->comment, sizeof(s->comment)); | |
481 url_fskip(pb, len5); | |
482 } else if (!memcmp(&g, &extended_content_header, sizeof(GUID))) { | |
483 int desc_count, i; | |
484 | |
485 desc_count = get_le16(pb); | |
486 for(i=0;i<desc_count;i++) | |
487 { | |
488 int name_len,value_type,value_len,value_num = 0; | |
489 char *name, *value; | |
490 | |
491 name_len = get_le16(pb); | |
210
12004b385a96
[svn] Sync with xmms-wma instead of bmp-wma & GThreadify. Does not explode, but does not play either.
chainsaw
parents:
142
diff
changeset
|
492 name = (char *)av_mallocz(name_len); |
137 | 493 get_str16_nolen(pb, name_len, name, name_len); |
494 value_type = get_le16(pb); | |
495 value_len = get_le16(pb); | |
496 if ((value_type == 0) || (value_type == 1)) // unicode or byte | |
497 { | |
210
12004b385a96
[svn] Sync with xmms-wma instead of bmp-wma & GThreadify. Does not explode, but does not play either.
chainsaw
parents:
142
diff
changeset
|
498 value = (char *)av_mallocz(value_len); |
137 | 499 get_str16_nolen(pb, value_len, value, value_len); |
500 if (strcmp(name,"WM/AlbumTitle")==0) { strcpy(s->album, value); } | |
501 if (strcmp(name,"WM/Genre")==0) { strcpy(s->genre, value); } | |
502 if (strcmp(name,"WM/Year")==0) s->year = atoi(value); | |
218
0bea7509d6ba
[svn] Working WMA support. I never said it would be pretty, neno, I should said it would play.
chainsaw
parents:
210
diff
changeset
|
503 free(value); |
137 | 504 } |
505 if ((value_type >= 2) || (value_type <= 5)) // boolean or DWORD or QWORD or WORD | |
506 { | |
507 if (value_type==2) value_num = get_le32(pb); | |
508 if (value_type==3) value_num = get_le32(pb); | |
509 if (value_type==4) value_num = get_le64(pb); | |
510 if (value_type==5) value_num = get_le16(pb); | |
511 if (strcmp(name,"WM/Track")==0) s->track = value_num + 1; | |
512 if (strcmp(name,"WM/TrackNumber")==0) s->track = value_num; | |
513 } | |
218
0bea7509d6ba
[svn] Working WMA support. I never said it would be pretty, neno, I should said it would play.
chainsaw
parents:
210
diff
changeset
|
514 free(name); |
137 | 515 } |
516 } else if (url_feof(pb)) { | |
517 goto fail; | |
518 } else { | |
519 url_fseek(pb, gsize - 24, SEEK_CUR); | |
520 } | |
521 } | |
522 get_guid(pb, &g); | |
523 get_le64(pb); | |
524 get_byte(pb); | |
525 get_byte(pb); | |
526 if (url_feof(pb)) | |
527 goto fail; | |
528 asf->data_offset = url_ftell(pb); | |
529 asf->packet_size_left = 0; | |
530 | |
531 return 0; | |
532 | |
533 fail: | |
534 for(i=0;i<s->nb_streams;i++) { | |
535 AVStream *st = s->streams[i]; | |
536 if (st) { | |
218
0bea7509d6ba
[svn] Working WMA support. I never said it would be pretty, neno, I should said it would play.
chainsaw
parents:
210
diff
changeset
|
537 free(st->priv_data); |
0bea7509d6ba
[svn] Working WMA support. I never said it would be pretty, neno, I should said it would play.
chainsaw
parents:
210
diff
changeset
|
538 free(st->codec.extradata); |
137 | 539 } |
218
0bea7509d6ba
[svn] Working WMA support. I never said it would be pretty, neno, I should said it would play.
chainsaw
parents:
210
diff
changeset
|
540 free(st); |
137 | 541 } |
542 return -1; | |
543 } | |
544 | |
545 #define DO_2BITS(bits, var, defval) \ | |
546 switch (bits & 3) \ | |
547 { \ | |
548 case 3: var = get_le32(pb); rsize += 4; break; \ | |
549 case 2: var = get_le16(pb); rsize += 2; break; \ | |
550 case 1: var = get_byte(pb); rsize++; break; \ | |
551 default: var = defval; break; \ | |
552 } | |
553 | |
554 static int asf_get_packet(AVFormatContext *s) | |
555 { | |
556 ASFContext *asf = s->priv_data; | |
557 ByteIOContext *pb = &s->pb; | |
558 uint32_t packet_length, padsize; | |
559 int rsize = 9; | |
560 int c; | |
561 | |
562 assert((url_ftell(&s->pb) - s->data_offset) % asf->packet_size == 0); | |
563 | |
564 c = get_byte(pb); | |
565 if (c != 0x82) { | |
566 if (!url_feof(pb)) | |
567 printf("ff asf bad header %x at:%lld\n", c, url_ftell(pb)); | |
568 } | |
569 if ((c & 0x0f) == 2) { // always true for now | |
570 if (get_le16(pb) != 0) { | |
571 if (!url_feof(pb)) | |
572 printf("ff asf bad non zero\n"); | |
573 return -EIO; | |
574 } | |
575 rsize+=2; | |
576 /* }else{ | |
577 if (!url_feof(pb)) | |
578 printf("ff asf bad header %x at:%lld\n", c, url_ftell(pb)); | |
579 return -EIO;*/ | |
580 } | |
581 | |
582 asf->packet_flags = get_byte(pb); | |
583 asf->packet_property = get_byte(pb); | |
584 | |
585 DO_2BITS(asf->packet_flags >> 5, packet_length, asf->packet_size); | |
586 DO_2BITS(asf->packet_flags >> 1, padsize, 0); // sequence ignored | |
587 DO_2BITS(asf->packet_flags >> 3, padsize, 0); // padding length | |
588 | |
589 asf->packet_timestamp = get_le32(pb); | |
590 get_le16(pb); /* duration */ | |
591 // rsize has at least 11 bytes which have to be present | |
592 | |
593 if (asf->packet_flags & 0x01) { | |
594 asf->packet_segsizetype = get_byte(pb); rsize++; | |
595 asf->packet_segments = asf->packet_segsizetype & 0x3f; | |
596 } else { | |
597 asf->packet_segments = 1; | |
598 asf->packet_segsizetype = 0x80; | |
599 } | |
600 asf->packet_size_left = packet_length - padsize - rsize; | |
601 if (packet_length < asf->hdr.min_pktsize) | |
602 padsize += asf->hdr.min_pktsize - packet_length; | |
603 asf->packet_padsize = padsize; | |
604 #ifdef DEBUG | |
605 printf("packet: size=%d padsize=%d left=%d\n", asf->packet_size, asf->packet_padsize, asf->packet_size_left); | |
606 #endif | |
607 return 0; | |
608 } | |
609 | |
610 static int asf_read_packet(AVFormatContext *s, AVPacket *pkt) | |
611 { | |
612 ASFContext *asf = s->priv_data; | |
613 ASFStream *asf_st = 0; | |
614 ByteIOContext *pb = &s->pb; | |
615 //static int pc = 0; | |
616 for (;;) { | |
617 int rsize = 0; | |
618 if (asf->packet_size_left < FRAME_HEADER_SIZE | |
619 || asf->packet_segments < 1) { | |
620 //asf->packet_size_left <= asf->packet_padsize) { | |
621 int ret = asf->packet_size_left + asf->packet_padsize; | |
622 //printf("PacketLeftSize:%d Pad:%d Pos:%Ld\n", asf->packet_size_left, asf->packet_padsize, url_ftell(pb)); | |
623 /* fail safe */ | |
624 url_fskip(pb, ret); | |
625 asf->packet_pos= url_ftell(&s->pb); | |
626 ret = asf_get_packet(s); | |
627 //printf("READ ASF PACKET %d r:%d c:%d\n", ret, asf->packet_size_left, pc++); | |
628 if (ret < 0 || url_feof(pb)) | |
629 return -EIO; | |
630 asf->packet_time_start = 0; | |
631 continue; | |
632 } | |
633 if (asf->packet_time_start == 0) { | |
634 /* read frame header */ | |
635 int num = get_byte(pb); | |
636 asf->packet_segments--; | |
637 rsize++; | |
638 asf->packet_key_frame = (num & 0x80) >> 7; | |
639 asf->stream_index = asf->asfid2avid[num & 0x7f]; | |
640 // sequence should be ignored! | |
641 DO_2BITS(asf->packet_property >> 4, asf->packet_seq, 0); | |
642 DO_2BITS(asf->packet_property >> 2, asf->packet_frag_offset, 0); | |
643 DO_2BITS(asf->packet_property, asf->packet_replic_size, 0); | |
644 //printf("key:%d stream:%d seq:%d offset:%d replic_size:%d\n", asf->packet_key_frame, asf->stream_index, asf->packet_seq, //asf->packet_frag_offset, asf->packet_replic_size); | |
645 if (asf->packet_replic_size > 1) { | |
646 assert(asf->packet_replic_size >= 8); | |
647 // it should be always at least 8 bytes - FIXME validate | |
648 asf->packet_obj_size = get_le32(pb); | |
649 asf->packet_frag_timestamp = get_le32(pb); // timestamp | |
650 if (asf->packet_replic_size > 8) | |
651 url_fskip(pb, asf->packet_replic_size - 8); | |
652 rsize += asf->packet_replic_size; // FIXME - check validity | |
653 } else if (asf->packet_replic_size==1){ | |
654 // multipacket - frag_offset is begining timestamp | |
655 asf->packet_time_start = asf->packet_frag_offset; | |
656 asf->packet_frag_offset = 0; | |
657 asf->packet_frag_timestamp = asf->packet_timestamp; | |
658 | |
659 asf->packet_time_delta = get_byte(pb); | |
660 rsize++; | |
661 }else{ | |
662 assert(asf->packet_replic_size==0); | |
663 } | |
664 if (asf->packet_flags & 0x01) { | |
665 DO_2BITS(asf->packet_segsizetype >> 6, asf->packet_frag_size, 0); // 0 is illegal | |
666 #undef DO_2BITS | |
667 //printf("Fragsize %d\n", asf->packet_frag_size); | |
668 } else { | |
669 asf->packet_frag_size = asf->packet_size_left - rsize; | |
670 //printf("Using rest %d %d %d\n", asf->packet_frag_size, asf->packet_size_left, rsize); | |
671 } | |
672 if (asf->packet_replic_size == 1) { | |
673 asf->packet_multi_size = asf->packet_frag_size; | |
674 if (asf->packet_multi_size > asf->packet_size_left) { | |
675 asf->packet_segments = 0; | |
676 continue; | |
677 } | |
678 } | |
679 asf->packet_size_left -= rsize; | |
680 //printf("___objsize____ %d %d rs:%d\n", asf->packet_obj_size, asf->packet_frag_offset, rsize); | |
681 | |
682 if (asf->stream_index < 0) { | |
683 asf->packet_time_start = 0; | |
684 /* unhandled packet (should not happen) */ | |
685 url_fskip(pb, asf->packet_frag_size); | |
686 asf->packet_size_left -= asf->packet_frag_size; | |
687 printf("ff asf skip %d %d\n", asf->packet_frag_size, num & 0x7f); | |
688 continue; | |
689 } | |
690 asf->asf_st = s->streams[asf->stream_index]->priv_data; | |
691 } | |
692 asf_st = asf->asf_st; | |
693 | |
694 if ((asf->packet_frag_offset != asf_st->frag_offset | |
695 || (asf->packet_frag_offset | |
696 && asf->packet_seq != asf_st->seq)) // seq should be ignored | |
697 ) { | |
698 /* cannot continue current packet: free it */ | |
699 // FIXME better check if packet was already allocated | |
700 printf("ff asf parser skips: %d - %d o:%d - %d %d %d fl:%d\n", | |
701 asf_st->pkt.size, | |
702 asf->packet_obj_size, | |
703 asf->packet_frag_offset, asf_st->frag_offset, | |
704 asf->packet_seq, asf_st->seq, asf->packet_frag_size); | |
705 if (asf_st->pkt.size) | |
706 av_free_packet(&asf_st->pkt); | |
707 asf_st->frag_offset = 0; | |
708 if (asf->packet_frag_offset != 0) { | |
709 url_fskip(pb, asf->packet_frag_size); | |
710 printf("ff asf parser skiping %db\n", asf->packet_frag_size); | |
711 asf->packet_size_left -= asf->packet_frag_size; | |
712 continue; | |
713 } | |
714 } | |
715 if (asf->packet_replic_size == 1) { | |
716 // frag_offset is here used as the begining timestamp | |
717 asf->packet_frag_timestamp = asf->packet_time_start; | |
718 asf->packet_time_start += asf->packet_time_delta; | |
719 asf->packet_obj_size = asf->packet_frag_size = get_byte(pb); | |
720 asf->packet_size_left--; | |
721 asf->packet_multi_size--; | |
722 if (asf->packet_multi_size < asf->packet_obj_size) | |
723 { | |
724 asf->packet_time_start = 0; | |
725 url_fskip(pb, asf->packet_multi_size); | |
726 asf->packet_size_left -= asf->packet_multi_size; | |
727 continue; | |
728 } | |
729 asf->packet_multi_size -= asf->packet_obj_size; | |
730 //printf("COMPRESS size %d %d %d ms:%d\n", asf->packet_obj_size, asf->packet_frag_timestamp, asf->packet_size_left, asf->packet_multi_size); | |
731 } | |
732 if (asf_st->frag_offset == 0) { | |
733 /* new packet */ | |
734 av_new_packet(&asf_st->pkt, asf->packet_obj_size); | |
735 asf_st->seq = asf->packet_seq; | |
736 asf_st->pkt.pts = asf->packet_frag_timestamp - asf->hdr.preroll; | |
737 asf_st->pkt.stream_index = asf->stream_index; | |
738 asf_st->packet_pos= asf->packet_pos; | |
739 //printf("new packet: stream:%d key:%d packet_key:%d audio:%d size:%d\n", | |
740 //asf->stream_index, asf->packet_key_frame, asf_st->pkt.flags & PKT_FLAG_KEY, | |
741 //s->streams[asf->stream_index]->codec.codec_type == CODEC_TYPE_AUDIO, asf->packet_obj_size); | |
742 if (s->streams[asf->stream_index]->codec.codec_type == CODEC_TYPE_AUDIO) | |
743 asf->packet_key_frame = 1; | |
744 if (asf->packet_key_frame) | |
745 asf_st->pkt.flags |= PKT_FLAG_KEY; | |
746 } | |
747 | |
748 /* read data */ | |
749 //printf("READ PACKET s:%d os:%d o:%d,%d l:%d DATA:%p\n", | |
750 // asf->packet_size, asf_st->pkt.size, asf->packet_frag_offset, | |
751 // asf_st->frag_offset, asf->packet_frag_size, asf_st->pkt.data); | |
752 asf->packet_size_left -= asf->packet_frag_size; | |
753 if (asf->packet_size_left < 0) | |
754 continue; | |
755 get_buffer(pb, asf_st->pkt.data + asf->packet_frag_offset, | |
756 asf->packet_frag_size); | |
757 asf_st->frag_offset += asf->packet_frag_size; | |
758 /* test if whole packet is read */ | |
759 if (asf_st->frag_offset == asf_st->pkt.size) { | |
760 /* return packet */ | |
761 if (asf_st->ds_span > 1) { | |
762 /* packet descrambling */ | |
218
0bea7509d6ba
[svn] Working WMA support. I never said it would be pretty, neno, I should said it would play.
chainsaw
parents:
210
diff
changeset
|
763 char* newdata = malloc(asf_st->pkt.size); |
137 | 764 if (newdata) { |
765 int offset = 0; | |
766 while (offset < asf_st->pkt.size) { | |
767 int off = offset / asf_st->ds_chunk_size; | |
768 int row = off / asf_st->ds_span; | |
769 int col = off % asf_st->ds_span; | |
770 int idx = row + col * asf_st->ds_packet_size / asf_st->ds_chunk_size; | |
771 //printf("off:%d row:%d col:%d idx:%d\n", off, row, col, idx); | |
772 memcpy(newdata + offset, | |
773 asf_st->pkt.data + idx * asf_st->ds_chunk_size, | |
774 asf_st->ds_chunk_size); | |
775 offset += asf_st->ds_chunk_size; | |
776 } | |
218
0bea7509d6ba
[svn] Working WMA support. I never said it would be pretty, neno, I should said it would play.
chainsaw
parents:
210
diff
changeset
|
777 free(asf_st->pkt.data); |
137 | 778 asf_st->pkt.data = newdata; |
779 } | |
780 } | |
781 asf_st->frag_offset = 0; | |
782 memcpy(pkt, &asf_st->pkt, sizeof(AVPacket)); | |
783 //printf("packet %d %d\n", asf_st->pkt.size, asf->packet_frag_size); | |
784 asf_st->pkt.size = 0; | |
785 asf_st->pkt.data = 0; | |
786 break; // packet completed | |
787 } | |
788 } | |
789 return 0; | |
790 } | |
791 | |
792 static int asf_read_close(AVFormatContext *s) | |
793 { | |
794 int i; | |
795 | |
796 for(i=0;i<s->nb_streams;i++) { | |
797 AVStream *st = s->streams[i]; | |
218
0bea7509d6ba
[svn] Working WMA support. I never said it would be pretty, neno, I should said it would play.
chainsaw
parents:
210
diff
changeset
|
798 free(st->priv_data); |
0bea7509d6ba
[svn] Working WMA support. I never said it would be pretty, neno, I should said it would play.
chainsaw
parents:
210
diff
changeset
|
799 free(st->codec.extradata); |
0bea7509d6ba
[svn] Working WMA support. I never said it would be pretty, neno, I should said it would play.
chainsaw
parents:
210
diff
changeset
|
800 free(st->codec.palctrl); |
137 | 801 } |
802 return 0; | |
803 } | |
804 | |
805 // Added to support seeking after packets have been read | |
806 // If information is not reset, read_packet fails due to | |
807 // leftover information from previous reads | |
808 static void asf_reset_header(AVFormatContext *s) | |
809 { | |
810 ASFContext *asf = s->priv_data; | |
811 ASFStream *asf_st; | |
812 int i; | |
813 | |
814 asf->packet_nb_frames = 0; | |
815 asf->packet_timestamp_start = -1; | |
816 asf->packet_timestamp_end = -1; | |
817 asf->packet_size_left = 0; | |
818 asf->packet_segments = 0; | |
819 asf->packet_flags = 0; | |
820 asf->packet_property = 0; | |
821 asf->packet_timestamp = 0; | |
822 asf->packet_segsizetype = 0; | |
823 asf->packet_segments = 0; | |
824 asf->packet_seq = 0; | |
825 asf->packet_replic_size = 0; | |
826 asf->packet_key_frame = 0; | |
827 asf->packet_padsize = 0; | |
828 asf->packet_frag_offset = 0; | |
829 asf->packet_frag_size = 0; | |
830 asf->packet_frag_timestamp = 0; | |
831 asf->packet_multi_size = 0; | |
832 asf->packet_obj_size = 0; | |
833 asf->packet_time_delta = 0; | |
834 asf->packet_time_start = 0; | |
835 | |
836 for(i=0; i<s->nb_streams; i++){ | |
837 asf_st= s->streams[i]->priv_data; | |
838 av_free_packet(&asf_st->pkt); | |
839 asf_st->frag_offset=0; | |
840 asf_st->seq=0; | |
841 } | |
842 asf->asf_st= NULL; | |
843 } | |
844 | |
845 static int64_t asf_read_pts(AVFormatContext *s, int64_t *ppos, int stream_index) | |
846 { | |
847 ASFContext *asf = s->priv_data; | |
848 AVPacket pkt1, *pkt = &pkt1; | |
849 ASFStream *asf_st; | |
850 int64_t pts; | |
851 int64_t pos= *ppos; | |
852 int i; | |
853 int64_t start_pos[s->nb_streams]; | |
854 | |
855 for(i=0; i<s->nb_streams; i++){ | |
856 start_pos[i]= pos; | |
857 } | |
858 | |
859 //printf("asf_read_pts\n"); | |
860 url_fseek(&s->pb, pos*asf->packet_size + s->data_offset, SEEK_SET); | |
861 asf_reset_header(s); | |
862 for(;;){ | |
863 if (av_read_frame(s, pkt) < 0){ | |
864 printf("seek failed\n"); | |
865 return AV_NOPTS_VALUE; | |
866 } | |
867 pts= pkt->pts; | |
868 | |
869 av_free_packet(pkt); | |
870 if(pkt->flags&PKT_FLAG_KEY){ | |
871 i= pkt->stream_index; | |
872 | |
873 asf_st= s->streams[i]->priv_data; | |
874 | |
875 assert((asf_st->packet_pos - s->data_offset) % asf->packet_size == 0); | |
876 pos= (asf_st->packet_pos - s->data_offset) / asf->packet_size; | |
877 | |
878 av_add_index_entry(s->streams[i], pos, pts, pos - start_pos[i] + 1, AVINDEX_KEYFRAME); | |
879 start_pos[i]= pos + 1; | |
880 | |
881 if(pkt->stream_index == stream_index) | |
882 break; | |
883 } | |
884 } | |
885 | |
886 *ppos= pos; | |
887 //printf("found keyframe at %Ld stream %d stamp:%Ld\n", *ppos, stream_index, pts); | |
888 | |
889 return pts; | |
890 } | |
891 | |
892 static int asf_read_seek(AVFormatContext *s, int stream_index, int64_t pts) | |
893 { | |
894 ASFContext *asf = s->priv_data; | |
895 AVStream *st; | |
896 int64_t pos; | |
897 int64_t pos_min, pos_max, pts_min, pts_max, cur_pts, pos_limit; | |
898 int no_change; | |
899 | |
900 if (stream_index == -1) | |
901 stream_index= av_find_default_stream_index(s); | |
902 | |
903 if (asf->packet_size <= 0) | |
904 return -1; | |
905 | |
906 pts_max= | |
907 pts_min= AV_NOPTS_VALUE; | |
908 pos_max= pos_limit= -1; // gcc thinks its uninitalized | |
909 | |
910 st= s->streams[stream_index]; | |
911 if(st->index_entries){ | |
912 AVIndexEntry *e; | |
913 int index; | |
914 | |
915 index= av_index_search_timestamp(st, pts); | |
916 e= &st->index_entries[index]; | |
917 if(e->timestamp <= pts){ | |
918 pos_min= e->pos; | |
919 pts_min= e->timestamp; | |
920 }else{ | |
921 assert(index==0); | |
922 } | |
923 index++; | |
924 if(index < st->nb_index_entries){ | |
925 e= &st->index_entries[index]; | |
926 assert(e->timestamp >= pts); | |
927 pos_max= e->pos; | |
928 pts_max= e->timestamp; | |
929 pos_limit= pos_max - e->min_distance; | |
930 } | |
931 } | |
932 | |
933 if(pts_min == AV_NOPTS_VALUE){ | |
934 pos_min = 0; | |
935 pts_min = asf_read_pts(s, &pos_min, stream_index); | |
936 if (pts_min == AV_NOPTS_VALUE) return -1; | |
937 } | |
938 if(pts_max == AV_NOPTS_VALUE){ | |
939 pos_max = (url_filesize(url_fileno(&s->pb)) - 1 - s->data_offset) / asf->packet_size; //FIXME wrong | |
940 pts_max = s->duration; //FIXME wrong | |
941 pos_limit= pos_max; | |
942 } | |
943 | |
944 no_change=0; | |
945 while (pos_min < pos_limit) { | |
946 int64_t start_pos; | |
947 assert(pos_limit <= pos_max); | |
948 | |
949 if(no_change==0){ | |
950 int64_t approximate_keyframe_distance= pos_max - pos_limit; | |
951 // interpolate position (better than dichotomy) | |
952 pos = (int64_t)((double)(pos_max - pos_min) * | |
953 (double)(pts - pts_min) / | |
954 (double)(pts_max - pts_min)) + pos_min - approximate_keyframe_distance; | |
955 }else if(no_change==1){ | |
956 // bisection, if interpolation failed to change min or max pos last time | |
957 pos = (pos_min + pos_limit)>>1; | |
958 }else{ | |
959 // linear search if bisection failed, can only happen if there are very few or no keyframes between min/max | |
960 pos=pos_min; | |
961 } | |
962 if(pos <= pos_min) | |
963 pos= pos_min + 1; | |
964 else if(pos > pos_limit) | |
965 pos= pos_limit; | |
966 start_pos= pos; | |
967 | |
968 // read the next timestamp | |
969 cur_pts = asf_read_pts(s, &pos, stream_index); | |
970 if(pos == pos_max) | |
971 no_change++; | |
972 else | |
973 no_change=0; | |
974 | |
975 assert (cur_pts != AV_NOPTS_VALUE); | |
976 if (pts < cur_pts) { | |
977 pos_limit = start_pos - 1; | |
978 pos_max = pos; | |
979 pts_max = cur_pts; | |
980 } else { | |
981 pos_min = pos; | |
982 pts_min = cur_pts; | |
983 /* check if we are lucky */ | |
984 if (pts == cur_pts) | |
985 break; | |
986 } | |
987 } | |
988 pos = pos_min; | |
989 url_fseek(&s->pb, pos*asf->packet_size + s->data_offset, SEEK_SET); | |
990 asf_reset_header(s); | |
991 return 0; | |
992 } | |
993 | |
994 static AVInputFormat asf_iformat = { | |
995 "asf", | |
996 "asf format", | |
997 sizeof(ASFContext), | |
998 asf_probe, | |
999 asf_read_header, | |
1000 asf_read_packet, | |
1001 asf_read_close, | |
1002 asf_read_seek, | |
1003 }; | |
1004 | |
1005 int asf_init(void) | |
1006 { | |
1007 av_register_input_format(&asf_iformat); | |
218
0bea7509d6ba
[svn] Working WMA support. I never said it would be pretty, neno, I should said it would play.
chainsaw
parents:
210
diff
changeset
|
1008 |
137 | 1009 return 0; |
1010 } |