static int gxf_interleave_packet(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush)

{

    GXFContext *gxf = s->priv_data;

    AVPacket new_pkt;

    int i;



    for (i = 0; i < s->nb_streams; i++) {

        if (s->streams[i]->codec->codec_type == CODEC_TYPE_AUDIO) {

            GXFStreamContext *sc = &gxf->streams[i];

            if (pkt && pkt->stream_index == i) {

                av_fifo_write(&sc->audio_buffer, pkt->data, pkt->size);

                pkt = NULL;

            }

            if (flush || av_fifo_size(&sc->audio_buffer) >= GXF_AUDIO_PACKET_SIZE) {

                if (!pkt && gxf_new_audio_packet(gxf, sc, &new_pkt, flush) > 0) {

                    pkt = &new_pkt;

                    break; /* add pkt right now into list */

                }

            }

        }

    }

    return av_interleave_packet_per_dts(s, out, pkt, flush);

}

static int gxf_interleave_packet(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush)

{

    GXFContext *gxf = s->priv_data;

    AVPacket new_pkt;

    int i;



    for (i = 0; i < s->nb_streams; i++) {

        if (s->streams[i]->codec->codec_type == CODEC_TYPE_AUDIO) {

            GXFStreamContext *sc = &gxf->streams[i];

            if (pkt && pkt->stream_index == i) {

                av_fifo_write(&sc->audio_buffer, pkt->data, pkt->size);

                pkt = NULL;

            }

            if (flush || av_fifo_size(&sc->audio_buffer) >= GXF_AUDIO_PACKET_SIZE) {

                if (!pkt && gxf_new_audio_packet(gxf, sc, &new_pkt, flush) > 0) {

                    pkt = &new_pkt;

                    break; 

                }

            }

        }

    }

    return av_interleave_packet_per_dts(s, out, pkt, flush);

}

static int FUNC_0(AVFormatContext *VAR_0, AVPacket *VAR_1, AVPacket *VAR_2, int VAR_3)

{

    GXFContext *gxf = VAR_0->priv_data;

    AVPacket new_pkt;

    int VAR_4;



    for (VAR_4 = 0; VAR_4 < VAR_0->nb_streams; VAR_4++) {

        if (VAR_0->streams[VAR_4]->codec->codec_type == CODEC_TYPE_AUDIO) {

            GXFStreamContext *sc = &gxf->streams[VAR_4];

            if (VAR_2 && VAR_2->stream_index == VAR_4) {

                av_fifo_write(&sc->audio_buffer, VAR_2->data, VAR_2->size);

                VAR_2 = NULL;

            }

            if (VAR_3 || av_fifo_size(&sc->audio_buffer) >= GXF_AUDIO_PACKET_SIZE) {

                if (!VAR_2 && gxf_new_audio_packet(gxf, sc, &new_pkt, VAR_3) > 0) {

                    VAR_2 = &new_pkt;

                    break; 

                }

            }

        }

    }

    return av_interleave_packet_per_dts(VAR_0, VAR_1, VAR_2, VAR_3);

}

static int FUNC_0(AVFormatContext *VAR_0, AVPacket *VAR_1, AVPacket *VAR_2, int VAR_3)
{ GXFContext *gxf = VAR_0->priv_data; AVPacket new_pkt; int VAR_4; for (VAR_4 = 0; VAR_4 < VAR_0->nb_streams; VAR_4++) { if (VAR_0->streams[VAR_4]->codec->codec_type == CODEC_TYPE_AUDIO) { GXFStreamContext *sc = &gxf->streams[VAR_4]; if (VAR_2 && VAR_2->stream_index == VAR_4) { av_fifo_write(&sc->audio_buffer, VAR_2->data, VAR_2->size); VAR_2 = NULL; } if (VAR_3 || av_fifo_size(&sc->audio_buffer) >= GXF_AUDIO_PACKET_SIZE) { if (!VAR_2 && gxf_new_audio_packet(gxf, sc, &new_pkt, VAR_3) > 0) { VAR_2 = &new_pkt; break; } } } } return av_interleave_packet_per_dts(VAR_0, VAR_1, VAR_2, VAR_3); }