From 02253c6f05494ae9cc2328ac20933136c8634ccf Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Fri, 16 May 2025 15:34:54 -0400 Subject: [PATCH] MT#62544 add output-buffer option Change-Id: Id823046b52ed7ebc8d19cc1d2d7b28eff0e0b6e0 --- docs/rtpengine-recording.md | 5 +++++ recording-daemon/main.c | 5 +++++ recording-daemon/main.h | 1 + recording-daemon/output.c | 17 +++++++++++++++++ recording-daemon/types.h | 1 + 5 files changed, 29 insertions(+) diff --git a/docs/rtpengine-recording.md b/docs/rtpengine-recording.md index f5b601000..71bbb839f 100644 --- a/docs/rtpengine-recording.md +++ b/docs/rtpengine-recording.md @@ -293,6 +293,11 @@ sufficient for a standard installation of rtpengine. are supported. If the value is blank or given as __-1__ then the user/group is left unchanged. +- __\-\-output-buffer=__*INT* + + Set the size of the I/O buffer used for writing files. The default is 2^18 + bytes (256 kB). Can be set to zero to effect unbuffered I/O. + - __\-\-mysql-host=__*HOST*\|*IP* - __\-\-mysql-port=__*INT* - __\-\-mysql-user=__*USERNAME* diff --git a/recording-daemon/main.c b/recording-daemon/main.c index 69909419c..ed43aaa53 100644 --- a/recording-daemon/main.c +++ b/recording-daemon/main.c @@ -49,6 +49,7 @@ mode_t output_chmod_dir; uid_t output_chown = -1; gid_t output_chgrp = -1; char *output_pattern = NULL; +int output_buffer = 1<<18; gboolean decoding_enabled; char *c_mysql_host, *c_mysql_user, @@ -213,6 +214,7 @@ static void options(int *argc, char ***argv) { { "output-chmod-dir", 0, 0, G_OPTION_ARG_STRING, &chmod_dir_mode,"Directory mode for recordings", "OCTAL" }, { "output-chown", 0, 0, G_OPTION_ARG_STRING, &user_uid, "File owner for recordings", "USER|UID" }, { "output-chgrp", 0, 0, G_OPTION_ARG_STRING, &group_gid, "File group for recordings", "GROUP|GID" }, + { "output-buffer", 0, 0, G_OPTION_ARG_INT, &output_buffer, "I/O buffer size for writing files", "INT" }, { "mysql-host", 0, 0, G_OPTION_ARG_STRING, &c_mysql_host, "MySQL host for storage of call metadata","HOST|IP" }, { "mysql-port", 0, 0, G_OPTION_ARG_INT, &c_mysql_port, "MySQL port" ,"INT" }, { "mysql-user", 0, 0, G_OPTION_ARG_STRING, &c_mysql_user, "MySQL connection credentials", "USERNAME" }, @@ -339,6 +341,9 @@ static void options(int *argc, char ***argv) { die("Invalid output pattern '%s' (no '%%c' format present)", output_pattern); if (!strstr(output_pattern, "%t")) die("Invalid output pattern '%s' (no '%%t' format present)", output_pattern); + + if (output_buffer < 0) + die("Invalid negative output-buffer value"); } static void options_free(void) { diff --git a/recording-daemon/main.h b/recording-daemon/main.h index 237cfa711..5b2f2f416 100644 --- a/recording-daemon/main.h +++ b/recording-daemon/main.h @@ -32,6 +32,7 @@ extern mode_t output_chmod_dir; extern uid_t output_chown; extern gid_t output_chgrp; extern char *output_pattern; +extern int output_buffer; extern gboolean decoding_enabled; extern char *c_mysql_host, *c_mysql_user, diff --git a/recording-daemon/output.c b/recording-daemon/output.c index 99f6d9fc3..1efcbc2f7 100644 --- a/recording-daemon/output.c +++ b/recording-daemon/output.c @@ -354,6 +354,22 @@ got_fn: if (!output->fp) goto err; + if (output_buffer > 0) { + err = "failed to alloc I/O buffer"; + output->iobuf = g_malloc(output_buffer); + if (!output->iobuf) + goto err; + + err = "failed to set I/O buffer"; + if (setvbuf(output->fp, output->iobuf, _IOFBF, output_buffer)) + goto err; + } + else { + err = "failed to set unuffered I/O"; + if (setvbuf(output->fp, NULL, _IONBF, 0)) + goto err; + } + err = "failed to alloc avio buffer"; void *avio_buf = av_malloc(DEFAULT_AVIO_BUFSIZE); if (!avio_buf) @@ -465,6 +481,7 @@ void output_close(metafile_t *mf, output_t *output, tag_t *tag, bool discard) { g_clear_pointer(&output->file_path, g_free); g_clear_pointer(&output->file_name, g_free); g_clear_pointer(&output->filename, g_free); + g_clear_pointer(&output->iobuf, g_free); g_free(output); } diff --git a/recording-daemon/types.h b/recording-daemon/types.h index 1fba610e8..c19cd8b67 100644 --- a/recording-daemon/types.h +++ b/recording-daemon/types.h @@ -175,6 +175,7 @@ struct output_s { int64_t start_time_us; FILE *fp; + char *iobuf; AVIOContext *avioctx; AVFormatContext *fmtctx; AVStream *avst;