Index: pjproject/trunk/pjmedia/src/pjmedia-videodev/sdl_dev.c
===================================================================
--- pjproject/trunk/pjmedia/src/pjmedia-videodev/sdl_dev.c	(revision 3723)
+++ pjproject/trunk/pjmedia/src/pjmedia-videodev/sdl_dev.c	(revision 3724)
@@ -705,5 +705,10 @@
         if (!((strm->param.flags & PJMEDIA_VID_DEV_CAP_OUTPUT_HIDE) &&
             strm->param.window_hide))
+        {
             flags |= SDL_WINDOW_SHOWN;
+        } else {
+            flags &= ~SDL_WINDOW_SHOWN;
+            flags |= SDL_WINDOW_HIDDEN;
+        }
 
 #if PJMEDIA_VIDEO_DEV_SDL_HAS_OPENGL
Index: pjproject/trunk/pjsip-apps/src/vidgui/vidgui.cpp
===================================================================
--- pjproject/trunk/pjsip-apps/src/vidgui/vidgui.cpp	(revision 3723)
+++ pjproject/trunk/pjsip-apps/src/vidgui/vidgui.cpp	(revision 3724)
@@ -29,4 +29,5 @@
 
 #define LOG_FILE		"vidgui.log"
+#define THIS_FILE		"vidgui.cpp"
 
 // These configure SIP registration
@@ -84,5 +85,5 @@
     /* Right pane */
     vbox_right->addWidget((localUri_ = new QLabel));
-    vbox_right->addWidget((previewButton_=new QPushButton(tr("Start Preview"))));
+    vbox_right->addWidget((previewButton_=new QPushButton(tr("Start &Preview"))));
     vbox_right->addWidget((callButton_=new QPushButton(tr("Call"))));
     vbox_right->addWidget((hangupButton_=new QPushButton(tr("Hangup"))));
@@ -121,5 +122,5 @@
     //statusBar_->showMessage(msg);
     statusBar_->setText(msg);
-    PJ_LOG(3,("vidgui.cpp", "%s", msg));
+    PJ_LOG(3,(THIS_FILE, "%s", msg));
 }
 
@@ -177,5 +178,6 @@
 	pjsua_vid_preview_stop(DEFAULT_CAP_DEV);
 
-	previewButton_->setText(tr("Start Preview"));
+	showStatus("Preview stopped");
+	previewButton_->setText(tr("Start &Preview"));
     } else {
 	pjsua_vid_win_id wid;
@@ -184,6 +186,7 @@
 	pj_status_t status;
 
-	pj_bzero(&pre_param, sizeof(pre_param));
+	pjsua_vid_preview_param_default(&pre_param);
 	pre_param.rend_id = DEFAULT_REND_DEV;
+	pre_param.show = PJ_FALSE;
 
 	status = pjsua_vid_preview_start(DEFAULT_CAP_DEV, &pre_param);
@@ -199,6 +202,12 @@
 	video_prev_ = new VidWin(&wi.hwnd);
 	vbox_left->addWidget(video_prev_, 1);
-
-	previewButton_->setText(tr("Stop Preview"));
+	//Using this will cause SDL window to display blank
+	//screen sometimes, probably because it's using different
+	//X11 Display
+	//status = pjsua_vid_win_set_show(wid, PJ_TRUE);
+	video_prev_->show();
+	showStatus("Preview started");
+
+	previewButton_->setText(tr("Stop &Preview"));
     }
     preview_on = !preview_on;
Index: pjproject/trunk/pjsip-apps/src/vidgui/vidwin.cpp
===================================================================
--- pjproject/trunk/pjsip-apps/src/vidgui/vidwin.cpp	(revision 3723)
+++ pjproject/trunk/pjsip-apps/src/vidgui/vidwin.cpp	(revision 3724)
@@ -141,4 +141,11 @@
 }
 
+void VidWin::show(bool visible)
+{
+    if (!hwnd.info.win.hwnd) return;
+
+    ShowWindow(hwnd.info.win.hwnd, visible ? SW_SHOW : SW_HIDE);
+}
+
 #elif defined(__APPLE__)
 
@@ -204,4 +211,18 @@
 }
 
+void VidWin::show(bool visible)
+{
+    if (!hwnd.info.cocoa.window) return;
+
+    NSWindow *w = (NSWindow*)hwnd.info.cocoa.window;
+
+    if (visible) {
+	if (![w isMiniaturized]) {
+	    [w makeKeyAndOrderFront:nil];
+	}
+    } else {
+	[w orderOut:nil];
+    }
+}
 
 #elif defined(linux) || defined(__linux)
@@ -212,4 +233,7 @@
 #include <stdio.h>
 
+#define GET_DISPLAY()	QX11Info::display()
+//#define GET_DISPLAY()	(Display*)hwnd.info.x11.display
+
 void VidWin::attach()
 {
@@ -221,5 +245,5 @@
     // the window failing to embed to this QWidget.
     //Display *d = (Display*)hwnd.info.x11.display;
-    Display *d = QX11Info::display();
+    Display *d = GET_DISPLAY();
     Window w = (Window)hwnd.info.x11.window;
     Window parent = (Window)this->winId();
@@ -240,5 +264,5 @@
 
     /* Update position and size */
-    Display *d = QX11Info::display();
+    Display *d = GET_DISPLAY();
     Window w = (Window)hwnd.info.x11.window;
     QRect qr = rect();
@@ -253,5 +277,5 @@
     if (!hwnd.info.x11.window) return;
 
-    Display *d = QX11Info::display();
+    Display *d = GET_DISPLAY();
     Window w = (Window)hwnd.info.x11.window;
 
@@ -262,4 +286,20 @@
 }
 
