[asterisk-commits] dvossel: branch dvossel/fixtheworld_phase1_step3 r300715 - in /team/dvossel/f...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Jan 5 21:06:39 UTC 2011
Author: dvossel
Date: Wed Jan 5 15:06:35 2011
New Revision: 300715
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=300715
Log:
All the remaining changes required to update channel.c for the ast_format conversion
Modified:
team/dvossel/fixtheworld_phase1_step3/include/asterisk/format_cap.h
team/dvossel/fixtheworld_phase1_step3/main/channel.c
team/dvossel/fixtheworld_phase1_step3/main/format_cap.c
Modified: team/dvossel/fixtheworld_phase1_step3/include/asterisk/format_cap.h
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/include/asterisk/format_cap.h?view=diff&rev=300715&r1=300714&r2=300715
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/include/asterisk/format_cap.h (original)
+++ team/dvossel/fixtheworld_phase1_step3/include/asterisk/format_cap.h Wed Jan 5 15:06:35 2011
@@ -107,6 +107,14 @@
int ast_cap_iscompatible(struct ast_cap *cap, struct ast_format *format);
/*!
+ * \brief is cap1 identical to cap2
+ *
+ * retval 1 true, identical
+ * retval 0 false, not identical
+ */
+int ast_cap_identical(struct ast_cap *cap1, struct ast_cap *cap2);
+
+/*!
* \brief Get joint capability structure.
*
* \retval !NULL success
@@ -118,10 +126,10 @@
* \brief Find out if capability structures have any joint capabilities without
* returning those capabilities.
*
- * \retval 1 success
- * \retval 0 failure
+ * \retval 1 true, has joint capabilities
+ * \retval 0 false, failure
*/
-struct ast_cap *ast_cap_has_joint(struct ast_cap *cap1, struct ast_cap *cap2);
+int ast_cap_has_joint(struct ast_cap *cap1, struct ast_cap *cap2);
/*!
* \brief Get all capabilities for a specific media type
Modified: team/dvossel/fixtheworld_phase1_step3/main/channel.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/main/channel.c?view=diff&rev=300715&r1=300714&r2=300715
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/main/channel.c (original)
+++ team/dvossel/fixtheworld_phase1_step3/main/channel.c Wed Jan 5 15:06:35 2011
@@ -6292,8 +6292,7 @@
*/
int ast_do_masquerade(struct ast_channel *original)
{
- format_t x;
- int i;
+ int x, i;
int res=0;
int origstate;
int visible_indication;
@@ -6311,12 +6310,16 @@
struct ast_cdr *cdr;
struct ast_datastore *xfer_ds;
struct xfer_masquerade_ds *xfer_colp;
- format_t rformat = original->readformat;
- format_t wformat = original->writeformat;
+ struct ast_format rformat;
+ struct ast_format wformat;
+ struct ast_format tmp_format;
char newn[AST_CHANNEL_NAME];
char orig[AST_CHANNEL_NAME];
char masqn[AST_CHANNEL_NAME];
char zombn[AST_CHANNEL_NAME];
+
+ ast_format_copy(&original->readformat, &rformat);
+ ast_format_copy(&original->writeformat, &wformat);
/* XXX This operation is a bit odd. We're essentially putting the guts of
* the clone channel into the original channel. Start by killing off the
@@ -6476,12 +6479,13 @@
}
/* Swap the raw formats */
- x = original->rawreadformat;
- original->rawreadformat = clonechan->rawreadformat;
- clonechan->rawreadformat = x;
- x = original->rawwriteformat;
- original->rawwriteformat = clonechan->rawwriteformat;
- clonechan->rawwriteformat = x;
+ ast_format_copy(&original->rawreadformat, &tmp_format);
+ ast_format_copy(&clonechan->rawreadformat, &original->rawreadformat);
+ ast_format_copy(&tmp_format, &clonechan->rawreadformat);
+
+ ast_format_copy(&original->rawwriteformat, &tmp_format);
+ ast_format_copy(&clonechan->rawwriteformat, &original->rawwriteformat);
+ ast_format_copy(&tmp_format, &clonechan->rawwriteformat);
clonechan->_softhangup = AST_SOFTHANGUP_DEV;
@@ -6585,10 +6589,10 @@
/* pvt switches. pbx stays the same, as does next */
/* Set the write format */
- ast_set_write_format(original, wformat);
+ ast_set_write_format(original, &wformat);
/* Set the read format */
- ast_set_read_format(original, rformat);
+ ast_set_read_format(original, &rformat);
/* Copy the music class */
ast_string_field_set(original, musicclass, clonechan->musicclass);
@@ -6602,7 +6606,7 @@
}
ast_debug(1, "Putting channel %s in %s/%s formats\n", original->name,
- ast_getformatname(wformat), ast_getformatname(rformat));
+ ast_getformatname(&wformat), ast_getformatname(&rformat));
/* Okay. Last thing is to let the channel driver know about all this mess, so he
can fix up everything as best as possible */
@@ -6846,8 +6850,8 @@
struct ast_channel *cs[3];
struct ast_frame *f;
enum ast_bridge_result res = AST_BRIDGE_COMPLETE;
- format_t o0nativeformats;
- format_t o1nativeformats;
+ struct ast_cap *o0nativeformats;
+ struct ast_cap *o1nativeformats;
int watch_c0_dtmf;
int watch_c1_dtmf;
void *pvt0, *pvt1;
@@ -6855,13 +6859,20 @@
int frame_put_in_jb = 0;
int jb_in_use;
int to;
-
+
+ o0nativeformats = ast_cap_copy(c0->nativeformats);
+ o1nativeformats = ast_cap_copy(c1->nativeformats);
+
+ if (!o0nativeformats || !o1nativeformats) {
+ ast_cap_destroy(o0nativeformats); /* NULL safe */
+ ast_cap_destroy(o1nativeformats); /* NULL safe */
+ return AST_BRIDGE_FAILED;
+ }
+
cs[0] = c0;
cs[1] = c1;
pvt0 = c0->tech_pvt;
pvt1 = c1->tech_pvt;
- o0nativeformats = c0->nativeformats;
- o1nativeformats = c1->nativeformats;
watch_c0_dtmf = config->flags & AST_BRIDGE_DTMF_CHANNEL_0;
watch_c1_dtmf = config->flags & AST_BRIDGE_DTMF_CHANNEL_1;
@@ -6883,8 +6894,8 @@
struct ast_channel *who, *other;
if ((c0->tech_pvt != pvt0) || (c1->tech_pvt != pvt1) ||
- (o0nativeformats != c0->nativeformats) ||
- (o1nativeformats != c1->nativeformats)) {
+ (!ast_cap_identical(o0nativeformats, c0->nativeformats)) ||
+ (!ast_cap_identical(o1nativeformats, c1->nativeformats))) {
/* Check for Masquerade, codec changes, etc */
res = AST_BRIDGE_RETRY;
break;
@@ -7034,6 +7045,9 @@
ast_poll_channel_del(c0, c1);
+ ast_cap_destroy(o0nativeformats);
+ ast_cap_destroy(o1nativeformats);
+
return res;
}
@@ -7143,8 +7157,8 @@
{
struct ast_channel *chans[2] = { c0, c1 };
enum ast_bridge_result res = AST_BRIDGE_COMPLETE;
- format_t o0nativeformats;
- format_t o1nativeformats;
+ struct ast_cap *o0nativeformats;
+ struct ast_cap *o1nativeformats;
long time_left_ms=0;
char caller_warning = 0;
char callee_warning = 0;
@@ -7165,6 +7179,16 @@
ast_test_flag(c1, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c1))
return -1;
+ o0nativeformats = ast_cap_copy(c0->nativeformats);
+ o1nativeformats = ast_cap_copy(c1->nativeformats);
+ if (!o0nativeformats || !o0nativeformats) {
+ ast_cap_destroy(o0nativeformats);
+ ast_cap_destroy(o0nativeformats);
+ ast_log(LOG_WARNING, "failed to copy native formats\n");
+ return -1;
+ }
+
+
*fo = NULL;
if (ast_tvzero(config->start_time)) {
@@ -7184,9 +7208,6 @@
c1->_bridge = c0;
ast_set_owners_and_peers(c0, c1);
-
- o0nativeformats = c0->nativeformats;
- o1nativeformats = c1->nativeformats;
if (config->feature_timer && !ast_tvzero(config->nexteventts)) {
config->nexteventts = ast_tvadd(config->feature_start_time, ast_samp2tv(config->feature_timer, 1000));
@@ -7338,6 +7359,8 @@
c0->_bridge = NULL;
c1->_bridge = NULL;
+ ast_cap_destroy(o0nativeformats);
+ ast_cap_destroy(o0nativeformats);
return res;
} else {
ast_clear_flag(c0, AST_FLAG_NBRIDGE);
@@ -7357,16 +7380,23 @@
}
}
- if (((c0->writeformat != c1->readformat) || (c0->readformat != c1->writeformat) ||
- (c0->nativeformats != o0nativeformats) || (c1->nativeformats != o1nativeformats)) &&
+ if (((ast_format_cmp(&c0->writeformat, &c1->readformat) == AST_FORMAT_CMP_NOT_EQUAL) ||
+ (ast_format_cmp(&c0->readformat, &c1->writeformat) == AST_FORMAT_CMP_NOT_EQUAL) ||
+ !ast_cap_identical(c0->nativeformats, o0nativeformats) ||
+ !ast_cap_identical(c1->nativeformats, o1nativeformats)) &&
!(c0->generator || c1->generator)) {
if (ast_channel_make_compatible(c0, c1)) {
ast_log(LOG_WARNING, "Can't make %s and %s compatible\n", c0->name, c1->name);
manager_bridge_event(0, 1, c0, c1);
+ ast_cap_destroy(o0nativeformats);
+ ast_cap_destroy(o0nativeformats);
return AST_BRIDGE_FAILED;
}
- o0nativeformats = c0->nativeformats;
- o1nativeformats = c1->nativeformats;
+
+ ast_cap_remove_all(o0nativeformats);
+ ast_cap_remove_all(o0nativeformats);
+ ast_cap_append(c0->nativeformats, o0nativeformats);
+ ast_cap_append(c1->nativeformats, o1nativeformats);
}
update_bridge_vars(c0, c1);
@@ -7403,6 +7433,8 @@
S_COR(c1->caller.id.number.valid, c1->caller.id.number.str, "<unknown>"));
ast_debug(1, "Bridge stops bridging channels %s and %s\n", c0->name, c1->name);
+ ast_cap_destroy(o0nativeformats);
+ ast_cap_destroy(o0nativeformats);
return res;
}
@@ -7449,7 +7481,7 @@
int v1_2;
int v2_2;
int v3_2;
- format_t origwfmt;
+ struct ast_format origwfmt;
int pos;
int duration;
int modulate;
@@ -7463,7 +7495,7 @@
struct tonepair_state *ts = params;
if (chan)
- ast_set_write_format(chan, ts->origwfmt);
+ ast_set_write_format(chan, &ts->origwfmt);
ast_free(ts);
}
@@ -7474,8 +7506,8 @@
if (!(ts = ast_calloc(1, sizeof(*ts))))
return NULL;
- ts->origwfmt = chan->writeformat;
- if (ast_set_write_format(chan, AST_FORMAT_SLINEAR)) {
+ ast_format_copy(&chan->writeformat, &ts->origwfmt);
+ if (ast_set_write_format_by_id(chan, AST_FORMAT_SLINEAR)) {
ast_log(LOG_WARNING, "Unable to set '%s' to signed linear format (write)\n", chan->name);
tonepair_release(NULL, ts);
ts = NULL;
@@ -7529,7 +7561,7 @@
ts->data[x] = ts->v3_1 + ts->v3_2;
}
ts->f.frametype = AST_FRAME_VOICE;
- ts->f.subclass.codec = AST_FORMAT_SLINEAR;
+ ast_format_set(&ts->f.subclass.format, AST_FORMAT_SLINEAR, 0);
ts->f.datalen = len;
ts->f.samples = samples;
ts->f.offset = AST_FRIENDLY_OFFSET;
@@ -7871,11 +7903,11 @@
short buf[samples];
struct ast_frame frame = {
.frametype = AST_FRAME_VOICE,
- .subclass.codec = AST_FORMAT_SLINEAR,
.data.ptr = buf,
.samples = samples,
.datalen = sizeof(buf),
};
+ ast_format_set(&frame.subclass.format, AST_FORMAT_SLINEAR, 0);
memset(buf, 0, sizeof(buf));
@@ -7892,7 +7924,7 @@
};
struct ast_silence_generator {
- int old_write_format;
+ struct ast_format old_write_format;
};
struct ast_silence_generator *ast_channel_start_silence_generator(struct ast_channel *chan)
@@ -7903,9 +7935,9 @@
return NULL;
}
- state->old_write_format = chan->writeformat;
-
- if (ast_set_write_format(chan, AST_FORMAT_SLINEAR) < 0) {
+ ast_format_copy(&chan->writeformat, &state->old_write_format);
+
+ if (ast_set_write_format_by_id(chan, AST_FORMAT_SLINEAR) < 0) {
ast_log(LOG_ERROR, "Could not set write format to SLINEAR\n");
ast_free(state);
return NULL;
@@ -7927,7 +7959,7 @@
ast_debug(1, "Stopped silence generator on '%s'\n", chan->name);
- if (ast_set_write_format(chan, state->old_write_format) < 0)
+ if (ast_set_write_format(chan, &state->old_write_format) < 0)
ast_log(LOG_ERROR, "Could not return write format to its original state\n");
ast_free(state);
Modified: team/dvossel/fixtheworld_phase1_step3/main/format_cap.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/main/format_cap.c?view=diff&rev=300715&r1=300714&r2=300715
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/main/format_cap.c (original)
+++ team/dvossel/fixtheworld_phase1_step3/main/format_cap.c Wed Jan 5 15:06:35 2011
@@ -261,7 +261,7 @@
return 0;
}
-struct ast_cap *ast_cap_has_joint(struct ast_cap *cap1, struct ast_cap *cap2)
+int ast_cap_has_joint(struct ast_cap *cap1, struct ast_cap *cap2)
{
struct ao2_iterator it;
struct ast_format *tmp;
@@ -283,6 +283,29 @@
return data->joint_found ? 1 : 0;
}
+int ast_cap_identical(struct ast_cap *cap1, struct ast_cap *cap2)
+{
+ struct ao2_iterator it;
+ struct ast_format *tmp;
+
+ if (ao2_count(ca1->formats) != ao2_count(cap2->formats)) {
+ return 0; /* if they are not the same size, they are not identical */
+ }
+
+ it = ao2_iterator_init(cap1->formats, 0);
+ while ((tmp = ao2_iterator_next(&it))) {
+ if (!ast_cap_iscompatible(cap, &tmp)) {
+ ao2_ref(tmp, -1);
+ ao2_iterator_destroy(&it);
+ return 0;
+ }
+ ao2_ref(tmp, -1);
+ }
+ ao2_iterator_destroy(&it);
+
+ return 1;
+}
+
struct ast_cap *ast_cap_joint(struct ast_cap *cap1, struct ast_cap *cap2)
{
struct ao2_iterator it;
More information about the asterisk-commits
mailing list