static int decoder_decode_frame(Decoder *d, void *fframe) {

    int got_frame = 0;

    AVFrame *frame = fframe;



    d->flushed = 0;



    do {

        int ret = -1;



        if (d->queue->abort_request)

            return -1;



        if (!d->packet_pending || d->queue->serial != d->pkt_serial) {

            AVPacket pkt;

            do {

                if (d->queue->nb_packets == 0)

                    SDL_CondSignal(d->empty_queue_cond);

                if (packet_queue_get(d->queue, &pkt, 1, &d->pkt_serial) < 0)

                    return -1;

                if (pkt.data == flush_pkt.data) {

                    avcodec_flush_buffers(d->avctx);

                    d->finished = 0;

                    d->flushed = 1;

                    d->next_pts = d->start_pts;

                    d->next_pts_tb = d->start_pts_tb;

                }

            } while (pkt.data == flush_pkt.data || d->queue->serial != d->pkt_serial);

            av_free_packet(&d->pkt);

            d->pkt_temp = d->pkt = pkt;

            d->packet_pending = 1;

        }



        switch (d->avctx->codec_type) {

            case AVMEDIA_TYPE_VIDEO:

                ret = avcodec_decode_video2(d->avctx, frame, &got_frame, &d->pkt_temp);

                if (got_frame) {

                    if (decoder_reorder_pts == -1) {

                        frame->pts = av_frame_get_best_effort_timestamp(frame);

                    } else if (decoder_reorder_pts) {

                        frame->pts = frame->pkt_pts;

                    } else {

                        frame->pts = frame->pkt_dts;

                    }

                }

                break;

            case AVMEDIA_TYPE_AUDIO:

                ret = avcodec_decode_audio4(d->avctx, frame, &got_frame, &d->pkt_temp);

                if (got_frame) {

                    AVRational tb = (AVRational){1, frame->sample_rate};

                    if (frame->pts != AV_NOPTS_VALUE)

                        frame->pts = av_rescale_q(frame->pts, d->avctx->time_base, tb);

                    else if (frame->pkt_pts != AV_NOPTS_VALUE)

                        frame->pts = av_rescale_q(frame->pkt_pts, av_codec_get_pkt_timebase(d->avctx), tb);

                    else if (d->next_pts != AV_NOPTS_VALUE)

                        frame->pts = av_rescale_q(d->next_pts, d->next_pts_tb, tb);

                    if (frame->pts != AV_NOPTS_VALUE) {

                        d->next_pts = frame->pts + frame->nb_samples;

                        d->next_pts_tb = tb;

                    }

                }

                break;

            case AVMEDIA_TYPE_SUBTITLE:

                ret = avcodec_decode_subtitle2(d->avctx, fframe, &got_frame, &d->pkt_temp);

                break;

        }



        if (ret < 0) {

            d->packet_pending = 0;

        } else {

            d->pkt_temp.dts =

            d->pkt_temp.pts = AV_NOPTS_VALUE;

            if (d->pkt_temp.data) {

                if (d->avctx->codec_type != AVMEDIA_TYPE_AUDIO)

                    ret = d->pkt_temp.size;

                d->pkt_temp.data += ret;

                d->pkt_temp.size -= ret;

                if (d->pkt_temp.size <= 0)

                    d->packet_pending = 0;

            } else {

                if (!got_frame) {

                    d->packet_pending = 0;

                    d->finished = d->pkt_serial;

                }

            }

        }

    } while (!got_frame && !d->finished);



    return got_frame;

}

