2003-02-04 15:48:42 +00:00
|
|
|
/*
|
2005-09-14 20:46:50 +00:00
|
|
|
* Asterisk -- An open source telephony toolkit.
|
2003-02-04 15:48:42 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2002, Pauline Middelink
|
2009-02-17 20:41:24 +00:00
|
|
|
* Copyright (C) 2009, Digium, Inc.
|
2003-02-04 15:48:42 +00:00
|
|
|
*
|
2005-09-14 20:46:50 +00:00
|
|
|
* 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.
|
|
|
|
*
|
2003-02-04 15:48:42 +00:00
|
|
|
* This program is free software, distributed under the terms of
|
2005-09-14 20:46:50 +00:00
|
|
|
* the GNU General Public License Version 2. See the LICENSE file
|
|
|
|
* at the top of the source tree.
|
|
|
|
*/
|
|
|
|
|
2009-02-17 20:41:24 +00:00
|
|
|
/*!
|
|
|
|
* \file
|
|
|
|
* \brief Indication Tone Handling
|
2003-02-04 15:48:42 +00:00
|
|
|
*
|
2005-10-24 20:12:06 +00:00
|
|
|
* \author Pauline Middelink <middelink@polyware.nl>
|
2009-02-17 20:41:24 +00:00
|
|
|
* \author Russell Bryant <russell@digium.com>
|
2003-02-04 15:48:42 +00:00
|
|
|
*/
|
|
|
|
|
2012-06-15 16:20:16 +00:00
|
|
|
/*** MODULEINFO
|
|
|
|
<support_level>core</support_level>
|
|
|
|
***/
|
|
|
|
|
2005-06-06 20:27:51 +00:00
|
|
|
#include "asterisk.h"
|
|
|
|
|
2006-06-07 18:54:56 +00:00
|
|
|
#include <math.h>
|
|
|
|
|
2006-12-21 04:05:21 +00:00
|
|
|
#include "asterisk/lock.h"
|
|
|
|
#include "asterisk/linkedlists.h"
|
2005-04-21 06:02:45 +00:00
|
|
|
#include "asterisk/indications.h"
|
|
|
|
#include "asterisk/frame.h"
|
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
|
|
|
#include "asterisk/format_cache.h"
|
2005-04-21 06:02:45 +00:00
|
|
|
#include "asterisk/channel.h"
|
|
|
|
#include "asterisk/utils.h"
|
2009-02-17 20:41:24 +00:00
|
|
|
#include "asterisk/cli.h"
|
|
|
|
#include "asterisk/module.h"
|
|
|
|
#include "asterisk/astobj2.h"
|
|
|
|
|
|
|
|
#include "asterisk/_private.h" /* _init(), _reload() */
|
|
|
|
|
|
|
|
/* Globals */
|
|
|
|
static const char config[] = "indications.conf";
|
|
|
|
|
|
|
|
static const int midi_tohz[128] = {
|
|
|
|
8, 8, 9, 9, 10, 10, 11, 12, 12, 13,
|
|
|
|
14, 15, 16, 17, 18, 19, 20, 21, 23, 24,
|
|
|
|
25, 27, 29, 30, 32, 34, 36, 38, 41, 43,
|
|
|
|
46, 48, 51, 55, 58, 61, 65, 69, 73, 77,
|
|
|
|
82, 87, 92, 97, 103, 110, 116, 123, 130, 138,
|
|
|
|
146, 155, 164, 174, 184, 195, 207, 220, 233, 246,
|
|
|
|
261, 277, 293, 311, 329, 349, 369, 391, 415, 440,
|
|
|
|
466, 493, 523, 554, 587, 622, 659, 698, 739, 783,
|
|
|
|
830, 880, 932, 987, 1046, 1108, 1174, 1244, 1318, 1396,
|
|
|
|
1479, 1567, 1661, 1760, 1864, 1975, 2093, 2217, 2349, 2489,
|
|
|
|
2637, 2793, 2959, 3135, 3322, 3520, 3729, 3951, 4186, 4434,
|
|
|
|
4698, 4978, 5274, 5587, 5919, 6271, 6644, 7040, 7458, 7902,
|
|
|
|
8372, 8869, 9397, 9956, 10548, 11175, 11839, 12543
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct ao2_container *ast_tone_zones;
|
2003-02-04 15:48:42 +00:00
|
|
|
|
2009-02-17 20:41:24 +00:00
|
|
|
#define NUM_TONE_ZONE_BUCKETS 53
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \note Access to this is protected by locking the ast_tone_zones container
|
|
|
|
*/
|
|
|
|
static struct ast_tone_zone *default_tone_zone;
|
2005-06-17 14:25:44 +00:00
|
|
|
|
2003-02-04 15:48:42 +00:00
|
|
|
struct playtones_item {
|
2005-10-16 03:07:15 +00:00
|
|
|
int fac1;
|
|
|
|
int init_v2_1;
|
|
|
|
int init_v3_1;
|
|
|
|
int fac2;
|
|
|
|
int init_v2_2;
|
|
|
|
int init_v3_2;
|
2004-01-08 15:47:16 +00:00
|
|
|
int modulate;
|
2005-10-16 03:07:15 +00:00
|
|
|
int duration;
|
2003-02-04 15:48:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct playtones_def {
|
|
|
|
int vol;
|
|
|
|
int reppos;
|
|
|
|
int nitems;
|
2003-03-16 22:37:31 +00:00
|
|
|
int interruptible;
|
2003-02-04 15:48:42 +00:00
|
|
|
struct playtones_item *items;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct playtones_state {
|
|
|
|
int vol;
|
2005-10-16 03:07:15 +00:00
|
|
|
int v1_1;
|
|
|
|
int v2_1;
|
|
|
|
int v3_1;
|
|
|
|
int v1_2;
|
|
|
|
int v2_2;
|
|
|
|
int v3_2;
|
2003-02-04 15:48:42 +00:00
|
|
|
int reppos;
|
|
|
|
int nitems;
|
|
|
|
struct playtones_item *items;
|
|
|
|
int npos;
|
2005-10-16 03:07:15 +00:00
|
|
|
int oldnpos;
|
2003-02-04 15:48:42 +00:00
|
|
|
int pos;
|
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
|
|
|
struct ast_format *origwfmt;
|
2003-02-04 15:48:42 +00:00
|
|
|
struct ast_frame f;
|
2004-07-18 15:58:57 +00:00
|
|
|
unsigned char offset[AST_FRIENDLY_OFFSET];
|
2003-02-04 15:48:42 +00:00
|
|
|
short data[4000];
|
|
|
|
};
|
|
|
|
|
|
|
|
static void playtones_release(struct ast_channel *chan, void *params)
|
|
|
|
{
|
|
|
|
struct playtones_state *ps = params;
|
2006-12-21 04:05:21 +00:00
|
|
|
|
2009-02-17 20:41:24 +00:00
|
|
|
if (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_set_write_format(chan, ps->origwfmt);
|
2009-02-17 20:41:24 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
ao2_cleanup(ps->origwfmt);
|
|
|
|
ast_free(ps->items);
|
2006-12-21 04:05:21 +00:00
|
|
|
|
2007-06-06 21:20:11 +00:00
|
|
|
ast_free(ps);
|
2003-02-04 15:48:42 +00:00
|
|
|
}
|
|
|
|
|
2009-02-17 20:41:24 +00:00
|
|
|
static void *playtones_alloc(struct ast_channel *chan, void *params)
|
2003-02-04 15:48:42 +00:00
|
|
|
{
|
|
|
|
struct playtones_def *pd = params;
|
2006-12-21 04:05:21 +00:00
|
|
|
struct playtones_state *ps = NULL;
|
|
|
|
|
2009-02-17 20:41:24 +00:00
|
|
|
if (!(ps = ast_calloc(1, sizeof(*ps)))) {
|
2003-02-04 15:48:42 +00:00
|
|
|
return NULL;
|
2009-02-17 20:41:24 +00:00
|
|
|
}
|
2006-12-21 04:05:21 +00:00
|
|
|
|
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
|
|
|
ps->origwfmt = ao2_bump(ast_channel_writeformat(chan));
|
2006-12-21 04:05:21 +00:00
|
|
|
|
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
|
|
|
if (ast_set_write_format(chan, ast_format_slin)) {
|
2012-01-09 22:15:50 +00:00
|
|
|
ast_log(LOG_WARNING, "Unable to set '%s' to signed linear format (write)\n", ast_channel_name(chan));
|
2003-02-04 15:48:42 +00:00
|
|
|
playtones_release(NULL, ps);
|
|
|
|
ps = NULL;
|
|
|
|
} else {
|
|
|
|
ps->vol = pd->vol;
|
|
|
|
ps->reppos = pd->reppos;
|
|
|
|
ps->nitems = pd->nitems;
|
|
|
|
ps->items = pd->items;
|
2005-10-16 03:07:15 +00:00
|
|
|
ps->oldnpos = -1;
|
2003-02-04 15:48:42 +00:00
|
|
|
}
|
2006-12-21 04:05:21 +00:00
|
|
|
|
2003-02-04 15:48:42 +00:00
|
|
|
/* Let interrupts interrupt :) */
|
2009-02-17 20:41:24 +00:00
|
|
|
if (pd->interruptible) {
|
2012-03-13 18:20:34 +00:00
|
|
|
ast_set_flag(ast_channel_flags(chan), AST_FLAG_WRITE_INT);
|
2009-02-17 20:41:24 +00:00
|
|
|
} else {
|
2012-03-13 18:20:34 +00:00
|
|
|
ast_clear_flag(ast_channel_flags(chan), AST_FLAG_WRITE_INT);
|
2009-02-17 20:41:24 +00:00
|
|
|
}
|
2006-12-21 04:05:21 +00:00
|
|
|
|
2003-02-04 15:48:42 +00:00
|
|
|
return ps;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int playtones_generator(struct ast_channel *chan, void *data, int len, int samples)
|
|
|
|
{
|
|
|
|
struct playtones_state *ps = data;
|
|
|
|
struct playtones_item *pi;
|
|
|
|
int x;
|
2009-02-17 20:41:24 +00:00
|
|
|
|
|
|
|
/* we need to prepare a frame with 16 * timelen samples as we're
|
|
|
|
* generating SLIN audio */
|
|
|
|
|
2003-02-04 15:48:42 +00:00
|
|
|
len = samples * 2;
|
|
|
|
if (len > sizeof(ps->data) / 2 - 1) {
|
|
|
|
ast_log(LOG_WARNING, "Can't generate that much data!\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2009-02-17 20:41:24 +00:00
|
|
|
|
2003-02-04 15:48:42 +00:00
|
|
|
memset(&ps->f, 0, sizeof(ps->f));
|
|
|
|
|
|
|
|
pi = &ps->items[ps->npos];
|
2009-02-17 20:41:24 +00:00
|
|
|
|
2005-10-16 03:07:15 +00:00
|
|
|
if (ps->oldnpos != ps->npos) {
|
|
|
|
/* Load new parameters */
|
|
|
|
ps->v1_1 = 0;
|
|
|
|
ps->v2_1 = pi->init_v2_1;
|
|
|
|
ps->v3_1 = pi->init_v3_1;
|
|
|
|
ps->v1_2 = 0;
|
|
|
|
ps->v2_2 = pi->init_v2_2;
|
|
|
|
ps->v3_2 = pi->init_v3_2;
|
|
|
|
ps->oldnpos = ps->npos;
|
|
|
|
}
|
2009-02-17 20:41:24 +00:00
|
|
|
|
|
|
|
for (x = 0; x < samples; x++) {
|
2005-10-16 03:07:15 +00:00
|
|
|
ps->v1_1 = ps->v2_1;
|
|
|
|
ps->v2_1 = ps->v3_1;
|
|
|
|
ps->v3_1 = (pi->fac1 * ps->v2_1 >> 15) - ps->v1_1;
|
2009-02-17 20:41:24 +00:00
|
|
|
|
2005-10-16 03:07:15 +00:00
|
|
|
ps->v1_2 = ps->v2_2;
|
|
|
|
ps->v2_2 = ps->v3_2;
|
|
|
|
ps->v3_2 = (pi->fac2 * ps->v2_2 >> 15) - ps->v1_2;
|
|
|
|
if (pi->modulate) {
|
|
|
|
int p;
|
|
|
|
p = ps->v3_2 - 32768;
|
2009-02-17 20:41:24 +00:00
|
|
|
if (p < 0) {
|
|
|
|
p = -p;
|
|
|
|
}
|
2005-10-16 03:07:15 +00:00
|
|
|
p = ((p * 9) / 10) + 1;
|
|
|
|
ps->data[x] = (ps->v3_1 * p) >> 15;
|
2009-02-17 20:41:24 +00:00
|
|
|
} else {
|
|
|
|
ps->data[x] = ps->v3_1 + ps->v3_2;
|
|
|
|
}
|
2003-02-04 15:48:42 +00:00
|
|
|
}
|
2009-02-17 20:41:24 +00:00
|
|
|
|
2003-02-04 15:48:42 +00:00
|
|
|
ps->f.frametype = AST_FRAME_VOICE;
|
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
|
|
|
ps->f.subclass.format = ast_format_slin;
|
2003-02-04 15:48:42 +00:00
|
|
|
ps->f.datalen = len;
|
|
|
|
ps->f.samples = samples;
|
|
|
|
ps->f.offset = AST_FRIENDLY_OFFSET;
|
2008-05-22 16:29:54 +00:00
|
|
|
ps->f.data.ptr = ps->data;
|
2009-02-17 20:41:24 +00:00
|
|
|
|
|
|
|
if (ast_write(chan, &ps->f)) {
|
|
|
|
return -1;
|
|
|
|
}
|
2003-02-04 15:48:42 +00:00
|
|
|
|
|
|
|
ps->pos += x;
|
2009-02-17 20:41:24 +00:00
|
|
|
|
2003-02-04 15:48:42 +00:00
|
|
|
if (pi->duration && ps->pos >= pi->duration * 8) { /* item finished? */
|
|
|
|
ps->pos = 0; /* start new item */
|
|
|
|
ps->npos++;
|
|
|
|
if (ps->npos >= ps->nitems) { /* last item? */
|
2009-02-17 20:41:24 +00:00
|
|
|
if (ps->reppos == -1) { /* repeat set? */
|
2003-02-04 15:48:42 +00:00
|
|
|
return -1;
|
2009-02-17 20:41:24 +00:00
|
|
|
}
|
2003-02-04 15:48:42 +00:00
|
|
|
ps->npos = ps->reppos; /* redo from top */
|
|
|
|
}
|
|
|
|
}
|
2009-02-17 20:41:24 +00:00
|
|
|
|
2003-02-04 15:48:42 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ast_generator playtones = {
|
2009-02-17 20:41:24 +00:00
|
|
|
.alloc = playtones_alloc,
|
|
|
|
.release = playtones_release,
|
|
|
|
.generate = playtones_generator,
|
2003-02-04 15:48:42 +00:00
|
|
|
};
|
|
|
|
|
2009-02-17 20:41:24 +00:00
|
|
|
int ast_tone_zone_part_parse(const char *s, struct ast_tone_zone_part *tone_data)
|
|
|
|
{
|
2012-03-22 19:51:16 +00:00
|
|
|
if (sscanf(s, "%30u+%30u/%30u", &tone_data->freq1, &tone_data->freq2,
|
2009-02-17 20:41:24 +00:00
|
|
|
&tone_data->time) == 3) {
|
|
|
|
/* f1+f2/time format */
|
2009-08-10 19:20:57 +00:00
|
|
|
} else if (sscanf(s, "%30u+%30u", &tone_data->freq1, &tone_data->freq2) == 2) {
|
2009-02-17 20:41:24 +00:00
|
|
|
/* f1+f2 format */
|
|
|
|
tone_data->time = 0;
|
2012-03-22 19:51:16 +00:00
|
|
|
} else if (sscanf(s, "%30u*%30u/%30u", &tone_data->freq1, &tone_data->freq2,
|
2009-02-17 20:41:24 +00:00
|
|
|
&tone_data->time) == 3) {
|
|
|
|
/* f1*f2/time format */
|
|
|
|
tone_data->modulate = 1;
|
2009-08-10 19:20:57 +00:00
|
|
|
} else if (sscanf(s, "%30u*%30u", &tone_data->freq1, &tone_data->freq2) == 2) {
|
2009-02-17 20:41:24 +00:00
|
|
|
/* f1*f2 format */
|
|
|
|
tone_data->time = 0;
|
|
|
|
tone_data->modulate = 1;
|
2009-08-10 19:20:57 +00:00
|
|
|
} else if (sscanf(s, "%30u/%30u", &tone_data->freq1, &tone_data->time) == 2) {
|
2009-02-17 20:41:24 +00:00
|
|
|
/* f1/time format */
|
|
|
|
tone_data->freq2 = 0;
|
2009-08-10 19:20:57 +00:00
|
|
|
} else if (sscanf(s, "%30u", &tone_data->freq1) == 1) {
|
2009-02-17 20:41:24 +00:00
|
|
|
/* f1 format */
|
|
|
|
tone_data->freq2 = 0;
|
|
|
|
tone_data->time = 0;
|
2012-03-22 19:51:16 +00:00
|
|
|
} else if (sscanf(s, "M%30u+M%30u/%30u", &tone_data->freq1, &tone_data->freq2,
|
2009-02-17 20:41:24 +00:00
|
|
|
&tone_data->time) == 3) {
|
|
|
|
/* Mf1+Mf2/time format */
|
|
|
|
tone_data->midinote = 1;
|
2009-08-10 19:20:57 +00:00
|
|
|
} else if (sscanf(s, "M%30u+M%30u", &tone_data->freq1, &tone_data->freq2) == 2) {
|
2009-02-17 20:41:24 +00:00
|
|
|
/* Mf1+Mf2 format */
|
|
|
|
tone_data->time = 0;
|
|
|
|
tone_data->midinote = 1;
|
2012-03-22 19:51:16 +00:00
|
|
|
} else if (sscanf(s, "M%30u*M%30u/%30u", &tone_data->freq1, &tone_data->freq2,
|
2009-02-17 20:41:24 +00:00
|
|
|
&tone_data->time) == 3) {
|
|
|
|
/* Mf1*Mf2/time format */
|
|
|
|
tone_data->modulate = 1;
|
|
|
|
tone_data->midinote = 1;
|
2009-08-10 19:20:57 +00:00
|
|
|
} else if (sscanf(s, "M%30u*M%30u", &tone_data->freq1, &tone_data->freq2) == 2) {
|
2009-02-17 20:41:24 +00:00
|
|
|
/* Mf1*Mf2 format */
|
|
|
|
tone_data->time = 0;
|
|
|
|
tone_data->modulate = 1;
|
|
|
|
tone_data->midinote = 1;
|
2009-08-10 19:20:57 +00:00
|
|
|
} else if (sscanf(s, "M%30u/%30u", &tone_data->freq1, &tone_data->time) == 2) {
|
2009-02-17 20:41:24 +00:00
|
|
|
/* Mf1/time format */
|
|
|
|
tone_data->freq2 = -1;
|
|
|
|
tone_data->midinote = 1;
|
2009-08-10 19:20:57 +00:00
|
|
|
} else if (sscanf(s, "M%30u", &tone_data->freq1) == 1) {
|
2009-02-17 20:41:24 +00:00
|
|
|
/* Mf1 format */
|
|
|
|
tone_data->freq2 = -1;
|
|
|
|
tone_data->time = 0;
|
|
|
|
tone_data->midinote = 1;
|
|
|
|
} else {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-03-16 22:37:31 +00:00
|
|
|
int ast_playtones_start(struct ast_channel *chan, int vol, const char *playlst, int interruptible)
|
2003-02-04 15:48:42 +00:00
|
|
|
{
|
2009-02-17 20:41:24 +00:00
|
|
|
char *s, *data = ast_strdupa(playlst);
|
|
|
|
struct playtones_def d = { vol, -1, 0, 1, NULL };
|
2006-05-10 13:22:15 +00:00
|
|
|
char *stringp;
|
2003-06-17 18:59:58 +00:00
|
|
|
char *separator;
|
2009-02-17 20:41:24 +00:00
|
|
|
static const float sample_rate = 8000.0;
|
|
|
|
static const float max_sample_val = 32768.0;
|
|
|
|
|
|
|
|
if (vol < 1) {
|
2005-10-16 03:07:15 +00:00
|
|
|
d.vol = 7219; /* Default to -8db */
|
2009-02-17 20:41:24 +00:00
|
|
|
}
|
2003-02-04 15:48:42 +00:00
|
|
|
|
2003-03-16 22:37:31 +00:00
|
|
|
d.interruptible = interruptible;
|
2009-02-17 20:41:24 +00:00
|
|
|
|
|
|
|
stringp = data;
|
|
|
|
|
2003-06-17 18:59:58 +00:00
|
|
|
/* check if the data is separated with '|' or with ',' by default */
|
2009-02-17 20:41:24 +00:00
|
|
|
if (strchr(stringp,'|')) {
|
2003-06-17 18:59:58 +00:00
|
|
|
separator = "|";
|
2009-02-17 20:41:24 +00:00
|
|
|
} else {
|
2003-06-17 18:59:58 +00:00
|
|
|
separator = ",";
|
2009-02-17 20:41:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
while ((s = strsep(&stringp, separator)) && !ast_strlen_zero(s)) {
|
2013-09-10 18:05:47 +00:00
|
|
|
struct playtones_item *new_items;
|
2009-02-17 20:41:24 +00:00
|
|
|
struct ast_tone_zone_part tone_data = {
|
|
|
|
.time = 0,
|
|
|
|
};
|
2003-02-04 15:48:42 +00:00
|
|
|
|
2009-02-17 20:41:24 +00:00
|
|
|
s = ast_strip(s);
|
|
|
|
if (s[0]=='!') {
|
2003-02-04 15:48:42 +00:00
|
|
|
s++;
|
2009-02-17 20:41:24 +00:00
|
|
|
} else if (d.reppos == -1) {
|
2003-02-04 15:48:42 +00:00
|
|
|
d.reppos = d.nitems;
|
|
|
|
}
|
|
|
|
|
2009-02-17 20:41:24 +00:00
|
|
|
if (ast_tone_zone_part_parse(s, &tone_data)) {
|
|
|
|
ast_log(LOG_ERROR, "Failed to parse tone part '%s'\n", s);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tone_data.midinote) {
|
2005-06-17 14:25:44 +00:00
|
|
|
/* midi notes must be between 0 and 127 */
|
2015-04-09 12:57:21 +00:00
|
|
|
if (tone_data.freq1 <= 127) {
|
2009-02-17 20:41:24 +00:00
|
|
|
tone_data.freq1 = midi_tohz[tone_data.freq1];
|
|
|
|
} else {
|
|
|
|
tone_data.freq1 = 0;
|
|
|
|
}
|
|
|
|
|
2015-04-09 12:57:21 +00:00
|
|
|
if (tone_data.freq2 <= 127) {
|
2009-02-17 20:41:24 +00:00
|
|
|
tone_data.freq2 = midi_tohz[tone_data.freq2];
|
|
|
|
} else {
|
|
|
|
tone_data.freq2 = 0;
|
|
|
|
}
|
2005-06-17 14:25:44 +00:00
|
|
|
}
|
|
|
|
|
2013-09-10 18:05:47 +00:00
|
|
|
new_items = ast_realloc(d.items, (d.nitems + 1) * sizeof(*d.items));
|
|
|
|
if (!new_items) {
|
|
|
|
ast_free(d.items);
|
2003-02-04 15:48:42 +00:00
|
|
|
return -1;
|
2005-06-17 14:25:44 +00:00
|
|
|
}
|
2013-09-10 18:05:47 +00:00
|
|
|
d.items = new_items;
|
2005-10-16 03:07:15 +00:00
|
|
|
|
2009-02-17 20:41:24 +00:00
|
|
|
d.items[d.nitems].fac1 = 2.0 * cos(2.0 * M_PI * (tone_data.freq1 / sample_rate)) * max_sample_val;
|
|
|
|
d.items[d.nitems].init_v2_1 = sin(-4.0 * M_PI * (tone_data.freq1 / sample_rate)) * d.vol;
|
|
|
|
d.items[d.nitems].init_v3_1 = sin(-2.0 * M_PI * (tone_data.freq1 / sample_rate)) * d.vol;
|
|
|
|
|
|
|
|
d.items[d.nitems].fac2 = 2.0 * cos(2.0 * M_PI * (tone_data.freq2 / sample_rate)) * max_sample_val;
|
|
|
|
d.items[d.nitems].init_v2_2 = sin(-4.0 * M_PI * (tone_data.freq2 / sample_rate)) * d.vol;
|
|
|
|
d.items[d.nitems].init_v3_2 = sin(-2.0 * M_PI * (tone_data.freq2 / sample_rate)) * d.vol;
|
2003-02-04 15:48:42 +00:00
|
|
|
|
2009-02-17 20:41:24 +00:00
|
|
|
d.items[d.nitems].duration = tone_data.time;
|
|
|
|
d.items[d.nitems].modulate = tone_data.modulate;
|
|
|
|
|
|
|
|
d.nitems++;
|
2003-02-04 15:48:42 +00:00
|
|
|
}
|
|
|
|
|
2009-02-26 15:40:10 +00:00
|
|
|
if (!d.nitems) {
|
|
|
|
ast_log(LOG_ERROR, "No valid tone parts\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2003-02-04 15:48:42 +00:00
|
|
|
if (ast_activate_generator(chan, &playtones, &d)) {
|
2007-06-06 21:20:11 +00:00
|
|
|
ast_free(d.items);
|
2003-02-04 15:48:42 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2009-02-17 20:41:24 +00:00
|
|
|
|
2003-02-04 15:48:42 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ast_playtones_stop(struct ast_channel *chan)
|
|
|
|
{
|
|
|
|
ast_deactivate_generator(chan);
|
|
|
|
}
|
|
|
|
|
2009-02-17 20:41:24 +00:00
|
|
|
int ast_tone_zone_count(void)
|
2006-03-30 17:10:11 +00:00
|
|
|
{
|
2009-02-17 20:41:24 +00:00
|
|
|
return ao2_container_count(ast_tone_zones);
|
|
|
|
}
|
2006-03-30 17:10:11 +00:00
|
|
|
|
2009-02-17 20:41:24 +00:00
|
|
|
struct ao2_iterator ast_tone_zone_iterator_init(void)
|
|
|
|
{
|
|
|
|
return ao2_iterator_init(ast_tone_zones, 0);
|
2006-03-30 17:10:11 +00:00
|
|
|
}
|
2003-02-04 15:48:42 +00:00
|
|
|
|
2012-03-22 19:51:16 +00:00
|
|
|
/*! \brief Set global indication country
|
2010-09-16 16:48:08 +00:00
|
|
|
If no country is specified or we are unable to find the zone, then return not found */
|
2009-02-17 20:41:24 +00:00
|
|
|
static int ast_set_indication_country(const char *country)
|
2003-02-04 15:48:42 +00:00
|
|
|
{
|
2009-02-17 20:41:24 +00:00
|
|
|
struct ast_tone_zone *zone = NULL;
|
2006-12-21 04:05:21 +00:00
|
|
|
|
2009-02-17 20:41:24 +00:00
|
|
|
if (ast_strlen_zero(country) || !(zone = ast_get_indication_zone(country))) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-07-26 15:49:18 +00:00
|
|
|
ast_verb(3, "Setting default indication country to '%s'\n", country);
|
2006-12-21 04:05:21 +00:00
|
|
|
|
2009-02-17 20:41:24 +00:00
|
|
|
ao2_lock(ast_tone_zones);
|
|
|
|
if (default_tone_zone) {
|
|
|
|
default_tone_zone = ast_tone_zone_unref(default_tone_zone);
|
|
|
|
}
|
|
|
|
default_tone_zone = ast_tone_zone_ref(zone);
|
|
|
|
ao2_unlock(ast_tone_zones);
|
|
|
|
|
|
|
|
zone = ast_tone_zone_unref(zone);
|
2006-12-21 04:05:21 +00:00
|
|
|
|
|
|
|
return 0;
|
2003-02-04 15:48:42 +00:00
|
|
|
}
|
|
|
|
|
2010-09-16 16:48:08 +00:00
|
|
|
/*! \brief locate ast_tone_zone, given the country. if country == NULL, use the default country */
|
2009-02-17 20:41:24 +00:00
|
|
|
struct ast_tone_zone *ast_get_indication_zone(const char *country)
|
2003-02-04 15:48:42 +00:00
|
|
|
{
|
2009-02-17 20:41:24 +00:00
|
|
|
struct ast_tone_zone *tz = NULL;
|
|
|
|
struct ast_tone_zone zone_arg = {
|
|
|
|
.nrringcadence = 0,
|
|
|
|
};
|
2006-12-21 04:05:21 +00:00
|
|
|
|
2009-01-07 17:35:39 +00:00
|
|
|
if (ast_strlen_zero(country)) {
|
2009-02-17 20:41:24 +00:00
|
|
|
ao2_lock(ast_tone_zones);
|
|
|
|
if (default_tone_zone) {
|
|
|
|
tz = ast_tone_zone_ref(default_tone_zone);
|
|
|
|
}
|
|
|
|
ao2_unlock(ast_tone_zones);
|
2006-12-21 04:05:21 +00:00
|
|
|
|
2009-02-17 20:41:24 +00:00
|
|
|
return tz;
|
|
|
|
}
|
2006-12-21 04:05:21 +00:00
|
|
|
|
2009-02-17 20:41:24 +00:00
|
|
|
ast_copy_string(zone_arg.country, country, sizeof(zone_arg.country));
|
2006-12-21 04:05:21 +00:00
|
|
|
|
2009-02-17 20:41:24 +00:00
|
|
|
return ao2_find(ast_tone_zones, &zone_arg, OBJ_POINTER);
|
2003-02-04 15:48:42 +00:00
|
|
|
}
|
|
|
|
|
2009-02-17 20:41:24 +00:00
|
|
|
struct ast_tone_zone_sound *ast_get_indication_tone(const struct ast_tone_zone *_zone, const char *indication)
|
2003-02-04 15:48:42 +00:00
|
|
|
{
|
2009-02-17 20:41:24 +00:00
|
|
|
struct ast_tone_zone_sound *ts = NULL;
|
|
|
|
/* _zone is const to the users of the API */
|
|
|
|
struct ast_tone_zone *zone = (struct ast_tone_zone *) _zone;
|
2006-12-21 04:05:21 +00:00
|
|
|
|
2009-02-17 20:41:24 +00:00
|
|
|
/* If no zone is specified, use the default */
|
2006-12-21 04:05:21 +00:00
|
|
|
if (!zone) {
|
2009-02-17 20:41:24 +00:00
|
|
|
ao2_lock(ast_tone_zones);
|
|
|
|
if (default_tone_zone) {
|
|
|
|
zone = ast_tone_zone_ref(default_tone_zone);
|
|
|
|
}
|
|
|
|
ao2_unlock(ast_tone_zones);
|
|
|
|
|
|
|
|
if (!zone) {
|
2006-12-21 04:05:21 +00:00
|
|
|
return NULL;
|
2003-02-04 15:48:42 +00:00
|
|
|
}
|
|
|
|
}
|
2006-12-21 04:05:21 +00:00
|
|
|
|
2009-02-17 20:41:24 +00:00
|
|
|
ast_tone_zone_lock(zone);
|
|
|
|
|
2006-12-21 04:05:21 +00:00
|
|
|
/* Look through list of tones in the zone searching for the right one */
|
2009-02-17 20:41:24 +00:00
|
|
|
AST_LIST_TRAVERSE(&zone->tones, ts, entry) {
|
|
|
|
if (!strcasecmp(ts->name, indication)) {
|
|
|
|
/* Increase ref count for the reference we will return */
|
|
|
|
ts = ast_tone_zone_sound_ref(ts);
|
2006-12-21 04:05:21 +00:00
|
|
|
break;
|
2009-02-17 20:41:24 +00:00
|
|
|
}
|
2006-12-21 04:05:21 +00:00
|
|
|
}
|
|
|
|
|
2009-02-17 20:41:24 +00:00
|
|
|
ast_tone_zone_unlock(zone);
|
2006-12-21 04:05:21 +00:00
|
|
|
|
2013-08-30 19:22:59 +00:00
|
|
|
if (!_zone)
|
|
|
|
zone = ast_tone_zone_unref(zone);
|
|
|
|
|
2006-12-21 04:05:21 +00:00
|
|
|
return ts;
|
2003-02-04 15:48:42 +00:00
|
|
|
}
|
|
|
|
|
2009-02-17 20:41:24 +00:00
|
|
|
static void ast_tone_zone_sound_destructor(void *obj)
|
2003-02-04 15:48:42 +00:00
|
|
|
{
|
2009-02-17 20:41:24 +00:00
|
|
|
struct ast_tone_zone_sound *ts = obj;
|
|
|
|
|
2008-11-07 16:18:52 +00:00
|
|
|
/* Deconstify the 'const char *'s so the compiler doesn't complain. (but it's safe) */
|
2009-02-17 20:41:24 +00:00
|
|
|
if (ts->name) {
|
|
|
|
ast_free((char *) ts->name);
|
|
|
|
ts->name = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ts->data) {
|
|
|
|
ast_free((char *) ts->data);
|
|
|
|
ts->data = NULL;
|
|
|
|
}
|
2008-11-07 16:18:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*! \brief deallocate the passed tone zone */
|
2009-02-17 20:41:24 +00:00
|
|
|
static void ast_tone_zone_destructor(void *obj)
|
2008-11-07 16:18:52 +00:00
|
|
|
{
|
2009-02-17 20:41:24 +00:00
|
|
|
struct ast_tone_zone *zone = obj;
|
|
|
|
struct ast_tone_zone_sound *current;
|
2008-11-07 16:18:52 +00:00
|
|
|
|
2009-02-17 20:41:24 +00:00
|
|
|
while ((current = AST_LIST_REMOVE_HEAD(&zone->tones, entry))) {
|
|
|
|
current = ast_tone_zone_sound_unref(current);
|
2003-02-04 15:48:42 +00:00
|
|
|
}
|
2006-12-21 04:05:21 +00:00
|
|
|
|
2009-02-17 20:41:24 +00:00
|
|
|
if (zone->ringcadence) {
|
2007-06-06 21:20:11 +00:00
|
|
|
ast_free(zone->ringcadence);
|
2009-02-17 20:41:24 +00:00
|
|
|
zone->ringcadence = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-16 16:48:08 +00:00
|
|
|
/*! \brief add a new country, if country exists, it will be replaced. */
|
2009-02-17 20:41:24 +00:00
|
|
|
static int ast_register_indication_country(struct ast_tone_zone *zone)
|
|
|
|
{
|
|
|
|
ao2_lock(ast_tone_zones);
|
|
|
|
if (!default_tone_zone) {
|
|
|
|
default_tone_zone = ast_tone_zone_ref(zone);
|
|
|
|
}
|
|
|
|
ao2_unlock(ast_tone_zones);
|
|
|
|
|
|
|
|
ao2_link(ast_tone_zones, zone);
|
2006-12-21 04:05:21 +00:00
|
|
|
|
2009-02-17 20:41:24 +00:00
|
|
|
ast_verb(3, "Registered indication country '%s'\n", zone->country);
|
|
|
|
|
|
|
|
return 0;
|
2003-02-04 15:48:42 +00:00
|
|
|
}
|
|
|
|
|
2010-09-16 16:48:08 +00:00
|
|
|
/*! \brief remove an existing country and all its indications, country must exist. */
|
2009-02-17 20:41:24 +00:00
|
|
|
static int ast_unregister_indication_country(const char *country)
|
|
|
|
{
|
|
|
|
struct ast_tone_zone *tz = NULL;
|
|
|
|
struct ast_tone_zone zone_arg = {
|
|
|
|
.nrringcadence = 0,
|
|
|
|
};
|
2003-02-04 15:48:42 +00:00
|
|
|
|
2009-02-17 20:41:24 +00:00
|
|
|
ast_copy_string(zone_arg.country, country, sizeof(zone_arg.country));
|
|
|
|
|
2012-12-11 02:13:37 +00:00
|
|
|
ao2_lock(ast_tone_zones);
|
|
|
|
tz = ao2_find(ast_tone_zones, &zone_arg, OBJ_POINTER | OBJ_UNLINK);
|
|
|
|
if (!tz) {
|
|
|
|
ao2_unlock(ast_tone_zones);
|
2009-02-17 20:41:24 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (default_tone_zone == tz) {
|
|
|
|
ast_tone_zone_unref(default_tone_zone);
|
|
|
|
/* Get a new default, punt to the first one we find */
|
|
|
|
default_tone_zone = ao2_callback(ast_tone_zones, 0, NULL, NULL);
|
|
|
|
}
|
|
|
|
ao2_unlock(ast_tone_zones);
|
|
|
|
|
|
|
|
tz = ast_tone_zone_unref(tz);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \note called with the tone zone locked
|
|
|
|
*/
|
|
|
|
static int ast_register_indication(struct ast_tone_zone *zone, const char *indication,
|
|
|
|
const char *tonelist)
|
2003-02-04 15:48:42 +00:00
|
|
|
{
|
2009-02-17 20:41:24 +00:00
|
|
|
struct ast_tone_zone_sound *ts;
|
2006-12-21 04:05:21 +00:00
|
|
|
|
2009-02-17 20:41:24 +00:00
|
|
|
if (ast_strlen_zero(indication) || ast_strlen_zero(tonelist)) {
|
|
|
|
return -1;
|
2003-02-04 15:48:42 +00:00
|
|
|
}
|
2006-12-21 04:05:21 +00:00
|
|
|
|
2009-02-17 20:41:24 +00:00
|
|
|
AST_LIST_TRAVERSE_SAFE_BEGIN(&zone->tones, ts, entry) {
|
|
|
|
if (!strcasecmp(indication, ts->name)) {
|
|
|
|
AST_LIST_REMOVE_CURRENT(entry);
|
|
|
|
ts = ast_tone_zone_sound_unref(ts);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
AST_LIST_TRAVERSE_SAFE_END;
|
2006-12-21 04:05:21 +00:00
|
|
|
|
2018-10-02 03:12:14 +00:00
|
|
|
ts = ao2_alloc_options(sizeof(*ts), ast_tone_zone_sound_destructor,
|
|
|
|
AO2_ALLOC_OPT_LOCK_NOLOCK);
|
|
|
|
if (!ts) {
|
2009-02-17 20:41:24 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2003-02-04 15:48:42 +00:00
|
|
|
|
2009-02-17 20:41:24 +00:00
|
|
|
if (!(ts->name = ast_strdup(indication)) || !(ts->data = ast_strdup(tonelist))) {
|
|
|
|
ts = ast_tone_zone_sound_unref(ts);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
AST_LIST_INSERT_TAIL(&zone->tones, ts, entry); /* Inherit reference */
|
2006-12-21 04:05:21 +00:00
|
|
|
|
2003-02-04 15:48:42 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-09-16 16:48:08 +00:00
|
|
|
/*! \brief remove an existing country's indication. Both country and indication must exist */
|
2009-02-17 20:41:24 +00:00
|
|
|
static int ast_unregister_indication(struct ast_tone_zone *zone, const char *indication)
|
2003-02-04 15:48:42 +00:00
|
|
|
{
|
2009-02-17 20:41:24 +00:00
|
|
|
struct ast_tone_zone_sound *ts;
|
2003-02-04 15:48:42 +00:00
|
|
|
int res = -1;
|
|
|
|
|
2009-02-17 20:41:24 +00:00
|
|
|
ast_tone_zone_lock(zone);
|
|
|
|
|
|
|
|
AST_LIST_TRAVERSE_SAFE_BEGIN(&zone->tones, ts, entry) {
|
|
|
|
if (!strcasecmp(indication, ts->name)) {
|
|
|
|
AST_LIST_REMOVE_CURRENT(entry);
|
|
|
|
ts = ast_tone_zone_sound_unref(ts);
|
|
|
|
res = 0;
|
|
|
|
break;
|
2003-02-04 15:48:42 +00:00
|
|
|
}
|
|
|
|
}
|
2009-02-17 20:41:24 +00:00
|
|
|
AST_LIST_TRAVERSE_SAFE_END;
|
|
|
|
|
|
|
|
ast_tone_zone_unlock(zone);
|
2006-12-21 04:05:21 +00:00
|
|
|
|
2003-02-04 15:48:42 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2009-02-17 20:41:24 +00:00
|
|
|
static struct ast_tone_zone *ast_tone_zone_alloc(void)
|
2003-02-04 15:48:42 +00:00
|
|
|
{
|
2009-02-17 20:41:24 +00:00
|
|
|
return ao2_alloc(sizeof(struct ast_tone_zone), ast_tone_zone_destructor);
|
|
|
|
}
|
2003-02-04 15:48:42 +00:00
|
|
|
|
2009-02-17 20:41:24 +00:00
|
|
|
static char *complete_country(struct ast_cli_args *a)
|
|
|
|
{
|
|
|
|
struct ao2_iterator i;
|
|
|
|
size_t wordlen;
|
|
|
|
struct ast_tone_zone *tz;
|
|
|
|
|
|
|
|
wordlen = strlen(a->word);
|
|
|
|
|
|
|
|
i = ao2_iterator_init(ast_tone_zones, 0);
|
|
|
|
while ((tz = ao2_iterator_next(&i))) {
|
2018-03-17 06:02:06 +00:00
|
|
|
if (!strncasecmp(a->word, tz->country, wordlen)) {
|
|
|
|
if (ast_cli_completion_add(ast_strdup(tz->country))) {
|
|
|
|
ast_tone_zone_unref(tz);
|
|
|
|
break;
|
|
|
|
}
|
2009-02-17 20:41:24 +00:00
|
|
|
}
|
2018-03-17 06:02:06 +00:00
|
|
|
ast_tone_zone_unref(tz);
|
2009-02-17 20:41:24 +00:00
|
|
|
}
|
2012-01-27 18:47:16 +00:00
|
|
|
ao2_iterator_destroy(&i);
|
2003-02-04 15:48:42 +00:00
|
|
|
|
2018-03-17 06:02:06 +00:00
|
|
|
return NULL;
|
2009-02-17 20:41:24 +00:00
|
|
|
}
|
2008-11-07 16:18:52 +00:00
|
|
|
|
2009-02-17 20:41:24 +00:00
|
|
|
static char *handle_cli_indication_add(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
|
|
|
|
{
|
|
|
|
struct ast_tone_zone *tz;
|
|
|
|
int created_country = 0;
|
|
|
|
char *res = CLI_SUCCESS;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case CLI_INIT:
|
|
|
|
e->command = "indication add";
|
|
|
|
e->usage =
|
|
|
|
"Usage: indication add <country> <indication> \"<tonelist>\"\n"
|
|
|
|
" Add the given indication to the country.\n";
|
|
|
|
return NULL;
|
|
|
|
case CLI_GENERATE:
|
|
|
|
if (a->pos == 2) {
|
|
|
|
return complete_country(a);
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (a->argc != 5) {
|
|
|
|
return CLI_SHOWUSAGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(tz = ast_get_indication_zone(a->argv[2]))) {
|
|
|
|
/* country does not exist, create it */
|
|
|
|
ast_log(LOG_NOTICE, "Country '%s' does not exist, creating it.\n", a->argv[2]);
|
|
|
|
|
|
|
|
if (!(tz = ast_tone_zone_alloc())) {
|
|
|
|
return CLI_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ast_copy_string(tz->country, a->argv[2], sizeof(tz->country));
|
|
|
|
|
|
|
|
if (ast_register_indication_country(tz)) {
|
|
|
|
ast_log(LOG_WARNING, "Unable to register new country\n");
|
|
|
|
tz = ast_tone_zone_unref(tz);
|
|
|
|
return CLI_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
created_country = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ast_tone_zone_lock(tz);
|
|
|
|
|
|
|
|
if (ast_register_indication(tz, a->argv[3], a->argv[4])) {
|
|
|
|
ast_log(LOG_WARNING, "Unable to register indication %s/%s\n", a->argv[2], a->argv[3]);
|
|
|
|
if (created_country) {
|
|
|
|
ast_unregister_indication_country(a->argv[2]);
|
|
|
|
}
|
|
|
|
res = CLI_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ast_tone_zone_unlock(tz);
|
|
|
|
|
|
|
|
tz = ast_tone_zone_unref(tz);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *complete_indications(struct ast_cli_args *a)
|
|
|
|
{
|
|
|
|
size_t wordlen;
|
|
|
|
struct ast_tone_zone_sound *ts;
|
2018-03-17 06:02:06 +00:00
|
|
|
struct ast_tone_zone *tz;
|
|
|
|
struct ast_tone_zone tmp_tz = {
|
2009-02-17 20:41:24 +00:00
|
|
|
.nrringcadence = 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
ast_copy_string(tmp_tz.country, a->argv[a->pos - 1], sizeof(tmp_tz.country));
|
|
|
|
|
2018-03-17 06:02:06 +00:00
|
|
|
tz = ao2_find(ast_tone_zones, &tmp_tz, OBJ_POINTER);
|
|
|
|
if (!tz) {
|
2009-02-17 20:41:24 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
wordlen = strlen(a->word);
|
|
|
|
|
|
|
|
ast_tone_zone_lock(tz);
|
|
|
|
AST_LIST_TRAVERSE(&tz->tones, ts, entry) {
|
2018-03-17 06:02:06 +00:00
|
|
|
if (!strncasecmp(a->word, ts->name, wordlen)) {
|
|
|
|
if (ast_cli_completion_add(ast_strdup(ts->name))) {
|
|
|
|
break;
|
|
|
|
}
|
2003-02-04 15:48:42 +00:00
|
|
|
}
|
|
|
|
}
|
2009-02-17 20:41:24 +00:00
|
|
|
ast_tone_zone_unlock(tz);
|
|
|
|
|
|
|
|
tz = ast_tone_zone_unref(tz);
|
|
|
|
|
2018-03-17 06:02:06 +00:00
|
|
|
return NULL;
|
2009-02-17 20:41:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *handle_cli_indication_remove(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
|
|
|
|
{
|
|
|
|
struct ast_tone_zone *tz;
|
|
|
|
char *res = CLI_SUCCESS;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case CLI_INIT:
|
|
|
|
e->command = "indication remove";
|
|
|
|
e->usage =
|
|
|
|
"Usage: indication remove <country> [indication]\n"
|
|
|
|
" Remove the given indication from the country.\n";
|
|
|
|
return NULL;
|
|
|
|
case CLI_GENERATE:
|
|
|
|
if (a->pos == 2) {
|
|
|
|
return complete_country(a);
|
|
|
|
} else if (a->pos == 3) {
|
|
|
|
return complete_indications(a);
|
2003-02-04 15:48:42 +00:00
|
|
|
}
|
|
|
|
}
|
2009-02-17 20:41:24 +00:00
|
|
|
|
|
|
|
if (a->argc != 3 && a->argc != 4) {
|
|
|
|
return CLI_SHOWUSAGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (a->argc == 3) {
|
|
|
|
/* remove entire country */
|
|
|
|
if (ast_unregister_indication_country(a->argv[2])) {
|
|
|
|
ast_log(LOG_WARNING, "Unable to unregister indication country %s\n", a->argv[2]);
|
|
|
|
return CLI_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CLI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(tz = ast_get_indication_zone(a->argv[2]))) {
|
|
|
|
ast_log(LOG_WARNING, "Unable to unregister indication %s/%s, country does not exists\n", a->argv[2], a->argv[3]);
|
|
|
|
return CLI_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ast_unregister_indication(tz, a->argv[3])) {
|
|
|
|
ast_log(LOG_WARNING, "Unable to unregister indication %s/%s\n", a->argv[2], a->argv[3]);
|
|
|
|
res = CLI_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
tz = ast_tone_zone_unref(tz);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *handle_cli_indication_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
|
|
|
|
{
|
|
|
|
struct ast_tone_zone *tz = NULL;
|
|
|
|
struct ast_str *buf;
|
|
|
|
int found_country = 0;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case CLI_INIT:
|
|
|
|
e->command = "indication show";
|
|
|
|
e->usage =
|
|
|
|
"Usage: indication show [<country> ...]\n"
|
|
|
|
" Display either a condensed summary of all countries and indications, or a\n"
|
|
|
|
" more verbose list of indications for the specified countries.\n";
|
|
|
|
return NULL;
|
|
|
|
case CLI_GENERATE:
|
|
|
|
return complete_country(a);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (a->argc == 2) {
|
|
|
|
struct ao2_iterator iter;
|
|
|
|
/* no arguments, show a list of countries */
|
|
|
|
ast_cli(a->fd, "Country Description\n");
|
|
|
|
ast_cli(a->fd, "===========================\n");
|
|
|
|
iter = ast_tone_zone_iterator_init();
|
|
|
|
while ((tz = ao2_iterator_next(&iter))) {
|
|
|
|
ast_tone_zone_lock(tz);
|
|
|
|
ast_cli(a->fd, "%-7.7s %s\n", tz->country, tz->description);
|
|
|
|
ast_tone_zone_unlock(tz);
|
|
|
|
tz = ast_tone_zone_unref(tz);
|
|
|
|
}
|
2012-01-27 18:47:16 +00:00
|
|
|
ao2_iterator_destroy(&iter);
|
2009-02-17 20:41:24 +00:00
|
|
|
return CLI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
buf = ast_str_alloca(256);
|
|
|
|
|
|
|
|
for (i = 2; i < a->argc; i++) {
|
|
|
|
struct ast_tone_zone zone_arg = {
|
|
|
|
.nrringcadence = 0,
|
|
|
|
};
|
|
|
|
struct ast_tone_zone_sound *ts;
|
|
|
|
int j;
|
|
|
|
|
|
|
|
ast_copy_string(zone_arg.country, a->argv[i], sizeof(zone_arg.country));
|
|
|
|
|
|
|
|
if (!(tz = ao2_find(ast_tone_zones, &zone_arg, OBJ_POINTER))) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found_country) {
|
|
|
|
found_country = 1;
|
|
|
|
ast_cli(a->fd, "Country Indication PlayList\n");
|
|
|
|
ast_cli(a->fd, "=====================================\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
ast_tone_zone_lock(tz);
|
|
|
|
|
|
|
|
ast_str_set(&buf, 0, "%-7.7s %-15.15s ", tz->country, "<ringcadence>");
|
|
|
|
for (j = 0; j < tz->nrringcadence; j++) {
|
|
|
|
ast_str_append(&buf, 0, "%d%s", tz->ringcadence[j],
|
|
|
|
(j == tz->nrringcadence - 1) ? "" : ",");
|
|
|
|
}
|
|
|
|
ast_str_append(&buf, 0, "\n");
|
2012-11-19 20:03:56 +00:00
|
|
|
ast_cli(a->fd, "%s", ast_str_buffer(buf));
|
2009-02-17 20:41:24 +00:00
|
|
|
|
|
|
|
AST_LIST_TRAVERSE(&tz->tones, ts, entry) {
|
|
|
|
ast_cli(a->fd, "%-7.7s %-15.15s %s\n", tz->country, ts->name, ts->data);
|
|
|
|
}
|
|
|
|
|
|
|
|
ast_tone_zone_unlock(tz);
|
|
|
|
tz = ast_tone_zone_unref(tz);
|
2003-02-04 15:48:42 +00:00
|
|
|
}
|
2008-11-07 16:18:52 +00:00
|
|
|
|
2009-02-17 20:41:24 +00:00
|
|
|
if (!found_country) {
|
|
|
|
ast_cli(a->fd, "No countries matched your criteria.\n");
|
2008-11-07 16:18:52 +00:00
|
|
|
}
|
|
|
|
|
2009-02-17 20:41:24 +00:00
|
|
|
return CLI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int is_valid_tone_zone(struct ast_tone_zone *zone)
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
|
|
|
|
ast_tone_zone_lock(zone);
|
|
|
|
res = (!ast_strlen_zero(zone->description) && !AST_LIST_EMPTY(&zone->tones));
|
|
|
|
ast_tone_zone_unlock(zone);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2010-09-16 16:48:08 +00:00
|
|
|
/*!\brief
|
|
|
|
*
|
2009-02-17 20:41:24 +00:00
|
|
|
* \note This is called with the tone zone locked.
|
|
|
|
*/
|
|
|
|
static void store_tone_zone_ring_cadence(struct ast_tone_zone *zone, const char *val)
|
|
|
|
{
|
|
|
|
char buf[1024];
|
|
|
|
char *ring, *c = buf;
|
|
|
|
|
|
|
|
ast_copy_string(buf, val, sizeof(buf));
|
|
|
|
|
|
|
|
while ((ring = strsep(&c, ","))) {
|
|
|
|
int *tmp, val;
|
|
|
|
|
|
|
|
ring = ast_strip(ring);
|
|
|
|
|
|
|
|
if (!isdigit(ring[0]) || (val = atoi(ring)) == -1) {
|
|
|
|
ast_log(LOG_WARNING, "Invalid ringcadence given '%s'.\n", ring);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(tmp = ast_realloc(zone->ringcadence, (zone->nrringcadence + 1) * sizeof(int)))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
zone->ringcadence = tmp;
|
|
|
|
tmp[zone->nrringcadence] = val;
|
|
|
|
zone->nrringcadence++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void store_config_tone_zone(struct ast_tone_zone *zone, const char *var,
|
|
|
|
const char *value)
|
|
|
|
{
|
|
|
|
CV_START(var, value);
|
|
|
|
|
|
|
|
CV_STR("description", zone->description);
|
|
|
|
CV_F("ringcadence", store_tone_zone_ring_cadence(zone, value));
|
|
|
|
|
|
|
|
ast_register_indication(zone, var, value);
|
|
|
|
|
|
|
|
CV_END;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void reset_tone_zone(struct ast_tone_zone *zone)
|
|
|
|
{
|
|
|
|
ast_tone_zone_lock(zone);
|
|
|
|
|
|
|
|
zone->killme = 0;
|
|
|
|
|
|
|
|
if (zone->nrringcadence) {
|
|
|
|
zone->nrringcadence = 0;
|
|
|
|
ast_free(zone->ringcadence);
|
|
|
|
zone->ringcadence = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ast_tone_zone_unlock(zone);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int parse_tone_zone(struct ast_config *cfg, const char *country)
|
|
|
|
{
|
|
|
|
struct ast_variable *v;
|
|
|
|
struct ast_tone_zone *zone;
|
|
|
|
struct ast_tone_zone tmp_zone = {
|
|
|
|
.nrringcadence = 0,
|
|
|
|
};
|
|
|
|
int allocd = 0;
|
|
|
|
|
|
|
|
ast_copy_string(tmp_zone.country, country, sizeof(tmp_zone.country));
|
|
|
|
|
|
|
|
if ((zone = ao2_find(ast_tone_zones, &tmp_zone, OBJ_POINTER))) {
|
|
|
|
reset_tone_zone(zone);
|
|
|
|
} else if ((zone = ast_tone_zone_alloc())) {
|
|
|
|
allocd = 1;
|
|
|
|
ast_copy_string(zone->country, country, sizeof(zone->country));
|
|
|
|
} else {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ast_tone_zone_lock(zone);
|
|
|
|
for (v = ast_variable_browse(cfg, country); v; v = v->next) {
|
|
|
|
store_config_tone_zone(zone, v->name, v->value);
|
|
|
|
}
|
|
|
|
ast_tone_zone_unlock(zone);
|
|
|
|
|
|
|
|
if (allocd) {
|
|
|
|
if (!is_valid_tone_zone(zone)) {
|
|
|
|
ast_log(LOG_WARNING, "Indication country '%s' is invalid\n", country);
|
|
|
|
} else if (ast_register_indication_country(zone)) {
|
|
|
|
ast_log(LOG_WARNING, "Unable to register indication country '%s'.\n",
|
|
|
|
country);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
zone = ast_tone_zone_unref(zone);
|
|
|
|
|
2003-02-04 15:48:42 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-09-16 16:48:08 +00:00
|
|
|
/*! \brief
|
2009-02-17 20:41:24 +00:00
|
|
|
* Mark the zone and its tones before parsing configuration. We will use this
|
|
|
|
* to know what to remove after configuration is parsed.
|
|
|
|
*/
|
|
|
|
static int tone_zone_mark(void *obj, void *arg, int flags)
|
|
|
|
{
|
|
|
|
struct ast_tone_zone *zone = obj;
|
|
|
|
struct ast_tone_zone_sound *s;
|
|
|
|
|
|
|
|
ast_tone_zone_lock(zone);
|
|
|
|
|
|
|
|
zone->killme = 1;
|
|
|
|
|
|
|
|
AST_LIST_TRAVERSE(&zone->tones, s, entry) {
|
|
|
|
s->killme = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ast_tone_zone_unlock(zone);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-09-16 16:48:08 +00:00
|
|
|
/*! \brief
|
2009-02-17 20:41:24 +00:00
|
|
|
* Prune tones no longer in the configuration, and have the tone zone unlinked
|
|
|
|
* if it is no longer in the configuration at all.
|
|
|
|
*/
|
|
|
|
static int prune_tone_zone(void *obj, void *arg, int flags)
|
|
|
|
{
|
|
|
|
struct ast_tone_zone *zone = obj;
|
|
|
|
struct ast_tone_zone_sound *s;
|
|
|
|
|
|
|
|
ast_tone_zone_lock(zone);
|
|
|
|
|
|
|
|
AST_LIST_TRAVERSE_SAFE_BEGIN(&zone->tones, s, entry) {
|
|
|
|
if (s->killme) {
|
|
|
|
AST_LIST_REMOVE_CURRENT(entry);
|
|
|
|
s = ast_tone_zone_sound_unref(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
AST_LIST_TRAVERSE_SAFE_END;
|
|
|
|
|
|
|
|
ast_tone_zone_unlock(zone);
|
|
|
|
|
|
|
|
return zone->killme ? CMP_MATCH : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*! \brief load indications module */
|
|
|
|
static int load_indications(int reload)
|
2003-02-04 15:48:42 +00:00
|
|
|
{
|
2009-02-17 20:41:24 +00:00
|
|
|
struct ast_config *cfg;
|
|
|
|
const char *cxt = NULL;
|
|
|
|
const char *country = NULL;
|
|
|
|
struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
|
2003-02-04 15:48:42 +00:00
|
|
|
int res = -1;
|
|
|
|
|
2009-02-17 20:41:24 +00:00
|
|
|
cfg = ast_config_load2(config, "indications", config_flags);
|
|
|
|
|
|
|
|
if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEINVALID) {
|
2010-04-19 21:57:56 +00:00
|
|
|
ast_log(LOG_WARNING, "Can't find indications config file %s.\n", config);
|
2010-04-19 21:49:30 +00:00
|
|
|
return 0;
|
2009-02-17 20:41:24 +00:00
|
|
|
} else if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
|
|
|
|
return 0;
|
|
|
|
}
|
2003-02-04 15:48:42 +00:00
|
|
|
|
2009-02-17 20:41:24 +00:00
|
|
|
/* Lock the container to prevent multiple simultaneous reloads */
|
|
|
|
ao2_lock(ast_tone_zones);
|
2008-11-07 16:18:52 +00:00
|
|
|
|
2009-02-17 20:41:24 +00:00
|
|
|
ao2_callback(ast_tone_zones, OBJ_NODATA, tone_zone_mark, NULL);
|
|
|
|
|
|
|
|
/* Use existing config to populate the Indication table */
|
|
|
|
while ((cxt = ast_category_browse(cfg, cxt))) {
|
|
|
|
/* All categories but "general" are considered countries */
|
|
|
|
if (!strcasecmp(cxt, "general")) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parse_tone_zone(cfg, cxt)) {
|
|
|
|
goto return_cleanup;
|
2003-02-04 15:48:42 +00:00
|
|
|
}
|
|
|
|
}
|
2008-11-07 16:18:52 +00:00
|
|
|
|
2009-02-17 20:41:24 +00:00
|
|
|
ao2_callback(ast_tone_zones, OBJ_NODATA | OBJ_MULTIPLE | OBJ_UNLINK,
|
|
|
|
prune_tone_zone, NULL);
|
|
|
|
|
|
|
|
/* determine which country is the default */
|
|
|
|
country = ast_variable_retrieve(cfg, "general", "country");
|
|
|
|
if (ast_strlen_zero(country) || ast_set_indication_country(country)) {
|
|
|
|
ast_log(LOG_WARNING, "Unable to set the default country (for indication tones)\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
res = 0;
|
|
|
|
|
|
|
|
return_cleanup:
|
|
|
|
ao2_unlock(ast_tone_zones);
|
|
|
|
ast_config_destroy(cfg);
|
|
|
|
|
2003-02-04 15:48:42 +00:00
|
|
|
return res;
|
|
|
|
}
|
2009-02-17 20:41:24 +00:00
|
|
|
|
|
|
|
/*! \brief CLI entries for commands provided by this module */
|
|
|
|
static struct ast_cli_entry cli_indications[] = {
|
|
|
|
AST_CLI_DEFINE(handle_cli_indication_add, "Add the given indication to the country"),
|
|
|
|
AST_CLI_DEFINE(handle_cli_indication_remove, "Remove the given indication from the country"),
|
|
|
|
AST_CLI_DEFINE(handle_cli_indication_show, "Display a list of all countries/indications")
|
|
|
|
};
|
|
|
|
|
|
|
|
static int ast_tone_zone_hash(const void *obj, const int flags)
|
|
|
|
{
|
|
|
|
const struct ast_tone_zone *zone = obj;
|
|
|
|
|
|
|
|
return ast_str_case_hash(zone->country);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ast_tone_zone_cmp(void *obj, void *arg, int flags)
|
|
|
|
{
|
|
|
|
struct ast_tone_zone *zone = obj;
|
|
|
|
struct ast_tone_zone *zone_arg = arg;
|
|
|
|
|
|
|
|
return (!strcasecmp(zone->country, zone_arg->country)) ?
|
|
|
|
CMP_MATCH | CMP_STOP : 0;
|
|
|
|
}
|
|
|
|
|
2013-08-16 17:33:21 +00:00
|
|
|
/*!
|
|
|
|
* \internal
|
|
|
|
* \brief Clean up resources on Asterisk shutdown
|
|
|
|
*/
|
2018-02-17 03:11:42 +00:00
|
|
|
static int unload_module(void)
|
2012-10-02 01:47:16 +00:00
|
|
|
{
|
2012-12-11 02:13:37 +00:00
|
|
|
ast_cli_unregister_multiple(cli_indications, ARRAY_LEN(cli_indications));
|
|
|
|
if (default_tone_zone) {
|
|
|
|
ast_tone_zone_unref(default_tone_zone);
|
|
|
|
default_tone_zone = NULL;
|
|
|
|
}
|
2012-10-02 01:47:16 +00:00
|
|
|
if (ast_tone_zones) {
|
|
|
|
ao2_ref(ast_tone_zones, -1);
|
|
|
|
ast_tone_zones = NULL;
|
|
|
|
}
|
2018-02-17 03:11:42 +00:00
|
|
|
|
|
|
|
return 0;
|
2012-10-02 01:47:16 +00:00
|
|
|
}
|
|
|
|
|
2009-02-17 20:41:24 +00:00
|
|
|
/*! \brief Load indications module */
|
2018-02-17 03:11:42 +00:00
|
|
|
static int load_module(void)
|
2009-02-17 20:41:24 +00:00
|
|
|
{
|
2018-11-19 20:10:02 +00:00
|
|
|
ast_tone_zones = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
|
|
|
|
NUM_TONE_ZONE_BUCKETS, ast_tone_zone_hash, NULL, ast_tone_zone_cmp);
|
2018-03-10 09:33:33 +00:00
|
|
|
if (!ast_tone_zones) {
|
2018-02-17 03:11:42 +00:00
|
|
|
return AST_MODULE_LOAD_FAILURE;
|
2009-02-17 20:41:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (load_indications(0)) {
|
2018-02-17 03:11:42 +00:00
|
|
|
return AST_MODULE_LOAD_FAILURE;
|
2009-02-17 20:41:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ast_cli_register_multiple(cli_indications, ARRAY_LEN(cli_indications));
|
|
|
|
|
2018-02-17 03:11:42 +00:00
|
|
|
return AST_MODULE_LOAD_SUCCESS;
|
2009-02-17 20:41:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*! \brief Reload indications module */
|
2018-02-17 03:11:42 +00:00
|
|
|
static int reload_module(void)
|
2009-02-17 20:41:24 +00:00
|
|
|
{
|
|
|
|
return load_indications(1);
|
|
|
|
}
|
2018-02-17 03:11:42 +00:00
|
|
|
|
|
|
|
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER, "Indication Tone Handling",
|
|
|
|
.support_level = AST_MODULE_SUPPORT_CORE,
|
|
|
|
.load = load_module,
|
|
|
|
.unload = unload_module,
|
|
|
|
.reload = reload_module,
|
|
|
|
.load_pri = AST_MODPRI_CORE,
|
2018-07-26 17:52:46 +00:00
|
|
|
.requires = "extconfig",
|
2018-02-17 03:11:42 +00:00
|
|
|
);
|