int ff_get_wav_header(AVFormatContext *s, AVIOContext *pb,

                      AVCodecContext *codec, int size, int big_endian)

{

    int id;

    uint64_t bitrate;



    if (size < 14) {

        avpriv_request_sample(codec, "wav header size < 14");

        return AVERROR_INVALIDDATA;

    }



    codec->codec_type  = AVMEDIA_TYPE_AUDIO;

    if (!big_endian) {

        id                 = avio_rl16(pb);

        codec->channels    = avio_rl16(pb);

        codec->sample_rate = avio_rl32(pb);

        bitrate            = avio_rl32(pb) * 8;

        codec->block_align = avio_rl16(pb);

    } else {

        id                 = avio_rb16(pb);

        codec->channels    = avio_rb16(pb);

        codec->sample_rate = avio_rb32(pb);

        bitrate            = avio_rb32(pb) * 8;

        codec->block_align = avio_rb16(pb);

    }

    if (size == 14) {  /* We're dealing with plain vanilla WAVEFORMAT */

        codec->bits_per_coded_sample = 8;

    } else {

        if (!big_endian) {

            codec->bits_per_coded_sample = avio_rl16(pb);

        } else {

            codec->bits_per_coded_sample = avio_rb16(pb);

        }

    }

    if (id == 0xFFFE) {

        codec->codec_tag = 0;

    } else {

        codec->codec_tag = id;

        codec->codec_id  = ff_wav_codec_get_id(id,

                                               codec->bits_per_coded_sample);

    }

    if (size >= 18) {  /* We're obviously dealing with WAVEFORMATEX */

        int cbSize = avio_rl16(pb); /* cbSize */

        if (big_endian) {

            avpriv_report_missing_feature(codec, "WAVEFORMATEX support for RIFX files\n");

            return AVERROR_PATCHWELCOME;

        }

        size  -= 18;

        cbSize = FFMIN(size, cbSize);

        if (cbSize >= 22 && id == 0xfffe) { /* WAVEFORMATEXTENSIBLE */

            parse_waveformatex(pb, codec);

            cbSize -= 22;

            size   -= 22;

        }

        if (cbSize > 0) {

            av_freep(&codec->extradata);

            if (ff_get_extradata(codec, pb, cbSize) < 0)

                return AVERROR(ENOMEM);

            size -= cbSize;

        }



        /* It is possible for the chunk to contain garbage at the end */

        if (size > 0)

            avio_skip(pb, size);

    }



    if (bitrate > INT_MAX) {

        if (s->error_recognition & AV_EF_EXPLODE) {

            av_log(s, AV_LOG_ERROR,

                   "The bitrate %"PRIu64" is too large.\n",

                    bitrate);

            return AVERROR_INVALIDDATA;

        } else {

            av_log(s, AV_LOG_WARNING,

                   "The bitrate %"PRIu64" is too large, resetting to 0.",

                   bitrate);

            codec->bit_rate = 0;

        }

    } else {

        codec->bit_rate = bitrate;

    }



    if (codec->sample_rate <= 0) {

        av_log(s, AV_LOG_ERROR,

               "Invalid sample rate: %d\n", codec->sample_rate);

        return AVERROR_INVALIDDATA;

    }

    if (codec->codec_id == AV_CODEC_ID_AAC_LATM) {

        /* Channels and sample_rate values are those prior to applying SBR

         * and/or PS. */

        codec->channels    = 0;

        codec->sample_rate = 0;

    }

    /* override bits_per_coded_sample for G.726 */

    if (codec->codec_id == AV_CODEC_ID_ADPCM_G726 && codec->sample_rate)

        codec->bits_per_coded_sample = codec->bit_rate / codec->sample_rate;



    return 0;

}

int ff_get_wav_header(AVFormatContext *s, AVIOContext *pb,

                      AVCodecContext *codec, int size, int big_endian)

