72static int cmp(
const void *
key,
const void *node)
91 ret = unlink(buffername);
96 c->filename = buffername;
99 options,
h->protocol_whitelist,
h->protocol_blacklist,
h);
112 pos = lseek(
c->fd, 0, SEEK_END);
120 ret = write(
c->fd, buf,
size);
134 entry->logical_pos +
entry->size !=
c->logical_pos ||
139 if (!
entry || !node) {
143 entry->logical_pos =
c->logical_pos;
148 if (entry_ret && entry_ret !=
entry) {
179 if (in_block_pos < entry->
size) {
180 int64_t physical_target =
entry->physical_pos + in_block_pos;
182 if (
c->cache_pos != physical_target) {
183 r = lseek(
c->fd, physical_target, SEEK_SET);
203 if (
c->logical_pos !=
c->inner_pos) {
225 c->end =
FFMAX(
c->end,
c->logical_pos);
248 if (whence == SEEK_CUR) {
250 pos +=
c->logical_pos;
251 }
else if (whence == SEEK_END &&
c->is_true_eof) {
259 c->logical_pos =
pos;
265 if ((whence == SEEK_SET &&
pos >=
c->logical_pos ||
266 whence == SEEK_END &&
pos <= 0) && ret < 0) {
267 if ( (whence == SEEK_SET &&
c->read_ahead_limit >=
pos -
c->logical_pos)
268 ||
c->read_ahead_limit < 0) {
270 while (
c->logical_pos <
pos || whence == SEEK_END) {
272 if (whence == SEEK_SET)
283 return c->logical_pos;
288 c->logical_pos = ret;
307 c->cache_hit,
c->cache_miss);
311 ret = unlink(
c->filename);
323#define OFFSET(x) offsetof(CacheContext, x)
324#define D AV_OPT_FLAG_DECODING_PARAM
327 {
"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 },
332 .class_name =
"cache",
static av_cold void close(AVCodecParserContext *s)
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int ffurl_open_whitelist(URLContext **puc, const char *filename, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options, const char *whitelist, const char *blacklist, URLContext *parent)
Create an URLContext for accessing to the resource indicated by url, and open it.
int ffurl_closep(URLContext **hh)
Close the resource accessed by the URLContext h, and free the memory used by it.
#define AVSEEK_SIZE
Passing this as the "whence" parameter to a seek function causes it to return the filesize without se...
static uint32_t BS_FUNC read(BSCTX *bc, unsigned int n)
Return n bits from the buffer, n has to be in the 0-32 range.
static int enu_free(void *opaque, void *elem)
static int add_entry(URLContext *h, const unsigned char *buf, int size)
static int cache_close(URLContext *h)
static int cache_open(URLContext *h, const char *arg, int flags, AVDictionary **options)
static const AVClass cache_context_class
static int64_t cache_seek(URLContext *h, int64_t pos, int whence)
static int cache_read(URLContext *h, unsigned char *buf, int size)
static int cmp(const void *key, const void *node)
const URLProtocol ff_cache_protocol
#define flags(name, subs,...)
@ AV_OPT_TYPE_INT
Underlying C type is int.
#define AVERROR_EOF
End of file.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
int av_strstart(const char *str, const char *pfx, const char **ptr)
Return non-zero if pfx is a prefix of str.
void av_tree_enumerate(AVTreeNode *t, void *opaque, int(*cmp)(void *opaque, void *elem), int(*enu)(void *opaque, void *elem))
Apply enu(opaque, &elem) to all the elements in the tree in a given range.
void * av_tree_insert(AVTreeNode **tp, void *key, int(*cmp)(const void *key, const void *b), AVTreeNode **next)
Insert or remove an element.
void av_tree_destroy(AVTreeNode *t)
struct AVTreeNode * av_tree_node_alloc(void)
Allocate an AVTreeNode.
#define LIBAVUTIL_VERSION_INT
int avpriv_tempfile(const char *prefix, char **filename, int log_offset, void *log_ctx)
Wrapper to work around the lack of mkstemp() on mingw.
#define FFDIFFSIGN(x, y)
Comparator.
Memory handling functions.
static av_always_inline int cmp(MPVEncContext *const s, const int x, const int y, const int subx, const int suby, const int size, const int h, int ref_index, int src_index, me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags)
compares a block (either a full macroblock or a partition thereof) against a proposed motion-compensa...
miscellaneous OS support macros and functions.
Describe the class of an AVClass context structure.
@TODO support keeping files support filling with a background thread
void * av_tree_find(const AVTreeNode *t, void *key, int(*cmp)(const void *key, const void *b), void *next[2])
unbuffered private I/O API
static 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.
static int ffurl_read(URLContext *h, uint8_t *buf, int size)
Read up to size bytes from the resource accessed by h, and store the read bytes in buf.