Revision f5a478f6 libavformat/mpeg.c

View differences:

libavformat/mpeg.c
18 18
 */
19 19
#include "avformat.h"
20 20
#include "bitstream.h"
21
#include "fifo.h"
21 22

  
22 23
#define MAX_PAYLOAD_SIZE 4096
23 24
//#define DEBUG_SEEK
......
35 36
} PacketDesc;
36 37

  
37 38
typedef struct {
38
    FifoBuffer fifo;
39
    AVFifoBuffer fifo;
39 40
    uint8_t id;
40 41
    int max_buffer_size; /* in bytes */
41 42
    int buffer_index;
......
45 46
    int packet_number;
46 47
    uint8_t lpcm_header[3];
47 48
    int lpcm_align;
48
    uint8_t *fifo_iframe_ptr;
49
    int bytes_to_iframe;
49 50
    int align_iframe;
50 51
    int64_t vobu_start_pts;
51 52
} StreamInfo;
......
412 413
        default:
413 414
            return -1;
414 415
        }
415
        fifo_init(&stream->fifo, 16);
416
        av_fifo_init(&stream->fifo, 16);
416 417
    }
417 418
    bitrate = 0;
418 419
    audio_bitrate = 0;
......
708 709
            }
709 710
        } else if (s->is_dvd) {
710 711
            if (stream->align_iframe || s->packet_number == 0){
711
                int bytes_to_iframe;
712
                int PES_bytes_to_fill;
713
                if (stream->fifo_iframe_ptr >= stream->fifo.rptr) {
714
                    bytes_to_iframe = stream->fifo_iframe_ptr - stream->fifo.rptr;
715
                } else {
716
                    bytes_to_iframe = (stream->fifo.end - stream->fifo.rptr) + (stream->fifo_iframe_ptr - stream->fifo.buffer);
717
                }
718
                PES_bytes_to_fill = s->packet_size - size - 10;
712
                int PES_bytes_to_fill = s->packet_size - size - 10;
719 713

  
720 714
                if (pts != AV_NOPTS_VALUE) {
721 715
                    if (dts != pts)
......
724 718
                        PES_bytes_to_fill -= 5;
725 719
                }
726 720

  
727
                if (bytes_to_iframe == 0 || s->packet_number == 0) {
721
                if (stream->bytes_to_iframe == 0 || s->packet_number == 0) {
728 722
                    size = put_system_header(ctx, buf_ptr, 0);
729 723
                    buf_ptr += size;
730 724
                    size = buf_ptr - buffer;
......
751 745
                    s->last_scr= scr;
752 746
                    buf_ptr += size;
753 747
                    /* GOP Start */
754
                } else if (bytes_to_iframe < PES_bytes_to_fill) {
755
                    pad_packet_bytes = PES_bytes_to_fill - bytes_to_iframe;
748
                } else if (stream->bytes_to_iframe < PES_bytes_to_fill) {
749
                    pad_packet_bytes = PES_bytes_to_fill - stream->bytes_to_iframe;
756 750
                }
757 751
            }
758 752
        } else {
......
824 818
            startcode = 0x100 + id;
825 819
        }
826 820

  
827
        stuffing_size = payload_size - fifo_size(&stream->fifo, stream->fifo.rptr);
821
        stuffing_size = payload_size - av_fifo_size(&stream->fifo);
828 822

  
829 823
        // first byte doesnt fit -> reset pts/dts + stuffing
830 824
        if(payload_size <= trailer_size && pts != AV_NOPTS_VALUE){
......
951 945
        }
952 946

  
953 947
        /* output data */
954
        if(put_fifo(&ctx->pb, &stream->fifo, payload_size - stuffing_size, &stream->fifo.rptr) < 0)
948
        if(av_fifo_generic_read(&stream->fifo, payload_size - stuffing_size, &put_buffer, &ctx->pb) < 0)
955 949
            return -1;
950
        stream->bytes_to_iframe -= payload_size - stuffing_size;
956 951
    }else{
957 952
        payload_size=
958 953
        stuffing_size= 0;
......
1065 1060
    for(i=0; i<ctx->nb_streams; i++){
1066 1061
        AVStream *st = ctx->streams[i];
1067 1062
        StreamInfo *stream = st->priv_data;
1068
        const int avail_data=  fifo_size(&stream->fifo, stream->fifo.rptr);
1063
        const int avail_data=  av_fifo_size(&stream->fifo);
1069 1064
        const int space= stream->max_buffer_size - stream->buffer_index;
1070 1065
        int rel_space= 1024*space / stream->max_buffer_size;
1071 1066
        PacketDesc *next_pkt= stream->premux_packet;
......
1125 1120
    st = ctx->streams[best_i];
1126 1121
    stream = st->priv_data;
1127 1122

  
1128
    assert(fifo_size(&stream->fifo, stream->fifo.rptr) > 0);
1123
    assert(av_fifo_size(&stream->fifo) > 0);
1129 1124

  
1130 1125
    assert(avail_space >= s->packet_size || ignore_constraints);
1131 1126

  
......
1141 1136
//av_log(ctx, AV_LOG_DEBUG, "dts:%f pts:%f scr:%f stream:%d\n", timestamp_packet->dts/90000.0, timestamp_packet->pts/90000.0, scr/90000.0, best_i);
1142 1137
        es_size= flush_packet(ctx, best_i, timestamp_packet->pts, timestamp_packet->dts, scr, trailer_size);
1143 1138
    }else{
1144
        assert(fifo_size(&stream->fifo, stream->fifo.rptr) == trailer_size);
1139
        assert(av_fifo_size(&stream->fifo) == trailer_size);
1145 1140
        es_size= flush_packet(ctx, best_i, AV_NOPTS_VALUE, AV_NOPTS_VALUE, scr, trailer_size);
1146 1141
    }
1147 1142

  
......
1204 1199
        stream->predecode_packet= pkt_desc;
1205 1200
    stream->next_packet= &pkt_desc->next;
1206 1201

  
1207
    fifo_realloc(&stream->fifo, fifo_size(&stream->fifo, NULL) + size + 1);
1202
    av_fifo_realloc(&stream->fifo, av_fifo_size(&stream->fifo) + size + 1);
1208 1203

  
1209 1204
    if (s->is_dvd){
1210 1205
        if (is_iframe && (s->packet_number == 0 || (pts - stream->vobu_start_pts >= 36000))) { // min VOBU length 0.4 seconds (mpucoder)
1211
            stream->fifo_iframe_ptr = stream->fifo.wptr;
1206
            stream->bytes_to_iframe = av_fifo_size(&stream->fifo);
1212 1207
            stream->align_iframe = 1;
1213 1208
            stream->vobu_start_pts = pts;
1214 1209
        } else {
......
1216 1211
        }
1217 1212
    }
1218 1213

  
1219
    fifo_write(&stream->fifo, buf, size, &stream->fifo.wptr);
1214
    av_fifo_write(&stream->fifo, buf, size);
1220 1215

  
1221 1216
    for(;;){
1222 1217
        int ret= output_packet(ctx, 0);
......
1248 1243
    for(i=0;i<ctx->nb_streams;i++) {
1249 1244
        stream = ctx->streams[i]->priv_data;
1250 1245

  
1251
        assert(fifo_size(&stream->fifo, stream->fifo.rptr) == 0);
1252
        fifo_free(&stream->fifo);
1246
        assert(av_fifo_size(&stream->fifo) == 0);
1247
        av_fifo_free(&stream->fifo);
1253 1248
    }
1254 1249
    return 0;
1255 1250
}

Also available in: Unified diff