int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples)

{

    int i, nb_samples1;

    short *bufin[2];

    short *bufout[2];

    short *buftmp2[2], *buftmp3[2];

    short *output_bak = NULL;

    int lenout;



    if (s->input_channels == s->output_channels && s->ratio == 1.0 && 0) {

        /* nothing to do */

        memcpy(output, input, nb_samples * s->input_channels * sizeof(short));

        return nb_samples;

    }



    if (s->sample_fmt[0] != SAMPLE_FMT_S16) {

        int istride[1] = { s->sample_size[0] };

        int ostride[1] = { 2 };

        const void *ibuf[1] = { input };

        void       *obuf[1];

        unsigned input_size = nb_samples*s->input_channels*s->sample_size[0];



        if (!s->buffer_size[0] || s->buffer_size[0] < input_size) {

            av_free(s->buffer[0]);

            s->buffer_size[0] = input_size;

            s->buffer[0] = av_malloc(s->buffer_size[0]);

            if (!s->buffer[0]) {

                av_log(s, AV_LOG_ERROR, "Could not allocate buffer\n");

                return 0;

            }

        }



        obuf[0] = s->buffer[0];



        if (av_audio_convert(s->convert_ctx[0], obuf, ostride,

                             ibuf, istride, nb_samples*s->input_channels) < 0) {

            av_log(s, AV_LOG_ERROR, "Audio sample format conversion failed\n");

            return 0;

        }



        input  = s->buffer[0];

    }



    lenout= 4*nb_samples * s->ratio + 16;



    if (s->sample_fmt[1] != SAMPLE_FMT_S16) {

        output_bak = output;



        if (!s->buffer_size[1] || s->buffer_size[1] < lenout) {

            av_free(s->buffer[1]);

            s->buffer_size[1] = lenout;

            s->buffer[1] = av_malloc(s->buffer_size[1]);

            if (!s->buffer[1]) {

                av_log(s, AV_LOG_ERROR, "Could not allocate buffer\n");

                return 0;

            }

        }



        output = s->buffer[1];

    }



    /* XXX: move those malloc to resample init code */

    for(i=0; i<s->filter_channels; i++){

        bufin[i]= av_malloc( (nb_samples + s->temp_len) * sizeof(short) );

        memcpy(bufin[i], s->temp[i], s->temp_len * sizeof(short));

        buftmp2[i] = bufin[i] + s->temp_len;

    }



    /* make some zoom to avoid round pb */

    bufout[0]= av_malloc( lenout * sizeof(short) );

    bufout[1]= av_malloc( lenout * sizeof(short) );



    if (s->input_channels == 2 &&

        s->output_channels == 1) {

        buftmp3[0] = output;

        stereo_to_mono(buftmp2[0], input, nb_samples);

    } else if (s->output_channels >= 2 && s->input_channels == 1) {

        buftmp3[0] = bufout[0];

        memcpy(buftmp2[0], input, nb_samples*sizeof(short));

    } else if (s->output_channels >= 2) {

        buftmp3[0] = bufout[0];

        buftmp3[1] = bufout[1];

        stereo_split(buftmp2[0], buftmp2[1], input, nb_samples);

    } else {

        buftmp3[0] = output;

        memcpy(buftmp2[0], input, nb_samples*sizeof(short));

    }



    nb_samples += s->temp_len;



    /* resample each channel */

    nb_samples1 = 0; /* avoid warning */

    for(i=0;i<s->filter_channels;i++) {

        int consumed;

        int is_last= i+1 == s->filter_channels;



        nb_samples1 = av_resample(s->resample_context, buftmp3[i], bufin[i], &consumed, nb_samples, lenout, is_last);

        s->temp_len= nb_samples - consumed;

        s->temp[i]= av_realloc(s->temp[i], s->temp_len*sizeof(short));

        memcpy(s->temp[i], bufin[i] + consumed, s->temp_len*sizeof(short));

    }



    if (s->output_channels == 2 && s->input_channels == 1) {

        mono_to_stereo(output, buftmp3[0], nb_samples1);

    } else if (s->output_channels == 2) {

        stereo_mux(output, buftmp3[0], buftmp3[1], nb_samples1);

    } else if (s->output_channels == 6) {

        ac3_5p1_mux(output, buftmp3[0], buftmp3[1], nb_samples1);

    }



    if (s->sample_fmt[1] != SAMPLE_FMT_S16) {

        int istride[1] = { 2 };

        int ostride[1] = { s->sample_size[1] };

        const void *ibuf[1] = { output };

        void       *obuf[1] = { output_bak };



        if (av_audio_convert(s->convert_ctx[1], obuf, ostride,

                             ibuf, istride, nb_samples1*s->output_channels) < 0) {

            av_log(s, AV_LOG_ERROR, "Audio sample format convertion failed\n");

            return 0;

        }

    }



    for(i=0; i<s->filter_channels; i++)

        av_free(bufin[i]);



    av_free(bufout[0]);

    av_free(bufout[1]);

    return nb_samples1;

}

