Browse Source

TT#41900 save monologue label into recording DB

closes #582

Change-Id: Ibc894e82b61e4231c99f9618685a6232f7e50da7
changes/30/23830/5
Richard Fuchs 7 years ago
parent
commit
31023572a5
11 changed files with 95 additions and 8 deletions
  1. +2
    -0
      daemon/recording.c
  2. +1
    -1
      recording-daemon/Makefile
  3. +13
    -4
      recording-daemon/db.c
  4. +1
    -1
      recording-daemon/db.h
  5. +17
    -1
      recording-daemon/metafile.c
  6. +1
    -1
      recording-daemon/packet.c
  7. +6
    -0
      recording-daemon/stream.c
  8. +1
    -0
      recording-daemon/stream.h
  9. +33
    -0
      recording-daemon/tag.c
  10. +10
    -0
      recording-daemon/tag.h
  11. +10
    -0
      recording-daemon/types.h

+ 2
- 0
daemon/recording.c View File

@ -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));
}


+ 1
- 1
recording-daemon/Makefile View File

@ -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)


+ 13
- 4
recording-daemon/db.c View File

@ -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);
}


+ 1
- 1
recording-daemon/db.h View File

@ -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);


+ 17
- 1
recording-daemon/metafile.c View File

@ -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;


+ 1
- 1
recording-daemon/packet.c View File

@ -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);


+ 6
- 0
recording-daemon/stream.c View File

@ -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;
}

+ 1
- 0
recording-daemon/stream.h View File

@ -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);


+ 33
- 0
recording-daemon/tag.c View File

@ -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);
}

+ 10
- 0
recording-daemon/tag.h View File

@ -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

+ 10
- 0
recording-daemon/types.h View File

@ -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;


Loading…
Cancel
Save