Index: channel.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channel.c,v
retrieving revision 1.73
diff -u -r1.73 channel.c
--- channel.c	31 Jan 2004 02:50:27 -0000	1.73
+++ channel.c	4 Feb 2004 14:25:15 -0000
@@ -62,7 +62,7 @@
 struct ast_channel *channels = NULL;
 
 /* Protect the channel list (highly unlikely that two things would change
-   it at the same time, but still! */
+   it at the same time, but still!) */
    
 static ast_mutex_t chlock = AST_MUTEX_INITIALIZER;
 
Index: frame.c
===================================================================
RCS file: /usr/cvsroot/asterisk/frame.c,v
retrieving revision 1.23
diff -u -r1.23 frame.c
--- frame.c	8 Jan 2004 16:52:11 -0000	1.23
+++ frame.c	4 Feb 2004 14:25:15 -0000
@@ -24,6 +24,7 @@
 #include <pthread.h>
 #include <stdio.h>
 #include "asterisk.h"
+#include "include/asterisk/rtp.h"
 
 #ifdef TRACE_FRAMES
 static int headers = 0;
@@ -345,106 +346,46 @@
 
 char* ast_getformatname(int format)
 {
-	if (format == AST_FORMAT_G723_1) 
-		return "G723";
-	else if (format == AST_FORMAT_GSM)
-		return "GSM";
-	else if (format == AST_FORMAT_ULAW)
-		return "ULAW";
-	else if (format == AST_FORMAT_ALAW)
-		return "ALAW";
-	else if (format == AST_FORMAT_G726)
-		return "G726";
-	else if (format == AST_FORMAT_SLINEAR)
-		return "SLINR";
-	else if (format == AST_FORMAT_LPC10)
-		return "LPC10";
-	else if (format == AST_FORMAT_ADPCM)
-		return "ADPCM";
-	else if (format == AST_FORMAT_G729A)
-		return "G729A";
-	else if (format == AST_FORMAT_SPEEX)
-		return "SPEEX";
-	else if (format == AST_FORMAT_ILBC)
-		return "ILBC";
-	else if (format == AST_FORMAT_JPEG)
-		return "JPEG";
-	else if (format == AST_FORMAT_PNG)
-		return "PNG";
-	else if (format == AST_FORMAT_H261)
-		return "H261";
-	else if (format == AST_FORMAT_H263)
-		return "H263";
+	char *rv = ast_rtp_lookup_mime_subtype(-1, format);
+	if (!rv[0]) 
 	return "UNKN";
+	return rv;
 }
 
 int ast_getformatbyname(char *name)
 {
+	// non official codec names (for compatibility)
 	if (!strcasecmp(name, "g723.1")) 
 		return AST_FORMAT_G723_1;
-	else if (!strcasecmp(name, "gsm"))
+	if (!strcasecmp(name, "gsm"))
 		return AST_FORMAT_GSM;
-	else if (!strcasecmp(name, "ulaw"))
+	if (!strcasecmp(name, "ulaw"))
 		return AST_FORMAT_ULAW;
-	else if (!strcasecmp(name, "alaw"))
+	if (!strcasecmp(name, "alaw"))
 		return AST_FORMAT_ALAW;
-	else if (!strcasecmp(name, "g726"))
+	if (!strcasecmp(name, "g726"))
 		return AST_FORMAT_G726;
-	else if (!strcasecmp(name, "slinear"))
+	if (!strcasecmp(name, "slinear"))
 		return AST_FORMAT_SLINEAR;
-	else if (!strcasecmp(name, "lpc10"))
+	if (!strcasecmp(name, "lpc10"))
 		return AST_FORMAT_LPC10;
-	else if (!strcasecmp(name, "adpcm"))
+	if (!strcasecmp(name, "adpcm"))
 		return AST_FORMAT_ADPCM;
-	else if (!strcasecmp(name, "g729"))
+	if (!strcasecmp(name, "g729"))
 		return AST_FORMAT_G729A;
-	else if (!strcasecmp(name, "speex"))
+	if (!strcasecmp(name, "speex"))
 		return AST_FORMAT_SPEEX;
-	else if (!strcasecmp(name, "ilbc"))
+	if (!strcasecmp(name, "ilbc"))
 		return AST_FORMAT_ILBC;
-	else if (!strcasecmp(name, "h261"))
+	if (!strcasecmp(name, "h261"))
 		return AST_FORMAT_H261;
-	else if (!strcasecmp(name, "h263"))
+	if (!strcasecmp(name, "h263"))
 		return AST_FORMAT_H263;
-	else if (!strcasecmp(name, "all"))
+	if (!strcasecmp(name, "all"))
 		return 0x7FFFFFFF;
-	return 0;
-}
 
