static int get_video_frame(VideoState *is, AVFrame *frame, int64_t *pts, AVPacket *pkt)

{

    int got_picture, i;



    if (packet_queue_get(&is->videoq, pkt, 1) < 0)

        return -1;



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

        avcodec_flush_buffers(is->video_st->codec);



        SDL_LockMutex(is->pictq_mutex);

        // Make sure there are no long delay timers (ideally we should just flush the que but thats harder)

        for (i = 0; i < VIDEO_PICTURE_QUEUE_SIZE; i++) {

            is->pictq[i].skip = 1;

        }

        while (is->pictq_size && !is->videoq.abort_request) {

            SDL_CondWait(is->pictq_cond, is->pictq_mutex);

        }

        is->video_current_pos = -1;

        is->frame_last_pts = AV_NOPTS_VALUE;

        is->frame_last_duration = 0;

        is->frame_timer = (double)av_gettime() / 1000000.0;

        is->frame_last_dropped_pts = AV_NOPTS_VALUE;

        SDL_UnlockMutex(is->pictq_mutex);



        return 0;

    }



    avcodec_decode_video2(is->video_st->codec, frame, &got_picture, pkt);



    if (got_picture) {

        int ret = 1;



        if (decoder_reorder_pts == -1) {

            *pts = av_frame_get_best_effort_timestamp(frame);

        } else if (decoder_reorder_pts) {

            *pts = frame->pkt_pts;

        } else {

            *pts = frame->pkt_dts;

        }



        if (*pts == AV_NOPTS_VALUE) {

            *pts = 0;

        }



        if (((is->av_sync_type == AV_SYNC_AUDIO_MASTER && is->audio_st) || is->av_sync_type == AV_SYNC_EXTERNAL_CLOCK) &&

             (framedrop>0 || (framedrop && is->audio_st))) {

            SDL_LockMutex(is->pictq_mutex);

            if (is->frame_last_pts != AV_NOPTS_VALUE && *pts) {

                double clockdiff = get_video_clock(is) - get_master_clock(is);

                double dpts = av_q2d(is->video_st->time_base) * *pts;

                double ptsdiff = dpts - is->frame_last_pts;

                if (fabs(clockdiff) < AV_NOSYNC_THRESHOLD &&

                     ptsdiff > 0 && ptsdiff < AV_NOSYNC_THRESHOLD &&

                     clockdiff + ptsdiff - is->frame_last_filter_delay < 0) {

                    is->frame_last_dropped_pos = pkt->pos;

                    is->frame_last_dropped_pts = dpts;

                    is->frame_drops_early++;

                    ret = 0;

                }

            }

            SDL_UnlockMutex(is->pictq_mutex);

        }



        return ret;

    }

    return 0;

}

static int get_video_frame(VideoState *is, AVFrame *frame, int64_t *pts, AVPacket *pkt)

