]> git.sesse.net Git - vlc/blobdiff - modules/control/motion.c
I422_YUY2: clobber lists for MMX and SSE2
[vlc] / modules / control / motion.c
index 091f76702586398392d716ffc71bd77754441ab9..b234f5c2548ca02502b88ab7fdd304e9c8c8e27c 100644 (file)
 #endif
 
 #include <math.h>
+#include <unistd.h>
 
 #include <vlc_common.h>
 #include <vlc_plugin.h>
 #include <vlc_interface.h>
+#include <vlc_playlist.h>
 #include <vlc_vout.h>
 
-#ifdef HAVE_UNISTD_H
-#    include <unistd.h>
+#ifdef __APPLE__
+# include "TargetConditionals.h"
+# if !TARGET_OS_IPHONE
+#  define HAVE_MACOS_UNIMOTION
+# endif
 #endif
 
-#ifdef __APPLE__
-#include "unimotion.h"
+#ifdef HAVE_MACOS_UNIMOTION
+# include "unimotion.h"
 #endif
 
 /*****************************************************************************
@@ -52,7 +57,7 @@ struct intf_sys_t
 {
     enum { NO_SENSOR, HDAPS_SENSOR, AMS_SENSOR, APPLESMC_SENSOR,
            UNIMOTION_SENSOR } sensor;
-#ifdef __APPLE__
+#ifdef HAVE_MACOS_UNIMOTION
     enum sms_hardware unimotion_hw;
 #endif
     int i_calibrate;
@@ -96,7 +101,7 @@ int Open ( vlc_object_t *p_this )
 {
     intf_thread_t *p_intf = (intf_thread_t *)p_this;
     FILE *f;
-    int i_x, i_y;
+    int i_x = 0, i_y = 0;
 
     p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
     if( p_intf->p_sys == NULL )
@@ -110,10 +115,8 @@ int Open ( vlc_object_t *p_this )
         f = fopen( "/sys/devices/platform/hdaps/calibrate", "r" );
         if( f )
         {
-            i_x = i_y = 0;
-            fscanf( f, "(%d,%d)", &i_x, &i_y );
+            p_intf->p_sys->i_calibrate = fscanf( f, "(%d,%d)", &i_x, &i_y ) == 2 ? i_x: 0;
             fclose( f );
-            p_intf->p_sys->i_calibrate = i_x;
             p_intf->p_sys->sensor = HDAPS_SENSOR;
         }
         else
@@ -133,10 +136,8 @@ int Open ( vlc_object_t *p_this )
         f = fopen( "/sys/devices/applesmc.768/calibrate", "r" );
         if( f )
         {
-            i_x = i_y = 0;
-            fscanf( f, "(%d,%d)", &i_x, &i_y );
+            p_intf->p_sys->i_calibrate = fscanf( f, "(%d,%d)", &i_x, &i_y ) == 2 ? i_x: 0;
             fclose( f );
-            p_intf->p_sys->i_calibrate = i_x;
             p_intf->p_sys->sensor = APPLESMC_SENSOR;
         }
         else
@@ -144,8 +145,8 @@ int Open ( vlc_object_t *p_this )
             p_intf->p_sys->sensor = NO_SENSOR;
         }
     }
-#ifdef __APPLE__
-    else if((p_intf->p_sys->unimotion_hw = detect_sms()))
+#ifdef HAVE_MACOS_UNIMOTION
+    else if( (p_intf->p_sys->unimotion_hw = detect_sms()) )
         p_intf->p_sys->sensor = UNIMOTION_SENSOR;
 #endif
     else
@@ -156,9 +157,9 @@ int Open ( vlc_object_t *p_this )
 
     p_intf->pf_run = RunIntf;
 
-    p_intf->p_sys->b_use_rotate =
-        var_InheritBool( p_intf, "motion-use-rotate" );
+    p_intf->p_sys->b_use_rotate = var_InheritBool( p_intf, "motion-use-rotate" );
 
+    msg_Dbg( p_intf, "Motion detection correctly loaded" );
     return VLC_SUCCESS;
 }
 
@@ -186,11 +187,11 @@ static void RunIntf( intf_thread_t *p_intf )
 
     for( ;; )
     {
-        vout_thread_t *p_vout;
         const char *psz_filter, *psz_type;
         bool b_change = false;
 
         /* Wait a bit, get orientation, change filter if necessary */
