[asterisk-commits] file: branch group/media_formats r408292 - /team/group/media_formats/channels/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Feb 18 06:08:05 CST 2014
Author: file
Date: Tue Feb 18 06:07:59 2014
New Revision: 408292
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=408292
Log:
Move chan_jingle over.
Modified:
team/group/media_formats/channels/chan_jingle.c
Modified: team/group/media_formats/channels/chan_jingle.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/channels/chan_jingle.c?view=diff&rev=408292&r1=408291&r2=408292
==============================================================================
--- team/group/media_formats/channels/chan_jingle.c (original)
+++ team/group/media_formats/channels/chan_jingle.c Tue Feb 18 06:07:59 2014
@@ -80,6 +80,7 @@
#include "asterisk/jabber.h"
#include "asterisk/jingle.h"
#include "asterisk/stasis_channels.h"
+#include "asterisk/format_cache.h"
#define JINGLE_CONFIG "jingle.conf"
@@ -116,7 +117,6 @@
iksrule *ringrule; /*!< Rule for matching RING request */
int initiator; /*!< If we're the initiator */
int alreadygone;
- struct ast_codec_pref prefs;
struct jingle_candidate *theircandidates;
struct jingle_candidate *ourcandidates;
char cid_num[80]; /*!< Caller ID num */
@@ -154,7 +154,6 @@
struct aji_client *connection;
struct aji_buddy *buddy;
struct jingle_pvt *p;
- struct ast_codec_pref prefs;
int amaflags; /*!< AMA Flags */
char user[100];
char context[100];
@@ -237,7 +236,7 @@
static void jingle_member_destroy(struct jingle *obj)
{
- obj->cap = ast_format_cap_destroy(obj->cap);
+ ao2_cleanup(obj->cap);
if (obj->connection) {
ASTOBJ_UNREF(obj->connection, ast_aji_client_destroy);
}
@@ -277,7 +276,7 @@
static void add_codec_to_answer(const struct jingle_pvt *p, struct ast_format *codec, iks *dcodecs)
{
- const char *format = ast_getformatname(codec);
+ const char *format = codec->codec->name;
if (!strcasecmp("ulaw", format)) {
iks *payload_eg711u, *payload_pcmu;
@@ -321,10 +320,8 @@
struct aji_client *c = client->connection;
iks *iq, *jingle, *dcodecs, *payload_red, *payload_audio, *payload_cn;
int x;
- struct ast_format pref_codec;
- struct ast_format_cap *alreadysent = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
-
- if (p->initiator || !alreadysent)
+
+ if (p->initiator)
return 1;
iq = iks_new("iq");
@@ -333,15 +330,11 @@
if (iq && jingle && dcodecs) {
iks_insert_attrib(dcodecs, "xmlns", JINGLE_AUDIO_RTP_NS);
- for (x = 0; x < AST_CODEC_PREF_SIZE; x++) {
- if (!(ast_codec_pref_index(&client->prefs, x, &pref_codec)))
- break;
- if (!(ast_format_cap_iscompatible(client->cap, &pref_codec)))
- continue;
- if ((ast_format_cap_iscompatible(alreadysent, &pref_codec)))
- continue;
- add_codec_to_answer(p, &pref_codec, dcodecs);
- ast_format_cap_add(alreadysent, &pref_codec);
+ for (x = 0; x < ast_format_cap_count(client->cap); x++) {
+ struct ast_format *format = ast_format_cap_get_format(client->cap, x);
+
+ add_codec_to_answer(p, format, dcodecs);
+ ao2_ref(format, -1);
}
payload_red = iks_new("payload-type");
iks_insert_attrib(payload_red, "id", "117");
@@ -378,7 +371,6 @@
iks_delete(jingle);
iks_delete(iq);
}
- alreadysent = ast_format_cap_destroy(alreadysent);
return 1;
}
@@ -430,7 +422,7 @@
{
struct jingle_pvt *p = ast_channel_tech_pvt(chan);
ast_mutex_lock(&p->lock);
- ast_format_cap_copy(result, p->peercap);
+ ast_format_cap_append_by_type(result, p->peercap, AST_MEDIA_TYPE_UNKNOWN);
ast_mutex_unlock(&p->lock);
}
@@ -798,17 +790,16 @@
return NULL;
}
- tmp->cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
- tmp->jointcap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
- tmp->peercap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
+ tmp->cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+ tmp->jointcap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+ tmp->peercap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
if (!tmp->cap || !tmp->jointcap || !tmp->peercap) {
- tmp->cap = ast_format_cap_destroy(tmp->cap);
- tmp->jointcap = ast_format_cap_destroy(tmp->jointcap);
- tmp->peercap = ast_format_cap_destroy(tmp->peercap);
+ ao2_cleanup(tmp->cap);
+ ao2_cleanup(tmp->jointcap);
+ ao2_cleanup(tmp->peercap);
ast_free(tmp);
return NULL;
}
- memcpy(&tmp->prefs, &client->prefs, sizeof(tmp->prefs));
if (sid) {
ast_copy_string(tmp->sid, sid, sizeof(tmp->sid));
@@ -849,10 +840,17 @@
/*! \brief Start new jingle channel */
static struct ast_channel *jingle_new(struct jingle *client, struct jingle_pvt *i, int state, const char *title, const char *linkedid)
{
+ struct ast_format_cap *caps;
struct ast_channel *tmp;
struct ast_format_cap *what; /* SHALLOW COPY DO NOT DESTROY */
- struct ast_format tmpfmt;
+ struct ast_format *tmpfmt;
const char *str;
+
+ caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+ if (!caps) {
+ ast_log(LOG_WARNING, "Unable to allocate Jingle capabilities structure!\n");
+ return NULL;
+ }
if (title)
str = title;
@@ -861,6 +859,7 @@
tmp = ast_channel_alloc(1, state, i->cid_num, i->cid_name, "", "", "", linkedid, 0, "Jingle/%s-%04lx", str, ast_random() & 0xffff);
if (!tmp) {
ast_log(LOG_WARNING, "Unable to allocate Jingle channel structure!\n");
+ ao2_ref(caps, -1);
return NULL;
}
@@ -870,27 +869,22 @@
/* Select our native format based on codec preference until we receive
something from another device to the contrary. */
- if (!ast_format_cap_is_empty(i->jointcap))
+ if (ast_format_cap_count(i->jointcap))
what = i->jointcap;
- else if (!(ast_format_cap_is_empty(i->cap)))
+ else if (ast_format_cap_count(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);
-
- ast_codec_choose(&i->prefs, what, 1, &tmpfmt);
- ast_format_cap_add(ast_channel_nativeformats(tmp), &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(ast_channel_nativeformats(tmp), &tmpfmt);
- }
- }
- ast_format_cap_iter_end(i->jointcap);
+// if (i->rtp)
+// ast_rtp_codecs_packetization_set(ast_rtp_instance_get_codecs(i->rtp), i->rtp, &i->prefs);
+
+ ast_best_codec(what, &tmpfmt);
+ ast_format_cap_add(caps, tmpfmt, 0);
+ ast_format_cap_append_by_type(caps, i->jointcap, AST_MEDIA_TYPE_VIDEO);
+ ast_channel_nativeformats_set(tmp, caps);
+ ao2_ref(caps, -1);
if (i->rtp) {
ast_channel_set_fd(tmp, 0, ast_rtp_instance_fd(i->rtp, 0));
@@ -904,12 +898,11 @@
ast_channel_rings_set(tmp, 1);
ast_channel_adsicpe_set(tmp, AST_ADSI_UNAVAILABLE);
-
- ast_best_codec(ast_channel_nativeformats(tmp), &tmpfmt);
- ast_format_copy(ast_channel_writeformat(tmp), &tmpfmt);
- ast_format_copy(ast_channel_rawwriteformat(tmp), &tmpfmt);
- ast_format_copy(ast_channel_readformat(tmp), &tmpfmt);
- ast_format_copy(ast_channel_rawreadformat(tmp), &tmpfmt);
+ ast_channel_set_writeformat(tmp, tmpfmt);
+ ast_channel_set_rawwriteformat(tmp, tmpfmt);
+ ast_channel_set_readformat(tmp, tmpfmt);
+ ast_channel_set_rawreadformat(tmp, tmpfmt);
+ ao2_ref(tmpfmt, -1);
ast_channel_tech_pvt_set(tmp, i);
ast_channel_callgroup_set(tmp, client->callgroup);
@@ -1020,9 +1013,9 @@
if (p->vrtp)
ast_rtp_instance_destroy(p->vrtp);
jingle_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);
+ ao2_cleanup(p->cap);
+ ao2_cleanup(p->jointcap);
+ ao2_cleanup(p->peercap);
ast_free(p);
}
@@ -1259,10 +1252,19 @@
if (p->owner) {
/* We already hold the channel lock */
if (f->frametype == AST_FRAME_VOICE) {
- if (!(ast_format_cap_iscompatible(ast_channel_nativeformats(p->owner), &f->subclass.format))) {
- ast_debug(1, "Oooh, format changed to %s\n", ast_getformatname(&f->subclass.format));
- ast_format_cap_remove_bytype(ast_channel_nativeformats(p->owner), AST_FORMAT_TYPE_AUDIO);
- ast_format_cap_add(ast_channel_nativeformats(p->owner), &f->subclass.format);
+ if (!(ast_format_cap_iscompatible_format(ast_channel_nativeformats(p->owner), f->subclass.format))) {
+ struct ast_format_cap *caps;
+
+ ast_debug(1, "Oooh, format changed to %s\n", f->subclass.format->codec->name);
+
+ caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+ if (caps) {
+ ast_format_cap_append_by_type(caps, ast_channel_nativeformats(p->owner), AST_MEDIA_TYPE_UNKNOWN);
+ ast_format_cap_remove_bytype(caps, AST_MEDIA_TYPE_AUDIO);
+ ast_format_cap_add(caps, f->subclass.format, 0);
+ ast_channel_nativeformats_set(p->owner, caps);
+ ao2_ref(caps, -1);
+ }
ast_set_read_format(p->owner, ast_channel_readformat(p->owner));
ast_set_write_format(p->owner, ast_channel_writeformat(p->owner));
}
@@ -1296,13 +1298,13 @@
switch (frame->frametype) {
case AST_FRAME_VOICE:
- if (!(ast_format_cap_iscompatible(ast_channel_nativeformats(ast), &frame->subclass.format))) {
+ if (!(ast_format_cap_iscompatible_format(ast_channel_nativeformats(ast), 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.format),
+ frame->subclass.format->codec->name,
ast_getformatname_multiple(buf, sizeof(buf), ast_channel_nativeformats(ast)),
- ast_getformatname(ast_channel_readformat(ast)),
- ast_getformatname(ast_channel_writeformat(ast)));
+ ast_channel_readformat(ast)->codec->name,
+ ast_channel_writeformat(ast)->codec->name);
return 0;
}
if (p) {
@@ -1541,7 +1543,7 @@
}
ast_setstate(ast, AST_STATE_RING);
- ast_format_cap_copy(p->jointcap, p->cap);
+ ast_format_cap_append_by_type(p->jointcap, p->cap, AST_MEDIA_TYPE_UNKNOWN);
if (!p->ringrule) {
ast_copy_string(p->ring, p->parent->connection->mid, sizeof(p->ring));
p->ringrule = iks_filter_add_rule(p->parent->connection->f, jingle_ringing_ack, p,
@@ -1670,8 +1672,8 @@
ast_channel_name(chan),
jid,
resource,
- ast_getformatname(ast_channel_readformat(chan)),
- ast_getformatname(ast_channel_writeformat(chan))
+ ast_channel_readformat(chan)->codec->name,
+ ast_channel_writeformat(chan)->codec->name
);
else
ast_log(LOG_WARNING, "No available channel\n");
@@ -1779,7 +1781,7 @@
*/
static int jingle_create_member(char *label, struct ast_variable *var, int allowguest,
- struct ast_codec_pref prefs, char *context,
+ char *context,
struct jingle *member)
{
struct aji_client *client;
@@ -1791,7 +1793,6 @@
ast_copy_string(member->user, label, sizeof(member->user));
ast_copy_string(member->context, context, sizeof(member->context));
member->allowguest = allowguest;
- member->prefs = prefs;
while (var) {
#if 0
struct jingle_candidate *candidate = NULL;
@@ -1799,9 +1800,9 @@
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->cap, var->value, 0);
+ ast_parse_allow_disallow(member->cap, var->value, 0);
else if (!strcasecmp(var->name, "allow"))
- ast_parse_allow_disallow(&member->prefs, member->cap, var->value, 1);
+ ast_parse_allow_disallow(member->cap, var->value, 1);
else if (!strcasecmp(var->name, "context"))
ast_copy_string(member->context, var->value, sizeof(member->context));
#if 0
@@ -1846,7 +1847,6 @@
struct jingle *member;
struct hostent *hp;
struct ast_hostent ahp;
- struct ast_codec_pref prefs;
struct aji_client_container *clients;
struct jingle_candidate *global_candidates = NULL;
struct ast_flags config_flags = { 0 };
@@ -1869,9 +1869,9 @@
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(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(global_capability, var->value, 1);
else if (!strcasecmp(var->name, "context"))
ast_copy_string(context, var->value, sizeof(context));
else if (!strcasecmp(var->name, "externip"))
@@ -1900,19 +1900,18 @@
member = ast_calloc(1, sizeof(*member));
ASTOBJ_INIT(member);
ASTOBJ_WRLOCK(member);
- member->cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
+ member->cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
if (!strcasecmp(cat, "guest")) {
ast_copy_string(member->name, "guest", sizeof(member->name));
ast_copy_string(member->user, "guest", sizeof(member->user));
ast_copy_string(member->context, context, sizeof(member->context));
member->allowguest = allowguest;
- member->prefs = prefs;
while (var) {
if (!strcasecmp(var->name, "disallow"))
- ast_parse_allow_disallow(&member->prefs, member->cap,
+ ast_parse_allow_disallow(member->cap,
var->value, 0);
else if (!strcasecmp(var->name, "allow"))
- ast_parse_allow_disallow(&member->prefs, member->cap,
+ ast_parse_allow_disallow(member->cap,
var->value, 1);
else if (!strcasecmp(var->name, "context"))
ast_copy_string(member->context, var->value,
@@ -1954,7 +1953,7 @@
}
} else {
ASTOBJ_UNLOCK(member);
- if (jingle_create_member(cat, var, allowguest, prefs, context, member))
+ if (jingle_create_member(cat, var, allowguest, context, member))
ASTOBJ_CONTAINER_LINK(&jingle_list, member);
ASTOBJ_UNREF(member, jingle_member_destroy);
}
@@ -1980,22 +1979,21 @@
{
struct ast_sockaddr ourip_tmp;
struct ast_sockaddr bindaddr_tmp;
- struct ast_format tmpfmt;
char *jabber_loaded = ast_module_helper("", "res_jabber.so", 0, 0, 0, 0);
- if (!(jingle_tech.capabilities = ast_format_cap_alloc(0))) {
+ if (!(jingle_tech.capabilities = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT))) {
return AST_MODULE_LOAD_DECLINE;
}
- ast_format_cap_add_all_by_type(jingle_tech.capabilities, AST_FORMAT_TYPE_AUDIO);
- if (!(global_capability = ast_format_cap_alloc(0))) {
+ ast_format_cap_add_all_by_type(jingle_tech.capabilities, AST_MEDIA_TYPE_AUDIO);
+ if (!(global_capability = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT))) {
return AST_MODULE_LOAD_DECLINE;
}
- 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));
+ ast_format_cap_add(global_capability, ast_format_ulaw, 0);
+ ast_format_cap_add(global_capability, ast_format_gsm, 0);
+ ast_format_cap_add(global_capability, ast_format_alaw, 0);
+ ast_format_cap_add(global_capability, ast_format_h263, 0);
free(jabber_loaded);
if (!jabber_loaded) {
@@ -2078,7 +2076,8 @@
ASTOBJ_CONTAINER_DESTROYALL(&jingle_list, jingle_member_destroy);
ASTOBJ_CONTAINER_DESTROY(&jingle_list);
- global_capability = ast_format_cap_destroy(global_capability);
+ ao2_ref(global_capability, -1);
+ global_capability = NULL;
return 0;
}
More information about the asterisk-commits
mailing list