]> git.sesse.net Git - vlc/blobdiff - modules/video_output/qte/qte.cpp
Merge branch 1.0-bugfix
[vlc] / modules / video_output / qte / qte.cpp
index f12204f7a87d814e733eca083f011c145b48afda..f91acd7b3eeeda38734d48da33ceae98d7012b00 100644 (file)
@@ -1,11 +1,11 @@
 /*****************************************************************************
  * qte.cpp : QT Embedded plugin for vlc
  *****************************************************************************
- * Copyright (C) 1998-2002 VideoLAN
- * $Id: qte.cpp,v 1.10 2003/02/02 00:46:58 sam Exp $
+ * Copyright (C) 1998-2003 the VideoLAN team
+ * $Id$
  *
- * Authors: Gerald Hansink <gerald.hansink@ordain.nl>
- *          Jean-Paul Saman <jpsaman@wxs.nl>
+ * Authors: Gerald Hansink <gerald.hansink@ordina.nl>
+ *          Jean-Paul Saman <jpsaman _at_ videolan _dot_ org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -19,7 +19,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
 extern "C"
 {
 #include <errno.h>                                                 /* ENOMEM */
-#include <stdlib.h>                                                /* free() */
-#include <string.h>                                                /* strerror() */
 
-#include <vlc/vlc.h>
-#include <vlc/intf.h>
-#include <vlc/vout.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_plugin.h>
+#include <vlc_interface.h>
+#include <vlc_vout.h>
 
 #ifdef HAVE_MACHINE_PARAM_H
     /* BSD */
@@ -71,28 +74,15 @@ extern "C"
 
 extern "C"
 {
-#include "netutils.h"                                 /* network_ChannelJoin */
 #include "qte.h"
 
 /*****************************************************************************
  * Module descriptor
  *****************************************************************************/
-#define ALT_FS_TEXT N_("alternate fullscreen method")
-#define ALT_FS_LONGTEXT N_( \
-    "There are two ways to make a fullscreen window, unfortunately each one " \
-    "has its drawbacks.\n" \
-    "1) Let the window manager handle your fullscreen window (default). But " \
-    "things like taskbars will likely show on top of the video.\n" \
-    "2) Completly bypass the window manager, but then nothing will be able " \
-    "to show on top of the video.")
-#define DISPLAY_TEXT N_("QT Embedded display name")
+#define DISPLAY_TEXT N_("QT Embedded display")
 #define DISPLAY_LONGTEXT N_( \
-    "Specify the Qt Embedded hardware display you want to use. By default VLC will " \
-    "use the value of the DISPLAY environment variable.")
-#define DRAWABLE_TEXT N_("QT Embedded drawable")
-#define DRAWABLE_LONGTEXT N_( \
-    "Specify a QT Embedded drawable to use instead of opening a new window. This " \
-    "option is DANGEROUS, use with care.")
+    "Qt Embedded hardware display to use. " \
+    "By default VLC will use the value of the DISPLAY environment variable.")
 
 /*****************************************************************************
  * Local prototypes
@@ -105,15 +95,15 @@ static int  Manage    ( vout_thread_t * );
 static int  Init      ( vout_thread_t * );
 static void End       ( vout_thread_t * );
 
-static int  CreateQtWindow ( vout_thread_t * );
-static void DestroyQtWindow( vout_thread_t * );
+static int  OpenDisplay ( vout_thread_t * );
+static void CloseDisplay( vout_thread_t * );
 
 static int  NewPicture     ( vout_thread_t *, picture_t * );
 static void FreePicture    ( vout_thread_t *, picture_t * );
 
 static void ToggleFullScreen      ( vout_thread_t * );
 
-static void RunQtThread( event_thread_t *p_event );
+static void* RunQtThread( vlc_object_t *p_this );
 } /* extern "C" */
 
 /*****************************************************************************
@@ -122,16 +112,16 @@ static void RunQtThread( event_thread_t *p_event );
 extern "C"
 {
 
-vlc_module_begin();
-//    add_category_hint( N_("QT Embedded"), NULL );
-//    add_string( "qte-display", "landscape", NULL, DISPLAY_TEXT, DISPLAY_LONGTEXT);
-//    add_bool( "qte-altfullscreen", 0, NULL, ALT_FS_TEXT, ALT_FS_LONGTEXT);
-//    add_integer( "qte-drawable", -1, NULL, NULL, NULL); //DRAWABLE_TEXT, DRAWABLE_LONGTEXT );
-    set_description( _("QT Embedded module") );
-    set_capability( "video output", 30 );
-//    add_shortcut( "qte" );
-    set_callbacks( Open, Close);
-vlc_module_end();
+vlc_module_begin ()
+    set_category( CAT_VIDEO )
+    set_subcategory( SUBCAT_VIDEO_VOUT )
+//    add_category_hint( N_("QT Embedded"), NULL )
+//    add_string( "qte-display", "landscape", NULL, DISPLAY_TEXT, DISPLAY_LONGTEXT)
+    set_description( N_("QT Embedded video output") )
+    set_capability( "video output", 70 )
+    add_shortcut( "qte" )
+    set_callbacks( Open, Close)
+vlc_module_end ()
 
 } /* extern "C" */
 
