MT#56469 generalise start/stop recording

Use a callback handler function for these two methods to eliminate code
duplication.

Change-Id: Iab8685d3e9e97b4d6d1b9aa5aff4d51b68165140
pull/1611/head
Richard Fuchs 3 years ago
parent c56c3cff4d
commit ce3a0d384f

@ -2370,16 +2370,16 @@ const char *call_list_ng(bencode_item_t *input, bencode_item_t *output) {
}
const char *call_start_recording_ng(bencode_item_t *input, bencode_item_t *output) {
static const char *call_recording_common_ng(bencode_item_t *input, bencode_item_t *output,
void (*fn)(bencode_item_t *input, struct call *call))
{
str callid, fromtag;
struct call *call;
str metadata;
str output_dest;
if (!bencode_dictionary_get_str(input, "call-id", &callid))
return "No call-id in message";
bencode_dictionary_get_str(input, "metadata", &metadata);
bencode_dictionary_get_str(input, "output-destination", &output_dest);
call = call_get_opmode(&callid, OP_OTHER);
if (!call)
return "Unknown call-id";
@ -2399,8 +2399,7 @@ const char *call_start_recording_ng(bencode_item_t *input, bencode_item_t *outpu
else
update_metadata_call(call, &metadata);
call->recording_on = 1;
recording_start(call, NULL, &output_dest);
fn(input, call);
rwlock_unlock_w(&call->master_lock);
obj_put(call);
@ -2408,41 +2407,26 @@ const char *call_start_recording_ng(bencode_item_t *input, bencode_item_t *outpu
return NULL;
}
const char *call_stop_recording_ng(bencode_item_t *input, bencode_item_t *output) {
str callid, fromtag;
struct call *call;
str metadata;
if (!bencode_dictionary_get_str(input, "call-id", &callid))
return "No call-id in message";
bencode_dictionary_get_str(input, "metadata", &metadata);
call = call_get_opmode(&callid, OP_OTHER);
if (!call)
return "Unknown call-id";
struct call_monologue *ml = NULL;
if (bencode_dictionary_get_str(input, "from-tag", &fromtag)) {
if (fromtag.s) {
ml = call_get_monologue(call, &fromtag);
if (!ml)
ilog(LOG_WARN, "Given from-tag " STR_FORMAT_M " not found", STR_FMT_M(&fromtag));
}
}
static void start_recording_fn(bencode_item_t *input, struct call *call) {
str output_dest;
bencode_dictionary_get_str(input, "output-destination", &output_dest);
call->recording_on = 1;
recording_start(call, NULL, &output_dest);
}
const char *call_start_recording_ng(bencode_item_t *input, bencode_item_t *output) {
return call_recording_common_ng(input, output, start_recording_fn);
}
if (ml)
update_metadata_monologue(ml, &metadata);
else
update_metadata_call(call, &metadata);
static void stop_recording_fn(bencode_item_t *input, struct call *call) {
call->recording_on = 0;
recording_stop(call);
rwlock_unlock_w(&call->master_lock);
obj_put(call);
return NULL;
}
const char *call_stop_recording_ng(bencode_item_t *input, bencode_item_t *output) {
return call_recording_common_ng(input, output, stop_recording_fn);
}
static const char *media_block_match1(struct call *call, struct call_monologue **monologue,
struct sdp_ng_flags *flags)

Loading…
Cancel
Save