MT#61822 support reloading of FS cache

Change-Id: I028a9f8ffb6ff51f753744fc39d0a5c0b19a9e7b
pull/1897/head
Richard Fuchs 4 months ago
parent ff16ac27f5
commit 8286cc93b9

@ -117,6 +117,8 @@ static void cli_incoming_media_reload_file(str *instr, struct cli_writer *cw, co
static void cli_incoming_media_reload_files(str *instr, struct cli_writer *cw, const cli_handler_t *);
static void cli_incoming_media_reload_db(str *instr, struct cli_writer *cw, const cli_handler_t *);
static void cli_incoming_media_reload_dbs(str *instr, struct cli_writer *cw, const cli_handler_t *);
static void cli_incoming_media_reload_cache(str *instr, struct cli_writer *cw, const cli_handler_t *);
static void cli_incoming_media_reload_caches(str *instr, struct cli_writer *cw, const cli_handler_t *);
static void cli_incoming_media_evict_file(str *instr, struct cli_writer *cw, const cli_handler_t *);
static void cli_incoming_media_evict_files(str *instr, struct cli_writer *cw, const cli_handler_t *);
@ -208,6 +210,8 @@ static const cli_handler_t cli_media_reload_handlers[] = {
{ "files", cli_incoming_media_reload_files, NULL },
{ "db", cli_incoming_media_reload_db, NULL },
{ "dbs", cli_incoming_media_reload_dbs, NULL },
{ "cache", cli_incoming_media_reload_cache, NULL },
{ "caches", cli_incoming_media_reload_caches, NULL },
{ NULL, },
};
static const cli_handler_t cli_media_evict_handlers[] = {
@ -1866,6 +1870,29 @@ static void cli_incoming_media_reload_dbs(str *instr, struct cli_writer *cw, con
cw->cw_printf(cw, "%u media entries reloaded\n", num);
}
static void cli_incoming_media_reload_cache(str *instr, struct cli_writer *cw, const cli_handler_t *handler) {
if (instr->len == 0) {
cw->cw_printf(cw, "More parameters required.\n");
return ;
}
unsigned long long id = str_to_ui(instr, 0);
if (id == 0 || id == ULLONG_MAX)
cw->cw_printf(cw, "Invalid ID '" STR_FORMAT "'\n", STR_FMT(instr));
else {
bool ok = media_player_reload_cache(id);
if (ok)
cw->cw_printf(cw, "Success\n");
else
cw->cw_printf(cw, "Failed to reload '" STR_FORMAT "'\n", STR_FMT(instr));
}
}
static void cli_incoming_media_reload_caches(str *instr, struct cli_writer *cw, const cli_handler_t *handler) {
unsigned int num = media_player_reload_caches();
cw->cw_printf(cw, "%u media entries reloaded\n", num);
}
static void cli_incoming_media_evict_file(str *instr, struct cli_writer *cw, const cli_handler_t *handler) {
if (instr->len == 0) {
cw->cw_printf(cw, "More parameters required.\n");

@ -2488,3 +2488,33 @@ bool media_player_preload_cache(char **ids) {
return true;
}
bool media_player_reload_cache(unsigned long long id) {
bool ret = false;
#ifdef WITH_TRANSCODING
// "reload" implies that the file has to exist already
g_autoptr(char) fn = media_player_make_cache_entry_name(id);
if (!g_file_test(fn, G_FILE_TEST_EXISTS))
return false;
str out;
const char *err = media_player_get_db_id(&out, id, dummy_dup,
media_player_add_cache_file_create);
if (!err)
ret = true;
#endif
return ret;
}
static void media_player_reload_caches_all(unsigned long long id, unsigned int *u) {
if (media_player_reload_cache(id))
(*u)++;
}
unsigned int media_player_reload_caches(void) {
unsigned int ret = 0;
media_player_iterate_db_cache(media_player_reload_caches_all, &ret);
return ret;
}

@ -167,6 +167,8 @@ GQueue media_player_list_caches(void);
bool media_player_evict_cache(unsigned long long);
unsigned int media_player_evict_caches(void);
bool media_player_preload_cache(char **);
bool media_player_reload_cache(unsigned long long);
unsigned int media_player_reload_caches(void);
struct send_timer *send_timer_new(struct packet_stream *);
void send_timer_push(struct send_timer *, struct codec_packet *);

@ -173,6 +173,8 @@ sub showusage {
print " files : reload all media files currently in memory\n";
print " db <index> : reload one media entry from database into memory\n";
print " dbs : reload all media entries from database currently in memory\n";
print " cache <index> : reload one database media entry into file cache\n";
print " caches : reload all database media entries currently in file cache\n";
print " evict <option>\n";
print " file <file name> : remove one media file from memory\n";
print " files : remove all media files from memory\n";

Loading…
Cancel
Save