samples_size = wanted_size;
} else {  is->audio_diff_avg_count = 0; is->audio_diff_cum = 0;
static int synchronize_audio(VideoState *is, short *samples,                              int samples_size, double pts){    int n, delay;    double ref_clock;        n = 2 * is->audio_st->codec.channels;    if (is->av_sync_type == AV_SYNC_EXTERNAL_CLOCK)        ref_clock = is->external_clock;    else if (is->av_sync_type == AV_SYNC_VIDEO_MASTER && is->video_st)        ref_clock = is->video_clock;    else        ref_clock = is->audio_clock;        /* if not master, then we try to remove or add samples to correct the clock */    if (((is->av_sync_type == AV_SYNC_VIDEO_MASTER && is->video_st) ||         is->av_sync_type == AV_SYNC_EXTERNAL_CLOCK) && pts != 0) {        double diff;        int wanted_size, min_size, max_size, nb_samples;        delay = audio_write_get_buf_size(is);        diff = pts - (double)delay / (double)(n * is->audio_st->codec.sample_rate) - ref_clock;        wanted_size = (int)(diff * is->audio_st->codec.sample_rate) * n;        nb_samples = samples_size / n;        min_size = ((nb_samples * (100 - SAMPLE_CORRECTION_PERCENT_MAX)) / 100) * n;        max_size = ((nb_samples * (100 + SAMPLE_CORRECTION_PERCENT_MAX)) / 100) * n;        if (wanted_size < min_size)            wanted_size = min_size;        else if (wanted_size > max_size)            wanted_size = max_size;                /* do the correct */        /* XXX: do it better with sample interpolation */        if (wanted_size < samples_size) {            /* remove samples */            samples_size = wanted_size;        } else if (wanted_size > samples_size) {            uint8_t *samples_end, *q;            int nb;            /* add samples */            nb = (samples_size - wanted_size);            samples_end = (uint8_t *)samples + samples_size - n;            q = samples_end + n;            while (nb > 0) {                memcpy(q, samples_end, n);                q += n;                nb -= n;            }            samples_size = wanted_size;        }    }    /* update audio clock */    if (is->av_sync_type == AV_SYNC_AUDIO_MASTER && pts != 0) {        /* a pts is given: we update the audio clock precisely */        delay = audio_write_get_buf_size(is);        is->audio_clock = pts - (double)delay / (double)(n * is->audio_st->codec.sample_rate);    } else {        is->audio_clock += (double)samples_size / (double)(n * is->audio_st->codec.sample_rate);    }    return samples_size;}