Revision 853a9753

View differences:

libavformat/mp3.c
402 402
/**
403 403
 * Try to find Xing/Info/VBRI tags and compute duration from info therein
404 404
 */
405
static void mp3_parse_vbr_tags(AVFormatContext *s, AVStream *st, int64_t base)
405
static int mp3_parse_vbr_tags(AVFormatContext *s, AVStream *st, int64_t base)
406 406
{
407 407
    uint32_t v, spf;
408 408
    int frames = -1; /* Total number of frames in file */
409 409
    const int64_t xing_offtbl[2][2] = {{32, 17}, {17,9}};
410 410
    MPADecodeContext c;
411
    int vbrtag_size = 0;
411 412

  
412 413
    v = get_be32(s->pb);
413 414
    if(ff_mpa_check_header(v) < 0)
414
      return;
415
      return -1;
415 416

  
416
    ff_mpegaudio_decode_header(&c, v);
417
    if (ff_mpegaudio_decode_header(&c, v) == 0)
418
        vbrtag_size = c.frame_size;
417 419
    if(c.layer != 3)
418
        return;
420
        return -1;
419 421

  
420 422
    /* Check for Xing / Info tag */
421 423
    url_fseek(s->pb, xing_offtbl[c.lsf == 1][c.nb_channels == 1], SEEK_CUR);
......
439 441
    }
440 442

  
441 443
    if(frames < 0)
442
        return;
444
        return -1;
445

  
446
    /* Skip the vbr tag frame */
447
    url_fseek(s->pb, base + vbrtag_size, SEEK_SET);
443 448

  
444 449
    spf = c.lsf ? 576 : 1152; /* Samples per frame, layer 3 */
445 450
    st->duration = av_rescale_q(frames, (AVRational){spf, c.sample_rate},
446 451
                                st->time_base);
452
    return 0;
447 453
}
448 454

  
449 455
static int mp3_read_header(AVFormatContext *s,
......
493 499
    }
494 500

  
495 501
    off = url_ftell(s->pb);
496
    mp3_parse_vbr_tags(s, st, off);
497
    url_fseek(s->pb, off, SEEK_SET);
502
    if (mp3_parse_vbr_tags(s, st, off) < 0)
503
        url_fseek(s->pb, off, SEEK_SET);
498 504

  
499 505
    /* the parameters will be extracted from the compressed bitstream */
500 506
    return 0;

Also available in: Unified diff