2009-04-02 17:20:52 +00:00
/*
* Asterisk - - An open source telephony toolkit .
*
* Copyright ( C ) 1999 - 2008 , Digium , Inc .
*
* Mark Spencer < markster @ digium . com >
*
* See http : //www.asterisk.org for more information about
* the Asterisk project . Please do not directly contact
* any of the maintainers of this project for assistance ;
* the project provides a web site , mailing lists and IRC
* channels for your use .
*
* This program is free software , distributed under the terms of
* the GNU General Public License Version 2. See the LICENSE file
* at the top of the source tree .
*/
/*!
* \ file
*
* \ brief Supports RTP and RTCP with Symmetric RTP support for NAT traversal .
*
* \ author Mark Spencer < markster @ digium . com >
*
* \ note RTP is defined in RFC 3550.
2009-10-30 04:08:39 +00:00
*
* \ ingroup rtp_engines
2009-04-02 17:20:52 +00:00
*/
2011-07-14 20:28:54 +00:00
/*** MODULEINFO
2013-03-12 19:08:59 +00:00
< use type = " external " > pjproject < / use >
2011-07-14 20:28:54 +00:00
< support_level > core < / support_level >
* * */
2009-04-02 17:20:52 +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 ( )
2009-04-02 17:20:52 +00:00
# include <sys/time.h>
# include <signal.h>
# include <fcntl.h>
2012-09-20 18:27:28 +00:00
# ifdef HAVE_OPENSSL_SRTP
# include <openssl/ssl.h>
# include <openssl/err.h>
# include <openssl/bio.h>
# endif
2013-03-12 19:08:59 +00:00
# ifdef HAVE_PJPROJECT
# include <pjlib.h>
# include <pjlib-util.h>
# include <pjnath.h>
# endif
2012-07-01 17:28:57 +00:00
2009-04-02 17:20:52 +00:00
# include "asterisk/stun.h"
# include "asterisk/pbx.h"
# include "asterisk/frame.h"
media formats: re-architect handling of media for performance improvements
In the old times media formats were represented using a bit field. This was
fast but had a few limitations.
1. Asterisk was limited in how many formats it could handle.
2. Formats, being a bit field, could not include any attribute information.
A format was strictly its type, e.g., "this is ulaw".
This was changed in Asterisk 10 (see
https://wiki.asterisk.org/wiki/display/AST/Media+Architecture+Proposal for
notes on that work) which led to the creation of the ast_format structure.
This structure allowed Asterisk to handle attributes and bundle information
with a format.
Additionally, ast_format_cap was created to act as a container for multiple
formats that, together, formed the capability of some entity. Another
mechanism was added to allow logic to be registered which performed format
attribute negotiation. Everywhere throughout the codebase Asterisk was
changed to use this strategy.
Unfortunately, in software, there is no free lunch. These new capabilities
came at a cost.
Performance analysis and profiling showed that we spend an inordinate
amount of time comparing, copying, and generally manipulating formats and
their related structures. Basic prototyping has shown that a reasonably
large performance improvement could be made in this area. This patch is the
result of that project, which overhauled the media format architecture
and its usage in Asterisk to improve performance.
Generally, the new philosophy for handling formats is as follows:
* The ast_format structure is reference counted. This removed a large amount
of the memory allocations and copying that was done in prior versions.
* In order to prevent race conditions while keeping things performant, the
ast_format structure is immutable by convention and lock-free. Violate this
tenet at your peril!
* Because formats are reference counted, codecs are also reference counted.
The Asterisk core generally provides built-in codecs and caches the
ast_format structures created to represent them. Generally, to prevent
inordinate amounts of module reference bumping, codecs and formats can be
added at run-time but cannot be removed.
* All compatibility with the bit field representation of codecs/formats has
been moved to a compatibility API. The primary user of this representation
is chan_iax2, which must continue to maintain its bit-field usage of formats
for interoperability concerns.
* When a format is negotiated with attributes, or when a format cannot be
represented by one of the cached formats, a new format object is created or
cloned from an existing format. That format may have the same codec
underlying it, but is a different format than a version of the format with
different attributes or without attributes.
* While formats are reference counted objects, the reference count maintained
on the format should be manipulated with care. Formats are generally cached
and will persist for the lifetime of Asterisk and do not explicitly need
to have their lifetime modified. An exception to this is when the user of a
format does not know where the format came from *and* the user may outlive
the provider of the format. This occurs, for example, when a format is read
from a channel: the channel may have a format with attributes (hence,
non-cached) and the user of the format may last longer than the channel (if
the reference to the channel is released prior to the format's reference).
For more information on this work, see the API design notes:
https://wiki.asterisk.org/wiki/display/AST/Media+Format+Rewrite
Finally, this work was the culmination of a large number of developer's
efforts. Extra thanks goes to Corey Farrell, who took on a large amount of the
work in the Asterisk core, chan_sip, and was an invaluable resource in peer
reviews throughout this project.
There were a substantial number of patches contributed during this work; the
following issues/patch names simply reflect some of the work (and will cause
the release scripts to give attribution to the individuals who work on them).
Reviews:
https://reviewboard.asterisk.org/r/3814
https://reviewboard.asterisk.org/r/3808
https://reviewboard.asterisk.org/r/3805
https://reviewboard.asterisk.org/r/3803
https://reviewboard.asterisk.org/r/3801
https://reviewboard.asterisk.org/r/3798
https://reviewboard.asterisk.org/r/3800
https://reviewboard.asterisk.org/r/3794
https://reviewboard.asterisk.org/r/3793
https://reviewboard.asterisk.org/r/3792
https://reviewboard.asterisk.org/r/3791
https://reviewboard.asterisk.org/r/3790
https://reviewboard.asterisk.org/r/3789
https://reviewboard.asterisk.org/r/3788
https://reviewboard.asterisk.org/r/3787
https://reviewboard.asterisk.org/r/3786
https://reviewboard.asterisk.org/r/3784
https://reviewboard.asterisk.org/r/3783
https://reviewboard.asterisk.org/r/3778
https://reviewboard.asterisk.org/r/3774
https://reviewboard.asterisk.org/r/3775
https://reviewboard.asterisk.org/r/3772
https://reviewboard.asterisk.org/r/3761
https://reviewboard.asterisk.org/r/3754
https://reviewboard.asterisk.org/r/3753
https://reviewboard.asterisk.org/r/3751
https://reviewboard.asterisk.org/r/3750
https://reviewboard.asterisk.org/r/3748
https://reviewboard.asterisk.org/r/3747
https://reviewboard.asterisk.org/r/3746
https://reviewboard.asterisk.org/r/3742
https://reviewboard.asterisk.org/r/3740
https://reviewboard.asterisk.org/r/3739
https://reviewboard.asterisk.org/r/3738
https://reviewboard.asterisk.org/r/3737
https://reviewboard.asterisk.org/r/3736
https://reviewboard.asterisk.org/r/3734
https://reviewboard.asterisk.org/r/3722
https://reviewboard.asterisk.org/r/3713
https://reviewboard.asterisk.org/r/3703
https://reviewboard.asterisk.org/r/3689
https://reviewboard.asterisk.org/r/3687
https://reviewboard.asterisk.org/r/3674
https://reviewboard.asterisk.org/r/3671
https://reviewboard.asterisk.org/r/3667
https://reviewboard.asterisk.org/r/3665
https://reviewboard.asterisk.org/r/3625
https://reviewboard.asterisk.org/r/3602
https://reviewboard.asterisk.org/r/3519
https://reviewboard.asterisk.org/r/3518
https://reviewboard.asterisk.org/r/3516
https://reviewboard.asterisk.org/r/3515
https://reviewboard.asterisk.org/r/3512
https://reviewboard.asterisk.org/r/3506
https://reviewboard.asterisk.org/r/3413
https://reviewboard.asterisk.org/r/3410
https://reviewboard.asterisk.org/r/3387
https://reviewboard.asterisk.org/r/3388
https://reviewboard.asterisk.org/r/3389
https://reviewboard.asterisk.org/r/3390
https://reviewboard.asterisk.org/r/3321
https://reviewboard.asterisk.org/r/3320
https://reviewboard.asterisk.org/r/3319
https://reviewboard.asterisk.org/r/3318
https://reviewboard.asterisk.org/r/3266
https://reviewboard.asterisk.org/r/3265
https://reviewboard.asterisk.org/r/3234
https://reviewboard.asterisk.org/r/3178
ASTERISK-23114 #close
Reported by: mjordan
media_formats_translation_core.diff uploaded by kharwell (License 6464)
rb3506.diff uploaded by mjordan (License 6283)
media_format_app_file.diff uploaded by kharwell (License 6464)
misc-2.diff uploaded by file (License 5000)
chan_mild-3.diff uploaded by file (License 5000)
chan_obscure.diff uploaded by file (License 5000)
jingle.diff uploaded by file (License 5000)
funcs.diff uploaded by file (License 5000)
formats.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
bridges.diff uploaded by file (License 5000)
mf-codecs-2.diff uploaded by file (License 5000)
mf-app_fax.diff uploaded by file (License 5000)
mf-apps-3.diff uploaded by file (License 5000)
media-formats-3.diff uploaded by file (License 5000)
ASTERISK-23715
rb3713.patch uploaded by coreyfarrell (License 5909)
rb3689.patch uploaded by mjordan (License 6283)
ASTERISK-23957
rb3722.patch uploaded by mjordan (License 6283)
mf-attributes-3.diff uploaded by file (License 5000)
ASTERISK-23958
Tested by: jrose
rb3822.patch uploaded by coreyfarrell (License 5909)
rb3800.patch uploaded by jrose (License 6182)
chan_sip.diff uploaded by mjordan (License 6283)
rb3747.patch uploaded by jrose (License 6182)
ASTERISK-23959 #close
Tested by: sgriepentrog, mjordan, coreyfarrell
sip_cleanup.diff uploaded by opticron (License 6273)
chan_sip_caps.diff uploaded by mjordan (License 6283)
rb3751.patch uploaded by coreyfarrell (License 5909)
chan_sip-3.diff uploaded by file (License 5000)
ASTERISK-23960 #close
Tested by: opticron
direct_media.diff uploaded by opticron (License 6273)
pjsip-direct-media.diff uploaded by file (License 5000)
format_cap_remove.diff uploaded by opticron (License 6273)
media_format_fixes.diff uploaded by opticron (License 6273)
chan_pjsip-2.diff uploaded by file (License 5000)
ASTERISK-23966 #close
Tested by: rmudgett
rb3803.patch uploaded by rmudgetti (License 5621)
chan_dahdi.diff uploaded by file (License 5000)
ASTERISK-24064 #close
Tested by: coreyfarrell, mjordan, opticron, file, rmudgett, sgriepentrog, jrose
rb3814.patch uploaded by rmudgett (License 5621)
moh_cleanup.diff uploaded by opticron (License 6273)
bridge_leak.diff uploaded by opticron (License 6273)
translate.diff uploaded by file (License 5000)
rb3795.patch uploaded by rmudgett (License 5621)
tls_fix.diff uploaded by mjordan (License 6283)
fax-mf-fix-2.diff uploaded by file (License 5000)
rtp_transfer_stuff uploaded by mjordan (License 6283)
rb3787.patch uploaded by rmudgett (License 5621)
media-formats-explicit-translate-format-3.diff uploaded by file (License 5000)
format_cache_case_fix.diff uploaded by opticron (License 6273)
rb3774.patch uploaded by rmudgett (License 5621)
rb3775.patch uploaded by rmudgett (License 5621)
rtp_engine_fix.diff uploaded by opticron (License 6273)
rtp_crash_fix.diff uploaded by opticron (License 6273)
rb3753.patch uploaded by mjordan (License 6283)
rb3750.patch uploaded by mjordan (License 6283)
rb3748.patch uploaded by rmudgett (License 5621)
media_format_fixes.diff uploaded by opticron (License 6273)
rb3740.patch uploaded by mjordan (License 6283)
rb3739.patch uploaded by mjordan (License 6283)
rb3734.patch uploaded by mjordan (License 6283)
rb3689.patch uploaded by mjordan (License 6283)
rb3674.patch uploaded by coreyfarrell (License 5909)
rb3671.patch uploaded by coreyfarrell (License 5909)
rb3667.patch uploaded by coreyfarrell (License 5909)
rb3665.patch uploaded by mjordan (License 6283)
rb3625.patch uploaded by coreyfarrell (License 5909)
rb3602.patch uploaded by coreyfarrell (License 5909)
format_compatibility-2.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419044 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-20 22:06:33 +00:00
# include "asterisk/format_cache.h"
2009-04-02 17:20:52 +00:00
# include "asterisk/channel.h"
# include "asterisk/acl.h"
# include "asterisk/config.h"
# include "asterisk/lock.h"
# include "asterisk/utils.h"
# include "asterisk/cli.h"
# include "asterisk/manager.h"
# include "asterisk/unaligned.h"
# include "asterisk/module.h"
# include "asterisk/rtp_engine.h"
media formats: re-architect handling of media for performance improvements
In the old times media formats were represented using a bit field. This was
fast but had a few limitations.
1. Asterisk was limited in how many formats it could handle.
2. Formats, being a bit field, could not include any attribute information.
A format was strictly its type, e.g., "this is ulaw".
This was changed in Asterisk 10 (see
https://wiki.asterisk.org/wiki/display/AST/Media+Architecture+Proposal for
notes on that work) which led to the creation of the ast_format structure.
This structure allowed Asterisk to handle attributes and bundle information
with a format.
Additionally, ast_format_cap was created to act as a container for multiple
formats that, together, formed the capability of some entity. Another
mechanism was added to allow logic to be registered which performed format
attribute negotiation. Everywhere throughout the codebase Asterisk was
changed to use this strategy.
Unfortunately, in software, there is no free lunch. These new capabilities
came at a cost.
Performance analysis and profiling showed that we spend an inordinate
amount of time comparing, copying, and generally manipulating formats and
their related structures. Basic prototyping has shown that a reasonably
large performance improvement could be made in this area. This patch is the
result of that project, which overhauled the media format architecture
and its usage in Asterisk to improve performance.
Generally, the new philosophy for handling formats is as follows:
* The ast_format structure is reference counted. This removed a large amount
of the memory allocations and copying that was done in prior versions.
* In order to prevent race conditions while keeping things performant, the
ast_format structure is immutable by convention and lock-free. Violate this
tenet at your peril!
* Because formats are reference counted, codecs are also reference counted.
The Asterisk core generally provides built-in codecs and caches the
ast_format structures created to represent them. Generally, to prevent
inordinate amounts of module reference bumping, codecs and formats can be
added at run-time but cannot be removed.
* All compatibility with the bit field representation of codecs/formats has
been moved to a compatibility API. The primary user of this representation
is chan_iax2, which must continue to maintain its bit-field usage of formats
for interoperability concerns.
* When a format is negotiated with attributes, or when a format cannot be
represented by one of the cached formats, a new format object is created or
cloned from an existing format. That format may have the same codec
underlying it, but is a different format than a version of the format with
different attributes or without attributes.
* While formats are reference counted objects, the reference count maintained
on the format should be manipulated with care. Formats are generally cached
and will persist for the lifetime of Asterisk and do not explicitly need
to have their lifetime modified. An exception to this is when the user of a
format does not know where the format came from *and* the user may outlive
the provider of the format. This occurs, for example, when a format is read
from a channel: the channel may have a format with attributes (hence,
non-cached) and the user of the format may last longer than the channel (if
the reference to the channel is released prior to the format's reference).
For more information on this work, see the API design notes:
https://wiki.asterisk.org/wiki/display/AST/Media+Format+Rewrite
Finally, this work was the culmination of a large number of developer's
efforts. Extra thanks goes to Corey Farrell, who took on a large amount of the
work in the Asterisk core, chan_sip, and was an invaluable resource in peer
reviews throughout this project.
There were a substantial number of patches contributed during this work; the
following issues/patch names simply reflect some of the work (and will cause
the release scripts to give attribution to the individuals who work on them).
Reviews:
https://reviewboard.asterisk.org/r/3814
https://reviewboard.asterisk.org/r/3808
https://reviewboard.asterisk.org/r/3805
https://reviewboard.asterisk.org/r/3803
https://reviewboard.asterisk.org/r/3801
https://reviewboard.asterisk.org/r/3798
https://reviewboard.asterisk.org/r/3800
https://reviewboard.asterisk.org/r/3794
https://reviewboard.asterisk.org/r/3793
https://reviewboard.asterisk.org/r/3792
https://reviewboard.asterisk.org/r/3791
https://reviewboard.asterisk.org/r/3790
https://reviewboard.asterisk.org/r/3789
https://reviewboard.asterisk.org/r/3788
https://reviewboard.asterisk.org/r/3787
https://reviewboard.asterisk.org/r/3786
https://reviewboard.asterisk.org/r/3784
https://reviewboard.asterisk.org/r/3783
https://reviewboard.asterisk.org/r/3778
https://reviewboard.asterisk.org/r/3774
https://reviewboard.asterisk.org/r/3775
https://reviewboard.asterisk.org/r/3772
https://reviewboard.asterisk.org/r/3761
https://reviewboard.asterisk.org/r/3754
https://reviewboard.asterisk.org/r/3753
https://reviewboard.asterisk.org/r/3751
https://reviewboard.asterisk.org/r/3750
https://reviewboard.asterisk.org/r/3748
https://reviewboard.asterisk.org/r/3747
https://reviewboard.asterisk.org/r/3746
https://reviewboard.asterisk.org/r/3742
https://reviewboard.asterisk.org/r/3740
https://reviewboard.asterisk.org/r/3739
https://reviewboard.asterisk.org/r/3738
https://reviewboard.asterisk.org/r/3737
https://reviewboard.asterisk.org/r/3736
https://reviewboard.asterisk.org/r/3734
https://reviewboard.asterisk.org/r/3722
https://reviewboard.asterisk.org/r/3713
https://reviewboard.asterisk.org/r/3703
https://reviewboard.asterisk.org/r/3689
https://reviewboard.asterisk.org/r/3687
https://reviewboard.asterisk.org/r/3674
https://reviewboard.asterisk.org/r/3671
https://reviewboard.asterisk.org/r/3667
https://reviewboard.asterisk.org/r/3665
https://reviewboard.asterisk.org/r/3625
https://reviewboard.asterisk.org/r/3602
https://reviewboard.asterisk.org/r/3519
https://reviewboard.asterisk.org/r/3518
https://reviewboard.asterisk.org/r/3516
https://reviewboard.asterisk.org/r/3515
https://reviewboard.asterisk.org/r/3512
https://reviewboard.asterisk.org/r/3506
https://reviewboard.asterisk.org/r/3413
https://reviewboard.asterisk.org/r/3410
https://reviewboard.asterisk.org/r/3387
https://reviewboard.asterisk.org/r/3388
https://reviewboard.asterisk.org/r/3389
https://reviewboard.asterisk.org/r/3390
https://reviewboard.asterisk.org/r/3321
https://reviewboard.asterisk.org/r/3320
https://reviewboard.asterisk.org/r/3319
https://reviewboard.asterisk.org/r/3318
https://reviewboard.asterisk.org/r/3266
https://reviewboard.asterisk.org/r/3265
https://reviewboard.asterisk.org/r/3234
https://reviewboard.asterisk.org/r/3178
ASTERISK-23114 #close
Reported by: mjordan
media_formats_translation_core.diff uploaded by kharwell (License 6464)
rb3506.diff uploaded by mjordan (License 6283)
media_format_app_file.diff uploaded by kharwell (License 6464)
misc-2.diff uploaded by file (License 5000)
chan_mild-3.diff uploaded by file (License 5000)
chan_obscure.diff uploaded by file (License 5000)
jingle.diff uploaded by file (License 5000)
funcs.diff uploaded by file (License 5000)
formats.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
bridges.diff uploaded by file (License 5000)
mf-codecs-2.diff uploaded by file (License 5000)
mf-app_fax.diff uploaded by file (License 5000)
mf-apps-3.diff uploaded by file (License 5000)
media-formats-3.diff uploaded by file (License 5000)
ASTERISK-23715
rb3713.patch uploaded by coreyfarrell (License 5909)
rb3689.patch uploaded by mjordan (License 6283)
ASTERISK-23957
rb3722.patch uploaded by mjordan (License 6283)
mf-attributes-3.diff uploaded by file (License 5000)
ASTERISK-23958
Tested by: jrose
rb3822.patch uploaded by coreyfarrell (License 5909)
rb3800.patch uploaded by jrose (License 6182)
chan_sip.diff uploaded by mjordan (License 6283)
rb3747.patch uploaded by jrose (License 6182)
ASTERISK-23959 #close
Tested by: sgriepentrog, mjordan, coreyfarrell
sip_cleanup.diff uploaded by opticron (License 6273)
chan_sip_caps.diff uploaded by mjordan (License 6283)
rb3751.patch uploaded by coreyfarrell (License 5909)
chan_sip-3.diff uploaded by file (License 5000)
ASTERISK-23960 #close
Tested by: opticron
direct_media.diff uploaded by opticron (License 6273)
pjsip-direct-media.diff uploaded by file (License 5000)
format_cap_remove.diff uploaded by opticron (License 6273)
media_format_fixes.diff uploaded by opticron (License 6273)
chan_pjsip-2.diff uploaded by file (License 5000)
ASTERISK-23966 #close
Tested by: rmudgett
rb3803.patch uploaded by rmudgetti (License 5621)
chan_dahdi.diff uploaded by file (License 5000)
ASTERISK-24064 #close
Tested by: coreyfarrell, mjordan, opticron, file, rmudgett, sgriepentrog, jrose
rb3814.patch uploaded by rmudgett (License 5621)
moh_cleanup.diff uploaded by opticron (License 6273)
bridge_leak.diff uploaded by opticron (License 6273)
translate.diff uploaded by file (License 5000)
rb3795.patch uploaded by rmudgett (License 5621)
tls_fix.diff uploaded by mjordan (License 6283)
fax-mf-fix-2.diff uploaded by file (License 5000)
rtp_transfer_stuff uploaded by mjordan (License 6283)
rb3787.patch uploaded by rmudgett (License 5621)
media-formats-explicit-translate-format-3.diff uploaded by file (License 5000)
format_cache_case_fix.diff uploaded by opticron (License 6273)
rb3774.patch uploaded by rmudgett (License 5621)
rb3775.patch uploaded by rmudgett (License 5621)
rtp_engine_fix.diff uploaded by opticron (License 6273)
rtp_crash_fix.diff uploaded by opticron (License 6273)
rb3753.patch uploaded by mjordan (License 6283)
rb3750.patch uploaded by mjordan (License 6283)
rb3748.patch uploaded by rmudgett (License 5621)
media_format_fixes.diff uploaded by opticron (License 6273)
rb3740.patch uploaded by mjordan (License 6283)
rb3739.patch uploaded by mjordan (License 6283)
rb3734.patch uploaded by mjordan (License 6283)
rb3689.patch uploaded by mjordan (License 6283)
rb3674.patch uploaded by coreyfarrell (License 5909)
rb3671.patch uploaded by coreyfarrell (License 5909)
rb3667.patch uploaded by coreyfarrell (License 5909)
rb3665.patch uploaded by mjordan (License 6283)
rb3625.patch uploaded by coreyfarrell (License 5909)
rb3602.patch uploaded by coreyfarrell (License 5909)
format_compatibility-2.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419044 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-20 22:06:33 +00:00
# include "asterisk/smoother.h"
2014-03-04 17:22:32 +00:00
# include "asterisk/test.h"
2009-04-02 17:20:52 +00:00
# define MAX_TIMESTAMP_SKEW 640
# define RTP_SEQ_MOD (1<<16) /*!< A sequence number can't be more than 16 bits */
# define RTCP_DEFAULT_INTERVALMS 5000 /*!< Default milli-seconds between RTCP reports we send */
# define RTCP_MIN_INTERVALMS 500 /*!< Min milli-seconds between RTCP reports we send */
# define RTCP_MAX_INTERVALMS 60000 /*!< Max milli-seconds between RTCP reports we send */
# define DEFAULT_RTP_START 5000 /*!< Default port number to start allocating RTP ports from */
# define DEFAULT_RTP_END 31000 /*!< Default maximum port number to end allocating RTP ports at */
# define MINIMUM_RTP_PORT 1024 /*!< Minimum port number to accept */
# define MAXIMUM_RTP_PORT 65535 /*!< Maximum port number to accept */
2014-09-16 11:12:30 +00:00
# define DEFAULT_TURN_PORT 3478
2012-07-01 17:28:57 +00:00
2014-09-16 11:12:30 +00:00
# define TURN_STATE_WAIT_TIME 2000
2012-07-01 17:28:57 +00:00
2009-04-02 17:20:52 +00:00
# define RTCP_PT_FUR 192
2013-07-05 17:33:33 +00:00
# define RTCP_PT_SR AST_RTP_RTCP_SR
# define RTCP_PT_RR AST_RTP_RTCP_RR
2009-04-02 17:20:52 +00:00
# define RTCP_PT_SDES 202
# define RTCP_PT_BYE 203
# define RTCP_PT_APP 204
2013-08-23 15:42:27 +00:00
/* VP8: RTCP Feedback */
# define RTCP_PT_PSFB 206
2009-04-02 17:20:52 +00:00
# define RTP_MTU 1200
2013-10-23 17:56:44 +00:00
# define DTMF_SAMPLE_RATE_MS 8 /*!< DTMF samples per millisecond */
2009-04-02 17:20:52 +00:00
2009-05-13 13:39:10 +00:00
# define DEFAULT_DTMF_TIMEOUT (150 * (8000 / 1000)) /*!< samples */
2009-04-02 17:20:52 +00:00
# define ZFONE_PROFILE_ID 0x505a
2012-01-17 17:15:05 +00:00
# define DEFAULT_LEARNING_MIN_SEQUENTIAL 4
2012-09-20 18:27:28 +00:00
# define SRTP_MASTER_KEY_LEN 16
# define SRTP_MASTER_SALT_LEN 14
# define SRTP_MASTER_LEN (SRTP_MASTER_KEY_LEN + SRTP_MASTER_SALT_LEN)
2012-08-17 12:42:33 +00:00
enum strict_rtp_state {
STRICT_RTP_OPEN = 0 , /*! No RTP packets should be dropped, all sources accepted */
STRICT_RTP_LEARN , /*! Accept next packet as source */
STRICT_RTP_CLOSED , /*! Drop all RTP packets not coming from source that was learned */
} ;
# define DEFAULT_STRICT_RTP STRICT_RTP_CLOSED
2012-11-11 17:15:47 +00:00
# define DEFAULT_ICESUPPORT 1
2012-08-17 12:42:33 +00:00
2010-06-08 05:29:08 +00:00
extern struct ast_srtp_res * res_srtp ;
2012-09-20 18:27:28 +00:00
extern struct ast_srtp_policy_res * res_srtp_policy ;
2009-04-02 17:20:52 +00:00
static int dtmftimeout = DEFAULT_DTMF_TIMEOUT ;
static int rtpstart = DEFAULT_RTP_START ; /*!< First port for RTP sessions (set in rtp.conf) */
static int rtpend = DEFAULT_RTP_END ; /*!< Last port for RTP sessions (set in rtp.conf) */
static int rtpdebug ; /*!< Are we debugging? */
static int rtcpdebug ; /*!< Are we debugging RTCP? */
static int rtcpstats ; /*!< Are we debugging RTCP? */
static int rtcpinterval = RTCP_DEFAULT_INTERVALMS ; /*!< Time between rtcp reports in millisecs */
2010-07-08 22:08:07 +00:00
static struct ast_sockaddr rtpdebugaddr ; /*!< Debug packets to/from this host */
static struct ast_sockaddr rtcpdebugaddr ; /*!< Debug RTCP packets to/from this host */
2011-11-28 14:34:14 +00:00
static int rtpdebugport ; /*< Debug only RTP packets from IP or IP+Port if port is > 0 */
static int rtcpdebugport ; /*< Debug only RTCP packets from IP or IP+Port if port is > 0 */
2009-04-02 17:20:52 +00:00
# ifdef SO_NO_CHECK
static int nochecksums ;
# endif
2012-08-17 12:42:33 +00:00
static int strictrtp = DEFAULT_STRICT_RTP ; /*< Only accept RTP frames from a defined source. If we receive an indication of a changing source, enter learning mode. */
static int learning_min_sequential = DEFAULT_LEARNING_MIN_SEQUENTIAL ; /*< Number of sequential RTP frames needed from a single source during learning mode to accept new source. */
2013-03-12 19:08:59 +00:00
# ifdef HAVE_PJPROJECT
2012-08-17 12:42:33 +00:00
static int icesupport = DEFAULT_ICESUPPORT ;
2012-07-01 17:28:57 +00:00
static struct sockaddr_in stunaddr ;
static pj_str_t turnaddr ;
2012-08-17 12:42:33 +00:00
static int turnport = DEFAULT_TURN_PORT ;
2012-07-01 17:28:57 +00:00
static pj_str_t turnusername ;
static pj_str_t turnpassword ;
/*! \brief Pool factory used by pjlib to allocate memory. */
static pj_caching_pool cachingpool ;
2014-09-16 11:12:30 +00:00
/*! \brief Global memory pool for configuration and timers */
2012-07-01 17:28:57 +00:00
static pj_pool_t * pool ;
2014-09-16 11:12:30 +00:00
/*! \brief Global timer heap */
static pj_timer_heap_t * timer_heap ;
2012-07-01 17:28:57 +00:00
2014-09-16 11:12:30 +00:00
/*! \brief Thread executing the timer heap */
static pj_thread_t * timer_thread ;
2012-07-01 17:28:57 +00:00
2014-09-16 11:12:30 +00:00
/*! \brief Used to tell the timer thread to terminate */
static int timer_terminate ;
/*! \brief Structure which contains ioqueue thread information */
struct ast_rtp_ioqueue_thread {
/*! \brief Pool used by the thread */
pj_pool_t * pool ;
/*! \brief The thread handling the queue and timer heap */
pj_thread_t * thread ;
/*! \brief Ioqueue which polls on sockets */
pj_ioqueue_t * ioqueue ;
/*! \brief Timer heap for scheduled items */
pj_timer_heap_t * timerheap ;
/*! \brief Termination request */
int terminate ;
/*! \brief Current number of descriptors being waited on */
unsigned int count ;
/*! \brief Linked list information */
AST_LIST_ENTRY ( ast_rtp_ioqueue_thread ) next ;
} ;
/*! \brief List of ioqueue threads */
static AST_LIST_HEAD_STATIC ( ioqueues , ast_rtp_ioqueue_thread ) ;
2012-07-01 17:28:57 +00:00
2013-03-12 19:08:59 +00:00
# endif
2009-04-02 17:20:52 +00:00
# define FLAG_3389_WARNING (1 << 0)
# define FLAG_NAT_ACTIVE (3 << 1)
# define FLAG_NAT_INACTIVE (0 << 1)
# define FLAG_NAT_INACTIVE_NOWARN (1 << 1)
# define FLAG_NEED_MARKER_BIT (1 << 3)
# define FLAG_DTMF_COMPENSATE (1 << 4)
2014-09-16 11:12:30 +00:00
# define TRANSPORT_SOCKET_RTP 0
# define TRANSPORT_SOCKET_RTCP 1
# define TRANSPORT_TURN_RTP 2
# define TRANSPORT_TURN_RTCP 3
2012-07-01 17:28:57 +00:00
2013-03-07 15:48:06 +00:00
/*! \brief RTP learning mode tracking information */
struct rtp_learning_info {
int max_seq ; /*!< The highest sequence number received */
int packets ; /*!< The number of remaining packets before the source is accepted */
} ;
2014-06-30 19:51:28 +00:00
# ifdef HAVE_OPENSSL_SRTP
struct dtls_details {
2015-07-01 12:55:47 +00:00
ast_mutex_t lock ; /*!< Lock for timeout timer synchronization */
2014-06-30 19:51:28 +00:00
SSL * ssl ; /*!< SSL session */
BIO * read_bio ; /*!< Memory buffer for reading */
BIO * write_bio ; /*!< Memory buffer for writing */
enum ast_rtp_dtls_setup dtls_setup ; /*!< Current setup state */
enum ast_rtp_dtls_connection connection ; /*!< Whether this is a new or existing connection */
2015-07-01 12:55:47 +00:00
int timeout_timer ; /*!< Scheduler id for timeout timer */
2014-06-30 19:51:28 +00:00
} ;
# endif
2009-04-02 17:20:52 +00:00
/*! \brief RTP session description */
struct ast_rtp {
int s ;
struct ast_frame f ;
unsigned char rawdata [ 8192 + AST_FRIENDLY_OFFSET ] ;
unsigned int ssrc ; /*!< Synchronization source, RFC 3550, page 10. */
unsigned int themssrc ; /*!< Their SSRC */
unsigned int rxssrc ;
unsigned int lastts ;
unsigned int lastrxts ;
unsigned int lastividtimestamp ;
unsigned int lastovidtimestamp ;
unsigned int lastitexttimestamp ;
unsigned int lastotexttimestamp ;
unsigned int lasteventseqn ;
int lastrxseqno ; /*!< Last received sequence number */
unsigned short seedrxseqno ; /*!< What sequence number did they start with?*/
unsigned int seedrxts ; /*!< What RTP timestamp did they start with? */
unsigned int rxcount ; /*!< How many packets have we received? */
unsigned int rxoctetcount ; /*!< How many octets have we received? should be rxcount *160*/
unsigned int txcount ; /*!< How many packets have we sent? */
unsigned int txoctetcount ; /*!< How many octets have we sent? (txcount*160)*/
unsigned int cycles ; /*!< Shifted count of sequence number cycles */
2012-01-19 22:44:38 +00:00
double rxjitter ; /*!< Interarrival jitter at the moment in seconds */
2009-04-02 17:20:52 +00:00
double rxtransit ; /*!< Relative transit time for previous packet */
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 * lasttxformat ;
struct ast_format * lastrxformat ;
2009-04-02 17:20:52 +00:00
int rtptimeout ; /*!< RTP timeout time (negative or zero means disabled, negative value means temporarily disabled) */
int rtpholdtimeout ; /*!< RTP timeout when on hold (negative or zero means disabled, negative value means temporarily disabled). */
int rtpkeepalive ; /*!< Send RTP comfort noice packets for keepalive */
/* DTMF Reception Variables */
Handle extremely out of order RFC 2833 DTMF
The current implementation of RFC 2833 DTMF handling in res_rtp_asterisk will,
if a packet arrives out of order, drop the packet. This is to prevent
duplicate ton generation in the Asterisk core. Since the RTP layer does not
buffer data itself, this is the only option the RTP layer currently has for
handling packets that arrive out of order.
For the most part, this doesn't matter. For a particular digit, so long as a
BEGIN packet arrives before the first END packet, the digit will be produced.
If subsequent BEGIN packets arrive interleaved with the ENDs, they will be
dropped; likewise, if the BEGIN or END packets themselves are out of order,
those packets are dropped but sufficient information is conveyed to the
Asterisk core to produce the appropriate digit.
For certain sequences of DTMF packets - most notably when, for a particular
digit, an END packet arrives before any BEGIN packet for that digit - this
is a real problem. When an END arrives before any BEGINs, the END packet is
dropped - but at the same time, it causes subsequent BEGIN packets for that
digit to be ignored. When the next in order END packet arrives, it too is
dropped - Asterisk believes that there was no initial BEGIN.
The solution this patch provides is to trust the END packet to convey the
information needed for the Asterisk core to produce the DTMF digit. If we
receive an END packet, and it:
* Has a timestamp greater then the last timestamp received from an END
packet
* Does not have the same sequence number as the last received sequence
number (and is thus not an END packet retransmission)
Then we send the END frame up to the Asterisk core. It contains enough
DTMF information for Asterisk to produce the digit.
On the other hand, if we receive a BEGIN or continuation packet that occurs
with a timestamp equal to or less then the last END timestamp, then we've
received something out of order - but we already have received enough
information to produce the digit. These packets are dropped.
Much thanks goes to Olle Johansson (oej) for providing the idea for this
solution.
Review: https://reviewboard.asterisk.org/r/2033/
(closes issue ASTERISK-18404)
Reported by: Stephane Chazelas
Tested by: Matt Jordan
........
Merged revisions 370252 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........
Merged revisions 370271 from http://svn.asterisk.org/svn/asterisk/branches/10
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@370272 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-07-19 21:45:20 +00:00
char resp ; /*!< The current digit being processed */
unsigned int last_seqno ; /*!< The last known sequence number for any DTMF packet */
unsigned int last_end_timestamp ; /*!< The last known timestamp received from an END packet */
unsigned int dtmf_duration ; /*!< Total duration in samples since the digit start event */
unsigned int dtmf_timeout ; /*!< When this timestamp is reached we consider END frame lost and forcibly abort digit */
2009-04-02 17:20:52 +00:00
unsigned int dtmfsamples ;
Handle extremely out of order RFC 2833 DTMF
The current implementation of RFC 2833 DTMF handling in res_rtp_asterisk will,
if a packet arrives out of order, drop the packet. This is to prevent
duplicate ton generation in the Asterisk core. Since the RTP layer does not
buffer data itself, this is the only option the RTP layer currently has for
handling packets that arrive out of order.
For the most part, this doesn't matter. For a particular digit, so long as a
BEGIN packet arrives before the first END packet, the digit will be produced.
If subsequent BEGIN packets arrive interleaved with the ENDs, they will be
dropped; likewise, if the BEGIN or END packets themselves are out of order,
those packets are dropped but sufficient information is conveyed to the
Asterisk core to produce the appropriate digit.
For certain sequences of DTMF packets - most notably when, for a particular
digit, an END packet arrives before any BEGIN packet for that digit - this
is a real problem. When an END arrives before any BEGINs, the END packet is
dropped - but at the same time, it causes subsequent BEGIN packets for that
digit to be ignored. When the next in order END packet arrives, it too is
dropped - Asterisk believes that there was no initial BEGIN.
The solution this patch provides is to trust the END packet to convey the
information needed for the Asterisk core to produce the DTMF digit. If we
receive an END packet, and it:
* Has a timestamp greater then the last timestamp received from an END
packet
* Does not have the same sequence number as the last received sequence
number (and is thus not an END packet retransmission)
Then we send the END frame up to the Asterisk core. It contains enough
DTMF information for Asterisk to produce the digit.
On the other hand, if we receive a BEGIN or continuation packet that occurs
with a timestamp equal to or less then the last END timestamp, then we've
received something out of order - but we already have received enough
information to produce the digit. These packets are dropped.
Much thanks goes to Olle Johansson (oej) for providing the idea for this
solution.
Review: https://reviewboard.asterisk.org/r/2033/
(closes issue ASTERISK-18404)
Reported by: Stephane Chazelas
Tested by: Matt Jordan
........
Merged revisions 370252 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........
Merged revisions 370271 from http://svn.asterisk.org/svn/asterisk/branches/10
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@370272 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-07-19 21:45:20 +00:00
enum ast_rtp_dtmf_mode dtmfmode ; /*!< The current DTMF mode of the RTP stream */
2009-04-02 17:20:52 +00:00
/* DTMF Transmission Variables */
unsigned int lastdigitts ;
char sending_digit ; /*!< boolean - are we sending digits */
char send_digit ; /*!< digit we are sending */
int send_payload ;
int send_duration ;
unsigned int flags ;
struct timeval rxcore ;
struct timeval txcore ;
double drxcore ; /*!< The double representation of the first received packet */
struct timeval lastrx ; /*!< timeval when we last received a packet */
struct timeval dtmfmute ;
struct ast_smoother * smoother ;
int * ioid ;
unsigned short seqno ; /*!< Sequence number, RFC 3550, page 13. */
unsigned short rxseqno ;
2010-12-20 17:15:54 +00:00
struct ast_sched_context * sched ;
2009-04-02 17:20:52 +00:00
struct io_context * io ;
void * data ;
struct ast_rtcp * rtcp ;
struct ast_rtp * bridged ; /*!< Who we are Packet bridged to */
enum strict_rtp_state strict_rtp_state ; /*!< Current state that strict RTP protection is in */
2010-07-08 22:08:07 +00:00
struct ast_sockaddr strict_rtp_address ; /*!< Remote address information for strict RTP purposes */
2009-04-02 17:20:52 +00:00
2012-01-17 17:15:05 +00:00
/*
* Learning mode values based on pjmedia ' s probation mode . Many of these values are redundant to the above ,
* but these are in place to keep learning mode sequence values sealed from their normal counterparts .
*/
2013-03-07 15:48:06 +00:00
struct rtp_learning_info rtp_source_learn ; /* Learning mode track for the expected RTP source */
struct rtp_learning_info alt_source_learn ; /* Learning mode tracking for a new RTP source after one has been chosen */
2012-01-17 17:15:05 +00:00
2009-04-02 17:20:52 +00:00
struct rtp_red * red ;
2012-07-01 17:28:57 +00:00
2013-03-12 19:08:59 +00:00
ast_mutex_t lock ; /*!< Lock for synchronization purposes */
ast_cond_t cond ; /*!< Condition for signaling */
# ifdef HAVE_PJPROJECT
2012-07-01 17:28:57 +00:00
pj_ice_sess * ice ; /*!< ICE session */
pj_turn_sock * turn_rtp ; /*!< RTP TURN relay */
pj_turn_sock * turn_rtcp ; /*!< RTCP TURN relay */
pj_turn_state_t turn_state ; /*!< Current state of the TURN relay session */
unsigned int passthrough : 1 ; /*!< Bit to indicate that the received packet should be passed through */
2014-09-16 11:12:30 +00:00
unsigned int rtp_passthrough : 1 ; /*!< Bit to indicate that TURN RTP should be passed through */
unsigned int rtcp_passthrough : 1 ; /*!< Bit to indicate that TURN RTCP should be passed through */
2014-03-04 17:22:32 +00:00
unsigned int ice_port ; /*!< Port that ICE was started with if it was previously started */
2014-09-16 11:12:30 +00:00
struct ast_sockaddr rtp_loop ; /*!< Loopback address for forwarding RTP from TURN */
struct ast_sockaddr rtcp_loop ; /*!< Loopback address for forwarding RTCP from TURN */
struct ast_rtp_ioqueue_thread * ioqueue ; /*!< The ioqueue thread handling us */
2012-07-01 17:28:57 +00:00
char remote_ufrag [ 256 ] ; /*!< The remote ICE username */
char remote_passwd [ 256 ] ; /*!< The remote ICE password */
char local_ufrag [ 256 ] ; /*!< The local ICE username */
char local_passwd [ 256 ] ; /*!< The local ICE password */
2014-03-04 17:22:32 +00:00
struct ao2_container * ice_local_candidates ; /*!< The local ICE candidates */
struct ao2_container * ice_active_remote_candidates ; /*!< The remote ICE candidates */
struct ao2_container * ice_proposed_remote_candidates ; /*!< Incoming remote ICE candidates for new session */
struct ast_sockaddr ice_original_rtp_addr ; /*!< rtp address that ICE started on first session */
2013-03-12 19:08:59 +00:00
# endif
2012-09-20 18:27:28 +00:00
# ifdef HAVE_OPENSSL_SRTP
SSL_CTX * ssl_ctx ; /*!< SSL context */
2014-06-30 19:51:28 +00:00
enum ast_rtp_dtls_verify dtls_verify ; /*!< What to verify */
2012-09-20 18:27:28 +00:00
enum ast_srtp_suite suite ; /*!< SRTP crypto suite */
2014-06-30 19:51:28 +00:00
enum ast_rtp_dtls_hash local_hash ; /*!< Local hash used for the fingerprint */
2012-09-20 18:27:28 +00:00
char local_fingerprint [ 160 ] ; /*!< Fingerprint of our certificate */
2014-06-30 19:51:28 +00:00
enum ast_rtp_dtls_hash remote_hash ; /*!< Remote hash used for the fingerprint */
2012-09-20 18:27:28 +00:00
unsigned char remote_fingerprint [ EVP_MAX_MD_SIZE ] ; /*!< Fingerprint of the peer certificate */
unsigned int rekey ; /*!< Interval at which to renegotiate and rekey */
int rekeyid ; /*!< Scheduled item id for rekeying */
2014-06-30 19:51:28 +00:00
struct dtls_details dtls ; /*!< DTLS state information */
2012-09-20 18:27:28 +00:00
# endif
2009-04-02 17:20:52 +00:00
} ;
/*!
* \ brief Structure defining an RTCP session .
*
* The concept " RTCP session " is not defined in RFC 3550 , but since
* this structure is analogous to ast_rtp , which tracks a RTP session ,
* it is logical to think of this as a RTCP session .
*
* RTCP packet is defined on page 9 of RFC 3550.
*
*/
struct ast_rtcp {
int rtcp_info ;
int s ; /*!< Socket */
2010-07-08 22:08:07 +00:00
struct ast_sockaddr us ; /*!< Socket representation of the local endpoint. */
struct ast_sockaddr them ; /*!< Socket representation of the remote endpoint. */
2009-04-02 17:20:52 +00:00
unsigned int soc ; /*!< What they told us */
unsigned int spc ; /*!< What they told us */
unsigned int themrxlsr ; /*!< The middle 32 bits of the NTP timestamp in the last received SR*/
struct timeval rxlsr ; /*!< Time when we got their last SR */
struct timeval txlsr ; /*!< Time when we sent or last SR*/
unsigned int expected_prior ; /*!< no. packets in previous interval */
unsigned int received_prior ; /*!< no. packets received in previous interval */
int schedid ; /*!< Schedid returned from ast_sched_add() to schedule RTCP-transmissions*/
unsigned int rr_count ; /*!< number of RRs we've sent, not including report blocks in SR's */
unsigned int sr_count ; /*!< number of SRs we've sent */
unsigned int lastsrtxcount ; /*!< Transmit packet count when last SR sent */
double accumulated_transit ; /*!< accumulated a-dlsr-lsr */
double rtt ; /*!< Last reported rtt */
unsigned int reported_jitter ; /*!< The contents of their last jitter entry in the RR */
unsigned int reported_lost ; /*!< Reported lost packets in their RR */
double reported_maxjitter ;
double reported_minjitter ;
double reported_normdev_jitter ;
double reported_stdev_jitter ;
unsigned int reported_jitter_count ;
double reported_maxlost ;
double reported_minlost ;
double reported_normdev_lost ;
double reported_stdev_lost ;
double rxlost ;
double maxrxlost ;
double minrxlost ;
double normdev_rxlost ;
double stdev_rxlost ;
unsigned int rxlost_count ;
double maxrxjitter ;
double minrxjitter ;
double normdev_rxjitter ;
double stdev_rxjitter ;
unsigned int rxjitter_count ;
double maxrtt ;
double minrtt ;
double normdevrtt ;
double stdevrtt ;
unsigned int rtt_count ;
2013-08-23 15:42:27 +00:00
/* VP8: sequence number for the RTCP FIR FCI */
int firseq ;
2014-06-30 19:51:28 +00:00
# ifdef HAVE_OPENSSL_SRTP
struct dtls_details dtls ; /*!< DTLS state information */
# endif
2009-04-02 17:20:52 +00:00
} ;
struct rtp_red {
struct ast_frame t140 ; /*!< Primary data */
struct ast_frame t140red ; /*!< Redundant t140*/
unsigned char pt [ AST_RED_MAX_GENERATION ] ; /*!< Payload types for redundancy data */
unsigned char ts [ AST_RED_MAX_GENERATION ] ; /*!< Time stamps */
unsigned char len [ AST_RED_MAX_GENERATION ] ; /*!< length of each generation */
int num_gen ; /*!< Number of generations */
int schedid ; /*!< Timer id */
int ti ; /*!< How long to buffer data before send */
unsigned char t140red_data [ 64000 ] ;
unsigned char buf_data [ 64000 ] ; /*!< buffered primary data */
int hdrlen ;
long int prev_ts ;
} ;
Recorded merge of revisions 254452 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r254452 | mmichelson | 2010-03-25 10:59:56 -0500 (Thu, 25 Mar 2010) | 44 lines
Several fixes regarding RFC2833 DTMF detection.
Here is a copy and paste of the details from my request on
reviewboard that dealt with these changes:
Fix 1. The first change in place is to fix Mantis issue 15811, which deals with a situation where Asterisk will incorrectly interpret out of order RFC2833 frames as duplicate DTMF digits. For instance, we would receive a sequence like:
seqno 1: DTMF 1
seqno 2: DTMF 1
seqno 3: DTMF 1
seqno 4: DTMF 1
seqno 6: DTMF 1 (end)
seqno 5: DTMF 1
seqno 7: DTMF 1 (end)
seqno 8: DTMF 1 (end)
Prior to this patch when we received the frame with seqno 5, we would interpret this as a new DTMF 1. With this patch, we will check the seqno of the incoming digit and not process the frame if the seqno is lower than the last recorded seqno. Note that we do not record the seqno of the dropped DTMF frame for future processing. While the above situation is what was designed to be fixed, the patch is written in such a way that the following would also be fixed too:
seqno 9: DTMF 1
seqno 10: DTMF 1 (end)
seqno 11: DTMF 1 (end)
seqno 13: DTMF 2
seqno 12: DTMF 1 (end)
seqno 14: DTMF 2
seqno 15: DTMF 2 (end)
seqno 16: DTMF 2 (end)
seqno 17: DTMF 2 (end)
In this second situation, the beginning of the DTMF 2 arrives before the final end frame of the DTMF 1. With the patch, seqno 12 is no processed and thus we properly interpret the DTMF.
Fix 2. The second change in place is to fix an issue like the following:
seqno 1: DTMF 1
seqno 2: DTMF 1
seqno 3: DTMF 1 (end) *packet lost*
seqno 4: DTMF 1 (end) *packet lost*
seqno 5: DTMF 1 (end) *packet lost*
seqno 6: DTMF 2
When we receive seqno 6, we had code in place that was supposed to properly end the previously unended DTMF 1. The problem was that the code was essentially a no-op. The code would set up an end frame for the DTMF 1 but would immediately overwrite the frame with the begin for DTMF 2. I changed process_dtmf_rfc2833() so that instead of returning a single frame, it is given as an output parameter a list of frames. Each frame that needs to be returned is appended to this list.
Fix 3. The final change is a minor one where an AST_CONTROL_SRCCHANGE frame could get lost. If we process a cisco DTMF or an RFC 3389 frame and no frame was returned, then we would return &ast_null_frame. The problem is that earlier in the function, we may have generated an AST_CONTROL_SRCCHANGE frame and put it in the list of frames we wish to return. This frame would be lost in such a case. The patch fixes this problem
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@254454 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2010-03-25 16:04:48 +00:00
AST_LIST_HEAD_NOLOCK ( frame_list , ast_frame ) ;
2009-04-02 17:20:52 +00:00
/* Forward Declarations */
2010-12-20 17:15:54 +00:00
static int ast_rtp_new ( struct ast_rtp_instance * instance , struct ast_sched_context * sched , struct ast_sockaddr * addr , void * data ) ;
2009-04-02 17:20:52 +00:00
static int ast_rtp_destroy ( struct ast_rtp_instance * instance ) ;
static int ast_rtp_dtmf_begin ( struct ast_rtp_instance * instance , char digit ) ;
static int ast_rtp_dtmf_end ( struct ast_rtp_instance * instance , char digit ) ;
2010-10-02 02:46:43 +00:00
static int ast_rtp_dtmf_end_with_duration ( struct ast_rtp_instance * instance , char digit , unsigned int duration ) ;
2011-07-19 18:07:22 +00:00
static int ast_rtp_dtmf_mode_set ( struct ast_rtp_instance * instance , enum ast_rtp_dtmf_mode dtmf_mode ) ;
static enum ast_rtp_dtmf_mode ast_rtp_dtmf_mode_get ( struct ast_rtp_instance * instance ) ;
2010-03-12 22:04:51 +00:00
static void ast_rtp_update_source ( struct ast_rtp_instance * instance ) ;
static void ast_rtp_change_source ( struct ast_rtp_instance * instance ) ;
2009-04-02 17:20:52 +00:00
static int ast_rtp_write ( struct ast_rtp_instance * instance , struct ast_frame * frame ) ;
static struct ast_frame * ast_rtp_read ( struct ast_rtp_instance * instance , int rtcp ) ;
static void ast_rtp_prop_set ( struct ast_rtp_instance * instance , enum ast_rtp_property property , int value ) ;
static int ast_rtp_fd ( struct ast_rtp_instance * instance , int rtcp ) ;
2010-07-08 22:08:07 +00:00
static void ast_rtp_remote_address_set ( struct ast_rtp_instance * instance , struct ast_sockaddr * addr ) ;
2009-04-02 17:20:52 +00:00
static int rtp_red_init ( struct ast_rtp_instance * instance , int buffer_time , int * payloads , int generations ) ;
static int rtp_red_buffer ( struct ast_rtp_instance * instance , struct ast_frame * frame ) ;
static int ast_rtp_local_bridge ( struct ast_rtp_instance * instance0 , struct ast_rtp_instance * instance1 ) ;
static int ast_rtp_get_stat ( struct ast_rtp_instance * instance , struct ast_rtp_instance_stats * stats , enum ast_rtp_instance_stat stat ) ;
static int ast_rtp_dtmf_compatible ( struct ast_channel * chan0 , struct ast_rtp_instance * instance0 , struct ast_channel * chan1 , struct ast_rtp_instance * instance1 ) ;
2010-07-08 22:08:07 +00:00
static void ast_rtp_stun_request ( struct ast_rtp_instance * instance , struct ast_sockaddr * suggestion , const char * username ) ;
2009-04-02 17:20:52 +00:00
static void ast_rtp_stop ( struct ast_rtp_instance * instance ) ;
2010-08-24 18:58:46 +00:00
static int ast_rtp_qos_set ( struct ast_rtp_instance * instance , int tos , int cos , const char * desc ) ;
2011-06-14 17:03:37 +00:00
static int ast_rtp_sendcng ( struct ast_rtp_instance * instance , int level ) ;
2009-04-02 17:20:52 +00:00
2012-09-20 18:27:28 +00:00
# ifdef HAVE_OPENSSL_SRTP
static int ast_rtp_activate ( struct ast_rtp_instance * instance ) ;
2014-06-30 19:51:28 +00:00
static void dtls_srtp_check_pending ( struct ast_rtp_instance * instance , struct ast_rtp * rtp , int rtcp ) ;
2015-07-01 12:55:47 +00:00
static void dtls_srtp_start_timeout_timer ( struct ast_rtp_instance * instance , struct ast_rtp * rtp , int rtcp ) ;
static void dtls_srtp_stop_timeout_timer ( struct ast_rtp_instance * instance , struct ast_rtp * rtp , int rtcp ) ;
2012-09-20 18:27:28 +00:00
# endif
static int __rtp_sendto ( struct ast_rtp_instance * instance , void * buf , size_t size , int flags , struct ast_sockaddr * sa , int rtcp , int * ice , int use_srtp ) ;
2014-09-16 11:12:30 +00:00
# ifdef HAVE_PJPROJECT
2013-03-12 19:08:59 +00:00
/*! \brief Helper function which updates an ast_sockaddr with the candidate used for the component */
2014-09-16 11:12:30 +00:00
static void update_address_with_ice_candidate ( struct ast_rtp * rtp , enum ast_rtp_ice_component_type component ,
struct ast_sockaddr * cand_address )
2013-03-12 19:08:59 +00:00
{
char address [ PJ_INET6_ADDRSTRLEN ] ;
if ( ! rtp - > ice | | ( component < 1 ) | | ! rtp - > ice - > comp [ component - 1 ] . valid_check ) {
return ;
}
ast_sockaddr_parse ( cand_address , pj_sockaddr_print ( & rtp - > ice - > comp [ component - 1 ] . valid_check - > rcand - > addr , address , sizeof ( address ) , 0 ) , 0 ) ;
ast_sockaddr_set_port ( cand_address , pj_sockaddr_get_port ( & rtp - > ice - > comp [ component - 1 ] . valid_check - > rcand - > addr ) ) ;
}
2012-07-01 17:28:57 +00:00
/*! \brief Destructor for locally created ICE candidates */
static void ast_rtp_ice_candidate_destroy ( void * obj )
{
struct ast_rtp_engine_ice_candidate * candidate = obj ;
if ( candidate - > foundation ) {
ast_free ( candidate - > foundation ) ;
}
if ( candidate - > transport ) {
ast_free ( candidate - > transport ) ;
}
}
static void ast_rtp_ice_set_authentication ( struct ast_rtp_instance * instance , const char * ufrag , const char * password )
{
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
if ( ! ast_strlen_zero ( ufrag ) ) {
ast_copy_string ( rtp - > remote_ufrag , ufrag , sizeof ( rtp - > remote_ufrag ) ) ;
}
if ( ! ast_strlen_zero ( password ) ) {
ast_copy_string ( rtp - > remote_passwd , password , sizeof ( rtp - > remote_passwd ) ) ;
}
}
2014-03-04 17:22:32 +00:00
static int ice_candidate_cmp ( void * obj , void * arg , int flags )
{
struct ast_rtp_engine_ice_candidate * candidate1 = obj , * candidate2 = arg ;
if ( strcmp ( candidate1 - > foundation , candidate2 - > foundation ) | |
candidate1 - > id ! = candidate2 - > id | |
ast_sockaddr_cmp ( & candidate1 - > address , & candidate2 - > address ) | |
candidate1 - > type ! = candidate1 - > type ) {
return 0 ;
}
return CMP_MATCH | CMP_STOP ;
}
2012-07-01 17:28:57 +00:00
static void ast_rtp_ice_add_remote_candidate ( struct ast_rtp_instance * instance , const struct ast_rtp_engine_ice_candidate * candidate )
{
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
struct ast_rtp_engine_ice_candidate * remote_candidate ;
2014-10-08 18:47:32 +00:00
/* ICE sessions only support UDP candidates */
2014-10-12 21:09:49 +00:00
if ( strcasecmp ( candidate - > transport , " udp " ) ) {
2014-10-08 18:47:32 +00:00
return ;
}
2014-03-04 17:22:32 +00:00
if ( ! rtp - > ice_proposed_remote_candidates & &
! ( rtp - > ice_proposed_remote_candidates = ao2_container_alloc ( 1 , NULL , ice_candidate_cmp ) ) ) {
2012-07-01 17:28:57 +00:00
return ;
}
/* If this is going to exceed the maximum number of ICE candidates don't even add it */
2014-03-04 17:22:32 +00:00
if ( ao2_container_count ( rtp - > ice_proposed_remote_candidates ) = = PJ_ICE_MAX_CAND ) {
2012-07-01 17:28:57 +00:00
return ;
}
if ( ! ( remote_candidate = ao2_alloc ( sizeof ( * remote_candidate ) , ast_rtp_ice_candidate_destroy ) ) ) {
return ;
}
remote_candidate - > foundation = ast_strdup ( candidate - > foundation ) ;
remote_candidate - > id = candidate - > id ;
remote_candidate - > transport = ast_strdup ( candidate - > transport ) ;
remote_candidate - > priority = candidate - > priority ;
ast_sockaddr_copy ( & remote_candidate - > address , & candidate - > address ) ;
ast_sockaddr_copy ( & remote_candidate - > relay_address , & candidate - > relay_address ) ;
remote_candidate - > type = candidate - > type ;
2014-03-04 17:22:32 +00:00
ao2_link ( rtp - > ice_proposed_remote_candidates , remote_candidate ) ;
2012-07-01 17:28:57 +00:00
ao2_ref ( remote_candidate , - 1 ) ;
}
2012-08-20 20:19:52 +00:00
AST_THREADSTORAGE ( pj_thread_storage ) ;
2012-07-01 17:28:57 +00:00
/*! \brief Function used to check if the calling thread is registered with pjlib. If it is not it will be registered. */
static void pj_thread_register_check ( void )
{
2012-08-20 20:19:52 +00:00
pj_thread_desc * desc ;
2012-07-01 17:28:57 +00:00
pj_thread_t * thread ;
if ( pj_thread_is_registered ( ) = = PJ_TRUE ) {
return ;
}
2012-08-20 20:19:52 +00:00
desc = ast_threadstorage_get ( & pj_thread_storage , sizeof ( pj_thread_desc ) ) ;
if ( ! desc ) {
ast_log ( LOG_ERROR , " Could not get thread desc from thread-local storage. Expect awful things to occur \n " ) ;
return ;
}
pj_bzero ( * desc , sizeof ( * desc ) ) ;
if ( pj_thread_register ( " Asterisk Thread " , * desc , & thread ) ! = PJ_SUCCESS ) {
ast_log ( LOG_ERROR , " Coudln't register thread with PJLIB. \n " ) ;
}
return ;
2012-07-01 17:28:57 +00:00
}
2014-03-04 17:22:32 +00:00
static int ice_create ( struct ast_rtp_instance * instance , struct ast_sockaddr * addr ,
int port , int replace ) ;
static void ast_rtp_ice_stop ( struct ast_rtp_instance * instance )
{
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
if ( ! rtp - > ice ) {
return ;
}
pj_thread_register_check ( ) ;
pj_ice_sess_destroy ( rtp - > ice ) ;
rtp - > ice = NULL ;
}
static int ice_reset_session ( struct ast_rtp_instance * instance )
{
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
2014-06-30 19:51:28 +00:00
pj_ice_sess_role role = rtp - > ice - > role ;
int res ;
2014-03-04 17:22:32 +00:00
2015-09-04 21:33:39 +00:00
ast_debug ( 3 , " Resetting ICE for RTP instance '%p' \n " , instance ) ;
2014-10-16 01:26:18 +00:00
if ( ! rtp - > ice - > is_nominating & & ! rtp - > ice - > is_complete ) {
2015-09-04 21:33:39 +00:00
ast_debug ( 3 , " Nevermind. ICE isn't ready for a reset \n " ) ;
2014-10-16 01:26:18 +00:00
return 0 ;
}
2015-09-04 21:33:39 +00:00
ast_debug ( 3 , " Stopping ICE for RTP instance '%p' \n " , instance ) ;
2014-03-04 17:22:32 +00:00
ast_rtp_ice_stop ( instance ) ;
2014-06-30 19:51:28 +00:00
2015-09-04 21:33:39 +00:00
ast_debug ( 3 , " Recreating ICE session %s (%d) for RTP instance '%p' \n " , ast_sockaddr_stringify ( & rtp - > ice_original_rtp_addr ) , rtp - > ice_port , instance ) ;
2014-06-30 19:51:28 +00:00
res = ice_create ( instance , & rtp - > ice_original_rtp_addr , rtp - > ice_port , 1 ) ;
if ( ! res ) {
/* Preserve the role that the old ICE session used */
pj_ice_sess_change_role ( rtp - > ice , role ) ;
}
return res ;
2014-03-04 17:22:32 +00:00
}
static int ice_candidates_compare ( struct ao2_container * left , struct ao2_container * right )
{
struct ao2_iterator i ;
struct ast_rtp_engine_ice_candidate * right_candidate ;
if ( ao2_container_count ( left ) ! = ao2_container_count ( right ) ) {
return - 1 ;
}
i = ao2_iterator_init ( right , 0 ) ;
while ( ( right_candidate = ao2_iterator_next ( & i ) ) ) {
struct ast_rtp_engine_ice_candidate * left_candidate = ao2_find ( left , right_candidate , OBJ_POINTER ) ;
if ( ! left_candidate ) {
ao2_ref ( right_candidate , - 1 ) ;
ao2_iterator_destroy ( & i ) ;
return - 1 ;
}
ao2_ref ( left_candidate , - 1 ) ;
ao2_ref ( right_candidate , - 1 ) ;
}
ao2_iterator_destroy ( & i ) ;
return 0 ;
}
2012-07-01 17:28:57 +00:00
static void ast_rtp_ice_start ( struct ast_rtp_instance * instance )
{
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
pj_str_t ufrag = pj_str ( rtp - > remote_ufrag ) , passwd = pj_str ( rtp - > remote_passwd ) ;
pj_ice_sess_cand candidates [ PJ_ICE_MAX_CAND ] ;
struct ao2_iterator i ;
struct ast_rtp_engine_ice_candidate * candidate ;
2014-10-09 21:39:12 +00:00
int cand_cnt = 0 , has_rtp = 0 , has_rtcp = 0 ;
2012-07-01 17:28:57 +00:00
2014-03-04 17:22:32 +00:00
if ( ! rtp - > ice | | ! rtp - > ice_proposed_remote_candidates ) {
return ;
}
/* Check for equivalence in the lists */
if ( rtp - > ice_active_remote_candidates & &
! ice_candidates_compare ( rtp - > ice_proposed_remote_candidates , rtp - > ice_active_remote_candidates ) ) {
2015-09-04 21:33:39 +00:00
ast_debug ( 3 , " Proposed == active candidates for RTP instance '%p' \n " , instance ) ;
2014-03-04 17:22:32 +00:00
ao2_cleanup ( rtp - > ice_proposed_remote_candidates ) ;
rtp - > ice_proposed_remote_candidates = NULL ;
return ;
}
/* Out with the old, in with the new */
ao2_cleanup ( rtp - > ice_active_remote_candidates ) ;
rtp - > ice_active_remote_candidates = rtp - > ice_proposed_remote_candidates ;
rtp - > ice_proposed_remote_candidates = NULL ;
/* Reset the ICE session. Is this going to work? */
if ( ice_reset_session ( instance ) ) {
ast_log ( LOG_NOTICE , " Failed to create replacement ICE session \n " ) ;
2012-07-01 17:28:57 +00:00
return ;
}
pj_thread_register_check ( ) ;
2014-03-04 17:22:32 +00:00
i = ao2_iterator_init ( rtp - > ice_active_remote_candidates , 0 ) ;
2012-07-01 17:28:57 +00:00
while ( ( candidate = ao2_iterator_next ( & i ) ) & & ( cand_cnt < PJ_ICE_MAX_CAND ) ) {
pj_str_t address ;
2014-10-09 21:39:12 +00:00
/* there needs to be at least one rtp and rtcp candidate in the list */
has_rtp | = candidate - > id = = AST_RTP_ICE_COMPONENT_RTP ;
has_rtcp | = candidate - > id = = AST_RTP_ICE_COMPONENT_RTCP ;
2012-07-01 17:28:57 +00:00
pj_strdup2 ( rtp - > ice - > pool , & candidates [ cand_cnt ] . foundation , candidate - > foundation ) ;
candidates [ cand_cnt ] . comp_id = candidate - > id ;
candidates [ cand_cnt ] . prio = candidate - > priority ;
pj_sockaddr_parse ( pj_AF_UNSPEC ( ) , 0 , pj_cstr ( & address , ast_sockaddr_stringify ( & candidate - > address ) ) , & candidates [ cand_cnt ] . addr ) ;
if ( ! ast_sockaddr_isnull ( & candidate - > relay_address ) ) {
pj_sockaddr_parse ( pj_AF_UNSPEC ( ) , 0 , pj_cstr ( & address , ast_sockaddr_stringify ( & candidate - > relay_address ) ) , & candidates [ cand_cnt ] . rel_addr ) ;
}
if ( candidate - > type = = AST_RTP_ICE_CANDIDATE_TYPE_HOST ) {
candidates [ cand_cnt ] . type = PJ_ICE_CAND_TYPE_HOST ;
} else if ( candidate - > type = = AST_RTP_ICE_CANDIDATE_TYPE_SRFLX ) {
candidates [ cand_cnt ] . type = PJ_ICE_CAND_TYPE_SRFLX ;
} else if ( candidate - > type = = AST_RTP_ICE_CANDIDATE_TYPE_RELAYED ) {
candidates [ cand_cnt ] . type = PJ_ICE_CAND_TYPE_RELAYED ;
}
2013-11-01 12:40:40 +00:00
if ( candidate - > id = = AST_RTP_ICE_COMPONENT_RTP & & rtp - > turn_rtp ) {
2015-09-04 21:33:39 +00:00
ast_debug ( 3 , " RTP candidate %s (%p) \n " , ast_sockaddr_stringify ( & candidate - > address ) , instance ) ;
2012-07-01 17:28:57 +00:00
pj_turn_sock_set_perm ( rtp - > turn_rtp , 1 , & candidates [ cand_cnt ] . addr , 1 ) ;
2013-11-01 12:40:40 +00:00
} else if ( candidate - > id = = AST_RTP_ICE_COMPONENT_RTCP & & rtp - > turn_rtcp ) {
2015-09-04 21:33:39 +00:00
ast_debug ( 3 , " RTCP candidate %s (%p) \n " , ast_sockaddr_stringify ( & candidate - > address ) , instance ) ;
2012-07-01 17:28:57 +00:00
pj_turn_sock_set_perm ( rtp - > turn_rtcp , 1 , & candidates [ cand_cnt ] . addr , 1 ) ;
}
cand_cnt + + ;
2014-03-04 17:22:32 +00:00
ao2_ref ( candidate , - 1 ) ;
2012-07-01 17:28:57 +00:00
}
ao2_iterator_destroy ( & i ) ;
2015-09-04 21:33:39 +00:00
if ( cand_cnt < ao2_container_count ( rtp - > ice_active_remote_candidates ) ) {
ast_log ( LOG_WARNING , " Lost %d ICE candidates. Consider increasing PJ_ICE_MAX_CAND in PJSIP (%p) \n " ,
ao2_container_count ( rtp - > ice_active_remote_candidates ) - cand_cnt , instance ) ;
}
if ( ! has_rtp ) {
ast_log ( LOG_WARNING , " No RTP candidates; skipping ICE checklist (%p) \n " , instance ) ;
}
if ( ! has_rtcp ) {
ast_log ( LOG_WARNING , " No RTCP candidates; skipping ICE checklist (%p) \n " , instance ) ;
}
if ( has_rtp & & has_rtcp ) {
pj_status_t res = pj_ice_sess_create_check_list ( rtp - > ice , & ufrag , & passwd , cand_cnt , & candidates [ 0 ] ) ;
char reason [ 80 ] ;
if ( res = = PJ_SUCCESS ) {
ast_debug ( 3 , " Successfully created ICE checklist (%p) \n " , instance ) ;
ast_test_suite_event_notify ( " ICECHECKLISTCREATE " , " Result: SUCCESS " ) ;
pj_ice_sess_start_check ( rtp - > ice ) ;
pj_timer_heap_poll ( timer_heap , NULL ) ;
rtp - > strict_rtp_state = STRICT_RTP_OPEN ;
return ;
}
pj_strerror ( res , reason , sizeof ( reason ) ) ;
ast_log ( LOG_WARNING , " Failed to create ICE session check list: %s (%p) \n " , reason , instance ) ;
2012-07-01 17:28:57 +00:00
}
2014-01-09 16:52:57 +00:00
2014-03-04 17:22:32 +00:00
ast_test_suite_event_notify ( " ICECHECKLISTCREATE " , " Result: FAILURE " ) ;
2014-01-09 16:52:57 +00:00
/* even though create check list failed don't stop ice as
it might still work */
/* however we do need to reset remote candidates since
this function may be re - entered */
2014-03-04 17:22:32 +00:00
ao2_ref ( rtp - > ice_active_remote_candidates , - 1 ) ;
rtp - > ice_active_remote_candidates = NULL ;
2014-01-09 16:52:57 +00:00
rtp - > ice - > rcand_cnt = rtp - > ice - > clist . count = 0 ;
2012-07-01 17:28:57 +00:00
}
static const char * ast_rtp_ice_get_ufrag ( struct ast_rtp_instance * instance )
{
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
return rtp - > local_ufrag ;
}
static const char * ast_rtp_ice_get_password ( struct ast_rtp_instance * instance )
{
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
return rtp - > local_passwd ;
}
static struct ao2_container * ast_rtp_ice_get_local_candidates ( struct ast_rtp_instance * instance )
{
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
2014-03-04 17:22:32 +00:00
if ( rtp - > ice_local_candidates ) {
ao2_ref ( rtp - > ice_local_candidates , + 1 ) ;
2012-07-01 17:28:57 +00:00
}
2014-03-04 17:22:32 +00:00
return rtp - > ice_local_candidates ;
2012-07-01 17:28:57 +00:00
}
static void ast_rtp_ice_lite ( struct ast_rtp_instance * instance )
{
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
if ( ! rtp - > ice ) {
return ;
}
pj_thread_register_check ( ) ;
pj_ice_sess_change_role ( rtp - > ice , PJ_ICE_SESS_ROLE_CONTROLLING ) ;
}
2014-06-30 19:51:28 +00:00
static void ast_rtp_ice_set_role ( struct ast_rtp_instance * instance , enum ast_rtp_ice_role role )
{
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
2015-09-04 21:33:39 +00:00
ast_debug ( 3 , " Set role to %s (%p) \n " ,
role = = AST_RTP_ICE_ROLE_CONTROLLED ? " CONTROLLED " : " CONTROLLING " , instance ) ;
2014-06-30 19:51:28 +00:00
if ( ! rtp - > ice ) {
2015-09-30 18:42:40 +00:00
ast_debug ( 3 , " Set role failed; no ice instance (%p) \n " , instance ) ;
2014-06-30 19:51:28 +00:00
return ;
}
pj_thread_register_check ( ) ;
pj_ice_sess_change_role ( rtp - > ice , role = = AST_RTP_ICE_ROLE_CONTROLLED ?
PJ_ICE_SESS_ROLE_CONTROLLED : PJ_ICE_SESS_ROLE_CONTROLLING ) ;
}
2012-07-01 17:28:57 +00:00
static void ast_rtp_ice_add_cand ( struct ast_rtp * rtp , unsigned comp_id , unsigned transport_id , pj_ice_cand_type type , pj_uint16_t local_pref ,
const pj_sockaddr_t * addr , const pj_sockaddr_t * base_addr , const pj_sockaddr_t * rel_addr , int addr_len )
{
pj_str_t foundation ;
2012-07-22 17:03:24 +00:00
struct ast_rtp_engine_ice_candidate * candidate , * existing ;
2012-07-01 17:28:57 +00:00
char address [ PJ_INET6_ADDRSTRLEN ] ;
pj_thread_register_check ( ) ;
pj_ice_calc_foundation ( rtp - > ice - > pool , & foundation , type , addr ) ;
2014-03-04 17:22:32 +00:00
if ( ! rtp - > ice_local_candidates & & ! ( rtp - > ice_local_candidates = ao2_container_alloc ( 1 , NULL , ice_candidate_cmp ) ) ) {
2012-07-01 17:28:57 +00:00
return ;
}
if ( ! ( candidate = ao2_alloc ( sizeof ( * candidate ) , ast_rtp_ice_candidate_destroy ) ) ) {
return ;
}
candidate - > foundation = ast_strndup ( pj_strbuf ( & foundation ) , pj_strlen ( & foundation ) ) ;
candidate - > id = comp_id ;
candidate - > transport = ast_strdup ( " UDP " ) ;
ast_sockaddr_parse ( & candidate - > address , pj_sockaddr_print ( addr , address , sizeof ( address ) , 0 ) , 0 ) ;
ast_sockaddr_set_port ( & candidate - > address , pj_sockaddr_get_port ( addr ) ) ;
if ( rel_addr ) {
ast_sockaddr_parse ( & candidate - > relay_address , pj_sockaddr_print ( rel_addr , address , sizeof ( address ) , 0 ) , 0 ) ;
ast_sockaddr_set_port ( & candidate - > relay_address , pj_sockaddr_get_port ( rel_addr ) ) ;
}
if ( type = = PJ_ICE_CAND_TYPE_HOST ) {
candidate - > type = AST_RTP_ICE_CANDIDATE_TYPE_HOST ;
} else if ( type = = PJ_ICE_CAND_TYPE_SRFLX ) {
candidate - > type = AST_RTP_ICE_CANDIDATE_TYPE_SRFLX ;
} else if ( type = = PJ_ICE_CAND_TYPE_RELAYED ) {
candidate - > type = AST_RTP_ICE_CANDIDATE_TYPE_RELAYED ;
}
2014-03-04 17:22:32 +00:00
if ( ( existing = ao2_find ( rtp - > ice_local_candidates , candidate , OBJ_POINTER ) ) ) {
2012-07-22 17:03:24 +00:00
ao2_ref ( existing , - 1 ) ;
ao2_ref ( candidate , - 1 ) ;
return ;
}
2014-02-27 19:54:19 +00:00
if ( pj_ice_sess_add_cand ( rtp - > ice , comp_id , transport_id , type , local_pref , & foundation , addr , base_addr , rel_addr , addr_len , NULL ) ! = PJ_SUCCESS ) {
2012-07-01 17:28:57 +00:00
ao2_ref ( candidate , - 1 ) ;
return ;
}
/* By placing the candidate into the ICE session it will have produced the priority, so update the local candidate with it */
candidate - > priority = rtp - > ice - > lcand [ rtp - > ice - > lcand_cnt - 1 ] . prio ;
2014-03-04 17:22:32 +00:00
ao2_link ( rtp - > ice_local_candidates , candidate ) ;
2012-07-01 17:28:57 +00:00
ao2_ref ( candidate , - 1 ) ;
}
2014-09-16 11:12:30 +00:00
static void ast_rtp_on_turn_rx_rtp_data ( pj_turn_sock * turn_sock , void * pkt , unsigned pkt_len , const pj_sockaddr_t * peer_addr , unsigned addr_len )
{
struct ast_rtp_instance * instance = pj_turn_sock_get_user_data ( turn_sock ) ;
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
pj_status_t status ;
status = pj_ice_sess_on_rx_pkt ( rtp - > ice , AST_RTP_ICE_COMPONENT_RTP , TRANSPORT_TURN_RTP , pkt , pkt_len , peer_addr ,
addr_len ) ;
if ( status ! = PJ_SUCCESS ) {
char buf [ 100 ] ;
pj_strerror ( status , buf , sizeof ( buf ) ) ;
ast_log ( LOG_WARNING , " PJ ICE Rx error status code: %d '%s'. \n " ,
( int ) status , buf ) ;
return ;
}
if ( ! rtp - > rtp_passthrough ) {
return ;
}
rtp - > rtp_passthrough = 0 ;
ast_sendto ( rtp - > s , pkt , pkt_len , 0 , & rtp - > rtp_loop ) ;
}
static void ast_rtp_on_turn_rtp_state ( pj_turn_sock * turn_sock , pj_turn_state_t old_state , pj_turn_state_t new_state )
{
struct ast_rtp_instance * instance = pj_turn_sock_get_user_data ( turn_sock ) ;
struct ast_rtp * rtp ;
/* If this is a leftover from an already notified RTP instance just ignore the state change */
if ( ! instance ) {
return ;
}
rtp = ast_rtp_instance_get_data ( instance ) ;
/* We store the new state so the other thread can actually handle it */
ast_mutex_lock ( & rtp - > lock ) ;
rtp - > turn_state = new_state ;
ast_cond_signal ( & rtp - > cond ) ;
if ( new_state = = PJ_TURN_STATE_DESTROYING ) {
pj_turn_sock_set_user_data ( rtp - > turn_rtp , NULL ) ;
rtp - > turn_rtp = NULL ;
}
ast_mutex_unlock ( & rtp - > lock ) ;
}
/* RTP TURN Socket interface declaration */
static pj_turn_sock_cb ast_rtp_turn_rtp_sock_cb = {
. on_rx_data = ast_rtp_on_turn_rx_rtp_data ,
. on_state = ast_rtp_on_turn_rtp_state ,
} ;
static void ast_rtp_on_turn_rx_rtcp_data ( pj_turn_sock * turn_sock , void * pkt , unsigned pkt_len , const pj_sockaddr_t * peer_addr , unsigned addr_len )
{
struct ast_rtp_instance * instance = pj_turn_sock_get_user_data ( turn_sock ) ;
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
pj_status_t status ;
status = pj_ice_sess_on_rx_pkt ( rtp - > ice , AST_RTP_ICE_COMPONENT_RTCP , TRANSPORT_TURN_RTCP , pkt , pkt_len , peer_addr ,
addr_len ) ;
if ( status ! = PJ_SUCCESS ) {
char buf [ 100 ] ;
pj_strerror ( status , buf , sizeof ( buf ) ) ;
ast_log ( LOG_WARNING , " PJ ICE Rx error status code: %d '%s'. \n " ,
( int ) status , buf ) ;
return ;
}
if ( ! rtp - > rtcp_passthrough ) {
return ;
}
rtp - > rtcp_passthrough = 0 ;
ast_sendto ( rtp - > rtcp - > s , pkt , pkt_len , 0 , & rtp - > rtcp_loop ) ;
}
static void ast_rtp_on_turn_rtcp_state ( pj_turn_sock * turn_sock , pj_turn_state_t old_state , pj_turn_state_t new_state )
{
struct ast_rtp_instance * instance = pj_turn_sock_get_user_data ( turn_sock ) ;
struct ast_rtp * rtp = NULL ;
/* If this is a leftover from an already destroyed RTP instance just ignore the state change */
if ( ! instance ) {
return ;
}
rtp = ast_rtp_instance_get_data ( instance ) ;
/* We store the new state so the other thread can actually handle it */
ast_mutex_lock ( & rtp - > lock ) ;
rtp - > turn_state = new_state ;
ast_cond_signal ( & rtp - > cond ) ;
if ( new_state = = PJ_TURN_STATE_DESTROYING ) {
pj_turn_sock_set_user_data ( rtp - > turn_rtcp , NULL ) ;
rtp - > turn_rtcp = NULL ;
}
ast_mutex_unlock ( & rtp - > lock ) ;
}
/* RTCP TURN Socket interface declaration */
static pj_turn_sock_cb ast_rtp_turn_rtcp_sock_cb = {
. on_rx_data = ast_rtp_on_turn_rx_rtcp_data ,
. on_state = ast_rtp_on_turn_rtcp_state ,
} ;
/*! \brief Worker thread for ioqueue and timerheap */
static int ioqueue_worker_thread ( void * data )
{
struct ast_rtp_ioqueue_thread * ioqueue = data ;
while ( ! ioqueue - > terminate ) {
const pj_time_val delay = { 0 , 10 } ;
pj_ioqueue_poll ( ioqueue - > ioqueue , & delay ) ;
pj_timer_heap_poll ( ioqueue - > timerheap , NULL ) ;
}
return 0 ;
}
/*! \brief Destroyer for ioqueue thread */
static void rtp_ioqueue_thread_destroy ( struct ast_rtp_ioqueue_thread * ioqueue )
{
if ( ioqueue - > thread ) {
ioqueue - > terminate = 1 ;
pj_thread_join ( ioqueue - > thread ) ;
pj_thread_destroy ( ioqueue - > thread ) ;
}
pj_pool_release ( ioqueue - > pool ) ;
ast_free ( ioqueue ) ;
}
/*! \brief Removal function for ioqueue thread, determines if it should be terminated and destroyed */
static void rtp_ioqueue_thread_remove ( struct ast_rtp_ioqueue_thread * ioqueue )
{
int destroy = 0 ;
/* If nothing is using this ioqueue thread destroy it */
AST_LIST_LOCK ( & ioqueues ) ;
if ( ( ioqueue - > count - 2 ) = = 0 ) {
destroy = 1 ;
AST_LIST_REMOVE ( & ioqueues , ioqueue , next ) ;
}
AST_LIST_UNLOCK ( & ioqueues ) ;
if ( ! destroy ) {
return ;
}
rtp_ioqueue_thread_destroy ( ioqueue ) ;
}
/*! \brief Finder and allocator for an ioqueue thread */
static struct ast_rtp_ioqueue_thread * rtp_ioqueue_thread_get_or_create ( void )
{
struct ast_rtp_ioqueue_thread * ioqueue ;
pj_lock_t * lock ;
AST_LIST_LOCK ( & ioqueues ) ;
/* See if an ioqueue thread exists that can handle more */
AST_LIST_TRAVERSE ( & ioqueues , ioqueue , next ) {
if ( ( ioqueue - > count + 2 ) < PJ_IOQUEUE_MAX_HANDLES ) {
break ;
}
}
/* If we found one bump it up and return it */
if ( ioqueue ) {
ioqueue - > count + = 2 ;
goto end ;
}
ioqueue = ast_calloc ( 1 , sizeof ( * ioqueue ) ) ;
if ( ! ioqueue ) {
goto end ;
}
ioqueue - > pool = pj_pool_create ( & cachingpool . factory , " rtp " , 512 , 512 , NULL ) ;
/* We use a timer on the ioqueue thread for TURN so that two threads aren't operating
* on a session at the same time
*/
if ( pj_timer_heap_create ( ioqueue - > pool , 4 , & ioqueue - > timerheap ) ! = PJ_SUCCESS ) {
goto fatal ;
}
if ( pj_lock_create_recursive_mutex ( ioqueue - > pool , " rtp%p " , & lock ) ! = PJ_SUCCESS ) {
goto fatal ;
}
pj_timer_heap_set_lock ( ioqueue - > timerheap , lock , PJ_TRUE ) ;
2014-09-16 21:06:22 +00:00
if ( pj_ioqueue_create ( ioqueue - > pool , PJ_IOQUEUE_MAX_HANDLES , & ioqueue - > ioqueue ) ! = PJ_SUCCESS ) {
2014-09-16 11:12:30 +00:00
goto fatal ;
}
if ( pj_thread_create ( ioqueue - > pool , " ice " , & ioqueue_worker_thread , ioqueue , 0 , 0 , & ioqueue - > thread ) ! = PJ_SUCCESS ) {
goto fatal ;
}
AST_LIST_INSERT_HEAD ( & ioqueues , ioqueue , next ) ;
/* Since this is being returned to an active session the count always starts at 2 */
ioqueue - > count = 2 ;
goto end ;
fatal :
rtp_ioqueue_thread_destroy ( ioqueue ) ;
ioqueue = NULL ;
end :
AST_LIST_UNLOCK ( & ioqueues ) ;
return ioqueue ;
}
static void ast_rtp_ice_turn_request ( struct ast_rtp_instance * instance , enum ast_rtp_ice_component_type component ,
enum ast_transport transport , const char * server , unsigned int port , const char * username , const char * password )
{
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
pj_turn_sock * * turn_sock ;
const pj_turn_sock_cb * turn_cb ;
pj_turn_tp_type conn_type ;
int conn_transport ;
pj_stun_auth_cred cred = { 0 , } ;
pj_str_t turn_addr ;
struct ast_sockaddr addr = { { 0 , } } ;
pj_stun_config stun_config ;
struct timeval wait = ast_tvadd ( ast_tvnow ( ) , ast_samp2tv ( TURN_STATE_WAIT_TIME , 1000 ) ) ;
struct timespec ts = { . tv_sec = wait . tv_sec , . tv_nsec = wait . tv_usec * 1000 , } ;
pj_turn_session_info info ;
struct ast_sockaddr local , loop ;
ast_rtp_instance_get_local_address ( instance , & local ) ;
if ( ast_sockaddr_is_ipv4 ( & local ) ) {
ast_sockaddr_parse ( & loop , " 127.0.0.1 " , PARSE_PORT_FORBID ) ;
} else {
ast_sockaddr_parse ( & loop , " ::1 " , PARSE_PORT_FORBID ) ;
}
/* Determine what component we are requesting a TURN session for */
if ( component = = AST_RTP_ICE_COMPONENT_RTP ) {
turn_sock = & rtp - > turn_rtp ;
turn_cb = & ast_rtp_turn_rtp_sock_cb ;
conn_transport = TRANSPORT_TURN_RTP ;
ast_sockaddr_set_port ( & loop , ast_sockaddr_port ( & local ) ) ;
} else if ( component = = AST_RTP_ICE_COMPONENT_RTCP ) {
turn_sock = & rtp - > turn_rtcp ;
turn_cb = & ast_rtp_turn_rtcp_sock_cb ;
conn_transport = TRANSPORT_TURN_RTCP ;
ast_sockaddr_set_port ( & loop , ast_sockaddr_port ( & rtp - > rtcp - > us ) ) ;
} else {
return ;
}
if ( transport = = AST_TRANSPORT_UDP ) {
conn_type = PJ_TURN_TP_UDP ;
} else if ( transport = = AST_TRANSPORT_TCP ) {
conn_type = PJ_TURN_TP_TCP ;
} else {
ast_assert ( 0 ) ;
return ;
}
ast_sockaddr_parse ( & addr , server , PARSE_PORT_FORBID ) ;
ast_mutex_lock ( & rtp - > lock ) ;
if ( * turn_sock ) {
pj_turn_sock_destroy ( * turn_sock ) ;
rtp - > turn_state = PJ_TURN_STATE_NULL ;
while ( rtp - > turn_state ! = PJ_TURN_STATE_DESTROYING ) {
ast_cond_timedwait ( & rtp - > cond , & rtp - > lock , & ts ) ;
}
}
ast_mutex_unlock ( & rtp - > lock ) ;
if ( component = = AST_RTP_ICE_COMPONENT_RTP & & ! rtp - > ioqueue ) {
rtp - > ioqueue = rtp_ioqueue_thread_get_or_create ( ) ;
if ( ! rtp - > ioqueue ) {
return ;
}
}
pj_stun_config_init ( & stun_config , & cachingpool . factory , 0 , rtp - > ioqueue - > ioqueue , rtp - > ioqueue - > timerheap ) ;
if ( pj_turn_sock_create ( & stun_config , ast_sockaddr_is_ipv4 ( & addr ) ? pj_AF_INET ( ) : pj_AF_INET6 ( ) , conn_type ,
turn_cb , NULL , instance , turn_sock ) ! = PJ_SUCCESS ) {
ast_log ( LOG_WARNING , " Could not create a TURN client socket \n " ) ;
return ;
}
cred . type = PJ_STUN_AUTH_CRED_STATIC ;
pj_strset2 ( & cred . data . static_cred . username , ( char * ) username ) ;
cred . data . static_cred . data_type = PJ_STUN_PASSWD_PLAIN ;
pj_strset2 ( & cred . data . static_cred . data , ( char * ) password ) ;
/* Because the TURN socket is asynchronous but we are synchronous we need to wait until it is done */
ast_mutex_lock ( & rtp - > lock ) ;
pj_turn_sock_alloc ( * turn_sock , pj_cstr ( & turn_addr , server ) , port , NULL , & cred , NULL ) ;
while ( rtp - > turn_state < PJ_TURN_STATE_READY ) {
ast_cond_timedwait ( & rtp - > cond , & rtp - > lock , & ts ) ;
}
ast_mutex_unlock ( & rtp - > lock ) ;
/* If a TURN session was allocated add it as a candidate */
if ( rtp - > turn_state ! = PJ_TURN_STATE_READY ) {
return ;
}
pj_turn_sock_get_info ( * turn_sock , & info ) ;
ast_rtp_ice_add_cand ( rtp , component , conn_transport , PJ_ICE_CAND_TYPE_RELAYED , 65535 , & info . relay_addr ,
2014-09-30 11:36:14 +00:00
& info . relay_addr , & info . mapped_addr , pj_sockaddr_get_len ( & info . relay_addr ) ) ;
2014-09-16 11:12:30 +00:00
if ( component = = AST_RTP_ICE_COMPONENT_RTP ) {
ast_sockaddr_copy ( & rtp - > rtp_loop , & loop ) ;
} else if ( component = = AST_RTP_ICE_COMPONENT_RTCP ) {
ast_sockaddr_copy ( & rtp - > rtcp_loop , & loop ) ;
}
}
2012-07-01 17:28:57 +00:00
static char * generate_random_string ( char * buf , size_t size )
{
long val [ 4 ] ;
int x ;
2012-12-03 16:45:49 +00:00
for ( x = 0 ; x < 4 ; x + + ) {
2012-07-01 17:28:57 +00:00
val [ x ] = ast_random ( ) ;
2012-12-03 16:45:49 +00:00
}
2014-05-09 22:49:26 +00:00
snprintf ( buf , size , " %08lx%08lx%08lx%08lx " , ( long unsigned ) val [ 0 ] , ( long unsigned ) val [ 1 ] , ( long unsigned ) val [ 2 ] , ( long unsigned ) val [ 3 ] ) ;
2012-07-01 17:28:57 +00:00
return buf ;
}
/* ICE RTP Engine interface declaration */
static struct ast_rtp_engine_ice ast_rtp_ice = {
. set_authentication = ast_rtp_ice_set_authentication ,
. add_remote_candidate = ast_rtp_ice_add_remote_candidate ,
. start = ast_rtp_ice_start ,
. stop = ast_rtp_ice_stop ,
. get_ufrag = ast_rtp_ice_get_ufrag ,
. get_password = ast_rtp_ice_get_password ,
. get_local_candidates = ast_rtp_ice_get_local_candidates ,
. ice_lite = ast_rtp_ice_lite ,
2014-06-30 19:51:28 +00:00
. set_role = ast_rtp_ice_set_role ,
2014-09-16 11:12:30 +00:00
. turn_request = ast_rtp_ice_turn_request ,
2012-07-01 17:28:57 +00:00
} ;
2013-03-12 19:08:59 +00:00
# endif
2012-07-01 17:28:57 +00:00
2012-09-20 18:27:28 +00:00
# ifdef HAVE_OPENSSL_SRTP
2014-06-30 19:51:28 +00:00
static int dtls_verify_callback ( int preverify_ok , X509_STORE_CTX * ctx )
{
/* We don't want to actually verify the certificate so just accept what they have provided */
return 1 ;
}
static int dtls_details_initialize ( struct dtls_details * dtls , SSL_CTX * ssl_ctx ,
enum ast_rtp_dtls_setup setup )
2012-09-20 18:27:28 +00:00
{
2014-06-30 19:51:28 +00:00
dtls - > dtls_setup = setup ;
2012-09-20 18:27:28 +00:00
2014-06-30 19:51:28 +00:00
if ( ! ( dtls - > ssl = SSL_new ( ssl_ctx ) ) ) {
ast_log ( LOG_ERROR , " Failed to allocate memory for SSL \n " ) ;
goto error ;
}
if ( ! ( dtls - > read_bio = BIO_new ( BIO_s_mem ( ) ) ) ) {
ast_log ( LOG_ERROR , " Failed to allocate memory for inbound SSL traffic \n " ) ;
goto error ;
}
BIO_set_mem_eof_return ( dtls - > read_bio , - 1 ) ;
if ( ! ( dtls - > write_bio = BIO_new ( BIO_s_mem ( ) ) ) ) {
ast_log ( LOG_ERROR , " Failed to allocate memory for outbound SSL traffic \n " ) ;
goto error ;
2012-09-20 18:27:28 +00:00
}
2014-06-30 19:51:28 +00:00
BIO_set_mem_eof_return ( dtls - > write_bio , - 1 ) ;
SSL_set_bio ( dtls - > ssl , dtls - > read_bio , dtls - > write_bio ) ;
if ( dtls - > dtls_setup = = AST_RTP_DTLS_SETUP_PASSIVE ) {
SSL_set_accept_state ( dtls - > ssl ) ;
} else {
SSL_set_connect_state ( dtls - > ssl ) ;
}
dtls - > connection = AST_RTP_DTLS_CONNECTION_NEW ;
2015-07-01 12:55:47 +00:00
ast_mutex_init ( & dtls - > lock ) ;
2014-06-30 19:51:28 +00:00
return 0 ;
2012-09-20 18:27:28 +00:00
2014-06-30 19:51:28 +00:00
error :
if ( dtls - > read_bio ) {
BIO_free ( dtls - > read_bio ) ;
dtls - > read_bio = NULL ;
}
if ( dtls - > write_bio ) {
BIO_free ( dtls - > write_bio ) ;
dtls - > write_bio = NULL ;
}
if ( dtls - > ssl ) {
SSL_free ( dtls - > ssl ) ;
dtls - > ssl = NULL ;
}
return - 1 ;
}
static int dtls_setup_rtcp ( struct ast_rtp_instance * instance )
{
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
if ( ! rtp - > ssl_ctx | | ! rtp - > rtcp ) {
return 0 ;
}
return dtls_details_initialize ( & rtp - > rtcp - > dtls , rtp - > ssl_ctx , rtp - > dtls . dtls_setup ) ;
2012-09-20 18:27:28 +00:00
}
static int ast_rtp_dtls_set_configuration ( struct ast_rtp_instance * instance , const struct ast_rtp_dtls_cfg * dtls_cfg )
{
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
2014-06-30 19:51:28 +00:00
int res ;
2015-08-05 10:23:21 +00:00
# ifndef HAVE_OPENSSL_ECDH_AUTO
EC_KEY * ecdh ;
# endif
2012-09-20 18:27:28 +00:00
if ( ! dtls_cfg - > enabled ) {
return 0 ;
}
if ( ! ast_rtp_engine_srtp_is_registered ( ) ) {
2015-05-08 15:39:42 +00:00
ast_log ( LOG_ERROR , " SRTP support module is not loaded or available. Try loading res_srtp.so. \n " ) ;
2012-09-20 18:27:28 +00:00
return - 1 ;
}
2014-07-01 14:42:46 +00:00
if ( rtp - > ssl_ctx ) {
return 0 ;
}
2012-09-20 18:27:28 +00:00
if ( ! ( rtp - > ssl_ctx = SSL_CTX_new ( DTLSv1_method ( ) ) ) ) {
return - 1 ;
}
2015-01-29 12:09:58 +00:00
SSL_CTX_set_read_ahead ( rtp - > ssl_ctx , 1 ) ;
2015-07-28 10:33:39 +00:00
# ifdef HAVE_OPENSSL_ECDH_AUTO
SSL_CTX_set_ecdh_auto ( rtp - > ssl_ctx , 1 ) ;
# else
2015-08-05 10:23:21 +00:00
ecdh = EC_KEY_new_by_curve_name ( NID_X9_62_prime256v1 ) ;
if ( ecdh ) {
SSL_CTX_set_tmp_ecdh ( rtp - > ssl_ctx , ecdh ) ;
EC_KEY_free ( ecdh ) ;
}
2015-07-28 10:33:39 +00:00
# endif
2014-06-30 19:51:28 +00:00
rtp - > dtls_verify = dtls_cfg - > verify ;
SSL_CTX_set_verify ( rtp - > ssl_ctx , ( rtp - > dtls_verify & AST_RTP_DTLS_VERIFY_FINGERPRINT ) | | ( rtp - > dtls_verify & AST_RTP_DTLS_VERIFY_CERTIFICATE ) ?
SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT : SSL_VERIFY_NONE , ! ( rtp - > dtls_verify & AST_RTP_DTLS_VERIFY_CERTIFICATE ) ?
dtls_verify_callback : NULL ) ;
2012-09-20 18:27:28 +00:00
if ( dtls_cfg - > suite = = AST_AES_CM_128_HMAC_SHA1_80 ) {
SSL_CTX_set_tlsext_use_srtp ( rtp - > ssl_ctx , " SRTP_AES128_CM_SHA1_80 " ) ;
} else if ( dtls_cfg - > suite = = AST_AES_CM_128_HMAC_SHA1_32 ) {
SSL_CTX_set_tlsext_use_srtp ( rtp - > ssl_ctx , " SRTP_AES128_CM_SHA1_32 " ) ;
} else {
ast_log ( LOG_ERROR , " Unsupported suite specified for DTLS-SRTP on RTP instance '%p' \n " , instance ) ;
2014-06-30 19:51:28 +00:00
return - 1 ;
2012-09-20 18:27:28 +00:00
}
2014-06-30 19:51:28 +00:00
rtp - > local_hash = dtls_cfg - > hash ;
2012-09-20 18:27:28 +00:00
if ( ! ast_strlen_zero ( dtls_cfg - > certfile ) ) {
char * private = ast_strlen_zero ( dtls_cfg - > pvtfile ) ? dtls_cfg - > certfile : dtls_cfg - > pvtfile ;
BIO * certbio ;
X509 * cert ;
2014-06-30 19:51:28 +00:00
const EVP_MD * type ;
2012-09-20 18:27:28 +00:00
unsigned int size , i ;
unsigned char fingerprint [ EVP_MAX_MD_SIZE ] ;
char * local_fingerprint = rtp - > local_fingerprint ;
if ( ! SSL_CTX_use_certificate_file ( rtp - > ssl_ctx , dtls_cfg - > certfile , SSL_FILETYPE_PEM ) ) {
ast_log ( LOG_ERROR , " Specified certificate file '%s' for RTP instance '%p' could not be used \n " ,
dtls_cfg - > certfile , instance ) ;
2014-06-30 19:51:28 +00:00
return - 1 ;
2012-09-20 18:27:28 +00:00
}
if ( ! SSL_CTX_use_PrivateKey_file ( rtp - > ssl_ctx , private , SSL_FILETYPE_PEM ) | |
! SSL_CTX_check_private_key ( rtp - > ssl_ctx ) ) {
ast_log ( LOG_ERROR , " Specified private key file '%s' for RTP instance '%p' could not be used \n " ,
private , instance ) ;
2014-06-30 19:51:28 +00:00
return - 1 ;
2012-09-20 18:27:28 +00:00
}
if ( ! ( certbio = BIO_new ( BIO_s_file ( ) ) ) ) {
ast_log ( LOG_ERROR , " Failed to allocate memory for certificate fingerprinting on RTP instance '%p' \n " ,
instance ) ;
2014-06-30 19:51:28 +00:00
return - 1 ;
}
if ( rtp - > local_hash = = AST_RTP_DTLS_HASH_SHA1 ) {
type = EVP_sha1 ( ) ;
} else if ( rtp - > local_hash = = AST_RTP_DTLS_HASH_SHA256 ) {
type = EVP_sha256 ( ) ;
} else {
ast_log ( LOG_ERROR , " Unsupported fingerprint hash type on RTP instance '%p' \n " ,
instance ) ;
return - 1 ;
2012-09-20 18:27:28 +00:00
}
if ( ! BIO_read_filename ( certbio , dtls_cfg - > certfile ) | |
! ( cert = PEM_read_bio_X509 ( certbio , NULL , 0 , NULL ) ) | |
2014-06-30 19:51:28 +00:00
! X509_digest ( cert , type , fingerprint , & size ) | |
2012-09-20 18:27:28 +00:00
! size ) {
ast_log ( LOG_ERROR , " Could not produce fingerprint from certificate '%s' for RTP instance '%p' \n " ,
dtls_cfg - > certfile , instance ) ;
BIO_free_all ( certbio ) ;
2014-06-30 19:51:28 +00:00
return - 1 ;
2012-09-20 18:27:28 +00:00
}
for ( i = 0 ; i < size ; i + + ) {
2014-12-17 10:23:32 +00:00
sprintf ( local_fingerprint , " %02hhX: " , fingerprint [ i ] ) ;
2012-09-20 18:27:28 +00:00
local_fingerprint + = 3 ;
}
* ( local_fingerprint - 1 ) = 0 ;
BIO_free_all ( certbio ) ;
}
if ( ! ast_strlen_zero ( dtls_cfg - > cipher ) ) {
if ( ! SSL_CTX_set_cipher_list ( rtp - > ssl_ctx , dtls_cfg - > cipher ) ) {
ast_log ( LOG_ERROR , " Invalid cipher specified in cipher list '%s' for RTP instance '%p' \n " ,
dtls_cfg - > cipher , instance ) ;
2014-06-30 19:51:28 +00:00
return - 1 ;
2012-09-20 18:27:28 +00:00
}
}
if ( ! ast_strlen_zero ( dtls_cfg - > cafile ) | | ! ast_strlen_zero ( dtls_cfg - > capath ) ) {
if ( ! SSL_CTX_load_verify_locations ( rtp - > ssl_ctx , S_OR ( dtls_cfg - > cafile , NULL ) , S_OR ( dtls_cfg - > capath , NULL ) ) ) {
ast_log ( LOG_ERROR , " Invalid certificate authority file '%s' or path '%s' specified for RTP instance '%p' \n " ,
S_OR ( dtls_cfg - > cafile , " " ) , S_OR ( dtls_cfg - > capath , " " ) , instance ) ;
2014-06-30 19:51:28 +00:00
return - 1 ;
2012-09-20 18:27:28 +00:00
}
}
rtp - > rekey = dtls_cfg - > rekey ;
rtp - > suite = dtls_cfg - > suite ;
2014-06-30 19:51:28 +00:00
res = dtls_details_initialize ( & rtp - > dtls , rtp - > ssl_ctx , dtls_cfg - > default_setup ) ;
if ( ! res ) {
dtls_setup_rtcp ( instance ) ;
2012-09-20 18:27:28 +00:00
}
2014-06-30 19:51:28 +00:00
return res ;
2012-09-20 18:27:28 +00:00
}
static int ast_rtp_dtls_active ( struct ast_rtp_instance * instance )
{
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
return ! rtp - > ssl_ctx ? 0 : 1 ;
}
static void ast_rtp_dtls_stop ( struct ast_rtp_instance * instance )
{
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
2015-07-01 12:55:47 +00:00
dtls_srtp_stop_timeout_timer ( instance , rtp , 0 ) ;
2012-09-20 18:27:28 +00:00
if ( rtp - > ssl_ctx ) {
SSL_CTX_free ( rtp - > ssl_ctx ) ;
rtp - > ssl_ctx = NULL ;
}
2014-06-30 19:51:28 +00:00
if ( rtp - > dtls . ssl ) {
SSL_free ( rtp - > dtls . ssl ) ;
rtp - > dtls . ssl = NULL ;
2015-07-01 12:55:47 +00:00
ast_mutex_destroy ( & rtp - > dtls . lock ) ;
2014-06-30 19:51:28 +00:00
}
2015-07-01 12:55:47 +00:00
if ( rtp - > rtcp ) {
dtls_srtp_stop_timeout_timer ( instance , rtp , 1 ) ;
if ( rtp - > rtcp - > dtls . ssl ) {
SSL_free ( rtp - > rtcp - > dtls . ssl ) ;
rtp - > rtcp - > dtls . ssl = NULL ;
ast_mutex_destroy ( & rtp - > rtcp - > dtls . lock ) ;
}
2012-09-20 18:27:28 +00:00
}
}
static void ast_rtp_dtls_reset ( struct ast_rtp_instance * instance )
{
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
2014-06-30 19:51:28 +00:00
if ( SSL_is_init_finished ( rtp - > dtls . ssl ) ) {
SSL_shutdown ( rtp - > dtls . ssl ) ;
rtp - > dtls . connection = AST_RTP_DTLS_CONNECTION_NEW ;
2012-09-20 18:27:28 +00:00
}
2014-06-30 19:51:28 +00:00
if ( rtp - > rtcp & & SSL_is_init_finished ( rtp - > rtcp - > dtls . ssl ) ) {
SSL_shutdown ( rtp - > rtcp - > dtls . ssl ) ;
rtp - > rtcp - > dtls . connection = AST_RTP_DTLS_CONNECTION_NEW ;
}
2012-09-20 18:27:28 +00:00
}
static enum ast_rtp_dtls_connection ast_rtp_dtls_get_connection ( struct ast_rtp_instance * instance )
{
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
2014-06-30 19:51:28 +00:00
return rtp - > dtls . connection ;
2012-09-20 18:27:28 +00:00
}
static enum ast_rtp_dtls_setup ast_rtp_dtls_get_setup ( struct ast_rtp_instance * instance )
{
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
2014-06-30 19:51:28 +00:00
return rtp - > dtls . dtls_setup ;
2012-09-20 18:27:28 +00:00
}
2014-06-30 19:51:28 +00:00
static void dtls_set_setup ( enum ast_rtp_dtls_setup * dtls_setup , enum ast_rtp_dtls_setup setup , SSL * ssl )
2012-09-20 18:27:28 +00:00
{
2014-06-30 19:51:28 +00:00
enum ast_rtp_dtls_setup old = * dtls_setup ;
2012-09-20 18:27:28 +00:00
switch ( setup ) {
case AST_RTP_DTLS_SETUP_ACTIVE :
2014-06-30 19:51:28 +00:00
* dtls_setup = AST_RTP_DTLS_SETUP_PASSIVE ;
2012-09-20 18:27:28 +00:00
break ;
case AST_RTP_DTLS_SETUP_PASSIVE :
2014-06-30 19:51:28 +00:00
* dtls_setup = AST_RTP_DTLS_SETUP_ACTIVE ;
2012-09-20 18:27:28 +00:00
break ;
case AST_RTP_DTLS_SETUP_ACTPASS :
/* We can't respond to an actpass setup with actpass ourselves... so respond with active, as we can initiate connections */
2014-06-30 19:51:28 +00:00
if ( * dtls_setup = = AST_RTP_DTLS_SETUP_ACTPASS ) {
* dtls_setup = AST_RTP_DTLS_SETUP_ACTIVE ;
2012-09-20 18:27:28 +00:00
}
break ;
case AST_RTP_DTLS_SETUP_HOLDCONN :
2014-06-30 19:51:28 +00:00
* dtls_setup = AST_RTP_DTLS_SETUP_HOLDCONN ;
2012-09-20 18:27:28 +00:00
break ;
default :
/* This should never occur... if it does exit early as we don't know what state things are in */
return ;
}
/* If the setup state did not change we go on as if nothing happened */
2014-06-30 19:51:28 +00:00
if ( old = = * dtls_setup ) {
2012-09-20 18:27:28 +00:00
return ;
}
/* If they don't want us to establish a connection wait until later */
2014-06-30 19:51:28 +00:00
if ( * dtls_setup = = AST_RTP_DTLS_SETUP_HOLDCONN ) {
2012-09-20 18:27:28 +00:00
return ;
}
2014-06-30 19:51:28 +00:00
if ( * dtls_setup = = AST_RTP_DTLS_SETUP_ACTIVE ) {
SSL_set_connect_state ( ssl ) ;
} else if ( * dtls_setup = = AST_RTP_DTLS_SETUP_PASSIVE ) {
SSL_set_accept_state ( ssl ) ;
2012-09-20 18:27:28 +00:00
} else {
return ;
}
}
2014-06-30 19:51:28 +00:00
static void ast_rtp_dtls_set_setup ( struct ast_rtp_instance * instance , enum ast_rtp_dtls_setup setup )
{
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
if ( rtp - > dtls . ssl ) {
dtls_set_setup ( & rtp - > dtls . dtls_setup , setup , rtp - > dtls . ssl ) ;
}
if ( rtp - > rtcp & & rtp - > rtcp - > dtls . ssl ) {
dtls_set_setup ( & rtp - > rtcp - > dtls . dtls_setup , setup , rtp - > rtcp - > dtls . ssl ) ;
}
}
2012-09-20 18:27:28 +00:00
static void ast_rtp_dtls_set_fingerprint ( struct ast_rtp_instance * instance , enum ast_rtp_dtls_hash hash , const char * fingerprint )
{
char * tmp = ast_strdupa ( fingerprint ) , * value ;
int pos = 0 ;
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
2014-06-30 19:51:28 +00:00
if ( hash ! = AST_RTP_DTLS_HASH_SHA1 & & hash ! = AST_RTP_DTLS_HASH_SHA256 ) {
2012-09-20 18:27:28 +00:00
return ;
}
2014-06-30 19:51:28 +00:00
rtp - > remote_hash = hash ;
2012-09-20 18:27:28 +00:00
while ( ( value = strsep ( & tmp , " : " ) ) & & ( pos ! = ( EVP_MAX_MD_SIZE - 1 ) ) ) {
2014-12-17 10:23:32 +00:00
sscanf ( value , " %02hhx " , & rtp - > remote_fingerprint [ pos + + ] ) ;
2012-09-20 18:27:28 +00:00
}
}
2014-06-30 19:51:28 +00:00
static enum ast_rtp_dtls_hash ast_rtp_dtls_get_fingerprint_hash ( struct ast_rtp_instance * instance )
2012-09-20 18:27:28 +00:00
{
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
2014-06-30 19:51:28 +00:00
return rtp - > local_hash ;
}
static const char * ast_rtp_dtls_get_fingerprint ( struct ast_rtp_instance * instance )
{
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
2012-09-20 18:27:28 +00:00
return rtp - > local_fingerprint ;
}
/* DTLS RTP Engine interface declaration */
static struct ast_rtp_engine_dtls ast_rtp_dtls = {
. set_configuration = ast_rtp_dtls_set_configuration ,
. active = ast_rtp_dtls_active ,
. stop = ast_rtp_dtls_stop ,
. reset = ast_rtp_dtls_reset ,
. get_connection = ast_rtp_dtls_get_connection ,
. get_setup = ast_rtp_dtls_get_setup ,
. set_setup = ast_rtp_dtls_set_setup ,
. set_fingerprint = ast_rtp_dtls_set_fingerprint ,
2014-06-30 19:51:28 +00:00
. get_fingerprint_hash = ast_rtp_dtls_get_fingerprint_hash ,
2012-09-20 18:27:28 +00:00
. get_fingerprint = ast_rtp_dtls_get_fingerprint ,
} ;
# endif
2009-04-02 17:20:52 +00:00
/* RTP Engine Declaration */
static struct ast_rtp_engine asterisk_rtp_engine = {
. name = " asterisk " ,
. new = ast_rtp_new ,
. destroy = ast_rtp_destroy ,
. dtmf_begin = ast_rtp_dtmf_begin ,
. dtmf_end = ast_rtp_dtmf_end ,
2010-10-02 02:46:43 +00:00
. dtmf_end_with_duration = ast_rtp_dtmf_end_with_duration ,
2011-07-19 18:07:22 +00:00
. dtmf_mode_set = ast_rtp_dtmf_mode_set ,
. dtmf_mode_get = ast_rtp_dtmf_mode_get ,
2010-03-12 22:04:51 +00:00
. update_source = ast_rtp_update_source ,
. change_source = ast_rtp_change_source ,
2009-04-02 17:20:52 +00:00
. write = ast_rtp_write ,
. read = ast_rtp_read ,
. prop_set = ast_rtp_prop_set ,
. fd = ast_rtp_fd ,
. remote_address_set = ast_rtp_remote_address_set ,
. red_init = rtp_red_init ,
. red_buffer = rtp_red_buffer ,
. local_bridge = ast_rtp_local_bridge ,
. get_stat = ast_rtp_get_stat ,
. dtmf_compatible = ast_rtp_dtmf_compatible ,
. stun_request = ast_rtp_stun_request ,
. stop = ast_rtp_stop ,
2010-08-24 18:58:46 +00:00
. qos = ast_rtp_qos_set ,
2011-06-14 17:03:37 +00:00
. sendcng = ast_rtp_sendcng ,
2013-03-12 19:08:59 +00:00
# ifdef HAVE_PJPROJECT
2012-07-01 17:28:57 +00:00
. ice = & ast_rtp_ice ,
2013-03-12 19:08:59 +00:00
# endif
2012-09-20 18:27:28 +00:00
# ifdef HAVE_OPENSSL_SRTP
. dtls = & ast_rtp_dtls ,
. activate = ast_rtp_activate ,
# endif
2012-07-01 17:28:57 +00:00
} ;
2014-06-30 19:51:28 +00:00
# ifdef HAVE_OPENSSL_SRTP
static void dtls_perform_handshake ( struct ast_rtp_instance * instance , struct dtls_details * dtls , int rtcp )
{
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
2015-07-01 12:55:47 +00:00
/* If we are not acting as a client connecting to the remote side then
* don ' t start the handshake as it will accomplish nothing and would conflict
* with the handshake we receive from the remote side .
*/
if ( ! dtls - > ssl | | ( dtls - > dtls_setup ! = AST_RTP_DTLS_SETUP_ACTIVE ) ) {
2014-06-30 19:51:28 +00:00
return ;
}
SSL_do_handshake ( dtls - > ssl ) ;
2015-07-01 12:55:47 +00:00
/* Since the handshake is started in a thread outside of the channel thread it's possible
* for the response to be handled in the channel thread before we start the timeout timer .
* To ensure this doesn ' t actually happen we hold the DTLS lock . The channel thread will
* block until we ' re done at which point the timeout timer will be immediately stopped .
*/
ast_mutex_lock ( & dtls - > lock ) ;
2014-06-30 19:51:28 +00:00
dtls_srtp_check_pending ( instance , rtp , rtcp ) ;
2015-07-01 12:55:47 +00:00
dtls_srtp_start_timeout_timer ( instance , rtp , rtcp ) ;
ast_mutex_unlock ( & dtls - > lock ) ;
2014-06-30 19:51:28 +00:00
}
# endif
2014-07-08 14:38:42 +00:00
# ifdef HAVE_PJPROJECT
static void rtp_learning_seq_init ( struct rtp_learning_info * info , uint16_t seq ) ;
2013-02-28 21:37:57 +00:00
static void ast_rtp_on_ice_complete ( pj_ice_sess * ice , pj_status_t status )
{
2014-06-30 19:51:28 +00:00
struct ast_rtp_instance * instance = ice - > user_data ;
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
2014-09-16 11:12:30 +00:00
if ( status = = PJ_SUCCESS ) {
struct ast_sockaddr remote_address ;
/* Symmetric RTP must be disabled for the remote address to not get overwritten */
ast_rtp_instance_set_prop ( instance , AST_RTP_PROPERTY_NAT , 0 ) ;
update_address_with_ice_candidate ( rtp , AST_RTP_ICE_COMPONENT_RTP , & remote_address ) ;
ast_rtp_instance_set_remote_address ( instance , & remote_address ) ;
if ( rtp - > rtcp ) {
update_address_with_ice_candidate ( rtp , AST_RTP_ICE_COMPONENT_RTCP , & rtp - > rtcp - > them ) ;
}
}
2015-07-28 10:33:39 +00:00
2014-06-30 19:51:28 +00:00
# ifdef HAVE_OPENSSL_SRTP
dtls_perform_handshake ( instance , & rtp - > dtls , 0 ) ;
if ( rtp - > rtcp ) {
dtls_perform_handshake ( instance , & rtp - > rtcp - > dtls , 1 ) ;
}
# endif
2013-02-28 21:37:57 +00:00
2013-02-28 21:59:56 +00:00
if ( ! strictrtp ) {
2013-02-28 21:37:57 +00:00
return ;
}
rtp - > strict_rtp_state = STRICT_RTP_LEARN ;
2013-03-07 15:48:06 +00:00
rtp_learning_seq_init ( & rtp - > rtp_source_learn , ( uint16_t ) rtp - > seqno ) ;
2013-02-28 21:37:57 +00:00
}
2012-07-01 17:28:57 +00:00
static void ast_rtp_on_ice_rx_data ( pj_ice_sess * ice , unsigned comp_id , unsigned transport_id , void * pkt , pj_size_t size , const pj_sockaddr_t * src_addr , unsigned src_addr_len )
{
2014-06-30 19:51:28 +00:00
struct ast_rtp_instance * instance = ice - > user_data ;
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
2012-07-01 17:28:57 +00:00
/* Instead of handling the packet here (which really doesn't work with our architecture) we set a bit to indicate that it should be handled after pj_ice_sess_on_rx_pkt
* returns */
2014-09-16 11:12:30 +00:00
if ( transport_id = = TRANSPORT_SOCKET_RTP | | transport_id = = TRANSPORT_SOCKET_RTCP ) {
rtp - > passthrough = 1 ;
} else if ( transport_id = = TRANSPORT_TURN_RTP ) {
rtp - > rtp_passthrough = 1 ;
} else if ( transport_id = = TRANSPORT_TURN_RTCP ) {
rtp - > rtcp_passthrough = 1 ;
}
2012-07-01 17:28:57 +00:00
}
static pj_status_t ast_rtp_on_ice_tx_pkt ( pj_ice_sess * ice , unsigned comp_id , unsigned transport_id , const void * pkt , pj_size_t size , const pj_sockaddr_t * dst_addr , unsigned dst_addr_len )
{
2014-06-30 19:51:28 +00:00
struct ast_rtp_instance * instance = ice - > user_data ;
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
2012-07-01 17:28:57 +00:00
pj_status_t status = PJ_EINVALIDOP ;
2012-09-10 19:22:54 +00:00
pj_ssize_t _size = ( pj_ssize_t ) size ;
2012-07-01 17:28:57 +00:00
if ( transport_id = = TRANSPORT_SOCKET_RTP ) {
/* Traffic is destined to go right out the RTP socket we already have */
2012-09-10 19:22:54 +00:00
status = pj_sock_sendto ( rtp - > s , pkt , & _size , 0 , dst_addr , dst_addr_len ) ;
/* sendto on a connectionless socket should send all the data, or none at all */
ast_assert ( _size = = size | | status ! = PJ_SUCCESS ) ;
2012-07-01 17:28:57 +00:00
} else if ( transport_id = = TRANSPORT_SOCKET_RTCP ) {
/* Traffic is destined to go right out the RTCP socket we already have */
2012-07-01 19:36:49 +00:00
if ( rtp - > rtcp ) {
2012-09-10 19:22:54 +00:00
status = pj_sock_sendto ( rtp - > rtcp - > s , pkt , & _size , 0 , dst_addr , dst_addr_len ) ;
/* sendto on a connectionless socket should send all the data, or none at all */
ast_assert ( _size = = size | | status ! = PJ_SUCCESS ) ;
2012-07-01 19:36:49 +00:00
} else {
status = PJ_SUCCESS ;
}
2012-07-01 17:28:57 +00:00
} else if ( transport_id = = TRANSPORT_TURN_RTP ) {
/* Traffic is going through the RTP TURN relay */
if ( rtp - > turn_rtp ) {
status = pj_turn_sock_sendto ( rtp - > turn_rtp , pkt , size , dst_addr , dst_addr_len ) ;
}
} else if ( transport_id = = TRANSPORT_TURN_RTCP ) {
/* Traffic is going through the RTCP TURN relay */
if ( rtp - > turn_rtcp ) {
status = pj_turn_sock_sendto ( rtp - > turn_rtcp , pkt , size , dst_addr , dst_addr_len ) ;
}
}
return status ;
}
/* ICE Session interface declaration */
static pj_ice_sess_cb ast_rtp_ice_sess_cb = {
2013-02-28 21:37:57 +00:00
. on_ice_complete = ast_rtp_on_ice_complete ,
2012-07-01 17:28:57 +00:00
. on_rx_data = ast_rtp_on_ice_rx_data ,
. on_tx_pkt = ast_rtp_on_ice_tx_pkt ,
2009-04-02 17:20:52 +00:00
} ;
2014-09-16 11:12:30 +00:00
/*! \brief Worker thread for timerheap */
static int timer_worker_thread ( void * data )
2012-07-01 17:28:57 +00:00
{
2014-09-16 21:06:22 +00:00
pj_ioqueue_t * ioqueue ;
if ( pj_ioqueue_create ( pool , 1 , & ioqueue ) ! = PJ_SUCCESS ) {
return - 1 ;
}
2014-09-16 11:12:30 +00:00
while ( ! timer_terminate ) {
2014-09-16 21:06:22 +00:00
const pj_time_val delay = { 0 , 10 } ;
2014-09-16 11:12:30 +00:00
pj_timer_heap_poll ( timer_heap , NULL ) ;
2014-09-16 21:06:22 +00:00
pj_ioqueue_poll ( ioqueue , & delay ) ;
2012-07-01 17:28:57 +00:00
}
return 0 ;
}
2013-03-12 19:08:59 +00:00
# endif
2012-07-01 17:28:57 +00:00
2010-07-08 22:08:07 +00:00
static inline int rtp_debug_test_addr ( struct ast_sockaddr * addr )
2009-04-02 17:20:52 +00:00
{
if ( ! rtpdebug ) {
return 0 ;
}
2011-11-28 14:34:14 +00:00
if ( ! ast_sockaddr_isnull ( & rtpdebugaddr ) ) {
if ( rtpdebugport ) {
return ( ast_sockaddr_cmp ( & rtpdebugaddr , addr ) = = 0 ) ; /* look for RTP packets from IP+Port */
} else {
return ( ast_sockaddr_cmp_addr ( & rtpdebugaddr , addr ) = = 0 ) ; /* only look for RTP packets from IP */
}
}
2009-04-02 17:20:52 +00:00
2011-11-28 14:34:14 +00:00
return 1 ;
2009-04-02 17:20:52 +00:00
}
2010-07-08 22:08:07 +00:00
static inline int rtcp_debug_test_addr ( struct ast_sockaddr * addr )
2009-04-02 17:20:52 +00:00
{
if ( ! rtcpdebug ) {
return 0 ;
}
2011-11-28 14:34:14 +00:00
if ( ! ast_sockaddr_isnull ( & rtcpdebugaddr ) ) {
if ( rtcpdebugport ) {
return ( ast_sockaddr_cmp ( & rtcpdebugaddr , addr ) = = 0 ) ; /* look for RTCP packets from IP+Port */
} else {
return ( ast_sockaddr_cmp_addr ( & rtcpdebugaddr , addr ) = = 0 ) ; /* only look for RTCP packets from IP */
}
}
2009-04-02 17:20:52 +00:00
2011-11-28 14:34:14 +00:00
return 1 ;
2009-04-02 17:20:52 +00:00
}
2012-09-20 18:27:28 +00:00
# ifdef HAVE_OPENSSL_SRTP
2015-07-01 12:55:47 +00:00
static int dtls_srtp_handle_timeout ( struct ast_rtp_instance * instance , int rtcp )
2014-04-25 19:26:14 +00:00
{
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
2015-07-01 12:55:47 +00:00
struct dtls_details * dtls = ! rtcp ? & rtp - > dtls : & rtp - > rtcp - > dtls ;
struct timeval dtls_timeout ;
DTLSv1_handle_timeout ( dtls - > ssl ) ;
dtls_srtp_check_pending ( instance , rtp , rtcp ) ;
2014-04-25 19:26:14 +00:00
2015-07-01 12:55:47 +00:00
/* If a timeout can't be retrieved then this recurring scheduled item must stop */
if ( ! DTLSv1_get_timeout ( dtls - > ssl , & dtls_timeout ) ) {
dtls - > timeout_timer = - 1 ;
2014-04-25 19:26:14 +00:00
return 0 ;
}
2015-07-01 12:55:47 +00:00
return dtls_timeout . tv_sec * 1000 + dtls_timeout . tv_usec / 1000 ;
}
static int dtls_srtp_handle_rtp_timeout ( const void * data )
{
struct ast_rtp_instance * instance = ( struct ast_rtp_instance * ) data ;
int reschedule ;
reschedule = dtls_srtp_handle_timeout ( instance , 0 ) ;
if ( ! reschedule ) {
2014-04-25 19:26:14 +00:00
ao2_ref ( instance , - 1 ) ;
}
2015-07-01 12:55:47 +00:00
return reschedule ;
}
static int dtls_srtp_handle_rtcp_timeout ( const void * data )
{
struct ast_rtp_instance * instance = ( struct ast_rtp_instance * ) data ;
int reschedule ;
reschedule = dtls_srtp_handle_timeout ( instance , 1 ) ;
2014-04-25 19:26:14 +00:00
2015-07-01 12:55:47 +00:00
if ( ! reschedule ) {
ao2_ref ( instance , - 1 ) ;
2014-04-25 19:26:14 +00:00
}
2015-07-01 12:55:47 +00:00
return reschedule ;
}
static void dtls_srtp_start_timeout_timer ( struct ast_rtp_instance * instance , struct ast_rtp * rtp , int rtcp )
{
struct dtls_details * dtls = ! rtcp ? & rtp - > dtls : & rtp - > rtcp - > dtls ;
struct timeval dtls_timeout ;
if ( DTLSv1_get_timeout ( dtls - > ssl , & dtls_timeout ) ) {
int timeout = dtls_timeout . tv_sec * 1000 + dtls_timeout . tv_usec / 1000 ;
ast_assert ( dtls - > timeout_timer = = - 1 ) ;
ao2_ref ( instance , + 1 ) ;
if ( ( dtls - > timeout_timer = ast_sched_add ( rtp - > sched , timeout ,
! rtcp ? dtls_srtp_handle_rtp_timeout : dtls_srtp_handle_rtcp_timeout , instance ) ) < 0 ) {
ao2_ref ( instance , - 1 ) ;
ast_log ( LOG_WARNING , " Scheduling '%s' DTLS retransmission for RTP instance [%p] failed. \n " ,
! rtcp ? " RTP " : " RTCP " , instance ) ;
}
2014-06-30 19:51:28 +00:00
}
2015-07-01 12:55:47 +00:00
}
2014-04-25 19:26:14 +00:00
2015-07-01 12:55:47 +00:00
static void dtls_srtp_stop_timeout_timer ( struct ast_rtp_instance * instance , struct ast_rtp * rtp , int rtcp )
{
struct dtls_details * dtls = ! rtcp ? & rtp - > dtls : & rtp - > rtcp - > dtls ;
2014-04-25 19:26:14 +00:00
2015-07-01 12:55:47 +00:00
AST_SCHED_DEL_UNREF ( rtp - > sched , dtls - > timeout_timer , ao2_ref ( instance , - 1 ) ) ;
2014-04-25 19:26:14 +00:00
}
2014-06-30 19:51:28 +00:00
static void dtls_srtp_check_pending ( struct ast_rtp_instance * instance , struct ast_rtp * rtp , int rtcp )
2012-09-20 18:27:28 +00:00
{
2014-06-30 19:51:28 +00:00
struct dtls_details * dtls = ! rtcp ? & rtp - > dtls : & rtp - > rtcp - > dtls ;
size_t pending ;
2012-09-20 18:27:28 +00:00
2014-06-30 19:51:28 +00:00
if ( ! dtls - > ssl | | ! dtls - > write_bio ) {
return ;
}
pending = BIO_ctrl_pending ( dtls - > write_bio ) ;
2012-09-20 18:27:28 +00:00
if ( pending > 0 ) {
char outgoing [ pending ] ;
size_t out ;
struct ast_sockaddr remote_address = { { 0 , } } ;
int ice ;
2014-06-30 19:51:28 +00:00
if ( ! rtcp ) {
ast_rtp_instance_get_remote_address ( instance , & remote_address ) ;
} else {
ast_sockaddr_copy ( & remote_address , & rtp - > rtcp - > them ) ;
}
2012-09-20 18:27:28 +00:00
/* If we do not yet know an address to send this to defer it until we do */
if ( ast_sockaddr_isnull ( & remote_address ) ) {
return ;
}
2014-06-30 19:51:28 +00:00
out = BIO_read ( dtls - > write_bio , outgoing , sizeof ( outgoing ) ) ;
__rtp_sendto ( instance , outgoing , out , 0 , & remote_address , rtcp , & ice , 0 ) ;
2012-09-20 18:27:28 +00:00
}
}
static int dtls_srtp_renegotiate ( const void * data )
{
struct ast_rtp_instance * instance = ( struct ast_rtp_instance * ) data ;
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
2014-06-30 19:51:28 +00:00
SSL_renegotiate ( rtp - > dtls . ssl ) ;
SSL_do_handshake ( rtp - > dtls . ssl ) ;
dtls_srtp_check_pending ( instance , rtp , 0 ) ;
if ( rtp - > rtcp & & rtp - > rtcp - > dtls . ssl ) {
SSL_renegotiate ( rtp - > rtcp - > dtls . ssl ) ;
SSL_do_handshake ( rtp - > rtcp - > dtls . ssl ) ;
dtls_srtp_check_pending ( instance , rtp , 1 ) ;
}
2012-09-20 18:27:28 +00:00
rtp - > rekeyid = - 1 ;
ao2_ref ( instance , - 1 ) ;
return 0 ;
}
static int dtls_srtp_setup ( struct ast_rtp * rtp , struct ast_srtp * srtp , struct ast_rtp_instance * instance )
{
unsigned char material [ SRTP_MASTER_LEN * 2 ] ;
unsigned char * local_key , * local_salt , * remote_key , * remote_salt ;
struct ast_srtp_policy * local_policy , * remote_policy = NULL ;
struct ast_rtp_instance_stats stats = { 0 , } ;
2015-04-28 10:38:30 +00:00
int res = - 1 ;
2012-09-20 18:27:28 +00:00
/* If a fingerprint is present in the SDP make sure that the peer certificate matches it */
2014-06-30 19:51:28 +00:00
if ( rtp - > dtls_verify & AST_RTP_DTLS_VERIFY_FINGERPRINT ) {
2012-09-20 18:27:28 +00:00
X509 * certificate ;
2014-06-30 19:51:28 +00:00
if ( ! ( certificate = SSL_get_peer_certificate ( rtp - > dtls . ssl ) ) ) {
2012-09-20 18:27:28 +00:00
ast_log ( LOG_WARNING , " No certificate was provided by the peer on RTP instance '%p' \n " , instance ) ;
return - 1 ;
}
/* If a fingerprint is present in the SDP make sure that the peer certificate matches it */
if ( rtp - > remote_fingerprint [ 0 ] ) {
2014-06-30 19:51:28 +00:00
const EVP_MD * type ;
2012-09-20 18:27:28 +00:00
unsigned char fingerprint [ EVP_MAX_MD_SIZE ] ;
unsigned int size ;
2014-06-30 19:51:28 +00:00
if ( rtp - > remote_hash = = AST_RTP_DTLS_HASH_SHA1 ) {
type = EVP_sha1 ( ) ;
} else if ( rtp - > remote_hash = = AST_RTP_DTLS_HASH_SHA256 ) {
type = EVP_sha256 ( ) ;
} else {
ast_log ( LOG_WARNING , " Unsupported fingerprint hash type on RTP instance '%p' \n " , instance ) ;
return - 1 ;
}
if ( ! X509_digest ( certificate , type , fingerprint , & size ) | |
2012-09-20 18:27:28 +00:00
! size | |
memcmp ( fingerprint , rtp - > remote_fingerprint , size ) ) {
X509_free ( certificate ) ;
ast_log ( LOG_WARNING , " Fingerprint provided by remote party does not match that of peer certificate on RTP instance '%p' \n " ,
instance ) ;
return - 1 ;
}
}
X509_free ( certificate ) ;
}
/* Ensure that certificate verification was successful */
2014-06-30 19:51:28 +00:00
if ( ( rtp - > dtls_verify & AST_RTP_DTLS_VERIFY_CERTIFICATE ) & & SSL_get_verify_result ( rtp - > dtls . ssl ) ! = X509_V_OK ) {
2012-09-20 18:27:28 +00:00
ast_log ( LOG_WARNING , " Peer certificate on RTP instance '%p' failed verification test \n " ,
instance ) ;
return - 1 ;
}
/* Produce key information and set up SRTP */
2014-06-30 19:51:28 +00:00
if ( ! SSL_export_keying_material ( rtp - > dtls . ssl , material , SRTP_MASTER_LEN * 2 , " EXTRACTOR-dtls_srtp " , 19 , NULL , 0 , 0 ) ) {
2012-09-20 18:27:28 +00:00
ast_log ( LOG_WARNING , " Unable to extract SRTP keying material from DTLS-SRTP negotiation on RTP instance '%p' \n " ,
instance ) ;
return - 1 ;
}
/* Whether we are acting as a server or client determines where the keys/salts are */
2014-06-30 19:51:28 +00:00
if ( rtp - > dtls . dtls_setup = = AST_RTP_DTLS_SETUP_ACTIVE ) {
2012-09-20 18:27:28 +00:00
local_key = material ;
remote_key = local_key + SRTP_MASTER_KEY_LEN ;
local_salt = remote_key + SRTP_MASTER_KEY_LEN ;
remote_salt = local_salt + SRTP_MASTER_SALT_LEN ;
} else {
remote_key = material ;
local_key = remote_key + SRTP_MASTER_KEY_LEN ;
remote_salt = local_key + SRTP_MASTER_KEY_LEN ;
local_salt = remote_salt + SRTP_MASTER_SALT_LEN ;
}
if ( ! ( local_policy = res_srtp_policy - > alloc ( ) ) ) {
return - 1 ;
}
if ( res_srtp_policy - > set_master_key ( local_policy , local_key , SRTP_MASTER_KEY_LEN , local_salt , SRTP_MASTER_SALT_LEN ) < 0 ) {
ast_log ( LOG_WARNING , " Could not set key/salt information on local policy of '%p' when setting up DTLS-SRTP \n " , rtp ) ;
goto error ;
}
if ( res_srtp_policy - > set_suite ( local_policy , rtp - > suite ) ) {
2014-05-09 22:49:26 +00:00
ast_log ( LOG_WARNING , " Could not set suite to '%u' on local policy of '%p' when setting up DTLS-SRTP \n " , rtp - > suite , rtp ) ;
2012-09-20 18:27:28 +00:00
goto error ;
}
if ( ast_rtp_instance_get_stats ( instance , & stats , AST_RTP_INSTANCE_STAT_LOCAL_SSRC ) ) {
goto error ;
}
res_srtp_policy - > set_ssrc ( local_policy , stats . local_ssrc , 0 ) ;
if ( ! ( remote_policy = res_srtp_policy - > alloc ( ) ) ) {
goto error ;
}
if ( res_srtp_policy - > set_master_key ( remote_policy , remote_key , SRTP_MASTER_KEY_LEN , remote_salt , SRTP_MASTER_SALT_LEN ) < 0 ) {
ast_log ( LOG_WARNING , " Could not set key/salt information on remote policy of '%p' when setting up DTLS-SRTP \n " , rtp ) ;
goto error ;
}
if ( res_srtp_policy - > set_suite ( remote_policy , rtp - > suite ) ) {
2014-05-09 22:49:26 +00:00
ast_log ( LOG_WARNING , " Could not set suite to '%u' on remote policy of '%p' when setting up DTLS-SRTP \n " , rtp - > suite , rtp ) ;
2012-09-20 18:27:28 +00:00
goto error ;
}
res_srtp_policy - > set_ssrc ( remote_policy , 0 , 1 ) ;
if ( ast_rtp_instance_add_srtp_policy ( instance , remote_policy , local_policy ) ) {
ast_log ( LOG_WARNING , " Could not set policies when setting up DTLS-SRTP on '%p' \n " , rtp ) ;
goto error ;
}
if ( rtp - > rekey ) {
ao2_ref ( instance , + 1 ) ;
if ( ( rtp - > rekeyid = ast_sched_add ( rtp - > sched , rtp - > rekey * 1000 , dtls_srtp_renegotiate , instance ) ) < 0 ) {
ao2_ref ( instance , - 1 ) ;
goto error ;
}
}
2015-04-28 10:38:30 +00:00
res = 0 ;
2012-09-20 18:27:28 +00:00
error :
2015-04-28 10:38:30 +00:00
/* policy->destroy() called even on success to release local reference to these resources */
2012-09-20 18:27:28 +00:00
res_srtp_policy - > destroy ( local_policy ) ;
if ( remote_policy ) {
res_srtp_policy - > destroy ( remote_policy ) ;
}
2015-04-28 10:38:30 +00:00
return res ;
2012-09-20 18:27:28 +00:00
}
# endif
2010-07-08 22:08:07 +00:00
static int __rtp_recvfrom ( struct ast_rtp_instance * instance , void * buf , size_t size , int flags , struct ast_sockaddr * sa , int rtcp )
2010-06-08 05:29:08 +00:00
{
int len ;
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
struct ast_srtp * srtp = ast_rtp_instance_get_srtp ( instance ) ;
2013-01-04 21:18:07 +00:00
char * in = buf ;
2014-09-16 11:12:30 +00:00
# ifdef HAVE_PJPROJECT
struct ast_sockaddr * loop = rtcp ? & rtp - > rtcp_loop : & rtp - > rtp_loop ;
# endif
2010-06-08 05:29:08 +00:00
2010-07-08 22:08:07 +00:00
if ( ( len = ast_recvfrom ( rtcp ? rtp - > rtcp - > s : rtp - > s , buf , size , flags , sa ) ) < 0 ) {
2010-06-08 05:29:08 +00:00
return len ;
}
2012-09-20 18:27:28 +00:00
# ifdef HAVE_OPENSSL_SRTP
2015-05-10 12:37:54 +00:00
/* If this is an SSL packet pass it to OpenSSL for processing. RFC section for first byte value:
* https : //tools.ietf.org/html/rfc5764#section-5.1.2 */
if ( ( * in > = 20 ) & & ( * in < = 63 ) ) {
2014-06-30 19:51:28 +00:00
struct dtls_details * dtls = ! rtcp ? & rtp - > dtls : & rtp - > rtcp - > dtls ;
int res = 0 ;
2012-09-20 18:27:28 +00:00
2014-06-30 19:51:28 +00:00
/* If no SSL session actually exists terminate things */
if ( ! dtls - > ssl ) {
ast_log ( LOG_ERROR , " Received SSL traffic on RTP instance '%p' without an SSL session \n " ,
instance ) ;
return - 1 ;
}
2012-09-20 18:27:28 +00:00
2015-07-01 12:55:47 +00:00
/* This mutex is locked so that this thread blocks until the dtls_perform_handshake function
* completes .
*/
ast_mutex_lock ( & dtls - > lock ) ;
ast_mutex_unlock ( & dtls - > lock ) ;
/* Before we feed data into OpenSSL ensure that the timeout timer is either stopped or completed */
dtls_srtp_stop_timeout_timer ( instance , rtp , rtcp ) ;
2014-06-30 19:51:28 +00:00
/* If we don't yet know if we are active or passive and we receive a packet... we are obviously passive */
if ( dtls - > dtls_setup = = AST_RTP_DTLS_SETUP_ACTPASS ) {
dtls - > dtls_setup = AST_RTP_DTLS_SETUP_PASSIVE ;
SSL_set_accept_state ( dtls - > ssl ) ;
}
2012-09-20 18:27:28 +00:00
2014-06-30 19:51:28 +00:00
dtls_srtp_check_pending ( instance , rtp , rtcp ) ;
2012-09-20 18:27:28 +00:00
2014-06-30 19:51:28 +00:00
BIO_write ( dtls - > read_bio , buf , len ) ;
2012-09-20 18:27:28 +00:00
2014-06-30 19:51:28 +00:00
len = SSL_read ( dtls - > ssl , buf , len ) ;
2012-09-20 18:27:28 +00:00
2014-06-30 19:51:28 +00:00
if ( ( len < 0 ) & & ( SSL_get_error ( dtls - > ssl , len ) = = SSL_ERROR_SSL ) ) {
unsigned long error = ERR_get_error ( ) ;
ast_log ( LOG_ERROR , " DTLS failure occurred on RTP instance '%p' due to reason '%s', terminating \n " ,
instance , ERR_reason_error_string ( error ) ) ;
return - 1 ;
}
2012-09-20 18:27:28 +00:00
2014-06-30 19:51:28 +00:00
dtls_srtp_check_pending ( instance , rtp , rtcp ) ;
2012-09-20 18:27:28 +00:00
2014-06-30 19:51:28 +00:00
if ( SSL_is_init_finished ( dtls - > ssl ) ) {
/* Any further connections will be existing since this is now established */
dtls - > connection = AST_RTP_DTLS_CONNECTION_EXISTING ;
if ( ! rtcp ) {
2012-09-20 18:27:28 +00:00
/* Use the keying material to set up key/salt information */
res = dtls_srtp_setup ( rtp , srtp , instance ) ;
}
2015-07-01 12:55:47 +00:00
} else {
/* Since we've sent additional traffic start the timeout timer for retransmission */
dtls_srtp_start_timeout_timer ( instance , rtp , rtcp ) ;
2012-09-20 18:27:28 +00:00
}
2014-06-30 19:51:28 +00:00
return res ;
2012-09-20 18:27:28 +00:00
}
# endif
2013-03-12 19:08:59 +00:00
# ifdef HAVE_PJPROJECT
2014-09-16 11:12:30 +00:00
if ( ! ast_sockaddr_isnull ( loop ) & & ! ast_sockaddr_cmp ( loop , sa ) ) {
/* ICE traffic will have been handled in the TURN callback, so skip it but update the address
* so it reflects the actual source and not the loopback
*/
if ( rtcp ) {
ast_sockaddr_copy ( sa , & rtp - > rtcp - > them ) ;
} else {
ast_rtp_instance_get_remote_address ( instance , sa ) ;
}
} else if ( rtp - > ice ) {
2012-07-01 17:28:57 +00:00
pj_str_t combined = pj_str ( ast_sockaddr_stringify ( sa ) ) ;
pj_sockaddr address ;
2012-09-05 17:38:22 +00:00
pj_status_t status ;
2012-07-01 17:28:57 +00:00
pj_thread_register_check ( ) ;
pj_sockaddr_parse ( pj_AF_UNSPEC ( ) , 0 , & combined , & address ) ;
2013-11-01 12:40:40 +00:00
status = pj_ice_sess_on_rx_pkt ( rtp - > ice , rtcp ? AST_RTP_ICE_COMPONENT_RTCP : AST_RTP_ICE_COMPONENT_RTP ,
2012-09-05 17:38:22 +00:00
rtcp ? TRANSPORT_SOCKET_RTCP : TRANSPORT_SOCKET_RTP , buf , len , & address ,
pj_sockaddr_get_len ( & address ) ) ;
if ( status ! = PJ_SUCCESS ) {
char buf [ 100 ] ;
pj_strerror ( status , buf , sizeof ( buf ) ) ;
ast_log ( LOG_WARNING , " PJ ICE Rx error status code: %d '%s'. \n " ,
2014-09-16 11:12:30 +00:00
( int ) status , buf ) ;
2012-07-01 17:28:57 +00:00
return - 1 ;
}
if ( ! rtp - > passthrough ) {
return 0 ;
}
rtp - > passthrough = 0 ;
}
2013-03-12 19:08:59 +00:00
# endif
2012-07-01 17:28:57 +00:00
2013-03-27 17:07:44 +00:00
if ( ( * in & 0xC0 ) & & res_srtp & & srtp & & res_srtp - > unprotect ( srtp , buf , & len , rtcp ) < 0 ) {
2010-06-08 05:29:08 +00:00
return - 1 ;
}
return len ;
}
2010-07-08 22:08:07 +00:00
static int rtcp_recvfrom ( struct ast_rtp_instance * instance , void * buf , size_t size , int flags , struct ast_sockaddr * sa )
2010-06-08 05:29:08 +00:00
{
2010-07-08 22:08:07 +00:00
return __rtp_recvfrom ( instance , buf , size , flags , sa , 1 ) ;
2010-06-08 05:29:08 +00:00
}
2010-07-08 22:08:07 +00:00
static int rtp_recvfrom ( struct ast_rtp_instance * instance , void * buf , size_t size , int flags , struct ast_sockaddr * sa )
2010-06-08 05:29:08 +00:00
{
2010-07-08 22:08:07 +00:00
return __rtp_recvfrom ( instance , buf , size , flags , sa , 0 ) ;
2010-06-08 05:29:08 +00:00
}
2012-09-20 18:27:28 +00:00
static int __rtp_sendto ( struct ast_rtp_instance * instance , void * buf , size_t size , int flags , struct ast_sockaddr * sa , int rtcp , int * ice , int use_srtp )
2010-06-08 05:29:08 +00:00
{
int len = size ;
void * temp = buf ;
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
struct ast_srtp * srtp = ast_rtp_instance_get_srtp ( instance ) ;
2015-07-09 19:17:53 +00:00
int res ;
2010-06-08 05:29:08 +00:00
2012-07-01 17:28:57 +00:00
* ice = 0 ;
2012-09-20 18:27:28 +00:00
if ( use_srtp & & res_srtp & & srtp & & res_srtp - > protect ( srtp , & temp , & len , rtcp ) < 0 ) {
2012-07-01 17:28:57 +00:00
return - 1 ;
}
2013-03-12 19:08:59 +00:00
# ifdef HAVE_PJPROJECT
2012-07-01 17:28:57 +00:00
if ( rtp - > ice ) {
pj_thread_register_check ( ) ;
2013-11-01 12:40:40 +00:00
if ( pj_ice_sess_send_data ( rtp - > ice , rtcp ? AST_RTP_ICE_COMPONENT_RTCP : AST_RTP_ICE_COMPONENT_RTP , temp , len ) = = PJ_SUCCESS ) {
2012-07-01 17:28:57 +00:00
* ice = 1 ;
2014-06-23 18:50:18 +00:00
return len ;
2012-07-01 17:28:57 +00:00
}
2010-06-08 05:29:08 +00:00
}
2013-03-12 19:08:59 +00:00
# endif
2010-06-08 05:29:08 +00:00
2015-07-09 19:17:53 +00:00
res = ast_sendto ( rtcp ? rtp - > rtcp - > s : rtp - > s , temp , len , flags , sa ) ;
if ( res > 0 ) {
ast_rtp_instance_set_last_tx ( instance , time ( NULL ) ) ;
}
return res ;
2010-06-08 05:29:08 +00:00
}
2012-07-01 17:28:57 +00:00
static int rtcp_sendto ( struct ast_rtp_instance * instance , void * buf , size_t size , int flags , struct ast_sockaddr * sa , int * ice )
2010-06-08 05:29:08 +00:00
{
2012-09-20 18:27:28 +00:00
return __rtp_sendto ( instance , buf , size , flags , sa , 1 , ice , 1 ) ;
2010-06-08 05:29:08 +00:00
}
2012-07-01 17:28:57 +00:00
static int rtp_sendto ( struct ast_rtp_instance * instance , void * buf , size_t size , int flags , struct ast_sockaddr * sa , int * ice )
2010-06-08 05:29:08 +00:00
{
2012-09-20 18:27:28 +00:00
return __rtp_sendto ( instance , buf , size , flags , sa , 0 , ice , 1 ) ;
2010-06-08 05:29:08 +00:00
}
2011-02-03 16:22:10 +00:00
static int rtp_get_rate ( struct ast_format * format )
2009-07-08 23:19:09 +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
/* For those wondering: due to a fluke in RFC publication, G.722 is advertised
* as having a sample rate of 8 kHz , while implementations must know that its
* real rate is 16 kHz . Seriously .
*/
return ( ast_format_cmp ( format , ast_format_g722 ) = = AST_FORMAT_CMP_EQUAL ) ? 8000 : ( int ) ast_format_get_sample_rate ( format ) ;
2009-07-08 23:19:09 +00:00
}
2009-04-02 17:20:52 +00:00
static unsigned int ast_rtcp_calc_interval ( struct ast_rtp * rtp )
{
unsigned int interval ;
/*! \todo XXX Do a more reasonable calculation on this one
* Look in RFC 3550 Section A .7 for an example */
interval = rtcpinterval ;
return interval ;
}
/*! \brief Calculate normal deviation */
static double normdev_compute ( double normdev , double sample , unsigned int sample_count )
{
normdev = normdev * sample_count + sample ;
sample_count + + ;
return normdev / sample_count ;
}
static double stddev_compute ( double stddev , double sample , double normdev , double normdev_curent , unsigned int sample_count )
{
/*
for the formula check http : //www.cs.umd.edu/~austinjp/constSD.pdf
return sqrt ( ( sample_count * pow ( stddev , 2 ) + sample_count * pow ( ( sample - normdev ) / ( sample_count + 1 ) , 2 ) + pow ( sample - normdev_curent , 2 ) ) / ( sample_count + 1 ) ) ;
we can compute the sigma ^ 2 and that way we would have to do the sqrt only 1 time at the end and would save another pow 2 compute
optimized formula
*/
# define SQUARE(x) ((x) * (x))
stddev = sample_count * stddev ;
sample_count + + ;
return stddev +
( sample_count * SQUARE ( ( sample - normdev ) / sample_count ) ) +
( SQUARE ( sample - normdev_curent ) / sample_count ) ;
# undef SQUARE
}
2010-07-08 22:08:07 +00:00
static int create_new_socket ( const char * type , int af )
2009-04-02 17:20:52 +00:00
{
2010-07-08 22:08:07 +00:00
int sock = socket ( af , SOCK_DGRAM , 0 ) ;
2009-04-02 17:20:52 +00:00
if ( sock < 0 ) {
if ( ! type ) {
type = " RTP/RTCP " ;
}
ast_log ( LOG_WARNING , " Unable to allocate %s socket: %s \n " , type , strerror ( errno ) ) ;
} else {
long flags = fcntl ( sock , F_GETFL ) ;
fcntl ( sock , F_SETFL , flags | O_NONBLOCK ) ;
# ifdef SO_NO_CHECK
if ( nochecksums ) {
setsockopt ( sock , SOL_SOCKET , SO_NO_CHECK , & nochecksums , sizeof ( nochecksums ) ) ;
}
# endif
}
return sock ;
}
2012-01-17 17:15:05 +00:00
/*!
* \ internal
* \ brief Initializes sequence values and probation for learning mode .
* \ note This is an adaptation of pjmedia ' s pjmedia_rtp_seq_init function .
*
2013-03-07 15:48:06 +00:00
* \ param info The learning information to track
* \ param seq sequence number read from the rtp header to initialize the information with
2012-01-17 17:15:05 +00:00
*/
2013-03-07 15:48:06 +00:00
static void rtp_learning_seq_init ( struct rtp_learning_info * info , uint16_t seq )
2012-01-17 17:15:05 +00:00
{
2013-03-07 15:48:06 +00:00
info - > max_seq = seq - 1 ;
info - > packets = learning_min_sequential ;
2012-01-17 17:15:05 +00:00
}
/*!
* \ internal
* \ brief Updates sequence information for learning mode and determines if probation / learning mode should remain in effect .
* \ note This function was adapted from pjmedia ' s pjmedia_rtp_seq_update function .
*
2013-03-07 15:48:06 +00:00
* \ param info Structure tracking the learning progress of some address
2012-01-17 17:15:05 +00:00
* \ param seq sequence number read from the rtp header
2013-03-07 15:48:06 +00:00
* \ retval 0 if probation mode should exit for this address
* \ retval non - zero if probation mode should continue
2012-01-17 17:15:05 +00:00
*/
2013-03-07 15:48:06 +00:00
static int rtp_learning_rtp_seq_update ( struct rtp_learning_info * info , uint16_t seq )
2012-01-17 17:15:05 +00:00
{
2013-03-07 15:48:06 +00:00
if ( seq = = info - > max_seq + 1 ) {
2012-01-17 17:15:05 +00:00
/* packet is in sequence */
2013-03-07 15:48:06 +00:00
info - > packets - - ;
2012-01-17 17:15:05 +00:00
} else {
2013-03-07 15:48:06 +00:00
/* Sequence discontinuity; reset */
info - > packets = learning_min_sequential - 1 ;
2012-01-17 17:15:05 +00:00
}
2013-03-07 15:48:06 +00:00
info - > max_seq = seq ;
2012-01-17 17:15:05 +00:00
2013-03-07 15:48:06 +00:00
return ( info - > packets = = 0 ) ;
2012-01-17 17:15:05 +00:00
}
2013-03-12 19:08:59 +00:00
# ifdef HAVE_PJPROJECT
2012-07-01 17:28:57 +00:00
static void rtp_add_candidates_to_ice ( struct ast_rtp_instance * instance , struct ast_rtp * rtp , struct ast_sockaddr * addr , int port , int component ,
2014-09-16 11:12:30 +00:00
int transport )
2012-07-01 17:28:57 +00:00
{
pj_sockaddr address [ 16 ] ;
unsigned int count = PJ_ARRAY_SIZE ( address ) , pos = 0 ;
/* Add all the local interface IP addresses */
2013-10-08 15:46:16 +00:00
if ( ast_sockaddr_is_ipv4 ( addr ) ) {
pj_enum_ip_interface ( pj_AF_INET ( ) , & count , address ) ;
} else if ( ast_sockaddr_is_any ( addr ) ) {
pj_enum_ip_interface ( pj_AF_UNSPEC ( ) , & count , address ) ;
} else {
pj_enum_ip_interface ( pj_AF_INET6 ( ) , & count , address ) ;
}
2012-07-01 17:28:57 +00:00
for ( pos = 0 ; pos < count ; pos + + ) {
pj_sockaddr_set_port ( & address [ pos ] , port ) ;
ast_rtp_ice_add_cand ( rtp , component , transport , PJ_ICE_CAND_TYPE_HOST , 65535 , & address [ pos ] , & address [ pos ] , NULL ,
pj_sockaddr_get_len ( & address [ pos ] ) ) ;
}
/* If configured to use a STUN server to get our external mapped address do so */
2014-02-27 19:54:19 +00:00
if ( stunaddr . sin_addr . s_addr & & ast_sockaddr_is_ipv4 ( addr ) & & count ) {
2012-07-01 17:28:57 +00:00
struct sockaddr_in answer ;
2014-02-27 19:54:19 +00:00
if ( ! ast_stun_request ( component = = AST_RTP_ICE_COMPONENT_RTCP ? rtp - > rtcp - > s : rtp - > s , & stunaddr , NULL , & answer ) ) {
pj_sockaddr base ;
2012-07-01 17:28:57 +00:00
pj_str_t mapped = pj_str ( ast_strdupa ( ast_inet_ntoa ( answer . sin_addr ) ) ) ;
2014-02-27 19:54:19 +00:00
/* Use the first local host candidate as the base */
pj_sockaddr_cp ( & base , & address [ 0 ] ) ;
2012-07-01 17:28:57 +00:00
pj_sockaddr_init ( pj_AF_INET ( ) , & address [ 0 ] , & mapped , ntohs ( answer . sin_port ) ) ;
2014-02-27 19:54:19 +00:00
ast_rtp_ice_add_cand ( rtp , component , transport , PJ_ICE_CAND_TYPE_SRFLX , 65535 , & address [ 0 ] , & base ,
2014-09-30 11:36:14 +00:00
& base , pj_sockaddr_get_len ( & address [ 0 ] ) ) ;
2012-07-01 17:28:57 +00:00
}
}
/* If configured to use a TURN relay create a session and allocate */
2014-09-16 11:12:30 +00:00
if ( pj_strlen ( & turnaddr ) ) {
ast_rtp_ice_turn_request ( instance , component , AST_TRANSPORT_TCP , pj_strbuf ( & turnaddr ) , turnport ,
pj_strbuf ( & turnusername ) , pj_strbuf ( & turnpassword ) ) ;
2012-07-01 17:28:57 +00:00
}
}
2013-03-12 19:08:59 +00:00
# endif
2012-07-01 17:28:57 +00:00
2013-10-23 17:56:44 +00:00
/*!
* \ internal
* \ brief Calculates the elapsed time from issue of the first tx packet in an
* rtp session and a specified time
*
* \ param rtp pointer to the rtp struct with the transmitted rtp packet
* \ param delivery time of delivery - if NULL or zero value , will be ast_tvnow ( )
*
* \ return time elapsed in milliseconds
*/
static unsigned int calc_txstamp ( struct ast_rtp * rtp , struct timeval * delivery )
{
struct timeval t ;
long ms ;
if ( ast_tvzero ( rtp - > txcore ) ) {
rtp - > txcore = ast_tvnow ( ) ;
rtp - > txcore . tv_usec - = rtp - > txcore . tv_usec % 20000 ;
}
t = ( delivery & & ! ast_tvzero ( * delivery ) ) ? * delivery : ast_tvnow ( ) ;
if ( ( ms = ast_tvdiff_ms ( t , rtp - > txcore ) ) < 0 ) {
ms = 0 ;
}
rtp - > txcore = t ;
return ( unsigned int ) ms ;
}
2014-03-04 17:22:32 +00:00
# ifdef HAVE_PJPROJECT
/*!
* \ internal
* \ brief Creates an ICE session . Can be used to replace a destroyed ICE session .
*
* \ param instance RTP instance for which the ICE session is being replaced
* \ param addr ast_sockaddr to use for adding RTP candidates to the ICE session
* \ param port port to use for adding RTP candidates to the ICE session
* \ param replace 0 when creating a new session , 1 when replacing a destroyed session
*
* \ retval 0 on success
* \ retval - 1 on failure
*/
static int ice_create ( struct ast_rtp_instance * instance , struct ast_sockaddr * addr ,
int port , int replace )
{
pj_stun_config stun_config ;
pj_str_t ufrag , passwd ;
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
ao2_cleanup ( rtp - > ice_local_candidates ) ;
rtp - > ice_local_candidates = NULL ;
pj_thread_register_check ( ) ;
2014-09-16 11:12:30 +00:00
pj_stun_config_init ( & stun_config , & cachingpool . factory , 0 , NULL , timer_heap ) ;
2014-03-04 17:22:32 +00:00
ufrag = pj_str ( rtp - > local_ufrag ) ;
passwd = pj_str ( rtp - > local_passwd ) ;
/* Create an ICE session for ICE negotiation */
if ( pj_ice_sess_create ( & stun_config , NULL , PJ_ICE_SESS_ROLE_UNKNOWN , 2 ,
& ast_rtp_ice_sess_cb , & ufrag , & passwd , NULL , & rtp - > ice ) = = PJ_SUCCESS ) {
/* Make this available for the callbacks */
2014-06-30 19:51:28 +00:00
rtp - > ice - > user_data = instance ;
2014-03-04 17:22:32 +00:00
/* Add all of the available candidates to the ICE session */
rtp_add_candidates_to_ice ( instance , rtp , addr , port , AST_RTP_ICE_COMPONENT_RTP ,
2014-09-16 11:12:30 +00:00
TRANSPORT_SOCKET_RTP ) ;
2014-03-04 17:22:32 +00:00
/* Only add the RTCP candidates to ICE when replacing the session. New sessions
* handle this in a separate part of the setup phase */
if ( replace & & rtp - > rtcp ) {
rtp_add_candidates_to_ice ( instance , rtp , & rtp - > rtcp - > us ,
ast_sockaddr_port ( & rtp - > rtcp - > us ) , AST_RTP_ICE_COMPONENT_RTCP ,
2014-09-16 11:12:30 +00:00
TRANSPORT_SOCKET_RTCP ) ;
2014-03-04 17:22:32 +00:00
}
return 0 ;
}
return - 1 ;
}
# endif
2010-07-08 22:08:07 +00:00
static int ast_rtp_new ( struct ast_rtp_instance * instance ,
2010-12-20 17:15:54 +00:00
struct ast_sched_context * sched , struct ast_sockaddr * addr ,
2010-07-08 22:08:07 +00:00
void * data )
2009-04-02 17:20:52 +00:00
{
struct ast_rtp * rtp = NULL ;
int x , startplace ;
/* Create a new RTP structure to hold all of our data */
if ( ! ( rtp = ast_calloc ( 1 , sizeof ( * rtp ) ) ) ) {
return - 1 ;
}
2012-07-01 17:28:57 +00:00
/* Initialize synchronization aspects */
ast_mutex_init ( & rtp - > lock ) ;
ast_cond_init ( & rtp - > cond , NULL ) ;
2009-04-02 17:20:52 +00:00
/* Set default parameters on the newly created RTP structure */
rtp - > ssrc = ast_random ( ) ;
rtp - > seqno = ast_random ( ) & 0xffff ;
rtp - > strict_rtp_state = ( strictrtp ? STRICT_RTP_LEARN : STRICT_RTP_OPEN ) ;
2012-01-17 17:15:05 +00:00
if ( strictrtp ) {
2013-03-07 15:48:06 +00:00
rtp_learning_seq_init ( & rtp - > rtp_source_learn , ( uint16_t ) rtp - > seqno ) ;
rtp_learning_seq_init ( & rtp - > alt_source_learn , ( uint16_t ) rtp - > seqno ) ;
2012-01-17 17:15:05 +00:00
}
2009-04-02 17:20:52 +00:00
/* Create a new socket for us to listen on and use */
2010-07-08 22:08:07 +00:00
if ( ( rtp - > s =
create_new_socket ( " RTP " ,
ast_sockaddr_is_ipv4 ( addr ) ? AF_INET :
ast_sockaddr_is_ipv6 ( addr ) ? AF_INET6 : - 1 ) ) < 0 ) {
2015-09-04 21:33:39 +00:00
ast_log ( LOG_WARNING , " Failed to create a new socket for RTP instance '%p' \n " , instance ) ;
2009-04-02 17:20:52 +00:00
ast_free ( rtp ) ;
return - 1 ;
}
/* Now actually find a free RTP port to use */
x = ( rtpend = = rtpstart ) ? rtpstart : ( ast_random ( ) % ( rtpend - rtpstart ) ) + rtpstart ;
x = x & ~ 1 ;
startplace = x ;
for ( ; ; ) {
2010-07-08 22:08:07 +00:00
ast_sockaddr_set_port ( addr , x ) ;
2009-04-02 17:20:52 +00:00
/* Try to bind, this will tell us whether the port is available or not */
2010-07-08 22:08:07 +00:00
if ( ! ast_bind ( rtp - > s , addr ) ) {
2009-04-02 17:20:52 +00:00
ast_debug ( 1 , " Allocated port %d for RTP instance '%p' \n " , x , instance ) ;
2010-07-08 22:08:07 +00:00
ast_rtp_instance_set_local_address ( instance , addr ) ;
2009-04-02 17:20:52 +00:00
break ;
}
x + = 2 ;
if ( x > rtpend ) {
x = ( rtpstart + 1 ) & ~ 1 ;
}
/* See if we ran out of ports or if the bind actually failed because of something other than the address being in use */
2014-01-30 20:36:21 +00:00
if ( x = = startplace | | ( errno ! = EADDRINUSE & & errno ! = EACCES ) ) {
2009-04-02 17:20:52 +00:00
ast_log ( LOG_ERROR , " Oh dear... we couldn't allocate a port for RTP instance '%p' \n " , instance ) ;
2012-05-18 14:43:44 +00:00
close ( rtp - > s ) ;
ast_free ( rtp ) ;
2009-04-02 17:20:52 +00:00
return - 1 ;
}
}
2013-03-12 19:08:59 +00:00
# ifdef HAVE_PJPROJECT
2012-07-01 17:28:57 +00:00
generate_random_string ( rtp - > local_ufrag , sizeof ( rtp - > local_ufrag ) ) ;
generate_random_string ( rtp - > local_passwd , sizeof ( rtp - > local_passwd ) ) ;
2013-03-13 14:39:54 +00:00
# endif
2009-04-02 17:20:52 +00:00
ast_rtp_instance_set_data ( instance , rtp ) ;
2013-03-13 14:39:54 +00:00
# ifdef HAVE_PJPROJECT
2012-07-01 17:28:57 +00:00
/* Create an ICE session for ICE negotiation */
2014-03-04 17:22:32 +00:00
if ( icesupport ) {
2015-09-04 21:33:39 +00:00
ast_debug ( 3 , " Creating ICE session %s (%d) for RTP instance '%p' \n " , ast_sockaddr_stringify ( addr ) , x , instance ) ;
2014-03-04 17:22:32 +00:00
if ( ice_create ( instance , addr , x , 0 ) ) {
ast_log ( LOG_NOTICE , " Failed to start ICE session \n " ) ;
} else {
rtp - > ice_port = x ;
ast_sockaddr_copy ( & rtp - > ice_original_rtp_addr , addr ) ;
}
2012-07-01 17:28:57 +00:00
}
2013-03-12 19:08:59 +00:00
# endif
2012-07-01 17:28:57 +00:00
/* Record any information we may need */
rtp - > sched = sched ;
2012-09-20 18:27:28 +00:00
# ifdef HAVE_OPENSSL_SRTP
rtp - > rekeyid = - 1 ;
2015-07-08 09:21:16 +00:00
rtp - > dtls . timeout_timer = - 1 ;
2012-09-20 18:27:28 +00:00
# endif
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
rtp - > f . subclass . format = ao2_bump ( ast_format_none ) ;
rtp - > lastrxformat = ao2_bump ( ast_format_none ) ;
rtp - > lasttxformat = ao2_bump ( ast_format_none ) ;
2009-04-02 17:20:52 +00:00
return 0 ;
}
static int ast_rtp_destroy ( struct ast_rtp_instance * instance )
{
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
2014-09-16 21:06:22 +00:00
# ifdef HAVE_PJPROJECT
2014-09-16 11:12:30 +00:00
struct timeval wait = ast_tvadd ( ast_tvnow ( ) , ast_samp2tv ( TURN_STATE_WAIT_TIME , 1000 ) ) ;
struct timespec ts = { . tv_sec = wait . tv_sec , . tv_nsec = wait . tv_usec * 1000 , } ;
2014-09-16 21:06:22 +00:00
# endif
2009-04-02 17:20:52 +00:00
2015-07-01 12:55:47 +00:00
# ifdef HAVE_OPENSSL_SRTP
ast_rtp_dtls_stop ( instance ) ;
# endif
2009-04-02 17:20:52 +00:00
/* Destroy the smoother that was smoothing out audio if present */
if ( rtp - > smoother ) {
ast_smoother_free ( rtp - > smoother ) ;
}
/* Close our own socket so we no longer get packets */
if ( rtp - > s > - 1 ) {
close ( rtp - > s ) ;
}
/* Destroy RTCP if it was being used */
if ( rtp - > rtcp ) {
2011-09-20 01:11:18 +00:00
/*
* It is not possible for there to be an active RTCP scheduler
* entry at this point since it holds a reference to the
* RTP instance while it ' s active .
*/
2009-04-02 17:20:52 +00:00
close ( rtp - > rtcp - > s ) ;
ast_free ( rtp - > rtcp ) ;
}
/* Destroy RED if it was being used */
if ( rtp - > red ) {
AST_SCHED_DEL ( rtp - > sched , rtp - > red - > schedid ) ;
ast_free ( rtp - > red ) ;
}
2013-03-12 19:08:59 +00:00
# ifdef HAVE_PJPROJECT
2012-07-01 17:28:57 +00:00
pj_thread_register_check ( ) ;
/* Destroy the RTP TURN relay if being used */
2014-09-16 11:12:30 +00:00
ast_mutex_lock ( & rtp - > lock ) ;
2012-07-01 17:28:57 +00:00
if ( rtp - > turn_rtp ) {
pj_turn_sock_destroy ( rtp - > turn_rtp ) ;
2014-09-16 11:12:30 +00:00
rtp - > turn_state = PJ_TURN_STATE_NULL ;
while ( rtp - > turn_state ! = PJ_TURN_STATE_DESTROYING ) {
ast_cond_timedwait ( & rtp - > cond , & rtp - > lock , & ts ) ;
}
2012-07-01 17:28:57 +00:00
}
/* Destroy the RTCP TURN relay if being used */
if ( rtp - > turn_rtcp ) {
pj_turn_sock_destroy ( rtp - > turn_rtcp ) ;
2014-09-16 11:12:30 +00:00
rtp - > turn_state = PJ_TURN_STATE_NULL ;
while ( rtp - > turn_state ! = PJ_TURN_STATE_DESTROYING ) {
ast_cond_timedwait ( & rtp - > cond , & rtp - > lock , & ts ) ;
}
}
ast_mutex_unlock ( & rtp - > lock ) ;
if ( rtp - > ioqueue ) {
rtp_ioqueue_thread_remove ( rtp - > ioqueue ) ;
}
/* Destroy the ICE session if being used */
if ( rtp - > ice ) {
pj_ice_sess_destroy ( rtp - > ice ) ;
2012-07-01 17:28:57 +00:00
}
/* Destroy any candidates */
2014-03-04 17:22:32 +00:00
if ( rtp - > ice_local_candidates ) {
ao2_ref ( rtp - > ice_local_candidates , - 1 ) ;
2012-07-01 17:28:57 +00:00
}
2014-03-04 17:22:32 +00:00
if ( rtp - > ice_active_remote_candidates ) {
ao2_ref ( rtp - > ice_active_remote_candidates , - 1 ) ;
2012-07-01 17:28:57 +00:00
}
2013-03-12 19:08:59 +00:00
# endif
2012-07-01 17:28: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 ( rtp - > lasttxformat ) ;
ao2_cleanup ( rtp - > lastrxformat ) ;
ao2_cleanup ( rtp - > f . subclass . format ) ;
2012-07-01 17:28:57 +00:00
/* Destroy synchronization items */
ast_mutex_destroy ( & rtp - > lock ) ;
ast_cond_destroy ( & rtp - > cond ) ;
2009-04-02 17:20:52 +00:00
/* Finally destroy ourselves */
ast_free ( rtp ) ;
return 0 ;
}
2011-07-19 18:07:22 +00:00
static int ast_rtp_dtmf_mode_set ( struct ast_rtp_instance * instance , enum ast_rtp_dtmf_mode dtmf_mode )
{
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
rtp - > dtmfmode = dtmf_mode ;
return 0 ;
}
static enum ast_rtp_dtmf_mode ast_rtp_dtmf_mode_get ( struct ast_rtp_instance * instance )
{
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
return rtp - > dtmfmode ;
}
2009-04-02 17:20:52 +00:00
static int ast_rtp_dtmf_begin ( struct ast_rtp_instance * instance , char digit )
{
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
2010-07-08 22:08:07 +00:00
struct ast_sockaddr remote_address = { { 0 , } } ;
2009-04-02 17:20:52 +00:00
int hdrlen = 12 , res = 0 , i = 0 , payload = 101 ;
char data [ 256 ] ;
unsigned int * rtpheader = ( unsigned int * ) data ;
ast_rtp_instance_get_remote_address ( instance , & remote_address ) ;
/* If we have no remote address information bail out now */
2010-07-08 22:08:07 +00:00
if ( ast_sockaddr_isnull ( & remote_address ) ) {
2009-04-02 17:20:52 +00:00
return - 1 ;
}
/* Convert given digit into what we want to transmit */
if ( ( digit < = ' 9 ' ) & & ( digit > = ' 0 ' ) ) {
digit - = ' 0 ' ;
} else if ( digit = = ' * ' ) {
digit = 10 ;
} else if ( digit = = ' # ' ) {
digit = 11 ;
} else if ( ( digit > = ' A ' ) & & ( digit < = ' D ' ) ) {
digit = digit - ' A ' + 12 ;
} else if ( ( digit > = ' a ' ) & & ( digit < = ' d ' ) ) {
digit = digit - ' a ' + 12 ;
} else {
ast_log ( LOG_WARNING , " Don't know how to represent '%c' \n " , digit ) ;
return - 1 ;
}
/* Grab the payload that they expect the RFC2833 packet to be received in */
2015-07-24 00:24:04 +00:00
payload = ast_rtp_codecs_payload_code_tx ( ast_rtp_instance_get_codecs ( instance ) , 0 , NULL , AST_RTP_DTMF ) ;
2009-04-02 17:20:52 +00:00
rtp - > dtmfmute = ast_tvadd ( ast_tvnow ( ) , ast_tv ( 0 , 500000 ) ) ;
rtp - > send_duration = 160 ;
2013-10-23 17:56:44 +00:00
rtp - > lastts + = calc_txstamp ( rtp , NULL ) * DTMF_SAMPLE_RATE_MS ;
2009-04-02 17:20:52 +00:00
rtp - > lastdigitts = rtp - > lastts + rtp - > send_duration ;
/* Create the actual packet that we will be sending */
rtpheader [ 0 ] = htonl ( ( 2 < < 30 ) | ( 1 < < 23 ) | ( payload < < 16 ) | ( rtp - > seqno ) ) ;
rtpheader [ 1 ] = htonl ( rtp - > lastdigitts ) ;
rtpheader [ 2 ] = htonl ( rtp - > ssrc ) ;
/* Actually send the packet */
for ( i = 0 ; i < 2 ; i + + ) {
2012-07-01 17:28:57 +00:00
int ice ;
2009-04-02 17:20:52 +00:00
rtpheader [ 3 ] = htonl ( ( digit < < 24 ) | ( 0xa < < 16 ) | ( rtp - > send_duration ) ) ;
2012-07-01 17:28:57 +00:00
res = rtp_sendto ( instance , ( void * ) rtpheader , hdrlen + 4 , 0 , & remote_address , & ice ) ;
2009-04-02 17:20:52 +00:00
if ( res < 0 ) {
2010-07-08 22:08:07 +00:00
ast_log ( LOG_ERROR , " RTP Transmission error to %s: %s \n " ,
ast_sockaddr_stringify ( & remote_address ) ,
strerror ( errno ) ) ;
2009-04-02 17:20:52 +00:00
}
if ( rtp_debug_test_addr ( & remote_address ) ) {
2014-05-09 22:49:26 +00:00
ast_verbose ( " Sent RTP DTMF packet to %s%s (type %-2.2d, seq %-6.6d, ts %-6.6u, len %-6.6d) \n " ,
2010-07-08 22:08:07 +00:00
ast_sockaddr_stringify ( & remote_address ) ,
2012-07-01 17:28:57 +00:00
ice ? " (via ICE) " : " " ,
2010-07-08 22:08:07 +00:00
payload , rtp - > seqno , rtp - > lastdigitts , res - hdrlen ) ;
2009-04-02 17:20:52 +00:00
}
rtp - > seqno + + ;
rtp - > send_duration + = 160 ;
rtpheader [ 0 ] = htonl ( ( 2 < < 30 ) | ( payload < < 16 ) | ( rtp - > seqno ) ) ;
}
/* Record that we are in the process of sending a digit and information needed to continue doing so */
rtp - > sending_digit = 1 ;
rtp - > send_digit = digit ;
rtp - > send_payload = payload ;
return 0 ;
}
static int ast_rtp_dtmf_continuation ( struct ast_rtp_instance * instance )
{
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
2010-07-08 22:08:07 +00:00
struct ast_sockaddr remote_address = { { 0 , } } ;
2009-04-02 17:20:52 +00:00
int hdrlen = 12 , res = 0 ;
char data [ 256 ] ;
unsigned int * rtpheader = ( unsigned int * ) data ;
2012-07-01 17:28:57 +00:00
int ice ;
2009-04-02 17:20:52 +00:00
ast_rtp_instance_get_remote_address ( instance , & remote_address ) ;
/* Make sure we know where the other side is so we can send them the packet */
2010-07-08 22:08:07 +00:00
if ( ast_sockaddr_isnull ( & remote_address ) ) {
2009-04-02 17:20:52 +00:00
return - 1 ;
}
/* Actually create the packet we will be sending */
2012-09-05 04:55:07 +00:00
rtpheader [ 0 ] = htonl ( ( 2 < < 30 ) | ( rtp - > send_payload < < 16 ) | ( rtp - > seqno ) ) ;
2009-04-02 17:20:52 +00:00
rtpheader [ 1 ] = htonl ( rtp - > lastdigitts ) ;
rtpheader [ 2 ] = htonl ( rtp - > ssrc ) ;
rtpheader [ 3 ] = htonl ( ( rtp - > send_digit < < 24 ) | ( 0xa < < 16 ) | ( rtp - > send_duration ) ) ;
/* Boom, send it on out */
2012-07-01 17:28:57 +00:00
res = rtp_sendto ( instance , ( void * ) rtpheader , hdrlen + 4 , 0 , & remote_address , & ice ) ;
2009-04-02 17:20:52 +00:00
if ( res < 0 ) {
2010-07-08 22:08:07 +00:00
ast_log ( LOG_ERROR , " RTP Transmission error to %s: %s \n " ,
ast_sockaddr_stringify ( & remote_address ) ,
strerror ( errno ) ) ;
2009-04-02 17:20:52 +00:00
}
if ( rtp_debug_test_addr ( & remote_address ) ) {
2014-05-09 22:49:26 +00:00
ast_verbose ( " Sent RTP DTMF packet to %s%s (type %-2.2d, seq %-6.6d, ts %-6.6u, len %-6.6d) \n " ,
2010-07-08 22:08:07 +00:00
ast_sockaddr_stringify ( & remote_address ) ,
2012-07-01 17:28:57 +00:00
ice ? " (via ICE) " : " " ,
2010-07-08 22:08:07 +00:00
rtp - > send_payload , rtp - > seqno , rtp - > lastdigitts , res - hdrlen ) ;
2009-04-02 17:20:52 +00:00
}
/* And now we increment some values for the next time we swing by */
rtp - > seqno + + ;
rtp - > send_duration + = 160 ;
2013-10-23 17:56:44 +00:00
rtp - > lastts + = calc_txstamp ( rtp , NULL ) * DTMF_SAMPLE_RATE_MS ;
2009-04-02 17:20:52 +00:00
return 0 ;
}
2010-10-02 02:46:43 +00:00
static int ast_rtp_dtmf_end_with_duration ( struct ast_rtp_instance * instance , char digit , unsigned int duration )
2009-04-02 17:20:52 +00:00
{
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
2010-07-08 22:08:07 +00:00
struct ast_sockaddr remote_address = { { 0 , } } ;
2013-05-01 21:18:24 +00:00
int hdrlen = 12 , res = - 1 , i = 0 ;
2009-04-02 17:20:52 +00:00
char data [ 256 ] ;
unsigned int * rtpheader = ( unsigned int * ) data ;
2010-10-02 02:46:43 +00:00
unsigned int measured_samples ;
2009-04-02 17:20:52 +00:00
ast_rtp_instance_get_remote_address ( instance , & remote_address ) ;
/* Make sure we know where the remote side is so we can send them the packet we construct */
2010-07-08 22:08:07 +00:00
if ( ast_sockaddr_isnull ( & remote_address ) ) {
2013-05-01 21:18:24 +00:00
goto cleanup ;
2009-04-02 17:20:52 +00:00
}
/* Convert the given digit to the one we are going to send */
if ( ( digit < = ' 9 ' ) & & ( digit > = ' 0 ' ) ) {
digit - = ' 0 ' ;
} else if ( digit = = ' * ' ) {
digit = 10 ;
} else if ( digit = = ' # ' ) {
digit = 11 ;
} else if ( ( digit > = ' A ' ) & & ( digit < = ' D ' ) ) {
digit = digit - ' A ' + 12 ;
} else if ( ( digit > = ' a ' ) & & ( digit < = ' d ' ) ) {
digit = digit - ' a ' + 12 ;
} else {
ast_log ( LOG_WARNING , " Don't know how to represent '%c' \n " , digit ) ;
2013-05-01 21:18:24 +00:00
goto cleanup ;
2009-04-02 17:20:52 +00:00
}
rtp - > dtmfmute = ast_tvadd ( ast_tvnow ( ) , ast_tv ( 0 , 500000 ) ) ;
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 ( duration > 0 & & ( measured_samples = duration * rtp_get_rate ( rtp - > f . subclass . format ) / 1000 ) > rtp - > send_duration ) {
2014-05-09 22:49:26 +00:00
ast_debug ( 2 , " Adjusting final end duration from %d to %u \n " , rtp - > send_duration , measured_samples ) ;
2010-10-02 02:46:43 +00:00
rtp - > send_duration = measured_samples ;
}
2009-04-02 17:20:52 +00:00
/* Construct the packet we are going to send */
rtpheader [ 1 ] = htonl ( rtp - > lastdigitts ) ;
rtpheader [ 2 ] = htonl ( rtp - > ssrc ) ;
rtpheader [ 3 ] = htonl ( ( digit < < 24 ) | ( 0xa < < 16 ) | ( rtp - > send_duration ) ) ;
rtpheader [ 3 ] | = htonl ( ( 1 < < 23 ) ) ;
/* Send it 3 times, that's the magical number */
for ( i = 0 ; i < 3 ; i + + ) {
2012-07-01 17:28:57 +00:00
int ice ;
2012-09-05 04:55:07 +00:00
rtpheader [ 0 ] = htonl ( ( 2 < < 30 ) | ( rtp - > send_payload < < 16 ) | ( rtp - > seqno ) ) ;
2012-09-05 12:18:47 +00:00
res = rtp_sendto ( instance , ( void * ) rtpheader , hdrlen + 4 , 0 , & remote_address , & ice ) ;
2012-07-01 17:28:57 +00:00
2009-04-02 17:20:52 +00:00
if ( res < 0 ) {
2010-07-08 22:08:07 +00:00
ast_log ( LOG_ERROR , " RTP Transmission error to %s: %s \n " ,
ast_sockaddr_stringify ( & remote_address ) ,
strerror ( errno ) ) ;
2009-04-02 17:20:52 +00:00
}
2012-07-01 17:28:57 +00:00
2009-04-02 17:20:52 +00:00
if ( rtp_debug_test_addr ( & remote_address ) ) {
2014-05-09 22:49:26 +00:00
ast_verbose ( " Sent RTP DTMF packet to %s%s (type %-2.2d, seq %-6.6d, ts %-6.6u, len %-6.6d) \n " ,
2010-07-08 22:08:07 +00:00
ast_sockaddr_stringify ( & remote_address ) ,
2012-07-01 17:28:57 +00:00
ice ? " (via ICE) " : " " ,
2010-07-08 22:08:07 +00:00
rtp - > send_payload , rtp - > seqno , rtp - > lastdigitts , res - hdrlen ) ;
2009-04-02 17:20:52 +00:00
}
2012-09-05 04:55:07 +00:00
rtp - > seqno + + ;
2009-04-02 17:20:52 +00:00
}
2013-05-01 21:18:24 +00:00
res = 0 ;
2009-04-02 17:20:52 +00:00
/* Oh and we can't forget to turn off the stuff that says we are sending DTMF */
2013-10-23 17:56:44 +00:00
rtp - > lastts + = calc_txstamp ( rtp , NULL ) * DTMF_SAMPLE_RATE_MS ;
2013-05-01 21:18:24 +00:00
cleanup :
2009-04-02 17:20:52 +00:00
rtp - > sending_digit = 0 ;
rtp - > send_digit = 0 ;
2013-05-01 21:18:24 +00:00
return res ;
2009-04-02 17:20:52 +00:00
}
2010-10-02 02:46:43 +00:00
static int ast_rtp_dtmf_end ( struct ast_rtp_instance * instance , char digit )
{
return ast_rtp_dtmf_end_with_duration ( instance , digit , 0 ) ;
}
2010-03-12 22:04:51 +00:00
static void ast_rtp_update_source ( struct ast_rtp_instance * instance )
2009-04-02 17:20:52 +00:00
{
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
/* We simply set this bit so that the next packet sent will have the marker bit turned on */
ast_set_flag ( rtp , FLAG_NEED_MARKER_BIT ) ;
2010-03-12 22:04:51 +00:00
ast_debug ( 3 , " Setting the marker bit due to a source update \n " ) ;
2009-04-02 17:20:52 +00:00
2010-03-12 22:04:51 +00:00
return ;
}
static void ast_rtp_change_source ( struct ast_rtp_instance * instance )
{
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
2010-09-01 18:52:27 +00:00
struct ast_srtp * srtp = ast_rtp_instance_get_srtp ( instance ) ;
2010-03-12 22:04:51 +00:00
unsigned int ssrc = ast_random ( ) ;
2010-09-01 18:52:27 +00:00
if ( ! rtp - > lastts ) {
ast_debug ( 3 , " Not changing SSRC since we haven't sent any RTP yet \n " ) ;
return ;
}
2010-03-12 22:04:51 +00:00
/* We simply set this bit so that the next packet sent will have the marker bit turned on */
ast_set_flag ( rtp , FLAG_NEED_MARKER_BIT ) ;
ast_debug ( 3 , " Changing ssrc from %u to %u due to a source change \n " , rtp - > ssrc , ssrc ) ;
2010-09-01 18:52:27 +00:00
if ( srtp ) {
ast_debug ( 3 , " Changing ssrc for SRTP from %u to %u \n " , rtp - > ssrc , ssrc ) ;
res_srtp - > change_source ( srtp , rtp - > ssrc , ssrc ) ;
}
2010-03-12 22:04:51 +00:00
rtp - > ssrc = ssrc ;
Merged revisions 221086 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r221086 | twilson | 2009-09-30 09:49:11 -0500 (Wed, 30 Sep 2009) | 25 lines
Change the SSRC by default when our media stream changes
Be default, change SSRC when doing an audio stream changes Asterisk doesn't
honor marker bit when reinvited to already-bridged RTP streams,resulting in
far-end stack discarding packets with "old" timestamps that areactually part of
a new stream. This patch sends AST_CONTROL_SRCUPDATE whenever there is a
reinvite, unless the 'constantssrc' is set to true in sip.conf.
The original issue reported to Digium support detailed the following situation:
ITSP <-> Asterisk 1.4.26.2 <-> SIP-based Application Server Call comes in
fromITSP, Asterisk dials the app server which sends a re-invite back
toAsterisk--not to negotiate to send media directly to the ITSP, but to
indicatethat it's changing the stream it's sending to Asterisk. The app
servergenerates a new SSRC, sequence numbers, timestamps, and sets the marker
bit on the new stream. Asterisk passes through the teimstamp of the new stream,
butdoes not reset the SSRC, sequence numbers, or set the marker bit.
When the timestamp on the new stream is older than the timestamp on the
originalstream, the ITSP (which doesn't know there has been any change) discards
the newframes because it thinks they are too old. This patch addresses this by
changing the SSRC on a stream update unless constantssrc=true is set in
sip.conf.
Review: https://reviewboard.asterisk.org/r/374/
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@221266 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-09-30 17:52:30 +00:00
2009-04-02 17:20:52 +00:00
return ;
}
static void timeval2ntp ( struct timeval tv , unsigned int * msw , unsigned int * lsw )
{
unsigned int sec , usec , frac ;
sec = tv . tv_sec + 2208988800u ; /* Sec between 1900 and 1970 */
usec = tv . tv_usec ;
frac = ( usec < < 12 ) + ( usec < < 8 ) - ( ( usec * 3650 ) > > 6 ) ;
* msw = sec ;
* lsw = frac ;
}
2013-07-05 17:33:33 +00:00
static void ntp2timeval ( unsigned int msw , unsigned int lsw , struct timeval * tv )
2009-04-02 17:20:52 +00:00
{
2013-07-05 17:33:33 +00:00
tv - > tv_sec = msw - 2208988800u ;
tv - > tv_usec = ( ( lsw < < 6 ) / 3650 ) - ( lsw > > 12 ) - ( lsw > > 8 ) ;
}
static void calculate_lost_packet_statistics ( struct ast_rtp * rtp ,
unsigned int * lost_packets ,
int * fraction_lost )
{
unsigned int extended_seq_no ;
unsigned int expected_packets ;
2009-04-02 17:20:52 +00:00
unsigned int expected_interval ;
unsigned int received_interval ;
double rxlost_current ;
2013-07-05 17:33:33 +00:00
int lost_interval ;
2009-04-02 17:20:52 +00:00
2013-07-05 17:33:33 +00:00
/* Compute statistics */
extended_seq_no = rtp - > cycles + rtp - > lastrxseqno ;
expected_packets = extended_seq_no - rtp - > seedrxseqno + 1 ;
if ( rtp - > rxcount > expected_packets ) {
expected_packets + = rtp - > rxcount - expected_packets ;
2012-12-03 16:45:49 +00:00
}
2013-07-05 17:33:33 +00:00
* lost_packets = expected_packets - rtp - > rxcount ;
expected_interval = expected_packets - rtp - > rtcp - > expected_prior ;
2009-04-02 17:20:52 +00:00
received_interval = rtp - > rxcount - rtp - > rtcp - > received_prior ;
lost_interval = expected_interval - received_interval ;
2013-07-05 17:33:33 +00:00
if ( expected_interval = = 0 | | lost_interval < = 0 ) {
* fraction_lost = 0 ;
} else {
* fraction_lost = ( lost_interval < < 8 ) / expected_interval ;
}
2009-04-02 17:20:52 +00:00
2013-07-05 17:33:33 +00:00
/* Update RTCP statistics */
rtp - > rtcp - > received_prior = rtp - > rxcount ;
rtp - > rtcp - > expected_prior = expected_packets ;
2012-12-03 16:45:49 +00:00
if ( lost_interval < = 0 ) {
2009-04-02 17:20:52 +00:00
rtp - > rtcp - > rxlost = 0 ;
2012-12-03 16:45:49 +00:00
} else {
2013-07-05 17:33:33 +00:00
rtp - > rtcp - > rxlost = lost_interval ;
2012-12-03 16:45:49 +00:00
}
if ( rtp - > rtcp - > rxlost_count = = 0 ) {
2009-04-02 17:20:52 +00:00
rtp - > rtcp - > minrxlost = rtp - > rtcp - > rxlost ;
2012-12-03 16:45:49 +00:00
}
if ( lost_interval < rtp - > rtcp - > minrxlost ) {
2009-04-02 17:20:52 +00:00
rtp - > rtcp - > minrxlost = rtp - > rtcp - > rxlost ;
2012-12-03 16:45:49 +00:00
}
if ( lost_interval > rtp - > rtcp - > maxrxlost ) {
2009-04-02 17:20:52 +00:00
rtp - > rtcp - > maxrxlost = rtp - > rtcp - > rxlost ;
2012-12-03 16:45:49 +00:00
}
2013-07-05 17:33:33 +00:00
rxlost_current = normdev_compute ( rtp - > rtcp - > normdev_rxlost ,
rtp - > rtcp - > rxlost ,
rtp - > rtcp - > rxlost_count ) ;
rtp - > rtcp - > stdev_rxlost = stddev_compute ( rtp - > rtcp - > stdev_rxlost ,
rtp - > rtcp - > rxlost ,
rtp - > rtcp - > normdev_rxlost ,
rxlost_current ,
rtp - > rtcp - > rxlost_count ) ;
2009-04-02 17:20:52 +00:00
rtp - > rtcp - > normdev_rxlost = rxlost_current ;
rtp - > rtcp - > rxlost_count + + ;
}
2013-07-05 17:33:33 +00:00
/*! \brief Send RTCP SR or RR report */
static int ast_rtcp_write_report ( struct ast_rtp_instance * instance , int sr )
2009-04-02 17:20:52 +00:00
{
2010-06-08 05:29:08 +00:00
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
2013-07-05 17:33:33 +00:00
RAII_VAR ( struct ast_json * , message_blob , NULL , ast_json_unref ) ;
2009-04-02 17:20:52 +00:00
int res ;
int len = 0 ;
struct timeval now ;
unsigned int now_lsw ;
unsigned int now_msw ;
unsigned int * rtcpheader ;
2013-07-05 17:33:33 +00:00
unsigned int lost_packets ;
int fraction_lost ;
struct timeval dlsr = { 0 , } ;
2009-04-02 17:20:52 +00:00
char bdata [ 512 ] ;
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
int rate = rtp_get_rate ( rtp - > f . subclass . format ) ;
2012-07-01 17:28:57 +00:00
int ice ;
2013-07-05 17:33:33 +00:00
int header_offset = 0 ;
res_hep_rtcp: Add module that sends RTCP information to a Homer Server
This patch adds a new module to Asterisk, res_hep_rtcp. The module subscribes
to the RTCP topics in Stasis and receives RTCP information back from the
message bus. It encodes into HEPv3 packets and sends the information to the
res_hep module for transmission.
Using this, someone with a Homer server can get live call quality monitoring
for all RTP-based channels in their Asterisk 12+ systems.
In addition, there were a few bugs in the RTP engine, res_rtp_asterisk, and
chan_pjsip that were uncovered by the tests written for the Asterisk Test
Suite. This patch fixes the following:
1) chan_pjsip failed to set its channel unique ids on its RTP instance on
outbound calls. It now does this in the appropriate location, in the
serialized call callback.
2) The rtp_engine was overflowing some values when packed into JSON.
Specifically, some longs and unsigned ints can't be be packed into integer
values, for obvious reasons. Since libjansson only supports integers,
floats, strings, booleans, and objects, we print these values into strings.
3) res_rtp_asterisk had a few problems:
(a) it would emit a source IP address of 0.0.0.0 if bound to that IP
address. We now use ast_find_ourip to get a better IP address, and
properly marshal the result into an ast_strdupa'd string.
(b) Reports can be generated with no report bodies. In particular, this
occurs when a sender is transmitting information to a receiver (who
will send no RTP back to the sender). As such, the sender has no report
body for what it received. We now properly handle this case, and the
sender will emit SR reports with no body. Likewise, if we receive an
RTCP packet with no report body, we will still generate the appropriate
events.
ASTERISK-24119 #close
........
Merged revisions 419823 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419825 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-31 11:57:51 +00:00
char * str_remote_address ;
char * str_local_address ;
struct ast_sockaddr remote_address = { { 0 , } } ;
struct ast_sockaddr local_address = { { 0 , } } ;
struct ast_sockaddr real_remote_address = { { 0 , } } ;
struct ast_sockaddr real_local_address = { { 0 , } } ;
struct ast_rtp_rtcp_report_block * report_block = NULL ;
2013-07-05 17:33:33 +00:00
RAII_VAR ( struct ast_rtp_rtcp_report * , rtcp_report ,
res_hep_rtcp: Add module that sends RTCP information to a Homer Server
This patch adds a new module to Asterisk, res_hep_rtcp. The module subscribes
to the RTCP topics in Stasis and receives RTCP information back from the
message bus. It encodes into HEPv3 packets and sends the information to the
res_hep module for transmission.
Using this, someone with a Homer server can get live call quality monitoring
for all RTP-based channels in their Asterisk 12+ systems.
In addition, there were a few bugs in the RTP engine, res_rtp_asterisk, and
chan_pjsip that were uncovered by the tests written for the Asterisk Test
Suite. This patch fixes the following:
1) chan_pjsip failed to set its channel unique ids on its RTP instance on
outbound calls. It now does this in the appropriate location, in the
serialized call callback.
2) The rtp_engine was overflowing some values when packed into JSON.
Specifically, some longs and unsigned ints can't be be packed into integer
values, for obvious reasons. Since libjansson only supports integers,
floats, strings, booleans, and objects, we print these values into strings.
3) res_rtp_asterisk had a few problems:
(a) it would emit a source IP address of 0.0.0.0 if bound to that IP
address. We now use ast_find_ourip to get a better IP address, and
properly marshal the result into an ast_strdupa'd string.
(b) Reports can be generated with no report bodies. In particular, this
occurs when a sender is transmitting information to a receiver (who
will send no RTP back to the sender). As such, the sender has no report
body for what it received. We now properly handle this case, and the
sender will emit SR reports with no body. Likewise, if we receive an
RTCP packet with no report body, we will still generate the appropriate
events.
ASTERISK-24119 #close
........
Merged revisions 419823 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419825 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-31 11:57:51 +00:00
ast_rtp_rtcp_report_alloc ( rtp - > themssrc ? 1 : 0 ) ,
2013-07-05 17:33:33 +00:00
ao2_cleanup ) ;
2009-04-02 17:20:52 +00:00
2012-12-03 16:45:49 +00:00
if ( ! rtp | | ! rtp - > rtcp ) {
2009-04-02 17:20:52 +00:00
return 0 ;
2012-12-03 16:45:49 +00:00
}
2009-04-02 17:20:52 +00:00
2010-07-08 22:08:07 +00:00
if ( ast_sockaddr_isnull ( & rtp - > rtcp - > them ) ) { /* This'll stop rtcp for this rtp session */
2013-07-05 17:33:33 +00:00
/* RTCP was stopped. */
2009-04-02 17:20:52 +00:00
return 0 ;
}
2013-07-05 17:33:33 +00:00
if ( ! rtcp_report ) {
return 1 ;
}
/* Compute statistics */
calculate_lost_packet_statistics ( rtp , & lost_packets , & fraction_lost ) ;
2009-04-02 17:20:52 +00:00
gettimeofday ( & now , NULL ) ;
res_hep_rtcp: Add module that sends RTCP information to a Homer Server
This patch adds a new module to Asterisk, res_hep_rtcp. The module subscribes
to the RTCP topics in Stasis and receives RTCP information back from the
message bus. It encodes into HEPv3 packets and sends the information to the
res_hep module for transmission.
Using this, someone with a Homer server can get live call quality monitoring
for all RTP-based channels in their Asterisk 12+ systems.
In addition, there were a few bugs in the RTP engine, res_rtp_asterisk, and
chan_pjsip that were uncovered by the tests written for the Asterisk Test
Suite. This patch fixes the following:
1) chan_pjsip failed to set its channel unique ids on its RTP instance on
outbound calls. It now does this in the appropriate location, in the
serialized call callback.
2) The rtp_engine was overflowing some values when packed into JSON.
Specifically, some longs and unsigned ints can't be be packed into integer
values, for obvious reasons. Since libjansson only supports integers,
floats, strings, booleans, and objects, we print these values into strings.
3) res_rtp_asterisk had a few problems:
(a) it would emit a source IP address of 0.0.0.0 if bound to that IP
address. We now use ast_find_ourip to get a better IP address, and
properly marshal the result into an ast_strdupa'd string.
(b) Reports can be generated with no report bodies. In particular, this
occurs when a sender is transmitting information to a receiver (who
will send no RTP back to the sender). As such, the sender has no report
body for what it received. We now properly handle this case, and the
sender will emit SR reports with no body. Likewise, if we receive an
RTCP packet with no report body, we will still generate the appropriate
events.
ASTERISK-24119 #close
........
Merged revisions 419823 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419825 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-31 11:57:51 +00:00
rtcp_report - > reception_report_count = rtp - > themssrc ? 1 : 0 ;
2013-07-05 17:33:33 +00:00
rtcp_report - > ssrc = rtp - > ssrc ;
rtcp_report - > type = sr ? RTCP_PT_SR : RTCP_PT_RR ;
if ( sr ) {
rtcp_report - > sender_information . ntp_timestamp = now ;
rtcp_report - > sender_information . rtp_timestamp = rtp - > lastts ;
rtcp_report - > sender_information . packet_count = rtp - > txcount ;
rtcp_report - > sender_information . octet_count = rtp - > txoctetcount ;
}
res_hep_rtcp: Add module that sends RTCP information to a Homer Server
This patch adds a new module to Asterisk, res_hep_rtcp. The module subscribes
to the RTCP topics in Stasis and receives RTCP information back from the
message bus. It encodes into HEPv3 packets and sends the information to the
res_hep module for transmission.
Using this, someone with a Homer server can get live call quality monitoring
for all RTP-based channels in their Asterisk 12+ systems.
In addition, there were a few bugs in the RTP engine, res_rtp_asterisk, and
chan_pjsip that were uncovered by the tests written for the Asterisk Test
Suite. This patch fixes the following:
1) chan_pjsip failed to set its channel unique ids on its RTP instance on
outbound calls. It now does this in the appropriate location, in the
serialized call callback.
2) The rtp_engine was overflowing some values when packed into JSON.
Specifically, some longs and unsigned ints can't be be packed into integer
values, for obvious reasons. Since libjansson only supports integers,
floats, strings, booleans, and objects, we print these values into strings.
3) res_rtp_asterisk had a few problems:
(a) it would emit a source IP address of 0.0.0.0 if bound to that IP
address. We now use ast_find_ourip to get a better IP address, and
properly marshal the result into an ast_strdupa'd string.
(b) Reports can be generated with no report bodies. In particular, this
occurs when a sender is transmitting information to a receiver (who
will send no RTP back to the sender). As such, the sender has no report
body for what it received. We now properly handle this case, and the
sender will emit SR reports with no body. Likewise, if we receive an
RTCP packet with no report body, we will still generate the appropriate
events.
ASTERISK-24119 #close
........
Merged revisions 419823 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419825 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-31 11:57:51 +00:00
if ( rtp - > themssrc ) {
report_block = ast_calloc ( 1 , sizeof ( * report_block ) ) ;
if ( ! report_block ) {
return 1 ;
}
rtcp_report - > report_block [ 0 ] = report_block ;
report_block - > source_ssrc = rtp - > themssrc ;
report_block - > lost_count . fraction = ( fraction_lost & 0xff ) ;
report_block - > lost_count . packets = ( lost_packets & 0xffffff ) ;
report_block - > highest_seq_no = ( rtp - > cycles | ( rtp - > lastrxseqno & 0xffff ) ) ;
report_block - > ia_jitter = ( unsigned int ) ( rtp - > rxjitter * rate ) ;
report_block - > lsr = rtp - > rtcp - > themrxlsr ;
/* If we haven't received an SR report, DLSR should be 0 */
if ( ! ast_tvzero ( rtp - > rtcp - > rxlsr ) ) {
timersub ( & now , & rtp - > rtcp - > rxlsr , & dlsr ) ;
report_block - > dlsr = ( ( ( dlsr . tv_sec * 1000 ) + ( dlsr . tv_usec / 1000 ) ) * 65536 ) / 1000 ;
}
2013-07-05 17:33:33 +00:00
}
timeval2ntp ( rtcp_report - > sender_information . ntp_timestamp , & now_msw , & now_lsw ) ;
2009-04-02 17:20:52 +00:00
rtcpheader = ( unsigned int * ) bdata ;
2013-07-05 17:33:33 +00:00
rtcpheader [ 1 ] = htonl ( rtcp_report - > ssrc ) ; /* Our SSRC */
len + = 8 ;
if ( sr ) {
header_offset = 5 ;
rtcpheader [ 2 ] = htonl ( now_msw ) ; /* now, MSW. gettimeofday() + SEC_BETWEEN_1900_AND_1970*/
rtcpheader [ 3 ] = htonl ( now_lsw ) ; /* now, LSW */
rtcpheader [ 4 ] = htonl ( rtcp_report - > sender_information . rtp_timestamp ) ;
rtcpheader [ 5 ] = htonl ( rtcp_report - > sender_information . packet_count ) ;
rtcpheader [ 6 ] = htonl ( rtcp_report - > sender_information . octet_count ) ;
len + = 20 ;
}
res_hep_rtcp: Add module that sends RTCP information to a Homer Server
This patch adds a new module to Asterisk, res_hep_rtcp. The module subscribes
to the RTCP topics in Stasis and receives RTCP information back from the
message bus. It encodes into HEPv3 packets and sends the information to the
res_hep module for transmission.
Using this, someone with a Homer server can get live call quality monitoring
for all RTP-based channels in their Asterisk 12+ systems.
In addition, there were a few bugs in the RTP engine, res_rtp_asterisk, and
chan_pjsip that were uncovered by the tests written for the Asterisk Test
Suite. This patch fixes the following:
1) chan_pjsip failed to set its channel unique ids on its RTP instance on
outbound calls. It now does this in the appropriate location, in the
serialized call callback.
2) The rtp_engine was overflowing some values when packed into JSON.
Specifically, some longs and unsigned ints can't be be packed into integer
values, for obvious reasons. Since libjansson only supports integers,
floats, strings, booleans, and objects, we print these values into strings.
3) res_rtp_asterisk had a few problems:
(a) it would emit a source IP address of 0.0.0.0 if bound to that IP
address. We now use ast_find_ourip to get a better IP address, and
properly marshal the result into an ast_strdupa'd string.
(b) Reports can be generated with no report bodies. In particular, this
occurs when a sender is transmitting information to a receiver (who
will send no RTP back to the sender). As such, the sender has no report
body for what it received. We now properly handle this case, and the
sender will emit SR reports with no body. Likewise, if we receive an
RTCP packet with no report body, we will still generate the appropriate
events.
ASTERISK-24119 #close
........
Merged revisions 419823 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419825 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-31 11:57:51 +00:00
if ( report_block ) {
rtcpheader [ 2 + header_offset ] = htonl ( report_block - > source_ssrc ) ; /* Their SSRC */
rtcpheader [ 3 + header_offset ] = htonl ( ( report_block - > lost_count . fraction < < 24 ) | report_block - > lost_count . packets ) ;
rtcpheader [ 4 + header_offset ] = htonl ( report_block - > highest_seq_no ) ;
rtcpheader [ 5 + header_offset ] = htonl ( report_block - > ia_jitter ) ;
rtcpheader [ 6 + header_offset ] = htonl ( report_block - > lsr ) ;
rtcpheader [ 7 + header_offset ] = htonl ( report_block - > dlsr ) ;
len + = 24 ;
}
rtcpheader [ 0 ] = htonl ( ( 2 < < 30 ) | ( rtcp_report - > reception_report_count < < 24 )
| ( ( sr ? RTCP_PT_SR : RTCP_PT_RR ) < < 16 ) | ( ( len / 4 ) - 1 ) ) ;
2009-04-02 17:20:52 +00:00
/* Insert SDES here. Probably should make SDES text equal to mimetypes[code].type (not subtype 'cos */
/* it can change mid call, and SDES can't) */
rtcpheader [ len / 4 ] = htonl ( ( 2 < < 30 ) | ( 1 < < 24 ) | ( RTCP_PT_SDES < < 16 ) | 2 ) ;
2013-07-05 17:33:33 +00:00
rtcpheader [ ( len / 4 ) + 1 ] = htonl ( rtcp_report - > ssrc ) ;
rtcpheader [ ( len / 4 ) + 2 ] = htonl ( 0x01 < < 24 ) ;
2009-04-02 17:20:52 +00:00
len + = 12 ;
2012-07-01 17:28:57 +00:00
ast_sockaddr_copy ( & remote_address , & rtp - > rtcp - > them ) ;
res = rtcp_sendto ( instance , ( unsigned int * ) rtcpheader , len , 0 , & remote_address , & ice ) ;
2009-04-02 17:20:52 +00:00
if ( res < 0 ) {
2013-07-05 17:33:33 +00:00
ast_log ( LOG_ERROR , " RTCP %s transmission error to %s, rtcp halted %s \n " ,
sr ? " SR " : " RR " ,
2010-07-08 22:08:07 +00:00
ast_sockaddr_stringify ( & rtp - > rtcp - > them ) ,
strerror ( errno ) ) ;
2009-04-02 17:20:52 +00:00
return 0 ;
}
2013-07-05 17:33:33 +00:00
/* Update RTCP SR/RR statistics */
if ( sr ) {
rtp - > rtcp - > txlsr = rtcp_report - > sender_information . ntp_timestamp ;
rtp - > rtcp - > sr_count + + ;
rtp - > rtcp - > lastsrtxcount = rtp - > txcount ;
} else {
rtp - > rtcp - > rr_count + + ;
}
2009-04-02 17:20:52 +00:00
if ( rtcp_debug_test_addr ( & rtp - > rtcp - > them ) ) {
2013-07-05 17:33:33 +00:00
ast_verbose ( " * Sent RTCP %s to %s%s \n " , sr ? " SR " : " RR " ,
ast_sockaddr_stringify ( & remote_address ) , ice ? " (via ICE) " : " " ) ;
ast_verbose ( " Our SSRC: %u \n " , rtcp_report - > ssrc ) ;
if ( sr ) {
ast_verbose ( " Sent(NTP): %u.%010u \n " ,
( unsigned int ) rtcp_report - > sender_information . ntp_timestamp . tv_sec ,
( unsigned int ) rtcp_report - > sender_information . ntp_timestamp . tv_usec * 4096 ) ;
ast_verbose ( " Sent(RTP): %u \n " , rtcp_report - > sender_information . rtp_timestamp ) ;
ast_verbose ( " Sent packets: %u \n " , rtcp_report - > sender_information . packet_count ) ;
ast_verbose ( " Sent octets: %u \n " , rtcp_report - > sender_information . octet_count ) ;
}
2015-02-16 21:29:39 +00:00
if ( report_block ) {
ast_verbose ( " Report block: \n " ) ;
ast_verbose ( " Their SSRC: %u \n " , report_block - > source_ssrc ) ;
ast_verbose ( " Fraction lost: %d \n " , report_block - > lost_count . fraction ) ;
ast_verbose ( " Cumulative loss: %u \n " , report_block - > lost_count . packets ) ;
ast_verbose ( " Highest seq no: %u \n " , report_block - > highest_seq_no ) ;
ast_verbose ( " IA jitter: %.4f \n " , ( double ) report_block - > ia_jitter / rate ) ;
ast_verbose ( " Their last SR: %u \n " , report_block - > lsr ) ;
ast_verbose ( " DLSR: %4.4f (sec) \n \n " , ( double ) ( report_block - > dlsr / 65536.0 ) ) ;
}
2013-07-05 17:33:33 +00:00
}
res_hep_rtcp: Add module that sends RTCP information to a Homer Server
This patch adds a new module to Asterisk, res_hep_rtcp. The module subscribes
to the RTCP topics in Stasis and receives RTCP information back from the
message bus. It encodes into HEPv3 packets and sends the information to the
res_hep module for transmission.
Using this, someone with a Homer server can get live call quality monitoring
for all RTP-based channels in their Asterisk 12+ systems.
In addition, there were a few bugs in the RTP engine, res_rtp_asterisk, and
chan_pjsip that were uncovered by the tests written for the Asterisk Test
Suite. This patch fixes the following:
1) chan_pjsip failed to set its channel unique ids on its RTP instance on
outbound calls. It now does this in the appropriate location, in the
serialized call callback.
2) The rtp_engine was overflowing some values when packed into JSON.
Specifically, some longs and unsigned ints can't be be packed into integer
values, for obvious reasons. Since libjansson only supports integers,
floats, strings, booleans, and objects, we print these values into strings.
3) res_rtp_asterisk had a few problems:
(a) it would emit a source IP address of 0.0.0.0 if bound to that IP
address. We now use ast_find_ourip to get a better IP address, and
properly marshal the result into an ast_strdupa'd string.
(b) Reports can be generated with no report bodies. In particular, this
occurs when a sender is transmitting information to a receiver (who
will send no RTP back to the sender). As such, the sender has no report
body for what it received. We now properly handle this case, and the
sender will emit SR reports with no body. Likewise, if we receive an
RTCP packet with no report body, we will still generate the appropriate
events.
ASTERISK-24119 #close
........
Merged revisions 419823 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419825 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-31 11:57:51 +00:00
ast_rtp_instance_get_local_address ( instance , & local_address ) ;
if ( ! ast_find_ourip ( & real_local_address , & local_address , 0 ) ) {
str_local_address = ast_strdupa ( ast_sockaddr_stringify ( & real_local_address ) ) ;
} else {
str_local_address = ast_strdupa ( ast_sockaddr_stringify ( & local_address ) ) ;
}
if ( ! ast_find_ourip ( & real_remote_address , & remote_address , 0 ) ) {
str_remote_address = ast_strdupa ( ast_sockaddr_stringify ( & real_remote_address ) ) ;
} else {
str_remote_address = ast_strdupa ( ast_sockaddr_stringify ( & remote_address ) ) ;
}
message_blob = ast_json_pack ( " {s: s, s: s} " ,
" to " , str_remote_address ,
" from " , str_local_address ) ;
2013-07-05 17:33:33 +00:00
ast_rtp_publish_rtcp_message ( instance , ast_rtp_rtcp_sent_type ( ) ,
rtcp_report ,
message_blob ) ;
2009-04-02 17:20:52 +00:00
return res ;
}
/*! \brief Write and RTCP packet to the far end
* \ note Decide if we are going to send an SR ( with Reception Block ) or RR
* RR is sent if we have not sent any rtp packets in the previous interval */
static int ast_rtcp_write ( const void * data )
{
2010-06-08 05:29:08 +00:00
struct ast_rtp_instance * instance = ( struct ast_rtp_instance * ) data ;
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
2009-04-02 17:20:52 +00:00
int res ;
2011-09-20 01:11:18 +00:00
if ( ! rtp | | ! rtp - > rtcp | | rtp - > rtcp - > schedid = = - 1 ) {
ao2_ref ( instance , - 1 ) ;
2009-04-02 17:20:52 +00:00
return 0 ;
2011-09-20 01:11:18 +00:00
}
2009-04-02 17:20:52 +00:00
2011-09-20 01:11:18 +00:00
if ( rtp - > txcount > rtp - > rtcp - > lastsrtxcount ) {
2013-07-05 17:33:33 +00:00
/* Send an SR */
res = ast_rtcp_write_report ( instance , 1 ) ;
2011-09-20 01:11:18 +00:00
} else {
2013-07-05 17:33:33 +00:00
/* Send an RR */
res = ast_rtcp_write_report ( instance , 0 ) ;
2011-09-20 01:11:18 +00:00
}
if ( ! res ) {
2013-08-23 15:42:27 +00:00
/*
2011-09-20 01:11:18 +00:00
* Not being rescheduled .
*/
rtp - > rtcp - > schedid = - 1 ;
2015-10-07 01:43:58 +00:00
ao2_ref ( instance , - 1 ) ;
2011-09-20 01:11:18 +00:00
}
2009-04-02 17:20:52 +00:00
return res ;
}
static int ast_rtp_raw_write ( struct ast_rtp_instance * instance , struct ast_frame * frame , int codec )
{
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
int pred , mark = 0 ;
unsigned int ms = calc_txstamp ( rtp , & frame - > delivery ) ;
2010-07-08 22:08:07 +00:00
struct ast_sockaddr remote_address = { { 0 , } } ;
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
int rate = rtp_get_rate ( frame - > subclass . format ) / 1000 ;
2009-07-08 23:19:09 +00:00
media formats: re-architect handling of media for performance improvements
In the old times media formats were represented using a bit field. This was
fast but had a few limitations.
1. Asterisk was limited in how many formats it could handle.
2. Formats, being a bit field, could not include any attribute information.
A format was strictly its type, e.g., "this is ulaw".
This was changed in Asterisk 10 (see
https://wiki.asterisk.org/wiki/display/AST/Media+Architecture+Proposal for
notes on that work) which led to the creation of the ast_format structure.
This structure allowed Asterisk to handle attributes and bundle information
with a format.
Additionally, ast_format_cap was created to act as a container for multiple
formats that, together, formed the capability of some entity. Another
mechanism was added to allow logic to be registered which performed format
attribute negotiation. Everywhere throughout the codebase Asterisk was
changed to use this strategy.
Unfortunately, in software, there is no free lunch. These new capabilities
came at a cost.
Performance analysis and profiling showed that we spend an inordinate
amount of time comparing, copying, and generally manipulating formats and
their related structures. Basic prototyping has shown that a reasonably
large performance improvement could be made in this area. This patch is the
result of that project, which overhauled the media format architecture
and its usage in Asterisk to improve performance.
Generally, the new philosophy for handling formats is as follows:
* The ast_format structure is reference counted. This removed a large amount
of the memory allocations and copying that was done in prior versions.
* In order to prevent race conditions while keeping things performant, the
ast_format structure is immutable by convention and lock-free. Violate this
tenet at your peril!
* Because formats are reference counted, codecs are also reference counted.
The Asterisk core generally provides built-in codecs and caches the
ast_format structures created to represent them. Generally, to prevent
inordinate amounts of module reference bumping, codecs and formats can be
added at run-time but cannot be removed.
* All compatibility with the bit field representation of codecs/formats has
been moved to a compatibility API. The primary user of this representation
is chan_iax2, which must continue to maintain its bit-field usage of formats
for interoperability concerns.
* When a format is negotiated with attributes, or when a format cannot be
represented by one of the cached formats, a new format object is created or
cloned from an existing format. That format may have the same codec
underlying it, but is a different format than a version of the format with
different attributes or without attributes.
* While formats are reference counted objects, the reference count maintained
on the format should be manipulated with care. Formats are generally cached
and will persist for the lifetime of Asterisk and do not explicitly need
to have their lifetime modified. An exception to this is when the user of a
format does not know where the format came from *and* the user may outlive
the provider of the format. This occurs, for example, when a format is read
from a channel: the channel may have a format with attributes (hence,
non-cached) and the user of the format may last longer than the channel (if
the reference to the channel is released prior to the format's reference).
For more information on this work, see the API design notes:
https://wiki.asterisk.org/wiki/display/AST/Media+Format+Rewrite
Finally, this work was the culmination of a large number of developer's
efforts. Extra thanks goes to Corey Farrell, who took on a large amount of the
work in the Asterisk core, chan_sip, and was an invaluable resource in peer
reviews throughout this project.
There were a substantial number of patches contributed during this work; the
following issues/patch names simply reflect some of the work (and will cause
the release scripts to give attribution to the individuals who work on them).
Reviews:
https://reviewboard.asterisk.org/r/3814
https://reviewboard.asterisk.org/r/3808
https://reviewboard.asterisk.org/r/3805
https://reviewboard.asterisk.org/r/3803
https://reviewboard.asterisk.org/r/3801
https://reviewboard.asterisk.org/r/3798
https://reviewboard.asterisk.org/r/3800
https://reviewboard.asterisk.org/r/3794
https://reviewboard.asterisk.org/r/3793
https://reviewboard.asterisk.org/r/3792
https://reviewboard.asterisk.org/r/3791
https://reviewboard.asterisk.org/r/3790
https://reviewboard.asterisk.org/r/3789
https://reviewboard.asterisk.org/r/3788
https://reviewboard.asterisk.org/r/3787
https://reviewboard.asterisk.org/r/3786
https://reviewboard.asterisk.org/r/3784
https://reviewboard.asterisk.org/r/3783
https://reviewboard.asterisk.org/r/3778
https://reviewboard.asterisk.org/r/3774
https://reviewboard.asterisk.org/r/3775
https://reviewboard.asterisk.org/r/3772
https://reviewboard.asterisk.org/r/3761
https://reviewboard.asterisk.org/r/3754
https://reviewboard.asterisk.org/r/3753
https://reviewboard.asterisk.org/r/3751
https://reviewboard.asterisk.org/r/3750
https://reviewboard.asterisk.org/r/3748
https://reviewboard.asterisk.org/r/3747
https://reviewboard.asterisk.org/r/3746
https://reviewboard.asterisk.org/r/3742
https://reviewboard.asterisk.org/r/3740
https://reviewboard.asterisk.org/r/3739
https://reviewboard.asterisk.org/r/3738
https://reviewboard.asterisk.org/r/3737
https://reviewboard.asterisk.org/r/3736
https://reviewboard.asterisk.org/r/3734
https://reviewboard.asterisk.org/r/3722
https://reviewboard.asterisk.org/r/3713
https://reviewboard.asterisk.org/r/3703
https://reviewboard.asterisk.org/r/3689
https://reviewboard.asterisk.org/r/3687
https://reviewboard.asterisk.org/r/3674
https://reviewboard.asterisk.org/r/3671
https://reviewboard.asterisk.org/r/3667
https://reviewboard.asterisk.org/r/3665
https://reviewboard.asterisk.org/r/3625
https://reviewboard.asterisk.org/r/3602
https://reviewboard.asterisk.org/r/3519
https://reviewboard.asterisk.org/r/3518
https://reviewboard.asterisk.org/r/3516
https://reviewboard.asterisk.org/r/3515
https://reviewboard.asterisk.org/r/3512
https://reviewboard.asterisk.org/r/3506
https://reviewboard.asterisk.org/r/3413
https://reviewboard.asterisk.org/r/3410
https://reviewboard.asterisk.org/r/3387
https://reviewboard.asterisk.org/r/3388
https://reviewboard.asterisk.org/r/3389
https://reviewboard.asterisk.org/r/3390
https://reviewboard.asterisk.org/r/3321
https://reviewboard.asterisk.org/r/3320
https://reviewboard.asterisk.org/r/3319
https://reviewboard.asterisk.org/r/3318
https://reviewboard.asterisk.org/r/3266
https://reviewboard.asterisk.org/r/3265
https://reviewboard.asterisk.org/r/3234
https://reviewboard.asterisk.org/r/3178
ASTERISK-23114 #close
Reported by: mjordan
media_formats_translation_core.diff uploaded by kharwell (License 6464)
rb3506.diff uploaded by mjordan (License 6283)
media_format_app_file.diff uploaded by kharwell (License 6464)
misc-2.diff uploaded by file (License 5000)
chan_mild-3.diff uploaded by file (License 5000)
chan_obscure.diff uploaded by file (License 5000)
jingle.diff uploaded by file (License 5000)
funcs.diff uploaded by file (License 5000)
formats.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
bridges.diff uploaded by file (License 5000)
mf-codecs-2.diff uploaded by file (License 5000)
mf-app_fax.diff uploaded by file (License 5000)
mf-apps-3.diff uploaded by file (License 5000)
media-formats-3.diff uploaded by file (License 5000)
ASTERISK-23715
rb3713.patch uploaded by coreyfarrell (License 5909)
rb3689.patch uploaded by mjordan (License 6283)
ASTERISK-23957
rb3722.patch uploaded by mjordan (License 6283)
mf-attributes-3.diff uploaded by file (License 5000)
ASTERISK-23958
Tested by: jrose
rb3822.patch uploaded by coreyfarrell (License 5909)
rb3800.patch uploaded by jrose (License 6182)
chan_sip.diff uploaded by mjordan (License 6283)
rb3747.patch uploaded by jrose (License 6182)
ASTERISK-23959 #close
Tested by: sgriepentrog, mjordan, coreyfarrell
sip_cleanup.diff uploaded by opticron (License 6273)
chan_sip_caps.diff uploaded by mjordan (License 6283)
rb3751.patch uploaded by coreyfarrell (License 5909)
chan_sip-3.diff uploaded by file (License 5000)
ASTERISK-23960 #close
Tested by: opticron
direct_media.diff uploaded by opticron (License 6273)
pjsip-direct-media.diff uploaded by file (License 5000)
format_cap_remove.diff uploaded by opticron (License 6273)
media_format_fixes.diff uploaded by opticron (License 6273)
chan_pjsip-2.diff uploaded by file (License 5000)
ASTERISK-23966 #close
Tested by: rmudgett
rb3803.patch uploaded by rmudgetti (License 5621)
chan_dahdi.diff uploaded by file (License 5000)
ASTERISK-24064 #close
Tested by: coreyfarrell, mjordan, opticron, file, rmudgett, sgriepentrog, jrose
rb3814.patch uploaded by rmudgett (License 5621)
moh_cleanup.diff uploaded by opticron (License 6273)
bridge_leak.diff uploaded by opticron (License 6273)
translate.diff uploaded by file (License 5000)
rb3795.patch uploaded by rmudgett (License 5621)
tls_fix.diff uploaded by mjordan (License 6283)
fax-mf-fix-2.diff uploaded by file (License 5000)
rtp_transfer_stuff uploaded by mjordan (License 6283)
rb3787.patch uploaded by rmudgett (License 5621)
media-formats-explicit-translate-format-3.diff uploaded by file (License 5000)
format_cache_case_fix.diff uploaded by opticron (License 6273)
rb3774.patch uploaded by rmudgett (License 5621)
rb3775.patch uploaded by rmudgett (License 5621)
rtp_engine_fix.diff uploaded by opticron (License 6273)
rtp_crash_fix.diff uploaded by opticron (License 6273)
rb3753.patch uploaded by mjordan (License 6283)
rb3750.patch uploaded by mjordan (License 6283)
rb3748.patch uploaded by rmudgett (License 5621)
media_format_fixes.diff uploaded by opticron (License 6273)
rb3740.patch uploaded by mjordan (License 6283)
rb3739.patch uploaded by mjordan (License 6283)
rb3734.patch uploaded by mjordan (License 6283)
rb3689.patch uploaded by mjordan (License 6283)
rb3674.patch uploaded by coreyfarrell (License 5909)
rb3671.patch uploaded by coreyfarrell (License 5909)
rb3667.patch uploaded by coreyfarrell (License 5909)
rb3665.patch uploaded by mjordan (License 6283)
rb3625.patch uploaded by coreyfarrell (License 5909)
rb3602.patch uploaded by coreyfarrell (License 5909)
format_compatibility-2.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419044 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-20 22:06:33 +00:00
if ( ast_format_cmp ( frame - > subclass . format , ast_format_g722 ) = = AST_FORMAT_CMP_EQUAL ) {
2009-07-08 23:19:09 +00:00
frame - > samples / = 2 ;
}
2009-04-02 17:20:52 +00:00
if ( rtp - > sending_digit ) {
return 0 ;
}
if ( frame - > frametype = = AST_FRAME_VOICE ) {
pred = rtp - > lastts + frame - > samples ;
/* Re-calculate last TS */
2009-07-08 23:19:09 +00:00
rtp - > lastts = rtp - > lastts + ms * rate ;
2009-04-02 17:20:52 +00:00
if ( ast_tvzero ( frame - > delivery ) ) {
/* If this isn't an absolute delivery time, Check if it is close to our prediction,
and if so , go with our prediction */
2015-03-30 02:45:29 +00:00
if ( abs ( ( int ) rtp - > lastts - pred ) < MAX_TIMESTAMP_SKEW ) {
2009-04-02 17:20:52 +00:00
rtp - > lastts = pred ;
} else {
2015-03-30 02:45:29 +00:00
ast_debug ( 3 , " Difference is %d, ms is %u \n " , abs ( ( int ) rtp - > lastts - pred ) , ms ) ;
2009-04-02 17:20:52 +00:00
mark = 1 ;
}
}
} else if ( frame - > frametype = = AST_FRAME_VIDEO ) {
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
mark = frame - > subclass . frame_ending ;
2009-04-02 17:20:52 +00:00
pred = rtp - > lastovidtimestamp + frame - > samples ;
/* Re-calculate last TS */
rtp - > lastts = rtp - > lastts + ms * 90 ;
/* If it's close to our prediction, go for it */
if ( ast_tvzero ( frame - > delivery ) ) {
2015-03-30 02:45:29 +00:00
if ( abs ( ( int ) rtp - > lastts - pred ) < 7200 ) {
2009-04-02 17:20:52 +00:00
rtp - > lastts = pred ;
rtp - > lastovidtimestamp + = frame - > samples ;
} else {
2015-03-30 02:45:29 +00:00
ast_debug ( 3 , " Difference is %d, ms is %u (%u), pred/ts/samples %u/%d/%d \n " , abs ( ( int ) rtp - > lastts - pred ) , ms , ms * 90 , rtp - > lastts , pred , frame - > samples ) ;
2009-04-02 17:20:52 +00:00
rtp - > lastovidtimestamp = rtp - > lastts ;
}
}
} else {
pred = rtp - > lastotexttimestamp + frame - > samples ;
/* Re-calculate last TS */
2009-04-14 17:40:50 +00:00
rtp - > lastts = rtp - > lastts + ms ;
2009-04-02 17:20:52 +00:00
/* If it's close to our prediction, go for it */
if ( ast_tvzero ( frame - > delivery ) ) {
2015-03-30 02:45:29 +00:00
if ( abs ( ( int ) rtp - > lastts - pred ) < 7200 ) {
2009-04-02 17:20:52 +00:00
rtp - > lastts = pred ;
rtp - > lastotexttimestamp + = frame - > samples ;
} else {
2015-03-30 02:45:29 +00:00
ast_debug ( 3 , " Difference is %d, ms is %u, pred/ts/samples %u/%d/%d \n " , abs ( ( int ) rtp - > lastts - pred ) , ms , rtp - > lastts , pred , frame - > samples ) ;
2009-04-02 17:20:52 +00:00
rtp - > lastotexttimestamp = rtp - > lastts ;
}
}
}
/* If we have been explicitly told to set the marker bit then do so */
if ( ast_test_flag ( rtp , FLAG_NEED_MARKER_BIT ) ) {
mark = 1 ;
ast_clear_flag ( rtp , FLAG_NEED_MARKER_BIT ) ;
}
/* If the timestamp for non-digt packets has moved beyond the timestamp for digits, update the digit timestamp */
if ( rtp - > lastts > rtp - > lastdigitts ) {
rtp - > lastdigitts = rtp - > lastts ;
}
if ( ast_test_flag ( frame , AST_FRFLAG_HAS_TIMING_INFO ) ) {
2009-07-08 23:19:09 +00:00
rtp - > lastts = frame - > ts * rate ;
2009-04-02 17:20:52 +00:00
}
ast_rtp_instance_get_remote_address ( instance , & remote_address ) ;
/* If we know the remote address construct a packet and send it out */
2010-07-08 22:08:07 +00:00
if ( ! ast_sockaddr_isnull ( & remote_address ) ) {
2012-07-01 17:28:57 +00:00
int hdrlen = 12 , res , ice ;
2009-04-02 17:20:52 +00:00
unsigned char * rtpheader = ( unsigned char * ) ( frame - > data . ptr - hdrlen ) ;
put_unaligned_uint32 ( rtpheader , htonl ( ( 2 < < 30 ) | ( codec < < 16 ) | ( rtp - > seqno ) | ( mark < < 23 ) ) ) ;
put_unaligned_uint32 ( rtpheader + 4 , htonl ( rtp - > lastts ) ) ;
put_unaligned_uint32 ( rtpheader + 8 , htonl ( rtp - > ssrc ) ) ;
2012-07-01 17:28:57 +00:00
if ( ( res = rtp_sendto ( instance , ( void * ) rtpheader , frame - > datalen + hdrlen , 0 , & remote_address , & ice ) ) < 0 ) {
2009-04-02 17:20:52 +00:00
if ( ! ast_rtp_instance_get_prop ( instance , AST_RTP_PROPERTY_NAT ) | | ( ast_rtp_instance_get_prop ( instance , AST_RTP_PROPERTY_NAT ) & & ( ast_test_flag ( rtp , FLAG_NAT_ACTIVE ) = = FLAG_NAT_ACTIVE ) ) ) {
2010-07-08 22:08:07 +00:00
ast_debug ( 1 , " RTP Transmission error of packet %d to %s: %s \n " ,
rtp - > seqno ,
ast_sockaddr_stringify ( & remote_address ) ,
strerror ( errno ) ) ;
2009-04-02 17:20:52 +00:00
} else if ( ( ( ast_test_flag ( rtp , FLAG_NAT_ACTIVE ) = = FLAG_NAT_INACTIVE ) | | rtpdebug ) & & ! ast_test_flag ( rtp , FLAG_NAT_INACTIVE_NOWARN ) ) {
/* Only give this error message once if we are not RTP debugging */
2011-02-04 16:55:39 +00:00
if ( rtpdebug )
2010-07-08 22:08:07 +00:00
ast_debug ( 0 , " RTP NAT: Can't write RTP to private address %s, waiting for other end to send audio... \n " ,
ast_sockaddr_stringify ( & remote_address ) ) ;
2009-04-02 17:20:52 +00:00
ast_set_flag ( rtp , FLAG_NAT_INACTIVE_NOWARN ) ;
}
} else {
rtp - > txcount + + ;
rtp - > txoctetcount + = ( res - hdrlen ) ;
2015-10-06 02:34:41 +00:00
if ( rtp - > rtcp & & rtp - > rtcp - > schedid < 0 ) {
2009-04-02 17:20:52 +00:00
ast_debug ( 1 , " Starting RTCP transmission on RTP instance '%p' \n " , instance ) ;
2011-09-20 01:11:18 +00:00
ao2_ref ( instance , + 1 ) ;
2010-06-08 05:29:08 +00:00
rtp - > rtcp - > schedid = ast_sched_add ( rtp - > sched , ast_rtcp_calc_interval ( rtp ) , ast_rtcp_write , instance ) ;
2011-09-20 01:11:18 +00:00
if ( rtp - > rtcp - > schedid < 0 ) {
ao2_ref ( instance , - 1 ) ;
ast_log ( LOG_WARNING , " scheduling RTCP transmission failed. \n " ) ;
}
2009-04-02 17:20:52 +00:00
}
}
if ( rtp_debug_test_addr ( & remote_address ) ) {
2014-05-09 22:49:26 +00:00
ast_verbose ( " Sent RTP packet to %s%s (type %-2.2d, seq %-6.6d, ts %-6.6u, len %-6.6d) \n " ,
2010-07-08 22:08:07 +00:00
ast_sockaddr_stringify ( & remote_address ) ,
2012-07-01 17:28:57 +00:00
ice ? " (via ICE) " : " " ,
2010-07-08 22:08:07 +00:00
codec , rtp - > seqno , rtp - > lastts , res - hdrlen ) ;
2009-04-02 17:20:52 +00:00
}
}
rtp - > seqno + + ;
return 0 ;
}
static struct ast_frame * red_t140_to_red ( struct rtp_red * red ) {
unsigned char * data = red - > t140red . data . ptr ;
int len = 0 ;
int i ;
/* replace most aged generation */
if ( red - > len [ 0 ] ) {
for ( i = 1 ; i < red - > num_gen + 1 ; i + + )
len + = red - > len [ i ] ;
memmove ( & data [ red - > hdrlen ] , & data [ red - > hdrlen + red - > len [ 0 ] ] , len ) ;
}
/* Store length of each generation and primary data length*/
for ( i = 0 ; i < red - > num_gen ; i + + )
red - > len [ i ] = red - > len [ i + 1 ] ;
red - > len [ i ] = red - > t140 . datalen ;
/* write each generation length in red header */
len = red - > hdrlen ;
2012-12-03 16:45:49 +00:00
for ( i = 0 ; i < red - > num_gen ; i + + ) {
2009-04-02 17:20:52 +00:00
len + = data [ i * 4 + 3 ] = red - > len [ i ] ;
2012-12-03 16:45:49 +00:00
}
2009-04-02 17:20:52 +00:00
/* add primary data to buffer */
memcpy ( & data [ len ] , red - > t140 . data . ptr , red - > t140 . datalen ) ;
red - > t140red . datalen = len + red - > t140 . datalen ;
/* no primary data and no generations to send */
2012-12-03 16:45:49 +00:00
if ( len = = red - > hdrlen & & ! red - > t140 . datalen ) {
2009-04-02 17:20:52 +00:00
return NULL ;
2012-12-03 16:45:49 +00:00
}
2009-04-02 17:20:52 +00:00
/* reset t.140 buffer */
red - > t140 . datalen = 0 ;
return & red - > t140red ;
}
static int ast_rtp_write ( struct ast_rtp_instance * instance , struct ast_frame * frame )
{
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
2010-07-08 22:08:07 +00:00
struct ast_sockaddr remote_address = { { 0 , } } ;
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 ;
2011-02-03 16:22:10 +00:00
int codec ;
2009-04-02 17:20:52 +00:00
ast_rtp_instance_get_remote_address ( instance , & remote_address ) ;
/* If we don't actually know the remote address don't even bother doing anything */
2010-07-08 22:08:07 +00:00
if ( ast_sockaddr_isnull ( & remote_address ) ) {
2009-04-02 17:20:52 +00:00
ast_debug ( 1 , " No remote address on RTP instance '%p' so dropping frame \n " , instance ) ;
2009-04-08 16:27:36 +00:00
return 0 ;
2009-04-02 17:20:52 +00:00
}
2013-08-23 15:42:27 +00:00
/* VP8: is this a request to send a RTCP FIR? */
if ( frame - > frametype = = AST_FRAME_CONTROL & & frame - > subclass . integer = = AST_CONTROL_VIDUPDATE ) {
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
unsigned int * rtcpheader ;
char bdata [ 1024 ] ;
int len = 20 ;
int ice ;
int res ;
if ( ! rtp | | ! rtp - > rtcp ) {
return 0 ;
}
if ( ast_sockaddr_isnull ( & rtp - > rtcp - > them ) ) {
/*
* RTCP was stopped .
*/
return 0 ;
}
/* Prepare RTCP FIR (PT=206, FMT=4) */
rtp - > rtcp - > firseq + + ;
if ( rtp - > rtcp - > firseq = = 256 ) {
rtp - > rtcp - > firseq = 0 ;
}
rtcpheader = ( unsigned int * ) bdata ;
rtcpheader [ 0 ] = htonl ( ( 2 < < 30 ) | ( 4 < < 24 ) | ( RTCP_PT_PSFB < < 16 ) | ( ( len / 4 ) - 1 ) ) ;
rtcpheader [ 1 ] = htonl ( rtp - > ssrc ) ;
rtcpheader [ 2 ] = htonl ( rtp - > themssrc ) ;
rtcpheader [ 3 ] = htonl ( rtp - > themssrc ) ; /* FCI: SSRC */
rtcpheader [ 4 ] = htonl ( rtp - > rtcp - > firseq < < 24 ) ; /* FCI: Sequence number */
res = rtcp_sendto ( instance , ( unsigned int * ) rtcpheader , len , 0 , & rtp - > rtcp - > them , & ice ) ;
if ( res < 0 ) {
ast_log ( LOG_ERROR , " RTCP FIR transmission error: %s \n " , strerror ( errno ) ) ;
}
return 0 ;
}
2009-04-02 17:20:52 +00:00
/* If there is no data length we can't very well send the packet */
if ( ! frame - > datalen ) {
ast_debug ( 1 , " Received frame with no data for RTP instance '%p' so dropping frame \n " , instance ) ;
2009-04-08 16:27:36 +00:00
return 0 ;
2009-04-02 17:20:52 +00:00
}
/* If the packet is not one our RTP stack supports bail out */
if ( frame - > frametype ! = AST_FRAME_VOICE & & frame - > frametype ! = AST_FRAME_VIDEO & & frame - > frametype ! = AST_FRAME_TEXT ) {
ast_log ( LOG_WARNING , " RTP can only send voice, video, and text \n " ) ;
return - 1 ;
}
if ( rtp - > red ) {
/* return 0; */
/* no primary data or generations to send */
if ( ( frame = red_t140_to_red ( rtp - > red ) ) = = NULL )
return 0 ;
}
/* Grab the subclass and look up the payload we are going to use */
2015-07-24 00:24:04 +00:00
codec = ast_rtp_codecs_payload_code_tx ( ast_rtp_instance_get_codecs ( instance ) ,
1 , frame - > subclass . format , 0 ) ;
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 ( codec < 0 ) {
ast_log ( LOG_WARNING , " Don't know how to send format %s packets with RTP \n " ,
ast_format_get_name ( frame - > subclass . format ) ) ;
2009-04-02 17:20:52 +00:00
return - 1 ;
}
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
/* Note that we do not increase the ref count here as this pointer
* will not be held by any thing explicitly . The format variable is
* merely a convenience reference to frame - > subclass . format */
format = frame - > subclass . format ;
if ( ast_format_cmp ( rtp - > lasttxformat , format ) = = AST_FORMAT_CMP_NOT_EQUAL ) {
/* Oh dear, if the format changed we will have to set up a new smoother */
if ( option_debug > 0 ) {
ast_debug ( 1 , " Ooh, format changed from %s to %s \n " ,
ast_format_get_name ( rtp - > lasttxformat ) ,
ast_format_get_name ( frame - > subclass . format ) ) ;
}
ao2_replace ( rtp - > lasttxformat , format ) ;
2009-04-02 17:20:52 +00:00
if ( rtp - > smoother ) {
ast_smoother_free ( rtp - > smoother ) ;
rtp - > smoother = NULL ;
}
}
/* If no smoother is present see if we have to set one up */
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 ( ! rtp - > smoother & & ast_format_can_be_smoothed ( format ) ) {
unsigned int framing_ms = ast_rtp_codecs_get_framing ( ast_rtp_instance_get_codecs ( instance ) ) ;
if ( framing_ms ) {
rtp - > smoother = ast_smoother_new ( ( framing_ms * ast_format_get_minimum_bytes ( format ) ) / ast_format_get_minimum_ms ( format ) ) ;
if ( ! rtp - > smoother ) {
ast_log ( LOG_WARNING , " Unable to create smoother: format %s ms: %u len: %u \n " ,
ast_format_get_name ( format ) , framing_ms , ast_format_get_minimum_bytes ( format ) ) ;
return - 1 ;
2009-04-02 17:20:52 +00:00
}
}
}
/* Feed audio frames into the actual function that will create a frame and send it */
if ( rtp - > smoother ) {
struct ast_frame * f ;
if ( ast_smoother_test_flag ( rtp - > smoother , AST_SMOOTHER_FLAG_BE ) ) {
ast_smoother_feed_be ( rtp - > smoother , frame ) ;
} else {
ast_smoother_feed ( rtp - > smoother , frame ) ;
}
while ( ( f = ast_smoother_read ( rtp - > smoother ) ) & & ( f - > data . ptr ) ) {
2009-07-08 23:19:09 +00:00
ast_rtp_raw_write ( instance , f , codec ) ;
2009-04-02 17:20:52 +00:00
}
} else {
int hdrlen = 12 ;
struct ast_frame * f = NULL ;
if ( frame - > offset < hdrlen ) {
f = ast_frdup ( frame ) ;
} else {
f = frame ;
}
if ( f - > data . ptr ) {
ast_rtp_raw_write ( instance , f , codec ) ;
}
if ( f ! = frame ) {
ast_frfree ( f ) ;
}
}
return 0 ;
}
static void calc_rxstamp ( struct timeval * tv , struct ast_rtp * rtp , unsigned int timestamp , int mark )
{
struct timeval now ;
2010-01-20 21:14:47 +00:00
struct timeval tmp ;
2009-04-02 17:20:52 +00:00
double transit ;
double current_time ;
double d ;
double dtv ;
double prog ;
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
int rate = rtp_get_rate ( rtp - > f . subclass . format ) ;
2009-04-02 17:20:52 +00:00
double normdev_rxjitter_current ;
if ( ( ! rtp - > rxcore . tv_sec & & ! rtp - > rxcore . tv_usec ) | | mark ) {
gettimeofday ( & rtp - > rxcore , NULL ) ;
rtp - > drxcore = ( double ) rtp - > rxcore . tv_sec + ( double ) rtp - > rxcore . tv_usec / 1000000 ;
/* map timestamp to a real time */
rtp - > seedrxts = timestamp ; /* Their RTP timestamp started with this */
2010-01-20 21:14:47 +00:00
tmp = ast_samp2tv ( timestamp , rate ) ;
rtp - > rxcore = ast_tvsub ( rtp - > rxcore , tmp ) ;
2009-04-02 17:20:52 +00:00
/* Round to 0.1ms for nice, pretty timestamps */
rtp - > rxcore . tv_usec - = rtp - > rxcore . tv_usec % 100 ;
}
gettimeofday ( & now , NULL ) ;
/* rxcore is the mapping between the RTP timestamp and _our_ real time from gettimeofday() */
2010-01-20 21:14:47 +00:00
tmp = ast_samp2tv ( timestamp , rate ) ;
* tv = ast_tvadd ( rtp - > rxcore , tmp ) ;
2009-07-08 23:19:09 +00:00
prog = ( double ) ( ( timestamp - rtp - > seedrxts ) / ( float ) ( rate ) ) ;
2009-04-02 17:20:52 +00:00
dtv = ( double ) rtp - > drxcore + ( double ) ( prog ) ;
current_time = ( double ) now . tv_sec + ( double ) now . tv_usec / 1000000 ;
transit = current_time - dtv ;
d = transit - rtp - > rxtransit ;
rtp - > rxtransit = transit ;
2012-12-03 16:45:49 +00:00
if ( d < 0 ) {
2009-04-02 17:20:52 +00:00
d = - d ;
2012-12-03 16:45:49 +00:00
}
2009-04-02 17:20:52 +00:00
rtp - > rxjitter + = ( 1. / 16. ) * ( d - rtp - > rxjitter ) ;
if ( rtp - > rtcp ) {
if ( rtp - > rxjitter > rtp - > rtcp - > maxrxjitter )
rtp - > rtcp - > maxrxjitter = rtp - > rxjitter ;
if ( rtp - > rtcp - > rxjitter_count = = 1 )
rtp - > rtcp - > minrxjitter = rtp - > rxjitter ;
if ( rtp - > rtcp & & rtp - > rxjitter < rtp - > rtcp - > minrxjitter )
rtp - > rtcp - > minrxjitter = rtp - > rxjitter ;
normdev_rxjitter_current = normdev_compute ( rtp - > rtcp - > normdev_rxjitter , rtp - > rxjitter , rtp - > rtcp - > rxjitter_count ) ;
rtp - > rtcp - > stdev_rxjitter = stddev_compute ( rtp - > rtcp - > stdev_rxjitter , rtp - > rxjitter , rtp - > rtcp - > normdev_rxjitter , normdev_rxjitter_current , rtp - > rtcp - > rxjitter_count ) ;
rtp - > rtcp - > normdev_rxjitter = normdev_rxjitter_current ;
rtp - > rtcp - > rxjitter_count + + ;
}
}
Recorded merge of revisions 254452 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r254452 | mmichelson | 2010-03-25 10:59:56 -0500 (Thu, 25 Mar 2010) | 44 lines
Several fixes regarding RFC2833 DTMF detection.
Here is a copy and paste of the details from my request on
reviewboard that dealt with these changes:
Fix 1. The first change in place is to fix Mantis issue 15811, which deals with a situation where Asterisk will incorrectly interpret out of order RFC2833 frames as duplicate DTMF digits. For instance, we would receive a sequence like:
seqno 1: DTMF 1
seqno 2: DTMF 1
seqno 3: DTMF 1
seqno 4: DTMF 1
seqno 6: DTMF 1 (end)
seqno 5: DTMF 1
seqno 7: DTMF 1 (end)
seqno 8: DTMF 1 (end)
Prior to this patch when we received the frame with seqno 5, we would interpret this as a new DTMF 1. With this patch, we will check the seqno of the incoming digit and not process the frame if the seqno is lower than the last recorded seqno. Note that we do not record the seqno of the dropped DTMF frame for future processing. While the above situation is what was designed to be fixed, the patch is written in such a way that the following would also be fixed too:
seqno 9: DTMF 1
seqno 10: DTMF 1 (end)
seqno 11: DTMF 1 (end)
seqno 13: DTMF 2
seqno 12: DTMF 1 (end)
seqno 14: DTMF 2
seqno 15: DTMF 2 (end)
seqno 16: DTMF 2 (end)
seqno 17: DTMF 2 (end)
In this second situation, the beginning of the DTMF 2 arrives before the final end frame of the DTMF 1. With the patch, seqno 12 is no processed and thus we properly interpret the DTMF.
Fix 2. The second change in place is to fix an issue like the following:
seqno 1: DTMF 1
seqno 2: DTMF 1
seqno 3: DTMF 1 (end) *packet lost*
seqno 4: DTMF 1 (end) *packet lost*
seqno 5: DTMF 1 (end) *packet lost*
seqno 6: DTMF 2
When we receive seqno 6, we had code in place that was supposed to properly end the previously unended DTMF 1. The problem was that the code was essentially a no-op. The code would set up an end frame for the DTMF 1 but would immediately overwrite the frame with the begin for DTMF 2. I changed process_dtmf_rfc2833() so that instead of returning a single frame, it is given as an output parameter a list of frames. Each frame that needs to be returned is appended to this list.
Fix 3. The final change is a minor one where an AST_CONTROL_SRCCHANGE frame could get lost. If we process a cisco DTMF or an RFC 3389 frame and no frame was returned, then we would return &ast_null_frame. The problem is that earlier in the function, we may have generated an AST_CONTROL_SRCCHANGE frame and put it in the list of frames we wish to return. This frame would be lost in such a case. The patch fixes this problem
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@254454 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2010-03-25 16:04:48 +00:00
static struct ast_frame * create_dtmf_frame ( struct ast_rtp_instance * instance , enum ast_frame_type type , int compensate )
2009-04-02 17:20:52 +00:00
{
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
2010-07-08 22:08:07 +00:00
struct ast_sockaddr remote_address = { { 0 , } } ;
2009-04-02 17:20:52 +00:00
ast_rtp_instance_get_remote_address ( instance , & remote_address ) ;
if ( ( ( compensate & & type = = AST_FRAME_DTMF_END ) | | ( type = = AST_FRAME_DTMF_BEGIN ) ) & & ast_tvcmp ( ast_tvnow ( ) , rtp - > dtmfmute ) < 0 ) {
2010-07-08 22:08:07 +00:00
ast_debug ( 1 , " Ignore potential DTMF echo from '%s' \n " ,
ast_sockaddr_stringify ( & remote_address ) ) ;
2009-04-02 17:20:52 +00:00
rtp - > resp = 0 ;
rtp - > dtmfsamples = 0 ;
return & ast_null_frame ;
}
Handle extremely out of order RFC 2833 DTMF
The current implementation of RFC 2833 DTMF handling in res_rtp_asterisk will,
if a packet arrives out of order, drop the packet. This is to prevent
duplicate ton generation in the Asterisk core. Since the RTP layer does not
buffer data itself, this is the only option the RTP layer currently has for
handling packets that arrive out of order.
For the most part, this doesn't matter. For a particular digit, so long as a
BEGIN packet arrives before the first END packet, the digit will be produced.
If subsequent BEGIN packets arrive interleaved with the ENDs, they will be
dropped; likewise, if the BEGIN or END packets themselves are out of order,
those packets are dropped but sufficient information is conveyed to the
Asterisk core to produce the appropriate digit.
For certain sequences of DTMF packets - most notably when, for a particular
digit, an END packet arrives before any BEGIN packet for that digit - this
is a real problem. When an END arrives before any BEGINs, the END packet is
dropped - but at the same time, it causes subsequent BEGIN packets for that
digit to be ignored. When the next in order END packet arrives, it too is
dropped - Asterisk believes that there was no initial BEGIN.
The solution this patch provides is to trust the END packet to convey the
information needed for the Asterisk core to produce the DTMF digit. If we
receive an END packet, and it:
* Has a timestamp greater then the last timestamp received from an END
packet
* Does not have the same sequence number as the last received sequence
number (and is thus not an END packet retransmission)
Then we send the END frame up to the Asterisk core. It contains enough
DTMF information for Asterisk to produce the digit.
On the other hand, if we receive a BEGIN or continuation packet that occurs
with a timestamp equal to or less then the last END timestamp, then we've
received something out of order - but we already have received enough
information to produce the digit. These packets are dropped.
Much thanks goes to Olle Johansson (oej) for providing the idea for this
solution.
Review: https://reviewboard.asterisk.org/r/2033/
(closes issue ASTERISK-18404)
Reported by: Stephane Chazelas
Tested by: Matt Jordan
........
Merged revisions 370252 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........
Merged revisions 370271 from http://svn.asterisk.org/svn/asterisk/branches/10
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@370272 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-07-19 21:45:20 +00:00
ast_debug ( 1 , " Creating %s DTMF Frame: %d (%c), at %s \n " ,
type = = AST_FRAME_DTMF_END ? " END " : " BEGIN " ,
rtp - > resp , rtp - > resp ,
ast_sockaddr_stringify ( & remote_address ) ) ;
2009-04-02 17:20:52 +00:00
if ( rtp - > resp = = ' X ' ) {
rtp - > f . frametype = AST_FRAME_CONTROL ;
2009-11-04 14:05:12 +00:00
rtp - > f . subclass . integer = AST_CONTROL_FLASH ;
2009-04-02 17:20:52 +00:00
} else {
rtp - > f . frametype = type ;
2009-11-04 14:05:12 +00:00
rtp - > f . subclass . integer = rtp - > resp ;
2009-04-02 17:20:52 +00:00
}
rtp - > f . datalen = 0 ;
rtp - > f . samples = 0 ;
rtp - > f . mallocd = 0 ;
rtp - > f . src = " RTP " ;
Recorded merge of revisions 254452 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r254452 | mmichelson | 2010-03-25 10:59:56 -0500 (Thu, 25 Mar 2010) | 44 lines
Several fixes regarding RFC2833 DTMF detection.
Here is a copy and paste of the details from my request on
reviewboard that dealt with these changes:
Fix 1. The first change in place is to fix Mantis issue 15811, which deals with a situation where Asterisk will incorrectly interpret out of order RFC2833 frames as duplicate DTMF digits. For instance, we would receive a sequence like:
seqno 1: DTMF 1
seqno 2: DTMF 1
seqno 3: DTMF 1
seqno 4: DTMF 1
seqno 6: DTMF 1 (end)
seqno 5: DTMF 1
seqno 7: DTMF 1 (end)
seqno 8: DTMF 1 (end)
Prior to this patch when we received the frame with seqno 5, we would interpret this as a new DTMF 1. With this patch, we will check the seqno of the incoming digit and not process the frame if the seqno is lower than the last recorded seqno. Note that we do not record the seqno of the dropped DTMF frame for future processing. While the above situation is what was designed to be fixed, the patch is written in such a way that the following would also be fixed too:
seqno 9: DTMF 1
seqno 10: DTMF 1 (end)
seqno 11: DTMF 1 (end)
seqno 13: DTMF 2
seqno 12: DTMF 1 (end)
seqno 14: DTMF 2
seqno 15: DTMF 2 (end)
seqno 16: DTMF 2 (end)
seqno 17: DTMF 2 (end)
In this second situation, the beginning of the DTMF 2 arrives before the final end frame of the DTMF 1. With the patch, seqno 12 is no processed and thus we properly interpret the DTMF.
Fix 2. The second change in place is to fix an issue like the following:
seqno 1: DTMF 1
seqno 2: DTMF 1
seqno 3: DTMF 1 (end) *packet lost*
seqno 4: DTMF 1 (end) *packet lost*
seqno 5: DTMF 1 (end) *packet lost*
seqno 6: DTMF 2
When we receive seqno 6, we had code in place that was supposed to properly end the previously unended DTMF 1. The problem was that the code was essentially a no-op. The code would set up an end frame for the DTMF 1 but would immediately overwrite the frame with the begin for DTMF 2. I changed process_dtmf_rfc2833() so that instead of returning a single frame, it is given as an output parameter a list of frames. Each frame that needs to be returned is appended to this list.
Fix 3. The final change is a minor one where an AST_CONTROL_SRCCHANGE frame could get lost. If we process a cisco DTMF or an RFC 3389 frame and no frame was returned, then we would return &ast_null_frame. The problem is that earlier in the function, we may have generated an AST_CONTROL_SRCCHANGE frame and put it in the list of frames we wish to return. This frame would be lost in such a case. The patch fixes this problem
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@254454 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2010-03-25 16:04:48 +00:00
AST_LIST_NEXT ( & rtp - > f , frame_list ) = NULL ;
2009-04-02 17:20:52 +00:00
return & rtp - > f ;
}
2010-07-08 22:08:07 +00:00
static void process_dtmf_rfc2833 ( struct ast_rtp_instance * instance , unsigned char * data , int len , unsigned int seqno , unsigned int timestamp , struct ast_sockaddr * addr , int payloadtype , int mark , struct frame_list * frames )
2009-04-02 17:20:52 +00:00
{
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
2010-07-08 22:08:07 +00:00
struct ast_sockaddr remote_address = { { 0 , } } ;
2009-04-02 17:20:52 +00:00
unsigned int event , event_end , samples ;
char resp = 0 ;
struct ast_frame * f = NULL ;
ast_rtp_instance_get_remote_address ( instance , & remote_address ) ;
/* Figure out event, event end, and samples */
event = ntohl ( * ( ( unsigned int * ) ( data ) ) ) ;
event > > = 24 ;
event_end = ntohl ( * ( ( unsigned int * ) ( data ) ) ) ;
event_end < < = 8 ;
event_end > > = 24 ;
samples = ntohl ( * ( ( unsigned int * ) ( data ) ) ) ;
samples & = 0xFFFF ;
2009-04-06 23:11:13 +00:00
if ( rtp_debug_test_addr ( & remote_address ) ) {
2014-05-09 22:49:26 +00:00
ast_verbose ( " Got RTP RFC2833 from %s (type %-2.2d, seq %-6.6u, ts %-6.6u, len %-6.6d, mark %d, event %08x, end %d, duration %-5.5u) \n " ,
2010-07-08 22:08:07 +00:00
ast_sockaddr_stringify ( & remote_address ) ,
payloadtype , seqno , timestamp , len , ( mark ? 1 : 0 ) , event , ( ( event_end & 0x80 ) ? 1 : 0 ) , samples ) ;
2009-04-06 23:11:13 +00:00
}
2009-04-02 17:20:52 +00:00
/* Print out debug if turned on */
2011-02-04 16:55:39 +00:00
if ( rtpdebug )
2009-04-02 17:20:52 +00:00
ast_debug ( 0 , " - RTP 2833 Event: %08x (len = %d) \n " , event , len ) ;
/* Figure out what digit was pressed */
if ( event < 10 ) {
resp = ' 0 ' + event ;
} else if ( event < 11 ) {
resp = ' * ' ;
} else if ( event < 12 ) {
resp = ' # ' ;
} else if ( event < 16 ) {
resp = ' A ' + ( event - 12 ) ;
} else if ( event < 17 ) { /* Event 16: Hook flash */
resp = ' X ' ;
} else {
/* Not a supported event */
2011-02-04 16:55:39 +00:00
ast_debug ( 1 , " Ignoring RTP 2833 Event: %08x. Not a DTMF Digit. \n " , event ) ;
Recorded merge of revisions 254452 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r254452 | mmichelson | 2010-03-25 10:59:56 -0500 (Thu, 25 Mar 2010) | 44 lines
Several fixes regarding RFC2833 DTMF detection.
Here is a copy and paste of the details from my request on
reviewboard that dealt with these changes:
Fix 1. The first change in place is to fix Mantis issue 15811, which deals with a situation where Asterisk will incorrectly interpret out of order RFC2833 frames as duplicate DTMF digits. For instance, we would receive a sequence like:
seqno 1: DTMF 1
seqno 2: DTMF 1
seqno 3: DTMF 1
seqno 4: DTMF 1
seqno 6: DTMF 1 (end)
seqno 5: DTMF 1
seqno 7: DTMF 1 (end)
seqno 8: DTMF 1 (end)
Prior to this patch when we received the frame with seqno 5, we would interpret this as a new DTMF 1. With this patch, we will check the seqno of the incoming digit and not process the frame if the seqno is lower than the last recorded seqno. Note that we do not record the seqno of the dropped DTMF frame for future processing. While the above situation is what was designed to be fixed, the patch is written in such a way that the following would also be fixed too:
seqno 9: DTMF 1
seqno 10: DTMF 1 (end)
seqno 11: DTMF 1 (end)
seqno 13: DTMF 2
seqno 12: DTMF 1 (end)
seqno 14: DTMF 2
seqno 15: DTMF 2 (end)
seqno 16: DTMF 2 (end)
seqno 17: DTMF 2 (end)
In this second situation, the beginning of the DTMF 2 arrives before the final end frame of the DTMF 1. With the patch, seqno 12 is no processed and thus we properly interpret the DTMF.
Fix 2. The second change in place is to fix an issue like the following:
seqno 1: DTMF 1
seqno 2: DTMF 1
seqno 3: DTMF 1 (end) *packet lost*
seqno 4: DTMF 1 (end) *packet lost*
seqno 5: DTMF 1 (end) *packet lost*
seqno 6: DTMF 2
When we receive seqno 6, we had code in place that was supposed to properly end the previously unended DTMF 1. The problem was that the code was essentially a no-op. The code would set up an end frame for the DTMF 1 but would immediately overwrite the frame with the begin for DTMF 2. I changed process_dtmf_rfc2833() so that instead of returning a single frame, it is given as an output parameter a list of frames. Each frame that needs to be returned is appended to this list.
Fix 3. The final change is a minor one where an AST_CONTROL_SRCCHANGE frame could get lost. If we process a cisco DTMF or an RFC 3389 frame and no frame was returned, then we would return &ast_null_frame. The problem is that earlier in the function, we may have generated an AST_CONTROL_SRCCHANGE frame and put it in the list of frames we wish to return. This frame would be lost in such a case. The patch fixes this problem
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@254454 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2010-03-25 16:04:48 +00:00
return ;
2009-04-02 17:20:52 +00:00
}
if ( ast_rtp_instance_get_prop ( instance , AST_RTP_PROPERTY_DTMF_COMPENSATE ) ) {
Handle extremely out of order RFC 2833 DTMF
The current implementation of RFC 2833 DTMF handling in res_rtp_asterisk will,
if a packet arrives out of order, drop the packet. This is to prevent
duplicate ton generation in the Asterisk core. Since the RTP layer does not
buffer data itself, this is the only option the RTP layer currently has for
handling packets that arrive out of order.
For the most part, this doesn't matter. For a particular digit, so long as a
BEGIN packet arrives before the first END packet, the digit will be produced.
If subsequent BEGIN packets arrive interleaved with the ENDs, they will be
dropped; likewise, if the BEGIN or END packets themselves are out of order,
those packets are dropped but sufficient information is conveyed to the
Asterisk core to produce the appropriate digit.
For certain sequences of DTMF packets - most notably when, for a particular
digit, an END packet arrives before any BEGIN packet for that digit - this
is a real problem. When an END arrives before any BEGINs, the END packet is
dropped - but at the same time, it causes subsequent BEGIN packets for that
digit to be ignored. When the next in order END packet arrives, it too is
dropped - Asterisk believes that there was no initial BEGIN.
The solution this patch provides is to trust the END packet to convey the
information needed for the Asterisk core to produce the DTMF digit. If we
receive an END packet, and it:
* Has a timestamp greater then the last timestamp received from an END
packet
* Does not have the same sequence number as the last received sequence
number (and is thus not an END packet retransmission)
Then we send the END frame up to the Asterisk core. It contains enough
DTMF information for Asterisk to produce the digit.
On the other hand, if we receive a BEGIN or continuation packet that occurs
with a timestamp equal to or less then the last END timestamp, then we've
received something out of order - but we already have received enough
information to produce the digit. These packets are dropped.
Much thanks goes to Olle Johansson (oej) for providing the idea for this
solution.
Review: https://reviewboard.asterisk.org/r/2033/
(closes issue ASTERISK-18404)
Reported by: Stephane Chazelas
Tested by: Matt Jordan
........
Merged revisions 370252 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........
Merged revisions 370271 from http://svn.asterisk.org/svn/asterisk/branches/10
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@370272 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-07-19 21:45:20 +00:00
if ( ( rtp - > last_end_timestamp ! = timestamp ) | | ( rtp - > resp & & rtp - > resp ! = resp ) ) {
2009-04-02 17:20:52 +00:00
rtp - > resp = resp ;
2009-05-13 13:39:10 +00:00
rtp - > dtmf_timeout = 0 ;
Recorded merge of revisions 254452 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r254452 | mmichelson | 2010-03-25 10:59:56 -0500 (Thu, 25 Mar 2010) | 44 lines
Several fixes regarding RFC2833 DTMF detection.
Here is a copy and paste of the details from my request on
reviewboard that dealt with these changes:
Fix 1. The first change in place is to fix Mantis issue 15811, which deals with a situation where Asterisk will incorrectly interpret out of order RFC2833 frames as duplicate DTMF digits. For instance, we would receive a sequence like:
seqno 1: DTMF 1
seqno 2: DTMF 1
seqno 3: DTMF 1
seqno 4: DTMF 1
seqno 6: DTMF 1 (end)
seqno 5: DTMF 1
seqno 7: DTMF 1 (end)
seqno 8: DTMF 1 (end)
Prior to this patch when we received the frame with seqno 5, we would interpret this as a new DTMF 1. With this patch, we will check the seqno of the incoming digit and not process the frame if the seqno is lower than the last recorded seqno. Note that we do not record the seqno of the dropped DTMF frame for future processing. While the above situation is what was designed to be fixed, the patch is written in such a way that the following would also be fixed too:
seqno 9: DTMF 1
seqno 10: DTMF 1 (end)
seqno 11: DTMF 1 (end)
seqno 13: DTMF 2
seqno 12: DTMF 1 (end)
seqno 14: DTMF 2
seqno 15: DTMF 2 (end)
seqno 16: DTMF 2 (end)
seqno 17: DTMF 2 (end)
In this second situation, the beginning of the DTMF 2 arrives before the final end frame of the DTMF 1. With the patch, seqno 12 is no processed and thus we properly interpret the DTMF.
Fix 2. The second change in place is to fix an issue like the following:
seqno 1: DTMF 1
seqno 2: DTMF 1
seqno 3: DTMF 1 (end) *packet lost*
seqno 4: DTMF 1 (end) *packet lost*
seqno 5: DTMF 1 (end) *packet lost*
seqno 6: DTMF 2
When we receive seqno 6, we had code in place that was supposed to properly end the previously unended DTMF 1. The problem was that the code was essentially a no-op. The code would set up an end frame for the DTMF 1 but would immediately overwrite the frame with the begin for DTMF 2. I changed process_dtmf_rfc2833() so that instead of returning a single frame, it is given as an output parameter a list of frames. Each frame that needs to be returned is appended to this list.
Fix 3. The final change is a minor one where an AST_CONTROL_SRCCHANGE frame could get lost. If we process a cisco DTMF or an RFC 3389 frame and no frame was returned, then we would return &ast_null_frame. The problem is that earlier in the function, we may have generated an AST_CONTROL_SRCCHANGE frame and put it in the list of frames we wish to return. This frame would be lost in such a case. The patch fixes this problem
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@254454 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2010-03-25 16:04:48 +00:00
f = ast_frdup ( create_dtmf_frame ( instance , AST_FRAME_DTMF_END , ast_rtp_instance_get_prop ( instance , AST_RTP_PROPERTY_DTMF_COMPENSATE ) ) ) ;
2009-04-02 17:20:52 +00:00
f - > len = 0 ;
Handle extremely out of order RFC 2833 DTMF
The current implementation of RFC 2833 DTMF handling in res_rtp_asterisk will,
if a packet arrives out of order, drop the packet. This is to prevent
duplicate ton generation in the Asterisk core. Since the RTP layer does not
buffer data itself, this is the only option the RTP layer currently has for
handling packets that arrive out of order.
For the most part, this doesn't matter. For a particular digit, so long as a
BEGIN packet arrives before the first END packet, the digit will be produced.
If subsequent BEGIN packets arrive interleaved with the ENDs, they will be
dropped; likewise, if the BEGIN or END packets themselves are out of order,
those packets are dropped but sufficient information is conveyed to the
Asterisk core to produce the appropriate digit.
For certain sequences of DTMF packets - most notably when, for a particular
digit, an END packet arrives before any BEGIN packet for that digit - this
is a real problem. When an END arrives before any BEGINs, the END packet is
dropped - but at the same time, it causes subsequent BEGIN packets for that
digit to be ignored. When the next in order END packet arrives, it too is
dropped - Asterisk believes that there was no initial BEGIN.
The solution this patch provides is to trust the END packet to convey the
information needed for the Asterisk core to produce the DTMF digit. If we
receive an END packet, and it:
* Has a timestamp greater then the last timestamp received from an END
packet
* Does not have the same sequence number as the last received sequence
number (and is thus not an END packet retransmission)
Then we send the END frame up to the Asterisk core. It contains enough
DTMF information for Asterisk to produce the digit.
On the other hand, if we receive a BEGIN or continuation packet that occurs
with a timestamp equal to or less then the last END timestamp, then we've
received something out of order - but we already have received enough
information to produce the digit. These packets are dropped.
Much thanks goes to Olle Johansson (oej) for providing the idea for this
solution.
Review: https://reviewboard.asterisk.org/r/2033/
(closes issue ASTERISK-18404)
Reported by: Stephane Chazelas
Tested by: Matt Jordan
........
Merged revisions 370252 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........
Merged revisions 370271 from http://svn.asterisk.org/svn/asterisk/branches/10
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@370272 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-07-19 21:45:20 +00:00
rtp - > last_end_timestamp = timestamp ;
Recorded merge of revisions 254452 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r254452 | mmichelson | 2010-03-25 10:59:56 -0500 (Thu, 25 Mar 2010) | 44 lines
Several fixes regarding RFC2833 DTMF detection.
Here is a copy and paste of the details from my request on
reviewboard that dealt with these changes:
Fix 1. The first change in place is to fix Mantis issue 15811, which deals with a situation where Asterisk will incorrectly interpret out of order RFC2833 frames as duplicate DTMF digits. For instance, we would receive a sequence like:
seqno 1: DTMF 1
seqno 2: DTMF 1
seqno 3: DTMF 1
seqno 4: DTMF 1
seqno 6: DTMF 1 (end)
seqno 5: DTMF 1
seqno 7: DTMF 1 (end)
seqno 8: DTMF 1 (end)
Prior to this patch when we received the frame with seqno 5, we would interpret this as a new DTMF 1. With this patch, we will check the seqno of the incoming digit and not process the frame if the seqno is lower than the last recorded seqno. Note that we do not record the seqno of the dropped DTMF frame for future processing. While the above situation is what was designed to be fixed, the patch is written in such a way that the following would also be fixed too:
seqno 9: DTMF 1
seqno 10: DTMF 1 (end)
seqno 11: DTMF 1 (end)
seqno 13: DTMF 2
seqno 12: DTMF 1 (end)
seqno 14: DTMF 2
seqno 15: DTMF 2 (end)
seqno 16: DTMF 2 (end)
seqno 17: DTMF 2 (end)
In this second situation, the beginning of the DTMF 2 arrives before the final end frame of the DTMF 1. With the patch, seqno 12 is no processed and thus we properly interpret the DTMF.
Fix 2. The second change in place is to fix an issue like the following:
seqno 1: DTMF 1
seqno 2: DTMF 1
seqno 3: DTMF 1 (end) *packet lost*
seqno 4: DTMF 1 (end) *packet lost*
seqno 5: DTMF 1 (end) *packet lost*
seqno 6: DTMF 2
When we receive seqno 6, we had code in place that was supposed to properly end the previously unended DTMF 1. The problem was that the code was essentially a no-op. The code would set up an end frame for the DTMF 1 but would immediately overwrite the frame with the begin for DTMF 2. I changed process_dtmf_rfc2833() so that instead of returning a single frame, it is given as an output parameter a list of frames. Each frame that needs to be returned is appended to this list.
Fix 3. The final change is a minor one where an AST_CONTROL_SRCCHANGE frame could get lost. If we process a cisco DTMF or an RFC 3389 frame and no frame was returned, then we would return &ast_null_frame. The problem is that earlier in the function, we may have generated an AST_CONTROL_SRCCHANGE frame and put it in the list of frames we wish to return. This frame would be lost in such a case. The patch fixes this problem
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@254454 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2010-03-25 16:04:48 +00:00
AST_LIST_INSERT_TAIL ( frames , f , frame_list ) ;
2009-04-02 17:20:52 +00:00
}
} else {
2009-05-13 13:39:10 +00:00
/* The duration parameter measures the complete
duration of the event ( from the beginning ) - RFC2833 .
Account for the fact that duration is only 16 bits long
( about 8 seconds at 8000 Hz ) and can wrap is digit
is hold for too long . */
unsigned int new_duration = rtp - > dtmf_duration ;
unsigned int last_duration = new_duration & 0xFFFF ;
if ( last_duration > 64000 & & samples < last_duration ) {
new_duration + = 0xFFFF + 1 ;
}
new_duration = ( new_duration & ~ 0xFFFF ) | samples ;
if ( event_end & 0x80 ) {
/* End event */
Handle extremely out of order RFC 2833 DTMF
The current implementation of RFC 2833 DTMF handling in res_rtp_asterisk will,
if a packet arrives out of order, drop the packet. This is to prevent
duplicate ton generation in the Asterisk core. Since the RTP layer does not
buffer data itself, this is the only option the RTP layer currently has for
handling packets that arrive out of order.
For the most part, this doesn't matter. For a particular digit, so long as a
BEGIN packet arrives before the first END packet, the digit will be produced.
If subsequent BEGIN packets arrive interleaved with the ENDs, they will be
dropped; likewise, if the BEGIN or END packets themselves are out of order,
those packets are dropped but sufficient information is conveyed to the
Asterisk core to produce the appropriate digit.
For certain sequences of DTMF packets - most notably when, for a particular
digit, an END packet arrives before any BEGIN packet for that digit - this
is a real problem. When an END arrives before any BEGINs, the END packet is
dropped - but at the same time, it causes subsequent BEGIN packets for that
digit to be ignored. When the next in order END packet arrives, it too is
dropped - Asterisk believes that there was no initial BEGIN.
The solution this patch provides is to trust the END packet to convey the
information needed for the Asterisk core to produce the DTMF digit. If we
receive an END packet, and it:
* Has a timestamp greater then the last timestamp received from an END
packet
* Does not have the same sequence number as the last received sequence
number (and is thus not an END packet retransmission)
Then we send the END frame up to the Asterisk core. It contains enough
DTMF information for Asterisk to produce the digit.
On the other hand, if we receive a BEGIN or continuation packet that occurs
with a timestamp equal to or less then the last END timestamp, then we've
received something out of order - but we already have received enough
information to produce the digit. These packets are dropped.
Much thanks goes to Olle Johansson (oej) for providing the idea for this
solution.
Review: https://reviewboard.asterisk.org/r/2033/
(closes issue ASTERISK-18404)
Reported by: Stephane Chazelas
Tested by: Matt Jordan
........
Merged revisions 370252 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........
Merged revisions 370271 from http://svn.asterisk.org/svn/asterisk/branches/10
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@370272 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-07-19 21:45:20 +00:00
if ( ( rtp - > last_seqno ! = seqno ) & & ( timestamp > rtp - > last_end_timestamp ) ) {
rtp - > last_end_timestamp = timestamp ;
2009-05-13 13:39:10 +00:00
rtp - > dtmf_duration = new_duration ;
Handle extremely out of order RFC 2833 DTMF
The current implementation of RFC 2833 DTMF handling in res_rtp_asterisk will,
if a packet arrives out of order, drop the packet. This is to prevent
duplicate ton generation in the Asterisk core. Since the RTP layer does not
buffer data itself, this is the only option the RTP layer currently has for
handling packets that arrive out of order.
For the most part, this doesn't matter. For a particular digit, so long as a
BEGIN packet arrives before the first END packet, the digit will be produced.
If subsequent BEGIN packets arrive interleaved with the ENDs, they will be
dropped; likewise, if the BEGIN or END packets themselves are out of order,
those packets are dropped but sufficient information is conveyed to the
Asterisk core to produce the appropriate digit.
For certain sequences of DTMF packets - most notably when, for a particular
digit, an END packet arrives before any BEGIN packet for that digit - this
is a real problem. When an END arrives before any BEGINs, the END packet is
dropped - but at the same time, it causes subsequent BEGIN packets for that
digit to be ignored. When the next in order END packet arrives, it too is
dropped - Asterisk believes that there was no initial BEGIN.
The solution this patch provides is to trust the END packet to convey the
information needed for the Asterisk core to produce the DTMF digit. If we
receive an END packet, and it:
* Has a timestamp greater then the last timestamp received from an END
packet
* Does not have the same sequence number as the last received sequence
number (and is thus not an END packet retransmission)
Then we send the END frame up to the Asterisk core. It contains enough
DTMF information for Asterisk to produce the digit.
On the other hand, if we receive a BEGIN or continuation packet that occurs
with a timestamp equal to or less then the last END timestamp, then we've
received something out of order - but we already have received enough
information to produce the digit. These packets are dropped.
Much thanks goes to Olle Johansson (oej) for providing the idea for this
solution.
Review: https://reviewboard.asterisk.org/r/2033/
(closes issue ASTERISK-18404)
Reported by: Stephane Chazelas
Tested by: Matt Jordan
........
Merged revisions 370252 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........
Merged revisions 370271 from http://svn.asterisk.org/svn/asterisk/branches/10
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@370272 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-07-19 21:45:20 +00:00
rtp - > resp = resp ;
Recorded merge of revisions 254452 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r254452 | mmichelson | 2010-03-25 10:59:56 -0500 (Thu, 25 Mar 2010) | 44 lines
Several fixes regarding RFC2833 DTMF detection.
Here is a copy and paste of the details from my request on
reviewboard that dealt with these changes:
Fix 1. The first change in place is to fix Mantis issue 15811, which deals with a situation where Asterisk will incorrectly interpret out of order RFC2833 frames as duplicate DTMF digits. For instance, we would receive a sequence like:
seqno 1: DTMF 1
seqno 2: DTMF 1
seqno 3: DTMF 1
seqno 4: DTMF 1
seqno 6: DTMF 1 (end)
seqno 5: DTMF 1
seqno 7: DTMF 1 (end)
seqno 8: DTMF 1 (end)
Prior to this patch when we received the frame with seqno 5, we would interpret this as a new DTMF 1. With this patch, we will check the seqno of the incoming digit and not process the frame if the seqno is lower than the last recorded seqno. Note that we do not record the seqno of the dropped DTMF frame for future processing. While the above situation is what was designed to be fixed, the patch is written in such a way that the following would also be fixed too:
seqno 9: DTMF 1
seqno 10: DTMF 1 (end)
seqno 11: DTMF 1 (end)
seqno 13: DTMF 2
seqno 12: DTMF 1 (end)
seqno 14: DTMF 2
seqno 15: DTMF 2 (end)
seqno 16: DTMF 2 (end)
seqno 17: DTMF 2 (end)
In this second situation, the beginning of the DTMF 2 arrives before the final end frame of the DTMF 1. With the patch, seqno 12 is no processed and thus we properly interpret the DTMF.
Fix 2. The second change in place is to fix an issue like the following:
seqno 1: DTMF 1
seqno 2: DTMF 1
seqno 3: DTMF 1 (end) *packet lost*
seqno 4: DTMF 1 (end) *packet lost*
seqno 5: DTMF 1 (end) *packet lost*
seqno 6: DTMF 2
When we receive seqno 6, we had code in place that was supposed to properly end the previously unended DTMF 1. The problem was that the code was essentially a no-op. The code would set up an end frame for the DTMF 1 but would immediately overwrite the frame with the begin for DTMF 2. I changed process_dtmf_rfc2833() so that instead of returning a single frame, it is given as an output parameter a list of frames. Each frame that needs to be returned is appended to this list.
Fix 3. The final change is a minor one where an AST_CONTROL_SRCCHANGE frame could get lost. If we process a cisco DTMF or an RFC 3389 frame and no frame was returned, then we would return &ast_null_frame. The problem is that earlier in the function, we may have generated an AST_CONTROL_SRCCHANGE frame and put it in the list of frames we wish to return. This frame would be lost in such a case. The patch fixes this problem
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@254454 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2010-03-25 16:04:48 +00:00
f = ast_frdup ( create_dtmf_frame ( instance , AST_FRAME_DTMF_END , 0 ) ) ;
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
f - > len = ast_tvdiff_ms ( ast_samp2tv ( rtp - > dtmf_duration , rtp_get_rate ( f - > subclass . format ) ) , ast_tv ( 0 , 0 ) ) ;
2009-05-13 13:39:10 +00:00
rtp - > resp = 0 ;
rtp - > dtmf_duration = rtp - > dtmf_timeout = 0 ;
Recorded merge of revisions 254452 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r254452 | mmichelson | 2010-03-25 10:59:56 -0500 (Thu, 25 Mar 2010) | 44 lines
Several fixes regarding RFC2833 DTMF detection.
Here is a copy and paste of the details from my request on
reviewboard that dealt with these changes:
Fix 1. The first change in place is to fix Mantis issue 15811, which deals with a situation where Asterisk will incorrectly interpret out of order RFC2833 frames as duplicate DTMF digits. For instance, we would receive a sequence like:
seqno 1: DTMF 1
seqno 2: DTMF 1
seqno 3: DTMF 1
seqno 4: DTMF 1
seqno 6: DTMF 1 (end)
seqno 5: DTMF 1
seqno 7: DTMF 1 (end)
seqno 8: DTMF 1 (end)
Prior to this patch when we received the frame with seqno 5, we would interpret this as a new DTMF 1. With this patch, we will check the seqno of the incoming digit and not process the frame if the seqno is lower than the last recorded seqno. Note that we do not record the seqno of the dropped DTMF frame for future processing. While the above situation is what was designed to be fixed, the patch is written in such a way that the following would also be fixed too:
seqno 9: DTMF 1
seqno 10: DTMF 1 (end)
seqno 11: DTMF 1 (end)
seqno 13: DTMF 2
seqno 12: DTMF 1 (end)
seqno 14: DTMF 2
seqno 15: DTMF 2 (end)
seqno 16: DTMF 2 (end)
seqno 17: DTMF 2 (end)
In this second situation, the beginning of the DTMF 2 arrives before the final end frame of the DTMF 1. With the patch, seqno 12 is no processed and thus we properly interpret the DTMF.
Fix 2. The second change in place is to fix an issue like the following:
seqno 1: DTMF 1
seqno 2: DTMF 1
seqno 3: DTMF 1 (end) *packet lost*
seqno 4: DTMF 1 (end) *packet lost*
seqno 5: DTMF 1 (end) *packet lost*
seqno 6: DTMF 2
When we receive seqno 6, we had code in place that was supposed to properly end the previously unended DTMF 1. The problem was that the code was essentially a no-op. The code would set up an end frame for the DTMF 1 but would immediately overwrite the frame with the begin for DTMF 2. I changed process_dtmf_rfc2833() so that instead of returning a single frame, it is given as an output parameter a list of frames. Each frame that needs to be returned is appended to this list.
Fix 3. The final change is a minor one where an AST_CONTROL_SRCCHANGE frame could get lost. If we process a cisco DTMF or an RFC 3389 frame and no frame was returned, then we would return &ast_null_frame. The problem is that earlier in the function, we may have generated an AST_CONTROL_SRCCHANGE frame and put it in the list of frames we wish to return. This frame would be lost in such a case. The patch fixes this problem
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@254454 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2010-03-25 16:04:48 +00:00
AST_LIST_INSERT_TAIL ( frames , f , frame_list ) ;
Handle extremely out of order RFC 2833 DTMF
The current implementation of RFC 2833 DTMF handling in res_rtp_asterisk will,
if a packet arrives out of order, drop the packet. This is to prevent
duplicate ton generation in the Asterisk core. Since the RTP layer does not
buffer data itself, this is the only option the RTP layer currently has for
handling packets that arrive out of order.
For the most part, this doesn't matter. For a particular digit, so long as a
BEGIN packet arrives before the first END packet, the digit will be produced.
If subsequent BEGIN packets arrive interleaved with the ENDs, they will be
dropped; likewise, if the BEGIN or END packets themselves are out of order,
those packets are dropped but sufficient information is conveyed to the
Asterisk core to produce the appropriate digit.
For certain sequences of DTMF packets - most notably when, for a particular
digit, an END packet arrives before any BEGIN packet for that digit - this
is a real problem. When an END arrives before any BEGINs, the END packet is
dropped - but at the same time, it causes subsequent BEGIN packets for that
digit to be ignored. When the next in order END packet arrives, it too is
dropped - Asterisk believes that there was no initial BEGIN.
The solution this patch provides is to trust the END packet to convey the
information needed for the Asterisk core to produce the DTMF digit. If we
receive an END packet, and it:
* Has a timestamp greater then the last timestamp received from an END
packet
* Does not have the same sequence number as the last received sequence
number (and is thus not an END packet retransmission)
Then we send the END frame up to the Asterisk core. It contains enough
DTMF information for Asterisk to produce the digit.
On the other hand, if we receive a BEGIN or continuation packet that occurs
with a timestamp equal to or less then the last END timestamp, then we've
received something out of order - but we already have received enough
information to produce the digit. These packets are dropped.
Much thanks goes to Olle Johansson (oej) for providing the idea for this
solution.
Review: https://reviewboard.asterisk.org/r/2033/
(closes issue ASTERISK-18404)
Reported by: Stephane Chazelas
Tested by: Matt Jordan
........
Merged revisions 370252 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........
Merged revisions 370271 from http://svn.asterisk.org/svn/asterisk/branches/10
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@370272 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-07-19 21:45:20 +00:00
} else if ( rtpdebug ) {
2014-05-09 22:49:26 +00:00
ast_debug ( 1 , " Dropping duplicate or out of order DTMF END frame (seqno: %u, ts %u, digit %c) \n " ,
Handle extremely out of order RFC 2833 DTMF
The current implementation of RFC 2833 DTMF handling in res_rtp_asterisk will,
if a packet arrives out of order, drop the packet. This is to prevent
duplicate ton generation in the Asterisk core. Since the RTP layer does not
buffer data itself, this is the only option the RTP layer currently has for
handling packets that arrive out of order.
For the most part, this doesn't matter. For a particular digit, so long as a
BEGIN packet arrives before the first END packet, the digit will be produced.
If subsequent BEGIN packets arrive interleaved with the ENDs, they will be
dropped; likewise, if the BEGIN or END packets themselves are out of order,
those packets are dropped but sufficient information is conveyed to the
Asterisk core to produce the appropriate digit.
For certain sequences of DTMF packets - most notably when, for a particular
digit, an END packet arrives before any BEGIN packet for that digit - this
is a real problem. When an END arrives before any BEGINs, the END packet is
dropped - but at the same time, it causes subsequent BEGIN packets for that
digit to be ignored. When the next in order END packet arrives, it too is
dropped - Asterisk believes that there was no initial BEGIN.
The solution this patch provides is to trust the END packet to convey the
information needed for the Asterisk core to produce the DTMF digit. If we
receive an END packet, and it:
* Has a timestamp greater then the last timestamp received from an END
packet
* Does not have the same sequence number as the last received sequence
number (and is thus not an END packet retransmission)
Then we send the END frame up to the Asterisk core. It contains enough
DTMF information for Asterisk to produce the digit.
On the other hand, if we receive a BEGIN or continuation packet that occurs
with a timestamp equal to or less then the last END timestamp, then we've
received something out of order - but we already have received enough
information to produce the digit. These packets are dropped.
Much thanks goes to Olle Johansson (oej) for providing the idea for this
solution.
Review: https://reviewboard.asterisk.org/r/2033/
(closes issue ASTERISK-18404)
Reported by: Stephane Chazelas
Tested by: Matt Jordan
........
Merged revisions 370252 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........
Merged revisions 370271 from http://svn.asterisk.org/svn/asterisk/branches/10
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@370272 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-07-19 21:45:20 +00:00
seqno , timestamp , resp ) ;
2009-05-13 13:39:10 +00:00
}
} else {
/* Begin/continuation */
Handle extremely out of order RFC 2833 DTMF
The current implementation of RFC 2833 DTMF handling in res_rtp_asterisk will,
if a packet arrives out of order, drop the packet. This is to prevent
duplicate ton generation in the Asterisk core. Since the RTP layer does not
buffer data itself, this is the only option the RTP layer currently has for
handling packets that arrive out of order.
For the most part, this doesn't matter. For a particular digit, so long as a
BEGIN packet arrives before the first END packet, the digit will be produced.
If subsequent BEGIN packets arrive interleaved with the ENDs, they will be
dropped; likewise, if the BEGIN or END packets themselves are out of order,
those packets are dropped but sufficient information is conveyed to the
Asterisk core to produce the appropriate digit.
For certain sequences of DTMF packets - most notably when, for a particular
digit, an END packet arrives before any BEGIN packet for that digit - this
is a real problem. When an END arrives before any BEGINs, the END packet is
dropped - but at the same time, it causes subsequent BEGIN packets for that
digit to be ignored. When the next in order END packet arrives, it too is
dropped - Asterisk believes that there was no initial BEGIN.
The solution this patch provides is to trust the END packet to convey the
information needed for the Asterisk core to produce the DTMF digit. If we
receive an END packet, and it:
* Has a timestamp greater then the last timestamp received from an END
packet
* Does not have the same sequence number as the last received sequence
number (and is thus not an END packet retransmission)
Then we send the END frame up to the Asterisk core. It contains enough
DTMF information for Asterisk to produce the digit.
On the other hand, if we receive a BEGIN or continuation packet that occurs
with a timestamp equal to or less then the last END timestamp, then we've
received something out of order - but we already have received enough
information to produce the digit. These packets are dropped.
Much thanks goes to Olle Johansson (oej) for providing the idea for this
solution.
Review: https://reviewboard.asterisk.org/r/2033/
(closes issue ASTERISK-18404)
Reported by: Stephane Chazelas
Tested by: Matt Jordan
........
Merged revisions 370252 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........
Merged revisions 370271 from http://svn.asterisk.org/svn/asterisk/branches/10
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@370272 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-07-19 21:45:20 +00:00
/* The second portion of the seqno check is to not mistakenly
* stop accepting DTMF if the seqno rolls over beyond
* 65535.
*/
if ( ( rtp - > last_seqno > seqno & & rtp - > last_seqno - seqno < 50 )
| | timestamp < = rtp - > last_end_timestamp ) {
/* Out of order frame. Processing this can cause us to
* improperly duplicate incoming DTMF , so just drop
* this .
*/
if ( rtpdebug ) {
2014-05-09 22:49:26 +00:00
ast_debug ( 1 , " Dropping out of order DTMF frame (seqno %u, ts %u, digit %c) \n " ,
Handle extremely out of order RFC 2833 DTMF
The current implementation of RFC 2833 DTMF handling in res_rtp_asterisk will,
if a packet arrives out of order, drop the packet. This is to prevent
duplicate ton generation in the Asterisk core. Since the RTP layer does not
buffer data itself, this is the only option the RTP layer currently has for
handling packets that arrive out of order.
For the most part, this doesn't matter. For a particular digit, so long as a
BEGIN packet arrives before the first END packet, the digit will be produced.
If subsequent BEGIN packets arrive interleaved with the ENDs, they will be
dropped; likewise, if the BEGIN or END packets themselves are out of order,
those packets are dropped but sufficient information is conveyed to the
Asterisk core to produce the appropriate digit.
For certain sequences of DTMF packets - most notably when, for a particular
digit, an END packet arrives before any BEGIN packet for that digit - this
is a real problem. When an END arrives before any BEGINs, the END packet is
dropped - but at the same time, it causes subsequent BEGIN packets for that
digit to be ignored. When the next in order END packet arrives, it too is
dropped - Asterisk believes that there was no initial BEGIN.
The solution this patch provides is to trust the END packet to convey the
information needed for the Asterisk core to produce the DTMF digit. If we
receive an END packet, and it:
* Has a timestamp greater then the last timestamp received from an END
packet
* Does not have the same sequence number as the last received sequence
number (and is thus not an END packet retransmission)
Then we send the END frame up to the Asterisk core. It contains enough
DTMF information for Asterisk to produce the digit.
On the other hand, if we receive a BEGIN or continuation packet that occurs
with a timestamp equal to or less then the last END timestamp, then we've
received something out of order - but we already have received enough
information to produce the digit. These packets are dropped.
Much thanks goes to Olle Johansson (oej) for providing the idea for this
solution.
Review: https://reviewboard.asterisk.org/r/2033/
(closes issue ASTERISK-18404)
Reported by: Stephane Chazelas
Tested by: Matt Jordan
........
Merged revisions 370252 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........
Merged revisions 370271 from http://svn.asterisk.org/svn/asterisk/branches/10
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@370272 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-07-19 21:45:20 +00:00
seqno , timestamp , resp ) ;
}
return ;
}
2009-05-13 13:39:10 +00:00
if ( rtp - > resp & & rtp - > resp ! = resp ) {
/* Another digit already began. End it */
Recorded merge of revisions 254452 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r254452 | mmichelson | 2010-03-25 10:59:56 -0500 (Thu, 25 Mar 2010) | 44 lines
Several fixes regarding RFC2833 DTMF detection.
Here is a copy and paste of the details from my request on
reviewboard that dealt with these changes:
Fix 1. The first change in place is to fix Mantis issue 15811, which deals with a situation where Asterisk will incorrectly interpret out of order RFC2833 frames as duplicate DTMF digits. For instance, we would receive a sequence like:
seqno 1: DTMF 1
seqno 2: DTMF 1
seqno 3: DTMF 1
seqno 4: DTMF 1
seqno 6: DTMF 1 (end)
seqno 5: DTMF 1
seqno 7: DTMF 1 (end)
seqno 8: DTMF 1 (end)
Prior to this patch when we received the frame with seqno 5, we would interpret this as a new DTMF 1. With this patch, we will check the seqno of the incoming digit and not process the frame if the seqno is lower than the last recorded seqno. Note that we do not record the seqno of the dropped DTMF frame for future processing. While the above situation is what was designed to be fixed, the patch is written in such a way that the following would also be fixed too:
seqno 9: DTMF 1
seqno 10: DTMF 1 (end)
seqno 11: DTMF 1 (end)
seqno 13: DTMF 2
seqno 12: DTMF 1 (end)
seqno 14: DTMF 2
seqno 15: DTMF 2 (end)
seqno 16: DTMF 2 (end)
seqno 17: DTMF 2 (end)
In this second situation, the beginning of the DTMF 2 arrives before the final end frame of the DTMF 1. With the patch, seqno 12 is no processed and thus we properly interpret the DTMF.
Fix 2. The second change in place is to fix an issue like the following:
seqno 1: DTMF 1
seqno 2: DTMF 1
seqno 3: DTMF 1 (end) *packet lost*
seqno 4: DTMF 1 (end) *packet lost*
seqno 5: DTMF 1 (end) *packet lost*
seqno 6: DTMF 2
When we receive seqno 6, we had code in place that was supposed to properly end the previously unended DTMF 1. The problem was that the code was essentially a no-op. The code would set up an end frame for the DTMF 1 but would immediately overwrite the frame with the begin for DTMF 2. I changed process_dtmf_rfc2833() so that instead of returning a single frame, it is given as an output parameter a list of frames. Each frame that needs to be returned is appended to this list.
Fix 3. The final change is a minor one where an AST_CONTROL_SRCCHANGE frame could get lost. If we process a cisco DTMF or an RFC 3389 frame and no frame was returned, then we would return &ast_null_frame. The problem is that earlier in the function, we may have generated an AST_CONTROL_SRCCHANGE frame and put it in the list of frames we wish to return. This frame would be lost in such a case. The patch fixes this problem
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@254454 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2010-03-25 16:04:48 +00:00
f = ast_frdup ( create_dtmf_frame ( instance , AST_FRAME_DTMF_END , 0 ) ) ;
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
f - > len = ast_tvdiff_ms ( ast_samp2tv ( rtp - > dtmf_duration , rtp_get_rate ( f - > subclass . format ) ) , ast_tv ( 0 , 0 ) ) ;
2009-05-13 13:39:10 +00:00
rtp - > resp = 0 ;
rtp - > dtmf_duration = rtp - > dtmf_timeout = 0 ;
Recorded merge of revisions 254452 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r254452 | mmichelson | 2010-03-25 10:59:56 -0500 (Thu, 25 Mar 2010) | 44 lines
Several fixes regarding RFC2833 DTMF detection.
Here is a copy and paste of the details from my request on
reviewboard that dealt with these changes:
Fix 1. The first change in place is to fix Mantis issue 15811, which deals with a situation where Asterisk will incorrectly interpret out of order RFC2833 frames as duplicate DTMF digits. For instance, we would receive a sequence like:
seqno 1: DTMF 1
seqno 2: DTMF 1
seqno 3: DTMF 1
seqno 4: DTMF 1
seqno 6: DTMF 1 (end)
seqno 5: DTMF 1
seqno 7: DTMF 1 (end)
seqno 8: DTMF 1 (end)
Prior to this patch when we received the frame with seqno 5, we would interpret this as a new DTMF 1. With this patch, we will check the seqno of the incoming digit and not process the frame if the seqno is lower than the last recorded seqno. Note that we do not record the seqno of the dropped DTMF frame for future processing. While the above situation is what was designed to be fixed, the patch is written in such a way that the following would also be fixed too:
seqno 9: DTMF 1
seqno 10: DTMF 1 (end)
seqno 11: DTMF 1 (end)
seqno 13: DTMF 2
seqno 12: DTMF 1 (end)
seqno 14: DTMF 2
seqno 15: DTMF 2 (end)
seqno 16: DTMF 2 (end)
seqno 17: DTMF 2 (end)
In this second situation, the beginning of the DTMF 2 arrives before the final end frame of the DTMF 1. With the patch, seqno 12 is no processed and thus we properly interpret the DTMF.
Fix 2. The second change in place is to fix an issue like the following:
seqno 1: DTMF 1
seqno 2: DTMF 1
seqno 3: DTMF 1 (end) *packet lost*
seqno 4: DTMF 1 (end) *packet lost*
seqno 5: DTMF 1 (end) *packet lost*
seqno 6: DTMF 2
When we receive seqno 6, we had code in place that was supposed to properly end the previously unended DTMF 1. The problem was that the code was essentially a no-op. The code would set up an end frame for the DTMF 1 but would immediately overwrite the frame with the begin for DTMF 2. I changed process_dtmf_rfc2833() so that instead of returning a single frame, it is given as an output parameter a list of frames. Each frame that needs to be returned is appended to this list.
Fix 3. The final change is a minor one where an AST_CONTROL_SRCCHANGE frame could get lost. If we process a cisco DTMF or an RFC 3389 frame and no frame was returned, then we would return &ast_null_frame. The problem is that earlier in the function, we may have generated an AST_CONTROL_SRCCHANGE frame and put it in the list of frames we wish to return. This frame would be lost in such a case. The patch fixes this problem
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@254454 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2010-03-25 16:04:48 +00:00
AST_LIST_INSERT_TAIL ( frames , f , frame_list ) ;
2009-05-13 13:39:10 +00:00
}
if ( rtp - > resp ) {
/* Digit continues */
rtp - > dtmf_duration = new_duration ;
} else {
/* New digit began */
rtp - > resp = resp ;
Recorded merge of revisions 254452 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r254452 | mmichelson | 2010-03-25 10:59:56 -0500 (Thu, 25 Mar 2010) | 44 lines
Several fixes regarding RFC2833 DTMF detection.
Here is a copy and paste of the details from my request on
reviewboard that dealt with these changes:
Fix 1. The first change in place is to fix Mantis issue 15811, which deals with a situation where Asterisk will incorrectly interpret out of order RFC2833 frames as duplicate DTMF digits. For instance, we would receive a sequence like:
seqno 1: DTMF 1
seqno 2: DTMF 1
seqno 3: DTMF 1
seqno 4: DTMF 1
seqno 6: DTMF 1 (end)
seqno 5: DTMF 1
seqno 7: DTMF 1 (end)
seqno 8: DTMF 1 (end)
Prior to this patch when we received the frame with seqno 5, we would interpret this as a new DTMF 1. With this patch, we will check the seqno of the incoming digit and not process the frame if the seqno is lower than the last recorded seqno. Note that we do not record the seqno of the dropped DTMF frame for future processing. While the above situation is what was designed to be fixed, the patch is written in such a way that the following would also be fixed too:
seqno 9: DTMF 1
seqno 10: DTMF 1 (end)
seqno 11: DTMF 1 (end)
seqno 13: DTMF 2
seqno 12: DTMF 1 (end)
seqno 14: DTMF 2
seqno 15: DTMF 2 (end)
seqno 16: DTMF 2 (end)
seqno 17: DTMF 2 (end)
In this second situation, the beginning of the DTMF 2 arrives before the final end frame of the DTMF 1. With the patch, seqno 12 is no processed and thus we properly interpret the DTMF.
Fix 2. The second change in place is to fix an issue like the following:
seqno 1: DTMF 1
seqno 2: DTMF 1
seqno 3: DTMF 1 (end) *packet lost*
seqno 4: DTMF 1 (end) *packet lost*
seqno 5: DTMF 1 (end) *packet lost*
seqno 6: DTMF 2
When we receive seqno 6, we had code in place that was supposed to properly end the previously unended DTMF 1. The problem was that the code was essentially a no-op. The code would set up an end frame for the DTMF 1 but would immediately overwrite the frame with the begin for DTMF 2. I changed process_dtmf_rfc2833() so that instead of returning a single frame, it is given as an output parameter a list of frames. Each frame that needs to be returned is appended to this list.
Fix 3. The final change is a minor one where an AST_CONTROL_SRCCHANGE frame could get lost. If we process a cisco DTMF or an RFC 3389 frame and no frame was returned, then we would return &ast_null_frame. The problem is that earlier in the function, we may have generated an AST_CONTROL_SRCCHANGE frame and put it in the list of frames we wish to return. This frame would be lost in such a case. The patch fixes this problem
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@254454 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2010-03-25 16:04:48 +00:00
f = ast_frdup ( create_dtmf_frame ( instance , AST_FRAME_DTMF_BEGIN , 0 ) ) ;
2009-05-13 13:39:10 +00:00
rtp - > dtmf_duration = samples ;
Recorded merge of revisions 254452 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r254452 | mmichelson | 2010-03-25 10:59:56 -0500 (Thu, 25 Mar 2010) | 44 lines
Several fixes regarding RFC2833 DTMF detection.
Here is a copy and paste of the details from my request on
reviewboard that dealt with these changes:
Fix 1. The first change in place is to fix Mantis issue 15811, which deals with a situation where Asterisk will incorrectly interpret out of order RFC2833 frames as duplicate DTMF digits. For instance, we would receive a sequence like:
seqno 1: DTMF 1
seqno 2: DTMF 1
seqno 3: DTMF 1
seqno 4: DTMF 1
seqno 6: DTMF 1 (end)
seqno 5: DTMF 1
seqno 7: DTMF 1 (end)
seqno 8: DTMF 1 (end)
Prior to this patch when we received the frame with seqno 5, we would interpret this as a new DTMF 1. With this patch, we will check the seqno of the incoming digit and not process the frame if the seqno is lower than the last recorded seqno. Note that we do not record the seqno of the dropped DTMF frame for future processing. While the above situation is what was designed to be fixed, the patch is written in such a way that the following would also be fixed too:
seqno 9: DTMF 1
seqno 10: DTMF 1 (end)
seqno 11: DTMF 1 (end)
seqno 13: DTMF 2
seqno 12: DTMF 1 (end)
seqno 14: DTMF 2
seqno 15: DTMF 2 (end)
seqno 16: DTMF 2 (end)
seqno 17: DTMF 2 (end)
In this second situation, the beginning of the DTMF 2 arrives before the final end frame of the DTMF 1. With the patch, seqno 12 is no processed and thus we properly interpret the DTMF.
Fix 2. The second change in place is to fix an issue like the following:
seqno 1: DTMF 1
seqno 2: DTMF 1
seqno 3: DTMF 1 (end) *packet lost*
seqno 4: DTMF 1 (end) *packet lost*
seqno 5: DTMF 1 (end) *packet lost*
seqno 6: DTMF 2
When we receive seqno 6, we had code in place that was supposed to properly end the previously unended DTMF 1. The problem was that the code was essentially a no-op. The code would set up an end frame for the DTMF 1 but would immediately overwrite the frame with the begin for DTMF 2. I changed process_dtmf_rfc2833() so that instead of returning a single frame, it is given as an output parameter a list of frames. Each frame that needs to be returned is appended to this list.
Fix 3. The final change is a minor one where an AST_CONTROL_SRCCHANGE frame could get lost. If we process a cisco DTMF or an RFC 3389 frame and no frame was returned, then we would return &ast_null_frame. The problem is that earlier in the function, we may have generated an AST_CONTROL_SRCCHANGE frame and put it in the list of frames we wish to return. This frame would be lost in such a case. The patch fixes this problem
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@254454 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2010-03-25 16:04:48 +00:00
AST_LIST_INSERT_TAIL ( frames , f , frame_list ) ;
2009-05-13 13:39:10 +00:00
}
rtp - > dtmf_timeout = timestamp + rtp - > dtmf_duration + dtmftimeout ;
2009-04-02 17:20:52 +00:00
}
2009-05-13 13:39:10 +00:00
Handle extremely out of order RFC 2833 DTMF
The current implementation of RFC 2833 DTMF handling in res_rtp_asterisk will,
if a packet arrives out of order, drop the packet. This is to prevent
duplicate ton generation in the Asterisk core. Since the RTP layer does not
buffer data itself, this is the only option the RTP layer currently has for
handling packets that arrive out of order.
For the most part, this doesn't matter. For a particular digit, so long as a
BEGIN packet arrives before the first END packet, the digit will be produced.
If subsequent BEGIN packets arrive interleaved with the ENDs, they will be
dropped; likewise, if the BEGIN or END packets themselves are out of order,
those packets are dropped but sufficient information is conveyed to the
Asterisk core to produce the appropriate digit.
For certain sequences of DTMF packets - most notably when, for a particular
digit, an END packet arrives before any BEGIN packet for that digit - this
is a real problem. When an END arrives before any BEGINs, the END packet is
dropped - but at the same time, it causes subsequent BEGIN packets for that
digit to be ignored. When the next in order END packet arrives, it too is
dropped - Asterisk believes that there was no initial BEGIN.
The solution this patch provides is to trust the END packet to convey the
information needed for the Asterisk core to produce the DTMF digit. If we
receive an END packet, and it:
* Has a timestamp greater then the last timestamp received from an END
packet
* Does not have the same sequence number as the last received sequence
number (and is thus not an END packet retransmission)
Then we send the END frame up to the Asterisk core. It contains enough
DTMF information for Asterisk to produce the digit.
On the other hand, if we receive a BEGIN or continuation packet that occurs
with a timestamp equal to or less then the last END timestamp, then we've
received something out of order - but we already have received enough
information to produce the digit. These packets are dropped.
Much thanks goes to Olle Johansson (oej) for providing the idea for this
solution.
Review: https://reviewboard.asterisk.org/r/2033/
(closes issue ASTERISK-18404)
Reported by: Stephane Chazelas
Tested by: Matt Jordan
........
Merged revisions 370252 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........
Merged revisions 370271 from http://svn.asterisk.org/svn/asterisk/branches/10
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@370272 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-07-19 21:45:20 +00:00
rtp - > last_seqno = seqno ;
2009-04-02 17:20:52 +00:00
}
rtp - > dtmfsamples = samples ;
Recorded merge of revisions 254452 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r254452 | mmichelson | 2010-03-25 10:59:56 -0500 (Thu, 25 Mar 2010) | 44 lines
Several fixes regarding RFC2833 DTMF detection.
Here is a copy and paste of the details from my request on
reviewboard that dealt with these changes:
Fix 1. The first change in place is to fix Mantis issue 15811, which deals with a situation where Asterisk will incorrectly interpret out of order RFC2833 frames as duplicate DTMF digits. For instance, we would receive a sequence like:
seqno 1: DTMF 1
seqno 2: DTMF 1
seqno 3: DTMF 1
seqno 4: DTMF 1
seqno 6: DTMF 1 (end)
seqno 5: DTMF 1
seqno 7: DTMF 1 (end)
seqno 8: DTMF 1 (end)
Prior to this patch when we received the frame with seqno 5, we would interpret this as a new DTMF 1. With this patch, we will check the seqno of the incoming digit and not process the frame if the seqno is lower than the last recorded seqno. Note that we do not record the seqno of the dropped DTMF frame for future processing. While the above situation is what was designed to be fixed, the patch is written in such a way that the following would also be fixed too:
seqno 9: DTMF 1
seqno 10: DTMF 1 (end)
seqno 11: DTMF 1 (end)
seqno 13: DTMF 2
seqno 12: DTMF 1 (end)
seqno 14: DTMF 2
seqno 15: DTMF 2 (end)
seqno 16: DTMF 2 (end)
seqno 17: DTMF 2 (end)
In this second situation, the beginning of the DTMF 2 arrives before the final end frame of the DTMF 1. With the patch, seqno 12 is no processed and thus we properly interpret the DTMF.
Fix 2. The second change in place is to fix an issue like the following:
seqno 1: DTMF 1
seqno 2: DTMF 1
seqno 3: DTMF 1 (end) *packet lost*
seqno 4: DTMF 1 (end) *packet lost*
seqno 5: DTMF 1 (end) *packet lost*
seqno 6: DTMF 2
When we receive seqno 6, we had code in place that was supposed to properly end the previously unended DTMF 1. The problem was that the code was essentially a no-op. The code would set up an end frame for the DTMF 1 but would immediately overwrite the frame with the begin for DTMF 2. I changed process_dtmf_rfc2833() so that instead of returning a single frame, it is given as an output parameter a list of frames. Each frame that needs to be returned is appended to this list.
Fix 3. The final change is a minor one where an AST_CONTROL_SRCCHANGE frame could get lost. If we process a cisco DTMF or an RFC 3389 frame and no frame was returned, then we would return &ast_null_frame. The problem is that earlier in the function, we may have generated an AST_CONTROL_SRCCHANGE frame and put it in the list of frames we wish to return. This frame would be lost in such a case. The patch fixes this problem
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@254454 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2010-03-25 16:04:48 +00:00
return ;
2009-04-02 17:20:52 +00:00
}
2010-07-08 22:08:07 +00:00
static struct ast_frame * process_dtmf_cisco ( struct ast_rtp_instance * instance , unsigned char * data , int len , unsigned int seqno , unsigned int timestamp , struct ast_sockaddr * addr , int payloadtype , int mark )
2009-04-02 17:20:52 +00:00
{
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
unsigned int event , flags , power ;
char resp = 0 ;
unsigned char seq ;
struct ast_frame * f = NULL ;
if ( len < 4 ) {
return NULL ;
}
/* The format of Cisco RTP DTMF packet looks like next:
+ 0 - sequence number of DTMF RTP packet ( begins from 1 ,
wrapped to 0 )
+ 1 - set of flags
+ 1 ( bit 0 ) - flaps by different DTMF digits delimited by audio
or repeated digit without audio ? ? ?
+ 2 ( + 4 , + 6 , . . . ) - power level ? ( rises from 0 to 32 at begin of tone
then falls to 0 at its end )
+ 3 ( + 5 , + 7 , . . . ) - detected DTMF digit ( 0. .9 , * , # , A - D , . . . )
Repeated DTMF information ( bytes 4 / 5 , 6 / 7 ) is history shifted right
by each new packet and thus provides some redudancy .
Sample of Cisco RTP DTMF packet is ( all data in hex ) :
19 07 00 02 12 02 20 02
showing end of DTMF digit ' 2 ' .
The packets
27 07 00 02 0 A 02 20 02
28 06 20 02 00 02 0 A 02
shows begin of new digit ' 2 ' with very short pause ( 20 ms ) after
previous digit ' 2 ' . Bit + 1.0 flips at begin of new digit .
Cisco RTP DTMF packets comes as replacement of audio RTP packets
so its uses the same sequencing and timestamping rules as replaced
audio packets . Repeat interval of DTMF packets is 20 ms and not rely
on audio framing parameters . Marker bit isn ' t used within stream of
DTMFs nor audio stream coming immediately after DTMF stream . Timestamps
are not sequential at borders between DTMF and audio streams ,
*/
seq = data [ 0 ] ;
flags = data [ 1 ] ;
power = data [ 2 ] ;
event = data [ 3 ] & 0x1f ;
2011-02-04 16:55:39 +00:00
if ( rtpdebug )
2014-05-09 22:49:26 +00:00
ast_debug ( 0 , " Cisco DTMF Digit: %02x (len=%d, seq=%d, flags=%02x, power=%u, history count=%d) \n " , event , len , seq , flags , power , ( len - 4 ) / 2 ) ;
2009-04-02 17:20:52 +00:00
if ( event < 10 ) {
resp = ' 0 ' + event ;
} else if ( event < 11 ) {
resp = ' * ' ;
} else if ( event < 12 ) {
resp = ' # ' ;
} else if ( event < 16 ) {
resp = ' A ' + ( event - 12 ) ;
} else if ( event < 17 ) {
resp = ' X ' ;
}
if ( ( ! rtp - > resp & & power ) | | ( rtp - > resp & & ( rtp - > resp ! = resp ) ) ) {
rtp - > resp = resp ;
/* Why we should care on DTMF compensation at reception? */
if ( ast_rtp_instance_get_prop ( instance , AST_RTP_PROPERTY_DTMF_COMPENSATE ) ) {
Recorded merge of revisions 254452 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r254452 | mmichelson | 2010-03-25 10:59:56 -0500 (Thu, 25 Mar 2010) | 44 lines
Several fixes regarding RFC2833 DTMF detection.
Here is a copy and paste of the details from my request on
reviewboard that dealt with these changes:
Fix 1. The first change in place is to fix Mantis issue 15811, which deals with a situation where Asterisk will incorrectly interpret out of order RFC2833 frames as duplicate DTMF digits. For instance, we would receive a sequence like:
seqno 1: DTMF 1
seqno 2: DTMF 1
seqno 3: DTMF 1
seqno 4: DTMF 1
seqno 6: DTMF 1 (end)
seqno 5: DTMF 1
seqno 7: DTMF 1 (end)
seqno 8: DTMF 1 (end)
Prior to this patch when we received the frame with seqno 5, we would interpret this as a new DTMF 1. With this patch, we will check the seqno of the incoming digit and not process the frame if the seqno is lower than the last recorded seqno. Note that we do not record the seqno of the dropped DTMF frame for future processing. While the above situation is what was designed to be fixed, the patch is written in such a way that the following would also be fixed too:
seqno 9: DTMF 1
seqno 10: DTMF 1 (end)
seqno 11: DTMF 1 (end)
seqno 13: DTMF 2
seqno 12: DTMF 1 (end)
seqno 14: DTMF 2
seqno 15: DTMF 2 (end)
seqno 16: DTMF 2 (end)
seqno 17: DTMF 2 (end)
In this second situation, the beginning of the DTMF 2 arrives before the final end frame of the DTMF 1. With the patch, seqno 12 is no processed and thus we properly interpret the DTMF.
Fix 2. The second change in place is to fix an issue like the following:
seqno 1: DTMF 1
seqno 2: DTMF 1
seqno 3: DTMF 1 (end) *packet lost*
seqno 4: DTMF 1 (end) *packet lost*
seqno 5: DTMF 1 (end) *packet lost*
seqno 6: DTMF 2
When we receive seqno 6, we had code in place that was supposed to properly end the previously unended DTMF 1. The problem was that the code was essentially a no-op. The code would set up an end frame for the DTMF 1 but would immediately overwrite the frame with the begin for DTMF 2. I changed process_dtmf_rfc2833() so that instead of returning a single frame, it is given as an output parameter a list of frames. Each frame that needs to be returned is appended to this list.
Fix 3. The final change is a minor one where an AST_CONTROL_SRCCHANGE frame could get lost. If we process a cisco DTMF or an RFC 3389 frame and no frame was returned, then we would return &ast_null_frame. The problem is that earlier in the function, we may have generated an AST_CONTROL_SRCCHANGE frame and put it in the list of frames we wish to return. This frame would be lost in such a case. The patch fixes this problem
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@254454 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2010-03-25 16:04:48 +00:00
f = create_dtmf_frame ( instance , AST_FRAME_DTMF_BEGIN , 0 ) ;
2009-04-02 17:20:52 +00:00
rtp - > dtmfsamples = 0 ;
}
} else if ( ( rtp - > resp = = resp ) & & ! power ) {
Recorded merge of revisions 254452 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r254452 | mmichelson | 2010-03-25 10:59:56 -0500 (Thu, 25 Mar 2010) | 44 lines
Several fixes regarding RFC2833 DTMF detection.
Here is a copy and paste of the details from my request on
reviewboard that dealt with these changes:
Fix 1. The first change in place is to fix Mantis issue 15811, which deals with a situation where Asterisk will incorrectly interpret out of order RFC2833 frames as duplicate DTMF digits. For instance, we would receive a sequence like:
seqno 1: DTMF 1
seqno 2: DTMF 1
seqno 3: DTMF 1
seqno 4: DTMF 1
seqno 6: DTMF 1 (end)
seqno 5: DTMF 1
seqno 7: DTMF 1 (end)
seqno 8: DTMF 1 (end)
Prior to this patch when we received the frame with seqno 5, we would interpret this as a new DTMF 1. With this patch, we will check the seqno of the incoming digit and not process the frame if the seqno is lower than the last recorded seqno. Note that we do not record the seqno of the dropped DTMF frame for future processing. While the above situation is what was designed to be fixed, the patch is written in such a way that the following would also be fixed too:
seqno 9: DTMF 1
seqno 10: DTMF 1 (end)
seqno 11: DTMF 1 (end)
seqno 13: DTMF 2
seqno 12: DTMF 1 (end)
seqno 14: DTMF 2
seqno 15: DTMF 2 (end)
seqno 16: DTMF 2 (end)
seqno 17: DTMF 2 (end)
In this second situation, the beginning of the DTMF 2 arrives before the final end frame of the DTMF 1. With the patch, seqno 12 is no processed and thus we properly interpret the DTMF.
Fix 2. The second change in place is to fix an issue like the following:
seqno 1: DTMF 1
seqno 2: DTMF 1
seqno 3: DTMF 1 (end) *packet lost*
seqno 4: DTMF 1 (end) *packet lost*
seqno 5: DTMF 1 (end) *packet lost*
seqno 6: DTMF 2
When we receive seqno 6, we had code in place that was supposed to properly end the previously unended DTMF 1. The problem was that the code was essentially a no-op. The code would set up an end frame for the DTMF 1 but would immediately overwrite the frame with the begin for DTMF 2. I changed process_dtmf_rfc2833() so that instead of returning a single frame, it is given as an output parameter a list of frames. Each frame that needs to be returned is appended to this list.
Fix 3. The final change is a minor one where an AST_CONTROL_SRCCHANGE frame could get lost. If we process a cisco DTMF or an RFC 3389 frame and no frame was returned, then we would return &ast_null_frame. The problem is that earlier in the function, we may have generated an AST_CONTROL_SRCCHANGE frame and put it in the list of frames we wish to return. This frame would be lost in such a case. The patch fixes this problem
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@254454 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2010-03-25 16:04:48 +00:00
f = create_dtmf_frame ( instance , AST_FRAME_DTMF_END , ast_rtp_instance_get_prop ( instance , AST_RTP_PROPERTY_DTMF_COMPENSATE ) ) ;
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
f - > samples = rtp - > dtmfsamples * ( rtp_get_rate ( rtp - > lastrxformat ) / 1000 ) ;
2009-04-02 17:20:52 +00:00
rtp - > resp = 0 ;
2012-12-03 09:35:55 +00:00
} else if ( rtp - > resp = = resp ) {
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
rtp - > dtmfsamples + = 20 * ( rtp_get_rate ( rtp - > lastrxformat ) / 1000 ) ;
2012-12-03 09:35:55 +00:00
}
2010-05-19 14:38:02 +00:00
2009-05-13 13:39:10 +00:00
rtp - > dtmf_timeout = 0 ;
2009-04-02 17:20:52 +00:00
return f ;
}
2010-07-08 22:08:07 +00:00
static struct ast_frame * process_cn_rfc3389 ( struct ast_rtp_instance * instance , unsigned char * data , int len , unsigned int seqno , unsigned int timestamp , struct ast_sockaddr * addr , int payloadtype , int mark )
2009-04-02 17:20:52 +00:00
{
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
/* Convert comfort noise into audio with various codecs. Unfortunately this doesn't
totally help us out becuase we don ' t have an engine to keep it going and we are not
guaranteed to have it every 20 ms or anything */
2012-12-03 09:35:55 +00:00
if ( rtpdebug ) {
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_debug ( 0 , " - RTP 3389 Comfort noise event: Format %s (len = %d) \n " ,
ast_format_get_name ( rtp - > lastrxformat ) , len ) ;
2012-12-03 09:35:55 +00:00
}
2009-04-02 17:20:52 +00:00
if ( ast_test_flag ( rtp , FLAG_3389_WARNING ) ) {
2010-07-08 22:08:07 +00:00
struct ast_sockaddr remote_address = { { 0 , } } ;
2009-04-02 17:20:52 +00:00
ast_rtp_instance_get_remote_address ( instance , & remote_address ) ;
2010-07-08 22:08:07 +00:00
ast_log ( LOG_NOTICE , " Comfort noise support incomplete in Asterisk (RFC 3389). Please turn off on client if possible. Client address: %s \n " ,
ast_sockaddr_stringify ( & remote_address ) ) ;
2009-04-02 17:20:52 +00:00
ast_set_flag ( rtp , FLAG_3389_WARNING ) ;
}
/* Must have at least one byte */
2012-12-03 09:35:55 +00:00
if ( ! len ) {
2009-04-02 17:20:52 +00:00
return NULL ;
2012-12-03 09:35:55 +00:00
}
2009-04-02 17:20:52 +00:00
if ( len < 24 ) {
rtp - > f . data . ptr = rtp - > rawdata + AST_FRIENDLY_OFFSET ;
rtp - > f . datalen = len - 1 ;
rtp - > f . offset = AST_FRIENDLY_OFFSET ;
memcpy ( rtp - > f . data . ptr , data + 1 , len - 1 ) ;
} else {
rtp - > f . data . ptr = NULL ;
rtp - > f . offset = 0 ;
rtp - > f . datalen = 0 ;
}
rtp - > f . frametype = AST_FRAME_CNG ;
2009-11-04 14:05:12 +00:00
rtp - > f . subclass . integer = data [ 0 ] & 0x7f ;
2009-04-02 17:20:52 +00:00
rtp - > f . samples = 0 ;
rtp - > f . delivery . tv_usec = rtp - > f . delivery . tv_sec = 0 ;
return & rtp - > f ;
}
2013-07-05 17:33:33 +00:00
static int update_rtt_stats ( struct ast_rtp * rtp , unsigned int lsr , unsigned int dlsr )
{
struct timeval now ;
struct timeval rtt_tv ;
unsigned int msw ;
unsigned int lsw ;
unsigned int rtt_msw ;
unsigned int rtt_lsw ;
unsigned int lsr_a ;
unsigned int rtt ;
double normdevrtt_current ;
gettimeofday ( & now , NULL ) ;
timeval2ntp ( now , & msw , & lsw ) ;
lsr_a = ( ( msw & 0x0000ffff ) < < 16 ) | ( ( lsw & 0xffff0000 ) > > 16 ) ;
rtt = lsr_a - lsr - dlsr ;
rtt_msw = ( rtt & 0xffff0000 ) > > 16 ;
rtt_lsw = ( rtt & 0x0000ffff ) < < 16 ;
rtt_tv . tv_sec = rtt_msw ;
rtt_tv . tv_usec = ( ( rtt_lsw < < 6 ) / 3650 ) - ( rtt_lsw > > 12 ) - ( rtt_lsw > > 8 ) ;
rtp - > rtcp - > rtt = ( double ) rtt_tv . tv_sec + ( ( double ) rtt_tv . tv_usec / 1000000 ) ;
if ( lsr_a - dlsr < lsr ) {
return 1 ;
}
rtp - > rtcp - > accumulated_transit + = rtp - > rtcp - > rtt ;
if ( rtp - > rtcp - > rtt_count = = 0 | | rtp - > rtcp - > minrtt > rtp - > rtcp - > rtt ) {
rtp - > rtcp - > minrtt = rtp - > rtcp - > rtt ;
}
if ( rtp - > rtcp - > maxrtt < rtp - > rtcp - > rtt ) {
rtp - > rtcp - > maxrtt = rtp - > rtcp - > rtt ;
}
normdevrtt_current = normdev_compute ( rtp - > rtcp - > normdevrtt ,
rtp - > rtcp - > rtt ,
rtp - > rtcp - > rtt_count ) ;
rtp - > rtcp - > stdevrtt = stddev_compute ( rtp - > rtcp - > stdevrtt ,
rtp - > rtcp - > rtt ,
rtp - > rtcp - > normdevrtt ,
normdevrtt_current ,
rtp - > rtcp - > rtt_count ) ;
rtp - > rtcp - > normdevrtt = normdevrtt_current ;
rtp - > rtcp - > rtt_count + + ;
return 0 ;
}
2013-08-16 17:33:21 +00:00
/*!
* \ internal
* \ brief Update RTCP interarrival jitter stats
*/
2013-07-05 17:33:33 +00:00
static void update_jitter_stats ( struct ast_rtp * rtp , unsigned int ia_jitter )
{
double reported_jitter ;
double reported_normdev_jitter_current ;
rtp - > rtcp - > reported_jitter = ia_jitter ;
reported_jitter = ( double ) rtp - > rtcp - > reported_jitter ;
if ( rtp - > rtcp - > reported_jitter_count = = 0 ) {
rtp - > rtcp - > reported_minjitter = reported_jitter ;
}
if ( reported_jitter < rtp - > rtcp - > reported_minjitter ) {
rtp - > rtcp - > reported_minjitter = reported_jitter ;
}
if ( reported_jitter > rtp - > rtcp - > reported_maxjitter ) {
rtp - > rtcp - > reported_maxjitter = reported_jitter ;
}
reported_normdev_jitter_current = normdev_compute ( rtp - > rtcp - > reported_normdev_jitter , reported_jitter , rtp - > rtcp - > reported_jitter_count ) ;
rtp - > rtcp - > reported_stdev_jitter = stddev_compute ( rtp - > rtcp - > reported_stdev_jitter , reported_jitter , rtp - > rtcp - > reported_normdev_jitter , reported_normdev_jitter_current , rtp - > rtcp - > reported_jitter_count ) ;
rtp - > rtcp - > reported_normdev_jitter = reported_normdev_jitter_current ;
}
2013-08-16 17:33:21 +00:00
/*!
* \ internal
* \ brief Update RTCP lost packet stats
*/
2013-07-05 17:33:33 +00:00
static void update_lost_stats ( struct ast_rtp * rtp , unsigned int lost_packets )
{
double reported_lost ;
double reported_normdev_lost_current ;
rtp - > rtcp - > reported_lost = lost_packets ;
reported_lost = ( double ) rtp - > rtcp - > reported_lost ;
if ( rtp - > rtcp - > reported_jitter_count = = 0 ) {
rtp - > rtcp - > reported_minlost = reported_lost ;
}
if ( reported_lost < rtp - > rtcp - > reported_minlost ) {
rtp - > rtcp - > reported_minlost = reported_lost ;
}
if ( reported_lost > rtp - > rtcp - > reported_maxlost ) {
rtp - > rtcp - > reported_maxlost = reported_lost ;
}
reported_normdev_lost_current = normdev_compute ( rtp - > rtcp - > reported_normdev_lost , reported_lost , rtp - > rtcp - > reported_jitter_count ) ;
rtp - > rtcp - > reported_stdev_lost = stddev_compute ( rtp - > rtcp - > reported_stdev_lost , reported_lost , rtp - > rtcp - > reported_normdev_lost , reported_normdev_lost_current , rtp - > rtcp - > reported_jitter_count ) ;
rtp - > rtcp - > reported_normdev_lost = reported_normdev_lost_current ;
}
2009-04-02 17:20:52 +00:00
static struct ast_frame * ast_rtcp_read ( struct ast_rtp_instance * instance )
{
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
2010-07-08 22:08:07 +00:00
struct ast_sockaddr addr ;
2012-07-10 11:49:18 +00:00
unsigned char rtcpdata [ 8192 + AST_FRIENDLY_OFFSET ] ;
2009-04-02 17:20:52 +00:00
unsigned int * rtcpheader = ( unsigned int * ) ( rtcpdata + AST_FRIENDLY_OFFSET ) ;
int res , packetwords , position = 0 ;
2013-07-05 17:33:33 +00:00
int report_counter = 0 ;
struct ast_rtp_rtcp_report_block * report_block ;
2009-04-02 17:20:52 +00:00
struct ast_frame * f = & ast_null_frame ;
res_hep_rtcp: Add module that sends RTCP information to a Homer Server
This patch adds a new module to Asterisk, res_hep_rtcp. The module subscribes
to the RTCP topics in Stasis and receives RTCP information back from the
message bus. It encodes into HEPv3 packets and sends the information to the
res_hep module for transmission.
Using this, someone with a Homer server can get live call quality monitoring
for all RTP-based channels in their Asterisk 12+ systems.
In addition, there were a few bugs in the RTP engine, res_rtp_asterisk, and
chan_pjsip that were uncovered by the tests written for the Asterisk Test
Suite. This patch fixes the following:
1) chan_pjsip failed to set its channel unique ids on its RTP instance on
outbound calls. It now does this in the appropriate location, in the
serialized call callback.
2) The rtp_engine was overflowing some values when packed into JSON.
Specifically, some longs and unsigned ints can't be be packed into integer
values, for obvious reasons. Since libjansson only supports integers,
floats, strings, booleans, and objects, we print these values into strings.
3) res_rtp_asterisk had a few problems:
(a) it would emit a source IP address of 0.0.0.0 if bound to that IP
address. We now use ast_find_ourip to get a better IP address, and
properly marshal the result into an ast_strdupa'd string.
(b) Reports can be generated with no report bodies. In particular, this
occurs when a sender is transmitting information to a receiver (who
will send no RTP back to the sender). As such, the sender has no report
body for what it received. We now properly handle this case, and the
sender will emit SR reports with no body. Likewise, if we receive an
RTCP packet with no report body, we will still generate the appropriate
events.
ASTERISK-24119 #close
........
Merged revisions 419823 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419825 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-31 11:57:51 +00:00
char * str_local_address ;
char * str_remote_address ;
struct ast_sockaddr local_address = { { 0 , } } ;
struct ast_sockaddr real_local_address = { { 0 , } } ;
struct ast_sockaddr real_remote_address = { { 0 , } } ;
2009-04-02 17:20:52 +00:00
/* Read in RTCP data from the socket */
2010-07-08 22:08:07 +00:00
if ( ( res = rtcp_recvfrom ( instance , rtcpdata + AST_FRIENDLY_OFFSET ,
2012-07-10 11:49:18 +00:00
sizeof ( rtcpdata ) - AST_FRIENDLY_OFFSET ,
2010-07-08 22:08:07 +00:00
0 , & addr ) ) < 0 ) {
2009-04-02 17:20:52 +00:00
ast_assert ( errno ! = EBADF ) ;
if ( errno ! = EAGAIN ) {
2012-09-05 17:38:22 +00:00
ast_log ( LOG_WARNING , " RTCP Read error: %s. Hanging up. \n " ,
( errno ) ? strerror ( errno ) : " Unspecified " ) ;
2009-04-02 17:20:52 +00:00
return NULL ;
}
return & ast_null_frame ;
}
2012-07-01 17:28:57 +00:00
/* If this was handled by the ICE session don't do anything further */
if ( ! res ) {
return & ast_null_frame ;
}
2012-07-10 11:49:18 +00:00
if ( ! * ( rtcpdata + AST_FRIENDLY_OFFSET ) ) {
struct sockaddr_in addr_tmp ;
struct ast_sockaddr addr_v4 ;
if ( ast_sockaddr_is_ipv4 ( & addr ) ) {
ast_sockaddr_to_sin ( & addr , & addr_tmp ) ;
} else if ( ast_sockaddr_ipv4_mapped ( & addr , & addr_v4 ) ) {
ast_debug ( 1 , " Using IPv6 mapped address %s for STUN \n " ,
ast_sockaddr_stringify ( & addr ) ) ;
ast_sockaddr_to_sin ( & addr_v4 , & addr_tmp ) ;
} else {
ast_debug ( 1 , " Cannot do STUN for non IPv4 address %s \n " ,
ast_sockaddr_stringify ( & addr ) ) ;
return & ast_null_frame ;
}
if ( ( ast_stun_handle_packet ( rtp - > rtcp - > s , & addr_tmp , rtcpdata + AST_FRIENDLY_OFFSET , res , NULL , NULL ) = = AST_STUN_ACCEPT ) ) {
ast_sockaddr_from_sin ( & addr , & addr_tmp ) ;
ast_sockaddr_copy ( & rtp - > rtcp - > them , & addr ) ;
}
return & ast_null_frame ;
}
2009-04-02 17:20:52 +00:00
packetwords = res / 4 ;
if ( ast_rtp_instance_get_prop ( instance , AST_RTP_PROPERTY_NAT ) ) {
/* Send to whoever sent to us */
2010-07-08 22:08:07 +00:00
if ( ast_sockaddr_cmp ( & rtp - > rtcp - > them , & addr ) ) {
ast_sockaddr_copy ( & rtp - > rtcp - > them , & addr ) ;
2012-12-03 09:35:55 +00:00
if ( rtpdebug ) {
2010-07-08 22:08:07 +00:00
ast_debug ( 0 , " RTCP NAT: Got RTCP from other end. Now sending to address %s \n " ,
ast_sockaddr_stringify ( & rtp - > rtcp - > them ) ) ;
2012-12-03 09:35:55 +00:00
}
2009-04-02 17:20:52 +00:00
}
}
ast_debug ( 1 , " Got RTCP report of %d bytes \n " , res ) ;
res_hep_rtcp: Add module that sends RTCP information to a Homer Server
This patch adds a new module to Asterisk, res_hep_rtcp. The module subscribes
to the RTCP topics in Stasis and receives RTCP information back from the
message bus. It encodes into HEPv3 packets and sends the information to the
res_hep module for transmission.
Using this, someone with a Homer server can get live call quality monitoring
for all RTP-based channels in their Asterisk 12+ systems.
In addition, there were a few bugs in the RTP engine, res_rtp_asterisk, and
chan_pjsip that were uncovered by the tests written for the Asterisk Test
Suite. This patch fixes the following:
1) chan_pjsip failed to set its channel unique ids on its RTP instance on
outbound calls. It now does this in the appropriate location, in the
serialized call callback.
2) The rtp_engine was overflowing some values when packed into JSON.
Specifically, some longs and unsigned ints can't be be packed into integer
values, for obvious reasons. Since libjansson only supports integers,
floats, strings, booleans, and objects, we print these values into strings.
3) res_rtp_asterisk had a few problems:
(a) it would emit a source IP address of 0.0.0.0 if bound to that IP
address. We now use ast_find_ourip to get a better IP address, and
properly marshal the result into an ast_strdupa'd string.
(b) Reports can be generated with no report bodies. In particular, this
occurs when a sender is transmitting information to a receiver (who
will send no RTP back to the sender). As such, the sender has no report
body for what it received. We now properly handle this case, and the
sender will emit SR reports with no body. Likewise, if we receive an
RTCP packet with no report body, we will still generate the appropriate
events.
ASTERISK-24119 #close
........
Merged revisions 419823 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419825 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-31 11:57:51 +00:00
ast_rtp_instance_get_local_address ( instance , & local_address ) ;
2009-04-02 17:20:52 +00:00
while ( position < packetwords ) {
int i , pt , rc ;
2013-07-05 17:33:33 +00:00
unsigned int length ;
2013-09-21 04:49:26 +00:00
struct ast_json * message_blob ;
RAII_VAR ( struct ast_rtp_rtcp_report * , rtcp_report , NULL , ao2_cleanup ) ;
2009-04-02 17:20:52 +00:00
i = position ;
length = ntohl ( rtcpheader [ i ] ) ;
pt = ( length & 0xff0000 ) > > 16 ;
rc = ( length & 0x1f000000 ) > > 24 ;
length & = 0xffff ;
2013-07-05 17:33:33 +00:00
rtcp_report = ast_rtp_rtcp_report_alloc ( rc ) ;
if ( ! rtcp_report ) {
return & ast_null_frame ;
}
rtcp_report - > reception_report_count = rc ;
rtcp_report - > ssrc = ntohl ( rtcpheader [ i + 1 ] ) ;
2009-04-02 17:20:52 +00:00
if ( ( i + length ) > packetwords ) {
2012-12-03 09:35:55 +00:00
if ( rtpdebug ) {
2011-02-04 16:55:39 +00:00
ast_debug ( 1 , " RTCP Read too short \n " ) ;
2012-12-03 09:35:55 +00:00
}
2009-04-02 17:20:52 +00:00
return & ast_null_frame ;
}
2010-07-08 22:08:07 +00:00
if ( rtcp_debug_test_addr ( & addr ) ) {
ast_verbose ( " \n \n Got RTCP from %s \n " ,
ast_sockaddr_stringify ( & addr ) ) ;
2013-07-05 17:33:33 +00:00
ast_verbose ( " PT: %d(%s) \n " , pt , ( pt = = RTCP_PT_SR ) ? " Sender Report " :
( pt = = RTCP_PT_RR ) ? " Receiver Report " :
( pt = = RTCP_PT_FUR ) ? " H.261 FUR " : " Unknown " ) ;
2009-04-02 17:20:52 +00:00
ast_verbose ( " Reception reports: %d \n " , rc ) ;
2013-07-05 17:33:33 +00:00
ast_verbose ( " SSRC of sender: %u \n " , rtcp_report - > ssrc ) ;
2009-04-02 17:20:52 +00:00
}
i + = 2 ; /* Advance past header and ssrc */
switch ( pt ) {
case RTCP_PT_SR :
2013-07-05 17:33:33 +00:00
gettimeofday ( & rtp - > rtcp - > rxlsr , NULL ) ;
rtp - > rtcp - > themrxlsr = ( ( ntohl ( rtcpheader [ i ] ) & 0x0000ffff ) < < 16 ) | ( ( ntohl ( rtcpheader [ i + 1 ] ) & 0xffff0000 ) > > 16 ) ;
rtp - > rtcp - > spc = ntohl ( rtcpheader [ i + 3 ] ) ;
2009-04-02 17:20:52 +00:00
rtp - > rtcp - > soc = ntohl ( rtcpheader [ i + 4 ] ) ;
2013-07-05 17:33:33 +00:00
rtcp_report - > type = RTCP_PT_SR ;
rtcp_report - > sender_information . packet_count = rtp - > rtcp - > spc ;
rtcp_report - > sender_information . octet_count = rtp - > rtcp - > soc ;
ntp2timeval ( ( unsigned int ) ntohl ( rtcpheader [ i ] ) ,
( unsigned int ) ntohl ( rtcpheader [ i + 1 ] ) ,
& rtcp_report - > sender_information . ntp_timestamp ) ;
rtcp_report - > sender_information . rtp_timestamp = ntohl ( rtcpheader [ i + 2 ] ) ;
2010-07-08 22:08:07 +00:00
if ( rtcp_debug_test_addr ( & addr ) ) {
2013-07-05 17:33:33 +00:00
ast_verbose ( " NTP timestamp: %u.%010u \n " ,
( unsigned int ) rtcp_report - > sender_information . ntp_timestamp . tv_sec ,
( unsigned int ) rtcp_report - > sender_information . ntp_timestamp . tv_usec * 4096 ) ;
ast_verbose ( " RTP timestamp: %u \n " , rtcp_report - > sender_information . rtp_timestamp ) ;
ast_verbose ( " SPC: %u \t SOC: %u \n " ,
rtcp_report - > sender_information . packet_count ,
rtcp_report - > sender_information . octet_count ) ;
2009-04-02 17:20:52 +00:00
}
i + = 5 ;
/* Intentional fall through */
case RTCP_PT_RR :
2013-07-05 17:33:33 +00:00
if ( rtcp_report - > type ! = RTCP_PT_SR ) {
rtcp_report - > type = RTCP_PT_RR ;
2012-12-03 09:35:55 +00:00
}
2009-04-02 17:20:52 +00:00
res_hep_rtcp: Add module that sends RTCP information to a Homer Server
This patch adds a new module to Asterisk, res_hep_rtcp. The module subscribes
to the RTCP topics in Stasis and receives RTCP information back from the
message bus. It encodes into HEPv3 packets and sends the information to the
res_hep module for transmission.
Using this, someone with a Homer server can get live call quality monitoring
for all RTP-based channels in their Asterisk 12+ systems.
In addition, there were a few bugs in the RTP engine, res_rtp_asterisk, and
chan_pjsip that were uncovered by the tests written for the Asterisk Test
Suite. This patch fixes the following:
1) chan_pjsip failed to set its channel unique ids on its RTP instance on
outbound calls. It now does this in the appropriate location, in the
serialized call callback.
2) The rtp_engine was overflowing some values when packed into JSON.
Specifically, some longs and unsigned ints can't be be packed into integer
values, for obvious reasons. Since libjansson only supports integers,
floats, strings, booleans, and objects, we print these values into strings.
3) res_rtp_asterisk had a few problems:
(a) it would emit a source IP address of 0.0.0.0 if bound to that IP
address. We now use ast_find_ourip to get a better IP address, and
properly marshal the result into an ast_strdupa'd string.
(b) Reports can be generated with no report bodies. In particular, this
occurs when a sender is transmitting information to a receiver (who
will send no RTP back to the sender). As such, the sender has no report
body for what it received. We now properly handle this case, and the
sender will emit SR reports with no body. Likewise, if we receive an
RTCP packet with no report body, we will still generate the appropriate
events.
ASTERISK-24119 #close
........
Merged revisions 419823 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419825 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-31 11:57:51 +00:00
if ( rc > 0 ) {
/* Don't handle multiple reception reports (rc > 1) yet */
report_block = ast_calloc ( 1 , sizeof ( * report_block ) ) ;
if ( ! report_block ) {
return & ast_null_frame ;
}
rtcp_report - > report_block [ report_counter ] = report_block ;
report_block - > source_ssrc = ntohl ( rtcpheader [ i ] ) ;
report_block - > lost_count . packets = ntohl ( rtcpheader [ i + 1 ] ) & 0x00ffffff ;
report_block - > lost_count . fraction = ( ( ntohl ( rtcpheader [ i + 1 ] ) & 0xff000000 ) > > 24 ) ;
report_block - > highest_seq_no = ntohl ( rtcpheader [ i + 2 ] ) ;
report_block - > ia_jitter = ntohl ( rtcpheader [ i + 3 ] ) ;
report_block - > lsr = ntohl ( rtcpheader [ i + 4 ] ) ;
report_block - > dlsr = ntohl ( rtcpheader [ i + 5 ] ) ;
if ( report_block - > lsr
& & update_rtt_stats ( rtp , report_block - > lsr , report_block - > dlsr )
& & rtcp_debug_test_addr ( & addr ) ) {
struct timeval now ;
unsigned int lsr_now , lsw , msw ;
gettimeofday ( & now , NULL ) ;
timeval2ntp ( now , & msw , & lsw ) ;
lsr_now = ( ( ( msw & 0xffff ) < < 16 ) | ( ( lsw & 0xffff0000 ) > > 16 ) ) ;
ast_verbose ( " Internal RTCP NTP clock skew detected: "
" lsr=%u, now=%u, dlsr=%u (%u:%03ums), "
" diff=%u \n " ,
report_block - > lsr , lsr_now , report_block - > dlsr , report_block - > dlsr / 65536 ,
( report_block - > dlsr % 65536 ) * 1000 / 65536 ,
report_block - > dlsr - ( lsr_now - report_block - > lsr ) ) ;
}
update_jitter_stats ( rtp , report_block - > ia_jitter ) ;
update_lost_stats ( rtp , report_block - > lost_count . packets ) ;
rtp - > rtcp - > reported_jitter_count + + ;
if ( rtcp_debug_test_addr ( & addr ) ) {
ast_verbose ( " Fraction lost: %d \n " , report_block - > lost_count . fraction ) ;
ast_verbose ( " Packets lost so far: %u \n " , report_block - > lost_count . packets ) ;
ast_verbose ( " Highest sequence number: %u \n " , report_block - > highest_seq_no & 0x0000ffff ) ;
ast_verbose ( " Sequence number cycles: %u \n " , report_block - > highest_seq_no > > 16 ) ;
ast_verbose ( " Interarrival jitter: %u \n " , report_block - > ia_jitter ) ;
ast_verbose ( " Last SR(our NTP): %lu.%010lu \n " , ( unsigned long ) ( report_block - > lsr ) > > 16 , ( ( unsigned long ) ( report_block - > lsr ) < < 16 ) * 4096 ) ;
ast_verbose ( " DLSR: %4.4f (sec) \n " , ( double ) report_block - > dlsr / 65536.0 ) ;
ast_verbose ( " RTT: %4.4f(sec) \n " , rtp - > rtcp - > rtt ) ;
}
report_counter + + ;
2012-12-03 09:35:55 +00:00
}
res_hep_rtcp: Add module that sends RTCP information to a Homer Server
This patch adds a new module to Asterisk, res_hep_rtcp. The module subscribes
to the RTCP topics in Stasis and receives RTCP information back from the
message bus. It encodes into HEPv3 packets and sends the information to the
res_hep module for transmission.
Using this, someone with a Homer server can get live call quality monitoring
for all RTP-based channels in their Asterisk 12+ systems.
In addition, there were a few bugs in the RTP engine, res_rtp_asterisk, and
chan_pjsip that were uncovered by the tests written for the Asterisk Test
Suite. This patch fixes the following:
1) chan_pjsip failed to set its channel unique ids on its RTP instance on
outbound calls. It now does this in the appropriate location, in the
serialized call callback.
2) The rtp_engine was overflowing some values when packed into JSON.
Specifically, some longs and unsigned ints can't be be packed into integer
values, for obvious reasons. Since libjansson only supports integers,
floats, strings, booleans, and objects, we print these values into strings.
3) res_rtp_asterisk had a few problems:
(a) it would emit a source IP address of 0.0.0.0 if bound to that IP
address. We now use ast_find_ourip to get a better IP address, and
properly marshal the result into an ast_strdupa'd string.
(b) Reports can be generated with no report bodies. In particular, this
occurs when a sender is transmitting information to a receiver (who
will send no RTP back to the sender). As such, the sender has no report
body for what it received. We now properly handle this case, and the
sender will emit SR reports with no body. Likewise, if we receive an
RTCP packet with no report body, we will still generate the appropriate
events.
ASTERISK-24119 #close
........
Merged revisions 419823 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419825 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-31 11:57:51 +00:00
/* If and when we handle more than one report block, this should occur outside
* this loop .
*/
if ( ! ast_find_ourip ( & real_local_address , & local_address , 0 ) ) {
str_local_address = ast_strdupa ( ast_sockaddr_stringify ( & real_local_address ) ) ;
} else {
str_local_address = ast_strdupa ( ast_sockaddr_stringify ( & local_address ) ) ;
2012-12-03 09:35:55 +00:00
}
2009-04-02 17:20:52 +00:00
res_hep_rtcp: Add module that sends RTCP information to a Homer Server
This patch adds a new module to Asterisk, res_hep_rtcp. The module subscribes
to the RTCP topics in Stasis and receives RTCP information back from the
message bus. It encodes into HEPv3 packets and sends the information to the
res_hep module for transmission.
Using this, someone with a Homer server can get live call quality monitoring
for all RTP-based channels in their Asterisk 12+ systems.
In addition, there were a few bugs in the RTP engine, res_rtp_asterisk, and
chan_pjsip that were uncovered by the tests written for the Asterisk Test
Suite. This patch fixes the following:
1) chan_pjsip failed to set its channel unique ids on its RTP instance on
outbound calls. It now does this in the appropriate location, in the
serialized call callback.
2) The rtp_engine was overflowing some values when packed into JSON.
Specifically, some longs and unsigned ints can't be be packed into integer
values, for obvious reasons. Since libjansson only supports integers,
floats, strings, booleans, and objects, we print these values into strings.
3) res_rtp_asterisk had a few problems:
(a) it would emit a source IP address of 0.0.0.0 if bound to that IP
address. We now use ast_find_ourip to get a better IP address, and
properly marshal the result into an ast_strdupa'd string.
(b) Reports can be generated with no report bodies. In particular, this
occurs when a sender is transmitting information to a receiver (who
will send no RTP back to the sender). As such, the sender has no report
body for what it received. We now properly handle this case, and the
sender will emit SR reports with no body. Likewise, if we receive an
RTCP packet with no report body, we will still generate the appropriate
events.
ASTERISK-24119 #close
........
Merged revisions 419823 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419825 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-31 11:57:51 +00:00
if ( ! ast_find_ourip ( & real_remote_address , & addr , 0 ) ) {
str_remote_address = ast_strdupa ( ast_sockaddr_stringify ( & real_remote_address ) ) ;
} else {
str_remote_address = ast_strdupa ( ast_sockaddr_stringify ( & addr ) ) ;
2009-04-02 17:20:52 +00:00
}
2013-07-05 17:33:33 +00:00
res_hep_rtcp: Add module that sends RTCP information to a Homer Server
This patch adds a new module to Asterisk, res_hep_rtcp. The module subscribes
to the RTCP topics in Stasis and receives RTCP information back from the
message bus. It encodes into HEPv3 packets and sends the information to the
res_hep module for transmission.
Using this, someone with a Homer server can get live call quality monitoring
for all RTP-based channels in their Asterisk 12+ systems.
In addition, there were a few bugs in the RTP engine, res_rtp_asterisk, and
chan_pjsip that were uncovered by the tests written for the Asterisk Test
Suite. This patch fixes the following:
1) chan_pjsip failed to set its channel unique ids on its RTP instance on
outbound calls. It now does this in the appropriate location, in the
serialized call callback.
2) The rtp_engine was overflowing some values when packed into JSON.
Specifically, some longs and unsigned ints can't be be packed into integer
values, for obvious reasons. Since libjansson only supports integers,
floats, strings, booleans, and objects, we print these values into strings.
3) res_rtp_asterisk had a few problems:
(a) it would emit a source IP address of 0.0.0.0 if bound to that IP
address. We now use ast_find_ourip to get a better IP address, and
properly marshal the result into an ast_strdupa'd string.
(b) Reports can be generated with no report bodies. In particular, this
occurs when a sender is transmitting information to a receiver (who
will send no RTP back to the sender). As such, the sender has no report
body for what it received. We now properly handle this case, and the
sender will emit SR reports with no body. Likewise, if we receive an
RTCP packet with no report body, we will still generate the appropriate
events.
ASTERISK-24119 #close
........
Merged revisions 419823 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419825 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-31 11:57:51 +00:00
message_blob = ast_json_pack ( " {s: s, s: s, s: f} " ,
" from " , str_remote_address ,
" to " , str_local_address ,
2013-07-05 17:33:33 +00:00
" rtt " , rtp - > rtcp - > rtt ) ;
ast_rtp_publish_rtcp_message ( instance , ast_rtp_rtcp_received_type ( ) ,
rtcp_report ,
message_blob ) ;
2013-09-21 04:49:26 +00:00
ast_json_unref ( message_blob ) ;
2009-04-02 17:20:52 +00:00
break ;
case RTCP_PT_FUR :
2013-08-23 15:42:27 +00:00
/* Handle RTCP FIR as FUR */
case RTCP_PT_PSFB :
2012-12-03 09:35:55 +00:00
if ( rtcp_debug_test_addr ( & addr ) ) {
2009-04-02 17:20:52 +00:00
ast_verbose ( " Received an RTCP Fast Update Request \n " ) ;
2012-12-03 09:35:55 +00:00
}
2009-04-02 17:20:52 +00:00
rtp - > f . frametype = AST_FRAME_CONTROL ;
2009-11-04 14:05:12 +00:00
rtp - > f . subclass . integer = AST_CONTROL_VIDUPDATE ;
2009-04-02 17:20:52 +00:00
rtp - > f . datalen = 0 ;
rtp - > f . samples = 0 ;
rtp - > f . mallocd = 0 ;
rtp - > f . src = " RTP " ;
f = & rtp - > f ;
break ;
case RTCP_PT_SDES :
2012-12-03 09:35:55 +00:00
if ( rtcp_debug_test_addr ( & addr ) ) {
2010-07-08 22:08:07 +00:00
ast_verbose ( " Received an SDES from %s \n " ,
ast_sockaddr_stringify ( & rtp - > rtcp - > them ) ) ;
2012-12-03 09:35:55 +00:00
}
2009-04-02 17:20:52 +00:00
break ;
case RTCP_PT_BYE :
2012-12-03 09:35:55 +00:00
if ( rtcp_debug_test_addr ( & addr ) ) {
2010-07-08 22:08:07 +00:00
ast_verbose ( " Received a BYE from %s \n " ,
ast_sockaddr_stringify ( & rtp - > rtcp - > them ) ) ;
2012-12-03 09:35:55 +00:00
}
2009-04-02 17:20:52 +00:00
break ;
default :
2010-07-08 22:08:07 +00:00
ast_debug ( 1 , " Unknown RTCP packet (pt=%d) received from %s \n " ,
pt , ast_sockaddr_stringify ( & rtp - > rtcp - > them ) ) ;
2009-04-02 17:20:52 +00:00
break ;
}
position + = ( length + 1 ) ;
}
rtp - > rtcp - > rtcp_info = 1 ;
return f ;
}
static int bridge_p2p_rtp_write ( struct ast_rtp_instance * instance , unsigned int * rtpheader , int len , int hdrlen )
{
struct ast_rtp_instance * instance1 = ast_rtp_instance_get_bridged ( instance ) ;
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) , * bridged = ast_rtp_instance_get_data ( instance1 ) ;
int res = 0 , payload = 0 , bridged_payload = 0 , mark ;
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
RAII_VAR ( struct ast_rtp_payload_type * , payload_type , NULL , ao2_cleanup ) ;
2009-04-02 17:20:52 +00:00
int reconstruct = ntohl ( rtpheader [ 0 ] ) ;
2010-07-08 22:08:07 +00:00
struct ast_sockaddr remote_address = { { 0 , } } ;
2012-07-01 17:28:57 +00:00
int ice ;
2009-04-02 17:20:52 +00:00
/* Get fields from packet */
payload = ( reconstruct & 0x7f0000 ) > > 16 ;
mark = ( ( ( reconstruct & 0x800000 ) > > 23 ) ! = 0 ) ;
/* Check what the payload value should be */
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
payload_type = ast_rtp_codecs_get_payload ( ast_rtp_instance_get_codecs ( instance ) , payload ) ;
if ( ! payload_type ) {
return - 1 ;
}
2009-04-02 17:20:52 +00:00
/* Otherwise adjust bridged payload to match */
2015-07-24 00:24:04 +00:00
bridged_payload = ast_rtp_codecs_payload_code_tx ( ast_rtp_instance_get_codecs ( instance1 ) ,
payload_type - > asterisk_format , payload_type - > format , payload_type - > rtp_code ) ;
2009-04-02 17:20:52 +00:00
2012-04-17 21:14:49 +00:00
/* If no codec could be matched between instance and instance1, then somehow things were made incompatible while we were still bridged. Bail. */
if ( bridged_payload < 0 ) {
return - 1 ;
}
2009-04-02 17:20:52 +00:00
/* If the payload coming in is not one of the negotiated ones then send it to the core, this will cause formats to change and the bridge to break */
2012-09-05 17:38:22 +00:00
if ( ast_rtp_codecs_find_payload_code ( ast_rtp_instance_get_codecs ( instance1 ) , bridged_payload ) = = - 1 ) {
2012-09-05 16:24:19 +00:00
ast_debug ( 1 , " Unsupported payload type received \n " ) ;
2009-04-02 17:20:52 +00:00
return - 1 ;
}
/* If the marker bit has been explicitly set turn it on */
if ( ast_test_flag ( rtp , FLAG_NEED_MARKER_BIT ) ) {
mark = 1 ;
ast_clear_flag ( rtp , FLAG_NEED_MARKER_BIT ) ;
}
/* Reconstruct part of the packet */
reconstruct & = 0xFF80FFFF ;
reconstruct | = ( bridged_payload < < 16 ) ;
reconstruct | = ( mark < < 23 ) ;
rtpheader [ 0 ] = htonl ( reconstruct ) ;
ast_rtp_instance_get_remote_address ( instance1 , & remote_address ) ;
2010-10-06 04:47:57 +00:00
if ( ast_sockaddr_isnull ( & remote_address ) ) {
2014-12-18 22:40:16 +00:00
ast_debug ( 5 , " Remote address is null, most likely RTP has been stopped \n " ) ;
2010-10-06 04:47:57 +00:00
return 0 ;
}
2009-04-02 17:20:52 +00:00
/* Send the packet back out */
2012-07-01 17:28:57 +00:00
res = rtp_sendto ( instance1 , ( void * ) rtpheader , len , 0 , & remote_address , & ice ) ;
2009-04-02 17:20:52 +00:00
if ( res < 0 ) {
if ( ! ast_rtp_instance_get_prop ( instance1 , AST_RTP_PROPERTY_NAT ) | | ( ast_rtp_instance_get_prop ( instance1 , AST_RTP_PROPERTY_NAT ) & & ( ast_test_flag ( bridged , FLAG_NAT_ACTIVE ) = = FLAG_NAT_ACTIVE ) ) ) {
2010-07-08 22:08:07 +00:00
ast_log ( LOG_WARNING ,
" RTP Transmission error of packet to %s: %s \n " ,
ast_sockaddr_stringify ( & remote_address ) ,
strerror ( errno ) ) ;
2009-04-02 17:20:52 +00:00
} else if ( ( ( ast_test_flag ( bridged , FLAG_NAT_ACTIVE ) = = FLAG_NAT_INACTIVE ) | | rtpdebug ) & & ! ast_test_flag ( bridged , FLAG_NAT_INACTIVE_NOWARN ) ) {
2012-12-03 09:35:55 +00:00
if ( option_debug | | rtpdebug ) {
2010-07-08 22:08:07 +00:00
ast_log ( LOG_WARNING ,
" RTP NAT: Can't write RTP to private "
" address %s, waiting for other end to "
" send audio... \n " ,
ast_sockaddr_stringify ( & remote_address ) ) ;
2012-12-03 09:35:55 +00:00
}
2009-04-02 17:20:52 +00:00
ast_set_flag ( bridged , FLAG_NAT_INACTIVE_NOWARN ) ;
}
return 0 ;
2012-07-01 17:28:57 +00:00
}
if ( rtp_debug_test_addr ( & remote_address ) ) {
2014-05-09 22:49:26 +00:00
ast_verbose ( " Sent RTP P2P packet to %s%s (type %-2.2d, len %-6.6d) \n " ,
2010-07-08 22:08:07 +00:00
ast_sockaddr_stringify ( & remote_address ) ,
2012-07-01 17:28:57 +00:00
ice ? " (via ICE) " : " " ,
2010-07-08 22:08:07 +00:00
bridged_payload , len - hdrlen ) ;
2009-04-02 17:20:52 +00:00
}
return 0 ;
}
static struct ast_frame * ast_rtp_read ( struct ast_rtp_instance * instance , int rtcp )
{
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
2010-07-08 22:08:07 +00:00
struct ast_sockaddr addr ;
2009-04-02 17:20:52 +00:00
int res , hdrlen = 12 , version , payloadtype , padding , mark , ext , cc , prev_seqno ;
unsigned int * rtpheader = ( unsigned int * ) ( rtp - > rawdata + AST_FRIENDLY_OFFSET ) , seqno , ssrc , timestamp ;
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
RAII_VAR ( struct ast_rtp_payload_type * , payload , NULL , ao2_cleanup ) ;
2010-07-08 22:08:07 +00:00
struct ast_sockaddr remote_address = { { 0 , } } ;
Recorded merge of revisions 254452 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r254452 | mmichelson | 2010-03-25 10:59:56 -0500 (Thu, 25 Mar 2010) | 44 lines
Several fixes regarding RFC2833 DTMF detection.
Here is a copy and paste of the details from my request on
reviewboard that dealt with these changes:
Fix 1. The first change in place is to fix Mantis issue 15811, which deals with a situation where Asterisk will incorrectly interpret out of order RFC2833 frames as duplicate DTMF digits. For instance, we would receive a sequence like:
seqno 1: DTMF 1
seqno 2: DTMF 1
seqno 3: DTMF 1
seqno 4: DTMF 1
seqno 6: DTMF 1 (end)
seqno 5: DTMF 1
seqno 7: DTMF 1 (end)
seqno 8: DTMF 1 (end)
Prior to this patch when we received the frame with seqno 5, we would interpret this as a new DTMF 1. With this patch, we will check the seqno of the incoming digit and not process the frame if the seqno is lower than the last recorded seqno. Note that we do not record the seqno of the dropped DTMF frame for future processing. While the above situation is what was designed to be fixed, the patch is written in such a way that the following would also be fixed too:
seqno 9: DTMF 1
seqno 10: DTMF 1 (end)
seqno 11: DTMF 1 (end)
seqno 13: DTMF 2
seqno 12: DTMF 1 (end)
seqno 14: DTMF 2
seqno 15: DTMF 2 (end)
seqno 16: DTMF 2 (end)
seqno 17: DTMF 2 (end)
In this second situation, the beginning of the DTMF 2 arrives before the final end frame of the DTMF 1. With the patch, seqno 12 is no processed and thus we properly interpret the DTMF.
Fix 2. The second change in place is to fix an issue like the following:
seqno 1: DTMF 1
seqno 2: DTMF 1
seqno 3: DTMF 1 (end) *packet lost*
seqno 4: DTMF 1 (end) *packet lost*
seqno 5: DTMF 1 (end) *packet lost*
seqno 6: DTMF 2
When we receive seqno 6, we had code in place that was supposed to properly end the previously unended DTMF 1. The problem was that the code was essentially a no-op. The code would set up an end frame for the DTMF 1 but would immediately overwrite the frame with the begin for DTMF 2. I changed process_dtmf_rfc2833() so that instead of returning a single frame, it is given as an output parameter a list of frames. Each frame that needs to be returned is appended to this list.
Fix 3. The final change is a minor one where an AST_CONTROL_SRCCHANGE frame could get lost. If we process a cisco DTMF or an RFC 3389 frame and no frame was returned, then we would return &ast_null_frame. The problem is that earlier in the function, we may have generated an AST_CONTROL_SRCCHANGE frame and put it in the list of frames we wish to return. This frame would be lost in such a case. The patch fixes this problem
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@254454 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2010-03-25 16:04:48 +00:00
struct frame_list frames ;
2009-04-02 17:20:52 +00:00
/* If this is actually RTCP let's hop on over and handle it */
if ( rtcp ) {
if ( rtp - > rtcp ) {
return ast_rtcp_read ( instance ) ;
}
return & ast_null_frame ;
}
/* If we are currently sending DTMF to the remote party send a continuation packet */
if ( rtp - > sending_digit ) {
ast_rtp_dtmf_continuation ( instance ) ;
}
/* Actually read in the data from the socket */
2010-07-08 22:08:07 +00:00
if ( ( res = rtp_recvfrom ( instance , rtp - > rawdata + AST_FRIENDLY_OFFSET ,
sizeof ( rtp - > rawdata ) - AST_FRIENDLY_OFFSET , 0 ,
& addr ) ) < 0 ) {
2009-04-02 17:20:52 +00:00
ast_assert ( errno ! = EBADF ) ;
if ( errno ! = EAGAIN ) {
2012-09-05 17:38:22 +00:00
ast_log ( LOG_WARNING , " RTP Read error: %s. Hanging up. \n " ,
( errno ) ? strerror ( errno ) : " Unspecified " ) ;
2009-04-02 17:20:52 +00:00
return NULL ;
}
return & ast_null_frame ;
}
2012-07-01 17:28:57 +00:00
/* If this was handled by the ICE session don't do anything */
if ( ! res ) {
return & ast_null_frame ;
}
2009-04-02 17:20:52 +00:00
/* Make sure the data that was read in is actually enough to make up an RTP packet */
if ( res < hdrlen ) {
2012-10-17 14:24:52 +00:00
/* If this is a keepalive containing only nulls, don't bother with a warning */
int i ;
for ( i = 0 ; i < res ; + + i ) {
if ( rtp - > rawdata [ AST_FRIENDLY_OFFSET + i ] ! = ' \0 ' ) {
ast_log ( LOG_WARNING , " RTP Read too short \n " ) ;
return & ast_null_frame ;
}
}
2009-04-02 17:20:52 +00:00
return & ast_null_frame ;
}
2012-07-09 16:44:24 +00:00
/* Get fields and verify this is an RTP packet */
seqno = ntohl ( rtpheader [ 0 ] ) ;
ast_rtp_instance_get_remote_address ( instance , & remote_address ) ;
if ( ! ( version = ( seqno & 0xC0000000 ) > > 30 ) ) {
struct sockaddr_in addr_tmp ;
struct ast_sockaddr addr_v4 ;
if ( ast_sockaddr_is_ipv4 ( & addr ) ) {
ast_sockaddr_to_sin ( & addr , & addr_tmp ) ;
} else if ( ast_sockaddr_ipv4_mapped ( & addr , & addr_v4 ) ) {
ast_debug ( 1 , " Using IPv6 mapped address %s for STUN \n " ,
ast_sockaddr_stringify ( & addr ) ) ;
ast_sockaddr_to_sin ( & addr_v4 , & addr_tmp ) ;
} else {
ast_debug ( 1 , " Cannot do STUN for non IPv4 address %s \n " ,
ast_sockaddr_stringify ( & addr ) ) ;
return & ast_null_frame ;
}
if ( ( ast_stun_handle_packet ( rtp - > s , & addr_tmp , rtp - > rawdata + AST_FRIENDLY_OFFSET , res , NULL , NULL ) = = AST_STUN_ACCEPT ) & &
ast_sockaddr_isnull ( & remote_address ) ) {
ast_sockaddr_from_sin ( & addr , & addr_tmp ) ;
ast_rtp_instance_set_remote_address ( instance , & addr ) ;
}
return & ast_null_frame ;
}
2009-04-02 17:20:52 +00:00
/* If strict RTP protection is enabled see if we need to learn the remote address or if we need to drop the packet */
if ( rtp - > strict_rtp_state = = STRICT_RTP_LEARN ) {
2013-03-07 15:48:06 +00:00
ast_debug ( 1 , " %p -- Probation learning mode pass with source address %s \n " , rtp , ast_sockaddr_stringify ( & addr ) ) ;
2012-01-17 17:15:05 +00:00
/* For now, we always copy the address. */
2010-07-08 22:08:07 +00:00
ast_sockaddr_copy ( & rtp - > strict_rtp_address , & addr ) ;
2012-01-17 17:15:05 +00:00
/* Send the rtp and the seqno from header to rtp_learning_rtp_seq_update to see whether we can exit or not*/
2013-03-07 15:48:06 +00:00
if ( rtp_learning_rtp_seq_update ( & rtp - > rtp_source_learn , seqno ) ) {
ast_debug ( 1 , " %p -- Probation at seq %d with %d to go; discarding frame \n " ,
rtp , rtp - > rtp_source_learn . max_seq , rtp - > rtp_source_learn . packets ) ;
2012-01-17 17:15:05 +00:00
return & ast_null_frame ;
}
2013-03-07 15:48:06 +00:00
ast_verb ( 4 , " %p -- Probation passed - setting RTP source address to %s \n " , rtp , ast_sockaddr_stringify ( & addr ) ) ;
2009-04-02 17:20:52 +00:00
rtp - > strict_rtp_state = STRICT_RTP_CLOSED ;
2013-03-07 15:48:06 +00:00
}
if ( rtp - > strict_rtp_state = = STRICT_RTP_CLOSED ) {
if ( ! ast_sockaddr_cmp ( & rtp - > strict_rtp_address , & addr ) ) {
/* Always reset the alternate learning source */
rtp_learning_seq_init ( & rtp - > alt_source_learn , seqno ) ;
} else {
/* Start trying to learn from the new address. If we pass a probationary period with
* it , that means we ' ve stopped getting RTP from the original source and we should
* switch to it .
*/
if ( rtp_learning_rtp_seq_update ( & rtp - > alt_source_learn , seqno ) ) {
ast_debug ( 1 , " %p -- Received RTP packet from %s, dropping due to strict RTP protection. Will switch to it in %d packets \n " ,
rtp , ast_sockaddr_stringify ( & addr ) , rtp - > alt_source_learn . packets ) ;
2009-06-18 15:20:17 +00:00
return & ast_null_frame ;
}
2013-03-07 15:48:06 +00:00
ast_verb ( 4 , " %p -- Switching RTP source address to %s \n " , rtp , ast_sockaddr_stringify ( & addr ) ) ;
ast_sockaddr_copy ( & rtp - > strict_rtp_address , & addr ) ;
2009-04-02 17:20:52 +00:00
}
}
/* If symmetric RTP is enabled see if the remote side is not what we expected and change where we are sending audio */
if ( ast_rtp_instance_get_prop ( instance , AST_RTP_PROPERTY_NAT ) ) {
2010-07-08 22:08:07 +00:00
if ( ast_sockaddr_cmp ( & remote_address , & addr ) ) {
2014-12-09 20:03:22 +00:00
/* do not update the originally given address, but only the remote */
ast_rtp_instance_set_incoming_source_address ( instance , & addr ) ;
2010-07-08 22:08:07 +00:00
ast_sockaddr_copy ( & remote_address , & addr ) ;
2009-04-02 17:20:52 +00:00
if ( rtp - > rtcp ) {
2010-07-08 22:08:07 +00:00
ast_sockaddr_copy ( & rtp - > rtcp - > them , & addr ) ;
ast_sockaddr_set_port ( & rtp - > rtcp - > them , ast_sockaddr_port ( & addr ) + 1 ) ;
2009-04-02 17:20:52 +00:00
}
rtp - > rxseqno = 0 ;
ast_set_flag ( rtp , FLAG_NAT_ACTIVE ) ;
2011-02-04 16:55:39 +00:00
if ( rtpdebug )
2010-07-08 22:08:07 +00:00
ast_debug ( 0 , " RTP NAT: Got audio from other end. Now sending to address %s \n " ,
ast_sockaddr_stringify ( & remote_address ) ) ;
2009-04-02 17:20:52 +00:00
}
}
/* If we are directly bridged to another instance send the audio directly out */
if ( ast_rtp_instance_get_bridged ( instance ) & & ! bridge_p2p_rtp_write ( instance , rtpheader , res , hdrlen ) ) {
return & ast_null_frame ;
}
/* If the version is not what we expected by this point then just drop the packet */
if ( version ! = 2 ) {
return & ast_null_frame ;
}
/* Pull out the various other fields we will need */
payloadtype = ( seqno & 0x7f0000 ) > > 16 ;
padding = seqno & ( 1 < < 29 ) ;
mark = seqno & ( 1 < < 23 ) ;
ext = seqno & ( 1 < < 28 ) ;
cc = ( seqno & 0xF000000 ) > > 24 ;
seqno & = 0xffff ;
timestamp = ntohl ( rtpheader [ 1 ] ) ;
ssrc = ntohl ( rtpheader [ 2 ] ) ;
2010-03-12 22:04:51 +00:00
AST_LIST_HEAD_INIT_NOLOCK ( & frames ) ;
/* Force a marker bit and change SSRC if the SSRC changes */
if ( rtp - > rxssrc & & rtp - > rxssrc ! = ssrc ) {
struct ast_frame * f , srcupdate = {
AST_FRAME_CONTROL ,
. subclass . integer = AST_CONTROL_SRCCHANGE ,
} ;
if ( ! mark ) {
2011-02-04 16:55:39 +00:00
if ( rtpdebug ) {
2010-03-12 22:04:51 +00:00
ast_debug ( 1 , " Forcing Marker bit, because SSRC has changed \n " ) ;
}
mark = 1 ;
2009-04-02 17:20:52 +00:00
}
2010-03-12 22:04:51 +00:00
f = ast_frisolate ( & srcupdate ) ;
AST_LIST_INSERT_TAIL ( & frames , f , frame_list ) ;
2013-01-13 22:07:00 +00:00
2013-09-28 22:32:18 +00:00
rtp - > seedrxseqno = 0 ;
rtp - > rxcount = 0 ;
rtp - > cycles = 0 ;
rtp - > lastrxseqno = 0 ;
2013-01-13 22:07:00 +00:00
rtp - > last_seqno = 0 ;
rtp - > last_end_timestamp = 0 ;
2013-10-22 23:10:22 +00:00
if ( rtp - > rtcp ) {
rtp - > rtcp - > expected_prior = 0 ;
rtp - > rtcp - > received_prior = 0 ;
}
2009-04-02 17:20:52 +00:00
}
2010-03-12 22:04:51 +00:00
rtp - > rxssrc = ssrc ;
2009-04-02 17:20:52 +00:00
/* Remove any padding bytes that may be present */
if ( padding ) {
res - = rtp - > rawdata [ AST_FRIENDLY_OFFSET + res - 1 ] ;
}
/* Skip over any CSRC fields */
if ( cc ) {
hdrlen + = cc * 4 ;
}
/* Look for any RTP extensions, currently we do not support any */
if ( ext ) {
hdrlen + = ( ntohl ( rtpheader [ hdrlen / 4 ] ) & 0xffff ) < < 2 ;
hdrlen + = 4 ;
if ( option_debug ) {
2014-05-09 22:49:26 +00:00
unsigned int profile ;
2009-04-02 17:20:52 +00:00
profile = ( ntohl ( rtpheader [ 3 ] ) & 0xffff0000 ) > > 16 ;
if ( profile = = 0x505a )
ast_debug ( 1 , " Found Zfone extension in RTP stream - zrtp - not supported. \n " ) ;
else
ast_debug ( 1 , " Found unknown RTP Extensions %x \n " , profile ) ;
}
}
/* Make sure after we potentially mucked with the header length that it is once again valid */
if ( res < hdrlen ) {
ast_log ( LOG_WARNING , " RTP Read too short (%d, expecting %d \n " , res , hdrlen ) ;
2010-03-12 22:04:51 +00:00
return AST_LIST_FIRST ( & frames ) ? AST_LIST_FIRST ( & frames ) : & ast_null_frame ;
2009-04-02 17:20:52 +00:00
}
rtp - > rxcount + + ;
if ( rtp - > rxcount = = 1 ) {
rtp - > seedrxseqno = seqno ;
}
/* Do not schedule RR if RTCP isn't run */
2015-10-06 02:34:41 +00:00
if ( rtp - > rtcp & & ! ast_sockaddr_isnull ( & rtp - > rtcp - > them ) & & rtp - > rtcp - > schedid < 0 ) {
2009-04-02 17:20:52 +00:00
/* Schedule transmission of Receiver Report */
2011-09-20 01:11:18 +00:00
ao2_ref ( instance , + 1 ) ;
2010-06-08 05:29:08 +00:00
rtp - > rtcp - > schedid = ast_sched_add ( rtp - > sched , ast_rtcp_calc_interval ( rtp ) , ast_rtcp_write , instance ) ;
2011-09-20 01:11:18 +00:00
if ( rtp - > rtcp - > schedid < 0 ) {
ao2_ref ( instance , - 1 ) ;
ast_log ( LOG_WARNING , " scheduling RTCP transmission failed. \n " ) ;
}
2009-04-02 17:20:52 +00:00
}
if ( ( int ) rtp - > lastrxseqno - ( int ) seqno > 100 ) /* if so it would indicate that the sender cycled; allow for misordering */
rtp - > cycles + = RTP_SEQ_MOD ;
prev_seqno = rtp - > lastrxseqno ;
rtp - > lastrxseqno = seqno ;
if ( ! rtp - > themssrc ) {
rtp - > themssrc = ntohl ( rtpheader [ 2 ] ) ; /* Record their SSRC to put in future RR */
}
2010-07-08 22:08:07 +00:00
if ( rtp_debug_test_addr ( & addr ) ) {
2014-05-09 22:49:26 +00:00
ast_verbose ( " Got RTP packet from %s (type %-2.2d, seq %-6.6u, ts %-6.6u, len %-6.6d) \n " ,
2010-07-08 22:08:07 +00:00
ast_sockaddr_stringify ( & addr ) ,
payloadtype , seqno , timestamp , res - hdrlen ) ;
2009-04-02 17:20:52 +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
payload = ast_rtp_codecs_get_payload ( ast_rtp_instance_get_codecs ( instance ) , payloadtype ) ;
2015-07-29 22:00:05 +00:00
if ( ! payload ) {
/* Unknown payload type. */
return AST_LIST_FIRST ( & frames ) ? AST_LIST_FIRST ( & frames ) : & ast_null_frame ;
}
2009-04-02 17:20:52 +00:00
/* If the payload is not actually an Asterisk one but a special one pass it off to the respective handler */
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 ( ! payload - > asterisk_format ) {
2009-04-02 17:20:52 +00:00
struct ast_frame * f = 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
if ( payload - > rtp_code = = AST_RTP_DTMF ) {
Recorded merge of revisions 254452 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r254452 | mmichelson | 2010-03-25 10:59:56 -0500 (Thu, 25 Mar 2010) | 44 lines
Several fixes regarding RFC2833 DTMF detection.
Here is a copy and paste of the details from my request on
reviewboard that dealt with these changes:
Fix 1. The first change in place is to fix Mantis issue 15811, which deals with a situation where Asterisk will incorrectly interpret out of order RFC2833 frames as duplicate DTMF digits. For instance, we would receive a sequence like:
seqno 1: DTMF 1
seqno 2: DTMF 1
seqno 3: DTMF 1
seqno 4: DTMF 1
seqno 6: DTMF 1 (end)
seqno 5: DTMF 1
seqno 7: DTMF 1 (end)
seqno 8: DTMF 1 (end)
Prior to this patch when we received the frame with seqno 5, we would interpret this as a new DTMF 1. With this patch, we will check the seqno of the incoming digit and not process the frame if the seqno is lower than the last recorded seqno. Note that we do not record the seqno of the dropped DTMF frame for future processing. While the above situation is what was designed to be fixed, the patch is written in such a way that the following would also be fixed too:
seqno 9: DTMF 1
seqno 10: DTMF 1 (end)
seqno 11: DTMF 1 (end)
seqno 13: DTMF 2
seqno 12: DTMF 1 (end)
seqno 14: DTMF 2
seqno 15: DTMF 2 (end)
seqno 16: DTMF 2 (end)
seqno 17: DTMF 2 (end)
In this second situation, the beginning of the DTMF 2 arrives before the final end frame of the DTMF 1. With the patch, seqno 12 is no processed and thus we properly interpret the DTMF.
Fix 2. The second change in place is to fix an issue like the following:
seqno 1: DTMF 1
seqno 2: DTMF 1
seqno 3: DTMF 1 (end) *packet lost*
seqno 4: DTMF 1 (end) *packet lost*
seqno 5: DTMF 1 (end) *packet lost*
seqno 6: DTMF 2
When we receive seqno 6, we had code in place that was supposed to properly end the previously unended DTMF 1. The problem was that the code was essentially a no-op. The code would set up an end frame for the DTMF 1 but would immediately overwrite the frame with the begin for DTMF 2. I changed process_dtmf_rfc2833() so that instead of returning a single frame, it is given as an output parameter a list of frames. Each frame that needs to be returned is appended to this list.
Fix 3. The final change is a minor one where an AST_CONTROL_SRCCHANGE frame could get lost. If we process a cisco DTMF or an RFC 3389 frame and no frame was returned, then we would return &ast_null_frame. The problem is that earlier in the function, we may have generated an AST_CONTROL_SRCCHANGE frame and put it in the list of frames we wish to return. This frame would be lost in such a case. The patch fixes this problem
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@254454 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2010-03-25 16:04:48 +00:00
/* process_dtmf_rfc2833 may need to return multiple frames. We do this
* by passing the pointer to the frame list to it so that the method
* can append frames to the list as needed .
*/
2010-07-08 22:08:07 +00:00
process_dtmf_rfc2833 ( instance , rtp - > rawdata + AST_FRIENDLY_OFFSET + hdrlen , res - hdrlen , seqno , timestamp , & addr , payloadtype , mark , & frames ) ;
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
} else if ( payload - > rtp_code = = AST_RTP_CISCO_DTMF ) {
2010-07-08 22:08:07 +00:00
f = process_dtmf_cisco ( instance , rtp - > rawdata + AST_FRIENDLY_OFFSET + hdrlen , res - hdrlen , seqno , timestamp , & addr , payloadtype , mark ) ;
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
} else if ( payload - > rtp_code = = AST_RTP_CN ) {
2010-07-08 22:08:07 +00:00
f = process_cn_rfc3389 ( instance , rtp - > rawdata + AST_FRIENDLY_OFFSET + hdrlen , res - hdrlen , seqno , timestamp , & addr , payloadtype , mark ) ;
2009-04-02 17:20:52 +00:00
} else {
2010-07-08 22:08:07 +00:00
ast_log ( LOG_NOTICE , " Unknown RTP codec %d received from '%s' \n " ,
payloadtype ,
ast_sockaddr_stringify ( & remote_address ) ) ;
2009-04-02 17:20:52 +00:00
}
2010-03-12 22:04:51 +00:00
if ( f ) {
AST_LIST_INSERT_TAIL ( & frames , f , frame_list ) ;
Recorded merge of revisions 254452 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r254452 | mmichelson | 2010-03-25 10:59:56 -0500 (Thu, 25 Mar 2010) | 44 lines
Several fixes regarding RFC2833 DTMF detection.
Here is a copy and paste of the details from my request on
reviewboard that dealt with these changes:
Fix 1. The first change in place is to fix Mantis issue 15811, which deals with a situation where Asterisk will incorrectly interpret out of order RFC2833 frames as duplicate DTMF digits. For instance, we would receive a sequence like:
seqno 1: DTMF 1
seqno 2: DTMF 1
seqno 3: DTMF 1
seqno 4: DTMF 1
seqno 6: DTMF 1 (end)
seqno 5: DTMF 1
seqno 7: DTMF 1 (end)
seqno 8: DTMF 1 (end)
Prior to this patch when we received the frame with seqno 5, we would interpret this as a new DTMF 1. With this patch, we will check the seqno of the incoming digit and not process the frame if the seqno is lower than the last recorded seqno. Note that we do not record the seqno of the dropped DTMF frame for future processing. While the above situation is what was designed to be fixed, the patch is written in such a way that the following would also be fixed too:
seqno 9: DTMF 1
seqno 10: DTMF 1 (end)
seqno 11: DTMF 1 (end)
seqno 13: DTMF 2
seqno 12: DTMF 1 (end)
seqno 14: DTMF 2
seqno 15: DTMF 2 (end)
seqno 16: DTMF 2 (end)
seqno 17: DTMF 2 (end)
In this second situation, the beginning of the DTMF 2 arrives before the final end frame of the DTMF 1. With the patch, seqno 12 is no processed and thus we properly interpret the DTMF.
Fix 2. The second change in place is to fix an issue like the following:
seqno 1: DTMF 1
seqno 2: DTMF 1
seqno 3: DTMF 1 (end) *packet lost*
seqno 4: DTMF 1 (end) *packet lost*
seqno 5: DTMF 1 (end) *packet lost*
seqno 6: DTMF 2
When we receive seqno 6, we had code in place that was supposed to properly end the previously unended DTMF 1. The problem was that the code was essentially a no-op. The code would set up an end frame for the DTMF 1 but would immediately overwrite the frame with the begin for DTMF 2. I changed process_dtmf_rfc2833() so that instead of returning a single frame, it is given as an output parameter a list of frames. Each frame that needs to be returned is appended to this list.
Fix 3. The final change is a minor one where an AST_CONTROL_SRCCHANGE frame could get lost. If we process a cisco DTMF or an RFC 3389 frame and no frame was returned, then we would return &ast_null_frame. The problem is that earlier in the function, we may have generated an AST_CONTROL_SRCCHANGE frame and put it in the list of frames we wish to return. This frame would be lost in such a case. The patch fixes this problem
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@254454 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2010-03-25 16:04:48 +00:00
}
/* Even if no frame was returned by one of the above methods,
* we may have a frame to return in our frame list
*/
2015-07-29 22:00:05 +00:00
return AST_LIST_FIRST ( & frames ) ? AST_LIST_FIRST ( & frames ) : & ast_null_frame ;
2009-04-02 17:20:52 +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_replace ( rtp - > lastrxformat , payload - > format ) ;
ao2_replace ( rtp - > f . subclass . format , payload - > format ) ;
switch ( ast_format_get_type ( rtp - > f . subclass . format ) ) {
case AST_MEDIA_TYPE_AUDIO :
rtp - > f . frametype = AST_FRAME_VOICE ;
break ;
case AST_MEDIA_TYPE_VIDEO :
rtp - > f . frametype = AST_FRAME_VIDEO ;
break ;
case AST_MEDIA_TYPE_TEXT :
rtp - > f . frametype = AST_FRAME_TEXT ;
break ;
case AST_MEDIA_TYPE_IMAGE :
/* Fall through */
default :
ast_log ( LOG_WARNING , " Unknown or unsupported media type: %s \n " ,
ast_codec_media_type2str ( ast_format_get_type ( rtp - > f . subclass . format ) ) ) ;
return & ast_null_frame ;
}
2009-04-02 17:20:52 +00:00
rtp - > rxseqno = seqno ;
2009-05-13 13:39:10 +00:00
if ( rtp - > dtmf_timeout & & rtp - > dtmf_timeout < timestamp ) {
rtp - > dtmf_timeout = 0 ;
if ( rtp - > resp ) {
struct ast_frame * f ;
Recorded merge of revisions 254452 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r254452 | mmichelson | 2010-03-25 10:59:56 -0500 (Thu, 25 Mar 2010) | 44 lines
Several fixes regarding RFC2833 DTMF detection.
Here is a copy and paste of the details from my request on
reviewboard that dealt with these changes:
Fix 1. The first change in place is to fix Mantis issue 15811, which deals with a situation where Asterisk will incorrectly interpret out of order RFC2833 frames as duplicate DTMF digits. For instance, we would receive a sequence like:
seqno 1: DTMF 1
seqno 2: DTMF 1
seqno 3: DTMF 1
seqno 4: DTMF 1
seqno 6: DTMF 1 (end)
seqno 5: DTMF 1
seqno 7: DTMF 1 (end)
seqno 8: DTMF 1 (end)
Prior to this patch when we received the frame with seqno 5, we would interpret this as a new DTMF 1. With this patch, we will check the seqno of the incoming digit and not process the frame if the seqno is lower than the last recorded seqno. Note that we do not record the seqno of the dropped DTMF frame for future processing. While the above situation is what was designed to be fixed, the patch is written in such a way that the following would also be fixed too:
seqno 9: DTMF 1
seqno 10: DTMF 1 (end)
seqno 11: DTMF 1 (end)
seqno 13: DTMF 2
seqno 12: DTMF 1 (end)
seqno 14: DTMF 2
seqno 15: DTMF 2 (end)
seqno 16: DTMF 2 (end)
seqno 17: DTMF 2 (end)
In this second situation, the beginning of the DTMF 2 arrives before the final end frame of the DTMF 1. With the patch, seqno 12 is no processed and thus we properly interpret the DTMF.
Fix 2. The second change in place is to fix an issue like the following:
seqno 1: DTMF 1
seqno 2: DTMF 1
seqno 3: DTMF 1 (end) *packet lost*
seqno 4: DTMF 1 (end) *packet lost*
seqno 5: DTMF 1 (end) *packet lost*
seqno 6: DTMF 2
When we receive seqno 6, we had code in place that was supposed to properly end the previously unended DTMF 1. The problem was that the code was essentially a no-op. The code would set up an end frame for the DTMF 1 but would immediately overwrite the frame with the begin for DTMF 2. I changed process_dtmf_rfc2833() so that instead of returning a single frame, it is given as an output parameter a list of frames. Each frame that needs to be returned is appended to this list.
Fix 3. The final change is a minor one where an AST_CONTROL_SRCCHANGE frame could get lost. If we process a cisco DTMF or an RFC 3389 frame and no frame was returned, then we would return &ast_null_frame. The problem is that earlier in the function, we may have generated an AST_CONTROL_SRCCHANGE frame and put it in the list of frames we wish to return. This frame would be lost in such a case. The patch fixes this problem
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@254454 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2010-03-25 16:04:48 +00:00
f = create_dtmf_frame ( instance , AST_FRAME_DTMF_END , 0 ) ;
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
f - > len = ast_tvdiff_ms ( ast_samp2tv ( rtp - > dtmf_duration , rtp_get_rate ( f - > subclass . format ) ) , ast_tv ( 0 , 0 ) ) ;
2009-05-13 13:39:10 +00:00
rtp - > resp = 0 ;
rtp - > dtmf_timeout = rtp - > dtmf_duration = 0 ;
2010-03-12 22:04:51 +00:00
AST_LIST_INSERT_TAIL ( & frames , f , frame_list ) ;
return AST_LIST_FIRST ( & frames ) ;
2009-05-13 13:39:10 +00:00
}
}
2009-04-02 17:20:52 +00:00
rtp - > lastrxts = timestamp ;
rtp - > f . src = " RTP " ;
rtp - > f . mallocd = 0 ;
rtp - > f . datalen = res - hdrlen ;
rtp - > f . data . ptr = rtp - > rawdata + hdrlen + AST_FRIENDLY_OFFSET ;
rtp - > f . offset = hdrlen + AST_FRIENDLY_OFFSET ;
rtp - > f . seqno = seqno ;
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 ( rtp - > f . subclass . format , ast_format_t140 ) = = AST_FORMAT_CMP_EQUAL )
& & ( ( int ) seqno - ( prev_seqno + 1 ) > 0 )
& & ( ( int ) seqno - ( prev_seqno + 1 ) < 10 ) ) {
2009-04-02 17:20:52 +00:00
unsigned char * data = rtp - > f . data . ptr ;
memmove ( rtp - > f . data . ptr + 3 , rtp - > f . data . ptr , rtp - > f . datalen ) ;
rtp - > f . datalen + = 3 ;
* data + + = 0xEF ;
* data + + = 0xBF ;
* data = 0xBD ;
}
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 ( rtp - > f . subclass . format , ast_format_t140_red ) = = AST_FORMAT_CMP_EQUAL ) {
2009-04-02 17:20:52 +00:00
unsigned char * data = rtp - > f . data . ptr ;
unsigned char * header_end ;
int num_generations ;
int header_length ;
int len ;
int diff = ( int ) seqno - ( prev_seqno + 1 ) ; /* if diff = 0, no drop*/
int x ;
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_replace ( rtp - > f . subclass . format , ast_format_t140 ) ;
2009-04-02 17:20:52 +00:00
header_end = memchr ( data , ( ( * data ) & 0x7f ) , rtp - > f . datalen ) ;
2009-07-27 20:54:54 +00:00
if ( header_end = = NULL ) {
2010-03-12 22:04:51 +00:00
return AST_LIST_FIRST ( & frames ) ? AST_LIST_FIRST ( & frames ) : & ast_null_frame ;
2009-07-27 20:54:54 +00:00
}
2009-04-02 17:20:52 +00:00
header_end + + ;
header_length = header_end - data ;
num_generations = header_length / 4 ;
len = header_length ;
if ( ! diff ) {
for ( x = 0 ; x < num_generations ; x + + )
len + = data [ x * 4 + 3 ] ;
if ( ! ( rtp - > f . datalen - len ) )
2010-03-12 22:04:51 +00:00
return AST_LIST_FIRST ( & frames ) ? AST_LIST_FIRST ( & frames ) : & ast_null_frame ;
2009-04-02 17:20:52 +00:00
rtp - > f . data . ptr + = len ;
rtp - > f . datalen - = len ;
} else if ( diff > num_generations & & diff < 10 ) {
len - = 3 ;
rtp - > f . data . ptr + = len ;
rtp - > f . datalen - = len ;
data = rtp - > f . data . ptr ;
* data + + = 0xEF ;
* data + + = 0xBF ;
* data = 0xBD ;
} else {
for ( x = 0 ; x < num_generations - diff ; x + + )
len + = data [ x * 4 + 3 ] ;
rtp - > f . data . ptr + = len ;
rtp - > f . datalen - = len ;
}
}
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_get_type ( rtp - > f . subclass . format ) = = AST_MEDIA_TYPE_AUDIO ) {
rtp - > f . samples = ast_codec_samples_count ( & rtp - > f ) ;
if ( ast_format_cache_is_slinear ( rtp - > f . subclass . format ) ) {
2009-04-02 17:20:52 +00:00
ast_frame_byteswap_be ( & rtp - > f ) ;
2010-06-21 20:33:41 +00:00
}
2009-04-02 17:20:52 +00:00
calc_rxstamp ( & rtp - > f . delivery , rtp , timestamp , mark ) ;
/* Add timing data to let ast_generic_bridge() put the frame into a jitterbuf */
ast_set_flag ( & rtp - > f , AST_FRFLAG_HAS_TIMING_INFO ) ;
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
rtp - > f . ts = timestamp / ( rtp_get_rate ( rtp - > f . subclass . format ) / 1000 ) ;
rtp - > f . len = rtp - > f . samples / ( ( ast_format_get_sample_rate ( rtp - > f . subclass . format ) / 1000 ) ) ;
} else if ( ast_format_get_type ( rtp - > f . subclass . format ) = = AST_MEDIA_TYPE_VIDEO ) {
2009-04-02 17:20:52 +00:00
/* Video -- samples is # of samples vs. 90000 */
if ( ! rtp - > lastividtimestamp )
rtp - > lastividtimestamp = timestamp ;
rtp - > f . samples = timestamp - rtp - > lastividtimestamp ;
rtp - > lastividtimestamp = timestamp ;
rtp - > f . delivery . tv_sec = 0 ;
rtp - > f . delivery . tv_usec = 0 ;
2011-02-03 16:22:10 +00:00
/* Pass the RTP marker bit as bit */
2015-10-06 16:05:00 +00:00
rtp - > f . subclass . frame_ending = mark ? 1 : 0 ;
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
} else if ( ast_format_get_type ( rtp - > f . subclass . format ) = = AST_MEDIA_TYPE_TEXT ) {
2009-04-02 17:20:52 +00:00
/* TEXT -- samples is # of samples vs. 1000 */
if ( ! rtp - > lastitexttimestamp )
rtp - > lastitexttimestamp = timestamp ;
rtp - > f . samples = timestamp - rtp - > lastitexttimestamp ;
rtp - > lastitexttimestamp = timestamp ;
rtp - > f . delivery . tv_sec = 0 ;
rtp - > f . delivery . tv_usec = 0 ;
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
} else {
ast_log ( LOG_WARNING , " Unknown or unsupported media type: %s \n " ,
ast_codec_media_type2str ( ast_format_get_type ( rtp - > f . subclass . format ) ) ) ;
return & ast_null_frame ; ;
2009-04-02 17:20:52 +00:00
}
2010-03-12 22:04:51 +00:00
AST_LIST_INSERT_TAIL ( & frames , & rtp - > f , frame_list ) ;
return AST_LIST_FIRST ( & frames ) ;
2009-04-02 17:20:52 +00:00
}
static void ast_rtp_prop_set ( struct ast_rtp_instance * instance , enum ast_rtp_property property , int value )
{
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
if ( property = = AST_RTP_PROPERTY_RTCP ) {
2011-10-14 20:51:19 +00:00
if ( value ) {
if ( rtp - > rtcp ) {
ast_debug ( 1 , " Ignoring duplicate RTCP property on RTP instance '%p' \n " , instance ) ;
return ;
}
/* Setup RTCP to be activated on the next RTP write */
if ( ! ( rtp - > rtcp = ast_calloc ( 1 , sizeof ( * rtp - > rtcp ) ) ) ) {
return ;
}
2010-07-08 22:08:07 +00:00
2011-10-14 20:51:19 +00:00
/* Grab the IP address and port we are going to use */
ast_rtp_instance_get_local_address ( instance , & rtp - > rtcp - > us ) ;
ast_sockaddr_set_port ( & rtp - > rtcp - > us ,
ast_sockaddr_port ( & rtp - > rtcp - > us ) + 1 ) ;
if ( ( rtp - > rtcp - > s =
create_new_socket ( " RTCP " ,
ast_sockaddr_is_ipv4 ( & rtp - > rtcp - > us ) ?
AF_INET :
ast_sockaddr_is_ipv6 ( & rtp - > rtcp - > us ) ?
AF_INET6 : - 1 ) ) < 0 ) {
ast_debug ( 1 , " Failed to create a new socket for RTCP on instance '%p' \n " , instance ) ;
ast_free ( rtp - > rtcp ) ;
rtp - > rtcp = NULL ;
return ;
}
2009-04-02 17:20:52 +00:00
2011-10-14 20:51:19 +00:00
/* Try to actually bind to the IP address and port we are going to use for RTCP, if this fails we have to bail out */
if ( ast_bind ( rtp - > rtcp - > s , & rtp - > rtcp - > us ) ) {
ast_debug ( 1 , " Failed to setup RTCP on RTP instance '%p' \n " , instance ) ;
close ( rtp - > rtcp - > s ) ;
ast_free ( rtp - > rtcp ) ;
rtp - > rtcp = NULL ;
return ;
}
2009-04-02 17:20:52 +00:00
2011-10-14 20:51:19 +00:00
ast_debug ( 1 , " Setup RTCP on RTP instance '%p' \n " , instance ) ;
rtp - > rtcp - > schedid = - 1 ;
2009-04-02 17:20:52 +00:00
2013-03-12 19:08:59 +00:00
# ifdef HAVE_PJPROJECT
2012-07-01 17:28:57 +00:00
if ( rtp - > ice ) {
2014-09-16 11:12:30 +00:00
rtp_add_candidates_to_ice ( instance , rtp , & rtp - > rtcp - > us , ast_sockaddr_port ( & rtp - > rtcp - > us ) , AST_RTP_ICE_COMPONENT_RTCP , TRANSPORT_SOCKET_RTCP ) ;
2012-07-01 17:28:57 +00:00
}
2013-03-12 19:08:59 +00:00
# endif
2012-07-01 17:28:57 +00:00
2014-06-30 19:51:28 +00:00
# ifdef HAVE_OPENSSL_SRTP
2015-07-08 09:21:16 +00:00
rtp - > rtcp - > dtls . timeout_timer = - 1 ;
2014-06-30 19:51:28 +00:00
dtls_setup_rtcp ( instance ) ;
# endif
2011-10-14 20:51:19 +00:00
return ;
} else {
if ( rtp - > rtcp ) {
2015-11-11 10:16:22 +00:00
if ( rtp - > rtcp - > schedid > - 1 ) {
2011-10-14 20:51:19 +00:00
if ( ! ast_sched_del ( rtp - > sched , rtp - > rtcp - > schedid ) ) {
/* Successfully cancelled scheduler entry. */
ao2_ref ( instance , - 1 ) ;
} else {
/* Unable to cancel scheduler entry */
ast_debug ( 1 , " Failed to tear down RTCP on RTP instance '%p' \n " , instance ) ;
return ;
}
rtp - > rtcp - > schedid = - 1 ;
}
close ( rtp - > rtcp - > s ) ;
2014-06-30 19:51:28 +00:00
# ifdef HAVE_OPENSSL_SRTP
if ( rtp - > rtcp - > dtls . ssl ) {
SSL_free ( rtp - > rtcp - > dtls . ssl ) ;
}
# endif
2011-10-14 20:51:19 +00:00
ast_free ( rtp - > rtcp ) ;
rtp - > rtcp = NULL ;
}
return ;
}
2009-04-02 17:20:52 +00:00
}
return ;
}
static int ast_rtp_fd ( struct ast_rtp_instance * instance , int rtcp )
{
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
return rtcp ? ( rtp - > rtcp ? rtp - > rtcp - > s : - 1 ) : rtp - > s ;
}
2010-07-08 22:08:07 +00:00
static void ast_rtp_remote_address_set ( struct ast_rtp_instance * instance , struct ast_sockaddr * addr )
2009-04-02 17:20:52 +00:00
{
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
if ( rtp - > rtcp ) {
ast_debug ( 1 , " Setting RTCP address on RTP instance '%p' \n " , instance ) ;
2010-07-08 22:08:07 +00:00
ast_sockaddr_copy ( & rtp - > rtcp - > them , addr ) ;
if ( ! ast_sockaddr_isnull ( addr ) ) {
ast_sockaddr_set_port ( & rtp - > rtcp - > them ,
ast_sockaddr_port ( addr ) + 1 ) ;
}
2009-04-02 17:20:52 +00:00
}
rtp - > rxseqno = 0 ;
2013-02-28 21:59:56 +00:00
if ( strictrtp & & rtp - > strict_rtp_state ! = STRICT_RTP_OPEN ) {
2009-04-02 17:20:52 +00:00
rtp - > strict_rtp_state = STRICT_RTP_LEARN ;
2013-03-07 15:48:06 +00:00
rtp_learning_seq_init ( & rtp - > rtp_source_learn , rtp - > seqno ) ;
2009-04-02 17:20:52 +00:00
}
return ;
}
/*! \brief Write t140 redundacy frame
* \ param data primary data to be buffered
*/
static int red_write ( const void * data )
{
struct ast_rtp_instance * instance = ( struct ast_rtp_instance * ) data ;
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
ast_rtp_write ( instance , & rtp - > red - > t140 ) ;
return 1 ;
}
static int rtp_red_init ( struct ast_rtp_instance * instance , int buffer_time , int * payloads , int generations )
{
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
int x ;
if ( ! ( rtp - > red = ast_calloc ( 1 , sizeof ( * rtp - > red ) ) ) ) {
return - 1 ;
}
rtp - > red - > t140 . frametype = AST_FRAME_TEXT ;
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_replace ( rtp - > red - > t140 . subclass . format , ast_format_t140_red ) ;
2009-04-02 17:20:52 +00:00
rtp - > red - > t140 . data . ptr = & rtp - > red - > buf_data ;
rtp - > red - > t140 . ts = 0 ;
rtp - > red - > t140red = rtp - > red - > t140 ;
rtp - > red - > t140red . data . ptr = & rtp - > red - > t140red_data ;
rtp - > red - > t140red . datalen = 0 ;
rtp - > red - > ti = buffer_time ;
rtp - > red - > num_gen = generations ;
rtp - > red - > hdrlen = generations * 4 + 1 ;
rtp - > red - > prev_ts = 0 ;
for ( x = 0 ; x < generations ; x + + ) {
rtp - > red - > pt [ x ] = payloads [ x ] ;
rtp - > red - > pt [ x ] | = 1 < < 7 ; /* mark redundant generations pt */
rtp - > red - > t140red_data [ x * 4 ] = rtp - > red - > pt [ x ] ;
}
rtp - > red - > t140red_data [ x * 4 ] = rtp - > red - > pt [ x ] = payloads [ x ] ; /* primary pt */
rtp - > red - > schedid = ast_sched_add ( rtp - > sched , generations , red_write , instance ) ;
rtp - > red - > t140 . datalen = 0 ;
return 0 ;
}
static int rtp_red_buffer ( struct ast_rtp_instance * instance , struct ast_frame * frame )
{
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
if ( frame - > datalen > - 1 ) {
struct rtp_red * red = rtp - > red ;
memcpy ( & red - > buf_data [ red - > t140 . datalen ] , frame - > data . ptr , frame - > datalen ) ;
red - > t140 . datalen + = frame - > datalen ;
red - > t140 . ts = frame - > ts ;
}
return 0 ;
}
static int ast_rtp_local_bridge ( struct ast_rtp_instance * instance0 , struct ast_rtp_instance * instance1 )
{
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance0 ) ;
ast_set_flag ( rtp , FLAG_NEED_MARKER_BIT ) ;
return 0 ;
}
static int ast_rtp_get_stat ( struct ast_rtp_instance * instance , struct ast_rtp_instance_stats * stats , enum ast_rtp_instance_stat stat )
{
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
if ( ! rtp - > rtcp ) {
return - 1 ;
}
AST_RTP_STAT_SET ( AST_RTP_INSTANCE_STAT_TXCOUNT , - 1 , stats - > txcount , rtp - > txcount ) ;
AST_RTP_STAT_SET ( AST_RTP_INSTANCE_STAT_RXCOUNT , - 1 , stats - > rxcount , rtp - > rxcount ) ;
AST_RTP_STAT_SET ( AST_RTP_INSTANCE_STAT_TXPLOSS , AST_RTP_INSTANCE_STAT_COMBINED_LOSS , stats - > txploss , rtp - > rtcp - > reported_lost ) ;
AST_RTP_STAT_SET ( AST_RTP_INSTANCE_STAT_RXPLOSS , AST_RTP_INSTANCE_STAT_COMBINED_LOSS , stats - > rxploss , rtp - > rtcp - > expected_prior - rtp - > rtcp - > received_prior ) ;
AST_RTP_STAT_SET ( AST_RTP_INSTANCE_STAT_REMOTE_MAXRXPLOSS , AST_RTP_INSTANCE_STAT_COMBINED_LOSS , stats - > remote_maxrxploss , rtp - > rtcp - > reported_maxlost ) ;
AST_RTP_STAT_SET ( AST_RTP_INSTANCE_STAT_REMOTE_MINRXPLOSS , AST_RTP_INSTANCE_STAT_COMBINED_LOSS , stats - > remote_minrxploss , rtp - > rtcp - > reported_minlost ) ;
AST_RTP_STAT_SET ( AST_RTP_INSTANCE_STAT_REMOTE_NORMDEVRXPLOSS , AST_RTP_INSTANCE_STAT_COMBINED_LOSS , stats - > remote_normdevrxploss , rtp - > rtcp - > reported_normdev_lost ) ;
AST_RTP_STAT_SET ( AST_RTP_INSTANCE_STAT_REMOTE_STDEVRXPLOSS , AST_RTP_INSTANCE_STAT_COMBINED_LOSS , stats - > remote_stdevrxploss , rtp - > rtcp - > reported_stdev_lost ) ;
AST_RTP_STAT_SET ( AST_RTP_INSTANCE_STAT_LOCAL_MAXRXPLOSS , AST_RTP_INSTANCE_STAT_COMBINED_LOSS , stats - > local_maxrxploss , rtp - > rtcp - > maxrxlost ) ;
AST_RTP_STAT_SET ( AST_RTP_INSTANCE_STAT_LOCAL_MINRXPLOSS , AST_RTP_INSTANCE_STAT_COMBINED_LOSS , stats - > local_minrxploss , rtp - > rtcp - > minrxlost ) ;
AST_RTP_STAT_SET ( AST_RTP_INSTANCE_STAT_LOCAL_NORMDEVRXPLOSS , AST_RTP_INSTANCE_STAT_COMBINED_LOSS , stats - > local_normdevrxploss , rtp - > rtcp - > normdev_rxlost ) ;
AST_RTP_STAT_SET ( AST_RTP_INSTANCE_STAT_LOCAL_STDEVRXPLOSS , AST_RTP_INSTANCE_STAT_COMBINED_LOSS , stats - > local_stdevrxploss , rtp - > rtcp - > stdev_rxlost ) ;
AST_RTP_STAT_TERMINATOR ( AST_RTP_INSTANCE_STAT_COMBINED_LOSS ) ;
AST_RTP_STAT_SET ( AST_RTP_INSTANCE_STAT_TXJITTER , AST_RTP_INSTANCE_STAT_COMBINED_JITTER , stats - > txjitter , rtp - > rxjitter ) ;
AST_RTP_STAT_SET ( AST_RTP_INSTANCE_STAT_RXJITTER , AST_RTP_INSTANCE_STAT_COMBINED_JITTER , stats - > rxjitter , rtp - > rtcp - > reported_jitter / ( unsigned int ) 65536.0 ) ;
AST_RTP_STAT_SET ( AST_RTP_INSTANCE_STAT_REMOTE_MAXJITTER , AST_RTP_INSTANCE_STAT_COMBINED_JITTER , stats - > remote_maxjitter , rtp - > rtcp - > reported_maxjitter ) ;
AST_RTP_STAT_SET ( AST_RTP_INSTANCE_STAT_REMOTE_MINJITTER , AST_RTP_INSTANCE_STAT_COMBINED_JITTER , stats - > remote_minjitter , rtp - > rtcp - > reported_minjitter ) ;
AST_RTP_STAT_SET ( AST_RTP_INSTANCE_STAT_REMOTE_NORMDEVJITTER , AST_RTP_INSTANCE_STAT_COMBINED_JITTER , stats - > remote_normdevjitter , rtp - > rtcp - > reported_normdev_jitter ) ;
AST_RTP_STAT_SET ( AST_RTP_INSTANCE_STAT_REMOTE_STDEVJITTER , AST_RTP_INSTANCE_STAT_COMBINED_JITTER , stats - > remote_stdevjitter , rtp - > rtcp - > reported_stdev_jitter ) ;
AST_RTP_STAT_SET ( AST_RTP_INSTANCE_STAT_LOCAL_MAXJITTER , AST_RTP_INSTANCE_STAT_COMBINED_JITTER , stats - > local_maxjitter , rtp - > rtcp - > maxrxjitter ) ;
AST_RTP_STAT_SET ( AST_RTP_INSTANCE_STAT_LOCAL_MINJITTER , AST_RTP_INSTANCE_STAT_COMBINED_JITTER , stats - > local_minjitter , rtp - > rtcp - > minrxjitter ) ;
AST_RTP_STAT_SET ( AST_RTP_INSTANCE_STAT_LOCAL_NORMDEVJITTER , AST_RTP_INSTANCE_STAT_COMBINED_JITTER , stats - > local_normdevjitter , rtp - > rtcp - > normdev_rxjitter ) ;
AST_RTP_STAT_SET ( AST_RTP_INSTANCE_STAT_LOCAL_STDEVJITTER , AST_RTP_INSTANCE_STAT_COMBINED_JITTER , stats - > local_stdevjitter , rtp - > rtcp - > stdev_rxjitter ) ;
AST_RTP_STAT_TERMINATOR ( AST_RTP_INSTANCE_STAT_COMBINED_JITTER ) ;
AST_RTP_STAT_SET ( AST_RTP_INSTANCE_STAT_RTT , AST_RTP_INSTANCE_STAT_COMBINED_RTT , stats - > rtt , rtp - > rtcp - > rtt ) ;
AST_RTP_STAT_SET ( AST_RTP_INSTANCE_STAT_MAX_RTT , AST_RTP_INSTANCE_STAT_COMBINED_RTT , stats - > maxrtt , rtp - > rtcp - > maxrtt ) ;
AST_RTP_STAT_SET ( AST_RTP_INSTANCE_STAT_MIN_RTT , AST_RTP_INSTANCE_STAT_COMBINED_RTT , stats - > minrtt , rtp - > rtcp - > minrtt ) ;
AST_RTP_STAT_SET ( AST_RTP_INSTANCE_STAT_NORMDEVRTT , AST_RTP_INSTANCE_STAT_COMBINED_RTT , stats - > normdevrtt , rtp - > rtcp - > normdevrtt ) ;
AST_RTP_STAT_SET ( AST_RTP_INSTANCE_STAT_STDEVRTT , AST_RTP_INSTANCE_STAT_COMBINED_RTT , stats - > stdevrtt , rtp - > rtcp - > stdevrtt ) ;
AST_RTP_STAT_TERMINATOR ( AST_RTP_INSTANCE_STAT_COMBINED_RTT ) ;
AST_RTP_STAT_SET ( AST_RTP_INSTANCE_STAT_LOCAL_SSRC , - 1 , stats - > local_ssrc , rtp - > ssrc ) ;
AST_RTP_STAT_SET ( AST_RTP_INSTANCE_STAT_REMOTE_SSRC , - 1 , stats - > remote_ssrc , rtp - > themssrc ) ;
2013-07-05 17:33:33 +00:00
AST_RTP_STAT_STRCPY ( AST_RTP_INSTANCE_STAT_CHANNEL_UNIQUEID , - 1 , stats - > channel_uniqueid , ast_rtp_instance_get_channel_id ( instance ) ) ;
2009-04-02 17:20:52 +00:00
return 0 ;
}
static int ast_rtp_dtmf_compatible ( struct ast_channel * chan0 , struct ast_rtp_instance * instance0 , struct ast_channel * chan1 , struct ast_rtp_instance * instance1 )
{
/* If both sides are not using the same method of DTMF transmission
* ( ie : one is RFC2833 , other is INFO . . . then we can not do direct media .
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* | DTMF Mode | HAS_DTMF | Accepts Begin Frames |
* | - - - - - - - - - - - | - - - - - - - - - - - - | - - - - - - - - - - - - - - - - - - - - - - - |
* | Inband | False | True |
* | RFC2833 | True | True |
* | SIP INFO | False | False |
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*/
return ( ( ( ast_rtp_instance_get_prop ( instance0 , AST_RTP_PROPERTY_DTMF ) ! = ast_rtp_instance_get_prop ( instance1 , AST_RTP_PROPERTY_DTMF ) ) | |
2012-02-20 23:43:27 +00:00
( ! ast_channel_tech ( chan0 ) - > send_digit_begin ! = ! ast_channel_tech ( chan1 ) - > send_digit_begin ) ) ? 0 : 1 ) ;
2009-04-02 17:20:52 +00:00
}
2010-07-08 22:08:07 +00:00
static void ast_rtp_stun_request ( struct ast_rtp_instance * instance , struct ast_sockaddr * suggestion , const char * username )
2009-04-02 17:20:52 +00:00
{
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
2010-07-08 22:08:07 +00:00
struct sockaddr_in suggestion_tmp ;
2009-04-02 17:20:52 +00:00
2010-07-08 22:08:07 +00:00
ast_sockaddr_to_sin ( suggestion , & suggestion_tmp ) ;
ast_stun_request ( rtp - > s , & suggestion_tmp , username , NULL ) ;
ast_sockaddr_from_sin ( suggestion , & suggestion_tmp ) ;
2009-04-02 17:20:52 +00:00
}
static void ast_rtp_stop ( struct ast_rtp_instance * instance )
{
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
2010-07-08 22:08:07 +00:00
struct ast_sockaddr addr = { { 0 , } } ;
2009-04-02 17:20:52 +00:00
2012-09-20 18:27:28 +00:00
# ifdef HAVE_OPENSSL_SRTP
AST_SCHED_DEL_UNREF ( rtp - > sched , rtp - > rekeyid , ao2_ref ( instance , - 1 ) ) ;
2015-07-01 12:55:47 +00:00
dtls_srtp_stop_timeout_timer ( instance , rtp , 0 ) ;
if ( rtp - > rtcp ) {
dtls_srtp_stop_timeout_timer ( instance , rtp , 1 ) ;
}
2012-09-20 18:27:28 +00:00
# endif
2015-11-11 10:16:22 +00:00
if ( rtp - > rtcp & & rtp - > rtcp - > schedid > - 1 ) {
2011-09-20 01:11:18 +00:00
if ( ! ast_sched_del ( rtp - > sched , rtp - > rtcp - > schedid ) ) {
/* successfully cancelled scheduler entry. */
ao2_ref ( instance , - 1 ) ;
}
rtp - > rtcp - > schedid = - 1 ;
2009-04-02 17:20:52 +00:00
}
2011-09-20 01:11:18 +00:00
2009-04-02 17:20:52 +00:00
if ( rtp - > red ) {
AST_SCHED_DEL ( rtp - > sched , rtp - > red - > schedid ) ;
2014-09-26 14:41:38 +00:00
ast_free ( rtp - > red ) ;
2009-04-02 17:20:52 +00:00
rtp - > red = NULL ;
}
2010-07-08 22:08:07 +00:00
ast_rtp_instance_set_remote_address ( instance , & addr ) ;
2009-04-02 17:20:52 +00:00
if ( rtp - > rtcp ) {
2010-07-08 22:08:07 +00:00
ast_sockaddr_setnull ( & rtp - > rtcp - > them ) ;
2009-04-02 17:20:52 +00:00
}
ast_set_flag ( rtp , FLAG_NEED_MARKER_BIT ) ;
}
2010-08-24 18:58:46 +00:00
static int ast_rtp_qos_set ( struct ast_rtp_instance * instance , int tos , int cos , const char * desc )
{
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
return ast_set_qos ( rtp - > s , tos , cos , desc ) ;
}
2011-06-14 17:03:37 +00:00
/*! \brief generate comfort noice (CNG) */
static int ast_rtp_sendcng ( struct ast_rtp_instance * instance , int level )
{
unsigned int * rtpheader ;
int hdrlen = 12 ;
2013-05-09 04:11:59 +00:00
int res , payload = 0 ;
2011-06-14 17:03:37 +00:00
char data [ 256 ] ;
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
struct ast_sockaddr remote_address = { { 0 , } } ;
2012-07-01 17:28:57 +00:00
int ice ;
2011-06-14 17:03:37 +00:00
ast_rtp_instance_get_remote_address ( instance , & remote_address ) ;
if ( ast_sockaddr_isnull ( & remote_address ) ) {
return - 1 ;
}
2015-07-24 00:24:04 +00:00
payload = ast_rtp_codecs_payload_code_tx ( ast_rtp_instance_get_codecs ( instance ) , 0 , NULL , AST_RTP_CN ) ;
2011-06-14 17:03:37 +00:00
level = 127 - ( level & 0x7f ) ;
2013-08-23 15:42:27 +00:00
2011-06-14 17:03:37 +00:00
rtp - > dtmfmute = ast_tvadd ( ast_tvnow ( ) , ast_tv ( 0 , 500000 ) ) ;
/* Get a pointer to the header */
rtpheader = ( unsigned int * ) data ;
2013-05-09 04:11:59 +00:00
rtpheader [ 0 ] = htonl ( ( 2 < < 30 ) | ( payload < < 16 ) | ( rtp - > seqno ) ) ;
2011-06-14 17:03:37 +00:00
rtpheader [ 1 ] = htonl ( rtp - > lastts ) ;
2013-08-23 15:42:27 +00:00
rtpheader [ 2 ] = htonl ( rtp - > ssrc ) ;
2011-06-14 17:03:37 +00:00
data [ 12 ] = level ;
2012-07-01 17:28:57 +00:00
res = rtp_sendto ( instance , ( void * ) rtpheader , hdrlen + 1 , 0 , & remote_address , & ice ) ;
2011-06-14 17:03:37 +00:00
if ( res < 0 ) {
ast_log ( LOG_ERROR , " RTP Comfort Noise Transmission error to %s: %s \n " , ast_sockaddr_stringify ( & remote_address ) , strerror ( errno ) ) ;
2012-07-01 17:28:57 +00:00
return res ;
}
if ( rtp_debug_test_addr ( & remote_address ) ) {
2014-05-09 22:49:26 +00:00
ast_verbose ( " Sent Comfort Noise RTP packet to %s%s (type %-2.2d, seq %-6.6d, ts %-6.6u, len %-6.6d) \n " ,
2012-07-01 17:28:57 +00:00
ast_sockaddr_stringify ( & remote_address ) ,
ice ? " (via ICE) " : " " ,
AST_RTP_CN , rtp - > seqno , rtp - > lastdigitts , res - hdrlen ) ;
2011-06-14 17:03:37 +00:00
}
2013-05-09 04:11:59 +00:00
rtp - > seqno + + ;
2011-06-14 17:03:37 +00:00
return res ;
}
2012-09-20 18:27:28 +00:00
# ifdef HAVE_OPENSSL_SRTP
2015-07-01 12:55:47 +00:00
static void dtls_perform_setup ( struct dtls_details * dtls )
{
if ( ! dtls - > ssl | | ! SSL_is_init_finished ( dtls - > ssl ) ) {
return ;
}
SSL_clear ( dtls - > ssl ) ;
if ( dtls - > dtls_setup = = AST_RTP_DTLS_SETUP_PASSIVE ) {
SSL_set_accept_state ( dtls - > ssl ) ;
} else {
SSL_set_connect_state ( dtls - > ssl ) ;
}
dtls - > connection = AST_RTP_DTLS_CONNECTION_NEW ;
}
2012-09-20 18:27:28 +00:00
static int ast_rtp_activate ( struct ast_rtp_instance * instance )
{
struct ast_rtp * rtp = ast_rtp_instance_get_data ( instance ) ;
2015-07-01 12:55:47 +00:00
dtls_perform_setup ( & rtp - > dtls ) ;
if ( rtp - > rtcp ) {
dtls_perform_setup ( & rtp - > rtcp - > dtls ) ;
}
2014-06-30 19:51:28 +00:00
/* If ICE negotiation is enabled the DTLS Handshake will be performed upon completion of it */
2015-03-08 01:47:03 +00:00
# ifdef HAVE_PJPROJECT
2014-06-30 19:51:28 +00:00
if ( rtp - > ice ) {
2012-09-20 18:27:28 +00:00
return 0 ;
}
2014-06-30 19:51:28 +00:00
# endif
2012-09-20 18:27:28 +00:00
2014-06-30 19:51:28 +00:00
dtls_perform_handshake ( instance , & rtp - > dtls , 0 ) ;
2012-09-20 18:27:28 +00:00
2014-06-30 19:51:28 +00:00
if ( rtp - > rtcp ) {
dtls_perform_handshake ( instance , & rtp - > rtcp - > dtls , 1 ) ;
}
2012-09-20 18:27:28 +00:00
return 0 ;
}
# endif
2009-04-02 17:20:52 +00:00
static char * rtp_do_debug_ip ( struct ast_cli_args * a )
{
2010-07-08 22:08:07 +00:00
char * arg = ast_strdupa ( a - > argv [ 4 ] ) ;
2011-11-28 14:34:14 +00:00
char * debughost = NULL ;
char * debugport = NULL ;
2010-07-08 22:08:07 +00:00
2011-11-28 14:34:14 +00:00
if ( ! ast_sockaddr_parse ( & rtpdebugaddr , arg , 0 ) | | ! ast_sockaddr_split_hostport ( arg , & debughost , & debugport , 0 ) ) {
2009-04-02 17:20:52 +00:00
ast_cli ( a - > fd , " Lookup failed for '%s' \n " , arg ) ;
return CLI_FAILURE ;
}
2011-11-28 14:34:14 +00:00
rtpdebugport = ( ! ast_strlen_zero ( debugport ) & & debugport [ 0 ] ! = ' 0 ' ) ;
2010-07-08 22:08:07 +00:00
ast_cli ( a - > fd , " RTP Debugging Enabled for address: %s \n " ,
ast_sockaddr_stringify ( & rtpdebugaddr ) ) ;
2009-04-02 17:20:52 +00:00
rtpdebug = 1 ;
return CLI_SUCCESS ;
}
static char * rtcp_do_debug_ip ( struct ast_cli_args * a )
{
2010-07-08 22:08:07 +00:00
char * arg = ast_strdupa ( a - > argv [ 4 ] ) ;
2011-11-28 14:34:14 +00:00
char * debughost = NULL ;
char * debugport = NULL ;
2010-07-08 22:08:07 +00:00
2011-11-28 14:34:14 +00:00
if ( ! ast_sockaddr_parse ( & rtcpdebugaddr , arg , 0 ) | | ! ast_sockaddr_split_hostport ( arg , & debughost , & debugport , 0 ) ) {
2009-04-02 17:20:52 +00:00
ast_cli ( a - > fd , " Lookup failed for '%s' \n " , arg ) ;
return CLI_FAILURE ;
}
2011-11-28 14:34:14 +00:00
rtcpdebugport = ( ! ast_strlen_zero ( debugport ) & & debugport [ 0 ] ! = ' 0 ' ) ;
2010-07-08 22:08:07 +00:00
ast_cli ( a - > fd , " RTCP Debugging Enabled for address: %s \n " ,
ast_sockaddr_stringify ( & rtcpdebugaddr ) ) ;
2009-04-02 17:20:52 +00:00
rtcpdebug = 1 ;
return CLI_SUCCESS ;
}
static char * handle_cli_rtp_set_debug ( struct ast_cli_entry * e , int cmd , struct ast_cli_args * a )
{
switch ( cmd ) {
case CLI_INIT :
e - > command = " rtp set debug {on|off|ip} " ;
e - > usage =
" Usage: rtp set debug {on|off|ip host[:port]} \n "
" Enable/Disable dumping of all RTP packets. If 'ip' is \n "
" specified, limit the dumped packets to those to and from \n "
" the specified 'host' with optional port. \n " ;
return NULL ;
case CLI_GENERATE :
return NULL ;
}
if ( a - > argc = = e - > args ) { /* set on or off */
if ( ! strncasecmp ( a - > argv [ e - > args - 1 ] , " on " , 2 ) ) {
rtpdebug = 1 ;
memset ( & rtpdebugaddr , 0 , sizeof ( rtpdebugaddr ) ) ;
ast_cli ( a - > fd , " RTP Debugging Enabled \n " ) ;
return CLI_SUCCESS ;
} else if ( ! strncasecmp ( a - > argv [ e - > args - 1 ] , " off " , 3 ) ) {
rtpdebug = 0 ;
ast_cli ( a - > fd , " RTP Debugging Disabled \n " ) ;
return CLI_SUCCESS ;
}
} else if ( a - > argc = = e - > args + 1 ) { /* ip */
return rtp_do_debug_ip ( a ) ;
}
return CLI_SHOWUSAGE ; /* default, failure */
}
static char * handle_cli_rtcp_set_debug ( struct ast_cli_entry * e , int cmd , struct ast_cli_args * a )
{
switch ( cmd ) {
case CLI_INIT :
e - > command = " rtcp set debug {on|off|ip} " ;
e - > usage =
" Usage: rtcp set debug {on|off|ip host[:port]} \n "
" Enable/Disable dumping of all RTCP packets. If 'ip' is \n "
" specified, limit the dumped packets to those to and from \n "
" the specified 'host' with optional port. \n " ;
return NULL ;
case CLI_GENERATE :
return NULL ;
}
if ( a - > argc = = e - > args ) { /* set on or off */
if ( ! strncasecmp ( a - > argv [ e - > args - 1 ] , " on " , 2 ) ) {
rtcpdebug = 1 ;
memset ( & rtcpdebugaddr , 0 , sizeof ( rtcpdebugaddr ) ) ;
ast_cli ( a - > fd , " RTCP Debugging Enabled \n " ) ;
return CLI_SUCCESS ;
} else if ( ! strncasecmp ( a - > argv [ e - > args - 1 ] , " off " , 3 ) ) {
rtcpdebug = 0 ;
ast_cli ( a - > fd , " RTCP Debugging Disabled \n " ) ;
return CLI_SUCCESS ;
}
} else if ( a - > argc = = e - > args + 1 ) { /* ip */
return rtcp_do_debug_ip ( a ) ;
}
return CLI_SHOWUSAGE ; /* default, failure */
}
static char * handle_cli_rtcp_set_stats ( struct ast_cli_entry * e , int cmd , struct ast_cli_args * a )
{
switch ( cmd ) {
case CLI_INIT :
e - > command = " rtcp set stats {on|off} " ;
e - > usage =
" Usage: rtcp set stats {on|off} \n "
" Enable/Disable dumping of RTCP stats. \n " ;
return NULL ;
case CLI_GENERATE :
return NULL ;
}
if ( a - > argc ! = e - > args )
return CLI_SHOWUSAGE ;
if ( ! strncasecmp ( a - > argv [ e - > args - 1 ] , " on " , 2 ) )
rtcpstats = 1 ;
else if ( ! strncasecmp ( a - > argv [ e - > args - 1 ] , " off " , 3 ) )
rtcpstats = 0 ;
else
return CLI_SHOWUSAGE ;
ast_cli ( a - > fd , " RTCP Stats %s \n " , rtcpstats ? " Enabled " : " Disabled " ) ;
return CLI_SUCCESS ;
}
static struct ast_cli_entry cli_rtp [ ] = {
AST_CLI_DEFINE ( handle_cli_rtp_set_debug , " Enable/Disable RTP debugging " ) ,
AST_CLI_DEFINE ( handle_cli_rtcp_set_debug , " Enable/Disable RTCP debugging " ) ,
AST_CLI_DEFINE ( handle_cli_rtcp_set_stats , " Enable/Disable RTCP stats " ) ,
} ;
static int rtp_reload ( int reload )
{
struct ast_config * cfg ;
const char * s ;
struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 } ;
cfg = ast_config_load2 ( " rtp.conf " , " rtp " , config_flags ) ;
if ( cfg = = CONFIG_STATUS_FILEMISSING | | cfg = = CONFIG_STATUS_FILEUNCHANGED | | cfg = = CONFIG_STATUS_FILEINVALID ) {
return 0 ;
}
rtpstart = DEFAULT_RTP_START ;
rtpend = DEFAULT_RTP_END ;
dtmftimeout = DEFAULT_DTMF_TIMEOUT ;
2012-08-17 12:42:33 +00:00
strictrtp = DEFAULT_STRICT_RTP ;
2012-01-17 17:15:05 +00:00
learning_min_sequential = DEFAULT_LEARNING_MIN_SEQUENTIAL ;
2012-09-24 12:42:19 +00:00
/** This resource is not "reloaded" so much as unloaded and loaded again.
* In the case of the TURN related variables , the memory referenced by a
* previously loaded instance * should * have been released when the
* corresponding pool was destroyed . If at some point in the future this
* resource were to support ACTUAL live reconfiguration and did NOT release
* the pool this will cause a small memory leak .
*/
2013-03-12 19:08:59 +00:00
# ifdef HAVE_PJPROJECT
2012-08-17 12:42:33 +00:00
icesupport = DEFAULT_ICESUPPORT ;
2012-07-01 17:28:57 +00:00
turnport = DEFAULT_TURN_PORT ;
2012-09-24 12:42:19 +00:00
memset ( & stunaddr , 0 , sizeof ( stunaddr ) ) ;
turnaddr = pj_str ( NULL ) ;
turnusername = pj_str ( NULL ) ;
turnpassword = pj_str ( NULL ) ;
2013-03-12 19:08:59 +00:00
# endif
2012-09-24 12:42:19 +00:00
2009-04-02 17:20:52 +00:00
if ( cfg ) {
if ( ( s = ast_variable_retrieve ( cfg , " general " , " rtpstart " ) ) ) {
rtpstart = atoi ( s ) ;
if ( rtpstart < MINIMUM_RTP_PORT )
rtpstart = MINIMUM_RTP_PORT ;
if ( rtpstart > MAXIMUM_RTP_PORT )
rtpstart = MAXIMUM_RTP_PORT ;
}
if ( ( s = ast_variable_retrieve ( cfg , " general " , " rtpend " ) ) ) {
rtpend = atoi ( s ) ;
if ( rtpend < MINIMUM_RTP_PORT )
rtpend = MINIMUM_RTP_PORT ;
if ( rtpend > MAXIMUM_RTP_PORT )
rtpend = MAXIMUM_RTP_PORT ;
}
if ( ( s = ast_variable_retrieve ( cfg , " general " , " rtcpinterval " ) ) ) {
rtcpinterval = atoi ( s ) ;
if ( rtcpinterval = = 0 )
rtcpinterval = 0 ; /* Just so we're clear... it's zero */
if ( rtcpinterval < RTCP_MIN_INTERVALMS )
rtcpinterval = RTCP_MIN_INTERVALMS ; /* This catches negative numbers too */
if ( rtcpinterval > RTCP_MAX_INTERVALMS )
rtcpinterval = RTCP_MAX_INTERVALMS ;
}
if ( ( s = ast_variable_retrieve ( cfg , " general " , " rtpchecksums " ) ) ) {
# ifdef SO_NO_CHECK
nochecksums = ast_false ( s ) ? 1 : 0 ;
# else
if ( ast_false ( s ) )
ast_log ( LOG_WARNING , " Disabling RTP checksums is not supported on this operating system! \n " ) ;
# endif
}
if ( ( s = ast_variable_retrieve ( cfg , " general " , " dtmftimeout " ) ) ) {
dtmftimeout = atoi ( s ) ;
2009-05-13 13:39:10 +00:00
if ( ( dtmftimeout < 0 ) | | ( dtmftimeout > 64000 ) ) {
2009-04-02 17:20:52 +00:00
ast_log ( LOG_WARNING , " DTMF timeout of '%d' outside range, using default of '%d' instead \n " ,
dtmftimeout , DEFAULT_DTMF_TIMEOUT ) ;
dtmftimeout = DEFAULT_DTMF_TIMEOUT ;
} ;
}
if ( ( s = ast_variable_retrieve ( cfg , " general " , " strictrtp " ) ) ) {
strictrtp = ast_true ( s ) ;
}
2012-01-17 17:15:05 +00:00
if ( ( s = ast_variable_retrieve ( cfg , " general " , " probation " ) ) ) {
if ( ( sscanf ( s , " %d " , & learning_min_sequential ) < = 0 ) | | learning_min_sequential < = 0 ) {
ast_log ( LOG_WARNING , " Value for 'probation' could not be read, using default of '%d' instead \n " ,
DEFAULT_LEARNING_MIN_SEQUENTIAL ) ;
}
}
2013-03-12 19:08:59 +00:00
# ifdef HAVE_PJPROJECT
2012-07-01 17:28:57 +00:00
if ( ( s = ast_variable_retrieve ( cfg , " general " , " icesupport " ) ) ) {
icesupport = ast_true ( s ) ;
}
if ( ( s = ast_variable_retrieve ( cfg , " general " , " stunaddr " ) ) ) {
stunaddr . sin_port = htons ( STANDARD_STUN_PORT ) ;
if ( ast_parse_arg ( s , PARSE_INADDR , & stunaddr ) ) {
ast_log ( LOG_WARNING , " Invalid STUN server address: %s \n " , s ) ;
}
}
if ( ( s = ast_variable_retrieve ( cfg , " general " , " turnaddr " ) ) ) {
2012-09-24 12:42:19 +00:00
struct sockaddr_in addr ;
addr . sin_port = htons ( DEFAULT_TURN_PORT ) ;
if ( ast_parse_arg ( s , PARSE_INADDR , & addr ) ) {
ast_log ( LOG_WARNING , " Invalid TURN server address: %s \n " , s ) ;
} else {
2014-09-16 11:12:30 +00:00
pj_strdup2_with_null ( pool , & turnaddr , ast_inet_ntoa ( addr . sin_addr ) ) ;
2012-09-24 12:42:19 +00:00
/* ntohs() is not a bug here. The port number is used in host byte order with
* a pjnat API . */
turnport = ntohs ( addr . sin_port ) ;
2012-07-01 17:28:57 +00:00
}
}
if ( ( s = ast_variable_retrieve ( cfg , " general " , " turnusername " ) ) ) {
2014-09-16 11:12:30 +00:00
pj_strdup2_with_null ( pool , & turnusername , s ) ;
2012-07-01 17:28:57 +00:00
}
if ( ( s = ast_variable_retrieve ( cfg , " general " , " turnpassword " ) ) ) {
2014-09-16 11:12:30 +00:00
pj_strdup2_with_null ( pool , & turnpassword , s ) ;
2012-07-01 17:28:57 +00:00
}
2013-03-12 19:08:59 +00:00
# endif
2009-04-02 17:20:52 +00:00
ast_config_destroy ( cfg ) ;
}
if ( rtpstart > = rtpend ) {
ast_log ( LOG_WARNING , " Unreasonable values for RTP start/end port in rtp.conf \n " ) ;
rtpstart = DEFAULT_RTP_START ;
rtpend = DEFAULT_RTP_END ;
}
ast_verb ( 2 , " RTP Allocating from port range %d -> %d \n " , rtpstart , rtpend ) ;
return 0 ;
}
static int reload_module ( void )
{
rtp_reload ( 1 ) ;
return 0 ;
}
2014-09-16 11:12:30 +00:00
# ifdef HAVE_PJPROJECT
static void rtp_terminate_pjproject ( void )
{
2014-09-17 18:06:06 +00:00
pj_thread_register_check ( ) ;
2014-09-16 11:12:30 +00:00
if ( timer_thread ) {
timer_terminate = 1 ;
pj_thread_join ( timer_thread ) ;
pj_thread_destroy ( timer_thread ) ;
}
pj_caching_pool_destroy ( & cachingpool ) ;
pj_shutdown ( ) ;
}
# endif
2009-04-02 17:20:52 +00:00
static int load_module ( void )
{
2013-03-12 19:08:59 +00:00
# ifdef HAVE_PJPROJECT
2012-07-02 00:35:40 +00:00
pj_lock_t * lock ;
2012-07-01 17:28:57 +00:00
if ( pj_init ( ) ! = PJ_SUCCESS ) {
return AST_MODULE_LOAD_DECLINE ;
}
if ( pjlib_util_init ( ) ! = PJ_SUCCESS ) {
2014-09-16 11:12:30 +00:00
rtp_terminate_pjproject ( ) ;
2012-07-01 17:28:57 +00:00
return AST_MODULE_LOAD_DECLINE ;
}
if ( pjnath_init ( ) ! = PJ_SUCCESS ) {
2014-09-16 11:12:30 +00:00
rtp_terminate_pjproject ( ) ;
2012-07-01 17:28:57 +00:00
return AST_MODULE_LOAD_DECLINE ;
}
pj_caching_pool_init ( & cachingpool , & pj_pool_factory_default_policy , 0 ) ;
2014-09-16 11:12:30 +00:00
pool = pj_pool_create ( & cachingpool . factory , " timer " , 512 , 512 , NULL ) ;
2012-07-01 17:28:57 +00:00
2014-09-16 11:12:30 +00:00
if ( pj_timer_heap_create ( pool , 100 , & timer_heap ) ! = PJ_SUCCESS ) {
rtp_terminate_pjproject ( ) ;
2012-07-01 17:28:57 +00:00
return AST_MODULE_LOAD_DECLINE ;
}
2012-07-02 00:35:40 +00:00
if ( pj_lock_create_recursive_mutex ( pool , " rtp%p " , & lock ) ! = PJ_SUCCESS ) {
2014-09-16 11:12:30 +00:00
rtp_terminate_pjproject ( ) ;
2012-07-02 00:35:40 +00:00
return AST_MODULE_LOAD_DECLINE ;
}
2014-09-16 11:12:30 +00:00
pj_timer_heap_set_lock ( timer_heap , lock , PJ_TRUE ) ;
2012-07-02 00:35:40 +00:00
2014-09-16 11:12:30 +00:00
if ( pj_thread_create ( pool , " timer " , & timer_worker_thread , NULL , 0 , 0 , & timer_thread ) ! = PJ_SUCCESS ) {
rtp_terminate_pjproject ( ) ;
2012-07-01 17:28:57 +00:00
return AST_MODULE_LOAD_DECLINE ;
}
2013-03-12 19:08:59 +00:00
# endif
2012-07-01 17:28:57 +00:00
2009-04-02 17:20:52 +00:00
if ( ast_rtp_engine_register ( & asterisk_rtp_engine ) ) {
2013-03-12 19:08:59 +00:00
# ifdef HAVE_PJPROJECT
2014-09-16 11:12:30 +00:00
rtp_terminate_pjproject ( ) ;
2013-03-12 19:08:59 +00:00
# endif
2009-04-02 17:20:52 +00:00
return AST_MODULE_LOAD_DECLINE ;
}
if ( ast_cli_register_multiple ( cli_rtp , ARRAY_LEN ( cli_rtp ) ) ) {
2013-03-12 19:08:59 +00:00
# ifdef HAVE_PJPROJECT
2009-04-02 17:20:52 +00:00
ast_rtp_engine_unregister ( & asterisk_rtp_engine ) ;
2014-09-16 11:12:30 +00:00
rtp_terminate_pjproject ( ) ;
2013-03-12 19:08:59 +00:00
# endif
2009-04-02 17:20:52 +00:00
return AST_MODULE_LOAD_DECLINE ;
}
rtp_reload ( 0 ) ;
return AST_MODULE_LOAD_SUCCESS ;
}
static int unload_module ( void )
{
ast_rtp_engine_unregister ( & asterisk_rtp_engine ) ;
ast_cli_unregister_multiple ( cli_rtp , ARRAY_LEN ( cli_rtp ) ) ;
2013-03-12 19:08:59 +00:00
# ifdef HAVE_PJPROJECT
2012-07-01 17:28:57 +00:00
pj_thread_register_check ( ) ;
2014-09-16 11:12:30 +00:00
rtp_terminate_pjproject ( ) ;
2013-03-12 19:08:59 +00:00
# endif
2012-07-01 17:28:57 +00:00
2009-04-02 17:20:52 +00:00
return 0 ;
}
2010-07-20 19:35:02 +00:00
AST_MODULE_INFO ( ASTERISK_GPL_KEY , AST_MODFLAG_LOAD_ORDER , " Asterisk RTP Stack " ,
2015-05-06 00:49:04 +00:00
. support_level = AST_MODULE_SUPPORT_CORE ,
. load = load_module ,
. unload = unload_module ,
. reload = reload_module ,
. load_pri = AST_MODPRI_CHANNEL_DEPEND ,
) ;