int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples)

{

    int i, nb_samples1;

    short *bufin[2];

    short *bufout[2];

    short *buftmp2[2], *buftmp3[2];

    short *output_bak = NULL;

    int lenout;



    if (s->input_channels == s->output_channels && s->ratio == 1.0 && 0) {

        

        memcpy(output, input, nb_samples * s->input_channels * sizeof(short));

        return nb_samples;

    }



    if (s->sample_fmt[0] != SAMPLE_FMT_S16) {

        int istride[1] = { s->sample_size[0] };

        int ostride[1] = { 2 };

        const void *ibuf[1] = { input };

        void       *obuf[1];

        unsigned input_size = nb_samples*s->input_channels*s->sample_size[0];



        if (!s->buffer_size[0] || s->buffer_size[0] < input_size) {

            av_free(s->buffer[0]);

            s->buffer_size[0] = input_size;

            s->buffer[0] = av_malloc(s->buffer_size[0]);

            if (!s->buffer[0]) {

                av_log(s, AV_LOG_ERROR, "Could not allocate buffer\n");

                return 0;

            }

        }



        obuf[0] = s->buffer[0];



        if (av_audio_convert(s->convert_ctx[0], obuf, ostride,

                             ibuf, istride, nb_samples*s->input_channels) < 0) {

            av_log(s, AV_LOG_ERROR, "Audio sample format conversion failed\n");

            return 0;

        }



        input  = s->buffer[0];

    }



    lenout= 4*nb_samples * s->ratio + 16;



    if (s->sample_fmt[1] != SAMPLE_FMT_S16) {

        output_bak = output;



        if (!s->buffer_size[1] || s->buffer_size[1] < lenout) {

            av_free(s->buffer[1]);

            s->buffer_size[1] = lenout;

            s->buffer[1] = av_malloc(s->buffer_size[1]);

            if (!s->buffer[1]) {

                av_log(s, AV_LOG_ERROR, "Could not allocate buffer\n");

                return 0;

            }

        }



        output = s->buffer[1];

    }



    

    for(i=0; i<s->filter_channels; i++){

        bufin[i]= av_malloc( (nb_samples + s->temp_len) * sizeof(short) );

        memcpy(bufin[i], s->temp[i], s->temp_len * sizeof(short));

        buftmp2[i] = bufin[i] + s->temp_len;

    }



    

    bufout[0]= av_malloc( lenout * sizeof(short) );

    bufout[1]= av_malloc( lenout * sizeof(short) );



    if (s->input_channels == 2 &&

        s->output_channels == 1) {

        buftmp3[0] = output;

        stereo_to_mono(buftmp2[0], input, nb_samples);

    } else if (s->output_channels >= 2 && s->input_channels == 1) {

        buftmp3[0] = bufout[0];

        memcpy(buftmp2[0], input, nb_samples*sizeof(short));

    } else if (s->output_channels >= 2) {

        buftmp3[0] = bufout[0];

        buftmp3[1] = bufout[1];

        stereo_split(buftmp2[0], buftmp2[1], input, nb_samples);

    } else {

        buftmp3[0] = output;

        memcpy(buftmp2[0], input, nb_samples*sizeof(short));

    }



    nb_samples += s->temp_len;



    

    nb_samples1 = 0; 

    for(i=0;i<s->filter_channels;i++) {

        int consumed;

        int is_last= i+1 == s->filter_channels;



        nb_samples1 = av_resample(s->resample_context, buftmp3[i], bufin[i], &consumed, nb_samples, lenout, is_last);

        s->temp_len= nb_samples - consumed;

        s->temp[i]= av_realloc(s->temp[i], s->temp_len*sizeof(short));

        memcpy(s->temp[i], bufin[i] + consumed, s->temp_len*sizeof(short));

    }



    if (s->output_channels == 2 && s->input_channels == 1) {

        mono_to_stereo(output, buftmp3[0], nb_samples1);

    } else if (s->output_channels == 2) {

        stereo_mux(output, buftmp3[0], buftmp3[1], nb_samples1);

    } else if (s->output_channels == 6) {

        ac3_5p1_mux(output, buftmp3[0], buftmp3[1], nb_samples1);

    }



    if (s->sample_fmt[1] != SAMPLE_FMT_S16) {

        int istride[1] = { 2 };

        int ostride[1] = { s->sample_size[1] };

        const void *ibuf[1] = { output };

        void       *obuf[1] = { output_bak };



        if (av_audio_convert(s->convert_ctx[1], obuf, ostride,

                             ibuf, istride, nb_samples1*s->output_channels) < 0) {

            av_log(s, AV_LOG_ERROR, "Audio sample format convertion failed\n");

            return 0;

        }

    }



    for(i=0; i<s->filter_channels; i++)

        av_free(bufin[i]);



    av_free(bufout[0]);

    av_free(bufout[1]);

    return nb_samples1;

}

        unsigned input_size = nb_samples*s->input_channels*s->sample_size[0];
