static int nist_read_header(AVFormatContext *s)

{

    char buffer[32], coding[32] = "pcm", format[32] = "01";

    int bps = 0, be = 0;

    int32_t header_size;

    AVStream *st;



    st = avformat_new_stream(s, NULL);

    if (!st)

        return AVERROR(ENOMEM);



    st->codec->codec_type = AVMEDIA_TYPE_AUDIO;



    ff_get_line(s->pb, buffer, sizeof(buffer));

    ff_get_line(s->pb, buffer, sizeof(buffer));

    sscanf(buffer, "%"SCNd32, &header_size);

    if (header_size <= 0)

        return AVERROR_INVALIDDATA;



    while (!url_feof(s->pb)) {

        ff_get_line(s->pb, buffer, sizeof(buffer));



        if (avio_tell(s->pb) >= header_size)

            return AVERROR_INVALIDDATA;



        if (!memcmp(buffer, "end_head", 8)) {

            if (!st->codec->bits_per_coded_sample)

                st->codec->bits_per_coded_sample = bps << 3;



            if (!av_strcasecmp(coding, "pcm")) {

                st->codec->codec_id = ff_get_pcm_codec_id(st->codec->bits_per_coded_sample,

                                                          0, be, 0xFFFF);

            } else if (!av_strcasecmp(coding, "alaw")) {

                st->codec->codec_id = AV_CODEC_ID_PCM_ALAW;

            } else if (!av_strcasecmp(coding, "ulaw") ||

                       !av_strcasecmp(coding, "mu-law")) {

                st->codec->codec_id = AV_CODEC_ID_PCM_MULAW;

            } else {

                avpriv_request_sample(s, "coding %s", coding);

            }



            avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);



            st->codec->block_align = st->codec->bits_per_coded_sample * st->codec->channels / 8;



            if (avio_tell(s->pb) > header_size)

                return AVERROR_INVALIDDATA;



            avio_skip(s->pb, header_size - avio_tell(s->pb));



            return 0;

        } else if (!memcmp(buffer, "channel_count", 13)) {

            sscanf(buffer, "%*s %*s %"SCNd32, &st->codec->channels);

        } else if (!memcmp(buffer, "sample_byte_format", 18)) {

            sscanf(buffer, "%*s %*s %31s", format);



            if (!av_strcasecmp(format, "01")) {

                be = 0;

            } else if (!av_strcasecmp(format, "10")) {

                be = 1;

            } else if (av_strcasecmp(format, "1")) {

                avpriv_request_sample(s, "sample byte format %s", format);

                return AVERROR_PATCHWELCOME;

            }

        } else if (!memcmp(buffer, "sample_coding", 13)) {

            sscanf(buffer, "%*s %*s %31s", coding);

        } else if (!memcmp(buffer, "sample_count", 12)) {

            sscanf(buffer, "%*s %*s %"SCNd64, &st->duration);

        } else if (!memcmp(buffer, "sample_n_bytes", 14)) {

            sscanf(buffer, "%*s %*s %"SCNd32, &bps);

        } else if (!memcmp(buffer, "sample_rate", 11)) {

            sscanf(buffer, "%*s %*s %"SCNd32, &st->codec->sample_rate);

        } else if (!memcmp(buffer, "sample_sig_bits", 15)) {

            sscanf(buffer, "%*s %*s %"SCNd32, &st->codec->bits_per_coded_sample);

        } else {

            char key[32], value[32];

            if (sscanf(buffer, "%31s %*s %31s", key, value) == 3) {

                av_dict_set(&s->metadata, key, value, AV_DICT_APPEND);

            } else {

                av_log(s, AV_LOG_ERROR, "Failed to parse '%s' as metadata\n", buffer);

            }

        }

    }



    return AVERROR_EOF;

}

static int nist_read_header(AVFormatContext *s)