static int decoder_decode_frame(Decoder *d, void *fframe) {

    int got_frame = 0;

    AVFrame *frame = fframe;



    d->flushed = 0;



    do {

        int ret = -1;



        if (d->queue->abort_request)

            return -1;



        if (!d->packet_pending || d->queue->serial != d->pkt_serial) {

            AVPacket pkt;

            do {

                if (d->queue->nb_packets == 0)

                    SDL_CondSignal(d->empty_queue_cond);

                if (packet_queue_get(d->queue, &pkt, 1, &d->pkt_serial) < 0)

                    return -1;

                if (pkt.data == flush_pkt.data) {

                    avcodec_flush_buffers(d->avctx);

                    d->finished = 0;

                    d->flushed = 1;

                    d->next_pts = d->start_pts;

                    d->next_pts_tb = d->start_pts_tb;

                }

            } while (pkt.data == flush_pkt.data || d->queue->serial != d->pkt_serial);

            av_free_packet(&d->pkt);

            d->pkt_temp = d->pkt = pkt;

            d->packet_pending = 1;

        }



        switch (d->avctx->codec_type) {

            case AVMEDIA_TYPE_VIDEO:

                ret = avcodec_decode_video2(d->avctx, frame, &got_frame, &d->pkt_temp);

                if (got_frame) {

                    if (decoder_reorder_pts == -1) {

                        frame->pts = av_frame_get_best_effort_timestamp(frame);

                    } else if (decoder_reorder_pts) {

                        frame->pts = frame->pkt_pts;

                    } else {

                        frame->pts = frame->pkt_dts;

                    }

                }

                break;

            case AVMEDIA_TYPE_AUDIO:

                ret = avcodec_decode_audio4(d->avctx, frame, &got_frame, &d->pkt_temp);

                if (got_frame) {

                    AVRational tb = (AVRational){1, frame->sample_rate};

                    if (frame->pts != AV_NOPTS_VALUE)

                        frame->pts = av_rescale_q(frame->pts, d->avctx->time_base, tb);

                    else if (frame->pkt_pts != AV_NOPTS_VALUE)

                        frame->pts = av_rescale_q(frame->pkt_pts, av_codec_get_pkt_timebase(d->avctx), tb);

                    else if (d->next_pts != AV_NOPTS_VALUE)

                        frame->pts = av_rescale_q(d->next_pts, d->next_pts_tb, tb);

                    if (frame->pts != AV_NOPTS_VALUE) {

                        d->next_pts = frame->pts + frame->nb_samples;

                        d->next_pts_tb = tb;

                    }

                }

                break;

            case AVMEDIA_TYPE_SUBTITLE:

                ret = avcodec_decode_subtitle2(d->avctx, fframe, &got_frame, &d->pkt_temp);

                break;

        }



        if (ret < 0) {

            d->packet_pending = 0;

        } else {

            d->pkt_temp.dts =

            d->pkt_temp.pts = AV_NOPTS_VALUE;

            if (d->pkt_temp.data) {

                if (d->avctx->codec_type != AVMEDIA_TYPE_AUDIO)

                    ret = d->pkt_temp.size;

                d->pkt_temp.data += ret;

                d->pkt_temp.size -= ret;

                if (d->pkt_temp.size <= 0)

                    d->packet_pending = 0;

            } else {

                if (!got_frame) {

                    d->packet_pending = 0;

                    d->finished = d->pkt_serial;

                }

            }

        }

    } while (!got_frame && !d->finished);



    return got_frame;

}