{

    int id;

    uint64_t bitrate;



    if (size < 14) {

        avpriv_request_sample(codec, "wav header size < 14");

        return AVERROR_INVALIDDATA;

    }



    codec->codec_type  = AVMEDIA_TYPE_AUDIO;

    if (!big_endian) {

        id                 = avio_rl16(pb);

        codec->channels    = avio_rl16(pb);

        codec->sample_rate = avio_rl32(pb);

        bitrate            = avio_rl32(pb) * 8;

        codec->block_align = avio_rl16(pb);

    } else {

        id                 = avio_rb16(pb);

        codec->channels    = avio_rb16(pb);

        codec->sample_rate = avio_rb32(pb);

        bitrate            = avio_rb32(pb) * 8;

        codec->block_align = avio_rb16(pb);

    }

    if (size == 14) {  

        codec->bits_per_coded_sample = 8;

    } else {

        if (!big_endian) {

            codec->bits_per_coded_sample = avio_rl16(pb);

        } else {

            codec->bits_per_coded_sample = avio_rb16(pb);

        }

    }

    if (id == 0xFFFE) {

        codec->codec_tag = 0;

    } else {

        codec->codec_tag = id;

        codec->codec_id  = ff_wav_codec_get_id(id,

                                               codec->bits_per_coded_sample);

    }

    if (size >= 18) {  

        int cbSize = avio_rl16(pb); 

        if (big_endian) {

            avpriv_report_missing_feature(codec, "WAVEFORMATEX support for RIFX files\n");

            return AVERROR_PATCHWELCOME;

        }

        size  -= 18;

        cbSize = FFMIN(size, cbSize);

        if (cbSize >= 22 && id == 0xfffe) { 

            parse_waveformatex(pb, codec);

            cbSize -= 22;

            size   -= 22;

        }

        if (cbSize > 0) {

            av_freep(&codec->extradata);

            if (ff_get_extradata(codec, pb, cbSize) < 0)

                return AVERROR(ENOMEM);

            size -= cbSize;

        }



        

        if (size > 0)

            avio_skip(pb, size);

    }



    if (bitrate > INT_MAX) {

        if (s->error_recognition & AV_EF_EXPLODE) {

            av_log(s, AV_LOG_ERROR,

                   "The bitrate %"PRIu64" is too large.\n",

                    bitrate);

            return AVERROR_INVALIDDATA;

        } else {

            av_log(s, AV_LOG_WARNING,

                   "The bitrate %"PRIu64" is too large, resetting to 0.",

                   bitrate);

            codec->bit_rate = 0;

        }

    } else {

        codec->bit_rate = bitrate;

    }



    if (codec->sample_rate <= 0) {

        av_log(s, AV_LOG_ERROR,

               "Invalid sample rate: %d\n", codec->sample_rate);

        return AVERROR_INVALIDDATA;

    }

    if (codec->codec_id == AV_CODEC_ID_AAC_LATM) {

        



        codec->channels    = 0;

        codec->sample_rate = 0;

    }

    

    if (codec->codec_id == AV_CODEC_ID_ADPCM_G726 && codec->sample_rate)

        codec->bits_per_coded_sample = codec->bit_rate / codec->sample_rate;



    return 0;

}

        bitrate            = avio_rl32(pb) * 8;         bitrate            = avio_rb32(pb) * 8;
int FUNC_0(AVFormatContext *VAR_0, AVIOContext *VAR_1,

                      AVCodecContext *VAR_2, int VAR_3, int VAR_4)

{

    int VAR_5;

    uint64_t bitrate;



    if (VAR_3 < 14) {

        avpriv_request_sample(VAR_2, "wav header VAR_3 < 14");

        return AVERROR_INVALIDDATA;

    }



    VAR_2->codec_type  = AVMEDIA_TYPE_AUDIO;

    if (!VAR_4) {

        VAR_5                 = avio_rl16(VAR_1);

        VAR_2->channels    = avio_rl16(VAR_1);

        VAR_2->sample_rate = avio_rl32(VAR_1);

        bitrate            = avio_rl32(VAR_1) * 8;

        VAR_2->block_align = avio_rl16(VAR_1);

    } else {

        VAR_5                 = avio_rb16(VAR_1);

        VAR_2->channels    = avio_rb16(VAR_1);

        VAR_2->sample_rate = avio_rb32(VAR_1);

        bitrate            = avio_rb32(VAR_1) * 8;

        VAR_2->block_align = avio_rb16(VAR_1);

    }

    if (VAR_3 == 14) {  

        VAR_2->bits_per_coded_sample = 8;

    } else {

        if (!VAR_4) {

            VAR_2->bits_per_coded_sample = avio_rl16(VAR_1);

        } else {

            VAR_2->bits_per_coded_sample = avio_rb16(VAR_1);

        }

    }

    if (VAR_5 == 0xFFFE) {

        VAR_2->codec_tag = 0;

    } else {

        VAR_2->codec_tag = VAR_5;

        VAR_2->codec_id  = ff_wav_codec_get_id(VAR_5,

                                               VAR_2->bits_per_coded_sample);

    }

    if (VAR_3 >= 18) {  

        int VAR_6 = avio_rl16(VAR_1); 

        if (VAR_4) {

            avpriv_report_missing_feature(VAR_2, "WAVEFORMATEX support for RIFX files\n");

            return AVERROR_PATCHWELCOME;

        }

        VAR_3  -= 18;

        VAR_6 = FFMIN(VAR_3, VAR_6);

        if (VAR_6 >= 22 && VAR_5 == 0xfffe) { 

            parse_waveformatex(VAR_1, VAR_2);

            VAR_6 -= 22;

            VAR_3   -= 22;

        }

        if (VAR_6 > 0) {

            av_freep(&VAR_2->extradata);

            if (ff_get_extradata(VAR_2, VAR_1, VAR_6) < 0)

                return AVERROR(ENOMEM);

            VAR_3 -= VAR_6;

        }



        

        if (VAR_3 > 0)

            avio_skip(VAR_1, VAR_3);

    }



    if (bitrate > INT_MAX) {

        if (VAR_0->error_recognition & AV_EF_EXPLODE) {

            av_log(VAR_0, AV_LOG_ERROR,

                   "The bitrate %"PRIu64" is too large.\n",

                    bitrate);

            return AVERROR_INVALIDDATA;

        } else {

            av_log(VAR_0, AV_LOG_WARNING,

                   "The bitrate %"PRIu64" is too large, resetting to 0.",

                   bitrate);

            VAR_2->bit_rate = 0;

        }

    } else {

        VAR_2->bit_rate = bitrate;

    }



    if (VAR_2->sample_rate <= 0) {

        av_log(VAR_0, AV_LOG_ERROR,

               "Invalid sample rate: %d\n", VAR_2->sample_rate);

        return AVERROR_INVALIDDATA;

    }

    if (VAR_2->codec_id == AV_CODEC_ID_AAC_LATM) {

        



        VAR_2->channels    = 0;

        VAR_2->sample_rate = 0;

    }

    

    if (VAR_2->codec_id == AV_CODEC_ID_ADPCM_G726 && VAR_2->sample_rate)

        VAR_2->bits_per_coded_sample = VAR_2->bit_rate / VAR_2->sample_rate;



    return 0;

}

