[asterisk-commits] mjordan: trunk r419044 - in /trunk: ./ addons/ apps/ apps/confbridge/ bridges...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sun Jul 20 17:07:27 CDT 2014


Author: mjordan
Date: Sun Jul 20 17:06:33 2014
New Revision: 419044

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=419044
Log:
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) 
  

Added:
    trunk/channels/iax2/codec_pref.c
      - copied unchanged from r419043, team/group/media_formats-reviewed-trunk/channels/iax2/codec_pref.c
    trunk/channels/iax2/format_compatibility.c
      - copied unchanged from r419043, team/group/media_formats-reviewed-trunk/channels/iax2/format_compatibility.c
    trunk/channels/iax2/include/codec_pref.h
      - copied unchanged from r419043, team/group/media_formats-reviewed-trunk/channels/iax2/include/codec_pref.h
    trunk/channels/iax2/include/format_compatibility.h
      - copied unchanged from r419043, team/group/media_formats-reviewed-trunk/channels/iax2/include/format_compatibility.h
    trunk/include/asterisk/codec.h
      - copied unchanged from r419043, team/group/media_formats-reviewed-trunk/include/asterisk/codec.h
    trunk/include/asterisk/format_cache.h
      - copied unchanged from r419043, team/group/media_formats-reviewed-trunk/include/asterisk/format_cache.h
    trunk/include/asterisk/format_compatibility.h
      - copied unchanged from r419043, team/group/media_formats-reviewed-trunk/include/asterisk/format_compatibility.h
    trunk/include/asterisk/smoother.h
      - copied unchanged from r419043, team/group/media_formats-reviewed-trunk/include/asterisk/smoother.h
    trunk/main/codec.c
      - copied unchanged from r419043, team/group/media_formats-reviewed-trunk/main/codec.c
    trunk/main/codec_builtin.c
      - copied unchanged from r419043, team/group/media_formats-reviewed-trunk/main/codec_builtin.c
    trunk/main/format_cache.c
      - copied unchanged from r419043, team/group/media_formats-reviewed-trunk/main/format_cache.c
    trunk/main/format_compatibility.c
      - copied unchanged from r419043, team/group/media_formats-reviewed-trunk/main/format_compatibility.c
    trunk/main/smoother.c
      - copied unchanged from r419043, team/group/media_formats-reviewed-trunk/main/smoother.c
    trunk/tests/test_core_codec.c
      - copied unchanged from r419043, team/group/media_formats-reviewed-trunk/tests/test_core_codec.c
    trunk/tests/test_core_format.c
      - copied unchanged from r419043, team/group/media_formats-reviewed-trunk/tests/test_core_format.c
    trunk/tests/test_format_cache.c
      - copied unchanged from r419043, team/group/media_formats-reviewed-trunk/tests/test_format_cache.c
    trunk/tests/test_format_cap.c
      - copied unchanged from r419043, team/group/media_formats-reviewed-trunk/tests/test_format_cap.c
Removed:
    trunk/include/asterisk/format_pref.h
    trunk/main/format_pref.c
    trunk/tests/test_format_api.c
