]> git.sesse.net Git - vlc/blobdiff - modules/video_filter/panoramix.c
Use var_InheritString for --decklink-video-connection.
[vlc] / modules / video_filter / panoramix.c
index 2fe05f2cf6dd83b89865dd21061b3e40e603d41c..68819e24cac9e599e0145b697d94be38f7d394b7 100644 (file)
@@ -46,7 +46,8 @@
 #   ifdef WIN32
 #       include <windows.h>
 #   else
-#       include <X11/Xlib.h>
+#       include <xcb/xcb.h>
+#       include <xcb/randr.h>
 #   endif
 #endif
 
 
 #define CFG_PREFIX "panoramix-"
 
+#define PANORAMIX_HELP N_("Split the video in multiple windows to " \
+    "display on a wall of screens")
+
 static int  Open ( vlc_object_t * );
 static void Close( vlc_object_t * );
 
 vlc_module_begin()
     set_description( N_("Panoramix: wall with overlap video filter") )
     set_shortname( N_("Panoramix" ))
+    set_help(PANORAMIX_HELP)
     set_capability( "video splitter", 0 )
     set_category( CAT_VIDEO )
     set_subcategory( SUBCAT_VIDEO_VFILTER )
@@ -91,7 +96,7 @@ vlc_module_begin()
 
 #define ATTENUATION_TEXT N_("Attenuation")
 #define ATTENUATION_LONGTEXT N_("Check this option if you want attenuate blended zone by this plug-in (if option is unchecked, attenuate is made by opengl)")
-    add_bool( CFG_PREFIX "attenuate", 1, NULL, ATTENUATION_TEXT, ATTENUATION_LONGTEXT, false )
+    add_bool( CFG_PREFIX "attenuate", true, NULL, ATTENUATION_TEXT, ATTENUATION_LONGTEXT, false )
 
 #define BEGIN_TEXT N_("Attenuation, begin (in %)")
 #define BEGIN_LONGTEXT N_("Select in percent the Lagrange coeff of the beginning blended zone")
@@ -160,9 +165,9 @@ vlc_module_begin()
     add_integer_with_range( CFG_PREFIX "bz-whitelevel-green", 0, 0, 255, NULL, GGAMMA_WL_TEXT, GGAMMA_WL_LONGTEXT, true )
     add_integer_with_range( CFG_PREFIX "bz-whitelevel-blue", 0, 0, 255, NULL, BGAMMA_WL_TEXT, BGAMMA_WL_LONGTEXT, true )
 #ifndef WIN32
-    add_deprecated_alias( CFG_PREFIX "xinerama" );
+    add_obsolete_bool( CFG_PREFIX "xinerama" );
 #endif
-    add_deprecated_alias( CFG_PREFIX "offset-x" )
+    add_obsolete_bool( CFG_PREFIX "offset-x" )
 #endif
 
     add_string( CFG_PREFIX "active", NULL, NULL, ACTIVE_TEXT, ACTIVE_LONGTEXT, true )
@@ -336,6 +341,72 @@ static const panoramix_chroma_t p_chroma_array[] = {
     { 0, {0, }, { 0, }, { 0, 0, 0 }, false }
 };
 
+#ifndef WIN32
+/* Get the number of outputs */
+static unsigned CountMonitors( vlc_object_t *obj )
+{
+    char *psz_display = var_CreateGetNonEmptyString( obj, "x11-display" );
+    int snum;
+    xcb_connection_t *conn = xcb_connect( psz_display, &snum );
+    free( psz_display );
+    if( xcb_connection_has_error( conn ) )
+        return 0;
+
+    const xcb_setup_t *setup = xcb_get_setup( conn );
+    xcb_screen_t *scr = NULL;
+    for( xcb_screen_iterator_t i = xcb_setup_roots_iterator( setup );
+         i.rem > 0; xcb_screen_next( &i ) )
+    {
+         if( snum == 0 )
+         {
+             scr = i.data;
+             break;
+         }
+         snum--;
+    }
+
+    unsigned n = 0;
+    if( scr == NULL )
+        goto error;
+
+    xcb_randr_query_version_reply_t *v =
+        xcb_randr_query_version_reply( conn,
+            xcb_randr_query_version( conn, 1, 2 ), NULL );
+    if( v == NULL )
+        goto error;
+    msg_Dbg( obj, "using X RandR extension v%"PRIu32".%"PRIu32,
+             v->major_version, v->minor_version );
+    free( v );
+
+    xcb_randr_get_screen_resources_reply_t *r =
+        xcb_randr_get_screen_resources_reply( conn,
+            xcb_randr_get_screen_resources( conn, scr->root ), NULL );
+    if( r == NULL )
+        goto error;
+
+    const xcb_randr_output_t *outputs =
+        xcb_randr_get_screen_resources_outputs( r );
+    for( unsigned i = 0; i < r->num_outputs; i++ )
+    {
+        xcb_randr_get_output_info_reply_t *output =
+            xcb_randr_get_output_info_reply( conn,
+                xcb_randr_get_output_info( conn, outputs[i], 0 ), NULL );
+        if( output == NULL )
+            continue;
+        /* FIXME: do not count cloned outputs multiple times */
+        /* XXX: what to do with UNKNOWN state connections? */
+        n += output->connection == XCB_RANDR_CONNECTION_CONNECTED;
+        free( output );
+    }
+    free( r );
+    msg_Dbg( obj, "X randr has %u outputs", n );
+
+error:
+    xcb_disconnect( conn );
+    return n;
+}
+#endif
+
 /*****************************************************************************
  * Open: allocates Wall video thread output method
  *****************************************************************************
@@ -394,14 +465,21 @@ static int Open( vlc_object_t *p_this )
             }
         }
 #else
-        /* TODO linux */
+        const unsigned i_monitors = CountMonitors( p_this );
+        if( i_monitors > 1 ) /* Find closest to square */
+            for( unsigned w = 1; (i_monitors / w) >= w ; w++ )
+            {
+                if( i_monitors % w )
+                    continue;
+                p_sys->i_row = w;
+                p_sys->i_col = i_monitors / w;
+            }
 #endif
         /* By default do 2x1 */
-        if( p_sys->i_col < 0 || p_sys->i_row < 0 )
-        {
-            p_sys->i_col = 2;
+        if( p_sys->i_row < 0 )
             p_sys->i_row = 1;
-        }
+        if( p_sys->i_col < 0 )
+            p_sys->i_col = 2;
         var_SetInteger( p_splitter, CFG_PREFIX "cols", p_sys->i_col);
         var_SetInteger( p_splitter, CFG_PREFIX "rows", p_sys->i_row);
     }