comparison asf.c @ 887:d70e50f1495f libavformat

COSMETICS: tabs --> spaces, some prettyprinting
author diego
date Thu, 22 Dec 2005 01:10:11 +0000
parents da1d5db0ce5c
children edbe5c3717f9
comparison
equal deleted inserted replaced
886:7ed1351f8c7e 887:d70e50f1495f
167 #endif 167 #endif
168 if (gsize < 24) 168 if (gsize < 24)
169 goto fail; 169 goto fail;
170 if (!memcmp(&g, &file_header, sizeof(GUID))) { 170 if (!memcmp(&g, &file_header, sizeof(GUID))) {
171 get_guid(pb, &asf->hdr.guid); 171 get_guid(pb, &asf->hdr.guid);
172 asf->hdr.file_size = get_le64(pb); 172 asf->hdr.file_size = get_le64(pb);
173 asf->hdr.create_time = get_le64(pb); 173 asf->hdr.create_time = get_le64(pb);
174 asf->hdr.packets_count = get_le64(pb); 174 asf->hdr.packets_count = get_le64(pb);
175 asf->hdr.send_time = get_le64(pb); 175 asf->hdr.send_time = get_le64(pb);
176 asf->hdr.play_time = get_le64(pb); 176 asf->hdr.play_time = get_le64(pb);
177 asf->hdr.preroll = get_le32(pb); 177 asf->hdr.preroll = get_le32(pb);
178 asf->hdr.ignore = get_le32(pb); 178 asf->hdr.ignore = get_le32(pb);
179 asf->hdr.flags = get_le32(pb); 179 asf->hdr.flags = get_le32(pb);
180 asf->hdr.min_pktsize = get_le32(pb); 180 asf->hdr.min_pktsize = get_le32(pb);
181 asf->hdr.max_pktsize = get_le32(pb); 181 asf->hdr.max_pktsize = get_le32(pb);
182 asf->hdr.max_bitrate = get_le32(pb); 182 asf->hdr.max_bitrate = get_le32(pb);
183 asf->packet_size = asf->hdr.max_pktsize; 183 asf->packet_size = asf->hdr.max_pktsize;
184 asf->nb_packets = asf->hdr.packets_count; 184 asf->nb_packets = asf->hdr.packets_count;
185 } else if (!memcmp(&g, &stream_header, sizeof(GUID))) { 185 } else if (!memcmp(&g, &stream_header, sizeof(GUID))) {
186 int type, total_size, type_specific_size, sizeX; 186 int type, total_size, type_specific_size, sizeX;
187 unsigned int tag1; 187 unsigned int tag1;
188 int64_t pos1, pos2; 188 int64_t pos1, pos2;
212 } 212 }
213 get_guid(pb, &g); 213 get_guid(pb, &g);
214 total_size = get_le64(pb); 214 total_size = get_le64(pb);
215 type_specific_size = get_le32(pb); 215 type_specific_size = get_le32(pb);
216 get_le32(pb); 216 get_le32(pb);
217 st->id = get_le16(pb) & 0x7f; /* stream id */ 217 st->id = get_le16(pb) & 0x7f; /* stream id */
218 // mapping of asf ID to AV stream ID; 218 // mapping of asf ID to AV stream ID;
219 asf->asfid2avid[st->id] = s->nb_streams - 1; 219 asf->asfid2avid[st->id] = s->nb_streams - 1;
220 220
221 get_le32(pb); 221 get_le32(pb);
222 st->codec->codec_type = type; 222 st->codec->codec_type = type;
223 if (type == CODEC_TYPE_AUDIO) { 223 if (type == CODEC_TYPE_AUDIO) {
224 get_wav_header(pb, st->codec, type_specific_size); 224 get_wav_header(pb, st->codec, type_specific_size);
225 st->need_parsing = 1; 225 st->need_parsing = 1;
226 /* We have to init the frame size at some point .... */ 226 /* We have to init the frame size at some point .... */
227 pos2 = url_ftell(pb); 227 pos2 = url_ftell(pb);
228 if (gsize > (pos2 + 8 - pos1 + 24)) { 228 if (gsize > (pos2 + 8 - pos1 + 24)) {
229 asf_st->ds_span = get_byte(pb); 229 asf_st->ds_span = get_byte(pb);
230 asf_st->ds_packet_size = get_le16(pb); 230 asf_st->ds_packet_size = get_le16(pb);
231 asf_st->ds_chunk_size = get_le16(pb); 231 asf_st->ds_chunk_size = get_le16(pb);
232 asf_st->ds_data_size = get_le16(pb); 232 asf_st->ds_data_size = get_le16(pb);
233 asf_st->ds_silence_data = get_byte(pb); 233 asf_st->ds_silence_data = get_byte(pb);
234 } 234 }
235 //printf("Descrambling: ps:%d cs:%d ds:%d s:%d sd:%d\n", 235 //printf("Descrambling: ps:%d cs:%d ds:%d s:%d sd:%d\n",
236 // asf_st->ds_packet_size, asf_st->ds_chunk_size, 236 // asf_st->ds_packet_size, asf_st->ds_chunk_size,
237 // asf_st->ds_data_size, asf_st->ds_span, asf_st->ds_silence_data); 237 // asf_st->ds_data_size, asf_st->ds_span, asf_st->ds_silence_data);
238 if (asf_st->ds_span > 1) { 238 if (asf_st->ds_span > 1) {
239 if (!asf_st->ds_chunk_size 239 if (!asf_st->ds_chunk_size
240 || (asf_st->ds_packet_size/asf_st->ds_chunk_size <= 1)) 240 || (asf_st->ds_packet_size/asf_st->ds_chunk_size <= 1))
241 asf_st->ds_span = 0; // disable descrambling 241 asf_st->ds_span = 0; // disable descrambling
242 } 242 }
243 switch (st->codec->codec_id) { 243 switch (st->codec->codec_id) {
244 case CODEC_ID_MP3: 244 case CODEC_ID_MP3:
245 st->codec->frame_size = MPA_FRAME_SIZE; 245 st->codec->frame_size = MPA_FRAME_SIZE;
246 break; 246 break;
247 case CODEC_ID_PCM_S16LE: 247 case CODEC_ID_PCM_S16LE:
258 /* This is probably wrong, but it prevents a crash later */ 258 /* This is probably wrong, but it prevents a crash later */
259 st->codec->frame_size = 1; 259 st->codec->frame_size = 1;
260 break; 260 break;
261 } 261 }
262 } else { 262 } else {
263 get_le32(pb); 263 get_le32(pb);
264 get_le32(pb); 264 get_le32(pb);
265 get_byte(pb); 265 get_byte(pb);
266 size = get_le16(pb); /* size */ 266 size = get_le16(pb); /* size */
267 sizeX= get_le32(pb); /* size */ 267 sizeX= get_le32(pb); /* size */
268 st->codec->width = get_le32(pb); 268 st->codec->width = get_le32(pb);
269 st->codec->height = get_le32(pb); 269 st->codec->height = get_le32(pb);
270 /* not available for asf */ 270 /* not available for asf */
271 get_le16(pb); /* panes */ 271 get_le16(pb); /* panes */
272 st->codec->bits_per_sample = get_le16(pb); /* depth */ 272 st->codec->bits_per_sample = get_le16(pb); /* depth */
273 tag1 = get_le32(pb); 273 tag1 = get_le32(pb);
274 url_fskip(pb, 20); 274 url_fskip(pb, 20);
275 // av_log(NULL, AV_LOG_DEBUG, "size:%d tsize:%d sizeX:%d\n", size, total_size, sizeX); 275 // av_log(NULL, AV_LOG_DEBUG, "size:%d tsize:%d sizeX:%d\n", size, total_size, sizeX);
276 size= sizeX; 276 size= sizeX;
277 if (size > 40) { 277 if (size > 40) {
278 st->codec->extradata_size = size - 40; 278 st->codec->extradata_size = size - 40;
279 st->codec->extradata = av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); 279 st->codec->extradata = av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
280 get_buffer(pb, st->codec->extradata, st->codec->extradata_size); 280 get_buffer(pb, st->codec->extradata, st->codec->extradata_size);
281 } 281 }
282 282
283 /* Extract palette from extradata if bpp <= 8 */ 283 /* Extract palette from extradata if bpp <= 8 */
284 /* This code assumes that extradata contains only palette */ 284 /* This code assumes that extradata contains only palette */
285 /* This is true for all paletted codecs implemented in ffmpeg */ 285 /* This is true for all paletted codecs implemented in ffmpeg */
286 if (st->codec->extradata_size && (st->codec->bits_per_sample <= 8)) { 286 if (st->codec->extradata_size && (st->codec->bits_per_sample <= 8)) {
294 #endif 294 #endif
295 st->codec->palctrl->palette_changed = 1; 295 st->codec->palctrl->palette_changed = 1;
296 } 296 }
297 297
298 st->codec->codec_tag = tag1; 298 st->codec->codec_tag = tag1;
299 st->codec->codec_id = codec_get_id(codec_bmp_tags, tag1); 299 st->codec->codec_id = codec_get_id(codec_bmp_tags, tag1);
300 if(tag1 == MKTAG('D', 'V', 'R', ' ')) 300 if(tag1 == MKTAG('D', 'V', 'R', ' '))
301 st->need_parsing = 1; 301 st->need_parsing = 1;
302 } 302 }
303 pos2 = url_ftell(pb); 303 pos2 = url_ftell(pb);
304 url_fskip(pb, gsize - (pos2 - pos1 + 24)); 304 url_fskip(pb, gsize - (pos2 - pos1 + 24));
314 len5 = get_le16(pb); 314 len5 = get_le16(pb);
315 get_str16_nolen(pb, len1, s->title, sizeof(s->title)); 315 get_str16_nolen(pb, len1, s->title, sizeof(s->title));
316 get_str16_nolen(pb, len2, s->author, sizeof(s->author)); 316 get_str16_nolen(pb, len2, s->author, sizeof(s->author));
317 get_str16_nolen(pb, len3, s->copyright, sizeof(s->copyright)); 317 get_str16_nolen(pb, len3, s->copyright, sizeof(s->copyright));
318 get_str16_nolen(pb, len4, s->comment, sizeof(s->comment)); 318 get_str16_nolen(pb, len4, s->comment, sizeof(s->comment));
319 url_fskip(pb, len5); 319 url_fskip(pb, len5);
320 } else if (!memcmp(&g, &extended_content_header, sizeof(GUID))) { 320 } else if (!memcmp(&g, &extended_content_header, sizeof(GUID))) {
321 int desc_count, i; 321 int desc_count, i;
322 322
323 desc_count = get_le16(pb); 323 desc_count = get_le16(pb);
324 for(i=0;i<desc_count;i++) 324 for(i=0;i<desc_count;i++)
397 return 0; 397 return 0;
398 398
399 fail: 399 fail:
400 for(i=0;i<s->nb_streams;i++) { 400 for(i=0;i<s->nb_streams;i++) {
401 AVStream *st = s->streams[i]; 401 AVStream *st = s->streams[i];
402 if (st) { 402 if (st) {
403 av_free(st->priv_data); 403 av_free(st->priv_data);
404 av_free(st->codec->extradata); 404 av_free(st->codec->extradata);
405 } 405 }
406 av_free(st); 406 av_free(st);
407 } 407 }
408 return -1; 408 return -1;
409 } 409 }
410 410
428 assert((url_ftell(&s->pb) - s->data_offset) % asf->packet_size == 0); 428 assert((url_ftell(&s->pb) - s->data_offset) % asf->packet_size == 0);
429 429
430 c = get_byte(pb); 430 c = get_byte(pb);
431 if (c != 0x82) { 431 if (c != 0x82) {
432 if (!url_feof(pb)) 432 if (!url_feof(pb))
433 av_log(s, AV_LOG_ERROR, "ff asf bad header %x at:%"PRId64"\n", c, url_ftell(pb)); 433 av_log(s, AV_LOG_ERROR, "ff asf bad header %x at:%"PRId64"\n", c, url_ftell(pb));
434 } 434 }
435 if ((c & 0x0f) == 2) { // always true for now 435 if ((c & 0x0f) == 2) { // always true for now
436 if (get_le16(pb) != 0) { 436 if (get_le16(pb) != 0) {
437 if (!url_feof(pb)) 437 if (!url_feof(pb))
438 av_log(s, AV_LOG_ERROR, "ff asf bad non zero\n"); 438 av_log(s, AV_LOG_ERROR, "ff asf bad non zero\n");
439 return AVERROR_IO; 439 return AVERROR_IO;
440 } 440 }
441 rsize+=2; 441 rsize+=2;
442 /* }else{ 442 /* }else{
443 if (!url_feof(pb)) 443 if (!url_feof(pb))
444 printf("ff asf bad header %x at:%lld\n", c, url_ftell(pb)); 444 printf("ff asf bad header %x at:%lld\n", c, url_ftell(pb));
445 return AVERROR_IO;*/ 445 return AVERROR_IO;*/
446 } 446 }
447 447
448 asf->packet_flags = get_byte(pb); 448 asf->packet_flags = get_byte(pb);
449 asf->packet_property = get_byte(pb); 449 asf->packet_property = get_byte(pb);
450 450
455 asf->packet_timestamp = get_le32(pb); 455 asf->packet_timestamp = get_le32(pb);
456 get_le16(pb); /* duration */ 456 get_le16(pb); /* duration */
457 // rsize has at least 11 bytes which have to be present 457 // rsize has at least 11 bytes which have to be present
458 458
459 if (asf->packet_flags & 0x01) { 459 if (asf->packet_flags & 0x01) {
460 asf->packet_segsizetype = get_byte(pb); rsize++; 460 asf->packet_segsizetype = get_byte(pb); rsize++;
461 asf->packet_segments = asf->packet_segsizetype & 0x3f; 461 asf->packet_segments = asf->packet_segsizetype & 0x3f;
462 } else { 462 } else {
463 asf->packet_segments = 1; 463 asf->packet_segments = 1;
464 asf->packet_segsizetype = 0x80; 464 asf->packet_segsizetype = 0x80;
465 } 465 }
466 asf->packet_size_left = packet_length - padsize - rsize; 466 asf->packet_size_left = packet_length - padsize - rsize;
467 if (packet_length < asf->hdr.min_pktsize) 467 if (packet_length < asf->hdr.min_pktsize)
468 padsize += asf->hdr.min_pktsize - packet_length; 468 padsize += asf->hdr.min_pktsize - packet_length;
478 ASFContext *asf = s->priv_data; 478 ASFContext *asf = s->priv_data;
479 ASFStream *asf_st = 0; 479 ASFStream *asf_st = 0;
480 ByteIOContext *pb = &s->pb; 480 ByteIOContext *pb = &s->pb;
481 //static int pc = 0; 481 //static int pc = 0;
482 for (;;) { 482 for (;;) {
483 int rsize = 0; 483 int rsize = 0;
484 if (asf->packet_size_left < FRAME_HEADER_SIZE 484 if (asf->packet_size_left < FRAME_HEADER_SIZE
485 || asf->packet_segments < 1) { 485 || asf->packet_segments < 1) {
486 //asf->packet_size_left <= asf->packet_padsize) { 486 //asf->packet_size_left <= asf->packet_padsize) {
487 int ret = asf->packet_size_left + asf->packet_padsize; 487 int ret = asf->packet_size_left + asf->packet_padsize;
488 //printf("PacketLeftSize:%d Pad:%d Pos:%Ld\n", asf->packet_size_left, asf->packet_padsize, url_ftell(pb)); 488 //printf("PacketLeftSize:%d Pad:%d Pos:%Ld\n", asf->packet_size_left, asf->packet_padsize, url_ftell(pb));
489 if((url_ftell(&s->pb) + ret - s->data_offset) % asf->packet_size) 489 if((url_ftell(&s->pb) + ret - s->data_offset) % asf->packet_size)
490 ret += asf->packet_size - ((url_ftell(&s->pb) + ret - s->data_offset) % asf->packet_size); 490 ret += asf->packet_size - ((url_ftell(&s->pb) + ret - s->data_offset) % asf->packet_size);
491 /* fail safe */ 491 /* fail safe */
492 url_fskip(pb, ret); 492 url_fskip(pb, ret);
493 asf->packet_pos= url_ftell(&s->pb); 493 asf->packet_pos= url_ftell(&s->pb);
494 ret = asf_get_packet(s); 494 ret = asf_get_packet(s);
495 //printf("READ ASF PACKET %d r:%d c:%d\n", ret, asf->packet_size_left, pc++); 495 //printf("READ ASF PACKET %d r:%d c:%d\n", ret, asf->packet_size_left, pc++);
496 if (ret < 0 || url_feof(pb)) 496 if (ret < 0 || url_feof(pb))
497 return AVERROR_IO; 497 return AVERROR_IO;
498 asf->packet_time_start = 0; 498 asf->packet_time_start = 0;
499 continue; 499 continue;
500 } 500 }
501 if (asf->packet_time_start == 0) { 501 if (asf->packet_time_start == 0) {
502 /* read frame header */ 502 /* read frame header */
503 int num = get_byte(pb); 503 int num = get_byte(pb);
504 asf->packet_segments--; 504 asf->packet_segments--;
505 rsize++; 505 rsize++;
506 asf->packet_key_frame = (num & 0x80) >> 7; 506 asf->packet_key_frame = (num & 0x80) >> 7;
507 asf->stream_index = asf->asfid2avid[num & 0x7f]; 507 asf->stream_index = asf->asfid2avid[num & 0x7f];
508 // sequence should be ignored! 508 // sequence should be ignored!
509 DO_2BITS(asf->packet_property >> 4, asf->packet_seq, 0); 509 DO_2BITS(asf->packet_property >> 4, asf->packet_seq, 0);
510 DO_2BITS(asf->packet_property >> 2, asf->packet_frag_offset, 0); 510 DO_2BITS(asf->packet_property >> 2, asf->packet_frag_offset, 0);
511 DO_2BITS(asf->packet_property, asf->packet_replic_size, 0); 511 DO_2BITS(asf->packet_property, asf->packet_replic_size, 0);
512 //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); 512 //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);
513 if (asf->packet_replic_size > 1) { 513 if (asf->packet_replic_size > 1) {
514 assert(asf->packet_replic_size >= 8); 514 assert(asf->packet_replic_size >= 8);
515 // it should be always at least 8 bytes - FIXME validate 515 // it should be always at least 8 bytes - FIXME validate
516 asf->packet_obj_size = get_le32(pb); 516 asf->packet_obj_size = get_le32(pb);
517 asf->packet_frag_timestamp = get_le32(pb); // timestamp 517 asf->packet_frag_timestamp = get_le32(pb); // timestamp
518 if (asf->packet_replic_size > 8) 518 if (asf->packet_replic_size > 8)
519 url_fskip(pb, asf->packet_replic_size - 8); 519 url_fskip(pb, asf->packet_replic_size - 8);
520 rsize += asf->packet_replic_size; // FIXME - check validity 520 rsize += asf->packet_replic_size; // FIXME - check validity
521 } else if (asf->packet_replic_size==1){ 521 } else if (asf->packet_replic_size==1){
522 // multipacket - frag_offset is begining timestamp 522 // multipacket - frag_offset is begining timestamp
523 asf->packet_time_start = asf->packet_frag_offset; 523 asf->packet_time_start = asf->packet_frag_offset;
524 asf->packet_frag_offset = 0; 524 asf->packet_frag_offset = 0;
525 asf->packet_frag_timestamp = asf->packet_timestamp; 525 asf->packet_frag_timestamp = asf->packet_timestamp;
526 526
527 asf->packet_time_delta = get_byte(pb); 527 asf->packet_time_delta = get_byte(pb);
528 rsize++; 528 rsize++;
529 }else{ 529 }else{
530 assert(asf->packet_replic_size==0); 530 assert(asf->packet_replic_size==0);
531 } 531 }
532 if (asf->packet_flags & 0x01) { 532 if (asf->packet_flags & 0x01) {
533 DO_2BITS(asf->packet_segsizetype >> 6, asf->packet_frag_size, 0); // 0 is illegal 533 DO_2BITS(asf->packet_segsizetype >> 6, asf->packet_frag_size, 0); // 0 is illegal
534 #undef DO_2BITS 534 #undef DO_2BITS
535 //printf("Fragsize %d\n", asf->packet_frag_size); 535 //printf("Fragsize %d\n", asf->packet_frag_size);
536 } else { 536 } else {
537 asf->packet_frag_size = asf->packet_size_left - rsize; 537 asf->packet_frag_size = asf->packet_size_left - rsize;
538 //printf("Using rest %d %d %d\n", asf->packet_frag_size, asf->packet_size_left, rsize); 538 //printf("Using rest %d %d %d\n", asf->packet_frag_size, asf->packet_size_left, rsize);
539 } 539 }
540 if (asf->packet_replic_size == 1) { 540 if (asf->packet_replic_size == 1) {
541 asf->packet_multi_size = asf->packet_frag_size; 541 asf->packet_multi_size = asf->packet_frag_size;
542 if (asf->packet_multi_size > asf->packet_size_left) { 542 if (asf->packet_multi_size > asf->packet_size_left) {
543 asf->packet_segments = 0; 543 asf->packet_segments = 0;
544 continue; 544 continue;
545 } 545 }
546 } 546 }
547 asf->packet_size_left -= rsize; 547 asf->packet_size_left -= rsize;
548 //printf("___objsize____ %d %d rs:%d\n", asf->packet_obj_size, asf->packet_frag_offset, rsize); 548 //printf("___objsize____ %d %d rs:%d\n", asf->packet_obj_size, asf->packet_frag_offset, rsize);
549 549
550 if (asf->stream_index < 0 550 if (asf->stream_index < 0
551 || s->streams[asf->stream_index]->discard >= AVDISCARD_ALL 551 || s->streams[asf->stream_index]->discard >= AVDISCARD_ALL
552 || (!asf->packet_key_frame && s->streams[asf->stream_index]->discard >= AVDISCARD_NONKEY) 552 || (!asf->packet_key_frame && s->streams[asf->stream_index]->discard >= AVDISCARD_NONKEY)
553 ) { 553 ) {
554 asf->packet_time_start = 0; 554 asf->packet_time_start = 0;
555 /* unhandled packet (should not happen) */ 555 /* unhandled packet (should not happen) */
556 url_fskip(pb, asf->packet_frag_size); 556 url_fskip(pb, asf->packet_frag_size);
557 asf->packet_size_left -= asf->packet_frag_size; 557 asf->packet_size_left -= asf->packet_frag_size;
558 if(asf->stream_index < 0) 558 if(asf->stream_index < 0)
559 av_log(s, AV_LOG_ERROR, "ff asf skip %d %d\n", asf->packet_frag_size, num & 0x7f); 559 av_log(s, AV_LOG_ERROR, "ff asf skip %d %d\n", asf->packet_frag_size, num & 0x7f);
560 continue; 560 continue;
561 } 561 }
562 asf->asf_st = s->streams[asf->stream_index]->priv_data; 562 asf->asf_st = s->streams[asf->stream_index]->priv_data;
563 } 563 }
564 asf_st = asf->asf_st; 564 asf_st = asf->asf_st;
565 565
566 if ((asf->packet_frag_offset != asf_st->frag_offset 566 if ((asf->packet_frag_offset != asf_st->frag_offset
567 || (asf->packet_frag_offset 567 || (asf->packet_frag_offset
568 && asf->packet_seq != asf_st->seq)) // seq should be ignored 568 && asf->packet_seq != asf_st->seq)) // seq should be ignored
569 ) { 569 ) {
570 /* cannot continue current packet: free it */ 570 /* cannot continue current packet: free it */
571 // FIXME better check if packet was already allocated 571 // FIXME better check if packet was already allocated
572 av_log(s, AV_LOG_INFO, "ff asf parser skips: %d - %d o:%d - %d %d %d fl:%d\n", 572 av_log(s, AV_LOG_INFO, "ff asf parser skips: %d - %d o:%d - %d %d %d fl:%d\n",
573 asf_st->pkt.size, 573 asf_st->pkt.size,
574 asf->packet_obj_size, 574 asf->packet_obj_size,
575 asf->packet_frag_offset, asf_st->frag_offset, 575 asf->packet_frag_offset, asf_st->frag_offset,
576 asf->packet_seq, asf_st->seq, asf->packet_frag_size); 576 asf->packet_seq, asf_st->seq, asf->packet_frag_size);
577 if (asf_st->pkt.size) 577 if (asf_st->pkt.size)
578 av_free_packet(&asf_st->pkt); 578 av_free_packet(&asf_st->pkt);
579 asf_st->frag_offset = 0; 579 asf_st->frag_offset = 0;
580 if (asf->packet_frag_offset != 0) { 580 if (asf->packet_frag_offset != 0) {
581 url_fskip(pb, asf->packet_frag_size); 581 url_fskip(pb, asf->packet_frag_size);
582 av_log(s, AV_LOG_INFO, "ff asf parser skipping %db\n", asf->packet_frag_size); 582 av_log(s, AV_LOG_INFO, "ff asf parser skipping %db\n", asf->packet_frag_size);
583 asf->packet_size_left -= asf->packet_frag_size; 583 asf->packet_size_left -= asf->packet_frag_size;
584 continue; 584 continue;
585 } 585 }
586 } 586 }
587 if (asf->packet_replic_size == 1) { 587 if (asf->packet_replic_size == 1) {
588 // frag_offset is here used as the begining timestamp 588 // frag_offset is here used as the begining timestamp
589 asf->packet_frag_timestamp = asf->packet_time_start; 589 asf->packet_frag_timestamp = asf->packet_time_start;
590 asf->packet_time_start += asf->packet_time_delta; 590 asf->packet_time_start += asf->packet_time_delta;
591 asf->packet_obj_size = asf->packet_frag_size = get_byte(pb); 591 asf->packet_obj_size = asf->packet_frag_size = get_byte(pb);
592 asf->packet_size_left--; 592 asf->packet_size_left--;
593 asf->packet_multi_size--; 593 asf->packet_multi_size--;
594 if (asf->packet_multi_size < asf->packet_obj_size) 594 if (asf->packet_multi_size < asf->packet_obj_size)
595 { 595 {
596 asf->packet_time_start = 0; 596 asf->packet_time_start = 0;
597 url_fskip(pb, asf->packet_multi_size); 597 url_fskip(pb, asf->packet_multi_size);
598 asf->packet_size_left -= asf->packet_multi_size; 598 asf->packet_size_left -= asf->packet_multi_size;
599 continue; 599 continue;
600 } 600 }
601 asf->packet_multi_size -= asf->packet_obj_size; 601 asf->packet_multi_size -= asf->packet_obj_size;
602 //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); 602 //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);
603 } 603 }
604 if (asf_st->frag_offset == 0) { 604 if (asf_st->frag_offset == 0) {
605 /* new packet */ 605 /* new packet */
606 av_new_packet(&asf_st->pkt, asf->packet_obj_size); 606 av_new_packet(&asf_st->pkt, asf->packet_obj_size);
607 asf_st->seq = asf->packet_seq; 607 asf_st->seq = asf->packet_seq;
608 asf_st->pkt.pts = asf->packet_frag_timestamp; 608 asf_st->pkt.pts = asf->packet_frag_timestamp;
609 asf_st->pkt.stream_index = asf->stream_index; 609 asf_st->pkt.stream_index = asf->stream_index;
610 asf_st->pkt.pos = 610 asf_st->pkt.pos =
611 asf_st->packet_pos= asf->packet_pos; 611 asf_st->packet_pos= asf->packet_pos;
612 //printf("new packet: stream:%d key:%d packet_key:%d audio:%d size:%d\n", 612 //printf("new packet: stream:%d key:%d packet_key:%d audio:%d size:%d\n",
613 //asf->stream_index, asf->packet_key_frame, asf_st->pkt.flags & PKT_FLAG_KEY, 613 //asf->stream_index, asf->packet_key_frame, asf_st->pkt.flags & PKT_FLAG_KEY,
614 //s->streams[asf->stream_index]->codec->codec_type == CODEC_TYPE_AUDIO, asf->packet_obj_size); 614 //s->streams[asf->stream_index]->codec->codec_type == CODEC_TYPE_AUDIO, asf->packet_obj_size);
615 if (s->streams[asf->stream_index]->codec->codec_type == CODEC_TYPE_AUDIO) 615 if (s->streams[asf->stream_index]->codec->codec_type == CODEC_TYPE_AUDIO)
616 asf->packet_key_frame = 1; 616 asf->packet_key_frame = 1;
617 if (asf->packet_key_frame) 617 if (asf->packet_key_frame)
618 asf_st->pkt.flags |= PKT_FLAG_KEY; 618 asf_st->pkt.flags |= PKT_FLAG_KEY;
619 } 619 }
620 620
621 /* read data */ 621 /* read data */
622 //printf("READ PACKET s:%d os:%d o:%d,%d l:%d DATA:%p\n", 622 //printf("READ PACKET s:%d os:%d o:%d,%d l:%d DATA:%p\n",
623 // asf->packet_size, asf_st->pkt.size, asf->packet_frag_offset, 623 // asf->packet_size, asf_st->pkt.size, asf->packet_frag_offset,
624 // asf_st->frag_offset, asf->packet_frag_size, asf_st->pkt.data); 624 // asf_st->frag_offset, asf->packet_frag_size, asf_st->pkt.data);
625 asf->packet_size_left -= asf->packet_frag_size; 625 asf->packet_size_left -= asf->packet_frag_size;
626 if (asf->packet_size_left < 0) 626 if (asf->packet_size_left < 0)
627 continue; 627 continue;
628 get_buffer(pb, asf_st->pkt.data + asf->packet_frag_offset, 628 get_buffer(pb, asf_st->pkt.data + asf->packet_frag_offset,
629 asf->packet_frag_size); 629 asf->packet_frag_size);
630 asf_st->frag_offset += asf->packet_frag_size; 630 asf_st->frag_offset += asf->packet_frag_size;
631 /* test if whole packet is read */ 631 /* test if whole packet is read */
632 if (asf_st->frag_offset == asf_st->pkt.size) { 632 if (asf_st->frag_offset == asf_st->pkt.size) {
633 /* return packet */ 633 /* return packet */
634 if (asf_st->ds_span > 1) { 634 if (asf_st->ds_span > 1) {
635 /* packet descrambling */ 635 /* packet descrambling */
636 char* newdata = av_malloc(asf_st->pkt.size); 636 char* newdata = av_malloc(asf_st->pkt.size);
637 if (newdata) { 637 if (newdata) {
638 int offset = 0; 638 int offset = 0;
639 while (offset < asf_st->pkt.size) { 639 while (offset < asf_st->pkt.size) {
640 int off = offset / asf_st->ds_chunk_size; 640 int off = offset / asf_st->ds_chunk_size;
641 int row = off / asf_st->ds_span; 641 int row = off / asf_st->ds_span;
642 int col = off % asf_st->ds_span; 642 int col = off % asf_st->ds_span;
643 int idx = row + col * asf_st->ds_packet_size / asf_st->ds_chunk_size; 643 int idx = row + col * asf_st->ds_packet_size / asf_st->ds_chunk_size;
644 //printf("off:%d row:%d col:%d idx:%d\n", off, row, col, idx); 644 //printf("off:%d row:%d col:%d idx:%d\n", off, row, col, idx);
645 memcpy(newdata + offset, 645 memcpy(newdata + offset,
646 asf_st->pkt.data + idx * asf_st->ds_chunk_size, 646 asf_st->pkt.data + idx * asf_st->ds_chunk_size,
647 asf_st->ds_chunk_size); 647 asf_st->ds_chunk_size);
648 offset += asf_st->ds_chunk_size; 648 offset += asf_st->ds_chunk_size;
649 } 649 }
650 av_free(asf_st->pkt.data); 650 av_free(asf_st->pkt.data);
651 asf_st->pkt.data = newdata; 651 asf_st->pkt.data = newdata;
652 } 652 }
653 } 653 }
654 asf_st->frag_offset = 0; 654 asf_st->frag_offset = 0;
655 memcpy(pkt, &asf_st->pkt, sizeof(AVPacket)); 655 memcpy(pkt, &asf_st->pkt, sizeof(AVPacket));
656 //printf("packet %d %d\n", asf_st->pkt.size, asf->packet_frag_size); 656 //printf("packet %d %d\n", asf_st->pkt.size, asf->packet_frag_size);
657 asf_st->pkt.size = 0; 657 asf_st->pkt.size = 0;
658 asf_st->pkt.data = 0; 658 asf_st->pkt.data = 0;
659 break; // packet completed 659 break; // packet completed
660 } 660 }
661 } 661 }
662 return 0; 662 return 0;
663 } 663 }
664 664
665 static int asf_read_close(AVFormatContext *s) 665 static int asf_read_close(AVFormatContext *s)
666 { 666 {
667 int i; 667 int i;
668 668
669 for(i=0;i<s->nb_streams;i++) { 669 for(i=0;i<s->nb_streams;i++) {
670 AVStream *st = s->streams[i]; 670 AVStream *st = s->streams[i];
671 av_free(st->priv_data); 671 av_free(st->priv_data);
672 av_free(st->codec->extradata); 672 av_free(st->codec->extradata);
673 av_free(st->codec->palctrl); 673 av_free(st->codec->palctrl);
674 } 674 }
675 return 0; 675 return 0;
676 } 676 }
677 677
736 //printf("asf_read_pts\n"); 736 //printf("asf_read_pts\n");
737 asf_reset_header(s); 737 asf_reset_header(s);
738 for(;;){ 738 for(;;){
739 if (av_read_frame(s, pkt) < 0){ 739 if (av_read_frame(s, pkt) < 0){
740 av_log(s, AV_LOG_INFO, "seek failed\n"); 740 av_log(s, AV_LOG_INFO, "seek failed\n");
741 return AV_NOPTS_VALUE; 741 return AV_NOPTS_VALUE;
742 } 742 }
743 743
744 pts= pkt->pts * 1000 / AV_TIME_BASE; 744 pts= pkt->pts * 1000 / AV_TIME_BASE;
745 745
746 av_free_packet(pkt); 746 av_free_packet(pkt);