Modified:
    trunk/UPGRADE.txt
    trunk/addons/chan_mobile.c
    trunk/addons/chan_ooh323.c
    trunk/addons/chan_ooh323.h
    trunk/addons/format_mp3.c
    trunk/addons/ooh323cDriver.c
    trunk/addons/ooh323cDriver.h
    trunk/apps/app_agent_pool.c
    trunk/apps/app_alarmreceiver.c
    trunk/apps/app_amd.c
    trunk/apps/app_chanspy.c
    trunk/apps/app_confbridge.c
    trunk/apps/app_dictate.c
    trunk/apps/app_dumpchan.c
    trunk/apps/app_echo.c
    trunk/apps/app_fax.c
    trunk/apps/app_festival.c
    trunk/apps/app_ices.c
    trunk/apps/app_jack.c
    trunk/apps/app_meetme.c
    trunk/apps/app_milliwatt.c
    trunk/apps/app_mixmonitor.c
    trunk/apps/app_mp3.c
    trunk/apps/app_nbscat.c
    trunk/apps/app_originate.c
    trunk/apps/app_record.c
    trunk/apps/app_sms.c
    trunk/apps/app_speech_utils.c
    trunk/apps/app_talkdetect.c
    trunk/apps/app_test.c
    trunk/apps/app_voicemail.c
    trunk/apps/app_waitforsilence.c
    trunk/apps/confbridge/conf_chan_record.c
    trunk/bridges/bridge_holding.c
    trunk/bridges/bridge_native_rtp.c
    trunk/bridges/bridge_simple.c
    trunk/bridges/bridge_softmix.c
    trunk/channels/chan_alsa.c
    trunk/channels/chan_bridge_media.c
    trunk/channels/chan_console.c
    trunk/channels/chan_dahdi.c
    trunk/channels/chan_iax2.c
    trunk/channels/chan_mgcp.c
    trunk/channels/chan_misdn.c
    trunk/channels/chan_motif.c
    trunk/channels/chan_multicast_rtp.c
    trunk/channels/chan_nbs.c
    trunk/channels/chan_oss.c
    trunk/channels/chan_phone.c
    trunk/channels/chan_pjsip.c
    trunk/channels/chan_sip.c
    trunk/channels/chan_skinny.c
    trunk/channels/chan_unistim.c
    trunk/channels/chan_vpb.cc
    trunk/channels/dahdi/bridge_native_dahdi.c
    trunk/channels/iax2/parser.c
    trunk/channels/iax2/provision.c
    trunk/channels/pjsip/dialplan_functions.c
    trunk/channels/sip/include/sip.h
    trunk/codecs/codec_a_mu.c
    trunk/codecs/codec_adpcm.c
    trunk/codecs/codec_alaw.c
    trunk/codecs/codec_dahdi.c
    trunk/codecs/codec_g722.c
    trunk/codecs/codec_g726.c
    trunk/codecs/codec_gsm.c
    trunk/codecs/codec_ilbc.c
    trunk/codecs/codec_lpc10.c
    trunk/codecs/codec_resample.c
    trunk/codecs/codec_speex.c
    trunk/codecs/codec_ulaw.c
    trunk/codecs/ex_adpcm.h
    trunk/codecs/ex_alaw.h
    trunk/codecs/ex_g722.h
    trunk/codecs/ex_g726.h
    trunk/codecs/ex_gsm.h
    trunk/codecs/ex_ilbc.h
    trunk/codecs/ex_lpc10.h
    trunk/codecs/ex_speex.h
    trunk/codecs/ex_ulaw.h
    trunk/formats/format_g719.c
    trunk/formats/format_g723.c
    trunk/formats/format_g726.c
    trunk/formats/format_g729.c
    trunk/formats/format_gsm.c
    trunk/formats/format_h263.c
    trunk/formats/format_h264.c
    trunk/formats/format_ilbc.c
    trunk/formats/format_jpeg.c
    trunk/formats/format_ogg_vorbis.c
    trunk/formats/format_pcm.c
    trunk/formats/format_siren14.c
    trunk/formats/format_siren7.c
    trunk/formats/format_sln.c
    trunk/formats/format_vox.c
    trunk/formats/format_wav.c
    trunk/formats/format_wav_gsm.c
    trunk/funcs/func_channel.c
    trunk/funcs/func_frame_trace.c
    trunk/funcs/func_pitchshift.c
    trunk/funcs/func_speex.c
    trunk/funcs/func_talkdetect.c
    trunk/include/asterisk/_private.h
    trunk/include/asterisk/abstract_jb.h
    trunk/include/asterisk/audiohook.h
    trunk/include/asterisk/bridge_channel.h
    trunk/include/asterisk/callerid.h
    trunk/include/asterisk/channel.h
    trunk/include/asterisk/config_options.h
    trunk/include/asterisk/data.h
    trunk/include/asterisk/file.h
    trunk/include/asterisk/format.h
    trunk/include/asterisk/format_cap.h
    trunk/include/asterisk/frame.h
    trunk/include/asterisk/image.h
    trunk/include/asterisk/mod_format.h
    trunk/include/asterisk/res_pjsip.h
    trunk/include/asterisk/res_pjsip_session.h
    trunk/include/asterisk/rtp_engine.h
    trunk/include/asterisk/slin.h
    trunk/include/asterisk/slinfactory.h
    trunk/include/asterisk/speech.h
    trunk/include/asterisk/translate.h
    trunk/include/asterisk/vector.h
    trunk/main/abstract_jb.c
    trunk/main/app.c
    trunk/main/asterisk.c
    trunk/main/audiohook.c
    trunk/main/bridge.c
    trunk/main/bridge_basic.c
    trunk/main/bridge_channel.c
    trunk/main/callerid.c
    trunk/main/ccss.c
    trunk/main/channel.c
    trunk/main/channel_internal_api.c
    trunk/main/cli.c
    trunk/main/config_options.c
    trunk/main/core_local.c
    trunk/main/core_unreal.c
    trunk/main/data.c
    trunk/main/dial.c
    trunk/main/dsp.c
    trunk/main/file.c
    trunk/main/format.c
    trunk/main/format_cap.c
    trunk/main/frame.c
    trunk/main/image.c
    trunk/main/indications.c
    trunk/main/manager.c
    trunk/main/media_index.c
    trunk/main/rtp_engine.c
    trunk/main/slinfactory.c
    trunk/main/sorcery.c
    trunk/main/sounds_index.c
    trunk/main/translate.c
    trunk/main/utils.c
    trunk/pbx/pbx_spool.c
    trunk/res/ari/resource_bridges.c
    trunk/res/ari/resource_channels.c
    trunk/res/ari/resource_sounds.c
    trunk/res/parking/parking_applications.c
    trunk/res/res_adsi.c
    trunk/res/res_agi.c
    trunk/res/res_calendar.c
    trunk/res/res_clioriginate.c
    trunk/res/res_fax.c
    trunk/res/res_fax_spandsp.c
    trunk/res/res_format_attr_celt.c
    trunk/res/res_format_attr_h263.c
    trunk/res/res_format_attr_h264.c
    trunk/res/res_format_attr_opus.c
    trunk/res/res_format_attr_silk.c
    trunk/res/res_musiconhold.c
    trunk/res/res_pjsip/pjsip_configuration.c
    trunk/res/res_pjsip_sdp_rtp.c
    trunk/res/res_pjsip_session.c
    trunk/res/res_rtp_asterisk.c
    trunk/res/res_rtp_multicast.c
    trunk/res/res_speech.c
    trunk/res/res_stasis.c
    trunk/res/res_stasis_snoop.c
    trunk/tests/test_abstract_jb.c
    trunk/tests/test_cel.c
    trunk/tests/test_config.c
    trunk/tests/test_voicemail_api.c

