2006-02-12 04:28:58 +00:00
|
|
|
/*
|
|
|
|
* Asterisk -- An open source telephony toolkit.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006, Digium, Inc.
|
|
|
|
*
|
|
|
|
* See http://www.asterisk.org for more information about
|
|
|
|
* the Asterisk project. Please do not directly contact
|
|
|
|
* any of the maintainers of this project for assistance;
|
|
|
|
* the project provides a web site, mailing lists and IRC
|
|
|
|
* channels for your use.
|
|
|
|
*
|
|
|
|
* This program is free software, distributed under the terms of
|
|
|
|
* the GNU General Public License Version 2. See the LICENSE file
|
|
|
|
* at the top of the source tree.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*! \file
|
|
|
|
*
|
2008-06-03 23:17:33 +00:00
|
|
|
* \brief Channel info dialplan functions
|
2006-02-12 04:28:58 +00:00
|
|
|
*
|
|
|
|
* \author Kevin P. Fleming <kpfleming@digium.com>
|
2008-06-03 23:17:33 +00:00
|
|
|
* \author Ben Winslow
|
2013-07-21 22:09:23 +00:00
|
|
|
*
|
2007-01-24 09:05:29 +00:00
|
|
|
* \ingroup functions
|
2006-02-12 04:28:58 +00:00
|
|
|
*/
|
|
|
|
|
2011-07-14 20:28:54 +00:00
|
|
|
/*** MODULEINFO
|
|
|
|
<support_level>core</support_level>
|
|
|
|
***/
|
|
|
|
|
2006-06-07 18:54:56 +00:00
|
|
|
#include "asterisk.h"
|
|
|
|
|
2008-06-03 23:17:33 +00:00
|
|
|
#include <regex.h>
|
2009-06-26 15:28:53 +00:00
|
|
|
#include <ctype.h>
|
2008-06-03 23:17:33 +00:00
|
|
|
|
2006-02-12 04:28:58 +00:00
|
|
|
#include "asterisk/module.h"
|
|
|
|
#include "asterisk/channel.h"
|
2013-07-25 04:06:32 +00:00
|
|
|
#include "asterisk/bridge.h"
|
2006-02-12 04:28:58 +00:00
|
|
|
#include "asterisk/pbx.h"
|
|
|
|
#include "asterisk/utils.h"
|
|
|
|
#include "asterisk/app.h"
|
|
|
|
#include "asterisk/indications.h"
|
|
|
|
#include "asterisk/stringfields.h"
|
2010-06-08 05:29:08 +00:00
|
|
|
#include "asterisk/global_datastores.h"
|
2013-07-25 04:06:32 +00:00
|
|
|
#include "asterisk/bridge_basic.h"
|
|
|
|
#include "asterisk/bridge_after.h"
|
2015-04-15 15:38:02 +00:00
|
|
|
#include "asterisk/max_forwards.h"
|
2006-06-07 18:54:56 +00:00
|
|
|
|
2008-11-01 21:10:07 +00:00
|
|
|
/*** DOCUMENTATION
|
|
|
|
<function name="CHANNELS" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Gets the list of channels, optionally filtering by a regular expression.
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="regular_expression" />
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>Gets the list of channels, optionally filtering by a <replaceable>regular_expression</replaceable>. If
|
|
|
|
no argument is provided, all known channels are returned. The
|
|
|
|
<replaceable>regular_expression</replaceable> must correspond to
|
|
|
|
the POSIX.2 specification, as shown in <emphasis>regex(7)</emphasis>. The list returned
|
|
|
|
will be space-delimited.</para>
|
|
|
|
</description>
|
|
|
|
</function>
|
2009-09-01 23:41:06 +00:00
|
|
|
<function name="MASTER_CHANNEL" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Gets or sets variables on the master channel
|
|
|
|
</synopsis>
|
|
|
|
<description>
|
|
|
|
<para>Allows access to the channel which created the current channel, if any. If the channel is already
|
|
|
|
a master channel, then accesses local channel variables.</para>
|
|
|
|
</description>
|
|
|
|
</function>
|
2008-11-01 21:10:07 +00:00
|
|
|
<function name="CHANNEL" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Gets/sets various pieces of information about the channel.
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="item" required="true">
|
|
|
|
<para>Standard items (provided by all channel technologies) are:</para>
|
|
|
|
<enumlist>
|
2013-04-03 17:17:33 +00:00
|
|
|
<enum name="amaflags">
|
|
|
|
<para>R/W the Automatic Message Accounting (AMA) flags on the channel.
|
|
|
|
When read from a channel, the integer value will always be returned.
|
|
|
|
When written to a channel, both the string format or integer value
|
|
|
|
is accepted.</para>
|
|
|
|
<enumlist>
|
|
|
|
<enum name="1"><para><literal>OMIT</literal></para></enum>
|
|
|
|
<enum name="2"><para><literal>BILLING</literal></para></enum>
|
|
|
|
<enum name="3"><para><literal>DOCUMENTATION</literal></para></enum>
|
|
|
|
</enumlist>
|
|
|
|
</enum>
|
|
|
|
<enum name="accountcode">
|
|
|
|
<para>R/W the channel's account code.</para>
|
|
|
|
</enum>
|
2008-11-01 21:10:07 +00:00
|
|
|
<enum name="audioreadformat">
|
|
|
|
<para>R/O format currently being read.</para>
|
|
|
|
</enum>
|
|
|
|
<enum name="audionativeformat">
|
|
|
|
<para>R/O format used natively for audio.</para>
|
|
|
|
</enum>
|
|
|
|
<enum name="audiowriteformat">
|
|
|
|
<para>R/O format currently being written.</para>
|
|
|
|
</enum>
|
2013-07-23 21:32:33 +00:00
|
|
|
<enum name="dtmf_features">
|
|
|
|
<para>R/W The channel's DTMF bridge features.
|
|
|
|
May include one or more of 'T' 'K' 'H' 'W' and 'X' in a similar manner to options
|
|
|
|
in the <literal>Dial</literal> application. When setting it, the features string
|
|
|
|
must be all upper case.</para>
|
|
|
|
</enum>
|
2008-11-01 21:10:07 +00:00
|
|
|
<enum name="callgroup">
|
2012-09-20 17:22:41 +00:00
|
|
|
<para>R/W numeric call pickup groups that this channel is a member.</para>
|
2008-11-01 21:10:07 +00:00
|
|
|
</enum>
|
2011-05-25 15:43:28 +00:00
|
|
|
<enum name="pickupgroup">
|
2012-09-20 17:22:41 +00:00
|
|
|
<para>R/W numeric call pickup groups this channel can pickup.</para>
|
|
|
|
</enum>
|
|
|
|
<enum name="namedcallgroup">
|
|
|
|
<para>R/W named call pickup groups that this channel is a member.</para>
|
|
|
|
</enum>
|
|
|
|
<enum name="namedpickupgroup">
|
|
|
|
<para>R/W named call pickup groups this channel can pickup.</para>
|
2011-05-25 15:43:28 +00:00
|
|
|
</enum>
|
2008-11-01 21:10:07 +00:00
|
|
|
<enum name="channeltype">
|
|
|
|
<para>R/O technology used for channel.</para>
|
|
|
|
</enum>
|
2010-09-07 21:14:54 +00:00
|
|
|
<enum name="checkhangup">
|
2010-09-08 07:15:19 +00:00
|
|
|
<para>R/O Whether the channel is hanging up (1/0)</para>
|
2010-09-07 21:14:54 +00:00
|
|
|
</enum>
|
2013-06-26 20:59:14 +00:00
|
|
|
<enum name="after_bridge_goto">
|
|
|
|
<para>R/W the parseable goto string indicating where the channel is
|
|
|
|
expected to return to in the PBX after exiting the next bridge it joins
|
|
|
|
on the condition that it doesn't hang up. The parseable goto string uses
|
|
|
|
the same syntax as the <literal>Goto</literal> application.</para>
|
|
|
|
</enum>
|
2012-06-29 17:02:32 +00:00
|
|
|
<enum name="hangup_handler_pop">
|
|
|
|
<para>W/O Replace the most recently added hangup handler
|
|
|
|
with a new hangup handler on the channel if supplied. The
|
|
|
|
assigned string is passed to the Gosub application when
|
|
|
|
the channel is hung up. Any optionally omitted context
|
|
|
|
and exten are supplied by the channel pushing the handler
|
|
|
|
before it is pushed.</para>
|
|
|
|
</enum>
|
|
|
|
<enum name="hangup_handler_push">
|
|
|
|
<para>W/O Push a hangup handler onto the channel hangup
|
|
|
|
handler stack. The assigned string is passed to the
|
|
|
|
Gosub application when the channel is hung up. Any
|
|
|
|
optionally omitted context and exten are supplied by the
|
|
|
|
channel pushing the handler before it is pushed.</para>
|
|
|
|
</enum>
|
|
|
|
<enum name="hangup_handler_wipe">
|
|
|
|
<para>W/O Wipe the entire hangup handler stack and replace
|
|
|
|
with a new hangup handler on the channel if supplied. The
|
|
|
|
assigned string is passed to the Gosub application when
|
|
|
|
the channel is hung up. Any optionally omitted context
|
|
|
|
and exten are supplied by the channel pushing the handler
|
|
|
|
before it is pushed.</para>
|
|
|
|
</enum>
|
2014-09-09 16:14:02 +00:00
|
|
|
<enum name="onhold">
|
|
|
|
<para>R/O Whether or not the channel is onhold. (1/0)</para>
|
|
|
|
</enum>
|
2008-11-01 21:10:07 +00:00
|
|
|
<enum name="language">
|
|
|
|
<para>R/W language for sounds played.</para>
|
|
|
|
</enum>
|
|
|
|
<enum name="musicclass">
|
|
|
|
<para>R/W class (from musiconhold.conf) for hold music.</para>
|
|
|
|
</enum>
|
2009-03-17 21:28:04 +00:00
|
|
|
<enum name="name">
|
|
|
|
<para>The name of the channel</para>
|
|
|
|
</enum>
|
2008-11-01 21:10:07 +00:00
|
|
|
<enum name="parkinglot">
|
|
|
|
<para>R/W parkinglot for parking.</para>
|
|
|
|
</enum>
|
|
|
|
<enum name="rxgain">
|
|
|
|
<para>R/W set rxgain level on channel drivers that support it.</para>
|
|
|
|
</enum>
|
2010-06-08 05:29:08 +00:00
|
|
|
<enum name="secure_bridge_signaling">
|
2014-09-05 20:38:27 +00:00
|
|
|
<para>Whether or not channels bridged to this channel require secure signaling (1/0)</para>
|
2010-06-08 05:29:08 +00:00
|
|
|
</enum>
|
|
|
|
<enum name="secure_bridge_media">
|
2014-09-05 20:38:27 +00:00
|
|
|
<para>Whether or not channels bridged to this channel require secure media (1/0)</para>
|
2010-06-08 05:29:08 +00:00
|
|
|
</enum>
|
2008-11-01 21:10:07 +00:00
|
|
|
<enum name="state">
|
2014-09-05 20:38:27 +00:00
|
|
|
<para>R/O state of the channel</para>
|
2008-11-01 21:10:07 +00:00
|
|
|
</enum>
|
|
|
|
<enum name="tonezone">
|
|
|
|
<para>R/W zone for indications played</para>
|
|
|
|
</enum>
|
2009-05-11 18:01:44 +00:00
|
|
|
<enum name="transfercapability">
|
|
|
|
<para>R/W ISDN Transfer Capability, one of:</para>
|
|
|
|
<enumlist>
|
|
|
|
<enum name="SPEECH" />
|
|
|
|
<enum name="DIGITAL" />
|
|
|
|
<enum name="RESTRICTED_DIGITAL" />
|
|
|
|
<enum name="3K1AUDIO" />
|
|
|
|
<enum name="DIGITAL_W_TONES" />
|
|
|
|
<enum name="VIDEO" />
|
|
|
|
</enumlist>
|
|
|
|
</enum>
|
2008-11-01 21:10:07 +00:00
|
|
|
<enum name="txgain">
|
|
|
|
<para>R/W set txgain level on channel drivers that support it.</para>
|
|
|
|
</enum>
|
|
|
|
<enum name="videonativeformat">
|
|
|
|
<para>R/O format used natively for video</para>
|
|
|
|
</enum>
|
|
|
|
<enum name="trace">
|
|
|
|
<para>R/W whether or not context tracing is enabled, only available
|
|
|
|
<emphasis>if CHANNEL_TRACE is defined</emphasis>.</para>
|
|
|
|
</enum>
|
2016-01-14 15:26:15 +00:00
|
|
|
<enum name="hangupsource">
|
|
|
|
<para>R/W returns the channel responsible for hangup.</para>
|
|
|
|
</enum>
|
|
|
|
<enum name="appname">
|
|
|
|
<para>R/O returns the internal application name.</para>
|
|
|
|
</enum>
|
|
|
|
<enum name="appdata">
|
|
|
|
<para>R/O returns the application data if available.</para>
|
|
|
|
</enum>
|
|
|
|
<enum name="exten">
|
|
|
|
<para>R/O returns the extension for an outbound channel.</para>
|
|
|
|
</enum>
|
|
|
|
<enum name="context">
|
|
|
|
<para>R/O returns the context for an outbound channel.</para>
|
|
|
|
</enum>
|
|
|
|
<enum name="channame">
|
|
|
|
<para>R/O returns the channel name for an outbound channel.</para>
|
|
|
|
</enum>
|
|
|
|
<enum name="uniqueid">
|
|
|
|
<para>R/O returns the channel uniqueid.</para>
|
|
|
|
</enum>
|
|
|
|
<enum name="linkedid">
|
|
|
|
<para>R/O returns the linkedid if available, otherwise returns the uniqueid.</para>
|
|
|
|
</enum>
|
2015-04-15 15:38:02 +00:00
|
|
|
<enum name="max_forwards">
|
2016-08-12 16:15:38 +00:00
|
|
|
<para>R/W The maximum number of forwards allowed.</para>
|
2015-04-15 15:38:02 +00:00
|
|
|
</enum>
|
2011-10-03 14:24:45 +00:00
|
|
|
</enumlist>
|
2016-08-15 20:29:53 +00:00
|
|
|
<xi:include xpointer="xpointer(/docs/info[@name='CHANNEL'])" />
|
2008-11-01 21:10:07 +00:00
|
|
|
</parameter>
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>Gets/sets various pieces of information about the channel, additional <replaceable>item</replaceable> may
|
|
|
|
be available from the channel driver; see its documentation for details. Any <replaceable>item</replaceable>
|
|
|
|
requested that is not available on the current channel will return an empty string.</para>
|
2016-08-12 16:15:38 +00:00
|
|
|
<example title="Standard CHANNEL item examples">
|
|
|
|
; Push a hangup handler subroutine existing at dialplan
|
|
|
|
; location default,s,1 onto the current channel
|
|
|
|
same => n,Set(CHANNEL(hangup_handler_push)=default,s,1)
|
|
|
|
|
|
|
|
; Set the current tonezone to Germany (de)
|
|
|
|
same => n,Set(CHANNEL(tonezone)=de)
|
|
|
|
|
|
|
|
; Set the allowed maximum number of forwarding attempts
|
|
|
|
same => n,Set(CHANNEL(max_forwards)=10)
|
|
|
|
|
|
|
|
; If this channel is ejected from its next bridge, and if
|
|
|
|
; the channel is not hung up, begin executing dialplan at
|
|
|
|
; location default,after-bridge,1
|
|
|
|
same => n,Set(CHANNEL(after_bridge_goto)=default,after-bridge,1)
|
|
|
|
|
|
|
|
; Log the current state of the channel
|
|
|
|
same => n,Log(NOTICE, This channel is: ${CHANNEL(state)})
|
|
|
|
</example>
|
2016-08-15 20:29:53 +00:00
|
|
|
<xi:include xpointer="xpointer(/docs/info[@name='CHANNEL_EXAMPLES'])" />
|
2008-11-01 21:10:07 +00:00
|
|
|
</description>
|
|
|
|
</function>
|
|
|
|
***/
|
|
|
|
|
2006-02-12 04:28:58 +00:00
|
|
|
#define locked_copy_string(chan, dest, source, len) \
|
|
|
|
do { \
|
2006-05-10 15:30:59 +00:00
|
|
|
ast_channel_lock(chan); \
|
2006-02-12 04:28:58 +00:00
|
|
|
ast_copy_string(dest, source, len); \
|
2006-05-10 15:30:59 +00:00
|
|
|
ast_channel_unlock(chan); \
|
2006-02-12 04:28:58 +00:00
|
|
|
} while (0)
|
|
|
|
#define locked_string_field_set(chan, field, source) \
|
|
|
|
do { \
|
2006-05-10 15:30:59 +00:00
|
|
|
ast_channel_lock(chan); \
|
2012-01-24 20:12:09 +00:00
|
|
|
ast_channel_##field##_set(chan, source); \
|
2006-05-10 15:30:59 +00:00
|
|
|
ast_channel_unlock(chan); \
|
2006-02-12 04:28:58 +00:00
|
|
|
} while (0)
|
|
|
|
|
2009-06-15 17:34:30 +00:00
|
|
|
static const char * const transfercapability_table[0x20] = {
|
2006-05-25 19:07:31 +00:00
|
|
|
"SPEECH", "UNK", "UNK", "UNK", "UNK", "UNK", "UNK", "UNK",
|
|
|
|
"DIGITAL", "RESTRICTED_DIGITAL", "UNK", "UNK", "UNK", "UNK", "UNK", "UNK",
|
|
|
|
"3K1AUDIO", "DIGITAL_W_TONES", "UNK", "UNK", "UNK", "UNK", "UNK", "UNK",
|
|
|
|
"VIDEO", "UNK", "UNK", "UNK", "UNK", "UNK", "UNK", "UNK", };
|
|
|
|
|
2007-01-06 00:13:33 +00:00
|
|
|
static int func_channel_read(struct ast_channel *chan, const char *function,
|
2006-02-12 04:28:58 +00:00
|
|
|
char *data, char *buf, size_t len)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
2011-02-03 16:22:10 +00:00
|
|
|
struct ast_format_cap *tmpcap;
|
2006-02-12 04:28:58 +00:00
|
|
|
|
2014-03-27 19:21:44 +00:00
|
|
|
if (!chan) {
|
|
|
|
ast_log(LOG_WARNING, "No channel was provided to %s function.\n", function);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-02-03 16:22:10 +00:00
|
|
|
if (!strcasecmp(data, "audionativeformat")) {
|
media formats: re-architect handling of media for performance improvements
In the old times media formats were represented using a bit field. This was
fast but had a few limitations.
1. Asterisk was limited in how many formats it could handle.
2. Formats, being a bit field, could not include any attribute information.
A format was strictly its type, e.g., "this is ulaw".
This was changed in Asterisk 10 (see
https://wiki.asterisk.org/wiki/display/AST/Media+Architecture+Proposal for
notes on that work) which led to the creation of the ast_format structure.
This structure allowed Asterisk to handle attributes and bundle information
with a format.
Additionally, ast_format_cap was created to act as a container for multiple
formats that, together, formed the capability of some entity. Another
mechanism was added to allow logic to be registered which performed format
attribute negotiation. Everywhere throughout the codebase Asterisk was
changed to use this strategy.
Unfortunately, in software, there is no free lunch. These new capabilities
came at a cost.
Performance analysis and profiling showed that we spend an inordinate
amount of time comparing, copying, and generally manipulating formats and
their related structures. Basic prototyping has shown that a reasonably
large performance improvement could be made in this area. This patch is the
result of that project, which overhauled the media format architecture
and its usage in Asterisk to improve performance.
Generally, the new philosophy for handling formats is as follows:
* The ast_format structure is reference counted. This removed a large amount
of the memory allocations and copying that was done in prior versions.
* In order to prevent race conditions while keeping things performant, the
ast_format structure is immutable by convention and lock-free. Violate this
tenet at your peril!
* Because formats are reference counted, codecs are also reference counted.
The Asterisk core generally provides built-in codecs and caches the
ast_format structures created to represent them. Generally, to prevent
inordinate amounts of module reference bumping, codecs and formats can be
added at run-time but cannot be removed.
* All compatibility with the bit field representation of codecs/formats has
been moved to a compatibility API. The primary user of this representation
is chan_iax2, which must continue to maintain its bit-field usage of formats
for interoperability concerns.
* When a format is negotiated with attributes, or when a format cannot be
represented by one of the cached formats, a new format object is created or
cloned from an existing format. That format may have the same codec
underlying it, but is a different format than a version of the format with
different attributes or without attributes.
* While formats are reference counted objects, the reference count maintained
on the format should be manipulated with care. Formats are generally cached
and will persist for the lifetime of Asterisk and do not explicitly need
to have their lifetime modified. An exception to this is when the user of a
format does not know where the format came from *and* the user may outlive
the provider of the format. This occurs, for example, when a format is read
from a channel: the channel may have a format with attributes (hence,
non-cached) and the user of the format may last longer than the channel (if
the reference to the channel is released prior to the format's reference).
For more information on this work, see the API design notes:
https://wiki.asterisk.org/wiki/display/AST/Media+Format+Rewrite
Finally, this work was the culmination of a large number of developer's
efforts. Extra thanks goes to Corey Farrell, who took on a large amount of the
work in the Asterisk core, chan_sip, and was an invaluable resource in peer
reviews throughout this project.
There were a substantial number of patches contributed during this work; the
following issues/patch names simply reflect some of the work (and will cause
the release scripts to give attribution to the individuals who work on them).
Reviews:
https://reviewboard.asterisk.org/r/3814
https://reviewboard.asterisk.org/r/3808
https://reviewboard.asterisk.org/r/3805
https://reviewboard.asterisk.org/r/3803
https://reviewboard.asterisk.org/r/3801
https://reviewboard.asterisk.org/r/3798
https://reviewboard.asterisk.org/r/3800
https://reviewboard.asterisk.org/r/3794
https://reviewboard.asterisk.org/r/3793
https://reviewboard.asterisk.org/r/3792
https://reviewboard.asterisk.org/r/3791
https://reviewboard.asterisk.org/r/3790
https://reviewboard.asterisk.org/r/3789
https://reviewboard.asterisk.org/r/3788
https://reviewboard.asterisk.org/r/3787
https://reviewboard.asterisk.org/r/3786
https://reviewboard.asterisk.org/r/3784
https://reviewboard.asterisk.org/r/3783
https://reviewboard.asterisk.org/r/3778
https://reviewboard.asterisk.org/r/3774
https://reviewboard.asterisk.org/r/3775
https://reviewboard.asterisk.org/r/3772
https://reviewboard.asterisk.org/r/3761
https://reviewboard.asterisk.org/r/3754
https://reviewboard.asterisk.org/r/3753
https://reviewboard.asterisk.org/r/3751
https://reviewboard.asterisk.org/r/3750
https://reviewboard.asterisk.org/r/3748
https://reviewboard.asterisk.org/r/3747
https://reviewboard.asterisk.org/r/3746
https://reviewboard.asterisk.org/r/3742
https://reviewboard.asterisk.org/r/3740
https://reviewboard.asterisk.org/r/3739
https://reviewboard.asterisk.org/r/3738
https://reviewboard.asterisk.org/r/3737
https://reviewboard.asterisk.org/r/3736
https://reviewboard.asterisk.org/r/3734
https://reviewboard.asterisk.org/r/3722
https://reviewboard.asterisk.org/r/3713
https://reviewboard.asterisk.org/r/3703
https://reviewboard.asterisk.org/r/3689
https://reviewboard.asterisk.org/r/3687
https://reviewboard.asterisk.org/r/3674
https://reviewboard.asterisk.org/r/3671
https://reviewboard.asterisk.org/r/3667
https://reviewboard.asterisk.org/r/3665
https://reviewboard.asterisk.org/r/3625
https://reviewboard.asterisk.org/r/3602
https://reviewboard.asterisk.org/r/3519
https://reviewboard.asterisk.org/r/3518
https://reviewboard.asterisk.org/r/3516
https://reviewboard.asterisk.org/r/3515
https://reviewboard.asterisk.org/r/3512
https://reviewboard.asterisk.org/r/3506
https://reviewboard.asterisk.org/r/3413
https://reviewboard.asterisk.org/r/3410
https://reviewboard.asterisk.org/r/3387
https://reviewboard.asterisk.org/r/3388
https://reviewboard.asterisk.org/r/3389
https://reviewboard.asterisk.org/r/3390
https://reviewboard.asterisk.org/r/3321
https://reviewboard.asterisk.org/r/3320
https://reviewboard.asterisk.org/r/3319
https://reviewboard.asterisk.org/r/3318
https://reviewboard.asterisk.org/r/3266
https://reviewboard.asterisk.org/r/3265
https://reviewboard.asterisk.org/r/3234
https://reviewboard.asterisk.org/r/3178
ASTERISK-23114 #close
Reported by: mjordan
media_formats_translation_core.diff uploaded by kharwell (License 6464)
rb3506.diff uploaded by mjordan (License 6283)
media_format_app_file.diff uploaded by kharwell (License 6464)
misc-2.diff uploaded by file (License 5000)
chan_mild-3.diff uploaded by file (License 5000)
chan_obscure.diff uploaded by file (License 5000)
jingle.diff uploaded by file (License 5000)
funcs.diff uploaded by file (License 5000)
formats.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
bridges.diff uploaded by file (License 5000)
mf-codecs-2.diff uploaded by file (License 5000)
mf-app_fax.diff uploaded by file (License 5000)
mf-apps-3.diff uploaded by file (License 5000)
media-formats-3.diff uploaded by file (License 5000)
ASTERISK-23715
rb3713.patch uploaded by coreyfarrell (License 5909)
rb3689.patch uploaded by mjordan (License 6283)
ASTERISK-23957
rb3722.patch uploaded by mjordan (License 6283)
mf-attributes-3.diff uploaded by file (License 5000)
ASTERISK-23958
Tested by: jrose
rb3822.patch uploaded by coreyfarrell (License 5909)
rb3800.patch uploaded by jrose (License 6182)
chan_sip.diff uploaded by mjordan (License 6283)
rb3747.patch uploaded by jrose (License 6182)
ASTERISK-23959 #close
Tested by: sgriepentrog, mjordan, coreyfarrell
sip_cleanup.diff uploaded by opticron (License 6273)
chan_sip_caps.diff uploaded by mjordan (License 6283)
rb3751.patch uploaded by coreyfarrell (License 5909)
chan_sip-3.diff uploaded by file (License 5000)
ASTERISK-23960 #close
Tested by: opticron
direct_media.diff uploaded by opticron (License 6273)
pjsip-direct-media.diff uploaded by file (License 5000)
format_cap_remove.diff uploaded by opticron (License 6273)
media_format_fixes.diff uploaded by opticron (License 6273)
chan_pjsip-2.diff uploaded by file (License 5000)
ASTERISK-23966 #close
Tested by: rmudgett
rb3803.patch uploaded by rmudgetti (License 5621)
chan_dahdi.diff uploaded by file (License 5000)
ASTERISK-24064 #close
Tested by: coreyfarrell, mjordan, opticron, file, rmudgett, sgriepentrog, jrose
rb3814.patch uploaded by rmudgett (License 5621)
moh_cleanup.diff uploaded by opticron (License 6273)
bridge_leak.diff uploaded by opticron (License 6273)
translate.diff uploaded by file (License 5000)
rb3795.patch uploaded by rmudgett (License 5621)
tls_fix.diff uploaded by mjordan (License 6283)
fax-mf-fix-2.diff uploaded by file (License 5000)
rtp_transfer_stuff uploaded by mjordan (License 6283)
rb3787.patch uploaded by rmudgett (License 5621)
media-formats-explicit-translate-format-3.diff uploaded by file (License 5000)
format_cache_case_fix.diff uploaded by opticron (License 6273)
rb3774.patch uploaded by rmudgett (License 5621)
rb3775.patch uploaded by rmudgett (License 5621)
rtp_engine_fix.diff uploaded by opticron (License 6273)
rtp_crash_fix.diff uploaded by opticron (License 6273)
rb3753.patch uploaded by mjordan (License 6283)
rb3750.patch uploaded by mjordan (License 6283)
rb3748.patch uploaded by rmudgett (License 5621)
media_format_fixes.diff uploaded by opticron (License 6273)
rb3740.patch uploaded by mjordan (License 6283)
rb3739.patch uploaded by mjordan (License 6283)
rb3734.patch uploaded by mjordan (License 6283)
rb3689.patch uploaded by mjordan (License 6283)
rb3674.patch uploaded by coreyfarrell (License 5909)
rb3671.patch uploaded by coreyfarrell (License 5909)
rb3667.patch uploaded by coreyfarrell (License 5909)
rb3665.patch uploaded by mjordan (License 6283)
rb3625.patch uploaded by coreyfarrell (License 5909)
rb3602.patch uploaded by coreyfarrell (License 5909)
format_compatibility-2.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419044 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-20 22:06:33 +00:00
|
|
|
tmpcap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
|
|
|
|
if (tmpcap) {
|
2015-11-09 09:01:41 +00:00
|
|
|
struct ast_str *codec_buf = ast_str_alloca(AST_FORMAT_CAP_NAMES_LEN);
|
2012-09-20 17:22:41 +00:00
|
|
|
|
2014-09-05 20:38:27 +00:00
|
|
|
ast_channel_lock(chan);
|
media formats: re-architect handling of media for performance improvements
In the old times media formats were represented using a bit field. This was
fast but had a few limitations.
1. Asterisk was limited in how many formats it could handle.
2. Formats, being a bit field, could not include any attribute information.
A format was strictly its type, e.g., "this is ulaw".
This was changed in Asterisk 10 (see
https://wiki.asterisk.org/wiki/display/AST/Media+Architecture+Proposal for
notes on that work) which led to the creation of the ast_format structure.
This structure allowed Asterisk to handle attributes and bundle information
with a format.
Additionally, ast_format_cap was created to act as a container for multiple
formats that, together, formed the capability of some entity. Another
mechanism was added to allow logic to be registered which performed format
attribute negotiation. Everywhere throughout the codebase Asterisk was
changed to use this strategy.
Unfortunately, in software, there is no free lunch. These new capabilities
came at a cost.
Performance analysis and profiling showed that we spend an inordinate
amount of time comparing, copying, and generally manipulating formats and
their related structures. Basic prototyping has shown that a reasonably
large performance improvement could be made in this area. This patch is the
result of that project, which overhauled the media format architecture
and its usage in Asterisk to improve performance.
Generally, the new philosophy for handling formats is as follows:
* The ast_format structure is reference counted. This removed a large amount
of the memory allocations and copying that was done in prior versions.
* In order to prevent race conditions while keeping things performant, the
ast_format structure is immutable by convention and lock-free. Violate this
tenet at your peril!
* Because formats are reference counted, codecs are also reference counted.
The Asterisk core generally provides built-in codecs and caches the
ast_format structures created to represent them. Generally, to prevent
inordinate amounts of module reference bumping, codecs and formats can be
added at run-time but cannot be removed.
* All compatibility with the bit field representation of codecs/formats has
been moved to a compatibility API. The primary user of this representation
is chan_iax2, which must continue to maintain its bit-field usage of formats
for interoperability concerns.
* When a format is negotiated with attributes, or when a format cannot be
represented by one of the cached formats, a new format object is created or
cloned from an existing format. That format may have the same codec
underlying it, but is a different format than a version of the format with
different attributes or without attributes.
* While formats are reference counted objects, the reference count maintained
on the format should be manipulated with care. Formats are generally cached
and will persist for the lifetime of Asterisk and do not explicitly need
to have their lifetime modified. An exception to this is when the user of a
format does not know where the format came from *and* the user may outlive
the provider of the format. This occurs, for example, when a format is read
from a channel: the channel may have a format with attributes (hence,
non-cached) and the user of the format may last longer than the channel (if
the reference to the channel is released prior to the format's reference).
For more information on this work, see the API design notes:
https://wiki.asterisk.org/wiki/display/AST/Media+Format+Rewrite
Finally, this work was the culmination of a large number of developer's
efforts. Extra thanks goes to Corey Farrell, who took on a large amount of the
work in the Asterisk core, chan_sip, and was an invaluable resource in peer
reviews throughout this project.
There were a substantial number of patches contributed during this work; the
following issues/patch names simply reflect some of the work (and will cause
the release scripts to give attribution to the individuals who work on them).
Reviews:
https://reviewboard.asterisk.org/r/3814
https://reviewboard.asterisk.org/r/3808
https://reviewboard.asterisk.org/r/3805
https://reviewboard.asterisk.org/r/3803
https://reviewboard.asterisk.org/r/3801
https://reviewboard.asterisk.org/r/3798
https://reviewboard.asterisk.org/r/3800
https://reviewboard.asterisk.org/r/3794
https://reviewboard.asterisk.org/r/3793
https://reviewboard.asterisk.org/r/3792
https://reviewboard.asterisk.org/r/3791
https://reviewboard.asterisk.org/r/3790
https://reviewboard.asterisk.org/r/3789
https://reviewboard.asterisk.org/r/3788
https://reviewboard.asterisk.org/r/3787
https://reviewboard.asterisk.org/r/3786
https://reviewboard.asterisk.org/r/3784
https://reviewboard.asterisk.org/r/3783
https://reviewboard.asterisk.org/r/3778
https://reviewboard.asterisk.org/r/3774
https://reviewboard.asterisk.org/r/3775
https://reviewboard.asterisk.org/r/3772
https://reviewboard.asterisk.org/r/3761
https://reviewboard.asterisk.org/r/3754
https://reviewboard.asterisk.org/r/3753
https://reviewboard.asterisk.org/r/3751
https://reviewboard.asterisk.org/r/3750
https://reviewboard.asterisk.org/r/3748
https://reviewboard.asterisk.org/r/3747
https://reviewboard.asterisk.org/r/3746
https://reviewboard.asterisk.org/r/3742
https://reviewboard.asterisk.org/r/3740
https://reviewboard.asterisk.org/r/3739
https://reviewboard.asterisk.org/r/3738
https://reviewboard.asterisk.org/r/3737
https://reviewboard.asterisk.org/r/3736
https://reviewboard.asterisk.org/r/3734
https://reviewboard.asterisk.org/r/3722
https://reviewboard.asterisk.org/r/3713
https://reviewboard.asterisk.org/r/3703
https://reviewboard.asterisk.org/r/3689
https://reviewboard.asterisk.org/r/3687
https://reviewboard.asterisk.org/r/3674
https://reviewboard.asterisk.org/r/3671
https://reviewboard.asterisk.org/r/3667
https://reviewboard.asterisk.org/r/3665
https://reviewboard.asterisk.org/r/3625
https://reviewboard.asterisk.org/r/3602
https://reviewboard.asterisk.org/r/3519
https://reviewboard.asterisk.org/r/3518
https://reviewboard.asterisk.org/r/3516
https://reviewboard.asterisk.org/r/3515
https://reviewboard.asterisk.org/r/3512
https://reviewboard.asterisk.org/r/3506
https://reviewboard.asterisk.org/r/3413
https://reviewboard.asterisk.org/r/3410
https://reviewboard.asterisk.org/r/3387
https://reviewboard.asterisk.org/r/3388
https://reviewboard.asterisk.org/r/3389
https://reviewboard.asterisk.org/r/3390
https://reviewboard.asterisk.org/r/3321
https://reviewboard.asterisk.org/r/3320
https://reviewboard.asterisk.org/r/3319
https://reviewboard.asterisk.org/r/3318
https://reviewboard.asterisk.org/r/3266
https://reviewboard.asterisk.org/r/3265
https://reviewboard.asterisk.org/r/3234
https://reviewboard.asterisk.org/r/3178
ASTERISK-23114 #close
Reported by: mjordan
media_formats_translation_core.diff uploaded by kharwell (License 6464)
rb3506.diff uploaded by mjordan (License 6283)
media_format_app_file.diff uploaded by kharwell (License 6464)
misc-2.diff uploaded by file (License 5000)
chan_mild-3.diff uploaded by file (License 5000)
chan_obscure.diff uploaded by file (License 5000)
jingle.diff uploaded by file (License 5000)
funcs.diff uploaded by file (License 5000)
formats.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
bridges.diff uploaded by file (License 5000)
mf-codecs-2.diff uploaded by file (License 5000)
mf-app_fax.diff uploaded by file (License 5000)
mf-apps-3.diff uploaded by file (License 5000)
media-formats-3.diff uploaded by file (License 5000)
ASTERISK-23715
rb3713.patch uploaded by coreyfarrell (License 5909)
rb3689.patch uploaded by mjordan (License 6283)
ASTERISK-23957
rb3722.patch uploaded by mjordan (License 6283)
mf-attributes-3.diff uploaded by file (License 5000)
ASTERISK-23958
Tested by: jrose
rb3822.patch uploaded by coreyfarrell (License 5909)
rb3800.patch uploaded by jrose (License 6182)
chan_sip.diff uploaded by mjordan (License 6283)
rb3747.patch uploaded by jrose (License 6182)
ASTERISK-23959 #close
Tested by: sgriepentrog, mjordan, coreyfarrell
sip_cleanup.diff uploaded by opticron (License 6273)
chan_sip_caps.diff uploaded by mjordan (License 6283)
rb3751.patch uploaded by coreyfarrell (License 5909)
chan_sip-3.diff uploaded by file (License 5000)
ASTERISK-23960 #close
Tested by: opticron
direct_media.diff uploaded by opticron (License 6273)
pjsip-direct-media.diff uploaded by file (License 5000)
format_cap_remove.diff uploaded by opticron (License 6273)
media_format_fixes.diff uploaded by opticron (License 6273)
chan_pjsip-2.diff uploaded by file (License 5000)
ASTERISK-23966 #close
Tested by: rmudgett
rb3803.patch uploaded by rmudgetti (License 5621)
chan_dahdi.diff uploaded by file (License 5000)
ASTERISK-24064 #close
Tested by: coreyfarrell, mjordan, opticron, file, rmudgett, sgriepentrog, jrose
rb3814.patch uploaded by rmudgett (License 5621)
moh_cleanup.diff uploaded by opticron (License 6273)
bridge_leak.diff uploaded by opticron (License 6273)
translate.diff uploaded by file (License 5000)
rb3795.patch uploaded by rmudgett (License 5621)
tls_fix.diff uploaded by mjordan (License 6283)
fax-mf-fix-2.diff uploaded by file (License 5000)
rtp_transfer_stuff uploaded by mjordan (License 6283)
rb3787.patch uploaded by rmudgett (License 5621)
media-formats-explicit-translate-format-3.diff uploaded by file (License 5000)
format_cache_case_fix.diff uploaded by opticron (License 6273)
rb3774.patch uploaded by rmudgett (License 5621)
rb3775.patch uploaded by rmudgett (License 5621)
rtp_engine_fix.diff uploaded by opticron (License 6273)
rtp_crash_fix.diff uploaded by opticron (License 6273)
rb3753.patch uploaded by mjordan (License 6283)
rb3750.patch uploaded by mjordan (License 6283)
rb3748.patch uploaded by rmudgett (License 5621)
media_format_fixes.diff uploaded by opticron (License 6273)
rb3740.patch uploaded by mjordan (License 6283)
rb3739.patch uploaded by mjordan (License 6283)
rb3734.patch uploaded by mjordan (License 6283)
rb3689.patch uploaded by mjordan (License 6283)
rb3674.patch uploaded by coreyfarrell (License 5909)
rb3671.patch uploaded by coreyfarrell (License 5909)
rb3667.patch uploaded by coreyfarrell (License 5909)
rb3665.patch uploaded by mjordan (License 6283)
rb3625.patch uploaded by coreyfarrell (License 5909)
rb3602.patch uploaded by coreyfarrell (License 5909)
format_compatibility-2.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419044 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-20 22:06:33 +00:00
|
|
|
ast_format_cap_append_from_cap(tmpcap, ast_channel_nativeformats(chan), AST_MEDIA_TYPE_AUDIO);
|
2014-09-05 20:38:27 +00:00
|
|
|
ast_channel_unlock(chan);
|
media formats: re-architect handling of media for performance improvements
In the old times media formats were represented using a bit field. This was
fast but had a few limitations.
1. Asterisk was limited in how many formats it could handle.
2. Formats, being a bit field, could not include any attribute information.
A format was strictly its type, e.g., "this is ulaw".
This was changed in Asterisk 10 (see
https://wiki.asterisk.org/wiki/display/AST/Media+Architecture+Proposal for
notes on that work) which led to the creation of the ast_format structure.
This structure allowed Asterisk to handle attributes and bundle information
with a format.
Additionally, ast_format_cap was created to act as a container for multiple
formats that, together, formed the capability of some entity. Another
mechanism was added to allow logic to be registered which performed format
attribute negotiation. Everywhere throughout the codebase Asterisk was
changed to use this strategy.
Unfortunately, in software, there is no free lunch. These new capabilities
came at a cost.
Performance analysis and profiling showed that we spend an inordinate
amount of time comparing, copying, and generally manipulating formats and
their related structures. Basic prototyping has shown that a reasonably
large performance improvement could be made in this area. This patch is the
result of that project, which overhauled the media format architecture
and its usage in Asterisk to improve performance.
Generally, the new philosophy for handling formats is as follows:
* The ast_format structure is reference counted. This removed a large amount
of the memory allocations and copying that was done in prior versions.
* In order to prevent race conditions while keeping things performant, the
ast_format structure is immutable by convention and lock-free. Violate this
tenet at your peril!
* Because formats are reference counted, codecs are also reference counted.
The Asterisk core generally provides built-in codecs and caches the
ast_format structures created to represent them. Generally, to prevent
inordinate amounts of module reference bumping, codecs and formats can be
added at run-time but cannot be removed.
* All compatibility with the bit field representation of codecs/formats has
been moved to a compatibility API. The primary user of this representation
is chan_iax2, which must continue to maintain its bit-field usage of formats
for interoperability concerns.
* When a format is negotiated with attributes, or when a format cannot be
represented by one of the cached formats, a new format object is created or
cloned from an existing format. That format may have the same codec
underlying it, but is a different format than a version of the format with
different attributes or without attributes.
* While formats are reference counted objects, the reference count maintained
on the format should be manipulated with care. Formats are generally cached
and will persist for the lifetime of Asterisk and do not explicitly need
to have their lifetime modified. An exception to this is when the user of a
format does not know where the format came from *and* the user may outlive
the provider of the format. This occurs, for example, when a format is read
from a channel: the channel may have a format with attributes (hence,
non-cached) and the user of the format may last longer than the channel (if
the reference to the channel is released prior to the format's reference).
For more information on this work, see the API design notes:
https://wiki.asterisk.org/wiki/display/AST/Media+Format+Rewrite
Finally, this work was the culmination of a large number of developer's
efforts. Extra thanks goes to Corey Farrell, who took on a large amount of the
work in the Asterisk core, chan_sip, and was an invaluable resource in peer
reviews throughout this project.
There were a substantial number of patches contributed during this work; the
following issues/patch names simply reflect some of the work (and will cause
the release scripts to give attribution to the individuals who work on them).
Reviews:
https://reviewboard.asterisk.org/r/3814
https://reviewboard.asterisk.org/r/3808
https://reviewboard.asterisk.org/r/3805
https://reviewboard.asterisk.org/r/3803
https://reviewboard.asterisk.org/r/3801
https://reviewboard.asterisk.org/r/3798
https://reviewboard.asterisk.org/r/3800
https://reviewboard.asterisk.org/r/3794
https://reviewboard.asterisk.org/r/3793
https://reviewboard.asterisk.org/r/3792
https://reviewboard.asterisk.org/r/3791
https://reviewboard.asterisk.org/r/3790
https://reviewboard.asterisk.org/r/3789
https://reviewboard.asterisk.org/r/3788
https://reviewboard.asterisk.org/r/3787
https://reviewboard.asterisk.org/r/3786
https://reviewboard.asterisk.org/r/3784
https://reviewboard.asterisk.org/r/3783
https://reviewboard.asterisk.org/r/3778
https://reviewboard.asterisk.org/r/3774
https://reviewboard.asterisk.org/r/3775
https://reviewboard.asterisk.org/r/3772
https://reviewboard.asterisk.org/r/3761
https://reviewboard.asterisk.org/r/3754
https://reviewboard.asterisk.org/r/3753
https://reviewboard.asterisk.org/r/3751
https://reviewboard.asterisk.org/r/3750
https://reviewboard.asterisk.org/r/3748
https://reviewboard.asterisk.org/r/3747
https://reviewboard.asterisk.org/r/3746
https://reviewboard.asterisk.org/r/3742
https://reviewboard.asterisk.org/r/3740
https://reviewboard.asterisk.org/r/3739
https://reviewboard.asterisk.org/r/3738
https://reviewboard.asterisk.org/r/3737
https://reviewboard.asterisk.org/r/3736
https://reviewboard.asterisk.org/r/3734
https://reviewboard.asterisk.org/r/3722
https://reviewboard.asterisk.org/r/3713
https://reviewboard.asterisk.org/r/3703
https://reviewboard.asterisk.org/r/3689
https://reviewboard.asterisk.org/r/3687
https://reviewboard.asterisk.org/r/3674
https://reviewboard.asterisk.org/r/3671
https://reviewboard.asterisk.org/r/3667
https://reviewboard.asterisk.org/r/3665
https://reviewboard.asterisk.org/r/3625
https://reviewboard.asterisk.org/r/3602
https://reviewboard.asterisk.org/r/3519
https://reviewboard.asterisk.org/r/3518
https://reviewboard.asterisk.org/r/3516
https://reviewboard.asterisk.org/r/3515
https://reviewboard.asterisk.org/r/3512
https://reviewboard.asterisk.org/r/3506
https://reviewboard.asterisk.org/r/3413
https://reviewboard.asterisk.org/r/3410
https://reviewboard.asterisk.org/r/3387
https://reviewboard.asterisk.org/r/3388
https://reviewboard.asterisk.org/r/3389
https://reviewboard.asterisk.org/r/3390
https://reviewboard.asterisk.org/r/3321
https://reviewboard.asterisk.org/r/3320
https://reviewboard.asterisk.org/r/3319
https://reviewboard.asterisk.org/r/3318
https://reviewboard.asterisk.org/r/3266
https://reviewboard.asterisk.org/r/3265
https://reviewboard.asterisk.org/r/3234
https://reviewboard.asterisk.org/r/3178
ASTERISK-23114 #close
Reported by: mjordan
media_formats_translation_core.diff uploaded by kharwell (License 6464)
rb3506.diff uploaded by mjordan (License 6283)
media_format_app_file.diff uploaded by kharwell (License 6464)
misc-2.diff uploaded by file (License 5000)
chan_mild-3.diff uploaded by file (License 5000)
chan_obscure.diff uploaded by file (License 5000)
jingle.diff uploaded by file (License 5000)
funcs.diff uploaded by file (License 5000)
formats.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
bridges.diff uploaded by file (License 5000)
mf-codecs-2.diff uploaded by file (License 5000)
mf-app_fax.diff uploaded by file (License 5000)
mf-apps-3.diff uploaded by file (License 5000)
media-formats-3.diff uploaded by file (License 5000)
ASTERISK-23715
rb3713.patch uploaded by coreyfarrell (License 5909)
rb3689.patch uploaded by mjordan (License 6283)
ASTERISK-23957
rb3722.patch uploaded by mjordan (License 6283)
mf-attributes-3.diff uploaded by file (License 5000)
ASTERISK-23958
Tested by: jrose
rb3822.patch uploaded by coreyfarrell (License 5909)
rb3800.patch uploaded by jrose (License 6182)
chan_sip.diff uploaded by mjordan (License 6283)
rb3747.patch uploaded by jrose (License 6182)
ASTERISK-23959 #close
Tested by: sgriepentrog, mjordan, coreyfarrell
sip_cleanup.diff uploaded by opticron (License 6273)
chan_sip_caps.diff uploaded by mjordan (License 6283)
rb3751.patch uploaded by coreyfarrell (License 5909)
chan_sip-3.diff uploaded by file (License 5000)
ASTERISK-23960 #close
Tested by: opticron
direct_media.diff uploaded by opticron (License 6273)
pjsip-direct-media.diff uploaded by file (License 5000)
format_cap_remove.diff uploaded by opticron (License 6273)
media_format_fixes.diff uploaded by opticron (License 6273)
chan_pjsip-2.diff uploaded by file (License 5000)
ASTERISK-23966 #close
Tested by: rmudgett
rb3803.patch uploaded by rmudgetti (License 5621)
chan_dahdi.diff uploaded by file (License 5000)
ASTERISK-24064 #close
Tested by: coreyfarrell, mjordan, opticron, file, rmudgett, sgriepentrog, jrose
rb3814.patch uploaded by rmudgett (License 5621)
moh_cleanup.diff uploaded by opticron (License 6273)
bridge_leak.diff uploaded by opticron (License 6273)
translate.diff uploaded by file (License 5000)
rb3795.patch uploaded by rmudgett (License 5621)
tls_fix.diff uploaded by mjordan (License 6283)
fax-mf-fix-2.diff uploaded by file (License 5000)
rtp_transfer_stuff uploaded by mjordan (License 6283)
rb3787.patch uploaded by rmudgett (License 5621)
media-formats-explicit-translate-format-3.diff uploaded by file (License 5000)
format_cache_case_fix.diff uploaded by opticron (License 6273)
rb3774.patch uploaded by rmudgett (License 5621)
rb3775.patch uploaded by rmudgett (License 5621)
rtp_engine_fix.diff uploaded by opticron (License 6273)
rtp_crash_fix.diff uploaded by opticron (License 6273)
rb3753.patch uploaded by mjordan (License 6283)
rb3750.patch uploaded by mjordan (License 6283)
rb3748.patch uploaded by rmudgett (License 5621)
media_format_fixes.diff uploaded by opticron (License 6273)
rb3740.patch uploaded by mjordan (License 6283)
rb3739.patch uploaded by mjordan (License 6283)
rb3734.patch uploaded by mjordan (License 6283)
rb3689.patch uploaded by mjordan (License 6283)
rb3674.patch uploaded by coreyfarrell (License 5909)
rb3671.patch uploaded by coreyfarrell (License 5909)
rb3667.patch uploaded by coreyfarrell (License 5909)
rb3665.patch uploaded by mjordan (License 6283)
rb3625.patch uploaded by coreyfarrell (License 5909)
rb3602.patch uploaded by coreyfarrell (License 5909)
format_compatibility-2.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419044 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-20 22:06:33 +00:00
|
|
|
ast_copy_string(buf, ast_format_cap_get_names(tmpcap, &codec_buf), len);
|
|
|
|
ao2_ref(tmpcap, -1);
|
2011-02-03 16:22:10 +00:00
|
|
|
}
|
|
|
|
} else if (!strcasecmp(data, "videonativeformat")) {
|
media formats: re-architect handling of media for performance improvements
In the old times media formats were represented using a bit field. This was
fast but had a few limitations.
1. Asterisk was limited in how many formats it could handle.
2. Formats, being a bit field, could not include any attribute information.
A format was strictly its type, e.g., "this is ulaw".
This was changed in Asterisk 10 (see
https://wiki.asterisk.org/wiki/display/AST/Media+Architecture+Proposal for
notes on that work) which led to the creation of the ast_format structure.
This structure allowed Asterisk to handle attributes and bundle information
with a format.
Additionally, ast_format_cap was created to act as a container for multiple
formats that, together, formed the capability of some entity. Another
mechanism was added to allow logic to be registered which performed format
attribute negotiation. Everywhere throughout the codebase Asterisk was
changed to use this strategy.
Unfortunately, in software, there is no free lunch. These new capabilities
came at a cost.
Performance analysis and profiling showed that we spend an inordinate
amount of time comparing, copying, and generally manipulating formats and
their related structures. Basic prototyping has shown that a reasonably
large performance improvement could be made in this area. This patch is the
result of that project, which overhauled the media format architecture
and its usage in Asterisk to improve performance.
Generally, the new philosophy for handling formats is as follows:
* The ast_format structure is reference counted. This removed a large amount
of the memory allocations and copying that was done in prior versions.
* In order to prevent race conditions while keeping things performant, the
ast_format structure is immutable by convention and lock-free. Violate this
tenet at your peril!
* Because formats are reference counted, codecs are also reference counted.
The Asterisk core generally provides built-in codecs and caches the
ast_format structures created to represent them. Generally, to prevent
inordinate amounts of module reference bumping, codecs and formats can be
added at run-time but cannot be removed.
* All compatibility with the bit field representation of codecs/formats has
been moved to a compatibility API. The primary user of this representation
is chan_iax2, which must continue to maintain its bit-field usage of formats
for interoperability concerns.
* When a format is negotiated with attributes, or when a format cannot be
represented by one of the cached formats, a new format object is created or
cloned from an existing format. That format may have the same codec
underlying it, but is a different format than a version of the format with
different attributes or without attributes.
* While formats are reference counted objects, the reference count maintained
on the format should be manipulated with care. Formats are generally cached
and will persist for the lifetime of Asterisk and do not explicitly need
to have their lifetime modified. An exception to this is when the user of a
format does not know where the format came from *and* the user may outlive
the provider of the format. This occurs, for example, when a format is read
from a channel: the channel may have a format with attributes (hence,
non-cached) and the user of the format may last longer than the channel (if
the reference to the channel is released prior to the format's reference).
For more information on this work, see the API design notes:
https://wiki.asterisk.org/wiki/display/AST/Media+Format+Rewrite
Finally, this work was the culmination of a large number of developer's
efforts. Extra thanks goes to Corey Farrell, who took on a large amount of the
work in the Asterisk core, chan_sip, and was an invaluable resource in peer
reviews throughout this project.
There were a substantial number of patches contributed during this work; the
following issues/patch names simply reflect some of the work (and will cause
the release scripts to give attribution to the individuals who work on them).
Reviews:
https://reviewboard.asterisk.org/r/3814
https://reviewboard.asterisk.org/r/3808
https://reviewboard.asterisk.org/r/3805
https://reviewboard.asterisk.org/r/3803
https://reviewboard.asterisk.org/r/3801
https://reviewboard.asterisk.org/r/3798
https://reviewboard.asterisk.org/r/3800
https://reviewboard.asterisk.org/r/3794
https://reviewboard.asterisk.org/r/3793
https://reviewboard.asterisk.org/r/3792
https://reviewboard.asterisk.org/r/3791
https://reviewboard.asterisk.org/r/3790
https://reviewboard.asterisk.org/r/3789
https://reviewboard.asterisk.org/r/3788
https://reviewboard.asterisk.org/r/3787
https://reviewboard.asterisk.org/r/3786
https://reviewboard.asterisk.org/r/3784
https://reviewboard.asterisk.org/r/3783
https://reviewboard.asterisk.org/r/3778
https://reviewboard.asterisk.org/r/3774
https://reviewboard.asterisk.org/r/3775
https://reviewboard.asterisk.org/r/3772
https://reviewboard.asterisk.org/r/3761
https://reviewboard.asterisk.org/r/3754
https://reviewboard.asterisk.org/r/3753
https://reviewboard.asterisk.org/r/3751
https://reviewboard.asterisk.org/r/3750
https://reviewboard.asterisk.org/r/3748
https://reviewboard.asterisk.org/r/3747
https://reviewboard.asterisk.org/r/3746
https://reviewboard.asterisk.org/r/3742
https://reviewboard.asterisk.org/r/3740
https://reviewboard.asterisk.org/r/3739
https://reviewboard.asterisk.org/r/3738
https://reviewboard.asterisk.org/r/3737
https://reviewboard.asterisk.org/r/3736
https://reviewboard.asterisk.org/r/3734
https://reviewboard.asterisk.org/r/3722
https://reviewboard.asterisk.org/r/3713
https://reviewboard.asterisk.org/r/3703
https://reviewboard.asterisk.org/r/3689
https://reviewboard.asterisk.org/r/3687
https://reviewboard.asterisk.org/r/3674
https://reviewboard.asterisk.org/r/3671
https://reviewboard.asterisk.org/r/3667
https://reviewboard.asterisk.org/r/3665
https://reviewboard.asterisk.org/r/3625
https://reviewboard.asterisk.org/r/3602
https://reviewboard.asterisk.org/r/3519
https://reviewboard.asterisk.org/r/3518
https://reviewboard.asterisk.org/r/3516
https://reviewboard.asterisk.org/r/3515
https://reviewboard.asterisk.org/r/3512
https://reviewboard.asterisk.org/r/3506
https://reviewboard.asterisk.org/r/3413
https://reviewboard.asterisk.org/r/3410
https://reviewboard.asterisk.org/r/3387
https://reviewboard.asterisk.org/r/3388
https://reviewboard.asterisk.org/r/3389
https://reviewboard.asterisk.org/r/3390
https://reviewboard.asterisk.org/r/3321
https://reviewboard.asterisk.org/r/3320
https://reviewboard.asterisk.org/r/3319
https://reviewboard.asterisk.org/r/3318
https://reviewboard.asterisk.org/r/3266
https://reviewboard.asterisk.org/r/3265
https://reviewboard.asterisk.org/r/3234
https://reviewboard.asterisk.org/r/3178
ASTERISK-23114 #close
Reported by: mjordan
media_formats_translation_core.diff uploaded by kharwell (License 6464)
rb3506.diff uploaded by mjordan (License 6283)
media_format_app_file.diff uploaded by kharwell (License 6464)
misc-2.diff uploaded by file (License 5000)
chan_mild-3.diff uploaded by file (License 5000)
chan_obscure.diff uploaded by file (License 5000)
jingle.diff uploaded by file (License 5000)
funcs.diff uploaded by file (License 5000)
formats.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
bridges.diff uploaded by file (License 5000)
mf-codecs-2.diff uploaded by file (License 5000)
mf-app_fax.diff uploaded by file (License 5000)
mf-apps-3.diff uploaded by file (License 5000)
media-formats-3.diff uploaded by file (License 5000)
ASTERISK-23715
rb3713.patch uploaded by coreyfarrell (License 5909)
rb3689.patch uploaded by mjordan (License 6283)
ASTERISK-23957
rb3722.patch uploaded by mjordan (License 6283)
mf-attributes-3.diff uploaded by file (License 5000)
ASTERISK-23958
Tested by: jrose
rb3822.patch uploaded by coreyfarrell (License 5909)
rb3800.patch uploaded by jrose (License 6182)
chan_sip.diff uploaded by mjordan (License 6283)
rb3747.patch uploaded by jrose (License 6182)
ASTERISK-23959 #close
Tested by: sgriepentrog, mjordan, coreyfarrell
sip_cleanup.diff uploaded by opticron (License 6273)
chan_sip_caps.diff uploaded by mjordan (License 6283)
rb3751.patch uploaded by coreyfarrell (License 5909)
chan_sip-3.diff uploaded by file (License 5000)
ASTERISK-23960 #close
Tested by: opticron
direct_media.diff uploaded by opticron (License 6273)
pjsip-direct-media.diff uploaded by file (License 5000)
format_cap_remove.diff uploaded by opticron (License 6273)
media_format_fixes.diff uploaded by opticron (License 6273)
chan_pjsip-2.diff uploaded by file (License 5000)
ASTERISK-23966 #close
Tested by: rmudgett
rb3803.patch uploaded by rmudgetti (License 5621)
chan_dahdi.diff uploaded by file (License 5000)
ASTERISK-24064 #close
Tested by: coreyfarrell, mjordan, opticron, file, rmudgett, sgriepentrog, jrose
rb3814.patch uploaded by rmudgett (License 5621)
moh_cleanup.diff uploaded by opticron (License 6273)
bridge_leak.diff uploaded by opticron (License 6273)
translate.diff uploaded by file (License 5000)
rb3795.patch uploaded by rmudgett (License 5621)
tls_fix.diff uploaded by mjordan (License 6283)
fax-mf-fix-2.diff uploaded by file (License 5000)
rtp_transfer_stuff uploaded by mjordan (License 6283)
rb3787.patch uploaded by rmudgett (License 5621)
media-formats-explicit-translate-format-3.diff uploaded by file (License 5000)
format_cache_case_fix.diff uploaded by opticron (License 6273)
rb3774.patch uploaded by rmudgett (License 5621)
rb3775.patch uploaded by rmudgett (License 5621)
rtp_engine_fix.diff uploaded by opticron (License 6273)
rtp_crash_fix.diff uploaded by opticron (License 6273)
rb3753.patch uploaded by mjordan (License 6283)
rb3750.patch uploaded by mjordan (License 6283)
rb3748.patch uploaded by rmudgett (License 5621)
media_format_fixes.diff uploaded by opticron (License 6273)
rb3740.patch uploaded by mjordan (License 6283)
rb3739.patch uploaded by mjordan (License 6283)
rb3734.patch uploaded by mjordan (License 6283)
rb3689.patch uploaded by mjordan (License 6283)
rb3674.patch uploaded by coreyfarrell (License 5909)
rb3671.patch uploaded by coreyfarrell (License 5909)
rb3667.patch uploaded by coreyfarrell (License 5909)
rb3665.patch uploaded by mjordan (License 6283)
rb3625.patch uploaded by coreyfarrell (License 5909)
rb3602.patch uploaded by coreyfarrell (License 5909)
format_compatibility-2.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419044 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-20 22:06:33 +00:00
|
|
|
tmpcap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
|
|
|
|
if (tmpcap) {
|
2015-11-09 09:01:41 +00:00
|
|
|
struct ast_str *codec_buf = ast_str_alloca(AST_FORMAT_CAP_NAMES_LEN);
|
2012-09-20 17:22:41 +00:00
|
|
|
|
2014-09-05 20:38:27 +00:00
|
|
|
ast_channel_lock(chan);
|
media formats: re-architect handling of media for performance improvements
In the old times media formats were represented using a bit field. This was
fast but had a few limitations.
1. Asterisk was limited in how many formats it could handle.
2. Formats, being a bit field, could not include any attribute information.
A format was strictly its type, e.g., "this is ulaw".
This was changed in Asterisk 10 (see
https://wiki.asterisk.org/wiki/display/AST/Media+Architecture+Proposal for
notes on that work) which led to the creation of the ast_format structure.
This structure allowed Asterisk to handle attributes and bundle information
with a format.
Additionally, ast_format_cap was created to act as a container for multiple
formats that, together, formed the capability of some entity. Another
mechanism was added to allow logic to be registered which performed format
attribute negotiation. Everywhere throughout the codebase Asterisk was
changed to use this strategy.
Unfortunately, in software, there is no free lunch. These new capabilities
came at a cost.
Performance analysis and profiling showed that we spend an inordinate
amount of time comparing, copying, and generally manipulating formats and
their related structures. Basic prototyping has shown that a reasonably
large performance improvement could be made in this area. This patch is the
result of that project, which overhauled the media format architecture
and its usage in Asterisk to improve performance.
Generally, the new philosophy for handling formats is as follows:
* The ast_format structure is reference counted. This removed a large amount
of the memory allocations and copying that was done in prior versions.
* In order to prevent race conditions while keeping things performant, the
ast_format structure is immutable by convention and lock-free. Violate this
tenet at your peril!
* Because formats are reference counted, codecs are also reference counted.
The Asterisk core generally provides built-in codecs and caches the
ast_format structures created to represent them. Generally, to prevent
inordinate amounts of module reference bumping, codecs and formats can be
added at run-time but cannot be removed.
* All compatibility with the bit field representation of codecs/formats has
been moved to a compatibility API. The primary user of this representation
is chan_iax2, which must continue to maintain its bit-field usage of formats
for interoperability concerns.
* When a format is negotiated with attributes, or when a format cannot be
represented by one of the cached formats, a new format object is created or
cloned from an existing format. That format may have the same codec
underlying it, but is a different format than a version of the format with
different attributes or without attributes.
* While formats are reference counted objects, the reference count maintained
on the format should be manipulated with care. Formats are generally cached
and will persist for the lifetime of Asterisk and do not explicitly need
to have their lifetime modified. An exception to this is when the user of a
format does not know where the format came from *and* the user may outlive
the provider of the format. This occurs, for example, when a format is read
from a channel: the channel may have a format with attributes (hence,
non-cached) and the user of the format may last longer than the channel (if
the reference to the channel is released prior to the format's reference).
For more information on this work, see the API design notes:
https://wiki.asterisk.org/wiki/display/AST/Media+Format+Rewrite
Finally, this work was the culmination of a large number of developer's
efforts. Extra thanks goes to Corey Farrell, who took on a large amount of the
work in the Asterisk core, chan_sip, and was an invaluable resource in peer
reviews throughout this project.
There were a substantial number of patches contributed during this work; the
following issues/patch names simply reflect some of the work (and will cause
the release scripts to give attribution to the individuals who work on them).
Reviews:
https://reviewboard.asterisk.org/r/3814
https://reviewboard.asterisk.org/r/3808
https://reviewboard.asterisk.org/r/3805
https://reviewboard.asterisk.org/r/3803
https://reviewboard.asterisk.org/r/3801
https://reviewboard.asterisk.org/r/3798
https://reviewboard.asterisk.org/r/3800
https://reviewboard.asterisk.org/r/3794
https://reviewboard.asterisk.org/r/3793
https://reviewboard.asterisk.org/r/3792
https://reviewboard.asterisk.org/r/3791
https://reviewboard.asterisk.org/r/3790
https://reviewboard.asterisk.org/r/3789
https://reviewboard.asterisk.org/r/3788
https://reviewboard.asterisk.org/r/3787
https://reviewboard.asterisk.org/r/3786
https://reviewboard.asterisk.org/r/3784
https://reviewboard.asterisk.org/r/3783
https://reviewboard.asterisk.org/r/3778
https://reviewboard.asterisk.org/r/3774
https://reviewboard.asterisk.org/r/3775
https://reviewboard.asterisk.org/r/3772
https://reviewboard.asterisk.org/r/3761
https://reviewboard.asterisk.org/r/3754
https://reviewboard.asterisk.org/r/3753
https://reviewboard.asterisk.org/r/3751
https://reviewboard.asterisk.org/r/3750
https://reviewboard.asterisk.org/r/3748
https://reviewboard.asterisk.org/r/3747
https://reviewboard.asterisk.org/r/3746
https://reviewboard.asterisk.org/r/3742
https://reviewboard.asterisk.org/r/3740
https://reviewboard.asterisk.org/r/3739
https://reviewboard.asterisk.org/r/3738
https://reviewboard.asterisk.org/r/3737
https://reviewboard.asterisk.org/r/3736
https://reviewboard.asterisk.org/r/3734
https://reviewboard.asterisk.org/r/3722
https://reviewboard.asterisk.org/r/3713
https://reviewboard.asterisk.org/r/3703
https://reviewboard.asterisk.org/r/3689
https://reviewboard.asterisk.org/r/3687
https://reviewboard.asterisk.org/r/3674
https://reviewboard.asterisk.org/r/3671
https://reviewboard.asterisk.org/r/3667
https://reviewboard.asterisk.org/r/3665
https://reviewboard.asterisk.org/r/3625
https://reviewboard.asterisk.org/r/3602
https://reviewboard.asterisk.org/r/3519
https://reviewboard.asterisk.org/r/3518
https://reviewboard.asterisk.org/r/3516
https://reviewboard.asterisk.org/r/3515
https://reviewboard.asterisk.org/r/3512
https://reviewboard.asterisk.org/r/3506
https://reviewboard.asterisk.org/r/3413
https://reviewboard.asterisk.org/r/3410
https://reviewboard.asterisk.org/r/3387
https://reviewboard.asterisk.org/r/3388
https://reviewboard.asterisk.org/r/3389
https://reviewboard.asterisk.org/r/3390
https://reviewboard.asterisk.org/r/3321
https://reviewboard.asterisk.org/r/3320
https://reviewboard.asterisk.org/r/3319
https://reviewboard.asterisk.org/r/3318
https://reviewboard.asterisk.org/r/3266
https://reviewboard.asterisk.org/r/3265
https://reviewboard.asterisk.org/r/3234
https://reviewboard.asterisk.org/r/3178
ASTERISK-23114 #close
Reported by: mjordan
media_formats_translation_core.diff uploaded by kharwell (License 6464)
rb3506.diff uploaded by mjordan (License 6283)
media_format_app_file.diff uploaded by kharwell (License 6464)
misc-2.diff uploaded by file (License 5000)
chan_mild-3.diff uploaded by file (License 5000)
chan_obscure.diff uploaded by file (License 5000)
jingle.diff uploaded by file (License 5000)
funcs.diff uploaded by file (License 5000)
formats.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
bridges.diff uploaded by file (License 5000)
mf-codecs-2.diff uploaded by file (License 5000)
mf-app_fax.diff uploaded by file (License 5000)
mf-apps-3.diff uploaded by file (License 5000)
media-formats-3.diff uploaded by file (License 5000)
ASTERISK-23715
rb3713.patch uploaded by coreyfarrell (License 5909)
rb3689.patch uploaded by mjordan (License 6283)
ASTERISK-23957
rb3722.patch uploaded by mjordan (License 6283)
mf-attributes-3.diff uploaded by file (License 5000)
ASTERISK-23958
Tested by: jrose
rb3822.patch uploaded by coreyfarrell (License 5909)
rb3800.patch uploaded by jrose (License 6182)
chan_sip.diff uploaded by mjordan (License 6283)
rb3747.patch uploaded by jrose (License 6182)
ASTERISK-23959 #close
Tested by: sgriepentrog, mjordan, coreyfarrell
sip_cleanup.diff uploaded by opticron (License 6273)
chan_sip_caps.diff uploaded by mjordan (License 6283)
rb3751.patch uploaded by coreyfarrell (License 5909)
chan_sip-3.diff uploaded by file (License 5000)
ASTERISK-23960 #close
Tested by: opticron
direct_media.diff uploaded by opticron (License 6273)
pjsip-direct-media.diff uploaded by file (License 5000)
format_cap_remove.diff uploaded by opticron (License 6273)
media_format_fixes.diff uploaded by opticron (License 6273)
chan_pjsip-2.diff uploaded by file (License 5000)
ASTERISK-23966 #close
Tested by: rmudgett
rb3803.patch uploaded by rmudgetti (License 5621)
chan_dahdi.diff uploaded by file (License 5000)
ASTERISK-24064 #close
Tested by: coreyfarrell, mjordan, opticron, file, rmudgett, sgriepentrog, jrose
rb3814.patch uploaded by rmudgett (License 5621)
moh_cleanup.diff uploaded by opticron (License 6273)
bridge_leak.diff uploaded by opticron (License 6273)
translate.diff uploaded by file (License 5000)
rb3795.patch uploaded by rmudgett (License 5621)
tls_fix.diff uploaded by mjordan (License 6283)
fax-mf-fix-2.diff uploaded by file (License 5000)
rtp_transfer_stuff uploaded by mjordan (License 6283)
rb3787.patch uploaded by rmudgett (License 5621)
media-formats-explicit-translate-format-3.diff uploaded by file (License 5000)
format_cache_case_fix.diff uploaded by opticron (License 6273)
rb3774.patch uploaded by rmudgett (License 5621)
rb3775.patch uploaded by rmudgett (License 5621)
rtp_engine_fix.diff uploaded by opticron (License 6273)
rtp_crash_fix.diff uploaded by opticron (License 6273)
rb3753.patch uploaded by mjordan (License 6283)
rb3750.patch uploaded by mjordan (License 6283)
rb3748.patch uploaded by rmudgett (License 5621)
media_format_fixes.diff uploaded by opticron (License 6273)
rb3740.patch uploaded by mjordan (License 6283)
rb3739.patch uploaded by mjordan (License 6283)
rb3734.patch uploaded by mjordan (License 6283)
rb3689.patch uploaded by mjordan (License 6283)
rb3674.patch uploaded by coreyfarrell (License 5909)
rb3671.patch uploaded by coreyfarrell (License 5909)
rb3667.patch uploaded by coreyfarrell (License 5909)
rb3665.patch uploaded by mjordan (License 6283)
rb3625.patch uploaded by coreyfarrell (License 5909)
rb3602.patch uploaded by coreyfarrell (License 5909)
format_compatibility-2.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419044 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-20 22:06:33 +00:00
|
|
|
ast_format_cap_append_from_cap(tmpcap, ast_channel_nativeformats(chan), AST_MEDIA_TYPE_VIDEO);
|
2014-09-05 20:38:27 +00:00
|
|
|
ast_channel_unlock(chan);
|
media formats: re-architect handling of media for performance improvements
In the old times media formats were represented using a bit field. This was
fast but had a few limitations.
1. Asterisk was limited in how many formats it could handle.
2. Formats, being a bit field, could not include any attribute information.
A format was strictly its type, e.g., "this is ulaw".
This was changed in Asterisk 10 (see
https://wiki.asterisk.org/wiki/display/AST/Media+Architecture+Proposal for
notes on that work) which led to the creation of the ast_format structure.
This structure allowed Asterisk to handle attributes and bundle information
with a format.
Additionally, ast_format_cap was created to act as a container for multiple
formats that, together, formed the capability of some entity. Another
mechanism was added to allow logic to be registered which performed format
attribute negotiation. Everywhere throughout the codebase Asterisk was
changed to use this strategy.
Unfortunately, in software, there is no free lunch. These new capabilities
came at a cost.
Performance analysis and profiling showed that we spend an inordinate
amount of time comparing, copying, and generally manipulating formats and
their related structures. Basic prototyping has shown that a reasonably
large performance improvement could be made in this area. This patch is the
result of that project, which overhauled the media format architecture
and its usage in Asterisk to improve performance.
Generally, the new philosophy for handling formats is as follows:
* The ast_format structure is reference counted. This removed a large amount
of the memory allocations and copying that was done in prior versions.
* In order to prevent race conditions while keeping things performant, the
ast_format structure is immutable by convention and lock-free. Violate this
tenet at your peril!
* Because formats are reference counted, codecs are also reference counted.
The Asterisk core generally provides built-in codecs and caches the
ast_format structures created to represent them. Generally, to prevent
inordinate amounts of module reference bumping, codecs and formats can be
added at run-time but cannot be removed.
* All compatibility with the bit field representation of codecs/formats has
been moved to a compatibility API. The primary user of this representation
is chan_iax2, which must continue to maintain its bit-field usage of formats
for interoperability concerns.
* When a format is negotiated with attributes, or when a format cannot be
represented by one of the cached formats, a new format object is created or
cloned from an existing format. That format may have the same codec
underlying it, but is a different format than a version of the format with
different attributes or without attributes.
* While formats are reference counted objects, the reference count maintained
on the format should be manipulated with care. Formats are generally cached
and will persist for the lifetime of Asterisk and do not explicitly need
to have their lifetime modified. An exception to this is when the user of a
format does not know where the format came from *and* the user may outlive
the provider of the format. This occurs, for example, when a format is read
from a channel: the channel may have a format with attributes (hence,
non-cached) and the user of the format may last longer than the channel (if
the reference to the channel is released prior to the format's reference).
For more information on this work, see the API design notes:
https://wiki.asterisk.org/wiki/display/AST/Media+Format+Rewrite
Finally, this work was the culmination of a large number of developer's
efforts. Extra thanks goes to Corey Farrell, who took on a large amount of the
work in the Asterisk core, chan_sip, and was an invaluable resource in peer
reviews throughout this project.
There were a substantial number of patches contributed during this work; the
following issues/patch names simply reflect some of the work (and will cause
the release scripts to give attribution to the individuals who work on them).
Reviews:
https://reviewboard.asterisk.org/r/3814
https://reviewboard.asterisk.org/r/3808
https://reviewboard.asterisk.org/r/3805
https://reviewboard.asterisk.org/r/3803
https://reviewboard.asterisk.org/r/3801
https://reviewboard.asterisk.org/r/3798
https://reviewboard.asterisk.org/r/3800
https://reviewboard.asterisk.org/r/3794
https://reviewboard.asterisk.org/r/3793
https://reviewboard.asterisk.org/r/3792
https://reviewboard.asterisk.org/r/3791
https://reviewboard.asterisk.org/r/3790
https://reviewboard.asterisk.org/r/3789
https://reviewboard.asterisk.org/r/3788
https://reviewboard.asterisk.org/r/3787
https://reviewboard.asterisk.org/r/3786
https://reviewboard.asterisk.org/r/3784
https://reviewboard.asterisk.org/r/3783
https://reviewboard.asterisk.org/r/3778
https://reviewboard.asterisk.org/r/3774
https://reviewboard.asterisk.org/r/3775
https://reviewboard.asterisk.org/r/3772
https://reviewboard.asterisk.org/r/3761
https://reviewboard.asterisk.org/r/3754
https://reviewboard.asterisk.org/r/3753
https://reviewboard.asterisk.org/r/3751
https://reviewboard.asterisk.org/r/3750
https://reviewboard.asterisk.org/r/3748
https://reviewboard.asterisk.org/r/3747
https://reviewboard.asterisk.org/r/3746
https://reviewboard.asterisk.org/r/3742
https://reviewboard.asterisk.org/r/3740
https://reviewboard.asterisk.org/r/3739
https://reviewboard.asterisk.org/r/3738
https://reviewboard.asterisk.org/r/3737
https://reviewboard.asterisk.org/r/3736
https://reviewboard.asterisk.org/r/3734
https://reviewboard.asterisk.org/r/3722
https://reviewboard.asterisk.org/r/3713
https://reviewboard.asterisk.org/r/3703
https://reviewboard.asterisk.org/r/3689
https://reviewboard.asterisk.org/r/3687
https://reviewboard.asterisk.org/r/3674
https://reviewboard.asterisk.org/r/3671
https://reviewboard.asterisk.org/r/3667
https://reviewboard.asterisk.org/r/3665
https://reviewboard.asterisk.org/r/3625
https://reviewboard.asterisk.org/r/3602
https://reviewboard.asterisk.org/r/3519
https://reviewboard.asterisk.org/r/3518
https://reviewboard.asterisk.org/r/3516
https://reviewboard.asterisk.org/r/3515
https://reviewboard.asterisk.org/r/3512
https://reviewboard.asterisk.org/r/3506
https://reviewboard.asterisk.org/r/3413
https://reviewboard.asterisk.org/r/3410
https://reviewboard.asterisk.org/r/3387
https://reviewboard.asterisk.org/r/3388
https://reviewboard.asterisk.org/r/3389
https://reviewboard.asterisk.org/r/3390
https://reviewboard.asterisk.org/r/3321
https://reviewboard.asterisk.org/r/3320
https://reviewboard.asterisk.org/r/3319
https://reviewboard.asterisk.org/r/3318
https://reviewboard.asterisk.org/r/3266
https://reviewboard.asterisk.org/r/3265
https://reviewboard.asterisk.org/r/3234
https://reviewboard.asterisk.org/r/3178
ASTERISK-23114 #close
Reported by: mjordan
media_formats_translation_core.diff uploaded by kharwell (License 6464)
rb3506.diff uploaded by mjordan (License 6283)
media_format_app_file.diff uploaded by kharwell (License 6464)
misc-2.diff uploaded by file (License 5000)
chan_mild-3.diff uploaded by file (License 5000)
chan_obscure.diff uploaded by file (License 5000)
jingle.diff uploaded by file (License 5000)
funcs.diff uploaded by file (License 5000)
formats.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
bridges.diff uploaded by file (License 5000)
mf-codecs-2.diff uploaded by file (License 5000)
mf-app_fax.diff uploaded by file (License 5000)
mf-apps-3.diff uploaded by file (License 5000)
media-formats-3.diff uploaded by file (License 5000)
ASTERISK-23715
rb3713.patch uploaded by coreyfarrell (License 5909)
rb3689.patch uploaded by mjordan (License 6283)
ASTERISK-23957
rb3722.patch uploaded by mjordan (License 6283)
mf-attributes-3.diff uploaded by file (License 5000)
ASTERISK-23958
Tested by: jrose
rb3822.patch uploaded by coreyfarrell (License 5909)
rb3800.patch uploaded by jrose (License 6182)
chan_sip.diff uploaded by mjordan (License 6283)
rb3747.patch uploaded by jrose (License 6182)
ASTERISK-23959 #close
Tested by: sgriepentrog, mjordan, coreyfarrell
sip_cleanup.diff uploaded by opticron (License 6273)
chan_sip_caps.diff uploaded by mjordan (License 6283)
rb3751.patch uploaded by coreyfarrell (License 5909)
chan_sip-3.diff uploaded by file (License 5000)
ASTERISK-23960 #close
Tested by: opticron
direct_media.diff uploaded by opticron (License 6273)
pjsip-direct-media.diff uploaded by file (License 5000)
format_cap_remove.diff uploaded by opticron (License 6273)
media_format_fixes.diff uploaded by opticron (License 6273)
chan_pjsip-2.diff uploaded by file (License 5000)
ASTERISK-23966 #close
Tested by: rmudgett
rb3803.patch uploaded by rmudgetti (License 5621)
chan_dahdi.diff uploaded by file (License 5000)
ASTERISK-24064 #close
Tested by: coreyfarrell, mjordan, opticron, file, rmudgett, sgriepentrog, jrose
rb3814.patch uploaded by rmudgett (License 5621)
moh_cleanup.diff uploaded by opticron (License 6273)
bridge_leak.diff uploaded by opticron (License 6273)
translate.diff uploaded by file (License 5000)
rb3795.patch uploaded by rmudgett (License 5621)
tls_fix.diff uploaded by mjordan (License 6283)
fax-mf-fix-2.diff uploaded by file (License 5000)
rtp_transfer_stuff uploaded by mjordan (License 6283)
rb3787.patch uploaded by rmudgett (License 5621)
media-formats-explicit-translate-format-3.diff uploaded by file (License 5000)
format_cache_case_fix.diff uploaded by opticron (License 6273)
rb3774.patch uploaded by rmudgett (License 5621)
rb3775.patch uploaded by rmudgett (License 5621)
rtp_engine_fix.diff uploaded by opticron (License 6273)
rtp_crash_fix.diff uploaded by opticron (License 6273)
rb3753.patch uploaded by mjordan (License 6283)
rb3750.patch uploaded by mjordan (License 6283)
rb3748.patch uploaded by rmudgett (License 5621)
media_format_fixes.diff uploaded by opticron (License 6273)
rb3740.patch uploaded by mjordan (License 6283)
rb3739.patch uploaded by mjordan (License 6283)
rb3734.patch uploaded by mjordan (License 6283)
rb3689.patch uploaded by mjordan (License 6283)
rb3674.patch uploaded by coreyfarrell (License 5909)
rb3671.patch uploaded by coreyfarrell (License 5909)
rb3667.patch uploaded by coreyfarrell (License 5909)
rb3665.patch uploaded by mjordan (License 6283)
rb3625.patch uploaded by coreyfarrell (License 5909)
rb3602.patch uploaded by coreyfarrell (License 5909)
format_compatibility-2.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419044 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-20 22:06:33 +00:00
|
|
|
ast_copy_string(buf, ast_format_cap_get_names(tmpcap, &codec_buf), len);
|
|
|
|
ao2_ref(tmpcap, -1);
|
2011-02-03 16:22:10 +00:00
|
|
|
}
|
|
|
|
} else if (!strcasecmp(data, "audioreadformat")) {
|
2014-09-05 20:38:27 +00:00
|
|
|
locked_copy_string(chan, buf, ast_format_get_name(ast_channel_readformat(chan)), len);
|
2011-02-03 16:22:10 +00:00
|
|
|
} else if (!strcasecmp(data, "audiowriteformat")) {
|
2014-09-05 20:38:27 +00:00
|
|
|
locked_copy_string(chan, buf, ast_format_get_name(ast_channel_writeformat(chan)), len);
|
2008-02-18 04:43:33 +00:00
|
|
|
#ifdef CHANNEL_TRACE
|
2011-02-03 16:22:10 +00:00
|
|
|
} else if (!strcasecmp(data, "trace")) {
|
2014-09-05 20:38:27 +00:00
|
|
|
locked_copy_string(chan, buf, ast_channel_trace_is_enabled(chan) ? "1" : "0", len);
|
2008-02-18 04:43:33 +00:00
|
|
|
#endif
|
2013-07-23 21:32:33 +00:00
|
|
|
} else if (!strcasecmp(data, "tonezone") && ast_channel_zone(chan)) {
|
2012-02-20 23:43:27 +00:00
|
|
|
locked_copy_string(chan, buf, ast_channel_zone(chan)->country, len);
|
2013-07-23 21:32:33 +00:00
|
|
|
} else if (!strcasecmp(data, "dtmf_features")) {
|
|
|
|
if (ast_bridge_features_ds_get_string(chan, buf, len)) {
|
|
|
|
buf[0] = '\0';
|
|
|
|
}
|
|
|
|
} else if (!strcasecmp(data, "language"))
|
2012-01-24 20:12:09 +00:00
|
|
|
locked_copy_string(chan, buf, ast_channel_language(chan), len);
|
2006-02-12 04:28:58 +00:00
|
|
|
else if (!strcasecmp(data, "musicclass"))
|
2012-01-24 20:12:09 +00:00
|
|
|
locked_copy_string(chan, buf, ast_channel_musicclass(chan), len);
|
2009-03-17 21:28:04 +00:00
|
|
|
else if (!strcasecmp(data, "name")) {
|
2012-01-09 22:15:50 +00:00
|
|
|
locked_copy_string(chan, buf, ast_channel_name(chan), len);
|
2009-03-17 21:28:04 +00:00
|
|
|
} else if (!strcasecmp(data, "parkinglot"))
|
2012-01-24 20:12:09 +00:00
|
|
|
locked_copy_string(chan, buf, ast_channel_parkinglot(chan), len);
|
2006-03-25 05:24:52 +00:00
|
|
|
else if (!strcasecmp(data, "state"))
|
2012-02-20 23:43:27 +00:00
|
|
|
locked_copy_string(chan, buf, ast_state2str(ast_channel_state(chan)), len);
|
2014-09-09 16:14:02 +00:00
|
|
|
else if (!strcasecmp(data, "onhold")) {
|
|
|
|
locked_copy_string(chan, buf,
|
|
|
|
ast_channel_hold_state(chan) == AST_CONTROL_HOLD ? "1" : "0", len);
|
|
|
|
} else if (!strcasecmp(data, "channeltype"))
|
2012-02-20 23:43:27 +00:00
|
|
|
locked_copy_string(chan, buf, ast_channel_tech(chan)->type, len);
|
2009-06-26 15:28:53 +00:00
|
|
|
else if (!strcasecmp(data, "accountcode"))
|
2012-01-24 20:12:09 +00:00
|
|
|
locked_copy_string(chan, buf, ast_channel_accountcode(chan), len);
|
2010-09-07 21:14:54 +00:00
|
|
|
else if (!strcasecmp(data, "checkhangup")) {
|
2014-09-05 20:38:27 +00:00
|
|
|
locked_copy_string(chan, buf, ast_check_hangup(chan) ? "1" : "0", len);
|
2010-09-07 21:14:54 +00:00
|
|
|
} else if (!strcasecmp(data, "peeraccount"))
|
2012-01-24 20:12:09 +00:00
|
|
|
locked_copy_string(chan, buf, ast_channel_peeraccount(chan), len);
|
2009-06-26 15:28:53 +00:00
|
|
|
else if (!strcasecmp(data, "hangupsource"))
|
2012-01-24 20:12:09 +00:00
|
|
|
locked_copy_string(chan, buf, ast_channel_hangupsource(chan), len);
|
2012-02-13 17:27:06 +00:00
|
|
|
else if (!strcasecmp(data, "appname") && ast_channel_appl(chan))
|
|
|
|
locked_copy_string(chan, buf, ast_channel_appl(chan), len);
|
|
|
|
else if (!strcasecmp(data, "appdata") && ast_channel_data(chan))
|
|
|
|
locked_copy_string(chan, buf, ast_channel_data(chan), len);
|
|
|
|
else if (!strcasecmp(data, "exten") && ast_channel_data(chan))
|
|
|
|
locked_copy_string(chan, buf, ast_channel_exten(chan), len);
|
|
|
|
else if (!strcasecmp(data, "context") && ast_channel_data(chan))
|
|
|
|
locked_copy_string(chan, buf, ast_channel_context(chan), len);
|
|
|
|
else if (!strcasecmp(data, "userfield") && ast_channel_data(chan))
|
2012-01-24 20:12:09 +00:00
|
|
|
locked_copy_string(chan, buf, ast_channel_userfield(chan), len);
|
2012-02-13 17:27:06 +00:00
|
|
|
else if (!strcasecmp(data, "channame") && ast_channel_data(chan))
|
2012-01-09 22:15:50 +00:00
|
|
|
locked_copy_string(chan, buf, ast_channel_name(chan), len);
|
2009-06-26 15:28:53 +00:00
|
|
|
else if (!strcasecmp(data, "linkedid")) {
|
|
|
|
ast_channel_lock(chan);
|
2012-01-24 20:12:09 +00:00
|
|
|
if (ast_strlen_zero(ast_channel_linkedid(chan))) {
|
2009-06-26 15:28:53 +00:00
|
|
|
/* fall back on the channel's uniqueid if linkedid is unset */
|
2012-01-24 20:12:09 +00:00
|
|
|
ast_copy_string(buf, ast_channel_uniqueid(chan), len);
|
2009-06-26 15:28:53 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-01-24 20:12:09 +00:00
|
|
|
ast_copy_string(buf, ast_channel_linkedid(chan), len);
|
2009-06-26 15:28:53 +00:00
|
|
|
}
|
|
|
|
ast_channel_unlock(chan);
|
|
|
|
} else if (!strcasecmp(data, "peer")) {
|
2015-01-20 16:59:30 +00:00
|
|
|
struct ast_channel *peer;
|
2012-09-20 17:22:41 +00:00
|
|
|
|
2015-01-20 16:59:30 +00:00
|
|
|
peer = ast_channel_bridge_peer(chan);
|
|
|
|
if (peer) {
|
|
|
|
/* Only real channels could have a bridge peer this way. */
|
|
|
|
ast_channel_lock(peer);
|
|
|
|
ast_copy_string(buf, ast_channel_name(peer), len);
|
|
|
|
ast_channel_unlock(peer);
|
|
|
|
ast_channel_unref(peer);
|
|
|
|
} else {
|
|
|
|
buf[0] = '\0';
|
|
|
|
ast_channel_lock(chan);
|
|
|
|
if (!ast_channel_tech(chan)) {
|
|
|
|
const char *pname;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A dummy channel can still pass along bridged peer info
|
|
|
|
* via the BRIDGEPEER variable.
|
|
|
|
*
|
|
|
|
* A horrible kludge, but... how else?
|
|
|
|
*/
|
|
|
|
pname = pbx_builtin_getvar_helper(chan, "BRIDGEPEER");
|
|
|
|
if (!ast_strlen_zero(pname)) {
|
|
|
|
ast_copy_string(buf, pname, len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ast_channel_unlock(chan);
|
2009-06-26 15:28:53 +00:00
|
|
|
}
|
|
|
|
} else if (!strcasecmp(data, "uniqueid")) {
|
2012-01-24 20:12:09 +00:00
|
|
|
locked_copy_string(chan, buf, ast_channel_uniqueid(chan), len);
|
2011-02-03 16:22:10 +00:00
|
|
|
} else if (!strcasecmp(data, "transfercapability")) {
|
2012-02-20 23:43:27 +00:00
|
|
|
locked_copy_string(chan, buf, transfercapability_table[ast_channel_transfercapability(chan) & 0x1f], len);
|
2011-02-03 16:22:10 +00:00
|
|
|
} else if (!strcasecmp(data, "callgroup")) {
|
2006-03-25 05:24:52 +00:00
|
|
|
char groupbuf[256];
|
2012-09-20 17:22:41 +00:00
|
|
|
|
2012-03-01 22:09:18 +00:00
|
|
|
locked_copy_string(chan, buf, ast_print_group(groupbuf, sizeof(groupbuf), ast_channel_callgroup(chan)), len);
|
2011-05-25 15:43:28 +00:00
|
|
|
} else if (!strcasecmp(data, "pickupgroup")) {
|
|
|
|
char groupbuf[256];
|
2012-09-20 17:22:41 +00:00
|
|
|
|
2012-03-01 22:09:18 +00:00
|
|
|
locked_copy_string(chan, buf, ast_print_group(groupbuf, sizeof(groupbuf), ast_channel_pickupgroup(chan)), len);
|
2012-09-20 17:22:41 +00:00
|
|
|
} else if (!strcasecmp(data, "namedcallgroup")) {
|
|
|
|
struct ast_str *tmp_str = ast_str_alloca(1024);
|
|
|
|
|
|
|
|
locked_copy_string(chan, buf, ast_print_namedgroups(&tmp_str, ast_channel_named_callgroups(chan)), len);
|
|
|
|
} else if (!strcasecmp(data, "namedpickupgroup")) {
|
|
|
|
struct ast_str *tmp_str = ast_str_alloca(1024);
|
|
|
|
|
|
|
|
locked_copy_string(chan, buf, ast_print_namedgroups(&tmp_str, ast_channel_named_pickupgroups(chan)), len);
|
2013-06-26 20:59:14 +00:00
|
|
|
} else if (!strcasecmp(data, "after_bridge_goto")) {
|
2013-07-25 02:20:23 +00:00
|
|
|
ast_bridge_read_after_goto(chan, buf, len);
|
2009-06-26 15:28:53 +00:00
|
|
|
} else if (!strcasecmp(data, "amaflags")) {
|
2012-09-20 17:22:41 +00:00
|
|
|
ast_channel_lock(chan);
|
2014-05-09 22:49:26 +00:00
|
|
|
snprintf(buf, len, "%u", ast_channel_amaflags(chan));
|
2012-09-20 17:22:41 +00:00
|
|
|
ast_channel_unlock(chan);
|
2010-06-08 05:29:08 +00:00
|
|
|
} else if (!strncasecmp(data, "secure_bridge_", 14)) {
|
|
|
|
struct ast_datastore *ds;
|
2012-09-20 17:22:41 +00:00
|
|
|
|
2014-09-05 20:38:27 +00:00
|
|
|
buf[0] = '\0';
|
2010-06-08 05:29:08 +00:00
|
|
|
ast_channel_lock(chan);
|
|
|
|
if ((ds = ast_channel_datastore_find(chan, &secure_call_info, NULL))) {
|
|
|
|
struct ast_secure_call_store *encrypt = ds->data;
|
2014-09-05 20:38:27 +00:00
|
|
|
|
2010-06-08 05:29:08 +00:00
|
|
|
if (!strcasecmp(data, "secure_bridge_signaling")) {
|
|
|
|
snprintf(buf, len, "%s", encrypt->signaling ? "1" : "");
|
|
|
|
} else if (!strcasecmp(data, "secure_bridge_media")) {
|
|
|
|
snprintf(buf, len, "%s", encrypt->media ? "1" : "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ast_channel_unlock(chan);
|
2015-04-15 15:38:02 +00:00
|
|
|
} else if (!strcasecmp(data, "max_forwards")) {
|
|
|
|
ast_channel_lock(chan);
|
|
|
|
snprintf(buf, len, "%d", ast_max_forwards_get(chan));
|
|
|
|
ast_channel_unlock(chan);
|
2012-02-20 23:43:27 +00:00
|
|
|
} else if (!ast_channel_tech(chan) || !ast_channel_tech(chan)->func_channel_read || ast_channel_tech(chan)->func_channel_read(chan, function, data, buf, len)) {
|
2006-02-12 04:28:58 +00:00
|
|
|
ast_log(LOG_WARNING, "Unknown or unavailable item requested: '%s'\n", data);
|
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-09-10 22:15:47 +00:00
|
|
|
static int func_channel_write_real(struct ast_channel *chan, const char *function,
|
2006-02-12 04:28:58 +00:00
|
|
|
char *data, const char *value)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
2006-05-03 22:02:50 +00:00
|
|
|
signed char gainset;
|
2006-02-12 04:28:58 +00:00
|
|
|
|
|
|
|
if (!strcasecmp(data, "language"))
|
|
|
|
locked_string_field_set(chan, language, value);
|
2008-04-21 23:42:45 +00:00
|
|
|
else if (!strcasecmp(data, "parkinglot"))
|
|
|
|
locked_string_field_set(chan, parkinglot, value);
|
2006-02-12 04:28:58 +00:00
|
|
|
else if (!strcasecmp(data, "musicclass"))
|
|
|
|
locked_string_field_set(chan, musicclass, value);
|
2009-06-26 15:28:53 +00:00
|
|
|
else if (!strcasecmp(data, "accountcode"))
|
|
|
|
locked_string_field_set(chan, accountcode, value);
|
|
|
|
else if (!strcasecmp(data, "userfield"))
|
|
|
|
locked_string_field_set(chan, userfield, value);
|
2013-06-26 20:59:14 +00:00
|
|
|
else if (!strcasecmp(data, "after_bridge_goto")) {
|
|
|
|
if (ast_strlen_zero(value)) {
|
2013-07-25 02:20:23 +00:00
|
|
|
ast_bridge_discard_after_goto(chan);
|
2013-06-26 20:59:14 +00:00
|
|
|
} else {
|
2013-07-25 02:20:23 +00:00
|
|
|
ast_bridge_set_after_go_on(chan, ast_channel_context(chan), ast_channel_exten(chan), ast_channel_priority(chan), value);
|
2013-06-26 20:59:14 +00:00
|
|
|
}
|
|
|
|
} else if (!strcasecmp(data, "amaflags")) {
|
2009-06-26 15:28:53 +00:00
|
|
|
ast_channel_lock(chan);
|
2013-06-17 03:00:38 +00:00
|
|
|
if (isdigit(*value)) {
|
2012-02-20 23:43:27 +00:00
|
|
|
int amaflags;
|
|
|
|
sscanf(value, "%30d", &amaflags);
|
|
|
|
ast_channel_amaflags_set(chan, amaflags);
|
2009-06-26 15:28:53 +00:00
|
|
|
} else if (!strcasecmp(value,"OMIT")){
|
2012-02-20 23:43:27 +00:00
|
|
|
ast_channel_amaflags_set(chan, 1);
|
2009-06-26 15:28:53 +00:00
|
|
|
} else if (!strcasecmp(value,"BILLING")){
|
2012-02-20 23:43:27 +00:00
|
|
|
ast_channel_amaflags_set(chan, 2);
|
2009-06-26 15:28:53 +00:00
|
|
|
} else if (!strcasecmp(value,"DOCUMENTATION")){
|
2012-02-20 23:43:27 +00:00
|
|
|
ast_channel_amaflags_set(chan, 3);
|
2009-06-26 15:28:53 +00:00
|
|
|
}
|
|
|
|
ast_channel_unlock(chan);
|
|
|
|
} else if (!strcasecmp(data, "peeraccount"))
|
|
|
|
locked_string_field_set(chan, peeraccount, value);
|
|
|
|
else if (!strcasecmp(data, "hangupsource"))
|
|
|
|
/* XXX - should we be forcing this here? */
|
|
|
|
ast_set_hangupsource(chan, value, 0);
|
2008-02-18 04:43:33 +00:00
|
|
|
#ifdef CHANNEL_TRACE
|
|
|
|
else if (!strcasecmp(data, "trace")) {
|
|
|
|
ast_channel_lock(chan);
|
2013-07-21 22:09:23 +00:00
|
|
|
if (ast_true(value))
|
2008-02-18 04:43:33 +00:00
|
|
|
ret = ast_channel_trace_enable(chan);
|
2009-06-26 15:28:53 +00:00
|
|
|
else if (ast_false(value))
|
2008-02-18 04:43:33 +00:00
|
|
|
ret = ast_channel_trace_disable(chan);
|
|
|
|
else {
|
|
|
|
ret = -1;
|
2012-04-06 18:19:03 +00:00
|
|
|
ast_log(LOG_WARNING, "Invalid value for CHANNEL(trace).\n");
|
2008-02-18 04:43:33 +00:00
|
|
|
}
|
|
|
|
ast_channel_unlock(chan);
|
|
|
|
}
|
|
|
|
#endif
|
2006-06-04 11:47:51 +00:00
|
|
|
else if (!strcasecmp(data, "tonezone")) {
|
2009-02-17 20:41:24 +00:00
|
|
|
struct ast_tone_zone *new_zone;
|
2006-11-16 08:18:41 +00:00
|
|
|
if (!(new_zone = ast_get_indication_zone(value))) {
|
|
|
|
ast_log(LOG_ERROR, "Unknown country code '%s' for tonezone. Check indications.conf for available country codes.\n", value);
|
2013-07-21 22:09:23 +00:00
|
|
|
ret = -1;
|
2009-02-17 20:41:24 +00:00
|
|
|
} else {
|
|
|
|
ast_channel_lock(chan);
|
2012-02-20 23:43:27 +00:00
|
|
|
if (ast_channel_zone(chan)) {
|
|
|
|
ast_channel_zone_set(chan, ast_tone_zone_unref(ast_channel_zone(chan)));
|
2009-02-17 20:41:24 +00:00
|
|
|
}
|
2012-02-20 23:43:27 +00:00
|
|
|
ast_channel_zone_set(chan, ast_tone_zone_ref(new_zone));
|
2009-02-17 20:41:24 +00:00
|
|
|
ast_channel_unlock(chan);
|
|
|
|
new_zone = ast_tone_zone_unref(new_zone);
|
|
|
|
}
|
2013-07-23 21:32:33 +00:00
|
|
|
} else if (!strcasecmp(data, "dtmf_features")) {
|
|
|
|
ret = ast_bridge_features_ds_set_string(chan, value);
|
2011-05-25 15:43:28 +00:00
|
|
|
} else if (!strcasecmp(data, "callgroup")) {
|
2012-09-20 17:22:41 +00:00
|
|
|
ast_channel_lock(chan);
|
2012-03-01 22:09:18 +00:00
|
|
|
ast_channel_callgroup_set(chan, ast_get_group(value));
|
2012-09-20 17:22:41 +00:00
|
|
|
ast_channel_unlock(chan);
|
2011-05-25 15:43:28 +00:00
|
|
|
} else if (!strcasecmp(data, "pickupgroup")) {
|
2012-09-20 17:22:41 +00:00
|
|
|
ast_channel_lock(chan);
|
2012-03-01 22:09:18 +00:00
|
|
|
ast_channel_pickupgroup_set(chan, ast_get_group(value));
|
2012-09-20 17:22:41 +00:00
|
|
|
ast_channel_unlock(chan);
|
|
|
|
} else if (!strcasecmp(data, "namedcallgroup")) {
|
|
|
|
struct ast_namedgroups *groups = ast_get_namedgroups(value);
|
|
|
|
|
|
|
|
ast_channel_lock(chan);
|
|
|
|
ast_channel_named_callgroups_set(chan, groups);
|
|
|
|
ast_channel_unlock(chan);
|
|
|
|
ast_unref_namedgroups(groups);
|
|
|
|
} else if (!strcasecmp(data, "namedpickupgroup")) {
|
|
|
|
struct ast_namedgroups *groups = ast_get_namedgroups(value);
|
|
|
|
|
|
|
|
ast_channel_lock(chan);
|
|
|
|
ast_channel_named_pickupgroups_set(chan, groups);
|
|
|
|
ast_channel_unlock(chan);
|
|
|
|
ast_unref_namedgroups(groups);
|
2011-05-25 15:43:28 +00:00
|
|
|
} else if (!strcasecmp(data, "txgain")) {
|
2009-08-10 19:20:57 +00:00
|
|
|
sscanf(value, "%4hhd", &gainset);
|
2006-05-03 22:02:50 +00:00
|
|
|
ast_channel_setoption(chan, AST_OPTION_TXGAIN, &gainset, sizeof(gainset), 0);
|
|
|
|
} else if (!strcasecmp(data, "rxgain")) {
|
2009-08-10 19:20:57 +00:00
|
|
|
sscanf(value, "%4hhd", &gainset);
|
2006-05-25 19:07:31 +00:00
|
|
|
ast_channel_setoption(chan, AST_OPTION_RXGAIN, &gainset, sizeof(gainset), 0);
|
|
|
|
} else if (!strcasecmp(data, "transfercapability")) {
|
|
|
|
unsigned short i;
|
2012-09-20 17:22:41 +00:00
|
|
|
|
|
|
|
ast_channel_lock(chan);
|
2006-05-25 19:07:31 +00:00
|
|
|
for (i = 0; i < 0x20; i++) {
|
|
|
|
if (!strcasecmp(transfercapability_table[i], value) && strcmp(value, "UNK")) {
|
2012-02-20 23:43:27 +00:00
|
|
|
ast_channel_transfercapability_set(chan, i);
|
2006-05-25 19:07:31 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-09-20 17:22:41 +00:00
|
|
|
ast_channel_unlock(chan);
|
2012-06-29 17:02:32 +00:00
|
|
|
} else if (!strcasecmp(data, "hangup_handler_pop")) {
|
|
|
|
/* Pop one hangup handler before pushing the new handler. */
|
|
|
|
ast_pbx_hangup_handler_pop(chan);
|
|
|
|
ast_pbx_hangup_handler_push(chan, value);
|
|
|
|
} else if (!strcasecmp(data, "hangup_handler_push")) {
|
|
|
|
ast_pbx_hangup_handler_push(chan, value);
|
|
|
|
} else if (!strcasecmp(data, "hangup_handler_wipe")) {
|
|
|
|
/* Pop all hangup handlers before pushing the new handler. */
|
|
|
|
while (ast_pbx_hangup_handler_pop(chan)) {
|
|
|
|
}
|
|
|
|
ast_pbx_hangup_handler_push(chan, value);
|
2010-06-08 05:29:08 +00:00
|
|
|
} else if (!strncasecmp(data, "secure_bridge_", 14)) {
|
|
|
|
struct ast_datastore *ds;
|
|
|
|
struct ast_secure_call_store *store;
|
|
|
|
|
|
|
|
if (!chan || !value) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ast_channel_lock(chan);
|
|
|
|
if (!(ds = ast_channel_datastore_find(chan, &secure_call_info, NULL))) {
|
|
|
|
if (!(ds = ast_datastore_alloc(&secure_call_info, NULL))) {
|
|
|
|
ast_channel_unlock(chan);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (!(store = ast_calloc(1, sizeof(*store)))) {
|
|
|
|
ast_channel_unlock(chan);
|
|
|
|
ast_free(ds);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
ds->data = store;
|
|
|
|
ast_channel_datastore_add(chan, ds);
|
|
|
|
} else {
|
|
|
|
store = ds->data;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcasecmp(data, "secure_bridge_signaling")) {
|
|
|
|
store->signaling = ast_true(value) ? 1 : 0;
|
|
|
|
} else if (!strcasecmp(data, "secure_bridge_media")) {
|
|
|
|
store->media = ast_true(value) ? 1 : 0;
|
|
|
|
}
|
2012-09-20 17:22:41 +00:00
|
|
|
ast_channel_unlock(chan);
|
2015-04-15 15:38:02 +00:00
|
|
|
} else if (!strcasecmp(data, "max_forwards")) {
|
|
|
|
int max_forwards;
|
|
|
|
if (sscanf(value, "%d", &max_forwards) != 1) {
|
|
|
|
ast_log(LOG_WARNING, "Unable to set max forwards to '%s'\n", value);
|
|
|
|
ret = -1;
|
|
|
|
} else {
|
|
|
|
ast_channel_lock(chan);
|
|
|
|
ret = ast_max_forwards_set(chan, max_forwards);
|
|
|
|
ast_channel_unlock(chan);
|
|
|
|
}
|
2012-02-20 23:43:27 +00:00
|
|
|
} else if (!ast_channel_tech(chan)->func_channel_write
|
|
|
|
|| ast_channel_tech(chan)->func_channel_write(chan, function, data, value)) {
|
2006-02-12 04:28:58 +00:00
|
|
|
ast_log(LOG_WARNING, "Unknown or unavailable item requested: '%s'\n",
|
|
|
|
data);
|
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-09-10 22:15:47 +00:00
|
|
|
static int func_channel_write(struct ast_channel *chan, const char *function, char *data, const char *value)
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
ast_chan_write_info_t write_info = {
|
|
|
|
.version = AST_CHAN_WRITE_INFO_T_VERSION,
|
|
|
|
.write_fn = func_channel_write_real,
|
|
|
|
.chan = chan,
|
|
|
|
.function = function,
|
|
|
|
.data = data,
|
|
|
|
.value = value,
|
|
|
|
};
|
|
|
|
|
2014-03-27 19:21:44 +00:00
|
|
|
if (!chan) {
|
|
|
|
ast_log(LOG_WARNING, "No channel was provided to %s function.\n", function);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-09-10 22:15:47 +00:00
|
|
|
res = func_channel_write_real(chan, function, data, value);
|
|
|
|
ast_channel_setoption(chan, AST_OPTION_CHANNEL_WRITE, &write_info, sizeof(write_info), 0);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2006-02-12 04:28:58 +00:00
|
|
|
static struct ast_custom_function channel_function = {
|
|
|
|
.name = "CHANNEL",
|
|
|
|
.read = func_channel_read,
|
|
|
|
.write = func_channel_write,
|
|
|
|
};
|
|
|
|
|
2008-06-03 23:17:33 +00:00
|
|
|
static int func_channels_read(struct ast_channel *chan, const char *function, char *data, char *buf, size_t maxlen)
|
|
|
|
{
|
|
|
|
struct ast_channel *c = NULL;
|
|
|
|
regex_t re;
|
|
|
|
int res;
|
|
|
|
size_t buflen = 0;
|
Convert the ast_channel data structure over to the astobj2 framework.
There is a lot that could be said about this, but the patch is a big
improvement for performance, stability, code maintainability,
and ease of future code development.
The channel list is no longer an unsorted linked list. The main container
for channels is an astobj2 hash table. All of the code related to searching
for channels or iterating active channels has been rewritten. Let n be
the number of active channels. Iterating the channel list has gone from
O(n^2) to O(n). Searching for a channel by name went from O(n) to O(1).
Searching for a channel by extension is still O(n), but uses a new method
for doing so, which is more efficient.
The ast_channel object is now a reference counted object. The benefits
here are plentiful. Some benefits directly related to issues in the
previous code include:
1) When threads other than the channel thread owning a channel wanted
access to a channel, it had to hold the lock on it to ensure that it didn't
go away. This is no longer a requirement. Holding a reference is
sufficient.
2) There are places that now require less dealing with channel locks.
3) There are places where channel locks are held for much shorter periods
of time.
4) There are places where dealing with more than one channel at a time becomes
_MUCH_ easier. ChanSpy is a great example of this. Writing code in the
future that deals with multiple channels will be much easier.
Some additional information regarding channel locking and reference count
handling can be found in channel.h, where a new section has been added that
discusses some of the rules associated with it.
Mark Michelson also assisted with the development of this patch. He did the
conversion of ChanSpy and introduced a new API, ast_autochan, which makes it
much easier to deal with holding on to a channel pointer for an extended period
of time and having it get automatically updated if the channel gets masqueraded.
Mark was also a huge help in the code review process.
Thanks to David Vossel for his assistance with this branch, as well. David
did the conversion of the DAHDIScan application by making it become a wrapper
for ChanSpy internally.
The changes come from the svn/asterisk/team/russell/ast_channel_ao2 branch.
Review: http://reviewboard.digium.com/r/203/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@190423 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-04-24 14:04:26 +00:00
|
|
|
struct ast_channel_iterator *iter;
|
|
|
|
|
2008-06-03 23:17:33 +00:00
|
|
|
buf[0] = '\0';
|
|
|
|
|
|
|
|
if (!ast_strlen_zero(data)) {
|
|
|
|
if ((res = regcomp(&re, data, REG_EXTENDED | REG_ICASE | REG_NOSUB))) {
|
|
|
|
regerror(res, &re, buf, maxlen);
|
|
|
|
ast_log(LOG_WARNING, "Error compiling regular expression for %s(%s): %s\n", function, data, buf);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-21 21:08:47 +00:00
|
|
|
if (!(iter = ast_channel_iterator_all_new())) {
|
Convert the ast_channel data structure over to the astobj2 framework.
There is a lot that could be said about this, but the patch is a big
improvement for performance, stability, code maintainability,
and ease of future code development.
The channel list is no longer an unsorted linked list. The main container
for channels is an astobj2 hash table. All of the code related to searching
for channels or iterating active channels has been rewritten. Let n be
the number of active channels. Iterating the channel list has gone from
O(n^2) to O(n). Searching for a channel by name went from O(n) to O(1).
Searching for a channel by extension is still O(n), but uses a new method
for doing so, which is more efficient.
The ast_channel object is now a reference counted object. The benefits
here are plentiful. Some benefits directly related to issues in the
previous code include:
1) When threads other than the channel thread owning a channel wanted
access to a channel, it had to hold the lock on it to ensure that it didn't
go away. This is no longer a requirement. Holding a reference is
sufficient.
2) There are places that now require less dealing with channel locks.
3) There are places where channel locks are held for much shorter periods
of time.
4) There are places where dealing with more than one channel at a time becomes
_MUCH_ easier. ChanSpy is a great example of this. Writing code in the
future that deals with multiple channels will be much easier.
Some additional information regarding channel locking and reference count
handling can be found in channel.h, where a new section has been added that
discusses some of the rules associated with it.
Mark Michelson also assisted with the development of this patch. He did the
conversion of ChanSpy and introduced a new API, ast_autochan, which makes it
much easier to deal with holding on to a channel pointer for an extended period
of time and having it get automatically updated if the channel gets masqueraded.
Mark was also a huge help in the code review process.
Thanks to David Vossel for his assistance with this branch, as well. David
did the conversion of the DAHDIScan application by making it become a wrapper
for ChanSpy internally.
The changes come from the svn/asterisk/team/russell/ast_channel_ao2 branch.
Review: http://reviewboard.digium.com/r/203/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@190423 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-04-24 14:04:26 +00:00
|
|
|
if (!ast_strlen_zero(data)) {
|
|
|
|
regfree(&re);
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
while ((c = ast_channel_iterator_next(iter))) {
|
|
|
|
ast_channel_lock(c);
|
2012-01-09 22:15:50 +00:00
|
|
|
if (ast_strlen_zero(data) || regexec(&re, ast_channel_name(c), 0, NULL, 0) == 0) {
|
|
|
|
size_t namelen = strlen(ast_channel_name(c));
|
2008-06-03 23:17:33 +00:00
|
|
|
if (buflen + namelen + (ast_strlen_zero(buf) ? 0 : 1) + 1 < maxlen) {
|
|
|
|
if (!ast_strlen_zero(buf)) {
|
|
|
|
strcat(buf, " ");
|
|
|
|
buflen++;
|
|
|
|
}
|
2012-01-09 22:15:50 +00:00
|
|
|
strcat(buf, ast_channel_name(c));
|
2008-06-03 23:17:33 +00:00
|
|
|
buflen += namelen;
|
|
|
|
} else {
|
|
|
|
ast_log(LOG_WARNING, "Number of channels exceeds the available buffer space. Output will be truncated!\n");
|
|
|
|
}
|
|
|
|
}
|
Convert the ast_channel data structure over to the astobj2 framework.
There is a lot that could be said about this, but the patch is a big
improvement for performance, stability, code maintainability,
and ease of future code development.
The channel list is no longer an unsorted linked list. The main container
for channels is an astobj2 hash table. All of the code related to searching
for channels or iterating active channels has been rewritten. Let n be
the number of active channels. Iterating the channel list has gone from
O(n^2) to O(n). Searching for a channel by name went from O(n) to O(1).
Searching for a channel by extension is still O(n), but uses a new method
for doing so, which is more efficient.
The ast_channel object is now a reference counted object. The benefits
here are plentiful. Some benefits directly related to issues in the
previous code include:
1) When threads other than the channel thread owning a channel wanted
access to a channel, it had to hold the lock on it to ensure that it didn't
go away. This is no longer a requirement. Holding a reference is
sufficient.
2) There are places that now require less dealing with channel locks.
3) There are places where channel locks are held for much shorter periods
of time.
4) There are places where dealing with more than one channel at a time becomes
_MUCH_ easier. ChanSpy is a great example of this. Writing code in the
future that deals with multiple channels will be much easier.
Some additional information regarding channel locking and reference count
handling can be found in channel.h, where a new section has been added that
discusses some of the rules associated with it.
Mark Michelson also assisted with the development of this patch. He did the
conversion of ChanSpy and introduced a new API, ast_autochan, which makes it
much easier to deal with holding on to a channel pointer for an extended period
of time and having it get automatically updated if the channel gets masqueraded.
Mark was also a huge help in the code review process.
Thanks to David Vossel for his assistance with this branch, as well. David
did the conversion of the DAHDIScan application by making it become a wrapper
for ChanSpy internally.
The changes come from the svn/asterisk/team/russell/ast_channel_ao2 branch.
Review: http://reviewboard.digium.com/r/203/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@190423 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-04-24 14:04:26 +00:00
|
|
|
ast_channel_unlock(c);
|
|
|
|
c = ast_channel_unref(c);
|
2008-06-03 23:17:33 +00:00
|
|
|
}
|
|
|
|
|
Convert the ast_channel data structure over to the astobj2 framework.
There is a lot that could be said about this, but the patch is a big
improvement for performance, stability, code maintainability,
and ease of future code development.
The channel list is no longer an unsorted linked list. The main container
for channels is an astobj2 hash table. All of the code related to searching
for channels or iterating active channels has been rewritten. Let n be
the number of active channels. Iterating the channel list has gone from
O(n^2) to O(n). Searching for a channel by name went from O(n) to O(1).
Searching for a channel by extension is still O(n), but uses a new method
for doing so, which is more efficient.
The ast_channel object is now a reference counted object. The benefits
here are plentiful. Some benefits directly related to issues in the
previous code include:
1) When threads other than the channel thread owning a channel wanted
access to a channel, it had to hold the lock on it to ensure that it didn't
go away. This is no longer a requirement. Holding a reference is
sufficient.
2) There are places that now require less dealing with channel locks.
3) There are places where channel locks are held for much shorter periods
of time.
4) There are places where dealing with more than one channel at a time becomes
_MUCH_ easier. ChanSpy is a great example of this. Writing code in the
future that deals with multiple channels will be much easier.
Some additional information regarding channel locking and reference count
handling can be found in channel.h, where a new section has been added that
discusses some of the rules associated with it.
Mark Michelson also assisted with the development of this patch. He did the
conversion of ChanSpy and introduced a new API, ast_autochan, which makes it
much easier to deal with holding on to a channel pointer for an extended period
of time and having it get automatically updated if the channel gets masqueraded.
Mark was also a huge help in the code review process.
Thanks to David Vossel for his assistance with this branch, as well. David
did the conversion of the DAHDIScan application by making it become a wrapper
for ChanSpy internally.
The changes come from the svn/asterisk/team/russell/ast_channel_ao2 branch.
Review: http://reviewboard.digium.com/r/203/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@190423 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-04-24 14:04:26 +00:00
|
|
|
ast_channel_iterator_destroy(iter);
|
|
|
|
|
2008-06-03 23:17:33 +00:00
|
|
|
if (!ast_strlen_zero(data)) {
|
|
|
|
regfree(&re);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ast_custom_function channels_function = {
|
|
|
|
.name = "CHANNELS",
|
|
|
|
.read = func_channels_read,
|
|
|
|
};
|
|
|
|
|
2009-09-01 23:41:06 +00:00
|
|
|
static int func_mchan_read(struct ast_channel *chan, const char *function,
|
|
|
|
char *data, struct ast_str **buf, ssize_t len)
|
|
|
|
{
|
2014-03-27 19:21:44 +00:00
|
|
|
struct ast_channel *mchan;
|
2012-07-31 20:21:43 +00:00
|
|
|
char *template = ast_alloca(4 + strlen(data));
|
2014-03-27 19:21:44 +00:00
|
|
|
|
|
|
|
if (!chan) {
|
|
|
|
ast_log(LOG_WARNING, "No channel was provided to %s function.\n", function);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
mchan = ast_channel_get_by_name(ast_channel_linkedid(chan));
|
2009-09-01 23:41:06 +00:00
|
|
|
sprintf(template, "${%s}", data); /* SAFE */
|
|
|
|
ast_str_substitute_variables(buf, len, mchan ? mchan : chan, template);
|
|
|
|
if (mchan) {
|
|
|
|
ast_channel_unref(mchan);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int func_mchan_write(struct ast_channel *chan, const char *function,
|
|
|
|
char *data, const char *value)
|
|
|
|
{
|
2014-03-27 19:21:44 +00:00
|
|
|
struct ast_channel *mchan;
|
|
|
|
|
|
|
|
if (!chan) {
|
|
|
|
ast_log(LOG_WARNING, "No channel was provided to %s function.\n", function);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
mchan = ast_channel_get_by_name(ast_channel_linkedid(chan));
|
2009-09-01 23:41:06 +00:00
|
|
|
pbx_builtin_setvar_helper(mchan ? mchan : chan, data, value);
|
|
|
|
if (mchan) {
|
|
|
|
ast_channel_unref(mchan);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ast_custom_function mchan_function = {
|
|
|
|
.name = "MASTER_CHANNEL",
|
|
|
|
.read2 = func_mchan_read,
|
|
|
|
.write = func_mchan_write,
|
|
|
|
};
|
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
static int unload_module(void)
|
2006-02-12 04:28:58 +00:00
|
|
|
{
|
2008-06-03 23:17:33 +00:00
|
|
|
int res = 0;
|
2009-09-01 23:41:06 +00:00
|
|
|
|
2008-06-03 23:17:33 +00:00
|
|
|
res |= ast_custom_function_unregister(&channel_function);
|
|
|
|
res |= ast_custom_function_unregister(&channels_function);
|
2009-09-01 23:41:06 +00:00
|
|
|
res |= ast_custom_function_unregister(&mchan_function);
|
|
|
|
|
2008-06-03 23:17:33 +00:00
|
|
|
return res;
|
2006-02-12 04:28:58 +00:00
|
|
|
}
|
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
static int load_module(void)
|
2006-02-12 04:28:58 +00:00
|
|
|
{
|
2008-06-03 23:17:33 +00:00
|
|
|
int res = 0;
|
2009-09-01 23:41:06 +00:00
|
|
|
|
2008-06-03 23:17:33 +00:00
|
|
|
res |= ast_custom_function_register(&channel_function);
|
|
|
|
res |= ast_custom_function_register(&channels_function);
|
2009-09-01 23:41:06 +00:00
|
|
|
res |= ast_custom_function_register(&mchan_function);
|
|
|
|
|
2008-06-03 23:17:33 +00:00
|
|
|
return res;
|
2006-02-12 04:28:58 +00:00
|
|
|
}
|
|
|
|
|
2008-06-03 23:17:33 +00:00
|
|
|
AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Channel information dialplan functions");
|