int FUNC_0(AVFormatContext *VAR_0, AVIOContext *VAR_1,
AVCodecContext *VAR_2, int VAR_3, int VAR_4)
{ int VAR_5; uint64_t bitrate; if (VAR_3 < 14) { avpriv_request_sample(VAR_2, "wav header VAR_3 < 14"); return AVERROR_INVALIDDATA; } VAR_2->codec_type  = AVMEDIA_TYPE_AUDIO; if (!VAR_4) { VAR_5                 = avio_rl16(VAR_1); VAR_2->channels    = avio_rl16(VAR_1); VAR_2->sample_rate = avio_rl32(VAR_1); bitrate            = avio_rl32(VAR_1) * 8; VAR_2->block_align = avio_rl16(VAR_1); } else { VAR_5                 = avio_rb16(VAR_1); VAR_2->channels    = avio_rb16(VAR_1); VAR_2->sample_rate = avio_rb32(VAR_1); bitrate            = avio_rb32(VAR_1) * 8; VAR_2->block_align = avio_rb16(VAR_1); } if (VAR_3 == 14) { VAR_2->bits_per_coded_sample = 8; } else { if (!VAR_4) { VAR_2->bits_per_coded_sample = avio_rl16(VAR_1); } else { VAR_2->bits_per_coded_sample = avio_rb16(VAR_1); } } if (VAR_5 == 0xFFFE) { VAR_2->codec_tag = 0; } else { VAR_2->codec_tag = VAR_5; VAR_2->codec_id  = ff_wav_codec_get_id(VAR_5,
VAR_2->bits_per_coded_sample); } if (VAR_3 >= 18) { int VAR_6 = avio_rl16(VAR_1); if (VAR_4) { avpriv_report_missing_feature(VAR_2, "WAVEFORMATEX support for RIFX files\n"); return AVERROR_PATCHWELCOME; } VAR_3  -= 18; VAR_6 = FFMIN(VAR_3, VAR_6); if (VAR_6 >= 22 && VAR_5 == 0xfffe) { parse_waveformatex(VAR_1, VAR_2); VAR_6 -= 22; VAR_3   -= 22; } if (VAR_6 > 0) { av_freep(&VAR_2->extradata); if (ff_get_extradata(VAR_2, VAR_1, VAR_6) < 0)
return AVERROR(ENOMEM); VAR_3 -= VAR_6; } if (VAR_3 > 0)
avio_skip(VAR_1, VAR_3); } if (bitrate > INT_MAX) { if (VAR_0->error_recognition & AV_EF_EXPLODE) { av_log(VAR_0, AV_LOG_ERROR,
"The bitrate %"PRIu64" is too large.\n",
bitrate); return AVERROR_INVALIDDATA; } else { av_log(VAR_0, AV_LOG_WARNING,
"The bitrate %"PRIu64" is too large, resetting to 0.",
bitrate); VAR_2->bit_rate = 0; } } else { VAR_2->bit_rate = bitrate; } if (VAR_2->sample_rate <= 0) { av_log(VAR_0, AV_LOG_ERROR,
"Invalid sample rate: %d\n", VAR_2->sample_rate); return AVERROR_INVALIDDATA; } if (VAR_2->codec_id == AV_CODEC_ID_AAC_LATM) { VAR_2->channels    = 0; VAR_2->sample_rate = 0; } if (VAR_2->codec_id == AV_CODEC_ID_ADPCM_G726 && VAR_2->sample_rate)
VAR_2->bits_per_coded_sample = VAR_2->bit_rate / VAR_2->sample_rate; return 0; }