Browse Source

make the new `stream` db field optional based on settings

Change-Id: I470ffa4c1bfcca5531786464c6e99850ac10f900
pull/521/head
Richard Fuchs 8 years ago
parent
commit
af963a23fd
3 changed files with 41 additions and 15 deletions
  1. +21
    -12
      recording-daemon/db.c
  2. +13
    -2
      recording-daemon/main.c
  3. +7
    -1
      recording-daemon/main.h

+ 21
- 12
recording-daemon/db.c View File

@ -84,9 +84,16 @@ static int check_conn() {
if (prep(&stm_close_call, "update recording_calls set " \
"end_timestamp = ?, status = 'completed' where id = ?"))
goto err;
if (prep(&stm_close_stream, "update recording_streams set " \
"end_timestamp = ?, stream = ? where id = ?"))
goto err;
if ((output_storage & OUTPUT_STORAGE_DB)) {
if (prep(&stm_close_stream, "update recording_streams set " \
"end_timestamp = ?, stream = ? where id = ?"))
goto err;
}
else {
if (prep(&stm_close_stream, "update recording_streams set " \
"end_timestamp = ? where id = ?"))
goto err;
}
if (prep(&stm_config_stream, "update recording_streams set channels = ?, sample_rate = ? where id = ?"))
goto err;
if (prep(&stm_insert_metadata, "insert into recording_metakeys (`call`, `key`, `value`) values " \
@ -310,12 +317,12 @@ void db_close_stream(output_t *op) {
stream.s = 0;
stream.len = 0;
if (!strcmp(output_storage, "db") || !strcmp(output_storage, "both")) {
if ((output_storage & OUTPUT_STORAGE_DB)) {
filename = malloc(strlen(op->full_filename) +
strlen(op->file_format) + 2);
if (!filename) {
ilog(LOG_ERR, "Failed to allocate memory for filename");
if (!strcmp(output_storage, "both"))
if ((output_storage & OUTPUT_STORAGE_FILE))
goto file;
return;
}
@ -325,7 +332,7 @@ void db_close_stream(output_t *op) {
FILE *f = fopen(filename, "rb");
if (!f) {
ilog(LOG_ERR, "Failed to open file: %s", filename);
if (!strcmp(output_storage, "both"))
if ((output_storage & OUTPUT_STORAGE_FILE))
goto file;
free(filename);
return;
@ -338,7 +345,7 @@ void db_close_stream(output_t *op) {
size_t count = fread(stream.s, 1, stream.len, f);
if (count != stream.len) {
ilog(LOG_ERR, "Failed to read from stream");
if (!strcmp(output_storage, "both"))
if ((output_storage & OUTPUT_STORAGE_FILE))
goto file;
free(filename);
return;
@ -347,16 +354,18 @@ void db_close_stream(output_t *op) {
fclose(f);
}
file:
my_d(&b[0], &now);
my_str(&b[1], &stream);
my_ull(&b[2], &op->db_id);
file:;
int par_idx = 0;
my_d(&b[par_idx++], &now);
if ((output_storage & OUTPUT_STORAGE_DB))
my_str(&b[par_idx++], &stream);
my_ull(&b[par_idx++], &op->db_id);
execute_wrap(&stm_close_stream, b, NULL);
if (stream.s)
free(stream.s);
if (!strcmp(output_storage, "db"))
if (!(output_storage & OUTPUT_STORAGE_FILE))
remove(filename);
free(filename);
}


+ 13
- 2
recording-daemon/main.c View File

@ -29,7 +29,7 @@
int ktable = 0;
int num_threads = 8;
const char *output_storage = "file";
enum output_storage_enum output_storage = OUTPUT_STORAGE_FILE;
const char *spool_dir = "/var/spool/rtpengine";
const char *output_dir = "/var/lib/rtpengine-recording";
static const char *output_format = "wav";
@ -135,11 +135,13 @@ static void cleanup(void) {
static void options(int *argc, char ***argv) {
const char *os_str;
GOptionEntry e[] = {
{ "table", 't', 0, G_OPTION_ARG_INT, &ktable, "Kernel table rtpengine uses", "INT" },
{ "spool-dir", 0, 0, G_OPTION_ARG_STRING, &spool_dir, "Directory containing rtpengine metadata files", "PATH" },
{ "num-threads", 0, 0, G_OPTION_ARG_INT, &num_threads, "Number of worker threads", "INT" },
{ "output-storage", 0, 0, G_OPTION_ARG_STRING, &output_storage,"Where to store audio streams", "file|db|both" },
{ "output-storage", 0, 0, G_OPTION_ARG_STRING, &os_str, "Where to store audio streams", "file|db|both" },
{ "output-dir", 0, 0, G_OPTION_ARG_STRING, &output_dir, "Where to write media files to", "PATH" },
{ "output-format", 0, 0, G_OPTION_ARG_STRING, &output_format, "Write audio files of this type", "wav|mp3|none" },
{ "resample-to", 0, 0, G_OPTION_ARG_INT, &resample_audio,"Resample all output audio", "INT" },
@ -168,6 +170,15 @@ static void options(int *argc, char ***argv) {
}
} else if (!output_mixed && !output_single)
output_mixed = output_single = 1;
if (!strcmp(os_str, "file"))
output_storage = OUTPUT_STORAGE_FILE;
else if (!strcmp(os_str, "db"))
output_storage = OUTPUT_STORAGE_DB;
else if (!strcmp(os_str, "both"))
output_storage = OUTPUT_STORAGE_BOTH;
else
die("Invalid 'output-storage' option");
}


+ 7
- 1
recording-daemon/main.h View File

@ -5,9 +5,15 @@
#include "auxlib.h"
enum output_storage_enum {
OUTPUT_STORAGE_FILE = 0x1,
OUTPUT_STORAGE_DB = 0x2,
OUTPUT_STORAGE_BOTH = 0x3,
};
extern int ktable;
extern int num_threads;
extern const char *output_storage;
extern enum output_storage_enum output_storage;
extern const char *spool_dir;
extern const char *output_dir;
extern int output_mixed;


Loading…
Cancel
Save