comparison mp3.c @ 2667:e896ac505ec6 libavformat

add support for reading duration from VBRI-tag in mp3 files
author andoma
date Wed, 24 Oct 2007 04:56:22 +0000
parents 33122df98824
children 2c2da3011d6e
comparison
equal deleted inserted replaced
2666:1995444f6267 2667:e896ac505ec6
424 else if(max_frames>=1) return 1; 424 else if(max_frames>=1) return 1;
425 else return 0; 425 else return 0;
426 } 426 }
427 427
428 /** 428 /**
429 * Try to extract a xing tag from the stream and if found, decode it 429 * Try to find Xing/Info/VBRI tags and compute duration from info therein
430 */ 430 */
431 static void mp3_parse_xing(AVFormatContext *s, AVStream *st) 431 static void mp3_parse_vbr_tags(AVFormatContext *s, AVStream *st, offset_t base)
432 { 432 {
433 uint32_t v, spf; 433 uint32_t v, spf;
434 int frames = -1; /* Total number of frames in file */ 434 int frames = -1; /* Total number of frames in file */
435 const offset_t xing_offtbl[2][2] = {{32, 17}, {17,9}}; 435 const offset_t xing_offtbl[2][2] = {{32, 17}, {17,9}};
436 MPADecodeContext c; 436 MPADecodeContext c;
444 v = get_be32(&s->pb); 444 v = get_be32(&s->pb);
445 if(v == MKBETAG('X', 'i', 'n', 'g') || v == MKBETAG('I', 'n', 'f', 'o')) { 445 if(v == MKBETAG('X', 'i', 'n', 'g') || v == MKBETAG('I', 'n', 'f', 'o')) {
446 v = get_be32(&s->pb); 446 v = get_be32(&s->pb);
447 if(v & 0x1) 447 if(v & 0x1)
448 frames = get_be32(&s->pb); 448 frames = get_be32(&s->pb);
449 }
450
451 /* Check for VBRI tag (always 32 bytes after end of mpegaudio header) */
452 url_fseek(&s->pb, base + 4 + 32, SEEK_SET);
453 v = get_be32(&s->pb);
454 if(v == MKBETAG('V', 'B', 'R', 'I')) {
455 /* Check tag version */
456 if(get_be16(&s->pb) == 1) {
457 /* skip delay, quality and total bytes */
458 url_fseek(&s->pb, 8, SEEK_CUR);
459 frames = get_be32(&s->pb);
460 }
449 } 461 }
450 462
451 if(frames < 0) 463 if(frames < 0)
452 return; 464 return;
453 465
501 } else { 513 } else {
502 url_fseek(&s->pb, 0, SEEK_SET); 514 url_fseek(&s->pb, 0, SEEK_SET);
503 } 515 }
504 516
505 off = url_ftell(&s->pb); 517 off = url_ftell(&s->pb);
506 mp3_parse_xing(s, st); 518 mp3_parse_vbr_tags(s, st, off);
507 url_fseek(&s->pb, off, SEEK_SET); 519 url_fseek(&s->pb, off, SEEK_SET);
508 520
509 /* the parameters will be extracted from the compressed bitstream */ 521 /* the parameters will be extracted from the compressed bitstream */
510 return 0; 522 return 0;
511 } 523 }