[asterisk-commits] branch oej/codecnegotiation r13620 - in /team/oej/codecnegotiation: ./ apps/ ...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Sun Mar 19 07:59:55 MST 2006


Author: oej
Date: Sun Mar 19 08:59:41 2006
New Revision: 13620

URL: http://svn.digium.com/view/asterisk?rev=13620&view=rev
Log:
Adding patch from issue 4825 - New codec negotiation algorithm

Added:
    team/oej/codecnegotiation/README.codecnegotiation-branch   (with props)
Modified:
    team/oej/codecnegotiation/apps/app_amd.c
    team/oej/codecnegotiation/apps/app_chanspy.c
    team/oej/codecnegotiation/apps/app_dictate.c
    team/oej/codecnegotiation/apps/app_dumpchan.c
    team/oej/codecnegotiation/apps/app_echo.c
    team/oej/codecnegotiation/apps/app_ices.c
    team/oej/codecnegotiation/apps/app_record.c
    team/oej/codecnegotiation/apps/app_talkdetect.c
    team/oej/codecnegotiation/apps/app_test.c
    team/oej/codecnegotiation/apps/app_waitforsilence.c
    team/oej/codecnegotiation/channel.c
    team/oej/codecnegotiation/channels/chan_agent.c
    team/oej/codecnegotiation/channels/chan_features.c
    team/oej/codecnegotiation/channels/chan_h323.c
    team/oej/codecnegotiation/channels/chan_iax2.c
    team/oej/codecnegotiation/channels/chan_mgcp.c
    team/oej/codecnegotiation/channels/chan_sip.c
    team/oej/codecnegotiation/channels/chan_skinny.c
    team/oej/codecnegotiation/include/asterisk/channel.h
    team/oej/codecnegotiation/res/res_features.c

Added: team/oej/codecnegotiation/README.codecnegotiation-branch
URL: http://svn.digium.com/view/asterisk/team/oej/codecnegotiation/README.codecnegotiation-branch?rev=13620&view=auto
==============================================================================
--- team/oej/codecnegotiation/README.codecnegotiation-branch (added)
+++ team/oej/codecnegotiation/README.codecnegotiation-branch Sun Mar 19 08:59:41 2006
@@ -1,0 +1,47 @@
+Codec API changes branch
+========================
+
+Why do we need this?
+---------------------
+
+There are many problems with the existing codec negotiation implementation, many
+people wants to change it. But all has one unresolved problem -- all changes,
+related to codec negotiation, need to modify all channel modules and most
+applications.
+
+This problem exists, because there is no easy and consistend API, that can be
+used for some standard situations, and there are a lot of duplicated code.
+
+What is the main idea of this patches?
+---------------------------------------
+
+I think, that direct access to chan->(raw)(read|write|native)format can be only
+from special functions. Loadable modules don't need to has direct access to
+this variables, only through channel API.
+
+After incorporating this to trunk, we could easily incorporate all patches like
+4824 (codec negotiation)
+
+Changes description
+-------------------
+
+Added functions (all this functions static inline):
+
+ - ast_chan_best_codec(chan) = ast_best_codec(chan->nativecodecs)
+   This need, because in future nativecodecs can be changed from int to struct
+   type;
+ - ast_get_read_format(chan) = chan->readformat
+ - ast_get_write_format(chan) = chan->writeformat
+
+Related changes:
+ - most places, where can be used new functions changed to use it
+
+Contacts
+--------
+
+If you have questions about this patches, or ideas for improvement, write me:
+Denis Smirnov <mithraen at freesource.info>
+
+Discussions are best done on the asterisk-dev mailing list.
+
+Bugs are reported to the bug tracker, issue #4825

Propchange: team/oej/codecnegotiation/README.codecnegotiation-branch
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/oej/codecnegotiation/README.codecnegotiation-branch
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/oej/codecnegotiation/README.codecnegotiation-branch
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: team/oej/codecnegotiation/apps/app_amd.c
URL: http://svn.digium.com/view/asterisk/team/oej/codecnegotiation/apps/app_amd.c?rev=13620&r1=13619&r2=13620&view=diff
==============================================================================
--- team/oej/codecnegotiation/apps/app_amd.c (original)
+++ team/oej/codecnegotiation/apps/app_amd.c Sun Mar 19 08:59:41 2006
@@ -133,7 +133,7 @@
 			     AST_APP_ARG(argSilenceThreshold);
 	);
 
