static int interleave_new_audio_packet(AVFormatContext *s, AVPacket *pkt,

                                       int stream_index, int flush)

{

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

    AudioInterleaveContext *aic = st->priv_data;



    int size = FFMIN(av_fifo_size(aic->fifo), *aic->samples * aic->sample_size);

    if (!size || (!flush && size == av_fifo_size(aic->fifo)))

        return 0;



    av_new_packet(pkt, size);

    av_fifo_generic_read(aic->fifo, pkt->data, size, NULL);



    pkt->dts = pkt->pts = aic->dts;

    pkt->duration = av_rescale_q(*aic->samples, st->time_base, aic->time_base);

    pkt->stream_index = stream_index;

    aic->dts += pkt->duration;



    aic->samples++;

    if (!*aic->samples)

        aic->samples = aic->samples_per_frame;



    return size;

}

static int interleave_new_audio_packet(AVFormatContext *s, AVPacket *pkt,

                                       int stream_index, int flush)

{

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

    AudioInterleaveContext *aic = st->priv_data;



    int size = FFMIN(av_fifo_size(aic->fifo), *aic->samples * aic->sample_size);

    if (!size || (!flush && size == av_fifo_size(aic->fifo)))

        return 0;



    av_new_packet(pkt, size);

    av_fifo_generic_read(aic->fifo, pkt->data, size, NULL);



    pkt->dts = pkt->pts = aic->dts;

    pkt->duration = av_rescale_q(*aic->samples, st->time_base, aic->time_base);

    pkt->stream_index = stream_index;

    aic->dts += pkt->duration;



    aic->samples++;

    if (!*aic->samples)

        aic->samples = aic->samples_per_frame;



    return size;

}

static int FUNC_0(AVFormatContext *VAR_0, AVPacket *VAR_1,

                                       int VAR_2, int VAR_3)

{

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

    AudioInterleaveContext *aic = st->priv_data;



    int VAR_4 = FFMIN(av_fifo_size(aic->fifo), *aic->samples * aic->sample_size);

    if (!VAR_4 || (!VAR_3 && VAR_4 == av_fifo_size(aic->fifo)))

        return 0;



    av_new_packet(VAR_1, VAR_4);

    av_fifo_generic_read(aic->fifo, VAR_1->data, VAR_4, NULL);



    VAR_1->dts = VAR_1->pts = aic->dts;

    VAR_1->duration = av_rescale_q(*aic->samples, st->time_base, aic->time_base);

    VAR_1->VAR_2 = VAR_2;

    aic->dts += VAR_1->duration;



    aic->samples++;

    if (!*aic->samples)

        aic->samples = aic->samples_per_frame;



    return VAR_4;

}

static int FUNC_0(AVFormatContext *VAR_0, AVPacket *VAR_1,
int VAR_2, int VAR_3)
{ AVStream *st = VAR_0->streams[VAR_2]; AudioInterleaveContext *aic = st->priv_data; int VAR_4 = FFMIN(av_fifo_size(aic->fifo), *aic->samples * aic->sample_size); if (!VAR_4 || (!VAR_3 && VAR_4 == av_fifo_size(aic->fifo)))
return 0; av_new_packet(VAR_1, VAR_4); av_fifo_generic_read(aic->fifo, VAR_1->data, VAR_4, NULL); VAR_1->dts = VAR_1->pts = aic->dts; VAR_1->duration = av_rescale_q(*aic->samples, st->time_base, aic->time_base); VAR_1->VAR_2 = VAR_2; aic->dts += VAR_1->duration; aic->samples++; if (!*aic->samples)
aic->samples = aic->samples_per_frame; return VAR_4; }