static int decoder_decode_frame(Decoder *d, void *fframe) {     AVFrame *frame = fframe;                 ret = avcodec_decode_subtitle2(d->avctx, fframe, &got_frame, &d->pkt_temp);
static int FUNC_0(Decoder *VAR_0, void *VAR_1) {

    int VAR_2 = 0;

    AVFrame *frame = VAR_1;



    VAR_0->flushed = 0;



    do {

        int VAR_3 = -1;



        if (VAR_0->queue->abort_request)

            return -1;



        if (!VAR_0->packet_pending || VAR_0->queue->serial != VAR_0->pkt_serial) {

            AVPacket pkt;

            do {

                if (VAR_0->queue->nb_packets == 0)

                    SDL_CondSignal(VAR_0->empty_queue_cond);

                if (packet_queue_get(VAR_0->queue, &pkt, 1, &VAR_0->pkt_serial) < 0)

                    return -1;

                if (pkt.data == flush_pkt.data) {

                    avcodec_flush_buffers(VAR_0->avctx);

                    VAR_0->finished = 0;

                    VAR_0->flushed = 1;

                    VAR_0->next_pts = VAR_0->start_pts;

                    VAR_0->next_pts_tb = VAR_0->start_pts_tb;

                }

            } while (pkt.data == flush_pkt.data || VAR_0->queue->serial != VAR_0->pkt_serial);

            av_free_packet(&VAR_0->pkt);

            VAR_0->pkt_temp = VAR_0->pkt = pkt;

            VAR_0->packet_pending = 1;

        }



        switch (VAR_0->avctx->codec_type) {

            case AVMEDIA_TYPE_VIDEO:

                VAR_3 = avcodec_decode_video2(VAR_0->avctx, frame, &VAR_2, &VAR_0->pkt_temp);

                if (VAR_2) {

                    if (decoder_reorder_pts == -1) {

                        frame->pts = av_frame_get_best_effort_timestamp(frame);

                    } else if (decoder_reorder_pts) {

                        frame->pts = frame->pkt_pts;

                    } else {

                        frame->pts = frame->pkt_dts;

                    }

                }

                break;

            case AVMEDIA_TYPE_AUDIO:

                VAR_3 = avcodec_decode_audio4(VAR_0->avctx, frame, &VAR_2, &VAR_0->pkt_temp);

                if (VAR_2) {

                    AVRational tb = (AVRational){1, frame->sample_rate};

                    if (frame->pts != AV_NOPTS_VALUE)

                        frame->pts = av_rescale_q(frame->pts, VAR_0->avctx->time_base, tb);

                    else if (frame->pkt_pts != AV_NOPTS_VALUE)

                        frame->pts = av_rescale_q(frame->pkt_pts, av_codec_get_pkt_timebase(VAR_0->avctx), tb);

                    else if (VAR_0->next_pts != AV_NOPTS_VALUE)

                        frame->pts = av_rescale_q(VAR_0->next_pts, VAR_0->next_pts_tb, tb);

                    if (frame->pts != AV_NOPTS_VALUE) {

                        VAR_0->next_pts = frame->pts + frame->nb_samples;

                        VAR_0->next_pts_tb = tb;

                    }

                }

                break;

            case AVMEDIA_TYPE_SUBTITLE:

                VAR_3 = avcodec_decode_subtitle2(VAR_0->avctx, VAR_1, &VAR_2, &VAR_0->pkt_temp);

                break;

        }



        if (VAR_3 < 0) {

            VAR_0->packet_pending = 0;

        } else {

            VAR_0->pkt_temp.dts =

            VAR_0->pkt_temp.pts = AV_NOPTS_VALUE;

            if (VAR_0->pkt_temp.data) {

                if (VAR_0->avctx->codec_type != AVMEDIA_TYPE_AUDIO)

                    VAR_3 = VAR_0->pkt_temp.size;

                VAR_0->pkt_temp.data += VAR_3;

                VAR_0->pkt_temp.size -= VAR_3;

                if (VAR_0->pkt_temp.size <= 0)

                    VAR_0->packet_pending = 0;

            } else {

                if (!VAR_2) {

                    VAR_0->packet_pending = 0;

                    VAR_0->finished = VAR_0->pkt_serial;

                }

            }

        }

    } while (!VAR_2 && !VAR_0->finished);



    return VAR_2;

}

static int FUNC_0(Decoder *VAR_0, void *VAR_1) { int VAR_2 = 0; AVFrame *frame = VAR_1; VAR_0->flushed = 0; do { int VAR_3 = -1; if (VAR_0->queue->abort_request)
return -1; if (!VAR_0->packet_pending || VAR_0->queue->serial != VAR_0->pkt_serial) { AVPacket pkt; do { if (VAR_0->queue->nb_packets == 0)
SDL_CondSignal(VAR_0->empty_queue_cond); if (packet_queue_get(VAR_0->queue, &pkt, 1, &VAR_0->pkt_serial) < 0)
return -1; if (pkt.data == flush_pkt.data) { avcodec_flush_buffers(VAR_0->avctx); VAR_0->finished = 0; VAR_0->flushed = 1; VAR_0->next_pts = VAR_0->start_pts; VAR_0->next_pts_tb = VAR_0->start_pts_tb; } } while (pkt.data == flush_pkt.data || VAR_0->queue->serial != VAR_0->pkt_serial); av_free_packet(&VAR_0->pkt); VAR_0->pkt_temp = VAR_0->pkt = pkt; VAR_0->packet_pending = 1; } switch (VAR_0->avctx->codec_type) { case AVMEDIA_TYPE_VIDEO:
VAR_3 = avcodec_decode_video2(VAR_0->avctx, frame, &VAR_2, &VAR_0->pkt_temp); if (VAR_2) { if (decoder_reorder_pts == -1) { frame->pts = av_frame_get_best_effort_timestamp(frame); } else if (decoder_reorder_pts) { frame->pts = frame->pkt_pts; } else { frame->pts = frame->pkt_dts; } } break; case AVMEDIA_TYPE_AUDIO:
VAR_3 = avcodec_decode_audio4(VAR_0->avctx, frame, &VAR_2, &VAR_0->pkt_temp); if (VAR_2) { AVRational tb = (AVRational){1, frame->sample_rate}; if (frame->pts != AV_NOPTS_VALUE)
frame->pts = av_rescale_q(frame->pts, VAR_0->avctx->time_base, tb); else if (frame->pkt_pts != AV_NOPTS_VALUE)
frame->pts = av_rescale_q(frame->pkt_pts, av_codec_get_pkt_timebase(VAR_0->avctx), tb); else if (VAR_0->next_pts != AV_NOPTS_VALUE)
frame->pts = av_rescale_q(VAR_0->next_pts, VAR_0->next_pts_tb, tb); if (frame->pts != AV_NOPTS_VALUE) { VAR_0->next_pts = frame->pts + frame->nb_samples; VAR_0->next_pts_tb = tb; } } break; case AVMEDIA_TYPE_SUBTITLE:
VAR_3 = avcodec_decode_subtitle2(VAR_0->avctx, VAR_1, &VAR_2, &VAR_0->pkt_temp); break; } if (VAR_3 < 0) { VAR_0->packet_pending = 0; } else { VAR_0->pkt_temp.dts =
VAR_0->pkt_temp.pts = AV_NOPTS_VALUE; if (VAR_0->pkt_temp.data) { if (VAR_0->avctx->codec_type != AVMEDIA_TYPE_AUDIO)
VAR_3 = VAR_0->pkt_temp.size; VAR_0->pkt_temp.data += VAR_3; VAR_0->pkt_temp.size -= VAR_3; if (VAR_0->pkt_temp.size <= 0)
VAR_0->packet_pending = 0; } else { if (!VAR_2) { VAR_0->packet_pending = 0; VAR_0->finished = VAR_0->pkt_serial; } } } } while (!VAR_2 && !VAR_0->finished); return VAR_2; }