-char *ast_codec2str(int codec) {
-	static char codecs[25][30] = {
-		/* Audio formats */
-		"G.723.1",                    /*  0 */
-		"GSM",                        /*  1 */
-		"G.711 u-law",                /*  2 */
-		"G.711 A-law",                /*  3 */
-		"MPEG-2 layer 3",             /*  4 */
-		"ADPCM",                      /*  5 */
-		"16 bit Signed Linear PCM",   /*  6 */
-		"LPC10",                      /*  7 */
-		"G.729A audio",               /*  8 */
-		"SpeeX",                      /*  9 */
-		"iLBC",                       /* 10 */
-		"undefined",                  /* 11 */
-		"undefined",                  /* 12 */
-		"undefined",                  /* 13 */
-		"undefined",                  /* 14 */
-		"Maximum audio format",       /* 15 */
-        /* Image formats */
-		"JPEG image",                 /* 16 */
-		"PNG image",                  /* 17 */
-		"H.261 Video",                /* 18 */
-		"H.263 Video",                /* 19 */
-		"undefined",                  /* 20 */
-		"undefined",                  /* 21 */
-		"undefined",                  /* 22 */
-		"undefined",                  /* 23 */
-        "Maximum video format",       /* 24 */
-		};
-	if ((codec >= 0) && (codec <= 24))
-		return codecs[codec];
-	else
-		return "unknown";
+	// official codec names according to the IANA.
+	return ast_rtp_get_mime_subtype_code(name);
 }
 
 static int show_codecs(int fd, int argc, char *argv[])
@@ -461,19 +402,19 @@
 	if ((argc == 2) || (!strcasecmp(argv[1],"audio"))) {
 		found = 1;
 		for (i=0;i<11;i++)
-			ast_cli(fd, "%11u (1 << %2d)  %s\n",1 << i,i,ast_codec2str(i));
+			ast_cli(fd, "%11u (1 << %2d) audio %s\n",1 << i,i,ast_getformatname(1 << i));
 	}
 
 	if ((argc == 2) || (!strcasecmp(argv[1],"image"))) {
 		found = 1;
 		for (i=16;i<18;i++)
-			ast_cli(fd, "%11u (1 << %2d)  %s\n",1 << i,i,ast_codec2str(i));
+			ast_cli(fd, "%11u (1 << %2d) image %s\n",1 << i,i,ast_getformatname(1 << i));
 	}
 
 	if ((argc == 2) || (!strcasecmp(argv[1],"video"))) {
 		found = 1;
 		for (i=18;i<20;i++)
-			ast_cli(fd, "%11u (1 << %2d)  %s\n",1 << i,i,ast_codec2str(i));
+			ast_cli(fd, "%11u (1 << %2d) video %s\n",1 << i,i,ast_getformatname(1 << i));
 	}
 
 	if (! found)
@@ -508,7 +449,7 @@
 	for (i=0;i<32;i++)
 		if (codec & (1 << i)) {
 			found = 1;
-			ast_cli(fd, "%11u (1 << %2d)  %s\n",1 << i,i,ast_codec2str(i));
+			ast_cli(fd, "%11u (1 << %2d)  %s\n",1 << i,i,ast_getformatname(1 << i));
 		}
 
 	if (! found)
Index: rtp.c
===================================================================
RCS file: /usr/cvsroot/asterisk/rtp.c,v
retrieving revision 1.47
diff -u -r1.47 rtp.c
--- rtp.c	25 Nov 2003 21:15:28 -0000	1.47
+++ rtp.c	4 Feb 2004 14:25:17 -0000
@@ -500,6 +500,7 @@
 
 // The following array defines the MIME type (and subtype) for each
 // of our codecs, or RTP-specific data type.
