From 31023572a5f4326f725654ccbbea98acf692656d Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Wed, 26 Sep 2018 15:38:52 -0400 Subject: [PATCH] TT#41900 save monologue label into recording DB closes #582 Change-Id: Ibc894e82b61e4231c99f9618685a6232f7e50da7 --- daemon/recording.c | 2 ++ recording-daemon/Makefile | 2 +- recording-daemon/db.c | 17 +++++++++++++---- recording-daemon/db.h | 2 +- recording-daemon/metafile.c | 18 +++++++++++++++++- recording-daemon/packet.c | 2 +- recording-daemon/stream.c | 6 ++++++ recording-daemon/stream.h | 1 + recording-daemon/tag.c | 33 +++++++++++++++++++++++++++++++++ recording-daemon/tag.h | 10 ++++++++++ recording-daemon/types.h | 10 ++++++++++ 11 files changed, 95 insertions(+), 8 deletions(-) create mode 100644 recording-daemon/tag.c create mode 100644 recording-daemon/tag.h diff --git a/daemon/recording.c b/daemon/recording.c index 9a5b9746e..da3d4af71 100644 --- a/daemon/recording.c +++ b/daemon/recording.c @@ -677,6 +677,8 @@ static void sdp_before_proc(struct recording *recording, const str *sdp, struct enum call_opmode opmode) { append_meta_chunk_str(recording, &ml->tag, "TAG %u", ml->unique_id); + if (ml->label.len) + append_meta_chunk_str(recording, &ml->label, "LABEL %u", ml->unique_id); append_meta_chunk_str(recording, sdp, "SDP from %u before %s", ml->unique_id, get_opmode_text(opmode)); } diff --git a/recording-daemon/Makefile b/recording-daemon/Makefile index cc0d42c9a..a117f0828 100644 --- a/recording-daemon/Makefile +++ b/recording-daemon/Makefile @@ -25,7 +25,7 @@ LDLIBS+= $(shell mysql_config --libs) LDLIBS+= $(shell pkg-config --libs openssl) SRCS= epoll.c garbage.c inotify.c main.c metafile.c stream.c recaux.c packet.c \ - decoder.c output.c mix.c db.c log.c forward.c + decoder.c output.c mix.c db.c log.c forward.c tag.c LIBSRCS= loglib.c auxlib.c rtplib.c codeclib.c resample.c str.c OBJS= $(SRCS:.c=.o) $(LIBSRCS:.c=.o) diff --git a/recording-daemon/db.c b/recording-daemon/db.c index f4d4c6df5..7b183c4ba 100644 --- a/recording-daemon/db.c +++ b/recording-daemon/db.c @@ -78,8 +78,9 @@ static int check_conn() { "file_format, " \ "output_type, " \ "stream_id, ssrc, " \ + "tag_label, " \ "start_timestamp) values " \ - "(?,concat(?,'.',?),concat(?,'.',?),?,?,?,?,?)")) + "(?,concat(?,'.',?),concat(?,'.',?),?,?,?,?,?,?)")) goto err; if (prep(&stm_close_call, "update recording_calls set " \ "end_timestamp = ?, status = 'completed' where id = ?")) @@ -253,7 +254,8 @@ void db_do_call(metafile_t *mf) { } -void db_do_stream(metafile_t *mf, output_t *op, const char *type, unsigned int id, unsigned long ssrc) { +// mf is locked +void db_do_stream(metafile_t *mf, output_t *op, const char *type, stream_t *stream, unsigned long ssrc) { if (check_conn()) return; if (mf->db_id == 0) @@ -261,9 +263,10 @@ void db_do_stream(metafile_t *mf, output_t *op, const char *type, unsigned int i if (op->db_id > 0) return; + unsigned long id = stream ? stream->id : 0; double now = now_double(); - MYSQL_BIND b[10]; + MYSQL_BIND b[11]; my_ull(&b[0], &mf->db_id); my_cstr(&b[1], op->file_name); my_cstr(&b[2], op->file_format); @@ -283,7 +286,13 @@ void db_do_stream(metafile_t *mf, output_t *op, const char *type, unsigned int i .buffer_length = sizeof(ssrc), .is_unsigned = 1, }; - my_d(&b[9], &now); + if (stream && mf->tags->len > stream->tag) { + tag_t *tag = g_ptr_array_index(mf->tags, stream->tag); + my_cstr(&b[9], tag->label ? : ""); + } + else + my_cstr(&b[9], ""); + my_d(&b[10], &now); execute_wrap(&stm_insert_stream, b, &op->db_id); } diff --git a/recording-daemon/db.h b/recording-daemon/db.h index 7842ca8ce..3fb1eee8d 100644 --- a/recording-daemon/db.h +++ b/recording-daemon/db.h @@ -6,7 +6,7 @@ void db_do_call(metafile_t *); void db_close_call(metafile_t *); -void db_do_stream(metafile_t *mf, output_t *op, const char *type, unsigned int id, unsigned long ssrc); +void db_do_stream(metafile_t *mf, output_t *op, const char *type, stream_t *, unsigned long ssrc); void db_close_stream(output_t *op); void db_config_stream(output_t *op); diff --git a/recording-daemon/metafile.c b/recording-daemon/metafile.c index 64ce12fd3..5e1d88f37 100644 --- a/recording-daemon/metafile.c +++ b/recording-daemon/metafile.c @@ -16,6 +16,7 @@ #include "mix.h" #include "db.h" #include "forward.h" +#include "tag.h" static pthread_mutex_t metafiles_lock = PTHREAD_MUTEX_INITIALIZER; static GHashTable *metafiles; @@ -34,6 +35,11 @@ static void meta_free(void *ptr) { stream_free(stream); } g_ptr_array_free(mf->streams, TRUE); + for (int i = 0; i < mf->tags->len; i++) { + tag_t *tag = g_ptr_array_index(mf->tags, i); + tag_free(tag); + } + g_ptr_array_free(mf->tags, TRUE); if (mf->ssrc_hash) g_hash_table_destroy(mf->ssrc_hash); g_slice_free1(sizeof(*mf), mf); @@ -71,7 +77,7 @@ static void meta_stream_interface(metafile_t *mf, unsigned long snum, char *cont snprintf(buf, sizeof(buf), "%s-mix", mf->parent); mf->mix_out = output_new(output_dir, buf); mf->mix = mix_new(); - db_do_stream(mf, mf->mix_out, "mixed", 0, 0); + db_do_stream(mf, mf->mix_out, "mixed", NULL, 0); } pthread_mutex_unlock(&mf->mix_lock); } @@ -83,6 +89,11 @@ static void meta_stream_interface(metafile_t *mf, unsigned long snum, char *cont // mf is locked static void meta_stream_details(metafile_t *mf, unsigned long snum, char *content) { dbg("stream %lu details %s", snum, content); + unsigned int tag, media, tm, cmp, flags; + if (sscanf_match(content, "TAG %u MEDIA %u TAG-MEDIA %u COMPONENT %u FLAGS %u", + &tag, &media, &tm, &cmp, &flags) != 5) + return; + stream_details(mf, snum, tag); } @@ -131,6 +142,10 @@ static void meta_section(metafile_t *mf, char *section, char *content, unsigned meta_stream_details(mf, lu, content); else if (sscanf_match(section, "MEDIA %lu PAYLOAD TYPE %u", &lu, &u) == 2) meta_rtp_payload_type(mf, lu, u, content); + else if (sscanf_match(section, "TAG %lu", &lu) == 1) + tag_name(mf, lu, content); + else if (sscanf_match(section, "LABEL %lu", &lu) == 1) + tag_label(mf, lu, content); } @@ -148,6 +163,7 @@ static metafile_t *metafile_get(char *name) { mf->name = g_string_chunk_insert(mf->gsc, name); pthread_mutex_init(&mf->lock, NULL); mf->streams = g_ptr_array_new(); + mf->tags = g_ptr_array_new(); mf->forward_fd = -1; mf->forward_count = 0; mf->forward_failed = 0; diff --git a/recording-daemon/packet.c b/recording-daemon/packet.c index 6c824e779..301ea3323 100644 --- a/recording-daemon/packet.c +++ b/recording-daemon/packet.c @@ -53,7 +53,7 @@ static ssrc_t *ssrc_get(stream_t *stream, unsigned long ssrc) { snprintf(buf, sizeof(buf), "%s-%08lx", mf->parent, ssrc); if (output_single) { ret->output = output_new(output_dir, buf); - db_do_stream(mf, ret->output, "single", stream->id, ssrc); + db_do_stream(mf, ret->output, "single", stream, ssrc); } g_hash_table_insert(mf->ssrc_hash, GUINT_TO_POINTER(ssrc), ret); diff --git a/recording-daemon/stream.c b/recording-daemon/stream.c index b6b40d17b..eba560aee 100644 --- a/recording-daemon/stream.c +++ b/recording-daemon/stream.c @@ -106,6 +106,7 @@ static stream_t *stream_get(metafile_t *mf, unsigned long id) { ret->fd = -1; ret->id = id; ret->metafile = mf; + ret->tag = (unsigned long) -1; out: return ret; @@ -134,3 +135,8 @@ void stream_open(metafile_t *mf, unsigned long id, char *name) { stream->handler.func = stream_handler; epoll_add(stream->fd, EPOLLIN, &stream->handler); } + +void stream_details(metafile_t *mf, unsigned long id, unsigned int tag) { + stream_t *stream = stream_get(mf, id); + stream->tag = tag; +} diff --git a/recording-daemon/stream.h b/recording-daemon/stream.h index 1af4047c1..e1859cc86 100644 --- a/recording-daemon/stream.h +++ b/recording-daemon/stream.h @@ -4,6 +4,7 @@ #include "types.h" void stream_open(metafile_t *mf, unsigned long id, char *name); +void stream_details(metafile_t *mf, unsigned long id, unsigned int tag); void stream_close(stream_t *stream); void stream_free(stream_t *stream); diff --git a/recording-daemon/tag.c b/recording-daemon/tag.c new file mode 100644 index 000000000..1f4bf7437 --- /dev/null +++ b/recording-daemon/tag.c @@ -0,0 +1,33 @@ +#include "tag.h" + + +// XXX copied from stream.c - unify? +static tag_t *tag_get(metafile_t *mf, unsigned long id) { + if (mf->tags->len <= id) + g_ptr_array_set_size(mf->tags, id + 1); + tag_t *ret = g_ptr_array_index(mf->tags, id); + if (ret) + goto out; + + ret = g_slice_alloc0(sizeof(*ret)); + g_ptr_array_index(mf->tags, id) = ret; + + ret->id = id; + +out: + return ret; +} + +void tag_name(metafile_t *mf, unsigned long t, const char *str) { + tag_t *tag = tag_get(mf, t); + tag->name = g_string_chunk_insert(mf->gsc, str); +} + +void tag_label(metafile_t *mf, unsigned long t, const char *str) { + tag_t *tag = tag_get(mf, t); + tag->label = g_string_chunk_insert(mf->gsc, str); +} + +void tag_free(tag_t *tag) { + g_slice_free1(sizeof(*tag), tag); +} diff --git a/recording-daemon/tag.h b/recording-daemon/tag.h new file mode 100644 index 000000000..c55528aa6 --- /dev/null +++ b/recording-daemon/tag.h @@ -0,0 +1,10 @@ +#ifndef _TAG_H_ +#define _TAG_H_ + +#include "types.h" + +void tag_name(metafile_t *mf, unsigned long t, const char *); +void tag_label(metafile_t *mf, unsigned long t, const char *); +void tag_free(tag_t *); + +#endif diff --git a/recording-daemon/types.h b/recording-daemon/types.h index 9492e50f1..5215e5444 100644 --- a/recording-daemon/types.h +++ b/recording-daemon/types.h @@ -44,6 +44,7 @@ struct stream_s { char *name; metafile_t *metafile; unsigned long id; + unsigned long tag; int fd; handler_t handler; }; @@ -76,6 +77,14 @@ struct ssrc_s { typedef struct ssrc_s ssrc_t; +struct tag_s { + unsigned long id; + char *name; + char *label; +}; +typedef struct tag_s tag_t; + + struct metafile_s { pthread_mutex_t lock; char *name; @@ -88,6 +97,7 @@ struct metafile_s { GStringChunk *gsc; // XXX limit max size GPtrArray *streams; + GPtrArray *tags; GHashTable *ssrc_hash; // contains ssrc_t objects pthread_mutex_t mix_lock;