int av_probe_input_buffer2(AVIOContext *pb, AVInputFormat **fmt,

                          const char *filename, void *logctx,

                          unsigned int offset, unsigned int max_probe_size)

{

    AVProbeData pd = { filename ? filename : "" };

    uint8_t *buf = NULL;

    uint8_t *mime_type;

    int ret = 0, probe_size, buf_offset = 0;

    int score = 0;



    if (!max_probe_size)

        max_probe_size = PROBE_BUF_MAX;

    else if (max_probe_size < PROBE_BUF_MIN) {

        av_log(logctx, AV_LOG_ERROR,

               "Specified probe size value %u cannot be < %u\n", max_probe_size, PROBE_BUF_MIN);

        return AVERROR(EINVAL);

    }



    if (offset >= max_probe_size)

        return AVERROR(EINVAL);



#ifdef FF_API_PROBE_MIME

    if (pb->av_class)

        av_opt_get(pb, "mime_type", AV_OPT_SEARCH_CHILDREN, &pd.mime_type);

#endif



#if !FF_API_PROBE_MIME

    if (!*fmt && pb->av_class && av_opt_get(pb, "mime_type", AV_OPT_SEARCH_CHILDREN, &mime_type) >= 0 && mime_type) {

        if (!av_strcasecmp(mime_type, "audio/aacp")) {

            *fmt = av_find_input_format("aac");

        }

        av_freep(&mime_type);

    }

#endif



    for (probe_size = PROBE_BUF_MIN; probe_size <= max_probe_size && !*fmt;

         probe_size = FFMIN(probe_size << 1,

                            FFMAX(max_probe_size, probe_size + 1))) {

        score = probe_size < max_probe_size ? AVPROBE_SCORE_RETRY : 0;



        /* Read probe data. */

        if ((ret = av_reallocp(&buf, probe_size + AVPROBE_PADDING_SIZE)) < 0)

            goto fail;

        if ((ret = avio_read(pb, buf + buf_offset,

                             probe_size - buf_offset)) < 0) {

            /* Fail if error was not end of file, otherwise, lower score. */

            if (ret != AVERROR_EOF)

                goto fail;



            score = 0;

            ret   = 0;          /* error was end of file, nothing read */

        }

        buf_offset += ret;

        if (buf_offset < offset)

            continue;

        pd.buf_size = buf_offset - offset;

        pd.buf = &buf[offset];



        memset(pd.buf + pd.buf_size, 0, AVPROBE_PADDING_SIZE);



        /* Guess file format. */

        *fmt = av_probe_input_format2(&pd, 1, &score);

        if (*fmt) {

            /* This can only be true in the last iteration. */

            if (score <= AVPROBE_SCORE_RETRY) {

                av_log(logctx, AV_LOG_WARNING,

                       "Format %s detected only with low score of %d, "

                       "misdetection possible!\n", (*fmt)->name, score);

            } else

                av_log(logctx, AV_LOG_DEBUG,

                       "Format %s probed with size=%d and score=%d\n",

                       (*fmt)->name, probe_size, score);

#if 0

            FILE *f = fopen("probestat.tmp", "ab");

            fprintf(f, "probe_size:%d format:%s score:%d filename:%s\n", probe_size, (*fmt)->name, score, filename);

            fclose(f);

#endif

        }

    }



    if (!*fmt)

        ret = AVERROR_INVALIDDATA;



fail:

    /* Rewind. Reuse probe buffer to avoid seeking. */

    if (ret >= 0)

        ret = ffio_rewind_with_probe_data(pb, &buf, buf_offset);



#ifdef FF_API_PROBE_MIME

    av_free(pd.mime_type);

#endif

    return ret < 0 ? ret : score;

}

int av_probe_input_buffer2(AVIOContext *pb, AVInputFormat **fmt,

                          const char *filename, void *logctx,

                          unsigned int offset, unsigned int max_probe_size)

