| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
#include <fcntl.h> |
|---|
| 29 |
|
|---|
| 30 |
#ifdef HAVE_CONFIG_H |
|---|
| 31 |
# include "config.h" |
|---|
| 32 |
#endif |
|---|
| 33 |
|
|---|
| 34 |
#include <vlc_common.h> |
|---|
| 35 |
#include <vlc_plugin.h> |
|---|
| 36 |
#include <vlc_interface.h> |
|---|
| 37 |
#include <vlc_osd.h> |
|---|
| 38 |
|
|---|
| 39 |
#ifdef HAVE_POLL |
|---|
| 40 |
# include <poll.h> |
|---|
| 41 |
#endif |
|---|
| 42 |
|
|---|
| 43 |
#include <lirc/lirc_client.h> |
|---|
| 44 |
|
|---|
| 45 |
#define LIRC_TEXT N_("Change the lirc configuration file.") |
|---|
| 46 |
#define LIRC_LONGTEXT N_( \ |
|---|
| 47 |
"Tell lirc to read this configuration file. By default it " \ |
|---|
| 48 |
"searches in the users home directory." ) |
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
static int Open ( vlc_object_t * ); |
|---|
| 54 |
static void Close ( vlc_object_t * ); |
|---|
| 55 |
|
|---|
| 56 |
vlc_module_begin(); |
|---|
| 57 |
set_shortname( N_("Infrared") ); |
|---|
| 58 |
set_category( CAT_INTERFACE ); |
|---|
| 59 |
set_subcategory( SUBCAT_INTERFACE_CONTROL ); |
|---|
| 60 |
set_description( N_("Infrared remote control interface") ); |
|---|
| 61 |
set_capability( "interface", 0 ); |
|---|
| 62 |
set_callbacks( Open, Close ); |
|---|
| 63 |
|
|---|
| 64 |
add_string( "lirc-file", NULL, NULL, |
|---|
| 65 |
LIRC_TEXT, LIRC_LONGTEXT, true ); |
|---|
| 66 |
vlc_module_end(); |
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
struct intf_sys_t |
|---|
| 72 |
{ |
|---|
| 73 |
char *psz_file; |
|---|
| 74 |
struct lirc_config *config; |
|---|
| 75 |
|
|---|
| 76 |
int i_fd; |
|---|
| 77 |
}; |
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
static void Run( intf_thread_t * ); |
|---|
| 83 |
|
|---|
| 84 |
static int Process( intf_thread_t * ); |
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 |
static int Open( vlc_object_t *p_this ) |
|---|
| 90 |
{ |
|---|
| 91 |
intf_thread_t *p_intf = (intf_thread_t *)p_this; |
|---|
| 92 |
intf_sys_t *p_sys; |
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 |
p_intf->p_sys = p_sys = malloc( sizeof( intf_sys_t ) ); |
|---|
| 96 |
if( p_sys == NULL ) |
|---|
| 97 |
return VLC_ENOMEM; |
|---|
| 98 |
|
|---|
| 99 |
p_intf->pf_run = Run; |
|---|
| 100 |
|
|---|
| 101 |
p_sys->psz_file = var_CreateGetNonEmptyString( p_intf, "lirc-file" ); |
|---|
| 102 |
p_sys->i_fd = lirc_init( "vlc", 1 ); |
|---|
| 103 |
if( p_sys->i_fd == -1 ) |
|---|
| 104 |
{ |
|---|
| 105 |
msg_Err( p_intf, "lirc initialisation failed" ); |
|---|
| 106 |
goto exit; |
|---|
| 107 |
} |
|---|
| 108 |
|
|---|
| 109 |
|
|---|
| 110 |
fcntl( p_sys->i_fd, F_SETFL, fcntl( p_sys->i_fd, F_GETFL ) | O_NONBLOCK ); |
|---|
| 111 |
|
|---|
| 112 |
|
|---|
| 113 |
if( lirc_readconfig( p_sys->psz_file, &p_sys->config, NULL ) != 0 ) |
|---|
| 114 |
{ |
|---|
| 115 |
msg_Err( p_intf, "failure while reading lirc config" ); |
|---|
| 116 |
goto exit; |
|---|
| 117 |
} |
|---|
| 118 |
|
|---|
| 119 |
return VLC_SUCCESS; |
|---|
| 120 |
|
|---|
| 121 |
exit: |
|---|
| 122 |
if( p_sys->i_fd != -1 ) |
|---|
| 123 |
lirc_deinit(); |
|---|
| 124 |
free( p_sys->psz_file ); |
|---|
| 125 |
free( p_sys ); |
|---|
| 126 |
return VLC_EGENERIC; |
|---|
| 127 |
} |
|---|
| 128 |
|
|---|
| 129 |
|
|---|
| 130 |
|
|---|
| 131 |
|
|---|
| 132 |
static void Close( vlc_object_t *p_this ) |
|---|
| 133 |
{ |
|---|
| 134 |
intf_thread_t *p_intf = (intf_thread_t *)p_this; |
|---|
| 135 |
intf_sys_t *p_sys = p_intf->p_sys; |
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 |
lirc_freeconfig( p_sys->config ); |
|---|
| 139 |
lirc_deinit(); |
|---|
| 140 |
free( p_sys->psz_file ); |
|---|
| 141 |
free( p_sys ); |
|---|
| 142 |
} |
|---|
| 143 |
|
|---|
| 144 |
|
|---|
| 145 |
|
|---|
| 146 |
|
|---|
| 147 |
static void Run( intf_thread_t *p_intf ) |
|---|
| 148 |
{ |
|---|
| 149 |
intf_sys_t *p_sys = p_intf->p_sys; |
|---|
| 150 |
|
|---|
| 151 |
for( ;; ) |
|---|
| 152 |
{ |
|---|
| 153 |
|
|---|
| 154 |
struct pollfd ufd = { .fd = p_sys->i_fd, .events = POLLIN, .revents = 0 }; |
|---|
| 155 |
if( poll( &ufd, 1, -1 ) == -1 ) |
|---|
| 156 |
break; |
|---|
| 157 |
|
|---|
| 158 |
|
|---|
| 159 |
int canc = vlc_savecancel(); |
|---|
| 160 |
Process( p_intf ); |
|---|
| 161 |
vlc_restorecancel(canc); |
|---|
| 162 |
} |
|---|
| 163 |
} |
|---|
| 164 |
|
|---|
| 165 |
static int Process( intf_thread_t *p_intf ) |
|---|
| 166 |
{ |
|---|
| 167 |
for( ;; ) |
|---|
| 168 |
{ |
|---|
| 169 |
char *code, *c; |
|---|
| 170 |
int i_ret = lirc_nextcode( &code ); |
|---|
| 171 |
|
|---|
| 172 |
if( i_ret ) |
|---|
| 173 |
return i_ret; |
|---|
| 174 |
|
|---|
| 175 |
if( code == NULL ) |
|---|
| 176 |
return 0; |
|---|
| 177 |
|
|---|
| 178 |
while( vlc_object_alive( p_intf ) |
|---|
| 179 |
&& (lirc_code2char( p_intf->p_sys->config, code, &c ) == 0) |
|---|
| 180 |
&& (c != NULL) ) |
|---|
| 181 |
{ |
|---|
| 182 |
vlc_value_t keyval; |
|---|
| 183 |
|
|---|
| 184 |
if( !strncmp( "key-", c, 4 ) ) |
|---|
| 185 |
{ |
|---|
| 186 |
keyval.i_int = config_GetInt( p_intf, c ); |
|---|
| 187 |
var_Set( p_intf->p_libvlc, "key-pressed", keyval ); |
|---|
| 188 |
} |
|---|
| 189 |
else if( !strncmp( "menu ", c, 5) ) |
|---|
| 190 |
{ |
|---|
| 191 |
if( !strncmp( c, "menu on", 7 ) || |
|---|
| 192 |
!strncmp( c, "menu show", 9 )) |
|---|
| 193 |
osd_MenuShow( VLC_OBJECT(p_intf) ); |
|---|
| 194 |
else if( !strncmp( c, "menu off", 8 ) || |
|---|
| 195 |
!strncmp( c, "menu hide", 9 ) ) |
|---|
| 196 |
osd_MenuHide( VLC_OBJECT(p_intf) ); |
|---|
| 197 |
else if( !strncmp( c, "menu up", 7 ) ) |
|---|
| 198 |
osd_MenuUp( VLC_OBJECT(p_intf) ); |
|---|
| 199 |
else if( !strncmp( c, "menu down", 9 ) ) |
|---|
| 200 |
osd_MenuDown( VLC_OBJECT(p_intf) ); |
|---|
| 201 |
else if( !strncmp( c, "menu left", 9 ) ) |
|---|
| 202 |
osd_MenuPrev( VLC_OBJECT(p_intf) ); |
|---|
| 203 |
else if( !strncmp( c, "menu right", 10 ) ) |
|---|
| 204 |
osd_MenuNext( VLC_OBJECT(p_intf) ); |
|---|
| 205 |
else if( !strncmp( c, "menu select", 11 ) ) |
|---|
| 206 |
osd_MenuActivate( VLC_OBJECT(p_intf) ); |
|---|
| 207 |
else |
|---|
| 208 |
{ |
|---|
| 209 |
msg_Err( p_intf, "Please provide one of the following parameters:" ); |
|---|
| 210 |
msg_Err( p_intf, "[on|off|up|down|left|right|select]" ); |
|---|
| 211 |
break; |
|---|
| 212 |
} |
|---|
| 213 |
} |
|---|
| 214 |
else |
|---|
| 215 |
{ |
|---|
| 216 |
msg_Err( p_intf, "this doesn't appear to be a valid keycombo lirc sent us. Please look at the doc/lirc/example.lirc file in VLC" ); |
|---|
| 217 |
break; |
|---|
| 218 |
} |
|---|
| 219 |
} |
|---|
| 220 |
free( code ); |
|---|
| 221 |
} |
|---|
| 222 |
} |
|---|