Skip to content

Commit

Permalink
siprec: add command to stop_recording
Browse files Browse the repository at this point in the history
  • Loading branch information
razvancrainea committed Jul 19, 2024
1 parent 24a51ce commit fe889fb
Show file tree
Hide file tree
Showing 6 changed files with 211 additions and 99 deletions.
23 changes: 23 additions & 0 deletions modules/siprec/doc/siprec_admin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,29 @@ modparam("siprec", "skip_failover_codes", "[34][0-9][0-9]")
siprec_resume_recording();
}
...
</programlisting>
</example>
</section>
<section id="func_siprec_stop_recording" xreflabel="siprec_stop_recording()">
<title>
<function moreinfo="none">siprec_stop_recording()</function>
</title>
<para>
Stops the recording for the ongoing call. Should be called for SIPREC
sessions that have been previously started.
</para>
<para>
This function can be used from any route.
</para>
<example>
<title>Use <function>siprec_stop_recording()</function> </title>
<programlisting format="linespecific">
...
if (has_totag() &amp;&amp; is_method("INVITE")) {
if (is_audio_on_hold())
siprec_stop_recording();
}
...
</programlisting>
</example>
</section>
Expand Down
19 changes: 19 additions & 0 deletions modules/siprec/siprec.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ static void mod_destroy(void);
static int siprec_start_rec(struct sip_msg *msg, str *srs);
static int siprec_pause_rec(struct sip_msg *msg);
static int siprec_resume_rec(struct sip_msg *msg);
static int siprec_stop_rec(struct sip_msg *msg);

/* modules dependencies */
static const dep_export_t deps = {
Expand All @@ -67,6 +68,8 @@ static const cmd_export_t cmds[] = {
{{0,0,0}}, ALL_ROUTES},
{"siprec_resume_recording",(cmd_function)siprec_resume_rec,
{{0,0,0}}, ALL_ROUTES},
{"siprec_stop_recording",(cmd_function)siprec_stop_rec,
{{0,0,0}}, ALL_ROUTES},
{0,0,{{0,0,0}},0}
};

Expand Down Expand Up @@ -321,3 +324,19 @@ static int siprec_resume_rec(struct sip_msg *msg)
{
return (src_resume_recording() < 0 ? -1: 1);
}

static int siprec_stop_rec(struct sip_msg *msg)
{
struct dlg_cell *dlg = srec_dlg.get_dlg();
struct src_sess *ss;
if (!dlg) {
LM_ERR("dialog not found!\n");
return -2;
}
ss = (struct src_sess *)srec_dlg.dlg_ctx_get_ptr(dlg, srec_dlg_idx);
if (!ss) {
LM_DBG("no recording session started\n");
return -1;
}
return (srec_stop_recording(ss)<0?-1:1);
}
28 changes: 17 additions & 11 deletions modules/siprec/siprec_logic.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,23 +129,15 @@ static void srec_tm_unref(void *p)
SIPREC_UNREF(ss);
}

static void srec_dlg_end(struct dlg_cell *dlg, int type, struct dlg_cb_params *_params)
int srec_stop_recording(struct src_sess *ss)
{
struct src_sess *ss;
struct b2b_req_data req;

str bye = str_init(BYE);

if (!_params) {
LM_ERR("no parameter specified to dlg callback!\n");
return;
}
ss = *_params->param;

if ((ss->flags & SIPREC_STARTED) == 0) {
LM_DBG("sess=%p no longer in progress\n", ss);
/* the session was not started, or it had been deleted in the meantime */
return;
return -1;
}

memset(&req, 0, sizeof(req));
Expand All @@ -159,7 +151,20 @@ static void srec_dlg_end(struct dlg_cell *dlg, int type, struct dlg_cb_params *_
LM_ERR("Cannot end recording session for key %.*s\n",
req.b2b_key->len, req.b2b_key->s);
srec_rtp.copy_delete(ss->rtp, &mod_name, &ss->media);
srec_logic_destroy(ss, 0);
src_clean_session(ss);
return 0;
}

static void srec_dlg_end(struct dlg_cell *dlg, int type, struct dlg_cb_params *_params)
{
struct src_sess *ss;

if (!_params) {
LM_ERR("no parameter specified to dlg callback!\n");
return;
}
ss = *_params->param;
srec_stop_recording(ss);
}

static void srec_dlg_sequential(struct dlg_cell *dlg, int type, struct dlg_cb_params *_params)
Expand Down Expand Up @@ -700,6 +705,7 @@ void srec_logic_destroy(struct src_sess *sess, int keep_sdp)
sess->b2b_key.s = NULL;

sess->flags &= ~(SIPREC_STARTED|SIPREC_ONGOING);
LM_DBG("stopped recording for %p!\n", sess);
}

struct src_sess *src_get_session(void)
Expand Down
2 changes: 2 additions & 0 deletions modules/siprec/siprec_logic.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ void tm_start_recording(struct cell *t, int type, struct tmcb_params *ps);
int srec_register_callbacks(struct src_sess *sess);
int srec_restore_callback(struct src_sess *sess);
void srec_logic_destroy(struct src_sess *sess, int keep_sdp);
void srec_nodes_destroy(struct src_sess *sess);
int src_pause_recording(void);
int src_resume_recording(void);
int src_start_recording(struct sip_msg *msg, struct src_sess *sess);
int srec_stop_recording(struct src_sess *ss);

extern int srec_dlg_idx;
extern struct b2b_api srec_b2b;
Expand Down
Loading

0 comments on commit fe889fb

Please sign in to comment.