Logo Search packages:      
Sourcecode: blender version File versions  Download package

int av_open_input_file ( AVFormatContext **  ic_ptr,
const char *  filename,
AVInputFormat *  fmt,
int  buf_size,
AVFormatParameters *  ap 
)

Open a media file as input. The codec are not opened. Only the file header (if present) is read.

Parameters:
ic_ptr the opened media file handle is put here
filename filename to open.
fmt if non NULL, force the file format to use
buf_size optional buffer size (zero if default is OK)
ap additionnal parameters needed when opening the file (NULL if default)
Returns:
0 if OK. AVERROR_xxx otherwise.

Definition at line 531 of file utils.c.

References av_freep(), av_open_input_stream(), av_probe_input_format(), av_realloc(), and PROBE_BUF_MIN.

{
    int err, must_open_file, file_opened, probe_size;
    AVProbeData probe_data, *pd = &probe_data;
    ByteIOContext pb1, *pb = &pb1;

    file_opened = 0;
    pd->filename = "";
    if (filename)
        pd->filename = filename;
    pd->buf = NULL;
    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)) {
        must_open_file = 0;
        pb= NULL; //FIXME this or memset(pb, 0, sizeof(ByteIOContext)); otherwise its uninitalized
    }

    if (!fmt || must_open_file) {
        /* if no file needed do not try to open one */
        if (url_fopen(pb, filename, URL_RDONLY) < 0) {
            err = AVERROR_IO;
            goto fail;
        }
        file_opened = 1;
        if (buf_size > 0) {
            url_setbufsize(pb, buf_size);
        }

        for(probe_size= PROBE_BUF_MIN; probe_size<=PROBE_BUF_MAX && !fmt; probe_size<<=1){
            /* read probe data */
            pd->buf= av_realloc(pd->buf, probe_size);
            pd->buf_size = get_buffer(pb, pd->buf, probe_size);
            if (url_fseek(pb, 0, SEEK_SET) == (offset_t)-EPIPE) {
                url_fclose(pb);
                if (url_fopen(pb, filename, URL_RDONLY) < 0) {
                    file_opened = 0;
                    err = AVERROR_IO;
                    goto fail;
                }
            }
            /* guess file format */
            fmt = av_probe_input_format(pd, 1);
        }
        av_freep(&pd->buf);
    }

    /* if still no format found, error */
    if (!fmt) {
        err = AVERROR_NOFMT;
        goto fail;
    }

    /* XXX: suppress this hack for redirectors */
#ifdef CONFIG_NETWORK
    if (fmt == &redir_demux) {
        err = redir_open(ic_ptr, pb);
        url_fclose(pb);
        return err;
    }
#endif

    /* check filename in case of an image number is expected */
    if (fmt->flags & AVFMT_NEEDNUMBER) {
        if (filename_number_test(filename) < 0) {
            err = AVERROR_NUMEXPECTED;
            goto fail;
        }
    }
    err = av_open_input_stream(ic_ptr, pb, filename, fmt, ap);
    if (err)
        goto fail;
    return 0;
 fail:
    av_freep(&pd->buf);
    if (file_opened)
        url_fclose(pb);
    *ic_ptr = NULL;
    return err;

}


Generated by  Doxygen 1.6.0   Back to index