Revision f5a478f6 ffmpeg.c

View differences:

ffmpeg.c
23 23
#include "framehook.h"
24 24
#include "dsputil.h"
25 25
#include "opt.h"
26
#include "fifo.h"
26 27

  
27 28
#ifndef __MINGW32__
28 29
#include <unistd.h>
......
267 268
    /* audio only */
268 269
    int audio_resample;
269 270
    ReSampleContext *resample; /* for audio resampling */
270
    FifoBuffer fifo;     /* for compression: one audio fifo per codec */
271
    AVFifoBuffer fifo;     /* for compression: one audio fifo per codec */
271 272
    FILE *logfile;
272 273
} AVOutputStream;
273 274

  
......
471 472

  
472 473
    if(audio_sync_method){
473 474
        double delta = get_sync_ipts(ost) * enc->sample_rate - ost->sync_opts
474
                - fifo_size(&ost->fifo, ost->fifo.rptr)/(ost->st->codec->channels * 2);
475
                - av_fifo_size(&ost->fifo)/(ost->st->codec->channels * 2);
475 476
        double idelta= delta*ist->st->codec->sample_rate / enc->sample_rate;
476 477
        int byte_delta= ((int)idelta)*2*ist->st->codec->channels;
477 478

  
......
508 509
                assert(ost->audio_resample);
509 510
                if(verbose > 2)
510 511
                    fprintf(stderr, "compensating audio timestamp drift:%f compensation:%d in:%d\n", delta, comp, enc->sample_rate);
511
//                fprintf(stderr, "drift:%f len:%d opts:%lld ipts:%lld fifo:%d\n", delta, -1, ost->sync_opts, (int64_t)(get_sync_ipts(ost) * enc->sample_rate), fifo_size(&ost->fifo, ost->fifo.rptr)/(ost->st->codec->channels * 2));
512
//                fprintf(stderr, "drift:%f len:%d opts:%lld ipts:%lld fifo:%d\n", delta, -1, ost->sync_opts, (int64_t)(get_sync_ipts(ost) * enc->sample_rate), av_fifo_size(&ost->fifo)/(ost->st->codec->channels * 2));
512 513
                av_resample_compensate(*(struct AVResampleContext**)ost->resample, comp, enc->sample_rate);
513 514
            }
514 515
        }
515 516
    }else
516 517
        ost->sync_opts= lrintf(get_sync_ipts(ost) * enc->sample_rate)
517
                        - fifo_size(&ost->fifo, ost->fifo.rptr)/(ost->st->codec->channels * 2); //FIXME wrong
518
                        - av_fifo_size(&ost->fifo)/(ost->st->codec->channels * 2); //FIXME wrong
518 519

  
519 520
    if (ost->audio_resample) {
520 521
        buftmp = audio_buf;
......
530 531
    /* now encode as many frames as possible */
531 532
    if (enc->frame_size > 1) {
532 533
        /* output resampled raw samples */
533
        fifo_write(&ost->fifo, buftmp, size_out,
534
                   &ost->fifo.wptr);
534
        av_fifo_write(&ost->fifo, buftmp, size_out);
535 535

  
536 536
        frame_bytes = enc->frame_size * 2 * enc->channels;
537 537

  
538
        while (fifo_read(&ost->fifo, audio_buf, frame_bytes,
539
                     &ost->fifo.rptr) == 0) {
538
        while (av_fifo_read(&ost->fifo, audio_buf, frame_bytes) == 0) {
540 539
            AVPacket pkt;
541 540
            av_init_packet(&pkt);
542 541

  
......
1317 1316

  
1318 1317
                        switch(ost->st->codec->codec_type) {
1319 1318
                        case CODEC_TYPE_AUDIO:
1320
                            fifo_bytes = fifo_size(&ost->fifo, NULL);
1319
                            fifo_bytes = av_fifo_size(&ost->fifo);
1321 1320
                            ret = 0;
1322 1321
                            /* encode any samples remaining in fifo */
1323 1322
                            if(fifo_bytes > 0 && enc->codec->capabilities & CODEC_CAP_SMALL_LAST_FRAME) {
1324 1323
                                int fs_tmp = enc->frame_size;
1325 1324
                                enc->frame_size = fifo_bytes / (2 * enc->channels);
1326
                                if(fifo_read(&ost->fifo, (uint8_t *)samples, fifo_bytes,
1327
                                        &ost->fifo.rptr) == 0) {
1325
                                if(av_fifo_read(&ost->fifo, (uint8_t *)samples, fifo_bytes) == 0) {
1328 1326
                                    ret = avcodec_encode_audio(enc, bit_buffer, bit_buffer_size, samples);
1329 1327
                                }
1330 1328
                                enc->frame_size = fs_tmp;
......
1563 1561
        } else {
1564 1562
            switch(codec->codec_type) {
1565 1563
            case CODEC_TYPE_AUDIO:
1566
                if (fifo_init(&ost->fifo, 2 * MAX_AUDIO_PACKET_SIZE))
1564
                if (av_fifo_init(&ost->fifo, 2 * MAX_AUDIO_PACKET_SIZE))
1567 1565
                    goto fail;
1568 1566

  
1569 1567
                if (codec->channels == icodec->channels &&
......
2018 2016
                    fclose(ost->logfile);
2019 2017
                    ost->logfile = NULL;
2020 2018
                }
2021
                fifo_free(&ost->fifo); /* works even if fifo is not
2022
                                          initialized but set to zero */
2019
                av_fifo_free(&ost->fifo); /* works even if fifo is not
2020
                                             initialized but set to zero */
2023 2021
                av_free(ost->pict_tmp.data[0]);
2024 2022
                if (ost->video_resample)
2025 2023
                    sws_freeContext(ost->img_resample_ctx);

Also available in: Unified diff