Index: pjproject/trunk/pjmedia/include/pjmedia/vid_stream.h
===================================================================
--- pjproject/trunk/pjmedia/include/pjmedia/vid_stream.h	(revision 4042)
+++ pjproject/trunk/pjmedia/include/pjmedia/vid_stream.h	(revision 4043)
@@ -72,4 +72,49 @@
  * #pjmedia_vid stream_info from local and remote SDP session descriptors.
  */
+
+
+/**
+ * Enumeration of video stream sending rate control.
+ */
+typedef enum pjmedia_vid_stream_rc_method
+{
+    /**
+     * No sending rate control. All outgoing RTP packets will be transmitted
+     * immediately right after encoding process is done.
+     */
+    PJMEDIA_VID_STREAM_RC_NONE		    = 0,
+
+    /**
+     * Simple blocking. Each outgoing RTP packet transmission may be delayed
+     * to avoid peak bandwidth that is much higher than specified. The thread
+     * invoking the video stream put_frame(), e.g: video capture device thread,
+     * will be blocked whenever transmission delay takes place.
+     */
+    PJMEDIA_VID_STREAM_RC_SIMPLE_BLOCKING   = 1
+
+} pjmedia_vid_stream_rc_method;
+
+
+/**
+ * Structure of configuration settings for video stream sending rate control.
+ */
+typedef struct pjmedia_vid_stream_rc_config
+{
+    /**
+     * Rate control method.
+     *
+     * Default: PJMEDIA_VID_STREAM_RC_SIMPLE_BLOCKING.
+     */
+    pjmedia_vid_stream_rc_method    method;
+
+    /**
+     * Upstream/outgoing bandwidth. If this is set to zero, the video stream
+     * will use codec maximum bitrate setting.
+     *
+     * Default: 0 (follow codec maximum bitrate).
+     */
+    unsigned			    bandwidth;
+
+} pjmedia_vid_stream_rc_config;
 
 
@@ -118,4 +163,7 @@
                                     /**< Disable automatic sending of RTCP
                                          SDES and BYE.                      */
+
+    pjmedia_vid_stream_rc_config rc_cfg;
+                                    /**< Stream send rate control settings. */
 } pjmedia_vid_stream_info;
 
@@ -144,4 +192,13 @@
 				 const pjmedia_sdp_session *remote,
 				 unsigned stream_idx);
+
+
+/**
+ * Initialize the video stream rate control with default settings.
+ *
+ * @param cfg		Video stream rate control structure to be initialized.
+ */
+PJ_DECL(void)
+pjmedia_vid_stream_rc_config_default(pjmedia_vid_stream_rc_config *cfg);
 
 
Index: pjproject/trunk/pjmedia/src/pjmedia/vid_stream.c
===================================================================
--- pjproject/trunk/pjmedia/src/pjmedia/vid_stream.c	(revision 4042)
+++ pjproject/trunk/pjmedia/src/pjmedia/vid_stream.c	(revision 4043)
@@ -154,6 +154,9 @@
 
     pjmedia_vid_codec	    *codec;	    /**< Codec instance being used. */
-    pj_uint32_t		     last_dec_ts;    /**< Last decoded timestamp.   */
-    int			     last_dec_seq;   /**< Last decoded sequence.    */
+    pj_uint32_t		     last_dec_ts;   /**< Last decoded timestamp.    */
+    int			     last_dec_seq;  /**< Last decoded sequence.     */
+
+
+    pj_timestamp	     ts_freq;	    /**< Timestamp frequency.	    */
 };
 
@@ -769,4 +772,6 @@
     pj_size_t total_sent = 0;
     pjmedia_vid_encode_opt enc_opt;
+    unsigned pkt_cnt = 0;
+    pj_timestamp initial_time;
 
 #if defined(PJMEDIA_STREAM_ENABLE_KA) && PJMEDIA_STREAM_ENABLE_KA != 0
@@ -827,4 +832,6 @@
 	return status;
     }
+    
+    pj_get_timestamp(&initial_time);
 
     /* Loop while we have frame to send */
@@ -865,4 +872,5 @@
 	pjmedia_rtcp_tx_rtp(&stream->rtcp, frame_out.size);
 	total_sent += frame_out.size;
+	pkt_cnt++;
 
 	if (!has_more_data)
