Ticket #5636: cache.patch

File cache.patch, 1.6 KB (added by chinshou, 10 years ago)
  • libavformat/cache.c

    diff --git a/libavformat/cache.c b/libavformat/cache.c
    index 6aabca2..aa9e398 100644
    a b typedef struct Context {  
    6363    URLContext *inner;
    6464    int64_t cache_hit, cache_miss;
    6565    int read_ahead_limit;
     66    char* cache_path;
    6667} Context;
    6768
    6869static int cmp(const void *key, const void *node)
    static int cache_open(URLContext *h, const char *arg, int flags, AVDictionary **  
    7778
    7879    av_strstart(arg, "cache:", &arg);
    7980
    80     c->fd = avpriv_tempfile("ffcache", &buffername, 0, h);
     81#   ifndef O_BINARY
     82#       define O_BINARY 0
     83#   endif
     84    if (c->cache_path)
     85      c->fd = open(c->cache_path, O_RDWR | O_BINARY | O_CREAT | O_EXCL, 0600);
     86    else
     87      c->fd = av_tempfile("ffcache", &buffername, 0, h);
     88   
    8189    if (c->fd < 0){
    8290        av_log(h, AV_LOG_ERROR, "Failed to create tempfile\n");
    8391        return c->fd;
    8492    }
    8593
     94    if (!c->cache_path)
     95    {
    8696    unlink(buffername);
    8797    av_freep(&buffername);
     98    }
    8899
    89100    return ffurl_open_whitelist(&c->inner, arg, flags, &h->interrupt_callback,
    90101                                options, h->protocol_whitelist, h->protocol_blacklist, h);
    static int cache_close(URLContext *h)  
    309320
    310321static const AVOption options[] = {
    311322    { "read_ahead_limit", "Amount in bytes that may be read ahead when seeking isn't supported, -1 for unlimited", OFFSET(read_ahead_limit), AV_OPT_TYPE_INT, { .i64 = 65536 }, -1, INT_MAX, D },
     323    {"cache_path", "cache path", offsetof(Context, cache_path), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, D},
    312324    {NULL},
    313325};
    314326