static int movie_push_frame(AVFilterContext *ctx, unsigned out_id)

{

    MovieContext *movie = ctx->priv;

    AVPacket *pkt = &movie->pkt;

    enum AVMediaType frame_type;

    MovieStream *st;

    int ret, got_frame = 0, pkt_out_id;

    AVFilterLink *outlink;

    AVFrame *frame;



    if (!pkt->size) {

        if (movie->eof) {

            if (movie->st[out_id].done) {

                if (movie->loop_count != 1) {

                    ret = rewind_file(ctx);

                    if (ret < 0)

                        return ret;

                    movie->loop_count -= movie->loop_count > 1;

                    av_log(ctx, AV_LOG_VERBOSE, "Stream finished, looping.\n");

                    return 0; /* retry */

                }

                return AVERROR_EOF;

            }

            pkt->stream_index = movie->st[out_id].st->index;

            /* packet is already ready for flushing */

        } else {

            ret = av_read_frame(movie->format_ctx, &movie->pkt0);

            if (ret < 0) {

                av_init_packet(&movie->pkt0); /* ready for flushing */

                *pkt = movie->pkt0;

                if (ret == AVERROR_EOF) {

                    movie->eof = 1;

                    return 0; /* start flushing */

                }

                return ret;

            }

            *pkt = movie->pkt0;

        }

    }



    pkt_out_id = pkt->stream_index > movie->max_stream_index ? -1 :

                 movie->out_index[pkt->stream_index];

    if (pkt_out_id < 0) {

        av_free_packet(&movie->pkt0);

        pkt->size = 0; /* ready for next run */

        pkt->data = NULL;

        return 0;

    }

    st = &movie->st[pkt_out_id];

    outlink = ctx->outputs[pkt_out_id];



    frame = av_frame_alloc();

    if (!frame)

        return AVERROR(ENOMEM);



    frame_type = st->st->codec->codec_type;

    switch (frame_type) {

    case AVMEDIA_TYPE_VIDEO:

        ret = avcodec_decode_video2(st->st->codec, frame, &got_frame, pkt);

        break;

    case AVMEDIA_TYPE_AUDIO:

        ret = avcodec_decode_audio4(st->st->codec, frame, &got_frame, pkt);

        break;

    default:

        ret = AVERROR(ENOSYS);

        break;

    }

    if (ret < 0) {

        av_log(ctx, AV_LOG_WARNING, "Decode error: %s\n", av_err2str(ret));

        av_frame_free(&frame);

        av_free_packet(&movie->pkt0);

        movie->pkt.size = 0;

        movie->pkt.data = NULL;

        return 0;

    }

    if (!ret || st->st->codec->codec_type == AVMEDIA_TYPE_VIDEO)

        ret = pkt->size;



    pkt->data += ret;

    pkt->size -= ret;

    if (pkt->size <= 0) {

        av_free_packet(&movie->pkt0);

        pkt->size = 0; /* ready for next run */

        pkt->data = NULL;

    }

    if (!got_frame) {

        if (!ret)

            st->done = 1;

        av_frame_free(&frame);

        return 0;

    }



    frame->pts = av_frame_get_best_effort_timestamp(frame);

    av_dlog(ctx, "movie_push_frame(): file:'%s' %s\n", movie->file_name,

            describe_frame_to_str((char[1024]){0}, 1024, frame, frame_type, outlink));



    if (st->st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {

        if (frame->format != outlink->format) {

            av_log(ctx, AV_LOG_ERROR, "Format changed %s -> %s, discarding frame\n",

                av_get_pix_fmt_name(outlink->format),

                av_get_pix_fmt_name(frame->format)

                );

            av_frame_free(&frame);

            return 0;

        }

    }

    ret = ff_filter_frame(outlink, frame);



    if (ret < 0)

        return ret;

    return pkt_out_id == out_id;

}

static int movie_push_frame(AVFilterContext *ctx, unsigned out_id)

{

    MovieContext *movie = ctx->priv;

    AVPacket *pkt = &movie->pkt;

    enum AVMediaType frame_type;

    MovieStream *st;

    int ret, got_frame = 0, pkt_out_id;

    AVFilterLink *outlink;

    AVFrame *frame;



    if (!pkt->size) {

        if (movie->eof) {

            if (movie->st[out_id].done) {

                if (movie->loop_count != 1) {

                    ret = rewind_file(ctx);

                    if (ret < 0)

                        return ret;

                    movie->loop_count -= movie->loop_count > 1;

                    av_log(ctx, AV_LOG_VERBOSE, "Stream finished, looping.\n");

                    return 0; 

                }

                return AVERROR_EOF;

            }

            pkt->stream_index = movie->st[out_id].st->index;

            

        } else {

            ret = av_read_frame(movie->format_ctx, &movie->pkt0);

            if (ret < 0) {

                av_init_packet(&movie->pkt0); 

                *pkt = movie->pkt0;

                if (ret == AVERROR_EOF) {

                    movie->eof = 1;

                    return 0; 

                }

                return ret;

            }

            *pkt = movie->pkt0;

        }

    }



    pkt_out_id = pkt->stream_index > movie->max_stream_index ? -1 :

                 movie->out_index[pkt->stream_index];

    if (pkt_out_id < 0) {

        av_free_packet(&movie->pkt0);

        pkt->size = 0; 

        pkt->data = NULL;

        return 0;

    }

    st = &movie->st[pkt_out_id];

    outlink = ctx->outputs[pkt_out_id];



    frame = av_frame_alloc();

    if (!frame)

        return AVERROR(ENOMEM);



    frame_type = st->st->codec->codec_type;

    switch (frame_type) {

    case AVMEDIA_TYPE_VIDEO:

        ret = avcodec_decode_video2(st->st->codec, frame, &got_frame, pkt);

        break;

    case AVMEDIA_TYPE_AUDIO:

        ret = avcodec_decode_audio4(st->st->codec, frame, &got_frame, pkt);

        break;

    default:

        ret = AVERROR(ENOSYS);

        break;

    }

    if (ret < 0) {

        av_log(ctx, AV_LOG_WARNING, "Decode error: %s\n", av_err2str(ret));

        av_frame_free(&frame);

        av_free_packet(&movie->pkt0);

        movie->pkt.size = 0;

        movie->pkt.data = NULL;

        return 0;

    }

    if (!ret || st->st->codec->codec_type == AVMEDIA_TYPE_VIDEO)

        ret = pkt->size;



    pkt->data += ret;

    pkt->size -= ret;

    if (pkt->size <= 0) {

        av_free_packet(&movie->pkt0);

        pkt->size = 0; 

        pkt->data = NULL;

    }

    if (!got_frame) {

        if (!ret)

            st->done = 1;

        av_frame_free(&frame);

        return 0;

    }



    frame->pts = av_frame_get_best_effort_timestamp(frame);

    av_dlog(ctx, "movie_push_frame(): file:'%s' %s\n", movie->file_name,

            describe_frame_to_str((char[1024]){0}, 1024, frame, frame_type, outlink));



    if (st->st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {

        if (frame->format != outlink->format) {

            av_log(ctx, AV_LOG_ERROR, "Format changed %s -> %s, discarding frame\n",

                av_get_pix_fmt_name(outlink->format),

                av_get_pix_fmt_name(frame->format)

                );

            av_frame_free(&frame);

            return 0;

        }

    }

    ret = ff_filter_frame(outlink, frame);



    if (ret < 0)

        return ret;

    return pkt_out_id == out_id;

}

static int FUNC_0(AVFilterContext *VAR_0, unsigned VAR_1)

{

    MovieContext *movie = VAR_0->priv;

    AVPacket *pkt = &movie->pkt;

    enum AVMediaType VAR_2;

    MovieStream *st;

    int VAR_3, VAR_4 = 0, VAR_5;

    AVFilterLink *outlink;

    AVFrame *frame;



    if (!pkt->size) {

        if (movie->eof) {

            if (movie->st[VAR_1].done) {

                if (movie->loop_count != 1) {

                    VAR_3 = rewind_file(VAR_0);

                    if (VAR_3 < 0)

                        return VAR_3;

                    movie->loop_count -= movie->loop_count > 1;

                    av_log(VAR_0, AV_LOG_VERBOSE, "Stream finished, looping.\n");

                    return 0; 

                }

                return AVERROR_EOF;

            }

            pkt->stream_index = movie->st[VAR_1].st->index;

            

        } else {

            VAR_3 = av_read_frame(movie->format_ctx, &movie->pkt0);

            if (VAR_3 < 0) {

                av_init_packet(&movie->pkt0); 

                *pkt = movie->pkt0;

                if (VAR_3 == AVERROR_EOF) {

                    movie->eof = 1;

                    return 0; 

                }

                return VAR_3;

            }

            *pkt = movie->pkt0;

        }

    }



    VAR_5 = pkt->stream_index > movie->max_stream_index ? -1 :

                 movie->out_index[pkt->stream_index];

    if (VAR_5 < 0) {

        av_free_packet(&movie->pkt0);

        pkt->size = 0; 

        pkt->data = NULL;

        return 0;

    }

    st = &movie->st[VAR_5];

    outlink = VAR_0->outputs[VAR_5];



    frame = av_frame_alloc();

    if (!frame)

        return AVERROR(ENOMEM);



    VAR_2 = st->st->codec->codec_type;

    switch (VAR_2) {

    case AVMEDIA_TYPE_VIDEO:

        VAR_3 = avcodec_decode_video2(st->st->codec, frame, &VAR_4, pkt);

        break;

    case AVMEDIA_TYPE_AUDIO:

        VAR_3 = avcodec_decode_audio4(st->st->codec, frame, &VAR_4, pkt);

        break;

    default:

        VAR_3 = AVERROR(ENOSYS);

        break;

    }

    if (VAR_3 < 0) {

        av_log(VAR_0, AV_LOG_WARNING, "Decode error: %s\n", av_err2str(VAR_3));

        av_frame_free(&frame);

        av_free_packet(&movie->pkt0);

        movie->pkt.size = 0;

        movie->pkt.data = NULL;

        return 0;

    }

    if (!VAR_3 || st->st->codec->codec_type == AVMEDIA_TYPE_VIDEO)

        VAR_3 = pkt->size;



    pkt->data += VAR_3;

    pkt->size -= VAR_3;

    if (pkt->size <= 0) {

        av_free_packet(&movie->pkt0);

        pkt->size = 0; 

        pkt->data = NULL;

    }

    if (!VAR_4) {

        if (!VAR_3)

            st->done = 1;

        av_frame_free(&frame);

        return 0;

    }



    frame->pts = av_frame_get_best_effort_timestamp(frame);

    av_dlog(VAR_0, "FUNC_0(): file:'%s' %s\n", movie->file_name,

            describe_frame_to_str((char[1024]){0}, 1024, frame, VAR_2, outlink));



    if (st->st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {

        if (frame->format != outlink->format) {

            av_log(VAR_0, AV_LOG_ERROR, "Format changed %s -> %s, discarding frame\n",

                av_get_pix_fmt_name(outlink->format),

                av_get_pix_fmt_name(frame->format)

                );

            av_frame_free(&frame);

            return 0;

        }

    }

    VAR_3 = ff_filter_frame(outlink, frame);



    if (VAR_3 < 0)

        return VAR_3;

    return VAR_5 == VAR_1;

}

static int FUNC_0(AVFilterContext *VAR_0, unsigned VAR_1)
{ MovieContext *movie = VAR_0->priv; AVPacket *pkt = &movie->pkt; enum AVMediaType VAR_2; MovieStream *st; int VAR_3, VAR_4 = 0, VAR_5; AVFilterLink *outlink; AVFrame *frame; if (!pkt->size) { if (movie->eof) { if (movie->st[VAR_1].done) { if (movie->loop_count != 1) { VAR_3 = rewind_file(VAR_0); if (VAR_3 < 0)
return VAR_3; movie->loop_count -= movie->loop_count > 1; av_log(VAR_0, AV_LOG_VERBOSE, "Stream finished, looping.\n"); return 0; } return AVERROR_EOF; } pkt->stream_index = movie->st[VAR_1].st->index; } else { VAR_3 = av_read_frame(movie->format_ctx, &movie->pkt0); if (VAR_3 < 0) { av_init_packet(&movie->pkt0); *pkt = movie->pkt0; if (VAR_3 == AVERROR_EOF) { movie->eof = 1; return 0; } return VAR_3; } *pkt = movie->pkt0; } } VAR_5 = pkt->stream_index > movie->max_stream_index ? -1 :
movie->out_index[pkt->stream_index]; if (VAR_5 < 0) { av_free_packet(&movie->pkt0); pkt->size = 0; pkt->data = NULL; return 0; } st = &movie->st[VAR_5]; outlink = VAR_0->outputs[VAR_5]; frame = av_frame_alloc(); if (!frame)
return AVERROR(ENOMEM); VAR_2 = st->st->codec->codec_type; switch (VAR_2) { case AVMEDIA_TYPE_VIDEO:
VAR_3 = avcodec_decode_video2(st->st->codec, frame, &VAR_4, pkt); break; case AVMEDIA_TYPE_AUDIO:
VAR_3 = avcodec_decode_audio4(st->st->codec, frame, &VAR_4, pkt); break; default:
VAR_3 = AVERROR(ENOSYS); break; } if (VAR_3 < 0) { av_log(VAR_0, AV_LOG_WARNING, "Decode error: %s\n", av_err2str(VAR_3)); av_frame_free(&frame); av_free_packet(&movie->pkt0); movie->pkt.size = 0; movie->pkt.data = NULL; return 0; } if (!VAR_3 || st->st->codec->codec_type == AVMEDIA_TYPE_VIDEO)
VAR_3 = pkt->size; pkt->data += VAR_3; pkt->size -= VAR_3; if (pkt->size <= 0) { av_free_packet(&movie->pkt0); pkt->size = 0; pkt->data = NULL; } if (!VAR_4) { if (!VAR_3)
st->done = 1; av_frame_free(&frame); return 0; } frame->pts = av_frame_get_best_effort_timestamp(frame); av_dlog(VAR_0, "FUNC_0(): file:'%s' %s\n", movie->file_name,
describe_frame_to_str((char[1024]){0}, 1024, frame, VAR_2, outlink)); if (st->st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { if (frame->format != outlink->format) { av_log(VAR_0, AV_LOG_ERROR, "Format changed %s -> %s, discarding frame\n",
av_get_pix_fmt_name(outlink->format),
av_get_pix_fmt_name(frame->format)
); av_frame_free(&frame); return 0; } } VAR_3 = ff_filter_frame(outlink, frame); if (VAR_3 < 0)
return VAR_3; return VAR_5 == VAR_1; }