@@ -886,5 +894,38 @@
 	    break;
 	}
-    }
+
+	/* Send rate control */
+	if (stream->info.rc_cfg.method==PJMEDIA_VID_STREAM_RC_SIMPLE_BLOCKING)
+	{
+	    pj_timestamp now, next_send_ts, total_send_ts;
+
+	    total_send_ts.u64 = total_sent * stream->ts_freq.u64 * 8 /
+				stream->info.rc_cfg.bandwidth;
+	    next_send_ts = initial_time;
+	    pj_add_timestamp(&next_send_ts, &total_send_ts);
+
+	    pj_get_timestamp(&now);
+	    if (pj_cmp_timestamp(&now, &next_send_ts) < 0) {
+		unsigned ms_sleep;
+		ms_sleep = pj_elapsed_msec(&now, &next_send_ts);
+
+		if (ms_sleep > 10)
+		    ms_sleep = 10;
+
+		pj_thread_sleep(ms_sleep);
+	    }
+	}
+    }
+
+#if 0
+    /* Trace log for rate control */
+    {
+	pj_timestamp end_time;
+	pj_get_timestamp(&end_time);
+	PJ_LOG(5, (stream->name.ptr, "total pkt=%d size=%d sleep=%d",
+		   pkt_cnt, total_sent,
+		   pj_elapsed_msec(&initial_time, &end_time)));
+    }
+#endif
 
     /* Check if now is the time to transmit RTCP SR/RR report. 
@@ -1414,4 +1455,9 @@
                            vfd_enc->fps.denum / vfd_enc->fps.num;
 
+    /* Initialize send rate states */
+    pj_get_timestamp_freq(&stream->ts_freq);
+    if (info->rc_cfg.bandwidth == 0)
+	info->rc_cfg.bandwidth = vfd_enc->max_bps * 150 / 100;
+
     /* Override the initial framerate in the decoding direction. This initial
      * value will be used by the renderer to configure its clock, and setting
@@ -1868,3 +1914,14 @@
 
 
+/*
+ * Initialize the video stream rate control with default settings.
+ */
+PJ_DEF(void)
+pjmedia_vid_stream_rc_config_default(pjmedia_vid_stream_rc_config *cfg)
+{
+    pj_bzero(cfg, sizeof(*cfg));
+    cfg->method = PJMEDIA_VID_STREAM_RC_SIMPLE_BLOCKING;
+}
+
+
 #endif /* PJMEDIA_HAS_VIDEO */
Index: pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h
===================================================================
--- pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h	(revision 4042)
+++ pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h	(revision 4043)
@@ -2883,4 +2883,11 @@
 
     /**
+     * Specify the send rate control for video stream.
+     *
+     * Default: see #pjmedia_vid_stream_rc_config
+     */
+    pjmedia_vid_stream_rc_config vid_stream_rc_cfg;
+
+    /**
      * Media transport config.
      */
Index: pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c
===================================================================
--- pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c	(revision 4042)
+++ pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c	(revision 4043)
@@ -219,4 +219,5 @@
     cfg->vid_cap_dev = PJMEDIA_VID_DEFAULT_CAPTURE_DEV;
     cfg->vid_rend_dev = PJMEDIA_VID_DEFAULT_RENDER_DEV;
+    pjmedia_vid_stream_rc_config_default(&cfg->vid_stream_rc_cfg);
     pjsua_transport_config_default(&cfg->rtp_cfg);
     cfg->use_srtp = pjsua_var.ua_cfg.use_srtp;
Index: pjproject/trunk/pjsip/src/pjsua-lib/pjsua_vid.c
===================================================================
--- pjproject/trunk/pjsip/src/pjsua-lib/pjsua_vid.c	(revision 4042)
+++ pjproject/trunk/pjsip/src/pjsua-lib/pjsua_vid.c	(revision 4043)
@@ -747,4 +747,7 @@
 	si->rtp_seq = call_med->rtp_tx_seq;
 	si->rtp_seq_ts_set = call_med->rtp_tx_seq_ts_set;
+
+	/* Set rate control config from account setting */
+	si->rc_cfg = acc->cfg.vid_stream_rc_cfg;
 
 #if defined(PJMEDIA_STREAM_ENABLE_KA) && PJMEDIA_STREAM_ENABLE_KA!=0