{

    AVProbeData pd = { filename ? filename : "" };

    uint8_t *buf = NULL;

    uint8_t *mime_type;

    int ret = 0, probe_size, buf_offset = 0;

    int score = 0;



    if (!max_probe_size)

        max_probe_size = PROBE_BUF_MAX;

    else if (max_probe_size < PROBE_BUF_MIN) {

        av_log(logctx, AV_LOG_ERROR,

               "Specified probe size value %u cannot be < %u\n", max_probe_size, PROBE_BUF_MIN);

        return AVERROR(EINVAL);

    }



    if (offset >= max_probe_size)

        return AVERROR(EINVAL);



#ifdef FF_API_PROBE_MIME

    if (pb->av_class)

        av_opt_get(pb, "mime_type", AV_OPT_SEARCH_CHILDREN, &pd.mime_type);

#endif



#if !FF_API_PROBE_MIME

    if (!*fmt && pb->av_class && av_opt_get(pb, "mime_type", AV_OPT_SEARCH_CHILDREN, &mime_type) >= 0 && mime_type) {

        if (!av_strcasecmp(mime_type, "audio/aacp")) {

            *fmt = av_find_input_format("aac");

        }

        av_freep(&mime_type);

    }

#endif



    for (probe_size = PROBE_BUF_MIN; probe_size <= max_probe_size && !*fmt;

         probe_size = FFMIN(probe_size << 1,

                            FFMAX(max_probe_size, probe_size + 1))) {

        score = probe_size < max_probe_size ? AVPROBE_SCORE_RETRY : 0;



        

        if ((ret = av_reallocp(&buf, probe_size + AVPROBE_PADDING_SIZE)) < 0)

            goto fail;

        if ((ret = avio_read(pb, buf + buf_offset,

                             probe_size - buf_offset)) < 0) {

            

            if (ret != AVERROR_EOF)

                goto fail;



            score = 0;

            ret   = 0;          

        }

        buf_offset += ret;

        if (buf_offset < offset)

            continue;

        pd.buf_size = buf_offset - offset;

        pd.buf = &buf[offset];



        memset(pd.buf + pd.buf_size, 0, AVPROBE_PADDING_SIZE);



        

        *fmt = av_probe_input_format2(&pd, 1, &score);

        if (*fmt) {

            

            if (score <= AVPROBE_SCORE_RETRY) {

                av_log(logctx, AV_LOG_WARNING,

                       "Format %s detected only with low score of %d, "

                       "misdetection possible!\n", (*fmt)->name, score);

            } else

                av_log(logctx, AV_LOG_DEBUG,

                       "Format %s probed with size=%d and score=%d\n",

                       (*fmt)->name, probe_size, score);

#if 0

            FILE *f = fopen("probestat.tmp", "ab");

            fprintf(f, "probe_size:%d format:%s score:%d filename:%s\n", probe_size, (*fmt)->name, score, filename);

            fclose(f);

#endif

        }

    }



    if (!*fmt)

        ret = AVERROR_INVALIDDATA;



fail:

    

    if (ret >= 0)

        ret = ffio_rewind_with_probe_data(pb, &buf, buf_offset);



#ifdef FF_API_PROBE_MIME

    av_free(pd.mime_type);

#endif

    return ret < 0 ? ret : score;

}

int FUNC_0(AVIOContext *VAR_0, AVInputFormat **VAR_1,

                          const char *VAR_2, void *VAR_3,

                          unsigned int VAR_4, unsigned int VAR_5)

{

    AVProbeData pd = { VAR_2 ? VAR_2 : "" };

    uint8_t *buf = NULL;

    uint8_t *mime_type;

    int VAR_6 = 0, VAR_7, VAR_8 = 0;

    int VAR_9 = 0;



    if (!VAR_5)

        VAR_5 = PROBE_BUF_MAX;

    else if (VAR_5 < PROBE_BUF_MIN) {

        av_log(VAR_3, AV_LOG_ERROR,

               "Specified probe size value %u cannot be < %u\n", VAR_5, PROBE_BUF_MIN);

        return AVERROR(EINVAL);

    }



    if (VAR_4 >= VAR_5)

        return AVERROR(EINVAL);



#ifdef FF_API_PROBE_MIME

    if (VAR_0->av_class)

        av_opt_get(VAR_0, "mime_type", AV_OPT_SEARCH_CHILDREN, &pd.mime_type);

#endif



#if !FF_API_PROBE_MIME

    if (!*VAR_1 && VAR_0->av_class && av_opt_get(VAR_0, "mime_type", AV_OPT_SEARCH_CHILDREN, &mime_type) >= 0 && mime_type) {

        if (!av_strcasecmp(mime_type, "audio/aacp")) {

            *VAR_1 = av_find_input_format("aac");

        }

        av_freep(&mime_type);

    }

#endif



    for (VAR_7 = PROBE_BUF_MIN; VAR_7 <= VAR_5 && !*VAR_1;

         VAR_7 = FFMIN(VAR_7 << 1,

                            FFMAX(VAR_5, VAR_7 + 1))) {

        VAR_9 = VAR_7 < VAR_5 ? AVPROBE_SCORE_RETRY : 0;



        

        if ((VAR_6 = av_reallocp(&buf, VAR_7 + AVPROBE_PADDING_SIZE)) < 0)

            goto fail;

        if ((VAR_6 = avio_read(VAR_0, buf + VAR_8,

                             VAR_7 - VAR_8)) < 0) {

            

            if (VAR_6 != AVERROR_EOF)

                goto fail;



            VAR_9 = 0;

            VAR_6   = 0;          

        }

        VAR_8 += VAR_6;

        if (VAR_8 < VAR_4)

            continue;

        pd.buf_size = VAR_8 - VAR_4;

        pd.buf = &buf[VAR_4];



        memset(pd.buf + pd.buf_size, 0, AVPROBE_PADDING_SIZE);



        

        *VAR_1 = av_probe_input_format2(&pd, 1, &VAR_9);

        if (*VAR_1) {

            

            if (VAR_9 <= AVPROBE_SCORE_RETRY) {

                av_log(VAR_3, AV_LOG_WARNING,

                       "Format %s detected only with low VAR_9 of %d, "

                       "misdetection possible!\n", (*VAR_1)->name, VAR_9);

            } else

                av_log(VAR_3, AV_LOG_DEBUG,

                       "Format %s probed with size=%d and VAR_9=%d\n",

                       (*VAR_1)->name, VAR_7, VAR_9);

#if 0

            FILE *f = fopen("probestat.tmp", "ab");

            fprintf(f, "VAR_7:%d format:%s VAR_9:%d VAR_2:%s\n", VAR_7, (*VAR_1)->name, VAR_9, VAR_2);

            fclose(f);

#endif

        }

    }



    if (!*VAR_1)

        VAR_6 = AVERROR_INVALIDDATA;



fail:

    

    if (VAR_6 >= 0)

        VAR_6 = ffio_rewind_with_probe_data(VAR_0, &buf, VAR_8);



#ifdef FF_API_PROBE_MIME

    av_free(pd.mime_type);

#endif

    return VAR_6 < 0 ? VAR_6 : VAR_9;

}

