Browse Source

MT#61822 supporting removing entries from FS cache

Change-Id: Ie358778ce5d8d6872bc4964367cf0ec22296934f
pull/1897/head
Richard Fuchs 11 months ago
parent
commit
0fd3ac73a8
4 changed files with 56 additions and 0 deletions
  1. +27
    -0
      daemon/cli.c
  2. +25
    -0
      daemon/media_player.c
  3. +2
    -0
      include/media_player.h
  4. +2
    -0
      utils/rtpengine-ctl

+ 27
- 0
daemon/cli.c View File

@ -122,6 +122,8 @@ static void cli_incoming_media_evict_file(str *instr, struct cli_writer *cw, con
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 *);
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 *);
#endif
@ -213,6 +215,8 @@ static const cli_handler_t cli_media_evict_handlers[] = {
{ "files", cli_incoming_media_evict_files, NULL },
{ "db", cli_incoming_media_evict_db, NULL },
{ "dbs", cli_incoming_media_evict_dbs, NULL },
{ "cache", cli_incoming_media_evict_cache, NULL },
{ "caches", cli_incoming_media_evict_caches, NULL },
{ NULL, },
};
static const cli_handler_t cli_media_handlers[] = {
@ -1910,4 +1914,27 @@ static void cli_incoming_media_list_caches(str *instr, struct cli_writer *cw, co
cw->cw_printf(cw, "%llu\n", (unsigned long long) GPOINTER_TO_UINT(id));
}
}
static void cli_incoming_media_evict_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_evict_cache(id);
if (ok)
cw->cw_printf(cw, "Success\n");
else
cw->cw_printf(cw, "Failed to evict '" STR_FORMAT "'\n", STR_FMT(instr));
}
}
static void cli_incoming_media_evict_caches(str *instr, struct cli_writer *cw, const cli_handler_t *handler) {
unsigned int num = media_player_evict_caches();
cw->cw_printf(cw, "%u DB cache entries evicted\n", num);
}
#endif

+ 25
- 0
daemon/media_player.c View File

@ -2379,6 +2379,7 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(DIR, closedir)
typedef union {
GQueue *q;
unsigned int *u;
} iterate_db_cache_arg __attribute__((__transparent_union__));
static void media_player_iterate_db_cache(void (*callback)(unsigned long long, iterate_db_cache_arg),
@ -2414,3 +2415,27 @@ GQueue media_player_list_caches(void) {
media_player_iterate_db_cache(media_player_add_to_queue, &ret);
return ret;
}
bool media_player_evict_cache(unsigned long long id) {
#ifdef WITH_TRANSCODING
g_autoptr(char) fn = media_player_make_cache_entry_name(id);
int ret = unlink(fn);
if (ret == 0)
return true;
if (errno == ENOENT) // ignore these
return false;
ilog(LOG_WARN, "Failed to unlink media cache file '%s': %s", fn, strerror(errno));
#endif
return false;
}
static void media_player_evict_caches_all(unsigned long long id, unsigned int *u) {
if (media_player_evict_cache(id))
(*u)++;
}
unsigned int media_player_evict_caches(void) {
unsigned int ret = 0;
media_player_iterate_db_cache(media_player_evict_caches_all, &ret);
return ret;
}

+ 2
- 0
include/media_player.h View File

@ -164,6 +164,8 @@ unsigned int media_player_evict_db_medias(void);
str_q media_player_list_files(void);
GQueue media_player_list_dbs(void);
GQueue media_player_list_caches(void);
bool media_player_evict_cache(unsigned long long);
unsigned int media_player_evict_caches(void);
struct send_timer *send_timer_new(struct packet_stream *);
void send_timer_push(struct send_timer *, struct codec_packet *);


+ 2
- 0
utils/rtpengine-ctl View File

@ -178,6 +178,8 @@ sub showusage {
print " files : remove all media files from memory\n";
print " db <index> : remove one database media entry from memory\n";
print " dbs : remove all database media entries from memory\n";
print " cache <index> : remove one database media entry from file cache\n";
print " caches : remove all database media entries from file cache\n";
print "\n";
print "\n";
print " Return Value:\n";


Loading…
Cancel
Save