Index: pjproject/branches/projects/2.0-dev/pjsip/src/pjsua-lib/pjsua_media.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjsip/src/pjsua-lib/pjsua_media.c	(revision 3609)
+++ pjproject/branches/projects/2.0-dev/pjsip/src/pjsua-lib/pjsua_media.c	(revision 3629)
@@ -1836,4 +1836,6 @@
 
 
+void stop_video_stream(pjsua_call_media *call_med);
+
 static void stop_media_session(pjsua_call_id call_id)
 {
@@ -1881,38 +1883,5 @@
 #if PJMEDIA_HAS_VIDEO
 	else if (call_med->type == PJMEDIA_TYPE_VIDEO) {
-	    pjmedia_vid_stream *strm = call_med->strm.v.stream;
-
-	    if (strm) {
-		pjmedia_rtcp_stat stat;
-
-		if (call_med->strm.v.capturer) {
-		    pjmedia_vid_port_stop(call_med->strm.v.capturer);
-		    pjmedia_vid_port_destroy(call_med->strm.v.capturer);
-		    call_med->strm.v.capturer = NULL;
-		}
-
-		if (call_med->strm.v.renderer) {
-		    pjmedia_vid_port_stop(call_med->strm.v.renderer);
-		    pjmedia_vid_port_destroy(call_med->strm.v.renderer);
-		    call_med->strm.v.renderer = NULL;
-		}
-
-		if ((call_med->dir & PJMEDIA_DIR_ENCODING) &&
-		    (pjmedia_vid_stream_get_stat(strm, &stat) == PJ_SUCCESS))
-		{
-		    /* Save RTP timestamp & sequence, so when media session is
-		     * restarted, those values will be restored as the initial
-		     * RTP timestamp & sequence of the new media session. So in
-		     * the same call session, RTP timestamp and sequence are
-		     * guaranteed to be contigue.
-		     */
-		    call_med->rtp_tx_seq_ts_set = 1 | (1 << 1);
-		    call_med->rtp_tx_seq = stat.rtp_tx_last_seq;
-		    call_med->rtp_tx_ts = stat.rtp_tx_last_ts;
-		}
-
-		pjmedia_vid_stream_destroy(strm);
-		call_med->strm.v.stream = NULL;
-	    }
+	    stop_video_stream(call_med);
 	}
 #endif
@@ -2183,254 +2152,8 @@
 
 
-#if PJMEDIA_HAS_VIDEO
-
-static pj_status_t video_channel_update(pjsua_call_media *call_med,
-                                        pj_pool_t *tmp_pool,
-				        const pjmedia_sdp_session *local_sdp,
-				        const pjmedia_sdp_session *remote_sdp)
-{
-    pjsua_call *call = call_med->call;
-    pjmedia_vid_stream_info the_si, *si = &the_si;
-    pjmedia_port *media_port;
-    unsigned strm_idx = call_med->idx;
-    pj_status_t status;
-    
-    status = pjmedia_vid_stream_info_from_sdp(si, tmp_pool, pjsua_var.med_endpt,
-					      local_sdp, remote_sdp, strm_idx);
-    if (status != PJ_SUCCESS)
-	return status;
-
-    /* Check if no media is active */
-    if (si->dir == PJMEDIA_DIR_NONE) {
-	/* Call media state */
-	call_med->state = PJSUA_CALL_MEDIA_NONE;
-
-	/* Call media direction */
-	call_med->dir = PJMEDIA_DIR_NONE;
-
-    } else {
-	pjmedia_transport_info tp_info;
-
-	/* Start/restart media transport */
-	status = pjmedia_transport_media_start(call_med->tp,
-					       tmp_pool, local_sdp,
-					       remote_sdp, strm_idx);
-	if (status != PJ_SUCCESS)
-	    return status;
-
-	call_med->tp_st = PJSUA_MED_TP_RUNNING;
-
-	/* Get remote SRTP usage policy */
-	pjmedia_transport_info_init(&tp_info);
-	pjmedia_transport_get_info(call_med->tp, &tp_info);
-	if (tp_info.specific_info_cnt > 0) {
-	    unsigned i;
-	    for (i = 0; i < tp_info.specific_info_cnt; ++i) {
-		if (tp_info.spc_info[i].type == PJMEDIA_TRANSPORT_TYPE_SRTP) 
-		{
-		    pjmedia_srtp_info *srtp_info = 
-				(pjmedia_srtp_info*) tp_info.spc_info[i].buffer;
-
-		    call_med->rem_srtp_use = srtp_info->peer_use;
-		    break;
-		}
-	    }
-	}
-
-	/* Optionally, application may modify other stream settings here
-	 * (such as jitter buffer parameters, codec ptime, etc.)
-	 */
-	si->jb_init = pjsua_var.media_cfg.jb_init;
-	si->jb_min_pre = pjsua_var.media_cfg.jb_min_pre;
-	si->jb_max_pre = pjsua_var.media_cfg.jb_max_pre;
-	si->jb_max = pjsua_var.media_cfg.jb_max;
-
-	/* Set SSRC */
-	si->ssrc = call_med->ssrc;
-
-	/* Set RTP timestamp & sequence, normally these value are intialized
-	 * automatically when stream session created, but for some cases (e.g:
-	 * call reinvite, call update) timestamp and sequence need to be kept
-	 * contigue.
-	 */
-	si->rtp_ts = call_med->rtp_tx_ts;
-	si->rtp_seq = call_med->rtp_tx_seq;
-	si->rtp_seq_ts_set = call_med->rtp_tx_seq_ts_set;
-
-#if defined(PJMEDIA_STREAM_ENABLE_KA) && PJMEDIA_STREAM_ENABLE_KA!=0
-	/* Enable/disable stream keep-alive and NAT hole punch. */
-	si->use_ka = pjsua_var.acc[call->acc_id].cfg.use_stream_ka;
-#endif
-
-	/* Try to get shared format ID between the capture device and 
-	 * the encoder to avoid format conversion in the capture device.
-	 */
-	if (si->dir & PJMEDIA_DIR_ENCODING) {
-	    pjmedia_vid_dev_info dev_info;
-	    pjmedia_vid_codec_info *codec_info = &si->codec_info;
-	    unsigned i, j;
-
-	    status = pjmedia_vid_dev_get_info(pjsua_var.vcap_dev, &dev_info);
-	    if (status != PJ_SUCCESS)
-		return status;
-
-	    /* Find matched format ID */
-	    for (i = 0; i < codec_info->dec_fmt_id_cnt; ++i) {
-		for (j = 0; j < dev_info.fmt_cnt; ++j) {
-		    if (codec_info->dec_fmt_id[i] == 
-			(pjmedia_format_id)dev_info.fmt[j].id)
-		    {
-			/* Apply the matched format ID to the codec */
-			si->codec_param->dec_fmt.id = codec_info->dec_fmt_id[i];
-			/* Force outer loop to break */
-			i = codec_info->dec_fmt_id_cnt;
-			break;
-		    }
-		}
-	    }
-	}
-
-	/* Create session based on session info. */
-	status = pjmedia_vid_stream_create(pjsua_var.med_endpt, NULL, si,
-					   call_med->tp, NULL,
-					   &call_med->strm.v.stream);
-	if (status != PJ_SUCCESS)
-	    return status;
-
-	/* Start stream */
-	status = pjmedia_vid_stream_start(call_med->strm.v.stream);
-	if (status != PJ_SUCCESS)
-	    return status;
-
-	/* Setup decoding direction */
-	if (si->dir & PJMEDIA_DIR_DECODING) {
-	    pjmedia_vid_port_param vport_param;
-
-	    status = pjmedia_vid_stream_get_port(call_med->strm.v.stream,
-						 PJMEDIA_DIR_DECODING,
-						 &media_port);
-	    if (status != PJ_SUCCESS)
-		return status;
-
-	    status = pjmedia_vid_dev_default_param(
-				tmp_pool, pjsua_var.vrdr_dev,
-				&vport_param.vidparam);
-	    if (status != PJ_SUCCESS)
-		return status;
-
-	    pjmedia_format_copy(&vport_param.vidparam.fmt,
-				&media_port->info.fmt);
-
-	    vport_param.vidparam.dir = PJMEDIA_DIR_RENDER;
-	    vport_param.active = PJ_TRUE;
-
-	    /* Create video renderer */
-	    status = pjmedia_vid_port_create(tmp_pool, &vport_param, 
-					     &call_med->strm.v.renderer);
-	    if (status != PJ_SUCCESS)
-		return status;
-
-	    /* Connect the video renderer to media_port */
-	    status = pjmedia_vid_port_connect(call_med->strm.v.renderer,
-					      media_port, PJ_FALSE);
-	    if (status != PJ_SUCCESS)
-		return status;
-
-	    /* Start the video renderer */
-	    status = pjmedia_vid_port_start(call_med->strm.v.renderer);
-	    if (status != PJ_SUCCESS)
-		return status;
-	}
-
-	/* Setup encoding direction */
-	if (si->dir & PJMEDIA_DIR_ENCODING && !call->local_hold) {
-	    pjmedia_vid_port_param vport_param;
-
-	    status = pjmedia_vid_stream_get_port(call_med->strm.v.stream,
-						 PJMEDIA_DIR_ENCODING,
-						 &media_port);
-	    if (status != PJ_SUCCESS)
-		return status;
-
-	    status = pjmedia_vid_dev_default_param(
-				tmp_pool, pjsua_var.vcap_dev,
-				&vport_param.vidparam);
-	    if (status != PJ_SUCCESS)
-		return status;
-
-	    pjmedia_format_copy(&vport_param.vidparam.fmt,
-				&media_port->info.fmt);
-	    vport_param.vidparam.dir = PJMEDIA_DIR_CAPTURE;
-	    vport_param.active = PJ_TRUE;
-
-	    /* Create video capturer */
-	    status = pjmedia_vid_port_create(tmp_pool, &vport_param, 
-					     &call_med->strm.v.capturer);
-	    if (status != PJ_SUCCESS)
-		return status;
-
-	    /* Connect the video capturer to media_port */
-	    status = pjmedia_vid_port_connect(call_med->strm.v.capturer,
-					      media_port, PJ_FALSE);
-	    if (status != PJ_SUCCESS)
-		return status;
-
-	    /* Start the video capturer */
-	    status = pjmedia_vid_port_start(call_med->strm.v.capturer);
-	    if (status != PJ_SUCCESS)
-		return status;
-	}
-
-	/* Call media direction */
-	call_med->dir = si->dir;
-
-	/* Call media state */
-	if (call->local_hold)
-	    call_med->state = PJSUA_CALL_MEDIA_LOCAL_HOLD;
-	else if (call_med->dir == PJMEDIA_DIR_DECODING)
-	    call_med->state = PJSUA_CALL_MEDIA_REMOTE_HOLD;
-	else
-	    call_med->state = PJSUA_CALL_MEDIA_ACTIVE;
-    }
-
-    /* Print info. */
-    {
-	char info[80];
-	int info_len = 0;
-	int len;
-	const char *dir;
-
-	switch (si->dir) {
-	case PJMEDIA_DIR_NONE:
-	    dir = "inactive";
-	    break;
-	case PJMEDIA_DIR_ENCODING:
-	    dir = "sendonly";
-	    break;
-	case PJMEDIA_DIR_DECODING:
-	    dir = "recvonly";
-	    break;
-	case PJMEDIA_DIR_ENCODING_DECODING:
-	    dir = "sendrecv";
-	    break;
-	default:
-	    dir = "unknown";
-	    break;
-	}
-	len = pj_ansi_sprintf( info+info_len,
-			       ", stream #%d: %.*s (%s)", strm_idx,
-			       (int)si->codec_info.encoding_name.slen,
-			       si->codec_info.encoding_name.ptr,
-			       dir);
-	if (len > 0)
-	    info_len += len;
-	PJ_LOG(4,(THIS_FILE,"Media updates%s", info));
-    }
-
-    return PJ_SUCCESS;
-}
-
-#endif
-
+pj_status_t video_channel_update(pjsua_call_media *call_med,
+                                 pj_pool_t *tmp_pool,
+			         const pjmedia_sdp_session *local_sdp,
+			         const pjmedia_sdp_session *remote_sdp);
 
 pj_status_t pjsua_media_channel_update(pjsua_call_id call_id,
