Browse Source

MT#61822 add CLI cmd to add cached media

Change-Id: I749833d1548069444b36d1933a56080eebf9583d
pull/1897/head
Richard Fuchs 11 months ago
parent
commit
e6172c34a2
4 changed files with 134 additions and 0 deletions
  1. +60
    -0
      daemon/cli.c
  2. +67
    -0
      daemon/media_player.c
  3. +3
    -0
      include/media_player.h
  4. +4
    -0
      utils/rtpengine-ctl

+ 60
- 0
daemon/cli.c View File

@ -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");


+ 67
- 0
daemon/media_player.c View File

@ -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;


+ 3
- 0
include/media_player.h View File

@ -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);


+ 4
- 0
utils/rtpengine-ctl View File

@ -175,6 +175,10 @@ sub showusage {
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 " add <option>\n";
print " file <file name> : add media file into memory\n";
print " db <index> : add media entry from database into memory\n";
print " cache <index> : add database media entry into 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