static int mpeg_mux_write_packet(AVFormatContext *ctx, int stream_index,

                                 const uint8_t *buf, int size, int64_t pts)

{

    MpegMuxContext *s = ctx->priv_data;

    AVStream *st = ctx->streams[stream_index];

    StreamInfo *stream = st->priv_data;

    int len;

    

    while (size > 0) {

        /* set pts */

        if (stream->start_pts == -1) {

            stream->start_pts = pts;

        }

        len = s->packet_data_max_size - stream->buffer_ptr;

        if (len > size)

            len = size;

        memcpy(stream->buffer + stream->buffer_ptr, buf, len);

        stream->buffer_ptr += len;

        buf += len;

        size -= len;

        while (stream->buffer_ptr >= s->packet_data_max_size) {

            /* output the packet */

            if (stream->start_pts == -1)

                stream->start_pts = pts;

            flush_packet(ctx, stream_index, 0);

        }

    }

    return 0;

}

static int mpeg_mux_write_packet(AVFormatContext *ctx, int stream_index,

                                 const uint8_t *buf, int size, int64_t pts)

{

    MpegMuxContext *s = ctx->priv_data;

    AVStream *st = ctx->streams[stream_index];

    StreamInfo *stream = st->priv_data;

    int len;

    

    while (size > 0) {

        

        if (stream->start_pts == -1) {

            stream->start_pts = pts;

        }

        len = s->packet_data_max_size - stream->buffer_ptr;

        if (len > size)

            len = size;

        memcpy(stream->buffer + stream->buffer_ptr, buf, len);

        stream->buffer_ptr += len;

        buf += len;

        size -= len;

        while (stream->buffer_ptr >= s->packet_data_max_size) {

            

            if (stream->start_pts == -1)

                stream->start_pts = pts;

            flush_packet(ctx, stream_index, 0);

        }

    }

    return 0;

}

static int FUNC_0(AVFormatContext *VAR_0, int VAR_1,

                                 const uint8_t *VAR_2, int VAR_3, int64_t VAR_4)

{

    MpegMuxContext *s = VAR_0->priv_data;

    AVStream *st = VAR_0->streams[VAR_1];

    StreamInfo *stream = st->priv_data;

    int VAR_5;

    

    while (VAR_3 > 0) {

        

        if (stream->start_pts == -1) {

            stream->start_pts = VAR_4;

        }

        VAR_5 = s->packet_data_max_size - stream->buffer_ptr;

        if (VAR_5 > VAR_3)

            VAR_5 = VAR_3;

        memcpy(stream->buffer + stream->buffer_ptr, VAR_2, VAR_5);

        stream->buffer_ptr += VAR_5;

        VAR_2 += VAR_5;

        VAR_3 -= VAR_5;

        while (stream->buffer_ptr >= s->packet_data_max_size) {

            

            if (stream->start_pts == -1)

                stream->start_pts = VAR_4;

            flush_packet(VAR_0, VAR_1, 0);

        }

    }

    return 0;

}

static int FUNC_0(AVFormatContext *VAR_0, int VAR_1,
const uint8_t *VAR_2, int VAR_3, int64_t VAR_4)
{ MpegMuxContext *s = VAR_0->priv_data; AVStream *st = VAR_0->streams[VAR_1]; StreamInfo *stream = st->priv_data; int VAR_5; while (VAR_3 > 0) { if (stream->start_pts == -1) { stream->start_pts = VAR_4; } VAR_5 = s->packet_data_max_size - stream->buffer_ptr; if (VAR_5 > VAR_3)
VAR_5 = VAR_3; memcpy(stream->buffer + stream->buffer_ptr, VAR_2, VAR_5); stream->buffer_ptr += VAR_5; VAR_2 += VAR_5; VAR_3 -= VAR_5; while (stream->buffer_ptr >= s->packet_data_max_size) { if (stream->start_pts == -1)
stream->start_pts = VAR_4; flush_packet(VAR_0, VAR_1, 0); } } return 0; }