{

    int got_picture, i;



    if (packet_queue_get(&is->videoq, pkt, 1) < 0)

        return -1;



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

        avcodec_flush_buffers(is->video_st->codec);



        SDL_LockMutex(is->pictq_mutex);

        

        for (i = 0; i < VIDEO_PICTURE_QUEUE_SIZE; i++) {

            is->pictq[i].skip = 1;

        }

        while (is->pictq_size && !is->videoq.abort_request) {

            SDL_CondWait(is->pictq_cond, is->pictq_mutex);

        }

        is->video_current_pos = -1;

        is->frame_last_pts = AV_NOPTS_VALUE;

        is->frame_last_duration = 0;

        is->frame_timer = (double)av_gettime() / 1000000.0;

        is->frame_last_dropped_pts = AV_NOPTS_VALUE;

        SDL_UnlockMutex(is->pictq_mutex);



        return 0;

    }



    avcodec_decode_video2(is->video_st->codec, frame, &got_picture, pkt);



    if (got_picture) {

        int ret = 1;



        if (decoder_reorder_pts == -1) {

            *pts = av_frame_get_best_effort_timestamp(frame);

        } else if (decoder_reorder_pts) {

            *pts = frame->pkt_pts;

        } else {

            *pts = frame->pkt_dts;

        }



        if (*pts == AV_NOPTS_VALUE) {

            *pts = 0;

        }



        if (((is->av_sync_type == AV_SYNC_AUDIO_MASTER && is->audio_st) || is->av_sync_type == AV_SYNC_EXTERNAL_CLOCK) &&

             (framedrop>0 || (framedrop && is->audio_st))) {

            SDL_LockMutex(is->pictq_mutex);

            if (is->frame_last_pts != AV_NOPTS_VALUE && *pts) {

                double clockdiff = get_video_clock(is) - get_master_clock(is);

                double dpts = av_q2d(is->video_st->time_base) * *pts;

                double ptsdiff = dpts - is->frame_last_pts;

                if (fabs(clockdiff) < AV_NOSYNC_THRESHOLD &&

                     ptsdiff > 0 && ptsdiff < AV_NOSYNC_THRESHOLD &&

                     clockdiff + ptsdiff - is->frame_last_filter_delay < 0) {

                    is->frame_last_dropped_pos = pkt->pos;

                    is->frame_last_dropped_pts = dpts;

                    is->frame_drops_early++;

                    ret = 0;

                }

            }

            SDL_UnlockMutex(is->pictq_mutex);

        }



        return ret;

    }

    return 0;

}

static int FUNC_0(VideoState *VAR_0, AVFrame *VAR_1, int64_t *VAR_2, AVPacket *VAR_3)

{

    int VAR_4, VAR_5;



    if (packet_queue_get(&VAR_0->videoq, VAR_3, 1) < 0)

        return -1;



    if (VAR_3->data == flush_pkt.data) {

        avcodec_flush_buffers(VAR_0->video_st->codec);



        SDL_LockMutex(VAR_0->pictq_mutex);

        

        for (VAR_5 = 0; VAR_5 < VIDEO_PICTURE_QUEUE_SIZE; VAR_5++) {

            VAR_0->pictq[VAR_5].skip = 1;

        }

        while (VAR_0->pictq_size && !VAR_0->videoq.abort_request) {

            SDL_CondWait(VAR_0->pictq_cond, VAR_0->pictq_mutex);

        }

        VAR_0->video_current_pos = -1;

        VAR_0->frame_last_pts = AV_NOPTS_VALUE;

        VAR_0->frame_last_duration = 0;

        VAR_0->frame_timer = (double)av_gettime() / 1000000.0;

        VAR_0->frame_last_dropped_pts = AV_NOPTS_VALUE;

        SDL_UnlockMutex(VAR_0->pictq_mutex);



        return 0;

    }



    avcodec_decode_video2(VAR_0->video_st->codec, VAR_1, &VAR_4, VAR_3);



    if (VAR_4) {

        int VAR_6 = 1;



        if (decoder_reorder_pts == -1) {

            *VAR_2 = av_frame_get_best_effort_timestamp(VAR_1);

        } else if (decoder_reorder_pts) {

            *VAR_2 = VAR_1->pkt_pts;

        } else {

            *VAR_2 = VAR_1->pkt_dts;

        }



        if (*VAR_2 == AV_NOPTS_VALUE) {

            *VAR_2 = 0;

        }



        if (((VAR_0->av_sync_type == AV_SYNC_AUDIO_MASTER && VAR_0->audio_st) || VAR_0->av_sync_type == AV_SYNC_EXTERNAL_CLOCK) &&

             (framedrop>0 || (framedrop && VAR_0->audio_st))) {

            SDL_LockMutex(VAR_0->pictq_mutex);

            if (VAR_0->frame_last_pts != AV_NOPTS_VALUE && *VAR_2) {

                double VAR_7 = get_video_clock(VAR_0) - get_master_clock(VAR_0);

                double VAR_8 = av_q2d(VAR_0->video_st->time_base) * *VAR_2;

                double VAR_9 = VAR_8 - VAR_0->frame_last_pts;

                if (fabs(VAR_7) < AV_NOSYNC_THRESHOLD &&

                     VAR_9 > 0 && VAR_9 < AV_NOSYNC_THRESHOLD &&

                     VAR_7 + VAR_9 - VAR_0->frame_last_filter_delay < 0) {

                    VAR_0->frame_last_dropped_pos = VAR_3->pos;

                    VAR_0->frame_last_dropped_pts = VAR_8;

                    VAR_0->frame_drops_early++;

                    VAR_6 = 0;

                }

            }

            SDL_UnlockMutex(VAR_0->pictq_mutex);

        }



        return VAR_6;

    }

    return 0;

}