+// see http://www.iana.org/assignments/rtp-parameters
 static struct {
   struct rtpPayloadType payloadType;
   char* type;
@@ -659,14 +660,19 @@
 
 char* ast_rtp_lookup_mime_subtype(int isAstFormat, int code) {
   int i;
-
-  for (i = 0; i < sizeof mimeTypes/sizeof mimeTypes[0]; ++i) {
+	for (i = 0; i < sizeof mimeTypes/sizeof mimeTypes[0]; ++i)
     if (mimeTypes[i].payloadType.code == code &&
-	mimeTypes[i].payloadType.isAstFormat == isAstFormat) {
+				(isAstFormat<0 || mimeTypes[i].payloadType.isAstFormat == isAstFormat))
       return mimeTypes[i].subtype;
-    }
-  }
   return "";
+}
+
+int ast_rtp_get_mime_subtype_code(const char *subtype) {
+	int i;
+	for (i = 0; i < sizeof mimeTypes/sizeof mimeTypes[0]; ++i)
+		if (!strcmp(subtype, mimeTypes[i].subtype))
+		   	return mimeTypes[i].payloadType.code;
+	return 0;
 }
 
 static struct ast_rtcp *ast_rtcp_new(void)
Index: channels/chan_phone.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_phone.c,v
retrieving revision 1.22
diff -u -r1.22 chan_phone.c
--- channels/chan_phone.c	9 Dec 2003 23:55:17 -0000	1.22
+++ channels/chan_phone.c	4 Feb 2004 14:25:18 -0000
@@ -1162,13 +1162,10 @@
 		} else if (!strcasecmp(v->name, "context")) {
 			strncpy(context, v->value, sizeof(context)-1);
 		} else if (!strcasecmp(v->name, "format")) {
-			if (!strcasecmp(v->value, "g723.1")) {
-				prefformat = AST_FORMAT_G723_1;
-			} else if (!strcasecmp(v->value, "slinear")) {
-				prefformat = AST_FORMAT_SLINEAR;
-			} else if (!strcasecmp(v->value, "ulaw")) {
-				prefformat = AST_FORMAT_ULAW;
-			} else
+			int format = ast_getformatbyname(v->value);
+			if (format & (AST_FORMAT_G723_1 | AST_FORMAT_SLINEAR | AST_FORMAT_ULAW))
+				prefformat = format;
+			else
 				ast_log(LOG_WARNING, "Unknown format '%s'\n", v->value);
 		} else if (!strcasecmp(v->name, "echocancel")) {
 			if (!strcasecmp(v->value, "off")) {
Index: include/asterisk/frame.h
===================================================================
RCS file: /usr/cvsroot/asterisk/include/asterisk/frame.h,v
retrieving revision 1.27
diff -u -r1.27 frame.h
--- include/asterisk/frame.h	4 Nov 2003 02:40:09 -0000	1.27
+++ include/asterisk/frame.h	4 Feb 2004 14:25:27 -0000
@@ -327,14 +327,6 @@
  */
 extern int ast_getformatbyname(char *name);
 
-//! Get a name from a format
-/*!
- * \param codec codec number (1,2,4,8,16,etc.)
- * Gets a name from a format
- * This returns a static string identifying the format on success, 0 on error.
- */
-extern char *ast_codec2str(int codec);
-
 //! Pick the best codec 
 /* Choose the best codec...  Uhhh...   Yah. */
 extern int ast_best_codec(int fmts);
Index: include/asterisk/rtp.h
===================================================================
RCS file: /usr/cvsroot/asterisk/include/asterisk/rtp.h,v
retrieving revision 1.13
diff -u -r1.13 rtp.h
--- include/asterisk/rtp.h	15 Nov 2003 00:52:49 -0000	1.13
+++ include/asterisk/rtp.h	4 Feb 2004 14:25:27 -0000
@@ -91,8 +91,15 @@
 void ast_rtp_get_current_formats(struct ast_rtp* rtp,
 			     int* astFormats, int* nonAstFormats);
 
-// Mapping an Asterisk code into a MIME subtype (string):
+//! Mapping an Asterisk code into a MIME subtype (string):
 char* ast_rtp_lookup_mime_subtype(int isAstFormat, int code);
+
+//! Mapping a MIME subtype (string) to an Asterisk code
+/*!
+ * \param subtype a string containing the mime type (G723, GSM, PCMU, PCMA, G726-32, L16, LPC, G729, SPEEX, iLBC,...)
+ * \return a format constant as defined in frame.h
+ */
+int ast_rtp_get_mime_subtype_code(const char *subtype);
 
 void ast_rtp_setnat(struct ast_rtp *rtp, int nat);
 
