char buf[PROBE_BUF_SIZE];
unsigned char buf[PROBE_BUF_SIZE];
int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,                        AVInputFormat *fmt,                       int buf_size,                       AVFormatParameters *ap){    AVFormatContext *ic = NULL;    int err, must_open_file;    char buf[PROBE_BUF_SIZE];    AVProbeData probe_data, *pd = &probe_data;    ic = av_mallocz(sizeof(AVFormatContext));    if (!ic) {        err = AVERROR_NOMEM;        goto fail;    }    ic->duration = AV_NOPTS_VALUE;    ic->start_time = AV_NOPTS_VALUE;    pstrcpy(ic->filename, sizeof(ic->filename), filename);    pd->filename = ic->filename;    pd->buf = buf;    pd->buf_size = 0;    if (!fmt) {        /* guess format if no file can be opened  */        fmt = av_probe_input_format(pd, 0);    }    /* do not open file if the format does not need it. XXX: specific       hack needed to handle RTSP/TCP */    must_open_file = 1;    if ((fmt && (fmt->flags & AVFMT_NOFILE)) #ifdef CONFIG_NETWORK        || (fmt == &rtp_demux && !strcmp(filename, "null"))#endif        ) {        must_open_file = 0;    }    if (!fmt || must_open_file) {        /* if no file needed do not try to open one */        if (url_fopen(&ic->pb, filename, URL_RDONLY) < 0) {            err = AVERROR_IO;            goto fail;        }        if (buf_size > 0) {            url_setbufsize(&ic->pb, buf_size);        }        if (!fmt) {            /* read probe data */            pd->buf_size = get_buffer(&ic->pb, buf, PROBE_BUF_SIZE);            url_fseek(&ic->pb, 0, SEEK_SET);        }    }        /* guess file format */    if (!fmt) {        fmt = av_probe_input_format(pd, 1);    }    /* if still no format found, error */    if (!fmt) {        err = AVERROR_NOFMT;        goto fail1;    }            /* XXX: suppress this hack for redirectors */#ifdef CONFIG_NETWORK    if (fmt == &redir_demux) {        err = redir_open(ic_ptr, &ic->pb);        url_fclose(&ic->pb);        av_free(ic);        return err;    }#endif    ic->iformat = fmt;    /* check filename in case of an image number is expected */    if (ic->iformat->flags & AVFMT_NEEDNUMBER) {        if (filename_number_test(ic->filename) < 0) {             err = AVERROR_NUMEXPECTED;            goto fail1;        }    }        /* allocate private data */    if (fmt->priv_data_size > 0) {        ic->priv_data = av_mallocz(fmt->priv_data_size);        if (!ic->priv_data) {            err = AVERROR_NOMEM;        goto fail1;        }    } else        ic->priv_data = NULL;    /* default pts settings is MPEG like */    av_set_pts_info(ic, 33, 1, 90000);    err = ic->iformat->read_header(ic, ap);    if (err < 0)        goto fail1;    *ic_ptr = ic;    return 0; fail1:    if (!fmt || must_open_file) {        url_fclose(&ic->pb);    } fail:    if (ic) {        av_freep(&ic->priv_data);    }    av_free(ic);    *ic_ptr = NULL;    return err;}