Index: /pjproject/trunk/pjmedia/include/pjmedia/event.h
===================================================================
--- /pjproject/trunk/pjmedia/include/pjmedia/event.h	(revision 6084)
+++ /pjproject/trunk/pjmedia/include/pjmedia/event.h	(revision 6085)
@@ -27,4 +27,5 @@
 #include <pjmedia/format.h>
 #include <pjmedia/signatures.h>
+#include <pjmedia/videodev.h>
 
 PJ_BEGIN_DECL
@@ -97,4 +98,9 @@
 
     /**
+     * Video device stopped on error.
+     */
+    PJMEDIA_EVENT_VID_DEV_ERROR = PJMEDIA_FOURCC('V', 'E', 'R', 'R'),
+
+    /**
      * Transport media error.
      */
@@ -159,5 +165,22 @@
     /** The error code */
     pj_status_t		     status;
+
 } pjmedia_event_aud_dev_err_data;
+
+/**
+ * Additional data/parameters for video device error event.
+ */
+typedef struct pjmedia_event_vid_dev_err_data
+{
+    /** The media direction that fails */
+    pjmedia_dir		     dir;
+
+    /** The video device ID */
+    pjmedia_vid_dev_index    id;
+
+    /** The error code */
+    pj_status_t		     status;
+
+} pjmedia_event_vid_dev_err_data;
 
 /**
@@ -265,4 +288,7 @@
 	/** Audio device error event data */
 	pjmedia_event_aud_dev_err_data		aud_dev_err;
+
+	/** Video device error event data */
+	pjmedia_event_vid_dev_err_data		vid_dev_err;
 
 	/** Storage for user event data */
Index: /pjproject/trunk/pjmedia/include/pjmedia/videodev.h
===================================================================
--- /pjproject/trunk/pjmedia/include/pjmedia/videodev.h	(revision 6084)
+++ /pjproject/trunk/pjmedia/include/pjmedia/videodev.h	(revision 6085)
@@ -26,5 +26,4 @@
 #include <pjmedia-videodev/config.h>
 #include <pjmedia-videodev/errno.h>
-#include <pjmedia/event.h>
 #include <pjmedia/frame.h>
 #include <pjmedia/format.h>
Index: /pjproject/trunk/pjmedia/src/pjmedia-videodev/android_opengl.c
===================================================================
--- /pjproject/trunk/pjmedia/src/pjmedia-videodev/android_opengl.c	(revision 6084)
+++ /pjproject/trunk/pjmedia/src/pjmedia-videodev/android_opengl.c	(revision 6085)
@@ -115,4 +115,7 @@
 static pj_status_t andgl_stream_destroy(pjmedia_vid_dev_stream *strm);
 
+static pj_status_t init_opengl(void * data);
+static pj_status_t deinit_opengl(void * data);
+
 /* Job queue prototypes */
 static pj_status_t job_queue_create(pj_pool_t *pool, job_queue **pjq);
@@ -155,5 +158,6 @@
     { \
         PJ_LOG(3, (THIS_FILE, "Unable to %s %d", str, eglGetError())); \
-        return PJMEDIA_EVID_SYSERR; \
+        status = PJMEDIA_EVID_SYSERR; \
+	goto on_return; \
     }
 
@@ -173,4 +177,5 @@
     EGLint width;
     EGLint height;
+    pj_status_t status;
     
     strm->display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
@@ -220,6 +225,14 @@
     
     /* Init GL buffers */
-    return pjmedia_vid_dev_opengl_init_buffers(strm->gl_buf);
-}
+    status = pjmedia_vid_dev_opengl_init_buffers(strm->gl_buf);
+    
+on_return:
+    if (status != PJ_SUCCESS)
+	deinit_opengl(strm);
+
+    return status;
+}
+
+#undef EGL_ERR
 
 static pj_status_t render(void * data)
@@ -387,4 +400,5 @@
         pjmedia_format *fmt = (pjmedia_format *)pval;
         andgl_fmt_info *ifi;
+        pj_status_t status = PJ_SUCCESS;
         
         if (!(ifi = get_andgl_format_info(fmt->id)))
@@ -407,9 +421,10 @@
         
 	if (strm->window)
-	    job_queue_post_job(strm->jq, init_opengl, strm, 0, NULL);
+	    job_queue_post_job(strm->jq, init_opengl, strm, 0, &status);
 	    
-	PJ_LOG(4, (THIS_FILE, "Re-initializing OpenGL due to format change"));
-        
-	return PJ_SUCCESS;
+	PJ_PERROR(4,(THIS_FILE, status,
+		     "Re-initializing OpenGL due to format change"));
+	return status;
+	
     } else if (cap == PJMEDIA_VID_DEV_CAP_OUTPUT_WINDOW) {
         pj_status_t status = PJ_SUCCESS;
@@ -430,8 +445,7 @@
         }
 
-        PJ_LOG(4, (THIS_FILE, "Re-initializing OpenGL with native window"
-        		      " %p: %s", strm->window,
-                              (status == PJ_SUCCESS? "success": "failed")));
-        
+        PJ_PERROR(4,(THIS_FILE, status,
+		     "Re-initializing OpenGL with native window %p",
+		     strm->window));
         return status;
     }
Index: /pjproject/trunk/pjmedia/src/pjmedia-videodev/sdl_dev.c
===================================================================
--- /pjproject/trunk/pjmedia/src/pjmedia-videodev/sdl_dev.c	(revision 6084)
+++ /pjproject/trunk/pjmedia/src/pjmedia-videodev/sdl_dev.c	(revision 6085)
@@ -18,4 +18,5 @@
  */
 #include <pjmedia-videodev/videodev_imp.h>
+#include <pjmedia/event.h>
 #include <pj/assert.h>
 #include <pj/log.h>
Index: /pjproject/trunk/pjmedia/src/pjmedia/vid_port.c
===================================================================
--- /pjproject/trunk/pjmedia/src/pjmedia/vid_port.c	(revision 6084)
+++ /pjproject/trunk/pjmedia/src/pjmedia/vid_port.c	(revision 6085)
@@ -1004,4 +1004,6 @@
                                                 &vp->conv.conv_param.dst);
             if (status != PJ_SUCCESS) {
+		pjmedia_event e;
+
                 PJ_PERROR(3,(THIS_FILE, status,
 		    "failure in changing the format of the video device"));
@@ -1009,4 +1011,13 @@
                                       status != PJMEDIA_EVID_ERR ? "success" :
                                       "failure"));
+
+		pjmedia_event_init(&e, PJMEDIA_EVENT_VID_DEV_ERROR, NULL, vp);
+		e.data.vid_dev_err.dir = vp->dir;
+		e.data.vid_dev_err.status = status;
+		e.data.vid_dev_err.id = (vp->dir==PJMEDIA_DIR_ENCODING?
+					 vid_param.cap_id : vid_param.rend_id);
+		pjmedia_event_publish(NULL, vp, &e,
+				      PJMEDIA_EVENT_PUBLISH_POST_EVENT);
+
                 return status;
             }
Index: /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c
===================================================================
--- /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c	(revision 6084)
+++ /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c	(revision 6085)
@@ -1550,4 +1550,13 @@
 					   w->rend_slot, NULL);
 		}
+	    }
+	    break;
+
+	case PJMEDIA_EVENT_VID_DEV_ERROR:
+	    {
+		PJ_PERROR(3,(THIS_FILE, event->data.vid_dev_err.status,
+			     "Video device id=%d error for call %d",
+			     event->data.vid_dev_err.id,
+			     call->index));
 	    }
 	    break;