{

    char buffer[32], coding[32] = "pcm", format[32] = "01";

    int bps = 0, be = 0;

    int32_t header_size;

    AVStream *st;



    st = avformat_new_stream(s, NULL);

    if (!st)

        return AVERROR(ENOMEM);



    st->codec->codec_type = AVMEDIA_TYPE_AUDIO;



    ff_get_line(s->pb, buffer, sizeof(buffer));

    ff_get_line(s->pb, buffer, sizeof(buffer));

    sscanf(buffer, "%"SCNd32, &header_size);

    if (header_size <= 0)

        return AVERROR_INVALIDDATA;



    while (!url_feof(s->pb)) {

        ff_get_line(s->pb, buffer, sizeof(buffer));



        if (avio_tell(s->pb) >= header_size)

            return AVERROR_INVALIDDATA;



        if (!memcmp(buffer, "end_head", 8)) {

            if (!st->codec->bits_per_coded_sample)

                st->codec->bits_per_coded_sample = bps << 3;



            if (!av_strcasecmp(coding, "pcm")) {

                st->codec->codec_id = ff_get_pcm_codec_id(st->codec->bits_per_coded_sample,

                                                          0, be, 0xFFFF);

            } else if (!av_strcasecmp(coding, "alaw")) {

                st->codec->codec_id = AV_CODEC_ID_PCM_ALAW;

            } else if (!av_strcasecmp(coding, "ulaw") ||

                       !av_strcasecmp(coding, "mu-law")) {

                st->codec->codec_id = AV_CODEC_ID_PCM_MULAW;

            } else {

                avpriv_request_sample(s, "coding %s", coding);

            }



            avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);



            st->codec->block_align = st->codec->bits_per_coded_sample * st->codec->channels / 8;



            if (avio_tell(s->pb) > header_size)

                return AVERROR_INVALIDDATA;



            avio_skip(s->pb, header_size - avio_tell(s->pb));



            return 0;

        } else if (!memcmp(buffer, "channel_count", 13)) {

            sscanf(buffer, "%*s %*s %"SCNd32, &st->codec->channels);

        } else if (!memcmp(buffer, "sample_byte_format", 18)) {

            sscanf(buffer, "%*s %*s %31s", format);



            if (!av_strcasecmp(format, "01")) {

                be = 0;

            } else if (!av_strcasecmp(format, "10")) {

                be = 1;

            } else if (av_strcasecmp(format, "1")) {

                avpriv_request_sample(s, "sample byte format %s", format);

                return AVERROR_PATCHWELCOME;

            }

        } else if (!memcmp(buffer, "sample_coding", 13)) {

            sscanf(buffer, "%*s %*s %31s", coding);

        } else if (!memcmp(buffer, "sample_count", 12)) {

            sscanf(buffer, "%*s %*s %"SCNd64, &st->duration);

        } else if (!memcmp(buffer, "sample_n_bytes", 14)) {

            sscanf(buffer, "%*s %*s %"SCNd32, &bps);

        } else if (!memcmp(buffer, "sample_rate", 11)) {

            sscanf(buffer, "%*s %*s %"SCNd32, &st->codec->sample_rate);

        } else if (!memcmp(buffer, "sample_sig_bits", 15)) {

            sscanf(buffer, "%*s %*s %"SCNd32, &st->codec->bits_per_coded_sample);

        } else {

            char key[32], value[32];

            if (sscanf(buffer, "%31s %*s %31s", key, value) == 3) {

                av_dict_set(&s->metadata, key, value, AV_DICT_APPEND);

            } else {

                av_log(s, AV_LOG_ERROR, "Failed to parse '%s' as metadata\n", buffer);

            }

        }

    }



    return AVERROR_EOF;

}

    int32_t header_size;
static int FUNC_0(AVFormatContext *VAR_0)