@@ -153,20 +143,17 @@ static int Open( vlc_object_t *p_this )
     p_vout->p_sys = (struct vout_sys_t*) malloc( sizeof( struct vout_sys_t ) );
 
     if( p_vout->p_sys == NULL )
-    {
-        msg_Err( p_vout, "out of memory" );
         return( 1 );
-    }
 
-//    memset(p_vout->p_sys, 0, sizeof( struct vout_sys_t ));
     p_vout->pf_init    = Init;
     p_vout->pf_end     = End;
-    p_vout->pf_manage  = NULL; //Manage;
+    p_vout->pf_manage  = Manage;
     p_vout->pf_render  = NULL; //Render;
     p_vout->pf_display = Display;
 
 #ifdef NEED_QTE_MAIN
-    p_vout->p_sys->p_qte_main = module_Need( p_this, "qte_main", "qte" );
+    p_vout->p_sys->p_qte_main =
+        module_need( p_this, "gui-helper", "qte", true );
     if( p_vout->p_sys->p_qte_main == NULL )
     {
         free( p_vout->p_sys );
@@ -174,7 +161,12 @@ static int Open( vlc_object_t *p_this )
     }
 #endif
 
-    CreateQtWindow(p_vout);
+    if (OpenDisplay(p_vout))
+    {
+        msg_Err( p_vout, "Cannot set up qte video output" );
+        Close(p_this);
+        return( -1 );
+    }
     return( 0 );
 }
 
