Index: pjproject/trunk/pjmedia/include/pjmedia/event.h
===================================================================
--- pjproject/trunk/pjmedia/include/pjmedia/event.h	(revision 5824)
+++ pjproject/trunk/pjmedia/include/pjmedia/event.h	(revision 5825)
@@ -83,5 +83,10 @@
      * Video orientation has been changed event.
      */
-    PJMEDIA_EVENT_ORIENT_CHANGED = PJMEDIA_FOURCC('O', 'R', 'N', 'T')
+    PJMEDIA_EVENT_ORIENT_CHANGED = PJMEDIA_FOURCC('O', 'R', 'N', 'T'),
+
+    /**
+     * RTCP-FB has been received.
+     */
+    PJMEDIA_EVENT_RX_RTCP_FB = PJMEDIA_FOURCC('R', 'T', 'F', 'B')
 
 } pjmedia_event_type;
Index: pjproject/trunk/pjmedia/include/pjmedia/rtcp_fb.h
===================================================================
--- pjproject/trunk/pjmedia/include/pjmedia/rtcp_fb.h	(revision 5824)
+++ pjproject/trunk/pjmedia/include/pjmedia/rtcp_fb.h	(revision 5825)
@@ -44,13 +44,32 @@
 
 /**
- * Enumeration of RTCP Feedback types.
+ * Enumeration of RTCP Feedback types. Each feedback type may have subtypes,
+ * which should be specified in feedback parameters.
  */
 typedef enum pjmedia_rtcp_fb_type
 {
-    PJMEDIA_RTCP_FB_ACK,     /**< Positive acknowledgement feedbacks.	    */
-    PJMEDIA_RTCP_FB_NACK,    /**< Negative acknowledgement feedbacks.	    */
-    PJMEDIA_RTCP_FB_TRR_INT, /**< Minimum interval between two regular RTCP
-				  packets.				    */
-    PJMEDIA_RTCP_FB_OTHER    /**< Other feedback type.			    */
+    /**
+     * Positive acknowledgement feedbacks. Sample subtypes are Reference Picture
+     * Selection Indication (RPSI) and application layer feedbacks.
+     */
+    PJMEDIA_RTCP_FB_ACK,
+
+    /**
+     * Negative acknowledgement feedbacks. Sample subtypes are generic NACK,
+     * Picture Loss Indication (PLI), Slice Loss Indication (SLI), Reference
+     * Picture Selection Indication (RPSI), and application layer feedbacks.
+     */
+    PJMEDIA_RTCP_FB_NACK,
+
+    /**
+     * Minimum interval between two regular RTCP packets.
+     */
+    PJMEDIA_RTCP_FB_TRR_INT,
+
+    /**
+     * Other feedback types.
+     */
+    PJMEDIA_RTCP_FB_OTHER
+
 } pjmedia_rtcp_fb_type;
 
@@ -80,5 +99,10 @@
 
     /**
-     * Specify the RTCP Feedback parameters.
+     * Specify the RTCP Feedback parameters. Feedback subtypes should be
+     * specified in this field, e.g:
+     * - 'pli' for Picture Loss Indication feedback,
+     * - 'sli' for Slice Loss Indication feedback,
+     * - 'rpsi' for Reference Picture Selection Indication feedback,
+     * - 'app' for specific/proprietary application layer feedback.
      */
     pj_str_t		    param;
