]> git.sesse.net Git - vlc/blobdiff - modules/video_filter/wrapper.c
Symplify configure.ac regarding OpenCV and rename the example file from C++ to C...
[vlc] / modules / video_filter / wrapper.c
index 8d8866a33e24aec8e35d89c60c306502e0f1e339..0f45f51a3b15589c70ccf71d20b38c4c45dfa72c 100644 (file)
@@ -53,6 +53,7 @@ DECLARE_OPEN(logo, true)
 
 DECLARE_OPEN(clone, false)
 DECLARE_OPEN(wall, false)
+DECLARE_OPEN(panoramix, false)
 
 #undef DECLARE_OPEN
 
@@ -81,6 +82,9 @@ vlc_module_begin()
     add_submodule()
     DECLARE_MODULE(wall)
 
+    add_submodule()
+    DECLARE_MODULE(panoramix)
+
 vlc_module_end()
 
 #undef DECLARE_MODULE
@@ -113,8 +117,6 @@ static int  FilterAllocationInit ( filter_t *, void * );
 static void FilterAllocationClean( filter_t * );
 
 /* */
-static int  FullscreenEventUp( vlc_object_t *, char const *,
-                               vlc_value_t, vlc_value_t, void * );
 static int  FullscreenEventDown( vlc_object_t *, char const *,
                                  vlc_value_t, vlc_value_t, void * );
 static int  SplitterPictureNew( video_splitter_t *, picture_t *pp_picture[] );
@@ -141,12 +143,8 @@ static int Open( vlc_object_t *p_this, const char *psz_name, bool b_filter )
     es_format_Init( &fmt, VIDEO_ES, p_vout->render.i_chroma );
     video_format_Setup( &fmt.video, p_vout->render.i_chroma,
                         p_vout->render.i_width, p_vout->render.i_height,
-                        p_vout->render.i_aspect );
-    if( fmt.video.i_sar_num <= 0 || fmt.video.i_sar_den <= 0 )
-    {
-        fmt.video.i_sar_num = fmt.video.i_aspect * fmt.video.i_visible_height;
-        fmt.video.i_sar_den = VOUT_ASPECT_FACTOR * fmt.video.i_visible_width;
-    }
+                        p_vout->render.i_aspect * p_vout->render.i_height,
+                        VOUT_ASPECT_FACTOR      * p_vout->render.i_width );
 
     /* Try to open our real module */
     filter_chain_t   *p_chain = NULL;