Modified: trunk/UPGRADE.txt
URL: http://svnview.digium.com/svn/asterisk/trunk/UPGRADE.txt?view=diff&rev=419044&r1=419043&r2=419044
==============================================================================
--- trunk/UPGRADE.txt (original)
+++ trunk/UPGRADE.txt Sun Jul 20 17:06:33 2014
@@ -208,6 +208,32 @@
    progress indications into a 180 Ringing (if a 180 has not yet been
    transmitted) if 'progressinband=never'.
 
+  - The codec preference order in an SDP during an offer is slightly different
+    than previous releases. Prior to Asterisk 13, the preference order of
+    codecs used to be:
+    (1) Our preferred codec
+    (2) Our configured codecs
+    (3) Any non-audio joint codecs
+
+    One of the ways the new media format architecture in Asterisk 13 improves
+    performance is by reference counting formats, such that they can be reused
+    in many places without additional allocation. To not require a large
+    amount of locking, an instance of a format is immutable by convention.
+    This works well except for formats with attributes. Since a media format
+    with an attribute is a different object than the same format without an
+    attribute, we have to carry over the formats with attributes from an
+    inbound offer so that the correct attributes are offered in an outgoing
+    INVITE request. This requires some subtle tweaks to the preference order
+    to ensure that the media format with attributes is offered to a remote
+    peer, as opposed to the same media format (but without attributes) that
+    may be stored in the peer object.
+
+    All of this means that our offer offer list will now be:
+    (1) Our preferred codec
+    (2) Any joint codecs offered by the inbound offer
+    (3) All other codecs that are not the preferred codec and not a joint
+        codec offered by the inbound offer
+
 CLI commands:
  - "core show settings" now lists the current console verbosity in addition
    to the root console verbosity.

Modified: trunk/addons/chan_mobile.c
URL: http://svnview.digium.com/svn/asterisk/trunk/addons/chan_mobile.c?view=diff&rev=419044&r1=419043&r2=419044
==============================================================================
--- trunk/addons/chan_mobile.c (original)
+++ trunk/addons/chan_mobile.c Sun Jul 20 17:06:33 2014
@@ -73,15 +73,15 @@
 #include "asterisk/app.h"
 #include "asterisk/manager.h"
 #include "asterisk/io.h"
+#include "asterisk/smoother.h"
+#include "asterisk/format_cache.h"
 
 #define MBL_CONFIG "chan_mobile.conf"
 #define MBL_CONFIG_OLD "mobile.conf"
 
 #define DEVICE_FRAME_SIZE 48
-#define DEVICE_FRAME_FORMAT AST_FORMAT_SLINEAR
+#define DEVICE_FRAME_FORMAT ast_format_slin
 #define CHANNEL_FRAME_SIZE 320
-
-static struct ast_format prefformat;
 
 static int discovery_interval = 60;			/* The device discovery interval, default 60 seconds. */
 static pthread_t discovery_thread = AST_PTHREADT_NULL;	/* The discovery thread */
@@ -840,7 +840,6 @@
 static struct ast_channel *mbl_new(int state, struct mbl_pvt *pvt, char *cid_num,
 		const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor)
 {
-
 	struct ast_channel *chn;
 
 	pvt->answered = 0;
@@ -862,11 +861,11 @@
 	}
 
 	ast_channel_tech_set(chn, &mbl_tech);
