Browse code

rtpengine: add un/silence_media() methods

Richard Fuchs authored on 23/07/2021 17:34:18
Showing 3 changed files
... ...
@@ -3038,6 +3038,52 @@ unblock_media("all");
3038 3038
 		</example>
3039 3039
 	</section>
3040 3040
 
3041
+	<section id="rtpengine.f.silence_media">
3042
+		<title>
3043
+		<function moreinfo="none">silence_media([flags])</function>
3044
+		</title>
3045
+		<para>
3046
+		Identical to <quote>block_media</quote> except that media &rtp; packets are not
3047
+		simply blocked, but instead have their audio payload replaced by silence audio.
3048
+		This is only supported for certain trivial audio codecs (e.g. G.711, G.722).
3049
+		</para>
3050
+		<para>
3051
+		See <quote>block_dtmf</quote> for a description of the flags that can be used.
3052
+		</para>
3053
+		<example>
3054
+		<title><function>silence_media</function> usage</title>
3055
+		<programlisting format="linespecific">
3056
+...
3057
+silence_media();
3058
+silence_media("directional");
3059
+silence_media("address=192.168.42.42");
3060
+...
3061
+		</programlisting>
3062
+		</example>
3063
+	</section>
3064
+
3065
+	<section id="rtpengine.f.unsilence_media">
3066
+		<title>
3067
+		<function moreinfo="none">unsilence_media([flags])</function>
3068
+		</title>
3069
+		<para>
3070
+		Identical to <quote>unblock_media</quote> except that it's the counterpart to
3071
+		<quote>silence_media</quote>.
3072
+		</para>
3073
+		<para>
3074
+		See <quote>unblock_dtmf</quote> for a description of the flags that can be used.
3075
+		</para>
3076
+		<example>
3077
+		<title><function>unsilence_media</function> usage</title>
3078
+		<programlisting format="linespecific">
3079
+...
3080
+unsilence_media();
3081
+unsilence_media("all");
3082
+...
3083
+		</programlisting>
3084
+		</example>
3085
+	</section>
3086
+
3041 3087
 	<section id="rtpengine.f.start_forwarding">
3042 3088
 		<title>
3043 3089
 		<function moreinfo="none">start_forwarding([flags])</function>
