Index: pjproject/branches/projects/sipit24/pjmedia/src/pjmedia-codec/ipp_codecs.c
===================================================================
--- pjproject/branches/projects/sipit24/pjmedia/src/pjmedia-codec/ipp_codecs.c	(revision 2708)
+++ pjproject/branches/projects/sipit24/pjmedia/src/pjmedia-codec/ipp_codecs.c	(revision 2709)
@@ -235,7 +235,8 @@
 #   if PJMEDIA_HAS_INTEL_IPP_CODEC_AMR
     {1, "AMR",	    PJMEDIA_RTP_PT_AMR,       &USC_GSMAMR_Fxns,  8000, 1, 160, 
-		    5900, 12200, 4, 1, 1, 
+		    7400, 12200, 2, 0, 1, 
 		    &predecode_amr, &parse_amr, &pack_amr
 		    /*, {1, {{{"octet-align", 11}, {"1", 1}}} } */
+		    , {1, {{{"mode-set", 8}, {"1,4,5", 5}}} }
     },
 #   endif
@@ -561,5 +562,12 @@
     /* Check Change Mode Request. */
     if ((setting->amr_nb && cmr <= 7) || (!setting->amr_nb && cmr <= 8)) {
+	struct ipp_codec *ippc = &ipp_codec[codec_data->codec_idx];
+
 	s->enc_mode = cmr;
+	codec_data->info->params.modes.bitrate = s->enc_setting.amr_nb?
+				pjmedia_codec_amrnb_bitrates[s->enc_mode] :
+				pjmedia_codec_amrwb_bitrates[s->enc_mode];
+	ippc->fxns->std.Control(&codec_data->info->params.modes, 
+				codec_data->enc);
     }
 
@@ -1034,5 +1042,5 @@
 
     /* Not sure if VAD affects decoder, just try to be safe */
-    codec_data->info->params.modes.vad = ippc->has_native_vad;
+    //codec_data->info->params.modes.vad = ippc->has_native_vad;
 
     /* Get number of memory blocks needed by the decoder */
@@ -1085,23 +1093,51 @@
 	amr_settings_t *s;
 	pj_uint8_t octet_align = 0;
-	const pj_str_t STR_FMTP_OCTET_ALIGN = {"octet-align", 11};
-
-	/* Check octet-align */
+	pj_int8_t enc_mode = -1;
+
+	/* Check AMR specific attributes */
+
 	for (i = 0; i < attr->setting.dec_fmtp.cnt; ++i) {
+	    /* octet-align, one of the parameters that must have same value 
+	     * in offer & answer (RFC 4867 Section 8.3.1). Just check fmtp
+	     * in the decoder side, since it's value is guaranteed to fulfil 
+	     * above requirement (by SDP negotiator).
+	     */
+	    const pj_str_t STR_FMTP_OCTET_ALIGN = {"octet-align", 11};
+	    
 	    if (pj_stricmp(&attr->setting.dec_fmtp.param[i].name, 
 			   &STR_FMTP_OCTET_ALIGN) == 0)
 	    {
 		octet_align=(pj_uint8_t)
-			    (pj_strtoul(&attr->setting.dec_fmtp.param[i].val));
+			    pj_strtoul(&attr->setting.dec_fmtp.param[i].val);
 		break;
 	    }
 	}
-
+	for (i = 0; i < attr->setting.enc_fmtp.cnt; ++i) {
+	    /* mode-set */
+	    const pj_str_t STR_FMTP_MODE_SET = {"mode-set", 8};
+	    
+	    if (pj_stricmp(&attr->setting.enc_fmtp.param[i].name, 
+			   &STR_FMTP_MODE_SET) == 0)
+	    {
+		pj_int8_t tmp;
+
+		/* Just get the first value. */
+		tmp = (pj_int8_t)
+		      pj_strtoul(&attr->setting.enc_fmtp.param[i].val);
+
+		if ((ippc->pt == PJMEDIA_RTP_PT_AMR && tmp > 0 && tmp < 8) ||
+		    (ippc->pt == PJMEDIA_RTP_PT_AMRWB && tmp > 0 && tmp < 9))
+		{
+		    enc_mode = tmp;
+		    PJ_LOG(4,(THIS_FILE, "Remote specifies AMR mode-set attr, "
+			      "selected: %d", enc_mode));
+		}
+		break;
+	    }
+	}
+
+	/* Initialize AMR specific settings */
 	s = PJ_POOL_ZALLOC_T(pool, amr_settings_t);
 	codec_data->codec_setting = s;
-
-	s->enc_mode = pjmedia_codec_amr_get_mode(ippc->def_bitrate);
-	if (s->enc_mode < 0)
-	    goto on_error;
 
 	s->enc_setting.amr_nb = (pj_uint8_t)(ippc->pt == PJMEDIA_RTP_PT_AMR);
@@ -1109,8 +1145,25 @@
 	s->enc_setting.reorder = PJ_TRUE;
 	s->enc_setting.cmr = 15;
-	
+
 	s->dec_setting.amr_nb = (pj_uint8_t)(ippc->pt == PJMEDIA_RTP_PT_AMR);
 	s->dec_setting.octet_aligned = octet_align;
 	s->dec_setting.reorder = PJ_TRUE;
+
+	s->enc_mode = pjmedia_codec_amr_get_mode(
+				    codec_data->info->params.modes.bitrate);
+	if (s->enc_mode < 0)
+	    goto on_error;
+
+	if (enc_mode != -1) {
+	    s->enc_mode = enc_mode;
+
+	    /* Apply requested encoder bitrate */
+	    codec_data->info->params.modes.bitrate = s->enc_setting.amr_nb?
+				    pjmedia_codec_amrnb_bitrates[s->enc_mode] :
+				    pjmedia_codec_amrwb_bitrates[s->enc_mode];
+	    ippc->fxns->std.Control(&codec_data->info->params.modes, 
+				    codec_data->enc);
+	}  
+
     }
 #endif
