Browse Source

MT#56447 add convenience _get_monologue

Remove code duplication by having one function to handle string printing
and monologue lookup.

Change-Id: I5ec30fe0bd07dd3c8f8fa2ceaa3f7bb88f7a07e5
pull/1642/head
Richard Fuchs 3 years ago
parent
commit
53ba78a775
1 changed files with 23 additions and 42 deletions
  1. +23
    -42
      daemon/janus.c

+ 23
- 42
daemon/janus.c View File

@ -90,6 +90,18 @@ static uint64_t jr_str_int(JsonReader *r) {
} }
static struct call_monologue *janus_get_monologue(uint64_t handle_id, struct call *call,
struct call_monologue *(*fn)(struct call *, const str *))
{
AUTO_CLEANUP_GBUF(handle_buf);
handle_buf = g_strdup_printf("%" PRIu64, handle_id);
str handle_str;
str_init(&handle_str, handle_buf);
return fn(call, &handle_str);
}
// frees 'builder', returns g_malloc'd string // frees 'builder', returns g_malloc'd string
static char *janus_json_print(JsonBuilder *builder) { static char *janus_json_print(JsonBuilder *builder) {
JsonGenerator *gen = json_generator_new(); JsonGenerator *gen = json_generator_new();
@ -326,11 +338,7 @@ static const char *janus_videoroom_join_sub(struct janus_handle *handle, struct
g_hash_table_insert(room->subscribers, uint64_dup(handle->id), uint64_dup(feed_id)); g_hash_table_insert(room->subscribers, uint64_dup(handle->id), uint64_dup(feed_id));
// add the subscription // add the subscription
AUTO_CLEANUP_GBUF(source_handle_buf);
source_handle_buf = g_strdup_printf("%" PRIu64, *feed_handle);
str source_handle_str;
str_init(&source_handle_str, source_handle_buf);
struct call_monologue *source_ml = call_get_monologue(call, &source_handle_str);
struct call_monologue *source_ml = janus_get_monologue(*feed_handle, call, call_get_monologue);
if (!source_ml) if (!source_ml)
return "Feed not found"; return "Feed not found";
@ -474,11 +482,8 @@ static const char *janus_videoroom_join(struct websocket_message *wm, struct jan
if (!srcs.length) if (!srcs.length)
return "No feeds to subscribe to given"; return "No feeds to subscribe to given";
AUTO_CLEANUP_GBUF(dest_handle_buf);
dest_handle_buf = g_strdup_printf("%" PRIu64, handle->id);
str dest_handle_str;
str_init(&dest_handle_str, dest_handle_buf);
struct call_monologue *dest_ml = call_get_or_create_monologue(call, &dest_handle_str);
struct call_monologue *dest_ml = janus_get_monologue(handle->id, call,
call_get_or_create_monologue);
AUTO_CLEANUP(struct sdp_ng_flags flags, call_ng_free_flags); AUTO_CLEANUP(struct sdp_ng_flags flags, call_ng_free_flags);
call_ng_flags_init(&flags, OP_REQUEST); call_ng_flags_init(&flags, OP_REQUEST);
@ -687,11 +692,7 @@ static const char *janus_videoroom_configure(struct websocket_message *wm, struc
if (!g_hash_table_lookup(room->publishers, &handle->id)) if (!g_hash_table_lookup(room->publishers, &handle->id))
return "Not a publisher"; return "Not a publisher";
AUTO_CLEANUP_GBUF(handle_buf);
handle_buf = g_strdup_printf("%" PRIu64, handle->id);
str handle_str;
str_init(&handle_str, handle_buf);
struct call_monologue *ml = call_get_or_create_monologue(call, &handle_str);
struct call_monologue *ml = janus_get_monologue(handle->id, call, call_get_or_create_monologue);
// accept unsupported codecs if necessary // accept unsupported codecs if necessary
flags.accept_any = 1; flags.accept_any = 1;
@ -843,20 +844,12 @@ static const char *janus_videoroom_start(struct websocket_message *wm, struct ja
if (!feed_handle) if (!feed_handle)
return "No such feed exists"; return "No such feed exists";
AUTO_CLEANUP_GBUF(source_handle_buf);
source_handle_buf = g_strdup_printf("%" PRIu64, *feed_handle);
str source_handle_str;
str_init(&source_handle_str, source_handle_buf);
struct call_monologue *source_ml = call_get_monologue(call, &source_handle_str);
struct call_monologue *source_ml = janus_get_monologue(*feed_handle, call, call_get_monologue);
if (!source_ml) if (!source_ml)
return "Feed not found"; return "Feed not found";
// XXX verify that dest_ml is subscribed to source_ml // XXX verify that dest_ml is subscribed to source_ml
AUTO_CLEANUP_GBUF(dest_handle_buf);
dest_handle_buf = g_strdup_printf("%" PRIu64, handle->id);
str dest_handle_str;
str_init(&dest_handle_str, dest_handle_buf);
struct call_monologue *dest_ml = call_get_monologue(call, &dest_handle_str);
struct call_monologue *dest_ml = janus_get_monologue(handle->id, call, call_get_monologue);
if (!dest_ml) if (!dest_ml)
return "Subscriber not found"; return "Subscriber not found";
@ -1289,12 +1282,8 @@ const char *janus_detach(struct websocket_message *wm, JsonReader *reader, JsonB
struct call *call = call_get(&room->call_id); struct call *call = call_get(&room->call_id);
if (call) { if (call) {
// remove publisher monologue // remove publisher monologue
AUTO_CLEANUP_GBUF(handle_buf);
handle_buf = g_strdup_printf("%" PRIu64, handle_id);
str handle_str;
str_init(&handle_str, handle_buf);
struct call_monologue *ml = call_get_or_create_monologue(call,
&handle_str);
struct call_monologue *ml = janus_get_monologue(handle_id, call,
call_get_or_create_monologue);
if (ml) if (ml)
monologue_destroy(ml); monologue_destroy(ml);
@ -1311,12 +1300,8 @@ const char *janus_detach(struct websocket_message *wm, JsonReader *reader, JsonB
struct call *call = call_get(&room->call_id); struct call *call = call_get(&room->call_id);
if (call) { if (call) {
// remove subscriber monologue // remove subscriber monologue
AUTO_CLEANUP_GBUF(handle_buf);
handle_buf = g_strdup_printf("%" PRIu64, handle_id);
str handle_str;
str_init(&handle_str, handle_buf);
struct call_monologue *ml = call_get_or_create_monologue(call,
&handle_str);
struct call_monologue *ml = janus_get_monologue(handle_id, call,
call_get_or_create_monologue);
if (ml) if (ml)
monologue_destroy(ml); monologue_destroy(ml);
@ -1477,11 +1462,7 @@ const char *janus_trickle(JsonReader *reader, struct janus_session *session, uin
return "No such room"; return "No such room";
} }
AUTO_CLEANUP_GBUF(handle_buf);
handle_buf = g_strdup_printf("%" PRIu64, handle_id);
str handle_str;
str_init(&handle_str, handle_buf);
struct call_monologue *ml = call_get_monologue(call, &handle_str);
struct call_monologue *ml = janus_get_monologue(handle_id, call, call_get_monologue);
if (!ml) if (!ml)
return "Handle not found in room"; return "Handle not found in room";


Loading…
Cancel
Save