[vlc-commits] qt: check if video widget is available up-front

Rémi Denis-Courmont git at videolan.org
Sun Dec 2 19:25:41 CET 2018


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Dec  2 17:26:39 2018 +0200| [d336d0c4464a5ac6fa39a4e9d781a5a63d532e27] | committer: Rémi Denis-Courmont

qt: check if video widget is available up-front

We need to know if it is available before it is enabled now.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=d336d0c4464a5ac6fa39a4e9d781a5a63d532e27
---

 modules/gui/qt/components/interface_widgets.cpp |  9 ++-----
 modules/gui/qt/components/interface_widgets.hpp |  2 +-
 modules/gui/qt/main_interface.cpp               | 34 +++++++++++++------------
 modules/gui/qt/main_interface.hpp               |  6 ++---
 4 files changed, 24 insertions(+), 27 deletions(-)

diff --git a/modules/gui/qt/components/interface_widgets.cpp b/modules/gui/qt/components/interface_widgets.cpp
index 04adbba168..f5261b2eec 100644
--- a/modules/gui/qt/components/interface_widgets.cpp
+++ b/modules/gui/qt/components/interface_widgets.cpp
@@ -117,13 +117,9 @@ void VideoWidget::sync( void )
 /**
  * Request the video to avoid the conflicts
  **/
-bool VideoWidget::request( struct vout_window_t *p_wnd )
+void VideoWidget::request( struct vout_window_t *p_wnd )
 {
-    if( stable )
-    {
-        msg_Dbg( p_intf, "embedded video already in use" );
-        return false;
-    }
+    assert( stable == NULL );
     assert( !p_window );
 
     /* The owner of the video window needs a stable handle (WinId). Reparenting
@@ -190,7 +186,6 @@ bool VideoWidget::request( struct vout_window_t *p_wnd )
         default:
             vlc_assert_unreachable();
     }
-    return true;
 }
 
 QSize VideoWidget::physicalSize() const
diff --git a/modules/gui/qt/components/interface_widgets.hpp b/modules/gui/qt/components/interface_widgets.hpp
index 76a9e3b5d5..b3960a3749 100644
--- a/modules/gui/qt/components/interface_widgets.hpp
+++ b/modules/gui/qt/components/interface_widgets.hpp
@@ -60,7 +60,7 @@ public:
     VideoWidget( intf_thread_t *, QWidget* p_parent );
     virtual ~VideoWidget();
 
-    bool request( struct vout_window_t * );
+    void request( struct vout_window_t * );
     void release( void );
     void sync( void );
 
diff --git a/modules/gui/qt/main_interface.cpp b/modules/gui/qt/main_interface.cpp
index 0b737622d4..da0e8bdeb7 100644
--- a/modules/gui/qt/main_interface.cpp
+++ b/modules/gui/qt/main_interface.cpp
@@ -92,7 +92,8 @@ static int IntfRaiseMainCB( vlc_object_t *p_this, const char *psz_variable,
 const QEvent::Type MainInterface::ToolbarsNeedRebuild =
         (QEvent::Type)QEvent::registerEventType();
 
-MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
+MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf ),
+    videoActive( ATOMIC_FLAG_INIT )
 {
     /* Variables initialisation */
     bgWidget             = NULL;
@@ -203,8 +204,8 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
 
     /* VideoWidget connects for asynchronous calls */
     b_videoFullScreen = false;
-    connect( this, SIGNAL(askGetVideo(struct vout_window_t*, unsigned, unsigned, bool, bool*)),
-             this, SLOT(getVideoSlot(struct vout_window_t*, unsigned, unsigned, bool, bool*)),
+    connect( this, SIGNAL(askGetVideo(struct vout_window_t*, unsigned, unsigned, bool)),
+             this, SLOT(getVideoSlot(struct vout_window_t*, unsigned, unsigned, bool)),
              Qt::BlockingQueuedConnection );
     connect( this, SIGNAL(askReleaseVideo( void )),
              this, SLOT(releaseVideoSlot( void )),
@@ -736,27 +737,25 @@ bool MainInterface::getVideo( struct vout_window_t *p_wnd,
         MainInterface::requestVideoWindowed,
         MainInterface::requestVideoFullScreen,
     };
-    bool result;
+
+    if( videoActive.test_and_set() )
+        return false;
 
     msg_Dbg( p_wnd, "requesting video window..." );
 
     /* This is a blocking call signal. Results are stored directly in the
      * vout_window_t and boolean pointers. Beware of deadlocks! */
-    emit askGetVideo( p_wnd, i_width, i_height, fullscreen, &result );
+    emit askGetVideo( p_wnd, i_width, i_height, fullscreen );
 
-    if( result )
-    {
-        p_wnd->ops = &ops;
-        p_wnd->info.has_double_click = true;
-        p_wnd->sys = this;
-    }
-
-    return result;
+    p_wnd->ops = &ops;
+    p_wnd->info.has_double_click = true;
+    p_wnd->sys = this;
+    return true;
 }
 
 void MainInterface::getVideoSlot( struct vout_window_t *p_wnd,
                                   unsigned i_width, unsigned i_height,
-                                  bool fullscreen, bool *res )
+                                  bool fullscreen )
 {
     /* Hidden or minimized, activate */
     if( isHidden() || isMinimized() )
@@ -768,8 +767,9 @@ void MainInterface::getVideoSlot( struct vout_window_t *p_wnd,
         videoWidget = new VideoWidget( p_intf, stackCentralW );
         stackCentralW->addWidget( videoWidget );
     }
-    *res = videoWidget->request( p_wnd );
-    if( *res ) /* The videoWidget is available */
+
+    videoWidget->request( p_wnd );
+    if( true ) /* The videoWidget is available */
     {
         setVideoFullScreen( fullscreen );
 
@@ -1020,6 +1020,8 @@ void MainInterface::releaseVideo( vout_window_t *p_wnd )
 
     msg_Dbg( p_wnd, "releasing video..." );
     emit p_mi->askReleaseVideo();
+    /* Releasing video is a blocking call. The video is no longer active. */
+    p_mi->videoActive.clear();
 }
 
 /*****************************************************************************
diff --git a/modules/gui/qt/main_interface.hpp b/modules/gui/qt/main_interface.hpp
index 0c64d192a3..997678f8c7 100644
--- a/modules/gui/qt/main_interface.hpp
+++ b/modules/gui/qt/main_interface.hpp
@@ -73,6 +73,7 @@ public:
     bool getVideo( struct vout_window_t *,
                    unsigned int i_width, unsigned int i_height, bool );
 private:
+    std::atomic_flag videoActive;
     static void releaseVideo( struct vout_window_t * );
     static void resizeVideo( struct vout_window_t *, unsigned, unsigned );
     static void requestVideoState( struct vout_window_t *, unsigned );
@@ -221,7 +222,7 @@ public slots:
 
     /* Manage the Video Functions from the vout threads */
     void getVideoSlot( struct vout_window_t *,
-                       unsigned i_width, unsigned i_height, bool, bool * );
+                       unsigned i_width, unsigned i_height, bool );
     void releaseVideoSlot( void );
 
     void emitBoss();
@@ -277,8 +278,7 @@ protected slots:
     void onInputChanged( bool );
 
 signals:
-    void askGetVideo( struct vout_window_t *, unsigned, unsigned, bool,
-                      bool * );
+    void askGetVideo( struct vout_window_t *, unsigned, unsigned, bool );
     void askReleaseVideo( );
     void askVideoToResize( unsigned int, unsigned int );
     void askVideoSetFullScreen( bool );



More information about the vlc-commits mailing list