int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt)

{

    int ret, flush = 0;



    ret = check_packet(s, pkt);

    if (ret < 0)

        goto fail;



    if (pkt) {

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



        //FIXME/XXX/HACK drop zero sized packets

        if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO && pkt->size == 0) {

            ret = 0;

            goto fail;

        }



        av_dlog(s, "av_interleaved_write_frame size:%d dts:%" PRId64 " pts:%" PRId64 "\n",

                pkt->size, pkt->dts, pkt->pts);

        if ((ret = compute_pkt_fields2(s, st, pkt)) < 0 && !(s->oformat->flags & AVFMT_NOTIMESTAMPS))

            goto fail;



        if (pkt->dts == AV_NOPTS_VALUE && !(s->oformat->flags & AVFMT_NOTIMESTAMPS)) {

            ret = AVERROR(EINVAL);

            goto fail;

        }

    } else {

        av_dlog(s, "av_interleaved_write_frame FLUSH\n");

        flush = 1;

    }



    for (;; ) {

        AVPacket opkt;

        int ret = interleave_packet(s, &opkt, pkt, flush);

        if (pkt) {

            memset(pkt, 0, sizeof(*pkt));

            av_init_packet(pkt);

            pkt = NULL;

        }

        if (ret <= 0) //FIXME cleanup needed for ret<0 ?

            return ret;



        ret = write_packet(s, &opkt);

        if (ret >= 0)

            s->streams[opkt.stream_index]->nb_frames++;



        av_free_packet(&opkt);



        if (ret < 0)

            return ret;

    }

fail:

    av_packet_unref(pkt);

    return ret;

}

int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt)

{

    int ret, flush = 0;



    ret = check_packet(s, pkt);

    if (ret < 0)

        goto fail;



    if (pkt) {

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



        

        if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO && pkt->size == 0) {

            ret = 0;

            goto fail;

        }



        av_dlog(s, "av_interleaved_write_frame size:%d dts:%" PRId64 " pts:%" PRId64 "\n",

                pkt->size, pkt->dts, pkt->pts);

        if ((ret = compute_pkt_fields2(s, st, pkt)) < 0 && !(s->oformat->flags & AVFMT_NOTIMESTAMPS))

            goto fail;



        if (pkt->dts == AV_NOPTS_VALUE && !(s->oformat->flags & AVFMT_NOTIMESTAMPS)) {

            ret = AVERROR(EINVAL);

            goto fail;

        }

    } else {

        av_dlog(s, "av_interleaved_write_frame FLUSH\n");

        flush = 1;

    }



    for (;; ) {

        AVPacket opkt;

        int ret = interleave_packet(s, &opkt, pkt, flush);

        if (pkt) {

            memset(pkt, 0, sizeof(*pkt));

            av_init_packet(pkt);

            pkt = NULL;

        }

        if (ret <= 0) 

            return ret;



        ret = write_packet(s, &opkt);

        if (ret >= 0)

            s->streams[opkt.stream_index]->nb_frames++;



        av_free_packet(&opkt);



        if (ret < 0)

            return ret;

    }

fail:

    av_packet_unref(pkt);

    return ret;

}

int FUNC_0(AVFormatContext *VAR_0, AVPacket *VAR_1)

{

    int VAR_4, VAR_3 = 0;



    VAR_4 = check_packet(VAR_0, VAR_1);

    if (VAR_4 < 0)

        goto fail;



    if (VAR_1) {

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



        

        if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO && VAR_1->size == 0) {

            VAR_4 = 0;

            goto fail;

        }



        av_dlog(VAR_0, "FUNC_0 size:%d dts:%" PRId64 " pts:%" PRId64 "\n",

                VAR_1->size, VAR_1->dts, VAR_1->pts);

        if ((VAR_4 = compute_pkt_fields2(VAR_0, st, VAR_1)) < 0 && !(VAR_0->oformat->flags & AVFMT_NOTIMESTAMPS))

            goto fail;



        if (VAR_1->dts == AV_NOPTS_VALUE && !(VAR_0->oformat->flags & AVFMT_NOTIMESTAMPS)) {

            VAR_4 = AVERROR(EINVAL);

            goto fail;

        }

    } else {

        av_dlog(VAR_0, "FUNC_0 FLUSH\n");

        VAR_3 = 1;

    }



    for (;; ) {

        AVPacket opkt;

        int VAR_4 = interleave_packet(VAR_0, &opkt, VAR_1, VAR_3);

        if (VAR_1) {

            memset(VAR_1, 0, sizeof(*VAR_1));

            av_init_packet(VAR_1);

            VAR_1 = NULL;

        }

        if (VAR_4 <= 0) 

            return VAR_4;



        VAR_4 = write_packet(VAR_0, &opkt);

        if (VAR_4 >= 0)

            VAR_0->streams[opkt.stream_index]->nb_frames++;



        av_free_packet(&opkt);



        if (VAR_4 < 0)

            return VAR_4;

    }

fail:

    av_packet_unref(VAR_1);

    return VAR_4;

}

int FUNC_0(AVFormatContext *VAR_0, AVPacket *VAR_1)
{ int VAR_4, VAR_3 = 0; VAR_4 = check_packet(VAR_0, VAR_1); if (VAR_4 < 0)
goto fail; if (VAR_1) { AVStream *st = VAR_0->streams[VAR_1->stream_index]; if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO && VAR_1->size == 0) { VAR_4 = 0; goto fail; } av_dlog(VAR_0, "FUNC_0 size:%d dts:%" PRId64 " pts:%" PRId64 "\n",
VAR_1->size, VAR_1->dts, VAR_1->pts); if ((VAR_4 = compute_pkt_fields2(VAR_0, st, VAR_1)) < 0 && !(VAR_0->oformat->flags & AVFMT_NOTIMESTAMPS))
goto fail; if (VAR_1->dts == AV_NOPTS_VALUE && !(VAR_0->oformat->flags & AVFMT_NOTIMESTAMPS)) { VAR_4 = AVERROR(EINVAL); goto fail; } } else { av_dlog(VAR_0, "FUNC_0 FLUSH\n"); VAR_3 = 1; } for (;; ) { AVPacket opkt; int VAR_4 = interleave_packet(VAR_0, &opkt, VAR_1, VAR_3); if (VAR_1) { memset(VAR_1, 0, sizeof(*VAR_1)); av_init_packet(VAR_1); VAR_1 = NULL; } if (VAR_4 <= 0)
return VAR_4; VAR_4 = write_packet(VAR_0, &opkt); if (VAR_4 >= 0)
VAR_0->streams[opkt.stream_index]->nb_frames++; av_free_packet(&opkt); if (VAR_4 < 0)
return VAR_4; } fail:
av_packet_unref(VAR_1); return VAR_4; }