diff --git a/daemon/cli.c b/daemon/cli.c index b468e640f..9eb4c433d 100644 --- a/daemon/cli.c +++ b/daemon/cli.c @@ -120,6 +120,10 @@ static void cli_incoming_media_reload_dbs(str *instr, struct cli_writer *cw, con 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_add_file(str *instr, struct cli_writer *cw, const cli_handler_t *); +static void cli_incoming_media_add_db(str *instr, struct cli_writer *cw, const cli_handler_t *); +static void cli_incoming_media_add_cache(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 *); static void cli_incoming_media_evict_db(str *instr, struct cli_writer *cw, const cli_handler_t *); @@ -205,6 +209,12 @@ static const cli_handler_t cli_media_list_handlers[] = { { "caches", cli_incoming_media_list_caches, NULL }, { NULL, }, }; +static const cli_handler_t cli_media_add_handlers[] = { + { "file", cli_incoming_media_add_file, NULL }, + { "db", cli_incoming_media_add_db, NULL }, + { "cache", cli_incoming_media_add_cache, NULL }, + { NULL, }, +}; static const cli_handler_t cli_media_reload_handlers[] = { { "file", cli_incoming_media_reload_file, NULL }, { "files", cli_incoming_media_reload_files, NULL }, @@ -225,6 +235,7 @@ static const cli_handler_t cli_media_evict_handlers[] = { }; static const cli_handler_t cli_media_handlers[] = { { "list", cli_generic_handler, cli_media_list_handlers }, + { "add", cli_generic_handler, cli_media_add_handlers }, { "reload", cli_generic_handler, cli_media_reload_handlers }, { "evict", cli_generic_handler, cli_media_evict_handlers }, { NULL, }, @@ -1829,6 +1840,19 @@ static void cli_incoming_media_list_dbs(str *instr, struct cli_writer *cw, const } } +static void cli_incoming_media_add_file(str *instr, struct cli_writer *cw, const cli_handler_t *handler) { + if (instr->len == 0) { + cw->cw_printf(cw, "More parameters required.\n"); + return ; + } + + bool ok = media_player_add_cached_file(instr); + 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_file(str *instr, struct cli_writer *cw, const cli_handler_t *handler) { if (instr->len == 0) { cw->cw_printf(cw, "More parameters required.\n"); @@ -1847,6 +1871,24 @@ static void cli_incoming_media_reload_files(str *instr, struct cli_writer *cw, c cw->cw_printf(cw, "%u media files reloaded\n", num); } +static void cli_incoming_media_add_db(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_add_db_media(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_db(str *instr, struct cli_writer *cw, const cli_handler_t *handler) { if (instr->len == 0) { cw->cw_printf(cw, "More parameters required.\n"); @@ -1870,6 +1912,24 @@ 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_add_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_add_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_cache(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 1c6f91e8d..02730a126 100644 --- a/daemon/media_player.c +++ b/daemon/media_player.c @@ -2141,6 +2141,33 @@ bool media_player_preload_db(char **ids) { return true; } +bool media_player_add_cached_file(str *name) { + bool ret = false; + +#ifdef WITH_TRANSCODING + __auto_type fonew = media_player_media_file_read_str(name); + if (!fonew) + return false; + + RWLOCK_W(&media_player_media_files_names_lock); + LOCK(&media_player_media_files_lock); + __auto_type foold = t_hash_table_lookup(media_player_media_files, name); + if (foold) { + fonew->str_link = foold->str_link; + t_hash_table_replace(media_player_media_files, name, fonew); + obj_put(foold); + } + else + media_player_media_files_insert(name, fonew); + + ilog(LOG_DEBUG, "Added cached media file '" STR_FORMAT "'", + STR_FMT(name)); + ret = true; +#endif + + return ret; +} + bool media_player_reload_file(str *name) { bool ret = false; @@ -2198,6 +2225,32 @@ unsigned int media_player_reload_files(void) { return ret; } +bool media_player_add_db_media(unsigned long long id) { + bool ret = false; + +#ifdef WITH_TRANSCODING + __auto_type fonew = media_player_db_id_read(id); + if (!fonew) + return false; + + RWLOCK_W(&media_player_db_media_ids_lock); + LOCK(&media_player_db_media_lock); + __auto_type foold = t_hash_table_lookup(media_player_db_media, GUINT_TO_POINTER(id)); + if (foold) { + fonew->gen_link = foold->gen_link; + t_hash_table_replace(media_player_db_media, GUINT_TO_POINTER(id), fonew); + obj_put(foold); + } + else + media_player_db_id_insert(id, fonew); + + ilog(LOG_DEBUG, "Added cached media DB entry %llu", id); + ret = true; +#endif + + return ret; +} + bool media_player_reload_db_media(unsigned long long id) { bool ret = false; @@ -2494,6 +2547,20 @@ bool media_player_preload_cache(char **ids) { return true; } +bool media_player_add_cache(unsigned long long id) { + bool ret = false; + +#ifdef WITH_TRANSCODING + 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; +} + bool media_player_reload_cache(unsigned long long id) { bool ret = false; diff --git a/include/media_player.h b/include/media_player.h index 35a5fce39..3116fd2da 100644 --- a/include/media_player.h +++ b/include/media_player.h @@ -150,8 +150,10 @@ void media_player_init(void); void media_player_free(void); void media_player_launch(void); bool media_player_preload_files(char **); +bool media_player_add_cached_file(str *name); bool media_player_reload_file(str *name); unsigned int media_player_reload_files(void); +bool media_player_add_db_media(unsigned long long); bool media_player_reload_db_media(unsigned long long); unsigned int media_player_reload_db_medias(void); enum thread_looper_action media_player_refresh_timer(void); @@ -167,6 +169,7 @@ 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_add_cache(unsigned long long); bool media_player_reload_cache(unsigned long long); unsigned int media_player_reload_caches(void); enum thread_looper_action media_player_refresh_cache(void); diff --git a/utils/rtpengine-ctl b/utils/rtpengine-ctl index 1399dbc31..f7f3bd9d9 100755 --- a/utils/rtpengine-ctl +++ b/utils/rtpengine-ctl @@ -175,6 +175,10 @@ sub showusage { 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 " add