diff options
Diffstat (limited to 'demux/cache.c')
-rw-r--r-- | demux/cache.c | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/demux/cache.c b/demux/cache.c index 4404c870de..6398f61823 100644 --- a/demux/cache.c +++ b/demux/cache.c @@ -26,6 +26,7 @@ #include "common/msg.h" #include "common/av_common.h" #include "demux.h" +#include "misc/io_utils.h" #include "options/path.h" #include "options/m_config.h" #include "options/m_option.h" @@ -40,9 +41,12 @@ struct demux_cache_opts { const struct m_sub_options demux_cache_conf = { .opts = (const struct m_option[]){ - OPT_STRING("cache-dir", cache_dir, M_OPT_FILE), - OPT_CHOICE("cache-unlink-files", unlink_files, 0, - ({"immediate", 2}, {"whendone", 1}, {"no", 0})), + {"demuxer-cache-dir", OPT_STRING(cache_dir), .flags = M_OPT_FILE}, + {"demuxer-cache-unlink-files", OPT_CHOICE(unlink_files, + {"immediate", 2}, {"whendone", 1}, {"no", 0}), + }, + {"cache-dir", OPT_REPLACED("demuxer-cache-dir")}, + {"cache-unlink-files", OPT_REPLACED("demuxer-cache-unlink-files")}, {0} }, .size = sizeof(struct demux_cache_opts), @@ -99,11 +103,16 @@ struct demux_cache *demux_cache_create(struct mpv_global *global, cache->fd = -1; char *cache_dir = cache->opts->cache_dir; - if (!(cache_dir && cache_dir[0])) { - MP_ERR(cache, "No cache data directory supplied.\n"); - goto fail; + if (cache_dir && cache_dir[0]) { + cache_dir = mp_get_user_path(NULL, global, cache_dir); + } else { + cache_dir = mp_find_user_file(NULL, global, "cache", ""); } + if (!cache_dir || !cache_dir[0]) + goto fail; + + mp_mkdirp(cache_dir); cache->filename = mp_path_join(cache, cache_dir, "mpv-cache-XXXXXX.dat"); cache->fd = mp_mkostemps(cache->filename, 4, O_CLOEXEC); if (cache->fd < 0) { @@ -206,7 +215,7 @@ int64_t demux_cache_write(struct demux_cache *cache, struct demux_packet *dp) } assert(!dp->is_cached); - assert(dp->len >= 0 && dp->len <= INT32_MAX); + assert(dp->len <= INT32_MAX); assert(dp->avpacket->flags >= 0 && dp->avpacket->flags <= INT32_MAX); assert(dp->avpacket->side_data_elems >= 0 && dp->avpacket->side_data_elems <= INT32_MAX); @@ -252,7 +261,7 @@ int64_t demux_cache_write(struct demux_cache *cache, struct demux_packet *dp) for (int n = 0; n < dp->avpacket->side_data_elems; n++) { AVPacketSideData *sd = &dp->avpacket->side_data[n]; - assert(sd->size >= 0 && sd->size <= INT32_MAX); + assert(sd->size <= INT32_MAX); assert(sd->type >= 0 && sd->type <= INT32_MAX); struct sd_header sd_hd = { @@ -285,9 +294,6 @@ struct demux_packet *demux_cache_read(struct demux_cache *cache, uint64_t pos) if (!read_raw(cache, &hd, sizeof(hd))) return NULL; - if (hd.data_len >= (size_t)-1) - return NULL; - struct demux_packet *dp = new_demux_packet(hd.data_len); if (!dp) goto fail; |