From 40bb74ad52913aafff5650f11f6f6d6f3e7b616c Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Mon, 6 Jan 2025 11:39:23 -0400 Subject: [PATCH] MT#61822 add db-media-reload option Change-Id: I50dbd868eeea2dd15d6cf95f5b80d5b4183f7d10 --- daemon/main.c | 4 ++++ daemon/media_player.c | 9 +++++++++ docs/rtpengine.md | 7 +++++++ etc/rtpengine.conf | 1 + include/main.h | 1 + include/media_player.h | 1 + 6 files changed, 23 insertions(+) diff --git a/daemon/main.c b/daemon/main.c index 1473045ea..b45fda146 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -676,6 +676,7 @@ static void options(int *argc, char ***argv, GHashTable *templates) { { "preload-media-files",0,0,G_OPTION_ARG_FILENAME_ARRAY,&rtpe_config.preload_media_files,"Preload media file(s) for playback into memory","FILE"}, { "media-files-reload",0,0,G_OPTION_ARG_INT, &rtpe_config.media_refresh,"Refresh/reload preloaded media files at a certain interval","SECONDS"}, { "preload-db-media",0,0,G_OPTION_ARG_STRING_ARRAY,&rtpe_config.preload_db_media,"Preload media from database for playback into memory","INT"}, + { "db-media-reload",0,0,G_OPTION_ARG_INT, &rtpe_config.db_refresh,"Reload preloaded media from DB at a certain interval","SECONDS"}, { "audio-buffer-length",0,0, G_OPTION_ARG_INT,&rtpe_config.audio_buffer_length,"Length in milliseconds of audio buffer","INT"}, { "audio-buffer-delay",0,0, G_OPTION_ARG_INT,&rtpe_config.audio_buffer_delay,"Initial delay in milliseconds for buffered audio","INT"}, { "audio-player",0,0, G_OPTION_ARG_STRING, &use_audio_player, "When to enable the internal audio player","on-demand|play-media|transcoding|always"}, @@ -1594,6 +1595,9 @@ int main(int argc, char **argv) { thread_create_looper(media_player_refresh_timer, rtpe_config.idle_scheduling, rtpe_config.idle_priority, "media refresh", rtpe_config.media_refresh * 1000000LL); + thread_create_looper(media_player_refresh_db, rtpe_config.idle_scheduling, + rtpe_config.idle_priority, "db refresh", rtpe_config.db_refresh * 1000000LL); + if (!is_addr_unspecified(&rtpe_config.redis_ep.address) && initial_rtpe_config.redis_delete_async) thread_create_detach(redis_delete_async_loop, NULL, "redis async"); diff --git a/daemon/media_player.c b/daemon/media_player.c index 2b7b245eb..79475a9fc 100644 --- a/daemon/media_player.c +++ b/daemon/media_player.c @@ -2178,3 +2178,12 @@ enum thread_looper_action media_player_refresh_timer(void) { return TLA_CONTINUE; } + +enum thread_looper_action media_player_refresh_db(void) { + if (rtpe_config.db_refresh <= 0) + return TLA_BREAK; + + media_player_reload_db_medias(); + + return TLA_CONTINUE; +} diff --git a/docs/rtpengine.md b/docs/rtpengine.md index 2cd9b81da..271ece8d3 100644 --- a/docs/rtpengine.md +++ b/docs/rtpengine.md @@ -1178,6 +1178,13 @@ call to inject-DTMF won't be sent to __\-\-dtmf-log-dest=__ or __\-\-listen-tcp- database instead of reading them from files. Each entry must be an integer corresponding to an index from the database. +- __\-\-db-media-reload=__*SECONDS* + + Similar to the __media-files-reload__ but applicable to media loaded from + database. Note that media stored in a database doesn't have a modification + timestamp, which means that all media will always be reloaded from the + database in the given interval. + - __\-\-audio-buffer-length=__*INT* Set the buffer length used by the audio player (see below) in milliseconds. The diff --git a/etc/rtpengine.conf b/etc/rtpengine.conf index 1540ffd22..9577e3e48 100644 --- a/etc/rtpengine.conf +++ b/etc/rtpengine.conf @@ -168,6 +168,7 @@ recording-method = proc # preload-media-files = /var/media/file1.wav ; /var/media/file2.wav ; /var/media/file3.wav ; on-demand # media-files-reload = 60 # preload-db-media = 1; 2; 3; 4 +# db-media-reload = 3600 # signalling templates (see key `templates` above) [templates] diff --git a/include/main.h b/include/main.h index 3bbac7156..8862b9a42 100644 --- a/include/main.h +++ b/include/main.h @@ -94,6 +94,7 @@ enum endpoint_learning { X(cpu_affinity) \ X(max_recv_iters) \ X(media_refresh) \ + X(db_refresh) \ #define RTPE_CONFIG_UINT64_PARAMS \ X(bw_limit) diff --git a/include/media_player.h b/include/media_player.h index d688196df..23927973f 100644 --- a/include/media_player.h +++ b/include/media_player.h @@ -156,6 +156,7 @@ 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); bool media_player_preload_db(char **); +enum thread_looper_action media_player_refresh_db(void); struct send_timer *send_timer_new(struct packet_stream *); void send_timer_push(struct send_timer *, struct codec_packet *);