-	ast_verbose(VERBOSE_PREFIX_3 "AMD: %s %s %s (Fmt: %d)\n", chan->name ,chan->cid.cid_ani, chan->cid.cid_rdnis, chan->readformat);
+	ast_verbose(VERBOSE_PREFIX_3 "AMD: %s %s %s (Fmt: %d)\n", chan->name ,chan->cid.cid_ani, chan->cid.cid_rdnis, ast_get_read_format(chan));
 
 	/* Lets parse the arguments. */
 	if (ast_strlen_zero(data)) {
@@ -182,7 +182,7 @@
 				initialSilence, greeting, afterGreetingSilence, totalAnalysisTime,
 				minimumWordLength, betweenWordsSilence, maximumNumberOfWords, silenceThreshold );
 
-	readFormat = chan->readformat;
+	readFormat = ast_get_read_format(chan);
 	res = ast_set_read_format(chan, AST_FORMAT_SLINEAR);
 	if (res < 0 ) {
 		ast_log(LOG_WARNING, "AMD: Channel [%s]. Unable to set to linear mode, giving up\n", chan->name );

Modified: team/oej/codecnegotiation/apps/app_chanspy.c
URL: http://svn.digium.com/view/asterisk/team/oej/codecnegotiation/apps/app_chanspy.c?rev=13620&r1=13619&r2=13620&view=diff
==============================================================================
--- team/oej/codecnegotiation/apps/app_chanspy.c (original)
+++ team/oej/codecnegotiation/apps/app_chanspy.c Sun Mar 19 08:59:41 2006
@@ -387,7 +387,7 @@
 
 	LOCAL_USER_ADD(u);
 
-	oldrf = chan->readformat;
+	oldrf = ast_get_read_format(chan);
 	oldwf = chan->writeformat;
 	if (ast_set_read_format(chan, AST_FORMAT_SLINEAR) < 0) {
 		ast_log(LOG_ERROR, "Could Not Set Read Format.\n");

Modified: team/oej/codecnegotiation/apps/app_dictate.c
URL: http://svn.digium.com/view/asterisk/team/oej/codecnegotiation/apps/app_dictate.c?rev=13620&r1=13619&r2=13620&view=diff
==============================================================================
--- team/oej/codecnegotiation/apps/app_dictate.c (original)
+++ team/oej/codecnegotiation/apps/app_dictate.c Sun Mar 19 08:59:41 2006
@@ -122,7 +122,7 @@
 	if (args.argc > 1 && args.filename) {
 		filename = args.filename;
 	} 
-	oldr = chan->readformat;
+	oldr = ast_get_read_format(chan);
 	if ((res = ast_set_read_format(chan, AST_FORMAT_SLINEAR)) < 0) {
 		ast_log(LOG_WARNING, "Unable to set to linear mode.\n");
 		LOCAL_USER_REMOVE(u);

Modified: team/oej/codecnegotiation/apps/app_dumpchan.c
URL: http://svn.digium.com/view/asterisk/team/oej/codecnegotiation/apps/app_dumpchan.c?rev=13620&r1=13619&r2=13620&view=diff
==============================================================================
--- team/oej/codecnegotiation/apps/app_dumpchan.c (original)
+++ team/oej/codecnegotiation/apps/app_dumpchan.c Sun Mar 19 08:59:41 2006
@@ -114,7 +114,7 @@
 			 c->rings,
 			 c->nativeformats,
 			 c->writeformat,
-			 c->readformat,
+			 ast_get_read_format(c),
 			 c->fds[0], c->fin & 0x7fffffff, (c->fin & 0x80000000) ? " (DEBUGGED)" : "",
 			 c->fout & 0x7fffffff, (c->fout & 0x80000000) ? " (DEBUGGED)" : "", (long)c->whentohangup,
 			 hour,

Modified: team/oej/codecnegotiation/apps/app_echo.c
URL: http://svn.digium.com/view/asterisk/team/oej/codecnegotiation/apps/app_echo.c?rev=13620&r1=13619&r2=13620&view=diff
==============================================================================
--- team/oej/codecnegotiation/apps/app_echo.c (original)
+++ team/oej/codecnegotiation/apps/app_echo.c Sun Mar 19 08:59:41 2006
@@ -63,7 +63,7 @@
 
 	LOCAL_USER_ADD(u);
 
-	format = ast_best_codec(chan->nativeformats);
+	format = ast_channel_best_codec(chan);
 	ast_set_write_format(chan, format);
 	ast_set_read_format(chan, format);
 

Modified: team/oej/codecnegotiation/apps/app_ices.c
URL: http://svn.digium.com/view/asterisk/team/oej/codecnegotiation/apps/app_ices.c?rev=13620&r1=13619&r2=13620&view=diff
==============================================================================
--- team/oej/codecnegotiation/apps/app_ices.c (original)
+++ team/oej/codecnegotiation/apps/app_ices.c Sun Mar 19 08:59:41 2006
@@ -131,7 +131,7 @@
 		return -1;
 	}
 
-	oreadformat = chan->readformat;
+	oreadformat = ast_get_read_format(chan);
 	res = ast_set_read_format(chan, AST_FORMAT_SLINEAR);
 	if (res < 0) {
 		close(fds[0]);

Modified: team/oej/codecnegotiation/apps/app_record.c
URL: http://svn.digium.com/view/asterisk/team/oej/codecnegotiation/apps/app_record.c?rev=13620&r1=13619&r2=13620&view=diff
==============================================================================
--- team/oej/codecnegotiation/apps/app_record.c (original)
+++ team/oej/codecnegotiation/apps/app_record.c Sun Mar 19 08:59:41 2006
@@ -222,7 +222,7 @@
 	/* The end of beep code.  Now the recording starts */
 		
 	if (silence > 0) {
-		rfmt = chan->readformat;
+		rfmt = ast_get_read_format(chan);
 		res = ast_set_read_format(chan, AST_FORMAT_SLINEAR);
 		if (res < 0) {
 			ast_log(LOG_WARNING, "Unable to set to linear mode, giving up\n");

Modified: team/oej/codecnegotiation/apps/app_talkdetect.c
URL: http://svn.digium.com/view/asterisk/team/oej/codecnegotiation/apps/app_talkdetect.c?rev=13620&r1=13619&r2=13620&view=diff
==============================================================================
--- team/oej/codecnegotiation/apps/app_talkdetect.c (original)
+++ team/oej/codecnegotiation/apps/app_talkdetect.c Sun Mar 19 08:59:41 2006
@@ -115,7 +115,7 @@
 		res = ast_answer(chan);
 	}
 	if (!res) {
-		origrformat = chan->readformat;
+		origrformat = ast_get_read_format(chan);
 		if ((res = ast_set_read_format(chan, AST_FORMAT_SLINEAR))) 
 			ast_log(LOG_WARNING, "Unable to set read format to linear!\n");
 	}

Modified: team/oej/codecnegotiation/apps/app_test.c
URL: http://svn.digium.com/view/asterisk/team/oej/codecnegotiation/apps/app_test.c?rev=13620&r1=13619&r2=13620&view=diff
==============================================================================
--- team/oej/codecnegotiation/apps/app_test.c (original)
+++ team/oej/codecnegotiation/apps/app_test.c Sun Mar 19 08:59:41 2006
@@ -76,7 +76,7 @@
 	struct timeval start;
 	struct ast_frame *f;
 	int rformat;
-	rformat = chan->readformat;
+	rformat = ast_get_read_format(chan);
 	if (ast_set_read_format(chan, AST_FORMAT_SLINEAR)) {
 		ast_log(LOG_NOTICE, "Unable to set to linear mode!\n");
 		return -1;

Modified: team/oej/codecnegotiation/apps/app_waitforsilence.c
URL: http://svn.digium.com/view/asterisk/team/oej/codecnegotiation/apps/app_waitforsilence.c?rev=13620&r1=13619&r2=13620&view=diff
==============================================================================
--- team/oej/codecnegotiation/apps/app_waitforsilence.c (original)
+++ team/oej/codecnegotiation/apps/app_waitforsilence.c Sun Mar 19 08:59:41 2006
@@ -76,7 +76,7 @@
 	time_t start, now;
 	time(&start);
 
-	rfmt = chan->readformat; /* Set to linear mode */
+	rfmt = ast_get_read_format(chan); /* Set to linear mode */
 	res = ast_set_read_format(chan, AST_FORMAT_SLINEAR);
 	if (res < 0) {
 		ast_log(LOG_WARNING, "Unable to set to linear mode, giving up\n");

Modified: team/oej/codecnegotiation/channel.c
URL: http://svn.digium.com/view/asterisk/team/oej/codecnegotiation/channel.c?rev=13620&r1=13619&r2=13620&view=diff
==============================================================================
--- team/oej/codecnegotiation/channel.c (original)
+++ team/oej/codecnegotiation/channel.c Sun Mar 19 08:59:41 2006
@@ -2733,12 +2733,12 @@
 	return -1;
 }
 
-int ast_channel_make_compatible(struct ast_channel *chan, struct ast_channel *peer)
+/*! Set up translation from chan to peer */
+static int ast_channel_make_compatible_helper(struct ast_channel *chan, struct ast_channel *peer)
 {
 	int src;
 	int dst;
 
-	/* Set up translation from the chan to the peer */
 	src = chan->nativeformats;
 	dst = peer->nativeformats;
 	if (ast_translator_best_choice(&dst, &src) < 0) {
@@ -2759,28 +2759,24 @@
 		ast_log(LOG_WARNING, "Unable to set write format on channel %s to %d\n", peer->name, dst);
 		return -1;
 	}
-
+	return 0;
+}
+
+int ast_channel_make_compatible(struct ast_channel *chan, struct ast_channel *peer)
+{
+	/* Some callers not check return code, and we must try to set all call legs correctly */
+	int rc = 0; 
+	/* Set up translation from the chan to the peer */
+	if (ast_channel_make_compatible_helper(chan, peer) < 0) {
+	    rc = -1;
+	}
+	
 	/* Set up translation from the peer to the chan */
-	src = peer->nativeformats;
-	dst = chan->nativeformats;
-	if (ast_translator_best_choice(&dst, &src) < 0) {
-		ast_log(LOG_WARNING, "No path to translate from %s(%d) to %s(%d)\n", peer->name, src, chan->name, dst);
-		return -1;
-	}
-	/* if the best path is not 'pass through', then
-	   transcoding is needed; if desired, force transcode path
-	   to use SLINEAR between channels */
-	if ((src != dst) && ast_opt_transcode_via_slin)
-		dst = AST_FORMAT_SLINEAR;
-	if (ast_set_read_format(peer, dst) < 0) {
-		ast_log(LOG_WARNING, "Unable to set read format on channel %s to %d\n", peer->name, dst);
-		return -1;
-	}
-	if (ast_set_write_format(chan, dst) < 0) {
-		ast_log(LOG_WARNING, "Unable to set write format on channel %s to %d\n", chan->name, dst);
-		return -1;
-	}
-	return 0;
+	if (ast_channel_make_compatible_helper(peer, chan) < 0) {
+	    rc = -1;
+	}
+	
+	return rc;
 }
 
 int ast_channel_masquerade(struct ast_channel *original, struct ast_channel *clone)

Modified: team/oej/codecnegotiation/channels/chan_agent.c
URL: http://svn.digium.com/view/asterisk/team/oej/codecnegotiation/channels/chan_agent.c?rev=13620&r1=13619&r2=13620&view=diff
==============================================================================
--- team/oej/codecnegotiation/channels/chan_agent.c (original)
+++ team/oej/codecnegotiation/channels/chan_agent.c Sun Mar 19 08:59:41 2006
@@ -214,11 +214,11 @@
 			ast_log(LOG_DEBUG, "Native formats changing from %d to %d\n", ast->nativeformats, p->chan->nativeformats); \
 			/* Native formats changed, reset things */ \
 			ast->nativeformats = p->chan->nativeformats; \
-			ast_log(LOG_DEBUG, "Resetting read to %d and write to %d\n", ast->readformat, ast->writeformat);\
-			ast_set_read_format(ast, ast->readformat); \
+			ast_log(LOG_DEBUG, "Resetting read to %d and write to %d\n", ast_get_read_format(ast), ast->writeformat);\
+			ast_set_read_format(ast, ast_get_read_format(ast)); \
 			ast_set_write_format(ast, ast->writeformat); \
 		} \
-		if (p->chan->readformat != ast->rawreadformat)  \
+		if (ast_get_read_format(p->chan) != ast->rawreadformat)  \
 			ast_set_read_format(p->chan, ast->rawreadformat); \
 		if (p->chan->writeformat != ast->rawwriteformat) \
 			ast_set_write_format(p->chan, ast->rawwriteformat); \
@@ -661,20 +661,20 @@
 		ast_log( LOG_DEBUG, "Waited for stream, result '%d'\n", res);
 	}
 	if (!res) {
-		res = ast_set_read_format(p->chan, ast_best_codec(p->chan->nativeformats));
+		res = ast_set_read_format(p->chan, ast_channel_best_codec(p->chan));
 		ast_log( LOG_DEBUG, "Set read format, result '%d'\n", res);
 		if (res)
-			ast_log(LOG_WARNING, "Unable to set read format to %s\n", ast_getformatname(ast_best_codec(p->chan->nativeformats)));
+			ast_log(LOG_WARNING, "Unable to set read format to %s\n", ast_getformatname(ast_channel_best_codec(p->chan)));
 	} else {
 		/* Agent hung-up */
 		p->chan = NULL;
 	}
 
 	if (!res) {
-		ast_set_write_format(p->chan, ast_best_codec(p->chan->nativeformats));
+		ast_set_write_format(p->chan, ast_channel_best_codec(p->chan));
 		ast_log( LOG_DEBUG, "Set write format, result '%d'\n", res);
 		if (res)
-			ast_log(LOG_WARNING, "Unable to set write format to %s\n", ast_getformatname(ast_best_codec(p->chan->nativeformats)));
+			ast_log(LOG_WARNING, "Unable to set write format to %s\n", ast_getformatname(ast_channel_best_codec(p->chan)));
 	}
 	if( !res )
 	{
@@ -911,8 +911,8 @@
 			tmp->nativeformats = p->chan->nativeformats;
 			tmp->writeformat = p->chan->writeformat;
 			tmp->rawwriteformat = p->chan->writeformat;
-			tmp->readformat = p->chan->readformat;
-			tmp->rawreadformat = p->chan->readformat;
+			tmp->readformat = ast_get_read_format(p->chan);
+			tmp->rawreadformat = ast_get_read_format(p->chan);
 			ast_string_field_set(tmp, language, p->chan->language);
 			ast_copy_string(tmp->context, p->chan->context, sizeof(tmp->context));
 			ast_copy_string(tmp->exten, p->chan->exten, sizeof(tmp->exten));
@@ -1890,14 +1890,14 @@
 					AST_LIST_LOCK(&agents);
 					ast_mutex_lock(&p->lock);
 					if (!res) {
-						res = ast_set_read_format(chan, ast_best_codec(chan->nativeformats));
+						res = ast_set_read_format(chan, ast_channel_best_codec(chan));
 						if (res)
-							ast_log(LOG_WARNING, "Unable to set read format to %d\n", ast_best_codec(chan->nativeformats));
+							ast_log(LOG_WARNING, "Unable to set read format to %d\n", ast_channel_best_codec(chan));
 					}
 					if (!res) {
-						res = ast_set_write_format(chan, ast_best_codec(chan->nativeformats));
+						res = ast_set_write_format(chan, ast_channel_best_codec(chan));
 						if (res)
-							ast_log(LOG_WARNING, "Unable to set write format to %d\n", ast_best_codec(chan->nativeformats));
+							ast_log(LOG_WARNING, "Unable to set write format to %d\n", ast_channel_best_codec(chan));
 					}
 					/* Check once more just in case */
 					if (p->chan)
@@ -1949,7 +1949,7 @@
 						ast_queue_log("NONE", chan->uniqueid, agent, "AGENTLOGIN", "%s", chan->name);
 						if (option_verbose > 1)
 							ast_verbose(VERBOSE_PREFIX_2 "Agent '%s' logged in (format %s/%s)\n", p->agent,
-								    ast_getformatname(chan->readformat), ast_getformatname(chan->writeformat));
+								    ast_getformatname(ast_get_read_format(chan)), ast_getformatname(chan->writeformat));
 						/* Login this channel and wait for it to
 						   go away */
 						p->chan = chan;

Modified: team/oej/codecnegotiation/channels/chan_features.c
URL: http://svn.digium.com/view/asterisk/team/oej/codecnegotiation/channels/chan_features.c?rev=13620&r1=13619&r2=13620&view=diff
==============================================================================
--- team/oej/codecnegotiation/channels/chan_features.c (original)
+++ team/oej/codecnegotiation/channels/chan_features.c Sun Mar 19 08:59:41 2006
@@ -189,8 +189,8 @@
 			p->subs[index].owner->timingfd = p->subchan->timingfd;
 			p->subs[index].owner->alertpipe[0] = p->subchan->alertpipe[0];
 			p->subs[index].owner->alertpipe[1] = p->subchan->alertpipe[1];
-			if (p->subs[index].owner->nativeformats != p->subchan->readformat) {
-				p->subs[index].owner->nativeformats = p->subchan->readformat;
+			if (p->subs[index].owner->nativeformats != ast_get_read_format(p->subchan)) {
+				p->subs[index].owner->nativeformats = ast_get_read_format(p->subchan);
 				if (p->subs[index].owner->readformat)
 					ast_set_read_format(p->subs[index].owner, p->subs[index].owner->readformat);
 				if (p->subs[index].owner->writeformat)
@@ -475,11 +475,11 @@
 			break;
 	}
 	ast_setstate(tmp, state);
-	tmp->writeformat = p->subchan->writeformat;
+	tmp->writeformat = ast_get_write_format(p->subchan);
 	tmp->rawwriteformat = p->subchan->rawwriteformat;
-	tmp->readformat = p->subchan->readformat;
+	tmp->readformat = ast_get_read_format(p->subchan);
 	tmp->rawreadformat = p->subchan->rawreadformat;
-	tmp->nativeformats = p->subchan->readformat;
+	tmp->nativeformats = ast_get_read_format(p->subchan);
 	tmp->tech_pvt = p;
 	p->subs[index].owner = tmp;
 	if (!p->owner)

Modified: team/oej/codecnegotiation/channels/chan_h323.c
URL: http://svn.digium.com/view/asterisk/team/oej/codecnegotiation/channels/chan_h323.c?rev=13620&r1=13619&r2=13620&view=diff
==============================================================================
--- team/oej/codecnegotiation/channels/chan_h323.c (original)
+++ team/oej/codecnegotiation/channels/chan_h323.c Sun Mar 19 08:59:41 2006
@@ -741,7 +741,7 @@
 			ch->nativeformats = global_options.capability;
 		}
 		pvt->nativeformats = ch->nativeformats;
-		fmt = ast_best_codec(ch->nativeformats);
+		fmt = ast_channel_best_codec(ch);
 		ch->type = type;
 		ch->fds[0] = ast_rtp_fd(pvt->rtp);
 		if (state == AST_STATE_RING) {

Modified: team/oej/codecnegotiation/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/team/oej/codecnegotiation/channels/chan_iax2.c?rev=13620&r1=13619&r2=13620&view=diff
==============================================================================
--- team/oej/codecnegotiation/channels/chan_iax2.c (original)
+++ team/oej/codecnegotiation/channels/chan_iax2.c Sun Mar 19 08:59:41 2006
@@ -6386,8 +6386,8 @@
 	if (chan2m && chan1m) {
 		ast_string_field_build(chan1m, name, "Parking/%s", chan1->name);
 		/* Make formats okay */
-		chan1m->readformat = chan1->readformat;
-		chan1m->writeformat = chan1->writeformat;
+		chan1m->readformat = ast_get_read_format(chan1);
+		chan1m->writeformat = ast_get_write_format(chan1);
 		ast_channel_masquerade(chan1m, chan1);
 		/* Setup the extensions and such */
 		ast_copy_string(chan1m->context, chan1->context, sizeof(chan1m->context));
@@ -6398,8 +6398,8 @@
 		   back the announcement */
 		ast_string_field_build(chan2m, name, "IAXPeer/%s",chan2->name);
 		/* Make formats okay */
-		chan2m->readformat = chan2->readformat;
-		chan2m->writeformat = chan2->writeformat;
+		chan2m->readformat = ast_get_read_format(chan2);
+		chan2m->writeformat = ast_get_write_format(chan2);
 		ast_channel_masquerade(chan2m, chan2);
 		/* Setup the extensions and such */
 		ast_copy_string(chan2m->context, chan2->context, sizeof(chan2m->context));
@@ -8236,8 +8236,7 @@
 			}
 			c->nativeformats = native;
 		}
-		c->readformat = ast_best_codec(c->nativeformats);
-		c->writeformat = c->readformat;
+		c->writeformat = c->readformat = ast_channel_best_codec(c);
 	}
 
 	return c;

Modified: team/oej/codecnegotiation/channels/chan_mgcp.c
URL: http://svn.digium.com/view/asterisk/team/oej/codecnegotiation/channels/chan_mgcp.c?rev=13620&r1=13619&r2=13620&view=diff
==============================================================================
--- team/oej/codecnegotiation/channels/chan_mgcp.c (original)
+++ team/oej/codecnegotiation/channels/chan_mgcp.c Sun Mar 19 08:59:41 2006
@@ -1453,7 +1453,7 @@
 		tmp->nativeformats = i->capability;
 		if (!tmp->nativeformats)
 			tmp->nativeformats = capability;
-		fmt = ast_best_codec(tmp->nativeformats);
+		fmt = ast_channel_best_codec(tmp);
 		ast_string_field_build(tmp, name, "MGCP/%s@%s-%d", i->name, i->parent->name, sub->id);
 		if (sub->rtp)
 			tmp->fds[0] = ast_rtp_fd(sub->rtp);

Modified: team/oej/codecnegotiation/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/oej/codecnegotiation/channels/chan_sip.c?rev=13620&r1=13619&r2=13620&view=diff
==============================================================================
--- team/oej/codecnegotiation/channels/chan_sip.c (original)
+++ team/oej/codecnegotiation/channels/chan_sip.c Sun Mar 19 08:59:41 2006
@@ -2672,8 +2672,13 @@
 	switch (frame->frametype) {
 	case AST_FRAME_VOICE:
 		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);
+			ast_log(LOG_WARNING, "Asked to transmit frame type %s, while native formats is %s (read/write = %s/%s)\n",
+			    ast_getformatname(frame->subclass),
+			    ast_getformatname(ast->nativeformats),
+			    ast_getformatname(ast_get_read_format(ast)),
+			    ast_getformatname(ast_get_write_format(ast)));
+			ast_frame_dump(ast->name, frame, "<<");
+			ast_backtrace();
 			return 0;
 		}
 		if (p) {
@@ -2893,7 +2898,7 @@
 	else
 		what = global_capability;
 	tmp->nativeformats = ast_codec_choose(&i->prefs, what, 1) | (i->jointcapability & AST_FORMAT_VIDEO_MASK);
-	fmt = ast_best_codec(tmp->nativeformats);
+	fmt = ast_channel_best_codec(tmp);
 
 	if (title)
 		ast_string_field_build(tmp, name, "SIP/%s-%04x", title, thread_safe_rand() & 0xffff);
@@ -3117,7 +3122,7 @@
 				if (option_debug)
 					ast_log(LOG_DEBUG, "Oooh, format changed to %d\n", f->subclass);
 				p->owner->nativeformats = (p->owner->nativeformats & AST_FORMAT_VIDEO_MASK) | f->subclass;
-				ast_set_read_format(p->owner, p->owner->readformat);
+				ast_set_read_format(p->owner, ast_get_read_format(p->owner));
 				ast_set_write_format(p->owner, p->owner->writeformat);
 			}
 			if ((ast_test_flag(p, SIP_DTMF) == SIP_DTMF_INBAND) && p->vad) {
@@ -3785,7 +3790,7 @@
 				ast_getformatname_multiple(s1, slen, p->jointcapability),
 				ast_getformatname_multiple(s2, slen, p->owner->nativeformats));
 		p->owner->nativeformats = ast_codec_choose(&p->prefs, p->jointcapability, 1) | (p->capability & vpeercapability);
-		ast_set_read_format(p->owner, p->owner->readformat);
+		ast_set_read_format(p->owner, ast_get_read_format(p->owner));
 		ast_set_write_format(p->owner, p->owner->writeformat);
 	}
 	if ((bridgepeer=ast_bridged_channel(p->owner))) {
@@ -10232,7 +10237,7 @@
 	}
 	ast_string_field_build(chan1m, name, "Parking/%s", chan1->name);
 	/* Make formats okay */
