Revision ec9a5deb libavformat/mp3enc.c

View differences:

libavformat/mp3enc.c
172 172
            uint32_t want;
173 173
            uint32_t seen;
174 174
            uint32_t pos;
175
            uint64_t sum;
176 175
            uint64_t bag[VBR_NUM_BAGS];
177 176
        } toc;
178 177
    } xing_header;
......
277 276
    mp3->xing_header.toc.want=1;
278 277
    mp3->xing_header.toc.seen=0;
279 278
    mp3->xing_header.toc.pos=0;
280
    mp3->xing_header.toc.sum=0;
281 279

  
282 280
    avio_wb32(s->pb, 0);  // frames
283 281
    avio_wb32(s->pb, 0);  // size
......
296 294
 * Add a frame to XING data.
297 295
 * Following lame's "VbrTag.c".
298 296
 */
299
static void mp3_xing_add_frame(AVFormatContext *s, AVPacket *pkt, MPADecodeHeader *c)
297
static void mp3_xing_add_frame(AVFormatContext *s, AVPacket *pkt)
300 298
{
301 299
    MP3Context  *mp3 = s->priv_data;
302 300
    struct xing_header *xing_header = &mp3->xing_header;
......
305 303

  
306 304
    ++xing_header->frames;
307 305
    xing_header->size += pkt->size;
308
    toc->sum += c->bit_rate / 1000;
309 306

  
310 307
    if (toc->want == ++toc->seen) {
311
        toc->bag[toc->pos] = toc->sum;
308
        toc->bag[toc->pos] = xing_header->size;
312 309

  
313 310
        if (VBR_NUM_BAGS == ++toc->pos) {
314 311
            /* shrink table to half size by throwing away each second bag. */
......
342 339

  
343 340
    for (i = 1; i < VBR_TOC_SIZE; ++i) {
344 341
        int j = (int)floor(scale * i);
345
        int seek_point = (int)floor(256.0 * toc->bag[j] / toc->sum);
346

  
342
        int seek_point = (int)floor(256.0 * toc->bag[j] / xing_header->size);
347 343
        avio_w8(s->pb, (uint8_t)(seek_point < 256 ? seek_point : 255));
348 344
    }
349 345

  
......
414 410
        MPADecodeHeader c;
415 411
        int base;
416 412

  
413
#ifdef FILTER_VBR_HEADERS
417 414
        ff_mpegaudio_decode_header(&c, AV_RB32(pkt->data));
418 415

  
419
#ifdef FILTER_VBR_HEADERS
420 416
        /* filter out XING and INFO headers. */
421 417
        base = 4 + xing_offtbl[c.lsf == 1][c.nb_channels == 1];
422 418

  
......
435 431
#endif
436 432

  
437 433
        if (0 < mp3->xing_header.offset)
438
            mp3_xing_add_frame(s, pkt, &c);
434
            mp3_xing_add_frame(s, pkt);
439 435

  
440 436
        return ff_raw_write_packet(s, pkt);
441 437
    }

Also available in: Unified diff