MT#61822 support evicting player cache data

Change-Id: I58c1127f2b906a3e238a2dc8579d433abe72c50b
pull/1897/head
Richard Fuchs 4 months ago
parent 601abd2e5b
commit d436c1d361

@ -131,6 +131,7 @@ static void cli_incoming_media_evict_db(str *instr, struct cli_writer *cw, const
static void cli_incoming_media_evict_dbs(str *instr, struct cli_writer *cw, const cli_handler_t *);
static void cli_incoming_media_evict_cache(str *instr, struct cli_writer *cw, const cli_handler_t *);
static void cli_incoming_media_evict_caches(str *instr, struct cli_writer *cw, const cli_handler_t *);
static void cli_incoming_media_evict_players(str *instr, struct cli_writer *cw, const cli_handler_t *);
#endif
@ -233,6 +234,7 @@ static const cli_handler_t cli_media_evict_handlers[] = {
{ "dbs", cli_incoming_media_evict_dbs, NULL },
{ "cache", cli_incoming_media_evict_cache, NULL },
{ "caches", cli_incoming_media_evict_caches, NULL },
{ "players", cli_incoming_media_evict_players, NULL },
{ NULL, },
};
static const cli_handler_t cli_media_handlers[] = {
@ -2035,4 +2037,9 @@ static void cli_incoming_media_evict_caches(str *instr, struct cli_writer *cw, c
unsigned int num = media_player_evict_caches();
cw->cw_printf(cw, "%u DB cache entries evicted\n", num);
}
static void cli_incoming_media_evict_players(str *instr, struct cli_writer *cw, const cli_handler_t *handler) {
unsigned int num = media_player_evict_player_caches();
cw->cw_printf(cw, "%u DB cache entries evicted\n", num);
}
#endif

@ -108,6 +108,7 @@ static void __media_player_cache_entry_free(struct media_player_cache_entry *p);
TYPED_GHASHTABLE(media_player_cache_ht, struct media_player_cache_index, struct media_player_cache_entry,
media_player_cache_entry_hash, media_player_cache_entry_eq,
NULL, __obj_put)
TYPED_GQUEUE(media_player_cache_entry, struct media_player_cache_entry)
static media_player_cache_ht media_player_cache; // keys and values only ever freed at shutdown
TYPED_GHASHTABLE(media_player_media_files_ht, str, struct media_player_media_file, str_hash, str_equal,
@ -663,6 +664,7 @@ static void media_player_cached_reader_start(struct media_player *mp, str_case_v
static void cache_packet_free(struct media_player_cache_packet *p) {
RTPE_GAUGE_ADD(player_cache, -1 * (ssize_t) p->s.len);
bufferpool_unref(p->buf);
g_slice_free1(sizeof(*p), p);
}
@ -2632,3 +2634,41 @@ charp_q media_player_list_player_cache(void) {
#endif
return ret;
}
#ifdef WITH_TRANSCODING
// lock must not be held
static bool media_player_evict_player_cache(struct media_player_cache_entry *entry) {
LOCK(&media_player_cache_lock);
if (t_hash_table_remove(media_player_cache, &entry->index))
return true;
return false;
}
#endif
unsigned int media_player_evict_player_caches(void) {
unsigned int ret = 0;
#ifdef WITH_TRANSCODING
if (!t_hash_table_is_set(media_player_cache))
return 0;
// grab references from hash table
media_player_cache_entry_q q = TYPED_GQUEUE_INIT;
media_player_cache_ht_iter iter;
{
LOCK(&media_player_cache_lock);
t_hash_table_iter_init(&iter, media_player_cache);
struct media_player_cache_entry *entry;
while (t_hash_table_iter_next(&iter, NULL, &entry))
t_queue_push_tail(&q, obj_get(entry));
}
// release references
while (q.head) {
__auto_type entry = t_queue_pop_head(&q);
if (media_player_evict_player_cache(entry))
ret++;
obj_put(entry);
}
#endif
return ret;
}

@ -174,6 +174,7 @@ bool media_player_reload_cache(unsigned long long);
unsigned int media_player_reload_caches(void);
enum thread_looper_action media_player_refresh_cache(void);
charp_q media_player_list_player_cache(void);
unsigned int media_player_evict_player_caches(void);
struct send_timer *send_timer_new(struct packet_stream *);
void send_timer_push(struct send_timer *, struct codec_packet *);

Loading…
Cancel
Save