1 /*****************************************************************************
2 * motion.c: control VLC with laptop built-in motion sensors
3 *****************************************************************************
4 * Copyright (C) 2006 - 2007 the VideoLAN team
7 * Author: Sam Hocevar <sam@zoy.org>
8 * Jérôme Decoodt <djc@videolan.org> (unimotion integration)
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
36 #define VLC_MODULE_LICENSE VLC_LICENSE_GPL_2_PLUS
37 #include <vlc_common.h>
38 #include <vlc_plugin.h>
39 #include <vlc_interface.h>
40 #include <vlc_playlist.h>
41 #include <vlc_input.h>
44 #include "motionlib.h"
46 /*****************************************************************************
47 * intf_sys_t: description and status of interface
48 *****************************************************************************/
51 motion_sensors_t *p_motion;
55 /*****************************************************************************
57 *****************************************************************************/
58 static int Open ( vlc_object_t * );
59 static void Close ( vlc_object_t * );
61 static void *RunIntf( void * );
63 /*****************************************************************************
65 *****************************************************************************/
67 set_shortname( N_("motion"))
68 set_category( CAT_INTERFACE )
69 set_subcategory( SUBCAT_INTERFACE_CONTROL )
70 set_description( N_("motion control interface") )
71 set_help( N_("Use HDAPS, AMS, APPLESMC or UNIMOTION motion sensors " \
72 "to rotate the video") )
74 add_obsolete_bool( "motion-use-rotate" ) /* since 2.1.0 */
76 set_capability( "interface", 0 )
77 set_callbacks( Open, Close )
80 /*****************************************************************************
81 * OpenIntf: initialise interface
82 *****************************************************************************/
83 int Open ( vlc_object_t *p_this )
85 intf_thread_t *p_intf = (intf_thread_t *)p_this;
86 intf_sys_t *p_sys = malloc( sizeof( *p_sys ) );
87 if( unlikely(p_sys == NULL) )
90 p_sys->p_motion = motion_create( VLC_OBJECT( p_intf ) );
91 if( p_sys->p_motion == NULL )
98 p_intf->p_sys = p_sys;
100 if( vlc_clone( &p_sys->thread, RunIntf, p_intf, VLC_THREAD_PRIORITY_LOW ) )
102 motion_destroy( p_sys->p_motion );
109 /*****************************************************************************
110 * CloseIntf: destroy interface
111 *****************************************************************************/
112 void Close ( vlc_object_t *p_this )
114 intf_thread_t *p_intf = (intf_thread_t *)p_this;
115 intf_sys_t *p_sys = p_intf->p_sys;
117 vlc_cancel( p_sys->thread );
118 vlc_join( p_sys->thread, NULL );
119 motion_destroy( p_sys->p_motion );
123 /*****************************************************************************
125 *****************************************************************************/
126 #define LOW_THRESHOLD 800
127 #define HIGH_THRESHOLD 1000
128 static void *RunIntf( void *data )
130 intf_thread_t *p_intf = data;
135 const char *psz_type;
136 bool b_change = false;
138 /* Wait a bit, get orientation, change filter if necessary */
139 #warning FIXME: check once (or less) per picture, not once per interval
140 msleep( INTF_IDLE_SLEEP );
142 int canc = vlc_savecancel();
143 int i_x = motion_get_angle( p_intf->p_sys->p_motion );
145 if( i_x < -HIGH_THRESHOLD && i_oldx > -LOW_THRESHOLD )
150 else if( ( i_x > -LOW_THRESHOLD && i_oldx < -HIGH_THRESHOLD )
151 || ( i_x < LOW_THRESHOLD && i_oldx > HIGH_THRESHOLD ) )
156 else if( i_x > HIGH_THRESHOLD && i_oldx < LOW_THRESHOLD )
164 #warning FIXME: refactor this plugin as a video filter!
165 input_thread_t *p_input = pl_CurrentInput( p_intf );
168 vout_thread_t *p_vout;
170 p_vout = input_GetVout( p_input );
173 if( psz_type != NULL )
175 var_Create( p_vout, "transform-type", VLC_VAR_STRING );
176 var_SetString( p_vout, "transform-type", psz_type );
179 var_Destroy( p_vout, "transform-type" );
181 var_SetString( p_vout, "video-filter",
182 psz_type != NULL ? "transform" : "" );
183 vlc_object_release( p_vout );
185 vlc_object_release( p_input );
190 vlc_restorecancel( canc );
192 vlc_assert_unreachable();
195 #undef HIGH_THRESHOLD