int FUNC_0(AVIOContext *VAR_0, AVInputFormat **VAR_1,
const char *VAR_2, void *VAR_3,
unsigned int VAR_4, unsigned int VAR_5)
{ AVProbeData pd = { VAR_2 ? VAR_2 : "" }; uint8_t *buf = NULL; uint8_t *mime_type; int VAR_6 = 0, VAR_7, VAR_8 = 0; int VAR_9 = 0; if (!VAR_5)
VAR_5 = PROBE_BUF_MAX; else if (VAR_5 < PROBE_BUF_MIN) { av_log(VAR_3, AV_LOG_ERROR,
"Specified probe size value %u cannot be < %u\n", VAR_5, PROBE_BUF_MIN); return AVERROR(EINVAL); } if (VAR_4 >= VAR_5)
return AVERROR(EINVAL); #ifdef FF_API_PROBE_MIME
if (VAR_0->av_class)
av_opt_get(VAR_0, "mime_type", AV_OPT_SEARCH_CHILDREN, &pd.mime_type); #endif
#if !FF_API_PROBE_MIME
if (!*VAR_1 && VAR_0->av_class && av_opt_get(VAR_0, "mime_type", AV_OPT_SEARCH_CHILDREN, &mime_type) >= 0 && mime_type) { if (!av_strcasecmp(mime_type, "audio/aacp")) { *VAR_1 = av_find_input_format("aac"); } av_freep(&mime_type); } #endif
for (VAR_7 = PROBE_BUF_MIN; VAR_7 <= VAR_5 && !*VAR_1; VAR_7 = FFMIN(VAR_7 << 1,
FFMAX(VAR_5, VAR_7 + 1))) { VAR_9 = VAR_7 < VAR_5 ? AVPROBE_SCORE_RETRY : 0; if ((VAR_6 = av_reallocp(&buf, VAR_7 + AVPROBE_PADDING_SIZE)) < 0)
goto fail; if ((VAR_6 = avio_read(VAR_0, buf + VAR_8,
VAR_7 - VAR_8)) < 0) { if (VAR_6 != AVERROR_EOF)
goto fail; VAR_9 = 0; VAR_6   = 0; } VAR_8 += VAR_6; if (VAR_8 < VAR_4)
continue; pd.buf_size = VAR_8 - VAR_4; pd.buf = &buf[VAR_4]; memset(pd.buf + pd.buf_size, 0, AVPROBE_PADDING_SIZE); *VAR_1 = av_probe_input_format2(&pd, 1, &VAR_9); if (*VAR_1) { if (VAR_9 <= AVPROBE_SCORE_RETRY) { av_log(VAR_3, AV_LOG_WARNING,
"Format %s detected only with low VAR_9 of %d, "
"misdetection possible!\n", (*VAR_1)->name, VAR_9); } else av_log(VAR_3, AV_LOG_DEBUG,
"Format %s probed with size=%d and VAR_9=%d\n",
(*VAR_1)->name, VAR_7, VAR_9); #if 0
FILE *f = fopen("probestat.tmp", "ab"); fprintf(f, "VAR_7:%d format:%s VAR_9:%d VAR_2:%s\n", VAR_7, (*VAR_1)->name, VAR_9, VAR_2); fclose(f); #endif
} } if (!*VAR_1)
VAR_6 = AVERROR_INVALIDDATA; fail:
if (VAR_6 >= 0)
VAR_6 = ffio_rewind_with_probe_data(VAR_0, &buf, VAR_8); #ifdef FF_API_PROBE_MIME
av_free(pd.mime_type); #endif
return VAR_6 < 0 ? VAR_6 : VAR_9; }