[asterisk-commits] tilghman: branch group/codec_bits r114017 - in /team/group/codec_bits: apps/ ...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Apr 9 19:44:38 CDT 2008
Author: tilghman
Date: Wed Apr 9 19:44:38 2008
New Revision: 114017
URL: http://svn.digium.com/view/asterisk?view=rev&rev=114017
Log:
Use constants in more places, and fixup more channel drivers
Modified:
team/group/codec_bits/apps/app_meetme.c
team/group/codec_bits/channels/chan_alsa.c
team/group/codec_bits/channels/chan_console.c
team/group/codec_bits/channels/chan_gtalk.c
team/group/codec_bits/channels/chan_jingle.c
team/group/codec_bits/channels/chan_local.c
team/group/codec_bits/channels/chan_mgcp.c
team/group/codec_bits/channels/chan_phone.c
team/group/codec_bits/channels/chan_skinny.c
team/group/codec_bits/channels/chan_usbradio.c
team/group/codec_bits/channels/console_video.c
team/group/codec_bits/formats/format_g726.c
team/group/codec_bits/include/asterisk/frame.h
team/group/codec_bits/main/app.c
team/group/codec_bits/main/channel.c
team/group/codec_bits/main/file.c
team/group/codec_bits/main/frame.c
team/group/codec_bits/main/rtp.c
team/group/codec_bits/main/translate.c
team/group/codec_bits/res/res_agi.c
Modified: team/group/codec_bits/apps/app_meetme.c
URL: http://svn.digium.com/view/asterisk/team/group/codec_bits/apps/app_meetme.c?view=diff&rev=114017&r1=114016&r2=114017
==============================================================================
--- team/group/codec_bits/apps/app_meetme.c (original)
+++ team/group/codec_bits/apps/app_meetme.c Wed Apr 9 19:44:38 2008
@@ -2542,7 +2542,7 @@
(user->adminflags & (ADMINFLAG_MUTED | ADMINFLAG_SELFMUTED)) ||
(!user->talking)) ) {
int index, bit, found = 0;
- struct ast_extended_codec sample = { { 0, }, };
+ struct ast_extended_codec sample = AST_FMT_NULL_MASK_INIT;
for (index = 0; index < sizeof(fr.codec.audio) / sizeof(fr.codec.audio[0]); index++) {
for (bit = 0; bit < sizeof(fr.codec.audio[0]) * 8; bit++) {
sample.audio[index] = 1 << bit;
Modified: team/group/codec_bits/channels/chan_alsa.c
URL: http://svn.digium.com/view/asterisk/team/group/codec_bits/channels/chan_alsa.c?view=diff&rev=114017&r1=114016&r2=114017
==============================================================================
--- team/group/codec_bits/channels/chan_alsa.c (original)
+++ team/group/codec_bits/channels/chan_alsa.c Wed Apr 9 19:44:38 2008
@@ -130,7 +130,7 @@
static int autoanswer = 1;
-static struct ast_channel *alsa_request(const char *type, int format, void *data, int *cause);
+static struct ast_channel *alsa_request(const char *type, struct ast_extended_codec format, 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,7 +144,7 @@
static const struct ast_channel_tech alsa_tech = {
.type = "Console",
.description = tdesc,
- .capabilities = AST_FORMAT_SLINEAR,
+ .capabilities = AST_FMT_SLINEAR_INIT,
.requester = alsa_request,
.send_digit_end = alsa_digit,
.send_text = alsa_text,
@@ -469,7 +469,8 @@
return &f;
}
f.frametype = AST_FRAME_VOICE;
- f.subclass = AST_FORMAT_SLINEAR;
+ f.subclass = 0;
+ f.codec = AST_FMT_SLINEAR;
f.samples = FRAME_SIZE;
f.datalen = FRAME_SIZE * 2;
f.data = buf;
@@ -539,9 +540,9 @@
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;
+ tmp->nativeformats = AST_FMT_SLINEAR;
+ tmp->readformat = AST_FMT_SLINEAR;
+ tmp->writeformat = AST_FMT_SLINEAR;
tmp->tech_pvt = p;
if (!ast_strlen_zero(p->context))
ast_copy_string(tmp->context, p->context, sizeof(tmp->context));
@@ -563,13 +564,14 @@
return tmp;
}
-static struct ast_channel *alsa_request(const char *type, int format, void *data, int *cause)
-{
- int oldformat = format;
+static struct ast_channel *alsa_request(const char *type, struct ast_extended_codec format, void *data, int *cause)
+{
+ struct ast_extended_codec oldformat = format;
struct ast_channel *tmp = NULL;
-
- if (!(format &= AST_FORMAT_SLINEAR)) {
- ast_log(LOG_NOTICE, "Asked to get a channel of format '%d'\n", oldformat);
+ struct ast_str *str = ast_str_alloca(BITSTRING_SIZE);
+
+ if (FMT_NOT(format = FMT_AND(format, AST_FMT_SLINEAR))) {
+ ast_log(LOG_NOTICE, "Asked to get a channel of format '%s'\n", ast_codec2bitstring(oldformat, &str));
return NULL;
}
Modified: team/group/codec_bits/channels/chan_console.c
URL: http://svn.digium.com/view/asterisk/team/group/codec_bits/channels/chan_console.c?view=diff&rev=114017&r1=114016&r2=114017
==============================================================================
--- team/group/codec_bits/channels/chan_console.c (original)
+++ team/group/codec_bits/channels/chan_console.c Wed Apr 9 19:44:38 2008
@@ -202,15 +202,10 @@
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 = {
.type = "Console",
.description = "Console Channel Driver",
- .capabilities = SUPPORTED_FORMATS,
+ .capabilities = { .audio = { AST_FORMAT_AUDIO_SLINEAR16 } },
.requester = console_request,
.send_digit_begin = console_digit_begin,
.send_digit_end = console_digit_end,
@@ -445,20 +440,21 @@
return chan;
}
-static struct ast_channel *console_request(const char *type, int format, void *data, int *cause)
-{
- int oldformat = format;
+static struct ast_channel *console_request(const char *type, struct ast_extended_codec format, void *data, int *cause)
+{
+ struct ast_extended_codec oldformat = format, slin16 = { .audio = { AST_FORMAT_AUDIO_SLINEAR16 } };
struct ast_channel *chan = NULL;
struct console_pvt *pvt;
+ struct ast_str *str = ast_str_alloca(BITSTRING_SIZE);
if (!(pvt = find_pvt(data))) {
ast_log(LOG_ERROR, "Console device '%s' not found\n", (char *) data);
return NULL;
}
- format &= SUPPORTED_FORMATS;
- if (!format) {
- ast_log(LOG_NOTICE, "Channel requested with unsupported format(s): '%d'\n", oldformat);
+ format = FMT_AND(format, slin16);
+ if (FMT_NOT(format)) {
+ ast_log(LOG_NOTICE, "Channel requested with unsupported format(s): '%s'\n", ast_codec2bitstring(oldformat, &str));
goto return_unref;
}
Modified: team/group/codec_bits/channels/chan_gtalk.c
URL: http://svn.digium.com/view/asterisk/team/group/codec_bits/channels/chan_gtalk.c?view=diff&rev=114017&r1=114016&r2=114017
==============================================================================
--- team/group/codec_bits/channels/chan_gtalk.c (original)
+++ team/group/codec_bits/channels/chan_gtalk.c Wed Apr 9 19:44:38 2008
@@ -103,7 +103,7 @@
iksrule *ringrule; /*!< Rule for matching RING request */
int initiator; /*!< If we're the initiator */
int alreadygone;
- int capability;
+ struct ast_extended_codec capability;
struct ast_codec_pref prefs;
struct gtalk_candidate *theircandidates;
struct gtalk_candidate *ourcandidates;
@@ -113,8 +113,8 @@
struct ast_channel *owner; /*!< Master Channel */
struct ast_rtp *rtp; /*!< RTP audio session */
struct ast_rtp *vrtp; /*!< RTP video session */
- int jointcapability; /*!< Supported capability at both ends (codecs ) */
- int peercapability;
+ struct ast_extended_codec jointcapability; /*!< Supported capability at both ends (codecs ) */
+ struct ast_extended_codec peercapability;
struct gtalk_pvt *next; /* Next entity */
};
@@ -143,7 +143,7 @@
char user[AJI_MAX_JIDLEN];
char context[AST_MAX_CONTEXT];
char accountcode[AST_MAX_ACCOUNT_CODE]; /*!< Account code */
- int capability;
+ struct ast_extended_codec capability;
ast_group_t callgroup; /*!< Call group */
ast_group_t pickupgroup; /*!< Pickup group */
int callingpres; /*!< Calling presentation */
@@ -158,12 +158,12 @@
static const char desc[] = "Gtalk Channel";
-static int global_capability = AST_FORMAT_ULAW | AST_FORMAT_ALAW | AST_FORMAT_GSM | AST_FORMAT_H263;
+static struct ast_extended_codec global_capability = { .audio = { AST_FORMAT_AUDIO_ULAW | AST_FORMAT_AUDIO_ALAW | AST_FORMAT_AUDIO_GSM }, .video = { AST_FORMAT_VIDEO_H263 } };
AST_MUTEX_DEFINE_STATIC(gtalklock); /*!< Protect the interface list (of gtalk_pvt's) */
/* Forward declarations */
-static struct ast_channel *gtalk_request(const char *type, int format, void *data, int *cause);
+static struct ast_channel *gtalk_request(const char *type, struct ast_extended_codec format, void *data, int *cause);
static int gtalk_digit(struct ast_channel *ast, char digit, unsigned int duration);
static int gtalk_digit_begin(struct ast_channel *ast, char digit);
static int gtalk_digit_end(struct ast_channel *ast, char digit, unsigned int duration);
@@ -183,15 +183,15 @@
static char *gtalk_show_channels(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
/*----- RTP interface functions */
static int gtalk_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp,
- struct ast_rtp *vrtp, struct ast_rtp *trtp, int codecs, int nat_active);
+ struct ast_rtp *vrtp, struct ast_rtp *trtp, struct ast_extended_codec codecs, int nat_active);
static enum ast_rtp_get_result gtalk_get_rtp_peer(struct ast_channel *chan, struct ast_rtp **rtp);
-static int gtalk_get_codec(struct ast_channel *chan);
+static struct ast_extended_codec gtalk_get_codec(struct ast_channel *chan);
/*! \brief PBX interface structure for channel registration */
static const struct ast_channel_tech gtalk_tech = {
.type = "Gtalk",
.description = "Gtalk Channel Driver",
- .capabilities = AST_FORMAT_AUDIO_MASK,
+ .capabilities = AST_FMT_AUDIO_MASK_INIT,
.requester = gtalk_request,
.send_digit_begin = gtalk_digit_begin,
.send_digit_end = gtalk_digit_end,
@@ -273,7 +273,7 @@
}
-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_extended_codec codec, iks *dcodecs)
{
int res = 0;
char *format = ast_getformatname(codec);
@@ -374,7 +374,7 @@
iks_insert_node(dcodecs, payload_gsm);
res++;
}
- ast_rtp_lookup_code(p->rtp, 1, codec);
+ ast_rtp_lookup_codec(p->rtp, codec);
return res;
}
@@ -383,8 +383,8 @@
struct gtalk *client = p->parent;
iks *iq, *gtalk, *dcodecs, *payload_telephone, *transport;
int x;
- int pref_codec = 0;
- int alreadysent = 0;
+ struct ast_extended_codec pref_codec = AST_FMT_NULL_MASK_INIT;
+ struct ast_extended_codec alreadysent = AST_FMT_NULL_MASK_INIT;
int codecs_num = 0;
iq = iks_new("iq");
@@ -406,14 +406,16 @@
iks_insert_attrib(dcodecs, "xml:lang", "en");
for (x = 0; x < 32; x++) {
- if (!(pref_codec = ast_codec_pref_index(&client->prefs, x)))
+ if (FMT_NOT(pref_codec = ast_codec_pref_index(&client->prefs, x)))
break;
- if (!(client->capability & pref_codec))
+ if (FMT_NOT(FMT_AND(client->capability, pref_codec))) {
continue;
- if (alreadysent & pref_codec)
+ }
+ if (FMT_NZ(FMT_AND(alreadysent, pref_codec))) {
continue;
+ }
codecs_num = add_codec_to_answer(p, pref_codec, dcodecs);
- alreadysent |= pref_codec;
+ alreadysent = FMT_OR(alreadysent, pref_codec);
}
if (codecs_num) {
@@ -527,13 +529,13 @@
return res;
}
-static int gtalk_get_codec(struct ast_channel *chan)
+static struct ast_extended_codec gtalk_get_codec(struct ast_channel *chan)
{
struct gtalk_pvt *p = chan->tech_pvt;
return p->peercapability;
}
-static int gtalk_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp, struct ast_rtp *vrtp, struct ast_rtp *trtp, int codecs, int nat_active)
+static int gtalk_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp, struct ast_rtp *vrtp, struct ast_rtp *trtp, struct ast_extended_codec codecs, int nat_active)
{
struct gtalk_pvt *p;
@@ -613,8 +615,8 @@
/* at this point, we received an awser from the remote Gtalk client,
which allows us to compare capabilities */
- tmp->jointcapability = tmp->capability & tmp->peercapability;
- if (!tmp->jointcapability) {
+ tmp->jointcapability = FMT_AND(tmp->capability, tmp->peercapability);
+ if (FMT_NOT(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));
@@ -930,10 +932,11 @@
ast_rtp_pt_clear(tmp->rtp);
/* add user configured codec capabilites */
- if (client->capability)
+ if (FMT_NZ(client->capability)) {
tmp->capability = client->capability;
- else if (global_capability)
+ } else if (FMT_NZ(global_capability)) {
tmp->capability = global_capability;
+ }
tmp->parent = client;
if (!tmp->rtp) {
@@ -963,8 +966,8 @@
static struct ast_channel *gtalk_new(struct gtalk *client, struct gtalk_pvt *i, int state, const char *title)
{
struct ast_channel *tmp;
- int fmt;
- int what;
+ struct ast_extended_codec fmt;
+ struct ast_extended_codec what;
const char *n2;
if (title)
@@ -980,9 +983,9 @@
/* Select our native format based on codec preference until we receive
something from another device to the contrary. */
- if (i->jointcapability)
+ if (FMT_NZ(i->jointcapability))
what = i->jointcapability;
- else if (i->capability)
+ else if (FMT_NZ(i->capability))
what = i->capability;
else
what = global_capability;
@@ -991,7 +994,7 @@
if (i->rtp)
ast_rtp_codec_setpref(i->rtp, &i->prefs);
- tmp->nativeformats = ast_codec_choose(&i->prefs, what, 1) | (i->jointcapability & AST_FORMAT_VIDEO_MASK);
+ tmp->nativeformats = FMT_OR(ast_codec_choose(&i->prefs, what, 1), FMT_AND(i->jointcapability, AST_FMT_VIDEO_MASK));
fmt = ast_best_codec(tmp->nativeformats);
if (i->rtp) {
@@ -1169,11 +1172,11 @@
/* Now gather all of the codecs that we are asked for */
ast_rtp_get_current_formats(p->rtp, &p->peercapability, &peernoncodeccapability);
- p->jointcapability = p->capability & p->peercapability;
+ p->jointcapability = FMT_AND(p->capability, p->peercapability);
ast_mutex_unlock(&p->lock);
ast_setstate(chan, AST_STATE_RING);
- if (!p->jointcapability) {
+ if (FMT_NOT(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));
@@ -1347,10 +1350,10 @@
if (p->owner) {
/* We already hold the channel lock */
if (f->frametype == AST_FRAME_VOICE) {
- if (f->subclass != (p->owner->nativeformats & AST_FORMAT_AUDIO_MASK)) {
- ast_debug(1, "Oooh, format changed to %d\n", f->subclass);
+ if (!FMT_EQ(f->codec, FMT_AND(p->owner->nativeformats, AST_FMT_AUDIO_MASK))) {
+ ast_debug(1, "Oooh, format changed to %s\n", ast_getformatname(f->codec));
p->owner->nativeformats =
- (p->owner->nativeformats & AST_FORMAT_VIDEO_MASK) | f->subclass;
+ FMT_OR(FMT_AND(p->owner->nativeformats, AST_FMT_VIDEO_MASK), f->codec);
ast_set_read_format(p->owner, p->owner->readformat);
ast_set_write_format(p->owner, p->owner->writeformat);
}
@@ -1380,14 +1383,17 @@
{
struct gtalk_pvt *p = ast->tech_pvt;
int res = 0;
+ struct ast_str *str[3] = { ast_str_alloca(BITSTRING_SIZE), ast_str_alloca(BITSTRING_SIZE), ast_str_alloca(BITSTRING_SIZE) };
switch (frame->frametype) {
case AST_FRAME_VOICE:
- if (!(frame->subclass & ast->nativeformats)) {
+ if (FMT_NOT(FMT_AND(frame->codec, ast->nativeformats))) {
ast_log(LOG_WARNING,
- "Asked to transmit frame type %d, while native formats is %d (read/write = %d/%d)\n",
- frame->subclass, ast->nativeformats, ast->readformat,
- ast->writeformat);
+ "Asked to transmit frame type %s, while native formats is %s (read/write = %s/%s)\n",
+ ast_getformatname(frame->codec),
+ ast_codec2bitstring(ast->nativeformats, &str[0]),
+ ast_codec2bitstring(ast->readformat, &str[1]),
+ ast_codec2bitstring(ast->writeformat, &str[2]));
return 0;
}
if (p) {
@@ -1580,7 +1586,7 @@
}
/*! \brief Part of PBX interface */
-static struct ast_channel *gtalk_request(const char *type, int format, void *data, int *cause)
+static struct ast_channel *gtalk_request(const char *type, struct ast_extended_codec format, void *data, int *cause)
{
struct gtalk_pvt *p = NULL;
struct gtalk *client = NULL;
Modified: team/group/codec_bits/channels/chan_jingle.c
URL: http://svn.digium.com/view/asterisk/team/group/codec_bits/channels/chan_jingle.c?view=diff&rev=114017&r1=114016&r2=114017
==============================================================================
--- team/group/codec_bits/channels/chan_jingle.c (original)
+++ team/group/codec_bits/channels/chan_jingle.c Wed Apr 9 19:44:38 2008
@@ -103,7 +103,7 @@
iksrule *ringrule; /*!< Rule for matching RING request */
int initiator; /*!< If we're the initiator */
int alreadygone;
- int capability;
+ struct ast_extended_codec capability;
struct ast_codec_pref prefs;
struct jingle_candidate *theircandidates;
struct jingle_candidate *ourcandidates;
@@ -113,8 +113,8 @@
struct ast_channel *owner; /*!< Master Channel */
struct ast_rtp *rtp; /*!< RTP audio session */
struct ast_rtp *vrtp; /*!< RTP video session */
- int jointcapability; /*!< Supported capability at both ends (codecs ) */
- int peercapability;
+ struct ast_extended_codec jointcapability; /*!< Supported capability at both ends (codecs ) */
+ struct ast_extended_codec peercapability;
struct jingle_pvt *next; /* Next entity */
};
@@ -144,7 +144,7 @@
char user[100];
char context[100];
char accountcode[AST_MAX_ACCOUNT_CODE]; /*!< Account code */
- int capability;
+ struct ast_extended_codec capability;
ast_group_t callgroup; /*!< Call group */
ast_group_t pickupgroup; /*!< Pickup group */
int callingpres; /*!< Calling presentation */
@@ -160,12 +160,12 @@
static const char desc[] = "Jingle Channel";
static const char type[] = "Jingle";
-static int global_capability = AST_FORMAT_ULAW | AST_FORMAT_ALAW | AST_FORMAT_GSM | AST_FORMAT_H263;
+static struct ast_extended_codec global_capability = { .audio = { AST_FORMAT_AUDIO_ULAW | AST_FORMAT_AUDIO_ALAW | AST_FORMAT_AUDIO_GSM }, .video = { AST_FORMAT_VIDEO_H263 } };
AST_MUTEX_DEFINE_STATIC(jinglelock); /*!< Protect the interface list (of jingle_pvt's) */
/* Forward declarations */
-static struct ast_channel *jingle_request(const char *type, int format, void *data, int *cause);
+static struct ast_channel *jingle_request(const char *type, struct ast_extended_codec format, void *data, int *cause);
static int jingle_digit_begin(struct ast_channel *ast, char digit);
static int jingle_digit_end(struct ast_channel *ast, char digit, unsigned int duration);
static int jingle_call(struct ast_channel *ast, char *dest, int timeout);
@@ -182,15 +182,15 @@
static char *jingle_do_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
/*----- RTP interface functions */
static int jingle_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp,
- struct ast_rtp *vrtp, struct ast_rtp *tpeer, int codecs, int nat_active);
+ struct ast_rtp *vrtp, struct ast_rtp *tpeer, struct ast_extended_codec codecs, int nat_active);
static enum ast_rtp_get_result jingle_get_rtp_peer(struct ast_channel *chan, struct ast_rtp **rtp);
-static int jingle_get_codec(struct ast_channel *chan);
+static struct ast_extended_codec jingle_get_codec(struct ast_channel *chan);
/*! \brief PBX interface structure for channel registration */
static const struct ast_channel_tech jingle_tech = {
.type = "Jingle",
.description = "Jingle Channel Driver",
- .capabilities = AST_FORMAT_AUDIO_MASK,
+ .capabilities = AST_FMT_AUDIO_MASK_INIT,
.requester = jingle_request,
.send_digit_begin = jingle_digit_begin,
.send_digit_end = jingle_digit_end,
@@ -266,7 +266,7 @@
}
-static void add_codec_to_answer(const struct jingle_pvt *p, int codec, iks *dcodecs)
+static void add_codec_to_answer(const struct jingle_pvt *p, struct ast_extended_codec codec, iks *dcodecs)
{
char *format = ast_getformatname(codec);
@@ -304,7 +304,7 @@
iks_insert_attrib(payload_g723, "name", "G723");
iks_insert_node(dcodecs, payload_g723);
}
- ast_rtp_lookup_code(p->rtp, 1, codec);
+ ast_rtp_lookup_codec(p->rtp, codec);
}
static int jingle_accept_call(struct jingle *client, struct jingle_pvt *p)
@@ -313,8 +313,7 @@
struct aji_client *c = client->connection;
iks *iq, *jingle, *dcodecs, *payload_red, *payload_audio, *payload_cn;
int x;
- int pref_codec = 0;
- int alreadysent = 0;
+ struct ast_extended_codec pref_codec = AST_FMT_NULL_MASK_INIT, alreadysent = AST_FMT_NULL_MASK_INIT;
if (p->initiator)
return 1;
@@ -326,14 +325,17 @@
iks_insert_attrib(dcodecs, "xmlns", JINGLE_AUDIO_RTP_NS);
for (x = 0; x < 32; x++) {
- if (!(pref_codec = ast_codec_pref_index(&client->prefs, x)))
+ if (FMT_NOT(pref_codec = ast_codec_pref_index(&client->prefs, x))) {
break;
- if (!(client->capability & pref_codec))
+ }
+ if (FMT_NOT(FMT_AND(client->capability, pref_codec))) {
continue;
- if (alreadysent & pref_codec)
+ }
+ if (FMT_NZ(FMT_AND(alreadysent, pref_codec))) {
continue;
+ }
add_codec_to_answer(p, pref_codec, dcodecs);
- alreadysent |= pref_codec;
+ alreadysent = FMT_OR(alreadysent, pref_codec);
}
payload_red = iks_new("payload-type");
iks_insert_attrib(payload_red, "id", "117");
@@ -416,13 +418,13 @@
return res;
}
-static int jingle_get_codec(struct ast_channel *chan)
+static struct ast_extended_codec jingle_get_codec(struct ast_channel *chan)
{
struct jingle_pvt *p = chan->tech_pvt;
return p->peercapability;
}
-static int jingle_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp, struct ast_rtp *vrtp, struct ast_rtp *tpeer, int codecs, int nat_active)
+static int jingle_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp, struct ast_rtp *vrtp, struct ast_rtp *tpeer, struct ast_extended_codec codecs, int nat_active)
{
struct jingle_pvt *p;
@@ -799,8 +801,7 @@
static struct ast_channel *jingle_new(struct jingle *client, struct jingle_pvt *i, int state, const char *title)
{
struct ast_channel *tmp;
- int fmt;
- int what;
+ struct ast_extended_codec fmt, what;
const char *str;
if (title)
@@ -816,18 +817,19 @@
/* Select our native format based on codec preference until we receive
something from another device to the contrary. */
- if (i->jointcapability)
+ if (FMT_NZ(i->jointcapability)) {
what = i->jointcapability;
- else if (i->capability)
+ } else if (FMT_NZ(i->capability)) {
what = i->capability;
- else
+ } else {
what = global_capability;
+ }
/* Set Frame packetization */
if (i->rtp)
ast_rtp_codec_setpref(i->rtp, &i->prefs);
- tmp->nativeformats = ast_codec_choose(&i->prefs, what, 1) | (i->jointcapability & AST_FORMAT_VIDEO_MASK);
+ tmp->nativeformats = FMT_OR(ast_codec_choose(&i->prefs, what, 1), FMT_AND(i->jointcapability, AST_FMT_VIDEO_MASK));
fmt = ast_best_codec(tmp->nativeformats);
if (i->rtp) {
@@ -1130,10 +1132,10 @@
if (p->owner) {
/* We already hold the channel lock */
if (f->frametype == AST_FRAME_VOICE) {
- if (f->subclass != (p->owner->nativeformats & AST_FORMAT_AUDIO_MASK)) {
- ast_debug(1, "Oooh, format changed to %d\n", f->subclass);
+ if (!FMT_EQ(f->codec, FMT_AND(p->owner->nativeformats, AST_FMT_AUDIO_MASK))) {
+ ast_debug(1, "Oooh, format changed to %s\n", ast_getformatname(f->codec));
p->owner->nativeformats =
- (p->owner->nativeformats & AST_FORMAT_VIDEO_MASK) | f->subclass;
+ FMT_OR(FMT_AND(p->owner->nativeformats, AST_FMT_VIDEO_MASK), f->codec);
ast_set_read_format(p->owner, p->owner->readformat);
ast_set_write_format(p->owner, p->owner->writeformat);
}
@@ -1163,14 +1165,17 @@
{
struct jingle_pvt *p = ast->tech_pvt;
int res = 0;
+ struct ast_str *str[3] = { ast_str_alloca(BITSTRING_SIZE), ast_str_alloca(BITSTRING_SIZE), ast_str_alloca(BITSTRING_SIZE) };
switch (frame->frametype) {
case AST_FRAME_VOICE:
- if (!(frame->subclass & ast->nativeformats)) {
+ if (FMT_NOT(FMT_AND(frame->codec, ast->nativeformats))) {
ast_log(LOG_WARNING,
- "Asked to transmit frame type %d, while native formats is %d (read/write = %d/%d)\n",
- frame->subclass, ast->nativeformats, ast->readformat,
- ast->writeformat);
+ "Asked to transmit frame type %s, while native formats is %s (read/write = %s/%s)\n",
+ ast_getformatname(frame->codec),
+ ast_codec2bitstring(ast->nativeformats, &str[0]),
+ ast_codec2bitstring(ast->readformat, &str[1]),
+ ast_codec2bitstring(ast->writeformat, &str[2]));
return 0;
}
if (p) {
@@ -1417,7 +1422,7 @@
}
/*! \brief Part of PBX interface */
-static struct ast_channel *jingle_request(const char *type, int format, void *data, int *cause)
+static struct ast_channel *jingle_request(const char *type, struct ast_extended_codec format, void *data, int *cause)
{
struct jingle_pvt *p = NULL;
struct jingle *client = NULL;
Modified: team/group/codec_bits/channels/chan_local.c
URL: http://svn.digium.com/view/asterisk/team/group/codec_bits/channels/chan_local.c?view=diff&rev=114017&r1=114016&r2=114017
==============================================================================
--- team/group/codec_bits/channels/chan_local.c (original)
+++ team/group/codec_bits/channels/chan_local.c Wed Apr 9 19:44:38 2008
@@ -629,7 +629,7 @@
{
struct ast_channel *tmp = NULL, *tmp2 = NULL;
int randnum = ast_random() & 0xffff;
- struct ast_extended_codec fmt = { { 0, }, };
+ struct ast_extended_codec fmt = AST_FMT_NULL_MASK_INIT;
const char *t;
int ama;
Modified: team/group/codec_bits/channels/chan_mgcp.c
URL: http://svn.digium.com/view/asterisk/team/group/codec_bits/channels/chan_mgcp.c?view=diff&rev=114017&r1=114016&r2=114017
==============================================================================
--- team/group/codec_bits/channels/chan_mgcp.c (original)
+++ team/group/codec_bits/channels/chan_mgcp.c Wed Apr 9 19:44:38 2008
@@ -2122,7 +2122,7 @@
snprintf(m, sizeof(m), "m=audio %d RTP/AVP", ntohs(dest.sin_port));
for (x = 0; x <= 7; x++) {
for (y = 0; y < 32; y++) {
- struct ast_extended_codec audiocodec = { { 0, }, };
+ struct ast_extended_codec audiocodec = AST_FMT_NULL_MASK_INIT;
audiocodec.audio[x] = (1 << y);
if (FMT_NZ(FMT_AND(p->capability, audiocodec))) {
@@ -2193,7 +2193,7 @@
ast_copy_string(local, "p:20", sizeof(local));
for (x = 0; x < 8; x++) {
for (y = 0; y <= 32; y++) {
- struct ast_extended_codec audiocodec = { { 0, }, };
+ struct ast_extended_codec audiocodec = AST_FMT_NULL_MASK_INIT;
audiocodec.audio[x] = (1 << y);
if (FMT_NZ(FMT_AND(p->capability, audiocodec))) {
snprintf(tmp, sizeof(tmp), ", a:%s", ast_rtp_lookup_codec_mime_subtype(audiocodec, 0));
@@ -2223,17 +2223,18 @@
char tmp[80];
int x, y;
struct mgcp_endpoint *p = sub->parent;
+ struct ast_extended_codec audiocodec = AST_FMT_NULL_MASK_INIT;
ast_copy_string(local, "p:20", sizeof(local));
- for (x = 0; x < 8; x++) {
+ for (x = 0; x < sizeof(audiocodec.audio) / sizeof(audiocodec.audio[0]); x++) {
for (y = 0; y <= 32; y++) {
- struct ast_extended_codec audiocodec = { { 0, }, };
audiocodec.audio[x] = (1 << y);
if (FMT_NZ(FMT_AND(p->capability, audiocodec))) {
snprintf(tmp, sizeof(tmp), ", a:%s", ast_rtp_lookup_codec_mime_subtype(audiocodec, 0));
strncat(local, tmp, sizeof(local) - strlen(local) - 1);
}
}
+ audiocodec.audio[x] = 0;
}
if (mgcpdebug) {
ast_verb(3, "Creating connection for %s@%s-%d in cxmode: %s callid: %s\n",
@@ -2503,7 +2504,7 @@
char *c;
struct mgcp_request *req;
struct mgcp_gateway *gw = p->parent;
- struct ast_extended_codec zero = { { 0, }, };
+ const struct ast_extended_codec zero = AST_FMT_NULL_MASK_INIT;
if (result < 200) {
/* provisional response */
Modified: team/group/codec_bits/channels/chan_phone.c
URL: http://svn.digium.com/view/asterisk/team/group/codec_bits/channels/chan_phone.c?view=diff&rev=114017&r1=114016&r2=114017
==============================================================================
--- team/group/codec_bits/channels/chan_phone.c (original)
+++ team/group/codec_bits/channels/chan_phone.c Wed Apr 9 19:44:38 2008
@@ -1351,7 +1351,7 @@
int mode = MODE_IMMEDIATE;
int txgain = DEFAULT_GAIN, rxgain = DEFAULT_GAIN; /* default gain 1.0 */
struct ast_flags config_flags = { 0 };
- const struct ast_extended_codec nonvoice = { { 0, }, { -1, -1, -1, -1, -1, -1, -1 }, { -1 }, { -1 } };
+ const struct ast_extended_codec nonvoice = { { 0, }, { -1, -1, -1, -1, -1, -1, -1, -1 }, { -1 }, { -1 } };
cfg = ast_config_load(config, config_flags);
Modified: team/group/codec_bits/channels/chan_skinny.c
URL: http://svn.digium.com/view/asterisk/team/group/codec_bits/channels/chan_skinny.c?view=diff&rev=114017&r1=114016&r2=114017
==============================================================================
--- team/group/codec_bits/channels/chan_skinny.c (original)
+++ team/group/codec_bits/channels/chan_skinny.c Wed Apr 9 19:44:38 2008
@@ -4540,7 +4540,7 @@
struct skinny_device *d = s->device;
struct skinny_line *l;
uint32_t count = 0;
- struct ast_extended_codec codecs = { { 0, }, };
+ struct ast_extended_codec codecs = AST_FMT_NULL_MASK_INIT;
int i;
struct ast_str *str = ast_str_alloca(BITSTRING_SIZE);
Modified: team/group/codec_bits/channels/chan_usbradio.c
URL: http://svn.digium.com/view/asterisk/team/group/codec_bits/channels/chan_usbradio.c?view=diff&rev=114017&r1=114016&r2=114017
==============================================================================
--- team/group/codec_bits/channels/chan_usbradio.c (original)
+++ team/group/codec_bits/channels/chan_usbradio.c Wed Apr 9 19:44:38 2008
@@ -450,8 +450,7 @@
static int setformat(struct chan_usbradio_pvt *o, int mode);
-static struct ast_channel *usbradio_request(const char *type, int format, void *data
-, int *cause);
+static struct ast_channel *usbradio_request(const char *type, struct ast_extended_codec format, void *data, int *cause);
static int usbradio_digit_begin(struct ast_channel *c, char digit);
static int usbradio_digit_end(struct ast_channel *c, char digit, unsigned int duration);
static int usbradio_text(struct ast_channel *c, const char *text);
@@ -472,7 +471,7 @@
static const struct ast_channel_tech usbradio_tech = {
.type = "Radio",
.description = tdesc,
- .capabilities = AST_FORMAT_SLINEAR,
+ .capabilities = AST_FMT_SLINEAR_INIT,
.requester = usbradio_request,
.send_digit_begin = usbradio_digit_begin,
.send_digit_end = usbradio_digit_end,
@@ -1189,7 +1188,8 @@
return f;
/* ok we can build and deliver the frame to the caller */
f->frametype = AST_FRAME_VOICE;
- f->subclass = AST_FORMAT_SLINEAR;
+ f->subclass = 0;
+ f->codec = AST_FMT_SLINEAR;
f->samples = FRAME_SIZE;
f->datalen = FRAME_SIZE * 2;
f->data = o->usbradio_read_buf_8k + AST_FRIENDLY_OFFSET;
@@ -1285,9 +1285,9 @@
if (o->sounddev < 0)
setformat(o, O_RDWR);
c->fds[0] = o->sounddev; /* -1 if device closed, override later */
- c->nativeformats = AST_FORMAT_SLINEAR;
- c->readformat = AST_FORMAT_SLINEAR;
- c->writeformat = AST_FORMAT_SLINEAR;
+ c->nativeformats = AST_FMT_SLINEAR;
+ c->readformat = AST_FMT_SLINEAR;
+ c->writeformat = AST_FMT_SLINEAR;
c->tech_pvt = o;
if (!ast_strlen_zero(o->language))
@@ -1316,10 +1316,11 @@
return c;
}
-static struct ast_channel *usbradio_request(const char *type, int format, void *data, int *cause)
+static struct ast_channel *usbradio_request(const char *type, struct ast_extended_codec format, void *data, int *cause)
{
struct ast_channel *c;
struct chan_usbradio_pvt *o = find_desc(data);
+ struct ast_str *str = ast_str_alloca(BITSTRING_SIZE);
ast_debug(4, "usbradio_request ty <%s> data 0x%p <%s>\n", type, data, (char *) data);
if (o == NULL) {
@@ -1327,8 +1328,8 @@
/* XXX we could default to 'dsp' perhaps ? */
return NULL;
}
- if ((format & AST_FORMAT_SLINEAR) == 0) {
- ast_log(LOG_NOTICE, "Format 0x%x unsupported\n", format);
+ if (FMT_NOT(FMT_AND(format, AST_FMT_SLINEAR))) {
+ ast_log(LOG_NOTICE, "Format %s unsupported\n", ast_codec2bitstring(format, &str));
return NULL;
}
if (o->owner) {
Modified: team/group/codec_bits/channels/console_video.c
URL: http://svn.digium.com/view/asterisk/team/group/codec_bits/channels/console_video.c?view=diff&rev=114017&r1=114016&r2=114017
==============================================================================
--- team/group/codec_bits/channels/console_video.c (original)
+++ team/group/codec_bits/channels/console_video.c Wed Apr 9 19:44:38 2008
@@ -134,7 +134,7 @@
{
}
-struct ast_extended_codec console_video_formats = { { 0, }, };
+struct ast_extended_codec console_video_formats = AST_FMT_NULL_MASK_INIT;
#else /* defined(HAVE_FFMPEG) && defined(HAVE_SDL) */
Modified: team/group/codec_bits/formats/format_g726.c
URL: http://svn.digium.com/view/asterisk/team/group/codec_bits/formats/format_g726.c?view=diff&rev=114017&r1=114016&r2=114017
==============================================================================
--- team/group/codec_bits/formats/format_g726.c (original)
+++ team/group/codec_bits/formats/format_g726.c Wed Apr 9 19:44:38 2008
@@ -234,7 +234,7 @@
.buf_size = BUF_SIZE + AST_FRIENDLY_OFFSET,
.desc_size = sizeof(struct g726_desc),
},
- { .format = { { 0 } } } /* terminator */
+ { .format = AST_FMT_NULL_MASK_INIT } /* terminator */
};
static int load_module(void)
Modified: team/group/codec_bits/include/asterisk/frame.h
URL: http://svn.digium.com/view/asterisk/team/group/codec_bits/include/asterisk/frame.h?view=diff&rev=114017&r1=114016&r2=114017
==============================================================================
--- team/group/codec_bits/include/asterisk/frame.h (original)
+++ team/group/codec_bits/include/asterisk/frame.h Wed Apr 9 19:44:38 2008
@@ -41,7 +41,7 @@
struct ast_extended_codec {
int audio[8]; /* 256 bits */
- int video[7]; /* 224 bits */
+ int video[8]; /* 256 bits */
int image[1]; /* 32 bits */
int text[1]; /* 32 bits */
};
@@ -287,14 +287,14 @@
extern const struct ast_extended_codec AST_FMT_IMAGE_MASK;
extern const struct ast_extended_codec AST_FMT_TEXT_MASK;
extern const struct ast_extended_codec AST_FMT_NULL_MASK;
-#define AST_FMT_ULAW_INIT { { AST_FORMAT_AUDIO_ULAW, }, }
-#define AST_FMT_SLINEAR_INIT { { AST_FORMAT_AUDIO_SLINEAR, }, }
-#define AST_FMT_AUDIO_MASK_INIT { { -1, -1, -1, -1, -1, -1, -1, -1 }, }
-#define AST_FMT_VIDEO_MASK_INIT { .video = { -1, -1, -1, -1, -1, -1, -1 }, }
+#define AST_FMT_ULAW_INIT { .audio = { AST_FORMAT_AUDIO_ULAW, }, }
+#define AST_FMT_SLINEAR_INIT { .audio = { AST_FORMAT_AUDIO_SLINEAR, }, }
+#define AST_FMT_AUDIO_MASK_INIT { .audio = { -1, -1, -1, -1, -1, -1, -1, -1 }, }
+#define AST_FMT_VIDEO_MASK_INIT { .video = { -1, -1, -1, -1, -1, -1, -1, -1 }, }
#define AST_FMT_IMAGE_MASK_INIT { .image = { -1 }, }
#define AST_FMT_TEXT_MASK_INIT { .text = { -1 }, }
-#define AST_FMT_FULL_MASK_INIT { { -1, -1, -1, -1, -1, -1, -1, -1 }, { -1, -1, -1, -1, -1, -1, -1 }, { -1 }, { -1 } }
-#define AST_FMT_NULL_MASK_INIT { { 0, } }
+#define AST_FMT_FULL_MASK_INIT { .audio = { -1, -1, -1, -1, -1, -1, -1, -1 }, .video = { -1, -1, -1, -1, -1, -1, -1, -1 }, .image = { -1 }, .text = { -1 } }
+#define AST_FMT_NULL_MASK_INIT { { 0 } }
enum ast_control_frame_type {
AST_CONTROL_HANGUP = 1, /*!< Other end has hungup */
@@ -652,6 +652,12 @@
#define BITSTRING_SIZE 60
/*! Common bitwise operations, now that codec is no longer a 32-bit integer. */
+#define FMT_AND(a,b) ast_extended_codec_and(a,b)
+#define FMT_OR(a,b) ast_extended_codec_or(a,b)
+#define FMT_EQ(a,b) ast_extended_codec_equal(a,b)
+#define FMT_COMPL(a) ast_extended_codec_compl(a)
+#define FMT_NZ(a) ast_extended_codec_nonzero(a)
+#define FMT_NOT(a) ast_extended_codec_not(a)
AST_INLINE_API(
int ast_extended_codec_not(struct ast_extended_codec format),
@@ -699,13 +705,12 @@
AST_INLINE_API(
struct ast_extended_codec ast_extended_codec_compl(struct ast_extended_codec format),
{
- int i;
- int max = sizeof(format) / sizeof(int);
+ unsigned int i;
union {
struct ast_extended_codec c;
int bits[sizeof(format) / sizeof(int)];
} u = { format };
- for (i = 0; i < max; i++) {
+ for (i = 0; i < sizeof(format) / sizeof(int); i++) {
u.bits[i] = ~u.bits[i];
}
return u.c;
@@ -714,13 +719,6 @@
extern struct ast_extended_codec ast_extended_codec_and(struct ast_extended_codec format1, struct ast_extended_codec format2);
extern struct ast_extended_codec ast_extended_codec_or(struct ast_extended_codec format1, struct ast_extended_codec format2);
-
-#define FMT_AND(a,b) ast_extended_codec_and(a,b)
-#define FMT_OR(a,b) ast_extended_codec_or(a,b)
-#define FMT_EQ(a,b) ast_extended_codec_equal(a,b)
-#define FMT_COMPL(a) ast_extended_codec_compl(a)
-#define FMT_NZ(a) ast_extended_codec_nonzero(a)
-#define FMT_NOT(a) ast_extended_codec_not(a)
AST_INLINE_API(
int ast_extended_codec_isaudio(struct ast_extended_codec format),
Modified: team/group/codec_bits/main/app.c
URL: http://svn.digium.com/view/asterisk/team/group/codec_bits/main/app.c?view=diff&rev=114017&r1=114016&r2=114017
==============================================================================
--- team/group/codec_bits/main/app.c (original)
+++ team/group/codec_bits/main/app.c Wed Apr 9 19:44:38 2008
@@ -573,7 +573,7 @@
time_t start, end;
struct ast_dsp *sildet = NULL; /* silence detector dsp */
int totalsilence = 0;
- struct ast_extended_codec rfmt = { { 0 } };
+ struct ast_extended_codec rfmt = AST_FMT_NULL_MASK_INIT;
struct ast_silence_generator *silgen = NULL;
char prependfile[80];
Modified: team/group/codec_bits/main/channel.c
URL: http://svn.digium.com/view/asterisk/team/group/codec_bits/main/channel.c?view=diff&rev=114017&r1=114016&r2=114017
==============================================================================
--- team/group/codec_bits/main/channel.c (original)
+++ team/group/codec_bits/main/channel.c Wed Apr 9 19:44:38 2008
@@ -708,7 +708,7 @@
/* This just our opinion, expressed in code. We are asked to choose
the best codec to use, given no information */
int x;
- struct ast_extended_codec result = { { 0 } };
+ struct ast_extended_codec result = AST_FMT_NULL_MASK_INIT;
struct ast_str *str = ast_str_alloca(BITSTRING_SIZE);
static const struct {
int page;
Modified: team/group/codec_bits/main/file.c
URL: http://svn.digium.com/view/asterisk/team/group/codec_bits/main/file.c?view=diff&rev=114017&r1=114016&r2=114017
==============================================================================
--- team/group/codec_bits/main/file.c (original)
+++ team/group/codec_bits/main/file.c Wed Apr 9 19:44:38 2008
@@ -612,7 +612,7 @@
* so we must enforce a format.
*/
int page, bits;
- struct ast_extended_codec codec = { { 0 } };
+ struct ast_extended_codec codec = AST_FMT_NULL_MASK_INIT;
char *buf;
int buflen;
Modified: team/group/codec_bits/main/frame.c
URL: http://svn.digium.com/view/asterisk/team/group/codec_bits/main/frame.c?view=diff&rev=114017&r1=114016&r2=114017
==============================================================================
--- team/group/codec_bits/main/frame.c (original)
+++ team/group/codec_bits/main/frame.c Wed Apr 9 19:44:38 2008
@@ -45,14 +45,14 @@
#endif
/*! Convenience structures */
[... 191 lines stripped ...]
More information about the asterisk-commits
mailing list