@@ -135,4 +159,55 @@
 
 /**
+ * This structure declares RTCP Feedback Generic NACK message.
+ */
+typedef struct pjmedia_rtcp_fb_nack
+{
+    pj_int32_t		 pid;		/**< Packet ID (RTP seq)    */
+    pj_uint16_t		 blp;		/**< Bitmask of following lost
+					     packets		    */
+} pjmedia_rtcp_fb_nack;
+
+
+/**
+ * This structure declares RTCP Feedback Slice Loss Indication (SLI) message.
+ */
+typedef struct pjmedia_rtcp_fb_sli
+{
+    pj_uint16_t		 first;		/**< First lost macroblock	*/
+    pj_uint16_t		 number;	/**< The number of lost macroblocks
+					     packets			*/
+    pj_uint8_t		 pict_id;	/**< Picture ID (temporal ref)	*/
+} pjmedia_rtcp_fb_sli;
+
+
+/**
+ * This structure declares RTCP Feedback Reference Picture Selection
+ * Indication (RPSI) message.
+ */
+typedef struct pjmedia_rtcp_fb_rpsi
+{
+    pj_uint8_t		 pt;		/**< Payload Type		*/
+    pj_str_t		 rpsi;		/**< Native RPSI bit string	*/
+    pj_size_t		 rpsi_bit_len;	/**< Length of RPSI in bit	*/
+} pjmedia_rtcp_fb_rpsi;
+
+
+/**
+ * Event data for incoming RTCP Feedback message event
+ * (PJMEDIA_EVENT_RX_RTCP_FB).
+ */
+typedef struct pjmedia_event_rx_rtcp_fb_data
+{
+    pjmedia_rtcp_fb_cap		cap;
+    union {
+	pjmedia_rtcp_fb_nack	nack;
+	pjmedia_rtcp_fb_sli	sli;
+	pjmedia_rtcp_fb_rpsi	rpsi;
+    } msg;
+
+} pjmedia_event_rx_rtcp_fb_data;
+
+
+/**
  * Initialize RTCP Feedback setting with default values.
  *
@@ -220,15 +295,4 @@
 
 /**
- * This structure declares RTCP Feedback Generic NACK message.
- */
-typedef struct pjmedia_rtcp_fb_nack
-{
-    pj_int32_t		 pid;		/**< Packet ID (RTP seq)    */
-    pj_uint16_t		 blp;		/**< Bitmask of following lost
-					     packets		    */
-} pjmedia_rtcp_fb_nack;
-
-
-/**
  * Build an RTCP Feedback Generic NACK packet. This packet can be appended to
  * other RTCP packets, e.g: RTCP RR/SR, to compose a compound RTCP packet.
@@ -273,16 +337,4 @@
 
 /**
- * This structure declares RTCP Feedback Slice Loss Indication (SLI) message.
- */
-typedef struct pjmedia_rtcp_fb_sli
-{
-    pj_uint16_t		 first;		/**< First lost macroblock	*/
-    pj_uint16_t		 number;	/**< The number of lost macroblocks
-					     packets			*/
-    pj_uint8_t		 pict_id;	/**< Picture ID (temporal ref)	*/
-} pjmedia_rtcp_fb_sli;
-
-
-/**
  * Build an RTCP Feedback Slice Loss Indication (SLI) packet. This packet can
  * be appended to other RTCP packets, e.g: RTCP RR/SR, to compose a compound
@@ -308,16 +360,4 @@
 
 /**
- * This structure declares RTCP Feedback Reference Picture Selection
- * Indication (RPSI) message.
- */
-typedef struct pjmedia_rtcp_fb_rpsi
-{
-    pj_uint8_t		 pt;		/**< Payload Type		*/
-    pj_str_t		 rpsi;		/**< Native RPSI bit string	*/
-    pj_size_t		 rpsi_bit_len;	/**< Length of RPSI in bit	*/
-} pjmedia_rtcp_fb_rpsi;
-
-
-/**
  * Build an RTCP Feedback Reference Picture Selection Indication (RPSI)
  * packet. This packet can be appended to other RTCP packets, e.g: RTCP RR/SR,
@@ -342,4 +382,78 @@
 
 /**
+ * Check whether the specified payload contains RTCP feedback generic NACK
+ * message, and parse the payload if it does.
+ *
+ * @param buf	    The payload buffer.
+ * @param length    The payload length.
+ * @param nack_cnt  On input, it specifies the maximum number of generic NACK
+ *		    messages.
+ *		    On output, it specifies the number of parsed generic NACK
+ *		    messages.
+ * @param nack	    The array of RTCP Feedback Generic NACK messages.
+ *
+ * @return	    PJ_SUCCESS if the payload contains generic NACK message
+ *		    and has been parsed successfully.
+ */
+PJ_DECL(pj_status_t) pjmedia_rtcp_fb_parse_nack(
+					const void *buf,
+					pj_size_t length,
+					unsigned *nack_cnt,
+					pjmedia_rtcp_fb_nack nack[]);
+
+
+/**
+ * Check whether the specified payload contains RTCP feedback Picture Loss
+ * Indication (PLI) message.
+ *
+ * @param buf	    The payload buffer.
+ * @param length    The payload length.
+ *
+ * @return	    PJ_SUCCESS if the payload contains PLI message.
+ */
+PJ_DECL(pj_status_t) pjmedia_rtcp_fb_parse_pli(
+					const void *buf,
+					pj_size_t length);
+
+
+/**
+ * Check whether the specified payload contains RTCP feedback Slice Loss
+ * Indication (SLI) message, and parse the payload if it does.
+ *
+ * @param buf	    The payload buffer.
+ * @param length    The payload length.
+ * @param sli_cnt   On input, it specifies the maximum number of SLI messages.
+ *		    On output, it specifies the number of parsed SLI messages.
+ * @param sli	    The array of RTCP Feedback SLI messages.
+ *
+ * @return	    PJ_SUCCESS if the payload contains SLI messages and
+ *		    has been parsed successfully.
+ */
+PJ_DECL(pj_status_t) pjmedia_rtcp_fb_parse_sli(
+					const void *buf,
+					pj_size_t length,
+					unsigned *sli_cnt,
+					pjmedia_rtcp_fb_sli sli[]);
+
+
+/**
+ * Check whether the specified payload contains RTCP feedback Reference
+ * Picture Selection Indication (RPSI) message, and parse the payload
+ * if it does.
+ *
+ * @param buf	    The payload buffer.
+ * @param length    The payload length.
+ * @param rpsi	    The parsed RTCP Feedback RPSI messages.
+ *
+ * @return	    PJ_SUCCESS if the payload contains SLI messages and
+ *		    has been parsed successfully.
+ */
+PJ_DECL(pj_status_t) pjmedia_rtcp_fb_parse_rpsi(
+					const void *buf,
+					pj_size_t length,
+					pjmedia_rtcp_fb_rpsi *rpsi);
+
+
+/**
  * @}
  */