@@ -279,22 +277,25 @@ static int Init( vout_thread_t *p_vout )
     {
         video_splitter_t *p_splitter = p_sys->p_splitter;
 
+        /* */
+        const int i_org_align = var_CreateGetInteger( p_vout, "align" );
+        const int i_org_x = var_CreateGetInteger( p_vout, "video-x" );
+        const int i_org_y = var_CreateGetInteger( p_vout, "video-y" );
+        const char *psz_org_vout = var_CreateGetNonEmptyString( p_vout, "vout" );
+
+        /* */
         for( int i = 0; i < p_splitter->i_output; i++ )
         {
             const video_splitter_output_t *p_cfg = &p_splitter->p_output[i];
 
             /* */
-            var_Create( p_vout, "align", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
             var_SetInteger( p_vout, "align", p_cfg->window.i_align);
 
-            var_Create( p_vout, "video-x", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
-            var_SetInteger( p_vout, "video-x", p_cfg->window.i_x );
+            var_SetInteger( p_vout, "video-x", i_org_x + p_cfg->window.i_x );
+            var_SetInteger( p_vout, "video-y", i_org_y + p_cfg->window.i_y );
 
-            var_Create( p_vout, "video-y", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
-            var_SetInteger( p_vout, "video-y", p_cfg->window.i_y );
-
-            var_Create( p_vout, "vout", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
-            var_SetString( p_vout, "vout", p_cfg->psz_module ? p_cfg->psz_module : "" );
+            if( p_cfg->psz_module )
+                var_SetString( p_vout, "vout", p_cfg->psz_module );
 
             /* */
             video_format_t fmt = p_cfg->fmt;
@@ -305,11 +306,18 @@ static int Init( vout_thread_t *p_vout )
                 VoutsClean( p_vout, i );
                 return VLC_EGENERIC;
             }
+        }
 
+        /* Attach once pp_vout is completly filed to avoid race conditions */
+        for( int i = 0; i < p_splitter->i_output; i++ )
             vout_filter_SetupChild( p_vout, p_sys->pp_vout[i],
                                     MouseEvent,
-                                    FullscreenEventUp, FullscreenEventDown, true );
-        }
+                                    FullscreenEventDown, true );
+        /* Restore settings */
+        var_SetInteger( p_vout, "align", i_org_align );
+        var_SetInteger( p_vout, "video-x", i_org_x );
+        var_SetInteger( p_vout, "video-y", i_org_y );
+        var_SetString( p_vout, "vout", psz_org_vout ? psz_org_vout : "" );
     }
 
     vout_filter_AllocateDirectBuffers( p_vout, VOUT_MAX_PICTURES );
@@ -380,21 +388,19 @@ static void VoutsClean( vout_thread_t *p_vout, int i_count )
 {
     vout_sys_t *p_sys = p_vout->p_sys;
 
+    /* Detach all vouts before destroying them */
     for( int i = 0; i < i_count; i++ )
     {
         if( p_sys->p_chain )
-        {
-            assert( i == 0 );
             vout_filter_DelChild( p_vout, p_sys->pp_vout[i], MouseEvent );
-        }
         else
-        {
              vout_filter_SetupChild( p_vout, p_sys->pp_vout[i],
                                      MouseEvent,
-                                     FullscreenEventUp, FullscreenEventDown, false );
-        }
-        vout_CloseAndRelease( p_sys->pp_vout[i] );
+                                     FullscreenEventDown, false );
     }
+
+    for( int i = 0; i < i_count; i++ )
+        vout_CloseAndRelease( p_sys->pp_vout[i] );
 }
 static int VoutsNewPicture( vout_thread_t *p_vout, picture_t *pp_dst[] )
 {
@@ -428,6 +434,7 @@ static int VoutsNewPicture( vout_thread_t *p_vout, picture_t *pp_dst[] )
 static int MouseEvent( vlc_object_t *p_this, char const *psz_var,
                        vlc_value_t oldval, vlc_value_t newval, void *p_data )
 {
+    VLC_UNUSED(psz_var); VLC_UNUSED(oldval); VLC_UNUSED(newval);
     vout_thread_t *p_vout = p_data;
     vout_sys_t *p_sys = p_vout->p_sys;
     int i_index;
@@ -447,8 +454,7 @@ static int MouseEvent( vlc_object_t *p_this, char const *psz_var,
 
     vlc_mouse_t m;
     vlc_mouse_Init( &m );
-    m.i_x = var_GetInteger( p_vout_src, "mouse-x" );
-    m.i_y = var_GetInteger( p_vout_src, "mouse-y" );
+    var_GetCoords( p_vout_src, "mouse-moved", &m.i_x, &m.i_y );
     m.i_pressed = var_GetInteger( p_vout_src, "mouse-button-down" );
 
     vlc_mutex_lock( &p_sys->lock );
@@ -478,15 +484,13 @@ static int MouseEvent( vlc_object_t *p_this, char const *psz_var,
 
     if( vlc_mouse_HasMoved( &omouse, &nmouse ) )
     {
-        var_SetInteger( p_vout, "mouse-x", nmouse.i_x );
-        var_SetInteger( p_vout, "mouse-y", nmouse.i_y );
-        var_SetBool( p_vout, "mouse-moved", true );
+        var_SetCoords( p_vout, "mouse-moved", nmouse.i_x, nmouse.i_y );
     }
     if( vlc_mouse_HasButton( &omouse, &nmouse ) )
     {
         var_SetInteger( p_vout, "mouse-button-down", nmouse.i_pressed );
         if( vlc_mouse_HasPressed( &omouse, &nmouse, MOUSE_BUTTON_LEFT ) )
-            var_SetBool( p_vout, "mouse-clicked", true );
+            var_SetCoords( p_vout, "mouse-clicked", nmouse.i_x, nmouse.i_y );
     }
     if( m.b_double_click )
     {
@@ -517,46 +521,20 @@ static int FilterAllocationInit( filter_t *p_filter, void *p_data )
 {
     VLC_UNUSED( p_data );
 
-    p_filter->pf_vout_buffer_new = VideoBufferNew;
-    p_filter->pf_vout_buffer_del = VideoBufferDelete;
+    p_filter->pf_video_buffer_new = VideoBufferNew;
+    p_filter->pf_video_buffer_del = VideoBufferDelete;
     p_filter->p_owner = p_data;
 
     return VLC_SUCCESS;
 }
 static void FilterAllocationClean( filter_t *p_filter )
 {
-    p_filter->pf_vout_buffer_new = NULL;
-    p_filter->pf_vout_buffer_del = NULL;
+    p_filter->pf_video_buffer_new = NULL;
+    p_filter->pf_video_buffer_del = NULL;
 }
 
 /* -- Splitter callbacks -- */
 
-/**
- * Forward fullscreen event to/from the childrens.
- *
- * FIXME probably unsafe (pp_vout[] content)
- */
-static bool IsFullscreenActive( vout_thread_t *p_vout )
-{
-    vout_sys_t *p_sys = p_vout->p_sys;
-    for( int i = 0; i < p_sys->i_vout; i++ )
-    {
-        if( var_GetBool( p_sys->pp_vout[i], "fullscreen" ) )
-            return true;
-    }
-    return false;
-}
-static int FullscreenEventUp( vlc_object_t *p_this, char const *psz_var,
-                              vlc_value_t oldval, vlc_value_t newval, void *p_data )
-{
-    vout_thread_t *p_vout = p_data;
-    VLC_UNUSED(oldval); VLC_UNUSED(p_this); VLC_UNUSED(psz_var); VLC_UNUSED(newval);
-
-    const bool b_fullscreen = IsFullscreenActive( p_vout );
-    if( !var_GetBool( p_vout, "fullscreen" ) != !b_fullscreen )
-        return var_SetBool( p_vout, "fullscreen", b_fullscreen );
-    return VLC_SUCCESS;
-}
 static int FullscreenEventDown( vlc_object_t *p_this, char const *psz_var,
                                 vlc_value_t oldval, vlc_value_t newval, void *p_data )
 {
@@ -564,19 +542,10 @@ static int FullscreenEventDown( vlc_object_t *p_this, char const *psz_var,
     vout_sys_t *p_sys = p_vout->p_sys;
     VLC_UNUSED(oldval); VLC_UNUSED(p_data); VLC_UNUSED(psz_var);
 
-    const bool b_fullscreen = IsFullscreenActive( p_vout );
-    if( !b_fullscreen != !newval.b_bool )
+    for( int i = 0; i < p_sys->i_vout; i++ )
     {
-        for( int i = 0; i < p_sys->i_vout; i++ )
-        {
-            vout_thread_t *p_child = p_sys->pp_vout[i];
-            if( !var_GetBool( p_child, "fullscreen" ) != !newval.b_bool )
-            {
-                var_SetBool( p_child, "fullscreen", newval.b_bool );
-                if( newval.b_bool )
-                    return VLC_SUCCESS;
-            }
-        }
+        vout_thread_t *p_child = p_sys->pp_vout[i];
+        var_SetBool( p_child, "fullscreen", newval.b_bool );
     }
     return VLC_SUCCESS;
 }
@@ -589,6 +558,7 @@ static int  SplitterPictureNew( video_splitter_t *p_splitter, picture_t *pp_pict
 }
 static void SplitterPictureDel( video_splitter_t *p_splitter, picture_t *pp_picture[] )
 {
+    VLC_UNUSED(p_splitter); VLC_UNUSED(pp_picture);
     /* FIXME is there anything to do ? */
 }