[asterisk-commits] tilghman: branch group/codec_bits r111813 - in /team/group/codec_bits: channe...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri Mar 28 15:08:08 CDT 2008
Author: tilghman
Date: Fri Mar 28 15:08:08 2008
New Revision: 111813
URL: http://svn.digium.com/view/asterisk?view=rev&rev=111813
Log:
Finishing conversion of channels
Modified:
team/group/codec_bits/channels/chan_agent.c
team/group/codec_bits/channels/chan_iax2.c
team/group/codec_bits/channels/chan_mgcp.c
team/group/codec_bits/channels/chan_oss.c
team/group/codec_bits/channels/chan_phone.c
team/group/codec_bits/channels/chan_sip.c
team/group/codec_bits/channels/chan_skinny.c
team/group/codec_bits/channels/chan_unistim.c
team/group/codec_bits/channels/chan_vpb.cc
team/group/codec_bits/channels/chan_zap.c
team/group/codec_bits/include/asterisk/callerid.h
team/group/codec_bits/include/asterisk/channel.h
team/group/codec_bits/include/asterisk/frame.h
Modified: team/group/codec_bits/channels/chan_agent.c
URL: http://svn.digium.com/view/asterisk/team/group/codec_bits/channels/chan_agent.c?view=diff&rev=111813&r1=111812&r2=111813
==============================================================================
--- team/group/codec_bits/channels/chan_agent.c (original)
+++ team/group/codec_bits/channels/chan_agent.c Fri Mar 28 15:08:08 2008
@@ -177,7 +177,7 @@
static AST_LIST_HEAD_STATIC(agents, agent_pvt); /*!< Holds the list of agents (loaded form agents.conf). */
#define CHECK_FORMATS(ast, p) do { \
- struct ast_str *fromstr = NULL, *tostr = NULL; \
+ struct ast_str *fromstr = ast_str_alloca(BITSTRING_SIZE), *tostr = ast_str_alloca(BITSTRING_SIZE); \
if (p->chan) {\
if (memcmp(&ast->nativeformats, &p->chan->nativeformats, sizeof(ast->nativeformats))) { \
ast_debug(1, "Native formats changing from %s to %s\n", ast_codec2bitstring(ast->nativeformats, &fromstr), ast_codec2bitstring(p->chan->nativeformats, &tostr)); \
@@ -191,8 +191,6 @@
ast_set_read_format(p->chan, ast->rawreadformat); \
if (memcmp(&p->chan->writeformat, &ast->rawwriteformat, sizeof(ast->rawwriteformat)) && !p->chan->generator) \
ast_set_write_format(p->chan, ast->rawwriteformat); \
- ast_free(fromstr); \
- ast_free(tostr); \
} \
} while(0)
@@ -1958,18 +1956,16 @@
struct ast_extended_codec codec = ast_best_codec(chan->nativeformats);
res = ast_set_read_format(chan, codec);
if (res) {
- struct ast_str *str = NULL;
+ struct ast_str *str = ast_str_alloca(BITSTRING_SIZE);
ast_log(LOG_WARNING, "Unable to set read format to %s\n", ast_codec2bitstring(codec, &str));
- ast_free(str);
}
}
if (!res) {
struct ast_extended_codec codec = ast_best_codec(chan->nativeformats);
res = ast_set_write_format(chan, codec);
if (res) {
- struct ast_str *str = NULL;
+ struct ast_str *str = ast_str_alloca(BITSTRING_SIZE);
ast_log(LOG_WARNING, "Unable to set write format to %s\n", ast_codec2bitstring(codec, &str));
- ast_free(str);
}
}
/* Check once more just in case */
Modified: team/group/codec_bits/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/team/group/codec_bits/channels/chan_iax2.c?view=diff&rev=111813&r1=111812&r2=111813
==============================================================================
--- team/group/codec_bits/channels/chan_iax2.c (original)
+++ team/group/codec_bits/channels/chan_iax2.c Fri Mar 28 15:08:08 2008
@@ -2747,7 +2747,7 @@
/* create an interpolation frame */
af.frametype = AST_FRAME_VOICE;
- af.subclass = pvt->voiceformat;
+ af.codec = pvt->voiceformat;
af.samples = frame.ms * 8;
af.src = "IAX2 JB interpolation";
af.delivery = ast_tvadd(pvt->rxcore, ast_samp2tv(next, 1000));
@@ -3700,14 +3700,12 @@
return AST_BRIDGE_FAILED_NOWARN;
}
if (c0->nativeformats != c1->nativeformats) {
- struct ast_str *str1, *str2;
+ struct ast_str *str1 = ast_str_alloca(BITSTRING_SIZE), *str2 = ast_str_alloca(BITSTRING_SIZE);
char buf0[255];
char buf1[255];
ast_getformatname_multiple(buf0, sizeof(buf0) -1, c0->nativeformats);
ast_getformatname_multiple(buf1, sizeof(buf1) -1, c1->nativeformats);
ast_verb(3, "Operating with different codecs %s[%s] %s[%s] , can't native bridge...\n", ast_codec2bitstring(c0->nativeformats, &str1), buf0, ast_codec2bitstring(c1->nativeformats, &str2), buf1);
- ast_free(str1);
- ast_free(str2);
/* Remove from native mode */
lock_both(callno0, callno1);
if (iaxs[callno0])
@@ -4489,7 +4487,7 @@
/* High two bytes are the same on timestamp, or sending on a trunk */ &&
(f->frametype == AST_FRAME_VOICE)
/* is a voice frame */ &&
- (f->subclass == pvt->svoiceformat)
+ (FMT_EQ(f->codec, pvt->svoiceformat))
/* is the same type */ ) {
/* Force immediate rather than delayed transmission */
now = 1;
@@ -4570,9 +4568,9 @@
if ((f->frametype == AST_FRAME_IAX) && (f->subclass == IAX_COMMAND_ACK))
fr->retries = -1;
else if (f->frametype == AST_FRAME_VOICE)
- pvt->svoiceformat = f->subclass;
+ pvt->svoiceformat = FMT_AND(f->codec, AST_FMT_AUDIO_MASK);
else if (f->frametype == AST_FRAME_VIDEO)
- pvt->svideoformat = f->subclass & ~0x1;
+ pvt->svideoformat = FMT_AND(f->codec, AST_FMT_VIDEO_MASK);
if (ast_test_flag(pvt, IAX_ENCRYPTED)) {
if (ast_test_flag(pvt, IAX_KEYPOPULATED)) {
if (iaxdebug) {
@@ -6347,10 +6345,10 @@
pvt->aseqno = 0;
pvt->peercallno = peercallno;
pvt->transferring = TRANSFER_NONE;
- pvt->svoiceformat = -1;
- pvt->voiceformat = 0;
- pvt->svideoformat = -1;
- pvt->videoformat = 0;
+ pvt->svoiceformat = AST_FMT_AUDIO_MASK;
+ pvt->voiceformat = AST_FMT_AUDIO_MASK;
+ pvt->svideoformat = AST_FMT_VIDEO_MASK;
+ pvt->videoformat = AST_FMT_NULL_MASK;
pvt->transfercallno = -1;
memset(&pvt->rxcore, 0, sizeof(pvt->rxcore));
memset(&pvt->offset, 0, sizeof(pvt->offset));
@@ -7618,11 +7616,11 @@
f.frametype = AST_FRAME_VOICE;
if (!iaxs[fr->callno]) {
/* drop it */
- } else if (iaxs[fr->callno]->voiceformat == 0) {
+ } else if (FMT_NOT(iaxs[fr->callno]->voiceformat)) {
ast_log(LOG_WARNING, "Received trunked frame before first full voice frame\n ");
iax2_vnak(fr->callno);
} else {
- f.subclass = iaxs[fr->callno]->voiceformat;
+ f.codec = iaxs[fr->callno]->voiceformat;
f.datalen = len;
if (f.datalen >= 0) {
if (f.datalen)
@@ -8081,11 +8079,10 @@
}
if (f.frametype == AST_FRAME_VOICE) {
- if (memcmp(&f.codec, &iaxs[fr->callno]->voiceformat) != 0) {
- struct ast_str *str = NULL;
- iaxs[fr->callno]->voiceformat = f.subclass;
+ if (!FMT_EQ(f.codec, iaxs[fr->callno]->voiceformat)) {
+ struct ast_str *str = ast_str_alloca(BITSTRING_SIZE);
+ iaxs[fr->callno]->voiceformat = f.codec;
ast_debug(1, "Ooh, voice format changed to %s\n", ast_codec2bitstring(f.codec, &str));
- ast_free(str);
if (iaxs[fr->callno]->owner) {
int orignative;
retryowner:
@@ -8875,10 +8872,9 @@
return 1;
}
} else {
- struct ast_str *str = NULL;
+ struct ast_str *str = ast_str_alloca(BITSTRING_SIZE);
ast_set_flag(&iaxs[fr->callno]->state, IAX_STATE_STARTED);
ast_verb(3, "Accepting DIAL from %s, formats = %s\n", ast_inet_ntoa(sin.sin_addr), ast_codec2bitstring(iaxs[fr->callno]->peerformat, &str));
- ast_free(str);
ast_set_flag(&iaxs[fr->callno]->state, IAX_STATE_STARTED);
send_command(iaxs[fr->callno], AST_FRAME_CONTROL, AST_CONTROL_PROGRESS, 0, NULL, 0, -1);
if (!(c = ast_iax2_new(fr->callno, AST_STATE_RING, iaxs[fr->callno]->peerformat)))
@@ -9165,9 +9161,9 @@
} else {
/* A mini frame */
f.frametype = AST_FRAME_VOICE;
- if (iaxs[fr->callno]->voiceformat > 0)
- f.subclass = iaxs[fr->callno]->voiceformat;
- else {
+ if (FMT_NZ(iaxs[fr->callno]->voiceformat)) {
+ f.codec = iaxs[fr->callno]->voiceformat;
+ } else {
ast_debug(1, "Received mini frame before first full voice frame\n");
iax2_vnak(fr->callno);
ast_mutex_unlock(&iaxsl[fr->callno]);
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=111813&r1=111812&r2=111813
==============================================================================
--- team/group/codec_bits/channels/chan_mgcp.c (original)
+++ team/group/codec_bits/channels/chan_mgcp.c Fri Mar 28 15:08:08 2008
@@ -1238,9 +1238,8 @@
/* We already hold the channel lock */
if (f->frametype == AST_FRAME_VOICE) {
if (memcmp(&f->codec, &sub->owner->nativeformats, sizeof(f->codec)) != 0) {
- struct ast_str *str = NULL;
+ struct ast_str *str = ast_str_alloca(BITSTRING_SIZE);
ast_debug(1, "Oooh, format changed to %s\n", ast_codec2bitstring(f->codec, &str));
- ast_free(str);
sub->owner->nativeformats = f->codec;
ast_set_read_format(sub->owner, sub->owner->readformat);
ast_set_write_format(sub->owner, sub->owner->writeformat);
@@ -1272,7 +1271,7 @@
{
struct mgcp_subchannel *sub = ast->tech_pvt;
int res = 0;
- struct ast_str *str[4] = { NULL, };
+ struct ast_str *str[4] = { ast_str_alloca(BITSTRING_SIZE), ast_str_alloca(BITSTRING_SIZE), ast_str_alloca(BITSTRING_SIZE), ast_str_alloca(BITSTRING_SIZE) };
if (frame->frametype != AST_FRAME_VOICE) {
if (frame->frametype == AST_FRAME_IMAGE)
return 0;
@@ -1281,13 +1280,9 @@
return 0;
}
} else {
- if (ast_extended_codec_not(ast_extended_codec_and(frame->codec, ast->nativeformats))) {
+ if (FMT_NOT(FMT_AND(frame->codec, ast->nativeformats))) {
ast_log(LOG_WARNING, "Asked to transmit frame type %s, while native formats is %s (read/write = %s/%s)\n",
ast_codec2bitstring(frame->codec, &str[0]), ast_codec2bitstring(ast->nativeformats, &str[1]), ast_codec2bitstring(ast->readformat, &str[2]), ast_codec2bitstring(ast->writeformat, &str[3]));
- ast_free(str[0]);
- ast_free(str[1]);
- ast_free(str[2]);
- ast_free(str[3]);
return -1;
}
}
@@ -1510,7 +1505,7 @@
if (tmp) {
tmp->tech = &mgcp_tech;
tmp->nativeformats = i->capability;
- if (ast_extended_codec_not(tmp->nativeformats))
+ if (FMT_NOT(tmp->nativeformats))
tmp->nativeformats = capability;
fmt = ast_best_codec(tmp->nativeformats);
ast_string_field_build(tmp, name, "MGCP/%s@%s-%d", i->name, i->parent->name, sub->id);
@@ -1941,18 +1936,15 @@
/* Now gather all of the codecs that were asked for: */
ast_rtp_get_current_formats(sub->rtp, &peercapability, &peerNonCodecCapability);
- p->capability = ast_extended_codec_and(capability, peercapability);
+ p->capability = FMT_AND(capability, peercapability);
if (mgcpdebug) {
- struct ast_str *str[3];
+ struct ast_str *str[3] = { ast_str_alloca(BITSTRING_SIZE), ast_str_alloca(BITSTRING_SIZE), ast_str_alloca(BITSTRING_SIZE) };
ast_verbose("Capabilities: us - %s, them - %s, combined - %s\n",
ast_codec2bitstring(capability, &str[0]), ast_codec2bitstring(peercapability, &str[1]), ast_codec2bitstring(p->capability, &str[2]));
- ast_free(str[0]);
- ast_free(str[1]);
- ast_free(str[2]);
ast_verbose("Non-codec capabilities: us - %d, them - %d, combined - %d\n",
nonCodecCapability, peerNonCodecCapability, p->nonCodecCapability);
}
- if (ast_extended_codec_not(p->capability)) {
+ if (FMT_NOT(p->capability)) {
ast_log(LOG_WARNING, "No compatible codecs!\n");
return -1;
}
@@ -2133,7 +2125,7 @@
struct ast_extended_codec audiocodec = { { 0, }, };
audiocodec.audio[x] = (1 << y);
- if (!ast_extended_codec_not(ast_extended_codec_and(p->capability, audiocodec))) {
+ if (FMT_NZ(FMT_AND(p->capability, audiocodec))) {
if (mgcpdebug) {
ast_verbose("Answering with capability %d\n", x);
}
@@ -2190,7 +2182,7 @@
struct mgcp_endpoint *p = sub->parent;
capability = p->capability;
- if (!ast_extended_codec_not(codecs))
+ if (FMT_NZ(codecs))
capability = codecs;
if (ast_strlen_zero(sub->cxident) && rtp) {
/* We don't have a CXident yet, store the destination and
@@ -2203,7 +2195,7 @@
for (y = 0; y <= 32; y++) {
struct ast_extended_codec audiocodec = { { 0, }, };
audiocodec.audio[x] = (1 << y);
- if (!ast_extended_codec_not(ast_extended_codec_and(p->capability, audiocodec))) {
+ 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);
}
@@ -2237,7 +2229,7 @@
for (y = 0; y <= 32; y++) {
struct ast_extended_codec audiocodec = { { 0, }, };
audiocodec.audio[x] = (1 << y);
- if (!ast_extended_codec_not(ast_extended_codec_and(p->capability, audiocodec))) {
+ 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);
}
@@ -3557,13 +3549,12 @@
struct ast_channel *tmpc = NULL;
char tmp[256];
char *dest = data;
- struct ast_str *str = NULL;
+ struct ast_str *str = ast_str_alloca(BITSTRING_SIZE);
oldformat = format;
- format = ast_extended_codec_and(capability, format);
- if (ast_extended_codec_not(format)) {
+ format = FMT_AND(capability, format);
+ if (FMT_NOT(format)) {
ast_log(LOG_NOTICE, "Asked to get a channel of unsupported format '%s'\n", ast_codec2bitstring(oldformat, &str));
- ast_free(str);
return NULL;
}
ast_copy_string(tmp, dest, sizeof(tmp));
@@ -4170,16 +4161,18 @@
}
} else if (!strcasecmp(v->name, "allow")) {
format = ast_getformatbyname(v->value);
- if (ast_extended_codec_not(format))
+ if (FMT_NOT(format)) {
ast_log(LOG_WARNING, "Cannot allow unknown format '%s'\n", v->value);
- else
- capability = ast_extended_codec_or(capability, format);
+ } else {
+ capability = FMT_OR(capability, format);
+ }
} else if (!strcasecmp(v->name, "disallow")) {
format = ast_getformatbyname(v->value);
- if (ast_extended_codec_not(format))
+ if (FMT_NOT(format)) {
ast_log(LOG_WARNING, "Cannot disallow unknown format '%s'\n", v->value);
- else
- capability = ast_extended_codec_and(ast_extended_codec_compl(format), capability);
+ } else {
+ capability = FMT_AND(FMT_COMPL(format), capability);
+ }
} else if (!strcasecmp(v->name, "tos")) {
if (ast_str2tos(v->value, &tos))
ast_log(LOG_WARNING, "Invalid tos value at line %d, refer to QoS documentation\n", v->lineno);
Modified: team/group/codec_bits/channels/chan_oss.c
URL: http://svn.digium.com/view/asterisk/team/group/codec_bits/channels/chan_oss.c?view=diff&rev=111813&r1=111812&r2=111813
==============================================================================
--- team/group/codec_bits/channels/chan_oss.c (original)
+++ team/group/codec_bits/channels/chan_oss.c Fri Mar 28 15:08:08 2008
@@ -850,9 +850,8 @@
return NULL;
}
if (ast_extended_codec_not(ast_extended_codec_and(format, AST_FMT_SLINEAR))) {
- struct ast_str *str = NULL;
+ struct ast_str *str = ast_str_alloca(BITSTRING_SIZE);
ast_log(LOG_NOTICE, "Format %s unsupported\n", ast_codec2bitstring(format, &str));
- ast_free(str);
return NULL;
}
if (o->owner) {
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=111813&r1=111812&r2=111813
==============================================================================
--- team/group/codec_bits/channels/chan_phone.c (original)
+++ team/group/codec_bits/channels/chan_phone.c Fri Mar 28 15:08:08 2008
@@ -436,10 +436,9 @@
if (memcmp(&p->lastinput, &ast->rawreadformat, sizeof(ast->rawreadformat)) != 0) {
p->lastinput = ast->rawreadformat;
if (ioctl(p->fd, PHONE_REC_CODEC, ast->rawreadformat.audio[0])) {
- struct ast_str *str = NULL;
+ struct ast_str *str = ast_str_alloca(BITSTRING_SIZE);
ast_log(LOG_WARNING, "Failed to set codec to %s\n",
ast_codec2bitstring(ast->rawreadformat, &str));
- ast_free(str);
return -1;
}
}
@@ -666,9 +665,8 @@
}
if (ast_extended_codec_not(ast_extended_codec_and(frame->codec, fullformat)) &&
p->mode != MODE_FXS) {
- struct ast_str *str = NULL;
+ struct ast_str *str = ast_str_alloca(BITSTRING_SIZE);
ast_log(LOG_WARNING, "Cannot handle frames in %s format\n", ast_codec2bitstring(frame->codec, &str));
- ast_free(str);
return -1;
}
#if 0
@@ -1253,9 +1251,8 @@
oldformat = format;
format = ast_extended_codec_and(format, normal);
if (ast_extended_codec_not(format)) {
- struct ast_str *str = NULL;
+ struct ast_str *str = ast_str_alloca(BITSTRING_SIZE);
ast_log(LOG_NOTICE, "Asked to get a channel of unsupported format '%s'\n", ast_codec2bitstring(oldformat, &str));
- ast_free(str);
return NULL;
}
}
Modified: team/group/codec_bits/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/group/codec_bits/channels/chan_sip.c?view=diff&rev=111813&r1=111812&r2=111813
==============================================================================
--- team/group/codec_bits/channels/chan_sip.c (original)
+++ team/group/codec_bits/channels/chan_sip.c Fri Mar 28 15:08:08 2008
@@ -4911,7 +4911,7 @@
case AST_FRAME_VOICE:
if (FMT_NOT(FMT_AND(frame->codec, ast->nativeformats))) {
char s1[512], s2[512], s3[512];
- struct ast_str *str1 = ast_str_alloca(128), *str2 = ast_str_alloca(128), *str3 = ast_str_alloca(128), *str4 = ast_str_alloca(128);
+ struct ast_str *str1 = ast_str_alloca(60), *str2 = ast_str_alloca(60), *str3 = ast_str_alloca(60), *str4 = ast_str_alloca(60);
ast_log(LOG_WARNING, "Asked to transmit frame type %s, while native formats is %s(%s) read/write = %s(%s)/%s(%s)\n",
ast_codec2bitstring(frame->codec, &str1),
ast_getformatname_multiple(s1, sizeof(s1) - 1, FMT_AND(ast->nativeformats, AST_FMT_AUDIO_MASK)),
@@ -6676,13 +6676,12 @@
struct ast_codec_pref *pref = ast_rtp_codec_getpref(p->rtp);
int codec_n;
struct ast_extended_codec format;
- struct ast_str *str = NULL;
+ struct ast_str *str = ast_str_alloca(60);
for (codec_n = 0; codec_n < last_rtpmap_codec; codec_n++) {
format = ast_rtp_codec_getformat(found_rtpmap_codecs[codec_n]);
if (FMT_NOT(format)) /* non-codec or not found */
continue;
ast_debug(1, "Setting framing for '%s' to %ld\n", ast_codec2bitstring(format, &str), framing);
- ast_free(str);
ast_codec_pref_setsize(pref, format, framing);
}
ast_rtp_codec_setpref(p->rtp, pref);
@@ -13432,7 +13431,7 @@
for (cur = dialoglist; cur; cur = cur->next) {
if (!strncasecmp(cur->callid, a->argv[3], len)) {
char formatbuf[SIPBUFSIZE/2];
- struct ast_str *str = NULL;
+ struct ast_str *str = ast_str_alloca(60);
ast_cli(a->fd, "\n");
if (cur->subscribed != NONE)
ast_cli(a->fd, " * Subscription (type: %s)\n", subscription_type2str(cur->subscribed));
@@ -13445,7 +13444,6 @@
ast_cli(a->fd, " Non-Codec Capability (DTMF): %d\n", cur->noncodeccapability);
ast_cli(a->fd, " Their Codec Capability: %s\n", ast_codec2bitstring(cur->peercapability, &str));
ast_cli(a->fd, " Joint Codec Capability: %s\n", ast_codec2bitstring(cur->jointcapability, &str));
- ast_free(str);
ast_cli(a->fd, " Format: %s\n", ast_getformatname_multiple(formatbuf, sizeof(formatbuf), cur->owner ? cur->owner->nativeformats : AST_FMT_NULL_MASK) );
ast_cli(a->fd, " T.38 support %s\n", cli_yesno(cur->udptl != NULL));
ast_cli(a->fd, " Video support %s\n", cli_yesno(cur->vrtp != NULL));
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=111813&r1=111812&r2=111813
==============================================================================
--- team/group/codec_bits/channels/chan_skinny.c (original)
+++ team/group/codec_bits/channels/chan_skinny.c Fri Mar 28 15:08:08 2008
@@ -63,10 +63,10 @@
#include "asterisk/utils.h"
#include "asterisk/dsp.h"
#include "asterisk/stringfields.h"
-#include "asterisk/astobj.h"
#include "asterisk/abstract_jb.h"
#include "asterisk/threadstorage.h"
#include "asterisk/devicestate.h"
+#include "asterisk/frame.h"
/*************************************
* Skinny/Asterisk Protocol Settings *
@@ -74,7 +74,7 @@
static const char tdesc[] = "Skinny Client Control Protocol (Skinny)";
static const char config[] = "skinny.conf";
-static int default_capability = AST_FORMAT_ULAW | AST_FORMAT_ALAW;
+static struct ast_extended_codec default_capability = { { AST_FORMAT_AUDIO_ULAW | AST_FORMAT_AUDIO_ALAW, }, };
static struct ast_codec_pref default_prefs;
enum skinny_codecs {
@@ -1174,7 +1174,7 @@
int instance;
int group;
int needdestroy;
- int capability;
+ struct ast_extended_codec capability;
int nonCodecCapability;
int onhooktime;
int msgstate; /* voicemail message state */
@@ -1222,7 +1222,7 @@
int registered;
int lastlineinstance;
int lastcallreference;
- int capability;
+ struct ast_extended_codec capability;
struct sockaddr_in addr;
struct in_addr ourip;
struct skinny_line *lines;
@@ -1252,7 +1252,7 @@
struct skinnysession *next;
} *sessions = NULL;
-static struct ast_channel *skinny_request(const char *type, int format, void *data, int *cause);
+static struct ast_channel *skinny_request(const char *type, struct ast_extended_codec format, void *data, int *cause);
static int skinny_devicestate(void *data);
static int skinny_call(struct ast_channel *ast, char *dest, int timeout);
static int skinny_hangup(struct ast_channel *ast);
@@ -1268,7 +1268,7 @@
static const struct ast_channel_tech skinny_tech = {
.type = "Skinny",
.description = tdesc,
- .capabilities = AST_FORMAT_AUDIO_MASK,
+ .capabilities = AST_FMT_AUDIO_MASK_INIT,
.properties = AST_CHAN_TP_WANTSJITTER | AST_CHAN_TP_CREATESJITTER,
.requester = skinny_request,
.devicestate = skinny_devicestate,
@@ -1572,46 +1572,40 @@
return sd;
}
-static int codec_skinny2ast(enum skinny_codecs skinnycodec)
-{
- switch (skinnycodec) {
- case SKINNY_CODEC_ALAW:
- return AST_FORMAT_ALAW;
- case SKINNY_CODEC_ULAW:
- return AST_FORMAT_ULAW;
- case SKINNY_CODEC_G723_1:
- return AST_FORMAT_G723_1;
- case SKINNY_CODEC_G729A:
- return AST_FORMAT_G729A;
- case SKINNY_CODEC_G726_32:
- return AST_FORMAT_G726_AAL2; /* XXX Is this right? */
- case SKINNY_CODEC_H261:
- return AST_FORMAT_H261;
- case SKINNY_CODEC_H263:
- return AST_FORMAT_H263;
- default:
- return 0;
- }
-}
-
-static int codec_ast2skinny(int astcodec)
-{
- switch (astcodec) {
- case AST_FORMAT_ALAW:
+static struct ast_extended_codec codec_skinny2ast(enum skinny_codecs skinnycodec)
+{
+ struct ast_extended_codec codec = AST_FMT_NULL_MASK;
+ codec.audio[0] =
+ skinnycodec == SKINNY_CODEC_ALAW ? AST_FORMAT_AUDIO_ALAW :
+ skinnycodec == SKINNY_CODEC_ULAW ? AST_FORMAT_AUDIO_ULAW :
+ skinnycodec == SKINNY_CODEC_G723_1 ? AST_FORMAT_AUDIO_G723_1 :
+ skinnycodec == SKINNY_CODEC_G729A ? AST_FORMAT_AUDIO_G729A :
+ skinnycodec == SKINNY_CODEC_G726_32 ? AST_FORMAT_AUDIO_G726_AAL2 : /* XXX Is this right? */
+ 0;
+ codec.video[0] =
+ skinnycodec == SKINNY_CODEC_H261 ? AST_FORMAT_VIDEO_H261 :
+ skinnycodec == SKINNY_CODEC_H263 ? AST_FORMAT_VIDEO_H263 :
+ 0;
+ return codec;
+}
+
+static int codec_ast2skinny(struct ast_extended_codec astcodec)
+{
+ if (astcodec.audio[0] == AST_FORMAT_AUDIO_ALAW) {
return SKINNY_CODEC_ALAW;
- case AST_FORMAT_ULAW:
+ } else if (astcodec.audio[0] == AST_FORMAT_AUDIO_ULAW) {
return SKINNY_CODEC_ULAW;
- case AST_FORMAT_G723_1:
+ } else if (astcodec.audio[0] == AST_FORMAT_AUDIO_G723_1) {
return SKINNY_CODEC_G723_1;
- case AST_FORMAT_G729A:
+ } else if (astcodec.audio[0] == AST_FORMAT_AUDIO_G729A) {
return SKINNY_CODEC_G729A;
- case AST_FORMAT_G726_AAL2: /* XXX Is this right? */
+ } else if (astcodec.audio[0] == AST_FORMAT_AUDIO_G726_AAL2) { /* XXX Is this right? */
return SKINNY_CODEC_G726_32;
- case AST_FORMAT_H261:
+ } else if (astcodec.video[0] == AST_FORMAT_VIDEO_H261) {
return SKINNY_CODEC_H261;
- case AST_FORMAT_H263:
+ } else if (astcodec.video[0] == AST_FORMAT_VIDEO_H263) {
return SKINNY_CODEC_H263;
- default:
+ } else {
return 0;
}
}
@@ -1891,7 +1885,7 @@
if (!(req = req_alloc(sizeof(struct open_receive_channel_message), OPEN_RECEIVE_CHANNEL_MESSAGE)))
return;
- fmt = ast_codec_pref_getsize(&l->prefs, ast_best_codec(l->capability), NULL);
+ fmt = ast_codec_pref_getsize(&l->prefs, ast_best_codec(l->capability));
req->data.openreceivechannel.conferenceId = htolel(sub->callid);
req->data.openreceivechannel.partyId = htolel(sub->callid);
@@ -2297,7 +2291,7 @@
}
-static int skinny_set_rtp_peer(struct ast_channel *c, struct ast_rtp *rtp, struct ast_rtp *vrtp, struct ast_rtp *trtp, int codecs, int nat_active)
+static int skinny_set_rtp_peer(struct ast_channel *c, struct ast_rtp *rtp, struct ast_rtp *vrtp, struct ast_rtp *trtp, struct ast_extended_codec codecs, int nat_active)
{
struct skinny_subchannel *sub;
struct skinny_line *l;
@@ -2322,6 +2316,8 @@
s = d->session;
if (rtp){
+ struct ast_str *str = ast_str_alloca(BITSTRING_SIZE);
+
ast_rtp_get_peer(rtp, &them);
/* Shutdown any early-media or previous media on re-invite */
@@ -2338,10 +2334,9 @@
if (!(req = req_alloc(sizeof(struct start_media_transmission_message), START_MEDIA_TRANSMISSION_MESSAGE)))
return -1;
- fmt = ast_codec_pref_getsize(&l->prefs, ast_best_codec(l->capability), NULL);
-
- if (skinnydebug)
- ast_debug(1, "Setting payloadType to '%d' (%d ms)\n", fmt.bits, fmt.cur_ms);
+ fmt = ast_codec_pref_getsize(&l->prefs, ast_best_codec(l->capability));
+
+ ast_debug(1, "Setting payloadType to '%s' (%d ms)\n", ast_codec2bitstring(fmt.bits, &str), fmt.cur_ms);
req->data.startmedia.conferenceId = htolel(sub->callid);
req->data.startmedia.passThruPartyId = htolel(sub->callid);
@@ -2596,19 +2591,20 @@
/*! \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;
-
- for(x = 0; x < 32 ; x++) {
+ int x;
+ struct ast_extended_codec codec;
+
+ for (x = 0; x < 32 ; x++) {
codec = ast_codec_pref_index(pref, x);
- if (!codec)
+ if (FMT_NOT(codec)) {
break;
- ast_cli(fd, "%s", ast_getformatname(codec));
+ }
+ ast_cli(fd, "%s%s", x > 0 ? "," : ":", ast_getformatname(codec));
ast_cli(fd, ":%d", pref->framing[x]);
- if (x < 31 && ast_codec_pref_index(pref, x + 1))
- ast_cli(fd, ",");
- }
- if (!x)
+ }
+ if (!x) {
ast_cli(fd, "none");
+ }
}
static char *handle_skinny_show_devices(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
@@ -2921,9 +2917,9 @@
} else if (!strcasecmp(v->name, "regexten")) {
ast_copy_string(regexten, v->value, sizeof(regexten));
} else if (!strcasecmp(v->name, "allow")) {
- ast_parse_allow_disallow(&d->prefs, &d->capability, NULL, v->value, 1);
+ ast_parse_allow_disallow(&d->prefs, &d->capability, v->value, 1);
} else if (!strcasecmp(v->name, "disallow")) {
- ast_parse_allow_disallow(&d->prefs, &d->capability, NULL, v->value, 0);
+ ast_parse_allow_disallow(&d->prefs, &d->capability, v->value, 0);
} else if (!strcasecmp(v->name, "version")) {
ast_copy_string(d->version_id, v->value, sizeof(d->version_id));
} else if (!strcasecmp(v->name, "canreinvite")) {
@@ -3423,9 +3419,10 @@
if (ast) {
/* We already hold the channel lock */
if (f->frametype == AST_FRAME_VOICE) {
- if (f->subclass != ast->nativeformats) {
- ast_debug(1, "Oooh, format changed to %d\n", f->subclass);
- ast->nativeformats = f->subclass;
+ if (!FMT_EQ(f->codec, ast->nativeformats)) {
+ struct ast_str *str = ast_str_alloca(BITSTRING_SIZE);
+ ast_debug(1, "Oooh, format changed to %s\n", ast_codec2bitstring(f->codec, &str));
+ ast->nativeformats = f->codec;
ast_set_read_format(ast, ast->readformat);
ast_set_write_format(ast, ast->writeformat);
}
@@ -3448,6 +3445,8 @@
{
struct skinny_subchannel *sub = ast->tech_pvt;
int res = 0;
+ struct ast_str *str[4] = { ast_str_alloca(BITSTRING_SIZE), ast_str_alloca(BITSTRING_SIZE), ast_str_alloca(BITSTRING_SIZE), ast_str_alloca(BITSTRING_SIZE) };
+
if (frame->frametype != AST_FRAME_VOICE) {
if (frame->frametype == AST_FRAME_IMAGE) {
return 0;
@@ -3456,9 +3455,12 @@
return 0;
}
} else {
- if (!(frame->subclass & 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);
+ if (FMT_NOT(FMT_AND(frame->codec, ast->nativeformats))) {
+ ast_log(LOG_WARNING, "Asked to transmit frame type %s, while native formats is %s (read/write = %s/%s)\n",
+ ast_codec2bitstring(frame->codec, &str[0]),
+ ast_codec2bitstring(ast->nativeformats, &str[1]),
+ ast_codec2bitstring(ast->readformat, &str[2]),
+ ast_codec2bitstring(ast->writeformat, &str[3]));
return -1;
}
}
@@ -3667,7 +3669,8 @@
struct skinny_subchannel *sub;
struct skinny_device *d = l->parent;
struct ast_variable *v = NULL;
- int fmt;
+ struct ast_extended_codec fmt;
+ struct ast_str *str1 = ast_str_alloca(BITSTRING_SIZE), *str2 = ast_str_alloca(BITSTRING_SIZE);
tmp = ast_channel_alloc(1, state, l->cid_num, l->cid_name, l->accountcode, l->exten, l->context, l->amaflags, "Skinny/%s@%s-%d", l->name, d->name, callnums);
if (!tmp) {
@@ -3696,11 +3699,11 @@
tmp->tech = &skinny_tech;
tmp->tech_pvt = sub;
tmp->nativeformats = l->capability;
- if (!tmp->nativeformats)
+ if (FMT_NOT(tmp->nativeformats)) {
tmp->nativeformats = default_capability;
+ }
fmt = ast_best_codec(tmp->nativeformats);
- if (skinnydebug)
- ast_debug(1, "skinny_new: tmp->nativeformats=%d fmt=%d\n", tmp->nativeformats, fmt);
+ ast_debug(1, "skinny_new: tmp->nativeformats=%s fmt=%s\n", ast_codec2bitstring(tmp->nativeformats, &str1), ast_codec2bitstring(fmt, &str2));
if (sub->rtp) {
ast_channel_set_fd(tmp, 0, ast_rtp_fd(sub->rtp));
}
@@ -4470,8 +4473,9 @@
struct skinny_device *d = s->device;
struct skinny_line *l;
uint32_t count = 0;
- int codecs = 0;
+ struct ast_extended_codec codecs = { { 0, }, };
int i;
+ struct ast_str *str = ast_str_alloca(BITSTRING_SIZE);
count = letohl(req->data.caps.count);
if (count > SKINNY_MAX_CAPABILITIES) {
@@ -4480,17 +4484,16 @@
}
for (i = 0; i < count; i++) {
- int acodec = 0;
+ struct ast_extended_codec acodec;
int scodec = 0;
scodec = letohl(req->data.caps.caps[i].codec);
acodec = codec_skinny2ast(scodec);
- if (skinnydebug)
- ast_debug(1, "Adding codec capability '%d (%d)'\n", acodec, scodec);
- codecs |= acodec;
- }
-
- d->capability &= codecs;
- ast_verb(0, "Device capability set to '%d'\n", d->capability);
+ ast_debug(1, "Adding codec capability '%s (%d)'\n", ast_codec2bitstring(acodec, &str), scodec);
+ codecs = FMT_OR(codecs, acodec);
+ }
+
+ d->capability = FMT_AND(d->capability, codecs);
+ ast_verb(0, "Device capability set to '%s'\n", ast_codec2bitstring(d->capability, &str));
for (l = d->lines; l; l = l->next) {
ast_mutex_lock(&l->lock);
l->capability = d->capability;
@@ -4775,6 +4778,7 @@
struct ast_format_list fmt;
struct sockaddr_in sin;
struct sockaddr_in us;
+ struct ast_str *str = ast_str_alloca(BITSTRING_SIZE);
uint32_t addr;
int port;
int status;
@@ -4814,10 +4818,10 @@
if (!(req = req_alloc(sizeof(struct start_media_transmission_message), START_MEDIA_TRANSMISSION_MESSAGE)))
return -1;
- fmt = ast_codec_pref_getsize(&l->prefs, ast_best_codec(l->capability), NULL);
+ fmt = ast_codec_pref_getsize(&l->prefs, ast_best_codec(l->capability));
if (skinnydebug)
- ast_debug(1, "Setting payloadType to '%d' (%d ms)\n", fmt.bits, fmt.cur_ms);
+ ast_debug(1, "Setting payloadType to '%s' (%d ms)\n", ast_codec2bitstring(fmt.bits, &str), fmt.cur_ms);
req->data.startmedia.conferenceId = htolel(sub->callid);
req->data.startmedia.passThruPartyId = htolel(sub->callid);
@@ -5706,21 +5710,21 @@
return get_devicestate(l);
}
-static struct ast_channel *skinny_request(const char *type, int format, void *data, int *cause)
-{
- int oldformat;
+static struct ast_channel *skinny_request(const char *type, struct ast_extended_codec format, void *data, int *cause)
+{
+ struct ast_extended_codec oldformat = format;
struct skinny_line *l;
struct ast_channel *tmpc = NULL;
char tmp[256];
char *dest = data;
-
- oldformat = format;
-
- if (!(format &= AST_FORMAT_AUDIO_MASK)) {
- ast_log(LOG_NOTICE, "Asked to get a channel of unsupported format '%d'\n", format);
+ struct ast_str *str = ast_str_alloca(BITSTRING_SIZE);
+
+ if (FMT_NOT(format = FMT_AND(format, AST_FMT_AUDIO_MASK))) {
+ /* XXX Seems strange that we would check, then do nothing with format XXX */
+ ast_log(LOG_NOTICE, "Asked to get a channel of unsupported format '%s'\n", ast_codec2bitstring(oldformat, &str));
return NULL;
- }
+ }
ast_copy_string(tmp, dest, sizeof(tmp));
if (ast_strlen_zero(tmp)) {
@@ -5826,9 +5830,9 @@
if (ast_str2cos(v->value, &cos_video))
ast_log(LOG_WARNING, "Invalid cos_video value at line %d, refer to QoS documentation\n", v->lineno);
} else if (!strcasecmp(v->name, "allow")) {
- ast_parse_allow_disallow(&default_prefs, &default_capability, NULL, v->value, 1);
+ ast_parse_allow_disallow(&default_prefs, &default_capability, v->value, 1);
} else if (!strcasecmp(v->name, "disallow")) {
- ast_parse_allow_disallow(&default_prefs, &default_capability, NULL, v->value, 0);
+ ast_parse_allow_disallow(&default_prefs, &default_capability, v->value, 0);
} else if (!strcasecmp(v->name, "bindport")) {
if (sscanf(v->value, "%d", &ourport) == 1) {
bindaddr.sin_port = htons(ourport);
Modified: team/group/codec_bits/channels/chan_unistim.c
URL: http://svn.digium.com/view/asterisk/team/group/codec_bits/channels/chan_unistim.c?view=diff&rev=111813&r1=111812&r2=111813
==============================================================================
--- team/group/codec_bits/channels/chan_unistim.c (original)
+++ team/group/codec_bits/channels/chan_unistim.c Fri Mar 28 15:08:08 2008
@@ -71,7 +71,8 @@
#include "asterisk/indications.h"
/*! Beware, G729 and G723 are not supported by asterisk, except with the proper licence */
-#define CAPABILITY AST_FORMAT_ALAW | AST_FORMAT_ULAW /* | AST_FORMAT_G729A | AST_FORMAT_G723_1 */
+#define CAPABILITY { { AST_FORMAT_AUDIO_ALAW | AST_FORMAT_AUDIO_ULAW /* | AST_FORMAT_G729A | AST_FORMAT_G723_1 */, }, }
+static const struct ast_extended_codec capability = CAPABILITY;
#define DEFAULTCONTEXT "default"
#define DEFAULTCALLERID "Unknown"
@@ -403,7 +404,7 @@
/*! AMA flags (for billing) */
int amaflags;
/*! Codec supported */
- int capability;
+ struct ast_extended_codec capability;
struct unistim_line *next;
struct unistim_device *parent;
};
@@ -670,8 +671,7 @@
static int unload_module(void);
static int reload_config(void);
static void show_main_page(struct unistimsession *pte);
-static struct ast_channel *unistim_request(const char *type, int format,
- void *data, int *cause);
+static struct ast_channel *unistim_request(const char *type, struct ast_extended_codec format, void *data, int *cause);
static int unistim_call(struct ast_channel *ast, char *dest, int timeout);
static int unistim_hangup(struct ast_channel *ast);
static int unistim_answer(struct ast_channel *ast);
@@ -2026,6 +2026,7 @@
struct sockaddr_in sin;
int codec;
struct sockaddr_in sout;
+ struct ast_str *str[3] = { ast_str_alloca(BITSTRING_SIZE), ast_str_alloca(BITSTRING_SIZE), ast_str_alloca(BITSTRING_SIZE) };
/* Sanity checks */
if (!sub) {
@@ -2074,43 +2075,38 @@
sizeof(sin.sin_addr));
sin.sin_port = htons(sub->parent->parent->rtp_port);
ast_rtp_set_peer(sub->rtp, &sin);
- if (!(sub->owner->nativeformats & sub->owner->readformat)) {
- int fmt;
- fmt = ast_best_codec(sub->owner->nativeformats);
+ if (FMT_NOT(FMT_AND(sub->owner->nativeformats, sub->owner->readformat))) {
+ struct ast_extended_codec fmt = ast_best_codec(sub->owner->nativeformats);
ast_log(LOG_WARNING,
- "Our read/writeformat has been changed to something incompatible : %s (%d), using %s (%d) best codec from %d\n",
- ast_getformatname(sub->owner->readformat),
- sub->owner->readformat, ast_getformatname(fmt), fmt,
- sub->owner->nativeformats);
+ "Our read/writeformat has been changed to something incompatible : %s (%s), using %s (%s) best codec from %s\n",
+ ast_getformatname(sub->owner->readformat), ast_codec2bitstring(sub->owner->readformat, &str[0]),
+ ast_getformatname(fmt), ast_codec2bitstring(fmt, &str[1]),
+ ast_codec2bitstring(sub->owner->nativeformats, &str[2]));
sub->owner->readformat = fmt;
sub->owner->writeformat = fmt;
}
- codec = ast_rtp_lookup_code(sub->rtp, 1, sub->owner->readformat);
+ codec = ast_rtp_lookup_codec(sub->rtp, 1, sub->owner->readformat);
/* Setting up RTP of the phone */
if (public_ip.sin_family == 0) /* NAT IP override ? */
memcpy(&public, &us, sizeof(public)); /* No defined, using IP from recvmsg */
else
memcpy(&public, &public_ip, sizeof(public)); /* override */
- if (unistimdebug) {
- ast_verb(0, "RTP started : Our IP/port is : %s:%hd with codec %s (%d)\n",
- ast_inet_ntoa(us.sin_addr),
- htons(us.sin_port), ast_getformatname(sub->owner->readformat),
- sub->owner->readformat);
- ast_verb(0, "Starting phone RTP stack. Our public IP is %s\n",
- ast_inet_ntoa(public.sin_addr));
- }
- if ((sub->owner->readformat == AST_FORMAT_ULAW) ||
- (sub->owner->readformat == AST_FORMAT_ALAW)) {
- if (unistimdebug)
- ast_verb(0, "Sending packet_send_rtp_packet_size for codec %d\n", codec);
+ ast_debug(1, "RTP started : Our IP/port is : %s:%hd with codec %s (%s)\n",
+ ast_inet_ntoa(us.sin_addr),
+ htons(us.sin_port), ast_getformatname(sub->owner->readformat),
+ ast_codec2bitstring(sub->owner->readformat, &str[0]));
+ ast_debug(1, "Starting phone RTP stack. Our public IP is %s\n",
+ ast_inet_ntoa(public.sin_addr));
+ if ((FMT_EQ(sub->owner->readformat, AST_FMT_ULAW)) ||
+ (FMT_EQ(sub->owner->readformat, AST_FMT_ALAW))) {
+ ast_debug(1, "Sending packet_send_rtp_packet_size for codec %d\n", codec);
memcpy(buffsend + SIZE_HEADER, packet_send_rtp_packet_size,
sizeof(packet_send_rtp_packet_size));
buffsend[10] = codec;
send_client(SIZE_HEADER + sizeof(packet_send_rtp_packet_size), buffsend,
sub->parent->parent->session);
}
- if (unistimdebug)
- ast_verb(0, "Sending Jitter Buffer Parameters Configuration\n");
+ ast_debug(1, "Sending Jitter Buffer Parameters Configuration\n");
memcpy(buffsend + SIZE_HEADER, packet_send_jitter_buffer_conf,
sizeof(packet_send_jitter_buffer_conf));
send_client(SIZE_HEADER + sizeof(packet_send_jitter_buffer_conf), buffsend,
@@ -2118,8 +2114,7 @@
if (sub->parent->parent->rtp_method != 0) {
uint16_t rtcpsin_port = htons(us.sin_port) + 1; /* RTCP port is RTP + 1 */
- if (unistimdebug)
- ast_verb(0, "Sending OpenAudioStreamTX using method #%d\n",
+ ast_debug(1, "Sending OpenAudioStreamTX using method #%d\n",
sub->parent->parent->rtp_method);
if (sub->parent->parent->rtp_method == 3)
memcpy(buffsend + SIZE_HEADER, packet_send_open_audio_stream_tx3,
@@ -2149,8 +2144,7 @@
send_client(SIZE_HEADER + sizeof(packet_send_open_audio_stream_tx), buffsend,
sub->parent->parent->session);
- if (unistimdebug)
- ast_verb(0, "Sending OpenAudioStreamRX\n");
+ ast_debug(1, "Sending OpenAudioStreamRX\n");
if (sub->parent->parent->rtp_method == 3)
memcpy(buffsend + SIZE_HEADER, packet_send_open_audio_stream_rx3,
sizeof(packet_send_open_audio_stream_rx3));
@@ -2181,8 +2175,7 @@
} else {
uint16_t rtcpsin_port = htons(us.sin_port) + 1; /* RTCP port is RTP + 1 */
[... 1107 lines stripped ...]
More information about the asterisk-commits
mailing list