Index: pjproject/trunk/pjmedia/src/pjmedia/rtcp.c
===================================================================
--- pjproject/trunk/pjmedia/src/pjmedia/rtcp.c	(revision 5824)
+++ pjproject/trunk/pjmedia/src/pjmedia/rtcp.c	(revision 5825)
@@ -20,4 +20,6 @@
 #include <pjmedia/rtcp.h>
 #include <pjmedia/errno.h>
+#include <pjmedia/event.h>
+#include <pjmedia/rtcp_fb.h>
 #include <pj/assert.h>
 #include <pj/log.h>
@@ -33,4 +35,8 @@
 #define RTCP_BYE  203
 #define RTCP_XR   207
+
+/* RTCP Feedbacks */
+#define RTCP_RTPFB	205
+#define RTCP_PSFB	206
 
 enum {
@@ -765,4 +771,44 @@
 
 
+static void parse_rtcp_fb(pjmedia_rtcp_session *sess,
+			  const void *pkt,
+			  pj_size_t size)
+{
+    unsigned cnt = 1;
+    pjmedia_rtcp_fb_nack nack[1];
+    //pjmedia_rtcp_fb_sli sli[1];
+    //pjmedia_rtcp_fb_rpsi rpsi;
+    pjmedia_event ev;
+    pjmedia_event_rx_rtcp_fb_data ev_data;
+    pj_timestamp ts_now;
+
+    pj_get_timestamp(&ts_now);
+    pj_bzero(&ev_data, sizeof(ev_data));
+
+    if (pjmedia_rtcp_fb_parse_nack(pkt, size, &cnt, nack)==PJ_SUCCESS)
+    {
+	pjmedia_event_init(&ev, PJMEDIA_EVENT_RX_RTCP_FB, &ts_now, sess);
+	ev_data.cap.type = PJMEDIA_RTCP_FB_NACK;
+	ev_data.msg.nack = nack[0];
+	ev.data.ptr = &ev_data;
+
+	/* Sync publish, i.e: don't use PJMEDIA_EVENT_PUBLISH_POST_EVENT */
+	pjmedia_event_publish(NULL, sess, &ev, 0);
+
+	/*  For other FB type implementations later
+    } else if (pjmedia_rtcp_fb_parse_pli(pkt, size)==PJ_SUCCESS)
+    {
+    } else if (pjmedia_rtcp_fb_parse_sli(pkt, size, &cnt, sli)==PJ_SUCCESS)
+    {
+    } else if (pjmedia_rtcp_fb_parse_rpsi(pkt, size, &rpsi)==PJ_SUCCESS)
+    {
+	*/
+    } else {
+	/* Ignore unknown RTCP Feedback */
+	TRACE_((sess->name, "Received unknown RTCP feedback"));
+    }
+}
+
+
 PJ_DEF(void) pjmedia_rtcp_rx_rtcp( pjmedia_rtcp_session *sess,
 				   const void *pkt,
@@ -789,4 +835,8 @@
 	case RTCP_BYE:
 	    parse_rtcp_bye(sess, p, len);
+	    break;
+	case RTCP_RTPFB:
+	case RTCP_PSFB:
+	    parse_rtcp_fb(sess, p, len);
 	    break;
 	default:
Index: pjproject/trunk/pjmedia/src/pjmedia/rtcp_fb.c
===================================================================
--- pjproject/trunk/pjmedia/src/pjmedia/rtcp_fb.c	(revision 5824)
+++ pjproject/trunk/pjmedia/src/pjmedia/rtcp_fb.c	(revision 5825)
@@ -215,21 +215,4 @@
 {
     pj_bzero(opt, sizeof(*opt));
-
-    /* == just for test == */
-    opt->cap_count = 4;
-
-    pj_cstr(&opt->caps[0].codec_id, "*");
-    opt->caps[0].type = PJMEDIA_RTCP_FB_ACK;
-    
-    pj_cstr(&opt->caps[1].codec_id, "speex/16000");
-    opt->caps[1].type = PJMEDIA_RTCP_FB_NACK;
-    
-    pj_cstr(&opt->caps[2].codec_id, "H264");
-    opt->caps[2].type = PJMEDIA_RTCP_FB_NACK;
-    pj_cstr(&opt->caps[2].param, "pli");
-
-    pj_cstr(&opt->caps[3].codec_id, "pcmu");
-    opt->caps[3].type = PJMEDIA_RTCP_FB_NACK;
-    /* == just for test == */
 
     return PJ_SUCCESS;
@@ -581,2 +564,145 @@
     return PJ_SUCCESS;
 }
+
+
+/*
+ * Check whether the specified payload contains RTCP feedback generic NACK
+ * message, and parse the payload if it does.
+ */
+PJ_DEF(pj_status_t) pjmedia_rtcp_fb_parse_nack(
+					const void *buf,
+					pj_size_t length,
+					unsigned *nack_cnt,
+					pjmedia_rtcp_fb_nack nack[])
+{
+    pjmedia_rtcp_common *hdr = (pjmedia_rtcp_common*) buf;
+    pj_uint8_t *p;
+    unsigned cnt, i;
+
+    PJ_ASSERT_RETURN(buf && nack_cnt && nack, PJ_EINVAL);
+    PJ_ASSERT_RETURN(length >= sizeof(pjmedia_rtcp_common), PJ_ETOOSMALL);
+
+    /* Generic NACK uses pt==RTCP_RTPFB and FMT==1 */
+    if (hdr->pt != RTCP_RTPFB || hdr->count != 1)
+	return PJ_ENOTFOUND;
+
+    cnt = pj_ntohs((pj_uint16_t)hdr->length) - 2;
+    if (length < (cnt+3)*4)
+	return PJ_ETOOSMALL;
+
+    *nack_cnt = PJ_MIN(*nack_cnt, cnt);
+
+    p = (pj_uint8_t*)hdr + sizeof(*hdr);
+    for (i = 0; i < *nack_cnt; ++i) {
+	pj_uint16_t val;
+
+	pj_memcpy(&val, p, 2);
+	nack[i].pid = pj_ntohs(val);
+	pj_memcpy(&val, p+2, 2);
+	nack[i].blp = pj_ntohs(val);
+	p += 4;
+    }
+
+    return PJ_SUCCESS;
+}
+
+
+/*
+ * Check whether the specified payload contains RTCP feedback Picture Loss
+ * Indication (PLI) message.
+ */
+PJ_DEF(pj_status_t) pjmedia_rtcp_fb_parse_pli(
+					const void *buf,
+					pj_size_t length)
+{
+    pjmedia_rtcp_common *hdr = (pjmedia_rtcp_common*) buf;
+
+    PJ_ASSERT_RETURN(buf, PJ_EINVAL);
+    PJ_ASSERT_RETURN(length >= 12, PJ_ETOOSMALL);
+
+    /* PLI uses pt==RTCP_PSFB and FMT==1 */
+    if (hdr->pt != RTCP_PSFB || hdr->count != 1)
+	return PJ_ENOTFOUND;
+
+    return PJ_SUCCESS;
+}
+
+
+/*
+ * Check whether the specified payload contains RTCP feedback Slice Loss
+ * Indication (SLI) message, and parse the payload if it does.
+ */
+PJ_DEF(pj_status_t) pjmedia_rtcp_fb_parse_sli(
+					const void *buf,
+					pj_size_t length,
+					unsigned *sli_cnt,
+					pjmedia_rtcp_fb_sli sli[])
+{
+    pjmedia_rtcp_common *hdr = (pjmedia_rtcp_common*) buf;
+    pj_uint8_t *p;
+    unsigned cnt, i;
+
+    PJ_ASSERT_RETURN(buf && sli_cnt && sli, PJ_EINVAL);
+    PJ_ASSERT_RETURN(length >= sizeof(pjmedia_rtcp_common), PJ_ETOOSMALL);
+
+    /* PLI uses pt==RTCP_PSFB and FMT==2 */
+    if (hdr->pt != RTCP_PSFB || hdr->count != 2)
+	return PJ_ENOTFOUND;
+
+    cnt = pj_ntohs((pj_uint16_t)hdr->length) - 2;
+    if (length < (cnt+3)*4)
+	return PJ_ETOOSMALL;
+
+    *sli_cnt = PJ_MIN(*sli_cnt, cnt);
+
+    p = (pj_uint8_t*)hdr + sizeof(*hdr);
+    for (i = 0; i < *sli_cnt; ++i) {
+	/* 'first' takes 13 bit */
+	sli[i].first = (p[0] << 5) + ((p[1] & 0xF8) >> 3);
+	/* 'number' takes 13 bit */
+	sli[i].number = ((p[1] & 0x07) << 10) +
+			(p[2] << 2) +
+			((p[3] & 0xC0) >> 6);
+	/* 'pict_id' takes 6 bit */
+	sli[i].pict_id = (p[3] & 0x3F);
+	p += 4;
+    }
+
+    return PJ_SUCCESS;
+}
+
+
+/*
+ * Check whether the specified payload contains RTCP feedback Reference
+ * Picture Selection Indication (RPSI) message, and parse the payload
+ * if it does.
+ */
+PJ_DEF(pj_status_t) pjmedia_rtcp_fb_parse_rpsi(
+					const void *buf,
+					pj_size_t length,
+					pjmedia_rtcp_fb_rpsi *rpsi)
+{
+    pjmedia_rtcp_common *hdr = (pjmedia_rtcp_common*) buf;
+    pj_uint8_t *p;
+    pj_uint8_t padlen;
+    pj_size_t rpsi_len;
+
+    PJ_ASSERT_RETURN(buf && rpsi, PJ_EINVAL);
+    PJ_ASSERT_RETURN(length >= sizeof(pjmedia_rtcp_common), PJ_ETOOSMALL);
+
+    /* RPSI uses pt==RTCP_PSFB and FMT==3 */
+    if (hdr->pt != RTCP_PSFB || hdr->count != 3)
+	return PJ_ENOTFOUND;
+
+    rpsi_len = (pj_ntohs((pj_uint16_t)hdr->length)-2) * 4;
+    if (length < rpsi_len + 12)
+	return PJ_ETOOSMALL;
+
+    p = (pj_uint8_t*)hdr + sizeof(*hdr);
+    padlen = *p++;
+    rpsi->pt = (*p++ & 0x7F);
+    rpsi->rpsi_bit_len = rpsi_len*8 - 16 - padlen;
+    pj_strset(&rpsi->rpsi, (char*)p, (rpsi->rpsi_bit_len + 7)/8);
+
+    return PJ_SUCCESS;
+}
Index: pjproject/trunk/pjmedia/src/pjmedia/stream.c
===================================================================
--- pjproject/trunk/pjmedia/src/pjmedia/stream.c	(revision 5824)
+++ pjproject/trunk/pjmedia/src/pjmedia/stream.c	(revision 5825)
@@ -249,6 +249,7 @@
 
     /* RTCP Feedback */
-    pj_bool_t		     send_rtcp_fb_nack;/**< Should we send NACK?    */
-    pjmedia_rtcp_fb_nack     rtcp_fb_nack;     /**< NACK state.		    */
+    pj_bool_t		     send_rtcp_fb_nack;	    /**< Send NACK?	    */
+    pjmedia_rtcp_fb_nack     rtcp_fb_nack;	    /**< TX NACK state.	    */
+    int			     rtcp_fb_nack_cap_idx;  /**< RX NACK cap idx.   */
 
 
@@ -1725,5 +1726,5 @@
     const void *payload;
     unsigned payloadlen;
-    pjmedia_rtp_status seq_st = {0};
+    pjmedia_rtp_status seq_st;
     pj_status_t status;
     pj_bool_t pkt_discarded = PJ_FALSE;
@@ -1768,4 +1769,5 @@
 
     /* Ignore the packet if decoder is paused */
+    pj_bzero(&seq_st, sizeof(seq_st));
     if (channel->paused)
 	goto on_return;
@@ -2193,4 +2195,31 @@
 
 /*
+ * Handle events.
+ */
+static pj_status_t stream_event_cb(pjmedia_event *event,
+                                   void *user_data)
+{
+    pjmedia_stream *stream = (pjmedia_stream*)user_data;
+
+    /* Set RTCP FB capability in the event */
+    if (event->type==PJMEDIA_EVENT_RX_RTCP_FB &&
+	event->epub==&stream->rtcp)
+    {
+	pjmedia_event_rx_rtcp_fb_data *data = (pjmedia_event_rx_rtcp_fb_data*)
+					      event->data.ptr;
+
+	/* Application not configured to listen to NACK, discard this event */
+	if (stream->rtcp_fb_nack_cap_idx < 0)
+	    return PJ_SUCCESS;
+	
+	data->cap = stream->si.loc_rtcp_fb.caps[stream->rtcp_fb_nack_cap_idx];
+    }
+
+    /* Republish events */
+    return pjmedia_event_publish(NULL, stream, event, 0);
+}
+
+
+/*
  * Create media stream.
  */
@@ -2569,4 +2598,8 @@
 	    stream->rtcp.stat.rtp_tx_last_ts = info->rtp_ts;
 	}
+
+	/* Subscribe to RTCP events */
+	pjmedia_event_subscribe(NULL, &stream_event_cb, stream,
+				&stream->rtcp);
     }
 
