2002-06-29 21:46:57 +00:00
|
|
|
/*
|
2005-09-14 20:46:50 +00:00
|
|
|
* Asterisk -- An open source telephony toolkit.
|
2002-06-29 21:46:57 +00:00
|
|
|
*
|
2010-10-20 00:41:49 +00:00
|
|
|
* Copyright (C) 1999 - 2010, Digium, Inc.
|
2002-06-29 21:46:57 +00:00
|
|
|
*
|
2004-09-07 01:22:57 +00:00
|
|
|
* Mark Spencer <markster@digium.com>
|
2002-06-29 21:46:57 +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.
|
|
|
|
*
|
2002-06-29 21:46:57 +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.
|
|
|
|
*/
|
|
|
|
|
2005-10-24 20:12:06 +00:00
|
|
|
/*! \file
|
|
|
|
*
|
|
|
|
* \brief Routines implementing music on hold
|
2005-09-14 20:46:50 +00:00
|
|
|
*
|
2005-12-30 21:18:06 +00:00
|
|
|
* \author Mark Spencer <markster@digium.com>
|
2002-06-29 21:46:57 +00:00
|
|
|
*/
|
|
|
|
|
2012-10-14 21:44:27 +00:00
|
|
|
/*! \li \ref res_musiconhold.c uses the configuration file \ref musiconhold.conf
|
2012-10-01 23:24:10 +00:00
|
|
|
* \addtogroup configuration_file Configuration Files
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \page musiconhold.conf musiconhold.conf
|
|
|
|
* \verbinclude musiconhold.conf.sample
|
|
|
|
*/
|
|
|
|
|
2006-04-24 17:11:45 +00:00
|
|
|
/*** MODULEINFO
|
|
|
|
<conflict>win32</conflict>
|
2011-07-14 20:28:54 +00:00
|
|
|
<support_level>core</support_level>
|
2006-04-24 17:11:45 +00:00
|
|
|
***/
|
|
|
|
|
2006-06-07 18:54:56 +00:00
|
|
|
#include "asterisk.h"
|
|
|
|
|
git migration: Refactor the ASTERISK_FILE_VERSION macro
Git does not support the ability to replace a token with a version
string during check-in. While it does have support for replacing a
token on clone, this is somewhat sub-optimal: the token is replaced
with the object hash, which is not particularly easy for human
consumption. What's more, in practice, the source file version was often
not terribly useful. Generally, when triaging bugs, the overall version
of Asterisk is far more useful than an individual SVN version of a file. As a
result, this patch removes Asterisk's support for showing source file
versions.
Specifically, it does the following:
* Rename ASTERISK_FILE_VERSION macro to ASTERISK_REGISTER_FILE, and
remove passing the version in with the macro. Other facilities
than 'core show file version' make use of the file names, such as
setting a debug level only on a specific file. As such, the act of
registering source files with the Asterisk core still has use. The
macro rename now reflects the new macro purpose.
* main/asterisk:
- Refactor the file_version structure to reflect that it no longer
tracks a version field.
- Remove the "core show file version" CLI command. Without the file
version, it is no longer useful.
- Remove the ast_file_version_find function. The file version is no
longer tracked.
- Rename ast_register_file_version/ast_unregister_file_version to
ast_register_file/ast_unregister_file, respectively.
* main/manager: Remove value from the Version key of the ModuleCheck
Action. The actual key itself has not been removed, as doing so would
absolutely constitute a backwards incompatible change. However, since
the file version is no longer tracked, there is no need to attempt to
include it in the Version key.
* UPGRADE: Add notes for:
- Modification to the ModuleCheck AMI Action
- Removal of the "core show file version" CLI command
Change-Id: I6cf0ff280e1668bf4957dc21f32a5ff43444a40e
2015-04-12 02:38:22 +00:00
|
|
|
ASTERISK_REGISTER_FILE()
|
2006-06-07 18:54:56 +00:00
|
|
|
|
2007-05-22 18:52:59 +00:00
|
|
|
#include <ctype.h>
|
2003-09-08 16:48:07 +00:00
|
|
|
#include <signal.h>
|
2002-06-29 21:46:57 +00:00
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/signal.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <dirent.h>
|
2005-06-06 22:12:19 +00:00
|
|
|
|
2010-01-16 00:54:08 +00:00
|
|
|
#ifdef SOLARIS
|
|
|
|
#include <thread.h>
|
|
|
|
#endif
|
|
|
|
|
2005-06-06 22:12:19 +00:00
|
|
|
#include "asterisk/lock.h"
|
|
|
|
#include "asterisk/file.h"
|
|
|
|
#include "asterisk/channel.h"
|
|
|
|
#include "asterisk/pbx.h"
|
2008-02-13 15:47:25 +00:00
|
|
|
#include "asterisk/app.h"
|
2005-06-06 22:12:19 +00:00
|
|
|
#include "asterisk/module.h"
|
|
|
|
#include "asterisk/translate.h"
|
|
|
|
#include "asterisk/say.h"
|
|
|
|
#include "asterisk/musiconhold.h"
|
|
|
|
#include "asterisk/config.h"
|
|
|
|
#include "asterisk/utils.h"
|
|
|
|
#include "asterisk/cli.h"
|
2006-02-01 23:05:28 +00:00
|
|
|
#include "asterisk/stringfields.h"
|
2006-04-29 13:15:05 +00:00
|
|
|
#include "asterisk/linkedlists.h"
|
2013-05-24 20:44:07 +00:00
|
|
|
#include "asterisk/stasis.h"
|
|
|
|
#include "asterisk/stasis_channels.h"
|
2008-10-16 08:30:32 +00:00
|
|
|
#include "asterisk/paths.h"
|
2008-12-22 16:10:40 +00:00
|
|
|
#include "asterisk/astobj2.h"
|
2010-08-26 23:51:55 +00:00
|
|
|
#include "asterisk/timing.h"
|
|
|
|
#include "asterisk/time.h"
|
|
|
|
#include "asterisk/poll-compat.h"
|
2005-06-06 22:12:19 +00:00
|
|
|
|
2006-06-04 06:21:43 +00:00
|
|
|
#define INITIAL_NUM_FILES 8
|
2009-12-03 00:08:55 +00:00
|
|
|
#define HANDLE_REF 1
|
|
|
|
#define DONT_UNREF 0
|
2002-06-29 21:46:57 +00:00
|
|
|
|
2009-06-06 23:03:15 +00:00
|
|
|
/*** DOCUMENTATION
|
|
|
|
<application name="MusicOnHold" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Play Music On Hold indefinitely.
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="class" required="true" />
|
|
|
|
<parameter name="duration" />
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>Plays hold music specified by class. If omitted, the default music
|
|
|
|
source for the channel will be used. Change the default class with
|
|
|
|
Set(CHANNEL(musicclass)=...). If duration is given, hold music will be played
|
|
|
|
specified number of seconds. If duration is ommited, music plays indefinitely.
|
|
|
|
Returns <literal>0</literal> when done, <literal>-1</literal> on hangup.</para>
|
2011-09-19 20:23:29 +00:00
|
|
|
<para>This application does not automatically answer and should be preceeded by
|
|
|
|
an application such as Answer() or Progress().</para>
|
2009-06-06 23:03:15 +00:00
|
|
|
</description>
|
|
|
|
</application>
|
|
|
|
<application name="StartMusicOnHold" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Play Music On Hold.
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="class" required="true" />
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>Starts playing music on hold, uses default music class for channel.
|
|
|
|
Starts playing music specified by class. If omitted, the default music
|
|
|
|
source for the channel will be used. Always returns <literal>0</literal>.</para>
|
|
|
|
</description>
|
|
|
|
</application>
|
|
|
|
<application name="StopMusicOnHold" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Stop playing Music On Hold.
|
|
|
|
</synopsis>
|
|
|
|
<syntax />
|
|
|
|
<description>
|
|
|
|
<para>Stops playing music on hold.</para>
|
|
|
|
</description>
|
|
|
|
</application>
|
|
|
|
***/
|
|
|
|
|
|
|
|
static const char play_moh[] = "MusicOnHold";
|
|
|
|
static const char start_moh[] = "StartMusicOnHold";
|
|
|
|
static const char stop_moh[] = "StopMusicOnHold";
|
2005-03-03 05:03:06 +00:00
|
|
|
|
2004-09-04 05:41:01 +00:00
|
|
|
static int respawn_time = 20;
|
|
|
|
|
2004-12-24 01:40:07 +00:00
|
|
|
struct moh_files_state {
|
2011-09-02 21:09:31 +00:00
|
|
|
/*! Holds a reference to the MOH class. */
|
2004-12-24 01:40:07 +00:00
|
|
|
struct mohclass *class;
|
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;
|
|
|
|
struct ast_format *mohwfmt;
|
2012-01-23 18:34:47 +00:00
|
|
|
int announcement;
|
2004-12-24 01:40:07 +00:00
|
|
|
int samples;
|
|
|
|
int sample_queue;
|
2007-08-27 16:16:56 +00:00
|
|
|
int pos;
|
|
|
|
int save_pos;
|
2014-08-25 16:16:52 +00:00
|
|
|
int save_total;
|
|
|
|
char name[MAX_MUSICCLASS];
|
2011-11-23 16:12:34 +00:00
|
|
|
char save_pos_filename[PATH_MAX];
|
2004-12-24 01:40:07 +00:00
|
|
|
};
|
|
|
|
|
2005-01-09 09:00:41 +00:00
|
|
|
#define MOH_QUIET (1 << 0)
|
|
|
|
#define MOH_SINGLE (1 << 1)
|
|
|
|
#define MOH_CUSTOM (1 << 2)
|
|
|
|
#define MOH_RANDOMIZE (1 << 3)
|
2007-10-01 14:43:56 +00:00
|
|
|
#define MOH_SORTALPHA (1 << 4)
|
2014-09-14 15:41:58 +00:00
|
|
|
#define MOH_RANDSTART (MOH_RANDOMIZE | MOH_SORTALPHA) /*!< Sorted but start at random position */
|
|
|
|
#define MOH_SORTMODE (3 << 3)
|
2005-01-09 09:00:41 +00:00
|
|
|
|
2014-09-25 20:49:04 +00:00
|
|
|
#define MOH_CACHERTCLASSES (1 << 5) /*!< Should we use a separate instance of MOH for each user or not */
|
|
|
|
#define MOH_ANNOUNCEMENT (1 << 6) /*!< Do we play announcement files between songs on this channel? */
|
|
|
|
#define MOH_PREFERCHANNELCLASS (1 << 7) /*!< Should queue moh override channel moh */
|
Adding support for realtime music on hold. The following are the main points:
1. When moh is started, we search first in memory to find the class. If we do not
find it in memory, we search realtime instead.
2. When moh is restarted (as in, it had been started on this particular channel, stopped,
and now we're starting it again), if using the "files" mode, then realtime will always
be rechecked. If you are using other modes, however, we will simply reattach to the external
running process which was playing moh earlier in the call. This is a necessary compromise so that
we don't end up with too many background processes.
3. musiconhold.conf has a general section now. It has one option: cachertclasses. If set to yes,
then moh classes found in realtime will be added to the in-memory list. This has the advantage
of not requiring database lookups each time moh is started, but it has the disadvantage of not
truly being realtime.
I have tested this for functionality, and it passes. I also tested this under valgrind and there
are no memory problems reported under typical use.
Special thanks to Sergee for implementing this feature and enduring my complaints on the bugtracker!
(closes issue #11196, reported and patched by sergee)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89946 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-28 00:47:22 +00:00
|
|
|
|
2009-12-03 00:08:55 +00:00
|
|
|
/* Custom astobj2 flag */
|
|
|
|
#define MOH_NOTDELETED (1 << 30) /*!< Find only records that aren't deleted? */
|
|
|
|
|
Adding support for realtime music on hold. The following are the main points:
1. When moh is started, we search first in memory to find the class. If we do not
find it in memory, we search realtime instead.
2. When moh is restarted (as in, it had been started on this particular channel, stopped,
and now we're starting it again), if using the "files" mode, then realtime will always
be rechecked. If you are using other modes, however, we will simply reattach to the external
running process which was playing moh earlier in the call. This is a necessary compromise so that
we don't end up with too many background processes.
3. musiconhold.conf has a general section now. It has one option: cachertclasses. If set to yes,
then moh classes found in realtime will be added to the in-memory list. This has the advantage
of not requiring database lookups each time moh is started, but it has the disadvantage of not
truly being realtime.
I have tested this for functionality, and it passes. I also tested this under valgrind and there
are no memory problems reported under typical use.
Special thanks to Sergee for implementing this feature and enduring my complaints on the bugtracker!
(closes issue #11196, reported and patched by sergee)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89946 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-28 00:47:22 +00:00
|
|
|
static struct ast_flags global_flags[1] = {{0}}; /*!< global MOH_ flags */
|
|
|
|
|
2002-06-29 21:46:57 +00:00
|
|
|
struct mohclass {
|
2005-08-22 19:29:29 +00:00
|
|
|
char name[MAX_MUSICCLASS];
|
2006-02-24 10:50:43 +00:00
|
|
|
char dir[256];
|
2005-08-22 19:29:29 +00:00
|
|
|
char args[256];
|
2012-01-23 18:34:47 +00:00
|
|
|
char announcement[256];
|
2005-08-22 19:29:29 +00:00
|
|
|
char mode[80];
|
2007-05-22 18:52:59 +00:00
|
|
|
char digit;
|
2006-06-04 06:21:43 +00:00
|
|
|
/*! A dynamically sized array to hold the list of filenames in "files" mode */
|
|
|
|
char **filearray;
|
|
|
|
/*! The current size of the filearray */
|
|
|
|
int allowed_files;
|
|
|
|
/*! The current number of files loaded into the filearray */
|
2004-12-24 01:40:07 +00:00
|
|
|
int total_files;
|
After some study, thought, comparing, etc. I've backed out the previous universal mod to make ast_flags a 64 bit thing. Instead, I added a 64-bit version of ast_flags (ast_flags64), and 64-bit versions of the test-flag, set-flag, etc. macros, and an app_parse_options64 routine, and I use these in app_dial alone, to eliminate the 30-option limit it had grown to meet. There is room now for 32 more options and flags. I was heavily tempted to implement some of the other ideas that were presented, but this solution does not intro any new versions of dial, doesn't have a different API, has a minimal/zero impact on code outside of dial, and doesn't seriously (I hope) affect the code structure of dial. It's the best I can think of right now. My goal was NOT to rewrite dial. I leave that to a future, coordinated effort.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@75983 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-07-19 23:24:27 +00:00
|
|
|
unsigned int flags;
|
2006-06-04 06:21:43 +00:00
|
|
|
/*! The format from the MOH source, not applicable to "files" mode */
|
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 *format;
|
2006-06-04 06:21:43 +00:00
|
|
|
/*! The pid of the external application delivering MOH */
|
|
|
|
int pid;
|
2004-09-04 05:41:01 +00:00
|
|
|
time_t start;
|
2002-06-29 21:46:57 +00:00
|
|
|
pthread_t thread;
|
2006-06-04 06:21:43 +00:00
|
|
|
/*! Source of audio */
|
2002-06-29 21:46:57 +00:00
|
|
|
int srcfd;
|
2010-08-26 23:51:55 +00:00
|
|
|
/*! Generic timer */
|
|
|
|
struct ast_timer *timer;
|
Adding support for realtime music on hold. The following are the main points:
1. When moh is started, we search first in memory to find the class. If we do not
find it in memory, we search realtime instead.
2. When moh is restarted (as in, it had been started on this particular channel, stopped,
and now we're starting it again), if using the "files" mode, then realtime will always
be rechecked. If you are using other modes, however, we will simply reattach to the external
running process which was playing moh earlier in the call. This is a necessary compromise so that
we don't end up with too many background processes.
3. musiconhold.conf has a general section now. It has one option: cachertclasses. If set to yes,
then moh classes found in realtime will be added to the in-memory list. This has the advantage
of not requiring database lookups each time moh is started, but it has the disadvantage of not
truly being realtime.
I have tested this for functionality, and it passes. I also tested this under valgrind and there
are no memory problems reported under typical use.
Special thanks to Sergee for implementing this feature and enduring my complaints on the bugtracker!
(closes issue #11196, reported and patched by sergee)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89946 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-28 00:47:22 +00:00
|
|
|
/*! Created on the fly, from RT engine */
|
2010-08-26 23:51:55 +00:00
|
|
|
unsigned int realtime:1;
|
2007-08-16 22:30:39 +00:00
|
|
|
unsigned int delete:1;
|
2006-04-29 13:15:05 +00:00
|
|
|
AST_LIST_HEAD_NOLOCK(, mohdata) members;
|
|
|
|
AST_LIST_ENTRY(mohclass) list;
|
2002-06-29 21:46:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct mohdata {
|
|
|
|
int pipe[2];
|
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;
|
2002-06-29 21:46:57 +00:00
|
|
|
struct mohclass *parent;
|
2006-04-29 13:15:05 +00:00
|
|
|
struct ast_frame f;
|
|
|
|
AST_LIST_ENTRY(mohdata) list;
|
2002-06-29 21:46:57 +00:00
|
|
|
};
|
|
|
|
|
2008-12-22 16:10:40 +00:00
|
|
|
static struct ao2_container *mohclasses;
|
2002-06-29 21:46:57 +00:00
|
|
|
|
2003-09-16 19:35:57 +00:00
|
|
|
#define LOCAL_MPG_123 "/usr/local/bin/mpg123"
|
2002-06-29 21:46:57 +00:00
|
|
|
#define MPG_123 "/usr/bin/mpg123"
|
|
|
|
#define MAX_MP3S 256
|
|
|
|
|
2014-09-14 15:41:58 +00:00
|
|
|
static void moh_parse_options(struct ast_variable *var, struct mohclass *mohclass);
|
2007-08-16 22:30:39 +00:00
|
|
|
static int reload(void);
|
2005-07-28 18:37:55 +00:00
|
|
|
|
2009-04-09 17:34:39 +00:00
|
|
|
#define mohclass_ref(class,string) (ao2_t_ref((class), +1, (string)), class)
|
2009-12-08 18:22:44 +00:00
|
|
|
|
2015-04-17 07:16:59 +00:00
|
|
|
#ifndef AST_DEVMODE
|
2014-05-09 22:49:26 +00:00
|
|
|
#define mohclass_unref(class,string) ({ ao2_t_ref((class), -1, (string)); (struct mohclass *) NULL; })
|
2009-12-08 18:22:44 +00:00
|
|
|
#else
|
|
|
|
#define mohclass_unref(class,string) _mohclass_unref(class, string, __FILE__,__LINE__,__PRETTY_FUNCTION__)
|
|
|
|
static struct mohclass *_mohclass_unref(struct mohclass *class, const char *tag, const char *file, int line, const char *funcname)
|
|
|
|
{
|
2014-08-21 21:35:58 +00:00
|
|
|
struct mohclass *dup = ao2_callback(mohclasses, OBJ_POINTER, ao2_match_by_addr, class);
|
|
|
|
|
|
|
|
if (dup) {
|
2015-04-17 07:16:59 +00:00
|
|
|
if (__ao2_ref(dup, -1, tag, file, line, funcname) == 2) {
|
2009-12-08 18:22:44 +00:00
|
|
|
ast_log(LOG_WARNING, "Attempt to unref mohclass %p (%s) when only 1 ref remained, and class is still in a container! (at %s:%d (%s))\n",
|
|
|
|
class, class->name, file, line, funcname);
|
|
|
|
} else {
|
|
|
|
ao2_ref(class, -1);
|
|
|
|
}
|
|
|
|
} else {
|
2015-04-17 07:16:59 +00:00
|
|
|
__ao2_ref(class, -1, tag, file, line, funcname);
|
2009-12-08 18:22:44 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#endif
|
2005-07-28 18:37:55 +00:00
|
|
|
|
2014-03-12 19:06:52 +00:00
|
|
|
static void moh_post_start(struct ast_channel *chan, const char *moh_class_name)
|
|
|
|
{
|
|
|
|
struct stasis_message *message;
|
|
|
|
struct ast_json *json_object;
|
|
|
|
|
|
|
|
ast_verb(3, "Started music on hold, class '%s', on channel '%s'\n",
|
|
|
|
moh_class_name, ast_channel_name(chan));
|
|
|
|
|
|
|
|
json_object = ast_json_pack("{s: s}", "class", moh_class_name);
|
|
|
|
if (!json_object) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
message = ast_channel_blob_create_from_cache(ast_channel_uniqueid(chan),
|
|
|
|
ast_channel_moh_start_type(), json_object);
|
|
|
|
if (message) {
|
2014-04-04 17:57:46 +00:00
|
|
|
/* A channel snapshot must have been in the cache. */
|
|
|
|
ast_assert(((struct ast_channel_blob *) stasis_message_data(message))->snapshot != NULL);
|
|
|
|
|
2014-03-12 19:06:52 +00:00
|
|
|
stasis_publish(ast_channel_topic(chan), message);
|
|
|
|
}
|
|
|
|
ao2_cleanup(message);
|
|
|
|
ast_json_unref(json_object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void moh_post_stop(struct ast_channel *chan)
|
|
|
|
{
|
|
|
|
struct stasis_message *message;
|
|
|
|
|
|
|
|
ast_verb(3, "Stopped music on hold on %s\n", ast_channel_name(chan));
|
|
|
|
|
|
|
|
message = ast_channel_blob_create_from_cache(ast_channel_uniqueid(chan),
|
|
|
|
ast_channel_moh_stop_type(), NULL);
|
|
|
|
if (message) {
|
2014-04-04 17:57:46 +00:00
|
|
|
/* A channel snapshot must have been in the cache. */
|
|
|
|
ast_assert(((struct ast_channel_blob *) stasis_message_data(message))->snapshot != NULL);
|
|
|
|
|
2014-03-12 19:06:52 +00:00
|
|
|
stasis_publish(ast_channel_topic(chan), message);
|
|
|
|
}
|
|
|
|
ao2_cleanup(message);
|
|
|
|
}
|
|
|
|
|
2004-12-24 01:40:07 +00:00
|
|
|
static void moh_files_release(struct ast_channel *chan, void *data)
|
|
|
|
{
|
2008-03-14 14:32:55 +00:00
|
|
|
struct moh_files_state *state;
|
|
|
|
|
2012-02-20 23:43:27 +00:00
|
|
|
if (!chan || !ast_channel_music_state(chan)) {
|
2008-12-22 16:10:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-20 23:43:27 +00:00
|
|
|
state = ast_channel_music_state(chan);
|
2008-12-22 16:10:40 +00:00
|
|
|
|
2012-02-20 23:43:27 +00:00
|
|
|
if (ast_channel_stream(chan)) {
|
|
|
|
ast_closestream(ast_channel_stream(chan));
|
|
|
|
ast_channel_stream_set(chan, NULL);
|
2008-12-22 16:10:40 +00:00
|
|
|
}
|
2014-03-12 19:06:52 +00:00
|
|
|
|
|
|
|
moh_post_stop(chan);
|
2004-12-24 01:40:07 +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_ref(state->mohwfmt, -1);
|
|
|
|
state->mohwfmt = NULL; /* make sure to clear this format before restoring the original format */
|
|
|
|
if (state->origwfmt && ast_set_write_format(chan, state->origwfmt)) {
|
|
|
|
ast_log(LOG_WARNING, "Unable to restore channel '%s' to format '%s'\n", ast_channel_name(chan),
|
|
|
|
ast_format_get_name(state->origwfmt));
|
2004-12-24 01:40:07 +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(state->origwfmt);
|
|
|
|
state->origwfmt = NULL;
|
2004-12-24 01:40:07 +00:00
|
|
|
|
2008-12-22 16:10:40 +00:00
|
|
|
state->save_pos = state->pos;
|
2012-01-23 18:34:47 +00:00
|
|
|
state->announcement = 0;
|
2008-12-22 16:10:40 +00:00
|
|
|
|
2009-12-03 00:08:55 +00:00
|
|
|
state->class = mohclass_unref(state->class, "Unreffing channel's music class upon deactivation of generator");
|
2008-12-22 16:10:40 +00:00
|
|
|
}
|
2004-12-24 01:40:07 +00:00
|
|
|
|
2005-01-10 22:12:58 +00:00
|
|
|
static int ast_moh_files_next(struct ast_channel *chan)
|
|
|
|
{
|
2012-02-20 23:43:27 +00:00
|
|
|
struct moh_files_state *state = ast_channel_music_state(chan);
|
2005-01-10 22:12:58 +00:00
|
|
|
int tries;
|
2004-12-24 01:40:07 +00:00
|
|
|
|
2007-02-01 21:12:26 +00:00
|
|
|
/* Discontinue a stream if it is running already */
|
2012-02-20 23:43:27 +00:00
|
|
|
if (ast_channel_stream(chan)) {
|
|
|
|
ast_closestream(ast_channel_stream(chan));
|
|
|
|
ast_channel_stream_set(chan, NULL);
|
2006-11-27 17:31:56 +00:00
|
|
|
}
|
2005-04-13 04:47:39 +00:00
|
|
|
|
2012-01-23 18:34:47 +00:00
|
|
|
if (ast_test_flag(state->class, MOH_ANNOUNCEMENT) && state->announcement == 0) {
|
|
|
|
state->announcement = 1;
|
2012-01-24 20:12:09 +00:00
|
|
|
if (ast_openstream_full(chan, state->class->announcement, ast_channel_language(chan), 1)) {
|
2012-01-23 18:34:47 +00:00
|
|
|
ast_debug(1, "%s Opened announcement '%s'\n", ast_channel_name(chan), state->class->announcement);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
state->announcement = 0;
|
|
|
|
}
|
|
|
|
|
2007-11-06 18:23:36 +00:00
|
|
|
if (!state->class->total_files) {
|
|
|
|
ast_log(LOG_WARNING, "No files available for class '%s'\n", state->class->name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-11-23 16:12:34 +00:00
|
|
|
if (state->pos == 0 && ast_strlen_zero(state->save_pos_filename)) {
|
2010-06-14 21:33:55 +00:00
|
|
|
/* First time so lets play the file. */
|
|
|
|
state->save_pos = -1;
|
2011-11-23 16:12:34 +00:00
|
|
|
} else if (state->save_pos >= 0 && state->save_pos < state->class->total_files && !strcmp(state->class->filearray[state->save_pos], state->save_pos_filename)) {
|
2010-06-14 21:33:55 +00:00
|
|
|
/* If a specific file has been saved confirm it still exists and that it is still valid */
|
2007-02-01 21:12:26 +00:00
|
|
|
state->pos = state->save_pos;
|
2007-08-27 16:16:56 +00:00
|
|
|
state->save_pos = -1;
|
2014-09-14 15:41:58 +00:00
|
|
|
} else if (ast_test_flag(state->class, MOH_SORTMODE) == MOH_RANDOMIZE) {
|
2007-02-01 21:12:26 +00:00
|
|
|
/* Get a random file and ensure we can open it */
|
2006-11-27 17:31:56 +00:00
|
|
|
for (tries = 0; tries < 20; tries++) {
|
2008-05-06 19:38:44 +00:00
|
|
|
state->pos = ast_random() % state->class->total_files;
|
2010-06-14 21:33:55 +00:00
|
|
|
if (ast_fileexists(state->class->filearray[state->pos], NULL, NULL) > 0) {
|
2005-01-10 22:12:58 +00:00
|
|
|
break;
|
2010-06-14 21:33:55 +00:00
|
|
|
}
|
2004-12-24 01:40:07 +00:00
|
|
|
}
|
2008-03-19 19:13:39 +00:00
|
|
|
state->save_pos = -1;
|
2007-02-01 21:12:26 +00:00
|
|
|
state->samples = 0;
|
|
|
|
} else {
|
|
|
|
/* This is easy, just increment our position and make sure we don't exceed the total file count */
|
|
|
|
state->pos++;
|
|
|
|
state->pos %= state->class->total_files;
|
2008-03-19 19:13:39 +00:00
|
|
|
state->save_pos = -1;
|
2007-02-01 21:12:26 +00:00
|
|
|
state->samples = 0;
|
2004-12-24 01:40:07 +00:00
|
|
|
}
|
|
|
|
|
2010-09-09 17:25:24 +00:00
|
|
|
for (tries = 0; tries < state->class->total_files; ++tries) {
|
2012-01-24 20:12:09 +00:00
|
|
|
if (ast_openstream_full(chan, state->class->filearray[state->pos], ast_channel_language(chan), 1)) {
|
2010-09-09 17:25:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-12-24 01:40:07 +00:00
|
|
|
ast_log(LOG_WARNING, "Unable to open file '%s': %s\n", state->class->filearray[state->pos], strerror(errno));
|
|
|
|
state->pos++;
|
2006-12-07 18:21:21 +00:00
|
|
|
state->pos %= state->class->total_files;
|
2010-09-09 17:25:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (tries == state->class->total_files) {
|
2004-12-24 01:40:07 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-03-19 19:13:39 +00:00
|
|
|
/* Record the pointer to the filename for position resuming later */
|
2011-11-23 16:12:34 +00:00
|
|
|
ast_copy_string(state->save_pos_filename, state->class->filearray[state->pos], sizeof(state->save_pos_filename));
|
2008-03-19 19:13:39 +00:00
|
|
|
|
2012-01-09 22:15:50 +00:00
|
|
|
ast_debug(1, "%s Opened file %d '%s'\n", ast_channel_name(chan), state->pos, state->class->filearray[state->pos]);
|
2004-12-24 01:40:07 +00:00
|
|
|
|
2010-06-14 21:33:55 +00:00
|
|
|
if (state->samples) {
|
2011-08-08 20:54:14 +00:00
|
|
|
size_t loc;
|
|
|
|
/* seek *SHOULD* be good since it's from a known location */
|
2012-02-20 23:43:27 +00:00
|
|
|
ast_seekstream(ast_channel_stream(chan), state->samples, SEEK_SET);
|
2011-08-08 20:54:14 +00:00
|
|
|
/* if the seek failed then recover because if there is not a valid read,
|
|
|
|
* moh_files_generate will return -1 and MOH will stop */
|
2012-02-20 23:43:27 +00:00
|
|
|
loc = ast_tellstream(ast_channel_stream(chan));
|
2011-08-08 20:54:14 +00:00
|
|
|
if (state->samples > loc && loc) {
|
|
|
|
/* seek one sample from the end for one guaranteed valid read */
|
2012-02-20 23:43:27 +00:00
|
|
|
ast_seekstream(ast_channel_stream(chan), 1, SEEK_END);
|
2011-08-08 20:54:14 +00:00
|
|
|
}
|
2010-06-14 21:33:55 +00:00
|
|
|
}
|
2004-12-24 01:40:07 +00:00
|
|
|
|
2005-01-09 09:00:41 +00:00
|
|
|
return 0;
|
2004-12-24 01:40:07 +00:00
|
|
|
}
|
|
|
|
|
2011-02-04 16:55:39 +00:00
|
|
|
static struct ast_frame *moh_files_readframe(struct ast_channel *chan)
|
2005-03-03 05:03:06 +00:00
|
|
|
{
|
2004-12-24 01:40:07 +00:00
|
|
|
struct ast_frame *f = NULL;
|
2011-02-04 16:55:39 +00:00
|
|
|
|
2012-02-20 23:43:27 +00:00
|
|
|
if (!(ast_channel_stream(chan) && (f = ast_readframe(ast_channel_stream(chan))))) {
|
2005-01-09 09:00:41 +00:00
|
|
|
if (!ast_moh_files_next(chan))
|
2012-02-20 23:43:27 +00:00
|
|
|
f = ast_readframe(ast_channel_stream(chan));
|
2004-12-24 01:40:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2011-04-21 18:11:40 +00:00
|
|
|
static void moh_files_write_format_change(struct ast_channel *chan, void *data)
|
|
|
|
{
|
2012-02-20 23:43:27 +00:00
|
|
|
struct moh_files_state *state = ast_channel_music_state(chan);
|
2011-04-21 18:11:40 +00:00
|
|
|
|
|
|
|
/* In order to prevent a recursive call to this function as a result
|
|
|
|
* of setting the moh write format back on the channel. Clear
|
|
|
|
* the moh write format before setting the write format on the channel.*/
|
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 (state->origwfmt) {
|
|
|
|
struct ast_format *tmp;
|
2011-04-21 18:11:40 +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
|
|
|
tmp = ao2_bump(ast_channel_writeformat(chan));
|
|
|
|
ao2_replace(state->origwfmt, NULL);
|
|
|
|
if (state->mohwfmt) {
|
|
|
|
ast_set_write_format(chan, state->mohwfmt);
|
2011-04-21 18:11:40 +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
|
|
|
state->origwfmt = tmp;
|
2011-04-21 18:11:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-12-24 01:40:07 +00:00
|
|
|
static int moh_files_generator(struct ast_channel *chan, void *data, int len, int samples)
|
|
|
|
{
|
2012-02-20 23:43:27 +00:00
|
|
|
struct moh_files_state *state = ast_channel_music_state(chan);
|
2004-12-24 01:40:07 +00:00
|
|
|
struct ast_frame *f = NULL;
|
|
|
|
int res = 0;
|
2005-09-01 19:34:49 +00:00
|
|
|
|
2004-12-24 01:40:07 +00:00
|
|
|
state->sample_queue += samples;
|
|
|
|
|
2005-01-09 09:00:41 +00:00
|
|
|
while (state->sample_queue > 0) {
|
2010-04-30 20:11:02 +00:00
|
|
|
ast_channel_lock(chan);
|
2014-05-14 15:41:42 +00:00
|
|
|
f = moh_files_readframe(chan);
|
|
|
|
|
|
|
|
/* We need to be sure that we unlock
|
|
|
|
* the channel prior to calling
|
|
|
|
* ast_write. Otherwise, the recursive locking
|
|
|
|
* that occurs can cause deadlocks when using
|
|
|
|
* indirect channels, like local channels
|
|
|
|
*/
|
|
|
|
ast_channel_unlock(chan);
|
|
|
|
if (!f) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
state->samples += f->samples;
|
|
|
|
state->sample_queue -= f->samples;
|
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_format_cmp(f->subclass.format, state->mohwfmt) == AST_FORMAT_CMP_NOT_EQUAL) {
|
|
|
|
ao2_replace(state->mohwfmt, f->subclass.format);
|
2014-05-14 15:41:42 +00:00
|
|
|
}
|
|
|
|
res = ast_write(chan, f);
|
|
|
|
ast_frfree(f);
|
|
|
|
if (res < 0) {
|
|
|
|
ast_log(LOG_WARNING, "Failed to write frame to '%s': %s\n", ast_channel_name(chan), strerror(errno));
|
|
|
|
return -1;
|
2010-04-30 20:11:02 +00:00
|
|
|
}
|
2004-12-24 01:40:07 +00:00
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *moh_files_alloc(struct ast_channel *chan, void *params)
|
|
|
|
{
|
|
|
|
struct moh_files_state *state;
|
|
|
|
struct mohclass *class = params;
|
|
|
|
|
2014-03-12 19:06:52 +00:00
|
|
|
state = ast_channel_music_state(chan);
|
|
|
|
if (!state && (state = ast_calloc(1, sizeof(*state)))) {
|
2012-02-20 23:43:27 +00:00
|
|
|
ast_channel_music_state_set(chan, state);
|
2009-12-08 18:22:44 +00:00
|
|
|
ast_module_ref(ast_module_info->self);
|
2008-12-22 16:10:40 +00:00
|
|
|
} else {
|
2011-09-02 21:09:31 +00:00
|
|
|
if (!state) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (state->class) {
|
|
|
|
mohclass_unref(state->class, "Uh Oh. Restarting MOH with an active class");
|
|
|
|
ast_log(LOG_WARNING, "Uh Oh. Restarting MOH with an active class\n");
|
|
|
|
}
|
2008-12-22 16:10:40 +00:00
|
|
|
}
|
|
|
|
|
2014-08-25 16:16:52 +00:00
|
|
|
/* Resume MOH from where we left off last time or start from scratch? */
|
|
|
|
if (state->save_total != class->total_files || strcmp(state->name, class->name) != 0) {
|
|
|
|
/* Start MOH from scratch. */
|
2014-08-25 16:45:40 +00:00
|
|
|
ao2_cleanup(state->origwfmt);
|
|
|
|
ao2_cleanup(state->mohwfmt);
|
2008-12-22 16:10:40 +00:00
|
|
|
memset(state, 0, sizeof(*state));
|
2009-02-09 14:49:24 +00:00
|
|
|
if (ast_test_flag(class, MOH_RANDOMIZE) && class->total_files) {
|
2008-12-22 16:10:40 +00:00
|
|
|
state->pos = ast_random() % class->total_files;
|
|
|
|
}
|
|
|
|
}
|
2004-12-24 01:40:07 +00:00
|
|
|
|
2009-04-09 17:30:39 +00:00
|
|
|
state->class = mohclass_ref(class, "Reffing music class for channel");
|
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
|
|
|
/* it's possible state is not a new allocation, don't leak old refs */
|
|
|
|
ao2_replace(state->origwfmt, ast_channel_writeformat(chan));
|
|
|
|
ao2_replace(state->mohwfmt, ast_channel_writeformat(chan));
|
2014-08-25 16:16:52 +00:00
|
|
|
/* For comparison on restart of MOH (see above) */
|
|
|
|
ast_copy_string(state->name, class->name, sizeof(state->name));
|
|
|
|
state->save_total = class->total_files;
|
2011-04-21 18:11:40 +00:00
|
|
|
|
2014-03-12 19:06:52 +00:00
|
|
|
moh_post_start(chan, class->name);
|
|
|
|
|
|
|
|
return state;
|
2004-12-24 01:40:07 +00:00
|
|
|
}
|
|
|
|
|
2008-12-22 16:10:40 +00:00
|
|
|
static int moh_digit_match(void *obj, void *arg, int flags)
|
2007-05-22 18:52:59 +00:00
|
|
|
{
|
2008-12-22 16:10:40 +00:00
|
|
|
char *digit = arg;
|
|
|
|
struct mohclass *class = obj;
|
2007-05-22 18:52:59 +00:00
|
|
|
|
2008-12-22 16:10:40 +00:00
|
|
|
return (*digit == class->digit) ? CMP_MATCH | CMP_STOP : 0;
|
|
|
|
}
|
2007-05-22 18:52:59 +00:00
|
|
|
|
2008-12-22 16:10:40 +00:00
|
|
|
/*! \note This function should be called with the mohclasses list locked */
|
|
|
|
static struct mohclass *get_mohbydigit(char digit)
|
|
|
|
{
|
2009-04-09 17:30:39 +00:00
|
|
|
return ao2_t_callback(mohclasses, 0, moh_digit_match, &digit, "digit callback");
|
2007-05-22 18:52:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void moh_handle_digit(struct ast_channel *chan, char digit)
|
|
|
|
{
|
2008-12-22 16:10:40 +00:00
|
|
|
struct mohclass *class;
|
2007-05-23 13:07:28 +00:00
|
|
|
const char *classname = NULL;
|
2007-05-22 18:52:59 +00:00
|
|
|
|
2008-12-22 16:10:40 +00:00
|
|
|
if ((class = get_mohbydigit(digit))) {
|
|
|
|
classname = ast_strdupa(class->name);
|
2009-04-09 17:30:39 +00:00
|
|
|
class = mohclass_unref(class, "Unreffing ao2_find from finding by digit");
|
2012-01-24 20:12:09 +00:00
|
|
|
ast_channel_musicclass_set(chan, classname);
|
2009-09-10 19:39:41 +00:00
|
|
|
ast_moh_stop(chan);
|
|
|
|
ast_moh_start(chan, classname, NULL);
|
2008-12-22 16:10:40 +00:00
|
|
|
}
|
2007-05-22 18:52:59 +00:00
|
|
|
}
|
|
|
|
|
2014-03-12 19:06:52 +00:00
|
|
|
static struct ast_generator moh_file_stream = {
|
2008-12-22 16:10:40 +00:00
|
|
|
.alloc = moh_files_alloc,
|
|
|
|
.release = moh_files_release,
|
|
|
|
.generate = moh_files_generator,
|
|
|
|
.digit = moh_handle_digit,
|
2011-04-21 18:11:40 +00:00
|
|
|
.write_format_change = moh_files_write_format_change,
|
2004-12-24 01:40:07 +00:00
|
|
|
};
|
|
|
|
|
2002-06-29 21:46:57 +00:00
|
|
|
static int spawn_mp3(struct mohclass *class)
|
|
|
|
{
|
|
|
|
int fds[2];
|
2005-06-30 18:08:27 +00:00
|
|
|
int files = 0;
|
2002-12-04 16:42:58 +00:00
|
|
|
char fns[MAX_MP3S][80];
|
2002-06-29 21:46:57 +00:00
|
|
|
char *argv[MAX_MP3S + 50];
|
|
|
|
char xargs[256];
|
|
|
|
char *argptr;
|
2004-07-02 23:11:14 +00:00
|
|
|
int argc = 0;
|
2005-06-30 18:08:27 +00:00
|
|
|
DIR *dir = NULL;
|
2002-06-29 21:46:57 +00:00
|
|
|
struct dirent *de;
|
2004-12-24 01:40:07 +00:00
|
|
|
|
|
|
|
|
2005-06-30 18:08:27 +00:00
|
|
|
if (!strcasecmp(class->dir, "nodir")) {
|
|
|
|
files = 1;
|
|
|
|
} else {
|
|
|
|
dir = opendir(class->dir);
|
2008-12-10 22:53:34 +00:00
|
|
|
if (!dir && strncasecmp(class->dir, "http://", 7)) {
|
2005-06-30 18:08:27 +00:00
|
|
|
ast_log(LOG_WARNING, "%s is not a valid directory\n", class->dir);
|
|
|
|
return -1;
|
|
|
|
}
|
2004-12-24 01:40:07 +00:00
|
|
|
}
|
2004-04-29 03:36:46 +00:00
|
|
|
|
2005-01-09 09:00:41 +00:00
|
|
|
if (!ast_test_flag(class, MOH_CUSTOM)) {
|
2004-07-17 20:12:28 +00:00
|
|
|
argv[argc++] = "mpg123";
|
|
|
|
argv[argc++] = "-q";
|
|
|
|
argv[argc++] = "-s";
|
|
|
|
argv[argc++] = "--mono";
|
|
|
|
argv[argc++] = "-r";
|
|
|
|
argv[argc++] = "8000";
|
|
|
|
|
2005-01-09 09:00:41 +00:00
|
|
|
if (!ast_test_flag(class, MOH_SINGLE)) {
|
2004-07-17 20:12:28 +00:00
|
|
|
argv[argc++] = "-b";
|
|
|
|
argv[argc++] = "2048";
|
|
|
|
}
|
2004-12-24 01:40:07 +00:00
|
|
|
|
2004-07-17 20:12:28 +00:00
|
|
|
argv[argc++] = "-f";
|
2004-12-24 01:40:07 +00:00
|
|
|
|
2005-01-09 09:00:41 +00:00
|
|
|
if (ast_test_flag(class, MOH_QUIET))
|
2004-07-17 20:12:28 +00:00
|
|
|
argv[argc++] = "4096";
|
|
|
|
else
|
|
|
|
argv[argc++] = "8192";
|
2004-12-24 01:40:07 +00:00
|
|
|
|
2004-07-17 20:12:28 +00:00
|
|
|
/* Look for extra arguments and add them to the list */
|
2006-04-21 18:26:54 +00:00
|
|
|
ast_copy_string(xargs, class->args, sizeof(xargs));
|
2004-07-17 20:12:28 +00:00
|
|
|
argptr = xargs;
|
2005-11-08 01:55:31 +00:00
|
|
|
while (!ast_strlen_zero(argptr)) {
|
2004-07-17 20:12:28 +00:00
|
|
|
argv[argc++] = argptr;
|
2006-04-21 18:26:54 +00:00
|
|
|
strsep(&argptr, ",");
|
2004-07-17 20:12:28 +00:00
|
|
|
}
|
2004-12-24 01:40:07 +00:00
|
|
|
} else {
|
2004-07-17 20:12:28 +00:00
|
|
|
/* Format arguments for argv vector */
|
2006-04-21 18:26:54 +00:00
|
|
|
ast_copy_string(xargs, class->args, sizeof(xargs));
|
2004-07-17 20:12:28 +00:00
|
|
|
argptr = xargs;
|
2005-11-08 01:55:31 +00:00
|
|
|
while (!ast_strlen_zero(argptr)) {
|
2004-07-17 20:12:28 +00:00
|
|
|
argv[argc++] = argptr;
|
2006-04-21 18:26:54 +00:00
|
|
|
strsep(&argptr, " ");
|
2002-06-29 21:46:57 +00:00
|
|
|
}
|
|
|
|
}
|
2004-07-02 22:40:09 +00:00
|
|
|
|
2008-12-10 22:11:46 +00:00
|
|
|
if (!strncasecmp(class->dir, "http://", 7)) {
|
2006-04-21 18:26:54 +00:00
|
|
|
ast_copy_string(fns[files], class->dir, sizeof(fns[files]));
|
2004-09-04 05:41:01 +00:00
|
|
|
argv[argc++] = fns[files];
|
|
|
|
files++;
|
2005-06-30 18:08:27 +00:00
|
|
|
} else if (dir) {
|
2005-01-09 09:00:41 +00:00
|
|
|
while ((de = readdir(dir)) && (files < MAX_MP3S)) {
|
2004-12-24 01:40:07 +00:00
|
|
|
if ((strlen(de->d_name) > 3) &&
|
2005-01-09 09:00:41 +00:00
|
|
|
((ast_test_flag(class, MOH_CUSTOM) &&
|
|
|
|
(!strcasecmp(de->d_name + strlen(de->d_name) - 4, ".raw") ||
|
|
|
|
!strcasecmp(de->d_name + strlen(de->d_name) - 4, ".sln"))) ||
|
|
|
|
!strcasecmp(de->d_name + strlen(de->d_name) - 4, ".mp3"))) {
|
2006-04-21 18:26:54 +00:00
|
|
|
ast_copy_string(fns[files], de->d_name, sizeof(fns[files]));
|
2004-09-04 05:41:01 +00:00
|
|
|
argv[argc++] = fns[files];
|
|
|
|
files++;
|
|
|
|
}
|
2004-07-02 23:11:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
argv[argc] = NULL;
|
2005-06-30 18:08:27 +00:00
|
|
|
if (dir) {
|
|
|
|
closedir(dir);
|
|
|
|
}
|
2004-07-02 23:11:14 +00:00
|
|
|
if (pipe(fds)) {
|
|
|
|
ast_log(LOG_WARNING, "Pipe failed\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (!files) {
|
2002-06-29 21:46:57 +00:00
|
|
|
ast_log(LOG_WARNING, "Found no files in '%s'\n", class->dir);
|
2003-11-04 23:23:00 +00:00
|
|
|
close(fds[0]);
|
|
|
|
close(fds[1]);
|
2002-06-29 21:46:57 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2008-12-10 22:11:46 +00:00
|
|
|
if (!strncasecmp(class->dir, "http://", 7) && time(NULL) - class->start < respawn_time) {
|
2004-09-04 05:41:01 +00:00
|
|
|
sleep(respawn_time - (time(NULL) - class->start));
|
|
|
|
}
|
2006-12-11 00:52:19 +00:00
|
|
|
|
2004-09-04 05:41:01 +00:00
|
|
|
time(&class->start);
|
2008-04-16 22:57:54 +00:00
|
|
|
class->pid = ast_safe_fork(0);
|
2002-06-29 21:46:57 +00:00
|
|
|
if (class->pid < 0) {
|
|
|
|
close(fds[0]);
|
|
|
|
close(fds[1]);
|
|
|
|
ast_log(LOG_WARNING, "Fork failed: %s\n", strerror(errno));
|
|
|
|
return -1;
|
|
|
|
}
|
2005-07-12 18:57:20 +00:00
|
|
|
if (!class->pid) {
|
2006-05-01 21:48:30 +00:00
|
|
|
if (ast_opt_high_priority)
|
|
|
|
ast_set_priority(0);
|
|
|
|
|
2005-07-12 18:57:20 +00:00
|
|
|
close(fds[0]);
|
|
|
|
/* Stdout goes to pipe */
|
|
|
|
dup2(fds[1], STDOUT_FILENO);
|
2008-04-16 22:57:54 +00:00
|
|
|
|
|
|
|
/* Close everything else */
|
|
|
|
ast_close_fds_above_n(STDERR_FILENO);
|
|
|
|
|
2005-07-12 18:57:20 +00:00
|
|
|
/* Child */
|
2010-03-05 01:05:46 +00:00
|
|
|
if (strncasecmp(class->dir, "http://", 7) && strcasecmp(class->dir, "nodir") && chdir(class->dir) < 0) {
|
2008-11-02 18:52:13 +00:00
|
|
|
ast_log(LOG_WARNING, "chdir() failed: %s\n", strerror(errno));
|
|
|
|
_exit(1);
|
|
|
|
}
|
2008-12-18 18:54:47 +00:00
|
|
|
setpgid(0, getpid());
|
2005-01-09 09:00:41 +00:00
|
|
|
if (ast_test_flag(class, MOH_CUSTOM)) {
|
2004-07-17 20:12:28 +00:00
|
|
|
execv(argv[0], argv);
|
2005-01-09 09:00:41 +00:00
|
|
|
} else {
|
|
|
|
/* Default install is /usr/local/bin */
|
|
|
|
execv(LOCAL_MPG_123, argv);
|
|
|
|
/* Many places have it in /usr/bin */
|
|
|
|
execv(MPG_123, argv);
|
|
|
|
/* Check PATH as a last-ditch effort */
|
|
|
|
execvp("mpg123", argv);
|
|
|
|
}
|
2008-04-16 22:57:54 +00:00
|
|
|
/* Can't use logger, since log FDs are closed */
|
|
|
|
fprintf(stderr, "MOH: exec failed: %s\n", strerror(errno));
|
2005-07-12 18:57:20 +00:00
|
|
|
close(fds[1]);
|
2006-10-27 17:42:57 +00:00
|
|
|
_exit(1);
|
2005-07-12 18:57:20 +00:00
|
|
|
} else {
|
|
|
|
/* Parent */
|
|
|
|
close(fds[1]);
|
2002-06-29 21:46:57 +00:00
|
|
|
}
|
2005-07-12 18:57:20 +00:00
|
|
|
return fds[0];
|
2002-06-29 21:46:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void *monmp3thread(void *data)
|
|
|
|
{
|
2003-07-27 03:53:19 +00:00
|
|
|
#define MOH_MS_INTERVAL 100
|
|
|
|
|
2002-06-29 21:46:57 +00:00
|
|
|
struct mohclass *class = data;
|
|
|
|
struct mohdata *moh;
|
|
|
|
short sbuf[8192];
|
2010-08-26 23:51:55 +00:00
|
|
|
int res = 0, res2;
|
2005-08-22 19:29:29 +00:00
|
|
|
int len;
|
2008-08-10 00:47:56 +00:00
|
|
|
struct timeval deadline, tv_tmp;
|
2003-07-27 03:53:19 +00:00
|
|
|
|
2008-08-10 00:47:56 +00:00
|
|
|
deadline.tv_sec = 0;
|
|
|
|
deadline.tv_usec = 0;
|
2002-06-29 21:46:57 +00:00
|
|
|
for(;/* ever */;) {
|
2006-04-17 17:17:41 +00:00
|
|
|
pthread_testcancel();
|
2002-06-29 21:46:57 +00:00
|
|
|
/* Spawn mp3 player if it's not there */
|
2004-06-29 04:42:19 +00:00
|
|
|
if (class->srcfd < 0) {
|
2002-06-29 21:46:57 +00:00
|
|
|
if ((class->srcfd = spawn_mp3(class)) < 0) {
|
2005-08-25 23:29:30 +00:00
|
|
|
ast_log(LOG_WARNING, "Unable to spawn mp3player\n");
|
2002-06-29 21:46:57 +00:00
|
|
|
/* Try again later */
|
|
|
|
sleep(500);
|
2012-04-17 21:14:49 +00:00
|
|
|
continue;
|
2002-06-29 21:46:57 +00:00
|
|
|
}
|
|
|
|
}
|
2010-08-26 23:51:55 +00:00
|
|
|
if (class->timer) {
|
Fix timing source dependency issues with MOH
Prior to this patch, res_musiconhold existed at the same module priority level
as the timing sources that it depends on. This would cause a problem when
music on hold was reloaded, as the timing source could be changed after
res_musiconhold was processed. This patch adds a new module priority level,
AST_MODPRI_TIMING, that the various timing modules are now loaded at. This
now occurs before loading other resource modules, such that the timing source
is guaranteed to be set prior to resolving the timing source dependencies.
(closes issue ASTERISK-17474)
Reporter: Luke H
Tested by: Luke H, Vladimir Mikhelson, zzsurf, Wes Van Tlghem, elguero, Thomas Arimont
Patches:
asterisk-17474-dahdi_timing-infinite-wait-fix_v3_branch-1.8.diff uploaded by elguero (License #5026)
asterisk-17474-dahdi_timing-infinite-wait-fix_v3_branch-10.diff uploaded by elguero (License #5026)
asterisk-17474-dahdi_timing-infinite-wait-fix_v3.diff uploaded by elguero (License #5026)
Review: https://reviewboard.asterisk.org/r/1578/
........
Merged revisions 349194 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........
Merged revisions 349195 from http://svn.asterisk.org/svn/asterisk/branches/10
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@349196 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2011-12-27 20:55:15 +00:00
|
|
|
struct pollfd pfd = { .fd = ast_timer_fd(class->timer), .events = POLLIN | POLLPRI, };
|
2010-08-26 23:51:55 +00:00
|
|
|
|
2007-01-23 01:47:55 +00:00
|
|
|
#ifdef SOLARIS
|
|
|
|
thr_yield();
|
|
|
|
#endif
|
2002-06-29 21:46:57 +00:00
|
|
|
/* Pause some amount of time */
|
2010-08-26 23:51:55 +00:00
|
|
|
if (ast_poll(&pfd, 1, -1) > 0) {
|
2012-11-05 23:10:14 +00:00
|
|
|
if (ast_timer_ack(class->timer, 1) < 0) {
|
|
|
|
ast_log(LOG_ERROR, "Failed to acknowledge timer for mp3player\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-01-17 14:17:04 +00:00
|
|
|
/* 25 samples per second => 40ms framerate => 320 samples */
|
|
|
|
res = 320; /* 320/40 = 8 samples/ms */
|
2010-08-26 23:51:55 +00:00
|
|
|
} else {
|
Fix timing source dependency issues with MOH
Prior to this patch, res_musiconhold existed at the same module priority level
as the timing sources that it depends on. This would cause a problem when
music on hold was reloaded, as the timing source could be changed after
res_musiconhold was processed. This patch adds a new module priority level,
AST_MODPRI_TIMING, that the various timing modules are now loaded at. This
now occurs before loading other resource modules, such that the timing source
is guaranteed to be set prior to resolving the timing source dependencies.
(closes issue ASTERISK-17474)
Reporter: Luke H
Tested by: Luke H, Vladimir Mikhelson, zzsurf, Wes Van Tlghem, elguero, Thomas Arimont
Patches:
asterisk-17474-dahdi_timing-infinite-wait-fix_v3_branch-1.8.diff uploaded by elguero (License #5026)
asterisk-17474-dahdi_timing-infinite-wait-fix_v3_branch-10.diff uploaded by elguero (License #5026)
asterisk-17474-dahdi_timing-infinite-wait-fix_v3.diff uploaded by elguero (License #5026)
Review: https://reviewboard.asterisk.org/r/1578/
........
Merged revisions 349194 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........
Merged revisions 349195 from http://svn.asterisk.org/svn/asterisk/branches/10
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@349196 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2011-12-27 20:55:15 +00:00
|
|
|
ast_log(LOG_WARNING, "poll() failed: %s\n", strerror(errno));
|
2010-08-26 23:51:55 +00:00
|
|
|
res = 0;
|
|
|
|
}
|
2006-04-17 17:17:41 +00:00
|
|
|
pthread_testcancel();
|
2002-06-29 21:46:57 +00:00
|
|
|
} else {
|
2005-07-15 23:00:47 +00:00
|
|
|
long delta;
|
2003-07-27 03:53:19 +00:00
|
|
|
/* Reliable sleep */
|
2005-07-15 23:00:47 +00:00
|
|
|
tv_tmp = ast_tvnow();
|
2008-08-10 00:47:56 +00:00
|
|
|
if (ast_tvzero(deadline))
|
|
|
|
deadline = tv_tmp;
|
|
|
|
delta = ast_tvdiff_ms(tv_tmp, deadline);
|
2005-07-15 23:00:47 +00:00
|
|
|
if (delta < MOH_MS_INTERVAL) { /* too early */
|
2008-08-10 00:47:56 +00:00
|
|
|
deadline = ast_tvadd(deadline, ast_samp2tv(MOH_MS_INTERVAL, 1000)); /* next deadline */
|
2005-07-15 23:00:47 +00:00
|
|
|
usleep(1000 * (MOH_MS_INTERVAL - delta));
|
2006-04-17 17:17:41 +00:00
|
|
|
pthread_testcancel();
|
2003-07-27 03:53:19 +00:00
|
|
|
} else {
|
|
|
|
ast_log(LOG_NOTICE, "Request to schedule in the past?!?!\n");
|
2008-08-10 00:47:56 +00:00
|
|
|
deadline = tv_tmp;
|
2003-07-27 03:53:19 +00:00
|
|
|
}
|
2014-01-17 14:17:04 +00:00
|
|
|
/* 10 samples per second (MOH_MS_INTERVAL) => 100ms framerate => 800 samples */
|
|
|
|
res = 8 * MOH_MS_INTERVAL; /* 800/100 = 8 samples/ms */
|
2002-06-29 21:46:57 +00:00
|
|
|
}
|
2014-01-17 14:17:04 +00:00
|
|
|
/* For non-8000Hz formats, we need to alter the resolution */
|
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
|
|
|
res = res * ast_format_get_sample_rate(class->format) / 8000;
|
2014-01-17 14:17:04 +00:00
|
|
|
|
2009-03-12 16:56:58 +00:00
|
|
|
if ((strncasecmp(class->dir, "http://", 7) && strcasecmp(class->dir, "nodir")) && AST_LIST_EMPTY(&class->members))
|
2002-06-29 21:46:57 +00:00
|
|
|
continue;
|
|
|
|
/* Read mp3 audio */
|
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
|
|
|
len = ast_format_determine_length(class->format, res);
|
2009-03-12 16:32:20 +00:00
|
|
|
|
2005-08-22 19:29:29 +00:00
|
|
|
if ((res2 = read(class->srcfd, sbuf, len)) != len) {
|
2002-06-29 21:46:57 +00:00
|
|
|
if (!res2) {
|
|
|
|
close(class->srcfd);
|
|
|
|
class->srcfd = -1;
|
2006-04-17 17:17:41 +00:00
|
|
|
pthread_testcancel();
|
2006-09-19 21:07:49 +00:00
|
|
|
if (class->pid > 1) {
|
2009-12-03 00:08:55 +00:00
|
|
|
do {
|
|
|
|
if (killpg(class->pid, SIGHUP) < 0) {
|
2009-12-10 18:56:23 +00:00
|
|
|
if (errno == ESRCH) {
|
|
|
|
break;
|
|
|
|
}
|
2009-12-03 00:08:55 +00:00
|
|
|
ast_log(LOG_WARNING, "Unable to send a SIGHUP to MOH process?!!: %s\n", strerror(errno));
|
|
|
|
}
|
|
|
|
usleep(100000);
|
|
|
|
if (killpg(class->pid, SIGTERM) < 0) {
|
|
|
|
if (errno == ESRCH) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ast_log(LOG_WARNING, "Unable to terminate MOH process?!!: %s\n", strerror(errno));
|
|
|
|
}
|
|
|
|
usleep(100000);
|
|
|
|
if (killpg(class->pid, SIGKILL) < 0) {
|
|
|
|
if (errno == ESRCH) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ast_log(LOG_WARNING, "Unable to kill MOH process?!!: %s\n", strerror(errno));
|
|
|
|
}
|
|
|
|
} while (0);
|
2002-06-29 21:46:57 +00:00
|
|
|
class->pid = 0;
|
|
|
|
}
|
2006-10-03 15:53:07 +00:00
|
|
|
} else {
|
2007-06-14 19:39:12 +00:00
|
|
|
ast_debug(1, "Read %d bytes of audio while expecting %d\n", res2, len);
|
2006-10-03 15:53:07 +00:00
|
|
|
}
|
2002-06-29 21:46:57 +00:00
|
|
|
continue;
|
|
|
|
}
|
2008-12-22 16:10:40 +00:00
|
|
|
|
2006-04-17 17:17:41 +00:00
|
|
|
pthread_testcancel();
|
2008-12-22 16:10:40 +00:00
|
|
|
|
|
|
|
ao2_lock(class);
|
|
|
|
AST_LIST_TRAVERSE(&class->members, moh, list) {
|
2002-06-29 21:46:57 +00:00
|
|
|
/* Write data */
|
2006-04-29 13:15:05 +00:00
|
|
|
if ((res = write(moh->pipe[1], sbuf, res2)) != res2) {
|
2007-06-14 19:39:12 +00:00
|
|
|
ast_debug(1, "Only wrote %d of %d bytes to pipe\n", res, res2);
|
2006-04-29 13:15:05 +00:00
|
|
|
}
|
2002-06-29 21:46:57 +00:00
|
|
|
}
|
2008-12-22 16:10:40 +00:00
|
|
|
ao2_unlock(class);
|
2002-06-29 21:46:57 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static int play_moh_exec(struct ast_channel *chan, const char *data)
|
2002-06-29 21:46:57 +00:00
|
|
|
{
|
2008-02-13 15:47:25 +00:00
|
|
|
char *parse;
|
|
|
|
char *class;
|
|
|
|
int timeout = -1;
|
|
|
|
int res;
|
|
|
|
AST_DECLARE_APP_ARGS(args,
|
|
|
|
AST_APP_ARG(class);
|
|
|
|
AST_APP_ARG(duration);
|
|
|
|
);
|
|
|
|
|
|
|
|
parse = ast_strdupa(data);
|
|
|
|
|
|
|
|
AST_STANDARD_APP_ARGS(args, parse);
|
|
|
|
|
|
|
|
if (!ast_strlen_zero(args.duration)) {
|
2009-08-10 19:20:57 +00:00
|
|
|
if (sscanf(args.duration, "%30d", &timeout) == 1) {
|
2008-02-13 15:47:25 +00:00
|
|
|
timeout *= 1000;
|
|
|
|
} else {
|
|
|
|
ast_log(LOG_WARNING, "Invalid MusicOnHold duration '%s'. Will wait indefinitely.\n", args.duration);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class = S_OR(args.class, NULL);
|
|
|
|
if (ast_moh_start(chan, class, NULL)) {
|
2012-01-09 22:15:50 +00:00
|
|
|
ast_log(LOG_WARNING, "Unable to start music on hold class '%s' on channel %s\n", class, ast_channel_name(chan));
|
2007-07-09 20:54:34 +00:00
|
|
|
return 0;
|
2002-06-29 21:46:57 +00:00
|
|
|
}
|
2008-02-13 15:47:25 +00:00
|
|
|
|
|
|
|
if (timeout > 0)
|
|
|
|
res = ast_safe_sleep(chan, timeout);
|
|
|
|
else {
|
|
|
|
while (!(res = ast_safe_sleep(chan, 10000)));
|
|
|
|
}
|
|
|
|
|
2005-01-06 04:18:15 +00:00
|
|
|
ast_moh_stop(chan);
|
2008-02-13 15:47:25 +00:00
|
|
|
|
|
|
|
return res;
|
2002-06-29 21:46:57 +00:00
|
|
|
}
|
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static int start_moh_exec(struct ast_channel *chan, const char *data)
|
2005-03-03 05:03:06 +00:00
|
|
|
{
|
2008-02-13 15:47:25 +00:00
|
|
|
char *parse;
|
|
|
|
char *class;
|
|
|
|
AST_DECLARE_APP_ARGS(args,
|
|
|
|
AST_APP_ARG(class);
|
|
|
|
);
|
|
|
|
|
|
|
|
parse = ast_strdupa(data);
|
|
|
|
|
|
|
|
AST_STANDARD_APP_ARGS(args, parse);
|
|
|
|
|
|
|
|
class = S_OR(args.class, NULL);
|
2006-07-19 20:44:39 +00:00
|
|
|
if (ast_moh_start(chan, class, NULL))
|
2012-01-09 22:15:50 +00:00
|
|
|
ast_log(LOG_WARNING, "Unable to start music on hold class '%s' on channel %s\n", class, ast_channel_name(chan));
|
2005-03-03 05:03:06 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static int stop_moh_exec(struct ast_channel *chan, const char *data)
|
2005-03-03 05:03:06 +00:00
|
|
|
{
|
|
|
|
ast_moh_stop(chan);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-12-03 00:08:55 +00:00
|
|
|
#define get_mohbyname(a,b,c) _get_mohbyname(a,b,c,__FILE__,__LINE__,__PRETTY_FUNCTION__)
|
|
|
|
|
|
|
|
static struct mohclass *_get_mohbyname(const char *name, int warn, int flags, const char *file, int lineno, const char *funcname)
|
2002-06-29 21:46:57 +00:00
|
|
|
{
|
2006-04-29 13:15:05 +00:00
|
|
|
struct mohclass *moh = NULL;
|
2008-12-22 16:10:40 +00:00
|
|
|
struct mohclass tmp_class = {
|
|
|
|
.flags = 0,
|
|
|
|
};
|
2006-04-29 13:15:05 +00:00
|
|
|
|
2008-12-22 16:10:40 +00:00
|
|
|
ast_copy_string(tmp_class.name, name, sizeof(tmp_class.name));
|
2006-04-29 13:15:05 +00:00
|
|
|
|
2015-04-17 07:16:59 +00:00
|
|
|
moh = __ao2_find(mohclasses, &tmp_class, flags,
|
2012-02-28 20:34:11 +00:00
|
|
|
"get_mohbyname", file, lineno, funcname);
|
2008-12-22 16:10:40 +00:00
|
|
|
|
|
|
|
if (!moh && warn) {
|
2015-07-16 14:13:10 +00:00
|
|
|
ast_log(LOG_WARNING, "Music on Hold class '%s' not found in memory. Verify your configuration.\n", name);
|
2008-12-22 16:10:40 +00:00
|
|
|
}
|
2007-07-09 20:54:34 +00:00
|
|
|
|
2006-04-29 13:15:05 +00:00
|
|
|
return moh;
|
2002-06-29 21:46:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct mohdata *mohalloc(struct mohclass *cl)
|
|
|
|
{
|
|
|
|
struct mohdata *moh;
|
2011-02-04 16:55:39 +00:00
|
|
|
long flags;
|
|
|
|
|
2006-01-21 22:09:06 +00:00
|
|
|
if (!(moh = ast_calloc(1, sizeof(*moh))))
|
2002-06-29 21:46:57 +00:00
|
|
|
return NULL;
|
2011-02-04 16:55:39 +00:00
|
|
|
|
2002-06-29 21:46:57 +00:00
|
|
|
if (pipe(moh->pipe)) {
|
|
|
|
ast_log(LOG_WARNING, "Failed to create pipe: %s\n", strerror(errno));
|
2007-06-06 21:20:11 +00:00
|
|
|
ast_free(moh);
|
2002-06-29 21:46:57 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2006-04-29 13:15:05 +00:00
|
|
|
|
2002-06-29 21:46:57 +00:00
|
|
|
/* Make entirely non-blocking */
|
|
|
|
flags = fcntl(moh->pipe[0], F_GETFL);
|
|
|
|
fcntl(moh->pipe[0], F_SETFL, flags | O_NONBLOCK);
|
|
|
|
flags = fcntl(moh->pipe[1], F_GETFL);
|
|
|
|
fcntl(moh->pipe[1], F_SETFL, flags | O_NONBLOCK);
|
2006-04-29 13:15:05 +00:00
|
|
|
|
|
|
|
moh->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
|
|
|
moh->f.subclass.format = cl->format;
|
2006-04-29 13:15:05 +00:00
|
|
|
moh->f.offset = AST_FRIENDLY_OFFSET;
|
|
|
|
|
2009-04-09 17:30:39 +00:00
|
|
|
moh->parent = mohclass_ref(cl, "Reffing music class for mohdata parent");
|
2007-07-13 20:14:23 +00:00
|
|
|
|
2008-12-22 16:10:40 +00:00
|
|
|
ao2_lock(cl);
|
2006-04-29 13:15:05 +00:00
|
|
|
AST_LIST_INSERT_HEAD(&cl->members, moh, list);
|
2008-12-22 16:10:40 +00:00
|
|
|
ao2_unlock(cl);
|
2006-04-29 13:15:05 +00:00
|
|
|
|
2002-06-29 21:46:57 +00:00
|
|
|
return moh;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void moh_release(struct ast_channel *chan, void *data)
|
|
|
|
{
|
2006-04-29 13:15:05 +00:00
|
|
|
struct mohdata *moh = data;
|
2008-12-22 16:10:40 +00:00
|
|
|
struct mohclass *class = moh->parent;
|
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 *oldwfmt;
|
2006-04-29 13:15:05 +00:00
|
|
|
|
2008-12-22 16:10:40 +00:00
|
|
|
ao2_lock(class);
|
|
|
|
AST_LIST_REMOVE(&moh->parent->members, moh, list);
|
|
|
|
ao2_unlock(class);
|
2006-04-29 13:15:05 +00:00
|
|
|
|
2002-06-29 21:46:57 +00:00
|
|
|
close(moh->pipe[0]);
|
|
|
|
close(moh->pipe[1]);
|
2008-12-22 16:10:40 +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
|
|
|
oldwfmt = moh->origwfmt;
|
2008-12-22 16:10:40 +00:00
|
|
|
|
2009-04-09 17:30:39 +00:00
|
|
|
moh->parent = class = mohclass_unref(class, "unreffing moh->parent upon deactivation of generator");
|
Adding support for realtime music on hold. The following are the main points:
1. When moh is started, we search first in memory to find the class. If we do not
find it in memory, we search realtime instead.
2. When moh is restarted (as in, it had been started on this particular channel, stopped,
and now we're starting it again), if using the "files" mode, then realtime will always
be rechecked. If you are using other modes, however, we will simply reattach to the external
running process which was playing moh earlier in the call. This is a necessary compromise so that
we don't end up with too many background processes.
3. musiconhold.conf has a general section now. It has one option: cachertclasses. If set to yes,
then moh classes found in realtime will be added to the in-memory list. This has the advantage
of not requiring database lookups each time moh is started, but it has the disadvantage of not
truly being realtime.
I have tested this for functionality, and it passes. I also tested this under valgrind and there
are no memory problems reported under typical use.
Special thanks to Sergee for implementing this feature and enduring my complaints on the bugtracker!
(closes issue #11196, reported and patched by sergee)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89946 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-28 00:47:22 +00:00
|
|
|
|
2007-06-06 21:20:11 +00:00
|
|
|
ast_free(moh);
|
2008-12-22 16:10:40 +00:00
|
|
|
|
2002-06-29 21:46:57 +00:00
|
|
|
if (chan) {
|
2011-09-02 21:09:31 +00:00
|
|
|
struct moh_files_state *state;
|
|
|
|
|
2012-02-20 23:43:27 +00:00
|
|
|
state = ast_channel_music_state(chan);
|
2011-09-02 21:09:31 +00:00
|
|
|
if (state && state->class) {
|
|
|
|
state->class = mohclass_unref(state->class, "Unreffing channel's music class upon deactivation of generator");
|
|
|
|
}
|
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 (oldwfmt && ast_set_write_format(chan, oldwfmt)) {
|
2008-12-22 16:10:40 +00:00
|
|
|
ast_log(LOG_WARNING, "Unable to restore channel '%s' to format %s\n",
|
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_channel_name(chan), ast_format_get_name(oldwfmt));
|
2008-12-22 16:10:40 +00:00
|
|
|
}
|
|
|
|
|
2014-03-12 19:06:52 +00:00
|
|
|
moh_post_stop(chan);
|
2002-06-29 21:46:57 +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(oldwfmt);
|
2002-06-29 21:46:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void *moh_alloc(struct ast_channel *chan, void *params)
|
|
|
|
{
|
|
|
|
struct mohdata *res;
|
2005-08-22 19:29:29 +00:00
|
|
|
struct mohclass *class = params;
|
Adding support for realtime music on hold. The following are the main points:
1. When moh is started, we search first in memory to find the class. If we do not
find it in memory, we search realtime instead.
2. When moh is restarted (as in, it had been started on this particular channel, stopped,
and now we're starting it again), if using the "files" mode, then realtime will always
be rechecked. If you are using other modes, however, we will simply reattach to the external
running process which was playing moh earlier in the call. This is a necessary compromise so that
we don't end up with too many background processes.
3. musiconhold.conf has a general section now. It has one option: cachertclasses. If set to yes,
then moh classes found in realtime will be added to the in-memory list. This has the advantage
of not requiring database lookups each time moh is started, but it has the disadvantage of not
truly being realtime.
I have tested this for functionality, and it passes. I also tested this under valgrind and there
are no memory problems reported under typical use.
Special thanks to Sergee for implementing this feature and enduring my complaints on the bugtracker!
(closes issue #11196, reported and patched by sergee)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89946 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-28 00:47:22 +00:00
|
|
|
struct moh_files_state *state;
|
|
|
|
|
|
|
|
/* Initiating music_state for current channel. Channel should know name of moh class */
|
2014-03-12 19:06:52 +00:00
|
|
|
state = ast_channel_music_state(chan);
|
|
|
|
if (!state && (state = ast_calloc(1, sizeof(*state)))) {
|
2012-02-20 23:43:27 +00:00
|
|
|
ast_channel_music_state_set(chan, state);
|
2009-12-08 18:22:44 +00:00
|
|
|
ast_module_ref(ast_module_info->self);
|
2011-09-02 21:09:31 +00:00
|
|
|
} else {
|
|
|
|
if (!state) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (state->class) {
|
|
|
|
mohclass_unref(state->class, "Uh Oh. Restarting MOH with an active class");
|
|
|
|
ast_log(LOG_WARNING, "Uh Oh. Restarting MOH with an active class\n");
|
|
|
|
}
|
2014-08-25 16:45:40 +00:00
|
|
|
ao2_cleanup(state->origwfmt);
|
|
|
|
ao2_cleanup(state->mohwfmt);
|
Adding support for realtime music on hold. The following are the main points:
1. When moh is started, we search first in memory to find the class. If we do not
find it in memory, we search realtime instead.
2. When moh is restarted (as in, it had been started on this particular channel, stopped,
and now we're starting it again), if using the "files" mode, then realtime will always
be rechecked. If you are using other modes, however, we will simply reattach to the external
running process which was playing moh earlier in the call. This is a necessary compromise so that
we don't end up with too many background processes.
3. musiconhold.conf has a general section now. It has one option: cachertclasses. If set to yes,
then moh classes found in realtime will be added to the in-memory list. This has the advantage
of not requiring database lookups each time moh is started, but it has the disadvantage of not
truly being realtime.
I have tested this for functionality, and it passes. I also tested this under valgrind and there
are no memory problems reported under typical use.
Special thanks to Sergee for implementing this feature and enduring my complaints on the bugtracker!
(closes issue #11196, reported and patched by sergee)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89946 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-28 00:47:22 +00:00
|
|
|
memset(state, 0, sizeof(*state));
|
|
|
|
}
|
2005-01-09 09:00:41 +00:00
|
|
|
|
2006-01-21 22:09:06 +00:00
|
|
|
if ((res = mohalloc(class))) {
|
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
|
|
|
res->origwfmt = ao2_bump(ast_channel_writeformat(chan));
|
|
|
|
if (ast_set_write_format(chan, class->format)) {
|
|
|
|
ast_log(LOG_WARNING, "Unable to set channel '%s' to format '%s'\n", ast_channel_name(chan),
|
|
|
|
ast_format_get_name(class->format));
|
2002-06-29 21:46:57 +00:00
|
|
|
moh_release(NULL, res);
|
|
|
|
res = NULL;
|
2011-09-02 21:09:31 +00:00
|
|
|
} else {
|
|
|
|
state->class = mohclass_ref(class, "Placing reference into state container");
|
2014-03-12 19:06:52 +00:00
|
|
|
moh_post_start(chan, class->name);
|
2002-06-29 21:46:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2002-12-04 16:42:58 +00:00
|
|
|
static int moh_generate(struct ast_channel *chan, void *data, int len, int samples)
|
2002-06-29 21:46:57 +00:00
|
|
|
{
|
|
|
|
struct mohdata *moh = data;
|
2003-07-27 03:53:19 +00:00
|
|
|
short buf[1280 + AST_FRIENDLY_OFFSET / 2];
|
2002-06-29 21:46:57 +00:00
|
|
|
int res;
|
2005-01-09 09:00:41 +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
|
|
|
len = ast_format_determine_length(moh->parent->format, samples);
|
2005-08-22 19:29:29 +00:00
|
|
|
|
2003-07-27 03:53:19 +00:00
|
|
|
if (len > sizeof(buf) - AST_FRIENDLY_OFFSET) {
|
2012-01-09 22:15:50 +00:00
|
|
|
ast_log(LOG_WARNING, "Only doing %d of %d requested bytes on %s\n", (int)sizeof(buf), len, ast_channel_name(chan));
|
2003-07-27 03:53:19 +00:00
|
|
|
len = sizeof(buf) - AST_FRIENDLY_OFFSET;
|
2002-06-29 21:46:57 +00:00
|
|
|
}
|
|
|
|
res = read(moh->pipe[0], buf + AST_FRIENDLY_OFFSET/2, len);
|
2005-01-09 09:00:41 +00:00
|
|
|
if (res <= 0)
|
|
|
|
return 0;
|
|
|
|
|
2006-04-29 13:15:05 +00:00
|
|
|
moh->f.datalen = res;
|
2008-05-22 16:29:54 +00:00
|
|
|
moh->f.data.ptr = buf + AST_FRIENDLY_OFFSET / 2;
|
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
|
|
|
moh->f.samples = ast_codec_samples_count(&moh->f);
|
2006-04-29 13:15:05 +00:00
|
|
|
|
|
|
|
if (ast_write(chan, &moh->f) < 0) {
|
2012-01-09 22:15:50 +00:00
|
|
|
ast_log(LOG_WARNING, "Failed to write frame to '%s': %s\n", ast_channel_name(chan), strerror(errno));
|
2005-01-09 09:00:41 +00:00
|
|
|
return -1;
|
2002-06-29 21:46:57 +00:00
|
|
|
}
|
2005-08-22 19:29:29 +00:00
|
|
|
|
2002-06-29 21:46:57 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-12-22 16:10:40 +00:00
|
|
|
static struct ast_generator mohgen = {
|
|
|
|
.alloc = moh_alloc,
|
|
|
|
.release = moh_release,
|
|
|
|
.generate = moh_generate,
|
2008-12-22 21:45:28 +00:00
|
|
|
.digit = moh_handle_digit,
|
2002-06-29 21:46:57 +00:00
|
|
|
};
|
|
|
|
|
2014-09-14 15:41:58 +00:00
|
|
|
static void moh_parse_options(struct ast_variable *var, struct mohclass *mohclass)
|
|
|
|
{
|
|
|
|
for (; var; var = var->next) {
|
|
|
|
if (!strcasecmp(var->name, "name")) {
|
|
|
|
ast_copy_string(mohclass->name, var->value, sizeof(mohclass->name));
|
|
|
|
} else if (!strcasecmp(var->name, "mode")) {
|
|
|
|
ast_copy_string(mohclass->mode, var->value, sizeof(mohclass->mode));
|
|
|
|
} else if (!strcasecmp(var->name, "directory")) {
|
|
|
|
ast_copy_string(mohclass->dir, var->value, sizeof(mohclass->dir));
|
|
|
|
} else if (!strcasecmp(var->name, "application")) {
|
|
|
|
ast_copy_string(mohclass->args, var->value, sizeof(mohclass->args));
|
|
|
|
} else if (!strcasecmp(var->name, "digit") && (isdigit(*var->value) || strchr("*#", *var->value))) {
|
|
|
|
mohclass->digit = *var->value;
|
|
|
|
} else if (!strcasecmp(var->name, "random")) {
|
|
|
|
static int deprecation_warning = 0;
|
|
|
|
if (!deprecation_warning) {
|
|
|
|
ast_log(LOG_WARNING, "Music on hold 'random' setting is deprecated in 14. Please use 'sort=random' instead.\n");
|
|
|
|
deprecation_warning = 1;
|
|
|
|
}
|
|
|
|
ast_set2_flag(mohclass, ast_true(var->value), MOH_RANDOMIZE);
|
|
|
|
} else if (!strcasecmp(var->name, "sort")) {
|
|
|
|
if (!strcasecmp(var->value, "random")) {
|
|
|
|
ast_set_flag(mohclass, MOH_RANDOMIZE);
|
|
|
|
} else if (!strcasecmp(var->value, "alpha")) {
|
|
|
|
ast_set_flag(mohclass, MOH_SORTALPHA);
|
|
|
|
} else if (!strcasecmp(var->value, "randstart")) {
|
|
|
|
ast_set_flag(mohclass, MOH_RANDSTART);
|
|
|
|
}
|
|
|
|
} else if (!strcasecmp(var->name, "format")) {
|
|
|
|
mohclass->format = ast_format_cache_get(var->value);
|
|
|
|
if (!mohclass->format) {
|
|
|
|
ast_log(LOG_WARNING, "Unknown format '%s' -- defaulting to SLIN\n", var->value);
|
|
|
|
mohclass->format = ao2_bump(ast_format_slin);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-04 06:21:43 +00:00
|
|
|
static int moh_add_file(struct mohclass *class, const char *filepath)
|
|
|
|
{
|
|
|
|
if (!class->allowed_files) {
|
2013-09-10 18:05:47 +00:00
|
|
|
class->filearray = ast_calloc(1, INITIAL_NUM_FILES * sizeof(*class->filearray));
|
|
|
|
if (!class->filearray) {
|
2006-06-04 06:21:43 +00:00
|
|
|
return -1;
|
2013-09-10 18:05:47 +00:00
|
|
|
}
|
2006-06-04 06:21:43 +00:00
|
|
|
class->allowed_files = INITIAL_NUM_FILES;
|
|
|
|
} else if (class->total_files == class->allowed_files) {
|
2013-09-10 18:05:47 +00:00
|
|
|
char **new_array;
|
|
|
|
|
|
|
|
new_array = ast_realloc(class->filearray, class->allowed_files * sizeof(*class->filearray) * 2);
|
|
|
|
if (!new_array) {
|
2006-06-04 06:21:43 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2013-09-10 18:05:47 +00:00
|
|
|
class->filearray = new_array;
|
2006-06-04 06:21:43 +00:00
|
|
|
class->allowed_files *= 2;
|
|
|
|
}
|
|
|
|
|
2013-09-10 18:05:47 +00:00
|
|
|
class->filearray[class->total_files] = ast_strdup(filepath);
|
|
|
|
if (!class->filearray[class->total_files]) {
|
2006-06-04 06:21:43 +00:00
|
|
|
return -1;
|
2013-09-10 18:05:47 +00:00
|
|
|
}
|
2006-06-04 06:21:43 +00:00
|
|
|
|
|
|
|
class->total_files++;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-10-01 14:43:56 +00:00
|
|
|
static int moh_sort_compare(const void *i1, const void *i2)
|
|
|
|
{
|
|
|
|
char *s1, *s2;
|
|
|
|
|
|
|
|
s1 = ((char **)i1)[0];
|
|
|
|
s2 = ((char **)i2)[0];
|
|
|
|
|
|
|
|
return strcasecmp(s1, s2);
|
|
|
|
}
|
|
|
|
|
2004-12-24 01:40:07 +00:00
|
|
|
static int moh_scan_files(struct mohclass *class) {
|
|
|
|
|
|
|
|
DIR *files_DIR;
|
|
|
|
struct dirent *files_dirent;
|
2008-10-16 08:30:32 +00:00
|
|
|
char dir_path[PATH_MAX];
|
2006-06-09 20:26:25 +00:00
|
|
|
char path[PATH_MAX];
|
2006-06-04 06:21:43 +00:00
|
|
|
char filepath[PATH_MAX];
|
2005-01-03 00:38:01 +00:00
|
|
|
char *ext;
|
2004-12-24 01:40:07 +00:00
|
|
|
struct stat statbuf;
|
|
|
|
int i;
|
Adding support for realtime music on hold. The following are the main points:
1. When moh is started, we search first in memory to find the class. If we do not
find it in memory, we search realtime instead.
2. When moh is restarted (as in, it had been started on this particular channel, stopped,
and now we're starting it again), if using the "files" mode, then realtime will always
be rechecked. If you are using other modes, however, we will simply reattach to the external
running process which was playing moh earlier in the call. This is a necessary compromise so that
we don't end up with too many background processes.
3. musiconhold.conf has a general section now. It has one option: cachertclasses. If set to yes,
then moh classes found in realtime will be added to the in-memory list. This has the advantage
of not requiring database lookups each time moh is started, but it has the disadvantage of not
truly being realtime.
I have tested this for functionality, and it passes. I also tested this under valgrind and there
are no memory problems reported under typical use.
Special thanks to Sergee for implementing this feature and enduring my complaints on the bugtracker!
(closes issue #11196, reported and patched by sergee)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89946 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-28 00:47:22 +00:00
|
|
|
|
2008-10-16 08:30:32 +00:00
|
|
|
if (class->dir[0] != '/') {
|
2010-10-16 11:51:54 +00:00
|
|
|
ast_copy_string(dir_path, ast_config_AST_DATA_DIR, sizeof(dir_path));
|
2008-11-02 18:52:13 +00:00
|
|
|
strncat(dir_path, "/", sizeof(dir_path) - 1);
|
|
|
|
strncat(dir_path, class->dir, sizeof(dir_path) - 1);
|
2008-10-16 08:30:32 +00:00
|
|
|
} else {
|
|
|
|
ast_copy_string(dir_path, class->dir, sizeof(dir_path));
|
|
|
|
}
|
|
|
|
ast_debug(4, "Scanning '%s' for files for class '%s'\n", dir_path, class->name);
|
|
|
|
files_DIR = opendir(dir_path);
|
2004-12-24 01:40:07 +00:00
|
|
|
if (!files_DIR) {
|
2008-10-16 08:30:32 +00:00
|
|
|
ast_log(LOG_WARNING, "Cannot open dir %s or dir does not exist\n", dir_path);
|
2004-12-24 01:40:07 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-04-17 18:57:40 +00:00
|
|
|
for (i = 0; i < class->total_files; i++) {
|
2007-06-06 21:20:11 +00:00
|
|
|
ast_free(class->filearray[i]);
|
2012-04-17 18:57:40 +00:00
|
|
|
}
|
2004-12-24 01:40:07 +00:00
|
|
|
class->total_files = 0;
|
2012-04-17 18:57:40 +00:00
|
|
|
|
2008-11-02 18:52:13 +00:00
|
|
|
if (!getcwd(path, sizeof(path))) {
|
|
|
|
ast_log(LOG_WARNING, "getcwd() failed: %s\n", strerror(errno));
|
2012-04-17 18:57:40 +00:00
|
|
|
closedir(files_DIR);
|
2008-11-02 18:52:13 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2008-11-02 19:09:41 +00:00
|
|
|
if (chdir(dir_path) < 0) {
|
2008-11-02 18:52:13 +00:00
|
|
|
ast_log(LOG_WARNING, "chdir() failed: %s\n", strerror(errno));
|
2012-04-17 18:57:40 +00:00
|
|
|
closedir(files_DIR);
|
2008-11-02 18:52:13 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2004-12-24 01:40:07 +00:00
|
|
|
while ((files_dirent = readdir(files_DIR))) {
|
2006-06-04 06:21:43 +00:00
|
|
|
/* The file name must be at least long enough to have the file type extension */
|
|
|
|
if ((strlen(files_dirent->d_name) < 4))
|
2004-12-24 01:40:07 +00:00
|
|
|
continue;
|
|
|
|
|
2006-11-02 17:51:56 +00:00
|
|
|
/* Skip files that starts with a dot */
|
|
|
|
if (files_dirent->d_name[0] == '.')
|
|
|
|
continue;
|
|
|
|
|
2006-09-19 23:08:35 +00:00
|
|
|
/* Skip files without extensions... they are not audio */
|
|
|
|
if (!strchr(files_dirent->d_name, '.'))
|
2006-09-19 21:07:49 +00:00
|
|
|
continue;
|
|
|
|
|
2008-10-16 08:30:32 +00:00
|
|
|
snprintf(filepath, sizeof(filepath), "%s/%s", dir_path, files_dirent->d_name);
|
2004-12-24 01:40:07 +00:00
|
|
|
|
|
|
|
if (stat(filepath, &statbuf))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!S_ISREG(statbuf.st_mode))
|
|
|
|
continue;
|
|
|
|
|
2007-09-18 22:43:45 +00:00
|
|
|
if ((ext = strrchr(filepath, '.')))
|
2005-01-03 00:38:01 +00:00
|
|
|
*ext = '\0';
|
|
|
|
|
2004-12-24 01:40:07 +00:00
|
|
|
/* if the file is present in multiple formats, ensure we only put it into the list once */
|
|
|
|
for (i = 0; i < class->total_files; i++)
|
|
|
|
if (!strcmp(filepath, class->filearray[i]))
|
|
|
|
break;
|
|
|
|
|
2006-06-04 06:21:43 +00:00
|
|
|
if (i == class->total_files) {
|
|
|
|
if (moh_add_file(class, filepath))
|
|
|
|
break;
|
|
|
|
}
|
2004-12-24 01:40:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
closedir(files_DIR);
|
2008-11-02 18:52:13 +00:00
|
|
|
if (chdir(path) < 0) {
|
|
|
|
ast_log(LOG_WARNING, "chdir() failed: %s\n", strerror(errno));
|
|
|
|
return -1;
|
|
|
|
}
|
2007-10-01 14:43:56 +00:00
|
|
|
if (ast_test_flag(class, MOH_SORTALPHA))
|
|
|
|
qsort(&class->filearray[0], class->total_files, sizeof(char *), moh_sort_compare);
|
2004-12-24 01:40:07 +00:00
|
|
|
return class->total_files;
|
|
|
|
}
|
|
|
|
|
2008-12-22 16:10:40 +00:00
|
|
|
static int init_files_class(struct mohclass *class)
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
|
|
|
|
res = moh_scan_files(class);
|
|
|
|
|
|
|
|
if (res < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!res) {
|
2011-11-29 18:43:16 +00:00
|
|
|
ast_verb(3, "Files not found in %s for moh class:%s\n",
|
|
|
|
class->dir, class->name);
|
2008-12-22 16:10:40 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-09-08 20:32:49 +00:00
|
|
|
static void moh_rescan_files(void) {
|
|
|
|
struct ao2_iterator i;
|
|
|
|
struct mohclass *c;
|
|
|
|
|
|
|
|
i = ao2_iterator_init(mohclasses, 0);
|
|
|
|
|
2010-09-08 20:43:38 +00:00
|
|
|
while ((c = ao2_iterator_next(&i))) {
|
2011-06-28 16:04:18 +00:00
|
|
|
if (!strcasecmp(c->mode, "files")) {
|
|
|
|
moh_scan_files(c);
|
|
|
|
}
|
2010-09-08 20:32:49 +00:00
|
|
|
ao2_ref(c, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
ao2_iterator_destroy(&i);
|
|
|
|
}
|
2008-12-22 16:10:40 +00:00
|
|
|
|
2007-10-18 07:12:18 +00:00
|
|
|
static int moh_diff(struct mohclass *old, struct mohclass *new)
|
|
|
|
{
|
2008-12-22 16:10:40 +00:00
|
|
|
if (!old || !new) {
|
2007-10-18 07:12:18 +00:00
|
|
|
return -1;
|
2008-12-22 16:10:40 +00:00
|
|
|
}
|
2007-10-18 07:12:18 +00:00
|
|
|
|
2008-12-22 16:10:40 +00:00
|
|
|
if (strcmp(old->dir, new->dir)) {
|
2007-10-18 07:12:18 +00:00
|
|
|
return -1;
|
2008-12-22 16:10:40 +00:00
|
|
|
} else if (strcmp(old->mode, new->mode)) {
|
2007-10-18 07:12:18 +00:00
|
|
|
return -1;
|
2008-12-22 16:10:40 +00:00
|
|
|
} else if (strcmp(old->args, new->args)) {
|
2007-10-18 07:12:18 +00:00
|
|
|
return -1;
|
2008-12-22 16:10:40 +00:00
|
|
|
} else if (old->flags != new->flags) {
|
2007-10-18 07:12:18 +00:00
|
|
|
return -1;
|
2008-12-22 16:10:40 +00:00
|
|
|
}
|
2007-10-18 07:12:18 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-12-22 16:10:40 +00:00
|
|
|
static int init_app_class(struct mohclass *class)
|
2002-06-29 21:46:57 +00:00
|
|
|
{
|
2008-12-22 16:10:40 +00:00
|
|
|
if (!strcasecmp(class->mode, "custom")) {
|
|
|
|
ast_set_flag(class, MOH_CUSTOM);
|
|
|
|
} else if (!strcasecmp(class->mode, "mp3nb")) {
|
|
|
|
ast_set_flag(class, MOH_SINGLE);
|
|
|
|
} else if (!strcasecmp(class->mode, "quietmp3nb")) {
|
|
|
|
ast_set_flag(class, MOH_SINGLE | MOH_QUIET);
|
|
|
|
} else if (!strcasecmp(class->mode, "quietmp3")) {
|
|
|
|
ast_set_flag(class, MOH_QUIET);
|
|
|
|
}
|
2010-08-26 23:51:55 +00:00
|
|
|
|
2008-12-22 16:10:40 +00:00
|
|
|
class->srcfd = -1;
|
2010-08-26 23:51:55 +00:00
|
|
|
|
|
|
|
if (!(class->timer = ast_timer_open())) {
|
|
|
|
ast_log(LOG_WARNING, "Unable to create timer: %s\n", strerror(errno));
|
Fix timing source dependency issues with MOH
Prior to this patch, res_musiconhold existed at the same module priority level
as the timing sources that it depends on. This would cause a problem when
music on hold was reloaded, as the timing source could be changed after
res_musiconhold was processed. This patch adds a new module priority level,
AST_MODPRI_TIMING, that the various timing modules are now loaded at. This
now occurs before loading other resource modules, such that the timing source
is guaranteed to be set prior to resolving the timing source dependencies.
(closes issue ASTERISK-17474)
Reporter: Luke H
Tested by: Luke H, Vladimir Mikhelson, zzsurf, Wes Van Tlghem, elguero, Thomas Arimont
Patches:
asterisk-17474-dahdi_timing-infinite-wait-fix_v3_branch-1.8.diff uploaded by elguero (License #5026)
asterisk-17474-dahdi_timing-infinite-wait-fix_v3_branch-10.diff uploaded by elguero (License #5026)
asterisk-17474-dahdi_timing-infinite-wait-fix_v3.diff uploaded by elguero (License #5026)
Review: https://reviewboard.asterisk.org/r/1578/
........
Merged revisions 349194 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........
Merged revisions 349195 from http://svn.asterisk.org/svn/asterisk/branches/10
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@349196 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2011-12-27 20:55:15 +00:00
|
|
|
return -1;
|
2010-08-26 23:51:55 +00:00
|
|
|
}
|
|
|
|
if (class->timer && ast_timer_set_rate(class->timer, 25)) {
|
|
|
|
ast_log(LOG_WARNING, "Unable to set 40ms frame rate: %s\n", strerror(errno));
|
|
|
|
ast_timer_close(class->timer);
|
|
|
|
class->timer = NULL;
|
2008-12-22 16:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ast_pthread_create_background(&class->thread, NULL, monmp3thread, class)) {
|
|
|
|
ast_log(LOG_WARNING, "Unable to create moh thread...\n");
|
2010-08-26 23:51:55 +00:00
|
|
|
if (class->timer) {
|
|
|
|
ast_timer_close(class->timer);
|
|
|
|
class->timer = NULL;
|
2008-12-22 16:10:40 +00:00
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
2009-12-03 00:08:55 +00:00
|
|
|
* \note This function owns the reference it gets to moh if unref is true
|
2008-12-22 16:10:40 +00:00
|
|
|
*/
|
2014-03-06 00:19:06 +00:00
|
|
|
#define moh_register(moh, reload, unref) _moh_register(moh, reload, unref, __FILE__, __LINE__, __PRETTY_FUNCTION__)
|
2009-12-03 00:08:55 +00:00
|
|
|
static int _moh_register(struct mohclass *moh, int reload, int unref, const char *file, int line, const char *funcname)
|
2008-12-22 16:10:40 +00:00
|
|
|
{
|
2007-08-16 22:30:39 +00:00
|
|
|
struct mohclass *mohclass = NULL;
|
|
|
|
|
Fix timing source dependency issues with MOH
Prior to this patch, res_musiconhold existed at the same module priority level
as the timing sources that it depends on. This would cause a problem when
music on hold was reloaded, as the timing source could be changed after
res_musiconhold was processed. This patch adds a new module priority level,
AST_MODPRI_TIMING, that the various timing modules are now loaded at. This
now occurs before loading other resource modules, such that the timing source
is guaranteed to be set prior to resolving the timing source dependencies.
(closes issue ASTERISK-17474)
Reporter: Luke H
Tested by: Luke H, Vladimir Mikhelson, zzsurf, Wes Van Tlghem, elguero, Thomas Arimont
Patches:
asterisk-17474-dahdi_timing-infinite-wait-fix_v3_branch-1.8.diff uploaded by elguero (License #5026)
asterisk-17474-dahdi_timing-infinite-wait-fix_v3_branch-10.diff uploaded by elguero (License #5026)
asterisk-17474-dahdi_timing-infinite-wait-fix_v3.diff uploaded by elguero (License #5026)
Review: https://reviewboard.asterisk.org/r/1578/
........
Merged revisions 349194 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........
Merged revisions 349195 from http://svn.asterisk.org/svn/asterisk/branches/10
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@349196 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2011-12-27 20:55:15 +00:00
|
|
|
mohclass = _get_mohbyname(moh->name, 0, MOH_NOTDELETED, file, line, funcname);
|
|
|
|
|
|
|
|
if (mohclass && !moh_diff(mohclass, moh)) {
|
2009-12-03 00:08:55 +00:00
|
|
|
ast_log(LOG_WARNING, "Music on Hold class '%s' already exists\n", moh->name);
|
|
|
|
mohclass = mohclass_unref(mohclass, "unreffing mohclass we just found by name");
|
|
|
|
if (unref) {
|
|
|
|
moh = mohclass_unref(moh, "unreffing potential new moh class (it is a duplicate)");
|
2005-11-16 17:48:18 +00:00
|
|
|
}
|
2009-12-03 00:08:55 +00:00
|
|
|
return -1;
|
|
|
|
} else if (mohclass) {
|
|
|
|
/* Found a class, but it's different from the one being registered */
|
|
|
|
mohclass = mohclass_unref(mohclass, "unreffing mohclass we just found by name");
|
2002-06-29 21:46:57 +00:00
|
|
|
}
|
2005-08-22 19:29:29 +00:00
|
|
|
|
2004-09-04 05:41:01 +00:00
|
|
|
time(&moh->start);
|
|
|
|
moh->start -= respawn_time;
|
2010-08-26 23:51:55 +00:00
|
|
|
|
2005-08-22 19:29:29 +00:00
|
|
|
if (!strcasecmp(moh->mode, "files")) {
|
2008-12-22 16:10:40 +00:00
|
|
|
if (init_files_class(moh)) {
|
2009-12-08 18:22:44 +00:00
|
|
|
if (unref) {
|
|
|
|
moh = mohclass_unref(moh, "unreffing potential new moh class (init_files_class failed)");
|
|
|
|
}
|
2004-12-24 01:40:07 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2008-12-22 16:10:40 +00:00
|
|
|
} else if (!strcasecmp(moh->mode, "mp3") || !strcasecmp(moh->mode, "mp3nb") ||
|
|
|
|
!strcasecmp(moh->mode, "quietmp3") || !strcasecmp(moh->mode, "quietmp3nb") ||
|
|
|
|
!strcasecmp(moh->mode, "httpmp3") || !strcasecmp(moh->mode, "custom")) {
|
|
|
|
if (init_app_class(moh)) {
|
2009-12-08 18:22:44 +00:00
|
|
|
if (unref) {
|
|
|
|
moh = mohclass_unref(moh, "unreffing potential new moh class (init_app_class_failed)");
|
|
|
|
}
|
2002-06-29 21:46:57 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else {
|
2005-08-22 19:29:29 +00:00
|
|
|
ast_log(LOG_WARNING, "Don't know how to do a mode '%s' music on hold\n", moh->mode);
|
2009-12-08 18:22:44 +00:00
|
|
|
if (unref) {
|
|
|
|
moh = mohclass_unref(moh, "unreffing potential new moh class (unknown mode)");
|
|
|
|
}
|
2002-06-29 21:46:57 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2006-04-29 13:15:05 +00:00
|
|
|
|
2009-04-09 17:30:39 +00:00
|
|
|
ao2_t_link(mohclasses, moh, "Adding class to container");
|
2008-12-22 16:10:40 +00:00
|
|
|
|
2009-04-09 17:30:39 +00:00
|
|
|
if (unref) {
|
|
|
|
moh = mohclass_unref(moh, "Unreffing new moh class because we just added it to the container");
|
|
|
|
}
|
2010-08-26 23:51:55 +00:00
|
|
|
|
2002-06-29 21:46:57 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-12-24 01:40:07 +00:00
|
|
|
static void local_ast_moh_cleanup(struct ast_channel *chan)
|
|
|
|
{
|
2012-02-20 23:43:27 +00:00
|
|
|
struct moh_files_state *state = ast_channel_music_state(chan);
|
Adding support for realtime music on hold. The following are the main points:
1. When moh is started, we search first in memory to find the class. If we do not
find it in memory, we search realtime instead.
2. When moh is restarted (as in, it had been started on this particular channel, stopped,
and now we're starting it again), if using the "files" mode, then realtime will always
be rechecked. If you are using other modes, however, we will simply reattach to the external
running process which was playing moh earlier in the call. This is a necessary compromise so that
we don't end up with too many background processes.
3. musiconhold.conf has a general section now. It has one option: cachertclasses. If set to yes,
then moh classes found in realtime will be added to the in-memory list. This has the advantage
of not requiring database lookups each time moh is started, but it has the disadvantage of not
truly being realtime.
I have tested this for functionality, and it passes. I also tested this under valgrind and there
are no memory problems reported under typical use.
Special thanks to Sergee for implementing this feature and enduring my complaints on the bugtracker!
(closes issue #11196, reported and patched by sergee)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89946 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-28 00:47:22 +00:00
|
|
|
|
|
|
|
if (state) {
|
2014-08-25 16:45:40 +00:00
|
|
|
ast_channel_music_state_set(chan, NULL);
|
2009-12-03 00:08:55 +00:00
|
|
|
if (state->class) {
|
2011-09-02 21:09:31 +00:00
|
|
|
/* This should never happen. We likely just leaked some resource. */
|
|
|
|
state->class =
|
|
|
|
mohclass_unref(state->class, "Uh Oh. Cleaning up MOH with an active class");
|
|
|
|
ast_log(LOG_WARNING, "Uh Oh. Cleaning up MOH with an active class\n");
|
2009-12-03 00:08:55 +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(state->origwfmt);
|
|
|
|
ao2_cleanup(state->mohwfmt);
|
2014-08-25 16:45:40 +00:00
|
|
|
ast_free(state);
|
2009-12-08 18:22:44 +00:00
|
|
|
/* Only held a module reference if we had a music state */
|
|
|
|
ast_module_unref(ast_module_info->self);
|
2004-12-24 01:40:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-22 16:10:40 +00:00
|
|
|
static void moh_class_destructor(void *obj);
|
|
|
|
|
2009-12-03 00:08:55 +00:00
|
|
|
#define moh_class_malloc() _moh_class_malloc(__FILE__,__LINE__,__PRETTY_FUNCTION__)
|
|
|
|
|
|
|
|
static struct mohclass *_moh_class_malloc(const char *file, int line, const char *funcname)
|
Adding support for realtime music on hold. The following are the main points:
1. When moh is started, we search first in memory to find the class. If we do not
find it in memory, we search realtime instead.
2. When moh is restarted (as in, it had been started on this particular channel, stopped,
and now we're starting it again), if using the "files" mode, then realtime will always
be rechecked. If you are using other modes, however, we will simply reattach to the external
running process which was playing moh earlier in the call. This is a necessary compromise so that
we don't end up with too many background processes.
3. musiconhold.conf has a general section now. It has one option: cachertclasses. If set to yes,
then moh classes found in realtime will be added to the in-memory list. This has the advantage
of not requiring database lookups each time moh is started, but it has the disadvantage of not
truly being realtime.
I have tested this for functionality, and it passes. I also tested this under valgrind and there
are no memory problems reported under typical use.
Special thanks to Sergee for implementing this feature and enduring my complaints on the bugtracker!
(closes issue #11196, reported and patched by sergee)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89946 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-28 00:47:22 +00:00
|
|
|
{
|
|
|
|
struct mohclass *class;
|
|
|
|
|
2015-04-17 07:16:59 +00:00
|
|
|
class = __ao2_alloc(sizeof(*class), moh_class_destructor, AO2_ALLOC_OPT_LOCK_MUTEX,
|
|
|
|
"Allocating new moh class", file, line, funcname);
|
|
|
|
if (class) {
|
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
|
|
|
class->format = ao2_bump(ast_format_slin);
|
2011-01-31 21:01:28 +00:00
|
|
|
class->srcfd = -1;
|
Adding support for realtime music on hold. The following are the main points:
1. When moh is started, we search first in memory to find the class. If we do not
find it in memory, we search realtime instead.
2. When moh is restarted (as in, it had been started on this particular channel, stopped,
and now we're starting it again), if using the "files" mode, then realtime will always
be rechecked. If you are using other modes, however, we will simply reattach to the external
running process which was playing moh earlier in the call. This is a necessary compromise so that
we don't end up with too many background processes.
3. musiconhold.conf has a general section now. It has one option: cachertclasses. If set to yes,
then moh classes found in realtime will be added to the in-memory list. This has the advantage
of not requiring database lookups each time moh is started, but it has the disadvantage of not
truly being realtime.
I have tested this for functionality, and it passes. I also tested this under valgrind and there
are no memory problems reported under typical use.
Special thanks to Sergee for implementing this feature and enduring my complaints on the bugtracker!
(closes issue #11196, reported and patched by sergee)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89946 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-28 00:47:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return class;
|
|
|
|
}
|
|
|
|
|
2016-03-24 12:51:00 +00:00
|
|
|
static struct ast_variable *load_realtime_musiconhold(const char *name)
|
|
|
|
{
|
|
|
|
struct ast_variable *var = ast_load_realtime("musiconhold", "name", name, SENTINEL);
|
|
|
|
if (!var) {
|
|
|
|
ast_log(LOG_WARNING,
|
|
|
|
"Music on Hold class '%s' not found in memory/database. "
|
|
|
|
"Verify your configuration.\n",
|
|
|
|
name);
|
|
|
|
}
|
|
|
|
return var;
|
|
|
|
}
|
|
|
|
|
2006-07-19 20:44:39 +00:00
|
|
|
static int local_ast_moh_start(struct ast_channel *chan, const char *mclass, const char *interpclass)
|
2002-06-29 21:46:57 +00:00
|
|
|
{
|
2007-07-10 16:01:27 +00:00
|
|
|
struct mohclass *mohclass = NULL;
|
2012-02-20 23:43:27 +00:00
|
|
|
struct moh_files_state *state = ast_channel_music_state(chan);
|
2009-07-27 20:11:42 +00:00
|
|
|
struct ast_variable *var = NULL;
|
2014-06-17 16:33:53 +00:00
|
|
|
int res = 0;
|
2014-09-25 20:49:04 +00:00
|
|
|
int i;
|
2009-07-27 20:11:42 +00:00
|
|
|
int realtime_possible = ast_check_realtime("musiconhold");
|
2016-03-24 12:51:00 +00:00
|
|
|
int warn_if_not_in_memory = !realtime_possible;
|
2014-09-25 20:49:04 +00:00
|
|
|
const char *classes[] = {NULL, NULL, interpclass, "default"};
|
|
|
|
|
|
|
|
if (ast_test_flag(global_flags, MOH_PREFERCHANNELCLASS)) {
|
|
|
|
classes[0] = ast_channel_musicclass(chan);
|
|
|
|
classes[1] = mclass;
|
|
|
|
} else {
|
|
|
|
classes[0] = mclass;
|
|
|
|
classes[1] = ast_channel_musicclass(chan);
|
|
|
|
}
|
2006-07-19 20:44:39 +00:00
|
|
|
|
|
|
|
/* The following is the order of preference for which class to use:
|
|
|
|
* 1) The channels explicitly set musicclass, which should *only* be
|
|
|
|
* set by a call to Set(CHANNEL(musicclass)=whatever) in the dialplan.
|
2014-09-25 20:49:04 +00:00
|
|
|
* Unless preferchannelclass in musiconhold.conf is false
|
2006-07-19 20:44:39 +00:00
|
|
|
* 2) The mclass argument. If a channel is calling ast_moh_start() as the
|
|
|
|
* result of receiving a HOLD control frame, this should be the
|
|
|
|
* payload that came with the frame.
|
2014-09-25 20:49:04 +00:00
|
|
|
* 3) The channels explicitly set musicclass, which should *only* be
|
|
|
|
* set by a call to Set(CHANNEL(musicclass)=whatever) in the dialplan.
|
|
|
|
* 4) The interpclass argument. This would be from the mohinterpret
|
2006-07-19 20:44:39 +00:00
|
|
|
* option from channel drivers. This is the same as the old musicclass
|
|
|
|
* option.
|
2014-09-25 20:49:04 +00:00
|
|
|
* 5) The default class.
|
2006-07-19 20:44:39 +00:00
|
|
|
*/
|
Adding support for realtime music on hold. The following are the main points:
1. When moh is started, we search first in memory to find the class. If we do not
find it in memory, we search realtime instead.
2. When moh is restarted (as in, it had been started on this particular channel, stopped,
and now we're starting it again), if using the "files" mode, then realtime will always
be rechecked. If you are using other modes, however, we will simply reattach to the external
running process which was playing moh earlier in the call. This is a necessary compromise so that
we don't end up with too many background processes.
3. musiconhold.conf has a general section now. It has one option: cachertclasses. If set to yes,
then moh classes found in realtime will be added to the in-memory list. This has the advantage
of not requiring database lookups each time moh is started, but it has the disadvantage of not
truly being realtime.
I have tested this for functionality, and it passes. I also tested this under valgrind and there
are no memory problems reported under typical use.
Special thanks to Sergee for implementing this feature and enduring my complaints on the bugtracker!
(closes issue #11196, reported and patched by sergee)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89946 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-28 00:47:22 +00:00
|
|
|
|
2014-09-25 20:49:04 +00:00
|
|
|
for (i = 0; i < ARRAY_LEN(classes); ++i) {
|
|
|
|
if (!ast_strlen_zero(classes[i])) {
|
2016-03-24 12:51:00 +00:00
|
|
|
mohclass = get_mohbyname(classes[i], warn_if_not_in_memory, 0);
|
2014-09-25 20:49:04 +00:00
|
|
|
if (!mohclass && realtime_possible) {
|
2016-03-24 12:51:00 +00:00
|
|
|
var = load_realtime_musiconhold(classes[i]);
|
2014-09-25 20:49:04 +00:00
|
|
|
}
|
|
|
|
if (mohclass || var) {
|
|
|
|
break;
|
|
|
|
}
|
2009-07-27 20:11:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If no moh class found in memory, then check RT. Note that the logic used
|
|
|
|
* above guarantees that if var is non-NULL, then mohclass must be NULL.
|
|
|
|
*/
|
|
|
|
if (var) {
|
|
|
|
if ((mohclass = moh_class_malloc())) {
|
Adding support for realtime music on hold. The following are the main points:
1. When moh is started, we search first in memory to find the class. If we do not
find it in memory, we search realtime instead.
2. When moh is restarted (as in, it had been started on this particular channel, stopped,
and now we're starting it again), if using the "files" mode, then realtime will always
be rechecked. If you are using other modes, however, we will simply reattach to the external
running process which was playing moh earlier in the call. This is a necessary compromise so that
we don't end up with too many background processes.
3. musiconhold.conf has a general section now. It has one option: cachertclasses. If set to yes,
then moh classes found in realtime will be added to the in-memory list. This has the advantage
of not requiring database lookups each time moh is started, but it has the disadvantage of not
truly being realtime.
I have tested this for functionality, and it passes. I also tested this under valgrind and there
are no memory problems reported under typical use.
Special thanks to Sergee for implementing this feature and enduring my complaints on the bugtracker!
(closes issue #11196, reported and patched by sergee)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89946 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-28 00:47:22 +00:00
|
|
|
mohclass->realtime = 1;
|
2014-09-14 15:41:58 +00:00
|
|
|
|
|
|
|
moh_parse_options(var, mohclass);
|
2007-11-28 23:03:09 +00:00
|
|
|
ast_variables_destroy(var);
|
2014-09-14 15:41:58 +00:00
|
|
|
|
Adding support for realtime music on hold. The following are the main points:
1. When moh is started, we search first in memory to find the class. If we do not
find it in memory, we search realtime instead.
2. When moh is restarted (as in, it had been started on this particular channel, stopped,
and now we're starting it again), if using the "files" mode, then realtime will always
be rechecked. If you are using other modes, however, we will simply reattach to the external
running process which was playing moh earlier in the call. This is a necessary compromise so that
we don't end up with too many background processes.
3. musiconhold.conf has a general section now. It has one option: cachertclasses. If set to yes,
then moh classes found in realtime will be added to the in-memory list. This has the advantage
of not requiring database lookups each time moh is started, but it has the disadvantage of not
truly being realtime.
I have tested this for functionality, and it passes. I also tested this under valgrind and there
are no memory problems reported under typical use.
Special thanks to Sergee for implementing this feature and enduring my complaints on the bugtracker!
(closes issue #11196, reported and patched by sergee)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89946 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-28 00:47:22 +00:00
|
|
|
if (ast_strlen_zero(mohclass->dir)) {
|
|
|
|
if (!strcasecmp(mohclass->mode, "custom")) {
|
|
|
|
strcpy(mohclass->dir, "nodir");
|
|
|
|
} else {
|
|
|
|
ast_log(LOG_WARNING, "A directory must be specified for class '%s'!\n", mohclass->name);
|
2009-04-09 17:30:39 +00:00
|
|
|
mohclass = mohclass_unref(mohclass, "unreffing potential mohclass (no directory specified)");
|
Adding support for realtime music on hold. The following are the main points:
1. When moh is started, we search first in memory to find the class. If we do not
find it in memory, we search realtime instead.
2. When moh is restarted (as in, it had been started on this particular channel, stopped,
and now we're starting it again), if using the "files" mode, then realtime will always
be rechecked. If you are using other modes, however, we will simply reattach to the external
running process which was playing moh earlier in the call. This is a necessary compromise so that
we don't end up with too many background processes.
3. musiconhold.conf has a general section now. It has one option: cachertclasses. If set to yes,
then moh classes found in realtime will be added to the in-memory list. This has the advantage
of not requiring database lookups each time moh is started, but it has the disadvantage of not
truly being realtime.
I have tested this for functionality, and it passes. I also tested this under valgrind and there
are no memory problems reported under typical use.
Special thanks to Sergee for implementing this feature and enduring my complaints on the bugtracker!
(closes issue #11196, reported and patched by sergee)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89946 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-28 00:47:22 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ast_strlen_zero(mohclass->mode)) {
|
|
|
|
ast_log(LOG_WARNING, "A mode must be specified for class '%s'!\n", mohclass->name);
|
2009-04-09 17:30:39 +00:00
|
|
|
mohclass = mohclass_unref(mohclass, "unreffing potential mohclass (no mode specified)");
|
Adding support for realtime music on hold. The following are the main points:
1. When moh is started, we search first in memory to find the class. If we do not
find it in memory, we search realtime instead.
2. When moh is restarted (as in, it had been started on this particular channel, stopped,
and now we're starting it again), if using the "files" mode, then realtime will always
be rechecked. If you are using other modes, however, we will simply reattach to the external
running process which was playing moh earlier in the call. This is a necessary compromise so that
we don't end up with too many background processes.
3. musiconhold.conf has a general section now. It has one option: cachertclasses. If set to yes,
then moh classes found in realtime will be added to the in-memory list. This has the advantage
of not requiring database lookups each time moh is started, but it has the disadvantage of not
truly being realtime.
I have tested this for functionality, and it passes. I also tested this under valgrind and there
are no memory problems reported under typical use.
Special thanks to Sergee for implementing this feature and enduring my complaints on the bugtracker!
(closes issue #11196, reported and patched by sergee)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89946 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-28 00:47:22 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (ast_strlen_zero(mohclass->args) && !strcasecmp(mohclass->mode, "custom")) {
|
|
|
|
ast_log(LOG_WARNING, "An application must be specified for class '%s'!\n", mohclass->name);
|
2009-04-09 17:30:39 +00:00
|
|
|
mohclass = mohclass_unref(mohclass, "unreffing potential mohclass (no app specified for custom mode");
|
Adding support for realtime music on hold. The following are the main points:
1. When moh is started, we search first in memory to find the class. If we do not
find it in memory, we search realtime instead.
2. When moh is restarted (as in, it had been started on this particular channel, stopped,
and now we're starting it again), if using the "files" mode, then realtime will always
be rechecked. If you are using other modes, however, we will simply reattach to the external
running process which was playing moh earlier in the call. This is a necessary compromise so that
we don't end up with too many background processes.
3. musiconhold.conf has a general section now. It has one option: cachertclasses. If set to yes,
then moh classes found in realtime will be added to the in-memory list. This has the advantage
of not requiring database lookups each time moh is started, but it has the disadvantage of not
truly being realtime.
I have tested this for functionality, and it passes. I also tested this under valgrind and there
are no memory problems reported under typical use.
Special thanks to Sergee for implementing this feature and enduring my complaints on the bugtracker!
(closes issue #11196, reported and patched by sergee)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89946 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-28 00:47:22 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ast_test_flag(global_flags, MOH_CACHERTCLASSES)) {
|
|
|
|
/* CACHERTCLASSES enabled, let's add this class to default tree */
|
|
|
|
if (state && state->class) {
|
|
|
|
/* Class already exist for this channel */
|
|
|
|
ast_log(LOG_NOTICE, "This channel already has a MOH class attached (%s)!\n", state->class->name);
|
|
|
|
}
|
2009-04-09 17:30:39 +00:00
|
|
|
/* We don't want moh_register to unref the mohclass because we do it at the end of this function as well.
|
|
|
|
* If we allowed moh_register to unref the mohclass,too, then the count would be off by one. The result would
|
|
|
|
* be that the destructor would be called when the generator on the channel is deactivated. The container then
|
|
|
|
* has a pointer to a freed mohclass, so any operations involving the mohclass container would result in reading
|
|
|
|
* invalid memory.
|
|
|
|
*/
|
2010-06-09 15:09:25 +00:00
|
|
|
if (moh_register(mohclass, 0, DONT_UNREF) == -1) {
|
|
|
|
mohclass = mohclass_unref(mohclass, "unreffing mohclass failed to register");
|
|
|
|
return -1;
|
|
|
|
}
|
Adding support for realtime music on hold. The following are the main points:
1. When moh is started, we search first in memory to find the class. If we do not
find it in memory, we search realtime instead.
2. When moh is restarted (as in, it had been started on this particular channel, stopped,
and now we're starting it again), if using the "files" mode, then realtime will always
be rechecked. If you are using other modes, however, we will simply reattach to the external
running process which was playing moh earlier in the call. This is a necessary compromise so that
we don't end up with too many background processes.
3. musiconhold.conf has a general section now. It has one option: cachertclasses. If set to yes,
then moh classes found in realtime will be added to the in-memory list. This has the advantage
of not requiring database lookups each time moh is started, but it has the disadvantage of not
truly being realtime.
I have tested this for functionality, and it passes. I also tested this under valgrind and there
are no memory problems reported under typical use.
Special thanks to Sergee for implementing this feature and enduring my complaints on the bugtracker!
(closes issue #11196, reported and patched by sergee)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89946 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-28 00:47:22 +00:00
|
|
|
} else {
|
|
|
|
/* We don't register RT moh class, so let's init it manualy */
|
|
|
|
|
|
|
|
time(&mohclass->start);
|
|
|
|
mohclass->start -= respawn_time;
|
2010-08-26 23:51:55 +00:00
|
|
|
|
Adding support for realtime music on hold. The following are the main points:
1. When moh is started, we search first in memory to find the class. If we do not
find it in memory, we search realtime instead.
2. When moh is restarted (as in, it had been started on this particular channel, stopped,
and now we're starting it again), if using the "files" mode, then realtime will always
be rechecked. If you are using other modes, however, we will simply reattach to the external
running process which was playing moh earlier in the call. This is a necessary compromise so that
we don't end up with too many background processes.
3. musiconhold.conf has a general section now. It has one option: cachertclasses. If set to yes,
then moh classes found in realtime will be added to the in-memory list. This has the advantage
of not requiring database lookups each time moh is started, but it has the disadvantage of not
truly being realtime.
I have tested this for functionality, and it passes. I also tested this under valgrind and there
are no memory problems reported under typical use.
Special thanks to Sergee for implementing this feature and enduring my complaints on the bugtracker!
(closes issue #11196, reported and patched by sergee)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89946 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-28 00:47:22 +00:00
|
|
|
if (!strcasecmp(mohclass->mode, "files")) {
|
|
|
|
if (!moh_scan_files(mohclass)) {
|
2009-04-09 17:30:39 +00:00
|
|
|
mohclass = mohclass_unref(mohclass, "unreffing potential mohclass (moh_scan_files failed)");
|
Adding support for realtime music on hold. The following are the main points:
1. When moh is started, we search first in memory to find the class. If we do not
find it in memory, we search realtime instead.
2. When moh is restarted (as in, it had been started on this particular channel, stopped,
and now we're starting it again), if using the "files" mode, then realtime will always
be rechecked. If you are using other modes, however, we will simply reattach to the external
running process which was playing moh earlier in the call. This is a necessary compromise so that
we don't end up with too many background processes.
3. musiconhold.conf has a general section now. It has one option: cachertclasses. If set to yes,
then moh classes found in realtime will be added to the in-memory list. This has the advantage
of not requiring database lookups each time moh is started, but it has the disadvantage of not
truly being realtime.
I have tested this for functionality, and it passes. I also tested this under valgrind and there
are no memory problems reported under typical use.
Special thanks to Sergee for implementing this feature and enduring my complaints on the bugtracker!
(closes issue #11196, reported and patched by sergee)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89946 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-28 00:47:22 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2014-09-14 15:41:58 +00:00
|
|
|
if (strchr(mohclass->args, 'r')) {
|
|
|
|
static int deprecation_warning = 0;
|
|
|
|
if (!deprecation_warning) {
|
|
|
|
ast_log(LOG_WARNING, "Music on hold 'application=r' setting is deprecated in 14. Please use 'sort=random' instead.\n");
|
|
|
|
deprecation_warning = 1;
|
|
|
|
}
|
Adding support for realtime music on hold. The following are the main points:
1. When moh is started, we search first in memory to find the class. If we do not
find it in memory, we search realtime instead.
2. When moh is restarted (as in, it had been started on this particular channel, stopped,
and now we're starting it again), if using the "files" mode, then realtime will always
be rechecked. If you are using other modes, however, we will simply reattach to the external
running process which was playing moh earlier in the call. This is a necessary compromise so that
we don't end up with too many background processes.
3. musiconhold.conf has a general section now. It has one option: cachertclasses. If set to yes,
then moh classes found in realtime will be added to the in-memory list. This has the advantage
of not requiring database lookups each time moh is started, but it has the disadvantage of not
truly being realtime.
I have tested this for functionality, and it passes. I also tested this under valgrind and there
are no memory problems reported under typical use.
Special thanks to Sergee for implementing this feature and enduring my complaints on the bugtracker!
(closes issue #11196, reported and patched by sergee)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89946 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-28 00:47:22 +00:00
|
|
|
ast_set_flag(mohclass, MOH_RANDOMIZE);
|
2014-09-14 15:41:58 +00:00
|
|
|
}
|
Adding support for realtime music on hold. The following are the main points:
1. When moh is started, we search first in memory to find the class. If we do not
find it in memory, we search realtime instead.
2. When moh is restarted (as in, it had been started on this particular channel, stopped,
and now we're starting it again), if using the "files" mode, then realtime will always
be rechecked. If you are using other modes, however, we will simply reattach to the external
running process which was playing moh earlier in the call. This is a necessary compromise so that
we don't end up with too many background processes.
3. musiconhold.conf has a general section now. It has one option: cachertclasses. If set to yes,
then moh classes found in realtime will be added to the in-memory list. This has the advantage
of not requiring database lookups each time moh is started, but it has the disadvantage of not
truly being realtime.
I have tested this for functionality, and it passes. I also tested this under valgrind and there
are no memory problems reported under typical use.
Special thanks to Sergee for implementing this feature and enduring my complaints on the bugtracker!
(closes issue #11196, reported and patched by sergee)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89946 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-28 00:47:22 +00:00
|
|
|
} else if (!strcasecmp(mohclass->mode, "mp3") || !strcasecmp(mohclass->mode, "mp3nb") || !strcasecmp(mohclass->mode, "quietmp3") || !strcasecmp(mohclass->mode, "quietmp3nb") || !strcasecmp(mohclass->mode, "httpmp3") || !strcasecmp(mohclass->mode, "custom")) {
|
|
|
|
|
|
|
|
if (!strcasecmp(mohclass->mode, "custom"))
|
|
|
|
ast_set_flag(mohclass, MOH_CUSTOM);
|
|
|
|
else if (!strcasecmp(mohclass->mode, "mp3nb"))
|
|
|
|
ast_set_flag(mohclass, MOH_SINGLE);
|
|
|
|
else if (!strcasecmp(mohclass->mode, "quietmp3nb"))
|
|
|
|
ast_set_flag(mohclass, MOH_SINGLE | MOH_QUIET);
|
|
|
|
else if (!strcasecmp(mohclass->mode, "quietmp3"))
|
|
|
|
ast_set_flag(mohclass, MOH_QUIET);
|
2010-08-26 23:51:55 +00:00
|
|
|
|
Adding support for realtime music on hold. The following are the main points:
1. When moh is started, we search first in memory to find the class. If we do not
find it in memory, we search realtime instead.
2. When moh is restarted (as in, it had been started on this particular channel, stopped,
and now we're starting it again), if using the "files" mode, then realtime will always
be rechecked. If you are using other modes, however, we will simply reattach to the external
running process which was playing moh earlier in the call. This is a necessary compromise so that
we don't end up with too many background processes.
3. musiconhold.conf has a general section now. It has one option: cachertclasses. If set to yes,
then moh classes found in realtime will be added to the in-memory list. This has the advantage
of not requiring database lookups each time moh is started, but it has the disadvantage of not
truly being realtime.
I have tested this for functionality, and it passes. I also tested this under valgrind and there
are no memory problems reported under typical use.
Special thanks to Sergee for implementing this feature and enduring my complaints on the bugtracker!
(closes issue #11196, reported and patched by sergee)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89946 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-28 00:47:22 +00:00
|
|
|
mohclass->srcfd = -1;
|
2010-08-26 23:51:55 +00:00
|
|
|
if (!(mohclass->timer = ast_timer_open())) {
|
|
|
|
ast_log(LOG_WARNING, "Unable to create timer: %s\n", strerror(errno));
|
Adding support for realtime music on hold. The following are the main points:
1. When moh is started, we search first in memory to find the class. If we do not
find it in memory, we search realtime instead.
2. When moh is restarted (as in, it had been started on this particular channel, stopped,
and now we're starting it again), if using the "files" mode, then realtime will always
be rechecked. If you are using other modes, however, we will simply reattach to the external
running process which was playing moh earlier in the call. This is a necessary compromise so that
we don't end up with too many background processes.
3. musiconhold.conf has a general section now. It has one option: cachertclasses. If set to yes,
then moh classes found in realtime will be added to the in-memory list. This has the advantage
of not requiring database lookups each time moh is started, but it has the disadvantage of not
truly being realtime.
I have tested this for functionality, and it passes. I also tested this under valgrind and there
are no memory problems reported under typical use.
Special thanks to Sergee for implementing this feature and enduring my complaints on the bugtracker!
(closes issue #11196, reported and patched by sergee)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89946 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-28 00:47:22 +00:00
|
|
|
}
|
2010-08-26 23:51:55 +00:00
|
|
|
if (mohclass->timer && ast_timer_set_rate(mohclass->timer, 25)) {
|
|
|
|
ast_log(LOG_WARNING, "Unable to set 40ms frame rate: %s\n", strerror(errno));
|
|
|
|
ast_timer_close(mohclass->timer);
|
|
|
|
mohclass->timer = NULL;
|
|
|
|
}
|
|
|
|
|
Adding support for realtime music on hold. The following are the main points:
1. When moh is started, we search first in memory to find the class. If we do not
find it in memory, we search realtime instead.
2. When moh is restarted (as in, it had been started on this particular channel, stopped,
and now we're starting it again), if using the "files" mode, then realtime will always
be rechecked. If you are using other modes, however, we will simply reattach to the external
running process which was playing moh earlier in the call. This is a necessary compromise so that
we don't end up with too many background processes.
3. musiconhold.conf has a general section now. It has one option: cachertclasses. If set to yes,
then moh classes found in realtime will be added to the in-memory list. This has the advantage
of not requiring database lookups each time moh is started, but it has the disadvantage of not
truly being realtime.
I have tested this for functionality, and it passes. I also tested this under valgrind and there
are no memory problems reported under typical use.
Special thanks to Sergee for implementing this feature and enduring my complaints on the bugtracker!
(closes issue #11196, reported and patched by sergee)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89946 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-28 00:47:22 +00:00
|
|
|
/* Let's check if this channel already had a moh class before */
|
|
|
|
if (state && state->class) {
|
|
|
|
/* Class already exist for this channel */
|
|
|
|
ast_log(LOG_NOTICE, "This channel already has a MOH class attached (%s)!\n", state->class->name);
|
|
|
|
if (state->class->realtime && !ast_test_flag(global_flags, MOH_CACHERTCLASSES) && !strcasecmp(mohclass->name, state->class->name)) {
|
|
|
|
/* we found RT class with the same name, seems like we should continue playing existing one */
|
2009-04-09 17:30:39 +00:00
|
|
|
mohclass = mohclass_unref(mohclass, "unreffing potential mohclass (channel already has one)");
|
2014-03-06 23:43:34 +00:00
|
|
|
mohclass = mohclass_ref(state->class, "using existing class from state");
|
Adding support for realtime music on hold. The following are the main points:
1. When moh is started, we search first in memory to find the class. If we do not
find it in memory, we search realtime instead.
2. When moh is restarted (as in, it had been started on this particular channel, stopped,
and now we're starting it again), if using the "files" mode, then realtime will always
be rechecked. If you are using other modes, however, we will simply reattach to the external
running process which was playing moh earlier in the call. This is a necessary compromise so that
we don't end up with too many background processes.
3. musiconhold.conf has a general section now. It has one option: cachertclasses. If set to yes,
then moh classes found in realtime will be added to the in-memory list. This has the advantage
of not requiring database lookups each time moh is started, but it has the disadvantage of not
truly being realtime.
I have tested this for functionality, and it passes. I also tested this under valgrind and there
are no memory problems reported under typical use.
Special thanks to Sergee for implementing this feature and enduring my complaints on the bugtracker!
(closes issue #11196, reported and patched by sergee)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89946 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-28 00:47:22 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (ast_pthread_create_background(&mohclass->thread, NULL, monmp3thread, mohclass)) {
|
|
|
|
ast_log(LOG_WARNING, "Unable to create moh...\n");
|
2010-08-26 23:51:55 +00:00
|
|
|
if (mohclass->timer) {
|
|
|
|
ast_timer_close(mohclass->timer);
|
|
|
|
mohclass->timer = NULL;
|
2008-12-22 16:10:40 +00:00
|
|
|
}
|
2009-04-09 17:30:39 +00:00
|
|
|
mohclass = mohclass_unref(mohclass, "Unreffing potential mohclass (failed to create background thread)");
|
Adding support for realtime music on hold. The following are the main points:
1. When moh is started, we search first in memory to find the class. If we do not
find it in memory, we search realtime instead.
2. When moh is restarted (as in, it had been started on this particular channel, stopped,
and now we're starting it again), if using the "files" mode, then realtime will always
be rechecked. If you are using other modes, however, we will simply reattach to the external
running process which was playing moh earlier in the call. This is a necessary compromise so that
we don't end up with too many background processes.
3. musiconhold.conf has a general section now. It has one option: cachertclasses. If set to yes,
then moh classes found in realtime will be added to the in-memory list. This has the advantage
of not requiring database lookups each time moh is started, but it has the disadvantage of not
truly being realtime.
I have tested this for functionality, and it passes. I also tested this under valgrind and there
are no memory problems reported under typical use.
Special thanks to Sergee for implementing this feature and enduring my complaints on the bugtracker!
(closes issue #11196, reported and patched by sergee)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89946 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-28 00:47:22 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ast_log(LOG_WARNING, "Don't know how to do a mode '%s' music on hold\n", mohclass->mode);
|
2009-04-09 17:30:39 +00:00
|
|
|
mohclass = mohclass_unref(mohclass, "unreffing potential mohclass (unknown mode)");
|
Adding support for realtime music on hold. The following are the main points:
1. When moh is started, we search first in memory to find the class. If we do not
find it in memory, we search realtime instead.
2. When moh is restarted (as in, it had been started on this particular channel, stopped,
and now we're starting it again), if using the "files" mode, then realtime will always
be rechecked. If you are using other modes, however, we will simply reattach to the external
running process which was playing moh earlier in the call. This is a necessary compromise so that
we don't end up with too many background processes.
3. musiconhold.conf has a general section now. It has one option: cachertclasses. If set to yes,
then moh classes found in realtime will be added to the in-memory list. This has the advantage
of not requiring database lookups each time moh is started, but it has the disadvantage of not
truly being realtime.
I have tested this for functionality, and it passes. I also tested this under valgrind and there
are no memory problems reported under typical use.
Special thanks to Sergee for implementing this feature and enduring my complaints on the bugtracker!
(closes issue #11196, reported and patched by sergee)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89946 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-28 00:47:22 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2009-07-27 20:11:42 +00:00
|
|
|
} else {
|
2007-11-28 23:03:09 +00:00
|
|
|
ast_variables_destroy(var);
|
2011-11-12 00:36:37 +00:00
|
|
|
var = NULL;
|
2008-12-22 16:10:40 +00:00
|
|
|
}
|
Adding support for realtime music on hold. The following are the main points:
1. When moh is started, we search first in memory to find the class. If we do not
find it in memory, we search realtime instead.
2. When moh is restarted (as in, it had been started on this particular channel, stopped,
and now we're starting it again), if using the "files" mode, then realtime will always
be rechecked. If you are using other modes, however, we will simply reattach to the external
running process which was playing moh earlier in the call. This is a necessary compromise so that
we don't end up with too many background processes.
3. musiconhold.conf has a general section now. It has one option: cachertclasses. If set to yes,
then moh classes found in realtime will be added to the in-memory list. This has the advantage
of not requiring database lookups each time moh is started, but it has the disadvantage of not
truly being realtime.
I have tested this for functionality, and it passes. I also tested this under valgrind and there
are no memory problems reported under typical use.
Special thanks to Sergee for implementing this feature and enduring my complaints on the bugtracker!
(closes issue #11196, reported and patched by sergee)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89946 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-28 00:47:22 +00:00
|
|
|
}
|
|
|
|
|
2008-12-22 16:10:40 +00:00
|
|
|
if (!mohclass) {
|
2004-12-24 01:40:07 +00:00
|
|
|
return -1;
|
2008-12-22 16:10:40 +00:00
|
|
|
}
|
2004-12-24 01:40:07 +00:00
|
|
|
|
2011-11-12 00:36:37 +00:00
|
|
|
/* If we are using a cached realtime class with files, re-scan the files */
|
|
|
|
if (!var && ast_test_flag(global_flags, MOH_CACHERTCLASSES) && mohclass->realtime && !strcasecmp(mohclass->mode, "files")) {
|
|
|
|
if (!moh_scan_files(mohclass)) {
|
|
|
|
mohclass = mohclass_unref(mohclass, "unreffing potential mohclass (moh_scan_files failed)");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-17 16:33:53 +00:00
|
|
|
if (!state || !state->class || strcmp(mohclass->name, state->class->name)) {
|
|
|
|
if (mohclass->total_files) {
|
|
|
|
res = ast_activate_generator(chan, &moh_file_stream, mohclass);
|
|
|
|
} else {
|
|
|
|
res = ast_activate_generator(chan, &mohgen, mohclass);
|
|
|
|
}
|
2008-12-22 16:10:40 +00:00
|
|
|
}
|
2014-03-12 19:06:52 +00:00
|
|
|
if (!res) {
|
|
|
|
ast_channel_latest_musicclass_set(chan, mohclass->name);
|
|
|
|
ast_set_flag(ast_channel_flags(chan), AST_FLAG_MOH);
|
2013-05-24 20:44:07 +00:00
|
|
|
}
|
|
|
|
|
2009-04-09 17:30:39 +00:00
|
|
|
mohclass = mohclass_unref(mohclass, "unreffing local reference to mohclass in local_ast_moh_start");
|
2008-12-22 16:10:40 +00:00
|
|
|
|
|
|
|
return res;
|
2002-06-29 21:46:57 +00:00
|
|
|
}
|
|
|
|
|
2004-12-09 19:55:01 +00:00
|
|
|
static void local_ast_moh_stop(struct ast_channel *chan)
|
2002-06-29 21:46:57 +00:00
|
|
|
{
|
2012-03-13 18:20:34 +00:00
|
|
|
ast_clear_flag(ast_channel_flags(chan), AST_FLAG_MOH);
|
2002-06-29 21:46:57 +00:00
|
|
|
ast_deactivate_generator(chan);
|
2004-12-24 01:40:07 +00:00
|
|
|
|
2010-04-30 20:11:02 +00:00
|
|
|
ast_channel_lock(chan);
|
2012-02-20 23:43:27 +00:00
|
|
|
if (ast_channel_music_state(chan)) {
|
|
|
|
if (ast_channel_stream(chan)) {
|
|
|
|
ast_closestream(ast_channel_stream(chan));
|
|
|
|
ast_channel_stream_set(chan, NULL);
|
2004-12-24 01:40:07 +00:00
|
|
|
}
|
|
|
|
}
|
2010-04-30 20:11:02 +00:00
|
|
|
ast_channel_unlock(chan);
|
2002-06-29 21:46:57 +00:00
|
|
|
}
|
|
|
|
|
2008-12-22 16:10:40 +00:00
|
|
|
static void moh_class_destructor(void *obj)
|
|
|
|
{
|
|
|
|
struct mohclass *class = obj;
|
|
|
|
struct mohdata *member;
|
2009-12-03 00:08:55 +00:00
|
|
|
pthread_t tid = 0;
|
2008-12-22 16:10:40 +00:00
|
|
|
|
|
|
|
ast_debug(1, "Destroying MOH class '%s'\n", class->name);
|
|
|
|
|
Fix timing source dependency issues with MOH
Prior to this patch, res_musiconhold existed at the same module priority level
as the timing sources that it depends on. This would cause a problem when
music on hold was reloaded, as the timing source could be changed after
res_musiconhold was processed. This patch adds a new module priority level,
AST_MODPRI_TIMING, that the various timing modules are now loaded at. This
now occurs before loading other resource modules, such that the timing source
is guaranteed to be set prior to resolving the timing source dependencies.
(closes issue ASTERISK-17474)
Reporter: Luke H
Tested by: Luke H, Vladimir Mikhelson, zzsurf, Wes Van Tlghem, elguero, Thomas Arimont
Patches:
asterisk-17474-dahdi_timing-infinite-wait-fix_v3_branch-1.8.diff uploaded by elguero (License #5026)
asterisk-17474-dahdi_timing-infinite-wait-fix_v3_branch-10.diff uploaded by elguero (License #5026)
asterisk-17474-dahdi_timing-infinite-wait-fix_v3.diff uploaded by elguero (License #5026)
Review: https://reviewboard.asterisk.org/r/1578/
........
Merged revisions 349194 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........
Merged revisions 349195 from http://svn.asterisk.org/svn/asterisk/branches/10
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@349196 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2011-12-27 20:55:15 +00:00
|
|
|
ao2_lock(class);
|
|
|
|
while ((member = AST_LIST_REMOVE_HEAD(&class->members, list))) {
|
2014-05-14 15:41:42 +00:00
|
|
|
ast_free(member);
|
Fix timing source dependency issues with MOH
Prior to this patch, res_musiconhold existed at the same module priority level
as the timing sources that it depends on. This would cause a problem when
music on hold was reloaded, as the timing source could be changed after
res_musiconhold was processed. This patch adds a new module priority level,
AST_MODPRI_TIMING, that the various timing modules are now loaded at. This
now occurs before loading other resource modules, such that the timing source
is guaranteed to be set prior to resolving the timing source dependencies.
(closes issue ASTERISK-17474)
Reporter: Luke H
Tested by: Luke H, Vladimir Mikhelson, zzsurf, Wes Van Tlghem, elguero, Thomas Arimont
Patches:
asterisk-17474-dahdi_timing-infinite-wait-fix_v3_branch-1.8.diff uploaded by elguero (License #5026)
asterisk-17474-dahdi_timing-infinite-wait-fix_v3_branch-10.diff uploaded by elguero (License #5026)
asterisk-17474-dahdi_timing-infinite-wait-fix_v3.diff uploaded by elguero (License #5026)
Review: https://reviewboard.asterisk.org/r/1578/
........
Merged revisions 349194 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........
Merged revisions 349195 from http://svn.asterisk.org/svn/asterisk/branches/10
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@349196 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2011-12-27 20:55:15 +00:00
|
|
|
}
|
|
|
|
ao2_unlock(class);
|
|
|
|
|
2009-12-03 00:08:55 +00:00
|
|
|
/* Kill the thread first, so it cannot restart the child process while the
|
|
|
|
* class is being destroyed */
|
|
|
|
if (class->thread != AST_PTHREADT_NULL && class->thread != 0) {
|
|
|
|
tid = class->thread;
|
|
|
|
class->thread = AST_PTHREADT_NULL;
|
|
|
|
pthread_cancel(tid);
|
|
|
|
/* We'll collect the exit status later, after we ensure all the readers
|
|
|
|
* are dead. */
|
|
|
|
}
|
|
|
|
|
2008-12-22 16:10:40 +00:00
|
|
|
if (class->pid > 1) {
|
|
|
|
char buff[8192];
|
|
|
|
int bytes, tbytes = 0, stime = 0, pid = 0;
|
|
|
|
|
2011-02-04 16:55:39 +00:00
|
|
|
ast_debug(1, "killing %d!\n", class->pid);
|
2008-12-22 16:10:40 +00:00
|
|
|
|
|
|
|
stime = time(NULL) + 2;
|
|
|
|
pid = class->pid;
|
|
|
|
class->pid = 0;
|
|
|
|
|
|
|
|
/* Back when this was just mpg123, SIGKILL was fine. Now we need
|
|
|
|
* to give the process a reason and time enough to kill off its
|
|
|
|
* children. */
|
2009-12-03 00:08:55 +00:00
|
|
|
do {
|
|
|
|
if (killpg(pid, SIGHUP) < 0) {
|
|
|
|
ast_log(LOG_WARNING, "Unable to send a SIGHUP to MOH process?!!: %s\n", strerror(errno));
|
|
|
|
}
|
|
|
|
usleep(100000);
|
|
|
|
if (killpg(pid, SIGTERM) < 0) {
|
|
|
|
if (errno == ESRCH) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ast_log(LOG_WARNING, "Unable to terminate MOH process?!!: %s\n", strerror(errno));
|
|
|
|
}
|
|
|
|
usleep(100000);
|
|
|
|
if (killpg(pid, SIGKILL) < 0) {
|
|
|
|
if (errno == ESRCH) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ast_log(LOG_WARNING, "Unable to kill MOH process?!!: %s\n", strerror(errno));
|
|
|
|
}
|
|
|
|
} while (0);
|
2008-12-22 16:10:40 +00:00
|
|
|
|
|
|
|
while ((ast_wait_for_input(class->srcfd, 100) > 0) &&
|
|
|
|
(bytes = read(class->srcfd, buff, 8192)) && time(NULL) < stime) {
|
|
|
|
tbytes = tbytes + bytes;
|
|
|
|
}
|
|
|
|
|
2011-02-04 16:55:39 +00:00
|
|
|
ast_debug(1, "mpg123 pid %d and child died after %d bytes read\n", pid, tbytes);
|
2008-12-22 16:10:40 +00:00
|
|
|
|
|
|
|
close(class->srcfd);
|
Fix timing source dependency issues with MOH
Prior to this patch, res_musiconhold existed at the same module priority level
as the timing sources that it depends on. This would cause a problem when
music on hold was reloaded, as the timing source could be changed after
res_musiconhold was processed. This patch adds a new module priority level,
AST_MODPRI_TIMING, that the various timing modules are now loaded at. This
now occurs before loading other resource modules, such that the timing source
is guaranteed to be set prior to resolving the timing source dependencies.
(closes issue ASTERISK-17474)
Reporter: Luke H
Tested by: Luke H, Vladimir Mikhelson, zzsurf, Wes Van Tlghem, elguero, Thomas Arimont
Patches:
asterisk-17474-dahdi_timing-infinite-wait-fix_v3_branch-1.8.diff uploaded by elguero (License #5026)
asterisk-17474-dahdi_timing-infinite-wait-fix_v3_branch-10.diff uploaded by elguero (License #5026)
asterisk-17474-dahdi_timing-infinite-wait-fix_v3.diff uploaded by elguero (License #5026)
Review: https://reviewboard.asterisk.org/r/1578/
........
Merged revisions 349194 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........
Merged revisions 349195 from http://svn.asterisk.org/svn/asterisk/branches/10
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@349196 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2011-12-27 20:55:15 +00:00
|
|
|
class->srcfd = -1;
|
2008-12-22 16:10:40 +00:00
|
|
|
}
|
Merged revisions 201600 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r201600 | russell | 2009-06-18 10:24:31 -0500 (Thu, 18 Jun 2009) | 29 lines
Fix memory corruption and leakage related reloads of non files mode MoH classes.
For Music on Hold classes that are not files mode, meaning that we are executing
an application that will feed us audio data, we use a thread to monitor the
external application and read audio from it. This thread also makes use of the
MoH class object. In the MoH class destructor, we used pthread_cancel() to ask
the thread to exit. Unfortunately, the code did not wait to ensure that the
thread actually went away. What needed to be done is a pthread_join() to ensure
that the thread fully cleans up before we proceed. By adding this one line, we
resolve two significant problems:
1) Since the thread was never joined, it never fully goes away. So, on every
reload of non-files mode MoH, an unused thread was sticking around.
2) There was a race condition here where the application monitoring thread
could still try to access the MoH class, even though the thread executing
the MoH reload has already destroyed it.
(issue #15109)
Reported by: jvandal
(issue #15123)
Reported by: axisinternet
(issue #15195)
Reported by: amorsen
(issue AST-208)
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@201610 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-06-18 15:27:10 +00:00
|
|
|
|
2008-12-22 16:10:40 +00:00
|
|
|
if (class->filearray) {
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < class->total_files; i++) {
|
2014-05-14 15:41:42 +00:00
|
|
|
ast_free(class->filearray[i]);
|
2008-12-22 16:10:40 +00:00
|
|
|
}
|
2014-05-14 15:41:42 +00:00
|
|
|
ast_free(class->filearray);
|
2008-12-22 16:10:40 +00:00
|
|
|
class->filearray = NULL;
|
|
|
|
}
|
2009-12-03 00:08:55 +00:00
|
|
|
|
2011-02-01 17:05:38 +00:00
|
|
|
if (class->timer) {
|
|
|
|
ast_timer_close(class->timer);
|
|
|
|
class->timer = NULL;
|
|
|
|
}
|
|
|
|
|
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(class->format);
|
|
|
|
|
2009-12-03 00:08:55 +00:00
|
|
|
/* Finally, collect the exit status of the monitor thread */
|
|
|
|
if (tid > 0) {
|
|
|
|
pthread_join(tid, NULL);
|
|
|
|
}
|
Fix timing source dependency issues with MOH
Prior to this patch, res_musiconhold existed at the same module priority level
as the timing sources that it depends on. This would cause a problem when
music on hold was reloaded, as the timing source could be changed after
res_musiconhold was processed. This patch adds a new module priority level,
AST_MODPRI_TIMING, that the various timing modules are now loaded at. This
now occurs before loading other resource modules, such that the timing source
is guaranteed to be set prior to resolving the timing source dependencies.
(closes issue ASTERISK-17474)
Reporter: Luke H
Tested by: Luke H, Vladimir Mikhelson, zzsurf, Wes Van Tlghem, elguero, Thomas Arimont
Patches:
asterisk-17474-dahdi_timing-infinite-wait-fix_v3_branch-1.8.diff uploaded by elguero (License #5026)
asterisk-17474-dahdi_timing-infinite-wait-fix_v3_branch-10.diff uploaded by elguero (License #5026)
asterisk-17474-dahdi_timing-infinite-wait-fix_v3.diff uploaded by elguero (License #5026)
Review: https://reviewboard.asterisk.org/r/1578/
........
Merged revisions 349194 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........
Merged revisions 349195 from http://svn.asterisk.org/svn/asterisk/branches/10
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@349196 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2011-12-27 20:55:15 +00:00
|
|
|
|
2008-12-22 16:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int moh_class_mark(void *obj, void *arg, int flags)
|
|
|
|
{
|
|
|
|
struct mohclass *class = obj;
|
|
|
|
|
|
|
|
class->delete = 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int moh_classes_delete_marked(void *obj, void *arg, int flags)
|
|
|
|
{
|
|
|
|
struct mohclass *class = obj;
|
|
|
|
|
2009-12-08 18:22:44 +00:00
|
|
|
return class->delete ? CMP_MATCH : 0;
|
2008-12-22 16:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int load_moh_classes(int reload)
|
2002-06-29 21:46:57 +00:00
|
|
|
{
|
|
|
|
struct ast_config *cfg;
|
|
|
|
struct ast_variable *var;
|
2005-08-22 19:29:29 +00:00
|
|
|
struct mohclass *class;
|
|
|
|
char *cat;
|
|
|
|
int numclasses = 0;
|
2008-12-22 16:10:40 +00:00
|
|
|
struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
|
2005-01-09 09:00:41 +00:00
|
|
|
|
2007-08-16 21:09:46 +00:00
|
|
|
cfg = ast_config_load("musiconhold.conf", config_flags);
|
2005-01-09 09:00:41 +00:00
|
|
|
|
2011-06-30 19:31:51 +00:00
|
|
|
if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEINVALID) {
|
2010-06-23 21:53:49 +00:00
|
|
|
if (ast_check_realtime("musiconhold") && reload) {
|
|
|
|
ao2_t_callback(mohclasses, OBJ_NODATA, moh_class_mark, NULL, "Mark deleted classes");
|
|
|
|
ao2_t_callback(mohclasses, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, moh_classes_delete_marked, NULL, "Purge marked classes");
|
|
|
|
}
|
2011-06-30 19:31:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
|
|
|
|
moh_rescan_files();
|
2005-01-09 09:00:41 +00:00
|
|
|
return 0;
|
2008-09-12 23:30:03 +00:00
|
|
|
}
|
2005-01-09 09:00:41 +00:00
|
|
|
|
2008-12-22 16:10:40 +00:00
|
|
|
if (reload) {
|
2009-04-09 17:30:39 +00:00
|
|
|
ao2_t_callback(mohclasses, OBJ_NODATA, moh_class_mark, NULL, "Mark deleted classes");
|
2007-08-16 22:30:39 +00:00
|
|
|
}
|
2010-08-26 23:51:55 +00:00
|
|
|
|
Adding support for realtime music on hold. The following are the main points:
1. When moh is started, we search first in memory to find the class. If we do not
find it in memory, we search realtime instead.
2. When moh is restarted (as in, it had been started on this particular channel, stopped,
and now we're starting it again), if using the "files" mode, then realtime will always
be rechecked. If you are using other modes, however, we will simply reattach to the external
running process which was playing moh earlier in the call. This is a necessary compromise so that
we don't end up with too many background processes.
3. musiconhold.conf has a general section now. It has one option: cachertclasses. If set to yes,
then moh classes found in realtime will be added to the in-memory list. This has the advantage
of not requiring database lookups each time moh is started, but it has the disadvantage of not
truly being realtime.
I have tested this for functionality, and it passes. I also tested this under valgrind and there
are no memory problems reported under typical use.
Special thanks to Sergee for implementing this feature and enduring my complaints on the bugtracker!
(closes issue #11196, reported and patched by sergee)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89946 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-28 00:47:22 +00:00
|
|
|
ast_clear_flag(global_flags, AST_FLAGS_ALL);
|
2014-09-25 20:49:04 +00:00
|
|
|
ast_set2_flag(global_flags, 1, MOH_PREFERCHANNELCLASS);
|
2007-08-16 22:30:39 +00:00
|
|
|
|
2005-08-22 19:29:29 +00:00
|
|
|
cat = ast_category_browse(cfg, NULL);
|
|
|
|
for (; cat; cat = ast_category_browse(cfg, cat)) {
|
Adding support for realtime music on hold. The following are the main points:
1. When moh is started, we search first in memory to find the class. If we do not
find it in memory, we search realtime instead.
2. When moh is restarted (as in, it had been started on this particular channel, stopped,
and now we're starting it again), if using the "files" mode, then realtime will always
be rechecked. If you are using other modes, however, we will simply reattach to the external
running process which was playing moh earlier in the call. This is a necessary compromise so that
we don't end up with too many background processes.
3. musiconhold.conf has a general section now. It has one option: cachertclasses. If set to yes,
then moh classes found in realtime will be added to the in-memory list. This has the advantage
of not requiring database lookups each time moh is started, but it has the disadvantage of not
truly being realtime.
I have tested this for functionality, and it passes. I also tested this under valgrind and there
are no memory problems reported under typical use.
Special thanks to Sergee for implementing this feature and enduring my complaints on the bugtracker!
(closes issue #11196, reported and patched by sergee)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89946 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-28 00:47:22 +00:00
|
|
|
/* Setup common options from [general] section */
|
|
|
|
if (!strcasecmp(cat, "general")) {
|
2008-12-22 16:10:40 +00:00
|
|
|
for (var = ast_variable_browse(cfg, cat); var; var = var->next) {
|
Adding support for realtime music on hold. The following are the main points:
1. When moh is started, we search first in memory to find the class. If we do not
find it in memory, we search realtime instead.
2. When moh is restarted (as in, it had been started on this particular channel, stopped,
and now we're starting it again), if using the "files" mode, then realtime will always
be rechecked. If you are using other modes, however, we will simply reattach to the external
running process which was playing moh earlier in the call. This is a necessary compromise so that
we don't end up with too many background processes.
3. musiconhold.conf has a general section now. It has one option: cachertclasses. If set to yes,
then moh classes found in realtime will be added to the in-memory list. This has the advantage
of not requiring database lookups each time moh is started, but it has the disadvantage of not
truly being realtime.
I have tested this for functionality, and it passes. I also tested this under valgrind and there
are no memory problems reported under typical use.
Special thanks to Sergee for implementing this feature and enduring my complaints on the bugtracker!
(closes issue #11196, reported and patched by sergee)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89946 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-28 00:47:22 +00:00
|
|
|
if (!strcasecmp(var->name, "cachertclasses")) {
|
|
|
|
ast_set2_flag(global_flags, ast_true(var->value), MOH_CACHERTCLASSES);
|
2014-09-25 20:49:04 +00:00
|
|
|
} else if (!strcasecmp(var->name, "preferchannelclass")) {
|
|
|
|
ast_set2_flag(global_flags, ast_true(var->value), MOH_PREFERCHANNELCLASS);
|
Adding support for realtime music on hold. The following are the main points:
1. When moh is started, we search first in memory to find the class. If we do not
find it in memory, we search realtime instead.
2. When moh is restarted (as in, it had been started on this particular channel, stopped,
and now we're starting it again), if using the "files" mode, then realtime will always
be rechecked. If you are using other modes, however, we will simply reattach to the external
running process which was playing moh earlier in the call. This is a necessary compromise so that
we don't end up with too many background processes.
3. musiconhold.conf has a general section now. It has one option: cachertclasses. If set to yes,
then moh classes found in realtime will be added to the in-memory list. This has the advantage
of not requiring database lookups each time moh is started, but it has the disadvantage of not
truly being realtime.
I have tested this for functionality, and it passes. I also tested this under valgrind and there
are no memory problems reported under typical use.
Special thanks to Sergee for implementing this feature and enduring my complaints on the bugtracker!
(closes issue #11196, reported and patched by sergee)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89946 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-28 00:47:22 +00:00
|
|
|
} else {
|
|
|
|
ast_log(LOG_WARNING, "Unknown option '%s' in [general] section of musiconhold.conf\n", var->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-05-22 18:52:59 +00:00
|
|
|
|
2008-12-22 16:10:40 +00:00
|
|
|
if (!(class = moh_class_malloc())) {
|
|
|
|
break;
|
|
|
|
}
|
2005-08-22 19:29:29 +00:00
|
|
|
|
2014-09-14 15:41:58 +00:00
|
|
|
moh_parse_options(ast_variable_browse(cfg, cat), class);
|
|
|
|
/* For compatibility with the past, we overwrite any name=name
|
|
|
|
* with the context [name]. */
|
2012-01-23 18:34:47 +00:00
|
|
|
ast_copy_string(class->name, cat, sizeof(class->name));
|
2008-12-22 16:10:40 +00:00
|
|
|
|
|
|
|
if (ast_strlen_zero(class->dir)) {
|
|
|
|
if (!strcasecmp(class->mode, "custom")) {
|
|
|
|
strcpy(class->dir, "nodir");
|
|
|
|
} else {
|
|
|
|
ast_log(LOG_WARNING, "A directory must be specified for class '%s'!\n", class->name);
|
2009-04-09 17:30:39 +00:00
|
|
|
class = mohclass_unref(class, "unreffing potential mohclass (no directory)");
|
2005-08-22 19:29:29 +00:00
|
|
|
continue;
|
|
|
|
}
|
2008-12-22 16:10:40 +00:00
|
|
|
}
|
|
|
|
if (ast_strlen_zero(class->mode)) {
|
|
|
|
ast_log(LOG_WARNING, "A mode must be specified for class '%s'!\n", class->name);
|
2009-04-09 17:30:39 +00:00
|
|
|
class = mohclass_unref(class, "unreffing potential mohclass (no mode)");
|
2008-12-22 16:10:40 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (ast_strlen_zero(class->args) && !strcasecmp(class->mode, "custom")) {
|
|
|
|
ast_log(LOG_WARNING, "An application must be specified for class '%s'!\n", class->name);
|
2009-04-09 17:30:39 +00:00
|
|
|
class = mohclass_unref(class, "unreffing potential mohclass (no app for custom mode)");
|
2008-12-22 16:10:40 +00:00
|
|
|
continue;
|
|
|
|
}
|
2005-08-22 19:29:29 +00:00
|
|
|
|
2008-12-22 16:10:40 +00:00
|
|
|
/* Don't leak a class when it's already registered */
|
2009-12-03 00:08:55 +00:00
|
|
|
if (!moh_register(class, reload, HANDLE_REF)) {
|
2009-04-08 16:52:20 +00:00
|
|
|
numclasses++;
|
|
|
|
}
|
2005-08-22 19:29:29 +00:00
|
|
|
}
|
2007-07-12 15:55:49 +00:00
|
|
|
|
2005-01-25 06:10:20 +00:00
|
|
|
ast_config_destroy(cfg);
|
2005-08-22 19:29:29 +00:00
|
|
|
|
2009-04-09 17:30:39 +00:00
|
|
|
ao2_t_callback(mohclasses, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE,
|
|
|
|
moh_classes_delete_marked, NULL, "Purge marked classes");
|
2007-08-16 22:30:39 +00:00
|
|
|
|
2008-12-22 16:10:40 +00:00
|
|
|
return numclasses;
|
2003-03-04 06:00:19 +00:00
|
|
|
}
|
|
|
|
|
2007-08-16 22:30:39 +00:00
|
|
|
static void ast_moh_destroy(void)
|
2005-06-06 02:29:18 +00:00
|
|
|
{
|
2007-08-16 22:30:39 +00:00
|
|
|
ast_verb(2, "Destroying musiconhold processes\n");
|
2012-10-02 01:47:16 +00:00
|
|
|
if (mohclasses) {
|
|
|
|
ao2_t_callback(mohclasses, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, NULL, NULL, "Destroy callback");
|
|
|
|
ao2_ref(mohclasses, -1);
|
|
|
|
mohclasses = NULL;
|
|
|
|
}
|
2004-12-24 01:40:07 +00:00
|
|
|
}
|
|
|
|
|
2007-09-18 22:43:45 +00:00
|
|
|
static char *handle_cli_moh_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
|
2004-12-24 01:40:07 +00:00
|
|
|
{
|
2007-09-18 22:43:45 +00:00
|
|
|
switch (cmd) {
|
|
|
|
case CLI_INIT:
|
|
|
|
e->command = "moh reload";
|
|
|
|
e->usage =
|
|
|
|
"Usage: moh reload\n"
|
|
|
|
" Reloads the MusicOnHold module.\n"
|
|
|
|
" Alias for 'module reload res_musiconhold.so'\n";
|
|
|
|
return NULL;
|
|
|
|
case CLI_GENERATE:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (a->argc != e->args)
|
|
|
|
return CLI_SHOWUSAGE;
|
|
|
|
|
2016-01-13 13:20:24 +00:00
|
|
|
/* The module loader will prevent concurrent reloads from occurring, so we delegate */
|
|
|
|
ast_module_reload("res_musiconhold");
|
2005-01-09 09:00:41 +00:00
|
|
|
|
2007-09-18 22:43:45 +00:00
|
|
|
return CLI_SUCCESS;
|
2004-12-24 01:40:07 +00:00
|
|
|
}
|
|
|
|
|
2007-09-18 22:43:45 +00:00
|
|
|
static char *handle_cli_moh_show_files(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
|
2005-01-03 00:38:01 +00:00
|
|
|
{
|
|
|
|
struct mohclass *class;
|
2008-12-22 16:10:40 +00:00
|
|
|
struct ao2_iterator i;
|
2005-01-03 00:38:01 +00:00
|
|
|
|
2007-09-18 22:43:45 +00:00
|
|
|
switch (cmd) {
|
|
|
|
case CLI_INIT:
|
|
|
|
e->command = "moh show files";
|
|
|
|
e->usage =
|
|
|
|
"Usage: moh show files\n"
|
|
|
|
" Lists all loaded file-based MusicOnHold classes and their\n"
|
|
|
|
" files.\n";
|
|
|
|
return NULL;
|
|
|
|
case CLI_GENERATE:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (a->argc != e->args)
|
|
|
|
return CLI_SHOWUSAGE;
|
|
|
|
|
2008-12-22 16:10:40 +00:00
|
|
|
i = ao2_iterator_init(mohclasses, 0);
|
2009-04-09 17:30:39 +00:00
|
|
|
for (; (class = ao2_t_iterator_next(&i, "Show files iterator")); mohclass_unref(class, "Unref iterator in moh show files")) {
|
2008-12-22 16:10:40 +00:00
|
|
|
int x;
|
|
|
|
|
|
|
|
if (!class->total_files) {
|
2005-01-03 00:38:01 +00:00
|
|
|
continue;
|
2008-12-22 16:10:40 +00:00
|
|
|
}
|
2005-01-03 00:38:01 +00:00
|
|
|
|
2007-09-18 22:43:45 +00:00
|
|
|
ast_cli(a->fd, "Class: %s\n", class->name);
|
2008-12-22 16:10:40 +00:00
|
|
|
for (x = 0; x < class->total_files; x++) {
|
|
|
|
ast_cli(a->fd, "\tFile: %s\n", class->filearray[x]);
|
|
|
|
}
|
2005-01-03 00:38:01 +00:00
|
|
|
}
|
2009-10-06 01:24:24 +00:00
|
|
|
ao2_iterator_destroy(&i);
|
2005-01-03 00:38:01 +00:00
|
|
|
|
2007-09-18 22:43:45 +00:00
|
|
|
return CLI_SUCCESS;
|
2005-01-03 00:38:01 +00:00
|
|
|
}
|
|
|
|
|
2007-09-18 22:43:45 +00:00
|
|
|
static char *handle_cli_moh_show_classes(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
|
2005-08-22 19:29:29 +00:00
|
|
|
{
|
|
|
|
struct mohclass *class;
|
2008-12-22 16:10:40 +00:00
|
|
|
struct ao2_iterator i;
|
2005-08-22 19:29:29 +00:00
|
|
|
|
2007-09-18 22:43:45 +00:00
|
|
|
switch (cmd) {
|
|
|
|
case CLI_INIT:
|
|
|
|
e->command = "moh show classes";
|
|
|
|
e->usage =
|
|
|
|
"Usage: moh show classes\n"
|
|
|
|
" Lists all MusicOnHold classes.\n";
|
|
|
|
return NULL;
|
|
|
|
case CLI_GENERATE:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (a->argc != e->args)
|
|
|
|
return CLI_SHOWUSAGE;
|
|
|
|
|
2008-12-22 16:10:40 +00:00
|
|
|
i = ao2_iterator_init(mohclasses, 0);
|
2009-04-09 17:30:39 +00:00
|
|
|
for (; (class = ao2_t_iterator_next(&i, "Show classes iterator")); mohclass_unref(class, "Unref iterator in moh show classes")) {
|
2007-09-18 22:43:45 +00:00
|
|
|
ast_cli(a->fd, "Class: %s\n", class->name);
|
|
|
|
ast_cli(a->fd, "\tMode: %s\n", S_OR(class->mode, "<none>"));
|
|
|
|
ast_cli(a->fd, "\tDirectory: %s\n", S_OR(class->dir, "<none>"));
|
2008-12-22 16:10:40 +00:00
|
|
|
if (ast_test_flag(class, MOH_CUSTOM)) {
|
2007-09-18 22:43:45 +00:00
|
|
|
ast_cli(a->fd, "\tApplication: %s\n", S_OR(class->args, "<none>"));
|
2008-12-22 16:10:40 +00:00
|
|
|
}
|
|
|
|
if (strcasecmp(class->mode, "files")) {
|
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_cli(a->fd, "\tFormat: %s\n", ast_format_get_name(class->format));
|
2008-12-22 16:10:40 +00:00
|
|
|
}
|
2005-08-22 19:29:29 +00:00
|
|
|
}
|
2009-10-06 01:24:24 +00:00
|
|
|
ao2_iterator_destroy(&i);
|
2005-08-22 19:29:29 +00:00
|
|
|
|
2007-09-18 22:43:45 +00:00
|
|
|
return CLI_SUCCESS;
|
2005-08-22 19:29:29 +00:00
|
|
|
}
|
|
|
|
|
2006-09-18 19:54:18 +00:00
|
|
|
static struct ast_cli_entry cli_moh[] = {
|
2007-10-22 20:05:18 +00:00
|
|
|
AST_CLI_DEFINE(handle_cli_moh_reload, "Reload MusicOnHold"),
|
|
|
|
AST_CLI_DEFINE(handle_cli_moh_show_classes, "List MusicOnHold classes"),
|
|
|
|
AST_CLI_DEFINE(handle_cli_moh_show_files, "List MusicOnHold file-based classes")
|
2006-09-18 19:54:18 +00:00
|
|
|
};
|
2005-01-03 00:38:01 +00:00
|
|
|
|
2008-12-22 16:10:40 +00:00
|
|
|
static int moh_class_hash(const void *obj, const int flags)
|
2005-04-07 14:53:31 +00:00
|
|
|
{
|
2008-12-22 16:10:40 +00:00
|
|
|
const struct mohclass *class = obj;
|
|
|
|
|
|
|
|
return ast_str_case_hash(class->name);
|
|
|
|
}
|
2006-04-29 13:15:05 +00:00
|
|
|
|
2008-12-22 16:10:40 +00:00
|
|
|
static int moh_class_cmp(void *obj, void *arg, int flags)
|
|
|
|
{
|
|
|
|
struct mohclass *class = obj, *class2 = arg;
|
|
|
|
|
2009-12-03 00:08:55 +00:00
|
|
|
return strcasecmp(class->name, class2->name) ? 0 :
|
|
|
|
(flags & MOH_NOTDELETED) && (class->delete || class2->delete) ? 0 :
|
|
|
|
CMP_MATCH | CMP_STOP;
|
2005-01-04 19:09:00 +00:00
|
|
|
}
|
2004-12-24 01:40:07 +00:00
|
|
|
|
2012-10-01 23:24:10 +00:00
|
|
|
/*!
|
|
|
|
* \brief Load the module
|
|
|
|
*
|
|
|
|
* Module loading including tests for configuration or dependencies.
|
|
|
|
* This function can return AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_DECLINE,
|
|
|
|
* or AST_MODULE_LOAD_SUCCESS. If a dependency or environment variable fails
|
|
|
|
* tests return AST_MODULE_LOAD_FAILURE. If the module can not load the
|
|
|
|
* configuration file or other non-critical problem return
|
|
|
|
* AST_MODULE_LOAD_DECLINE. On success return AST_MODULE_LOAD_SUCCESS.
|
|
|
|
*/
|
2006-08-21 02:11:39 +00:00
|
|
|
static int load_module(void)
|
2002-06-29 21:46:57 +00:00
|
|
|
{
|
|
|
|
int res;
|
2005-01-09 09:00:41 +00:00
|
|
|
|
2009-04-09 17:30:39 +00:00
|
|
|
if (!(mohclasses = ao2_t_container_alloc(53, moh_class_hash, moh_class_cmp, "Moh class container"))) {
|
2008-12-22 16:10:40 +00:00
|
|
|
return AST_MODULE_LOAD_DECLINE;
|
|
|
|
}
|
|
|
|
|
2010-06-23 21:53:49 +00:00
|
|
|
if (!load_moh_classes(0) && ast_check_realtime("musiconhold") == 0) { /* No music classes configured, so skip it */
|
2008-12-22 16:10:40 +00:00
|
|
|
ast_log(LOG_WARNING, "No music on hold classes configured, "
|
|
|
|
"disabling music on hold.\n");
|
|
|
|
} else {
|
|
|
|
ast_install_music_functions(local_ast_moh_start, local_ast_moh_stop,
|
|
|
|
local_ast_moh_cleanup);
|
|
|
|
}
|
|
|
|
|
2009-06-06 23:03:15 +00:00
|
|
|
res = ast_register_application_xml(play_moh, play_moh_exec);
|
2003-08-07 03:48:00 +00:00
|
|
|
ast_register_atexit(ast_moh_destroy);
|
2008-12-05 10:31:25 +00:00
|
|
|
ast_cli_register_multiple(cli_moh, ARRAY_LEN(cli_moh));
|
2005-03-03 05:03:06 +00:00
|
|
|
if (!res)
|
2009-06-06 23:03:15 +00:00
|
|
|
res = ast_register_application_xml(start_moh, start_moh_exec);
|
2005-03-03 05:03:06 +00:00
|
|
|
if (!res)
|
2009-06-06 23:03:15 +00:00
|
|
|
res = ast_register_application_xml(stop_moh, stop_moh_exec);
|
2004-12-24 01:40:07 +00:00
|
|
|
|
2008-12-22 16:10:40 +00:00
|
|
|
return AST_MODULE_LOAD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int reload(void)
|
|
|
|
{
|
|
|
|
if (load_moh_classes(1)) {
|
|
|
|
ast_install_music_functions(local_ast_moh_start, local_ast_moh_stop,
|
|
|
|
local_ast_moh_cleanup);
|
2005-08-25 23:29:30 +00:00
|
|
|
}
|
2005-01-09 09:00:41 +00:00
|
|
|
|
2007-10-31 19:24:29 +00:00
|
|
|
return AST_MODULE_LOAD_SUCCESS;
|
2002-06-29 21:46:57 +00:00
|
|
|
}
|
|
|
|
|
2008-12-22 16:10:40 +00:00
|
|
|
static int moh_class_inuse(void *obj, void *arg, int flags)
|
2004-12-24 01:40:07 +00:00
|
|
|
{
|
2008-12-22 16:10:40 +00:00
|
|
|
struct mohclass *class = obj;
|
2004-12-24 01:40:07 +00:00
|
|
|
|
2008-12-22 16:10:40 +00:00
|
|
|
return AST_LIST_EMPTY(&class->members) ? 0 : CMP_MATCH | CMP_STOP;
|
2005-01-09 09:00:41 +00:00
|
|
|
}
|
2004-12-24 01:40:07 +00:00
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
static int unload_module(void)
|
2002-06-29 21:46:57 +00:00
|
|
|
{
|
2008-04-23 18:33:28 +00:00
|
|
|
int res = 0;
|
|
|
|
struct mohclass *class = NULL;
|
|
|
|
|
2008-12-22 16:10:40 +00:00
|
|
|
/* XXX This check shouldn't be required if module ref counting was being used
|
|
|
|
* properly ... */
|
2009-04-09 17:30:39 +00:00
|
|
|
if ((class = ao2_t_callback(mohclasses, 0, moh_class_inuse, NULL, "Module unload callback"))) {
|
|
|
|
class = mohclass_unref(class, "unref of class from module unload callback");
|
2008-12-22 16:10:40 +00:00
|
|
|
res = -1;
|
2008-04-23 18:33:28 +00:00
|
|
|
}
|
2008-12-22 16:10:40 +00:00
|
|
|
|
2008-04-23 18:33:28 +00:00
|
|
|
if (res < 0) {
|
|
|
|
ast_log(LOG_WARNING, "Unable to unload res_musiconhold due to active MOH channels\n");
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
ast_uninstall_music_functions();
|
2008-12-22 16:10:40 +00:00
|
|
|
|
2008-04-23 18:33:28 +00:00
|
|
|
ast_moh_destroy();
|
|
|
|
res = ast_unregister_application(play_moh);
|
|
|
|
res |= ast_unregister_application(start_moh);
|
|
|
|
res |= ast_unregister_application(stop_moh);
|
2008-12-05 10:31:25 +00:00
|
|
|
ast_cli_unregister_multiple(cli_moh, ARRAY_LEN(cli_moh));
|
2008-11-18 23:59:02 +00:00
|
|
|
ast_unregister_atexit(ast_moh_destroy);
|
2008-12-22 16:10:40 +00:00
|
|
|
|
2008-04-23 18:33:28 +00:00
|
|
|
return res;
|
2002-06-29 21:46:57 +00:00
|
|
|
}
|
|
|
|
|
2010-07-20 19:35:02 +00:00
|
|
|
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Music On Hold Resource",
|
2014-07-25 16:47:17 +00:00
|
|
|
.support_level = AST_MODULE_SUPPORT_CORE,
|
2008-12-22 16:10:40 +00:00
|
|
|
.load = load_module,
|
|
|
|
.unload = unload_module,
|
|
|
|
.reload = reload,
|
2010-07-20 19:35:02 +00:00
|
|
|
.load_pri = AST_MODPRI_CHANNEL_DEPEND,
|
2008-12-22 16:10:40 +00:00
|
|
|
);
|