{

    char VAR_1[32], VAR_2[32] = "pcm", VAR_3[32] = "01";

    int VAR_4 = 0, VAR_5 = 0;

    int32_t header_size;

    AVStream *st;



    st = avformat_new_stream(VAR_0, NULL);

    if (!st)

        return AVERROR(ENOMEM);



    st->codec->codec_type = AVMEDIA_TYPE_AUDIO;



    ff_get_line(VAR_0->pb, VAR_1, sizeof(VAR_1));

    ff_get_line(VAR_0->pb, VAR_1, sizeof(VAR_1));

    sscanf(VAR_1, "%"SCNd32, &header_size);

    if (header_size <= 0)

        return AVERROR_INVALIDDATA;



    while (!url_feof(VAR_0->pb)) {

        ff_get_line(VAR_0->pb, VAR_1, sizeof(VAR_1));



        if (avio_tell(VAR_0->pb) >= header_size)

            return AVERROR_INVALIDDATA;



        if (!memcmp(VAR_1, "end_head", 8)) {

            if (!st->codec->bits_per_coded_sample)

                st->codec->bits_per_coded_sample = VAR_4 << 3;



            if (!av_strcasecmp(VAR_2, "pcm")) {

                st->codec->codec_id = ff_get_pcm_codec_id(st->codec->bits_per_coded_sample,

                                                          0, VAR_5, 0xFFFF);

            } else if (!av_strcasecmp(VAR_2, "alaw")) {

                st->codec->codec_id = AV_CODEC_ID_PCM_ALAW;

            } else if (!av_strcasecmp(VAR_2, "ulaw") ||

                       !av_strcasecmp(VAR_2, "mu-law")) {

                st->codec->codec_id = AV_CODEC_ID_PCM_MULAW;

            } else {

                avpriv_request_sample(VAR_0, "VAR_2 %VAR_0", VAR_2);

            }



            avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);



            st->codec->block_align = st->codec->bits_per_coded_sample * st->codec->channels / 8;



            if (avio_tell(VAR_0->pb) > header_size)

                return AVERROR_INVALIDDATA;



            avio_skip(VAR_0->pb, header_size - avio_tell(VAR_0->pb));



            return 0;

        } else if (!memcmp(VAR_1, "channel_count", 13)) {

            sscanf(VAR_1, "%*VAR_0 %*VAR_0 %"SCNd32, &st->codec->channels);

        } else if (!memcmp(VAR_1, "sample_byte_format", 18)) {

            sscanf(VAR_1, "%*VAR_0 %*VAR_0 %31s", VAR_3);



            if (!av_strcasecmp(VAR_3, "01")) {

                VAR_5 = 0;

            } else if (!av_strcasecmp(VAR_3, "10")) {

                VAR_5 = 1;

            } else if (av_strcasecmp(VAR_3, "1")) {

                avpriv_request_sample(VAR_0, "sample byte VAR_3 %VAR_0", VAR_3);

                return AVERROR_PATCHWELCOME;

            }

        } else if (!memcmp(VAR_1, "sample_coding", 13)) {

            sscanf(VAR_1, "%*VAR_0 %*VAR_0 %31s", VAR_2);

        } else if (!memcmp(VAR_1, "sample_count", 12)) {

            sscanf(VAR_1, "%*VAR_0 %*VAR_0 %"SCNd64, &st->duration);

        } else if (!memcmp(VAR_1, "sample_n_bytes", 14)) {

            sscanf(VAR_1, "%*VAR_0 %*VAR_0 %"SCNd32, &VAR_4);

        } else if (!memcmp(VAR_1, "sample_rate", 11)) {

            sscanf(VAR_1, "%*VAR_0 %*VAR_0 %"SCNd32, &st->codec->sample_rate);

        } else if (!memcmp(VAR_1, "sample_sig_bits", 15)) {

            sscanf(VAR_1, "%*VAR_0 %*VAR_0 %"SCNd32, &st->codec->bits_per_coded_sample);

        } else {

            char VAR_6[32], VAR_7[32];

            if (sscanf(VAR_1, "%31s %*VAR_0 %31s", VAR_6, VAR_7) == 3) {

                av_dict_set(&VAR_0->metadata, VAR_6, VAR_7, AV_DICT_APPEND);

            } else {

                av_log(VAR_0, AV_LOG_ERROR, "Failed to parse '%VAR_0' as metadata\n", VAR_1);

            }

        }

    }



    return AVERROR_EOF;

}