@@ -2665,5 +2698,5 @@
 #endif
 
-    /* Check if RTCP-FB generic NACK is enabled for this codec */
+    /* Check if we should send RTCP-FB generic NACK for this codec */
     if (stream->si.rem_rtcp_fb.cap_count) {
 	pjmedia_rtcp_fb_info *rfi = &stream->si.rem_rtcp_fb;
@@ -2679,4 +2712,24 @@
 	    {
 		stream->send_rtcp_fb_nack = PJ_TRUE;
+		break;
+	    }
+	}
+    }
+
+    /* Check if we handle incoming RTCP-FB generic NACK for this codec */
+    stream->rtcp_fb_nack_cap_idx = -1;
+    if (stream->si.loc_rtcp_fb.cap_count) {
+	pjmedia_rtcp_fb_info *lfi = &stream->si.loc_rtcp_fb;
+	char cid[32];
+	unsigned i;
+
+	pjmedia_codec_info_to_id(&stream->si.fmt, cid, sizeof(cid));
+
+	for (i = 0; i < lfi->cap_count; ++i) {
+	    if (lfi->caps[i].type == PJMEDIA_RTCP_FB_NACK &&
+		(!pj_strcmp2( &lfi->caps[i].codec_id, "*") ||
+		 !pj_stricmp2(&lfi->caps[i].codec_id, cid)))
+	    {
+		stream->rtcp_fb_nack_cap_idx = i;
 		break;
 	    }
@@ -2796,4 +2849,8 @@
 	}
     }