int FUNC_0(ReSampleContext *VAR_0, short *VAR_1, short *VAR_2, int VAR_3)

{

    int VAR_4, VAR_5;

    short *VAR_6[2];

    short *VAR_7[2];

    short *VAR_8[2], *VAR_9[2];

    short *VAR_10 = NULL;

    int VAR_11;



    if (VAR_0->input_channels == VAR_0->output_channels && VAR_0->ratio == 1.0 && 0) {

        

        memcpy(VAR_1, VAR_2, VAR_3 * VAR_0->input_channels * sizeof(short));

        return VAR_3;

    }



    if (VAR_0->sample_fmt[0] != SAMPLE_FMT_S16) {

        int VAR_17[1] = { VAR_0->sample_size[0] };

        int VAR_17[1] = { 2 };

        const void *VAR_17[1] = { VAR_2 };

        void       *VAR_17[1];

        unsigned VAR_16 = VAR_3*VAR_0->input_channels*VAR_0->sample_size[0];



        if (!VAR_0->buffer_size[0] || VAR_0->buffer_size[0] < VAR_16) {

            av_free(VAR_0->buffer[0]);

            VAR_0->buffer_size[0] = VAR_16;

            VAR_0->buffer[0] = av_malloc(VAR_0->buffer_size[0]);

            if (!VAR_0->buffer[0]) {

                av_log(VAR_0, AV_LOG_ERROR, "Could not allocate buffer\n");

                return 0;

            }

        }



        VAR_17[0] = VAR_0->buffer[0];



        if (av_audio_convert(VAR_0->convert_ctx[0], VAR_17, VAR_17,

                             VAR_17, VAR_17, VAR_3*VAR_0->input_channels) < 0) {

            av_log(VAR_0, AV_LOG_ERROR, "Audio sample format conversion failed\n");

            return 0;

        }



        VAR_2  = VAR_0->buffer[0];

    }



    VAR_11= 4*VAR_3 * VAR_0->ratio + 16;



    if (VAR_0->sample_fmt[1] != SAMPLE_FMT_S16) {

        VAR_10 = VAR_1;



        if (!VAR_0->buffer_size[1] || VAR_0->buffer_size[1] < VAR_11) {

            av_free(VAR_0->buffer[1]);

            VAR_0->buffer_size[1] = VAR_11;

            VAR_0->buffer[1] = av_malloc(VAR_0->buffer_size[1]);

            if (!VAR_0->buffer[1]) {

                av_log(VAR_0, AV_LOG_ERROR, "Could not allocate buffer\n");

                return 0;

            }

        }



        VAR_1 = VAR_0->buffer[1];

    }



    

    for(VAR_4=0; VAR_4<VAR_0->filter_channels; VAR_4++){

        VAR_6[VAR_4]= av_malloc( (VAR_3 + VAR_0->temp_len) * sizeof(short) );

        memcpy(VAR_6[VAR_4], VAR_0->temp[VAR_4], VAR_0->temp_len * sizeof(short));

        VAR_8[VAR_4] = VAR_6[VAR_4] + VAR_0->temp_len;

    }



    

    VAR_7[0]= av_malloc( VAR_11 * sizeof(short) );

    VAR_7[1]= av_malloc( VAR_11 * sizeof(short) );



    if (VAR_0->input_channels == 2 &&

        VAR_0->output_channels == 1) {

        VAR_9[0] = VAR_1;

        stereo_to_mono(VAR_8[0], VAR_2, VAR_3);

    } else if (VAR_0->output_channels >= 2 && VAR_0->input_channels == 1) {

        VAR_9[0] = VAR_7[0];

        memcpy(VAR_8[0], VAR_2, VAR_3*sizeof(short));

    } else if (VAR_0->output_channels >= 2) {

        VAR_9[0] = VAR_7[0];

        VAR_9[1] = VAR_7[1];

        stereo_split(VAR_8[0], VAR_8[1], VAR_2, VAR_3);

    } else {

        VAR_9[0] = VAR_1;

        memcpy(VAR_8[0], VAR_2, VAR_3*sizeof(short));

    }



    VAR_3 += VAR_0->temp_len;



    

    VAR_5 = 0; 

    for(VAR_4=0;VAR_4<VAR_0->filter_channels;VAR_4++) {

        int consumed;

        int is_last= VAR_4+1 == VAR_0->filter_channels;



        VAR_5 = av_resample(VAR_0->resample_context, VAR_9[VAR_4], VAR_6[VAR_4], &consumed, VAR_3, VAR_11, is_last);

        VAR_0->temp_len= VAR_3 - consumed;

        VAR_0->temp[VAR_4]= av_realloc(VAR_0->temp[VAR_4], VAR_0->temp_len*sizeof(short));

        memcpy(VAR_0->temp[VAR_4], VAR_6[VAR_4] + consumed, VAR_0->temp_len*sizeof(short));

    }



    if (VAR_0->output_channels == 2 && VAR_0->input_channels == 1) {

        mono_to_stereo(VAR_1, VAR_9[0], VAR_5);

    } else if (VAR_0->output_channels == 2) {

        stereo_mux(VAR_1, VAR_9[0], VAR_9[1], VAR_5);

    } else if (VAR_0->output_channels == 6) {

        ac3_5p1_mux(VAR_1, VAR_9[0], VAR_9[1], VAR_5);

    }



    if (VAR_0->sample_fmt[1] != SAMPLE_FMT_S16) {

        int VAR_17[1] = { 2 };

        int VAR_17[1] = { VAR_0->sample_size[1] };

        const void *VAR_17[1] = { VAR_1 };

        void       *VAR_17[1] = { VAR_10 };



        if (av_audio_convert(VAR_0->convert_ctx[1], VAR_17, VAR_17,

                             VAR_17, VAR_17, VAR_5*VAR_0->output_channels) < 0) {

            av_log(VAR_0, AV_LOG_ERROR, "Audio sample format convertion failed\n");

            return 0;

        }

    }



    for(VAR_4=0; VAR_4<VAR_0->filter_channels; VAR_4++)

        av_free(VAR_6[VAR_4]);



    av_free(VAR_7[0]);

    av_free(VAR_7[1]);

    return VAR_5;

}