-	chan1m->readformat = chan1->readformat;
+	chan1m->readformat = ast_get_read_format(chan1);
 	chan1m->writeformat = chan1->writeformat;
 	ast_channel_masquerade(chan1m, chan1);
 	/* Setup the extensions and such */
@@ -10244,7 +10249,7 @@
 	   back the announcement */
 	ast_string_field_build(chan2m, name, "SIPPeer/%s",chan2->name);
 	/* Make formats okay */
-	chan2m->readformat = chan2->readformat;
+	chan2m->readformat = ast_get_read_format(chan2);
 	chan2m->writeformat = chan2->writeformat;
 	ast_channel_masquerade(chan2m, chan2);
 	/* Setup the extensions and such */

Modified: team/oej/codecnegotiation/channels/chan_skinny.c
URL: http://svn.digium.com/view/asterisk/team/oej/codecnegotiation/channels/chan_skinny.c?rev=13620&r1=13619&r2=13620&view=diff
==============================================================================
--- team/oej/codecnegotiation/channels/chan_skinny.c (original)
+++ team/oej/codecnegotiation/channels/chan_skinny.c Sun Mar 19 08:59:41 2006
@@ -2261,7 +2261,7 @@
 		tmp->nativeformats = l->capability;
 		if (!tmp->nativeformats)
 			tmp->nativeformats = capability;