+#warning FIXME: check once (or less) per picture, not once per interval
         msleep( INTF_IDLE_SLEEP );
 
         int canc = vlc_savecancel();
@@ -206,7 +207,7 @@ static void RunIntf( intf_thread_t *p_intf )
             {
                 /* TODO: cache object pointer */
                 vlc_object_t *p_obj =
-                vlc_object_find_name( p_intf->p_libvlc, "rotate", FIND_CHILD );
+                vlc_object_find_name( p_intf->p_libvlc, "rotate" );
                 if( p_obj )
                 {
                     var_SetInteger( p_obj, "rotate-deciangle",
@@ -240,14 +241,24 @@ static void RunIntf( intf_thread_t *p_intf )
 
         if( b_change )
         {
-            p_vout = (vout_thread_t *)
-                vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
-            if( p_vout )
+#warning FIXME: refactor this plugin as a video filter!
+            input_thread_t *p_input;
+
+            p_input = playlist_CurrentInput( pl_Get( p_intf ) );
+            if( p_input )
             {
-                config_PutPsz( p_vout, "transform-type", psz_type );
-                var_SetString( p_vout, "video-filter", psz_filter );
-                vlc_object_release( p_vout );
+                vout_thread_t *p_vout;
 
+                p_vout = input_GetVout( p_input );
+                if( p_vout )
+                {
+#warning FIXME: do not override the permanent configuration!
+#warning FIXME: transform-type does not exist anymore
+                    config_PutPsz( p_vout, "transform-type", psz_type );
+                    var_SetString( p_vout, "video-filter", psz_filter );
+                    vlc_object_release( p_vout );
+                }
+                vlc_object_release( p_input );
                 i_oldx = i_x;
             }
         }
@@ -265,7 +276,8 @@ loop:
 static int GetOrientation( intf_thread_t *p_intf )
 {
     FILE *f;
-    int i_x, i_y, i_z = 0;
+    int i_x = 0, i_y = 0, i_z = 0;
+    int i_ret;
 
     switch( p_intf->p_sys->sensor )
     {
@@ -276,11 +288,13 @@ static int GetOrientation( intf_thread_t *p_intf )
             return 0;
         }
 
-        i_x = i_y = 0;
-        fscanf( f, "(%d,%d)", &i_x, &i_y );
+        i_ret = fscanf( f, "(%d,%d)", &i_x, &i_y );
         fclose( f );
 
-        return ( i_x - p_intf->p_sys->i_calibrate ) * 10;
+        if( i_ret < 2 )
+            return 0;
+        else
+            return ( i_x - p_intf->p_sys->i_calibrate ) * 10;
 
     case AMS_SENSOR:
         f = fopen( "/sys/devices/ams/x", "r" );
@@ -289,10 +303,13 @@ static int GetOrientation( intf_thread_t *p_intf )
             return 0;
         }
 
-        fscanf( f, "%d", &i_x);
+        i_ret = fscanf( f, "%d", &i_x);
         fclose( f );
 
-        return - i_x * 30; /* FIXME: arbitrary */
+        if( i_ret < 1 )
+            return 0;
+        else
+            return - i_x * 30; /* FIXME: arbitrary */
 
     case APPLESMC_SENSOR:
         f = fopen( "/sys/devices/applesmc.768/position", "r" );
@@ -301,13 +318,15 @@ static int GetOrientation( intf_thread_t *p_intf )
             return 0;
         }
 
-        i_x = i_y = i_z = 0;
-        fscanf( f, "(%d,%d,%d)", &i_x, &i_y, &i_z );
+        i_ret = fscanf( f, "(%d,%d,%d)", &i_x, &i_y, &i_z );
         fclose( f );
 
-        return ( i_x - p_intf->p_sys->i_calibrate ) * 10;
+        if( i_ret < 3 )
+            return 0;
+        else
+            return ( i_x - p_intf->p_sys->i_calibrate ) * 10;
 
-#ifdef __APPLE__
+#ifdef HAVE_MACOS_UNIMOTION
     case UNIMOTION_SENSOR:
         if( read_sms_raw( p_intf->p_sys->unimotion_hw, &i_x, &i_y, &i_z ) )
         {
@@ -323,6 +342,7 @@ static int GetOrientation( intf_thread_t *p_intf )
         else
             return 0;
 #endif
+    case NO_SENSOR:
     default:
         return 0;
     }