| 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 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
#ifdef HAVE_CONFIG_H |
|---|
| 37 |
# include "config.h" |
|---|
| 38 |
#endif |
|---|
| 39 |
|
|---|
| 40 |
#include <vlc_common.h> |
|---|
| 41 |
|
|---|
| 42 |
#include <vlc_aout.h> |
|---|
| 43 |
#include <vlc_vout.h> |
|---|
| 44 |
|
|---|
| 45 |
#include "vlc_interface.h" |
|---|
| 46 |
#include "libvlc.h" |
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
static void* RunInterface( vlc_object_t *p_this ); |
|---|
| 52 |
#if defined( __APPLE__ ) || defined( WIN32 ) |
|---|
| 53 |
static void * MonitorLibVLCDeath( vlc_object_t *p_this ); |
|---|
| 54 |
#endif |
|---|
| 55 |
static int AddIntfCallback( vlc_object_t *, char const *, |
|---|
| 56 |
vlc_value_t , vlc_value_t , void * ); |
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
static void intf_Destroy( vlc_object_t *obj ) |
|---|
| 65 |
{ |
|---|
| 66 |
intf_thread_t *p_intf = (intf_thread_t *)obj; |
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
if( p_intf->p_module ) |
|---|
| 70 |
module_unneed( p_intf, p_intf->p_module ); |
|---|
| 71 |
|
|---|
| 72 |
free( p_intf->psz_intf ); |
|---|
| 73 |
vlc_mutex_destroy( &p_intf->change_lock ); |
|---|
| 74 |
} |
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 |
intf_thread_t* __intf_Create( vlc_object_t *p_this, const char *psz_module ) |
|---|
| 90 |
{ |
|---|
| 91 |
intf_thread_t * p_intf; |
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 |
p_intf = vlc_object_create( p_this, VLC_OBJECT_INTF ); |
|---|
| 95 |
if( !p_intf ) |
|---|
| 96 |
return NULL; |
|---|
| 97 |
p_intf->b_interaction = false; |
|---|
| 98 |
#if defined( __APPLE__ ) || defined( WIN32 ) |
|---|
| 99 |
p_intf->b_should_run_on_first_thread = false; |
|---|
| 100 |
#endif |
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 |
p_intf->psz_intf = strdup( psz_module ); |
|---|
| 104 |
p_intf->p_module = module_need( p_intf, "interface", psz_module, true ); |
|---|
| 105 |
|
|---|
| 106 |
if( p_intf->p_module == NULL ) |
|---|
| 107 |
{ |
|---|
| 108 |
msg_Err( p_intf, "no suitable interface module" ); |
|---|
| 109 |
free( p_intf->psz_intf ); |
|---|
| 110 |
vlc_object_release( p_intf ); |
|---|
| 111 |
return NULL; |
|---|
| 112 |
} |
|---|
| 113 |
|
|---|
| 114 |
|
|---|
| 115 |
p_intf->b_menu = false; |
|---|
| 116 |
p_intf->b_menu_change = false; |
|---|
| 117 |
|
|---|
| 118 |
|
|---|
| 119 |
vlc_mutex_init( &p_intf->change_lock ); |
|---|
| 120 |
|
|---|
| 121 |
|
|---|
| 122 |
vlc_object_attach( p_intf, p_this ); |
|---|
| 123 |
vlc_object_set_destructor( p_intf, intf_Destroy ); |
|---|
| 124 |
|
|---|
| 125 |
return p_intf; |
|---|
| 126 |
} |
|---|
| 127 |
|
|---|
| 128 |
|
|---|
| 129 |
|
|---|
| 130 |
|
|---|
| 131 |
|
|---|
| 132 |
|
|---|
| 133 |
|
|---|
| 134 |
|
|---|
| 135 |
|
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 |
|
|---|
| 139 |
int intf_RunThread( intf_thread_t *p_intf ) |
|---|
| 140 |
{ |
|---|
| 141 |
#if defined( __APPLE__ ) || defined( WIN32 ) |
|---|
| 142 |
|
|---|
| 143 |
|
|---|
| 144 |
if( p_intf->b_should_run_on_first_thread ) |
|---|
| 145 |
{ |
|---|
| 146 |
if( vlc_thread_create( p_intf, "interface", MonitorLibVLCDeath, |
|---|
| 147 |
VLC_THREAD_PRIORITY_LOW, false ) ) |
|---|
| 148 |
{ |
|---|
| 149 |
msg_Err( p_intf, "cannot spawn libvlc death monitoring thread" ); |
|---|
| 150 |
return VLC_EGENERIC; |
|---|
| 151 |
} |
|---|
| 152 |
RunInterface( VLC_OBJECT(p_intf) ); |
|---|
| 153 |
|
|---|
| 154 |
|
|---|
| 155 |
vlc_object_kill( p_intf ); |
|---|
| 156 |
|
|---|
| 157 |
vlc_object_signal( p_intf->p_libvlc ); |
|---|
| 158 |
vlc_thread_join( p_intf ); |
|---|
| 159 |
|
|---|
| 160 |
vlc_object_detach( p_intf ); |
|---|
| 161 |
vlc_object_release( p_intf ); |
|---|
| 162 |
return VLC_SUCCESS; |
|---|
| 163 |
} |
|---|
| 164 |
#endif |
|---|
| 165 |
|
|---|
| 166 |
if( vlc_thread_create( p_intf, "interface", RunInterface, |
|---|
| 167 |
VLC_THREAD_PRIORITY_LOW, false ) ) |
|---|
| 168 |
{ |
|---|
| 169 |
msg_Err( p_intf, "cannot spawn interface thread" ); |
|---|
| 170 |
return VLC_EGENERIC; |
|---|
| 171 |
} |
|---|
| 172 |
|
|---|
| 173 |
return VLC_SUCCESS; |
|---|
| 174 |
} |
|---|
| 175 |
|
|---|
| 176 |
|
|---|
| 177 |
|
|---|
| 178 |
|
|---|
| 179 |
|
|---|
| 180 |
|
|---|
| 181 |
|
|---|
| 182 |
|
|---|
| 183 |
void intf_StopThread( intf_thread_t *p_intf ) |
|---|
| 184 |
{ |
|---|
| 185 |
|
|---|
| 186 |
vlc_object_kill( p_intf ); |
|---|
| 187 |
vlc_thread_join( p_intf ); |
|---|
| 188 |
} |
|---|
| 189 |
|
|---|
| 190 |
|
|---|
| 191 |
|
|---|
| 192 |
|
|---|
| 193 |
|
|---|
| 194 |
|
|---|
| 195 |
static void* RunInterface( vlc_object_t *p_this ) |
|---|
| 196 |
{ |
|---|
| 197 |
intf_thread_t *p_intf = (intf_thread_t *)p_this; |
|---|
| 198 |
vlc_value_t val, text; |
|---|
| 199 |
int canc = vlc_savecancel (); |
|---|
| 200 |
|
|---|
| 201 |
|
|---|
| 202 |
var_Create( p_intf, "intf-add", VLC_VAR_STRING | |
|---|
| 203 |
VLC_VAR_HASCHOICE | VLC_VAR_ISCOMMAND ); |
|---|
| 204 |
text.psz_string = _("Add Interface"); |
|---|
| 205 |
var_Change( p_intf, "intf-add", VLC_VAR_SETTEXT, &text, NULL ); |
|---|
| 206 |
|
|---|
| 207 |
val.psz_string = (char *)"rc"; |
|---|
| 208 |
text.psz_string = (char *)_("Console"); |
|---|
| 209 |
var_Change( p_intf, "intf-add", VLC_VAR_ADDCHOICE, &val, &text ); |
|---|
| 210 |
val.psz_string = (char *)"telnet"; |
|---|
| 211 |
text.psz_string = (char *)_("Telnet Interface"); |
|---|
| 212 |
var_Change( p_intf, "intf-add", VLC_VAR_ADDCHOICE, &val, &text ); |
|---|
| 213 |
val.psz_string = (char *)"http"; |
|---|
| 214 |
text.psz_string = (char *)_("Web Interface"); |
|---|
| 215 |
var_Change( p_intf, "intf-add", VLC_VAR_ADDCHOICE, &val, &text ); |
|---|
| 216 |
val.psz_string = (char *)"logger"; |
|---|
| 217 |
text.psz_string = (char *)_("Debug logging"); |
|---|
| 218 |
var_Change( p_intf, "intf-add", VLC_VAR_ADDCHOICE, &val, &text ); |
|---|
| 219 |
val.psz_string = (char *)"gestures"; |
|---|
| 220 |
text.psz_string = (char *)_("Mouse Gestures"); |
|---|
| 221 |
var_Change( p_intf, "intf-add", VLC_VAR_ADDCHOICE, &val, &text ); |
|---|
| 222 |
|
|---|
| 223 |
var_AddCallback( p_intf, "intf-add", AddIntfCallback, NULL ); |
|---|
| 224 |
vlc_restorecancel (canc); |
|---|
| 225 |
|
|---|
| 226 |
|
|---|
| 227 |
if( p_intf->pf_run ) |
|---|
| 228 |
p_intf->pf_run( p_intf ); |
|---|
| 229 |
|
|---|
| 230 |
return NULL; |
|---|
| 231 |
} |
|---|
| 232 |
|
|---|
| 233 |
#if defined( __APPLE__ ) || defined( WIN32 ) |
|---|
| 234 |
|
|---|
| 235 |
|
|---|
| 236 |
|
|---|
| 237 |
static void * MonitorLibVLCDeath( vlc_object_t * p_this ) |
|---|
| 238 |
{ |
|---|
| 239 |
intf_thread_t *p_intf = (intf_thread_t *)p_this; |
|---|
| 240 |
libvlc_int_t * p_libvlc = p_intf->p_libvlc; |
|---|
| 241 |
int canc = vlc_savecancel (); |
|---|
| 242 |
|
|---|
| 243 |
vlc_object_lock( p_libvlc ); |
|---|
| 244 |
while(vlc_object_alive( p_libvlc ) ) |
|---|
| 245 |
{ |
|---|
| 246 |
if(p_intf->b_die) |
|---|
| 247 |
{ |
|---|
| 248 |
vlc_object_unlock( p_libvlc ); |
|---|
| 249 |
return NULL; |
|---|
| 250 |
} |
|---|
| 251 |
vlc_object_wait( p_libvlc ); |
|---|
| 252 |
} |
|---|
| 253 |
vlc_object_unlock( p_libvlc ); |
|---|
| 254 |
|
|---|
| 255 |
|
|---|
| 256 |
|
|---|
| 257 |
|
|---|
| 258 |
|
|---|
| 259 |
vlc_list_t * p_list = vlc_list_find( p_libvlc, VLC_OBJECT_INTF, FIND_CHILD ); |
|---|
| 260 |
for( int i = 0; i < p_list->i_count; i++ ) |
|---|
| 261 |
{ |
|---|
| 262 |
vlc_object_t * p_intf = p_list->p_values[i].p_object; |
|---|
| 263 |
vlc_object_kill( p_intf ); |
|---|
| 264 |
} |
|---|
| 265 |
vlc_list_release( p_list ); |
|---|
| 266 |
vlc_restorecancel (canc); |
|---|
| 267 |
return NULL; |
|---|
| 268 |
} |
|---|
| 269 |
#endif |
|---|
| 270 |
|
|---|
| 271 |
static int AddIntfCallback( vlc_object_t *p_this, char const *psz_cmd, |
|---|
| 272 |
vlc_value_t oldval, vlc_value_t newval, void *p_data ) |
|---|
| 273 |
{ |
|---|
| 274 |
intf_thread_t *p_intf; |
|---|
| 275 |
char *psz_intf = malloc( strlen(newval.psz_string) + sizeof(",none") ); |
|---|
| 276 |
|
|---|
| 277 |
(void)psz_cmd; (void)oldval; (void)p_data; |
|---|
| 278 |
|
|---|
| 279 |
|
|---|
| 280 |
sprintf( psz_intf, "%s,none", newval.psz_string ); |
|---|
| 281 |
p_intf = intf_Create( p_this->p_libvlc, psz_intf ); |
|---|
| 282 |
free( psz_intf ); |
|---|
| 283 |
if( p_intf == NULL ) |
|---|
| 284 |
{ |
|---|
| 285 |
msg_Err( p_this, "interface \"%s\" initialization failed", |
|---|
| 286 |
newval.psz_string ); |
|---|
| 287 |
return VLC_EGENERIC; |
|---|
| 288 |
} |
|---|
| 289 |
|
|---|
| 290 |
|
|---|
| 291 |
if( intf_RunThread( p_intf ) != VLC_SUCCESS ) |
|---|
| 292 |
{ |
|---|
| 293 |
vlc_object_detach( p_intf ); |
|---|
| 294 |
vlc_object_release( p_intf ); |
|---|
| 295 |
return VLC_EGENERIC; |
|---|
| 296 |
} |
|---|
| 297 |
|
|---|
| 298 |
return VLC_SUCCESS; |
|---|
| 299 |
} |
|---|
| 300 |
|
|---|