-	ast_format_cap_add(ast_channel_nativeformats(chn), &prefformat);
-	ast_format_copy(ast_channel_rawreadformat(chn), &prefformat);
-	ast_format_copy(ast_channel_rawwriteformat(chn), &prefformat);
-	ast_format_copy(ast_channel_writeformat(chn), &prefformat);
-	ast_format_copy(ast_channel_readformat(chn), &prefformat);
+	ast_channel_nativeformats_set(chn, mbl_tech.capabilities);
+	ast_channel_set_rawreadformat(chn, DEVICE_FRAME_FORMAT);
+	ast_channel_set_rawwriteformat(chn, DEVICE_FRAME_FORMAT);
+	ast_channel_set_writeformat(chn, DEVICE_FRAME_FORMAT);
+	ast_channel_set_readformat(chn, DEVICE_FRAME_FORMAT);
 	ast_channel_tech_pvt_set(chn, pvt);
 
 	if (state == AST_STATE_RING)
@@ -902,9 +901,9 @@
 		return NULL;
 	}
 
-	if (!(ast_format_cap_iscompatible(cap, &prefformat))) {
-		char tmp[256];
-		ast_log(LOG_WARNING, "Asked to get a channel of unsupported format '%s'\n", ast_getformatname_multiple(tmp, sizeof(tmp), cap));
+	if (ast_format_cap_iscompatible_format(cap, DEVICE_FRAME_FORMAT) == AST_FORMAT_CMP_NOT_EQUAL) {
+		struct ast_str *codec_buf = ast_str_alloca(64);
+		ast_log(LOG_WARNING, "Asked to get a channel of unsupported format '%s'\n", ast_format_cap_get_names(cap, &codec_buf));
 		*cause = AST_CAUSE_FACILITY_NOT_IMPLEMENTED;
 		return NULL;
 	}
@@ -1116,7 +1115,7 @@
 
 	memset(&pvt->fr, 0x00, sizeof(struct ast_frame));
 	pvt->fr.frametype = AST_FRAME_VOICE;
-	ast_format_set(&pvt->fr.subclass.format, DEVICE_FRAME_FORMAT, 0);
+	pvt->fr.subclass.format = DEVICE_FRAME_FORMAT;
 	pvt->fr.src = "Mobile";
 	pvt->fr.offset = AST_FRIENDLY_OFFSET;
 	pvt->fr.mallocd = 0;
@@ -4697,7 +4696,8 @@
 	if (sdp_session)
 		sdp_close(sdp_session);
 
-	mbl_tech.capabilities = ast_format_cap_destroy(mbl_tech.capabilities);
+	ao2_ref(mbl_tech.capabilities, -1);
+	mbl_tech.capabilities = NULL;
 	return 0;
 }
 
@@ -4706,11 +4706,11 @@
 
 	int dev_id, s;
 
-	if (!(mbl_tech.capabilities = ast_format_cap_alloc(0))) {
+	if (!(mbl_tech.capabilities = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT))) {
 		return AST_MODULE_LOAD_DECLINE;
 	}
-	ast_format_set(&prefformat, DEVICE_FRAME_FORMAT, 0);
-	ast_format_cap_add(mbl_tech.capabilities, &prefformat);
+
+	ast_format_cap_append(mbl_tech.capabilities, DEVICE_FRAME_FORMAT, 0);
 	/* Check if we have Bluetooth, no point loading otherwise... */
 	dev_id = hci_get_route(NULL);
 	s = hci_open_dev(dev_id);

Modified: trunk/addons/chan_ooh323.c
URL: http://svnview.digium.com/svn/asterisk/trunk/addons/chan_ooh323.c?view=diff&rev=419044&r1=419043&r2=419044
==============================================================================
--- trunk/addons/chan_ooh323.c (original)
+++ trunk/addons/chan_ooh323.c Sun Jul 20 17:06:33 2014
@@ -91,8 +91,6 @@
           struct ast_rtp_instance *vrtp, struct ast_rtp_instance *trtp, const struct ast_format_cap *codecs, int nat_active);
 static void ooh323_get_codec(struct ast_channel *chan, struct ast_format_cap *result);
 void setup_rtp_remote(ooCallData *call, const char *remoteIp, int remotePort);
-
-static void print_codec_to_cli(int fd, struct ast_codec_pref *pref);
 
 struct ooh323_peer *find_friend(const char *name, int port);
 
@@ -174,10 +172,9 @@
 	char callee_url[AST_MAX_EXTENSION];
  
 	int port;
-	struct ast_format readformat;   /* negotiated read format */
-	struct ast_format writeformat;  /* negotiated write format */
+	struct ast_format *readformat;   /* negotiated read format */
+	struct ast_format *writeformat;  /* negotiated write format */
 	struct ast_format_cap *cap;
