Index: pjproject/branches/projects/aps-direct/pjmedia/include/pjmedia/port.h
===================================================================
--- pjproject/branches/projects/aps-direct/pjmedia/include/pjmedia/port.h	(revision 2438)
+++ pjproject/branches/projects/aps-direct/pjmedia/include/pjmedia/port.h	(revision 2439)
@@ -382,5 +382,5 @@
     move_src = (pj_uint8_t*)pjmedia_frame_ext_get_subframe(frm, n);
     sf = pjmedia_frame_ext_get_subframe(frm, frm->subframe_cnt-1);
-    move_len = (pj_uint8_t*)sf - move_src + sf->bitlen/8;
+    move_len = (pj_uint8_t*)sf - move_src + sizeof(sf->bitlen) + sf->bitlen/8;
     if (sf->bitlen % 8 != 0)
 	++move_len;
Index: pjproject/branches/projects/aps-direct/pjmedia/src/pjmedia/symbian_sound_aps.cpp
===================================================================
--- pjproject/branches/projects/aps-direct/pjmedia/src/pjmedia/symbian_sound_aps.cpp	(revision 2438)
+++ pjproject/branches/projects/aps-direct/pjmedia/src/pjmedia/symbian_sound_aps.cpp	(revision 2439)
@@ -759,45 +759,62 @@
 
     switch(strm->setting.format.u32) {
-    
     case PJMEDIA_FOURCC_G711U:
     case PJMEDIA_FOURCC_G711A:
-	/* Add header. */
-	buf.iBuffer.Append(1);
-	buf.iBuffer.Append(0);
-
-	/* Assume frame size is 10ms if frame size hasn't been known. */
-	if (g711_frame_len == 0)
-	    g711_frame_len = 80;
-	
-	/* Call parent stream callback to get samples to play. */
-	while (samples_ready < g711_frame_len) {
-	    if (frame->samples_cnt == 0) {
-		frame->base.type = PJMEDIA_FRAME_TYPE_EXTENDED;
-		strm->play_cb(strm->user_data, 0, strm->play_buf,
-			      strm->samples_per_frame<<1);
+	{
+	    /* Add header. */
+	    buf.iBuffer.Append(1);
+	    buf.iBuffer.Append(0);
+    
+	    /* Assume frame size is 10ms if frame size hasn't been known. */
+	    if (g711_frame_len == 0)
+		g711_frame_len = 80;
+	    
+	    /* Call parent stream callback to get samples to play. */
+	    while (samples_ready < g711_frame_len) {
+		if (frame->samples_cnt == 0) {
+		    frame->base.type = PJMEDIA_FRAME_TYPE_EXTENDED;
+		    strm->play_cb(strm->user_data, 0, strm->play_buf,
+				  strm->samples_per_frame<<1);
+		    
+		    pj_assert(frame->base.type==PJMEDIA_FRAME_TYPE_EXTENDED ||
+			      frame->base.type==PJMEDIA_FRAME_TYPE_NONE);
+		}
+    
+		if (frame->base.type == PJMEDIA_FRAME_TYPE_EXTENDED) { 
+		    pjmedia_frame_ext_subframe *sf;
+		    unsigned samples_cnt;
+		    
+		    sf = pjmedia_frame_ext_get_subframe(frame, 0);
+		    samples_cnt = frame->samples_cnt / frame->subframe_cnt;
+		    if (sf->data && sf->bitlen)
+			buf.iBuffer.Append((TUint8*)sf->data, sf->bitlen>>3);
+		    else {
+			pj_uint8_t silence_code;
+			
+			if (strm->setting.format.u32 == PJMEDIA_FOURCC_G711U)
+			    silence_code = pjmedia_linear2ulaw(0);
+			else
+			    silence_code = pjmedia_linear2alaw(0);
+			
+			buf.iBuffer.AppendFill(silence_code, samples_cnt);
+		    }
+		    samples_ready += samples_cnt;
+		    
+		    pjmedia_frame_ext_pop_subframes(frame, 1);
 		
-		pj_assert(frame->base.type == PJMEDIA_FRAME_TYPE_EXTENDED ||
-			  frame->base.type == PJMEDIA_FRAME_TYPE_NONE);
-	    }
-
-	    if (frame->base.type == PJMEDIA_FRAME_TYPE_EXTENDED) { 
-		pjmedia_frame_ext_subframe *sf;
-		unsigned samples_cnt;
-		
-		sf = pjmedia_frame_ext_get_subframe(frame, 0);
-		samples_cnt = frame->samples_cnt / frame->subframe_cnt;
-		if (sf->data && sf->bitlen)
-		    buf.iBuffer.Append((TUint8*)sf->data, sf->bitlen>>3);
-		else 
-		    buf.iBuffer.AppendFill(0, samples_cnt);
-		samples_ready += samples_cnt;
-		
-		pjmedia_frame_ext_pop_subframes(frame, 1);
-	    
-	    } else { /* PJMEDIA_FRAME_TYPE_NONE */
-		buf.iBuffer.AppendFill(0, g711_frame_len - samples_ready);
-		samples_ready = g711_frame_len;
-		frame->samples_cnt = 0;
-		frame->subframe_cnt = 0;
+		} else { /* PJMEDIA_FRAME_TYPE_NONE */
+		    pj_uint8_t silence_code;
+		    
+		    if (strm->setting.format.u32 == PJMEDIA_FOURCC_G711U)
+			silence_code = pjmedia_linear2ulaw(0);
+		    else
+			silence_code = pjmedia_linear2alaw(0);
+		    
+		    buf.iBuffer.AppendFill(silence_code, 
+					   g711_frame_len - samples_ready);
+		    samples_ready = g711_frame_len;
+		    frame->samples_cnt = 0;
+		    frame->subframe_cnt = 0;
+		}
 	    }
 	}
@@ -807,6 +824,4 @@
 	break;
     }
-    
-    unsigned tes = buf.iBuffer.Length();
 }
 
Index: pjproject/branches/projects/aps-direct/pjsip-apps/src/symbian_ua/ua.cpp
===================================================================
--- pjproject/branches/projects/aps-direct/pjsip-apps/src/symbian_ua/ua.cpp	(revision 2438)
+++ pjproject/branches/projects/aps-direct/pjsip-apps/src/symbian_ua/ua.cpp	(revision 2439)
@@ -281,13 +281,4 @@
 	return;
 
-    /* Don't need to reopen sound device when the session doesn't use
-     * PCM format. 
-     */
-    if (strm_info->param->info.format.u32 == 0 ||
-	strm_info->param->info.format.u32 == PJMEDIA_FOURCC_L16) 
-    {
-	return;
-    }
-    
     pj_bzero(&setting, sizeof(setting));
     setting.format = strm_info->param->info.format;
@@ -878,9 +869,9 @@
 #endif
 	
-    // Let pjsua destroys app pool, since the pool may still be used by app
-    // until pjsua_destroy() finished.
-    // e.g: quitting app when there is an active call may cause sound port 
-    // memory destroyed before sound port itself gets closed/destroyed.
-    /*
+    if (snd_port) {
+	pjmedia_snd_port_destroy(snd_port);
+	snd_port = NULL;
+    }
+
     // Release application pool
     if (app_pool) {
@@ -888,5 +879,4 @@
 	app_pool = NULL;
     }
-    */
     
     // Shutdown pjsua
