| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
#include "vlc_internal.h" |
|---|
| 25 |
#include "../../src/libvlc.h" |
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
#ifndef vlcinternalMODINIT_FUNC |
|---|
| 32 |
#define vlcinternalMODINIT_FUNC void |
|---|
| 33 |
#endif |
|---|
| 34 |
|
|---|
| 35 |
static PyMethodDef vlcinternal_methods[] = { |
|---|
| 36 |
{ NULL } |
|---|
| 37 |
}; |
|---|
| 38 |
|
|---|
| 39 |
vlcinternalMODINIT_FUNC |
|---|
| 40 |
initvlcinternal( void ) |
|---|
| 41 |
{ |
|---|
| 42 |
PyObject* p_module; |
|---|
| 43 |
|
|---|
| 44 |
p_module = Py_InitModule3( "vlcinternal", vlcinternal_methods, |
|---|
| 45 |
"VLC media player internal module" ); |
|---|
| 46 |
|
|---|
| 47 |
if( !p_module ) |
|---|
| 48 |
return; |
|---|
| 49 |
|
|---|
| 50 |
if( PyType_Ready( &vlcObject_Type ) < 0 ) |
|---|
| 51 |
return; |
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
Py_INCREF( &vlcObject_Type ); |
|---|
| 55 |
PyModule_AddObject( p_module, "Object", |
|---|
| 56 |
( PyObject * )&vlcObject_Type ); |
|---|
| 57 |
} |
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
void * fast_memcpy( void * to, const void * from, size_t len ) |
|---|
| 62 |
{ |
|---|
| 63 |
return memcpy( to, from, len ); |
|---|
| 64 |
} |
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 |
static PyObject |
|---|
| 71 |
*vlcObject_new( PyTypeObject *p_type, PyObject *p_args, PyObject *p_kwds ) |
|---|
| 72 |
{ |
|---|
| 73 |
vlcObject *self; |
|---|
| 74 |
vlc_object_t *p_object; |
|---|
| 75 |
int i_id; |
|---|
| 76 |
|
|---|
| 77 |
self = PyObject_New( vlcObject, &vlcObject_Type ); |
|---|
| 78 |
|
|---|
| 79 |
if( !PyArg_ParseTuple( p_args, "i", &i_id ) ) |
|---|
| 80 |
return NULL; |
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 |
p_object = ( vlc_object_t* )vlc_current_object( i_id ); |
|---|
| 84 |
|
|---|
| 85 |
if( !p_object ) |
|---|
| 86 |
{ |
|---|
| 87 |
|
|---|
| 88 |
i_id = VLC_Create(); |
|---|
| 89 |
if( i_id < 0 ) |
|---|
| 90 |
{ |
|---|
| 91 |
PyErr_SetString( PyExc_StandardError, "Unable to create a VLC instance." ); |
|---|
| 92 |
return NULL; |
|---|
| 93 |
} |
|---|
| 94 |
p_object = ( vlc_object_t* )vlc_current_object( i_id ); |
|---|
| 95 |
} |
|---|
| 96 |
|
|---|
| 97 |
if( !p_object ) |
|---|
| 98 |
{ |
|---|
| 99 |
PyErr_SetString( PyExc_StandardError, "Unable to get object." ); |
|---|
| 100 |
return NULL; |
|---|
| 101 |
} |
|---|
| 102 |
|
|---|
| 103 |
self->p_object = p_object; |
|---|
| 104 |
self->b_released = 0; |
|---|
| 105 |
|
|---|
| 106 |
Py_INCREF( self ); |
|---|
| 107 |
return ( PyObject * )self; |
|---|
| 108 |
} |
|---|
| 109 |
|
|---|
| 110 |
static PyObject * |
|---|
| 111 |
vlcObject_release( PyObject *self, PyObject *p_args ) |
|---|
| 112 |
{ |
|---|
| 113 |
if( VLCSELF->b_released == 0 ) |
|---|
| 114 |
{ |
|---|
| 115 |
vlc_object_release( VLCSELF->p_object ); |
|---|
| 116 |
VLCSELF->b_released = 1; |
|---|
| 117 |
} |
|---|
| 118 |
Py_INCREF( Py_None ); |
|---|
| 119 |
return Py_None; |
|---|
| 120 |
} |
|---|
| 121 |
|
|---|
| 122 |
static void |
|---|
| 123 |
vlcObject_dealloc( PyObject *self ) |
|---|
| 124 |
{ |
|---|
| 125 |
vlcObject_release( self, NULL ); |
|---|
| 126 |
PyObject_DEL( self ); |
|---|
| 127 |
} |
|---|
| 128 |
|
|---|
| 129 |
static PyObject * |
|---|
| 130 |
vlcObject_find_object( PyObject *self, PyObject *args ) |
|---|
| 131 |
{ |
|---|
| 132 |
vlcObject *p_retval; |
|---|
| 133 |
vlc_object_t *p_obj; |
|---|
| 134 |
char *psz_name; |
|---|
| 135 |
int i_object_type; |
|---|
| 136 |
|
|---|
| 137 |
if( !PyArg_ParseTuple( args, "s", &psz_name ) ) |
|---|
| 138 |
return NULL; |
|---|
| 139 |
|
|---|
| 140 |
|
|---|
| 141 |
|
|---|
| 142 |
|
|---|
| 143 |
if( !strncmp( psz_name, "aout", 4 ) ) |
|---|
| 144 |
{ |
|---|
| 145 |
i_object_type = VLC_OBJECT_AOUT; |
|---|
| 146 |
} |
|---|
| 147 |
else if (! strncmp( psz_name, "decoder", 7 ) ) |
|---|
| 148 |
{ |
|---|
| 149 |
i_object_type = VLC_OBJECT_DECODER; |
|---|
| 150 |
} |
|---|
| 151 |
else if (! strncmp( psz_name, "httpd", 5 ) ) |
|---|
| 152 |
{ |
|---|
| 153 |
i_object_type = VLC_OBJECT_HTTPD; |
|---|
| 154 |
} |
|---|
| 155 |
else if (! strncmp( psz_name, "intf", 4 ) ) |
|---|
| 156 |
{ |
|---|
| 157 |
i_object_type = VLC_OBJECT_INTF; |
|---|
| 158 |
} |
|---|
| 159 |
else if (! strncmp( psz_name, "input", 5 ) ) |
|---|
| 160 |
{ |
|---|
| 161 |
i_object_type = VLC_OBJECT_INPUT; |
|---|
| 162 |
} |
|---|
| 163 |
else if (! strncmp( psz_name, "playlist", 8 ) ) |
|---|
| 164 |
{ |
|---|
| 165 |
i_object_type = VLC_OBJECT_PLAYLIST; |
|---|
| 166 |
} |
|---|
| 167 |
else if (! strncmp( psz_name, "libvlc", 6 ) ) |
|---|
| 168 |
{ |
|---|
| 169 |
i_object_type = VLC_OBJECT_LIBVLC; |
|---|
| 170 |
} |
|---|
| 171 |
else if (! strncmp( psz_name, "vout", 4 ) ) |
|---|
| 172 |
{ |
|---|
| 173 |
i_object_type = VLC_OBJECT_VOUT; |
|---|
| 174 |
} |
|---|
| 175 |
else if (! strncmp( psz_name, "sout", 4 ) ) |
|---|
| 176 |
{ |
|---|
| 177 |
i_object_type = VLC_OBJECT_SOUT; |
|---|
| 178 |
} |
|---|
| 179 |
else if (! strncmp( psz_name, "global", 6 ) ) |
|---|
| 180 |
{ |
|---|
| 181 |
i_object_type = VLC_OBJECT_GLOBAL; |
|---|
| 182 |
} |
|---|
| 183 |
else if (! strncmp( psz_name, "packetizer", 10 ) ) |
|---|
| 184 |
{ |
|---|
| 185 |
i_object_type = VLC_OBJECT_PACKETIZER; |
|---|
| 186 |
} |
|---|
| 187 |
else if (! strncmp( psz_name, "encoder", 7 ) ) |
|---|
| 188 |
{ |
|---|
| 189 |
i_object_type = VLC_OBJECT_ENCODER; |
|---|
| 190 |
} |
|---|
| 191 |
else if (! strncmp( psz_name, "vlm", 3 ) ) |
|---|
| 192 |
{ |
|---|
| 193 |
i_object_type = VLC_OBJECT_VLM; |
|---|
| 194 |
} |
|---|
| 195 |
else if (! strncmp( psz_name, "announce", 8 ) ) |
|---|
| 196 |
{ |
|---|
| 197 |
i_object_type = VLC_OBJECT_ANNOUNCE; |
|---|
| 198 |
} |
|---|
| 199 |
else if (! strncmp( psz_name, "demux", 5 ) ) |
|---|
| 200 |
{ |
|---|
| 201 |
i_object_type = VLC_OBJECT_DEMUX; |
|---|
| 202 |
} |
|---|
| 203 |
else if (! strncmp( psz_name, "access", 6 ) ) |
|---|
| 204 |
{ |
|---|
| 205 |
i_object_type = VLC_OBJECT_ACCESS; |
|---|
| 206 |
} |
|---|
| 207 |
else if (! strncmp( psz_name, "stream", 6 ) ) |
|---|
| 208 |
{ |
|---|
| 209 |
i_object_type = VLC_OBJECT_STREAM; |
|---|
| 210 |
} |
|---|
| 211 |
else if (! strncmp( psz_name, "filter", 6 ) ) |
|---|
| 212 |
{ |
|---|
| 213 |
i_object_type = VLC_OBJECT_FILTER; |
|---|
| 214 |
} |
|---|
| 215 |
else if (! strncmp( psz_name, "vod", 3 ) ) |
|---|
| 216 |
{ |
|---|
| 217 |
i_object_type = VLC_OBJECT_VOD; |
|---|
| 218 |
} |
|---|
| 219 |
else if (! strncmp( psz_name, "xml", 3 ) ) |
|---|
| 220 |
{ |
|---|
| 221 |
i_object_type = VLC_OBJECT_XML; |
|---|
| 222 |
} |
|---|
| 223 |
else if (! strncmp( psz_name, "osdmenu", 7 ) ) |
|---|
| 224 |
{ |
|---|
| 225 |
i_object_type = VLC_OBJECT_OSDMENU; |
|---|
| 226 |
} |
|---|
| 227 |
else if (! strncmp( psz_name, "stats", 5 ) ) |
|---|
| 228 |
{ |
|---|
| 229 |
i_object_type = VLC_OBJECT_STATS; |
|---|
| 230 |
} |
|---|
| 231 |
else if (! strncmp( psz_name, "metaengine", 10 ) ) |
|---|
| 232 |
{ |
|---|
| 233 |
i_object_type = VLC_OBJECT_META_ENGINE; |
|---|
| 234 |
} |
|---|
| 235 |
else |
|---|
| 236 |
{ |
|---|
| 237 |
|
|---|
| 238 |
Py_INCREF( Py_None ); |
|---|
| 239 |
return Py_None; |
|---|
| 240 |
} |
|---|
| 241 |
|
|---|
| 242 |
p_obj = vlc_object_find( VLCSELF->p_object, i_object_type, FIND_ANYWHERE ); |
|---|
| 243 |
|
|---|
| 244 |
if( !p_obj ) |
|---|
| 245 |
{ |
|---|
| 246 |
Py_INCREF( Py_None ); |
|---|
| 247 |
return Py_None; |
|---|
| 248 |
} |
|---|
| 249 |
|
|---|
| 250 |
p_retval = PyObject_New( vlcObject, &vlcObject_Type ); |
|---|
| 251 |
|
|---|
| 252 |
p_retval->p_object = p_obj; |
|---|
| 253 |
|
|---|
| 254 |
return ( PyObject * )p_retval; |
|---|
| 255 |
} |
|---|
| 256 |
|
|---|
| 257 |
static PyObject * |
|---|
| 258 |
vlcObject_find_name( PyObject *self, PyObject *args ) |
|---|
| 259 |
{ |
|---|
| 260 |
vlcObject *p_retval; |
|---|
| 261 |
vlc_object_t *p_obj; |
|---|
| 262 |
char *psz_name; |
|---|
| 263 |
|
|---|
| 264 |
if( !PyArg_ParseTuple( args, "s", &psz_name ) ) |
|---|
| 265 |
return NULL; |
|---|
| 266 |
|
|---|
| 267 |
p_obj = vlc_object_find_name( VLCSELF->p_object, psz_name, FIND_ANYWHERE ); |
|---|
| 268 |
|
|---|
| 269 |
if( !p_obj ) |
|---|
| 270 |
{ |
|---|
| 271 |
Py_INCREF( Py_None ); |
|---|
| 272 |
return Py_None; |
|---|
| 273 |
} |
|---|
| 274 |
|
|---|
| 275 |
p_retval = PyObject_New( vlcObject, &vlcObject_Type ); |
|---|
| 276 |
|
|---|
| 277 |
p_retval->p_object = p_obj; |
|---|
| 278 |
|
|---|
| 279 |
return ( PyObject * )p_retval; |
|---|
| 280 |
} |
|---|
| 281 |
|
|---|
| 282 |
static PyObject * |
|---|
| 283 |
vlcObject_info( PyObject *self, PyObject *args ) |
|---|
| 284 |
{ |
|---|
| 285 |
PyObject *p_retval; |
|---|
| 286 |
vlc_object_t *p_obj; |
|---|
| 287 |
vlc_object_internals_t *p_priv; |
|---|
| 288 |
|
|---|
| 289 |
p_obj = VLCSELF->p_object; |
|---|
| 290 |
p_priv = vlc_internals( p_obj ); |
|---|
| 291 |
|
|---|
| 292 |
|
|---|
| 293 |
p_retval = PyDict_New(); |
|---|
| 294 |
|
|---|
| 295 |
PyDict_SetItemString( p_retval, "object-id", |
|---|
| 296 |
Py_BuildValue( "l", p_obj->i_object_id ) ); |
|---|
| 297 |
PyDict_SetItemString( p_retval, "object-type", |
|---|
| 298 |
Py_BuildValue( "s", p_obj->psz_object_type ) ); |
|---|
| 299 |
PyDict_SetItemString( p_retval, "object-name", |
|---|
| 300 |
Py_BuildValue( "s", p_obj->psz_object_name ) ); |
|---|
| 301 |
PyDict_SetItemString( p_retval, "thread", |
|---|
| 302 |
PyBool_FromLong( p_priv->b_thread ) ); |
|---|
| 303 |
PyDict_SetItemString( p_retval, "thread-id", |
|---|
| 304 |
PyLong_FromLongLong( p_priv->thread_id ) ); |
|---|
| 305 |
PyDict_SetItemString( p_retval, "refcount", |
|---|
| 306 |
PyInt_FromLong( p_priv->i_refcount ) ); |
|---|
| 307 |
return p_retval; |
|---|
| 308 |
} |
|---|
| 309 |
|
|---|
| 310 |
static PyObject * |
|---|
| 311 |
vlcObject_find_id( PyObject *self, PyObject *args ) |
|---|
| 312 |
{ |
|---|
| 313 |
vlcObject *p_retval; |
|---|
| 314 |
vlc_object_t* p_object; |
|---|
| 315 |
int i_id; |
|---|
| 316 |
|
|---|
| 317 |
if( !PyArg_ParseTuple( args, "i", &i_id ) ) |
|---|
| 318 |
return NULL; |
|---|
| 319 |
|
|---|
| 320 |
p_object = ( vlc_object_t* )vlc_current_object( i_id ); |
|---|
| 321 |
|
|---|
| 322 |
if( !p_object ) |
|---|
| 323 |
{ |
|---|
| 324 |
Py_INCREF( Py_None ); |
|---|
| 325 |
return Py_None; |
|---|
| 326 |
} |
|---|
| 327 |
|
|---|
| 328 |
p_retval = PyObject_NEW( vlcObject, &vlcObject_Type ); |
|---|
| 329 |
|
|---|
| 330 |
p_retval->p_object = p_object; |
|---|
| 331 |
|
|---|
| 332 |
return ( PyObject * )p_retval; |
|---|
| 333 |
} |
|---|
| 334 |
|
|---|
| 335 |
|
|---|
| 336 |
static PyObject * |
|---|
| 337 |
vlcObject_var_get( PyObject *self, PyObject *args ) |
|---|
| 338 |
{ |
|---|
| 339 |
PyObject *p_retval; |
|---|
| 340 |
vlc_value_t value; |
|---|
| 341 |
char *psz_name; |
|---|
| 342 |
int i_type; |
|---|
| 343 |
|
|---|
| 344 |
if( !PyArg_ParseTuple( args, "s", &psz_name ) ) |
|---|
| 345 |
return NULL; |
|---|
| 346 |
|
|---|
| 347 |
if( var_Get( VLCSELF->p_object, psz_name, &value ) != VLC_SUCCESS ) |
|---|
| 348 |
{ |
|---|
| 349 |
PyErr_SetString( PyExc_StandardError, |
|---|
| 350 |
"Error: variable does not exist.\n" ); |
|---|
| 351 |
return NULL; |
|---|
| 352 |
} |
|---|
| 353 |
|
|---|
| 354 |
i_type = var_Type ( VLCSELF->p_object, psz_name ); |
|---|
| 355 |
|
|---|
| 356 |
switch ( i_type ) |
|---|
| 357 |
{ |
|---|
| 358 |
case VLC_VAR_VOID : |
|---|
| 359 |
p_retval = PyString_FromString( "A void variable" ); |
|---|
| 360 |
break; |
|---|
| 361 |
case VLC_VAR_BOOL : |
|---|
| 362 |
p_retval = PyBool_FromLong( value.b_bool ); |
|---|
| 363 |
break; |
|---|
| 364 |
case VLC_VAR_INTEGER : |
|---|
| 365 |
p_retval = PyInt_FromLong( ( long )value.i_int ); |
|---|
| 366 |
break; |
|---|
| 367 |
case VLC_VAR_HOTKEY : |
|---|
| 368 |
p_retval = PyString_FromFormat( "A hotkey variable ( %d )", value.i_int ); |
|---|
| 369 |
break; |
|---|
| 370 |
case VLC_VAR_FILE : |
|---|
| 371 |
case VLC_VAR_STRING : |
|---|
| 372 |
case VLC_VAR_DIRECTORY : |
|---|
| 373 |
case VLC_VAR_VARIABLE : |
|---|
| 374 |
p_retval = PyString_FromString( value.psz_string ); |
|---|
| 375 |
break; |
|---|
| 376 |
case VLC_VAR_MODULE : |
|---|
| 377 |
p_retval = ( PyObject* )PyObject_New( vlcObject, &vlcObject_Type ); |
|---|
| 378 |
( ( vlcObject* )p_retval )->p_object = value.p_object; |
|---|
| 379 |
break; |
|---|
| 380 |
case VLC_VAR_FLOAT : |
|---|
| 381 |
p_retval = PyFloat_FromDouble( ( double )value.f_float ); |
|---|
| 382 |
break; |
|---|
| 383 |
case VLC_VAR_TIME : |
|---|
| 384 |
p_retval = PyLong_FromLongLong( value.i_time ); |
|---|
| 385 |
break; |
|---|
| 386 |
case VLC_VAR_ADDRESS : |
|---|
| 387 |
p_retval = PyString_FromString( "A VLC address ( not handled yet )" ); |
|---|
| 388 |
break; |
|---|
| 389 |
case VLC_VAR_LIST : |
|---|
| 390 |
p_retval = PyString_FromString( "A VLC list ( not handled yet )" ); |
|---|
| 391 |
break; |
|---|
| 392 |
case VLC_VAR_MUTEX : |
|---|
| 393 |
p_retval = PyString_FromString( "A mutex" ); |
|---|
| 394 |
break; |
|---|
| 395 |
default: |
|---|
| 396 |
p_retval = Py_None; |
|---|
| 397 |
} |
|---|
| 398 |
|
|---|
| 399 |
Py_INCREF( p_retval ); |
|---|
| 400 |
return p_retval; |
|---|
| 401 |
} |
|---|
| 402 |
|
|---|
| 403 |
static PyObject * |
|---|
| 404 |
vlcObject_var_type( PyObject *self, PyObject *args ) |
|---|
| 405 |
{ |
|---|
| 406 |
char *psz_name; |
|---|
| 407 |
PyObject *p_retval; |
|---|
| 408 |
int i_type; |
|---|
| 409 |
|
|---|
| 410 |
if( !PyArg_ParseTuple( args, "s", &psz_name ) ) |
|---|
| 411 |
return NULL; |
|---|
| 412 |
|
|---|
| 413 |
i_type = var_Type( VLCSELF->p_object, psz_name ); |
|---|
| 414 |
|
|---|
| 415 |
switch ( i_type ) |
|---|
| 416 |
{ |
|---|
| 417 |
case VLC_VAR_VOID : |
|---|
| 418 |
p_retval = PyString_FromString( "Void" ); |
|---|
| 419 |
break; |
|---|
| 420 |
case VLC_VAR_BOOL : |
|---|
| 421 |
p_retval = PyString_FromString( "Boolean" ); |
|---|
| 422 |
break; |
|---|
| 423 |
case VLC_VAR_INTEGER : |
|---|
| 424 |
p_retval = PyString_FromString( "Integer" ); |
|---|
| 425 |
break; |
|---|
| 426 |
case VLC_VAR_HOTKEY : |
|---|
| 427 |
p_retval = PyString_FromString( "Hotkey" ); |
|---|
| 428 |
break; |
|---|
| 429 |
case VLC_VAR_FILE : |
|---|
| 430 |
p_retval = PyString_FromString( "File" ); |
|---|
| 431 |
break; |
|---|
| 432 |
case VLC_VAR_STRING : |
|---|
| 433 |
p_retval = PyString_FromString( "String" ); |
|---|
| 434 |
break; |
|---|
| 435 |
case VLC_VAR_DIRECTORY : |
|---|
| 436 |
p_retval = PyString_FromString( "Directory" ); |
|---|
| 437 |
break; |
|---|
| 438 |
case VLC_VAR_VARIABLE : |
|---|
| 439 |
p_retval = PyString_FromString( "Variable" ); |
|---|
| 440 |
break; |
|---|
| 441 |
case VLC_VAR_MODULE : |
|---|
| 442 |
p_retval = PyString_FromString( "Module" ); |
|---|
| 443 |
break; |
|---|
| 444 |
case VLC_VAR_FLOAT : |
|---|
| 445 |
p_retval = PyString_FromString( "Float" ); |
|---|
| 446 |
break; |
|---|
| 447 |
case VLC_VAR_TIME : |
|---|
| 448 |
p_retval = PyString_FromString( "Time" ); |
|---|
| 449 |
break; |
|---|
| 450 |
case VLC_VAR_ADDRESS : |
|---|
| 451 |
p_retval = PyString_FromString( "Address" ); |
|---|
| 452 |
break; |
|---|
| 453 |
case VLC_VAR_LIST : |
|---|
| 454 |
p_retval = PyString_FromString( "List" ); |
|---|
| 455 |
break; |
|---|
| 456 |
case VLC_VAR_MUTEX : |
|---|
| 457 |
p_retval = PyString_FromString( "Mutex" ); |
|---|
| 458 |
break; |
|---|
| 459 |
default: |
|---|
| 460 |
p_retval = PyString_FromString( "Unknown" ); |
|---|
| 461 |
} |
|---|
| 462 |
return p_retval; |
|---|
| 463 |
} |
|---|
| 464 |
|
|---|
| 465 |
|
|---|
| 466 |
static PyObject * |
|---|
| 467 |
vlcObject_var_set( PyObject *self, PyObject *args ) |
|---|
| 468 |
{ |
|---|
| 469 |
vlc_value_t value; |
|---|
| 470 |
char *psz_name; |
|---|
| 471 |
PyObject *py_value; |
|---|
| 472 |
int i_type; |
|---|
| 473 |
vlc_object_t *p_obj; |
|---|
| 474 |
|
|---|
| 475 |
if( !PyArg_ParseTuple( args, "sO", &psz_name, &py_value ) ) |
|---|
| 476 |
return NULL; |
|---|
| 477 |
|
|---|
| 478 |
p_obj = VLCSELF->p_object; |
|---|
| 479 |
i_type = var_Type( p_obj, psz_name ); |
|---|
| 480 |
|
|---|
| 481 |
switch ( i_type ) |
|---|
| 482 |
{ |
|---|
| 483 |
case VLC_VAR_VOID : |
|---|
| 484 |
break; |
|---|
| 485 |
case VLC_VAR_BOOL : |
|---|
| 486 |
value.b_bool = PyInt_AsLong( py_value ); |
|---|
| 487 |
break; |
|---|
| 488 |
case VLC_VAR_INTEGER : |
|---|
| 489 |
case VLC_VAR_HOTKEY : |
|---|
| 490 |
value.i_int = PyInt_AsLong( py_value ); |
|---|
| 491 |
break; |
|---|
| 492 |
case VLC_VAR_FILE : |
|---|
| 493 |
case VLC_VAR_STRING : |
|---|
| 494 |
case VLC_VAR_DIRECTORY : |
|---|
| 495 |
case VLC_VAR_VARIABLE : |
|---|
| 496 |
value.psz_string = strdup( PyString_AsString( py_value ) ); |
|---|
| 497 |
break; |
|---|
| 498 |
case VLC_VAR_MODULE : |
|---|
| 499 |
|
|---|
| 500 |
value.p_object = ( ( vlcObject* )p_obj )->p_object; |
|---|
| 501 |
break; |
|---|
| 502 |
case VLC_VAR_FLOAT : |
|---|
| 503 |
value.f_float = PyFloat_AsDouble( py_value ); |
|---|
| 504 |
break; |
|---|
| 505 |
case VLC_VAR_TIME : |
|---|
| 506 |
value.i_time = PyLong_AsLongLong( py_value ); |
|---|
| 507 |
break; |
|---|
| 508 |
case VLC_VAR_ADDRESS : |
|---|
| 509 |
value.p_address = ( char* )PyLong_AsVoidPtr( py_value ); |
|---|
| 510 |
break; |
|---|
| 511 |
case VLC_VAR_LIST : |
|---|
| 512 |
|
|---|
| 513 |
value.p_list = NULL; |
|---|
| 514 |
break; |
|---|
| 515 |
case VLC_VAR_MUTEX : |
|---|
| 516 |
break; |
|---|
| 517 |
} |
|---|
| 518 |
|
|---|
| 519 |
var_Set( p_obj, psz_name, value ); |
|---|
| 520 |
|
|---|
| 521 |
Py_INCREF( Py_None ); |
|---|
| 522 |
return Py_None; |
|---|
| 523 |
} |
|---|
| 524 |
|
|---|
| 525 |
static PyObject * |
|---|
| 526 |
vlcObject_var_list( PyObject *self, PyObject *args ) |
|---|
| 527 |
{ |
|---|
| 528 |
PyObject *p_retval; |
|---|
| 529 |
Py_ssize_t i_size; |
|---|
| 530 |
Py_ssize_t i_index; |
|---|
| 531 |
vlc_object_internals_t *p_priv; |
|---|
| 532 |
|
|---|
| 533 |
p_priv = vlc_internals( VLCSELF->p_object ); |
|---|
| 534 |
i_size = p_priv->i_vars; |
|---|
| 535 |
p_retval = PyTuple_New( i_size ); |
|---|
| 536 |
|
|---|
| 537 |
|
|---|
| 538 |
for ( i_index = 0 ; i_index < i_size ; i_index++ ) |
|---|
| 539 |
{ |
|---|
| 540 |
PyTuple_SetItem( p_retval, i_index, |
|---|
| 541 |
Py_BuildValue( "s", p_priv->p_vars[i_index].psz_name ) ); |
|---|
| 542 |
} |
|---|
| 543 |
|
|---|
| 544 |
return p_retval; |
|---|
| 545 |
} |
|---|
| 546 |
|
|---|
| 547 |
|
|---|
| 548 |
static PyObject * |
|---|
| 549 |
vlcObject_config_get( PyObject *self, PyObject *args ) |
|---|
| 550 |
{ |
|---|
| 551 |
PyObject *p_retval; |
|---|
| 552 |
vlc_value_t value; |
|---|
| 553 |
char *psz_name; |
|---|
| 554 |
module_config_t *p_config; |
|---|
| 555 |
|
|---|
| 556 |
if( !PyArg_ParseTuple( args, "s", &psz_name ) ) |
|---|
| 557 |
return NULL; |
|---|
| 558 |
|
|---|
| 559 |
p_config = config_FindConfig( VLCSELF->p_object, psz_name ); |
|---|
| 560 |
|
|---|
| 561 |
if( !p_config ) |
|---|
| 562 |
{ |
|---|
| 563 |
PyErr_SetString( PyExc_StandardError, |
|---|
| 564 |
"Error: config variable does not exist.\n" ); |
|---|
| 565 |
return NULL; |
|---|
| 566 |
} |
|---|
| 567 |
|
|---|
| 568 |
switch ( p_config->i_type ) |
|---|
| 569 |
{ |
|---|
| 570 |
case CONFIG_ITEM_BOOL : |
|---|
| 571 |
p_retval = PyBool_FromLong( p_config->value.i ); |
|---|
| 572 |
break; |
|---|
| 573 |
case CONFIG_ITEM_INTEGER : |
|---|
| 574 |
p_retval = PyInt_FromLong( ( long )p_config->value.i ); |
|---|
| 575 |
break; |
|---|
| 576 |
case CONFIG_ITEM_KEY : |
|---|
| 577 |
p_retval = PyString_FromFormat( "A hotkey variable ( %d )", p_config->value.i ); |
|---|
| 578 |
break; |
|---|
| 579 |
case CONFIG_ITEM_FILE : |
|---|
| 580 |
case CONFIG_ITEM_STRING : |
|---|
| 581 |
case CONFIG_ITEM_DIRECTORY : |
|---|
| 582 |
case CONFIG_ITEM_MODULE : |
|---|
| 583 |
vlc_mutex_lock( p_config->p_lock ); |
|---|
| 584 |
if( p_config->value.psz ) |
|---|
| 585 |
p_retval = PyString_FromString( p_config->value.psz ); |
|---|
| 586 |
else |
|---|
| 587 |
p_retval = PyString_FromString( "" ); |
|---|
| 588 |
vlc_mutex_unlock( p_config->p_lock ); |
|---|
| 589 |
break; |
|---|
| 590 |
p_retval = ( PyObject* )PyObject_New( vlcObject, &vlcObject_Type ); |
|---|
| 591 |
( ( vlcObject* )p_retval )->p_object = value.p_object; |
|---|
| 592 |
break; |
|---|
| 593 |
case CONFIG_ITEM_FLOAT : |
|---|
| 594 |
p_retval = PyFloat_FromDouble( ( double )p_config->value.f ); |
|---|
| 595 |
break; |
|---|
| 596 |
default: |
|---|
| 597 |
p_retval = Py_None; |
|---|
| 598 |
Py_INCREF( p_retval ); |
|---|
| 599 |
} |
|---|
| 600 |
|
|---|
| 601 |
return p_retval; |
|---|
| 602 |
} |
|---|
| 603 |
|
|---|
| 604 |
|
|---|
| 605 |
static PyObject * |
|---|
| 606 |
vlcObject_config_set( PyObject *self, PyObject *args ) |
|---|
| 607 |
{ |
|---|
| 608 |
char *psz_name; |
|---|
| 609 |
PyObject *py_value; |
|---|
| 610 |
vlc_object_t *p_obj; |
|---|
| 611 |
module_config_t *p_config; |
|---|
| 612 |
|
|---|
| 613 |
|
|---|
| 614 |
if( !PyArg_ParseTuple( args, "sO", &psz_name, &py_value ) ) |
|---|
| 615 |
return NULL; |
|---|
| 616 |
|
|---|
| 617 |
p_obj = VLCSELF->p_object; |
|---|
| 618 |
p_config = config_FindConfig( p_obj, psz_name ); |
|---|
| 619 |
|
|---|
| 620 |
if( !p_config ) |
|---|
| 621 |
{ |
|---|
| 622 |
PyErr_SetString( PyExc_StandardError, |
|---|
| 623 |
"Error: option does not exist.\n" ); |
|---|
| 624 |
return NULL; |
|---|
| 625 |
} |
|---|
| 626 |
|
|---|
| 627 |
switch ( p_config->i_type ) |
|---|
| 628 |
{ |
|---|
| 629 |
case CONFIG_ITEM_BOOL : |
|---|
| 630 |
case CONFIG_ITEM_INTEGER : |
|---|
| 631 |
case CONFIG_ITEM_KEY : |
|---|
| 632 |
config_PutInt( p_obj, psz_name, PyInt_AsLong( py_value ) ); |
|---|
| 633 |
break; |
|---|
| 634 |
case CONFIG_ITEM_FILE : |
|---|
| 635 |
case CONFIG_ITEM_STRING : |
|---|
| 636 |
case CONFIG_ITEM_DIRECTORY : |
|---|
| 637 |
case CONFIG_ITEM_MODULE : |
|---|
| 638 |
config_PutPsz( p_obj, psz_name, PyString_AsString( py_value ) ); |
|---|
| 639 |
break; |
|---|
| 640 |
case CONFIG_ITEM_FLOAT : |
|---|
| 641 |
config_PutFloat( p_obj, psz_name, PyFloat_AsDouble( py_value ) ); |
|---|
| 642 |
break; |
|---|
| 643 |
} |
|---|
| 644 |
Py_INCREF( Py_None ); |
|---|
| 645 |
return Py_None; |
|---|
| 646 |
} |
|---|
| 647 |
|
|---|
| 648 |
static PyObject * |
|---|
| 649 |
vlcObject_children( PyObject *self, PyObject *args ) |
|---|
| 650 |
{ |
|---|
| 651 |
PyObject *p_retval; |
|---|
| 652 |
Py_ssize_t i_size; |
|---|
| 653 |
Py_ssize_t i_index; |
|---|
| 654 |
|
|---|
| 655 |
i_size = VLCSELF->p_object->i_children; |
|---|
| 656 |
p_retval = PyTuple_New( i_size ); |
|---|
| 657 |
|
|---|
| 658 |
for ( i_index = 0 ; i_index < i_size ; i_index++ ) |
|---|
| 659 |
{ |
|---|
| 660 |
PyTuple_SetItem( p_retval, i_index, |
|---|
| 661 |
Py_BuildValue( "i", |
|---|
| 662 |
VLCSELF->p_object->pp_children[i_index]->i_object_id ) ); |
|---|
| 663 |
} |
|---|
| 664 |
|
|---|
| 665 |
return p_retval; |
|---|
| 666 |
} |
|---|
| 667 |
|
|---|
| 668 |
|
|---|
| 669 |
|
|---|
| 670 |
static PyMethodDef vlcObject_methods[] = |
|---|
| 671 |
{ |
|---|
| 672 |
{ "get", vlcObject_var_get, METH_VARARGS, |
|---|
| 673 |
"get( str ) -> value Get a variable value."}, |
|---|
| 674 |
{ "set", vlcObject_var_set, METH_VARARGS, |
|---|
| 675 |
"set( str, value ) Set a variable value" }, |
|---|
| 676 |
{ "config_get", vlcObject_config_get, METH_VARARGS, |
|---|
| 677 |
"config_get( str ) -> value Get a configuration option." }, |
|---|
| 678 |
{ "config_set", vlcObject_config_set, METH_VARARGS, |
|---|
| 679 |
"config_set( str, value ) Set a configuration option" }, |
|---|
| 680 |
{ "type", vlcObject_var_type, METH_VARARGS, |
|---|
| 681 |
"type( str ) -> str Get a variable type" }, |
|---|
| 682 |
{ "list", vlcObject_var_list, METH_NOARGS, |
|---|
| 683 |
"list( ) List the available variables" }, |
|---|
| 684 |
{ "children", vlcObject_children, METH_NOARGS, |
|---|
| 685 |
"children( ) List the children ids" }, |
|---|
| 686 |
{ "find_object", vlcObject_find_object, METH_VARARGS, |
|---|
| 687 |
"find_object( str ) -> Object Find the object of a given type.\n\nAvailable types are : aout, decoder, input, httpd, intf, playlist, root, vlc, vout"}, |
|---|
| 688 |
{ "find_id", vlcObject_find_id, METH_VARARGS, |
|---|
| 689 |
"find_id( int ) -> Object Find an object by id" }, |
|---|
| 690 |
{ "find_name", vlcObject_find_name, METH_VARARGS, |
|---|
| 691 |
"find_name( str ) -> Object Find an object by name" }, |
|---|
| 692 |
{ "info", vlcObject_info, METH_NOARGS, |
|---|
| 693 |
"info( ) -> dict Return information about the object" }, |
|---|
| 694 |
{ "release", vlcObject_release, METH_NOARGS, |
|---|
| 695 |
"release( ) -> Release the VLC Object" }, |
|---|
| 696 |
{ NULL, NULL, 0, NULL }, |
|---|
| 697 |
}; |
|---|
| 698 |
|
|---|
| 699 |
static PyTypeObject vlcObject_Type = |
|---|
| 700 |
{ |
|---|
| 701 |
PyObject_HEAD_INIT( NULL ) |
|---|
| 702 |
0, |
|---|
| 703 |
"vlc.Object", |
|---|
| 704 |
sizeof( vlcObject_Type ), |
|---|
| 705 |
0, |
|---|
| 706 |
( destructor )vlcObject_dealloc, |
|---|
| 707 |
0, |
|---|
| 708 |
0, |
|---|
| 709 |
0, |
|---|
| 710 |
0, |
|---|
| 711 |
0, |
|---|
| 712 |
0, |
|---|
| 713 |
0, |
|---|
| 714 |
0, |
|---|
| 715 |
0, |
|---|
| 716 |
0, |
|---|
| 717 |
0, |
|---|
| 718 |
0, |
|---|
| 719 |
0, |
|---|
| 720 |
0, |
|---|
| 721 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, |
|---|
| 722 |
"Expose VLC object internal infrastructure.\n\nConstructor: vlc.Object(object_id)\n\nPLEASE BE AWARE that accessing internal features of VLC voids the guarantee for the product and is not advised except if you know what you are doing.", |
|---|
| 723 |
0, |
|---|
| 724 |
0, |
|---|
| 725 |
0, |
|---|
| 726 |
0, |
|---|
| 727 |
0, |
|---|
| 728 |
0, |
|---|
| 729 |
vlcObject_methods, |
|---|
| 730 |
0, |
|---|
| 731 |
0, |
|---|
| 732 |
0, |
|---|
| 733 |
0, |
|---|
| 734 |
0, |
|---|
| 735 |
0, |
|---|
| 736 |
0, |
|---|
| 737 |
0, |
|---|
| 738 |
0, |
|---|
| 739 |
vlcObject_new, |
|---|
| 740 |
}; |
|---|