+
+    /* Unsubscribe from RTCP session events */
+    pjmedia_event_unsubscribe(NULL, &stream_event_cb, stream,
+			      &stream->rtcp);
 
     /* Detach from transport
Index: pjproject/trunk/pjsip/src/pjsua-lib/pjsua_aud.c
===================================================================
--- pjproject/trunk/pjsip/src/pjsua-lib/pjsua_aud.c	(revision 5824)
+++ pjproject/trunk/pjsip/src/pjsua-lib/pjsua_aud.c	(revision 5825)
@@ -502,4 +502,7 @@
 
     if (strm) {
+	/* Unsubscribe from stream events */
+	pjmedia_event_unsubscribe(NULL, &call_media_on_event, call_med, strm);
+
 	pjmedia_stream_send_rtcp_bye(strm);
 
@@ -701,4 +704,8 @@
 	    }
 	}
+
+	/* Subscribe to stream events */
+	pjmedia_event_subscribe(NULL, &call_media_on_event, call_med,
+				call_med->strm.a.stream);
     }
 
Index: pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c
===================================================================
--- pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c	(revision 5824)
+++ pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c	(revision 5825)
@@ -110,4 +110,15 @@
 	goto on_error;
 #endif
+
+    /* Create event manager (if not yet, e.g: PJMEDIA_HAS_VIDEO==0) */
+    if (!pjmedia_event_mgr_instance()) {
+	status = pjmedia_event_mgr_create(pjsua_var.pool, 
+					  PJMEDIA_EVENT_MGR_NO_THREAD, NULL);
+	if (status != PJ_SUCCESS) {
+	    PJ_PERROR(1,(THIS_FILE, status,
+			 "Error creating PJMEDIA event manager"));
+	    goto on_error;
+	}
+    }
 
     pj_log_pop_indent();
