Index: /pjproject/trunk/pjmedia/include/pjmedia/jbuf.h
===================================================================
--- /pjproject/trunk/pjmedia/include/pjmedia/jbuf.h	(revision 5802)
+++ /pjproject/trunk/pjmedia/include/pjmedia/jbuf.h	(revision 5803)
@@ -282,5 +282,6 @@
  * @param bit_info	Bit precise info of the frame, e.g: a frame may not 
  *			exactly start and end at the octet boundary, so this
- *			field may be used for specifying start & end bit offset.
+ *			field may be used for specifying start & end bit
+ *			offset.
  * @param frame_seq	The frame sequence number.
  * @param discarded	Flag whether the frame is discarded by jitter buffer.
@@ -307,5 +308,6 @@
  * @param bit_info	Bit precise info of the frame, e.g: a frame may not 
  *			exactly start and end at the octet boundary, so this
- *			field may be used for specifying start & end bit offset.
+ *			field may be used for specifying start & end bit
+ *			offset.
  * @param frame_seq	The frame sequence number.
  * @param frame_ts	The frame timestamp.
@@ -355,10 +357,12 @@
  * @param frame		Buffer to receive the payload from the jitter buffer.
  *			@see pjmedia_jbuf_get_frame().    
- * @param size		Pointer to receive frame size.
+ * @param size		On input, it points to maximum buffer length.
+ *			On output, it will be filled with received frame size.
  * @param p_frm_type	Pointer to receive frame type.
  *			@see pjmedia_jbuf_get_frame().    
  * @param bit_info	Bit precise info of the frame, e.g: a frame may not 
  *			exactly start and end at the octet boundary, so this
- *			field may be used for specifying start & end bit offset.
+ *			field may be used for specifying start & end bit
+ *			offset.
  */
 PJ_DECL(void) pjmedia_jbuf_get_frame2(pjmedia_jbuf *jb, 
@@ -376,10 +380,12 @@
  * @param frame		Buffer to receive the payload from the jitter buffer.
  *			@see pjmedia_jbuf_get_frame().    
- * @param size		Pointer to receive frame size.
+ * @param size		On input, it points to maximum buffer length.
+ *			On output, it will be filled with received frame size.
  * @param p_frm_type	Pointer to receive frame type.
  *			@see pjmedia_jbuf_get_frame().    
  * @param bit_info	Bit precise info of the frame, e.g: a frame may not 
  *			exactly start and end at the octet boundary, so this
- *			field may be used for specifying start & end bit offset.
+ *			field may be used for specifying start & end bit
+ *			offset.
  * @param ts		Frame timestamp.
  * @param seq		Frame sequence number.
@@ -407,5 +413,6 @@
  * @param bit_info	Bit precise info of the frame, e.g: a frame may not 
  *			exactly start and end at the octet boundary, so this
- *			field may be used for specifying start & end bit offset.
+ *			field may be used for specifying start & end bit
+ *			offset.
  * @param ts		Frame timestamp.
  * @param seq		Frame sequence number.
Index: /pjproject/trunk/pjmedia/src/pjmedia/jbuf.c
===================================================================
--- /pjproject/trunk/pjmedia/src/pjmedia/jbuf.c	(revision 5802)
+++ /pjproject/trunk/pjmedia/src/pjmedia/jbuf.c	(revision 5803)
@@ -296,12 +296,23 @@
 		    *bit_info = 0;
 	    } else {
+		pj_size_t frm_size = framelist->content_len[framelist->head];
+		pj_size_t max_size = size? *size : frm_size;
+		pj_size_t copy_size = PJ_MIN(max_size, frm_size);
+
+		/* Buffer size should not be smaller than frame size. */
+		if (max_size < frm_size) {
+		    pj_assert(!"Buffer too small");
+		    PJ_LOG(4, (THIS_FILE, "Warning: buffer too small for the "
+					  "retrieved frame!"));
+		}
+
 		pj_memcpy(frame,
 			  framelist->content +
 			  framelist->head * framelist->frame_size,
-			  framelist->frame_size);
+			  copy_size);
 		*p_type = (pjmedia_jb_frame_type)
 			  framelist->frame_type[framelist->head];
 		if (size)
-		    *size   = framelist->content_len[framelist->head];
+		    *size = copy_size;
 		if (bit_info)
 		    *bit_info = framelist->bit_info[framelist->head];
@@ -988,4 +999,10 @@
     cur_size = jb_framelist_eff_size(&jb->jb_framelist);
 
+    /* Check if frame size is larger than JB frame size */
+    if (frame_size > jb->jb_frame_size) {
+	PJ_LOG(4, (THIS_FILE, "Warning: frame too large for jitter buffer, "
+		   "it will be truncated!"));
+    }
+
     /* Attempt to store the frame */
     min_frame_size = PJ_MIN(frame_size, jb->jb_frame_size);
Index: /pjproject/trunk/pjmedia/src/pjmedia/stream.c
===================================================================
--- /pjproject/trunk/pjmedia/src/pjmedia/stream.c	(revision 5802)
+++ /pjproject/trunk/pjmedia/src/pjmedia/stream.c	(revision 5803)
@@ -87,5 +87,4 @@
     unsigned		    out_pkt_size;   /**< Size of output buffer.	    */
     void		   *out_pkt;	    /**< Output buffer.		    */
-    unsigned                out_pkt_len;    /**< Length of data in buffer.  */
     pjmedia_rtp_session	    rtp;	    /**< RTP session.		    */
 };
@@ -531,5 +530,5 @@
     for (samples_count=0; samples_count < samples_required;) {
 	char frame_type;
-	pj_size_t frame_size;
+	pj_size_t frame_size = channel->out_pkt_size;
 	pj_uint32_t bit_info;
 
@@ -822,5 +821,5 @@
     while (f->samples_cnt < samples_required) {
 	char frame_type;
-	pj_size_t frame_size;
+	pj_size_t frame_size = channel->out_pkt_size;
 	pj_uint32_t bit_info;
 
@@ -2077,8 +2076,20 @@
 
     if (param->type == PJMEDIA_TYPE_AUDIO) {
-        channel->out_pkt_size = sizeof(pjmedia_rtp_hdr) +
-			        stream->codec_param.info.max_bps *
-			        PJMEDIA_MAX_FRAME_DURATION_MS /
-			        8 / 1000;
+	unsigned max_rx_based_size;
+	unsigned max_bps_based_size;
+
+	/* out_pkt buffer is used for sending and receiving, so lets calculate
+	 * its size based on both. For receiving, we have stream->frame_size,
+	 * which is used in configuring jitter buffer frame length.
+	 * For sending, it is based on codec max_bps info.
+	 */
+	max_rx_based_size = stream->frame_size;
+	max_bps_based_size = stream->codec_param.info.max_bps *
+			     PJMEDIA_MAX_FRAME_DURATION_MS / 8 / 1000;
+	channel->out_pkt_size = PJ_MAX(max_rx_based_size, max_bps_based_size);
+
+	/* Also include RTP header size (for sending) */
+        channel->out_pkt_size += sizeof(pjmedia_rtp_hdr);
+
         if (channel->out_pkt_size > PJMEDIA_MAX_MTU -
 				    PJMEDIA_STREAM_RESV_PAYLOAD_LEN)
