qte.cpp
上传用户:kjfoods
上传日期:2020-07-06
资源大小:29949k
文件大小:22k
源码类别:

midi

开发平台:

Unix_Linux

  1. /*****************************************************************************
  2.  * qte.cpp : QT Embedded plugin for vlc
  3.  *****************************************************************************
  4.  * Copyright (C) 1998-2003 the VideoLAN team
  5.  * $Id: 1c310bc5a494d4e9dda8f25928c0d955bc8680a0 $
  6.  *
  7.  * Authors: Gerald Hansink <gerald.hansink@ordina.nl>
  8.  *          Jean-Paul Saman <jpsaman _at_ videolan _dot_ org>
  9.  *
  10.  * This program is free software; you can redistribute it and/or modify
  11.  * it under the terms of the GNU General Public License as published by
  12.  * the Free Software Foundation; either version 2 of the License, or
  13.  * (at your option) any later version.
  14.  *
  15.  * This program is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  * GNU General Public License for more details.
  19.  *
  20.  * You should have received a copy of the GNU General Public License
  21.  * along with this program; if not, write to the Free Software
  22.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  23.  *****************************************************************************/
  24. /*****************************************************************************
  25.  * Preamble
  26.  *****************************************************************************/
  27. /*****************************************************************************
  28.  * notes:
  29.  * - written for ipaq, so hardcoded assumptions specific for ipaq...
  30.  * - runs full screen
  31.  * - no "mouse events" handling
  32.  * - etc.
  33.  *****************************************************************************/
  34. extern "C"
  35. {
  36. #include <errno.h>                                                 /* ENOMEM */
  37. #ifdef HAVE_CONFIG_H
  38. # include "config.h"
  39. #endif
  40. #include <vlc_common.h>
  41. #include <vlc_plugin.h>
  42. #include <vlc_interface.h>
  43. #include <vlc_vout.h>
  44. #ifdef HAVE_MACHINE_PARAM_H
  45.     /* BSD */
  46. #   include <machine/param.h>
  47. #   include <sys/types.h>                                  /* typedef ushort */
  48. #   include <sys/ipc.h>
  49. #endif
  50. #ifndef WIN32
  51. #   include <netinet/in.h>                            /* BSD: struct in_addr */
  52. #endif
  53. #ifdef HAVE_SYS_SHM_H
  54. #   include <sys/shm.h>                                /* shmget(), shmctl() */
  55. #endif
  56. } /* extern "C" */
  57. #include <qapplication.h>
  58. #include <qpainter.h>
  59. #ifdef Q_WS_QWS
  60. #   define USE_DIRECT_PAINTER
  61. #   include <qdirectpainter_qws.h>
  62. #   include <qgfxraster_qws.h>
  63. #endif
  64. extern "C"
  65. {
  66. #include "qte.h"
  67. /*****************************************************************************
  68.  * Module descriptor
  69.  *****************************************************************************/
  70. #define DISPLAY_TEXT N_("QT Embedded display")
  71. #define DISPLAY_LONGTEXT N_( 
  72.     "Qt Embedded hardware display to use. " 
  73.     "By default VLC will use the value of the DISPLAY environment variable.")
  74. /*****************************************************************************
  75.  * Local prototypes
  76.  *****************************************************************************/
  77. static int  Open      ( vlc_object_t * );
  78. static void Close     ( vlc_object_t * );
  79. static void Render    ( vout_thread_t *, picture_t * );
  80. static void Display   ( vout_thread_t *, picture_t * );
  81. static int  Manage    ( vout_thread_t * );
  82. static int  Init      ( vout_thread_t * );
  83. static void End       ( vout_thread_t * );
  84. static int  OpenDisplay ( vout_thread_t * );
  85. static void CloseDisplay( vout_thread_t * );
  86. static int  NewPicture     ( vout_thread_t *, picture_t * );
  87. static void FreePicture    ( vout_thread_t *, picture_t * );
  88. static void ToggleFullScreen      ( vout_thread_t * );
  89. static void* RunQtThread( vlc_object_t *p_this );
  90. } /* extern "C" */
  91. /*****************************************************************************
  92. * Exported prototypes
  93. *****************************************************************************/
  94. extern "C"
  95. {
  96. vlc_module_begin ()
  97.     set_category( CAT_VIDEO )
  98.     set_subcategory( SUBCAT_VIDEO_VOUT )
  99. //    add_category_hint( N_("QT Embedded"), NULL )
  100. //    add_string( "qte-display", "landscape", NULL, DISPLAY_TEXT, DISPLAY_LONGTEXT)
  101.     set_description( N_("QT Embedded video output") )
  102.     set_capability( "video output", 70 )
  103.     add_shortcut( "qte" )
  104.     set_callbacks( Open, Close)
  105. vlc_module_end ()
  106. } /* extern "C" */
  107. /*****************************************************************************
  108.  * Seeking function TODO: put this in a generic location !
  109.  *****************************************************************************/
  110. static inline void vout_Seek( off_t i_seek )
  111. {
  112. }
  113. /*****************************************************************************
  114.  * Open: allocate video thread output method
  115.  *****************************************************************************/
  116. static int Open( vlc_object_t *p_this )
  117. {
  118.     vout_thread_t * p_vout = (vout_thread_t *)p_this;
  119.     /* Allocate structure */
  120.     p_vout->p_sys = (struct vout_sys_t*) malloc( sizeof( struct vout_sys_t ) );
  121.     if( p_vout->p_sys == NULL )
  122.         return( 1 );
  123.     p_vout->pf_init    = Init;
  124.     p_vout->pf_end     = End;
  125.     p_vout->pf_manage  = Manage;
  126.     p_vout->pf_render  = NULL; //Render;
  127.     p_vout->pf_display = Display;
  128. #ifdef NEED_QTE_MAIN
  129.     p_vout->p_sys->p_qte_main =
  130.         module_need( p_this, "gui-helper", "qte", true );
  131.     if( p_vout->p_sys->p_qte_main == NULL )
  132.     {
  133.         free( p_vout->p_sys );
  134.         return VLC_ENOMOD;
  135.     }
  136. #endif
  137.     if (OpenDisplay(p_vout))
  138.     {
  139.         msg_Err( p_vout, "Cannot set up qte video output" );
  140.         Close(p_this);
  141.         return( -1 );
  142.     }
  143.     return( 0 );
  144. }
  145. /*****************************************************************************
  146.  * CloseVideo: destroy Sys video thread output method
  147.  *****************************************************************************
  148.  * Terminate an output method created by Open
  149.  *****************************************************************************/
  150. static void Close ( vlc_object_t *p_this )
  151. {
  152.     vout_thread_t * p_vout = (vout_thread_t *)p_this;
  153.     msg_Dbg( p_vout, "close" );
  154.     if( p_vout->p_sys->p_event )
  155.     {
  156.         vlc_object_detach( p_vout->p_sys->p_event );
  157.         /* Kill RunQtThread */
  158.         vlc_object_kill( p_vout->p_sys->p_event );
  159.         CloseDisplay(p_vout);
  160.         vlc_thread_join( p_vout->p_sys->p_event );
  161.         vlc_object_release( p_vout->p_sys->p_event );
  162.     }
  163. #ifdef NEED_QTE_MAIN
  164.     msg_Dbg( p_vout, "releasing gui-helper" );
  165.     module_unneed( p_vout, p_vout->p_sys->p_qte_main );
  166. #endif
  167.     if( p_vout->p_sys )
  168.     {
  169.         free( p_vout->p_sys );
  170.         p_vout->p_sys = NULL;
  171.     }
  172. }
  173. /*****************************************************************************
  174.  * Init: initialize video thread output method
  175.  *****************************************************************************
  176.  * This function create the buffers needed by the output thread. It is called
  177.  * at the beginning of the thread, but also each time the window is resized.
  178.  *****************************************************************************/
  179. static int Init( vout_thread_t *p_vout )
  180. {
  181.     int         i_index;
  182.     picture_t*  p_pic;
  183.     int         dd = QPixmap::defaultDepth();
  184.     I_OUTPUTPICTURES = 0;
  185.     p_vout->output.i_chroma = (dd == 16) ? VLC_FOURCC('R','V','1','6'): VLC_FOURCC('R','V','3','2');
  186.     p_vout->output.i_rmask  = 0xf800;
  187.     p_vout->output.i_gmask  = 0x07e0;
  188.     p_vout->output.i_bmask  = 0x001f;
  189.     /* All we have is an RGB image with square pixels */
  190.     p_vout->output.i_width  = p_vout->p_sys->i_width;
  191.     p_vout->output.i_height = p_vout->p_sys->i_height;
  192.     if( !p_vout->b_fullscreen )
  193.     {
  194.         p_vout->output.i_aspect = p_vout->output.i_width
  195.                                    * VOUT_ASPECT_FACTOR
  196.                                    / p_vout->output.i_height;
  197.     }
  198.     else
  199.     {
  200.         p_vout->output.i_aspect = p_vout->render.i_aspect;
  201.     }
  202. #if 0
  203.     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 );
  204. #endif
  205.     /* Try to initialize MAX_DIRECTBUFFERS direct buffers */
  206.     while( I_OUTPUTPICTURES < QTE_MAX_DIRECTBUFFERS )
  207.     {
  208.         p_pic = NULL;
  209.         /* Find an empty picture slot */
  210.         for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
  211.         {
  212.             if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
  213.             {
  214.                 p_pic = p_vout->p_picture + i_index;
  215.                 break;
  216.             }
  217.         }
  218.         /* Allocate the picture */
  219.         if( p_pic == NULL ||  NewPicture( p_vout, p_pic ) )
  220.         {
  221.             break;
  222.         }
  223.         p_pic->i_status = DESTROYED_PICTURE;
  224.         p_pic->i_type   = DIRECT_PICTURE;
  225.         PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
  226.         I_OUTPUTPICTURES++;
  227.     }
  228.     return( 0 );
  229. }
  230. /*****************************************************************************
  231.  * Render: render previously calculated output
  232.  *****************************************************************************/
  233. static void Render( vout_thread_t *p_vout, picture_t *p_pic )
  234. {
  235.     ;
  236. }
  237. /*****************************************************************************
  238.  * Display: displays previously rendered output
  239.  *****************************************************************************
  240.  * This function sends the currently rendered image to screen.
  241.  *****************************************************************************/
  242. static void Display( vout_thread_t *p_vout, picture_t *p_pic )
  243. {
  244.     unsigned int x, y, w, h;
  245.     vout_PlacePicture( p_vout, p_vout->output.i_width, p_vout->output.i_height,
  246.                        &x, &y, &w, &h );
  247. #if 0
  248.     msg_Dbg(p_vout, "+qte::Display( p_vout, i_width=%d, i_height=%d, x=%u, y=%u, w=%u, h=%u",
  249.         p_vout->output.i_width, p_vout->output.i_height, x, y, w, h );
  250. #endif
  251.     if(p_vout->p_sys->p_VideoWidget)
  252.     {
  253. // shameless borrowed from opie mediaplayer....
  254. #ifndef USE_DIRECT_PAINTER
  255.         msg_Dbg(p_vout, "not using direct painter");
  256.         QPainter p(p_vout->p_sys->p_VideoWidget);
  257.         /* rotate frame */
  258.         int dd      = QPixmap::defaultDepth();
  259.         int bytes   = ( dd == 16 ) ? 2 : 4;
  260.         int rw = h, rh = w;
  261.         QImage rotatedFrame( rw, rh, bytes << 3 );
  262.         ushort* in  = (ushort*)p_pic->p_sys->pQImage->bits();
  263.         ushort* out = (ushort*)rotatedFrame.bits();
  264.         int spl = rotatedFrame.bytesPerLine() / bytes;
  265.         for (int x=0; x<h; x++)
  266.         {
  267.             if ( bytes == 2 )
  268.             {
  269.                 ushort* lout = out++ + (w - 1)*spl;
  270.                 for (int y=0; y<w; y++)
  271.                 {
  272.                     *lout=*in++;
  273.                     lout-=spl;
  274.                 }
  275.             }
  276.             else
  277.             {
  278.                 ulong* lout = ((ulong *)out)++ + (w - 1)*spl;
  279.                 for (int y=0; y<w; y++)
  280.                 {
  281.                     *lout=*((ulong*)in)++;
  282.                     lout-=spl;
  283.                 }
  284.             }
  285.         }
  286.         p.drawImage( x, y, rotatedFrame, 0, 0, rw, rh );
  287. #else
  288.         QDirectPainter p(p_vout->p_sys->p_VideoWidget);
  289.         p.transformOrientation();
  290.         // just copy the image to the frame buffer...
  291.         memcpy(p.frameBuffer(), (p_pic->p_sys->pQImage->jumpTable())[0], h * p.lineStep());
  292. #endif
  293.     }
  294. }
  295. /*****************************************************************************
  296.  * Manage: handle Qte events
  297.  *****************************************************************************
  298.  * This function should be called regularly by video output thread. It manages
  299.  * Qte events and allows window resizing. It returns a non null value on
  300.  * error.
  301.  *****************************************************************************/
  302. static int Manage( vout_thread_t *p_vout )
  303. {
  304. //    msg_Dbg( p_vout, "Manage" );
  305.     /* Fullscreen change */
  306.     if( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE )
  307.     {
  308.         p_vout->b_fullscreen = ! p_vout->b_fullscreen;
  309. //        p_vout->p_sys->b_cursor_autohidden = 0;
  310. //        SDL_ShowCursor( p_vout->p_sys->b_cursor &&
  311. //                        ! p_vout->p_sys->b_cursor_autohidden );
  312.         p_vout->i_changes &= ~VOUT_FULLSCREEN_CHANGE;
  313.         p_vout->i_changes |= VOUT_SIZE_CHANGE;
  314.     }
  315.     /*
  316.      * Size change
  317.      */
  318.     if( p_vout->i_changes & VOUT_SIZE_CHANGE )
  319.     {
  320.         msg_Dbg( p_vout, "video display resized (%dx%d)",
  321.                  p_vout->p_sys->i_width, p_vout->p_sys->i_height );
  322.         CloseDisplay( p_vout );
  323.         OpenDisplay( p_vout );
  324.         /* We don't need to signal the vout thread about the size change if
  325.          * we can handle rescaling ourselves */
  326.         p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
  327.     }
  328.     /* Pointer change */
  329. //    if( ! p_vout->p_sys->b_cursor_autohidden &&
  330. //        ( mdate() - p_vout->p_sys->i_lastmoved >
  331. //            p_vout->p_sys->i_mouse_hide_timeout ) )
  332. //    {
  333. //        /* Hide the mouse automatically */
  334. //        p_vout->p_sys->b_cursor_autohidden = 1;
  335. //        SDL_ShowCursor( 0 );
  336. //    }
  337. //
  338. //    if( !vlc_object_alive (p_vout->p_libvlc) )
  339. //        p_vout->p_sys->bRunning = FALSE;
  340.     return 0;
  341. }
  342. /*****************************************************************************
  343.  * End: terminate video thread output method
  344.  *****************************************************************************
  345.  * Destroy the buffers created by vout_Init. It is called at the end of
  346.  * the thread, but also each time the window is resized.
  347.  *****************************************************************************/
  348. static void End( vout_thread_t *p_vout )
  349. {
  350.     int i_index;
  351.     /* Free the direct buffers we allocated */
  352.     for( i_index = I_OUTPUTPICTURES ; i_index ; )
  353.     {
  354.         i_index--;
  355.         FreePicture( p_vout, PP_OUTPUTPICTURE[ i_index ] );
  356.     }
  357. }
  358. /*****************************************************************************
  359.  * NewPicture: allocate a picture
  360.  *****************************************************************************
  361.  * Returns 0 on success, -1 otherwise
  362.  *****************************************************************************/
  363. static int NewPicture( vout_thread_t *p_vout, picture_t *p_pic )
  364. {
  365.     int dd = QPixmap::defaultDepth();
  366.     p_pic->p_sys = (picture_sys_t*) malloc( sizeof( picture_sys_t ) );
  367.     if( p_pic->p_sys == NULL )
  368.     {
  369.         return -1;
  370.     }
  371.     /* Create the display */
  372.     p_pic->p_sys->pQImage = new QImage(p_vout->output.i_width,
  373.                                        p_vout->output.i_height, dd );
  374.     if(p_pic->p_sys->pQImage == NULL)
  375.     {
  376.         return -1;
  377.     }
  378.     switch( dd )
  379.     {
  380.         case 8:
  381.             p_pic->p->i_pixel_pitch = 1;
  382.             break;
  383.         case 15:
  384.         case 16:
  385.             p_pic->p->i_pixel_pitch = 2;
  386.             break;
  387.         case 24:
  388.         case 32:
  389.             p_pic->p->i_pixel_pitch = 4;
  390.             break;
  391.         default:
  392.             return( -1 );
  393.     }
  394.     p_pic->p->p_pixels = (p_pic->p_sys->pQImage->jumpTable())[0];
  395.     p_pic->p->i_pitch = p_pic->p_sys->pQImage->bytesPerLine();
  396.     p_pic->p->i_lines = p_vout->output.i_height;
  397.     p_pic->p->i_visible_lines = p_vout->output.i_height;
  398.     p_pic->p->i_visible_pitch =
  399.             p_pic->p->i_pixel_pitch * p_vout->output.i_width;
  400.     p_pic->i_planes = 1;
  401.     return 0;
  402. }
  403. /*****************************************************************************
  404.  * FreePicture: destroy a picture allocated with NewPicture
  405.  *****************************************************************************/
  406. static void FreePicture( vout_thread_t *p_vout, picture_t *p_pic )
  407. {
  408.     delete p_pic->p_sys->pQImage;
  409. }
  410. /*****************************************************************************
  411.  * ToggleFullScreen: Enable or disable full screen mode
  412.  *****************************************************************************
  413.  * This function will switch between fullscreen and window mode.
  414.  *
  415.  *****************************************************************************/
  416. static void ToggleFullScreen ( vout_thread_t *p_vout )
  417. {
  418.     if ( p_vout->b_fullscreen )
  419.        p_vout->p_sys->p_VideoWidget->showFullScreen();
  420.     else
  421.        p_vout->p_sys->p_VideoWidget->showNormal();
  422.     p_vout->b_fullscreen = !p_vout->b_fullscreen;
  423. }
  424. /*****************************************************************************
  425.  * OpenDisplay: create qte applicaton / window
  426.  *****************************************************************************
  427.  * Create a window according to video output given size, and set other
  428.  * properties according to the display properties.
  429.  *****************************************************************************/
  430. static int OpenDisplay( vout_thread_t *p_vout )
  431. {
  432.     /* for displaying the vout in a qt window we need the QtApplication */
  433.     p_vout->p_sys->p_QApplication = NULL;
  434.     p_vout->p_sys->p_VideoWidget = NULL;
  435.     p_vout->p_sys->p_event = (event_thread_t*) vlc_object_create( p_vout, sizeof(event_thread_t) );
  436.     p_vout->p_sys->p_event->p_vout = p_vout;
  437.     /* Initializations */
  438. #if 1 /* FIXME: I need an event queue to handle video output size changes. */
  439.     p_vout->b_fullscreen = true;
  440. #endif
  441.     /* Set main window's size */
  442.     QWidget *desktop = p_vout->p_sys->p_QApplication->desktop();
  443.     p_vout->p_sys->i_width = p_vout->b_fullscreen ? desktop->height() :
  444.                                                     p_vout->i_window_width;
  445.     p_vout->p_sys->i_height = p_vout->b_fullscreen ? desktop->width() :
  446.                                                      p_vout->i_window_height;
  447. #if 0 /* FIXME: I need an event queue to handle video output size changes. */
  448.     /* Update dimensions */
  449.     p_vout->i_changes |= VOUT_SIZE_CHANGE;
  450.     p_vout->i_window_width = p_vout->p_sys->i_width;
  451.     p_vout->i_window_height = p_vout->p_sys->i_height;
  452. #endif
  453.     msg_Dbg( p_vout, "opening display (h=%d,w=%d)",p_vout->p_sys->i_height,p_vout->p_sys->i_width);
  454.     /* create thread to exec the qpe application */
  455.     if ( vlc_thread_create( p_vout->p_sys->p_event, "QT Embedded Thread",
  456.                             RunQtThread,
  457.                             VLC_THREAD_PRIORITY_OUTPUT, true) )
  458.     {
  459.         msg_Err( p_vout, "cannot create QT Embedded Thread" );
  460.         vlc_object_release( p_vout->p_sys->p_event );
  461.         p_vout->p_sys->p_event = NULL;
  462.         return -1;
  463.     }
  464.     if( p_vout->p_sys->p_event->b_error )
  465.     {
  466.         msg_Err( p_vout, "RunQtThread failed" );
  467.         return -1;
  468.     }
  469.     vlc_object_attach( p_vout->p_sys->p_event, p_vout );
  470.     msg_Dbg( p_vout, "RunQtThread running" );
  471.     // just wait until the crew is complete...
  472.     while(p_vout->p_sys->p_VideoWidget == NULL)
  473.     {
  474.         msleep(1);
  475.     }
  476.     return VLC_SUCCESS;
  477. }
  478. /*****************************************************************************
  479.  * CloseDisplay: destroy the window
  480.  *****************************************************************************/
  481. static void CloseDisplay( vout_thread_t *p_vout )
  482. {
  483.     // quit qt application loop
  484.     msg_Dbg( p_vout, "destroying Qt Window" );
  485. #ifdef NEED_QTE_MAIN
  486.     if(p_vout->p_sys->p_QApplication)
  487.     {
  488.         p_vout->p_sys->bRunning = FALSE;
  489.         while(p_vout->p_sys->p_VideoWidget)
  490.         {
  491.             msleep(1);
  492.         }
  493.     }
  494. #else
  495.     if (p_vout->p_sys->p_QApplication)
  496.        p_vout->p_sys->p_QApplication->quit();
  497. #endif
  498. }
  499. /*****************************************************************************
  500.  * main loop of qtapplication
  501.  *****************************************************************************/
  502. static void* RunQtThread( vlc_object_t *p_this )
  503. {
  504.     event_thread_t *p_event = (event_thread_t *)p_this;
  505.     int canc = vlc_savecancel ();
  506.     msg_Dbg( p_event->p_vout, "RunQtThread starting" );
  507. #ifdef NEED_QTE_MAIN
  508.     if (qApp)
  509.     {
  510.         p_event->p_vout->p_sys->p_QApplication = qApp;
  511.         p_event->p_vout->p_sys->bOwnsQApp = FALSE;
  512.         p_event->p_vout->p_sys->p_VideoWidget = qApp->mainWidget();
  513.         msg_Dbg( p_event->p_vout, "RunQtThread applicaton attached" );
  514.     }
  515. #else
  516.     if (qApp==NULL)
  517.     {
  518.         int argc = 0;
  519.         QApplication* pApp = new QApplication(argc, NULL);
  520.         if(pApp)
  521.         {
  522.             p_event->p_vout->p_sys->p_QApplication = pApp;
  523.             p_event->p_vout->p_sys->bOwnsQApp = TRUE;
  524.         }
  525.         QWidget* pWidget = new QWidget();
  526.         if (pWidget)
  527.             {
  528.             p_event->p_vout->p_sys->p_VideoWidget = pWidget;
  529.         }
  530.     }
  531. #endif
  532.     /* signal the creation of the window */
  533.     vlc_thread_ready( p_event );
  534.     msg_Dbg( p_event->p_vout, "RunQtThread ready" );
  535.     if (p_event->p_vout->p_sys->p_QApplication)
  536.     {
  537.         /* Set default window width and heigh to exactly preferred size. */
  538.             QWidget *desktop = p_event->p_vout->p_sys->p_QApplication->desktop();
  539.             p_event->p_vout->p_sys->p_VideoWidget->setMinimumWidth( 10 );
  540.              p_event->p_vout->p_sys->p_VideoWidget->setMinimumHeight( 10 );
  541.             p_event->p_vout->p_sys->p_VideoWidget->setBaseSize( p_event->p_vout->p_sys->i_width,
  542.             p_event->p_vout->p_sys->i_height );
  543.         p_event->p_vout->p_sys->p_VideoWidget->setMaximumWidth( desktop->width() );
  544.         p_event->p_vout->p_sys->p_VideoWidget->setMaximumHeight( desktop->height() );
  545.         /* Check on fullscreen */
  546.         if (p_event->p_vout->b_fullscreen)
  547.                   p_event->p_vout->p_sys->p_VideoWidget->showFullScreen();
  548.         else
  549.                 p_event->p_vout->p_sys->p_VideoWidget->showNormal();
  550.         p_event->p_vout->p_sys->p_VideoWidget->show();
  551.         p_event->p_vout->p_sys->bRunning = TRUE;
  552. #ifdef NEED_QTE_MAIN
  553.         while(vlc_object_alive (p_event) && p_event->p_vout->p_sys->bRunning)
  554.               {
  555.                /* Check if we are asked to exit */
  556.            if( !vlc_object_alive (p_event) )
  557.                break;
  558.                msleep(100);
  559.             }
  560. #else
  561.         // run the main loop of qtapplication until someone says: 'quit'
  562.         p_event->p_vout->p_sys->pcQApplication->exec();
  563. #endif
  564.     }
  565. #ifndef NEED_QTE_MAIN
  566.     if(p_event->p_vout->p_sys->p_QApplication)
  567.     {
  568.         delete p_event->p_vout->p_sys->p_VideoWidget;
  569.         p_event->p_vout->p_sys->p_VideoWidget = NULL;
  570.         delete p_event->p_vout->p_sys->p_QApplication;
  571.         p_event->p_vout->p_sys->p_QApplication = NULL;
  572.     }
  573. #else
  574.     p_event->p_vout->p_sys->p_VideoWidget = NULL;
  575. #endif
  576.     msg_Dbg( p_event->p_vout, "RunQtThread terminating" );
  577.     vlc_restorecancel (canc);
  578.     return NULL;
  579. }