static int FUNC_0(VideoState *VAR_0, AVFrame *VAR_1, int64_t *VAR_2, AVPacket *VAR_3)
{ int VAR_4, VAR_5; if (packet_queue_get(&VAR_0->videoq, VAR_3, 1) < 0)
return -1; if (VAR_3->data == flush_pkt.data) { avcodec_flush_buffers(VAR_0->video_st->codec); SDL_LockMutex(VAR_0->pictq_mutex); for (VAR_5 = 0; VAR_5 < VIDEO_PICTURE_QUEUE_SIZE; VAR_5++) { VAR_0->pictq[VAR_5].skip = 1; } while (VAR_0->pictq_size && !VAR_0->videoq.abort_request) { SDL_CondWait(VAR_0->pictq_cond, VAR_0->pictq_mutex); } VAR_0->video_current_pos = -1; VAR_0->frame_last_pts = AV_NOPTS_VALUE; VAR_0->frame_last_duration = 0; VAR_0->frame_timer = (double)av_gettime() / 1000000.0; VAR_0->frame_last_dropped_pts = AV_NOPTS_VALUE; SDL_UnlockMutex(VAR_0->pictq_mutex); return 0; } avcodec_decode_video2(VAR_0->video_st->codec, VAR_1, &VAR_4, VAR_3); if (VAR_4) { int VAR_6 = 1; if (decoder_reorder_pts == -1) { *VAR_2 = av_frame_get_best_effort_timestamp(VAR_1); } else if (decoder_reorder_pts) { *VAR_2 = VAR_1->pkt_pts; } else { *VAR_2 = VAR_1->pkt_dts; } if (*VAR_2 == AV_NOPTS_VALUE) { *VAR_2 = 0; } if (((VAR_0->av_sync_type == AV_SYNC_AUDIO_MASTER && VAR_0->audio_st) || VAR_0->av_sync_type == AV_SYNC_EXTERNAL_CLOCK) &&
(framedrop>0 || (framedrop && VAR_0->audio_st))) { SDL_LockMutex(VAR_0->pictq_mutex); if (VAR_0->frame_last_pts != AV_NOPTS_VALUE && *VAR_2) { double VAR_7 = get_video_clock(VAR_0) - get_master_clock(VAR_0); double VAR_8 = av_q2d(VAR_0->video_st->time_base) * *VAR_2; double VAR_9 = VAR_8 - VAR_0->frame_last_pts; if (fabs(VAR_7) < AV_NOSYNC_THRESHOLD &&
VAR_9 > 0 && VAR_9 < AV_NOSYNC_THRESHOLD &&
VAR_7 + VAR_9 - VAR_0->frame_last_filter_delay < 0) { VAR_0->frame_last_dropped_pos = VAR_3->pos; VAR_0->frame_last_dropped_pts = VAR_8; VAR_0->frame_drops_early++; VAR_6 = 0; } } SDL_UnlockMutex(VAR_0->pictq_mutex); } return VAR_6; } return 0; }