@@ -187,21 +179,22 @@ static void Close ( vlc_object_t *p_this )
 {
     vout_thread_t * p_vout = (vout_thread_t *)p_this;
 
-    msg_Err( p_vout, "Close" );
+    msg_Dbg( p_vout, "close" );
     if( p_vout->p_sys->p_event )
     {
         vlc_object_detach( p_vout->p_sys->p_event );
 
         /* Kill RunQtThread */
-        p_vout->p_sys->p_event->b_die = VLC_TRUE;
-        DestroyQtWindow(p_vout);
+        vlc_object_kill( p_vout->p_sys->p_event );
+        CloseDisplay(p_vout);
 
         vlc_thread_join( p_vout->p_sys->p_event );
-        vlc_object_destroy( p_vout->p_sys->p_event );
+        vlc_object_release( p_vout->p_sys->p_event );
     }
 
 #ifdef NEED_QTE_MAIN
-    module_Unneed( p_vout, p_vout->p_sys->p_qte_main );
+    msg_Dbg( p_vout, "releasing gui-helper" );
+    module_unneed( p_vout, p_vout->p_sys->p_qte_main );
 #endif
 
     if( p_vout->p_sys )
@@ -225,17 +218,27 @@ static int Init( vout_thread_t *p_vout )
 
     I_OUTPUTPICTURES = 0;
 
-    p_vout->output.i_chroma = (dd == 16) ? VLC_FOURCC('R','V','1','6'): VLC_FOURCC('R','V','3','2');
+    p_vout->output.i_chroma = (dd == 16) ? VLC_CODEC_RGB16 : VLC_CODEC_RGB32;
     p_vout->output.i_rmask  = 0xf800;
     p_vout->output.i_gmask  = 0x07e0;
     p_vout->output.i_bmask  = 0x001f;
 
-    /* We may need to convert the chroma, but at least we keep the
-     * aspect ratio */
+    /* All we have is an RGB image with square pixels */
     p_vout->output.i_width  = p_vout->p_sys->i_width;
     p_vout->output.i_height = p_vout->p_sys->i_height;
-    p_vout->output.i_aspect = p_vout->render.i_aspect;
-
+    if( !p_vout->b_fullscreen )
+    {
+        p_vout->output.i_aspect = p_vout->output.i_width
+                                   * VOUT_ASPECT_FACTOR
+                                   / p_vout->output.i_height;
+    }
+    else
+    {
+        p_vout->output.i_aspect = p_vout->render.i_aspect;
+    }
+#if 0
+    msg_Dbg( p_vout, "Init (h=%d,w=%d,aspect=%d)",p_vout->output.i_height,p_vout->output.i_width,p_vout->output.i_aspect );
+#endif
     /* Try to initialize MAX_DIRECTBUFFERS direct buffers */
     while( I_OUTPUTPICTURES < QTE_MAX_DIRECTBUFFERS )
     {
@@ -286,17 +289,19 @@ static void Display( vout_thread_t *p_vout, picture_t *p_pic )
 {
     unsigned int x, y, w, h;
 
-    vout_PlacePicture( p_vout, p_vout->p_sys->i_width, p_vout->p_sys->i_height,
+    vout_PlacePicture( p_vout, p_vout->output.i_width, p_vout->output.i_height,
                        &x, &y, &w, &h );
+#if 0
+    msg_Dbg(p_vout, "+qte::Display( p_vout, i_width=%d, i_height=%d, x=%u, y=%u, w=%u, h=%u",
+        p_vout->output.i_width, p_vout->output.i_height, x, y, w, h );
+#endif
 
-    msg_Err(p_vout, "+qte::Display( p_vout, i_width=%d, i_height=%d, x=%u, y=%u, w=%u, h=%u",
-                                       p_vout->p_sys->i_width, p_vout->p_sys->i_height, x, y, w, h );
-
-    if(p_vout->p_sys->pcVoutWidget)
+    if(p_vout->p_sys->p_VideoWidget)
     {
 // shameless borrowed from opie mediaplayer....
 #ifndef USE_DIRECT_PAINTER
-        QPainter p(p_vout->p_sys->pcVoutWidget);
+        msg_Dbg(p_vout, "not using direct painter");
+        QPainter p(p_vout->p_sys->p_VideoWidget);
 
         /* rotate frame */
         int dd      = QPixmap::defaultDepth();
@@ -333,25 +338,67 @@ static void Display( vout_thread_t *p_vout, picture_t *p_pic )
 
         p.drawImage( x, y, rotatedFrame, 0, 0, rw, rh );
 #else
-        QDirectPainter p(p_vout->p_sys->pcVoutWidget);
-
+        QDirectPainter p(p_vout->p_sys->p_VideoWidget);
+        p.transformOrientation();
         // just copy the image to the frame buffer...
         memcpy(p.frameBuffer(), (p_pic->p_sys->pQImage->jumpTable())[0], h * p.lineStep());
 #endif
     }
-    msg_Err(p_vout, "-qte::Display" );
-
 }
 
 /*****************************************************************************
- * Manage: handle X11 events
+ * Manage: handle Qte events
  *****************************************************************************
  * This function should be called regularly by video output thread. It manages
- * X11 events and allows window resizing. It returns a non null value on
+ * Qte events and allows window resizing. It returns a non null value on
  * error.
  *****************************************************************************/
 static int Manage( vout_thread_t *p_vout )
 {
+//    msg_Dbg( p_vout, "Manage" );
+
+    /* Fullscreen change */
+    if( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE )
+    {
+        p_vout->b_fullscreen = ! p_vout->b_fullscreen;
+
+//        p_vout->p_sys->b_cursor_autohidden = 0;
+//        SDL_ShowCursor( p_vout->p_sys->b_cursor &&
+//                        ! p_vout->p_sys->b_cursor_autohidden );
+
+        p_vout->i_changes &= ~VOUT_FULLSCREEN_CHANGE;
+        p_vout->i_changes |= VOUT_SIZE_CHANGE;
+    }
+
+    /*
+     * Size change
+     */
+    if( p_vout->i_changes & VOUT_SIZE_CHANGE )
+    {
+        msg_Dbg( p_vout, "video display resized (%dx%d)",
+                 p_vout->p_sys->i_width, p_vout->p_sys->i_height );
+
+        CloseDisplay( p_vout );
+        OpenDisplay( p_vout );
+
+        /* We don't need to signal the vout thread about the size change if
+         * we can handle rescaling ourselves */
+        p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
+    }
+
+    /* Pointer change */
+//    if( ! p_vout->p_sys->b_cursor_autohidden &&
+//        ( mdate() - p_vout->p_sys->i_lastmoved >
+//            p_vout->p_sys->i_mouse_hide_timeout ) )
+//    {
+//        /* Hide the mouse automatically */
+//        p_vout->p_sys->b_cursor_autohidden = 1;
+//        SDL_ShowCursor( 0 );
+//    }
+//
+//    if( !vlc_object_alive (p_vout->p_libvlc) )
+//        p_vout->p_sys->bRunning = FALSE;
+
     return 0;
 }
 
@@ -383,81 +430,46 @@ static int NewPicture( vout_thread_t *p_vout, picture_t *p_pic )
 {
     int dd = QPixmap::defaultDepth();
 
-    msg_Dbg(p_vout, "+NewPicture::dd = %d",dd );
-
     p_pic->p_sys = (picture_sys_t*) malloc( sizeof( picture_sys_t ) );
-
     if( p_pic->p_sys == NULL )
     {
         return -1;
     }
 
-    switch(p_vout->output.i_chroma)
-    {
-    case VLC_FOURCC('R','V','1','6'):
-        if(dd == 16)
-        {
-            p_pic->p_sys->pQImage = new QImage(p_vout->output.i_width,
-                                               p_vout->output.i_height,
-                                               dd );
-
-            if(p_pic->p_sys->pQImage == NULL)
-            {
-                return -1;
-            }
-
-            p_pic->p->p_pixels = (p_pic->p_sys->pQImage->jumpTable())[0];
-
-            p_pic->p->i_pitch = p_pic->p_sys->pQImage->bytesPerLine();
-
-            p_pic->p->i_lines = p_vout->output.i_height;
-            p_pic->p->i_pixel_pitch   = 2;
-            p_pic->p->i_visible_pitch = 0;
-//            p_pic->p->i_pixel_bytes = 2;
-//            p_pic->p->b_margin      = 0;
-            p_pic->i_planes         = 1;
-        }
-        else
-        {
-            return -1;
-        }
-        break;
-    case VLC_FOURCC('R','V','3','2'):
-        if(dd == 32)
-        {
-            p_pic->p_sys->pQImage = new QImage(p_vout->output.i_width,
-                                               p_vout->output.i_height,
-                                               dd );
-
-            if(p_pic->p_sys->pQImage == NULL)
-            {
-                return -1;
-            }
+    /* Create the display */
+    p_pic->p_sys->pQImage = new QImage(p_vout->output.i_width,
+                                       p_vout->output.i_height, dd );
 
-            p_pic->p->p_pixels = (p_pic->p_sys->pQImage->jumpTable())[0];
-
-            p_pic->p->i_pitch = p_pic->p_sys->pQImage->bytesPerLine();
-
-            p_pic->p->i_lines = p_vout->output.i_height;
-            p_pic->p->i_pixel_pitch   = 4;
-            p_pic->p->i_visible_pitch = 0;
-//            p_pic->p->i_pixel_bytes = 4;
-//            p_pic->p->b_margin      = 0;
-            p_pic->i_planes         = 1;
-        }
-        else
-        {
-            return -1;
-        }
-        break;
-    default:
+    if(p_pic->p_sys->pQImage == NULL)
+    {
         return -1;
-        break;
     }
 
-    msg_Dbg(p_vout, "-NewPicture: %d %d %d",p_vout->output.i_width,
-                                 p_vout->output.i_height,
-                                 p_vout->output.i_chroma );
+    switch( dd )
+    {
+        case 8:
+            p_pic->p->i_pixel_pitch = 1;
+            break;
+        case 15:
+        case 16:
+            p_pic->p->i_pixel_pitch = 2;
+            break;
+        case 24:
+        case 32:
+            p_pic->p->i_pixel_pitch = 4;
+            break;
+        default:
+            return( -1 );
+    }
+
+    p_pic->p->p_pixels = (p_pic->p_sys->pQImage->jumpTable())[0];
+    p_pic->p->i_pitch = p_pic->p_sys->pQImage->bytesPerLine();
+    p_pic->p->i_lines = p_vout->output.i_height;
+    p_pic->p->i_visible_lines = p_vout->output.i_height;
+    p_pic->p->i_visible_pitch =
+            p_pic->p->i_pixel_pitch * p_vout->output.i_width;
+
+    p_pic->i_planes = 1;
 
     return 0;
 }
@@ -478,152 +490,187 @@ static void FreePicture( vout_thread_t *p_vout, picture_t *p_pic )
  *****************************************************************************/
 static void ToggleFullScreen ( vout_thread_t *p_vout )
 {
-}
+    if ( p_vout->b_fullscreen )
+       p_vout->p_sys->p_VideoWidget->showFullScreen();
+    else
+       p_vout->p_sys->p_VideoWidget->showNormal();
 
+    p_vout->b_fullscreen = !p_vout->b_fullscreen;
+}
 
 /*****************************************************************************
- * CreateQtWindow: create qte applicaton / window
+ * OpenDisplay: create qte applicaton / window
  *****************************************************************************
  * Create a window according to video output given size, and set other
  * properties according to the display properties.
  *****************************************************************************/
-static int CreateQtWindow( vout_thread_t *p_vout )
+static int OpenDisplay( vout_thread_t *p_vout )
 {
     /* for displaying the vout in a qt window we need the QtApplication */
-    p_vout->p_sys->pcVoutWidget = NULL;
-    msg_Dbg( p_vout, "creating RunQtThread" );
+    p_vout->p_sys->p_QApplication = NULL;
+    p_vout->p_sys->p_VideoWidget = NULL;
 
     p_vout->p_sys->p_event = (event_thread_t*) vlc_object_create( p_vout, sizeof(event_thread_t) );
     p_vout->p_sys->p_event->p_vout = p_vout;
 
     /* Initializations */
-    p_vout->p_sys->i_width  = 320;
-    p_vout->p_sys->i_height = 240;
+#if 1 /* FIXME: I need an event queue to handle video output size changes. */
+    p_vout->b_fullscreen = true;
+#endif
+
+    /* Set main window's size */
+    QWidget *desktop = p_vout->p_sys->p_QApplication->desktop();
+    p_vout->p_sys->i_width = p_vout->b_fullscreen ? desktop->height() :
+                                                    p_vout->i_window_width;
+    p_vout->p_sys->i_height = p_vout->b_fullscreen ? desktop->width() :
+                                                     p_vout->i_window_height;
+
+#if 0 /* FIXME: I need an event queue to handle video output size changes. */
+    /* Update dimensions */
+    p_vout->i_changes |= VOUT_SIZE_CHANGE;
+    p_vout->i_window_width = p_vout->p_sys->i_width;
+    p_vout->i_window_height = p_vout->p_sys->i_height;
+#endif
+
+    msg_Dbg( p_vout, "opening display (h=%d,w=%d)",p_vout->p_sys->i_height,p_vout->p_sys->i_width);
 
     /* create thread to exec the qpe application */
     if ( vlc_thread_create( p_vout->p_sys->p_event, "QT Embedded Thread",
-                                                       RunQtThread,
-                            VLC_THREAD_PRIORITY_OUTPUT, VLC_TRUE) )
+                            RunQtThread,
+                            VLC_THREAD_PRIORITY_OUTPUT, true) )
     {
         msg_Err( p_vout, "cannot create QT Embedded Thread" );
-        vlc_object_destroy( p_vout->p_sys->p_event );
+        vlc_object_release( p_vout->p_sys->p_event );
         p_vout->p_sys->p_event = NULL;
-        goto error;
+        return -1;
     }
 
     if( p_vout->p_sys->p_event->b_error )
     {
         msg_Err( p_vout, "RunQtThread failed" );
-        goto error;
+        return -1;
     }
 
     vlc_object_attach( p_vout->p_sys->p_event, p_vout );
     msg_Dbg( p_vout, "RunQtThread running" );
 
     // just wait until the crew is complete...
-    while(p_vout->p_sys->pcVoutWidget == NULL)
+    while(p_vout->p_sys->p_VideoWidget == NULL)
     {
         msleep(1);
     }
-
     return VLC_SUCCESS;
-
- error:
-    Close( VLC_OBJECT(p_vout) );
-    return VLC_EGENERIC;
 }
 
 
 /*****************************************************************************
- * DestroyQtWindow: destroy the window
+ * CloseDisplay: destroy the window
  *****************************************************************************/
-static void DestroyQtWindow( vout_thread_t *p_vout )
+static void CloseDisplay( vout_thread_t *p_vout )
 {
     // quit qt application loop
-    if(p_vout->p_sys->pcQApplication)
+    msg_Dbg( p_vout, "destroying Qt Window" );
+#ifdef NEED_QTE_MAIN
+    if(p_vout->p_sys->p_QApplication)
     {
-#ifndef NEED_QTE_MAIN
-        if(p_vout->p_sys->bOwnsQApp)
-        {
-            p_vout->p_sys->pcQApplication->quit();
-        }
-        else
-#endif
-            p_vout->p_sys->bRunning = FALSE;
-
-        while(p_vout->p_sys->pcVoutWidget)
+        p_vout->p_sys->bRunning = FALSE;
+        while(p_vout->p_sys->p_VideoWidget)
         {
             msleep(1);
         }
     }
+#else
+    if (p_vout->p_sys->p_QApplication)
+       p_vout->p_sys->p_QApplication->quit();
+#endif
 }
 
 /*****************************************************************************
  * main loop of qtapplication
  *****************************************************************************/
-static void RunQtThread(event_thread_t *p_event)
+static void* RunQtThread( vlc_object_t *p_this )
 {
-    int     argc    = 0;
-
-    msg_Dbg( p_event->p_vout, "+qte::RunQtThread" );
+    event_thread_t *p_event = (event_thread_t *)p_this;
+    int canc = vlc_savecancel ();
+    msg_Dbg( p_event->p_vout, "RunQtThread starting" );
 
-    if(qApp == NULL)
+#ifdef NEED_QTE_MAIN
+    if (qApp)
+    {
+        p_event->p_vout->p_sys->p_QApplication = qApp;
+        p_event->p_vout->p_sys->bOwnsQApp = FALSE;
+        p_event->p_vout->p_sys->p_VideoWidget = qApp->mainWidget();
+        msg_Dbg( p_event->p_vout, "RunQtThread applicaton attached" );
+    }
+#else
+    if (qApp==NULL)
     {
+        int argc = 0;
         QApplication* pApp = new QApplication(argc, NULL);
         if(pApp)
         {
-            p_event->p_vout->p_sys->pcQApplication = pApp;
+            p_event->p_vout->p_sys->p_QApplication = pApp;
             p_event->p_vout->p_sys->bOwnsQApp = TRUE;
         }
-        msg_Dbg( p_event->p_vout, "RunQtThread application created" );
-    }
-    else
-    {
-        p_event->p_vout->p_sys->pcQApplication = qApp;
-        p_event->p_vout->p_sys->bOwnsQApp = FALSE;
-        msg_Dbg( p_event->p_vout, "RunQtThread applicaton attached" );
+        QWidget* pWidget = new QWidget();
+        if (pWidget)
+            {
+            p_event->p_vout->p_sys->p_VideoWidget = pWidget;
+        }
     }
-
+#endif
     /* signal the creation of the window */
     vlc_thread_ready( p_event );
-    msg_Dbg( p_event->p_vout, "+qte::RunQtThread ready" );
+    msg_Dbg( p_event->p_vout, "RunQtThread ready" );
 
-    if (p_event->p_vout->p_sys->pcQApplication)
+    if (p_event->p_vout->p_sys->p_QApplication)
     {
-        QWidget vo(0, "qte");
-        vo.showFullScreen();
-        vo.show();
-        p_event->p_vout->p_sys->pcVoutWidget = &vo;
+        /* Set default window width and heigh to exactly preferred size. */
+            QWidget *desktop = p_event->p_vout->p_sys->p_QApplication->desktop();
+            p_event->p_vout->p_sys->p_VideoWidget->setMinimumWidth( 10 );
+             p_event->p_vout->p_sys->p_VideoWidget->setMinimumHeight( 10 );
+            p_event->p_vout->p_sys->p_VideoWidget->setBaseSize( p_event->p_vout->p_sys->i_width,
+            p_event->p_vout->p_sys->i_height );
+        p_event->p_vout->p_sys->p_VideoWidget->setMaximumWidth( desktop->width() );
+        p_event->p_vout->p_sys->p_VideoWidget->setMaximumHeight( desktop->height() );
+        /* Check on fullscreen */
+        if (p_event->p_vout->b_fullscreen)
+                  p_event->p_vout->p_sys->p_VideoWidget->showFullScreen();
+        else
+                p_event->p_vout->p_sys->p_VideoWidget->showNormal();
+
+        p_event->p_vout->p_sys->p_VideoWidget->show();
         p_event->p_vout->p_sys->bRunning = TRUE;
 
-        if(p_event->p_vout->p_sys->bOwnsQApp)
-        {
-            // run the main loop of qtapplication until someone says: 'quit'
-            msg_Dbg( p_event->p_vout, "+qte::RunQtThread starting application" );
-            p_event->p_vout->p_sys->pcQApplication->exec();
-        }
-        else
-        {
-            while(!p_event->b_die && p_event->p_vout->p_sys->bRunning)
-                       {
-                  /* Check if we are asked to exit */
-               if( p_event->b_die )
-                   break;
-
-                               msleep(100);
-                       }
-        }
-    }
+#ifdef NEED_QTE_MAIN
+        while(vlc_object_alive (p_event) && p_event->p_vout->p_sys->bRunning)
+              {
+               /* Check if we are asked to exit */
+           if( !vlc_object_alive (p_event) )
+               break;
 
-    p_event->p_vout->p_sys->pcVoutWidget = NULL;
+               msleep(100);
+            }
+#else
+        // run the main loop of qtapplication until someone says: 'quit'
+        p_event->p_vout->p_sys->pcQApplication->exec();
+#endif
+    }
 
-    if(p_event->p_vout->p_sys->bOwnsQApp)
+#ifndef NEED_QTE_MAIN
+    if(p_event->p_vout->p_sys->p_QApplication)
     {
-        msg_Dbg( p_event->p_vout, "+qte::RunQtThread deleting application" );
-        delete p_event->p_vout->p_sys->pcQApplication;
-        p_event->p_vout->p_sys->pcQApplication = NULL;
+        delete p_event->p_vout->p_sys->p_VideoWidget;
+        p_event->p_vout->p_sys->p_VideoWidget = NULL;
+        delete p_event->p_vout->p_sys->p_QApplication;
+        p_event->p_vout->p_sys->p_QApplication = NULL;
     }
+#else
+    p_event->p_vout->p_sys->p_VideoWidget = NULL;
+#endif
 
-    msg_Dbg( p_event->p_vout, "-qte::RunQtThread terminating" );
+    msg_Dbg( p_event->p_vout, "RunQtThread terminating" );
+    vlc_restorecancel (canc);
+    return NULL;
 }