diff --git a/daemon/cli.c b/daemon/cli.c index a3c86f201..b468e640f 100644 --- a/daemon/cli.c +++ b/daemon/cli.c @@ -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"); diff --git a/daemon/media_player.c b/daemon/media_player.c index b3dea6c51..ca607131d 100644 --- a/daemon/media_player.c +++ b/daemon/media_player.c @@ -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; +} diff --git a/include/media_player.h b/include/media_player.h index 56bf115e7..6e9cd3977 100644 --- a/include/media_player.h +++ b/include/media_player.h @@ -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 *); diff --git a/utils/rtpengine-ctl b/utils/rtpengine-ctl index 2e665e168..1399dbc31 100755 --- a/utils/rtpengine-ctl +++ b/utils/rtpengine-ctl @@ -173,6 +173,8 @@ sub showusage { print " files : reload all media files currently in memory\n"; print " db : reload one media entry from database into memory\n"; print " dbs : reload all media entries from database currently in memory\n"; + print " cache : reload one database media entry into file cache\n"; + print " caches : reload all database media entries currently in file cache\n"; print " evict