diff --git a/daemon/main.c b/daemon/main.c index 3a064b3af..8ebe86a66 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -674,6 +674,7 @@ static void options(int *argc, char ***argv, GHashTable *templates) { { "kernel-player",0,0, G_OPTION_ARG_INT, &rtpe_config.kernel_player,"Max number of kernel media player streams","INT"}, { "kernel-player-media",0,0,G_OPTION_ARG_INT, &rtpe_config.kernel_player_media,"Max number of kernel media files","INT"}, { "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"}, { "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"}, @@ -1586,6 +1587,9 @@ int main(int argc, char **argv) { /* thread to refresh DTLS certificate */ dtls_timer(); + thread_create_looper(media_player_refresh_timer, rtpe_config.idle_scheduling, + rtpe_config.idle_priority, "media refresh", rtpe_config.media_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 da76cf786..3fafc51a6 100644 --- a/daemon/media_player.c +++ b/daemon/media_player.c @@ -1988,3 +1988,12 @@ unsigned int media_player_reload_files(void) { return ret; } + +enum thread_looper_action media_player_refresh_timer(void) { + if (rtpe_config.media_refresh <= 0) + return TLA_BREAK; + + media_player_reload_files(); + + return TLA_CONTINUE; +} diff --git a/docs/rtpengine.md b/docs/rtpengine.md index fd9b534a8..a15b028dd 100644 --- a/docs/rtpengine.md +++ b/docs/rtpengine.md @@ -1159,6 +1159,14 @@ call to inject-DTMF won't be sent to __\-\-dtmf-log-dest=__ or __\-\-listen-tcp- file name differs (or an entirely different file is requested for playback) then playback will happen from file as usual. +- __\-\-media-files-reload=__*SECONDS* + + Spawn a background thread to periodically check and, if needed, update + media files kept in the memory cache. Each file's modification timestamp is + checked against the last time it was read, and if the file was updated + since then, it will be re-read and will replace the previous cached + contents. + - __\-\-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 0049f99f5..338eb6a73 100644 --- a/etc/rtpengine.conf +++ b/etc/rtpengine.conf @@ -166,6 +166,7 @@ recording-method = proc # moh-attr-name = rtpengine-hold # preload-media-files = /var/media/file1.wav ; /var/media/file2.wav ; /var/media/file3.wav +# media-files-reload = 60 # signalling templates (see key `templates` above) [templates] diff --git a/include/main.h b/include/main.h index 27844a3d8..b3ff8b47f 100644 --- a/include/main.h +++ b/include/main.h @@ -92,7 +92,8 @@ enum endpoint_learning { X(mqtt_publish_interval) \ X(rtcp_interval) \ X(cpu_affinity) \ - X(max_recv_iters) + X(max_recv_iters) \ + X(media_refresh) \ #define RTPE_CONFIG_UINT64_PARAMS \ X(bw_limit) diff --git a/include/media_player.h b/include/media_player.h index fbe385753..339e682df 100644 --- a/include/media_player.h +++ b/include/media_player.h @@ -152,6 +152,7 @@ void media_player_launch(void); bool media_player_preload_files(char **); bool media_player_reload_file(str *name); unsigned int media_player_reload_files(void); +enum thread_looper_action media_player_refresh_timer(void); struct send_timer *send_timer_new(struct packet_stream *); void send_timer_push(struct send_timer *, struct codec_packet *);