qte.cpp
上传用户:riyaled888
上传日期:2009-03-27
资源大小:7338k
文件大小:22k
源码类别:

多媒体

开发平台:

MultiPlatform

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