Asterisk media architecture conversion - no more format bitfields
authorDavid Vossel <dvossel@digium.com>
Thu, 3 Feb 2011 16:22:10 +0000 (16:22 +0000)
committerDavid Vossel <dvossel@digium.com>
Thu, 3 Feb 2011 16:22:10 +0000 (16:22 +0000)
This patch is the foundation of an entire new way of looking at media in Asterisk.
The code present in this patch is everything required to complete phase1 of my
Media Architecture proposal.  For more information about this project visit the link below.
https://wiki.asterisk.org/wiki/display/AST/Media+Architecture+Proposal

The primary function of this patch is to convert all the usages of format
bitfields in Asterisk to use the new format and format_cap APIs.  Functionally
no change in behavior should be present in this patch.  Thanks to twilson
and russell for all the time they spent reviewing these changes.

Review: https://reviewboard.asterisk.org/r/1083/

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@306010 65c4cc65-6c06-0410-ace0-fbb531ad65f3

168 files changed:
addons/chan_mobile.c
addons/chan_ooh323.c
addons/chan_ooh323.h
addons/format_mp3.c
addons/ooh323cDriver.c
addons/ooh323cDriver.h
apps/app_alarmreceiver.c
apps/app_amd.c
apps/app_chanspy.c
apps/app_confbridge.c
apps/app_dahdibarge.c
apps/app_dictate.c
apps/app_dumpchan.c
apps/app_echo.c
apps/app_fax.c
apps/app_festival.c
apps/app_followme.c
apps/app_ices.c
apps/app_jack.c
apps/app_meetme.c
apps/app_milliwatt.c
apps/app_mixmonitor.c
apps/app_mp3.c
apps/app_nbscat.c
apps/app_originate.c
apps/app_parkandannounce.c
apps/app_record.c
apps/app_rpt.c
apps/app_sms.c
apps/app_speech_utils.c
apps/app_talkdetect.c
apps/app_test.c
apps/app_voicemail.c
apps/app_waitforsilence.c
bridges/bridge_multiplexed.c
bridges/bridge_simple.c
bridges/bridge_softmix.c
channels/chan_agent.c
channels/chan_alsa.c
channels/chan_bridge.c
channels/chan_console.c
channels/chan_dahdi.c
channels/chan_gtalk.c
channels/chan_h323.c
channels/chan_iax2.c
channels/chan_jingle.c
channels/chan_local.c
channels/chan_mgcp.c
channels/chan_misdn.c
channels/chan_multicast_rtp.c
channels/chan_nbs.c
channels/chan_oss.c
channels/chan_phone.c
channels/chan_sip.c
channels/chan_skinny.c
channels/chan_unistim.c
channels/chan_usbradio.c
channels/chan_vpb.cc
channels/h323/ast_h323.cxx
channels/h323/chan_h323.h
channels/iax2-parser.c
channels/iax2-parser.h
channels/iax2-provision.c
channels/iax2.h
channels/sip/include/globals.h
channels/sip/include/sip.h
codecs/codec_a_mu.c
codecs/codec_adpcm.c
codecs/codec_alaw.c
codecs/codec_dahdi.c
codecs/codec_g722.c
codecs/codec_g726.c
codecs/codec_gsm.c
codecs/codec_ilbc.c
codecs/codec_lpc10.c
codecs/codec_resample.c
codecs/codec_speex.c
codecs/codec_ulaw.c
codecs/ex_adpcm.h
codecs/ex_alaw.h
codecs/ex_g722.h
codecs/ex_g726.h
codecs/ex_gsm.h
codecs/ex_lpc10.h
codecs/ex_speex.h
codecs/ex_ulaw.h
formats/format_g719.c
formats/format_g723.c
formats/format_g726.c
formats/format_g729.c
formats/format_gsm.c
formats/format_h263.c
formats/format_h264.c
formats/format_ilbc.c
formats/format_jpeg.c
formats/format_ogg_vorbis.c
formats/format_pcm.c
formats/format_siren14.c
formats/format_siren7.c
formats/format_sln.c
formats/format_sln16.c
formats/format_vox.c
formats/format_wav.c
formats/format_wav_gsm.c
funcs/func_channel.c
funcs/func_frame_trace.c
funcs/func_pitchshift.c
include/asterisk/abstract_jb.h
include/asterisk/astobj2.h
include/asterisk/audiohook.h
include/asterisk/bridging.h
include/asterisk/bridging_technology.h
include/asterisk/callerid.h
include/asterisk/channel.h
include/asterisk/data.h
include/asterisk/file.h
include/asterisk/format.h [new file with mode: 0644]
include/asterisk/format_cap.h [new file with mode: 0644]
include/asterisk/format_pref.h [new file with mode: 0644]
include/asterisk/frame.h
include/asterisk/frame_defs.h
include/asterisk/image.h
include/asterisk/mod_format.h
include/asterisk/pbx.h
include/asterisk/rtp_engine.h
include/asterisk/slin.h
include/asterisk/slinfactory.h
include/asterisk/speech.h
include/asterisk/translate.h
main/abstract_jb.c
main/app.c
main/asterisk.c
main/astobj2.c
main/audiohook.c
main/bridging.c
main/callerid.c
main/ccss.c
main/channel.c
main/cli.c
main/data.c
main/dial.c
main/dsp.c
main/features.c
main/file.c
main/format.c [new file with mode: 0644]
main/format_cap.c [new file with mode: 0644]
main/format_pref.c [new file with mode: 0644]
main/frame.c
main/image.c
main/indications.c
main/manager.c
main/pbx.c
main/rtp_engine.c
main/slinfactory.c
main/translate.c
main/udptl.c
pbx/pbx_spool.c
res/res_adsi.c
res/res_agi.c
res/res_calendar.c
res/res_clioriginate.c
res/res_fax.c
res/res_fax_spandsp.c
res/res_musiconhold.c
res/res_rtp_asterisk.c
res/res_rtp_multicast.c
res/res_speech.c
tests/test_format_api.c [new file with mode: 0644]

index 29d14e0..dd48f93 100644 (file)
@@ -71,7 +71,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 #define DEVICE_FRAME_FORMAT AST_FORMAT_SLINEAR
 #define CHANNEL_FRAME_SIZE 320
 
-static format_t prefformat = DEVICE_FRAME_FORMAT;
+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 */
@@ -196,7 +196,7 @@ static char *mblsendsms_desc =
 
 static struct ast_channel *mbl_new(int state, struct mbl_pvt *pvt, char *cid_num,
                const struct ast_channel *requestor);
