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;

    int64_t dts;

    int len;



    /* XXX: system clock should be computed precisely, especially for

       CBR case. The current mode gives at least something coherent */

    if (stream_index == s->scr_stream_index)

        s->last_scr = pts;

    

#if 0

    printf("%d: pts=%0.3f scr=%0.3f\n", 

           stream_index, pts / 90000.0, s->last_scr / 90000.0);

#endif

    

    /* XXX: currently no way to pass dts, will change soon */

    dts = AV_NOPTS_VALUE;



    /* we assume here that pts != AV_NOPTS_VALUE */

    if (stream->start_pts == AV_NOPTS_VALUE) {

        stream->start_pts = pts;

        stream->start_dts = dts;

    }

    while (size > 0) {

        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 */

            flush_packet(ctx, stream_index,

                         stream->start_pts, stream->start_dts, s->last_scr);

            /* Make sure only the FIRST pes packet for this frame has

               a timestamp */

            stream->start_pts = AV_NOPTS_VALUE;

            stream->start_dts = AV_NOPTS_VALUE;

        }

    }

    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;

    int64_t dts;

    int len;



    



    if (stream_index == s->scr_stream_index)

        s->last_scr = pts;

    

#if 0

    printf("%d: pts=%0.3f scr=%0.3f\n", 

           stream_index, pts / 90000.0, s->last_scr / 90000.0);

#endif

    

    

    dts = AV_NOPTS_VALUE;



    

    if (stream->start_pts == AV_NOPTS_VALUE) {

        stream->start_pts = pts;

        stream->start_dts = dts;

    }

    while (size > 0) {

        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) {

            

            flush_packet(ctx, stream_index,

                         stream->start_pts, stream->start_dts, s->last_scr);

            



            stream->start_pts = AV_NOPTS_VALUE;

            stream->start_dts = AV_NOPTS_VALUE;

        }

    }

    return 0;

}

    int64_t dts;     int len;         stream->start_pts = pts;         stream->start_dts = dts;         len = s->packet_data_max_size - stream->buffer_ptr;         while (stream->buffer_ptr >= s->packet_data_max_size) {
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;

    int64_t dts;

    int VAR_5;



    



    if (VAR_1 == s->scr_stream_index)

        s->last_scr = VAR_4;

    

#if 0

    printf("%d: VAR_4=%0.3f scr=%0.3f\n", 

           VAR_1, VAR_4 / 90000.0, s->last_scr / 90000.0);

#endif

    

    

    dts = AV_NOPTS_VALUE;



    

    if (stream->start_pts == AV_NOPTS_VALUE) {

        stream->start_pts = VAR_4;

        stream->start_dts = dts;

    }

    while (VAR_3 > 0) {

        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) {

            

            flush_packet(VAR_0, VAR_1,

                         stream->start_pts, stream->start_dts, s->last_scr);

            



            stream->start_pts = AV_NOPTS_VALUE;

            stream->start_dts = AV_NOPTS_VALUE;

        }

    }

    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; int64_t dts; int VAR_5; if (VAR_1 == s->scr_stream_index)
s->last_scr = VAR_4; #if 0
printf("%d: VAR_4=%0.3f scr=%0.3f\n",
VAR_1, VAR_4 / 90000.0, s->last_scr / 90000.0); #endif
dts = AV_NOPTS_VALUE; if (stream->start_pts == AV_NOPTS_VALUE) { stream->start_pts = VAR_4; stream->start_dts = dts; } while (VAR_3 > 0) { 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) { flush_packet(VAR_0, VAR_1,
stream->start_pts, stream->start_dts, s->last_scr); stream->start_pts = AV_NOPTS_VALUE; stream->start_dts = AV_NOPTS_VALUE; } } return 0; }