static int FUNC_0(AVFormatContext *VAR_0)
{ char VAR_1[32], VAR_2[32] = "pcm", VAR_3[32] = "01"; int VAR_4 = 0, VAR_5 = 0; int32_t header_size; AVStream *st; st = avformat_new_stream(VAR_0, NULL); if (!st)
return AVERROR(ENOMEM); st->codec->codec_type = AVMEDIA_TYPE_AUDIO; ff_get_line(VAR_0->pb, VAR_1, sizeof(VAR_1)); ff_get_line(VAR_0->pb, VAR_1, sizeof(VAR_1)); sscanf(VAR_1, "%"SCNd32, &header_size); if (header_size <= 0)
return AVERROR_INVALIDDATA; while (!url_feof(VAR_0->pb)) { ff_get_line(VAR_0->pb, VAR_1, sizeof(VAR_1)); if (avio_tell(VAR_0->pb) >= header_size)
return AVERROR_INVALIDDATA; if (!memcmp(VAR_1, "end_head", 8)) { if (!st->codec->bits_per_coded_sample)
st->codec->bits_per_coded_sample = VAR_4 << 3; if (!av_strcasecmp(VAR_2, "pcm")) { st->codec->codec_id = ff_get_pcm_codec_id(st->codec->bits_per_coded_sample,
0, VAR_5, 0xFFFF); } else if (!av_strcasecmp(VAR_2, "alaw")) { st->codec->codec_id = AV_CODEC_ID_PCM_ALAW; } else if (!av_strcasecmp(VAR_2, "ulaw") || !av_strcasecmp(VAR_2, "mu-law")) { st->codec->codec_id = AV_CODEC_ID_PCM_MULAW; } else { avpriv_request_sample(VAR_0, "VAR_2 %VAR_0", VAR_2); } avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); st->codec->block_align = st->codec->bits_per_coded_sample * st->codec->channels / 8; if (avio_tell(VAR_0->pb) > header_size)
return AVERROR_INVALIDDATA; avio_skip(VAR_0->pb, header_size - avio_tell(VAR_0->pb)); return 0; } else if (!memcmp(VAR_1, "channel_count", 13)) { sscanf(VAR_1, "%*VAR_0 %*VAR_0 %"SCNd32, &st->codec->channels); } else if (!memcmp(VAR_1, "sample_byte_format", 18)) { sscanf(VAR_1, "%*VAR_0 %*VAR_0 %31s", VAR_3); if (!av_strcasecmp(VAR_3, "01")) { VAR_5 = 0; } else if (!av_strcasecmp(VAR_3, "10")) { VAR_5 = 1; } else if (av_strcasecmp(VAR_3, "1")) { avpriv_request_sample(VAR_0, "sample byte VAR_3 %VAR_0", VAR_3); return AVERROR_PATCHWELCOME; } } else if (!memcmp(VAR_1, "sample_coding", 13)) { sscanf(VAR_1, "%*VAR_0 %*VAR_0 %31s", VAR_2); } else if (!memcmp(VAR_1, "sample_count", 12)) { sscanf(VAR_1, "%*VAR_0 %*VAR_0 %"SCNd64, &st->duration); } else if (!memcmp(VAR_1, "sample_n_bytes", 14)) { sscanf(VAR_1, "%*VAR_0 %*VAR_0 %"SCNd32, &VAR_4); } else if (!memcmp(VAR_1, "sample_rate", 11)) { sscanf(VAR_1, "%*VAR_0 %*VAR_0 %"SCNd32, &st->codec->sample_rate); } else if (!memcmp(VAR_1, "sample_sig_bits", 15)) { sscanf(VAR_1, "%*VAR_0 %*VAR_0 %"SCNd32, &st->codec->bits_per_coded_sample); } else { char VAR_6[32], VAR_7[32]; if (sscanf(VAR_1, "%31s %*VAR_0 %31s", VAR_6, VAR_7) == 3) { av_dict_set(&VAR_0->metadata, VAR_6, VAR_7, AV_DICT_APPEND); } else { av_log(VAR_0, AV_LOG_ERROR, "Failed to parse '%VAR_0' as metadata\n", VAR_1); } } } return AVERROR_EOF; }