Index: channels/chan_sip.c
===================================================================
--- channels/chan_sip.c	(revision 114319)
+++ channels/chan_sip.c	(working copy)
@@ -740,6 +740,8 @@
 static int global_min_se;                     /*!< Lowest threshold for session refresh interval  */
 static int global_max_se;                     /*!< Highest threshold for session refresh interval */
 
+static int global_preferred_only = 0;	      /*!< Should the preferred codec only be answered? */
+
 /*@}*/ 
 
 /*! \name Object counters @{
@@ -1247,6 +1249,7 @@
 	int jointcapability;			/*!< Supported capability at both ends (codecs) */
 	int peercapability;			/*!< Supported peer capability */
 	int prefcodec;				/*!< Preferred codec (outbound only) */
+	int peer_preferred_pt;
 	int noncodeccapability;			/*!< DTMF RFC2833 telephony-event */
 	int jointnoncodeccapability;            /*!< Joint Non codec capability */
 	int redircodecs;			/*!< Redirect codecs */
@@ -5517,6 +5520,9 @@
 	if (i->prefcodec)
 		ast_debug(3, "*** Our preferred formats from the incoming channel are %s \n", ast_getformatname_multiple(buf, SIPBUFSIZE, i->prefcodec));
 
+	if (global_preferred_only && i->peer_preferred_pt != -1) {
+		tmp->nativeformats = ast_rtp_pt2code(i->rtp, i->peer_preferred_pt);
+	}
 	/* XXX Why are we choosing a codec from the native formats?? */
 	fmt = ast_best_codec(tmp->nativeformats);
 
@@ -5980,6 +5986,7 @@
 	p->session_modify = TRUE;
 	p->stimer = NULL;
 	p->prefs = default_prefs;		/* Set default codecs for this call */
+	p->peer_preferred_pt = -1;
 
 	if (intended_method != SIP_OPTIONS) {	/* Peerpoke has it's own system */
 		p->timer_t1 = global_t1;	/* Default SIP retransmission timer T1 (RFC 3261) */
@@ -6754,6 +6761,8 @@
 				}
 				if (debug)
 					ast_verbose("Found RTP audio format %d\n", codec);
+				if (global_preferred_only && p->peer_preferred_pt == -1)
+					p->peer_preferred_pt = codec;
 				ast_rtp_set_m_type(newaudiortp, codec);
 			}
 		} else if ((sscanf(m, "video %d/%d RTP/AVP %n", &x, &numberofports, &len) == 2) ||
@@ -8416,6 +8425,13 @@
 	else
 		hold = "a=sendrecv\r\n";
 
+	if (global_preferred_only && p->peer_preferred_pt != -1) {
+		int codec = ast_rtp_pt2code(p->rtp, p->peer_preferred_pt);
+		add_codec_to_sdp(p, codec, SDP_SAMPLE_RATE(codec),
+				 &m_audio, &a_audio,
+				 debug, &min_audio_packet_size);
+		capability &= AST_FORMAT_VIDEO_MASK;
+	}
 	/* Now, start adding audio codecs. These are added in this order:
 		- First what was requested by the calling channel
 		- Then preferences in order from sip.conf device config for this peer/user
@@ -21475,6 +21491,8 @@
 			allow_external_domains = ast_true(v->value);
 		} else if (!strcasecmp(v->name, "autodomain")) {
 			auto_sip_domains = ast_true(v->value);
+		} else if (!strcasecmp(v->name, "preferred_codec_only")) {
+			global_preferred_only = ast_true(v->value);
 		} else if (!strcasecmp(v->name, "domain")) {
 			char *domain = ast_strdupa(v->value);
 			char *context = strchr(domain, ',');
Index: include/asterisk/rtp.h
===================================================================
--- include/asterisk/rtp.h	(revision 114319)
+++ include/asterisk/rtp.h	(working copy)
@@ -194,6 +194,7 @@
 /*! \brief  Mapping between RTP payload format codes and Asterisk codes: */
 struct rtpPayloadType ast_rtp_lookup_pt(struct ast_rtp* rtp, int pt);
 int ast_rtp_lookup_code(struct ast_rtp* rtp, int isAstFormat, int code);
+int ast_rtp_pt2code(struct ast_rtp *rtp, int pt);
 
 void ast_rtp_get_current_formats(struct ast_rtp* rtp,
 			     int* astFormats, int* nonAstFormats);
Index: main/rtp.c
===================================================================
--- main/rtp.c	(revision 114319)
+++ main/rtp.c	(working copy)
@@ -2061,6 +2061,11 @@
 	return result;
 }
 
+/*! \brief Looks up an codec out of payload type. */
+int ast_rtp_pt2code(struct ast_rtp* rtp, int pt) {
+	return ast_rtp_lookup_pt(rtp, pt).code;
+}
+
 /*! \brief Looks up an RTP code out of our *static* outbound list */
 int ast_rtp_lookup_code(struct ast_rtp* rtp, const int isAstFormat, const int code)
 {
Index: configs/sip.conf.sample
===================================================================
--- configs/sip.conf.sample	(revision 114319)
+++ configs/sip.conf.sample	(working copy)
@@ -652,6 +652,8 @@
 ; jblog = no                  ; Enables jitterbuffer frame logging. Defaults to "no".
 ;-----------------------------------------------------------------------------------
 
+;preferred_codec_only = no    ; Should the preferred codec only be answered?
+
 [authentication]
 ; Global credentials for outbound calls, i.e. when a proxy challenges your
 ; Asterisk server for authentication. These credentials override
