[svn-commits] file: branch group/media_formats-reviewed r413482 - in /team/group/media_form...
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Wed May 7 17:22:50 CDT 2014
Author: file
Date: Wed May 7 17:22:40 2014
New Revision: 413482
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=413482
Log:
Add a legacy format API and move chan_iax2, chan_h323, and chan_misdn over.
Review: https://reviewboard.asterisk.org/r/3519/
Added:
team/group/media_formats-reviewed/include/asterisk/format_compatibility.h (with props)
team/group/media_formats-reviewed/main/format_compatibility.c (with props)
Modified:
team/group/media_formats-reviewed/apps/app_meetme.c
team/group/media_formats-reviewed/channels/chan_h323.c
team/group/media_formats-reviewed/channels/chan_iax2.c
team/group/media_formats-reviewed/channels/chan_misdn.c
team/group/media_formats-reviewed/channels/chan_phone.c
team/group/media_formats-reviewed/channels/h323/ast_h323.cxx
team/group/media_formats-reviewed/channels/h323/chan_h323.h
team/group/media_formats-reviewed/channels/iax2/parser.c
team/group/media_formats-reviewed/channels/iax2/provision.c
team/group/media_formats-reviewed/codecs/codec_dahdi.c
team/group/media_formats-reviewed/include/asterisk/codec.h
team/group/media_formats-reviewed/include/asterisk/format_cache.h
team/group/media_formats-reviewed/include/asterisk/translate.h
team/group/media_formats-reviewed/main/codec_builtin.c
Modified: team/group/media_formats-reviewed/apps/app_meetme.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed/apps/app_meetme.c?view=diff&rev=413482&r1=413481&r2=413482
==============================================================================
--- team/group/media_formats-reviewed/apps/app_meetme.c (original)
+++ team/group/media_formats-reviewed/apps/app_meetme.c Wed May 7 17:22:40 2014
@@ -77,6 +77,7 @@
#include "asterisk/stasis_channels.h"
#include "asterisk/stasis_message_router.h"
#include "asterisk/json.h"
+#include "asterisk/format_compatibility.h"
#include "enter.h"
#include "leave.h"
@@ -4298,7 +4299,7 @@
)) {
int idx;
for (idx = 0; idx < AST_FRAME_BITS; idx++) {
- if (ast_channel_rawwriteformat(chan)->codec->original_id & (1 << idx)) {
+ if (ast_format_compatibility_format2bitfield(ast_channel_rawwriteformat(chan)) & (1 << idx)) {
break;
}
}
Modified: team/group/media_formats-reviewed/channels/chan_h323.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed/channels/chan_h323.c?view=diff&rev=413482&r1=413481&r2=413482
==============================================================================
--- team/group/media_formats-reviewed/channels/chan_h323.c (original)
+++ team/group/media_formats-reviewed/channels/chan_h323.c Wed May 7 17:22:40 2014
@@ -97,6 +97,8 @@
#include "asterisk/astobj.h"
#include "asterisk/format.h"
#include "asterisk/format_cap.h"
+#include "asterisk/format_cache.h"
+#include "asterisk/format_compatibility.h"
#ifdef __cplusplus
}
@@ -142,13 +144,13 @@
static char default_context[AST_MAX_CONTEXT] = "default";
static struct sockaddr_in bindaddr;
-#define GLOBAL_CAPABILITY (ast_format_id_to_old_bitfield(AST_FORMAT_G723_1) | \
- ast_format_id_to_old_bitfield(AST_FORMAT_GSM) | \
- ast_format_id_to_old_bitfield(AST_FORMAT_ULAW) | \
- ast_format_id_to_old_bitfield(AST_FORMAT_ALAW) | \
- ast_format_id_to_old_bitfield(AST_FORMAT_G729A) | \
- ast_format_id_to_old_bitfield(AST_FORMAT_G726_AAL2) | \
- ast_format_id_to_old_bitfield(AST_FORMAT_H261)) \
+#define GLOBAL_CAPABILITY (ast_format_compatibility_format2bitfield(ast_format_g723) | \
+ ast_format_compatibility_format2bitfield(ast_format_gsm) | \
+ ast_format_compatibility_format2bitfield(ast_format_ulaw) | \
+ ast_format_compatibility_format2bitfield(ast_format_alaw) | \
+ ast_format_compatibility_format2bitfield(ast_format_g729) | \
+ ast_format_compatibility_format2bitfield(ast_format_g726_aal2) | \
+ ast_format_compatibility_format2bitfield(ast_format_h261)) \
/** H.323 configuration values */
static int h323_signalling_port = 1720;
@@ -350,13 +352,22 @@
/*! \brief Channel and private structures should be already locked */
static void __oh323_update_info(struct ast_channel *c, struct oh323_pvt *pvt)
{
- h323_format chan_nativeformats_bits = ast_format_cap_to_old_bitfield(ast_channel_nativeformats(c));
+ h323_format chan_nativeformats_bits = ast_format_compatibility_cap2bitfield(ast_channel_nativeformats(c));
if (chan_nativeformats_bits != pvt->nativeformats) {
- if (h323debug)
- ast_debug(1, "Preparing %s for new native format\n", ast_channel_name(c));
- ast_format_cap_from_old_bitfield(ast_channel_nativeformats(c), pvt->nativeformats);
- ast_set_read_format(c, ast_channel_readformat(c));
- ast_set_write_format(c, ast_channel_writeformat(c));
+ struct ast_format_cap *nativeformats;
+
+ nativeformats = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+ if (nativeformats) {
+ if (h323debug)
+ ast_debug(1, "Preparing %s for new native format\n", ast_channel_name(c));
+
+ ast_format_compatibility_bitfield2cap(pvt->nativeformats, nativeformats);
+ ast_channel_nativeformats_set(c, nativeformats);
+ ast_set_read_format(c, ast_channel_readformat(c));
+ ast_set_write_format(c, ast_channel_writeformat(c));
+
+ ao2_ref(nativeformats, -1);
+ }
}
if (pvt->needhangup) {
if (h323debug)
@@ -784,25 +795,36 @@
if (f && pvt->owner) {
/* We already hold the channel lock */
if (f->frametype == AST_FRAME_VOICE) {
- if (!ast_format_cap_iscompatible(ast_channel_nativeformats(pvt->owner), &f->subclass.format)) {
- /* Try to avoid deadlock */
- if (ast_channel_trylock(pvt->owner)) {
- ast_log(LOG_NOTICE, "Format changed but channel is locked. Ignoring frame...\n");
- return &ast_null_frame;
+ if (!ast_format_cap_iscompatible_format(ast_channel_nativeformats(pvt->owner), f->subclass.format)) {
+ struct ast_format_cap *nativeformats;
+
+ nativeformats = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+
+ if (nativeformats) {
+ /* Try to avoid deadlock */
+ if (ast_channel_trylock(pvt->owner)) {
+ ast_log(LOG_NOTICE, "Format changed but channel is locked. Ignoring frame...\n");
+ return &ast_null_frame;
+ }
+ if (h323debug)
+ ast_debug(1, "Oooh, format changed to '%s'\n", ast_format_get_name(f->subclass.format));
+ ast_format_cap_add(nativeformats, f->subclass.format, 0);
+ ast_channel_nativeformats_set(pvt->owner, nativeformats);
+
+ pvt->nativeformats = ast_format_compatibility_format2bitfield(f->subclass.format);
+
+ ast_set_read_format(pvt->owner, ast_channel_readformat(pvt->owner));
+ ast_set_write_format(pvt->owner, ast_channel_writeformat(pvt->owner));
+ ast_channel_unlock(pvt->owner);
+
+ ao2_ref(nativeformats, -1);
}
- if (h323debug)
- ast_debug(1, "Oooh, format changed to '%s'\n", ast_getformatname(&f->subclass.format));
- ast_format_cap_set(ast_channel_nativeformats(pvt->owner), &f->subclass.format);
-
- pvt->nativeformats = ast_format_to_old_bitfield(&f->subclass.format);
-
- ast_set_read_format(pvt->owner, ast_channel_readformat(pvt->owner));
- ast_set_write_format(pvt->owner,ast_channel_writeformat(pvt->owner));
- ast_channel_unlock(pvt->owner);
}
/* Do in-band DTMF detection */
if ((pvt->options.dtmfmode & H323_DTMF_INBAND) && pvt->vad) {
- if ((pvt->nativeformats & (AST_FORMAT_SLINEAR | AST_FORMAT_ALAW | AST_FORMAT_ULAW))) {
+ if ((pvt->nativeformats & (ast_format_compatibility_format2bitfield(ast_format_slin) |
+ ast_format_compatibility_format2bitfield(ast_format_alaw) |
+ ast_format_compatibility_format2bitfield(ast_format_ulaw)))) {
if (!ast_channel_trylock(pvt->owner)) {
f = ast_dsp_process(pvt->owner, pvt->vad, f);
ast_channel_unlock(pvt->owner);
@@ -810,7 +832,8 @@
else
ast_log(LOG_NOTICE, "Unable to process inband DTMF while channel is locked\n");
} else if (pvt->nativeformats && !pvt->noInbandDtmf) {
- ast_log(LOG_NOTICE, "Inband DTMF is not supported on codec %s. Use RFC2833\n", ast_getformatname(&f->subclass.format));
+ ast_log(LOG_NOTICE, "Inband DTMF is not supported on codec %s. Use RFC2833\n",
+ ast_format_get_name(f->subclass.format));
pvt->noInbandDtmf = 1;
}
if (f &&(f->frametype == AST_FRAME_DTMF)) {
@@ -860,13 +883,13 @@
return 0;
}
} else {
- if (!(ast_format_cap_iscompatible(ast_channel_nativeformats(c), &frame->subclass.format))) {
+ if (!(ast_format_cap_iscompatible_format(ast_channel_nativeformats(c), frame->subclass.format))) {
char tmp[256];
ast_log(LOG_WARNING, "Asked to transmit frame type '%s', while native formats is '%s' (read/write = %s/%s)\n",
- ast_getformatname(&frame->subclass.format),
+ ast_format_get_name(frame->subclass.format),
ast_getformatname_multiple(tmp, sizeof(tmp), ast_channel_nativeformats(c)),
- ast_getformatname(ast_channel_readformat(c)),
- ast_getformatname(ast_channel_writeformat(c)));
+ ast_format_get_name(ast_channel_readformat(c)),
+ ast_format_get_name(ast_channel_writeformat(c)));
return 0;
}
}
@@ -1023,8 +1046,11 @@
if (pvt->dtmf_pt[1] > 0)
ast_rtp_codecs_payloads_set_rtpmap_type(ast_rtp_instance_get_codecs(pvt->rtp), pvt->rtp, pvt->dtmf_pt[1], "audio", "cisco-telephone-event", 0);
+ /* BUGBUG: RTP - Needs to be updated if API changes */
+#if 0
if (pvt->peercapability)
ast_rtp_codecs_packetization_set(ast_rtp_instance_get_codecs(pvt->rtp), pvt->rtp, &pvt->peer_prefs);
+#endif
if (pvt->owner && !ast_channel_trylock(pvt->owner)) {
ast_jb_configure(pvt->owner, &global_jbconf);
@@ -1041,10 +1067,17 @@
/*! \brief Private structure should be locked on a call */
static struct ast_channel *__oh323_new(struct oh323_pvt *pvt, int state, const char *host, const char *linkedid)
{
+ struct ast_format_cap *nativeformats;
struct ast_channel *ch;
char *cid_num, *cid_name;
h323_format fmt;
- struct ast_format tmpfmt;
+ struct ast_format *tmpfmt;
+
+ nativeformats = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+ if (!nativeformats) {
+ ast_log(LOG_WARNING, "Unable to allocate memory for native formats\n");
+ return NULL;
+ }
if (!ast_strlen_zero(pvt->options.cid_num))
cid_num = pvt->options.cid_num;
@@ -1067,17 +1100,21 @@
if (!(fmt = pvt->jointcapability) && !(fmt = pvt->options.capability))
fmt = global_options.capability;
- ast_format_cap_from_old_bitfield(ast_channel_nativeformats(ch), fmt);
- ast_codec_choose(&pvt->options.prefs, ast_channel_nativeformats(ch), 1, &tmpfmt)/* | (pvt->jointcapability & AST_FORMAT_VIDEO_MASK)*/;
-
- ast_format_cap_set(ast_channel_nativeformats(ch), &tmpfmt);
-
- pvt->nativeformats = ast_format_cap_to_old_bitfield(ast_channel_nativeformats(ch));
- ast_best_codec(ast_channel_nativeformats(ch), &tmpfmt);
- ast_format_copy(ast_channel_writeformat(ch), &tmpfmt);
- ast_format_copy(ast_channel_rawwriteformat(ch), &tmpfmt);
- ast_format_copy(ast_channel_readformat(ch), &tmpfmt);
- ast_format_copy(ast_channel_rawreadformat(ch), &tmpfmt);
+ ast_format_compatibility_bitfield2cap(fmt, nativeformats);
+ ast_channel_nativeformats_set(ch, nativeformats);
+
+ ast_best_codec(nativeformats, &tmpfmt);
+
+ ast_format_cap_remove_bytype(nativeformats, AST_MEDIA_TYPE_UNKNOWN);
+ ast_format_cap_add(nativeformats, tmpfmt, 0);
+
+ pvt->nativeformats = ast_format_compatibility_cap2bitfield(nativeformats);
+ ast_channel_set_writeformat(ch, tmpfmt);
+ ast_channel_set_rawwriteformat(ch, tmpfmt);
+ ast_channel_set_readformat(ch, tmpfmt);
+ ast_channel_set_rawreadformat(ch, tmpfmt);
+
+ ao2_ref(tmpfmt, -1);
if (!pvt->rtp)
__oh323_rtp_create(pvt);
#if 0
@@ -1150,6 +1187,9 @@
} else {
ast_log(LOG_WARNING, "Unable to allocate channel structure\n");
}
+
+ ao2_ref(nativeformats, -1);
+
return ch;
}
@@ -1314,15 +1354,15 @@
static int h323_parse_allow_disallow(struct ast_codec_pref *pref, h323_format *formats, const char *list, int allowing)
{
int res;
- struct ast_format_cap *cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
+ struct ast_format_cap *cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
if (!cap) {
return 1;
}
- ast_format_cap_from_old_bitfield(cap, *formats);
- res = ast_parse_allow_disallow(pref, cap, list, allowing);
- *formats = ast_format_cap_to_old_bitfield(cap);
- cap = ast_format_cap_destroy(cap);
+ ast_format_compatibility_bitfield2cap(*formats, cap);
+ res = ast_parse_allow_disallow(cap, list, allowing);
+ *formats = ast_format_compatibility_cap2bitfield(cap);
+ ao2_ref(cap, -1);
return res;
}
@@ -1835,7 +1875,7 @@
ast_log(LOG_WARNING, "Unable to build pvt data for '%s'\n", dest);
return NULL;
}
- if (!(ast_format_cap_has_type(cap, AST_FORMAT_TYPE_AUDIO))) {
+ 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_getformatname_multiple(tmp, sizeof(tmp), cap));
oh323_destroy(pvt);
if (cause)
@@ -2058,7 +2098,7 @@
if (!pvt->rtp)
__oh323_rtp_create(pvt);
- if ((pt == 2) && (pvt->jointcapability & AST_FORMAT_G726_AAL2)) {
+ if ((pt == 2) && (pvt->jointcapability & ast_format_compatibility_format2bitfield(ast_format_g726_aal2))) {
ast_rtp_codecs_payloads_set_rtpmap_type(ast_rtp_instance_get_codecs(pvt->rtp), pvt->rtp, pt, "audio", "G726-32", AST_RTP_OPT_G726_NONSTANDARD);
}
@@ -2091,8 +2131,8 @@
if (pt != 128 && pvt->rtp) { /* Payload type is invalid, so try to use previously decided */
struct ast_rtp_payload_type rtptype = ast_rtp_codecs_payload_lookup(ast_rtp_instance_get_codecs(pvt->rtp), pt);
if (rtptype.asterisk_format) {
- if (pvt->nativeformats != ast_format_to_old_bitfield(&rtptype.format)) {
- pvt->nativeformats = ast_format_to_old_bitfield(&rtptype.format);
+ if (pvt->nativeformats != ast_format_compatibility_format2bitfield(&rtptype.format)) {
+ pvt->nativeformats = ast_format_compatibility_format2bitfield(&rtptype.format);
nativeformats_changed = 1;
}
}
@@ -2102,23 +2142,20 @@
/* Don't try to lock the channel if nothing changed */
if (nativeformats_changed || pvt->options.progress_audio || (rtp_change != NEED_NONE)) {
if (pvt->owner && !ast_channel_trylock(pvt->owner)) {
- struct ast_format_cap *pvt_native = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
- ast_format_cap_from_old_bitfield(pvt_native, pvt->nativeformats);
-
- /* Re-build translation path only if native format(s) has been changed */
- if (!(ast_format_cap_identical(ast_channel_nativeformats(pvt->owner), pvt_native))) {
- if (h323debug) {
- char tmp[256], tmp2[256];
- ast_debug(1, "Native format changed to '%s' from '%s', read format is %s, write format is %s\n",
- ast_getformatname_multiple(tmp, sizeof(tmp), pvt_native),
- ast_getformatname_multiple(tmp2, sizeof(tmp2), ast_channel_nativeformats(pvt->owner)),
- ast_getformatname(ast_channel_readformat(pvt->owner)),
- ast_getformatname(ast_channel_writeformat(pvt->owner)));
- }
- ast_format_cap_copy(ast_channel_nativeformats(pvt->owner), pvt_native);
- ast_set_read_format(pvt->owner, ast_channel_readformat(pvt->owner));
- ast_set_write_format(pvt->owner, ast_channel_writeformat(pvt->owner));
- }
+ struct ast_format_cap *pvt_native = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+ ast_format_compatibility_bitfield2cap(pvt->nativeformats, pvt_native);
+
+ if (h323debug) {
+ char tmp[256], tmp2[256];
+ ast_debug(1, "Native format changed to '%s' from '%s', read format is %s, write format is %s\n",
+ ast_getformatname_multiple(tmp, sizeof(tmp), pvt_native),
+ ast_getformatname_multiple(tmp2, sizeof(tmp2), ast_channel_nativeformats(pvt->owner)),
+ ast_format_get_name(ast_channel_readformat(pvt->owner)),
+ ast_format_get_name(ast_channel_writeformat(pvt->owner)));
+ }
+ ast_channel_nativeformats_set(pvt->owner, pvt_native);
+ ast_set_read_format(pvt->owner, ast_channel_readformat(pvt->owner));
+ ast_set_write_format(pvt->owner, ast_channel_writeformat(pvt->owner));
if (pvt->options.progress_audio)
ast_queue_control(pvt->owner, AST_CONTROL_PROGRESS);
switch (rtp_change) {
@@ -2132,7 +2169,7 @@
break;
}
ast_channel_unlock(pvt->owner);
- pvt_native = ast_format_cap_destroy(pvt_native);
+ ao2_ref(pvt_native, -1);
} else {
if (pvt->options.progress_audio)
pvt->newcontrol = AST_CONTROL_PROGRESS;
@@ -2565,19 +2602,26 @@
memcpy(&pvt->peer_prefs, prefs, sizeof(pvt->peer_prefs));
if (h323debug) {
int i;
+ struct ast_format *fmt;
for (i = 0; i < 32; ++i) {
if (!prefs->order[i])
break;
- ast_debug(1, "prefs[%d]=%s:%d\n", i, (prefs->order[i] ? ast_getformatname(&prefs->formats[i]) : "<none>"), prefs->framing[i]);
+ ast_debug(1, "prefs[%d]=%s\n", i, ast_format_get_name(ast_codec_pref_index(prefs, i, &fmt)));
}
}
if (pvt->rtp) {
if (pvt->options.autoframing) {
ast_debug(2, "Autoframing option set, using peer's packetization settings\n");
+ /* BUGBUG: RTP - Needs to be updated if API changes */
+#if 0
ast_rtp_codecs_packetization_set(ast_rtp_instance_get_codecs(pvt->rtp), pvt->rtp, &pvt->peer_prefs);
+#endif
} else {
ast_debug(2, "Autoframing option not set, ignoring peer's packetization settings\n");
+ /* BUGBUG: RTP - Needs to be updated if API changes */
+#if 0
ast_rtp_codecs_packetization_set(ast_rtp_instance_get_codecs(pvt->rtp), pvt->rtp, &pvt->options.prefs);
+#endif
}
}
}
@@ -2605,10 +2649,11 @@
if (h323debug) {
int i;
+ struct ast_format *fmt;
for (i = 0; i < 32; i++) {
if (!prefs.order[i])
break;
- ast_debug(1, "local prefs[%d]=%s:%d\n", i, (prefs.order[i] ? ast_getformatname(&prefs.formats[i]) : "<none>"), prefs.framing[i]);
+ ast_debug(1, "local prefs[%d]=%s\n", i, ast_format_get_name(ast_codec_pref_index(&prefs, i, &fmt)));
}
ast_debug(1, "Capabilities for connection %s is set\n", token);
}
@@ -3345,10 +3390,10 @@
{
int res;
- if (!(oh323_tech.capabilities = ast_format_cap_alloc(0))) {
+ if (!(oh323_tech.capabilities = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT))) {
return AST_MODULE_LOAD_FAILURE;
}
- ast_format_cap_add_all_by_type(oh323_tech.capabilities, AST_FORMAT_TYPE_AUDIO);
+ ast_format_cap_add_all_by_type(oh323_tech.capabilities, AST_MEDIA_TYPE_AUDIO);
h323debug = 0;
sched = ast_sched_context_create();
@@ -3520,7 +3565,8 @@
ASTOBJ_CONTAINER_DESTROYALL(&aliasl, oh323_destroy_alias);
ASTOBJ_CONTAINER_DESTROY(&aliasl);
- oh323_tech.capabilities = ast_format_cap_destroy(oh323_tech.capabilities);
+ ao2_ref(oh323_tech.capabilities, -1);
+ oh323_tech.capabilities = NULL;
return 0;
}
Modified: team/group/media_formats-reviewed/channels/chan_iax2.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed/channels/chan_iax2.c?view=diff&rev=413482&r1=413481&r2=413482
==============================================================================
--- team/group/media_formats-reviewed/channels/chan_iax2.c (original)
+++ team/group/media_formats-reviewed/channels/chan_iax2.c Wed May 7 17:22:40 2014
@@ -116,6 +116,8 @@
#include "asterisk/stasis.h"
#include "asterisk/stasis_system.h"
#include "asterisk/stasis_channels.h"
+#include "asterisk/format_cache.h"
+#include "asterisk/format_compatibility.h"
#include "iax2/include/iax2.h"
#include "iax2/include/firmware.h"
@@ -347,22 +349,22 @@
#define IAX_CAPABILITY_FULLBANDWIDTH 0xFFFF
/* T1, maybe ISDN */
#define IAX_CAPABILITY_MEDBANDWIDTH (IAX_CAPABILITY_FULLBANDWIDTH & \
- ~ast_format_id_to_old_bitfield(AST_FORMAT_SLINEAR) & \
- ~ast_format_id_to_old_bitfield(AST_FORMAT_SLINEAR16) & \
- ~ast_format_id_to_old_bitfield(AST_FORMAT_SIREN7) & \
- ~ast_format_id_to_old_bitfield(AST_FORMAT_SIREN14) & \
- ~ast_format_id_to_old_bitfield(AST_FORMAT_G719) & \
- ~ast_format_id_to_old_bitfield(AST_FORMAT_ULAW) & \
- ~ast_format_id_to_old_bitfield(AST_FORMAT_ALAW) & \
- ~ast_format_id_to_old_bitfield(AST_FORMAT_G722))
+ ~ast_format_compatibility_format2bitfield(ast_format_slin) & \
+ ~ast_format_compatibility_format2bitfield(ast_format_slin16) & \
+ ~ast_format_compatibility_format2bitfield(ast_format_siren7) & \
+ ~ast_format_compatibility_format2bitfield(ast_format_siren14) & \
+ ~ast_format_compatibility_format2bitfield(ast_format_g719) & \
+ ~ast_format_compatibility_format2bitfield(ast_format_ulaw) & \
+ ~ast_format_compatibility_format2bitfield(ast_format_alaw) & \
+ ~ast_format_compatibility_format2bitfield(ast_format_g722))
/* A modem */
#define IAX_CAPABILITY_LOWBANDWIDTH (IAX_CAPABILITY_MEDBANDWIDTH & \
- ~ast_format_id_to_old_bitfield(AST_FORMAT_G726) & \
- ~ast_format_id_to_old_bitfield(AST_FORMAT_G726_AAL2) & \
- ~ast_format_id_to_old_bitfield(AST_FORMAT_ADPCM))
+ ~ast_format_compatibility_format2bitfield(ast_format_g726) & \
+ ~ast_format_compatibility_format2bitfield(ast_format_g726_aal2) & \
+ ~ast_format_compatibility_format2bitfield(ast_format_adpcm))
#define IAX_CAPABILITY_LOWFREE (IAX_CAPABILITY_LOWBANDWIDTH & \
- ~ast_format_id_to_old_bitfield(AST_FORMAT_G723_1))
+ ~ast_format_compatibility_format2bitfield(ast_format_g723))
#define DEFAULT_MAXMS 2000 /* Must be faster than 2 seconds by default */
@@ -1715,14 +1717,15 @@
static iax2_format iax2_codec_choose(struct ast_codec_pref *pref, iax2_format formats, int find_best)
{
struct ast_format_cap *cap;
- struct ast_format tmpfmt;
+ struct ast_format *tmpfmt;
iax2_format format = 0;
- if ((cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK))) {
- ast_format_clear(&tmpfmt);
- ast_format_cap_from_old_bitfield(cap, formats);
- ast_codec_choose(pref, cap, find_best, &tmpfmt);
- format = ast_format_to_old_bitfield(&tmpfmt);
- cap = ast_format_cap_destroy(cap);
+
+ if ((cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT))) {
+ ast_format_compatibility_bitfield2cap(formats, cap);
+ ast_best_codec(cap, &tmpfmt);
+ format = ast_format_compatibility_format2bitfield(tmpfmt);
+ ao2_ref(tmpfmt, -1);
+ ao2_ref(cap, -1);
}
return format;
@@ -1730,55 +1733,69 @@
static iax2_format iax2_best_codec(iax2_format formats)
{
- struct ast_format_cap *cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
- struct ast_format tmpfmt;
+ struct ast_format_cap *cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+ struct ast_format *tmpfmt;
+ iax2_format format;
+
if (!cap) {
return 0;
}
- ast_format_clear(&tmpfmt);
- ast_format_cap_from_old_bitfield(cap, formats);
+ ast_format_compatibility_bitfield2cap(formats, cap);
ast_best_codec(cap, &tmpfmt);
- cap = ast_format_cap_destroy(cap);
- return ast_format_to_old_bitfield(&tmpfmt);
+ format = ast_format_compatibility_format2bitfield(tmpfmt);
+ ao2_ref(tmpfmt, -1);
+ ao2_ref(cap, -1);
+
+ return format;
}
const char *iax2_getformatname(iax2_format format)
{
- struct ast_format tmpfmt;
- if (!(ast_format_from_old_bitfield(&tmpfmt, format))) {
+ struct ast_format *tmpfmt;
+
+ tmpfmt = ast_format_compatibility_bitfield2format(format);
+ if (!tmpfmt) {
return "Unknown";
}
- return ast_getformatname(&tmpfmt);
+ return ast_format_get_name(tmpfmt);
}
static char *iax2_getformatname_multiple(char *codec_buf, size_t len, iax2_format format)
{
- struct ast_format_cap *cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
+ struct ast_format_cap *cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
if (!cap) {
return "(Nothing)";
}
- ast_format_cap_from_old_bitfield(cap, format);
+ ast_format_compatibility_bitfield2cap(format, cap);
ast_getformatname_multiple(codec_buf, len, cap);
- cap = ast_format_cap_destroy(cap);
+ ao2_ref(cap, -1);
return codec_buf;
}
static int iax2_parse_allow_disallow(struct ast_codec_pref *pref, iax2_format *formats, const char *list, int allowing)
{
- int res;
- struct ast_format_cap *cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
+ int res, i;
+ struct ast_format_cap *cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+
if (!cap) {
return 1;
}
- ast_format_cap_from_old_bitfield(cap, *formats);
- res = ast_parse_allow_disallow(pref, cap, list, allowing);
- *formats = ast_format_cap_to_old_bitfield(cap);
- cap = ast_format_cap_destroy(cap);
+ ast_format_compatibility_bitfield2cap(*formats, cap);
+ res = ast_parse_allow_disallow(cap, list, allowing);
+
+ for (i = 0; i < ast_format_cap_count(cap); i++) {
+ struct ast_format *fmt = ast_format_cap_get_format(cap, i);
+
+ ast_codec_pref_append(pref, fmt, ast_format_cap_get_framing(cap, fmt));
+ ao2_ref(fmt, -1);
+ }
+
+ ao2_ref(cap, -1);
return res;
}
@@ -1786,13 +1803,13 @@
static int iax2_data_add_codecs(struct ast_data *root, const char *node_name, iax2_format formats)
{
int res;
- struct ast_format_cap *cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
+ struct ast_format_cap *cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
if (!cap) {
return -1;
}
- ast_format_cap_from_old_bitfield(cap, formats);
+ ast_format_compatibility_bitfield2cap(formats, cap);
res = ast_data_add_codecs(root, node_name, cap);
- cap = ast_format_cap_destroy(cap);
+ ao2_ref(cap, -1);
return res;
}
@@ -3697,10 +3714,10 @@
ast_cli(a->fd, " Codec Order : (");
for(x = 0; x < AST_CODEC_PREF_SIZE; x++) {
- struct ast_format tmpfmt;
+ struct ast_format *tmpfmt;
if(!(ast_codec_pref_index(&peer->prefs, x, &tmpfmt)))
break;
- ast_cli(a->fd, "%s", ast_getformatname(&tmpfmt));
+ ast_cli(a->fd, "%s", ast_format_get_name(tmpfmt));
if(x < 31 && ast_codec_pref_index(&peer->prefs, x+1, &tmpfmt))
ast_cli(a->fd, "|");
}
@@ -3987,9 +4004,9 @@
ms = ast_tvdiff_ms(now, pvt->rxcore);
if(ms >= (next = jb_next(pvt->jb))) {
- struct ast_format voicefmt;
- ast_format_from_old_bitfield(&voicefmt, pvt->voiceformat);
- ret = jb_get(pvt->jb, &frame, ms, ast_codec_interp_len(&voicefmt));
+ struct ast_format *voicefmt;
+ voicefmt = ast_format_compatibility_bitfield2format(pvt->voiceformat);
+ ret = jb_get(pvt->jb, &frame, ms, ast_format_get_default_ms(voicefmt));
switch(ret) {
case JB_OK:
fr = frame.data;
@@ -4003,8 +4020,8 @@
/* create an interpolation frame */
af.frametype = AST_FRAME_VOICE;
- ast_format_copy(&af.subclass.format, &voicefmt);
- af.samples = frame.ms * (ast_format_rate(&voicefmt) / 1000);
+ af.subclass.format = voicefmt;
+ af.samples = frame.ms * (ast_format_get_sample_rate(voicefmt) / 1000);
af.src = "IAX2 JB interpolation";
af.delivery = ast_tvadd(pvt->rxcore, ast_samp2tv(next, 1000));
af.offset = AST_FRIENDLY_OFFSET;
@@ -4085,7 +4102,7 @@
if(fr->af.frametype == AST_FRAME_VOICE) {
type = JB_TYPE_VOICE;
- len = ast_codec_get_samples(&fr->af) / (ast_format_rate(&fr->af.subclass.format) / 1000);
+ len = ast_codec_samples_count(&fr->af) / (ast_format_get_sample_rate(fr->af.subclass.format) / 1000);
} else if(fr->af.frametype == AST_FRAME_CNG) {
type = JB_TYPE_SILENCE;
}
@@ -4507,12 +4524,15 @@
/* But move the calling channel's native codec to the top of the preference list */
memcpy(&ourprefs, &prefs, sizeof(ourprefs));
if (c) {
- struct ast_format tmpfmt;
- ast_format_cap_iter_start(ast_channel_nativeformats(c));
- while (!(ast_format_cap_iter_next(ast_channel_nativeformats(c), &tmpfmt))) {
- ast_codec_pref_prepend(&ourprefs, &tmpfmt, 1);
+ int i;
+
+ for (i = 0; i < ast_format_cap_count(ast_channel_nativeformats(c)); i++) {
+ struct ast_format *format = ast_format_cap_get_format(
+ ast_channel_nativeformats(c), i);
+
+ ast_codec_pref_prepend(&ourprefs, format, ast_format_cap_get_framing(ast_channel_nativeformats(c), format), 1);
+ ao2_ref(format, -1);
}
- ast_format_cap_iter_end(ast_channel_nativeformats(c));
}
ast_codec_pref_convert(&ourprefs, cai->prefs, sizeof(cai->prefs), 1);
return 0;
@@ -4538,13 +4558,15 @@
memcpy(&ourprefs, &peer->prefs, sizeof(ourprefs));
/* Move the calling channel's native codec to the top of the preference list */
if (c) {
- struct ast_format tmpfmt;
- ast_format_cap_iter_start(ast_channel_nativeformats(c));
- while (!(ast_format_cap_iter_next(ast_channel_nativeformats(c), &tmpfmt))) {
- ast_debug(1, "prepending %s to prefs\n", ast_getformatname(&tmpfmt));
- ast_codec_pref_prepend(&ourprefs, &tmpfmt, 1);
- }
- ast_format_cap_iter_end(ast_channel_nativeformats(c));
+ int i;
+
+ for (i = 0; i < ast_format_cap_count(ast_channel_nativeformats(c)); i++) {
+ struct ast_format *tmpfmt = ast_format_cap_get_format(
+ ast_channel_nativeformats(c), i);
+
+ ast_codec_pref_prepend(&ourprefs, tmpfmt, ast_format_cap_get_framing(ast_channel_nativeformats(c), tmpfmt), 1);
+ ao2_ref(tmpfmt, -1);
+ }
}
ast_codec_pref_convert(&ourprefs, cai->prefs, sizeof(cai->prefs), 1);
ast_copy_string(cai->context, peer->context, sizeof(cai->context));
@@ -5084,7 +5106,7 @@
if (pds.password)
ast_string_field_set(iaxs[callno], secret, pds.password);
- iax2_tmpfmt = ast_format_cap_to_old_bitfield(ast_channel_nativeformats(c));
+ iax2_tmpfmt = ast_format_compatibility_cap2bitfield(ast_channel_nativeformats(c));
iax_ie_append_int(&ied, IAX_IE_FORMAT, (int) iax2_tmpfmt);
iax_ie_append_versioned_uint64(&ied, IAX_IE_FORMAT2, 0, iax2_tmpfmt);
@@ -5678,11 +5700,17 @@
struct ast_channel *tmp;
struct chan_iax2_pvt *i;
struct ast_variable *v = NULL;
- struct ast_format tmpfmt;
+ struct ast_format_cap *native;
+ struct ast_format *tmpfmt;
struct ast_callid *callid;
if (!(i = iaxs[callno])) {
ast_log(LOG_WARNING, "No IAX2 pvt found for callno '%d' !\n", callno);
+ return NULL;
+ }
+
+ native = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+ if (!native) {
return NULL;
}
@@ -5698,9 +5726,11 @@
tmp = ast_channel_release(tmp);
ast_mutex_lock(&iaxsl[callno]);
}
+ ao2_ref(native, -1);
return NULL;
}
if (!tmp) {
+ ao2_ref(native, -1);
return NULL;
}
@@ -5711,14 +5741,18 @@
}
ast_channel_tech_set(tmp, &iax2_tech);
+
/* We can support any format by default, until we get restricted */
- ast_format_cap_from_old_bitfield(ast_channel_nativeformats(tmp), capability);
+ ast_format_compatibility_bitfield2cap(capability, native);
+ ast_channel_nativeformats_set(tmp, native);
ast_best_codec(ast_channel_nativeformats(tmp), &tmpfmt);
- ast_format_copy(ast_channel_readformat(tmp), &tmpfmt);
- ast_format_copy(ast_channel_rawreadformat(tmp), &tmpfmt);
- ast_format_copy(ast_channel_writeformat(tmp), &tmpfmt);
- ast_format_copy(ast_channel_rawwriteformat(tmp), &tmpfmt);
+ ast_channel_set_readformat(tmp, tmpfmt);
+ ast_channel_set_rawreadformat(tmp, tmpfmt);
+ ast_channel_set_writeformat(tmp, tmpfmt);
+ ast_channel_set_rawwriteformat(tmp, tmpfmt);
+
+ ao2_ref(native, -1);
ast_channel_tech_pvt_set(tmp, CALLNO_TO_PTR(i->callno));
@@ -5869,7 +5903,7 @@
int voice = 0;
int genuine = 0;
int adjust;
- int rate = ast_format_rate(&f->subclass.format) / 1000;
+ int rate = ast_format_get_sample_rate(f->subclass.format) / 1000;
struct timeval *delivery = NULL;
@@ -6242,9 +6276,9 @@
memcpy(efh->encdata, workspace + padding, *datalen - sizeof(struct ast_iax2_full_enc_hdr));
f->frametype = fh->type;
if (f->frametype == AST_FRAME_VIDEO) {
- ast_format_from_old_bitfield(&f->subclass.format, (uncompress_subclass(fh->csub & ~0x40) | ((fh->csub >> 6) & 0x1)));
+ f->subclass.format = ast_format_compatibility_bitfield2format(uncompress_subclass(fh->csub & ~0x40) | ((fh->csub >> 6) & 0x1));
} else if (f->frametype == AST_FRAME_VOICE) {
- ast_format_from_old_bitfield(&f->subclass.format, uncompress_subclass(fh->csub));
+ f->subclass.format = ast_format_compatibility_bitfield2format(uncompress_subclass(fh->csub));
} else {
f->subclass.integer = uncompress_subclass(fh->csub);
}
@@ -6385,7 +6419,7 @@
/* High two bytes are the same on timestamp, or sending on a trunk */ &&
(f->frametype == AST_FRAME_VOICE)
/* is a voice frame */ &&
- (f->subclass.format.id == ast_format_id_from_old_bitfield(pvt->svoiceformat))
+ (ast_format_cmp(f->subclass.format, ast_format_compatibility_bitfield2format(pvt->svoiceformat)))
/* is the same type */ ) {
/* Force immediate rather than delayed transmission */
now = 1;
@@ -6399,7 +6433,7 @@
* Otherwise send a mini video frame
*/
if (((fts & 0xFFFF8000L) == (pvt->lastvsent & 0xFFFF8000L)) &&
- ((f->subclass.format.id) == ast_format_id_from_old_bitfield(pvt->svideoformat))
+ (ast_format_cmp(f->subclass.format, ast_format_compatibility_bitfield2format(pvt->svideoformat)))
) {
now = 1;
sendmini = 1;
@@ -6454,11 +6488,11 @@
fh->type = fr->af.frametype & 0xFF;
if (fr->af.frametype == AST_FRAME_VIDEO) {
- iax2_format tmpfmt = ast_format_to_old_bitfield(&fr->af.subclass.format);
- tmpfmt |= ast_format_get_video_mark(&fr->af.subclass.format) ? 0x1LL : 0;
+ iax2_format tmpfmt = ast_format_compatibility_format2bitfield(fr->af.subclass.format);
+ tmpfmt |= fr->af.subclass.video.frame_ending ? 0x1LL : 0;
fh->csub = compress_subclass(tmpfmt | ((tmpfmt & 0x1LL) << 6));
} else if (fr->af.frametype == AST_FRAME_VOICE) {
- fh->csub = compress_subclass(ast_format_to_old_bitfield(&fr->af.subclass.format));
+ fh->csub = compress_subclass(ast_format_compatibility_format2bitfield(fr->af.subclass.format));
} else {
fh->csub = compress_subclass(fr->af.subclass.integer);
}
@@ -6481,9 +6515,9 @@
if ((f->frametype == AST_FRAME_IAX) && (f->subclass.integer == IAX_COMMAND_ACK))
fr->retries = -1;
else if (f->frametype == AST_FRAME_VOICE)
- pvt->svoiceformat = ast_format_to_old_bitfield(&f->subclass.format);
+ pvt->svoiceformat = ast_format_compatibility_format2bitfield(f->subclass.format);
else if (f->frametype == AST_FRAME_VIDEO)
- pvt->svideoformat = ast_format_to_old_bitfield(&f->subclass.format);
+ pvt->svideoformat = ast_format_compatibility_format2bitfield(f->subclass.format);
if (ast_test_flag64(pvt, IAX_ENCRYPTED)) {
if (ast_test_flag64(pvt, IAX_KEYPOPULATED)) {
if (fr->transfer)
@@ -6514,7 +6548,7 @@
vh = (struct ast_iax2_video_hdr *)(fr->af.data.ptr - sizeof(struct ast_iax2_video_hdr));
vh->zeros = 0;
vh->callno = htons(0x8000 | fr->callno);
- vh->ts = htons((fr->ts & 0x7FFF) | (ast_format_get_video_mark(&fr->af.subclass.format) ? 0x8000 : 0));
+ vh->ts = htons((fr->ts & 0x7FFF) | (fr->af.subclass.video.frame_ending ? 0x8000 : 0));
fr->datalen = fr->af.datalen + sizeof(struct ast_iax2_video_hdr);
fr->data = vh;
fr->retries = -1;
@@ -9719,7 +9753,7 @@
ast_log(LOG_WARNING, "Received trunked frame before first full voice frame\n");
iax2_vnak(fr->callno);
} else {
- ast_format_from_old_bitfield(&f.subclass.format, iaxs[fr->callno]->voiceformat);
+ f.subclass.format = ast_format_compatibility_bitfield2format(iaxs[fr->callno]->voiceformat);
f.datalen = len;
if (f.datalen >= 0) {
if (f.datalen)
@@ -9739,7 +9773,7 @@
f.mallocd = 0;
f.offset = 0;
if (f.datalen && (f.frametype == AST_FRAME_VOICE))
- f.samples = ast_codec_get_samples(&f);
+ f.samples = ast_codec_samples_count(&f);
else
f.samples = 0;
fr->outoforder = 0;
@@ -9949,12 +9983,12 @@
/* Retrieve the type and subclass */
f.frametype = fh->type;
if (f.frametype == AST_FRAME_VIDEO) {
- ast_format_from_old_bitfield(&f.subclass.format, (uncompress_subclass(fh->csub & ~0x40)));
+ f.subclass.format = ast_format_compatibility_bitfield2format(uncompress_subclass(fh->csub & ~0x40));
if ((fh->csub >> 6) & 0x1) {
- ast_format_set_video_mark(&f.subclass.format);
+ f.subclass.video.frame_ending = 1;
}
} else if (f.frametype == AST_FRAME_VOICE) {
- ast_format_from_old_bitfield(&f.subclass.format, uncompress_subclass(fh->csub));
+ f.subclass.format = ast_format_compatibility_bitfield2format(uncompress_subclass(fh->csub));
} else {
f.subclass.integer = uncompress_subclass(fh->csub);
}
@@ -10378,22 +10412,21 @@
}
if (f.frametype == AST_FRAME_VOICE) {
- if (ast_format_to_old_bitfield(&f.subclass.format) != iaxs[fr->callno]->voiceformat) {
- iaxs[fr->callno]->voiceformat = ast_format_to_old_bitfield(&f.subclass.format);
- ast_debug(1, "Ooh, voice format changed to '%s'\n", ast_getformatname(&f.subclass.format));
+ if (ast_format_compatibility_format2bitfield(f.subclass.format) != iaxs[fr->callno]->voiceformat) {
+ iaxs[fr->callno]->voiceformat = ast_format_compatibility_format2bitfield(f.subclass.format);
+ ast_debug(1, "Ooh, voice format changed to '%s'\n", ast_format_get_name(f.subclass.format));
if (iaxs[fr->callno]->owner) {
iax2_lock_owner(fr->callno);
if (iaxs[fr->callno]) {
if (iaxs[fr->callno]->owner) {
- struct ast_format_cap *orignative = ast_format_cap_dup(ast_channel_nativeformats(iaxs[fr->callno]->owner));
- struct ast_format_cap *native = ast_channel_nativeformats(iaxs[fr->callno]->owner);
- if (orignative) {
- ast_format_cap_set(native, &f.subclass.format);
- if (ast_channel_readformat(iaxs[fr->callno]->owner)->id) {
+ struct ast_format_cap *native = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+ if (native) {
+ ast_format_cap_add(native, f.subclass.format, 0);
+ ast_channel_nativeformats_set(iaxs[fr->callno]->owner, native);
+ if (ast_channel_readformat(iaxs[fr->callno]->owner)) {
ast_set_read_format(iaxs[fr->callno]->owner, ast_channel_readformat(iaxs[fr->callno]->owner));
}
- ast_format_cap_copy(native, orignative);
- orignative = ast_format_cap_destroy(orignative);
+ ao2_ref(native, -1);
}
ast_channel_unlock(iaxs[fr->callno]->owner);
}
@@ -10412,9 +10445,9 @@
}
}
if (f.frametype == AST_FRAME_VIDEO) {
- if (f.subclass.format.id != ast_format_id_from_old_bitfield(iaxs[fr->callno]->videoformat)) {
- ast_debug(1, "Ooh, video format changed to %s\n", ast_getformatname(&f.subclass.format));
- iaxs[fr->callno]->videoformat = ast_format_to_old_bitfield(&f.subclass.format);
+ if (ast_format_compatibility_format2bitfield(f.subclass.format) != iaxs[fr->callno]->videoformat) {
+ ast_debug(1, "Ooh, video format changed to %s\n", ast_format_get_name(f.subclass.format));
+ iaxs[fr->callno]->videoformat = ast_format_compatibility_format2bitfield(f.subclass.format);
}
}
if (f.frametype == AST_FRAME_CONTROL && iaxs[fr->callno]->owner) {
@@ -10584,7 +10617,7 @@
strcpy(caller_pref_buf, "disabled");
strcpy(host_pref_buf, "disabled");
} else {
- struct ast_format tmpfmt;
+ struct ast_format *tmpfmt;
using_prefs = "mine";
/* If the information elements are in here... use them */
if (ies.codec_prefs)
@@ -10643,7 +10676,7 @@
strcpy(caller_pref_buf,"disabled");
strcpy(host_pref_buf,"disabled");
} else {
- struct ast_format tmpfmt;
+ struct ast_format *tmpfmt;
using_prefs = "mine";
if (ast_codec_pref_index(&iaxs[fr->callno]->rprefs, 0, &tmpfmt)) {
/* Do the opposite of what we tried above. */
@@ -10822,7 +10855,7 @@
iaxs[fr->callno]->peerformat = ies.format;
[... 1637 lines stripped ...]
More information about the svn-commits
mailing list