... ...
@@ -137,6 +137,8 @@ static const char *command_strings[] = {
137 137
 	[OP_UNBLOCK_DTMF]	= "unblock DTMF",
138 138
 	[OP_BLOCK_MEDIA]	= "block media",
139 139
 	[OP_UNBLOCK_MEDIA]	= "unblock media",
140
+	[OP_SILENCE_MEDIA]	= "silence media",
141
+	[OP_UNSILENCE_MEDIA]	= "unsilence media",
140 142
 	[OP_START_FORWARDING]	= "start forwarding",
141 143
 	[OP_STOP_FORWARDING]	= "stop forwarding",
142 144
 	[OP_PLAY_MEDIA]		= "play media",
... ...
@@ -200,6 +202,8 @@ static int block_dtmf_f(struct sip_msg *, char *, char *);
200 202
 static int unblock_dtmf_f(struct sip_msg *, char *, char *);
201 203
 static int block_media_f(struct sip_msg *, char *, char *);
202 204
 static int unblock_media_f(struct sip_msg *, char *, char *);
205
+static int silence_media_f(struct sip_msg *, char *, char *);
206
+static int unsilence_media_f(struct sip_msg *, char *, char *);
203 207
 static int start_forwarding_f(struct sip_msg *, char *, char *);
204 208
 static int stop_forwarding_f(struct sip_msg *, char *, char *);
205 209
 static int play_media_f(struct sip_msg *, char *, char *);
... ...
@@ -355,6 +359,12 @@ static cmd_export_t cmds[] = {
355 359
 	{"unblock_media",	(cmd_function)unblock_media_f, 		0,
356 360
 		0, 0,
357 361
 		ANY_ROUTE},
362
+	{"silence_media",	(cmd_function)silence_media_f,	 	0,
363
+		0, 0,
364
+		ANY_ROUTE },
365
+	{"unsilence_media",	(cmd_function)unsilence_media_f, 	0,
366
+		0, 0,
367
+		ANY_ROUTE},
358 368
 	{"block_dtmf",		(cmd_function)block_dtmf_f,	 	1,
359 369
 		fixup_spve_null, 0,
360 370
 		ANY_ROUTE },
... ...
@@ -367,6 +377,12 @@ static cmd_export_t cmds[] = {
367 377
 	{"unblock_media",	(cmd_function)unblock_media_f, 		1,
368 378
 		fixup_spve_null, 0,
369 379
 		ANY_ROUTE},
380
+	{"silence_media",	(cmd_function)silence_media_f,	 	1,
381
+		fixup_spve_null, 0,
382
+		ANY_ROUTE },
383
+	{"unsilence_media",	(cmd_function)unsilence_media_f, 	1,
384
+		fixup_spve_null, 0,
385
+		ANY_ROUTE},
370 386
 	{"start_forwarding",	(cmd_function)start_forwarding_f,	0,
371 387
 		0, 0,
372 388
 		ANY_ROUTE },
... ...
@@ -2631,7 +2647,8 @@ static bencode_item_t *rtpp_function_call(bencode_buffer_t *bencbuf, struct sip_
2631 2647
 	bencode_list_add_string(item, ip_addr2a(&msg->rcv.src_ip));
2632 2648
 
2633 2649
 	if (op == OP_BLOCK_DTMF || op == OP_BLOCK_MEDIA || op == OP_UNBLOCK_DTMF
2634
-			|| op == OP_UNBLOCK_MEDIA || op == OP_START_FORWARDING || op == OP_STOP_FORWARDING)
2650
+			|| op == OP_UNBLOCK_MEDIA || op == OP_START_FORWARDING || op == OP_STOP_FORWARDING
2651
+			|| op == OP_SILENCE_MEDIA || op == OP_UNSILENCE_MEDIA)
2635 2652
 	{
2636 2653
 		if (ng_flags.directional)
2637 2654
 			bencode_dictionary_add_str(ng_flags.dict, "from-tag", &ng_flags.from_tag);
... ...
@@ -4018,6 +4035,18 @@ unblock_media_f(struct sip_msg* msg, char *str1, char *str2)
4018 4035
 	return rtpengine_generic_f(msg, str1, OP_UNBLOCK_MEDIA);
4019 4036
 }
4020 4037
 
4038
+static int
4039
+silence_media_f(struct sip_msg* msg, char *str1, char *str2)
4040
+{
4041
+	return rtpengine_generic_f(msg, str1, OP_SILENCE_MEDIA);
4042
+}
4043
+
4044
+static int
4045
+unsilence_media_f(struct sip_msg* msg, char *str1, char *str2)
4046
+{
4047
+	return rtpengine_generic_f(msg, str1, OP_UNSILENCE_MEDIA);
4048
+}
4049
+
4021 4050
 static int rtpengine_play_media(struct sip_msg *msg, void *d, int more, enum rtpe_operation op) {
4022 4051
 	bencode_buffer_t bencbuf;
4023 4052
 	long long duration;
... ...
@@ -4235,6 +4264,23 @@ static int ki_unblock_media(sip_msg_t *msg , str *flags)
4235 4264
 	return rtpengine_rtpp_set_wrap(msg, rtpengine_simple_wrap, flags->s, 1, OP_UNBLOCK_MEDIA);
4236 4265
 }
4237 4266
 
4267
+static int ki_silence_media0(sip_msg_t *msg)
4268
+{
4269
+	return rtpengine_rtpp_set_wrap(msg, rtpengine_simple_wrap, NULL, 1, OP_SILENCE_MEDIA);
4270
+}
4271
+static int ki_silence_media(sip_msg_t *msg, str *flags)
4272
+{
4273
+	return rtpengine_rtpp_set_wrap(msg, rtpengine_simple_wrap, flags->s, 1, OP_SILENCE_MEDIA);
4274
+}
4275
+static int ki_unsilence_media0(sip_msg_t *msg)
4276
+{
4277
+	return rtpengine_rtpp_set_wrap(msg, rtpengine_simple_wrap, NULL, 1, OP_UNSILENCE_MEDIA);
4278
+}
4279
+static int ki_unsilence_media(sip_msg_t *msg , str *flags)
4280
+{
4281
+	return rtpengine_rtpp_set_wrap(msg, rtpengine_simple_wrap, flags->s, 1, OP_UNSILENCE_MEDIA);
4282
+}
4283
+
4238 4284
 static int ki_block_dtmf0(sip_msg_t *msg)
4239 4285
 {
4240 4286
 	return rtpengine_rtpp_set_wrap(msg, rtpengine_simple_wrap, NULL, 1, OP_BLOCK_DTMF);
... ...
@@ -4403,6 +4449,27 @@ static sr_kemi_t sr_kemi_rtpengine_exports[] = {
4403 4449
             SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
4404 4450
     },
4405 4451
 
4452
+	{ str_init("rtpengine"), str_init("silence_media0"),
4453
+        SR_KEMIP_INT, ki_silence_media0,
4454
+        { SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
4455
+            SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
4456
+    },
4457
+    { str_init("rtpengine"), str_init("silence_media"),
4458
+        SR_KEMIP_INT, ki_silence_media,
4459
+        { SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
4460
+            SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
4461
+    },
4462
+	{ str_init("rtpengine"), str_init("unsilence_media0"),
4463
+        SR_KEMIP_INT, ki_unsilence_media0,
4464
+        { SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
4465
+            SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
4466
+    },
4467
+    { str_init("rtpengine"), str_init("unsilence_media"),
4468
+        SR_KEMIP_INT, ki_unsilence_media,
4469
+        { SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
4470
+            SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
4471
+    },
4472
+
4406 4473
 	{ str_init("rtpengine"), str_init("block_dtmf0"),
4407 4474
         SR_KEMIP_INT, ki_block_dtmf0,
4408 4475
         { SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
... ...
@@ -42,6 +42,8 @@ enum rtpe_operation {
42 42
         OP_UNBLOCK_DTMF,
43 43
         OP_BLOCK_MEDIA,
44 44
         OP_UNBLOCK_MEDIA,
45
+        OP_SILENCE_MEDIA,
46
+        OP_UNSILENCE_MEDIA,
45 47
         OP_START_FORWARDING,
46 48
         OP_STOP_FORWARDING,
47 49
         OP_PLAY_MEDIA,