int FUNC_0(ReSampleContext *VAR_0, short *VAR_1, short *VAR_2, int VAR_3)
{ int VAR_4, VAR_5; short *VAR_6[2]; short *VAR_7[2]; short *VAR_8[2], *VAR_9[2]; short *VAR_10 = NULL; int VAR_11; if (VAR_0->input_channels == VAR_0->output_channels && VAR_0->ratio == 1.0 && 0) { memcpy(VAR_1, VAR_2, VAR_3 * VAR_0->input_channels * sizeof(short)); return VAR_3; } if (VAR_0->sample_fmt[0] != SAMPLE_FMT_S16) { int VAR_17[1] = { VAR_0->sample_size[0] }; int VAR_17[1] = { 2 }; const void *VAR_17[1] = { VAR_2 }; void       *VAR_17[1]; unsigned VAR_16 = VAR_3*VAR_0->input_channels*VAR_0->sample_size[0]; if (!VAR_0->buffer_size[0] || VAR_0->buffer_size[0] < VAR_16) { av_free(VAR_0->buffer[0]); VAR_0->buffer_size[0] = VAR_16; VAR_0->buffer[0] = av_malloc(VAR_0->buffer_size[0]); if (!VAR_0->buffer[0]) { av_log(VAR_0, AV_LOG_ERROR, "Could not allocate buffer\n"); return 0; } } VAR_17[0] = VAR_0->buffer[0]; if (av_audio_convert(VAR_0->convert_ctx[0], VAR_17, VAR_17,
VAR_17, VAR_17, VAR_3*VAR_0->input_channels) < 0) { av_log(VAR_0, AV_LOG_ERROR, "Audio sample format conversion failed\n"); return 0; } VAR_2  = VAR_0->buffer[0]; } VAR_11= 4*VAR_3 * VAR_0->ratio + 16; if (VAR_0->sample_fmt[1] != SAMPLE_FMT_S16) { VAR_10 = VAR_1; if (!VAR_0->buffer_size[1] || VAR_0->buffer_size[1] < VAR_11) { av_free(VAR_0->buffer[1]); VAR_0->buffer_size[1] = VAR_11; VAR_0->buffer[1] = av_malloc(VAR_0->buffer_size[1]); if (!VAR_0->buffer[1]) { av_log(VAR_0, AV_LOG_ERROR, "Could not allocate buffer\n"); return 0; } } VAR_1 = VAR_0->buffer[1]; } for(VAR_4=0; VAR_4<VAR_0->filter_channels; VAR_4++){ VAR_6[VAR_4]= av_malloc( (VAR_3 + VAR_0->temp_len) * sizeof(short) ); memcpy(VAR_6[VAR_4], VAR_0->temp[VAR_4], VAR_0->temp_len * sizeof(short)); VAR_8[VAR_4] = VAR_6[VAR_4] + VAR_0->temp_len; } VAR_7[0]= av_malloc( VAR_11 * sizeof(short) ); VAR_7[1]= av_malloc( VAR_11 * sizeof(short) ); if (VAR_0->input_channels == 2 &&
VAR_0->output_channels == 1) { VAR_9[0] = VAR_1; stereo_to_mono(VAR_8[0], VAR_2, VAR_3); } else if (VAR_0->output_channels >= 2 && VAR_0->input_channels == 1) { VAR_9[0] = VAR_7[0]; memcpy(VAR_8[0], VAR_2, VAR_3*sizeof(short)); } else if (VAR_0->output_channels >= 2) { VAR_9[0] = VAR_7[0]; VAR_9[1] = VAR_7[1]; stereo_split(VAR_8[0], VAR_8[1], VAR_2, VAR_3); } else { VAR_9[0] = VAR_1; memcpy(VAR_8[0], VAR_2, VAR_3*sizeof(short)); } VAR_3 += VAR_0->temp_len; VAR_5 = 0; for(VAR_4=0;VAR_4<VAR_0->filter_channels;VAR_4++) { int consumed; int is_last= VAR_4+1 == VAR_0->filter_channels; VAR_5 = av_resample(VAR_0->resample_context, VAR_9[VAR_4], VAR_6[VAR_4], &consumed, VAR_3, VAR_11, is_last); VAR_0->temp_len= VAR_3 - consumed; VAR_0->temp[VAR_4]= av_realloc(VAR_0->temp[VAR_4], VAR_0->temp_len*sizeof(short)); memcpy(VAR_0->temp[VAR_4], VAR_6[VAR_4] + consumed, VAR_0->temp_len*sizeof(short)); } if (VAR_0->output_channels == 2 && VAR_0->input_channels == 1) { mono_to_stereo(VAR_1, VAR_9[0], VAR_5); } else if (VAR_0->output_channels == 2) { stereo_mux(VAR_1, VAR_9[0], VAR_9[1], VAR_5); } else if (VAR_0->output_channels == 6) { ac3_5p1_mux(VAR_1, VAR_9[0], VAR_9[1], VAR_5); } if (VAR_0->sample_fmt[1] != SAMPLE_FMT_S16) { int VAR_17[1] = { 2 }; int VAR_17[1] = { VAR_0->sample_size[1] }; const void *VAR_17[1] = { VAR_1 }; void       *VAR_17[1] = { VAR_10 }; if (av_audio_convert(VAR_0->convert_ctx[1], VAR_17, VAR_17,
VAR_17, VAR_17, VAR_5*VAR_0->output_channels) < 0) { av_log(VAR_0, AV_LOG_ERROR, "Audio sample format convertion failed\n"); return 0; } } for(VAR_4=0; VAR_4<VAR_0->filter_channels; VAR_4++) av_free(VAR_6[VAR_4]); av_free(VAR_7[0]); av_free(VAR_7[1]); return VAR_5; }