From 81af35179009ca30721c8d376697656d90b9bbf0 Mon Sep 17 00:00:00 2001
From: bgerofi <bgerofi@bgerofi-desktop.(none)>
Date: Sat, 11 Apr 2009 18:15:17 +0900
Subject: [PATCH] dbus FilterSet extension

---
 modules/control/dbus.c |   97 ++++++++++++++++++++++++++++++++++++++++++++++++
 modules/control/dbus.h |    3 +
 2 files changed, 100 insertions(+), 0 deletions(-)

diff --git a/modules/control/dbus.c b/modules/control/dbus.c
index 2753140..6067845 100644
--- a/modules/control/dbus.c
+++ b/modules/control/dbus.c
@@ -52,6 +52,8 @@
 #include <vlc_aout.h>
 #include <vlc_interface.h>
 #include <vlc_playlist.h>
+#include <vlc_vout.h>
+#include <vlc_osd.h>
 
 #include <math.h>
 
@@ -244,6 +246,100 @@ DBUS_METHOD( VolumeGet )
     REPLY_SEND;
 }
 
+DBUS_METHOD( FilterSet )
+{ /* set filter string */
+    REPLY_INIT;
+
+    DBusError error;
+    dbus_error_init( &error );
+
+    char *psz_name;
+    vout_thread_t **pp_vout;
+    vout_thread_t *p_vout;
+    unsigned i_vout;
+    const char *psz_filter_type;
+    input_thread_t *p_input;
+    playlist_t *p_playlist = pl_Hold( (vlc_object_t*) p_this );
+
+    dbus_message_get_args( p_from, &error,
+            DBUS_TYPE_STRING, &psz_name,
+            DBUS_TYPE_INVALID );
+
+    if( dbus_error_is_set( &error ) )
+    {
+        msg_Err( (vlc_object_t*) p_this, "D-Bus message reading : %s",
+                error.message );
+        dbus_error_free( &error );
+        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+    }
+
+    if ( !(p_input =  playlist_CurrentInput( p_playlist )) ) 
+    {
+        msg_Err( (vlc_object_t*) p_this, "No input media found");
+        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+    }
+
+    if( input_Control( p_input, INPUT_GET_VOUTS, &pp_vout, &i_vout ) ) 
+    {
+        msg_Err( (vlc_object_t*) p_this, "No video output found");
+        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+    }
+
+    module_t *p_obj = module_find( psz_name );
+    if( !p_obj )
+    {
+        msg_Err( (vlc_object_t*) p_this, "Unable to find filter module \"%s\".", psz_name );
+        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+    }
+
+    if( module_provides( p_obj, "video filter2" ) )
+    {
+        psz_filter_type = "video-filter";
+    }
+    else if( module_provides( p_obj, "video filter" ) )
+    {
+        psz_filter_type = "vout-filter";
+    }
+    else if( module_provides( p_obj, "sub filter" ) )
+    {
+        psz_filter_type = "sub-filter";
+    }
+    else
+    {
+        module_release (p_obj);
+        msg_Err( (vlc_object_t*) p_this, "Unknown video filter type." );
+        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+    }
+    module_release (p_obj);
+
+    while( strlen( psz_name ) > 0 &&
+            *( psz_name + strlen( psz_name ) -1 ) == ':' )
+    {
+        *( psz_name + strlen( psz_name ) -1 ) = '\0';
+    }
+
+    /* Vout is not kept, so put that in the config */
+    config_PutPsz( (vlc_object_t*) p_this, psz_filter_type, psz_name );
+
+    /* Loop over video outputs and set the filter on each */
+    for( unsigned i = 0; i < i_vout; i++ ) {
+        
+        p_vout = pp_vout[i];
+
+        if( !strcmp( psz_filter_type, "sub-filter" ) ) 
+            var_SetString( p_vout->p_spu, psz_filter_type, psz_name );
+        else
+            var_SetString( p_vout, psz_filter_type, psz_name );
+
+        vlc_object_release( p_vout );
+    }
+
+    free( pp_vout );
+
+    REPLY_SEND;
+}
+
+
 DBUS_METHOD( VolumeSet )
 { /* set volume in percentage */
     REPLY_INIT;
@@ -687,6 +783,7 @@ DBUS_METHOD( handle_player )
     METHOD_FUNC( "GetStatus",               GetStatus );
     METHOD_FUNC( "GetMetadata",             GetCurrentMetadata );
     METHOD_FUNC( "GetCaps",                 GetCaps );
+    METHOD_FUNC( "FilterSet",               FilterSet );
 
     return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 }
diff --git a/modules/control/dbus.h b/modules/control/dbus.h
index 929588b..76c5c36 100644
--- a/modules/control/dbus.h
+++ b/modules/control/dbus.h
@@ -139,6 +139,9 @@ const char* psz_introspection_xml_data_player =
 "    <method name=\"VolumeGet\">\n"
 "      <arg type=\"i\" direction=\"out\" />\n"
 "    </method>\n"
+"    <method name=\"FilterSet\">\n"
+"      <arg type=\"s\" direction=\"in\" />\n"
+"    </method>\n"
 "    <method name=\"PositionSet\">\n"
 "      <arg type=\"i\" direction=\"in\" />\n"
 "    </method>\n"
-- 
1.5.6.3