-	struct ast_codec_pref prefs;
 	int dtmfmode;
 	int dtmfcodec;
 	char exten[AST_MAX_EXTENSION];	/* Requested extension */
@@ -212,7 +209,6 @@
 	char		accountcode[20];
 	int		amaflags;
 	struct ast_format_cap *cap;
-	struct ast_codec_pref prefs;
 	int		dtmfmode;
 	int		dtmfcodec;
 	int		faxdetect;
@@ -239,7 +235,6 @@
 	unsigned    outgoinglimit;
 	unsigned    outUse;
 	struct ast_format_cap *cap;
-	struct ast_codec_pref prefs;
 	char        accountcode[20];
 	int         amaflags;
 	int         dtmfmode;
@@ -307,7 +302,6 @@
 static char gCallerID[AST_MAX_EXTENSION] = "";
 static struct ooAliases *gAliasList;
 static struct ast_format_cap *gCap;
-static struct ast_codec_pref gPrefs;
 static int  gDTMFMode = H323_DTMF_RFC2833;
 static int  gDTMFCodec = 101;
 static int  gFAXdetect = FAXDETECT_CNG;
@@ -366,15 +360,17 @@
                                              const char *host, struct ast_format_cap *cap, 
 											 const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor)
 {
+	struct ast_format_cap *caps = NULL;
 	struct ast_channel *ch = NULL;
-	struct ast_format tmpfmt;
+	struct ast_format *tmpfmt = NULL;
 	int features = 0;
 
 	if (gH323Debug) {
 		ast_verb(0, "---   ooh323_new - %s\n", host);
 	}
 
-	ast_format_clear(&tmpfmt);
+	caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+
 	/* Don't hold a h323 pvt lock while we allocate a channel */
 	ast_mutex_unlock(&i->lock);
    	ast_mutex_lock(&ooh323c_cn_lock);
@@ -386,17 +382,25 @@
    
 	ast_mutex_lock(&i->lock);
 
-	if (ch) {
+	if (ch && caps) {
 		ast_channel_tech_set(ch, &ooh323_tech);
 
-		if (cap)
-			ast_best_codec(cap, &tmpfmt);
-		if (!tmpfmt.id)
-			ast_codec_pref_index(&i->prefs, 0, &tmpfmt);
-
-		ast_format_cap_add(ast_channel_nativeformats(ch), &tmpfmt);
-		ast_format_copy(ast_channel_rawwriteformat(ch), &tmpfmt);
-		ast_format_copy(ast_channel_rawreadformat(ch), &tmpfmt);
+		if (cap) {
+			tmpfmt = ast_format_cap_get_format(cap, 0);
+		}
+		if (!tmpfmt) {
+			tmpfmt = ast_format_cap_get_format(i->cap, 0);
+		}
+
+		ast_format_cap_append(caps, tmpfmt, 0);
+		ast_channel_nativeformats_set(ch, caps);
+		ao2_ref(caps, -1);
+
+		ast_channel_set_rawwriteformat(ch, tmpfmt);
+		ast_channel_set_rawreadformat(ch, tmpfmt);
+		ast_set_write_format(ch, tmpfmt);
+		ast_set_read_format(ch, tmpfmt);
+		ao2_ref(tmpfmt, -1);
 
 		ast_jb_configure(ch, &global_jbconf);
 
@@ -404,8 +408,6 @@
 			ast_channel_rings_set(ch, 1);
 
 		ast_channel_adsicpe_set(ch, AST_ADSI_UNAVAILABLE);
-		ast_set_write_format(ch, &tmpfmt);
-		ast_set_read_format(ch, &tmpfmt);
 		ast_channel_tech_pvt_set(ch, i);
 		i->owner = ch;
 		ast_module_ref(myself);
@@ -485,8 +487,10 @@
 			ast_publish_channel_state(ch);
 
 		}
-	} else
+	} else {
+		ao2_cleanup(caps);
 		ast_log(LOG_WARNING, "Unable to allocate channel structure\n");
+	}
 
 
    	if(ch)   ast_channel_unlock(ch);
@@ -512,7 +516,7 @@
 		ast_log(LOG_ERROR, "Couldn't allocate private ooh323 structure\n");
 		return NULL;
 	}