-static struct ast_channel *mbl_request(const char *type, format_t format,
+static struct ast_channel *mbl_request(const char *type, struct ast_format_cap *cap,
                const struct ast_channel *requestor, void *data, int *cause);
 static int mbl_call(struct ast_channel *ast, char *dest, int timeout);
 static int mbl_hangup(struct ast_channel *ast);
@@ -450,10 +450,9 @@ static struct msg_queue_entry *msg_queue_head(struct mbl_pvt *pvt);
  * channel stuff
  */
 
-static const struct ast_channel_tech mbl_tech = {
+static struct ast_channel_tech mbl_tech = {
        .type = "Mobile",
        .description = "Bluetooth Mobile Device Channel Driver",
-       .capabilities = AST_FORMAT_SLINEAR,
        .requester = mbl_request,
        .call = mbl_call,
        .hangup = mbl_hangup,
@@ -844,11 +843,11 @@ static struct ast_channel *mbl_new(int state, struct mbl_pvt *pvt, char *cid_num
        }
 
        chn->tech = &mbl_tech;
-       chn->nativeformats = prefformat;
-       chn->rawreadformat = prefformat;
-       chn->rawwriteformat = prefformat;
-       chn->writeformat = prefformat;
-       chn->readformat = prefformat;
+       ast_format_cap_add(chn->nativeformats, &prefformat);
+       ast_format_copy(&chn->rawreadformat, &prefformat);
+       ast_format_copy(&chn->rawwriteformat, &prefformat);
+       ast_format_copy(&chn->writeformat, &prefformat);
+       ast_format_copy(&chn->readformat, &prefformat);
        chn->tech_pvt = pvt;
 
        if (state == AST_STATE_RING)
@@ -867,7 +866,7 @@ e_return:
        return NULL;
 }
 
-static struct ast_channel *mbl_request(const char *type, format_t format,
+static struct ast_channel *mbl_request(const char *type, struct ast_format_cap *cap,
                const struct ast_channel *requestor, void *data, int *cause)
 {
 
@@ -875,7 +874,6 @@ static struct ast_channel *mbl_request(const char *type, format_t format,
        struct mbl_pvt *pvt;
        char *dest_dev = NULL;
        char *dest_num = NULL;
-       format_t oldformat;
        int group = -1;
 
        if (!data) {
@@ -884,10 +882,9 @@ static struct ast_channel *mbl_request(const char *type, format_t format,
                return NULL;
        }
 
-       oldformat = format;
-       format &= (AST_FORMAT_SLINEAR);
-       if (!format) {
-               ast_log(LOG_WARNING, "Asked to get a channel of unsupported format '%s'\n", ast_getformatname(oldformat));
+       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));
                *cause = AST_CAUSE_FACILITY_NOT_IMPLEMENTED;
                return NULL;
        }
@@ -1099,7 +1096,7 @@ static struct ast_frame *mbl_read(struct ast_channel *ast)
 
        memset(&pvt->fr, 0x00, sizeof(struct ast_frame));
        pvt->fr.frametype = AST_FRAME_VOICE;
-       pvt->fr.subclass.codec = DEVICE_FRAME_FORMAT;
+       ast_format_set(&pvt->fr.subclass.format, DEVICE_FRAME_FORMAT, 0);
        pvt->fr.src = "Mobile";
        pvt->fr.offset = AST_FRIENDLY_OFFSET;
        pvt->fr.mallocd = 0;
@@ -4534,6 +4531,7 @@ static int unload_module(void)
        if (sdp_session)
                sdp_close(sdp_session);
 
+       mbl_tech.capabilities = ast_format_cap_destroy(mbl_tech.capabilities);
        return 0;
 }
 
@@ -4542,6 +4540,11 @@ static int load_module(void)
 
        int dev_id, s;
 
+       if (!(mbl_tech.capabilities = ast_format_cap_alloc())) {
+               return AST_MODULE_LOAD_DECLINE;
+       }
+       ast_format_set(&prefformat, DEVICE_FRAME_FORMAT, 0);
+       ast_format_cap_add(mbl_tech.capabilities, &prefformat);
        /* Check if we have Bluetooth, no point loading otherwise... */
        dev_id = hci_get_route(NULL);
        s = hci_open_dev(dev_id);
index a49e3a8..df4965b 100644 (file)
@@ -66,7 +66,7 @@ static struct ast_jb_conf default_jbconf =
 static struct ast_jb_conf global_jbconf;
 
 /* Channel Definition */
-static struct ast_channel *ooh323_request(const char *type, format_t format, 
+static struct ast_channel *ooh323_request(const char *type, struct ast_format_cap *cap,
                        const struct ast_channel *requestor,  void *data, int *cause);
 static int ooh323_digit_begin(struct ast_channel *ast, char digit);
 static int ooh323_digit_end(struct ast_channel *ast, char digit, unsigned int duration);
@@ -82,7 +82,7 @@ static int ooh323_fixup(struct ast_channel *oldchan, struct ast_channel *newchan
 static enum ast_rtp_glue_result ooh323_get_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance **rtp);
 static enum ast_rtp_glue_result ooh323_get_vrtp_peer(struct ast_channel *chan, struct ast_rtp_instance **rtp);
 static int ooh323_set_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance *rtp, 
-          struct ast_rtp_instance *vrtp, struct ast_rtp_instance *trtp, format_t codecs, int nat_active);
+          struct ast_rtp_instance *vrtp, struct ast_rtp_instance *trtp, const struct ast_format_cap *codecs, int nat_active);
 
 static struct ast_udptl *ooh323_get_udptl_peer(struct ast_channel *chan);
 static int ooh323_set_udptl_peer(struct ast_channel *chan, struct ast_udptl *udptl);
@@ -92,10 +92,9 @@ static void print_codec_to_cli(int fd, struct ast_codec_pref *pref);
 struct ooh323_peer *find_friend(const char *name, int port);
 
 
-static const struct ast_channel_tech ooh323_tech = {
+static struct ast_channel_tech ooh323_tech = {
        .type = type,
        .description = tdesc,
-       .capabilities = -1,
        .properties = AST_CHAN_TP_WANTSJITTER | AST_CHAN_TP_CREATESJITTER,
        .requester = ooh323_request,
        .send_digit_begin = ooh323_digit_begin,
@@ -172,9 +171,9 @@ static struct ooh323_pvt {
        char callee_url[AST_MAX_EXTENSION];
  
        int port;
-       format_t readformat;   /* negotiated read format */
-       format_t writeformat;  /* negotiated write format */
-       format_t capability;
+       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;
@@ -204,7 +203,7 @@ struct ooh323_user{
        unsigned    inUse;
        char        accountcode[20];
        int         amaflags;
-       format_t    capability;
+       struct ast_format_cap *cap;
        struct ast_codec_pref prefs;
        int         dtmfmode;
        int         dtmfcodec;
@@ -225,7 +224,7 @@ struct ooh323_peer{
        char        name[256];
        unsigned    outgoinglimit;
        unsigned    outUse;
-       format_t    capability;
+       struct ast_format_cap *cap;
        struct ast_codec_pref prefs;
        char        accountcode[20];
        int         amaflags;
@@ -286,7 +285,7 @@ static int  gPort = 1720;
 static char gIP[20];
 static char gCallerID[AST_MAX_EXTENSION] = "";
 static struct ooAliases *gAliasList;
-static format_t gCapability = AST_FORMAT_ULAW;
+static struct ast_format_cap *gCap;
 static struct ast_codec_pref gPrefs;
 static int  gDTMFMode = H323_DTMF_RFC2833;
 static int  gDTMFCodec = 101;
@@ -337,14 +336,14 @@ static pthread_t monitor_thread = AST_PTHREADT_NULL;
 
 
 static struct ast_channel *ooh323_new(struct ooh323_pvt *i, int state,
-                                             const char *host, int capability, const char *linkedid) 
+                                             const char *host, struct ast_format_cap *cap, const char *linkedid) 
 {
        struct ast_channel *ch = NULL;
-       int fmt = 0;
+       struct ast_format tmpfmt;
        if (gH323Debug)
-               ast_verbose("---   ooh323_new - %s, %d\n", host, capability);
-
+               ast_verbose("---   ooh323_new - %s\n", host);
 
+       ast_format_clear(&tmpfmt);
        /* Don't hold a h323 pvt lock while we allocate a channel */
        ast_mutex_unlock(&i->lock);
        ch = ast_channel_alloc(1, state, i->callerid_num, i->callerid_name, 
@@ -360,12 +359,14 @@ static struct ast_channel *ooh323_new(struct ooh323_pvt *i, int state,
                ast_channel_lock(ch);
                ch->tech = &ooh323_tech;
 
-               if (capability)
-                       fmt = ast_best_codec(capability);
-               if (!fmt) 
-                       fmt = ast_codec_pref_index(&i->prefs, 0);
+               if (cap)
+                       ast_best_codec(cap, &tmpfmt);
+               if (!tmpfmt.id)
+                       ast_codec_pref_index(&i->prefs, 0, &tmpfmt);
 
-               ch->nativeformats = ch->rawwriteformat = ch->rawreadformat = fmt;
+               ast_format_cap_add(ch->nativeformats, &tmpfmt);
+               ast_format_copy(&ch->rawwriteformat, &tmpfmt);
+               ast_format_copy(&ch->rawreadformat, &tmpfmt);
 
                ast_channel_set_fd(ch, 0, ast_rtp_instance_fd(i->rtp, 0));
                ast_channel_set_fd(ch, 1, ast_rtp_instance_fd(i->rtp, 1));
@@ -377,8 +378,8 @@ static struct ast_channel *ooh323_new(struct ooh323_pvt *i, int state,
                        ch->rings = 1;
 
                ch->adsicpe = AST_ADSI_UNAVAILABLE;
-               ast_set_write_format(ch, fmt);
-               ast_set_read_format(ch, fmt);
+               ast_set_write_format(ch, &tmpfmt);
+               ast_set_read_format(ch, &tmpfmt);
                ch->tech_pvt = i;
                i->owner = ch;
                ast_module_ref(myself);
@@ -472,6 +473,11 @@ static struct ooh323_pvt *ooh323_alloc(int callref, char *callToken)
                ast_log(LOG_ERROR, "Couldn't allocate private ooh323 structure\n");
                return NULL;
        }
+       if (!(pvt->cap = ast_format_cap_alloc_nolock())) {
+               ast_free(pvt);
+               ast_log(LOG_ERROR, "Couldn't allocate private ooh323 structure\n");
+               return NULL;
+       }
 
        ast_mutex_init(&pvt->lock);
        ast_mutex_lock(&pvt->lock);
@@ -529,7 +535,7 @@ static struct ooh323_pvt *ooh323_alloc(int callref, char *callToken)
        ast_copy_string(pvt->accountcode, gAccountcode, sizeof(pvt->accountcode));
 
        pvt->amaflags = gAMAFLAGS;
-       pvt->capability = gCapability;
+       ast_format_cap_copy(pvt->cap, gCap);
        memcpy(&pvt->prefs, &gPrefs, sizeof(pvt->prefs));
 
        ast_mutex_unlock(&pvt->lock); 
@@ -549,7 +555,7 @@ static struct ooh323_pvt *ooh323_alloc(int callref, char *callToken)
 /*
        Possible data values - peername, exten/peername, exten@ip
  */
-static struct ast_channel *ooh323_request(const char *type, format_t format,
+static struct ast_channel *ooh323_request(const char *type, struct ast_format_cap *cap,
                const struct ast_channel *requestor, void *data, int *cause)
 
 {
@@ -560,17 +566,14 @@ static struct ast_channel *ooh323_request(const char *type, format_t format,
        char *ext = NULL;
        char tmp[256];
        char formats[FORMAT_STRING_SIZE];
-       int oldformat;
        int port = 0;
 
        if (gH323Debug)
                ast_verbose("---   ooh323_request - data %s format %s\n", (char*)data,  
-                                                                               ast_getformatname_multiple(formats,FORMAT_STRING_SIZE,format));
+                                                                               ast_getformatname_multiple(formats,FORMAT_STRING_SIZE,cap));
 
-       oldformat = format;
-       format &= AST_FORMAT_AUDIO_MASK;
-       if (!format) {
-               ast_log(LOG_NOTICE, "Asked to get a channel of unsupported format '%lld'\n", (long long) format);
+       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));
                return NULL;
        }
 
@@ -633,7 +636,7 @@ static struct ast_channel *ooh323_request(const char *type, format_t format,
                if (ext)
                        ast_copy_string(p->exten, ext, sizeof(p->exten));
 
-               p->capability = peer->capability;
+               ast_format_cap_copy(p->cap, peer->cap);
                memcpy(&p->prefs, &peer->prefs, sizeof(struct ast_codec_pref));
                p->dtmfmode |= peer->dtmfmode;
                p->dtmfcodec  = peer->dtmfcodec;
@@ -667,7 +670,7 @@ static struct ast_channel *ooh323_request(const char *type, format_t format,
                p->dtmfcodec = gDTMFCodec;
                p->t38support = gT38Support;
                p->rtptimeout = gRTPTimeout;
-               p->capability = gCapability;
+               ast_format_cap_copy(p->cap, gCap);
                p->rtdrinterval = gRTDRInterval;
                p->rtdrcount = gRTDRCount;
                p->faststart = gFastStart;
@@ -686,7 +689,7 @@ static struct ast_channel *ooh323_request(const char *type, format_t format,
        }
 
 
-       chan = ooh323_new(p, AST_STATE_DOWN, p->username, format,
+       chan = ooh323_new(p, AST_STATE_DOWN, p->username, cap,
                                 requestor ? requestor->linkedid : NULL);
        
        ast_mutex_unlock(&p->lock);
@@ -1140,16 +1143,16 @@ static int ooh323_write(struct ast_channel *ast, struct ast_frame *f)
                        }
 
 
-                       if (!(f->subclass.codec & ast->nativeformats)) {
-                               if (ast->nativeformats != 0) {
+                       if (!(ast_format_cap_iscompatible(ast->nativeformats, &f->subclass.format))) {
+                               if (!(ast_format_cap_is_empty(ast->nativeformats))) {
                                        ast_log(LOG_WARNING,
                                                        "Asked to transmit frame type %s, while native formats is %s (read/write = %s/%s)\n",
-                                                       ast_getformatname(f->subclass.codec),
+                                                       ast_getformatname(&f->subclass.format),
                                                        ast_getformatname_multiple(buf, sizeof(buf), ast->nativeformats),
-                                                       ast_getformatname(ast->readformat),
-                                                       ast_getformatname(ast->writeformat));
+                                                       ast_getformatname(&ast->readformat),
+                                                       ast_getformatname(&ast->writeformat));
 
-                                       ast_set_write_format(ast, f->subclass.codec);
+                                       ast_set_write_format(ast, &f->subclass.format);
                                } else {
                                        /* ast_set_write_format(ast, f->subclass);
                                        ast->nativeformats = f->subclass; */
@@ -1409,14 +1412,14 @@ static int ooh323_fixup(struct ast_channel *oldchan, struct ast_channel *newchan
 }
 
 
-void ooh323_set_write_format(ooCallData *call, int fmt, int txframes)
+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_verbose("---   ooh323_update_writeformat %s/%d\n", 
-                               ast_getformatname_multiple(formats,FORMAT_STRING_SIZE, fmt), txframes);
+                               ast_getformatname(fmt), txframes);
        
        p = find_call(call);
        if (!p) {
@@ -1426,7 +1429,7 @@ void ooh323_set_write_format(ooCallData *call, int fmt, int txframes)
 
        ast_mutex_lock(&p->lock);
 
-       p->writeformat = fmt;
+       ast_format_copy(&p->writeformat, fmt);
 
        if (p->owner) {
                while (p->owner && ast_channel_trylock(p->owner)) {
@@ -1440,8 +1443,8 @@ void ooh323_set_write_format(ooCallData *call, int fmt, int txframes)
                }
                if (gH323Debug)
                        ast_verbose("Writeformat before update %s/%s\n", 
-                         ast_getformatname_multiple(formats,FORMAT_STRING_SIZE, p->owner->writeformat),
-                         ast_getformatname_multiple(formats,FORMAT_STRING_SIZE, p->owner->nativeformats));
+                         ast_getformatname(&p->owner->writeformat),
+                         ast_getformatname_multiple(formats, sizeof(formats), p->owner->nativeformats));
                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);
@@ -1454,9 +1457,9 @@ void ooh323_set_write_format(ooCallData *call, int fmt, int txframes)
                                 p->rtp, p->dtmfcodec, "audio", "cisco-telephone-event", 0);
                }
 
-               p->owner->nativeformats = fmt;
-               ast_set_write_format(p->owner, p->owner->writeformat);
-               ast_set_read_format(p->owner, p->owner->readformat);
+               ast_format_cap_set(p->owner->nativeformats, fmt);
+               ast_set_write_format(p->owner, &p->owner->writeformat);
+               ast_set_read_format(p->owner, &p->owner->readformat);
                ast_channel_unlock(p->owner);
        } else
                ast_log(LOG_ERROR, "No owner found\n");
@@ -1468,14 +1471,13 @@ void ooh323_set_write_format(ooCallData *call, int fmt, int txframes)
                ast_verbose("+++   ooh323_update_writeformat\n");
 }
 
-void ooh323_set_read_format(ooCallData *call, int fmt)
+void ooh323_set_read_format(ooCallData *call, struct ast_format *fmt)
 {
        struct ooh323_pvt *p = NULL;
-       char formats[FORMAT_STRING_SIZE];
 
        if (gH323Debug)
                ast_verbose("---   ooh323_update_readformat %s\n", 
-                               ast_getformatname_multiple(formats,FORMAT_STRING_SIZE, fmt));
+                               ast_getformatname(fmt));
        
        p = find_call(call);
        if (!p) {
@@ -1485,8 +1487,7 @@ void ooh323_set_read_format(ooCallData *call, int fmt)
 
        ast_mutex_lock(&p->lock);
 
-       p->readformat = fmt;
-
+       ast_format_copy(&p->readformat, fmt);
 
        if (p->owner) {
                while (p->owner && ast_channel_trylock(p->owner)) {
@@ -1501,9 +1502,9 @@ void ooh323_set_read_format(ooCallData *call, int fmt)
 
                if (gH323Debug)
                        ast_verbose("Readformat before update %s\n", 
-                                 ast_getformatname_multiple(formats,FORMAT_STRING_SIZE, p->owner->readformat));
-               p->owner->nativeformats = fmt;
-               ast_set_read_format(p->owner, p->owner->readformat);
+                                 ast_getformatname(&p->owner->readformat));
+               ast_format_cap_set(p->owner->nativeformats, fmt);
+               ast_set_read_format(p->owner, &p->owner->readformat);
                ast_channel_unlock(p->owner);
        } else
                ast_log(LOG_ERROR, "No owner found\n");
@@ -1760,7 +1761,7 @@ int ooh323_onReceivedSetup(ooCallData *call, Q931Message *pmsg)
                ast_copy_string(p->context, user->context, sizeof(p->context));
                ast_copy_string(p->accountcode, user->accountcode, sizeof(p->accountcode));
                p->amaflags = user->amaflags;
-               p->capability = user->capability;
+               ast_format_cap_copy(p->cap, user->cap);
                memcpy(&p->prefs, &user->prefs, sizeof(struct ast_codec_pref));
                p->dtmfmode |= user->dtmfmode;
                p->dtmfcodec = user->dtmfcodec;
@@ -1804,7 +1805,7 @@ int ooh323_onReceivedSetup(ooCallData *call, Q931Message *pmsg)
         }
        }
 
-       ooh323c_set_capability_for_call(call, &p->prefs, p->capability, p->dtmfmode, p->dtmfcodec,
+       ooh323c_set_capability_for_call(call, &p->prefs, p->cap, p->dtmfmode, p->dtmfcodec,
                                         p->t38support);
        configure_local_rtp(p, call);
 
@@ -1971,7 +1972,7 @@ int onNewCallCreated(ooCallData *call)
                                p->username?p->username:"NULL", call->callToken, prefsBuf);
                }
 
-               ooh323c_set_capability_for_call(call, &p->prefs, p->capability, 
+               ooh323c_set_capability_for_call(call, &p->prefs, p->cap,
                                      p->dtmfmode, p->dtmfcodec, p->t38support);
 
                configure_local_rtp(p, call);
@@ -2157,6 +2158,7 @@ void ooh323_delete_peer(struct ooh323_peer *peer)
       if(peer->url)      free(peer->url);
       if(peer->e164)     free(peer->e164);
 
+               peer->cap = ast_format_cap_destroy(peer->cap);
                free(peer);
        }  
 
@@ -2176,10 +2178,14 @@ static struct ooh323_user *build_user(const char *name, struct ast_variable *v)
 
        user = ast_calloc(1,sizeof(struct ooh323_user));
        if (user) {
+               if (!(user->cap = ast_format_cap_alloc_nolock())) {
+                       ast_free(user);
+                       return NULL;
+               }
                memset(user, 0, sizeof(struct ooh323_user));
                ast_mutex_init(&user->lock);
                ast_copy_string(user->name, name, sizeof(user->name));
-               user->capability = gCapability;
+               ast_format_cap_copy(user->cap, gCap);
                memcpy(&user->prefs, &gPrefs, sizeof(user->prefs));
                user->rtptimeout = gRTPTimeout;
                user->dtmfmode = gDTMFMode;
@@ -2223,14 +2229,14 @@ static struct ooh323_user *build_user(const char *name, struct ast_variable *v)
                                } else user->rtpmask = NULL;
                        } else if (!strcasecmp(v->name, "disallow")) {
                                ast_parse_allow_disallow(&user->prefs, 
-                                       &user->capability,  v->value, 0);
+                                       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->capability,  tcodecs, 1);
+                                        user->cap,  tcodecs, 1);
                        } else if (!strcasecmp(v->name, "amaflags")) {
                                user->amaflags = ast_cdr_amaflags2int(v->value);
                        } else if (!strcasecmp(v->name, "ip")) {
@@ -2285,10 +2291,14 @@ static struct ooh323_peer *build_peer(const char *name, struct ast_variable *v,
 
        peer = ast_calloc(1, sizeof(*peer));
        if (peer) {
+               if (!(peer->cap = ast_format_cap_alloc_nolock())) {
+                       ast_free(peer);
+                       return NULL;
+               }
                memset(peer, 0, sizeof(struct ooh323_peer));
                ast_mutex_init(&peer->lock);
                ast_copy_string(peer->name, name, sizeof(peer->name));
-               peer->capability = gCapability;
+               ast_format_cap_copy(peer->cap, gCap);
                memcpy(&peer->prefs, &gPrefs, sizeof(peer->prefs));
                peer->rtptimeout = gRTPTimeout;
                ast_copy_string(peer->accountcode, gAccountcode, sizeof(peer->accountcode));
@@ -2362,14 +2372,14 @@ static struct ooh323_peer *build_peer(const char *name, struct ast_variable *v,
                                                                sizeof(peer->rtpmaskstr));
                                } else peer->rtpmask = NULL;
                        } else if (!strcasecmp(v->name, "disallow")) {
-                               ast_parse_allow_disallow(&peer->prefs, &peer->capability, 
+                               ast_parse_allow_disallow(&peer->prefs, peer->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(&peer->prefs, &peer->capability, 
+                               ast_parse_allow_disallow(&peer->prefs, peer->cap, 
                                                                                                 tcodecs, 1);                            
                        } else if (!strcasecmp(v->name,  "amaflags")) {
                                peer->amaflags = ast_cdr_amaflags2int(v->value);
@@ -2475,6 +2485,7 @@ int reload_config(int reload)
        struct ooh323_peer *peer = NULL;
        char *cat;
        const char *utype;
+       struct ast_format tmpfmt;
 
        if (gH323Debug)
                ast_verbose("---   reload_config\n");
@@ -2509,7 +2520,7 @@ int reload_config(int reload)
        gPort = 1720;
        gIP[0] = '\0';
        strcpy(gCallerID, DEFAULT_H323ID);
-       gCapability = AST_FORMAT_ALAW;
+       ast_format_cap_set(gCap, ast_format_set(&tmpfmt, AST_FORMAT_ALAW, 0));
        memset(&gPrefs, 0, sizeof(struct ast_codec_pref));
        gDTMFMode = H323_DTMF_RFC2833;
        gDTMFCodec = 101;
@@ -2678,13 +2689,13 @@ int reload_config(int reload)
                } else if (!strcasecmp(v->name, "accountcode")) {
          ast_copy_string(gAccountcode, v->value, sizeof(gAccountcode));
                } else if (!strcasecmp(v->name, "disallow")) {
-                       ast_parse_allow_disallow(&gPrefs, &gCapability, v->value, 0);
+                       ast_parse_allow_disallow(&gPrefs, gCap, 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(&gPrefs, &gCapability, tcodecs, 1);
+                       ast_parse_allow_disallow(&gPrefs, gCap, tcodecs, 1);
                } else if (!strcasecmp(v->name, "dtmfmode")) {
                        if (!strcasecmp(v->value, "inband"))
                                gDTMFMode = H323_DTMF_INBAND;
@@ -2893,7 +2904,7 @@ static char *handle_cli_ooh323_show_peers(struct ast_cli_entry *e, int cmd, stru
      ast_cli(a->fd, FORMAT, peer->name, 
                                        peer->accountcode,
                                        ip_port,
-                 ast_getformatname_multiple(formats,FORMAT_STRING_SIZE,peer->capability));
+                 ast_getformatname_multiple(formats,FORMAT_STRING_SIZE,peer->cap));
                prev = peer;
                peer = peer->next;
                ast_mutex_unlock(&prev->lock);
@@ -2907,15 +2918,15 @@ static char *handle_cli_ooh323_show_peers(struct ast_cli_entry *e, int cmd, stru
 /*! \brief Print codec list from preference to CLI/manager */
 static void print_codec_to_cli(int fd, struct ast_codec_pref *pref)
 {
-       int x, codec;
-
+       int x;
+       struct ast_format tmpfmt;
        for (x = 0; x < 32; x++) {
-               codec = ast_codec_pref_index(pref, x);
-               if (!codec)
+               ast_codec_pref_index(pref, x, &tmpfmt);
+               if (!tmpfmt.id)
                        break;
-               ast_cli(fd, "%s", ast_getformatname(codec));
+               ast_cli(fd, "%s", ast_getformatname(&tmpfmt));
                ast_cli(fd, ":%d", pref->framing[x]);
-               if (x < 31 && ast_codec_pref_index(pref, x + 1))
+               if (x < 31 && ast_codec_pref_index(pref, x + 1, &tmpfmt))
                        ast_cli(fd, ",");
        }
        if (!x)
@@ -3038,7 +3049,7 @@ static char *handle_cli_ooh323_show_users(struct ast_cli_entry *e, int cmd, stru
                ast_mutex_lock(&user->lock);
                ast_cli(a->fd, FORMAT1, user->name, 
                                        user->accountcode, user->context,
-                                       ast_getformatname_multiple(formats, FORMAT_STRING_SIZE, user->capability));
+                                       ast_getformatname_multiple(formats, FORMAT_STRING_SIZE, user->cap));
                prev = user;
                user = user->next;
                ast_mutex_unlock(&prev->lock);
@@ -3137,7 +3148,7 @@ static char *handle_cli_ooh323_show_config(struct ast_cli_entry *e, int cmd, str
    ast_cli(a->fd,  "%-20s%s\n", "Context:", gContext);
    
    ast_cli(a->fd,  "%-20s%s\n", "Capability:", 
-           ast_getformatname_multiple(value,FORMAT_STRING_SIZE,gCapability));
+           ast_getformatname_multiple(value,FORMAT_STRING_SIZE,gCap));
 
    ast_cli(a->fd, "%-20s", "DTMF Mode: ");
        if (gDTMFMode & H323_DTMF_CISCO) {
@@ -3207,6 +3218,7 @@ static int load_module(void)
        int res;
        struct ooAliases * pNewAlias = NULL;
        struct ooh323_peer *peer = NULL;
+       struct ast_format tmpfmt;
        OOH225MsgCallbacks h225Callbacks = {0, 0, 0, 0};
 
        OOH323CALLBACKS h323Callbacks = {
@@ -3221,6 +3233,14 @@ static int load_module(void)
                .onReceivedDTMF = ooh323_onReceivedDigit,
                .onModeChanged = onModeChanged
        };
+       if (!(gCap = ast_format_cap_alloc())) {
+               return 1;
+       }
+       if (!(ooh323_tech.capabilities = ast_format_cap_alloc())) {
+               return 1;
+       }
+       ast_format_cap_add(gCap, ast_format_set(&tmpfmt, AST_FORMAT_ULAW, 0));
+       ast_format_cap_add_all(ooh323_tech.capabilities);
 
        myself = ast_module_info->self;
 
@@ -3334,7 +3354,7 @@ static int load_module(void)
                ooH323EpSetH323Callbacks(h323Callbacks);
 
                /* Add endpoint capabilities */
-               if (ooh323c_set_capability(&gPrefs, gCapability, gDTMFMode, gDTMFCodec) < 0) {
+               if (ooh323c_set_capability(&gPrefs, gCap, gDTMFMode, gDTMFCodec) < 0) {
                        ast_log(LOG_ERROR, "Capabilities failure for OOH323. OOH323 Disabled.\n");
                        return 1;
                }
@@ -3558,7 +3578,7 @@ int ooh323_destroy(struct ooh323_pvt *p)
 
                ast_mutex_unlock(&cur->lock);
                ast_mutex_destroy(&cur->lock);
-
+               cur->cap = ast_format_cap_destroy(cur->cap);
                ast_free(cur);
        }
 
@@ -3623,6 +3643,7 @@ int delete_users()
                                free(prev->rtpmask);
                        }
                }
+               prev->cap = ast_format_cap_destroy(prev->cap);
                free(prev);
                if (cur == userl.users) {
                        break;
@@ -3751,6 +3772,8 @@ static int unload_module(void)
                ast_verbose("+++ ooh323  unload_module \n");    
        }
 
+       gCap = ast_format_cap_destroy(gCap);
+       ooh323_tech.capabilities = ast_format_cap_destroy(ooh323_tech.capabilities);
        return 0;
 }
 
@@ -3802,22 +3825,23 @@ int ooh323_update_capPrefsOrderForCall
        (ooCallData *call, struct ast_codec_pref *prefs)
 {
        int i = 0;
-       int codec = ast_codec_pref_index(prefs, i);
+       struct ast_format tmpfmt;
+
+       ast_codec_pref_index(prefs, i, &tmpfmt);
 
        ooResetCapPrefs(call);
-       while (codec) {
-               ooAppendCapToCapPrefs(call, ooh323_convertAsteriskCapToH323Cap(codec));
-               codec = ast_codec_pref_index(prefs, ++i);
+       while (tmpfmt.id) {
+               ooAppendCapToCapPrefs(call, ooh323_convertAsteriskCapToH323Cap(&tmpfmt));
+               ast_codec_pref_index(prefs, ++i, &tmpfmt);
        }
 
        return 0;
 }
 
 
-int ooh323_convertAsteriskCapToH323Cap(format_t cap)
+int ooh323_convertAsteriskCapToH323Cap(struct ast_format *format)
 {
-       char formats[FORMAT_STRING_SIZE];
-       switch (cap) {
+       switch (format->id) {
        case AST_FORMAT_ULAW:
                return OO_G711ULAW64K;
        case AST_FORMAT_ALAW:
@@ -3845,14 +3869,13 @@ int ooh323_convertAsteriskCapToH323Cap(format_t cap)
        case AST_FORMAT_H263:
                return OO_H263VIDEO;
        default:
-               ast_log(LOG_NOTICE, "Don't know how to deal with mode %s\n", 
-                        ast_getformatname_multiple(formats,FORMAT_STRING_SIZE,cap));
+               ast_log(LOG_NOTICE, "Don't know how to deal with mode %s\n", ast_getformatname(format));
                return -1;
        }
 }
 
 static int ooh323_set_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance *rtp,
-        struct ast_rtp_instance *vrtp, struct ast_rtp_instance *trtp, format_t codecs, int nat_active)
+        struct ast_rtp_instance *vrtp, struct ast_rtp_instance *trtp, const struct ast_format_cap *cap, int nat_active)
 {
        /* XXX Deal with Video */
        struct ooh323_pvt *p;
@@ -3868,7 +3891,7 @@ static int ooh323_set_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance
                return 0;
        }
 
-       mode = ooh323_convertAsteriskCapToH323Cap(chan->writeformat); 
+       mode = ooh323_convertAsteriskCapToH323Cap(&chan->writeformat); 
        p = (struct ooh323_pvt *) chan->tech_pvt;
        if (!p) {
                ast_log(LOG_ERROR, "No Private Structure, this is bad\n");
@@ -3890,7 +3913,9 @@ int configure_local_rtp(struct ooh323_pvt *p, ooCallData *call)
        struct ast_sockaddr tmp;
        ooMediaInfo mediaInfo;
        int x;
-       format_t format = 0;
+       struct ast_format tmpfmt;
+
+       ast_format_clear(&tmpfmt);
 
        if (gH323Debug)
                ast_verbose("---   configure_local_rtp\n");
@@ -3929,9 +3954,9 @@ int configure_local_rtp(struct ooh323_pvt *p, ooCallData *call)
        ast_copy_string(mediaInfo.lMediaIP, ast_inet_ntoa(us.sin_addr), sizeof(mediaInfo.lMediaIP));
        mediaInfo.lMediaPort = ntohs(us.sin_port);
        mediaInfo.lMediaCntrlPort = mediaInfo.lMediaPort +1;
-       for (x = 0; 0 != (format = ast_codec_pref_index(&p->prefs, x)); x++) {
+       for (x = 0; ast_codec_pref_index(&p->prefs, x, &tmpfmt); x++) {
                strcpy(mediaInfo.dir, "transmit");
-               mediaInfo.cap = ooh323_convertAsteriskCapToH323Cap(format);
+               mediaInfo.cap = ooh323_convertAsteriskCapToH323Cap(&tmpfmt);
                ooAddMediaInfo(call, mediaInfo);
                strcpy(mediaInfo.dir, "receive");
                ooAddMediaInfo(call, mediaInfo);
@@ -3995,7 +4020,7 @@ void setup_rtp_connection(ooCallData *call, const char *remoteIp,
        ast_sockaddr_from_sin(&tmp, &them);
        ast_rtp_instance_set_remote_address(p->rtp, &tmp);
 
-       if (p->writeformat & AST_FORMAT_G726_AAL2) 
+       if (p->writeformat.id == AST_FORMAT_G726_AAL2) 
                 ast_rtp_codecs_payloads_set_rtpmap_type(ast_rtp_instance_get_codecs(p->rtp), p->rtp, 2,
                                                        "audio", "G726-32", AST_RTP_OPT_G726_NONSTANDARD);
 
@@ -4237,16 +4262,16 @@ struct ast_frame *ooh323_rtp_read(struct ast_channel *ast, struct ooh323_pvt *p)
        if (p->owner) {
                /* We already hold the channel lock */
                if (f->frametype == AST_FRAME_VOICE && !p->faxmode) {
-                       if (f->subclass.codec != p->owner->nativeformats) {
-                               ast_debug(1, "Oooh, voice format changed to %s\n", ast_getformatname(f->subclass.codec));
-                               p->owner->nativeformats = f->subclass.codec;
-                               ast_set_read_format(p->owner, p->owner->readformat);
-                               ast_set_write_format(p->owner, p->owner->writeformat);
+                       if (!(ast_format_cap_iscompatible(p->owner->nativeformats, &f->subclass.format))) {
+                               ast_debug(1, "Oooh, voice format changed to %s\n", ast_getformatname(&f->subclass.format));
+                               ast_format_cap_set(p->owner->nativeformats, &f->subclass.format);
+                               ast_set_read_format(p->owner, &p->owner->readformat);
+                               ast_set_write_format(p->owner, &p->owner->writeformat);
                        }
 
                        if ((p->dtmfmode & H323_DTMF_INBAND) && p->vad &&
-                               (f->subclass.codec == AST_FORMAT_SLINEAR || f->subclass.codec == AST_FORMAT_ALAW ||
-                                       f->subclass.codec == AST_FORMAT_ULAW)) {
+                               (f->subclass.format.id == AST_FORMAT_SLINEAR || f->subclass.format.id == AST_FORMAT_ALAW ||
+                                       f->subclass.format.id == AST_FORMAT_ULAW)) {
                                f = ast_dsp_process(p->owner, p->vad, f);
                                if (f && (f->frametype == AST_FRAME_DTMF)) 
                                                ast_debug(1, "* Detected inband DTMF '%c'\n", f->subclass.integer);
index 65eefb7..2fb9039 100644 (file)
@@ -61,7 +61,8 @@
 #include "asterisk/manager.h"
 #include "asterisk/dsp.h"
 #include "asterisk/stringfields.h"
-#include "asterisk/frame_defs.h"
+#include "asterisk/format.h"
+#include "asterisk/format_cap.h"
 #include "asterisk/udptl.h"
 
 #include "ootypes.h"
@@ -99,13 +100,13 @@ void close_rtp_connection(ooCallData *call);
 struct ast_frame *ooh323_rtp_read
          (struct ast_channel *ast, struct ooh323_pvt *p);
 
-void ooh323_set_write_format(ooCallData *call, int fmt, int txframes);
-void ooh323_set_read_format(ooCallData *call, int fmt);
+void ooh323_set_write_format(ooCallData *call, struct ast_format *fmt, int txframes);
+void ooh323_set_read_format(ooCallData *call, struct ast_format *fmt);
 
 int ooh323_update_capPrefsOrderForCall
    (ooCallData *call, struct ast_codec_pref *prefs);
 
-int ooh323_convertAsteriskCapToH323Cap(format_t cap);
+int ooh323_convertAsteriskCapToH323Cap(struct ast_format *format);
 
 int ooh323_convert_hangupcause_asteriskToH323(int cause);
 int ooh323_convert_hangupcause_h323ToAsterisk(int cause);
index ceb1acc..d59411d 100644 (file)
@@ -224,7 +224,7 @@ static struct ast_frame *mp3_read(struct ast_filestream *s, int *whennext)
        p->offset += p->buflen;
        delay = p->buflen/2;
        s->fr.frametype = AST_FRAME_VOICE;
-       s->fr.subclass.codec = AST_FORMAT_SLINEAR;
+       ast_format_set(&s->fr.subclass.format, AST_FORMAT_SLINEAR, 0);
        AST_FRAME_SET_BUFFER(&s->fr, s->buf, AST_FRIENDLY_OFFSET, p->buflen);
        s->fr.mallocd = 0;
        s->fr.samples = delay;
@@ -293,10 +293,9 @@ static char *mp3_getcomment(struct ast_filestream *s)
        return NULL;
 }
 
-static const struct ast_format mp3_f = {
+static struct ast_format_def mp3_f = {
        .name = "mp3",
        .exts = "mp3",
-       .format = AST_FORMAT_SLINEAR,
        .open = mp3_open,
        .write = mp3_write,
        .rewrite = mp3_rewrite,
@@ -313,13 +312,14 @@ static const struct ast_format mp3_f = {
 
 static int load_module(void)
 {
+       ast_format_set(&mp3_f.format, AST_FORMAT_SLINEAR, 0);
        InitMP3Constants();
-       return ast_format_register(&mp3_f);
+       return ast_format_def_register(&mp3_f);
 }
 
 static int unload_module(void)
 {
-       return ast_format_unregister(name);
+       return ast_format_def_unregister(name);
 }      
 
 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "MP3 format [Any rate but 8000hz mono is optimal]");
index dd07bb4..604336c 100644 (file)
@@ -226,15 +226,16 @@ int ooh323c_stop_stack_thread(void)
 }
 
 int ooh323c_set_capability
-   (struct ast_codec_pref *prefs, int capability, int dtmf, int dtmfcodec)
+   (struct ast_codec_pref *prefs, struct ast_format_cap *cap, int dtmf, int dtmfcodec)
 {
-   int ret = 0, x, format=0;
+   int ret = 0, x;
+   struct ast_format tmpfmt;
    if(gH323Debug)
      ast_verbose("\tAdding capabilities to H323 endpoint\n");
    
-   for(x=0; 0 != (format=ast_codec_pref_index(prefs, x)); x++)
+   for(x=0; ast_codec_pref_index(prefs, x, &tmpfmt); x++)
    {
-      if(format & AST_FORMAT_ULAW)
+      if(tmpfmt.id == AST_FORMAT_ULAW)
       {
          if(gH323Debug)
             ast_verbose("\tAdding g711 ulaw capability to H323 endpoint\n");
@@ -244,7 +245,7 @@ int ooh323c_set_capability
                                      &ooh323c_stop_receive_channel, 
                                      &ooh323c_stop_transmit_channel);
       }
-      if(format & AST_FORMAT_ALAW)
+      if(tmpfmt.id == AST_FORMAT_ALAW)
       {
          if(gH323Debug)
             ast_verbose("\tAdding g711 alaw capability to H323 endpoint\n");
@@ -255,7 +256,7 @@ int ooh323c_set_capability
                                      &ooh323c_stop_transmit_channel);
       }
 
-      if(format & AST_FORMAT_G729A)
+      if(tmpfmt.id == AST_FORMAT_G729A)
       {
          if(gH323Debug)
             ast_verbose("\tAdding g729A capability to H323 endpoint\n");
@@ -281,7 +282,7 @@ int ooh323c_set_capability
                                      &ooh323c_stop_transmit_channel);
       }
 
-      if(format & AST_FORMAT_G723_1)
+      if(tmpfmt.id == AST_FORMAT_G723_1)
       {
          if(gH323Debug)
             ast_verbose("\tAdding g7231 capability to H323 endpoint\n");
@@ -293,7 +294,7 @@ int ooh323c_set_capability
 
       }
 
-      if(format & AST_FORMAT_G726)
+      if(tmpfmt.id == AST_FORMAT_G726)
       {
          if(gH323Debug)
             ast_verbose("\tAdding g726 capability to H323 endpoint\n");
@@ -305,7 +306,7 @@ int ooh323c_set_capability
 
       }
 
-      if(format & AST_FORMAT_G726_AAL2)
+      if(tmpfmt.id == AST_FORMAT_G726_AAL2)
       {
          if(gH323Debug)
             ast_verbose("\tAdding g726aal2 capability to H323 endpoint\n");
@@ -317,7 +318,7 @@ int ooh323c_set_capability
 
       }
 
-      if(format & AST_FORMAT_H263)
+      if(tmpfmt.id == AST_FORMAT_H263)
       {
          if(gH323Debug)
             ast_verbose("\tAdding h263 capability to H323 endpoint\n");
@@ -329,7 +330,7 @@ int ooh323c_set_capability
 
       }
 
-      if(format & AST_FORMAT_GSM)
+      if(tmpfmt.id == AST_FORMAT_GSM)
       {
          if(gH323Debug)
             ast_verbose("\tAdding gsm capability to H323 endpoint\n");
@@ -342,7 +343,7 @@ int ooh323c_set_capability
       }
       
 #ifdef AST_FORMAT_AMRNB
-      if(format & AST_FORMAT_AMRNB)
+      if(tmpfmt.id == AST_FORMAT_AMRNB)
       {
          if(gH323Debug)
             ast_verbose("\tAdding amr nb capability to H323 endpoint\n");
@@ -356,7 +357,7 @@ int ooh323c_set_capability
 #endif
 
 #ifdef AST_FORMAT_SPEEX
-      if(format & AST_FORMAT_SPEEX)
+      if(tmpfmt.id == AST_FORMAT_SPEEX)
       {
          if(gH323Debug)
             ast_verbose("\tAdding speex capability to H323 endpoint\n");
@@ -384,11 +385,11 @@ int ooh323c_set_capability
 }
 
 int ooh323c_set_capability_for_call
-   (ooCallData *call, struct ast_codec_pref *prefs, int capability, int dtmf, int dtmfcodec,
+   (ooCallData *call, struct ast_codec_pref *prefs, struct ast_format_cap *cap, int dtmf, int dtmfcodec,
                 int t38support)
 {
    int ret = 0, x, txframes;
-   int format=0;
+   struct ast_format tmpfmt;
    if(gH323Debug)
      ast_verbose("\tAdding capabilities to call(%s, %s)\n", call->callType, 
                                                             call->callToken);
@@ -409,9 +410,9 @@ int ooh323c_set_capability_for_call
                                        &ooh323c_stop_transmit_datachannel,
                                        0);
 
-   for(x=0; 0 !=(format=ast_codec_pref_index(prefs, x)); x++)
+   for(x=0; ast_codec_pref_index(prefs, x, &tmpfmt); x++)
    {
-      if(format & AST_FORMAT_ULAW)
+      if(tmpfmt.id == AST_FORMAT_ULAW)
       {
          if(gH323Debug)
             ast_verbose("\tAdding g711 ulaw capability to call(%s, %s)\n", 
@@ -424,7 +425,7 @@ int ooh323c_set_capability_for_call
                                       &ooh323c_stop_receive_channel, 
                                       &ooh323c_stop_transmit_channel);
       }
-      if(format & AST_FORMAT_ALAW)
+      if(tmpfmt.id == AST_FORMAT_ALAW)
       {
          if(gH323Debug)
             ast_verbose("\tAdding g711 alaw capability to call(%s, %s)\n",
@@ -438,7 +439,7 @@ int ooh323c_set_capability_for_call
                                      &ooh323c_stop_transmit_channel);
       }
 
-      if(format & AST_FORMAT_G726)
+      if(tmpfmt.id == AST_FORMAT_G726)
       {
          if(gH323Debug)
             ast_verbose("\tAdding g726 capability to call (%s, %s)\n",
@@ -452,7 +453,7 @@ int ooh323c_set_capability_for_call
 
       }
 
-      if(format & AST_FORMAT_G726_AAL2)
+      if(tmpfmt.id == AST_FORMAT_G726_AAL2)
       {
          if(gH323Debug)
             ast_verbose("\tAdding g726aal2 capability to call (%s, %s)\n",
@@ -466,7 +467,7 @@ int ooh323c_set_capability_for_call
 
       }
 
-      if(format & AST_FORMAT_G729A)
+      if(tmpfmt.id == AST_FORMAT_G729A)
       {
       
          txframes = (prefs->framing[x])/10;
@@ -497,7 +498,7 @@ int ooh323c_set_capability_for_call
 
       }
 
-      if(format & AST_FORMAT_G723_1)
+      if(tmpfmt.id == AST_FORMAT_G723_1)
       {
          if(gH323Debug)
             ast_verbose("\tAdding g7231 capability to call (%s, %s)\n",
@@ -510,7 +511,7 @@ int ooh323c_set_capability_for_call
 
       }
 
-      if(format & AST_FORMAT_H263)
+      if(tmpfmt.id == AST_FORMAT_H263)
       {
          if(gH323Debug)
             ast_verbose("\tAdding h263 capability to call (%s, %s)\n",
@@ -523,7 +524,7 @@ int ooh323c_set_capability_for_call
 
       }
 
-      if(format & AST_FORMAT_GSM)
+      if(tmpfmt.id == AST_FORMAT_GSM)
       {
          if(gH323Debug)
             ast_verbose("\tAdding gsm capability to call(%s, %s)\n", 
@@ -536,7 +537,7 @@ int ooh323c_set_capability_for_call
       }
 
 #ifdef AST_FORMAT_AMRNB
-      if(format & AST_FORMAT_AMRNB)
+      if(tmpfmt.id == AST_FORMAT_AMRNB)
       {
          if(gH323Debug)
             ast_verbose("\tAdding AMR capability to call(%s, %s)\n", 
@@ -549,7 +550,7 @@ int ooh323c_set_capability_for_call
       }
 #endif
 #ifdef AST_FORMAT_SPEEX
-      if(format & AST_FORMAT_SPEEX)
+      if(tmpfmt.id == AST_FORMAT_SPEEX)
       {
          if(gH323Debug)
             ast_verbose("\tAdding Speex capability to call(%s, %s)\n", 
@@ -594,9 +595,9 @@ int ooh323c_set_aliases(ooAliases * aliases)
    
 int ooh323c_start_receive_channel(ooCallData *call, ooLogicalChannel *pChannel)
 {
-   format_t fmt=-1;
-   fmt = convertH323CapToAsteriskCap(pChannel->chanCap->cap);
-   if(fmt>0) {
+   struct ast_format tmpfmt;
+   convertH323CapToAsteriskCap(pChannel->chanCap->cap, &tmpfmt);
+   if(tmpfmt.id) {
       /* ooh323_set_read_format(call, fmt); */
    }else{
      ast_log(LOG_ERROR, "Invalid capability type for receive channel %s\n",
@@ -608,19 +609,19 @@ int ooh323c_start_receive_channel(ooCallData *call, ooLogicalChannel *pChannel)
 
 int ooh323c_start_transmit_channel(ooCallData *call, ooLogicalChannel *pChannel)
 {
-   format_t fmt;
-   fmt = convertH323CapToAsteriskCap(pChannel->chanCap->cap);
-   if(fmt>0) {
-      switch (fmt) {
+   struct ast_format tmpfmt;
+   convertH323CapToAsteriskCap(pChannel->chanCap->cap, &tmpfmt);
+   if(tmpfmt.id) {
+      switch (tmpfmt.id) {
       case AST_FORMAT_ALAW:
       case AST_FORMAT_ULAW:
-       ooh323_set_write_format(call, fmt, ((OOCapParams *)(pChannel->chanCap->params))->txframes);
+       ooh323_set_write_format(call, &tmpfmt, ((OOCapParams *)(pChannel->chanCap->params))->txframes);
        break;
       case AST_FORMAT_G729A:
-       ooh323_set_write_format(call, fmt, ((OOCapParams *)(pChannel->chanCap->params))->txframes*10);
+       ooh323_set_write_format(call, &tmpfmt, ((OOCapParams *)(pChannel->chanCap->params))->txframes*10);
        break;
       default:
-       ooh323_set_write_format(call, fmt, 0);
+       ooh323_set_write_format(call, &tmpfmt, 0);
       }
    }else{
       ast_log(LOG_ERROR, "Invalid capability type for receive channel %s\n",
@@ -665,47 +666,47 @@ int ooh323c_stop_transmit_datachannel(ooCallData *call, ooLogicalChannel *pChann
    return 1;
 }
 
-format_t convertH323CapToAsteriskCap(int cap)
+struct ast_format *convertH323CapToAsteriskCap(int cap, struct ast_format *result)
 {
-
+   ast_format_clear(result);
    switch(cap)
    {
       case OO_G711ULAW64K:
-         return AST_FORMAT_ULAW;
+         return ast_format_set(result, AST_FORMAT_ULAW, 0);
       case OO_G711ALAW64K:
-         return AST_FORMAT_ALAW;
+         return ast_format_set(result, AST_FORMAT_ALAW, 0);
       case OO_GSMFULLRATE:
-         return AST_FORMAT_GSM;
+         return ast_format_set(result, AST_FORMAT_GSM, 0);
 
 #ifdef AST_FORMAT_AMRNB
       case OO_AMRNB:
-         return AST_FORMAT_AMRNB;
+         return ast_format_set(result, AST_FORMAT_AMRNB, 0);
 #endif
 #ifdef AST_FORMAT_SPEEX
       case OO_SPEEX:
-         return AST_FORMAT_SPEEX;
+         return ast_format_set(result, AST_FORMAT_SPEEX, 0);
 #endif
 
       case OO_G729:
-         return AST_FORMAT_G729A;
+         return ast_format_set(result, AST_FORMAT_G729A, 0);
       case OO_G729A:
-         return AST_FORMAT_G729A;
+         return ast_format_set(result, AST_FORMAT_G729A, 0);
       case OO_G729B:
-         return AST_FORMAT_G729A;
+         return ast_format_set(result, AST_FORMAT_G729A, 0);
       case OO_G7231:
-         return AST_FORMAT_G723_1;
+         return ast_format_set(result, AST_FORMAT_G723_1, 0);
       case OO_G726:
-         return AST_FORMAT_G726;
+         return ast_format_set(result, AST_FORMAT_G726, 0);
       case OO_G726AAL2:
-         return AST_FORMAT_G726_AAL2;
+         return ast_format_set(result, AST_FORMAT_G726_AAL2, 0);
       case OO_H263VIDEO:
-         return AST_FORMAT_H263;
+         return ast_format_set(result, AST_FORMAT_H263, 0);
       default:
          ast_debug(1, "Cap %d is not supported by driver yet\n", cap);
-         return -1;
+         return NULL;
    }
 
-   return -1;
+   return NULL;
 }
 
  
index 269c56a..f16b8af 100644 (file)
@@ -22,7 +22,7 @@
 #include "ooCalls.h"
 #include "ooCapability.h"
 #include "ooStackCmds.h"
-#include "asterisk/frame_defs.h"
+#include "asterisk/format.h"
 #define H323_DTMF_RFC2833          (1 << 0)
 #define H323_DTMF_Q931             (1 << 1)
 #define H323_DTMF_H245ALPHANUMERIC (1 << 2)
@@ -37,9 +37,9 @@ int ooh323c_stop_stack_thread(void);
 int ooh323c_start_call_thread(ooCallData *call);
 int ooh323c_stop_call_thread(ooCallData *call);
 int ooh323c_set_capability
-   (struct ast_codec_pref *prefs, int capability, int dtmf, int dtmfcodec);
-format_t convertH323CapToAsteriskCap(int cap);
+   (struct ast_codec_pref *prefs, struct ast_format_cap *cap, int dtmf, int dtmfcodec);
+struct ast_format *convertH323CapToAsteriskCap(int cap, struct ast_format *format);
 int ooh323c_set_capability_for_call
-   (ooCallData *call, struct ast_codec_pref *prefs, int capability, int dtmf, int dtmfcodec,
+   (ooCallData *call, struct ast_codec_pref *prefs, struct ast_format_cap *cap, int dtmf, int dtmfcodec,
        int t38support);
 #endif
index 952ef72..6936cb5 100644 (file)
@@ -191,7 +191,7 @@ static int send_tone_burst(struct ast_channel *chan, float freq, int duration, i
 
                if (f->frametype == AST_FRAME_VOICE) {
                        wf.frametype = AST_FRAME_VOICE;
-                       wf.subclass.codec = AST_FORMAT_ULAW;
+                       ast_format_set(&wf.subclass.format, AST_FORMAT_ULAW, 0);
                        wf.offset = AST_FRIENDLY_OFFSET;
                        wf.mallocd = 0;
                        wf.data.ptr = tone_block.buf;
@@ -578,12 +578,12 @@ static int alarmreceiver_exec(struct ast_channel *chan, const char *data)
        /* Set write and read formats to ULAW */
        ast_verb(4, "AlarmReceiver: Setting read and write formats to ULAW\n");
 
-       if (ast_set_write_format(chan,AST_FORMAT_ULAW)) {
+       if (ast_set_write_format_by_id(chan,AST_FORMAT_ULAW)) {
                ast_log(LOG_WARNING, "AlarmReceiver: Unable to set write format to Mu-law on %s\n",chan->name);
                return -1;
        }
 
-       if (ast_set_read_format(chan,AST_FORMAT_ULAW)) {
+       if (ast_set_read_format_by_id(chan,AST_FORMAT_ULAW)) {
                ast_log(LOG_WARNING, "AlarmReceiver: Unable to set read format to Mu-law on %s\n",chan->name);
                return -1;
        }
index c978ce0..60c13fd 100644 (file)
@@ -148,7 +148,8 @@ static void isAnsweringMachine(struct ast_channel *chan, const char *data)
        int res = 0;
        struct ast_frame *f = NULL;
        struct ast_dsp *silenceDetector = NULL;
-       int dspsilence = 0, readFormat, framelength = 0;
+       int dspsilence = 0, framelength = 0;
+       struct ast_format readFormat;
        int inInitialSilence = 1;
        int inGreeting = 0;
        int voiceDuration = 0;
@@ -188,10 +189,11 @@ static void isAnsweringMachine(struct ast_channel *chan, const char *data)
                AST_APP_ARG(argMaximumWordLength);
        );
 
+       ast_format_clear(&readFormat);
        ast_verb(3, "AMD: %s %s %s (Fmt: %s)\n", chan->name,
                S_COR(chan->caller.ani.number.valid, chan->caller.ani.number.str, "(N/A)"),
                S_COR(chan->redirecting.from.number.valid, chan->redirecting.from.number.str, "(N/A)"),
-               ast_getformatname(chan->readformat));
+               ast_getformatname(&chan->readformat));
 
        /* Lets parse the arguments. */
        if (!ast_strlen_zero(parse)) {
@@ -240,8 +242,8 @@ static void isAnsweringMachine(struct ast_channel *chan, const char *data)
                                minimumWordLength, betweenWordsSilence, maximumNumberOfWords, silenceThreshold, maximumWordLength);
 
        /* Set read format to signed linear so we get signed linear frames in */
-       readFormat = chan->readformat;
-       if (ast_set_read_format(chan, AST_FORMAT_SLINEAR) < 0 ) {
+       ast_format_copy(&readFormat, &chan->readformat);
+       if (ast_set_read_format_by_id(chan, AST_FORMAT_SLINEAR) < 0 ) {
                ast_log(LOG_WARNING, "AMD: Channel [%s]. Unable to set to linear mode, giving up\n", chan->name );
                pbx_builtin_setvar_helper(chan , "AMDSTATUS", "");
                pbx_builtin_setvar_helper(chan , "AMDCAUSE", "");
@@ -399,7 +401,7 @@ static void isAnsweringMachine(struct ast_channel *chan, const char *data)
        pbx_builtin_setvar_helper(chan , "AMDCAUSE" , amdCause);
 
        /* Restore channel read format */
-       if (readFormat && ast_set_read_format(chan, readFormat))
+       if (readFormat.id && ast_set_read_format(chan, &readFormat))
                ast_log(LOG_WARNING, "AMD: Unable to restore read format on '%s'\n", chan->name);
 
        /* Free the DSP used to detect silence */
index 4b671df..1fc544a 100644 (file)
@@ -427,6 +427,9 @@ static int spy_generate(struct ast_channel *chan, void *data, int len, int sampl
 {
        struct chanspy_translation_helper *csth = data;
        struct ast_frame *f, *cur;
+       struct ast_format format_slin;
+
+       ast_format_set(&format_slin, AST_FORMAT_SLINEAR, 0);
 
        ast_audiohook_lock(&csth->spy_audiohook);
        if (csth->spy_audiohook.status != AST_AUDIOHOOK_STATUS_RUNNING) {
@@ -437,9 +440,9 @@ static int spy_generate(struct ast_channel *chan, void *data, int len, int sampl
 
        if (ast_test_flag(&csth->spy_audiohook, OPTION_READONLY)) {
                /* Option 'o' was set, so don't mix channel audio */
-               f = ast_audiohook_read_frame(&csth->spy_audiohook, samples, AST_AUDIOHOOK_DIRECTION_READ, AST_FORMAT_SLINEAR);
+               f = ast_audiohook_read_frame(&csth->spy_audiohook, samples, AST_AUDIOHOOK_DIRECTION_READ, &format_slin);
        } else {
-               f = ast_audiohook_read_frame(&csth->spy_audiohook, samples, AST_AUDIOHOOK_DIRECTION_BOTH, AST_FORMAT_SLINEAR);
+               f = ast_audiohook_read_frame(&csth->spy_audiohook, samples, AST_AUDIOHOOK_DIRECTION_BOTH, &format_slin);
        }
 
        ast_audiohook_unlock(&csth->spy_audiohook);
@@ -1006,7 +1009,7 @@ static int chanspy_exec(struct ast_channel *chan, const char *data)
                .volume = '#',
                .exit = '\0',
        };
-       int oldwf = 0;
+       struct ast_format oldwf;
        int volfactor = 0;
        int res;
        char *mailbox = NULL;
@@ -1019,6 +1022,7 @@ static int chanspy_exec(struct ast_channel *chan, const char *data)
        char *parse = ast_strdupa(data);
 
        AST_STANDARD_APP_ARGS(args, parse);
+       ast_format_clear(&oldwf);
 
        if (args.spec && !strcmp(args.spec, "all"))
                args.spec = NULL;
@@ -1082,8 +1086,8 @@ static int chanspy_exec(struct ast_channel *chan, const char *data)
                ast_clear_flag(&flags, AST_FLAGS_ALL);
        }
 
-       oldwf = chan->writeformat;
-       if (ast_set_write_format(chan, AST_FORMAT_SLINEAR) < 0) {
+       ast_format_copy(&oldwf, &chan->writeformat);
+       if (ast_set_write_format_by_id(chan, AST_FORMAT_SLINEAR) < 0) {
                ast_log(LOG_ERROR, "Could Not Set Write Format.\n");
                return -1;
        }
@@ -1103,7 +1107,7 @@ static int chanspy_exec(struct ast_channel *chan, const char *data)
        if (fd)
                close(fd);
 
-       if (oldwf && ast_set_write_format(chan, oldwf) < 0)
+       if (oldwf.id && ast_set_write_format(chan, &oldwf) < 0)
                ast_log(LOG_ERROR, "Could Not Set Write Format.\n");
 
        if (ast_test_flag(&flags, OPTION_EXITONHANGUP)) {
@@ -1125,7 +1129,7 @@ static int extenspy_exec(struct ast_channel *chan, const char *data)
                .volume = '#',
                .exit = '\0',
        };
-       int oldwf = 0;
+       struct ast_format oldwf;
        int volfactor = 0;
        int res;
        char *mailbox = NULL;
@@ -1137,12 +1141,13 @@ static int extenspy_exec(struct ast_channel *chan, const char *data)
        char *parse = ast_strdupa(data);
 
        AST_STANDARD_APP_ARGS(args, parse);
+       ast_format_clear(&oldwf);
+
        if (!ast_strlen_zero(args.context) && (ptr = strchr(args.context, '@'))) {
                exten = args.context;
                *ptr++ = '\0';
                args.context = ptr;
        }
-
        if (ast_strlen_zero(args.context))
                args.context = ast_strdupa(chan->context);
 
@@ -1206,7 +1211,7 @@ static int extenspy_exec(struct ast_channel *chan, const char *data)
        }
 
        oldwf = chan->writeformat;
-       if (ast_set_write_format(chan, AST_FORMAT_SLINEAR) < 0) {
+       if (ast_set_write_format_by_id(chan, AST_FORMAT_SLINEAR) < 0) {
                ast_log(LOG_ERROR, "Could Not Set Write Format.\n");
                return -1;
        }
@@ -1227,7 +1232,7 @@ static int extenspy_exec(struct ast_channel *chan, const char *data)
        if (fd)
                close(fd);
 
-       if (oldwf && ast_set_write_format(chan, oldwf) < 0)
+       if (oldwf.id && ast_set_write_format(chan, &oldwf) < 0)
                ast_log(LOG_ERROR, "Could Not Set Write Format.\n");
 
        return res;
@@ -1242,12 +1247,12 @@ static int dahdiscan_exec(struct ast_channel *chan, const char *data)
                .volume = '\0',
                .exit = '*',
        };
-       int oldwf = 0;
+       struct ast_format oldwf;
        int res;
        char *mygroup = NULL;
 
        ast_clear_flag(&flags, AST_FLAGS_ALL);
-
+       ast_format_clear(&oldwf);
        if (!ast_strlen_zero(data)) {
                mygroup = ast_strdupa(data);
        }
@@ -1255,15 +1260,15 @@ static int dahdiscan_exec(struct ast_channel *chan, const char *data)
        ast_set_flag(&flags, OPTION_DTMF_CYCLE);
        ast_set_flag(&flags, OPTION_DAHDI_SCAN);
 
-       oldwf = chan->writeformat;
-       if (ast_set_write_format(chan, AST_FORMAT_SLINEAR) < 0) {
+       ast_format_copy(&oldwf, &chan->writeformat);
+       if (ast_set_write_format_by_id(chan, AST_FORMAT_SLINEAR) < 0) {
                ast_log(LOG_ERROR, "Could Not Set Write Format.\n");
                return -1;
        }
 
        res = common_exec(chan, &flags, 0, 0, &user_options, mygroup, NULL, spec, NULL, NULL, NULL, NULL);
 
-       if (oldwf && ast_set_write_format(chan, oldwf) < 0)
+       if (oldwf.id && ast_set_write_format(chan, &oldwf) < 0)
                ast_log(LOG_ERROR, "Could Not Set Write Format.\n");
 
        return res;
index 71608d4..e533c80 100644 (file)
@@ -568,11 +568,18 @@ static int play_sound_file(struct conference_bridge *conference_bridge, const ch
 
        if (!(conference_bridge->playback_chan)) {
                int cause;
-
-               if (!(conference_bridge->playback_chan = ast_request("Bridge", AST_FORMAT_SLINEAR, NULL, "", &cause))) {
+               struct ast_format_cap *cap = ast_format_cap_alloc_nolock();
+               struct ast_format tmpfmt;
+               if (!cap) {
+                       return -1;
+               }
+               ast_format_cap_add(cap, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR, 0));
+               if (!(conference_bridge->playback_chan = ast_request("Bridge", cap, NULL, "", &cause))) {
                        ast_mutex_unlock(&conference_bridge->playback_lock);
+                       cap = ast_format_cap_destroy(cap);
                        return -1;
                }
+               cap = ast_format_cap_destroy(cap);
 
                conference_bridge->playback_chan->bridge = conference_bridge->bridge;
 
index d9dd590..082405e 100644 (file)
@@ -113,13 +113,13 @@ static int conf_run(struct ast_channel *chan, int confno, int confflags)
        char *buf = __buf + AST_FRIENDLY_OFFSET;
 
        /* Set it into U-law mode (write) */
-       if (ast_set_write_format(chan, AST_FORMAT_ULAW) < 0) {
+       if (ast_set_write_format_by_id(chan, AST_FORMAT_ULAW) < 0) {
                ast_log(LOG_WARNING, "Unable to set '%s' to write ulaw mode\n", chan->name);
                goto outrun;
        }
 
        /* Set it into U-law mode (read) */
-       if (ast_set_read_format(chan, AST_FORMAT_ULAW) < 0) {
+       if (ast_set_read_format_by_id(chan, AST_FORMAT_ULAW) < 0) {
                ast_log(LOG_WARNING, "Unable to set '%s' to read ulaw mode\n", chan->name);
                goto outrun;
        }
@@ -214,11 +214,11 @@ dahdiretry:
                                break;
                        } else if (fd != chan->fds[0]) {
                                if (f->frametype == AST_FRAME_VOICE) {
-                                       if (f->subclass.codec == AST_FORMAT_ULAW) {
+                                       if (f->subclass.format.id == AST_FORMAT_ULAW) {
                                                /* Carefully write */
                                                careful_write(fd, f->data.ptr, f->datalen);
                                        } else
-                                               ast_log(LOG_WARNING, "Huh?  Got a non-ulaw (%s) frame in the conference\n", ast_getformatname(f->subclass.codec));
+                                               ast_log(LOG_WARNING, "Huh?  Got a non-ulaw (%s) frame in the conference\n", ast_getformatname(&f->subclass.format));
                                }
                        }
                        ast_frfree(f);
@@ -227,7 +227,7 @@ dahdiretry:
                        if (res > 0) {
                                memset(&fr, 0, sizeof(fr));
                                fr.frametype = AST_FRAME_VOICE;
-                               fr.subclass.codec = AST_FORMAT_ULAW;
+                               ast_format_set(&fr.subclass.format, AST_FORMAT_ULAW, 0);
                                fr.datalen = res;
                                fr.samples = res;
                                fr.data.ptr = buf;
index e9e5f0d..5bf439d 100644 (file)
@@ -97,7 +97,6 @@ static int dictate_exec(struct ast_channel *chan, const char *data)
        int ffactor = 320 * 80,
                res = 0,
                done = 0,
-               oldr = 0,
                lastop = 0,
                samples = 0,
                speed = 1,
@@ -105,6 +104,8 @@ static int dictate_exec(struct ast_channel *chan, const char *data)
                len = 0,
                maxlen = 0,
                mode = 0;
+       struct ast_format oldr;
+       ast_format_clear(&oldr);
 
        snprintf(dftbase, sizeof(dftbase), "%s/dictate", ast_config_AST_SPOOL_DIR);
        if (!ast_strlen_zero(data)) {
@@ -121,8 +122,8 @@ static int dictate_exec(struct ast_channel *chan, const char *data)
        if (args.argc > 1 && args.filename) {
                filename = args.filename;
        }
-       oldr = chan->readformat;
-       if ((res = ast_set_read_format(chan, AST_FORMAT_SLINEAR)) < 0) {
+       ast_format_copy(&oldr, &chan->readformat);
+       if ((res = ast_set_read_format_by_id(chan, AST_FORMAT_SLINEAR)) < 0) {
                ast_log(LOG_WARNING, "Unable to set to linear mode.\n");
                return -1;
        }
@@ -330,8 +331,8 @@ static int dictate_exec(struct ast_channel *chan, const char *data)
                        ast_frfree(f);
                }
        }
-       if (oldr) {
-               ast_set_read_format(chan, oldr);
+       if (oldr.id) {
+               ast_set_read_format(chan, &oldr);
        }
        return 0;
 }
index feaeda2..4788893 100644 (file)
@@ -126,10 +126,10 @@ static int serialize_showchan(struct ast_channel *c, char *buf, size_t size)
                        c->_state,
                        c->rings,
                        ast_getformatname_multiple(formatbuf, sizeof(formatbuf), c->nativeformats),
-                       ast_getformatname_multiple(formatbuf, sizeof(formatbuf), c->writeformat),
-                       ast_getformatname_multiple(formatbuf, sizeof(formatbuf), c->readformat),
-                       ast_getformatname_multiple(formatbuf, sizeof(formatbuf), c->rawwriteformat),
-                       ast_getformatname_multiple(formatbuf, sizeof(formatbuf), c->rawreadformat),
+                       ast_getformatname(&c->writeformat),
+                       ast_getformatname(&c->readformat),
+                       ast_getformatname(&c->rawwriteformat),
+                       ast_getformatname(&c->rawreadformat),
                        c->fds[0], c->fin & ~DEBUGCHAN_FLAG, (c->fin & DEBUGCHAN_FLAG) ? " (DEBUGGED)" : "",
                        c->fout & ~DEBUGCHAN_FLAG, (c->fout & DEBUGCHAN_FLAG) ? " (DEBUGGED)" : "", (long)c->whentohangup.tv_sec,
                        hour,
index 1c72110..ab99142 100644 (file)
@@ -51,11 +51,11 @@ static const char app[] = "Echo";
 static int echo_exec(struct ast_channel *chan, const char *data)
 {
        int res = -1;
-       format_t format;
+       struct ast_format format;
 
-       format = ast_best_codec(chan->nativeformats);
-       ast_set_write_format(chan, format);
-       ast_set_read_format(chan, format);
+       ast_best_codec(chan->nativeformats, &format);
+       ast_set_write_format(chan, &format);
+       ast_set_read_format(chan, &format);
 
        while (ast_waitfor(chan, -1) > -1) {
                struct ast_frame *f = ast_read(chan);
index 54d22db..ce85419 100644 (file)
@@ -329,9 +329,9 @@ static int fax_generator_generate(struct ast_channel *chan, void *data, int len,
     
        struct ast_frame outf = {
                .frametype = AST_FRAME_VOICE,
-               .subclass.codec = AST_FORMAT_SLINEAR,
                .src = __FUNCTION__,
        };
+       ast_format_set(&outf.subclass.format, AST_FORMAT_SLINEAR, 0);
 
        if (samples > MAX_SAMPLES) {
                ast_log(LOG_WARNING, "Only generating %d samples, where %d requested\n", MAX_SAMPLES, samples);
@@ -362,8 +362,8 @@ static struct ast_generator generator = {
 static int transmit_audio(fax_session *s)
 {
        int res = -1;
-       int original_read_fmt = AST_FORMAT_SLINEAR;
-       int original_write_fmt = AST_FORMAT_SLINEAR;
+       struct ast_format original_read_fmt;
+       struct ast_format original_write_fmt;
        fax_state_t fax;
        t30_state_t *t30state;
        struct ast_frame *inf = NULL;
@@ -383,6 +383,9 @@ static int transmit_audio(fax_session *s)
 */
        };
 
+       ast_format_clear(&original_read_fmt);
+       ast_format_clear(&original_write_fmt);
+
        /* if in called party mode, try to use T.38 */
        if (s->caller_mode == FALSE) {
                /* check if we are already in T.38 mode (unlikely), or if we can request
@@ -455,18 +458,18 @@ static int transmit_audio(fax_session *s)
         t30state = &fax.t30_state;
 #endif
 
-       original_read_fmt = s->chan->readformat;
-       if (original_read_fmt != AST_FORMAT_SLINEAR) {
-               res = ast_set_read_format(s->chan, AST_FORMAT_SLINEAR);
+       ast_format_copy(&original_read_fmt, &s->chan->readformat);
+       if (original_read_fmt.id != AST_FORMAT_SLINEAR) {
+               res = ast_set_read_format_by_id(s->chan, AST_FORMAT_SLINEAR);
                if (res < 0) {
                        ast_log(LOG_WARNING, "Unable to set to linear read mode, giving up\n");
                        goto done;
                }
        }
 
-       original_write_fmt = s->chan->writeformat;
-       if (original_write_fmt != AST_FORMAT_SLINEAR) {
-               res = ast_set_write_format(s->chan, AST_FORMAT_SLINEAR);
+       ast_format_copy(&original_write_fmt, &s->chan->writeformat);
+       if (original_write_fmt.id != AST_FORMAT_SLINEAR) {
+               res = ast_set_write_format_by_id(s->chan, AST_FORMAT_SLINEAR);
                if (res < 0) {
                        ast_log(LOG_WARNING, "Unable to set to linear write mode, giving up\n");
                        goto done;
@@ -523,12 +526,12 @@ static int transmit_audio(fax_session *s)
                        break;
                }
 
-               ast_debug(10, "frame %d/%llu, len=%d\n", inf->frametype, (unsigned long long) inf->subclass.codec, inf->datalen);
+               ast_debug(10, "frame %d/%u, len=%d\n", inf->frametype, (unsigned int) inf->subclass.format.id, inf->datalen);
 
                /* Check the frame type. Format also must be checked because there is a chance
                   that a frame in old format was already queued before we set channel format
                   to slinear so it will still be received by ast_read */
-               if (inf->frametype == AST_FRAME_VOICE && inf->subclass.codec == AST_FORMAT_SLINEAR) {
+               if (inf->frametype == AST_FRAME_VOICE && inf->subclass.format.id == AST_FORMAT_SLINEAR) {
                        if (fax_rx(&fax, inf->data.ptr, inf->samples) < 0) {
                                /* I know fax_rx never returns errors. The check here is for good style only */
                                ast_log(LOG_WARNING, "fax_rx returned error\n");
@@ -582,13 +585,13 @@ static int transmit_audio(fax_session *s)
        fax_release(&fax);
 
 done:
-       if (original_write_fmt != AST_FORMAT_SLINEAR) {
-               if (ast_set_write_format(s->chan, original_write_fmt) < 0)
+       if (original_write_fmt.id != AST_FORMAT_SLINEAR) {
+               if (ast_set_write_format(s->chan, &original_write_fmt) < 0)
                        ast_log(LOG_WARNING, "Unable to restore write format on '%s'\n", s->chan->name);
        }
 
-       if (original_read_fmt != AST_FORMAT_SLINEAR) {
-               if (ast_set_read_format(s->chan, original_read_fmt) < 0)
+       if (original_read_fmt.id != AST_FORMAT_SLINEAR) {
+               if (ast_set_read_format(s->chan, &original_read_fmt) < 0)
                        ast_log(LOG_WARNING, "Unable to restore read format on '%s'\n", s->chan->name);
        }
 
index ef8827a..f6f3734 100644 (file)
@@ -165,7 +165,7 @@ static int send_waveform_to_channel(struct ast_channel *chan, char *waveform, in
        int fds[2];
        int pid = -1;
        int needed = 0;
-       int owriteformat;
+       struct ast_format owriteformat;
        struct ast_frame *f;
        struct myframe {
                struct ast_frame f;
@@ -175,6 +175,7 @@ static int send_waveform_to_channel(struct ast_channel *chan, char *waveform, in
                .f = { 0, },
        };
 
+       ast_format_clear(&owriteformat);
        if (pipe(fds)) {
                ast_log(LOG_WARNING, "Unable to create pipe\n");
                return -1;
@@ -186,8 +187,8 @@ static int send_waveform_to_channel(struct ast_channel *chan, char *waveform, in
        ast_stopstream(chan);
        ast_indicate(chan, -1);
        
-       owriteformat = chan->writeformat;
-       res = ast_set_write_format(chan, AST_FORMAT_SLINEAR);
+       ast_format_copy(&owriteformat, &chan->writeformat);
+       res = ast_set_write_format_by_id(chan, AST_FORMAT_SLINEAR);
        if (res < 0) {
                ast_log(LOG_WARNING, "Unable to set write format to signed linear\n");
                return -1;
@@ -229,7 +230,7 @@ static int send_waveform_to_channel(struct ast_channel *chan, char *waveform, in
                                res = read(fds[0], myf.frdata, needed);
                                if (res > 0) {
                                        myf.f.frametype = AST_FRAME_VOICE;
-                                       myf.f.subclass.codec = AST_FORMAT_SLINEAR;
+                                       ast_format_set(&myf.f.subclass.format, AST_FORMAT_SLINEAR, 0);
                                        myf.f.datalen = res;
                                        myf.f.samples = res / 2;
                                        myf.f.offset = AST_FRIENDLY_OFFSET;
@@ -261,8 +262,8 @@ static int send_waveform_to_channel(struct ast_channel *chan, char *waveform, in
        if (pid > -1)
                kill(pid, SIGKILL);
 #endif
-       if (!res && owriteformat)
-               ast_set_write_format(chan, owriteformat);
+       if (!res && owriteformat.id)
+               ast_set_write_format(chan, &owriteformat);
        return res;
 }
 
index 95b1cea..8b9f106 100644 (file)
@@ -848,7 +848,7 @@ static void findmeexec(struct fm_args *tpargs)
                                return;
                        }
 
-                       outbound = ast_request("Local", ast_best_codec(caller->nativeformats), caller, dialarg, &dg);
+                       outbound = ast_request("Local", caller->nativeformats, caller, dialarg, &dg);
                        if (outbound) {
                                ast_set_callerid(outbound,
                                        S_COR(caller->caller.id.number.valid, caller->caller.id.number.str, NULL),
index f2b9498..b7eea94 100644 (file)
@@ -111,12 +111,13 @@ static int ices_exec(struct ast_channel *chan, const char *data)
        int ms = -1;
        int pid = -1;
        int flags;
-       int oreadformat;
+       struct ast_format oreadformat;
        struct timeval last;
        struct ast_frame *f;
        char filename[256]="";
        char *c;
 
+       ast_format_clear(&oreadformat);
        if (ast_strlen_zero(data)) {
                ast_log(LOG_WARNING, "ICES requires an argument (configfile.xml)\n");
                return -1;
@@ -143,8 +144,8 @@ static int ices_exec(struct ast_channel *chan, const char *data)
                return -1;
        }
 
-       oreadformat = chan->readformat;
-       res = ast_set_read_format(chan, AST_FORMAT_SLINEAR);
+       ast_format_copy(&oreadformat, &chan->readformat);
+       res = ast_set_read_format_by_id(chan, AST_FORMAT_SLINEAR);
        if (res < 0) {
                close(fds[0]);
                close(fds[1]);
@@ -195,8 +196,8 @@ static int ices_exec(struct ast_channel *chan, const char *data)
 
        if (pid > -1)
                kill(pid, SIGKILL);
-       if (!res && oreadformat)
-               ast_set_read_format(chan, oreadformat);
+       if (!res && oreadformat.id)
+               ast_set_read_format(chan, &oreadformat);
 
        return res;
 }
index 2f263b6..d073451 100644 (file)
@@ -604,12 +604,12 @@ static void handle_jack_audio(struct ast_channel *chan, struct jack_data *jack_d
        short buf[160];
        struct ast_frame f = {
                .frametype = AST_FRAME_VOICE,
-               .subclass.codec = AST_FORMAT_SLINEAR,
                .src = "JACK",
                .data.ptr = buf,
                .datalen = sizeof(buf),
                .samples = ARRAY_LEN(buf),
        };
+       ast_format_set(&f.subclass.format, AST_FORMAT_SLINEAR, 0);
 
        for (;;) {
                size_t res, read_len;
@@ -754,12 +754,12 @@ static int jack_exec(struct ast_channel *chan, const char *data)
                return -1;
        }
 
-       if (ast_set_read_format(chan, AST_FORMAT_SLINEAR)) {
+       if (ast_set_read_format_by_id(chan, AST_FORMAT_SLINEAR)) {
                destroy_jack_data(jack_data);
                return -1;
        }
 
-       if (ast_set_write_format(chan, AST_FORMAT_SLINEAR)) {
+       if (ast_set_write_format_by_id(chan, AST_FORMAT_SLINEAR)) {
                destroy_jack_data(jack_data);
                return -1;
        }
@@ -823,9 +823,9 @@ static int jack_hook_callback(struct ast_audiohook *audiohook, struct ast_channe
        if (frame->frametype != AST_FRAME_VOICE)
                return 0;
 
-       if (frame->subclass.codec != AST_FORMAT_SLINEAR) {
+       if (frame->subclass.format.id != AST_FORMAT_SLINEAR) {
                ast_log(LOG_WARNING, "Expected frame in SLINEAR for the audiohook, but got format %s\n",
-                       ast_getformatname(frame->subclass.codec));
+                       ast_getformatname(&frame->subclass.format));
                return 0;
        }
 
index 18b1e11..ae60cfb 100644 (file)
@@ -1189,6 +1189,8 @@ static struct ast_conference *build_conf(const char *confno, const char *pin,
        struct ast_conference *cnf;
        struct dahdi_confinfo dahdic = { 0, };
        int confno_int = 0;
+       struct ast_format_cap *cap_slin = ast_format_cap_alloc_nolock();
+       struct ast_format tmp_fmt;
 
        AST_LIST_LOCK(&confs);
 
@@ -1197,9 +1199,10 @@ static struct ast_conference *build_conf(const char *confno, const char *pin,
                        break;
        }
 
-       if (cnf || (!make && !dynamic))
+       if (cnf || (!make && !dynamic) || !cap_slin)
                goto cnfout;
 
+       ast_format_cap_add(cap_slin, ast_format_set(&tmp_fmt, AST_FORMAT_SLINEAR, 0));
        /* Make a new one */
        if (!(cnf = ast_calloc(1, sizeof(*cnf))) ||
                !(cnf->usercontainer = ao2_container_alloc(1, NULL, user_no_cmp))) {
@@ -1245,10 +1248,10 @@ static struct ast_conference *build_conf(const char *confno, const char *pin,
        cnf->dahdiconf = dahdic.confno;
 
        /* Setup a new channel for playback of audio files */
-       cnf->chan = ast_request("DAHDI", AST_FORMAT_SLINEAR, chan, "pseudo", NULL);
+       cnf->chan = ast_request("DAHDI", cap_slin, chan, "pseudo", NULL);
        if (cnf->chan) {
-               ast_set_read_format(cnf->chan, AST_FORMAT_SLINEAR);
-               ast_set_write_format(cnf->chan, AST_FORMAT_SLINEAR);
+               ast_set_read_format_by_id(cnf->chan, AST_FORMAT_SLINEAR);
+               ast_set_write_format_by_id(cnf->chan, AST_FORMAT_SLINEAR);
                dahdic.chan = 0;
                dahdic.confno = cnf->dahdiconf;
                dahdic.confmode = DAHDI_CONF_CONFANN | DAHDI_CONF_CONFANNMON;
@@ -1284,6 +1287,7 @@ static struct ast_conference *build_conf(const char *confno, const char *pin,
                conf_map[confno_int] = 1;
        
 cnfout:
+       cap_slin = ast_format_cap_destroy(cap_slin);
        if (cnf)
                ast_atomic_fetchadd_int(&cnf->refcount, refcount);
 
@@ -2260,9 +2264,16 @@ static int conf_run(struct ast_channel *chan, struct ast_conference *conf, struc
        int setusercount = 0;
        int confsilence = 0, totalsilence = 0;
        char *mailbox, *context;
+       struct ast_format_cap *cap_slin = ast_format_cap_alloc_nolock();
+       struct ast_format tmpfmt;
+
+       if (!cap_slin) {
+               goto conf_run_cleanup;
+       }
+       ast_format_cap_add(cap_slin, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR, 0));
 
        if (!(user = ao2_alloc(sizeof(*user), NULL))) {
-               return ret;
+               goto conf_run_cleanup;
        }
 
        /* Possible timeout waiting for marked user */
@@ -2372,9 +2383,9 @@ static int conf_run(struct ast_channel *chan, struct ast_conference *conf, struc
 
        ast_mutex_lock(&conf->recordthreadlock);
        if ((conf->recordthread == AST_PTHREADT_NULL) && ast_test_flag64(confflags, CONFFLAG_RECORDCONF) &&
-               ((conf->lchan = ast_request("DAHDI", AST_FORMAT_SLINEAR, chan, "pseudo", NULL)))) {
-               ast_set_read_format(conf->lchan, AST_FORMAT_SLINEAR);
-               ast_set_write_format(conf->lchan, AST_FORMAT_SLINEAR);
+               ((conf->lchan = ast_request("DAHDI", cap_slin, chan, "pseudo", NULL)))) {
+               ast_set_read_format_by_id(conf->lchan, AST_FORMAT_SLINEAR);
+               ast_set_write_format_by_id(conf->lchan, AST_FORMAT_SLINEAR);
                dahdic.chan = 0;
                dahdic.confno = conf->dahdiconf;
                dahdic.confmode = DAHDI_CONF_CONFANN | DAHDI_CONF_CONFANNMON;
@@ -2601,12 +2612,12 @@ static int conf_run(struct ast_channel *chan, struct ast_conference *conf, struc
                ast_indicate(chan, -1);
        }
 
-       if (ast_set_write_format(chan, AST_FORMAT_SLINEAR) < 0) {
+       if (ast_set_write_format_by_id(chan, AST_FORMAT_SLINEAR) < 0) {
                ast_log(LOG_WARNING, "Unable to set '%s' to write linear mode\n", chan->name);
                goto outrun;
        }
 
-       if (ast_set_read_format(chan, AST_FORMAT_SLINEAR) < 0) {
+       if (ast_set_read_format_by_id(chan, AST_FORMAT_SLINEAR) < 0) {
                ast_log(LOG_WARNING, "Unable to set '%s' to read linear mode\n", chan->name);
                goto outrun;
        }
@@ -3167,7 +3178,7 @@ static int conf_run(struct ast_channel *chan, struct ast_conference *conf, struc
                                        dtmfstr[1] = '\0';
                                }
 
-                               if ((f->frametype == AST_FRAME_VOICE) && (f->subclass.codec == AST_FORMAT_SLINEAR)) {
+                               if ((f->frametype == AST_FRAME_VOICE) && (f->subclass.format.id == AST_FORMAT_SLINEAR)) {
                                        if (user->talk.actual) {
                                                ast_frame_adjust_volume(f, user->talk.actual);
                                        }
@@ -3339,9 +3350,9 @@ static int conf_run(struct ast_channel *chan, struct ast_conference *conf, struc
                                                                        }
 
                                                                        ast_mutex_lock(&conf->recordthreadlock);
-                                                                       if ((conf->recordthread == AST_PTHREADT_NULL) && ast_test_flag64(confflags, CONFFLAG_RECORDCONF) && ((conf->lchan = ast_request("DAHDI", AST_FORMAT_SLINEAR, chan, "pseudo", NULL)))) {
-                                                                               ast_set_read_format(conf->lchan, AST_FORMAT_SLINEAR);
-                                                                               ast_set_write_format(conf->lchan, AST_FORMAT_SLINEAR);
+                                                                       if ((conf->recordthread == AST_PTHREADT_NULL) && ast_test_flag64(confflags, CONFFLAG_RECORDCONF) && ((conf->lchan = ast_request("DAHDI", cap_slin, chan, "pseudo", NULL)))) {
+                                                                               ast_set_read_format_by_id(conf->lchan, AST_FORMAT_SLINEAR);
+                                                                               ast_set_write_format_by_id(conf->lchan, AST_FORMAT_SLINEAR);
                                                                                dahdic.chan = 0;
                                                                                dahdic.confno = conf->dahdiconf;
                                                                                dahdic.confmode = DAHDI_CONF_CONFANN | DAHDI_CONF_CONFANNMON;
@@ -3627,7 +3638,7 @@ static int conf_run(struct ast_channel *chan, struct ast_conference *conf, struc
                                if (res > 0) {
                                        memset(&fr, 0, sizeof(fr));
                                        fr.frametype = AST_FRAME_VOICE;
-                                       fr.subclass.codec = AST_FORMAT_SLINEAR;
+                                       ast_format_set(&fr.subclass.format, AST_FORMAT_SLINEAR, 0);
                                        fr.datalen = res;
                                        fr.samples = res / 2;
                                        fr.data.ptr = buf;
@@ -3639,7 +3650,7 @@ static int conf_run(struct ast_channel *chan, struct ast_conference *conf, struc
                                                 )) {
                                                int idx;
                                                for (idx = 0; idx < AST_FRAME_BITS; idx++) {
-                                                       if (chan->rawwriteformat & (1 << idx)) {
+                                                       if (ast_format_to_old_bitfield(&chan->rawwriteformat) & (1 << idx)) {
                                                                break;
                                                        }
                                                }
@@ -3654,7 +3665,11 @@ static int conf_run(struct ast_channel *chan, struct ast_conference *conf, struc
                                                                        mohtempstopped = 1;
                                                                }
                                                                if (!conf->transpath[idx]) {
-                                                                       conf->transpath[idx] = ast_translator_build_path((1 << idx), AST_FORMAT_SLINEAR);
+                                                                       struct ast_format src;
+                                                                       struct ast_format dst;
+                                                                       ast_format_set(&src, AST_FORMAT_SLINEAR, 0);
+                                                                       ast_format_from_old_bitfield(&dst, (1 << idx));
+                                                                       conf->transpath[idx] = ast_translator_build_path(&dst, &src);
                                                                }
                                                                if (conf->transpath[idx]) {
                                                                        conf->transframe[idx] = ast_translate(conf->transpath[idx], conf->origframe, 0);
@@ -3821,6 +3836,10 @@ bailoutandtrynormal:
        ao2_ref(user, -1);
        AST_LIST_UNLOCK(&confs);
 
+
+conf_run_cleanup:
+       cap_slin = ast_format_cap_destroy(cap_slin);
+
        return ret;
 }
 
index 2413760..26cba3c 100644 (file)
@@ -78,10 +78,10 @@ static int milliwatt_generate(struct ast_channel *chan, void *data, int len, int
        int i, *indexp = (int *) data;
        struct ast_frame wf = {
                .frametype = AST_FRAME_VOICE,
-               .subclass.codec = AST_FORMAT_ULAW,
                .offset = AST_FRIENDLY_OFFSET,
                .src = __FUNCTION__,
        };
+       ast_format_set(&wf.subclass.format, AST_FORMAT_ULAW, 0);
        wf.data.ptr = buf + AST_FRIENDLY_OFFSET;
 
        /* Instead of len, use samples, because channel.c generator_force
@@ -120,8 +120,8 @@ static struct ast_generator milliwattgen = {
 
 static int old_milliwatt_exec(struct ast_channel *chan)
 {
-       ast_set_write_format(chan, AST_FORMAT_ULAW);
-       ast_set_read_format(chan, AST_FORMAT_ULAW);
+       ast_set_write_format_by_id(chan, AST_FORMAT_ULAW);
+       ast_set_read_format_by_id(chan, AST_FORMAT_ULAW);
 
        if (chan->_state != AST_STATE_UP) {
                ast_answer(chan);
index ca3a239..8e6adea 100644 (file)
@@ -281,7 +281,9 @@ static void *mixmonitor_thread(void *obj)
        unsigned int oflags;
        char *ext;
        int errflag = 0;
+       struct ast_format format_slin;
 
+       ast_format_set(&format_slin, AST_FORMAT_SLINEAR, 0);
        ast_verb(2, "Begin MixMonitor Recording %s\n", mixmonitor->name);
 
        fs = &mixmonitor->mixmonitor_ds->fs;
@@ -291,7 +293,7 @@ static void *mixmonitor_thread(void *obj)
        while (mixmonitor->audiohook.status == AST_AUDIOHOOK_STATUS_RUNNING && !mixmonitor->mixmonitor_ds->fs_quit) {
                struct ast_frame *fr = NULL;
 
-               if (!(fr = ast_audiohook_read_frame(&mixmonitor->audiohook, SAMPLES_PER_FRAME, AST_AUDIOHOOK_DIRECTION_BOTH, AST_FORMAT_SLINEAR))) {
+               if (!(fr = ast_audiohook_read_frame(&mixmonitor->audiohook, SAMPLES_PER_FRAME, AST_AUDIOHOOK_DIRECTION_BOTH, &format_slin))) {
                        ast_audiohook_trigger_wait(&mixmonitor->audiohook);
 
                        if (mixmonitor->audiohook.status != AST_AUDIOHOOK_STATUS_RUNNING) {
index f8e42a1..f8c5a05 100644 (file)
@@ -137,7 +137,7 @@ static int mp3_exec(struct ast_channel *chan, const char *data)
        int fds[2];
        int ms = -1;
        int pid = -1;
-       int owriteformat;
+       struct ast_format owriteformat;
        int timeout = 2000;
        struct timeval next;
        struct ast_frame *f;
@@ -149,6 +149,7 @@ static int mp3_exec(struct ast_channel *chan, const char *data)
                .f = { 0, },
        };
 
+       ast_format_clear(&owriteformat);
        if (ast_strlen_zero(data)) {
                ast_log(LOG_WARNING, "MP3 Playback requires an argument (filename)\n");
                return -1;
@@ -161,8 +162,8 @@ static int mp3_exec(struct ast_channel *chan, const char *data)
        
        ast_stopstream(chan);
 
-       owriteformat = chan->writeformat;
-       res = ast_set_write_format(chan, AST_FORMAT_SLINEAR);
+       ast_format_copy(&owriteformat, &chan->writeformat);
+       res = ast_set_write_format_by_id(chan, AST_FORMAT_SLINEAR);
        if (res < 0) {
                ast_log(LOG_WARNING, "Unable to set write format to signed linear\n");
                return -1;
@@ -185,7 +186,7 @@ static int mp3_exec(struct ast_channel *chan, const char *data)
                                res = timed_read(fds[0], myf.frdata, sizeof(myf.frdata), timeout);
                                if (res > 0) {
                                        myf.f.frametype = AST_FRAME_VOICE;
-                                       myf.f.subclass.codec = AST_FORMAT_SLINEAR;
+                                       ast_format_set(&myf.f.subclass.format, AST_FORMAT_SLINEAR, 0);
                                        myf.f.datalen = res;
                                        myf.f.samples = res / 2;
                                        myf.f.mallocd = 0;
@@ -234,8 +235,8 @@ static int mp3_exec(struct ast_channel *chan, const char *data)
        
        if (pid > -1)
                kill(pid, SIGKILL);
-       if (!res && owriteformat)
-               ast_set_write_format(chan, owriteformat);
+       if (!res && owriteformat.id)
+               ast_set_write_format(chan, &owriteformat);
        
        return res;
 }
index dd7637a..2bbde63 100644 (file)
@@ -111,7 +111,7 @@ static int NBScat_exec(struct ast_channel *chan, const char *data)
        int fds[2];
        int ms = -1;
        int pid = -1;
-       int owriteformat;
+       struct ast_format owriteformat;
        struct timeval next;
        struct ast_frame *f;
        struct myframe {
@@ -119,7 +119,8 @@ static int NBScat_exec(struct ast_channel *chan, const char *data)
                char offset[AST_FRIENDLY_OFFSET];
                short frdata[160];
        } myf;
-       
+
+       ast_format_clear(&owriteformat);
        if (socketpair(AF_LOCAL, SOCK_STREAM, 0, fds)) {
                ast_log(LOG_WARNING, "Unable to create socketpair\n");
                return -1;
@@ -127,8 +128,8 @@ static int NBScat_exec(struct ast_channel *chan, const char *data)
        
        ast_stopstream(chan);
 
-       owriteformat = chan->writeformat;
-       res = ast_set_write_format(chan, AST_FORMAT_SLINEAR);
+       ast_format_copy(&owriteformat, &chan->writeformat);
+       res = ast_set_write_format_by_id(chan, AST_FORMAT_SLINEAR);
        if (res < 0) {
                ast_log(LOG_WARNING, "Unable to set write format to signed linear\n");
                return -1;
@@ -148,7 +149,7 @@ static int NBScat_exec(struct ast_channel *chan, const char *data)
                                res = timed_read(fds[0], myf.frdata, sizeof(myf.frdata));
                                if (res > 0) {
                                        myf.f.frametype = AST_FRAME_VOICE;
-                                       myf.f.subclass.codec = AST_FORMAT_SLINEAR;
+                                       ast_format_set(&myf.f.subclass.format, AST_FORMAT_SLINEAR, 0);
                                        myf.f.datalen = res;
                                        myf.f.samples = res / 2;
                                        myf.f.mallocd = 0;
@@ -197,8 +198,8 @@ static int NBScat_exec(struct ast_channel *chan, const char *data)
        
        if (pid > -1)
                kill(pid, SIGKILL);
-       if (!res && owriteformat)
-               ast_set_write_format(chan, owriteformat);
+       if (!res && owriteformat.id)
+               ast_set_write_format(chan, &owriteformat);
 
        return res;
 }
index 659ea29..94ac359 100644 (file)
@@ -105,8 +105,14 @@ static int originate_exec(struct ast_channel *chan, const char *data)
        int outgoing_status = 0;
        static const unsigned int timeout = 30;
        static const char default_exten[] = "s";
+       struct ast_format tmpfmt;
+       struct ast_format_cap *cap_slin = ast_format_cap_alloc_nolock();
 
        ast_autoservice_start(chan);
+       if (!cap_slin) {
+               goto return_cleanup;
+       }
+       ast_format_cap_add(cap_slin, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR, 0));
 
        if (ast_strlen_zero(data)) {
                ast_log(LOG_ERROR, "Originate() requires arguments\n");
@@ -148,14 +154,14 @@ static int originate_exec(struct ast_channel *chan, const char *data)
                ast_debug(1, "Originating call to '%s/%s' and connecting them to extension %s,%s,%d\n",
                                chantech, chandata, args.arg1, exten, priority);
 
-               outgoing_res = ast_pbx_outgoing_exten(chantech, AST_FORMAT_SLINEAR, chandata,
+               outgoing_res = ast_pbx_outgoing_exten(chantech, cap_slin, chandata,
                                timeout * 1000, args.arg1, exten, priority, &outgoing_status, 0, NULL,
                                NULL, NULL, NULL, NULL);
        } else if (!strcasecmp(args.type, "app")) {
                ast_debug(1, "Originating call to '%s/%s' and connecting them to %s(%s)\n",
                                chantech, chandata, args.arg1, S_OR(args.arg2, ""));
 
-               outgoing_res = ast_pbx_outgoing_app(chantech, AST_FORMAT_SLINEAR, chandata,
+               outgoing_res = ast_pbx_outgoing_app(chantech, cap_slin, chandata,
                                timeout * 1000, args.arg1, args.arg2, &outgoing_status, 0, NULL,
                                NULL, NULL, NULL, NULL);
        } else {
@@ -194,7 +200,7 @@ return_cleanup:
                        break;
                }
        }
-
+       cap_slin = ast_format_cap_destroy(cap_slin);
        ast_autoservice_stop(chan);
 
        return res;
index 5bb8b65..fb3e713 100644 (file)
@@ -96,6 +96,9 @@ static int parkandannounce_exec(struct ast_channel *chan, const char *data)
        struct ast_channel *dchan;
        struct outgoing_helper oh = { 0, };
        int outstate;
+       struct ast_format tmpfmt;
+       struct ast_format_cap *cap_slin = ast_format_cap_alloc_nolock();
+
        AST_DECLARE_APP_ARGS(args,
                AST_APP_ARG(template);
                AST_APP_ARG(timeout);
@@ -104,9 +107,15 @@ static int parkandannounce_exec(struct ast_channel *chan, const char *data)
        );
        if (ast_strlen_zero(data)) {
                ast_log(LOG_WARNING, "ParkAndAnnounce requires arguments: (announce:template|timeout|dial|[return_context])\n");
-               return -1;
+               res = -1;
+               goto parkcleanup;
+       }
+       if (!cap_slin) {
+               res = -1;
+               goto parkcleanup;
        }
-  
+       ast_format_cap_add(cap_slin, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR, 0));
+
        s = ast_strdupa(data);
        AST_STANDARD_APP_ARGS(args, s);
 
@@ -115,7 +124,8 @@ static int parkandannounce_exec(struct ast_channel *chan, const char *data)
 
        if (ast_strlen_zero(args.dial)) {
                ast_log(LOG_WARNING, "PARK: A dial resource must be specified i.e: Console/dsp or DAHDI/g1/5551212\n");
-               return -1;
+               res = -1;
+               goto parkcleanup;
        }
 
        dialtech = strsep(&args.dial, "/");
@@ -138,8 +148,9 @@ static int parkandannounce_exec(struct ast_channel *chan, const char *data)
        before we are done announcing and the channel is messed with, Kablooeee.  So we use Masq to prevent this.  */
 
        res = ast_masq_park_call(chan, NULL, timeout, &lot);
-       if (res == -1)
-               return res;
+       if (res == -1) {
+               goto parkcleanup;
+       }
 
        ast_verb(3, "Call Parking Called, lot: %d, timeout: %d, context: %s\n", lot, timeout, args.return_context);
 
@@ -148,7 +159,7 @@ static int parkandannounce_exec(struct ast_channel *chan, const char *data)
        snprintf(buf, sizeof(buf), "%d", lot);
        oh.parent_channel = chan;
        oh.vars = ast_variable_new("_PARKEDAT", buf, "");
-       dchan = __ast_request_and_dial(dialtech, AST_FORMAT_SLINEAR, chan, args.dial, 30000,
+       dchan = __ast_request_and_dial(dialtech, cap_slin, chan, args.dial, 30000,
                &outstate,
                S_COR(chan->caller.id.number.valid, chan->caller.id.number.str, NULL),
                S_COR(chan->caller.id.name.valid, chan->caller.id.name.str, NULL),
@@ -160,11 +171,13 @@ static int parkandannounce_exec(struct ast_channel *chan, const char *data)
                        ast_verb(4, "Channel %s was never answered.\n", dchan->name);
                        ast_log(LOG_WARNING, "PARK: Channel %s was never answered for the announce.\n", dchan->name);
                        ast_hangup(dchan);
-                       return -1;
+                       res = -1;
+                       goto parkcleanup;
                }
        } else {
                ast_log(LOG_WARNING, "PARK: Unable to allocate announce channel.\n");
-               return -1; 
+               res = -1;
+               goto parkcleanup;
        }
 
        ast_stopstream(dchan);
@@ -197,7 +210,10 @@ static int parkandannounce_exec(struct ast_channel *chan, const char *data)
 
        ast_stopstream(dchan);  
        ast_hangup(dchan);
-       
+
+parkcleanup:
+       cap_slin = ast_format_cap_destroy(cap_slin);
+
        return res;
 }
 
index 64e6350..a192b1a 100644 (file)
@@ -154,7 +154,7 @@ static int record_exec(struct ast_channel *chan, const char *data)
        int maxduration = 0;            /* max duration of recording in milliseconds */
        int gottimeout = 0;             /* did we timeout for maxduration exceeded? */
        int terminator = '#';
-       int rfmt = 0;
+       struct ast_format rfmt;
        int ioflags;
        int waitres;
        struct ast_silence_generator *silgen = NULL;
@@ -165,7 +165,8 @@ static int record_exec(struct ast_channel *chan, const char *data)
                AST_APP_ARG(maxduration);
                AST_APP_ARG(options);
        );
-       
+
+       ast_format_clear(&rfmt);
        /* The next few lines of code parse out the filename and header from the input string */
        if (ast_strlen_zero(data)) { /* no data implies no filename or anything is present */
                ast_log(LOG_WARNING, "Record requires an argument (filename)\n");
@@ -286,8 +287,8 @@ static int record_exec(struct ast_channel *chan, const char *data)
        /* The end of beep code.  Now the recording starts */
 
        if (silence > 0) {
-               rfmt = chan->readformat;
-               res = ast_set_read_format(chan, AST_FORMAT_SLINEAR);
+               ast_format_copy(&rfmt, &chan->readformat);
+               res = ast_set_read_format_by_id(chan, AST_FORMAT_SLINEAR);
                if (res < 0) {
                        ast_log(LOG_WARNING, "Unable to set to linear mode, giving up\n");
                        pbx_builtin_setvar_helper(chan, "RECORD_STATUS", "ERROR");
@@ -408,8 +409,8 @@ static int record_exec(struct ast_channel *chan, const char *data)
                ast_channel_stop_silence_generator(chan, silgen);
 
 out:
-       if ((silence > 0) && rfmt) {
-               res = ast_set_read_format(chan, rfmt);
+       if ((silence > 0) && rfmt.id) {
+               res = ast_set_read_format(chan, &rfmt);
                if (res)
                        ast_log(LOG_WARNING, "Unable to restore read format on '%s'\n", chan->name);
                if (sildet)
index a4d350d..765f731 100644 (file)
@@ -882,6 +882,7 @@ static int setrem(struct rpt *myrpt);
 static int setrtx_check(struct rpt *myrpt);
 static int channel_revert(struct rpt *myrpt);
 static int channel_steer(struct rpt *myrpt, char *data);
+static struct ast_format_cap *get_slin_cap(struct ast_format_cap *cap);
 
 AST_MUTEX_DEFINE_STATIC(nodeloglock);
 
@@ -951,7 +952,6 @@ int i;
        return(NULL);
 }
 
-
 static void rpt_mutex_spew(void)
 {
        struct by_lightning lock_ring_copy[32];
@@ -1070,6 +1070,18 @@ pthread_t id;
 
 #endif  /* APP_RPT_LOCK_DEBUG */
 
+static struct ast_format_cap *get_slin_cap(struct ast_format_cap *cap)
+{
+       struct ast_format tmp;
+       cap = ast_format_cap_alloc_nolock();
+       if (!cap) {
+               return NULL;
+       }
+       ast_format_cap_add(cap, ast_format_set(&tmp, AST_FORMAT_SLINEAR, 0));
+
+       return cap;
+}
+
 /*
 * Return 1 if rig is multimode capable
 */
@@ -3961,7 +3973,7 @@ char mhz[MAXREMSTR];
 char decimals[MAXREMSTR];
 char   mystr[200];
 struct dahdi_params par;
-
+struct ast_format_cap *cap = NULL;
 
        /* get a pointer to myrpt */
        myrpt = mytele->rpt;
@@ -4004,7 +4016,8 @@ struct dahdi_params par;
 
 
        /* allocate a pseudo-channel thru asterisk */
-       mychannel = ast_request("DAHDI", AST_FORMAT_SLINEAR, NULL, "pseudo", NULL);
+       mychannel = ast_request("DAHDI", get_slin_cap(cap), NULL, "pseudo", NULL);
+       cap = ast_format_cap_destroy(cap);
        if (!mychannel)
        {
                fprintf(stderr,"rpt:Sorry unable to obtain pseudo channel\n");
@@ -5288,10 +5301,12 @@ struct  rpt *myrpt = (struct rpt *)this;
 int    res;
 int stopped,congstarted,dialtimer,lastcidx,aborted;
 struct ast_channel *mychannel,*genchannel;
+struct ast_format_cap *cap = NULL;
 
        myrpt->mydtmf = 0;
        /* allocate a pseudo-channel thru asterisk */
-       mychannel = ast_request("DAHDI", AST_FORMAT_SLINEAR, NULL, "pseudo", NULL);
+       mychannel = ast_request("DAHDI", get_slin_cap(cap), NULL, "pseudo", NULL);
+       cap = ast_format_cap_destroy(cap);
        if (!mychannel)
        {
                fprintf(stderr,"rpt:Sorry unable to obtain pseudo channel\n");
@@ -5317,7 +5332,8 @@ struct ast_channel *mychannel,*genchannel;
                pthread_exit(NULL);
        }
        /* allocate a pseudo-channel thru asterisk */
-       genchannel = ast_request("DAHDI", AST_FORMAT_SLINEAR, NULL, "pseudo", NULL);
+       genchannel = ast_request("DAHDI", get_slin_cap(cap), NULL, "pseudo", NULL);
+       cap = ast_format_cap_destroy(cap);
        if (!genchannel)
        {
                fprintf(stderr,"rpt:Sorry unable to obtain pseudo channel\n");
@@ -5689,6 +5705,7 @@ static int connect_link(struct rpt *myrpt, char* node, int mode, int perma)
        int reconnects = 0;
        int i,n;
        struct dahdi_confinfo ci;  /* conference info */
+       struct ast_format_cap *cap = NULL;
 
        val = node_lookup(myrpt,node);
        if (!val){
@@ -5792,10 +5809,11 @@ static int connect_link(struct rpt *myrpt, char* node, int mode, int perma)
                return -1;
        }
        *tele++ = 0;
-       l->chan = ast_request(deststr, AST_FORMAT_SLINEAR, NULL, tele, NULL);
+       l->chan = ast_request(deststr, get_slin_cap(cap), NULL, tele, NULL);
+       cap = ast_format_cap_destroy(cap);
        if (l->chan){
-               ast_set_read_format(l->chan, AST_FORMAT_SLINEAR);
-               ast_set_write_format(l->chan, AST_FORMAT_SLINEAR);
+               ast_set_read_format_by_id(l->chan, AST_FORMAT_SLINEAR);
+               ast_set_write_format_by_id(l->chan, AST_FORMAT_SLINEAR);
 #ifdef AST_CDR_FLAG_POST_DISABLED
                if (l->chan->cdr)
                        ast_set_flag(l->chan->cdr,AST_CDR_FLAG_POST_DISABLED);
@@ -5827,15 +5845,16 @@ static int connect_link(struct rpt *myrpt, char* node, int mode, int perma)
                return -1;
        }
        /* allocate a pseudo-channel thru asterisk */
-       l->pchan = ast_request("DAHDI", AST_FORMAT_SLINEAR, NULL, "pseudo", NULL);
+       l->pchan = ast_request("DAHDI", get_slin_cap(cap), NULL, "pseudo", NULL);
+       cap = ast_format_cap_destroy(cap);
        if (!l->pchan){
                ast_log(LOG_WARNING,"rpt connect: Sorry unable to obtain pseudo channel\n");
                ast_hangup(l->chan);
                ast_free(l);
                return -1;
        }
-       ast_set_read_format(l->pchan, AST_FORMAT_SLINEAR);
-       ast_set_write_format(l->pchan, AST_FORMAT_SLINEAR);
+       ast_set_read_format_by_id(l->pchan, AST_FORMAT_SLINEAR);
+       ast_set_write_format_by_id(l->pchan, AST_FORMAT_SLINEAR);
 #ifdef AST_CDR_FLAG_POST_DISABLED
        if (l->pchan->cdr)
                ast_set_flag(l->pchan->cdr,AST_CDR_FLAG_POST_DISABLED);
@@ -10341,6 +10360,7 @@ static int attempt_reconnect(struct rpt *myrpt, struct rpt_link *l)
        char *val, *s, *s1, *s2, *tele;
        char tmp[300], deststr[300] = "";
        char sx[320],*sy;
+       struct ast_format_cap *cap = NULL;
 
 
        val = node_lookup(myrpt,l->name);
@@ -10376,10 +10396,11 @@ static int attempt_reconnect(struct rpt *myrpt, struct rpt_link *l)
        l->connecttime = 0;
        l->thisconnected = 0;
        l->newkey = 0;
-       l->chan = ast_request(deststr, AST_FORMAT_SLINEAR, NULL, tele, NULL);
+       l->chan = ast_request(deststr, get_slin_cap(cap), NULL, tele, NULL);
+       cap = ast_format_cap_destroy(cap);
        if (l->chan){
-               ast_set_read_format(l->chan, AST_FORMAT_SLINEAR);
-               ast_set_write_format(l->chan, AST_FORMAT_SLINEAR);
+               ast_set_read_format_by_id(l->chan, AST_FORMAT_SLINEAR);
+               ast_set_write_format_by_id(l->chan, AST_FORMAT_SLINEAR);
 #ifndef        NEW_ASTERISK
                l->chan->whentohangup = 0;
 #endif
@@ -10743,6 +10764,7 @@ time_t  t;
 struct rpt_link *l,*m;
 struct rpt_tele *telem;
 char tmpstr[300],lstr[MAXLINKLIST];
+struct ast_format_cap *cap = NULL;
 
 
        if (myrpt->p.archivedir) mkdir(myrpt->p.archivedir,0600);
@@ -10795,7 +10817,8 @@ char tmpstr[300],lstr[MAXLINKLIST];
                pthread_exit(NULL);
        }
        *tele++ = 0;
-       myrpt->rxchannel = ast_request(tmpstr, AST_FORMAT_SLINEAR, NULL, tele, NULL);
+       myrpt->rxchannel = ast_request(tmpstr, get_slin_cap(cap), NULL, tele, NULL);
+       cap = ast_format_cap_destroy(cap);
        myrpt->dahdirxchannel = NULL;
        if (!strcasecmp(tmpstr,"DAHDI"))
                myrpt->dahdirxchannel = myrpt->rxchannel;
@@ -10809,8 +10832,8 @@ char tmpstr[300],lstr[MAXLINKLIST];
                        myrpt->rpt_thread = AST_PTHREADT_STOP;
                        pthread_exit(NULL);
                }
-               ast_set_read_format(myrpt->rxchannel,AST_FORMAT_SLINEAR);
-               ast_set_write_format(myrpt->rxchannel,AST_FORMAT_SLINEAR);
+               ast_set_read_format_by_id(myrpt->rxchannel,AST_FORMAT_SLINEAR);
+               ast_set_write_format_by_id(myrpt->rxchannel,AST_FORMAT_SLINEAR);
 #ifdef AST_CDR_FLAG_POST_DISABLED
                if (myrpt->rxchannel->cdr)
                        ast_set_flag(myrpt->rxchannel->cdr,AST_CDR_FLAG_POST_DISABLED);
@@ -10853,7 +10876,8 @@ char tmpstr[300],lstr[MAXLINKLIST];
                        pthread_exit(NULL);
                }
                *tele++ = 0;
-               myrpt->txchannel = ast_request(tmpstr, AST_FORMAT_SLINEAR, NULL, tele, NULL);
+               myrpt->txchannel = ast_request(tmpstr, get_slin_cap(cap), NULL, tele, NULL);
+               cap = ast_format_cap_destroy(cap);
                if (!strcasecmp(tmpstr,"DAHDI"))
                        myrpt->dahditxchannel = myrpt->txchannel;
                if (myrpt->txchannel)
@@ -10867,8 +10891,8 @@ char tmpstr[300],lstr[MAXLINKLIST];
                                myrpt->rpt_thread = AST_PTHREADT_STOP;
                                pthread_exit(NULL);
                        }                       
-                       ast_set_read_format(myrpt->txchannel,AST_FORMAT_SLINEAR);
-                       ast_set_write_format(myrpt->txchannel,AST_FORMAT_SLINEAR);
+                       ast_set_read_format_by_id(myrpt->txchannel,AST_FORMAT_SLINEAR);
+                       ast_set_write_format_by_id(myrpt->txchannel,AST_FORMAT_SLINEAR);
 #ifdef AST_CDR_FLAG_POST_DISABLED
                        if (myrpt->txchannel->cdr)
                                ast_set_flag(myrpt->txchannel->cdr,AST_CDR_FLAG_POST_DISABLED);
@@ -10909,7 +10933,8 @@ char tmpstr[300],lstr[MAXLINKLIST];
        ast_indicate(myrpt->txchannel,AST_CONTROL_RADIO_KEY);
        ast_indicate(myrpt->txchannel,AST_CONTROL_RADIO_UNKEY);
        /* allocate a pseudo-channel thru asterisk */
-       myrpt->pchannel = ast_request("DAHDI", AST_FORMAT_SLINEAR, NULL, "pseudo", NULL);
+       myrpt->pchannel = ast_request("DAHDI", get_slin_cap(cap), NULL, "pseudo", NULL);
+       cap = ast_format_cap_destroy(cap);
        if (!myrpt->pchannel)
        {
                fprintf(stderr,"rpt:Sorry unable to obtain pseudo channel\n");
@@ -10928,7 +10953,8 @@ char tmpstr[300],lstr[MAXLINKLIST];
        if (!myrpt->dahditxchannel)
        {
                /* allocate a pseudo-channel thru asterisk */
-               myrpt->dahditxchannel = ast_request("DAHDI", AST_FORMAT_SLINEAR, NULL, "pseudo", NULL);
+               myrpt->dahditxchannel = ast_request("DAHDI", get_slin_cap(cap), NULL, "pseudo", NULL);
+               cap = ast_format_cap_destroy(cap);
                if (!myrpt->dahditxchannel)
                {
                        fprintf(stderr,"rpt:Sorry unable to obtain pseudo channel\n");
@@ -10939,15 +10965,16 @@ char tmpstr[300],lstr[MAXLINKLIST];
                        myrpt->rpt_thread = AST_PTHREADT_STOP;
                        pthread_exit(NULL);
                }
-               ast_set_read_format(myrpt->dahditxchannel,AST_FORMAT_SLINEAR);
-               ast_set_write_format(myrpt->dahditxchannel,AST_FORMAT_SLINEAR);
+               ast_set_read_format_by_id(myrpt->dahditxchannel,AST_FORMAT_SLINEAR);
+               ast_set_write_format_by_id(myrpt->dahditxchannel,AST_FORMAT_SLINEAR);
 #ifdef AST_CDR_FLAG_POST_DISABLED
                if (myrpt->dahditxchannel->cdr)
                        ast_set_flag(myrpt->dahditxchannel->cdr,AST_CDR_FLAG_POST_DISABLED);
 #endif
        }
        /* allocate a pseudo-channel thru asterisk */
-       myrpt->monchannel = ast_request("DAHDI", AST_FORMAT_SLINEAR, NULL, "pseudo", NULL);
+       myrpt->monchannel = ast_request("DAHDI", get_slin_cap(cap), NULL, "pseudo", NULL);
+       cap = ast_format_cap_destroy(cap);
        if (!myrpt->monchannel)
        {
                fprintf(stderr,"rpt:Sorry unable to obtain pseudo channel\n");
@@ -10958,8 +10985,8 @@ char tmpstr[300],lstr[MAXLINKLIST];
                myrpt->rpt_thread = AST_PTHREADT_STOP;
                pthread_exit(NULL);
        }
-       ast_set_read_format(myrpt->monchannel,AST_FORMAT_SLINEAR);
-       ast_set_write_format(myrpt->monchannel,AST_FORMAT_SLINEAR);
+       ast_set_read_format_by_id(myrpt->monchannel,AST_FORMAT_SLINEAR);
+       ast_set_write_format_by_id(myrpt->monchannel,AST_FORMAT_SLINEAR);
 #ifdef AST_CDR_FLAG_POST_DISABLED
        if (myrpt->monchannel->cdr)
                ast_set_flag(myrpt->monchannel->cdr,AST_CDR_FLAG_POST_DISABLED);
@@ -11042,7 +11069,8 @@ char tmpstr[300],lstr[MAXLINKLIST];
                pthread_exit(NULL);
        }
        /* allocate a pseudo-channel thru asterisk */
-       myrpt->parrotchannel = ast_request("DAHDI", AST_FORMAT_SLINEAR, NULL, "pseudo", NULL);
+       myrpt->parrotchannel = ast_request("DAHDI", get_slin_cap(cap), NULL, "pseudo", NULL);
+       cap = ast_format_cap_destroy(cap);
        if (!myrpt->parrotchannel)
        {
                fprintf(stderr,"rpt:Sorry unable to obtain pseudo channel\n");
@@ -11053,14 +11081,15 @@ char tmpstr[300],lstr[MAXLINKLIST];
                myrpt->rpt_thread = AST_PTHREADT_STOP;
                pthread_exit(NULL);
        }
-       ast_set_read_format(myrpt->parrotchannel,AST_FORMAT_SLINEAR);
-       ast_set_write_format(myrpt->parrotchannel,AST_FORMAT_SLINEAR);
+       ast_set_read_format_by_id(myrpt->parrotchannel,AST_FORMAT_SLINEAR);
+       ast_set_write_format_by_id(myrpt->parrotchannel,AST_FORMAT_SLINEAR);
 #ifdef AST_CDR_FLAG_POST_DISABLED
        if (myrpt->parrotchannel->cdr)
                ast_set_flag(myrpt->parrotchannel->cdr,AST_CDR_FLAG_POST_DISABLED);
 #endif
        /* allocate a pseudo-channel thru asterisk */
-       myrpt->voxchannel = ast_request("DAHDI", AST_FORMAT_SLINEAR, NULL, "pseudo", NULL);
+       myrpt->voxchannel = ast_request("DAHDI", get_slin_cap(cap), NULL, "pseudo", NULL);
+       cap = ast_format_cap_destroy(cap);
        if (!myrpt->voxchannel)
        {
                fprintf(stderr,"rpt:Sorry unable to obtain pseudo channel\n");
@@ -11071,14 +11100,15 @@ char tmpstr[300],lstr[MAXLINKLIST];
                myrpt->rpt_thread = AST_PTHREADT_STOP;
                pthread_exit(NULL);
        }
-       ast_set_read_format(myrpt->voxchannel,AST_FORMAT_SLINEAR);
-       ast_set_write_format(myrpt->voxchannel,AST_FORMAT_SLINEAR);
+       ast_set_read_format_by_id(myrpt->voxchannel,AST_FORMAT_SLINEAR);
+       ast_set_write_format_by_id(myrpt->voxchannel,AST_FORMAT_SLINEAR);
 #ifdef AST_CDR_FLAG_POST_DISABLED
        if (myrpt->voxchannel->cdr)
                ast_set_flag(myrpt->voxchannel->cdr,AST_CDR_FLAG_POST_DISABLED);
 #endif
        /* allocate a pseudo-channel thru asterisk */
-       myrpt->txpchannel = ast_request("DAHDI", AST_FORMAT_SLINEAR, NULL, "pseudo", NULL);
+       myrpt->txpchannel = ast_request("DAHDI", get_slin_cap(cap), NULL, "pseudo", NULL);
+       cap = ast_format_cap_destroy(cap);
        if (!myrpt->txpchannel)
        {
                fprintf(stderr,"rpt:Sorry unable to obtain pseudo channel\n");
@@ -13146,6 +13176,7 @@ static int rpt_exec(struct ast_channel *chan, const char *data)
        struct  dahdi_radio_param z;
        struct rpt_tele *telem;
        int     numlinks;
+       struct ast_format_cap *cap = NULL;
 
        nullfd = open("/dev/null",O_RDWR);
        if (ast_strlen_zero(data)) {
@@ -13631,17 +13662,18 @@ static int rpt_exec(struct ast_channel *chan, const char *data)
                l->lastf2 = NULL;
                l->dtmfed = 0;
                voxinit_link(l,1);
-               ast_set_read_format(l->chan,AST_FORMAT_SLINEAR);
-               ast_set_write_format(l->chan,AST_FORMAT_SLINEAR);
+               ast_set_read_format_by_id(l->chan,AST_FORMAT_SLINEAR);
+               ast_set_write_format_by_id(l->chan,AST_FORMAT_SLINEAR);
                /* allocate a pseudo-channel thru asterisk */
-               l->pchan = ast_request("DAHDI", AST_FORMAT_SLINEAR, NULL, "pseudo", NULL);
+               l->pchan = ast_request("DAHDI", get_slin_cap(cap), NULL, "pseudo", NULL);
+               cap = ast_format_cap_destroy(cap);
                if (!l->pchan)
                {
                        fprintf(stderr,"rpt:Sorry unable to obtain pseudo channel\n");
                        pthread_exit(NULL);
                }
-               ast_set_read_format(l->pchan,AST_FORMAT_SLINEAR);
-               ast_set_write_format(l->pchan,AST_FORMAT_SLINEAR);
+               ast_set_read_format_by_id(l->pchan,AST_FORMAT_SLINEAR);
+               ast_set_write_format_by_id(l->pchan,AST_FORMAT_SLINEAR);
 #ifdef AST_CDR_FLAG_POST_DISABLED
                if (l->pchan->cdr)
                        ast_set_flag(l->pchan->cdr,AST_CDR_FLAG_POST_DISABLED);
@@ -13778,14 +13810,15 @@ static int rpt_exec(struct ast_channel *chan, const char *data)
                pthread_exit(NULL);
        }
        *tele++ = 0;
-       myrpt->rxchannel = ast_request(myrpt->rxchanname, AST_FORMAT_SLINEAR, NULL, tele, NULL);
+       myrpt->rxchannel = ast_request(myrpt->rxchanname, get_slin_cap(cap), NULL, tele, NULL);
+       cap = ast_format_cap_destroy(cap);
        myrpt->dahdirxchannel = NULL;
        if (!strcasecmp(myrpt->rxchanname,"DAHDI"))
                myrpt->dahdirxchannel = myrpt->rxchannel;
        if (myrpt->rxchannel)
        {
-               ast_set_read_format(myrpt->rxchannel,AST_FORMAT_SLINEAR);
-               ast_set_write_format(myrpt->rxchannel,AST_FORMAT_SLINEAR);
+               ast_set_read_format_by_id(myrpt->rxchannel,AST_FORMAT_SLINEAR);
+               ast_set_write_format_by_id(myrpt->rxchannel,AST_FORMAT_SLINEAR);
 #ifdef AST_CDR_FLAG_POST_DISABLED
                if (myrpt->rxchannel->cdr)
                        ast_set_flag(myrpt->rxchannel->cdr,AST_CDR_FLAG_POST_DISABLED);
@@ -13821,13 +13854,14 @@ static int rpt_exec(struct ast_channel *chan, const char *data)
                        pthread_exit(NULL);
                }
                *tele++ = 0;
-               myrpt->txchannel = ast_request(myrpt->txchanname, AST_FORMAT_SLINEAR, NULL, tele, NULL);
+               myrpt->txchannel = ast_request(myrpt->txchanname, get_slin_cap(cap), NULL, tele, NULL);
+               cap = ast_format_cap_destroy(cap);
                if (!strncasecmp(myrpt->txchanname,"DAHDI",3))
                        myrpt->dahditxchannel = myrpt->txchannel;
                if (myrpt->txchannel)
                {
-                       ast_set_read_format(myrpt->txchannel,AST_FORMAT_SLINEAR);
-                       ast_set_write_format(myrpt->txchannel,AST_FORMAT_SLINEAR);
+                       ast_set_read_format_by_id(myrpt->txchannel,AST_FORMAT_SLINEAR);
+                       ast_set_write_format_by_id(myrpt->txchannel,AST_FORMAT_SLINEAR);
 #ifdef AST_CDR_FLAG_POST_DISABLED
                        if (myrpt->txchannel->cdr)
                                ast_set_flag(myrpt->txchannel->cdr,AST_CDR_FLAG_POST_DISABLED);
@@ -13860,7 +13894,8 @@ static int rpt_exec(struct ast_channel *chan, const char *data)
                        myrpt->dahditxchannel = myrpt->rxchannel;
        }
        /* allocate a pseudo-channel thru asterisk */
-       myrpt->pchannel = ast_request("DAHDI", AST_FORMAT_SLINEAR, NULL, "pseudo", NULL);
+       myrpt->pchannel = ast_request("DAHDI", get_slin_cap(cap), NULL, "pseudo", NULL);
+       cap = ast_format_cap_destroy(cap);
        if (!myrpt->pchannel)
        {
                fprintf(stderr,"rpt:Sorry unable to obtain pseudo channel\n");
@@ -13870,8 +13905,8 @@ static int rpt_exec(struct ast_channel *chan, const char *data)
                ast_hangup(myrpt->rxchannel);
                pthread_exit(NULL);
        }
-       ast_set_read_format(myrpt->pchannel,AST_FORMAT_SLINEAR);
-       ast_set_write_format(myrpt->pchannel,AST_FORMAT_SLINEAR);
+       ast_set_read_format_by_id(myrpt->pchannel,AST_FORMAT_SLINEAR);
+       ast_set_write_format_by_id(myrpt->pchannel,AST_FORMAT_SLINEAR);
 #ifdef AST_CDR_FLAG_POST_DISABLED
        if (myrpt->pchannel->cdr)
                ast_set_flag(myrpt->pchannel->cdr,AST_CDR_FLAG_POST_DISABLED);
@@ -13987,8 +14022,8 @@ static int rpt_exec(struct ast_channel *chan, const char *data)
        myrpt->tele.prev = &myrpt->tele;
        myrpt->newkey = 0;
        rpt_mutex_unlock(&myrpt->lock);
-       ast_set_write_format(chan, AST_FORMAT_SLINEAR);
-       ast_set_read_format(chan, AST_FORMAT_SLINEAR);
+       ast_set_write_format_by_id(chan, AST_FORMAT_SLINEAR);
+       ast_set_read_format_by_id(chan, AST_FORMAT_SLINEAR);
        rem_rx = 0;
        remkeyed = 0;
        /* if we are on 2w loop and are a remote, turn EC on */
index b5c471b..07af71d 100644 (file)
@@ -1603,7 +1603,7 @@ static int sms_generate(struct ast_channel *chan, void *data, int len, int sampl
        buf = alloca(len);
 
        f.frametype = AST_FRAME_VOICE;
-       f.subclass.codec = __OUT_FMT;
+       ast_format_set(&f.subclass.format, __OUT_FMT, 0);
        f.datalen = samples * sizeof(*buf);
        f.offset = AST_FRIENDLY_OFFSET;
        f.mallocd = 0;
@@ -2001,9 +2001,9 @@ static int sms_exec(struct ast_channel *chan, const char *data)
                sms_messagetx(&h);
        }
 
-       res = ast_set_write_format(chan, __OUT_FMT);
+       res = ast_set_write_format_by_id(chan, __OUT_FMT);
        if (res >= 0) {
-               res = ast_set_read_format(chan, AST_FORMAT_SLINEAR);
+               res = ast_set_read_format_by_id(chan, AST_FORMAT_SLINEAR);
        }
        if (res < 0) {
                ast_log(LOG_ERROR, "Unable to set to linear mode, giving up\n");
index 0323f7c..fe99157 100644 (file)
@@ -642,7 +642,7 @@ static int speech_background(struct ast_channel *chan, const char *data)
        int res = 0, done = 0, started = 0, quieted = 0, max_dtmf_len = 0;
        struct ast_speech *speech = find_speech(chan);
        struct ast_frame *f = NULL;
-       int oldreadformat = AST_FORMAT_SLINEAR;
+       struct ast_format oldreadformat;
        char dtmf[AST_MAX_EXTENSION] = "";
        struct timeval start = { 0, 0 }, current;
        struct ast_datastore *datastore = NULL;
@@ -658,6 +658,7 @@ static int speech_background(struct ast_channel *chan, const char *data)
        parse = ast_strdupa(data);
        AST_STANDARD_APP_ARGS(args, parse);
 
+       ast_format_clear(&oldreadformat);
        if (speech == NULL)
                return -1;
 
@@ -673,10 +674,10 @@ static int speech_background(struct ast_channel *chan, const char *data)
        }
 
        /* Record old read format */
-       oldreadformat = chan->readformat;
+       ast_format_copy(&oldreadformat, &chan->readformat);
 
        /* Change read format to be signed linear */
-       if (ast_set_read_format(chan, speech->format))
+       if (ast_set_read_format(chan, &speech->format))
                return -1;
 
        if (!ast_strlen_zero(args.soundfile)) {
@@ -881,7 +882,7 @@ static int speech_background(struct ast_channel *chan, const char *data)
                        ast_channel_datastore_remove(chan, datastore);
        } else {
                /* Channel is okay so restore read format */
-               ast_set_read_format(chan, oldreadformat);
+               ast_set_read_format(chan, &oldreadformat);
        }
 
        return 0;
index 615929e..545261c 100644 (file)
@@ -87,7 +87,7 @@ static int background_detect_exec(struct ast_channel *chan, const char *data)
        int analysistime = -1;
        int continue_analysis = 1;
        int x;
-       int origrformat = 0;
+       struct ast_format origrformat;
        struct ast_dsp *dsp = NULL;
        AST_DECLARE_APP_ARGS(args,
                AST_APP_ARG(filename);
@@ -96,7 +96,8 @@ static int background_detect_exec(struct ast_channel *chan, const char *data)
                AST_APP_ARG(max);
                AST_APP_ARG(analysistime);
        );
-       
+
+       ast_format_clear(&origrformat);
        if (ast_strlen_zero(data)) {
                ast_log(LOG_WARNING, "BackgroundDetect requires an argument (filename)\n");
                return -1;
@@ -126,8 +127,8 @@ static int background_detect_exec(struct ast_channel *chan, const char *data)
                        }
                }
 
-               origrformat = chan->readformat;
-               if ((ast_set_read_format(chan, AST_FORMAT_SLINEAR))) {
+               ast_format_copy(&origrformat, &chan->readformat);
+               if ((ast_set_read_format_by_id(chan, AST_FORMAT_SLINEAR))) {
                        ast_log(LOG_WARNING, "Unable to set read format to linear!\n");
                        res = -1;
                        break;
@@ -182,7 +183,7 @@ static int background_detect_exec(struct ast_channel *chan, const char *data)
                                                ast_frfree(fr);
                                                break;
                                        }
-                               } else if ((fr->frametype == AST_FRAME_VOICE) && (fr->subclass.codec == AST_FORMAT_SLINEAR) && continue_analysis) {
+                               } else if ((fr->frametype == AST_FRAME_VOICE) && (fr->subclass.format.id == AST_FORMAT_SLINEAR) && continue_analysis) {
                                        int totalsilence;
                                        int ms;
                                        res = ast_dsp_silence(dsp, fr, &totalsilence);
@@ -228,9 +229,9 @@ static int background_detect_exec(struct ast_channel *chan, const char *data)
        } while (0);
 
        if (res > -1) {
-               if (origrformat && ast_set_read_format(chan, origrformat)) {
+               if (origrformat.id && ast_set_read_format(chan, &origrformat)) {
                        ast_log(LOG_WARNING, "Failed to restore read format for %s to %s\n", 
-                               chan->name, ast_getformatname(origrformat));
+                               chan->name, ast_getformatname(&origrformat));
                }
        }
        if (dsp) {
index a7aa7b6..7d0214a 100644 (file)
@@ -87,9 +87,10 @@ static int measurenoise(struct ast_channel *chan, int ms, char *who)
        short *foo;
        struct timeval start;
        struct ast_frame *f;
-       int rformat;
-       rformat = chan->readformat;
-       if (ast_set_read_format(chan, AST_FORMAT_SLINEAR)) {
+       struct ast_format rformat;
+
+       ast_format_copy(&rformat, &chan->readformat);
+       if (ast_set_read_format_by_id(chan, AST_FORMAT_SLINEAR)) {
                ast_log(LOG_NOTICE, "Unable to set to linear mode!\n");
                return -1;
        }
@@ -106,7 +107,7 @@ static int measurenoise(struct ast_channel *chan, int ms, char *who)
                        res = -1;
                        break;
                }
-               if ((f->frametype == AST_FRAME_VOICE) && (f->subclass.codec == AST_FORMAT_SLINEAR)) {
+               if ((f->frametype == AST_FRAME_VOICE) && (f->subclass.format.id == AST_FORMAT_SLINEAR)) {
                        foo = (short *)f->data.ptr;
                        for (x=0;x<f->samples;x++) {
                                noise += abs(foo[x]);
@@ -116,8 +117,8 @@ static int measurenoise(struct ast_channel *chan, int ms, char *who)
                ast_frfree(f);
        }
 
-       if (rformat) {
-               if (ast_set_read_format(chan, rformat)) {
+       if (rformat.id) {
+               if (ast_set_read_format(chan, &rformat)) {
                        ast_log(LOG_NOTICE, "Unable to restore original format!\n");
                        return -1;
                }
index 166df4c..f7882c2 100644 (file)
@@ -12347,11 +12347,11 @@ AST_TEST_DEFINE(test_voicemail_vmsayname)
        }
 
        /* normally this is done in the channel driver */
-       test_channel1->nativeformats = AST_FORMAT_GSM;
-       test_channel1->writeformat = AST_FORMAT_GSM;
-       test_channel1->rawwriteformat = AST_FORMAT_GSM;
-       test_channel1->readformat = AST_FORMAT_GSM;
-       test_channel1->rawreadformat = AST_FORMAT_GSM;
+       ast_format_set(&test_channel1->writeformat, AST_FORMAT_GSM, 0);
+       ast_format_cap_add(test_channel1->nativeformats, &test_channel1->writeformat);
+       ast_format_set(&test_channel1->rawwriteformat, AST_FORMAT_GSM, 0);
+       ast_format_set(&test_channel1->readformat, AST_FORMAT_GSM, 0);
+       ast_format_set(&test_channel1->rawreadformat, AST_FORMAT_GSM, 0);
        test_channel1->tech = &fake_tech;
 
        ast_test_status_update(test, "Test playing of extension when greeting is not available...\n");
index fb76f91..fe4b1e1 100644 (file)
@@ -125,7 +125,7 @@ static char *app_noise = "WaitForNoise";
 static int do_waiting(struct ast_channel *chan, int timereqd, time_t waitstart, int timeout, int wait_for_silence) {
        struct ast_frame *f = NULL;
        int dsptime = 0;
-       int rfmt = 0;
+       struct ast_format rfmt;
        int res = 0;
        struct ast_dsp *sildet;  /* silence detector dsp */
        time_t now;
@@ -134,8 +134,8 @@ static int do_waiting(struct ast_channel *chan, int timereqd, time_t waitstart,
        int (*ast_dsp_func)(struct ast_dsp*, struct ast_frame*, int*) =
                                wait_for_silence ? ast_dsp_silence : ast_dsp_noise;
 
-       rfmt = chan->readformat; /* Set to linear mode */
-       if ((res = ast_set_read_format(chan, AST_FORMAT_SLINEAR)) < 0) {
+       ast_format_copy(&rfmt, &chan->readformat); /* Set to linear mode */
+       if ((res = ast_set_read_format_by_id(chan, AST_FORMAT_SLINEAR)) < 0) {
                ast_log(LOG_WARNING, "Unable to set channel to linear mode, giving up\n");
                return -1;
        }
@@ -195,8 +195,8 @@ static int do_waiting(struct ast_channel *chan, int timereqd, time_t waitstart,
        }
 
 
-       if (rfmt && ast_set_read_format(chan, rfmt)) {
-               ast_log(LOG_WARNING, "Unable to restore format %s to channel '%s'\n", ast_getformatname(rfmt), chan->name);
+       if (rfmt.id && ast_set_read_format(chan, &rfmt)) {
+               ast_log(LOG_WARNING, "Unable to restore format %s to channel '%s'\n", ast_getformatname(&rfmt), chan->name);
        }
        ast_dsp_free(sildet);
        return res;
index 5206731..0d2b3e2 100644 (file)
@@ -306,7 +306,9 @@ static int multiplexed_bridge_join(struct ast_bridge *bridge, struct ast_bridge_
                return 0;
        }
 
-       if (((c0->writeformat == c1->readformat) && (c0->readformat == c1->writeformat) && (c0->nativeformats == c1->nativeformats))) {
+       if ((ast_format_cmp(&c0->writeformat, &c1->readformat) == AST_FORMAT_CMP_EQUAL) &&
+               (ast_format_cmp(&c0->readformat, &c1->writeformat) == AST_FORMAT_CMP_EQUAL) &&
+               (ast_format_cap_identical(c0->nativeformats, c1->nativeformats))) {
                return 0;
        }
 
@@ -373,7 +375,6 @@ static struct ast_bridge_technology multiplexed_bridge = {
        .name = "multiplexed_bridge",
        .capabilities = AST_BRIDGE_CAPABILITY_1TO1MIX,
        .preference = AST_BRIDGE_PREFERENCE_HIGH,
-       .formats = AST_FORMAT_AUDIO_MASK | AST_FORMAT_VIDEO_MASK | AST_FORMAT_TEXT_MASK,
        .create = multiplexed_bridge_create,
        .destroy = multiplexed_bridge_destroy,
        .join = multiplexed_bridge_join,
@@ -388,6 +389,7 @@ static int unload_module(void)
        int res = ast_bridge_technology_unregister(&multiplexed_bridge);
 
        ao2_ref(multiplexed_threads, -1);
+       multiplexed_bridge.format_capabilities = ast_format_cap_destroy(multiplexed_bridge.format_capabilities);
 
        return res;
 }
@@ -397,7 +399,12 @@ static int load_module(void)
        if (!(multiplexed_threads = ao2_container_alloc(MULTIPLEXED_BUCKETS, NULL, NULL))) {
                return AST_MODULE_LOAD_DECLINE;
        }
-
+       if (!(multiplexed_bridge.format_capabilities = ast_format_cap_alloc())) {
+               return AST_MODULE_LOAD_DECLINE;
+       }
+       ast_format_cap_add_all_by_type(multiplexed_bridge.format_capabilities, AST_FORMAT_TYPE_AUDIO);
+       ast_format_cap_add_all_by_type(multiplexed_bridge.format_capabilities, AST_FORMAT_TYPE_VIDEO);
+       ast_format_cap_add_all_by_type(multiplexed_bridge.format_capabilities, AST_FORMAT_TYPE_TEXT);
        return ast_bridge_technology_register(&multiplexed_bridge);
 }
 
index 0dbcd25..72b9108 100644 (file)
@@ -51,7 +51,9 @@ static int simple_bridge_join(struct ast_bridge *bridge, struct ast_bridge_chann
        }
 
        /* See if we need to make these compatible */
-       if (((c0->writeformat == c1->readformat) && (c0->readformat == c1->writeformat) && (c0->nativeformats == c1->nativeformats))) {
+       if ((ast_format_cmp(&c0->writeformat, &c1->readformat) == AST_FORMAT_CMP_EQUAL) &&
+               (ast_format_cmp(&c0->readformat, &c1->writeformat) == AST_FORMAT_CMP_EQUAL) &&
+               (ast_format_cap_identical(c0->nativeformats, c1->nativeformats))) {
                return 0;
        }
 
@@ -85,18 +87,25 @@ static struct ast_bridge_technology simple_bridge = {
        .name = "simple_bridge",
        .capabilities = AST_BRIDGE_CAPABILITY_1TO1MIX | AST_BRIDGE_CAPABILITY_THREAD,
        .preference = AST_BRIDGE_PREFERENCE_MEDIUM,
-       .formats = AST_FORMAT_AUDIO_MASK | AST_FORMAT_VIDEO_MASK | AST_FORMAT_TEXT_MASK,
        .join = simple_bridge_join,
        .write = simple_bridge_write,
 };
 
 static int unload_module(void)
 {
+       ast_format_cap_destroy(simple_bridge.format_capabilities);
        return ast_bridge_technology_unregister(&simple_bridge);
 }
 
 static int load_module(void)
 {
+       if (!(simple_bridge.format_capabilities = ast_format_cap_alloc())) {
+               return AST_MODULE_LOAD_DECLINE;
+       }
+       ast_format_cap_add_all_by_type(simple_bridge.format_capabilities, AST_FORMAT_TYPE_AUDIO);
+       ast_format_cap_add_all_by_type(simple_bridge.format_capabilities, AST_FORMAT_TYPE_VIDEO);
+       ast_format_cap_add_all_by_type(simple_bridge.format_capabilities, AST_FORMAT_TYPE_TEXT);
+
        return ast_bridge_technology_register(&simple_bridge);
 }
 
index 69d13a2..b25ab99 100644 (file)
@@ -126,9 +126,9 @@ static int softmix_bridge_join(struct ast_bridge *bridge, struct ast_bridge_chan
        /* Setup frame parameters */
        sc->frame.frametype = AST_FRAME_VOICE;
 #ifdef SOFTMIX_16_SUPPORT
-       sc->frame.subclass.codec = AST_FORMAT_SLINEAR16;
+       ast_format_set(&sc->frame.subclass.format, AST_FORMAT_SLINEAR16, 0);
 #else
-       sc->frame.subclass.codec = AST_FORMAT_SLINEAR;
+       ast_format_set(&sc->frame.subclass.format, AST_FORMAT_SLINEAR, 0);
 #endif
        sc->frame.data.ptr = sc->final_buf;
        sc->frame.datalen = SOFTMIX_DATALEN;
@@ -171,9 +171,9 @@ static enum ast_bridge_write_result softmix_bridge_write(struct ast_bridge *brid
 
        /* If a frame was provided add it to the smoother */
 #ifdef SOFTMIX_16_SUPPORT
-       if (frame->frametype == AST_FRAME_VOICE && frame->subclass.codec == AST_FORMAT_SLINEAR16) {
+       if (frame->frametype == AST_FRAME_VOICE && frame->subclass.format.id == AST_FORMAT_SLINEAR16) {
 #else
-       if (frame->frametype == AST_FRAME_VOICE && frame->subclass.codec == AST_FORMAT_SLINEAR) {
+       if (frame->frametype == AST_FRAME_VOICE && frame->subclass.format.id == AST_FORMAT_SLINEAR) {
 #endif
                ast_slinfactory_feed(&sc->factory, frame);
        }
@@ -282,11 +282,6 @@ static struct ast_bridge_technology softmix_bridge = {
        .name = "softmix",
        .capabilities = AST_BRIDGE_CAPABILITY_MULTIMIX | AST_BRIDGE_CAPABILITY_THREAD | AST_BRIDGE_CAPABILITY_MULTITHREADED,
        .preference = AST_BRIDGE_PREFERENCE_LOW,
-#ifdef SOFTMIX_16_SUPPORT
-       .formats = AST_FORMAT_SLINEAR16,
-#else
-       .formats = AST_FORMAT_SLINEAR,
-#endif
        .create = softmix_bridge_create,
        .destroy = softmix_bridge_destroy,
        .join = softmix_bridge_join,
@@ -298,11 +293,21 @@ static struct ast_bridge_technology softmix_bridge = {
 
 static int unload_module(void)
 {
+       ast_format_cap_destroy(softmix_bridge.format_capabilities);
        return ast_bridge_technology_unregister(&softmix_bridge);
 }
 
 static int load_module(void)
 {
+       struct ast_format tmp;
+       if (!(softmix_bridge.format_capabilities = ast_format_cap_alloc())) {
+               return AST_MODULE_LOAD_DECLINE;
+       }
+#ifdef SOFTMIX_16_SUPPORT
+       ast_format_cap_add(softmix_bridge.format_capabilities, ast_format_set(&tmp, AST_FORMAT_SLINEAR16, 0));
+#else
+       ast_format_cap_add(softmix_bridge.format_capabilities, ast_format_set(&tmp, AST_FORMAT_SLINEAR, 0));
+#endif
        return ast_bridge_technology_register(&softmix_bridge);
 }
 
index 7cf5e69..9e1dfed 100644 (file)
@@ -297,19 +297,19 @@ static AST_LIST_HEAD_STATIC(agents, agent_pvt);   /*!< Holds the list of agents (l
 
 #define CHECK_FORMATS(ast, p) do { \
        if (p->chan) {\
-               if (ast->nativeformats != p->chan->nativeformats) { \
+               if (!(ast_format_cap_identical(ast->nativeformats, p->chan->nativeformats))) { \
                        char tmp1[256], tmp2[256]; \
                        ast_debug(1, "Native formats changing from '%s' to '%s'\n", ast_getformatname_multiple(tmp1, sizeof(tmp1), ast->nativeformats), ast_getformatname_multiple(tmp2, sizeof(tmp2), p->chan->nativeformats)); \
                        /* Native formats changed, reset things */ \
-                       ast->nativeformats = p->chan->nativeformats; \
-                       ast_debug(1, "Resetting read to '%s' and write to '%s'\n", ast_getformatname_multiple(tmp1, sizeof(tmp1), ast->readformat), ast_getformatname_multiple(tmp2, sizeof(tmp2), ast->writeformat));\
-                       ast_set_read_format(ast, ast->readformat); \
-                       ast_set_write_format(ast, ast->writeformat); \
+                       ast_format_cap_copy(ast->nativeformats, p->chan->nativeformats); \
+                       ast_debug(1, "Resetting read to '%s' and write to '%s'\n", ast_getformatname(&ast->readformat), ast_getformatname(&ast->writeformat));\
+                       ast_set_read_format(ast, &ast->readformat); \
+                       ast_set_write_format(ast, &ast->writeformat); \
                } \
-               if (p->chan->readformat != ast->rawreadformat && !p->chan->generator)  \
-                       ast_set_read_format(p->chan, ast->rawreadformat); \
-               if (p->chan->writeformat != ast->rawwriteformat && !p->chan->generator) \
-                       ast_set_write_format(p->chan, ast->rawwriteformat); \
+               if ((ast_format_cmp(&p->chan->readformat, &ast->rawreadformat) != AST_FORMAT_CMP_EQUAL) && !p->chan->generator)  \
+                       ast_set_read_format(p->chan, &ast->rawreadformat); \
+               if ((ast_format_cmp(&p->chan->writeformat, &ast->rawwriteformat) != AST_FORMAT_CMP_EQUAL) && !p->chan->generator) \
+                       ast_set_write_format(p->chan, &ast->rawwriteformat); \
        } \
 } while(0)
 
@@ -329,7 +329,7 @@ static AST_LIST_HEAD_STATIC(agents, agent_pvt);     /*!< Holds the list of agents (l
 } while(0)
 
 /*--- Forward declarations */
-static struct ast_channel *agent_request(const char *type, format_t format, const struct ast_channel *requestor, void *data, int *cause);
+static struct ast_channel *agent_request(const char *type, struct ast_format_cap *cap, const struct ast_channel *requestor, void *data, int *cause);
 static int agent_devicestate(void *data);
 static int agent_digit_begin(struct ast_channel *ast, char digit);
 static int agent_digit_end(struct ast_channel *ast, char digit, unsigned int duration);
@@ -349,10 +349,9 @@ static int agent_set_base_channel(struct ast_channel *chan, struct ast_channel *
 static int agent_logoff(const char *agent, int soft);
 
 /*! \brief Channel interface description for PBX integration */
-static const struct ast_channel_tech agent_tech = {
+static struct ast_channel_tech agent_tech = {
        .type = "Agent",
        .description = tdesc,
-       .capabilities = -1,
        .requester = agent_request,
        .devicestate = agent_devicestate,
        .send_digit_begin = agent_digit_begin,
@@ -695,7 +694,7 @@ static int agent_write(struct ast_channel *ast, struct ast_frame *f)
        else {
                if ((f->frametype != AST_FRAME_VOICE) ||
                    (f->frametype != AST_FRAME_VIDEO) ||
-                   (f->subclass.codec == p->chan->writeformat)) {
+                   (ast_format_cmp(&f->subclass.format, &p->chan->writeformat) != AST_FORMAT_CMP_NOT_EQUAL)) {
                        res = ast_write(p->chan, f);
                } else {
                        ast_debug(1, "Dropping one incompatible %s frame on '%s' to '%s'\n", 
@@ -799,10 +798,11 @@ static int agent_call(struct ast_channel *ast, char *dest, int timeout)
                ast_debug(3, "Waited for stream, result '%d'\n", res);
        }
        if (!res) {
-               res = ast_set_read_format(p->chan, ast_best_codec(p->chan->nativeformats));
+               struct ast_format tmpfmt;
+               res = ast_set_read_format_from_cap(p->chan, p->chan->nativeformats);
                ast_debug(3, "Set read format, result '%d'\n", res);
                if (res)
-                       ast_log(LOG_WARNING, "Unable to set read format to %s\n", ast_getformatname(ast_best_codec(p->chan->nativeformats)));
+                       ast_log(LOG_WARNING, "Unable to set read format to %s\n", ast_getformatname(&tmpfmt));
        } else {
                /* Agent hung-up */
                p->chan = NULL;
@@ -810,10 +810,11 @@ static int agent_call(struct ast_channel *ast, char *dest, int timeout)
        }
 
        if (!res) {
-               res = ast_set_write_format(p->chan, ast_best_codec(p->chan->nativeformats));
+               struct ast_format tmpfmt;
+               res = ast_set_write_format_from_cap(p->chan, p->chan->nativeformats);
                ast_debug(3, "Set write format, result '%d'\n", res);
                if (res)
-                       ast_log(LOG_WARNING, "Unable to set write format to %s\n", ast_getformatname(ast_best_codec(p->chan->nativeformats)));
+                       ast_log(LOG_WARNING, "Unable to set write format to %s\n", ast_getformatname(&tmpfmt));
        }
        if(!res) {
                /* Call is immediately up, or might need ack */
@@ -1047,21 +1048,21 @@ static struct ast_channel *agent_new(struct agent_pvt *p, int state, const char
 
        tmp->tech = &agent_tech;
        if (p->chan) {
-               tmp->nativeformats = p->chan->nativeformats;
-               tmp->writeformat = p->chan->writeformat;
-               tmp->rawwriteformat = p->chan->writeformat;
-               tmp->readformat = p->chan->readformat;
-               tmp->rawreadformat = p->chan->readformat;
+               ast_format_cap_copy(tmp->nativeformats, p->chan->nativeformats);
+               ast_format_copy(&tmp->writeformat, &p->chan->writeformat);
+               ast_format_copy(&tmp->rawwriteformat, &p->chan->writeformat);
+               ast_format_copy(&tmp->readformat, &p->chan->readformat);
+               ast_format_copy(&tmp->rawreadformat, &p->chan->readformat);
                ast_string_field_set(tmp, language, p->chan->language);
                ast_copy_string(tmp->context, p->chan->context, sizeof(tmp->context));
                ast_copy_string(tmp->exten, p->chan->exten, sizeof(tmp->exten));
                /* XXX Is this really all we copy form the originating channel?? */
        } else {
-               tmp->nativeformats = AST_FORMAT_SLINEAR;
-               tmp->writeformat = AST_FORMAT_SLINEAR;
-               tmp->rawwriteformat = AST_FORMAT_SLINEAR;
-               tmp->readformat = AST_FORMAT_SLINEAR;
-               tmp->rawreadformat = AST_FORMAT_SLINEAR;
+               ast_format_set(&tmp->writeformat, AST_FORMAT_SLINEAR, 0);
+               ast_format_set(&tmp->rawwriteformat, AST_FORMAT_SLINEAR, 0);
+               ast_format_set(&tmp->readformat, AST_FORMAT_SLINEAR, 0);
+               ast_format_set(&tmp->rawreadformat, AST_FORMAT_SLINEAR, 0);
+               ast_format_cap_add(tmp->nativeformats, &tmp->writeformat);
        }
        /* Safe, agentlock already held */
        tmp->tech_pvt = p;
@@ -1374,7 +1375,7 @@ static int check_beep(struct agent_pvt *newlyavailable, int needlock)
 }
 
 /*! \brief Part of the Asterisk PBX interface */
-static struct ast_channel *agent_request(const char *type, format_t format, const struct ast_channel* requestor, void *data, int *cause)
+static struct ast_channel *agent_request(const char *type, struct ast_format_cap *cap, const struct ast_channel* requestor, void *data, int *cause)
 {
        struct agent_pvt *p;
        struct ast_channel *chan = NULL;
@@ -1997,14 +1998,18 @@ static int login_exec(struct ast_channel *chan, const char *data)
                                        AST_LIST_LOCK(&agents);
                                        ast_mutex_lock(&p->lock);
                                        if (!res) {
-                                               res = ast_set_read_format(chan, ast_best_codec(chan->nativeformats));
-                                               if (res)
-                                                       ast_log(LOG_WARNING, "Unable to set read format to %s\n", ast_getformatname(ast_best_codec(chan->nativeformats)));
+                                               struct ast_format tmpfmt;
+                                               res = ast_set_read_format_from_cap(chan, chan->nativeformats);
+                                               if (res) {
+                                                       ast_log(LOG_WARNING, "Unable to set read format to %s\n", ast_getformatname(&tmpfmt));
+                                               }
                                        }
                                        if (!res) {
-                                               res = ast_set_write_format(chan, ast_best_codec(chan->nativeformats));
-                                               if (res)
-                                                       ast_log(LOG_WARNING, "Unable to set write format to %s\n", ast_getformatname(ast_best_codec(chan->nativeformats)));
+                                               struct ast_format tmpfmt;
+                                               res = ast_set_write_format_from_cap(chan, chan->nativeformats);
+                                               if (res) {
+                                                       ast_log(LOG_WARNING, "Unable to set write format to %s\n", ast_getformatname(&tmpfmt));
+                                               }
                                        }
                                        /* Check once more just in case */
                                        if (p->chan)
@@ -2024,7 +2029,7 @@ static int login_exec(struct ast_channel *chan, const char *data)
                                                        snprintf(chan->cdr->channel, sizeof(chan->cdr->channel), "Agent/%s", p->agent);
                                                ast_queue_log("NONE", chan->uniqueid, agent, "AGENTLOGIN", "%s", chan->name);
                                                ast_verb(2, "Agent '%s' logged in (format %s/%s)\n", p->agent,
-                                                                   ast_getformatname(chan->readformat), ast_getformatname(chan->writeformat));
+                                                                   ast_getformatname(&chan->readformat), ast_getformatname(&chan->writeformat));
                                                /* Login this channel and wait for it to go away */
                                                p->chan = chan;
                                                if (p->ackcall) {
@@ -2418,6 +2423,11 @@ static const struct ast_data_entry agents_data_providers[] = {
  */
 static int load_module(void)
 {
+       if (!(agent_tech.capabilities = ast_format_cap_alloc())) {
+               ast_log(LOG_ERROR, "ast_format_cap_alloc_nolock fail.\n");
+               return AST_MODULE_LOAD_FAILURE;
+       }
+       ast_format_cap_add_all(agent_tech.capabilities);
        /* Make sure we can register our agent channel type */
        if (ast_channel_register(&agent_tech)) {
                ast_log(LOG_ERROR, "Unable to register channel class 'Agent'\n");
@@ -2477,6 +2487,8 @@ static int unload_module(void)
                ast_free(p);
        }
        AST_LIST_UNLOCK(&agents);
+
+       agent_tech.capabilities = ast_format_cap_destroy(agent_tech.capabilities);
        return 0;
 }
 
index 120987a..5838288 100644 (file)
@@ -133,7 +133,7 @@ static int autoanswer = 1;
 static int mute = 0;
 static int noaudiocapture = 0;
 
-static struct ast_channel *alsa_request(const char *type, format_t format, const struct ast_channel *requestor, void *data, int *cause);
+static struct ast_channel *alsa_request(const char *type, struct ast_format_cap *cap, const struct ast_channel *requestor, void *data, int *cause);
 static int alsa_digit(struct ast_channel *c, char digit, unsigned int duration);
 static int alsa_text(struct ast_channel *c, const char *text);
 static int alsa_hangup(struct ast_channel *c);
@@ -144,10 +144,9 @@ static int alsa_write(struct ast_channel *chan, struct ast_frame *f);
 static int alsa_indicate(struct ast_channel *chan, int cond, const void *data, size_t datalen);
 static int alsa_fixup(struct ast_channel *oldchan, struct ast_channel *newchan);
 
-static const struct ast_channel_tech alsa_tech = {
+static struct ast_channel_tech alsa_tech = {
        .type = "Console",
        .description = tdesc,
-       .capabilities = AST_FORMAT_SLINEAR,
        .requester = alsa_request,
        .send_digit_end = alsa_digit,
        .send_text = alsa_text,
@@ -502,7 +501,7 @@ static struct ast_frame *alsa_read(struct ast_channel *chan)
                }
 
                f.frametype = AST_FRAME_VOICE;
-               f.subclass.codec = AST_FORMAT_SLINEAR;
+               ast_format_set(&f.subclass.format, AST_FORMAT_SLINEAR, 0);
                f.samples = FRAME_SIZE;
                f.datalen = FRAME_SIZE * 2;
                f.data.ptr = buf;
@@ -572,9 +571,10 @@ static struct ast_channel *alsa_new(struct chan_alsa_pvt *p, int state, const ch
 
        tmp->tech = &alsa_tech;
        ast_channel_set_fd(tmp, 0, readdev);
-       tmp->nativeformats = AST_FORMAT_SLINEAR;
-       tmp->readformat = AST_FORMAT_SLINEAR;
-       tmp->writeformat = AST_FORMAT_SLINEAR;
+       ast_format_set(&tmp->readformat, AST_FORMAT_SLINEAR, 0);
+       ast_format_set(&tmp->writeformat, AST_FORMAT_SLINEAR, 0);
+       ast_format_cap_add(tmp->nativeformats, &tmp->writeformat);
+
        tmp->tech_pvt = p;
        if (!ast_strlen_zero(p->context))
                ast_copy_string(tmp->context, p->context, sizeof(tmp->context));
@@ -596,14 +596,16 @@ static struct ast_channel *alsa_new(struct chan_alsa_pvt *p, int state, const ch
        return tmp;
 }
 
-static struct ast_channel *alsa_request(const char *type, format_t fmt, const struct ast_channel *requestor, void *data, int *cause)
+static struct ast_channel *alsa_request(const char *type, struct ast_format_cap *cap, const struct ast_channel *requestor, void *data, int *cause)
 {
-       format_t oldformat = fmt;
+       struct ast_format tmpfmt;
        char buf[256];
        struct ast_channel *tmp = NULL;
 
-       if (!(fmt &= AST_FORMAT_SLINEAR)) {
-               ast_log(LOG_NOTICE, "Asked to get a channel of format '%s'\n", ast_getformatname_multiple(buf, sizeof(buf), oldformat));
+       ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR, 0);
+
+       if (!(ast_format_cap_iscompatible(cap, &tmpfmt))) {
+               ast_log(LOG_NOTICE, "Asked to get a channel of format '%s'\n", ast_getformatname_multiple(buf, sizeof(buf), cap));
                return NULL;
        }
 
@@ -929,6 +931,12 @@ static int load_module(void)
        struct ast_config *cfg;
        struct ast_variable *v;
        struct ast_flags config_flags = { 0 };
+       struct ast_format tmpfmt;
+
+       if (!(alsa_tech.capabilities = ast_format_cap_alloc())) {
+               return AST_MODULE_LOAD_DECLINE;
+       }
+       ast_format_cap_add(alsa_tech.capabilities, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR, 0));
 
        /* Copy the default jb config over global_jbconf */
        memcpy(&global_jbconf, &default_jbconf, sizeof(struct ast_jb_conf));
@@ -1006,6 +1014,7 @@ static int unload_module(void)
        if (alsa.owner)
                return -1;
 
+       alsa_tech.capabilities = ast_format_cap_destroy(alsa_tech.capabilities);
        return 0;
 }
 
index 8218bdc..a58cfcc 100644 (file)
@@ -46,17 +46,16 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 #include "asterisk/app.h"
 #include "asterisk/bridging.h"
 
-static struct ast_channel *bridge_request(const char *type, format_t format, const struct ast_channel *requestor, void *data, int *cause);
+static struct ast_channel *bridge_request(const char *type, struct ast_format_cap *cap, const struct ast_channel *requestor, void *data, int *cause);
 static int bridge_call(struct ast_channel *ast, char *dest, int timeout);
 static int bridge_hangup(struct ast_channel *ast);
 static struct ast_frame *bridge_read(struct ast_channel *ast);
 static int bridge_write(struct ast_channel *ast, struct ast_frame *f);
 static struct ast_channel *bridge_bridgedchannel(struct ast_channel *chan, struct ast_channel *bridge);
 
-static const struct ast_channel_tech bridge_tech = {
+static struct ast_channel_tech bridge_tech = {
        .type = "Bridge",
        .description = "Bridge Interaction Channel",
-       .capabilities = -1,
        .requester = bridge_request,
        .call = bridge_call,
        .hangup = bridge_hangup,
@@ -189,9 +188,10 @@ static int bridge_hangup(struct ast_channel *ast)
 }
 
 /*! \brief Called when we want to place a call somewhere, but not actually call it... yet */
-static struct ast_channel *bridge_request(const char *type, format_t format, const struct ast_channel *requestor, void *data, int *cause)
+static struct ast_channel *bridge_request(const char *type, struct ast_format_cap *cap, const struct ast_channel *requestor, void *data, int *cause)
 {
        struct bridge_pvt *p = NULL;
+       struct ast_format slin;
 
        /* Try to allocate memory for our very minimal pvt structure */
        if (!(p = ast_calloc(1, sizeof(*p)))) {
@@ -215,11 +215,19 @@ static struct ast_channel *bridge_request(const char *type, format_t format, con
        /* Setup parameters on both new channels */
        p->input->tech = p->output->tech = &bridge_tech;
        p->input->tech_pvt = p->output->tech_pvt = p;
-       p->input->nativeformats = p->output->nativeformats = AST_FORMAT_SLINEAR;
-       p->input->readformat = p->output->readformat = AST_FORMAT_SLINEAR;
-       p->input->rawreadformat = p->output->rawreadformat = AST_FORMAT_SLINEAR;
-       p->input->writeformat = p->output->writeformat = AST_FORMAT_SLINEAR;
-       p->input->rawwriteformat = p->output->rawwriteformat = AST_FORMAT_SLINEAR;
+
+       ast_format_set(&slin, AST_FORMAT_SLINEAR, 0);
+
+       ast_format_cap_add(p->input->nativeformats, &slin);
+       ast_format_cap_add(p->output->nativeformats, &slin);
+       ast_format_copy(&p->input->readformat, &slin);
+       ast_format_copy(&p->output->readformat, &slin);
+       ast_format_copy(&p->input->rawreadformat, &slin);
+       ast_format_copy(&p->output->rawreadformat, &slin);
+       ast_format_copy(&p->input->writeformat, &slin);
+       ast_format_copy(&p->output->writeformat, &slin);
+       ast_format_copy(&p->input->rawwriteformat, &slin);
+       ast_format_copy(&p->output->rawwriteformat, &slin);
 
        return p->input;
 }
@@ -227,6 +235,11 @@ static struct ast_channel *bridge_request(const char *type, format_t format, con
 /*! \brief Load module into PBX, register channel */
 static int load_module(void)
 {
+       if (!(bridge_tech.capabilities = ast_format_cap_alloc())) {
+               return AST_MODULE_LOAD_FAILURE;
+       }
+
+       ast_format_cap_add_all(bridge_tech.capabilities);
        /* Make sure we can register our channel type */
        if (ast_channel_register(&bridge_tech)) {
                ast_log(LOG_ERROR, "Unable to register channel class 'Bridge'\n");
@@ -239,6 +252,7 @@ static int load_module(void)
 static int unload_module(void)
 {
        ast_channel_unregister(&bridge_tech);
+       bridge_tech.capabilities = ast_format_cap_destroy(bridge_tech.capabilities);
        return 0;
 }
 
index 64c1b87..eb961b6 100644 (file)
@@ -183,7 +183,7 @@ static struct ast_jb_conf default_jbconf = {
 static struct ast_jb_conf global_jbconf;
 
 /*! Channel Technology Callbacks @{ */
-static struct ast_channel *console_request(const char *type, format_t format,
+static struct ast_channel *console_request(const char *type, struct ast_format_cap *cap,
        const struct ast_channel *requestor, void *data, int *cause);
 static int console_digit_begin(struct ast_channel *c, char digit);
 static int console_digit_end(struct ast_channel *c, char digit, unsigned int duration);
@@ -198,15 +198,9 @@ static int console_indicate(struct ast_channel *chan, int cond,
 static int console_fixup(struct ast_channel *oldchan, struct ast_channel *newchan);
 /*! @} */
 
-/*!
- * \brief Formats natively supported by this module.
- */
-#define SUPPORTED_FORMATS ( AST_FORMAT_SLINEAR16 )
-
-static const struct ast_channel_tech console_tech = {
+static struct ast_channel_tech console_tech = {
        .type = "Console",
        .description = "Console Channel Driver",
-       .capabilities = SUPPORTED_FORMATS,
        .requester = console_request,
        .send_digit_begin = console_digit_begin,
        .send_digit_end = console_digit_end,
@@ -265,12 +259,12 @@ static void *stream_monitor(void *data)
        PaError res;
        struct ast_frame f = {
                .frametype = AST_FRAME_VOICE,
-               .subclass.codec = AST_FORMAT_SLINEAR16,
                .src = "console_stream_monitor",
                .data.ptr = buf,
                .datalen = sizeof(buf),
                .samples = sizeof(buf) / sizeof(int16_t),
        };
+       ast_format_set(&f.subclass.format, AST_FORMAT_SLINEAR16, 0);
 
        for (;;) {
                pthread_testcancel();
@@ -424,9 +418,9 @@ static struct ast_channel *console_new(struct console_pvt *pvt, const char *ext,
        }
 
        chan->tech = &console_tech;
-       chan->nativeformats = AST_FORMAT_SLINEAR16;
-       chan->readformat = AST_FORMAT_SLINEAR16;
-       chan->writeformat = AST_FORMAT_SLINEAR16;
+       ast_format_set(&chan->readformat, AST_FORMAT_SLINEAR16, 0);
+       ast_format_set(&chan->writeformat, AST_FORMAT_SLINEAR16, 0);
+       ast_format_cap_add(chan->nativeformats, &chan->readformat);
        chan->tech_pvt = ref_pvt(pvt);
 
        pvt->owner = chan;
@@ -448,9 +442,8 @@ static struct ast_channel *console_new(struct console_pvt *pvt, const char *ext,
        return chan;
 }
 
-static struct ast_channel *console_request(const char *type, format_t format, const struct ast_channel *requestor, void *data, int *cause)
+static struct ast_channel *console_request(const char *type, struct ast_format_cap *cap, const struct ast_channel *requestor, void *data, int *cause)
 {
-       format_t oldformat = format;
        struct ast_channel *chan = NULL;
        struct console_pvt *pvt;
        char buf[512];
@@ -460,9 +453,8 @@ static struct ast_channel *console_request(const char *type, format_t format, co
                return NULL;
        }
 
-       format &= SUPPORTED_FORMATS;
-       if (!format) {
-               ast_log(LOG_NOTICE, "Channel requested with unsupported format(s): '%s'\n", ast_getformatname_multiple(buf, sizeof(buf), oldformat));
+       if (!(ast_format_cap_has_joint(cap, console_tech.capabilities))) {
+               ast_log(LOG_NOTICE, "Channel requested with unsupported format(s): '%s'\n", ast_getformatname_multiple(buf, sizeof(buf), cap));
                goto return_unref;
        }
 
@@ -1457,6 +1449,7 @@ static void stop_streams(void)
 
 static int unload_module(void)
 {
+       console_tech.capabilities = ast_format_cap_destroy(console_tech.capabilities);
        ast_channel_unregister(&console_tech);
        ast_cli_unregister_multiple(cli_console, ARRAY_LEN(cli_console));
 
@@ -1474,8 +1467,14 @@ static int unload_module(void)
 
 static int load_module(void)
 {
+       struct ast_format tmpfmt;
        PaError res;
 
+       if (!(console_tech.capabilities = ast_format_cap_alloc())) {
+               return AST_MODULE_LOAD_DECLINE;
+       }
+       ast_format_cap_add(console_tech.capabilities, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR16, 0));
+
        init_pvt(&globals, NULL);
 
        if (!(pvts = ao2_container_alloc(NUM_PVT_BUCKETS, pvt_hash_cb, pvt_cmp_cb)))
index 09f4612..b5f398f 100644 (file)
@@ -1471,7 +1471,7 @@ static struct dahdi_chan_conf dahdi_chan_conf_default(void)
 }
 
 
-static struct ast_channel *dahdi_request(const char *type, format_t format, const struct ast_channel *requestor, void *data, int *cause);
+static struct ast_channel *dahdi_request(const char *type, struct ast_format_cap *cap, const struct ast_channel *requestor, void *data, int *cause);
 static int dahdi_digit_begin(struct ast_channel *ast, char digit);
 static int dahdi_digit_end(struct ast_channel *ast, char digit, unsigned int duration);
 static int dahdi_sendtext(struct ast_channel *c, const char *text);
@@ -1490,10 +1490,9 @@ static int dahdi_func_write(struct ast_channel *chan, const char *function, char
 static int dahdi_devicestate(void *data);
 static int dahdi_cc_callback(struct ast_channel *inbound, const char *dest, ast_cc_callback_fn callback);
 
-static const struct ast_channel_tech dahdi_tech = {
+static struct ast_channel_tech dahdi_tech = {
        .type = "DAHDI",
        .description = tdesc,
-       .capabilities = AST_FORMAT_SLINEAR | AST_FORMAT_ULAW | AST_FORMAT_ALAW,
        .requester = dahdi_request,
        .send_digit_begin = dahdi_digit_begin,
        .send_digit_end = dahdi_digit_end,
@@ -1679,6 +1678,7 @@ static int my_get_callerid(void *pvt, char *namebuf, char *numbuf, enum analog_e
        int res;
        unsigned char buf[256];
        int flags;
+       struct ast_format tmpfmt;
 
        poller.fd = p->subs[SUB_REAL].dfd;
        poller.events = POLLPRI | POLLIN;
@@ -1714,9 +1714,9 @@ static int my_get_callerid(void *pvt, char *namebuf, char *numbuf, enum analog_e
                }
 
                if (p->cid_signalling == CID_SIG_V23_JP) {
-                       res = callerid_feed_jp(p->cs, buf, res, AST_LAW(p));
+                       res = callerid_feed_jp(p->cs, buf, res, ast_format_set(&tmpfmt, AST_LAW(p), 0));
                } else {
-                       res = callerid_feed(p->cs, buf, res, AST_LAW(p));
+                       res = callerid_feed(p->cs, buf, res, ast_format_set(&tmpfmt, AST_LAW(p), 0));
                }
                if (res < 0) {
                        /*
@@ -1885,6 +1885,7 @@ static int restore_conference(struct dahdi_pvt *p);
 static int my_callwait(void *pvt)
 {
        struct dahdi_pvt *p = pvt;
+       struct ast_format tmpfmt;
        p->callwaitingrepeat = CALLWAITING_REPEAT_SAMPLES;
        if (p->cidspill) {
                ast_log(LOG_WARNING, "Spill already exists?!?\n");
@@ -1901,11 +1902,11 @@ static int my_callwait(void *pvt)
        /* Silence */
        memset(p->cidspill, 0x7f, 2400 + 600 + READ_SIZE * 4);
        if (!p->callwaitrings && p->callwaitingcallerid) {
-               ast_gen_cas(p->cidspill, 1, 2400 + 680, AST_LAW(p));
+               ast_gen_cas(p->cidspill, 1, 2400 + 680, ast_format_set(&tmpfmt, AST_LAW(p), 0));
                p->callwaitcas = 1;
                p->cidlen = 2400 + 680 + READ_SIZE * 4;
        } else {
-               ast_gen_cas(p->cidspill, 1, 2400, AST_LAW(p));
+               ast_gen_cas(p->cidspill, 1, 2400, ast_format_set(&tmpfmt, AST_LAW(p), 0));
                p->callwaitcas = 0;
                p->cidlen = 2400 + READ_SIZE * 4;
        }
@@ -1918,6 +1919,7 @@ static int my_callwait(void *pvt)
 static int my_send_callerid(void *pvt, int cwcid, struct ast_party_caller *caller)
 {
        struct dahdi_pvt *p = pvt;
+       struct ast_format tmpfmt;
 
        ast_debug(2, "Starting cid spill\n");
 
@@ -1931,7 +1933,7 @@ static int my_send_callerid(void *pvt, int cwcid, struct ast_party_caller *calle
                        p->cidlen = ast_callerid_generate(p->cidspill,
                                caller->id.name.str,
                                caller->id.number.str,
-                               AST_LAW(p));
+                               ast_format_set(&tmpfmt, AST_LAW(p), 0));
                } else {
                        ast_verb(3, "CPE supports Call Waiting Caller*ID.  Sending '%s/%s'\n",
                                caller->id.name.str, caller->id.number.str);
@@ -1940,7 +1942,7 @@ static int my_send_callerid(void *pvt, int cwcid, struct ast_party_caller *calle
                        p->cidlen = ast_callerid_callwaiting_generate(p->cidspill,
                                caller->id.name.str,
                                caller->id.number.str,
-                               AST_LAW(p));
+                               ast_format_set(&tmpfmt, AST_LAW(p), 0));
                        p->cidlen += READ_SIZE * 4;
                }
                p->cidpos = 0;
@@ -5106,12 +5108,14 @@ static int restore_conference(struct dahdi_pvt *p)
 
 static int send_cwcidspill(struct dahdi_pvt *p)
 {
+       struct ast_format tmpfmt;
+
        p->callwaitcas = 0;
        p->cidcwexpire = 0;
        p->cid_suppress_expire = 0;
        if (!(p->cidspill = ast_malloc(MAX_CALLERID_SIZE)))
                return -1;
-       p->cidlen = ast_callerid_callwaiting_generate(p->cidspill, p->callwait_name, p->callwait_num, AST_LAW(p));
+       p->cidlen = ast_callerid_callwaiting_generate(p->cidspill, p->callwait_name, p->callwait_num, ast_format_set(&tmpfmt, AST_LAW(p), 0));
        /* Make sure we account for the end */
        p->cidlen += READ_SIZE * 4;
        p->cidpos = 0;
@@ -5186,6 +5190,7 @@ static int send_callerid(struct dahdi_pvt *p)
 static int dahdi_callwait(struct ast_channel *ast)
 {
        struct dahdi_pvt *p = ast->tech_pvt;
+       struct ast_format tmpfmt;
        p->callwaitingrepeat = CALLWAITING_REPEAT_SAMPLES;
        if (p->cidspill) {
                ast_log(LOG_WARNING, "Spill already exists?!?\n");
@@ -5202,11 +5207,11 @@ static int dahdi_callwait(struct ast_channel *ast)
        /* Silence */
        memset(p->cidspill, 0x7f, 2400 + 600 + READ_SIZE * 4);
        if (!p->callwaitrings && p->callwaitingcallerid) {
-               ast_gen_cas(p->cidspill, 1, 2400 + 680, AST_LAW(p));
+               ast_gen_cas(p->cidspill, 1, 2400 + 680, ast_format_set(&tmpfmt, AST_LAW(p), 0));
                p->callwaitcas = 1;
                p->cidlen = 2400 + 680 + READ_SIZE * 4;
        } else {
-               ast_gen_cas(p->cidspill, 1, 2400, AST_LAW(p));
+               ast_gen_cas(p->cidspill, 1, 2400, ast_format_set(&tmpfmt, AST_LAW(p), 0));
                p->callwaitcas = 0;
                p->cidlen = 2400 + READ_SIZE * 4;
        }
@@ -8823,15 +8828,15 @@ static struct ast_frame *dahdi_read(struct ast_channel *ast)
                return &p->subs[idx].f;
        }
 
-       if (ast->rawreadformat == AST_FORMAT_SLINEAR) {
+       if (ast->rawreadformat.id == AST_FORMAT_SLINEAR) {
                if (!p->subs[idx].linear) {
                        p->subs[idx].linear = 1;
                        res = dahdi_setlinear(p->subs[idx].dfd, p->subs[idx].linear);
                        if (res)
                                ast_log(LOG_WARNING, "Unable to set channel %d (index %d) to linear mode.\n", p->channel, idx);
                }
-       } else if ((ast->rawreadformat == AST_FORMAT_ULAW) ||
-               (ast->rawreadformat == AST_FORMAT_ALAW)) {
+       } else if ((ast->rawreadformat.id == AST_FORMAT_ULAW) ||
+               (ast->rawreadformat.id == AST_FORMAT_ALAW)) {
                if (p->subs[idx].linear) {
                        p->subs[idx].linear = 0;
                        res = dahdi_setlinear(p->subs[idx].dfd, p->subs[idx].linear);
@@ -8839,7 +8844,7 @@ static struct ast_frame *dahdi_read(struct ast_channel *ast)
                                ast_log(LOG_WARNING, "Unable to set channel %d (index %d) to companded mode.\n", p->channel, idx);
                }
        } else {
-               ast_log(LOG_WARNING, "Don't know how to read frames in format %s\n", ast_getformatname(ast->rawreadformat));
+               ast_log(LOG_WARNING, "Don't know how to read frames in format %s\n", ast_getformatname(&ast->rawreadformat));
                ast_mutex_unlock(&p->lock);
                return NULL;
        }
@@ -8931,7 +8936,7 @@ static struct ast_frame *dahdi_read(struct ast_channel *ast)
        }
 
        p->subs[idx].f.frametype = AST_FRAME_VOICE;
-       p->subs[idx].f.subclass.codec = ast->rawreadformat;
+       ast_format_copy(&p->subs[idx].f.subclass.format, &ast->rawreadformat);
        p->subs[idx].f.samples = READ_SIZE;
        p->subs[idx].f.mallocd = 0;
        p->subs[idx].f.offset = AST_FRIENDLY_OFFSET;
@@ -9101,10 +9106,10 @@ static int dahdi_write(struct ast_channel *ast, struct ast_frame *frame)
                        ast_log(LOG_WARNING, "Don't know what to do with frame type '%d'\n", frame->frametype);
                return 0;
        }
-       if ((frame->subclass.codec != AST_FORMAT_SLINEAR) &&
-               (frame->subclass.codec != AST_FORMAT_ULAW) &&
-               (frame->subclass.codec != AST_FORMAT_ALAW)) {
-               ast_log(LOG_WARNING, "Cannot handle frames in %s format\n", ast_getformatname(frame->subclass.codec));
+       if ((frame->subclass.format.id != AST_FORMAT_SLINEAR) &&
+               (frame->subclass.format.id != AST_FORMAT_ULAW) &&
+               (frame->subclass.format.id != AST_FORMAT_ALAW)) {
+               ast_log(LOG_WARNING, "Cannot handle frames in %s format\n", ast_getformatname(&frame->subclass.format));
                return -1;
        }
        if (p->dialing) {
@@ -9124,7 +9129,7 @@ static int dahdi_write(struct ast_channel *ast, struct ast_frame *frame)
        if (!frame->data.ptr || !frame->datalen)
                return 0;
 
-       if (frame->subclass.codec == AST_FORMAT_SLINEAR) {
+       if (frame->subclass.format.id == AST_FORMAT_SLINEAR) {
                if (!p->subs[idx].linear) {
                        p->subs[idx].linear = 1;
                        res = dahdi_setlinear(p->subs[idx].dfd, p->subs[idx].linear);
@@ -9316,7 +9321,7 @@ static struct ast_str *create_channel_name(struct dahdi_pvt *i)
 static struct ast_channel *dahdi_new(struct dahdi_pvt *i, int state, int startpbx, int idx, int law, const char *linkedid)
 {
        struct ast_channel *tmp;
-       format_t deflaw;
+       struct ast_format deflaw;
        int x;
        int features;
        struct ast_str *chan_name;
@@ -9327,6 +9332,7 @@ static struct ast_channel *dahdi_new(struct dahdi_pvt *i, int state, int startpb
                return NULL;
        }
 
+       ast_format_clear(&deflaw);
 #if defined(HAVE_PRI)
        /*
         * The dnid has been stuffed with the called-number[:subaddress]
@@ -9354,9 +9360,9 @@ static struct ast_channel *dahdi_new(struct dahdi_pvt *i, int state, int startpb
        if (law) {
                i->law = law;
                if (law == DAHDI_LAW_ALAW) {
-                       deflaw = AST_FORMAT_ALAW;
+                       ast_format_set(&deflaw, AST_FORMAT_ALAW, 0);
                } else {
-                       deflaw = AST_FORMAT_ULAW;
+                       ast_format_set(&deflaw, AST_FORMAT_ULAW, 0);
                }
        } else {
                switch (i->sig) {
@@ -9370,18 +9376,18 @@ static struct ast_channel *dahdi_new(struct dahdi_pvt *i, int state, int startpb
                        break;
                }
                if (i->law_default == DAHDI_LAW_ALAW) {
-                       deflaw = AST_FORMAT_ALAW;
+                       ast_format_set(&deflaw, AST_FORMAT_ALAW, 0);
                } else {
-                       deflaw = AST_FORMAT_ULAW;
+                       ast_format_set(&deflaw, AST_FORMAT_ULAW, 0);
                }
        }
        ast_channel_set_fd(tmp, 0, i->subs[idx].dfd);
-       tmp->nativeformats = deflaw;
+       ast_format_cap_add(tmp->nativeformats, &deflaw);
        /* Start out assuming ulaw since it's smaller :) */
-       tmp->rawreadformat = deflaw;
-       tmp->readformat = deflaw;
-       tmp->rawwriteformat = deflaw;
-       tmp->writeformat = deflaw;
+       ast_format_copy(&tmp->rawreadformat, &deflaw);
+       ast_format_copy(&tmp->readformat, &deflaw);
+       ast_format_copy(&tmp->rawwriteformat, &deflaw);
+       ast_format_copy(&tmp->writeformat, &deflaw);
        i->subs[idx].linear = 0;
        dahdi_setlinear(i->subs[idx].dfd, i->subs[idx].linear);
        features = 0;
@@ -9619,6 +9625,7 @@ static void *analog_ss_thread(void *data)
        int len = 0;
        int res;
        int idx;
+       struct ast_format tmpfmt;
 
        ast_mutex_lock(&ss_thread_lock);
        ss_thread_count++;
@@ -10279,9 +10286,9 @@ static void *analog_ss_thread(void *data)
                                                        samples += res;
 
                                                        if (p->cid_signalling == CID_SIG_V23_JP) {
-                                                               res = callerid_feed_jp(cs, buf, res, AST_LAW(p));
+                                                               res = callerid_feed_jp(cs, buf, res, ast_format_set(&tmpfmt, AST_LAW(p), 0));
                                                        } else {
-                                                               res = callerid_feed(cs, buf, res, AST_LAW(p));
+                                                               res = callerid_feed(cs, buf, res, ast_format_set(&tmpfmt, AST_LAW(p), 0));
                                                        }
                                                        if (res < 0) {
                                                                /*
@@ -10550,7 +10557,7 @@ static void *analog_ss_thread(void *data)
                                                                }
                                                        }
                                                        samples += res;
-                                                       res = callerid_feed(cs, buf, res, AST_LAW(p));
+                                                       res = callerid_feed(cs, buf, res, ast_format_set(&tmpfmt, AST_LAW(p), 0));
                                                        if (res < 0) {
                                                                /*
                                                                 * The previous diagnostic message output likely
@@ -10718,7 +10725,7 @@ struct mwi_thread_data {
        size_t len;
 };
 
-static int calc_energy(const unsigned char *buf, int len, format_t law)
+static int calc_energy(const unsigned char *buf, int len, enum ast_format_id law)
 {
        int x;
        int sum = 0;
@@ -10743,6 +10750,7 @@ static void *mwi_thread(void *data)
        int i, res;
        unsigned int spill_done = 0;
        int spill_result = -1;
+       struct ast_format tmpfmt;
 
        if (!(cs = callerid_new(mtd->pvt->cid_signalling))) {
                mtd->pvt->mwimonitoractive = 0;
@@ -10750,7 +10758,7 @@ static void *mwi_thread(void *data)
                return NULL;
        }
 
-       callerid_feed(cs, mtd->buf, mtd->len, AST_LAW(mtd->pvt));
+       callerid_feed(cs, mtd->buf, mtd->len, ast_format_set(&tmpfmt, AST_LAW(mtd->pvt), 0));
 
        bump_gains(mtd->pvt);
 
@@ -10832,7 +10840,7 @@ static void *mwi_thread(void *data)
                        }
                        samples += res;
                        if (!spill_done) {
-                               if ((spill_result = callerid_feed(cs, mtd->buf, res, AST_LAW(mtd->pvt))) < 0) {
+                               if ((spill_result = callerid_feed(cs, mtd->buf, res, ast_format_set(&tmpfmt, AST_LAW(mtd->pvt), 0))) < 0) {
                                        /*
                                         * The previous diagnostic message output likely
                                         * explains why it failed.
@@ -10891,6 +10899,7 @@ quit_no_clean:
 static int mwi_send_init(struct dahdi_pvt * pvt)
 {
        int x, res;
+       struct ast_format tmpfmt;
 
 #ifdef HAVE_DAHDI_LINEREVERSE_VMWI
        /* Determine how this spill is to be sent */
@@ -10933,7 +10942,7 @@ static int mwi_send_init(struct dahdi_pvt * pvt)
        if (pvt->mwisend_fsk) {
 #endif
                pvt->cidlen = ast_callerid_vmwi_generate(pvt->cidspill, has_voicemail(pvt), CID_MWI_TYPE_MDMF_FULL,
-                                                        AST_LAW(pvt), pvt->cid_name, pvt->cid_num, 0);
+                                                        ast_format_set(&tmpfmt, AST_LAW(pvt), 0), pvt->cid_name, pvt->cid_num, 0);
                pvt->cidpos = 0;
 #ifdef HAVE_DAHDI_LINEREVERSE_VMWI
        }
@@ -13295,7 +13304,7 @@ static struct dahdi_pvt *determine_starting_point(const char *data, struct dahdi
        return p;
 }
 
-static struct ast_channel *dahdi_request(const char *type, format_t format, const struct ast_channel *requestor, void *data, int *cause)
+static struct ast_channel *dahdi_request(const char *type, struct ast_format_cap *cap, const struct ast_channel *requestor, void *data, int *cause)
 {
        int callwait = 0;
        struct dahdi_pvt *p;
@@ -16285,6 +16294,8 @@ static int __unload_module(void)
        }
 #endif /* defined(HAVE_SS7) */
        ast_cond_destroy(&ss_thread_complete);
+
+       dahdi_tech.capabilities = ast_format_cap_destroy(dahdi_tech.capabilities);
        return 0;
 }
 
@@ -18034,10 +18045,18 @@ static const struct ast_data_entry dahdi_data_providers[] = {
 static int load_module(void)
 {
        int res;
+       struct ast_format tmpfmt;
 #if defined(HAVE_PRI) || defined(HAVE_SS7)
        int y;
 #endif /* defined(HAVE_PRI) || defined(HAVE_SS7) */
 
+       if (!(dahdi_tech.capabilities = ast_format_cap_alloc())) {
+               return AST_MODULE_LOAD_FAILURE;
+       }
+       ast_format_cap_add(dahdi_tech.capabilities, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR, 0));
+       ast_format_cap_add(dahdi_tech.capabilities, ast_format_set(&tmpfmt, AST_FORMAT_ULAW, 0));
+       ast_format_cap_add(dahdi_tech.capabilities, ast_format_set(&tmpfmt, AST_FORMAT_ALAW, 0));
+
 #ifdef HAVE_PRI
        memset(pris, 0, sizeof(pris));
        for (y = 0; y < NUM_SPANS; y++) {
@@ -18146,7 +18165,10 @@ static int dahdi_sendtext(struct ast_channel *c, const char *text)
                return -1;
        mybuf = buf;
        if (p->mate) {
-               int codec = AST_LAW(p);
+               struct ast_format tmp;
+               /* PUT_CLI_MARKMS is a macro and requires a format ptr called codec to be present */
+               struct ast_format *codec = &tmp;
+               ast_format_set(codec, AST_LAW(p), 0);
                for (x = 0; x < HEADER_MS; x++) {       /* 50 ms of Mark */
                        PUT_CLID_MARKMS;
                }
index 280cac4..3bbf161 100644 (file)
@@ -111,7 +111,6 @@ struct gtalk_pvt {
        iksrule *ringrule;               /*!< Rule for matching RING request */
        int initiator;                   /*!< If we're the initiator */
        int alreadygone;
-       int capability;
        struct ast_codec_pref prefs;
        struct gtalk_candidate *theircandidates;
        struct gtalk_candidate *ourcandidates;
@@ -121,8 +120,9 @@ struct gtalk_pvt {
        struct ast_channel *owner;       /*!< Master Channel */
        struct ast_rtp_instance *rtp;             /*!< RTP audio session */
        struct ast_rtp_instance *vrtp;            /*!< RTP video session */
-       format_t jointcapability;             /*!< Supported capability at both ends (codecs ) */
-       format_t peercapability;
+       struct ast_format_cap *cap;
+       struct ast_format_cap *jointcap;             /*!< Supported capability at both ends (codecs ) */
+       struct ast_format_cap *peercap;
        struct gtalk_pvt *next; /* Next entity */
 };
 
@@ -152,7 +152,7 @@ struct gtalk {
        char context[AST_MAX_CONTEXT];
        char parkinglot[AST_MAX_CONTEXT];       /*!<  Parkinglot */
        char accountcode[AST_MAX_ACCOUNT_CODE]; /*!< Account code */
-       format_t capability;
+       struct ast_format_cap *cap;
        ast_group_t callgroup;  /*!< Call group */
        ast_group_t pickupgroup;        /*!< Pickup group */
        int callingpres;                /*!< Calling presentation */
@@ -169,12 +169,12 @@ static const char desc[]          = "Gtalk Channel";
 static const char DEFAULT_CONTEXT[]    = "default";
 static const int DEFAULT_ALLOWGUEST    = 1;
 
-static format_t global_capability = AST_FORMAT_ULAW | AST_FORMAT_ALAW | AST_FORMAT_GSM | AST_FORMAT_H263;
+static struct ast_format_cap *global_capability;
 
 AST_MUTEX_DEFINE_STATIC(gtalklock); /*!< Protect the interface list (of gtalk_pvt's) */
 
 /* Forward declarations */
-static struct ast_channel *gtalk_request(const char *type, format_t format, const struct ast_channel *requestor, void *data, int *cause);
+static struct ast_channel *gtalk_request(const char *type, struct ast_format_cap *cap, const struct ast_channel *requestor, void *data, int *cause);
 /*static int gtalk_digit(struct ast_channel *ast, char digit, unsigned int duration);*/
 static int gtalk_sendtext(struct ast_channel *ast, const char *text);
 static int gtalk_digit_begin(struct ast_channel *ast, char digit);
@@ -200,10 +200,9 @@ static int gtalk_parser(void *data, ikspak *pak);
 static int gtalk_create_candidates(struct gtalk *client, struct gtalk_pvt *p, char *sid, char *from, char *to);
 
 /*! \brief PBX interface structure for channel registration */
-static const struct ast_channel_tech gtalk_tech = {
+static struct ast_channel_tech gtalk_tech = {
        .type = "Gtalk",
        .description = "Gtalk Channel Driver",
-       .capabilities = AST_FORMAT_AUDIO_MASK,
        .requester = gtalk_request,
        .send_text = gtalk_sendtext,
        .send_digit_begin = gtalk_digit_begin,
@@ -247,6 +246,7 @@ static struct gtalk_container gtalk_list;
 
 static void gtalk_member_destroy(struct gtalk *obj)
 {
+       obj->cap = ast_format_cap_destroy(obj->cap);
        ast_free(obj);
 }
 
@@ -282,7 +282,7 @@ static struct gtalk *find_gtalk(char *name, char *connection)
 }
 
 
-static int add_codec_to_answer(const struct gtalk_pvt *p, int codec, iks *dcodecs)
+static int add_codec_to_answer(const struct gtalk_pvt *p, struct ast_format *codec, iks *dcodecs)
 {
        int res = 0;
        char *format = ast_getformatname(codec);
@@ -392,17 +392,17 @@ static int gtalk_invite(struct gtalk_pvt *p, char *to, char *from, char *sid, in
        struct gtalk *client = p->parent;
        iks *iq, *gtalk, *dcodecs, *payload_telephone, *transport;
        int x;
-       int pref_codec = 0;
-       int alreadysent = 0;
+       struct ast_format_cap *alreadysent;
        int codecs_num = 0;
        char *lowerto = NULL;
+       struct ast_format tmpfmt;
 
        iq = iks_new("iq");
        gtalk = iks_new("session");
        dcodecs = iks_new("description");
        transport = iks_new("transport");
        payload_telephone = iks_new("payload-type");
-       if (!(iq && gtalk && dcodecs && transport && payload_telephone)){
+       if (!(iq && gtalk && dcodecs && transport && payload_telephone)) {
                iks_delete(iq);
                iks_delete(gtalk);
                iks_delete(dcodecs);
@@ -415,16 +415,23 @@ static int gtalk_invite(struct gtalk_pvt *p, char *to, char *from, char *sid, in
        iks_insert_attrib(dcodecs, "xmlns", GOOGLE_AUDIO_NS);
        iks_insert_attrib(dcodecs, "xml:lang", "en");
 
-       for (x = 0; x < 64; x++) {
-               if (!(pref_codec = ast_codec_pref_index(&client->prefs, x)))
+       if (!(alreadysent = ast_format_cap_alloc_nolock())) {
+               return 0;
+       }
+       for (x = 0; x < AST_CODEC_PREF_SIZE; x++) {
+               if (!(ast_codec_pref_index(&client->prefs, x, &tmpfmt))) {
                        break;
-               if (!(client->capability & pref_codec))
+               }
+               if (!(ast_format_cap_iscompatible(client->cap, &tmpfmt))) {
                        continue;
-               if (alreadysent & pref_codec)
+               }
+               if (ast_format_cap_iscompatible(alreadysent, &tmpfmt)) {
                        continue;
-               codecs_num = add_codec_to_answer(p, pref_codec, dcodecs);
-               alreadysent |= pref_codec;
+               }
+               codecs_num = add_codec_to_answer(p, &tmpfmt, dcodecs);
+               ast_format_cap_add(alreadysent, &tmpfmt);
        }
+       alreadysent = ast_format_cap_destroy(alreadysent);
 
        if (codecs_num) {
                /* only propose DTMF within an audio session */
@@ -544,13 +551,15 @@ static enum ast_rtp_glue_result gtalk_get_rtp_peer(struct ast_channel *chan, str
        return res;
 }
 
-static format_t gtalk_get_codec(struct ast_channel *chan)
+static void gtalk_get_codec(struct ast_channel *chan, struct ast_format_cap *result)
 {
        struct gtalk_pvt *p = chan->tech_pvt;
-       return p->peercapability;
+       ast_mutex_lock(&p->lock);
+       ast_format_cap_copy(result, p->peercap);
+       ast_mutex_unlock(&p->lock);
 }
 
-static int gtalk_set_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance *rtp, struct ast_rtp_instance *vrtp, struct ast_rtp_instance *trtp, format_t codecs, int nat_active)
+static int gtalk_set_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance *rtp, struct ast_rtp_instance *vrtp, struct ast_rtp_instance *trtp, const struct ast_format_cap *cap, int nat_active)
 {
        struct gtalk_pvt *p;
 
@@ -658,15 +667,15 @@ static int gtalk_is_answered(struct gtalk *client, ikspak *pak)
        }
 
        /* Now gather all of the codecs that we are asked for */
-       ast_rtp_codecs_payload_formats(ast_rtp_instance_get_codecs(tmp->rtp), &tmp->peercapability, &peernoncodeccapability);
+       ast_rtp_codecs_payload_formats(ast_rtp_instance_get_codecs(tmp->rtp), tmp->peercap, &peernoncodeccapability);
 
-       /* at this point, we received an awser from the remote Gtalk client,
+       /* at this point, we received an answer from the remote Gtalk client,
           which allows us to compare capabilities */
-       tmp->jointcapability = tmp->capability & tmp->peercapability;
-       if (!tmp->jointcapability) {
-               ast_log(LOG_WARNING, "Capabilities don't match : us - %s, peer - %s, combined - %s \n", ast_getformatname_multiple(s1, BUFSIZ, tmp->capability),
-                       ast_getformatname_multiple(s2, BUFSIZ, tmp->peercapability),
-                       ast_getformatname_multiple(s3, BUFSIZ, tmp->jointcapability));
+       ast_format_cap_joint_copy(tmp->cap, tmp->peercap, tmp->jointcap);
+       if (ast_format_cap_is_empty(tmp->jointcap)) {
+               ast_log(LOG_WARNING, "Capabilities don't match : us - %s, peer - %s, combined - %s \n", ast_getformatname_multiple(s1, BUFSIZ, tmp->cap),
+                       ast_getformatname_multiple(s2, BUFSIZ, tmp->peercap),
+                       ast_getformatname_multiple(s3, BUFSIZ, tmp->jointcap));
                /* close session if capabilities don't match */
                ast_queue_hangup(tmp->owner);
 
@@ -1018,6 +1027,16 @@ static struct gtalk_pvt *gtalk_alloc(struct gtalk *client, const char *us, const
        if (!(tmp = ast_calloc(1, sizeof(*tmp)))) {
                return NULL;
        }
+       tmp->cap = ast_format_cap_alloc_nolock();
+       tmp->jointcap = ast_format_cap_alloc_nolock();
+       tmp->peercap = ast_format_cap_alloc_nolock();
+       if (!tmp->jointcap || !tmp->peercap || !tmp->cap) {
+               tmp->cap = ast_format_cap_destroy(tmp->cap);
+               tmp->jointcap = ast_format_cap_destroy(tmp->jointcap);
+               tmp->peercap = ast_format_cap_destroy(tmp->peercap);
+               ast_free(tmp);
+               return NULL;
+       }
 
        memcpy(&tmp->prefs, &client->prefs, sizeof(struct ast_codec_pref));
 
@@ -1046,10 +1065,10 @@ static struct gtalk_pvt *gtalk_alloc(struct gtalk *client, const char *us, const
        ast_rtp_codecs_payloads_clear(ast_rtp_instance_get_codecs(tmp->rtp), tmp->rtp);
 
        /* add user configured codec capabilites */
-       if (client->capability) {
-               tmp->capability = client->capability;
-       } else if (global_capability) {
-               tmp->capability = global_capability;
+       if (!(ast_format_cap_is_empty(client->cap))) {
+               ast_format_cap_copy(tmp->cap, client->cap);
+       } else if (!(ast_format_cap_is_empty(global_capability))) {
+               ast_format_cap_copy(tmp->cap, global_capability);
        }
 
        tmp->parent = client;
@@ -1081,9 +1100,9 @@ static struct gtalk_pvt *gtalk_alloc(struct gtalk *client, const char *us, const
 static struct ast_channel *gtalk_new(struct gtalk *client, struct gtalk_pvt *i, int state, const char *title, const char *linkedid)
 {
        struct ast_channel *tmp;
-       int fmt;
-       int what;
        const char *n2;
+       struct ast_format_cap *what; /* used as SHALLOW COPY DO NOT DESTROY */
+       struct ast_format tmpfmt;
 
        if (title)
                n2 = title;
@@ -1098,20 +1117,29 @@ static struct ast_channel *gtalk_new(struct gtalk *client, struct gtalk_pvt *i,
 
        /* Select our native format based on codec preference until we receive
           something from another device to the contrary. */
-       if (i->jointcapability)
-               what = i->jointcapability;
-       else if (i->capability)
-               what = i->capability;
-       else
+       if (!(ast_format_cap_is_empty(i->jointcap))) {
+               what = i->jointcap;
+       } else if (i->cap) {
+               what = i->cap;
+       } else {
                what = global_capability;
+       }
 
        /* Set Frame packetization */
        if (i->rtp) {
                ast_rtp_codecs_packetization_set(ast_rtp_instance_get_codecs(i->rtp), i->rtp, &i->prefs);
        }
 
-       tmp->nativeformats = ast_codec_choose(&i->prefs, what, 1) | (i->jointcapability & AST_FORMAT_VIDEO_MASK);
-       fmt = ast_best_codec(tmp->nativeformats);
+       ast_codec_choose(&i->prefs, what, 1, &tmpfmt);
+       ast_format_cap_add(tmp->nativeformats, &tmpfmt);
+
+       ast_format_cap_iter_start(i->jointcap);
+       while (!(ast_format_cap_iter_next(i->jointcap, &tmpfmt))) {
+               if (AST_FORMAT_GET_TYPE(tmpfmt.id) == AST_FORMAT_TYPE_VIDEO) {
+                       ast_format_cap_add(tmp->nativeformats, &tmpfmt);
+               }
+       }
+       ast_format_cap_iter_end(i->jointcap);
 
        if (i->rtp) {
                ast_channel_set_fd(tmp, 0, ast_rtp_instance_fd(i->rtp, 0));
@@ -1124,10 +1152,12 @@ static struct ast_channel *gtalk_new(struct gtalk *client, struct gtalk_pvt *i,
        if (state == AST_STATE_RING)
                tmp->rings = 1;
        tmp->adsicpe = AST_ADSI_UNAVAILABLE;
-       tmp->writeformat = fmt;
-       tmp->rawwriteformat = fmt;
-       tmp->readformat = fmt;
-       tmp->rawreadformat = fmt;
+
+       ast_best_codec(tmp->nativeformats, &tmpfmt);
+       ast_format_copy(&tmp->writeformat, &tmpfmt);
+       ast_format_copy(&tmp->rawwriteformat, &tmpfmt);
+       ast_format_copy(&tmp->readformat, &tmpfmt);
+       ast_format_copy(&tmp->rawreadformat, &tmpfmt);
        tmp->tech_pvt = i;
 
        tmp->callgroup = client->callgroup;
@@ -1240,6 +1270,9 @@ static void gtalk_free_pvt(struct gtalk *client, struct gtalk_pvt *p)
        if (p->vrtp)
                ast_rtp_instance_destroy(p->vrtp);
        gtalk_free_candidates(p->theircandidates);
+       p->cap = ast_format_cap_destroy(p->cap);
+       p->jointcap = ast_format_cap_destroy(p->jointcap);
+       p->peercap = ast_format_cap_destroy(p->peercap);
        ast_free(p);
 }
 
@@ -1341,15 +1374,15 @@ static int gtalk_newcall(struct gtalk *client, ikspak *pak)
        }
 
        /* Now gather all of the codecs that we are asked for */
-       ast_rtp_codecs_payload_formats(ast_rtp_instance_get_codecs(p->rtp), &p->peercapability, &peernoncodeccapability);
-       p->jointcapability = p->capability & p->peercapability;
+       ast_rtp_codecs_payload_formats(ast_rtp_instance_get_codecs(p->rtp), p->peercap, &peernoncodeccapability);
+       ast_format_cap_joint_copy(p->cap, p->peercap, p->jointcap);
        ast_mutex_unlock(&p->lock);
 
        ast_setstate(chan, AST_STATE_RING);
-       if (!p->jointcapability) {
-               ast_log(LOG_WARNING, "Capabilities don't match : us - %s, peer - %s, combined - %s \n", ast_getformatname_multiple(s1, BUFSIZ, p->capability),
-                       ast_getformatname_multiple(s2, BUFSIZ, p->peercapability),
-                       ast_getformatname_multiple(s3, BUFSIZ, p->jointcapability));
+       if (ast_format_cap_is_empty(p->jointcap)) {
+               ast_log(LOG_WARNING, "Capabilities don't match : us - %s, peer - %s, combined - %s \n", ast_getformatname_multiple(s1, BUFSIZ, p->cap),
+                       ast_getformatname_multiple(s2, BUFSIZ, p->peercap),
+                       ast_getformatname_multiple(s3, BUFSIZ, p->jointcap));
                /* close session if capabilities don't match */
                gtalk_action(client, p, "reject");
                p->alreadygone = 1;
@@ -1572,12 +1605,12 @@ static struct ast_frame *gtalk_rtp_read(struct ast_channel *ast, struct gtalk_pv
        if (p->owner) {
                /* We already hold the channel lock */
                if (f->frametype == AST_FRAME_VOICE) {
-                       if (f->subclass.codec != (p->owner->nativeformats & AST_FORMAT_AUDIO_MASK)) {
-                               ast_debug(1, "Oooh, format changed to %s\n", ast_getformatname(f->subclass.codec));
-                               p->owner->nativeformats =
-                                       (p->owner->nativeformats & AST_FORMAT_VIDEO_MASK) | f->subclass.codec;
-                               ast_set_read_format(p->owner, p->owner->readformat);
-                               ast_set_write_format(p->owner, p->owner->writeformat);
+                       if (!ast_format_cap_iscompatible(p->owner->nativeformats, &f->subclass.format)) {
+                               ast_debug(1, "Oooh, format changed to %s\n", ast_getformatname(&f->subclass.format));
+                               ast_format_cap_remove_bytype(p->owner->nativeformats, AST_FORMAT_TYPE_AUDIO);
+                               ast_format_cap_add(p->owner->nativeformats, &f->subclass.format);
+                               ast_set_read_format(p->owner, &p->owner->readformat);
+                               ast_set_write_format(p->owner, &p->owner->writeformat);
                        }
                        /* if ((ast_test_flag(p, SIP_DTMF) == SIP_DTMF_INBAND) && p->vad) {
                                f = ast_dsp_process(p->owner, p->vad, f);
@@ -1609,13 +1642,13 @@ static int gtalk_write(struct ast_channel *ast, struct ast_frame *frame)
 
        switch (frame->frametype) {
        case AST_FRAME_VOICE:
-               if (!(frame->subclass.codec & ast->nativeformats)) {
+               if (!(ast_format_cap_iscompatible(ast->nativeformats, &frame->subclass.format))) {
                        ast_log(LOG_WARNING,
                                        "Asked to transmit frame type %s, while native formats is %s (read/write = %s/%s)\n",
-                                       ast_getformatname(frame->subclass.codec),
+                                       ast_getformatname(&frame->subclass.format),
                                        ast_getformatname_multiple(buf, sizeof(buf), ast->nativeformats),
-                                       ast_getformatname(ast->readformat),
-                                       ast_getformatname(ast->writeformat));
+                                       ast_getformatname(&ast->readformat),
+                                       ast_getformatname(&ast->writeformat));
                        return 0;
                }
                if (p) {
@@ -1845,7 +1878,7 @@ static int gtalk_hangup(struct ast_channel *ast)
 }
 
 /*!\brief Part of PBX interface */
-static struct ast_channel *gtalk_request(const char *type, format_t format, const struct ast_channel *requestor, void *data, int *cause)
+static struct ast_channel *gtalk_request(const char *type, struct ast_format_cap *cap, const struct ast_channel *requestor, void *data, int *cause)
 {
        struct gtalk_pvt *p = NULL;
        struct gtalk *client = NULL;
@@ -1937,8 +1970,8 @@ static char *gtalk_show_channels(struct ast_cli_entry *e, int cmd, struct ast_cl
                                        chan->name,
                                        jid,
                                        resource,
-                                       ast_getformatname(chan->readformat),
-                                       ast_getformatname(chan->writeformat)
+                                       ast_getformatname(&chan->readformat),
+                                       ast_getformatname(&chan->writeformat)
                                        );
                        else
                                ast_log(LOG_WARNING, "No available channel\n");
@@ -2067,9 +2100,9 @@ static int gtalk_create_member(char *label, struct ast_variable *var, int allowg
                if (!strcasecmp(var->name, "username"))
                        ast_copy_string(member->user, var->value, sizeof(member->user));
                else if (!strcasecmp(var->name, "disallow"))
-                       ast_parse_allow_disallow(&member->prefs, &member->capability, var->value, 0);
+                       ast_parse_allow_disallow(&member->prefs, member->cap, var->value, 0);
                else if (!strcasecmp(var->name, "allow"))
-                       ast_parse_allow_disallow(&member->prefs, &member->capability, var->value, 1);
+                       ast_parse_allow_disallow(&member->prefs, member->cap, var->value, 1);
                else if (!strcasecmp(var->name, "context"))
                        ast_copy_string(member->context, var->value, sizeof(member->context));
                else if (!strcasecmp(var->name, "parkinglot"))
@@ -2122,6 +2155,7 @@ static int gtalk_load_config(void)
        memcpy(&global_jbconf, &default_jbconf, sizeof(struct ast_jb_conf));
 
        /* set defaults */
+       memset(&prefs, 0, sizeof(prefs));
        memset(&stunaddr, 0, sizeof(stunaddr));
        global_stunaddr = 0;
        global_allowguest = DEFAULT_ALLOWGUEST;
@@ -2138,9 +2172,9 @@ static int gtalk_load_config(void)
                if (!strcasecmp(var->name, "allowguest")) {
                        global_allowguest = (ast_true(ast_variable_retrieve(cfg, "general", "allowguest"))) ? 1 : 0;
                } else if (!strcasecmp(var->name, "disallow")) {
-                       ast_parse_allow_disallow(&prefs, &global_capability, var->value, 0);
+                       ast_parse_allow_disallow(&prefs, global_capability, var->value, 0);
                } else if (!strcasecmp(var->name, "allow")) {
-                       ast_parse_allow_disallow(&prefs, &global_capability, var->value, 1);
+                       ast_parse_allow_disallow(&prefs, global_capability, var->value, 1);
                } else if (!strcasecmp(var->name, "context")) {
                        ast_copy_string(global_context, var->value, sizeof(global_context));
                } else if (!strcasecmp(var->name, "externip")) {
@@ -2167,6 +2201,7 @@ static int gtalk_load_config(void)
                        member = ast_calloc(1, sizeof(*member));
                        ASTOBJ_INIT(member);
                        ASTOBJ_WRLOCK(member);
+                       member->cap = ast_format_cap_alloc_nolock();
                        if (!strcasecmp(cat, "guest")) {
                                ast_copy_string(member->name, "guest", sizeof(member->name));
                                ast_copy_string(member->user, "guest", sizeof(member->user));
@@ -2176,10 +2211,10 @@ static int gtalk_load_config(void)
                                member->prefs = prefs;
                                while (var) {
                                        if (!strcasecmp(var->name, "disallow")) {
-                                               ast_parse_allow_disallow(&member->prefs, &member->capability,
+                                               ast_parse_allow_disallow(&member->prefs, member->cap,
                                                                                                 var->value, 0);
                                        } else if (!strcasecmp(var->name, "allow")) {
-                                               ast_parse_allow_disallow(&member->prefs, &member->capability,
+                                               ast_parse_allow_disallow(&member->prefs, member->cap,
                                                                                                 var->value, 1);
                                        } else if (!strcasecmp(var->name, "context")) {
                                                ast_copy_string(member->context, var->value,
@@ -2229,8 +2264,22 @@ static int load_module(void)
 {
        struct ast_sockaddr bindaddr_tmp;
        struct ast_sockaddr ourip_tmp;
-
        char *jabber_loaded = ast_module_helper("", "res_jabber.so", 0, 0, 0, 0);
+       struct ast_format tmpfmt;
+
+       if (!(gtalk_tech.capabilities = ast_format_cap_alloc())) {
+               return AST_MODULE_LOAD_DECLINE;
+       }
+       if (!(global_capability = ast_format_cap_alloc())) {
+               return AST_MODULE_LOAD_DECLINE;
+       }
+
+       ast_format_cap_add_all_by_type(gtalk_tech.capabilities, AST_FORMAT_TYPE_AUDIO);
+       ast_format_cap_add(global_capability, ast_format_set(&tmpfmt, AST_FORMAT_ULAW, 0));
+       ast_format_cap_add(global_capability, ast_format_set(&tmpfmt, AST_FORMAT_GSM, 0));
+       ast_format_cap_add(global_capability, ast_format_set(&tmpfmt, AST_FORMAT_ALAW, 0));
+       ast_format_cap_add(global_capability, ast_format_set(&tmpfmt, AST_FORMAT_H263, 0));
+
        free(jabber_loaded);
        if (!jabber_loaded) {
                /* If embedded, check for a different module name */
@@ -2313,6 +2362,8 @@ static int unload_module(void)
        }
        ASTOBJ_CONTAINER_DESTROYALL(&gtalk_list, gtalk_member_destroy);
        ASTOBJ_CONTAINER_DESTROY(&gtalk_list);
+       global_capability = ast_format_cap_destroy(global_capability);
+       gtalk_tech.capabilities = ast_format_cap_destroy(gtalk_tech.capabilities);
        return 0;
 }
 
index e549d42..ccc0348 100644 (file)
@@ -85,6 +85,8 @@ extern "C" {
 #include "asterisk/stringfields.h"
 #include "asterisk/abstract_jb.h"
 #include "asterisk/astobj.h"
+#include "asterisk/format.h"
+#include "asterisk/format_cap.h"
 
 #ifdef __cplusplus
 }
@@ -129,7 +131,13 @@ static const char config[] = "h323.conf";
 static char default_context[AST_MAX_CONTEXT] = "default";
 static struct sockaddr_in bindaddr;
 
-#define GLOBAL_CAPABILITY (AST_FORMAT_G723_1 | AST_FORMAT_GSM | AST_FORMAT_ULAW | AST_FORMAT_ALAW | AST_FORMAT_G729A | AST_FORMAT_G726_AAL2 | AST_FORMAT_H261)
+#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)) \
 
 /** H.323 configuration values */
 static int h323_signalling_port = 1720;
@@ -173,9 +181,9 @@ static struct oh323_pvt {
        int newcontrol;                         /*!< Pending control to send */
        int newdigit;                           /*!< Pending DTMF digit to send */
        int newduration;                        /*!< Pending DTMF digit duration to send */
-       format_t pref_codec;                            /*!< Preferred codec */
-       format_t peercapability;                        /*!< Capabilities learned from peer */
-       format_t jointcapability;                       /*!< Common capabilities for local and remote side */
+       h323_format pref_codec;                         /*!< Preferred codec */
+       h323_format peercapability;                     /*!< Capabilities learned from peer */
+       h323_format jointcapability;                    /*!< Common capabilities for local and remote side */
        struct ast_codec_pref peer_prefs;       /*!< Preferenced list of codecs which remote side supports */
        int dtmf_pt[2];                         /*!< Payload code used for RFC2833/CISCO messages */
        int curDTMF;                            /*!< DTMF tone being generated to Asterisk side */
@@ -231,7 +239,7 @@ static void delete_users(void);
 static void delete_aliases(void);
 static void prune_peers(void);
 
-static struct ast_channel *oh323_request(const char *type, format_t format, const struct ast_channel *requestor, void *data, int *cause);
+static struct ast_channel *oh323_request(const char *type, struct ast_format_cap *cap, const struct ast_channel *requestor, void *data, int *cause);
 static int oh323_digit_begin(struct ast_channel *c, char digit);
 static int oh323_digit_end(struct ast_channel *c, char digit, unsigned int duration);
 static int oh323_call(struct ast_channel *c, char *dest, int timeout);
@@ -242,10 +250,9 @@ static int oh323_write(struct ast_channel *c, struct ast_frame *frame);
 static int oh323_indicate(struct ast_channel *c, int condition, const void *data, size_t datalen);
 static int oh323_fixup(struct ast_channel *oldchan, struct ast_channel *newchan);
 
-static const struct ast_channel_tech oh323_tech = {
+static struct ast_channel_tech oh323_tech = {
        .type = "H323",
        .description = tdesc,
-       .capabilities = AST_FORMAT_AUDIO_MASK,
        .properties = AST_CHAN_TP_WANTSJITTER | AST_CHAN_TP_CREATESJITTER,
        .requester = oh323_request,
        .send_digit_begin = oh323_digit_begin,
@@ -331,12 +338,13 @@ static int oh323_simulate_dtmf_end(const void *data)
 /*! \brief Channel and private structures should be already locked */
 static void __oh323_update_info(struct ast_channel *c, struct oh323_pvt *pvt)
 {
-       if (c->nativeformats != pvt->nativeformats) {
+       h323_format chan_nativeformats_bits = ast_format_cap_to_old_bitfield(c->nativeformats);
+       if (chan_nativeformats_bits != pvt->nativeformats) {
                if (h323debug)
                        ast_debug(1, "Preparing %s for new native format\n", c->name);
-               c->nativeformats = pvt->nativeformats;
-               ast_set_read_format(c, c->readformat);
-               ast_set_write_format(c, c->writeformat);
+               ast_format_cap_from_old_bitfield(c->nativeformats, pvt->nativeformats);
+               ast_set_read_format(c, &c->readformat);
+               ast_set_write_format(c, &c->writeformat);
        }
        if (pvt->needhangup) {
                if (h323debug)
@@ -764,18 +772,20 @@ static struct ast_frame *oh323_rtp_read(struct oh323_pvt *pvt)
        if (pvt->owner) {
                /* We already hold the channel lock */
                if (f->frametype == AST_FRAME_VOICE) {
-                       if (f->subclass.codec != pvt->owner->nativeformats) {
+                       if (!ast_format_cap_iscompatible(pvt->owner->nativeformats, &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 (h323debug)
-                                       ast_debug(1, "Oooh, format changed to '%s'\n", ast_getformatname(f->subclass.codec));
-                               pvt->owner->nativeformats = f->subclass.codec;
-                               pvt->nativeformats = f->subclass.codec;
-                               ast_set_read_format(pvt->owner, pvt->owner->readformat);
-                               ast_set_write_format(pvt->owner, pvt->owner->writeformat);
+                                       ast_debug(1, "Oooh, format changed to '%s'\n", ast_getformatname(&f->subclass.format));
+                               ast_format_cap_set(pvt->owner->nativeformats, &f->subclass.format);
+
+                               pvt->nativeformats = ast_format_to_old_bitfield(&f->subclass.format);
+
+                               ast_set_read_format(pvt->owner, &pvt->owner->readformat);
+                               ast_set_write_format(pvt->owner, &pvt->owner->writeformat);
                                ast_channel_unlock(pvt->owner);
                        }
                        /* Do in-band DTMF detection */
@@ -788,7 +798,7 @@ static struct ast_frame *oh323_rtp_read(struct oh323_pvt *pvt)
                                        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.codec));
+                                       ast_log(LOG_NOTICE, "Inband DTMF is not supported on codec %s. Use RFC2833\n", ast_getformatname(&f->subclass.format));
                                        pvt->noInbandDtmf = 1;
                                }
                                if (f &&(f->frametype == AST_FRAME_DTMF)) {
@@ -838,10 +848,10 @@ static int oh323_write(struct ast_channel *c, struct ast_frame *frame)
                        return 0;
                }
        } else {
-               if (!(frame->subclass.codec & c->nativeformats)) {
+               if (!(ast_format_cap_iscompatible(c->nativeformats, &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.codec), ast_getformatname_multiple(tmp, sizeof(tmp), c->nativeformats), ast_getformatname(c->readformat), ast_getformatname(c->writeformat));
+                               ast_getformatname(&frame->subclass.format), ast_getformatname_multiple(tmp, sizeof(tmp), c->nativeformats), ast_getformatname(&c->readformat), ast_getformatname(&c->writeformat));
                        return 0;
                }
        }
@@ -1011,7 +1021,8 @@ static struct ast_channel *__oh323_new(struct oh323_pvt *pvt, int state, const c
 {
        struct ast_channel *ch;
        char *cid_num, *cid_name;
-       int fmt;
+       h323_format fmt;
+       struct ast_format tmpfmt;
 
        if (!ast_strlen_zero(pvt->options.cid_num))
                cid_num = pvt->options.cid_num;
@@ -1033,13 +1044,18 @@ static struct ast_channel *__oh323_new(struct oh323_pvt *pvt, int state, const c
                ch->tech = &oh323_tech;
                if (!(fmt = pvt->jointcapability) && !(fmt = pvt->options.capability))
                        fmt = global_options.capability;
-               ch->nativeformats = ast_codec_choose(&pvt->options.prefs, fmt, 1)/* | (pvt->jointcapability & AST_FORMAT_VIDEO_MASK)*/;
-               pvt->nativeformats = ch->nativeformats;
-               fmt = ast_best_codec(ch->nativeformats);
-               ch->writeformat = fmt;
-               ch->rawwriteformat = fmt;
-               ch->readformat = fmt;
-               ch->rawreadformat = fmt;
+
+               ast_format_cap_from_old_bitfield(ch->nativeformats, fmt);
+               ast_codec_choose(&pvt->options.prefs, ch->nativeformats, 1, &tmpfmt)/* | (pvt->jointcapability & AST_FORMAT_VIDEO_MASK)*/;
+
+               ast_format_cap_set(ch->nativeformats, &tmpfmt);
+
+               pvt->nativeformats = ast_format_cap_to_old_bitfield(ch->nativeformats);
+               ast_best_codec(ch->nativeformats, &tmpfmt);
+               ast_format_copy(&ch->writeformat, &tmpfmt);
+               ast_format_copy(&ch->rawwriteformat, &tmpfmt);
+               ast_format_copy(&ch->readformat, &tmpfmt);
+               ast_format_copy(&ch->rawreadformat, &tmpfmt);
                if (!pvt->rtp)
                        __oh323_rtp_create(pvt);
 #if 0
@@ -1264,17 +1280,33 @@ static struct oh323_alias *realtime_alias(const char *alias)
        return a;
 }
 
+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_nolock();
+       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);
+       return res;
+
+}
+
 static int update_common_options(struct ast_variable *v, struct call_options *options)
 {
        int tmp = 0;
        char *val, *opt;
 
        if (!strcasecmp(v->name, "allow")) {
-               ast_parse_allow_disallow(&options->prefs, &options->capability, v->value, 1);
+               h323_parse_allow_disallow(&options->prefs, &options->capability, v->value, 1);
        } else if (!strcasecmp(v->name, "autoframing")) {
                options->autoframing = ast_true(v->value);
        } else if (!strcasecmp(v->name, "disallow")) {
-               ast_parse_allow_disallow(&options->prefs, &options->capability, v->value, 0);
+               h323_parse_allow_disallow(&options->prefs, &options->capability, v->value, 0);
        } else if (!strcasecmp(v->name, "dtmfmode")) {
                val = ast_strdupa(v->value);
                if ((opt = strchr(val, ':')) != (char *)NULL) {
@@ -1745,9 +1777,8 @@ static int create_addr(struct oh323_pvt *pvt, char *opeer)
                return 0;
        }
 }
-static struct ast_channel *oh323_request(const char *type, format_t format, const struct ast_channel *requestor, void *data, int *cause)
+static struct ast_channel *oh323_request(const char *type, struct ast_format_cap *cap, const struct ast_channel *requestor, void *data, int *cause)
 {
-       format_t oldformat;
        struct oh323_pvt *pvt;
        struct ast_channel *tmpc = NULL;
        char *dest = (char *)data;
@@ -1756,17 +1787,15 @@ static struct ast_channel *oh323_request(const char *type, format_t format, cons
        char tmp[256], tmp1[256];
 
        if (h323debug)
-               ast_debug(1, "type=%s, format=%s, data=%s.\n", type, ast_getformatname_multiple(tmp, sizeof(tmp), format), (char *)data);
+               ast_debug(1, "type=%s, format=%s, data=%s.\n", type, ast_getformatname_multiple(tmp, sizeof(tmp), cap), (char *)data);
 
        pvt = oh323_alloc(0);
        if (!pvt) {
                ast_log(LOG_WARNING, "Unable to build pvt data for '%s'\n", (char *)data);
                return NULL;
        }
-       oldformat = format;
-       format &= AST_FORMAT_AUDIO_MASK;
-       if (!format) {
-               ast_log(LOG_NOTICE, "Asked to get a channel of unsupported format '%s'\n", ast_getformatname_multiple(tmp, sizeof(tmp), format));
+       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(tmp, sizeof(tmp), cap));
                oh323_destroy(pvt);
                if (cause)
                        *cause = AST_CAUSE_INCOMPATIBLE_DESTINATION;
@@ -2020,11 +2049,11 @@ static void setup_rtp_connection(unsigned call_reference, const char *remoteIp,
        nativeformats_changed = 0;
        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 (h323debug)
-                       ast_debug(1, "Native format is set to %llu from %d by RTP payload type %d\n", (unsigned long long) rtptype.code, pvt->nativeformats, pt);
-               if (pvt->nativeformats != rtptype.code) {
-                       pvt->nativeformats = rtptype.code;
-                       nativeformats_changed = 1;
+               if (rtptype.asterisk_format) {
+                       if (pvt->nativeformats != ast_format_to_old_bitfield(&rtptype.format)) {
+                               pvt->nativeformats = ast_format_to_old_bitfield(&rtptype.format);
+                               nativeformats_changed = 1;
+                       }
                }
        } else if (h323debug)
                ast_log(LOG_NOTICE, "Payload type is unknown, formats isn't changed\n");
@@ -2032,15 +2061,18 @@ static void setup_rtp_connection(unsigned call_reference, const char *remoteIp,
        /* 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_nolock();
+                       ast_format_cap_from_old_bitfield(pvt_native, pvt->nativeformats);
+
                        /* Re-build translation path only if native format(s) has been changed */
-                       if (pvt->owner->nativeformats != pvt->nativeformats) {
+                       if (!(ast_format_cap_identical(pvt->owner->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->nativeformats), ast_getformatname_multiple(tmp2, sizeof(tmp2), pvt->owner->nativeformats), ast_getformatname(pvt->owner->readformat), ast_getformatname(pvt->owner->writeformat));
+                                       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), pvt->owner->nativeformats), ast_getformatname(&pvt->owner->readformat), ast_getformatname(&pvt->owner->writeformat));
                                }
-                               pvt->owner->nativeformats = pvt->nativeformats;
-                               ast_set_read_format(pvt->owner, pvt->owner->readformat);
-                               ast_set_write_format(pvt->owner, pvt->owner->writeformat);
+                               ast_format_cap_copy(pvt->owner->nativeformats, pvt_native);
+                               ast_set_read_format(pvt->owner, &pvt->owner->readformat);
+                               ast_set_write_format(pvt->owner, &pvt->owner->writeformat);
                        }
                        if (pvt->options.progress_audio)
                                ast_queue_control(pvt->owner, AST_CONTROL_PROGRESS);
@@ -2055,6 +2087,7 @@ static void setup_rtp_connection(unsigned call_reference, const char *remoteIp,
                                break;
                        }
                        ast_channel_unlock(pvt->owner);
+                       pvt_native = ast_format_cap_destroy(pvt_native);
                }
                else {
                        if (pvt->options.progress_audio)
@@ -2491,7 +2524,7 @@ static void set_peer_capabilities(unsigned call_reference, const char *token, in
                        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(1 << (prefs->order[i]-1)) : "<none>"), prefs->framing[i]);
+                               ast_debug(1, "prefs[%d]=%s:%d\n", i, (prefs->order[i] ? ast_getformatname(&prefs->formats[i]) : "<none>"), prefs->framing[i]);
                        }
                }
                if (pvt->rtp) {
@@ -2531,7 +2564,7 @@ static void set_local_capabilities(unsigned call_reference, const char *token)
                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(1 << (prefs.order[i]-1)) : "<none>"), prefs.framing[i]);
+                       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, "Capabilities for connection %s is set\n", token);
        }
@@ -3191,9 +3224,9 @@ static enum ast_rtp_glue_result oh323_get_rtp_peer(struct ast_channel *chan, str
        return res;
 }
 
-static char *convertcap(format_t cap)
+static char *convertcap(struct ast_format *format)
 {
-       switch (cap) {
+       switch (format->id) {
        case AST_FORMAT_G723_1:
                return "G.723";
        case AST_FORMAT_GSM:
@@ -3213,12 +3246,12 @@ static char *convertcap(format_t cap)
        case AST_FORMAT_ILBC:
                return "ILBC";
        default:
-               ast_log(LOG_NOTICE, "Don't know how to deal with mode %" PRId64 "\n", cap);
+               ast_log(LOG_NOTICE, "Don't know how to deal with mode %s\n", ast_getformatname(format));
                return NULL;
        }
 }
 
-static int oh323_set_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance *rtp, struct ast_rtp_instance *vrtp, struct ast_rtp_instance *trtp, format_t codecs, int nat_active)
+static int oh323_set_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance *rtp, struct ast_rtp_instance *vrtp, struct ast_rtp_instance *trtp, const struct ast_format_cap *codecs, int nat_active)
 {
        /* XXX Deal with Video */
        struct oh323_pvt *pvt;
@@ -3230,7 +3263,7 @@ static int oh323_set_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance
                return 0;
        }
 
-       mode = convertcap(chan->writeformat);
+       mode = convertcap(&chan->writeformat);
        pvt = (struct oh323_pvt *) chan->tech_pvt;
        if (!pvt) {
                ast_log(LOG_ERROR, "No Private Structure, this is bad\n");
@@ -3260,6 +3293,11 @@ static enum ast_module_load_result load_module(void)
 {
        int res;
 
+       if (!(oh323_tech.capabilities = ast_format_cap_alloc())) {
+               return AST_MODULE_LOAD_FAILURE;
+       }
+       ast_format_cap_add_all_by_type(oh323_tech.capabilities, AST_FORMAT_TYPE_AUDIO);
+
        h323debug = 0;
        sched = ast_sched_context_create();
        if (!sched) {
@@ -3430,6 +3468,7 @@ static int unload_module(void)
        ASTOBJ_CONTAINER_DESTROYALL(&aliasl, oh323_destroy_alias);
        ASTOBJ_CONTAINER_DESTROY(&aliasl);
 
+       oh323_tech.capabilities = ast_format_cap_destroy(oh323_tech.capabilities);
        return 0;
 }
 
index 5de2c4a..49434d6 100644 (file)
@@ -317,22 +317,22 @@ static int (*iax2_regfunk)(const char *username, int onoff) = NULL;
 #define IAX_CAPABILITY_FULLBANDWIDTH   0xFFFF
 /* T1, maybe ISDN */
 #define IAX_CAPABILITY_MEDBANDWIDTH (IAX_CAPABILITY_FULLBANDWIDTH & \
-                     ~AST_FORMAT_SLINEAR &      \
-                     ~AST_FORMAT_SLINEAR16 &    \
-                     ~AST_FORMAT_SIREN7 &       \
-                     ~AST_FORMAT_SIREN14 &      \
-                     ~AST_FORMAT_G719 &         \
-                     ~AST_FORMAT_ULAW &         \
-                     ~AST_FORMAT_ALAW &         \
-                     ~AST_FORMAT_G722)
+                     ~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))
 /* A modem */
 #define IAX_CAPABILITY_LOWBANDWIDTH (IAX_CAPABILITY_MEDBANDWIDTH & \
-                     ~AST_FORMAT_G726 &         \
-                     ~AST_FORMAT_G726_AAL2 &    \
-                     ~AST_FORMAT_ADPCM)
+                     ~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))
 
 #define IAX_CAPABILITY_LOWFREE      (IAX_CAPABILITY_LOWBANDWIDTH & \
-                     ~AST_FORMAT_G723_1)
+                     ~ast_format_id_to_old_bitfield(AST_FORMAT_G723_1))
 
 
 #define DEFAULT_MAXMS          2000            /* Must be faster than 2 seconds by default */
@@ -361,7 +361,7 @@ static struct ast_sched_context *sched;
 
 #define DONT_RESCHEDULE -2
 
-static format_t iax2_capability = IAX_CAPABILITY_FULLBANDWIDTH;
+static iax2_format iax2_capability = IAX_CAPABILITY_FULLBANDWIDTH;
 
 static int iaxdebug = 0;
 
@@ -470,7 +470,7 @@ struct iax2_user {
        int amaflags;
        int adsi;
        uint64_t flags;
-       format_t capability;
+       iax2_format capability;
        int maxauthreq; /*!< Maximum allowed outstanding AUTHREQs */
        int curauthreq; /*!< Current number of outstanding AUTHREQs */
        struct ast_codec_pref prefs;
@@ -517,7 +517,7 @@ struct iax2_peer {
 
        int expire;                                     /*!< Schedule entry for expiry */
        int expiry;                                     /*!< How soon to expire */
-       format_t capability;        /*!< Capability */
+       iax2_format capability;        /*!< Capability */
 
        /* Qualification */
        int callno;                                     /*!< Call number of POKE request */
@@ -648,15 +648,15 @@ struct chan_iax2_pvt {
        /*! Socket to send/receive on for this call */
        int sockfd;
        /*! Last received voice format */
-       format_t voiceformat;
+       iax2_format voiceformat;
        /*! Last received video format */
-       format_t videoformat;
+       iax2_format videoformat;
        /*! Last sent voice format */
-       format_t svoiceformat;
+       iax2_format svoiceformat;
        /*! Last sent video format */
-       format_t svideoformat;
+       iax2_format svideoformat;
        /*! What we are capable of sending */
-       format_t capability;
+       iax2_format capability;
        /*! Last received timestamp */
        unsigned int last;
        /*! Last sent timestamp - never send the same timestamp twice in a single call */
@@ -690,11 +690,11 @@ struct chan_iax2_pvt {
        /*! Negotiated format, this is only used to remember what format was
            chosen for an unauthenticated call so that the channel can get
            created later using the right format */
-       format_t chosenformat;
+       iax2_format chosenformat;
        /*! Peer selected format */
-       format_t peerformat;
+       iax2_format peerformat;
        /*! Peer capability */
-       format_t peercapability;
+       iax2_format peercapability;
        /*! timeval that we base our transmission on */
        struct timeval offset;
        /*! timeval that we base our delivery on */
@@ -1191,7 +1191,7 @@ static int send_command_final(struct chan_iax2_pvt *, char, int, unsigned int, c
 static int send_command_immediate(struct chan_iax2_pvt *, char, int, unsigned int, const unsigned char *, int, int);
 static int send_command_locked(unsigned short callno, char, int, unsigned int, const unsigned char *, int, int);
 static int send_command_transfer(struct chan_iax2_pvt *, char, int, unsigned int, const unsigned char *, int);
-static struct ast_channel *iax2_request(const char *type, format_t format, const struct ast_channel *requestor, void *data, int *cause);
+static struct ast_channel *iax2_request(const char *type, struct ast_format_cap *cap, const struct ast_channel *requestor, void *data, int *cause);
 static struct ast_frame *iax2_read(struct ast_channel *c);
 static struct iax2_peer *build_peer(const char *name, struct ast_variable *v, struct ast_variable *alt, int temponly);
 static struct iax2_user *build_user(const char *name, struct ast_variable *v, struct ast_variable *alt, int temponly);
@@ -1211,10 +1211,9 @@ static int replace_callno(const void *obj);
 static void sched_delay_remove(struct sockaddr_in *sin, struct callno_entry *callno_entry);
 static void network_change_event_cb(const struct ast_event *, void *);
 
-static const struct ast_channel_tech iax2_tech = {
+static struct ast_channel_tech iax2_tech = {
        .type = "IAX2",
        .description = tdesc,
-       .capabilities = IAX_CAPABILITY_FULLBANDWIDTH,
        .properties = AST_CHAN_TP_WANTSJITTER,
        .requester = iax2_request,
        .devicestate = iax2_devicestate,
@@ -1604,7 +1603,7 @@ static int send_lagrq(const void *data)
        return 0;
 }
 
-static unsigned char compress_subclass(format_t subclass)
+static unsigned char compress_subclass(iax2_format subclass)
 {
        int x;
        int power=-1;
@@ -1624,7 +1623,7 @@ static unsigned char compress_subclass(format_t subclass)
        return power | IAX_FLAG_SC_LOG;
 }
 
-static format_t uncompress_subclass(unsigned char csub)
+static iax2_format uncompress_subclass(unsigned char csub)
 {
        /* If the SC_LOG flag is set, return 2^csub otherwise csub */
        if (csub & IAX_FLAG_SC_LOG) {
@@ -1638,6 +1637,90 @@ static format_t uncompress_subclass(unsigned char csub)
                return csub;
 }
 
+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;
+       iax2_format format = 0;
+       if ((cap = ast_format_cap_alloc_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);
+       }
+
+       return format;
+}
+
+static iax2_format iax2_best_codec(iax2_format formats)
+{
+       struct ast_format_cap *cap = ast_format_cap_alloc_nolock();
+       struct ast_format tmpfmt;
+       if (!cap) {
+               return 0;
+       }
+
+       ast_format_clear(&tmpfmt);
+       ast_format_cap_from_old_bitfield(cap, formats);
+       ast_best_codec(cap, &tmpfmt);
+       cap = ast_format_cap_destroy(cap);
+       return ast_format_to_old_bitfield(&tmpfmt);
+}
+
+char *iax2_getformatname(iax2_format format)
+{
+       struct ast_format tmpfmt;
+       if (!(ast_format_from_old_bitfield(&tmpfmt, format))) {
+               return "Unknown";
+       }
+
+       return ast_getformatname(&tmpfmt);
+}
+
+static char *iax2_getformatname_multiple(char *codec_buf, size_t len, iax2_format format)
+{
+       struct ast_format_cap *cap = ast_format_cap_alloc_nolock();
+
+       if (!cap) {
+               return "(Nothing)";
+       }
+       ast_format_cap_from_old_bitfield(cap, format);
+       ast_getformatname_multiple(codec_buf, len, cap);
+       cap = ast_format_cap_destroy(cap);
+
+       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_nolock();
+       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);
+
+       return res;
+}
+
+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_nolock();
+       if (!cap) {
+               return -1;
+       }
+       ast_format_cap_from_old_bitfield(cap, formats);
+       res = ast_data_add_codecs(root, node_name, cap);
+       cap = ast_format_cap_destroy(cap);
+       return res;
+}
+
 /*!
  * \note The only member of the peer passed here guaranteed to be set is the name field
  */
@@ -3727,7 +3810,7 @@ static char *handle_cli_iax2_show_peer(struct ast_cli_entry *e, int cmd, struct
        struct iax2_peer *peer;
        char codec_buf[512];
        struct ast_str *encmethods = ast_str_alloca(256);
-       int x = 0, codec = 0, load_realtime = 0;
+       int x = 0, load_realtime = 0;
 
        switch (cmd) {
        case CLI_INIT:
@@ -3772,16 +3855,16 @@ static char *handle_cli_iax2_show_peer(struct ast_cli_entry *e, int cmd, struct
                ast_cli(a->fd, "  Defaddr->IP  : %s Port %d\n", ast_inet_ntoa(peer->defaddr.sin_addr), ntohs(peer->defaddr.sin_port));
                ast_cli(a->fd, "  Username     : %s\n", peer->username);
                ast_cli(a->fd, "  Codecs       : ");
-               ast_getformatname_multiple(codec_buf, sizeof(codec_buf) -1, peer->capability);
+               iax2_getformatname_multiple(codec_buf, sizeof(codec_buf) -1, peer->capability);
                ast_cli(a->fd, "%s\n", codec_buf);
 
                ast_cli(a->fd, "  Codec Order  : (");
-               for(x = 0; x < 32 ; x++) {
-                       codec = ast_codec_pref_index(&peer->prefs,x);
-                       if(!codec)
+               for(x = 0; x < AST_CODEC_PREF_SIZE; x++) {
+                       struct ast_format tmpfmt;
+                       if(!(ast_codec_pref_index(&peer->prefs, x, &tmpfmt)))
                                break;
-                       ast_cli(a->fd, "%s", ast_getformatname(codec));
-                       if(x < 31 && ast_codec_pref_index(&peer->prefs,x+1))
+                       ast_cli(a->fd, "%s", ast_getformatname(&tmpfmt));
+                       if(x < 31 && ast_codec_pref_index(&peer->prefs, x+1, &tmpfmt))
                                ast_cli(a->fd, "|");
                }
 
@@ -4067,7 +4150,9 @@ static void __get_from_jb(const void *p)
        ms = ast_tvdiff_ms(now, pvt->rxcore);
        
        if(ms >= (next = jb_next(pvt->jb))) {
-               ret = jb_get(pvt->jb,&frame,ms,ast_codec_interp_len(pvt->voiceformat));
+               struct ast_format voicefmt;
+               ast_format_from_old_bitfield(&voicefmt, pvt->voiceformat);
+               ret = jb_get(pvt->jb, &frame, ms, ast_codec_interp_len(&voicefmt));
                switch(ret) {
                case JB_OK:
                        fr = frame.data;
@@ -4081,8 +4166,8 @@ static void __get_from_jb(const void *p)
                        
                        /* create an interpolation frame */
                        af.frametype = AST_FRAME_VOICE;
-                       af.subclass.codec = pvt->voiceformat;
-                       af.samples  = frame.ms * (ast_format_rate(pvt->voiceformat) / 1000);
+                       ast_format_copy(&af.subclass.format, &voicefmt);
+                       af.samples  = frame.ms * (ast_format_rate(&voicefmt) / 1000);
                        af.src  = "IAX2 JB interpolation";
                        af.delivery = ast_tvadd(pvt->rxcore, ast_samp2tv(next, 1000));
                        af.offset = AST_FRIENDLY_OFFSET;
@@ -4154,7 +4239,7 @@ static int schedule_delivery(struct iax_frame *fr, int updatehistory, int fromtr
 
        if(fr->af.frametype == AST_FRAME_VOICE) {
                type = JB_TYPE_VOICE;
-               len = ast_codec_get_samples(&fr->af) / (ast_format_rate(fr->af.subclass.codec) / 1000);
+               len = ast_codec_get_samples(&fr->af) / (ast_format_rate(&fr->af.subclass.format) / 1000);
        } else if(fr->af.frametype == AST_FRAME_CNG) {
                type = JB_TYPE_SILENCE;
        }
@@ -4511,7 +4596,7 @@ static void realtime_update_peer(const char *peername, struct ast_sockaddr *sock
 }
 
 struct create_addr_info {
-       format_t capability;
+       iax2_format capability;
        uint64_t flags;
        int maxtime;
        int encmethods;
@@ -4557,8 +4642,14 @@ static int create_addr(const char *peername, struct ast_channel *c, struct socka
                /* use global iax prefs for unknown peer/user */
                /* But move the calling channel's native codec to the top of the preference list */
                memcpy(&ourprefs, &prefs, sizeof(ourprefs));
-               if (c)
-                       ast_codec_pref_prepend(&ourprefs, c->nativeformats, 1);
+               if (c) {
+                       struct ast_format tmpfmt;
+                       ast_format_cap_iter_start(c->nativeformats);
+                       while (!(ast_format_cap_iter_next(c->nativeformats, &tmpfmt))) {
+                               ast_codec_pref_prepend(&ourprefs, &tmpfmt, 1);
+                       }
+                       ast_format_cap_iter_end(c->nativeformats);
+               }
                ast_codec_pref_convert(&ourprefs, cai->prefs, sizeof(cai->prefs), 1);
                return 0;
        }
@@ -4585,8 +4676,13 @@ static int create_addr(const char *peername, struct ast_channel *c, struct socka
        memcpy(&ourprefs, &peer->prefs, sizeof(ourprefs));
        /* Move the calling channel's native codec to the top of the preference list */
        if (c) {
-               ast_debug(1, "prepending %llx to prefs\n", (unsigned long long) c->nativeformats);
-               ast_codec_pref_prepend(&ourprefs, c->nativeformats, 1);
+               struct ast_format tmpfmt;
+               ast_format_cap_iter_start(c->nativeformats);
+               while (!(ast_format_cap_iter_next(c->nativeformats, &tmpfmt))) {
+                       ast_debug(1, "prepending %s to prefs\n", ast_getformatname(&tmpfmt));
+                       ast_codec_pref_prepend(&ourprefs, &tmpfmt, 1);
+               }
+               ast_format_cap_iter_end(c->nativeformats);
        }
        ast_codec_pref_convert(&ourprefs, cai->prefs, sizeof(cai->prefs), 1);
        ast_copy_string(cai->context, peer->context, sizeof(cai->context));
@@ -4995,6 +5091,7 @@ static int iax2_call(struct ast_channel *c, char *dest, int timeout)
        unsigned char osp_block_index;
        unsigned int osp_block_length;
        unsigned char osp_buffer[256];
+       iax2_format iax2_tmpfmt;
 
        if ((c->_state != AST_STATE_DOWN) && (c->_state != AST_STATE_RESERVED)) {
                ast_log(LOG_WARNING, "Channel is already in use (%s)?\n", c->name);