static int synchronize_audio(VideoState *is, int nb_samples)

{

    int wanted_nb_samples = nb_samples;



    /* if not master, then we try to remove or add samples to correct the clock */

    if (get_master_sync_type(is) != AV_SYNC_AUDIO_MASTER) {

        double diff, avg_diff;

        int min_nb_samples, max_nb_samples;



        diff = get_audio_clock(is) - get_master_clock(is);



        if (fabs(diff) < AV_NOSYNC_THRESHOLD) {

            is->audio_diff_cum = diff + is->audio_diff_avg_coef * is->audio_diff_cum;

            if (is->audio_diff_avg_count < AUDIO_DIFF_AVG_NB) {

                /* not enough measures to have a correct estimate */

                is->audio_diff_avg_count++;

            } else {

                /* estimate the A-V difference */

                avg_diff = is->audio_diff_cum * (1.0 - is->audio_diff_avg_coef);



                if (fabs(avg_diff) >= is->audio_diff_threshold) {

                    wanted_nb_samples = nb_samples + (int)(diff * is->audio_src.freq);

                    min_nb_samples = ((nb_samples * (100 - SAMPLE_CORRECTION_PERCENT_MAX) / 100));

                    max_nb_samples = ((nb_samples * (100 + SAMPLE_CORRECTION_PERCENT_MAX) / 100));

                    wanted_nb_samples = FFMIN(FFMAX(wanted_nb_samples, min_nb_samples), max_nb_samples);

                }

                av_dlog(NULL, "diff=%f adiff=%f sample_diff=%d apts=%0.3f %f\n",

                        diff, avg_diff, wanted_nb_samples - nb_samples,

                        is->audio_clock, is->audio_diff_threshold);

            }

        } else {

            /* too big difference : may be initial PTS errors, so

               reset A-V filter */

            is->audio_diff_avg_count = 0;

            is->audio_diff_cum       = 0;

        }

    }



    return wanted_nb_samples;

}

static int synchronize_audio(VideoState *is, int nb_samples)

{

    int wanted_nb_samples = nb_samples;



    

    if (get_master_sync_type(is) != AV_SYNC_AUDIO_MASTER) {

        double diff, avg_diff;

        int min_nb_samples, max_nb_samples;



        diff = get_audio_clock(is) - get_master_clock(is);



        if (fabs(diff) < AV_NOSYNC_THRESHOLD) {

            is->audio_diff_cum = diff + is->audio_diff_avg_coef * is->audio_diff_cum;

            if (is->audio_diff_avg_count < AUDIO_DIFF_AVG_NB) {

                

                is->audio_diff_avg_count++;

            } else {

                

                avg_diff = is->audio_diff_cum * (1.0 - is->audio_diff_avg_coef);



                if (fabs(avg_diff) >= is->audio_diff_threshold) {

                    wanted_nb_samples = nb_samples + (int)(diff * is->audio_src.freq);

                    min_nb_samples = ((nb_samples * (100 - SAMPLE_CORRECTION_PERCENT_MAX) / 100));

                    max_nb_samples = ((nb_samples * (100 + SAMPLE_CORRECTION_PERCENT_MAX) / 100));

                    wanted_nb_samples = FFMIN(FFMAX(wanted_nb_samples, min_nb_samples), max_nb_samples);

                }

                av_dlog(NULL, "diff=%f adiff=%f sample_diff=%d apts=%0.3f %f\n",

                        diff, avg_diff, wanted_nb_samples - nb_samples,

                        is->audio_clock, is->audio_diff_threshold);

            }

        } else {

            



            is->audio_diff_avg_count = 0;

            is->audio_diff_cum       = 0;

        }

    }



    return wanted_nb_samples;

}

static int FUNC_0(VideoState *VAR_0, int VAR_1)

{

    int VAR_2 = VAR_1;



    

    if (get_master_sync_type(VAR_0) != AV_SYNC_AUDIO_MASTER) {

        double VAR_3, VAR_4;

        int VAR_5, VAR_6;



        VAR_3 = get_audio_clock(VAR_0) - get_master_clock(VAR_0);



        if (fabs(VAR_3) < AV_NOSYNC_THRESHOLD) {

            VAR_0->audio_diff_cum = VAR_3 + VAR_0->audio_diff_avg_coef * VAR_0->audio_diff_cum;

            if (VAR_0->audio_diff_avg_count < AUDIO_DIFF_AVG_NB) {

                

                VAR_0->audio_diff_avg_count++;

            } else {

                

                VAR_4 = VAR_0->audio_diff_cum * (1.0 - VAR_0->audio_diff_avg_coef);



                if (fabs(VAR_4) >= VAR_0->audio_diff_threshold) {

                    VAR_2 = VAR_1 + (int)(VAR_3 * VAR_0->audio_src.freq);

                    VAR_5 = ((VAR_1 * (100 - SAMPLE_CORRECTION_PERCENT_MAX) / 100));

                    VAR_6 = ((VAR_1 * (100 + SAMPLE_CORRECTION_PERCENT_MAX) / 100));

                    VAR_2 = FFMIN(FFMAX(VAR_2, VAR_5), VAR_6);

                }

                av_dlog(NULL, "VAR_3=%f adiff=%f sample_diff=%d apts=%0.3f %f\n",

                        VAR_3, VAR_4, VAR_2 - VAR_1,

                        VAR_0->audio_clock, VAR_0->audio_diff_threshold);

            }

        } else {

            



            VAR_0->audio_diff_avg_count = 0;

            VAR_0->audio_diff_cum       = 0;

        }

    }



    return VAR_2;

}

static int FUNC_0(VideoState *VAR_0, int VAR_1)
{ int VAR_2 = VAR_1; if (get_master_sync_type(VAR_0) != AV_SYNC_AUDIO_MASTER) { double VAR_3, VAR_4; int VAR_5, VAR_6; VAR_3 = get_audio_clock(VAR_0) - get_master_clock(VAR_0); if (fabs(VAR_3) < AV_NOSYNC_THRESHOLD) { VAR_0->audio_diff_cum = VAR_3 + VAR_0->audio_diff_avg_coef * VAR_0->audio_diff_cum; if (VAR_0->audio_diff_avg_count < AUDIO_DIFF_AVG_NB) { VAR_0->audio_diff_avg_count++; } else { VAR_4 = VAR_0->audio_diff_cum * (1.0 - VAR_0->audio_diff_avg_coef); if (fabs(VAR_4) >= VAR_0->audio_diff_threshold) { VAR_2 = VAR_1 + (int)(VAR_3 * VAR_0->audio_src.freq); VAR_5 = ((VAR_1 * (100 - SAMPLE_CORRECTION_PERCENT_MAX) / 100)); VAR_6 = ((VAR_1 * (100 + SAMPLE_CORRECTION_PERCENT_MAX) / 100)); VAR_2 = FFMIN(FFMAX(VAR_2, VAR_5), VAR_6); } av_dlog(NULL, "VAR_3=%f adiff=%f sample_diff=%d apts=%0.3f %f\n",
VAR_3, VAR_4, VAR_2 - VAR_1,
VAR_0->audio_clock, VAR_0->audio_diff_threshold); } } else { VAR_0->audio_diff_avg_count = 0; VAR_0->audio_diff_cum       = 0; } } return VAR_2; }