<p>Joshua Colp <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/16268">View Change</a></p><div style="white-space:pre-wrap">Approvals:
George Joseph: Looks good to me, approved
Joshua Colp: Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">func_frame_drop: New function<br><br>Adds function to selectively drop specified frames<br>in the TX or RX direction on a channel, including<br>control frames.<br><br>ASTERISK-29478<br><br>Change-Id: I8147c9d55d74e2e48861edba6b22f930920541ec<br>---<br>A doc/CHANGES-staging/func_framedrop.txt<br>A funcs/func_frame_drop.c<br>2 files changed, 296 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/doc/CHANGES-staging/func_framedrop.txt b/doc/CHANGES-staging/func_framedrop.txt</span><br><span>new file mode 100644</span><br><span>index 0000000..c17bccd</span><br><span>--- /dev/null</span><br><span>+++ b/doc/CHANGES-staging/func_framedrop.txt</span><br><span>@@ -0,0 +1,5 @@</span><br><span style="color: hsl(120, 100%, 40%);">+Subject: func_framedrop</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+New function to selectively drop specified frames</span><br><span style="color: hsl(120, 100%, 40%);">+in either direction on a channel.</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>diff --git a/funcs/func_frame_drop.c b/funcs/func_frame_drop.c</span><br><span>new file mode 100644</span><br><span>index 0000000..5aa66df</span><br><span>--- /dev/null</span><br><span>+++ b/funcs/func_frame_drop.c</span><br><span>@@ -0,0 +1,291 @@</span><br><span style="color: hsl(120, 100%, 40%);">+/*</span><br><span style="color: hsl(120, 100%, 40%);">+ * Asterisk -- An open source telephony toolkit.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Copyright (C) 2021, Naveen Albert</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Naveen Albert <asterisk@phreaknet.org></span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * See http://www.asterisk.org for more information about</span><br><span style="color: hsl(120, 100%, 40%);">+ * the Asterisk project. Please do not directly contact</span><br><span style="color: hsl(120, 100%, 40%);">+ * any of the maintainers of this project for assistance;</span><br><span style="color: hsl(120, 100%, 40%);">+ * the project provides a web site, mailing lists and IRC</span><br><span style="color: hsl(120, 100%, 40%);">+ * channels for your use.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is free software, distributed under the terms of</span><br><span style="color: hsl(120, 100%, 40%);">+ * the GNU General Public License Version 2. See the LICENSE file</span><br><span style="color: hsl(120, 100%, 40%);">+ * at the top of the source tree.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*! \file</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Function that drops specified frames from channels</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \author Naveen Albert <asterisk@phreaknet.org></span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \ingroup functions</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*** MODULEINFO</span><br><span style="color: hsl(120, 100%, 40%);">+ <support_level>extended</support_level></span><br><span style="color: hsl(120, 100%, 40%);">+ ***/</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include "asterisk.h"</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include "asterisk/module.h"</span><br><span style="color: hsl(120, 100%, 40%);">+#include "asterisk/channel.h"</span><br><span style="color: hsl(120, 100%, 40%);">+#include "asterisk/pbx.h"</span><br><span style="color: hsl(120, 100%, 40%);">+#include "asterisk/framehook.h"</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*** DOCUMENTATION</span><br><span style="color: hsl(120, 100%, 40%);">+ <function name="FRAME_DROP" language="en_US"></span><br><span style="color: hsl(120, 100%, 40%);">+ <synopsis></span><br><span style="color: hsl(120, 100%, 40%);">+ Drops specific frame types in the TX or RX direction on a channel.</span><br><span style="color: hsl(120, 100%, 40%);">+ </synopsis></span><br><span style="color: hsl(120, 100%, 40%);">+ <syntax></span><br><span style="color: hsl(120, 100%, 40%);">+ <parameter name="direction" required="true"></span><br><span style="color: hsl(120, 100%, 40%);">+ <para>List of frame types to be dropped for the specified direction. Direction can be <literal>TX</literal> or <literal>RX</literal>. The <literal>TX</literal> direction will prevent Asterisk from sending frames to a channel, and the <literal>RX</literal> direction will prevent Asterisk from receiving frames from a channel.</para></span><br><span style="color: hsl(120, 100%, 40%);">+ <para>Subsequent calls to this function will replace previous settings, allowing certain frames to be dropped only temporarily, for instance.</para></span><br><span style="color: hsl(120, 100%, 40%);">+ <para>Below are the different types of frames that can be dropped. Other actions may need to be taken in conjunction with use of this function:</span><br><span style="color: hsl(120, 100%, 40%);">+ for instance, if you drop ANSWER control frames, you should explicitly use <literal>Progress()</literal> for your call or undesired behavior</span><br><span style="color: hsl(120, 100%, 40%);">+ may occur.</para></span><br><span style="color: hsl(120, 100%, 40%);">+ <enumlist></span><br><span style="color: hsl(120, 100%, 40%);">+ <enum name = "DTMF_BEGIN" /></span><br><span style="color: hsl(120, 100%, 40%);">+ <enum name = "DTMF_END" /></span><br><span style="color: hsl(120, 100%, 40%);">+ <enum name = "VOICE" /></span><br><span style="color: hsl(120, 100%, 40%);">+ <enum name = "VIDEO" /></span><br><span style="color: hsl(120, 100%, 40%);">+ <enum name = "CONTROL" /></span><br><span style="color: hsl(120, 100%, 40%);">+ <enum name = "NULL" /></span><br><span style="color: hsl(120, 100%, 40%);">+ <enum name = "IAX" /></span><br><span style="color: hsl(120, 100%, 40%);">+ <enum name = "TEXT" /></span><br><span style="color: hsl(120, 100%, 40%);">+ <enum name = "TEXT_DATA" /></span><br><span style="color: hsl(120, 100%, 40%);">+ <enum name = "IMAGE" /></span><br><span style="color: hsl(120, 100%, 40%);">+ <enum name = "HTML" /></span><br><span style="color: hsl(120, 100%, 40%);">+ <enum name = "CNG" /></span><br><span style="color: hsl(120, 100%, 40%);">+ <enum name = "MODEM" /></span><br><span style="color: hsl(120, 100%, 40%);">+ </enumlist></span><br><span style="color: hsl(120, 100%, 40%);">+ <para>The following CONTROL frames can also be dropped:</para></span><br><span style="color: hsl(120, 100%, 40%);">+ <enumlist></span><br><span style="color: hsl(120, 100%, 40%);">+ <enum name = "RING" /></span><br><span style="color: hsl(120, 100%, 40%);">+ <enum name = "RINGING" /></span><br><span style="color: hsl(120, 100%, 40%);">+ <enum name = "ANSWER" /></span><br><span style="color: hsl(120, 100%, 40%);">+ <enum name = "BUSY" /></span><br><span style="color: hsl(120, 100%, 40%);">+ <enum name = "TAKEOFFHOOK" /></span><br><span style="color: hsl(120, 100%, 40%);">+ <enum name = "OFFHOOK" /></span><br><span style="color: hsl(120, 100%, 40%);">+ <enum name = "CONGESTION" /></span><br><span style="color: hsl(120, 100%, 40%);">+ <enum name = "FLASH" /></span><br><span style="color: hsl(120, 100%, 40%);">+ <enum name = "WINK" /></span><br><span style="color: hsl(120, 100%, 40%);">+ <enum name = "PROGRESS" /></span><br><span style="color: hsl(120, 100%, 40%);">+ <enum name = "PROCEEDING" /></span><br><span style="color: hsl(120, 100%, 40%);">+ <enum name = "HOLD" /></span><br><span style="color: hsl(120, 100%, 40%);">+ <enum name = "UNHOLD" /></span><br><span style="color: hsl(120, 100%, 40%);">+ <enum name = "VIDUPDATE" /></span><br><span style="color: hsl(120, 100%, 40%);">+ <enum name = "CONNECTED_LINE" /></span><br><span style="color: hsl(120, 100%, 40%);">+ <enum name = "REDIRECTING" /></span><br><span style="color: hsl(120, 100%, 40%);">+ </enumlist></span><br><span style="color: hsl(120, 100%, 40%);">+ </parameter></span><br><span style="color: hsl(120, 100%, 40%);">+ </syntax></span><br><span style="color: hsl(120, 100%, 40%);">+ <description></span><br><span style="color: hsl(120, 100%, 40%);">+ <para>Examples:</para></span><br><span style="color: hsl(120, 100%, 40%);">+ <para>exten => 1,1,Set(FRAME_DROP(TX)=DTMF_BEGIN,DTMF_END); drop only DTMF frames towards this channel.</para></span><br><span style="color: hsl(120, 100%, 40%);">+ <para>exten => 1,1,Set(FRAME_DROP(TX)=ANSWER); drop only ANSWER CONTROL frames towards this channel.</para></span><br><span style="color: hsl(120, 100%, 40%);">+ <para>exten => 1,1,Set(FRAME_DROP(RX)=DTMF_BEGIN,DTMF_END); drop only DTMF frames received on this channel.</para></span><br><span style="color: hsl(120, 100%, 40%);">+ </description></span><br><span style="color: hsl(120, 100%, 40%);">+ </function></span><br><span style="color: hsl(120, 100%, 40%);">+ ***/</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static struct {</span><br><span style="color: hsl(120, 100%, 40%);">+ enum ast_frame_type type;</span><br><span style="color: hsl(120, 100%, 40%);">+ const char *str;</span><br><span style="color: hsl(120, 100%, 40%);">+} frametype2str[] = {</span><br><span style="color: hsl(120, 100%, 40%);">+ { AST_FRAME_DTMF_BEGIN, ",DTMF_BEGIN," },</span><br><span style="color: hsl(120, 100%, 40%);">+ { AST_FRAME_DTMF_END, ",DTMF_END," },</span><br><span style="color: hsl(120, 100%, 40%);">+ { AST_FRAME_VOICE, ",VOICE," },</span><br><span style="color: hsl(120, 100%, 40%);">+ { AST_FRAME_VIDEO, ",VIDEO," },</span><br><span style="color: hsl(120, 100%, 40%);">+ { AST_FRAME_CONTROL, ",CONTROL," },</span><br><span style="color: hsl(120, 100%, 40%);">+ { AST_FRAME_NULL, ",NULL," },</span><br><span style="color: hsl(120, 100%, 40%);">+ { AST_FRAME_IAX, ",IAX," },</span><br><span style="color: hsl(120, 100%, 40%);">+ { AST_FRAME_TEXT, ",TEXT," },</span><br><span style="color: hsl(120, 100%, 40%);">+ { AST_FRAME_TEXT_DATA, ",TEXT_DATA," },</span><br><span style="color: hsl(120, 100%, 40%);">+ { AST_FRAME_IMAGE, ",IMAGE," },</span><br><span style="color: hsl(120, 100%, 40%);">+ { AST_FRAME_HTML, ",HTML," },</span><br><span style="color: hsl(120, 100%, 40%);">+ { AST_FRAME_CNG, ",CNG," },</span><br><span style="color: hsl(120, 100%, 40%);">+ { AST_FRAME_MODEM, ",MODEM," },</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static struct {</span><br><span style="color: hsl(120, 100%, 40%);">+ int type;</span><br><span style="color: hsl(120, 100%, 40%);">+ const char *str;</span><br><span style="color: hsl(120, 100%, 40%);">+} controlframetype2str[] = {</span><br><span style="color: hsl(120, 100%, 40%);">+ { AST_CONTROL_RING, ",RING," },</span><br><span style="color: hsl(120, 100%, 40%);">+ { AST_CONTROL_RINGING, ",RINGING," },</span><br><span style="color: hsl(120, 100%, 40%);">+ { AST_CONTROL_ANSWER, ",ANSWER," },</span><br><span style="color: hsl(120, 100%, 40%);">+ { AST_CONTROL_BUSY, ",BUSY," },</span><br><span style="color: hsl(120, 100%, 40%);">+ { AST_CONTROL_TAKEOFFHOOK, ",TAKEOFFHOOK," },</span><br><span style="color: hsl(120, 100%, 40%);">+ { AST_CONTROL_OFFHOOK, ",OFFHOOK," },</span><br><span style="color: hsl(120, 100%, 40%);">+ { AST_CONTROL_CONGESTION, ",CONGESTION," },</span><br><span style="color: hsl(120, 100%, 40%);">+ { AST_CONTROL_FLASH, ",FLASH," },</span><br><span style="color: hsl(120, 100%, 40%);">+ { AST_CONTROL_WINK, ",WINK," },</span><br><span style="color: hsl(120, 100%, 40%);">+ { AST_CONTROL_PROGRESS, ",PROGRESS," },</span><br><span style="color: hsl(120, 100%, 40%);">+ { AST_CONTROL_PROCEEDING, ",PROCEEDING," },</span><br><span style="color: hsl(120, 100%, 40%);">+ { AST_CONTROL_HOLD, ",HOLD," },</span><br><span style="color: hsl(120, 100%, 40%);">+ { AST_CONTROL_UNHOLD, ",UNHOLD," },</span><br><span style="color: hsl(120, 100%, 40%);">+ { AST_CONTROL_VIDUPDATE, ",VIDUPDATE," },</span><br><span style="color: hsl(120, 100%, 40%);">+ { AST_CONTROL_CONNECTED_LINE, ",CONNECTED_LINE," },</span><br><span style="color: hsl(120, 100%, 40%);">+ { AST_CONTROL_REDIRECTING, ",REDIRECTING," },</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+enum direction {</span><br><span style="color: hsl(120, 100%, 40%);">+ TX = 0,</span><br><span style="color: hsl(120, 100%, 40%);">+ RX,</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+struct frame_drop_data {</span><br><span style="color: hsl(120, 100%, 40%);">+ enum direction list_type;</span><br><span style="color: hsl(120, 100%, 40%);">+ int values[ARRAY_LEN(frametype2str)];</span><br><span style="color: hsl(120, 100%, 40%);">+ int controlvalues[ARRAY_LEN(controlframetype2str)];</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static void datastore_destroy_cb(void *data) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_free(data);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static const struct ast_datastore_info frame_drop_datastore = {</span><br><span style="color: hsl(120, 100%, 40%);">+ .type = "framedrop",</span><br><span style="color: hsl(120, 100%, 40%);">+ .destroy = datastore_destroy_cb</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static void hook_destroy_cb(void *framedata)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_free(framedata);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static struct ast_frame *hook_event_cb(struct ast_channel *chan, struct ast_frame *frame, enum ast_framehook_event event, void *data)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ int i;</span><br><span style="color: hsl(120, 100%, 40%);">+ int drop_frame = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct frame_drop_data *framedata = data;</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!frame) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return frame;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!((event == AST_FRAMEHOOK_EVENT_WRITE && framedata->list_type == TX) ||</span><br><span style="color: hsl(120, 100%, 40%);">+ (event == AST_FRAMEHOOK_EVENT_READ && framedata->list_type == RX))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return frame;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (frame->frametype == AST_FRAME_CONTROL) {</span><br><span style="color: hsl(120, 100%, 40%);">+ for (i = 0; i < ARRAY_LEN(controlframetype2str); i++) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (frame->subclass.integer == controlframetype2str[i].type) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (framedata->controlvalues[i]) {</span><br><span style="color: hsl(120, 100%, 40%);">+ drop_frame = 1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ break;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ for (i = 0; i < ARRAY_LEN(frametype2str); i++) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (frame->frametype == frametype2str[i].type) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (framedata->values[i]) {</span><br><span style="color: hsl(120, 100%, 40%);">+ drop_frame = 1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ break;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (drop_frame) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_frfree(frame);</span><br><span style="color: hsl(120, 100%, 40%);">+ frame = &ast_null_frame;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ return frame;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static int frame_drop_helper(struct ast_channel *chan, const char *cmd, char *data, const char *value)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ char *buffer;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct frame_drop_data *framedata;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_datastore *datastore = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_framehook_interface interface = {</span><br><span style="color: hsl(120, 100%, 40%);">+ .version = AST_FRAMEHOOK_INTERFACE_VERSION,</span><br><span style="color: hsl(120, 100%, 40%);">+ .event_cb = hook_event_cb,</span><br><span style="color: hsl(120, 100%, 40%);">+ .destroy_cb = hook_destroy_cb,</span><br><span style="color: hsl(120, 100%, 40%);">+ };</span><br><span style="color: hsl(120, 100%, 40%);">+ int i = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!(framedata = ast_calloc(1, sizeof(*framedata)))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ interface.data = framedata;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!strcasecmp(data, "RX")) {</span><br><span style="color: hsl(120, 100%, 40%);">+ framedata->list_type = RX;</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ framedata->list_type = TX;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ buffer = ast_malloc(sizeof(value) + 3); /* leading and trailing comma and null terminator */</span><br><span style="color: hsl(120, 100%, 40%);">+ snprintf(buffer, sizeof(value) + 2, ",%s,", value);</span><br><span style="color: hsl(120, 100%, 40%);">+ for (i = 0; i < ARRAY_LEN(frametype2str); i++) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (strcasestr(value, frametype2str[i].str)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ framedata->values[i] = 1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ for (i = 0; i < ARRAY_LEN(controlframetype2str); i++) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (strcasestr(value, controlframetype2str[i].str)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ framedata->controlvalues[i] = 1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_free(buffer);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_lock(chan);</span><br><span style="color: hsl(120, 100%, 40%);">+ i = ast_framehook_attach(chan, &interface);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (i >= 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+ int *id;</span><br><span style="color: hsl(120, 100%, 40%);">+ if ((datastore = ast_channel_datastore_find(chan, &frame_drop_datastore, NULL))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ id = datastore->data;</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_framehook_detach(chan, *id);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_datastore_remove(chan, datastore);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_datastore_free(datastore);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!(datastore = ast_datastore_alloc(&frame_drop_datastore, NULL))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_framehook_detach(chan, i);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_unlock(chan);</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!(id = ast_calloc(1, sizeof(int)))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_datastore_free(datastore);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_framehook_detach(chan, i);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_unlock(chan);</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ *id = i; /* Store off the id. The channel is still locked so it is safe to access this ptr. */</span><br><span style="color: hsl(120, 100%, 40%);">+ datastore->data = id;</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_datastore_add(chan, datastore);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_unlock(chan);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static struct ast_custom_function frame_drop_function = {</span><br><span style="color: hsl(120, 100%, 40%);">+ .name = "FRAME_DROP",</span><br><span style="color: hsl(120, 100%, 40%);">+ .write = frame_drop_helper,</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static int unload_module(void)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ return ast_custom_function_unregister(&frame_drop_function);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static int load_module(void)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ int res = ast_custom_function_register(&frame_drop_function);</span><br><span style="color: hsl(120, 100%, 40%);">+ return res ? AST_MODULE_LOAD_DECLINE : AST_MODULE_LOAD_SUCCESS;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+AST_MODULE_INFO_STANDARD_EXTENDED(ASTERISK_GPL_KEY, "Function to drop frames on a channel.");</span><br><span></span><br></pre><div style="white-space:pre-wrap"></div><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/16268">change 16268</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/16268"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 18 </div>
<div style="display:none"> Gerrit-Change-Id: I8147c9d55d74e2e48861edba6b22f930920541ec </div>
<div style="display:none"> Gerrit-Change-Number: 16268 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: N A <mail@interlinked.x10host.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>