68 static int cmp(
const void *key,
const void *node)
103 pos = lseek(c->
fd, 0, SEEK_END);
111 ret = write(c->
fd, buf, size);
130 if (!entry || !node) {
139 if (entry_ret && entry_ret != entry) {
170 if (in_block_pos < entry->size) {
171 int64_t physical_target = entry->
physical_pos + in_block_pos;
174 r = lseek(c->
fd, physical_target, SEEK_SET);
180 r = read(c->
fd, buf,
FFMIN(size, entry->
size - in_block_pos));
204 if (r == 0 && size>0) {
239 if (whence == SEEK_CUR) {
248 if (whence == SEEK_SET && pos >= 0 && pos < c->
end) {
256 if ((whence == SEEK_SET && pos >= c->
logical_pos ||
257 whence == SEEK_END && pos <= 0) && ret < 0) {
261 while (c->
logical_pos < pos || whence == SEEK_END) {
262 int size =
sizeof(tmp);
263 if (whence == SEEK_SET)
266 if (ret == 0 && whence == SEEK_END) {
290 av_log(h,
AV_LOG_INFO,
"Statistics, cache hits:%"PRId64
" cache misses:%"PRId64
"\n",
300 #define OFFSET(x) offsetof(Context, x)
301 #define D AV_OPT_FLAG_DECODING_PARAM
304 {
"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 },
321 .priv_data_size =
sizeof(
Context),
322 .priv_data_class = &cache_context_class,
support keeping files support filling with a background thread
#define LIBAVUTIL_VERSION_INT
AVIOInterruptCB interrupt_callback
static const AVClass cache_context_class
void * av_tree_find(const AVTreeNode *t, void *key, int(*cmp)(const void *key, const void *b), void *next[2])
static const AVOption options[]
struct AVTreeNode * av_tree_node_alloc(void)
Allocate an AVTreeNode.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
#define av_assert0(cond)
assert() equivalent, that is always enabled.
miscellaneous OS support macros and functions.
static av_cold int end(AVCodecContext *avctx)
URLProtocol ff_cache_protocol
void av_tree_destroy(AVTreeNode *t)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * protocol_whitelist
simple assert() macros that are a bit more flexible than ISO C assert().
static int cache_open(URLContext *h, const char *arg, int flags, AVDictionary **options)
#define FFDIFFSIGN(x, y)
Comparator.
static int cache_close(URLContext *h)
static int cmp(const void *key, const void *node)
static int64_t cache_seek(URLContext *h, int64_t pos, int whence)
int av_tempfile(const char *prefix, char **filename, int log_offset, void *log_ctx)
Wrapper to work around the lack of mkstemp() on mingw.
#define AV_LOG_INFO
Standard information.
int ffurl_open_whitelist(URLContext **puc, const char *filename, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options, const char *whitelist)
Create an URLContext for accessing to the resource indicated by url, and open it. ...
static int cache_read(URLContext *h, unsigned char *buf, int size)
Describe the class of an AVClass context structure.
int ffurl_close(URLContext *h)
int av_strstart(const char *str, const char *pfx, const char **ptr)
Return non-zero if pfx is a prefix of str.
int64_t ffurl_seek(URLContext *h, int64_t pos, int whence)
Change the position that will be used by the next read/write operation on the resource accessed by h...
#define AVSEEK_SIZE
Passing this as the "whence" parameter to a seek function causes it to return the filesize without se...
static int add_entry(URLContext *h, const unsigned char *buf, int size)
void * av_tree_insert(AVTreeNode **tp, void *key, int(*cmp)(const void *key, const void *b), AVTreeNode **next)
Insert or remove an element.
unbuffered private I/O API
int ffurl_read(URLContext *h, unsigned char *buf, int size)
Read up to size bytes from the resource accessed by h, and store the read bytes in buf...