|
|
|
@ -98,8 +98,8 @@ struct media_player_media_file { |
|
|
|
str_list *str_link; |
|
|
|
GList *gen_link; |
|
|
|
}; |
|
|
|
time_t mtime; |
|
|
|
time_t atime; |
|
|
|
int64_t mtime_us; |
|
|
|
int64_t atime_us; |
|
|
|
}; |
|
|
|
|
|
|
|
static mutex_t media_player_cache_lock = MUTEX_STATIC_INIT; |
|
|
|
@ -1253,7 +1253,7 @@ static struct media_player_media_file *media_player_media_file_new(str blob) { |
|
|
|
fo->blob = blob; |
|
|
|
fo->blob.dup = call_ref; // string is allocated by reference on `fo` |
|
|
|
RTPE_GAUGE_ADD(media_cache, blob.len); |
|
|
|
fo->atime = fo->mtime = timeval_from_us(rtpe_now).tv_sec; |
|
|
|
fo->atime_us = fo->mtime_us = rtpe_now; |
|
|
|
return fo; |
|
|
|
} |
|
|
|
|
|
|
|
@ -1302,7 +1302,7 @@ static struct media_player_media_file *media_player_media_files_get_only(const s |
|
|
|
return NULL; |
|
|
|
|
|
|
|
obj_hold(fo); |
|
|
|
fo->atime = timeval_from_us(rtpe_now).tv_sec; |
|
|
|
fo->atime_us = rtpe_now; |
|
|
|
} |
|
|
|
|
|
|
|
return fo; |
|
|
|
@ -1321,7 +1321,7 @@ static struct media_player_media_file *media_player_db_id_get_only(unsigned long |
|
|
|
return NULL; |
|
|
|
|
|
|
|
obj_hold(fo); |
|
|
|
fo->atime = timeval_from_us(rtpe_now).tv_sec; |
|
|
|
fo->atime_us = rtpe_now; |
|
|
|
} |
|
|
|
|
|
|
|
return fo; |
|
|
|
@ -2267,7 +2267,7 @@ bool media_player_reload_file(str *name) { |
|
|
|
if (fail) |
|
|
|
ilog(LOG_WARN, "Failed to stat() media file '" STR_FORMAT "': %s", |
|
|
|
STR_FMT(name), strerror(errno)); |
|
|
|
else if (sb.st_mtim.tv_sec > fo->mtime) { |
|
|
|
else if (timespec_us(sb.st_mtim) > fo->mtime_us) { |
|
|
|
__auto_type fonew = media_player_media_file_read_c(file_s); |
|
|
|
if (fonew) { |
|
|
|
// got a new entry. swap it out against the old one |
|
|
|
@ -2518,28 +2518,28 @@ GQueue media_player_list_dbs(void) { |
|
|
|
return ret; |
|
|
|
} |
|
|
|
|
|
|
|
bool media_player_get_file_times(const str *s, time_t *mtime, time_t *atime) { |
|
|
|
bool media_player_get_file_times(const str *s, int64_t *mtime, int64_t *atime) { |
|
|
|
#ifdef WITH_TRANSCODING |
|
|
|
LOCK(&media_player_media_files_lock); |
|
|
|
__auto_type fo = t_hash_table_lookup(media_player_media_files, s); |
|
|
|
if (!fo) |
|
|
|
return false; |
|
|
|
*mtime = fo->mtime; |
|
|
|
*atime = fo->atime; |
|
|
|
*mtime = fo->mtime_us / 1000000L; |
|
|
|
*atime = fo->atime_us / 1000000L; |
|
|
|
return true; |
|
|
|
#else |
|
|
|
return false; |
|
|
|
#endif |
|
|
|
} |
|
|
|
|
|
|
|
bool media_player_get_db_times(unsigned long long id, time_t *mtime, time_t *atime) { |
|
|
|
bool media_player_get_db_times(unsigned long long id, int64_t *mtime, int64_t *atime) { |
|
|
|
#ifdef WITH_TRANSCODING |
|
|
|
LOCK(&media_player_db_media_lock); |
|
|
|
__auto_type fo = t_hash_table_lookup(media_player_db_media, GUINT_TO_POINTER(id)); |
|
|
|
if (!fo) |
|
|
|
return false; |
|
|
|
*mtime = fo->mtime; |
|
|
|
*atime = fo->atime; |
|
|
|
*mtime = fo->mtime_us / 1000000L; |
|
|
|
*atime = fo->atime_us / 1000000L; |
|
|
|
return true; |
|
|
|
#else |
|
|
|
return false; |
|
|
|
@ -2587,7 +2587,7 @@ GQueue media_player_list_caches(void) { |
|
|
|
return ret; |
|
|
|
} |
|
|
|
|
|
|
|
bool media_player_get_cache_times(unsigned long long id, time_t *mtime, time_t *atime) { |
|
|
|
bool media_player_get_cache_times(unsigned long long id, int64_t *mtime, int64_t *atime) { |
|
|
|
#ifdef WITH_TRANSCODING |
|
|
|
g_autoptr(char) fn = media_player_make_cache_entry_name(id); |
|
|
|
struct stat sb; |
|
|
|
@ -2764,7 +2764,7 @@ static void media_player_expire_files(void) { |
|
|
|
if (rtpe_config.media_expire <= 0) |
|
|
|
return; |
|
|
|
|
|
|
|
time_t limit = timeval_from_us(rtpe_now).tv_sec - rtpe_config.media_expire; |
|
|
|
int64_t limit = rtpe_now - rtpe_config.media_expire * 1000000L; // XXX scale to micro |
|
|
|
unsigned int num = 0; |
|
|
|
|
|
|
|
{ |
|
|
|
@ -2778,7 +2778,7 @@ static void media_player_expire_files(void) { |
|
|
|
__auto_type fo = t_hash_table_lookup(media_player_media_files, l->data); |
|
|
|
if (!fo) |
|
|
|
continue; |
|
|
|
if (fo->atime >= limit) |
|
|
|
if (fo->atime_us >= limit) |
|
|
|
continue; |
|
|
|
name = str_dup_str(l->data); |
|
|
|
} |
|
|
|
@ -2795,7 +2795,7 @@ static void media_player_expire_dbs(void) { |
|
|
|
if (rtpe_config.db_expire <= 0) |
|
|
|
return; |
|
|
|
|
|
|
|
time_t limit = timeval_from_us(rtpe_now).tv_sec - rtpe_config.db_expire; |
|
|
|
int64_t limit = rtpe_now - rtpe_config.db_expire * 1000000L; // XXX scale to micro |
|
|
|
unsigned int num = 0; |
|
|
|
|
|
|
|
{ |
|
|
|
@ -2809,7 +2809,7 @@ static void media_player_expire_dbs(void) { |
|
|
|
__auto_type fo = t_hash_table_lookup(media_player_db_media, l->data); |
|
|
|
if (!fo) |
|
|
|
continue; |
|
|
|
if (fo->atime >= limit) |
|
|
|
if (fo->atime_us >= limit) |
|
|
|
continue; |
|
|
|
id = GPOINTER_TO_UINT(l->data); |
|
|
|
} |
|
|
|
@ -2823,10 +2823,10 @@ static void media_player_expire_dbs(void) { |
|
|
|
} |
|
|
|
|
|
|
|
static void media_player_expire_cache_entry(unsigned long long id, unsigned int *num) { |
|
|
|
time_t mtime, atime; |
|
|
|
int64_t mtime, atime; |
|
|
|
if (!media_player_get_cache_times(id, &mtime, &atime)) |
|
|
|
return; |
|
|
|
time_t limit = timeval_from_us(rtpe_now).tv_sec - rtpe_config.db_expire; |
|
|
|
int64_t limit = rtpe_now - rtpe_config.db_expire * 1000000L; // XXX scale to micro |
|
|
|
if (atime >= limit) |
|
|
|
return; |
|
|
|
if (media_player_evict_cache(id)) |
|
|
|
|