-		fmt = ast_best_codec(tmp->nativeformats);
+		fmt = ast_channel_best_codec(tmp);
 		ast_verbose("skinny_new: tmp->nativeformats=%d fmt=%d\n", tmp->nativeformats, fmt);
 		ast_string_field_build(tmp, name, "Skinny/%s@%s-%d", l->name, l->parent->name, sub->callid);
 		if (sub->rtp) {

Modified: team/oej/codecnegotiation/include/asterisk/channel.h
URL: http://svn.digium.com/view/asterisk/team/oej/codecnegotiation/include/asterisk/channel.h?rev=13620&r1=13619&r2=13620&view=diff
==============================================================================
--- team/oej/codecnegotiation/include/asterisk/channel.h (original)
+++ team/oej/codecnegotiation/include/asterisk/channel.h Sun Mar 19 08:59:41 2006
@@ -804,6 +804,29 @@
  */
 int ast_set_read_format(struct ast_channel *chan, int format);
 
+/*! Gets read format from channel chan */
+/*! 
+ * \param chan channel to get info
+ * Get read format for channel
+ * Returns read format
+ */
+static inline int ast_get_read_format(struct ast_channel *chan)
+{
+    return chan->readformat;
+}
+
+/*! Gets write format from channel chan */
+/*! 
+ * \param chan channel to get info
+ * Get write format for channel
+ * Returns write format
+ */
+static inline int ast_get_write_format(struct ast_channel *chan)
+{
+    return chan->writeformat;
+}
+
+
 /*! Sets write format on channel chan */
 /*! 
  * \param chan channel to change
@@ -987,6 +1010,14 @@
 /* Choose the best codec...  Uhhh...   Yah. */
 extern int ast_best_codec(int fmts);
 
+/*! Pick the best codec from channel nativeformats */
+/*!
+ * \param channel channel, from that nativeformats used
+ */
+static inline int ast_channel_best_codec(struct ast_channel *channel)
+{
+	return ast_best_codec(channel->nativeformats);
+}
 
 /*! Checks the value of an option */
 /*! 

Modified: team/oej/codecnegotiation/res/res_features.c
URL: http://svn.digium.com/view/asterisk/team/oej/codecnegotiation/res/res_features.c?rev=13620&r1=13619&r2=13620&view=diff
==============================================================================
--- team/oej/codecnegotiation/res/res_features.c (original)
+++ team/oej/codecnegotiation/res/res_features.c Sun Mar 19 08:59:41 2006
@@ -704,7 +704,7 @@
 		cid_name = transferer->cid.cid_name;
 		if (ast_exists_extension(transferer, transferer_real_context,xferto, 1, cid_num)) {
 			snprintf(dialstr, sizeof(dialstr), "%s@%s/n", xferto, transferer_real_context);
-			newchan = ast_feature_request_and_dial(transferer, "Local", ast_best_codec(transferer->nativeformats), dialstr, 15000, &outstate, cid_num, cid_name);
+			newchan = ast_feature_request_and_dial(transferer, "Local", ast_channel_best_codec(transferer), dialstr, 15000, &outstate, cid_num, cid_name);
 			ast_indicate(transferer, -1);
 			if (newchan) {
 				res = ast_channel_make_compatible(transferer, newchan);



More information about the asterisk-commits mailing list