+void VidWin::show(bool visible)
+{
+    if (!hwnd.info.x11.window) return;
+
+    Display *d = GET_DISPLAY();
+    Window w = (Window)hwnd.info.x11.window;
+
+    if (visible) {
+	XMapRaised(d, w);
+    } else {
+	XUnmapWindow(d, w);
+    }
+
+    XFlush(d);
+}
+
 #endif
 
Index: pjproject/trunk/pjsip-apps/src/vidgui/vidwin.h
===================================================================
--- pjproject/trunk/pjsip-apps/src/vidgui/vidwin.h	(revision 3723)
+++ pjproject/trunk/pjsip-apps/src/vidgui/vidwin.h	(revision 3724)
@@ -33,4 +33,5 @@
     virtual ~VidWin();
     QSize sizeHint() const { return size_hint; }
+    void show(bool visible=true);
 
 protected:
Index: pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h
===================================================================
--- pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h	(revision 3723)
+++ pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h	(revision 3724)
@@ -5438,8 +5438,25 @@
      * Device ID for the video renderer to be used for rendering the
      * capture stream for preview.
+     *
+     * Default: PJMEDIA_VID_DEFAULT_RENDER_DEV
      */
     pjmedia_vid_dev_index	rend_id;
+
+    /**
+     * Show window initially.
+     *
+     * Default: PJ_TRUE.
+     */
+    pj_bool_t			show;
+
 } pjsua_vid_preview_param;
 
+
+/**
+ * Initialize pjsua_vid_preview_param
+ *
+ * @param p		The parameter to be initialized.
+ */
+PJ_DECL(void) pjsua_vid_preview_param_default(pjsua_vid_preview_param *p);
 
 /**
@@ -5448,5 +5465,5 @@
  * @param id		The capture device ID where its preview will be
  * 			started.
- * @param prm		Optional video preview parameters. Specify NULL
+ * @param p		Optional video preview parameters. Specify NULL
  * 			to use default values.
  *
@@ -5454,5 +5471,5 @@
  */
 PJ_DECL(pj_status_t) pjsua_vid_preview_start(pjmedia_vid_dev_index id,
-                                             pjsua_vid_preview_param *prm);
+                                             const pjsua_vid_preview_param *p);
 
 /**
Index: pjproject/trunk/pjsip/src/pjsua-lib/pjsua_vid.c
===================================================================
--- pjproject/trunk/pjsip/src/pjsua-lib/pjsua_vid.c	(revision 3723)
+++ pjproject/trunk/pjsip/src/pjsua-lib/pjsua_vid.c	(revision 3724)
@@ -117,4 +117,11 @@
 }
 
+PJ_DEF(void) pjsua_vid_preview_param_default(pjsua_vid_preview_param *p)
+{
+    p->rend_id = PJMEDIA_VID_DEFAULT_RENDER_DEV;
+    p->show = PJ_TRUE;
+}
+
+
 /*****************************************************************************
  * Devices.
@@ -339,17 +346,13 @@
 	if (wid != PJSUA_INVALID_ID) {
 	    /* Yes, it exists */
-
-	    /* Show window if requested */
-	    if (show) {
-		pjmedia_vid_dev_stream *rdr;
-		pj_bool_t hide = PJ_FALSE;
-		
-		rdr = pjmedia_vid_port_get_stream(pjsua_var.win[wid].vp_rend);
-		pj_assert(rdr);
-		status = pjmedia_vid_dev_stream_set_cap(
-					rdr,
-					PJMEDIA_VID_DEV_CAP_OUTPUT_HIDE,
-					&hide);
-	    }
+	    /* Show/hide window */
+	    pjmedia_vid_dev_stream *rdr;
+	    pj_bool_t hide = !show;
+
+	    rdr = pjmedia_vid_port_get_stream(pjsua_var.win[wid].vp_rend);
+	    pj_assert(rdr);
+	    status = pjmedia_vid_dev_stream_set_cap(
+				    rdr, PJMEDIA_VID_DEV_CAP_OUTPUT_HIDE,
+				    &hide);
 
 	    /* Done */
@@ -833,21 +836,23 @@
  */
 PJ_DEF(pj_status_t) pjsua_vid_preview_start(pjmedia_vid_dev_index id,
-                                            pjsua_vid_preview_param *prm)
+                                            const pjsua_vid_preview_param *prm)
 {
     pjsua_vid_win_id wid;
     pjsua_vid_win *w;
     pjmedia_vid_dev_index rend_id;
+    pjsua_vid_preview_param default_param;
     pj_status_t status;
 
     PJSUA_LOCK();
 
-    if (prm) {
-	rend_id = prm->rend_id;
-    } else {
-	rend_id = PJMEDIA_VID_DEFAULT_RENDER_DEV;
-    }
+    if (!prm) {
+	pjsua_vid_preview_param_default(&default_param);
+	prm = &default_param;
+    }
+
+    rend_id = prm->rend_id;
 
     status = create_vid_win(PJSUA_WND_TYPE_PREVIEW, NULL, rend_id, id,
-			    PJ_TRUE, &wid);
+			    prm->show, &wid);
     if (status != PJ_SUCCESS) {
 	PJSUA_UNLOCK();