-	if (!(pvt->cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK))) {
+	if (!(pvt->cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT))) {
 		ast_free(pvt);
 		ast_log(LOG_ERROR, "Couldn't allocate private ooh323 structure\n");
 		return NULL;
@@ -546,8 +550,7 @@
 	ast_copy_string(pvt->accountcode, gAccountcode, sizeof(pvt->accountcode));
 
 	pvt->amaflags = gAMAFLAGS;
-	ast_format_cap_copy(pvt->cap, gCap);
-	memcpy(&pvt->prefs, &gPrefs, sizeof(pvt->prefs));
+	ast_format_cap_append_from_cap(pvt->cap, gCap, AST_MEDIA_TYPE_UNKNOWN);
 
 	pvt->aniasdni = gANIasDNI;
 
@@ -573,21 +576,21 @@
 		const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *data, int *cause)
 
 {
+	struct ast_str *codec_buf = ast_str_alloca(64);
 	struct ast_channel *chan = NULL;
 	struct ooh323_pvt *p = NULL;
 	struct ooh323_peer *peer = NULL;
 	char *dest = NULL; 
 	char *ext = NULL;
 	char tmp[256];
-	char formats[FORMAT_STRING_SIZE];
 	int port = 0;
 
-	if (gH323Debug)
-		ast_verb(0, "---   ooh323_request - data %s format %s\n", data,
-										ast_getformatname_multiple(formats,FORMAT_STRING_SIZE,cap));
-
-	if (!(ast_format_cap_has_type(cap, AST_FORMAT_TYPE_AUDIO))) {
-		ast_log(LOG_NOTICE, "Asked to get a channel of unsupported format '%s'\n", ast_getformatname_multiple(formats,FORMAT_STRING_SIZE,cap));
+	if (gH323Debug) {
+		ast_verb(0, "---   ooh323_request - data %s format %s\n", data, ast_format_cap_get_names(cap, &codec_buf));
+	}
+
+	if (!(ast_format_cap_has_type(cap, AST_MEDIA_TYPE_AUDIO))) {
+		ast_log(LOG_NOTICE, "Asked to get a channel of unsupported format '%s'\n", ast_format_cap_get_names(cap, &codec_buf));
 		return NULL;
 	}
 
@@ -651,8 +654,7 @@
 		if (ext)
 			ast_copy_string(p->exten, ext, sizeof(p->exten));
 
-		ast_format_cap_copy(p->cap, peer->cap);
-		memcpy(&p->prefs, &peer->prefs, sizeof(struct ast_codec_pref));
+		ast_format_cap_append_from_cap(p->cap, peer->cap, AST_MEDIA_TYPE_UNKNOWN);
 		p->g729onlyA = peer->g729onlyA;
 		p->dtmfmode |= peer->dtmfmode;
 		p->dtmfcodec  = peer->dtmfcodec;
@@ -697,7 +699,7 @@
 		p->t38support = gT38Support;
 		p->rtptimeout = gRTPTimeout;
 		p->nat = gNat;
-		ast_format_cap_copy(p->cap, gCap);
+		ast_format_cap_append_from_cap(p->cap, gCap, AST_MEDIA_TYPE_UNKNOWN);
 		p->rtdrinterval = gRTDRInterval;
 		p->rtdrcount = gRTDRCount;
 		p->faststart = gFastStart;
@@ -705,7 +707,6 @@
 		p->directrtp = gDirectRTP;
 		p->earlydirect = gEarlyDirect;
 
-		memcpy(&p->prefs, &gPrefs, sizeof(struct ast_codec_pref));
 		p->username = strdup(dest);
 
 		p->host = strdup(dest);
@@ -1164,7 +1165,6 @@
 {
 	struct ooh323_pvt *p = ast_channel_tech_pvt(ast);
 	int res = 0;
-	char buf[256];
 
 	if (p) {
 		ast_mutex_lock(&p->lock);
@@ -1190,16 +1190,17 @@
 			}
 
 
-			if (!(ast_format_cap_iscompatible(ast_channel_nativeformats(ast), &f->subclass.format))) {
-				if (!(ast_format_cap_is_empty(ast_channel_nativeformats(ast)))) {
+			if (ast_format_cap_iscompatible_format(ast_channel_nativeformats(ast), f->subclass.format) == AST_FORMAT_CMP_NOT_EQUAL) {
+				if (ast_format_cap_count(ast_channel_nativeformats(ast))) {
+					struct ast_str *codec_buf = ast_str_alloca(64);
 					ast_log(LOG_WARNING,
 							"Asked to transmit frame type %s, while native formats is %s (read/write = %s/%s)\n",
-							ast_getformatname(&f->subclass.format),
-							ast_getformatname_multiple(buf, sizeof(buf), ast_channel_nativeformats(ast)),
-							ast_getformatname(ast_channel_readformat(ast)),
-							ast_getformatname(ast_channel_writeformat(ast)));
-
-					ast_set_write_format(ast, &f->subclass.format);
+							ast_format_get_name(f->subclass.format),
+							ast_format_cap_get_names(ast_channel_nativeformats(ast), &codec_buf),
+							ast_format_get_name(ast_channel_readformat(ast)),
+							ast_format_get_name(ast_channel_writeformat(ast)));
+
+					ast_set_write_format(ast, f->subclass.format);
 				} else {
 					/* ast_set_write_format(ast, f->subclass);
 					ast->nativeformats = f->subclass; */
@@ -1508,11 +1509,10 @@
 void ooh323_set_write_format(ooCallData *call, struct ast_format *fmt, int txframes)
 {
 	struct ooh323_pvt *p = NULL;
-	char formats[FORMAT_STRING_SIZE];
 
 	if (gH323Debug)
 		ast_verb(0, "---   ooh323_update_writeformat %s/%d\n", 
-				ast_getformatname(fmt), txframes);
+				ast_format_get_name(fmt), txframes);
 	
 	p = find_call(call);
 	if (!p) {
@@ -1522,9 +1522,17 @@
 
 	ast_mutex_lock(&p->lock);
 
-	ast_format_copy(&(p->writeformat), fmt);
+	ao2_replace(p->writeformat, fmt);
 
 	if (p->owner) {
+		struct ast_format_cap *caps;
+
+		caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+		if (!caps) {
+			ast_log(LOG_ERROR, "Could not allocate capabilities structure\n");
+			return;
+		}
+
 		while (p->owner && ast_channel_trylock(p->owner)) {
 			ast_debug(1,"Failed to grab lock, trying again\n");
 			DEADLOCK_AVOIDANCE(&p->lock);
@@ -1532,15 +1540,16 @@
 		if (!p->owner) {
 			ast_mutex_unlock(&p->lock);
 			ast_log(LOG_ERROR, "Channel has no owner\n");
+			ao2_ref(caps, -1);
 			return;
 		}
-		if (gH323Debug)
-	  		ast_verb(0, "Writeformat before update %s/%s\n", 
-			  ast_getformatname(ast_channel_writeformat(p->owner)),
-			  ast_getformatname_multiple(formats, sizeof(formats), ast_channel_nativeformats(p->owner)));
-		if (txframes)
-			ast_codec_pref_setsize(&p->prefs, fmt, txframes);
-		ast_rtp_codecs_packetization_set(ast_rtp_instance_get_codecs(p->rtp), p->rtp, &p->prefs);
+		if (gH323Debug) {
+			struct ast_str *codec_buf = ast_str_alloca(64);
+			ast_verb(0, "Writeformat before update %s/%s\n", 
+			  ast_format_get_name(ast_channel_writeformat(p->owner)),
+			  ast_format_cap_get_names(ast_channel_nativeformats(p->owner), &codec_buf));
+		}
+
 		if (p->dtmfmode & H323_DTMF_RFC2833 && p->dtmfcodec) {
 			ast_rtp_codecs_payloads_set_rtpmap_type(ast_rtp_instance_get_codecs(p->rtp),
 				 p->rtp, p->dtmfcodec, "audio", "telephone-event", 0);
@@ -1550,7 +1559,12 @@
 				 p->rtp, p->dtmfcodec, "audio", "cisco-telephone-event", 0);
 		}
 
-		ast_format_cap_set(ast_channel_nativeformats(p->owner), fmt);
+		if (txframes) {
+			ast_format_cap_set_framing(caps, txframes);
+		}
+		ast_format_cap_append(caps, fmt, 0);
+		ast_channel_nativeformats_set(p->owner, caps);
+		ao2_ref(caps, -1);
 	  	ast_set_write_format(p->owner, ast_channel_writeformat(p->owner));
 	  	ast_set_read_format(p->owner, ast_channel_readformat(p->owner));
 		ast_channel_unlock(p->owner);
@@ -1570,7 +1584,7 @@
 
 	if (gH323Debug)
 		ast_verb(0, "---   ooh323_update_readformat %s\n", 
-				ast_getformatname(fmt));
+				ast_format_get_name(fmt));
 	
 	p = find_call(call);
 	if (!p) {
@@ -1580,9 +1594,17 @@
 
 	ast_mutex_lock(&p->lock);
 
-	ast_format_copy(&(p->readformat), fmt);
+	ao2_replace(p->readformat, fmt);
 
 	if (p->owner) {
+		struct ast_format_cap *caps;
+
+		caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+		if (!caps) {
+			ast_log(LOG_ERROR, "Could not allocate capabilities structure\n");
+			return;
+		}
+
 		while (p->owner && ast_channel_trylock(p->owner)) {
 			ast_debug(1,"Failed to grab lock, trying again\n");
 			DEADLOCK_AVOIDANCE(&p->lock);
@@ -1590,14 +1612,18 @@
 		if (!p->owner) {
 			ast_mutex_unlock(&p->lock);
 			ast_log(LOG_ERROR, "Channel has no owner\n");
+			ao2_ref(caps, -1);
 			return;
 		}
 
-		if (gH323Debug)
-	  		ast_verb(0, "Readformat before update %s\n", 
-				  ast_getformatname(ast_channel_readformat(p->owner)));
-		ast_format_cap_set(ast_channel_nativeformats(p->owner), fmt);
-	  	ast_set_read_format(p->owner, ast_channel_readformat(p->owner));
+		if (gH323Debug) {
+			ast_verb(0, "Readformat before update %s\n", 
+			  ast_format_get_name(ast_channel_readformat(p->owner)));
+		}
+		ast_format_cap_append(caps, fmt, 0);
+		ast_channel_nativeformats_set(p->owner, caps);
+		ao2_ref(caps, -1);
+		ast_set_read_format(p->owner, ast_channel_readformat(p->owner));
 		ast_channel_unlock(p->owner);
    	} else
 		ast_log(LOG_ERROR, "No owner found\n");
@@ -1854,9 +1880,8 @@
 		ast_copy_string(p->context, user->context, sizeof(p->context));
 		ast_copy_string(p->accountcode, user->accountcode, sizeof(p->accountcode));
 		p->amaflags = user->amaflags;
-		ast_format_cap_copy(p->cap, user->cap);
+		ast_format_cap_append_from_cap(p->cap, user->cap, AST_MEDIA_TYPE_UNKNOWN);
 		p->g729onlyA = user->g729onlyA;
-		memcpy(&p->prefs, &user->prefs, sizeof(struct ast_codec_pref));
 		p->dtmfmode |= user->dtmfmode;
 		p->dtmfcodec = user->dtmfcodec;
 		p->faxdetect = user->faxdetect;
@@ -1914,7 +1939,7 @@
 	 }
 	}
 
-	ooh323c_set_capability_for_call(call, &p->prefs, p->cap, p->dtmfmode, p->dtmfcodec,
+	ooh323c_set_capability_for_call(call, p->cap, p->dtmfmode, p->dtmfcodec,
 					 p->t38support, p->g729onlyA);
 /* Incoming call */
   	c = ooh323_new(p, AST_STATE_RING, p->username, 0, NULL, NULL);
@@ -2088,13 +2113,14 @@
 		}
 
 		if (gH323Debug) {
-			char prefsBuf[256];
-			ast_codec_pref_string(&p->prefs, prefsBuf, sizeof(prefsBuf));
+			struct ast_str *codec_buf = ast_str_alloca(64);
+
 			ast_verb(0, " Outgoing call %s(%s) - Codec prefs - %s\n", 
-				p->username?p->username:"NULL", call->callToken, prefsBuf);
-		}
-
-      		ooh323c_set_capability_for_call(call, &p->prefs, p->cap,
+				p->username?p->username:"NULL", call->callToken,
+				ast_format_cap_get_names(p->cap, &codec_buf));
+		}
+
+      		ooh323c_set_capability_for_call(call, p->cap,
                                      p->dtmfmode, p->dtmfcodec, p->t38support, p->g729onlyA);
 
 		configure_local_rtp(p, call);
@@ -2284,7 +2310,7 @@
       if(peer->url)      free(peer->url);
       if(peer->e164)     free(peer->e164);
 
-		peer->cap = ast_format_cap_destroy(peer->cap);
+      ao2_cleanup(peer->cap);
 		free(peer);
 	}  
 
@@ -2311,8 +2337,7 @@
 		}
 		ast_mutex_init(&user->lock);
 		ast_copy_string(user->name, name, sizeof(user->name));
-		ast_format_cap_copy(user->cap, gCap);
-		memcpy(&user->prefs, &gPrefs, sizeof(user->prefs));
+		ast_format_cap_append_from_cap(user->cap, gCap, AST_MEDIA_TYPE_UNKNOWN);
 		user->rtptimeout = gRTPTimeout;
 		user->nat = gNat;
 		user->dtmfmode = gDTMFMode;
@@ -2367,15 +2392,13 @@
 								sizeof(user->rtpmaskstr));
 				} else user->rtpmask = NULL;
 			} else if (!strcasecmp(v->name, "disallow")) {
-				ast_parse_allow_disallow(&user->prefs, 
-					user->cap,  v->value, 0);
+				ast_format_cap_update_by_allow_disallow(user->cap,  v->value, 0);
 			} else if (!strcasecmp(v->name, "allow")) {
 				const char* tcodecs = v->value;
 				if (!strcasecmp(v->value, "all")) {
 					tcodecs = "ulaw,alaw,g729,g723,gsm";
 				}
-				ast_parse_allow_disallow(&user->prefs,
-					 user->cap,  tcodecs, 1);
+				ast_format_cap_update_by_allow_disallow(user->cap,  tcodecs, 1);
 			} else if (!strcasecmp(v->name, "amaflags")) {

[... 29776 lines stripped ...]



More information about the asterisk-commits mailing list