| 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 |
#ifdef HAVE_CONFIG_H |
|---|
| 29 |
# include "config.h" |
|---|
| 30 |
#endif |
|---|
| 31 |
|
|---|
| 32 |
#include <vlc_common.h> |
|---|
| 33 |
#include <vlc_plugin.h> |
|---|
| 34 |
#include <vlc_access.h> |
|---|
| 35 |
|
|---|
| 36 |
#include <vlc_network.h> |
|---|
| 37 |
|
|---|
| 38 |
#include <sys/types.h> |
|---|
| 39 |
#include <sys/socket.h> |
|---|
| 40 |
#include <sys/un.h> |
|---|
| 41 |
#include <unistd.h> |
|---|
| 42 |
|
|---|
| 43 |
#import <Foundation/Foundation.h> |
|---|
| 44 |
|
|---|
| 45 |
#define MTU 65535 |
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
static int Open ( vlc_object_t * ); |
|---|
| 54 |
static void Close( vlc_object_t * ); |
|---|
| 55 |
|
|---|
| 56 |
#define CHANNEL_TEXT N_("Channel number") |
|---|
| 57 |
#define CHANNEL_LONGTEXT N_( \ |
|---|
| 58 |
"EyeTV program number, or use 0 for last channel, " \ |
|---|
| 59 |
"-1 for S-Video input, -2 for Composite input" ) |
|---|
| 60 |
|
|---|
| 61 |
#define CACHING_TEXT N_("Caching value in ms") |
|---|
| 62 |
#define CACHING_LONGTEXT N_( \ |
|---|
| 63 |
"Caching value for EyeTV captures. This " \ |
|---|
| 64 |
"value should be set in milliseconds." ) |
|---|
| 65 |
|
|---|
| 66 |
vlc_module_begin(); |
|---|
| 67 |
set_shortname( "EyeTV" ); |
|---|
| 68 |
set_description( N_("EyeTV access module") ); |
|---|
| 69 |
set_category( CAT_INPUT ); |
|---|
| 70 |
set_subcategory( SUBCAT_INPUT_ACCESS ); |
|---|
| 71 |
|
|---|
| 72 |
add_integer( "eyetv-channel", 0, NULL, |
|---|
| 73 |
CHANNEL_TEXT, CHANNEL_LONGTEXT, false ); |
|---|
| 74 |
|
|---|
| 75 |
set_capability( "access", 0 ); |
|---|
| 76 |
add_shortcut( "eyetv" ); |
|---|
| 77 |
set_callbacks( Open, Close ); |
|---|
| 78 |
add_integer( "eyetv-caching", DEFAULT_PTS_DELAY / 1000, NULL, |
|---|
| 79 |
CACHING_TEXT, CACHING_LONGTEXT, true); |
|---|
| 80 |
vlc_module_end(); |
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
struct access_sys_t |
|---|
| 86 |
{ |
|---|
| 87 |
int eyetvSock; |
|---|
| 88 |
int i_pts_delay; |
|---|
| 89 |
}; |
|---|
| 90 |
|
|---|
| 91 |
static block_t *BlockRead( access_t *); |
|---|
| 92 |
static int Control( access_t *, int, va_list ); |
|---|
| 93 |
|
|---|
| 94 |
static void selectChannel( vlc_object_t *p_this, int theChannelNum ) |
|---|
| 95 |
{ |
|---|
| 96 |
NSAppleScript *script; |
|---|
| 97 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
|---|
| 98 |
switch( theChannelNum ) |
|---|
| 99 |
{ |
|---|
| 100 |
case -2: |
|---|
| 101 |
script = [[NSAppleScript alloc] initWithSource: |
|---|
| 102 |
@"tell application \"EyeTV\"\n" |
|---|
| 103 |
" input_change input source composite video input\n" |
|---|
| 104 |
" volume_change level 0\n" |
|---|
| 105 |
" show player_window\n" |
|---|
| 106 |
" tell application \"System Events\" to set visible of process \"EyeTV\" to false\n" |
|---|
| 107 |
"end tell"]; |
|---|
| 108 |
break; |
|---|
| 109 |
case -1: |
|---|
| 110 |
script = [[NSAppleScript alloc] initWithSource: |
|---|
| 111 |
@"tell application \"EyeTV\"\n" |
|---|
| 112 |
" input_change input source S video input\n" |
|---|
| 113 |
" volume_change level 0\n" |
|---|
| 114 |
" show player_window\n" |
|---|
| 115 |
" tell application \"System Events\" to set visible of process \"EyeTV\" to false\n" |
|---|
| 116 |
"end tell"]; |
|---|
| 117 |
break; |
|---|
| 118 |
case 0: |
|---|
| 119 |
script = [[NSAppleScript alloc] initWithSource: |
|---|
| 120 |
@"tell application \"EyeTV\"\n" |
|---|
| 121 |
" volume_change level 0\n" |
|---|
| 122 |
" show player_window\n" |
|---|
| 123 |
" tell application \"System Events\" to set visible of process \"EyeTV\" to false\n" |
|---|
| 124 |
"end tell"]; |
|---|
| 125 |
break; |
|---|
| 126 |
default: |
|---|
| 127 |
if( theChannelNum > 0 ) |
|---|
| 128 |
{ |
|---|
| 129 |
NSString *channel_change = [NSString stringWithFormat: |
|---|
| 130 |
@"tell application \"EyeTV\"\n" |
|---|
| 131 |
" channel_change channel number %d\n" |
|---|
| 132 |
" volume_change level 0\n" |
|---|
| 133 |
" show player_window\n" |
|---|
| 134 |
" tell application \"System Events\" to set visible of process \"EyeTV\" to false\n" |
|---|
| 135 |
"end tell", theChannelNum]; |
|---|
| 136 |
script = [[NSAppleScript alloc] initWithSource:channel_change]; |
|---|
| 137 |
} |
|---|
| 138 |
else |
|---|
| 139 |
return; |
|---|
| 140 |
} |
|---|
| 141 |
NSDictionary *errorDict; |
|---|
| 142 |
NSAppleEventDescriptor *descriptor = [script executeAndReturnError:&errorDict]; |
|---|
| 143 |
if( nil == descriptor ) |
|---|
| 144 |
{ |
|---|
| 145 |
NSString *errorString = [errorDict objectForKey:NSAppleScriptErrorMessage]; |
|---|
| 146 |
msg_Err( p_this, "EyeTV source change failed with error status '%s'", [errorString UTF8String] ); |
|---|
| 147 |
} |
|---|
| 148 |
[script release]; |
|---|
| 149 |
[pool release]; |
|---|
| 150 |
} |
|---|
| 151 |
|
|---|
| 152 |
|
|---|
| 153 |
|
|---|
| 154 |
|
|---|
| 155 |
static int Open( vlc_object_t *p_this ) |
|---|
| 156 |
{ |
|---|
| 157 |
access_t *p_access = (access_t *)p_this; |
|---|
| 158 |
access_sys_t *p_sys; |
|---|
| 159 |
|
|---|
| 160 |
struct sockaddr_un publicAddr, peerAddr; |
|---|
| 161 |
int publicSock; |
|---|
| 162 |
|
|---|
| 163 |
vlc_value_t val; |
|---|
| 164 |
|
|---|
| 165 |
|
|---|
| 166 |
access_InitFields( p_access ); \ |
|---|
| 167 |
ACCESS_SET_CALLBACKS( NULL, BlockRead, Control, NULL ); \ |
|---|
| 168 |
MALLOC_ERR( p_access->p_sys, access_sys_t ); \ |
|---|
| 169 |
p_access->info.b_prebuffered = false; |
|---|
| 170 |
|
|---|
| 171 |
p_sys = p_access->p_sys; memset( p_sys, 0, sizeof( access_sys_t ) ); |
|---|
| 172 |
p_sys->i_pts_delay = var_CreateGetInteger( p_access, "eyetv-caching" ); |
|---|
| 173 |
|
|---|
| 174 |
var_Create( p_access, "eyetv-channel", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT ); |
|---|
| 175 |
var_Get( p_access, "eyetv-channel", &val); |
|---|
| 176 |
|
|---|
| 177 |
msg_Dbg( p_access, "coming up" ); |
|---|
| 178 |
|
|---|
| 179 |
selectChannel(p_this, val.i_int); |
|---|
| 180 |
|
|---|
| 181 |
|
|---|
| 182 |
memset(&publicAddr, 0, sizeof(publicAddr)); |
|---|
| 183 |
publicAddr.sun_family = AF_UNIX; |
|---|
| 184 |
strncpy(publicAddr.sun_path, "/tmp/.vlc-eyetv-bridge", sizeof(publicAddr.sun_path)-1); |
|---|
| 185 |
|
|---|
| 186 |
if( (0 != unlink(publicAddr.sun_path)) && (ENOENT != errno) ) |
|---|
| 187 |
{ |
|---|
| 188 |
msg_Err( p_access, "local socket path is not usable (errno=%d)", errno ); |
|---|
| 189 |
free( p_sys ); |
|---|
| 190 |
return VLC_EGENERIC; |
|---|
| 191 |
} |
|---|
| 192 |
|
|---|
| 193 |
publicSock = socket(AF_UNIX, SOCK_STREAM, 0); |
|---|
| 194 |
if( publicSock == -1 ) |
|---|
| 195 |
{ |
|---|
| 196 |
msg_Err( p_access, "create local socket failed (errno=%d)", errno ); |
|---|
| 197 |
free( p_sys ); |
|---|
| 198 |
return VLC_EGENERIC; |
|---|
| 199 |
} |
|---|
| 200 |
|
|---|
| 201 |
if( bind(publicSock, (struct sockaddr *)&publicAddr, sizeof(struct sockaddr_un)) == -1 ) |
|---|
| 202 |
{ |
|---|
| 203 |
msg_Err( p_access, "bind local socket failed (errno=%d)", errno ); |
|---|
| 204 |
close( publicSock ); |
|---|
| 205 |
free( p_sys ); |
|---|
| 206 |
return VLC_EGENERIC; |
|---|
| 207 |
} |
|---|
| 208 |
|
|---|
| 209 |
|
|---|
| 210 |
if( listen(publicSock, 1) == -1 ) |
|---|
| 211 |
{ |
|---|
| 212 |
msg_Err( p_access, "cannot accept connection (errno=%d)", errno ); |
|---|
| 213 |
close( publicSock ); |
|---|
| 214 |
free( p_sys ); |
|---|
| 215 |
return VLC_EGENERIC; |
|---|
| 216 |
} |
|---|
| 217 |
else |
|---|
| 218 |
{ |
|---|
| 219 |
socklen_t peerSockLen = sizeof(struct sockaddr_un); |
|---|
| 220 |
int peerSock; |
|---|
| 221 |
|
|---|
| 222 |
|
|---|
| 223 |
CFNotificationCenterPostNotification( CFNotificationCenterGetDistributedCenter (), |
|---|
| 224 |
CFSTR("VLCAccessStartDataSending"), |
|---|
| 225 |
CFSTR("VLCEyeTVSupport"), |
|---|
| 226 |
NULL, |
|---|
| 227 |
TRUE ); |
|---|
| 228 |
|
|---|
| 229 |
msg_Dbg( p_access, "plugin notified" ); |
|---|
| 230 |
|
|---|
| 231 |
peerSock = accept(publicSock, (struct sockaddr *)&peerAddr, &peerSockLen); |
|---|
| 232 |
if( peerSock == -1 ) |
|---|
| 233 |
{ |
|---|
| 234 |
msg_Err( p_access, "cannot wait for connection (errno=%d)", errno ); |
|---|
| 235 |
close( publicSock ); |
|---|
| 236 |
free( p_sys ); |
|---|
| 237 |
return VLC_EGENERIC; |
|---|
| 238 |
} |
|---|
| 239 |
|
|---|
| 240 |
msg_Dbg( p_access, "plugin connected" ); |
|---|
| 241 |
|
|---|
| 242 |
p_sys->eyetvSock = peerSock; |
|---|
| 243 |
|
|---|
| 244 |
|
|---|
| 245 |
close(publicSock); |
|---|
| 246 |
unlink(publicAddr.sun_path); |
|---|
| 247 |
} |
|---|
| 248 |
return VLC_SUCCESS; |
|---|
| 249 |
} |
|---|
| 250 |
|
|---|
| 251 |
|
|---|
| 252 |
|
|---|
| 253 |
|
|---|
| 254 |
static void Close( vlc_object_t *p_this ) |
|---|
| 255 |
{ |
|---|
| 256 |
access_t *p_access = (access_t *)p_this; |
|---|
| 257 |
access_sys_t *p_sys = p_access->p_sys; |
|---|
| 258 |
|
|---|
| 259 |
msg_Dbg( p_access, "closing" ); |
|---|
| 260 |
|
|---|
| 261 |
|
|---|
| 262 |
CFNotificationCenterPostNotification( CFNotificationCenterGetDistributedCenter (), |
|---|
| 263 |
CFSTR("VLCAccessStopDataSending"), |
|---|
| 264 |
CFSTR("VLCEyeTVSupport"), |
|---|
| 265 |
NULL, |
|---|
| 266 |
TRUE ); |
|---|
| 267 |
|
|---|
| 268 |
msg_Dbg( p_access, "plugin notified" ); |
|---|
| 269 |
|
|---|
| 270 |
close(p_sys->eyetvSock); |
|---|
| 271 |
|
|---|
| 272 |
msg_Dbg( p_access, "msg port closed and freed" ); |
|---|
| 273 |
|
|---|
| 274 |
free( p_sys ); |
|---|
| 275 |
} |
|---|
| 276 |
|
|---|
| 277 |
|
|---|
| 278 |
|
|---|
| 279 |
|
|---|
| 280 |
static block_t *BlockRead( access_t *p_access ) |
|---|
| 281 |
{ |
|---|
| 282 |
access_sys_t *p_sys = p_access->p_sys; |
|---|
| 283 |
block_t *p_block; |
|---|
| 284 |
ssize_t len; |
|---|
| 285 |
|
|---|
| 286 |
if( p_access->info.b_eof ) |
|---|
| 287 |
return NULL; |
|---|
| 288 |
|
|---|
| 289 |
|
|---|
| 290 |
p_block = block_New( p_access, MTU ); |
|---|
| 291 |
len = net_Read( p_access, p_sys->eyetvSock, NULL, |
|---|
| 292 |
p_block->p_buffer, MTU, false ); |
|---|
| 293 |
|
|---|
| 294 |
if( len < 0 ) |
|---|
| 295 |
{ |
|---|
| 296 |
block_Release( p_block ); |
|---|
| 297 |
return NULL; |
|---|
| 298 |
} |
|---|
| 299 |
|
|---|
| 300 |
return block_Realloc( p_block, 0, p_block->i_buffer = len ); |
|---|
| 301 |
} |
|---|
| 302 |
|
|---|
| 303 |
|
|---|
| 304 |
|
|---|
| 305 |
|
|---|
| 306 |
static int Control( access_t *p_access, int i_query, va_list args ) |
|---|
| 307 |
{ |
|---|
| 308 |
bool *pb_bool; |
|---|
| 309 |
int *pi_int; |
|---|
| 310 |
int64_t *pi_64; |
|---|
| 311 |
access_sys_t *p_sys = (access_sys_t *) p_access->p_sys; |
|---|
| 312 |
|
|---|
| 313 |
switch( i_query ) |
|---|
| 314 |
{ |
|---|
| 315 |
case ACCESS_CAN_SEEK: |
|---|
| 316 |
case ACCESS_CAN_FASTSEEK: |
|---|
| 317 |
pb_bool = (bool*)va_arg( args, bool* ); |
|---|
| 318 |
*pb_bool = false; |
|---|
| 319 |
break; |
|---|
| 320 |
case ACCESS_CAN_PAUSE: |
|---|
| 321 |
pb_bool = (bool*)va_arg( args, bool* ); |
|---|
| 322 |
*pb_bool = false; |
|---|
| 323 |
break; |
|---|
| 324 |
case ACCESS_CAN_CONTROL_PACE: |
|---|
| 325 |
pb_bool = (bool*)va_arg( args, bool* ); |
|---|
| 326 |
*pb_bool = false; |
|---|
| 327 |
break; |
|---|
| 328 |
|
|---|
| 329 |
|
|---|
| 330 |
case ACCESS_GET_MTU: |
|---|
| 331 |
pi_int = (int*)va_arg( args, int * ); |
|---|
| 332 |
*pi_int = MTU; |
|---|
| 333 |
break; |
|---|
| 334 |
|
|---|
| 335 |
case ACCESS_GET_PTS_DELAY: |
|---|
| 336 |
pi_64 = (int64_t*)va_arg( args, int64_t * ); |
|---|
| 337 |
*pi_64 = (int64_t) p_sys->i_pts_delay * 1000; |
|---|
| 338 |
break; |
|---|
| 339 |
|
|---|
| 340 |
case ACCESS_SET_PAUSE_STATE: |
|---|
| 341 |
case ACCESS_GET_TITLE_INFO: |
|---|
| 342 |
case ACCESS_SET_TITLE: |
|---|
| 343 |
case ACCESS_SET_SEEKPOINT: |
|---|
| 344 |
case ACCESS_SET_PRIVATE_ID_STATE: |
|---|
| 345 |
case ACCESS_GET_CONTENT_TYPE: |
|---|
| 346 |
return VLC_EGENERIC; |
|---|
| 347 |
|
|---|
| 348 |
default: |
|---|
| 349 |
msg_Warn( p_access, "unimplemented query in control" ); |
|---|
| 350 |
return VLC_EGENERIC; |
|---|
| 351 |
|
|---|
| 352 |
} |
|---|
| 353 |
return VLC_SUCCESS; |
|---|
| 354 |
} |
|---|