Lines Matching +full:file +full:- +full:entry +full:- +full:cache
2 * Input cache protocol.
5 * This file is part of FFmpeg.
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 * Based on file.c by Fabrice Bellard
71 return FFDIFFSIGN(*(const int64_t *)key, ((const CacheEntry *) node)->logical_pos); in cmp()
78 Context *c= h->priv_data; in cache_open()
80 av_strstart(arg, "cache:", &arg); in cache_open()
82 c->fd = avpriv_tempfile("ffcache", &buffername, 0, h); in cache_open()
83 if (c->fd < 0){ in cache_open()
85 return c->fd; in cache_open()
93 c->filename = buffername; in cache_open()
95 return ffurl_open_whitelist(&c->inner, arg, flags, &h->interrupt_callback, in cache_open()
96 options, h->protocol_whitelist, h->protocol_blacklist, h); in cache_open()
101 Context *c= h->priv_data; in add_entry()
102 int64_t pos = -1; in add_entry()
104 CacheEntry *entry = NULL, *next[2] = {NULL, NULL}; in add_entry() local
109 pos = lseek(c->fd, 0, SEEK_END); in add_entry()
112 av_log(h, AV_LOG_ERROR, "seek in cache failed\n"); in add_entry()
115 c->cache_pos = pos; in add_entry()
117 ret = write(c->fd, buf, size); in add_entry()
120 av_log(h, AV_LOG_ERROR, "write in cache failed\n"); in add_entry()
123 c->cache_pos += ret; in add_entry()
125 entry = av_tree_find(c->root, &c->logical_pos, cmp, (void**)next); in add_entry()
127 if (!entry) in add_entry()
128 entry = next[0]; in add_entry()
130 if (!entry || in add_entry()
131 entry->logical_pos + entry->size != c->logical_pos || in add_entry()
132 entry->physical_pos + entry->size != pos in add_entry()
134 entry = av_malloc(sizeof(*entry)); in add_entry()
136 if (!entry || !node) { in add_entry()
140 entry->logical_pos = c->logical_pos; in add_entry()
141 entry->physical_pos = pos; in add_entry()
142 entry->size = ret; in add_entry()
144 entry_ret = av_tree_insert(&c->root, entry, cmp, &node); in add_entry()
145 if (entry_ret && entry_ret != entry) { in add_entry()
146 ret = -1; in add_entry()
151 entry->size += ret; in add_entry()
155 //we could truncate the file to pos here if pos >=0 but ftruncate isn't available in VS so in add_entry()
156 //for simplicty we just leave the file a bit larger in add_entry()
157 av_free(entry); in add_entry()
164 Context *c= h->priv_data; in cache_read()
165 CacheEntry *entry, *next[2] = {NULL, NULL}; in cache_read() local
168 entry = av_tree_find(c->root, &c->logical_pos, cmp, (void**)next); in cache_read()
170 if (!entry) in cache_read()
171 entry = next[0]; in cache_read()
173 if (entry) { in cache_read()
174 int64_t in_block_pos = c->logical_pos - entry->logical_pos; in cache_read()
175 av_assert0(entry->logical_pos <= c->logical_pos); in cache_read()
176 if (in_block_pos < entry->size) { in cache_read()
177 int64_t physical_target = entry->physical_pos + in_block_pos; in cache_read()
179 if (c->cache_pos != physical_target) { in cache_read()
180 r = lseek(c->fd, physical_target, SEEK_SET); in cache_read()
182 r = c->cache_pos; in cache_read()
185 c->cache_pos = r; in cache_read()
186 r = read(c->fd, buf, FFMIN(size, entry->size - in_block_pos)); in cache_read()
190 c->cache_pos += r; in cache_read()
191 c->logical_pos += r; in cache_read()
192 c->cache_hit ++; in cache_read()
198 // Cache miss or some kind of fault with the cache in cache_read()
200 if (c->logical_pos != c->inner_pos) { in cache_read()
201 r = ffurl_seek(c->inner, c->logical_pos, SEEK_SET); in cache_read()
206 c->inner_pos = r; in cache_read()
209 r = ffurl_read(c->inner, buf, size); in cache_read()
211 c->is_true_eof = 1; in cache_read()
212 av_assert0(c->end >= c->logical_pos); in cache_read()
216 c->inner_pos += r; in cache_read()
218 c->cache_miss ++; in cache_read()
221 c->logical_pos += r; in cache_read()
222 c->end = FFMAX(c->end, c->logical_pos); in cache_read()
229 Context *c= h->priv_data; in cache_seek()
233 pos= ffurl_seek(c->inner, pos, whence); in cache_seek()
235 pos= ffurl_seek(c->inner, -1, SEEK_END); in cache_seek()
236 if (ffurl_seek(c->inner, c->inner_pos, SEEK_SET) < 0) in cache_seek()
240 c->is_true_eof = 1; in cache_seek()
241 c->end = FFMAX(c->end, pos); in cache_seek()
247 pos += c->logical_pos; in cache_seek()
248 } else if (whence == SEEK_END && c->is_true_eof) { in cache_seek()
251 pos += c->end; in cache_seek()
254 if (whence == SEEK_SET && pos >= 0 && pos < c->end) { in cache_seek()
256 c->logical_pos = pos; in cache_seek()
260 //cache miss in cache_seek()
261 ret= ffurl_seek(c->inner, pos, whence); in cache_seek()
262 if ((whence == SEEK_SET && pos >= c->logical_pos || in cache_seek()
264 if ( (whence == SEEK_SET && c->read_ahead_limit >= pos - c->logical_pos) in cache_seek()
265 || c->read_ahead_limit < 0) { in cache_seek()
267 while (c->logical_pos < pos || whence == SEEK_END) { in cache_seek()
270 size = FFMIN(sizeof(tmp), pos - c->logical_pos); in cache_seek()
273 av_assert0(c->is_true_eof); in cache_seek()
280 return c->logical_pos; in cache_seek()
285 c->logical_pos = ret; in cache_seek()
286 c->end = FFMAX(c->end, ret); in cache_seek()
300 Context *c= h->priv_data; in cache_close()
303 av_log(h, AV_LOG_INFO, "Statistics, cache hits:%"PRId64" cache misses:%"PRId64"\n", in cache_close()
304 c->cache_hit, c->cache_miss); in cache_close()
306 close(c->fd); in cache_close()
307 if (c->filename) { in cache_close()
308 ret = unlink(c->filename); in cache_close()
310 av_log(h, AV_LOG_ERROR, "Could not delete %s.\n", c->filename); in cache_close()
311 av_freep(&c->filename); in cache_close()
313 ffurl_closep(&c->inner); in cache_close()
314 av_tree_enumerate(c->root, NULL, NULL, enu_free); in cache_close()
315 av_tree_destroy(c->root); in cache_close()
324 …ahead when seeking isn't supported, -1 for unlimited", OFFSET(read_ahead_limit), AV_OPT_TYPE_INT, …
329 .class_name = "cache",
336 .name = "cache",