Commit 42088654 authored by Clément Stenac's avatar Clément Stenac

Merge fixes to the python binding from my branch

parent c58f4c10
...@@ -34,7 +34,8 @@ def get_ldflags(): ...@@ -34,7 +34,8 @@ def get_ldflags():
# To compile in a local vlc tree # To compile in a local vlc tree
vlclocal = Extension('vlc', vlclocal = Extension('vlc',
sources = ['vlcglue.c', '../../src/control/init.c'], sources = ['vlcglue.c',
'../../src/control/init.c'],
include_dirs = ['../../include', '../../', '/usr/win32/include' ], include_dirs = ['../../include', '../../', '/usr/win32/include' ],
extra_objects = [ '../../lib/libvlc.a' ], extra_objects = [ '../../lib/libvlc.a' ],
extra_compile_args = get_cflags(), extra_compile_args = get_cflags(),
......
#include <Python.h> /*****************************************************************************
#include "structmember.h" * vlcglue.c: VLC Module
*****************************************************************************
/* Undefine the following define to disable low-level vlc Object support */ * Copyright (C) 1998-2004 the VideoLAN team
#define VLCOBJECT_SUPPORT 1 * $Id: vlc.c 12667 2005-09-25 10:19:26Z zorglub $
*
#define __VLC__ * Authors: Olivier Aubert <oaubert at bat710.univ-lyon1.fr>
* Clment Stenac <zorglub@videolan.org>
#include <stdio.h> *
* This program is free software; you can redistribute it and/or modify
#include <vlc/control.h> * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
#define SELF ((MediaControl*)self) * (at your option) any later version.
*
#define MC_TRY exception=mediacontrol_exception_init(exception) * This program is distributed in the hope that it will be useful,
#define MC_EXCEPT \ * but WITHOUT ANY WARRANTY; without even the implied warranty of
if (exception->code) { \ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
PyObject *py_exc = MediaControl_InternalException; \ * GNU General Public License for more details.
switch (exception->code) { \ *
case mediacontrol_InternalException: \ * You should have received a copy of the GNU General Public License
py_exc = MediaControl_InternalException; \ * along with this program; if not, write to the Free Software
break; \ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
case mediacontrol_PlaylistException: \ *****************************************************************************/
py_exc = MediaControl_PlaylistException; \ #include "vlcglue.h"
break; \
case mediacontrol_InvalidPosition: \ /**************************************************************************
py_exc = MediaControl_InvalidPosition; \ * VLC Module
break; \ **************************************************************************/
case mediacontrol_PositionKeyNotSupported: \
py_exc = MediaControl_PositionKeyNotSupported; \ #ifndef vlcMODINIT_FUNC /* declarations for DLL import/export */
break; \ #define vlcMODINIT_FUNC void
case mediacontrol_PositionOriginNotSupported: \ #endif
py_exc = MediaControl_PositionOriginNotSupported; \
break; \ static PyMethodDef vlc_methods[] = {
} \ {NULL} /* Sentinel */
PyErr_SetString(py_exc, exception->message); \ };
mediacontrol_exception_free(exception); \
return NULL; \
} else { mediacontrol_exception_free(exception); }
/* Module globals */ /* Module globals */
static PyObject *MediaControl_InternalException = NULL; PyObject* MediaControl_InternalException = NULL;
static PyObject *MediaControl_PositionKeyNotSupported = NULL; PyObject* MediaControl_PositionKeyNotSupported = NULL;
static PyObject *MediaControl_PositionOriginNotSupported = NULL; PyObject *MediaControl_PositionOriginNotSupported = NULL;
static PyObject *MediaControl_InvalidPosition = NULL; PyObject* MediaControl_InvalidPosition = NULL;
static PyObject *MediaControl_PlaylistException = NULL; PyObject *MediaControl_PlaylistException = NULL;
vlcMODINIT_FUNC initvlc(void)
{
PyObject* m;
PyPosition_Type.tp_new = PyType_GenericNew;
PyPosition_Type.tp_alloc = PyType_GenericAlloc;
if (PyType_Ready(&PyPosition_Type) < 0)
return;
if (PyType_Ready(&MediaControl_Type) < 0)
return;
#ifdef VLCOBJECT_SUPPORT #ifdef VLCOBJECT_SUPPORT
if (PyType_Ready(&vlcObject_Type) < 0)
return;
#endif
/* PyEval_InitThreads(); */
/* Have a look at
http://base.bel-epa.com/pyapache/Python/MySQL-python/MySQL-python-0.3.0/_mysqlmodule.c */
m = Py_InitModule3( "vlc", vlc_methods,
"VLC media player embedding module.");
/* Exceptions */
MediaControl_InternalException =
PyErr_NewException("vlc.InternalException", NULL, NULL);
PyModule_AddObject(m, "InternalException", MediaControl_InternalException);
/* vlcObject (low level access) */ MediaControl_PositionKeyNotSupported =
#define VLCSELF ((vlcObject*)self) PyErr_NewException("vlc.PositionKeyNotSupported", NULL, NULL);
typedef struct { PyModule_AddObject(m, "PositionKeyNotSupported",
PyObject_HEAD MediaControl_PositionKeyNotSupported);
vlc_object_t* p_object;
} vlcObject;
staticforward PyTypeObject vlcObject_Type; MediaControl_PositionOriginNotSupported=
PyErr_NewException("vlc.InvalidPosition", NULL, NULL);
PyModule_AddObject(m, "PositionOriginNotSupported",
MediaControl_PositionOriginNotSupported);
MediaControl_InvalidPosition =
PyErr_NewException("vlc.InvalidPosition", NULL, NULL);
PyModule_AddObject(m, "InvalidPosition", MediaControl_InvalidPosition);
MediaControl_PlaylistException =
PyErr_NewException("vlc.PlaylistException", NULL, NULL);
PyModule_AddObject(m, "PlaylistException", MediaControl_PlaylistException);
/* Types */
Py_INCREF(&PyPosition_Type);
PyModule_AddObject(m, "Position", (PyObject *)&PyPosition_Type);
Py_INCREF(&MediaControl_Type);
PyModule_AddObject(m, "MediaControl", (PyObject *)&MediaControl_Type);
#ifdef VLCOBJECT_SUPPORT
Py_INCREF(&vlcObject_Type);
PyModule_AddObject(m, "Object", (PyObject *)&vlcObject_Type);
#endif #endif
/* MediaControl object */ /* Constants */
typedef struct { PyModule_AddIntConstant(m, "AbsolutePosition",
PyObject_HEAD mediacontrol_AbsolutePosition);
mediacontrol_Instance* mc; PyModule_AddIntConstant(m, "RelativePosition",
} MediaControl; mediacontrol_RelativePosition);
PyModule_AddIntConstant(m, "ModuloPosition",
mediacontrol_ModuloPosition);
PyModule_AddIntConstant(m, "ByteCount", mediacontrol_ByteCount);
PyModule_AddIntConstant(m, "SampleCount", mediacontrol_SampleCount);
PyModule_AddIntConstant(m, "MediaTime", mediacontrol_MediaTime);
PyModule_AddIntConstant(m, "PlayingStatus", mediacontrol_PlayingStatus);
PyModule_AddIntConstant(m, "PauseStatus", mediacontrol_PauseStatus);
PyModule_AddIntConstant(m, "ForwardStatus", mediacontrol_ForwardStatus);
PyModule_AddIntConstant(m, "BackwardStatus", mediacontrol_BackwardStatus);
PyModule_AddIntConstant(m, "InitStatus", mediacontrol_InitStatus);
PyModule_AddIntConstant(m, "EndStatus", mediacontrol_EndStatus);
PyModule_AddIntConstant(m, "UndefinedStatus", mediacontrol_UndefinedStatus);
}
/* Make libpostproc happy... */
void * fast_memcpy(void * to, const void * from, size_t len)
{
return memcpy(to, from, len);
}
staticforward PyTypeObject MediaControl_Type; /*****************************************************************************
* VLCObject implementation
*****************************************************************************/
/* Position object */ #ifdef VLCOBJECT_SUPPORT
typedef struct {
PyObject_HEAD
int origin;
int key;
long long value;
} PyPosition;
static int static PyObject *vlcObject_new(
PyPosition_init(PyPosition *self, PyObject *args, PyObject *kwds) PyTypeObject *type, PyObject *args, PyObject *kwds)
{ {
self->origin = mediacontrol_AbsolutePosition; vlcObject *self;
self->key = mediacontrol_MediaTime; vlc_object_t *p_object;
self->value = 0; int i_id;
self = PyObject_New(vlcObject, &vlcObject_Type);
if ( !PyArg_ParseTuple(args, "i", &i_id) )
return NULL;
return 0; /* Maybe we were already initialized */
p_object = (vlc_object_t*)vlc_current_object(i_id);
if (! p_object)
{
/* Try to initialize */
i_id = VLC_Create();
p_object = (vlc_object_t*)vlc_current_object(i_id);
}
if (! p_object)
{
PyErr_SetString(PyExc_StandardError, "Unable to get object.");
return NULL;
}
self->p_object = p_object;
self->b_released = 0;
Py_INCREF( self ); /* Ah bon ? */
return (PyObject *)self;
} }
static PyMethodDef PyPosition_methods[] = { static PyObject * vlcObject_release( PyObject *self )
{NULL} /* Sentinel */ {
}; if( VLCSELF->b_released == 0 )
{
vlc_object_release( VLCSELF->p_object );
VLCSELF->b_released = 1;
}
Py_INCREF( Py_None);
return Py_None;
}
static void vlcObject_dealloc(PyObject *self)
{
vlcObject_release( self );
PyMem_DEL(self);
}
static PyObject * vlcObject_find_object(PyObject *self, PyObject *args)
{
vlcObject *retval;
vlc_object_t *p_obj;
char *psz_name;
int i_object_type;
if ( !PyArg_ParseTuple(args, "s", &psz_name) )
return NULL;
static PyMemberDef PyPosition_members[] = { /* psz_name is in
{"origin", T_INT, offsetof(PyPosition, origin), 0, "Position origin"}, (aout, decoder, input, httpd, intf, playlist, root, vlc, vout)
{"key", T_INT, offsetof(PyPosition, key), 0, "Position key"}, */
{"value", T_ULONG, offsetof(PyPosition, value), 0, "Position value"}, switch (psz_name[0])
{NULL} /* Sentinel */ {
case 'a':
i_object_type = VLC_OBJECT_AOUT;
break;
case 'd':
i_object_type = VLC_OBJECT_DECODER;
break;
case 'h':
i_object_type = VLC_OBJECT_HTTPD;
break;
case 'i':
if (strlen(psz_name) < 3)
i_object_type = VLC_OBJECT_INTF;
else if (psz_name[2] == 't')
i_object_type = VLC_OBJECT_INTF;
else
i_object_type = VLC_OBJECT_INPUT;
break;
case 'p':
i_object_type = VLC_OBJECT_PLAYLIST;
break;
case 'r':
i_object_type = VLC_OBJECT_ROOT;
break;
case 'v':
if (strlen(psz_name) < 3)
i_object_type = VLC_OBJECT_VLC;
else if (psz_name[1] == 'l')
i_object_type = VLC_OBJECT_VLC;
else
i_object_type = VLC_OBJECT_VOUT;
break;
default:
/* FIXME: raise an exception */
return Py_None;
}
p_obj = vlc_object_find( VLCSELF->p_object, i_object_type, FIND_ANYWHERE );
if (! p_obj)
{
Py_INCREF(Py_None);
return Py_None;
}
retval = PyObject_New(vlcObject, &vlcObject_Type);
retval->p_object = p_obj;
return (PyObject *)retval;
}
static PyObject * vlcObject_info(PyObject *self, PyObject *args)
{
PyObject *retval;
vlc_object_t *p_obj;
p_obj = VLCSELF->p_object;
/* Return information about the object as a dict. */
retval = PyDict_New();
PyDict_SetItemString(retval, "object-id",
Py_BuildValue("l", p_obj->i_object_id));
PyDict_SetItemString(retval, "object-type",
Py_BuildValue("s", p_obj->psz_object_type));
PyDict_SetItemString(retval, "object-name",
Py_BuildValue("s", p_obj->psz_object_name));
PyDict_SetItemString(retval, "thread",
PyBool_FromLong(p_obj->b_thread));
PyDict_SetItemString(retval, "thread-id",
PyLong_FromLongLong(p_obj->thread_id));
PyDict_SetItemString(retval, "refcount",
PyInt_FromLong(p_obj->i_refcount));
return retval;
}
static PyObject * vlcObject_find_id(PyObject *self, PyObject *args)
{
vlcObject *retval;
vlc_object_t* p_object;
int i_id;
if ( !PyArg_ParseTuple(args, "i", &i_id) )
{
PyErr_SetString(PyExc_StandardError, "Error: no id was given.\n");
return Py_None;
}
p_object = (vlc_object_t*)vlc_current_object(i_id);
if (! p_object)
{
Py_INCREF(Py_None);
return Py_None;
}
retval = PyObject_NEW(vlcObject, &vlcObject_Type);
retval->p_object = p_object;
return (PyObject *)retval;
}
/* Do a var_Get call on the object. Parameter: the variable name. */
/* FIXME: We should make them attributes */
static PyObject * vlcObject_var_get(PyObject *self, PyObject *args)
{
PyObject *retval;
vlc_value_t value;
char *psz_name;
int i_type;
if ( !PyArg_ParseTuple(args, "s", &psz_name) )
{
PyErr_SetString(PyExc_StandardError, "Error: no variable name was given.\n");
Py_INCREF(Py_None);
return Py_None;
}
if( var_Get( VLCSELF->p_object, psz_name, &value ) != VLC_SUCCESS )
{
PyErr_SetString(PyExc_StandardError, "Error: no variable name was given.\n");
Py_INCREF(Py_None);
return Py_None;
}
i_type = var_Type (VLCSELF->p_object, psz_name);
switch (i_type)
{
case VLC_VAR_VOID :
retval = PyString_FromString("A void variable");
break;
case VLC_VAR_BOOL :
retval = PyBool_FromLong(value.b_bool);
break;
case VLC_VAR_INTEGER :
retval = PyInt_FromLong((long)value.i_int);
break;
case VLC_VAR_HOTKEY :
retval = PyString_FromFormat("A hotkey variable (%d)", value.i_int);
break;
case VLC_VAR_FILE :
case VLC_VAR_STRING :
case VLC_VAR_DIRECTORY :
case VLC_VAR_VARIABLE :
retval = PyString_FromString(value.psz_string);
break;
case VLC_VAR_MODULE :
retval = (PyObject*)PyObject_New(vlcObject, &vlcObject_Type);
((vlcObject*)retval)->p_object = value.p_object;
break;
case VLC_VAR_FLOAT :
retval = PyFloat_FromDouble((double)value.f_float);
break;
case VLC_VAR_TIME :
retval = PyLong_FromLongLong(value.i_time);
break;
case VLC_VAR_ADDRESS :
retval = PyString_FromString("A VLC address (not handled yet)");
break;
case VLC_VAR_LIST :
retval = PyString_FromString("A VLC list (not handled yet)");
break;
case VLC_VAR_MUTEX :
retval = PyString_FromString("A mutex");
break;
default:
retval = Py_None;
}
Py_INCREF(retval);
return retval;
}
static PyObject * vlcObject_var_type(PyObject *self,
PyObject *args)
{
char *psz_name;
PyObject *retval;
int i_type;
if ( !PyArg_ParseTuple(args, "s", &psz_name))
{
PyErr_SetString(PyExc_StandardError, "Error: no variable name was given.\n");
Py_INCREF(Py_None);
return Py_None;
}
i_type = var_Type(VLCSELF->p_object, psz_name);
switch (i_type)
{
case VLC_VAR_VOID :
retval = PyString_FromString("Void");
break;
case VLC_VAR_BOOL :
retval = PyString_FromString("Boolean");
break;
case VLC_VAR_INTEGER :
retval = PyString_FromString("Integer");
break;
case VLC_VAR_HOTKEY :
retval = PyString_FromString("Hotkey");
break;
case VLC_VAR_FILE :
retval = PyString_FromString("File");
break;
case VLC_VAR_STRING :
retval = PyString_FromString("String");
break;
case VLC_VAR_DIRECTORY :
retval = PyString_FromString("Directory");
break;
case VLC_VAR_VARIABLE :
retval = PyString_FromString("Variable");
break;
case VLC_VAR_MODULE :
retval = PyString_FromString("Module");
break;
case VLC_VAR_FLOAT :
retval = PyString_FromString("Float");
break;
case VLC_VAR_TIME :
retval = PyString_FromString("Time");
break;
case VLC_VAR_ADDRESS :
retval = PyString_FromString("Address");
break;
case VLC_VAR_LIST :
retval = PyString_FromString("List");
break;
case VLC_VAR_MUTEX :
retval = PyString_FromString("Mutex");
break;
default:
retval = PyString_FromString("Unknown");
}
return retval;
}
/* Do a var_Set call on the object. Parameter: the variable name. */
/* FIXME: We should make them attributes */
static PyObject * vlcObject_var_set(PyObject *self,
PyObject *args)
{
vlc_value_t value;
char *psz_name;
PyObject *py_value;
int i_type;
vlc_object_t *p_obj;
if ( !PyArg_ParseTuple(args, "sO", &psz_name, &py_value) )
{
PyErr_SetString(PyExc_StandardError, "Error: no variable name was given.\n");
Py_INCREF(Py_None);
return Py_None;
}
p_obj = VLCSELF->p_object;
i_type = var_Type(p_obj, psz_name);
switch (i_type)
{
case VLC_VAR_VOID :
break;
case VLC_VAR_BOOL :
value.b_bool = PyInt_AsLong(py_value);
break;
case VLC_VAR_INTEGER :
case VLC_VAR_HOTKEY :
value.i_int = PyInt_AsLong(py_value);
break;
case VLC_VAR_FILE :
case VLC_VAR_STRING :
case VLC_VAR_DIRECTORY :
case VLC_VAR_VARIABLE :
value.psz_string = strdup(PyString_AsString(py_value));
break;
case VLC_VAR_MODULE :
/* FIXME: we should check the PyObject type and get its p_object */
value.p_object = ((vlcObject*)p_obj)->p_object;
break;
case VLC_VAR_FLOAT :
value.f_float = PyFloat_AsDouble(py_value);
break;
case VLC_VAR_TIME :
value.i_time = PyLong_AsLongLong(py_value);
break;
case VLC_VAR_ADDRESS :
value.p_address = (char*)PyLong_AsVoidPtr(py_value);
break;
case VLC_VAR_LIST :
/* FIXME */
value.p_list = NULL;
break;
case VLC_VAR_MUTEX :
break;
}
var_Set(p_obj, psz_name, value);
Py_INCREF(Py_None);
return Py_None;
}
static PyObject * vlcObject_var_list(PyObject *self,
PyObject *args)
{
PyObject *retval;
int i_size;
int i_index;
i_size = VLCSELF->p_object->i_vars;
retval = PyTuple_New(i_size);
for (i_index = 0 ; i_index < i_size ; i_index++)
{
PyTuple_SetItem(retval, i_index,
Py_BuildValue("s", VLCSELF->p_object->p_vars[i_index].psz_name));
}
/* Py_INCREF(retval); */
return retval;
}
/* Do a config_Get call on the object. Parameter: the variable name. */
static PyObject * vlcObject_config_get(PyObject *self,
PyObject *args)
{
PyObject *retval;
vlc_value_t value;
char *psz_name;
module_config_t *p_config;
if ( !PyArg_ParseTuple(args, "s", &psz_name) )
{
PyErr_SetString(PyExc_StandardError, "Error: no config variable name was given.\n");
Py_INCREF(Py_None);
return Py_None;
}
p_config = config_FindConfig( VLCSELF->p_object, psz_name );
if( !p_config )
{
PyErr_SetString(PyExc_StandardError, "Error: config variable does not exist.\n");
Py_INCREF(Py_None);
return Py_None;
}
switch (p_config->i_type)
{
case CONFIG_ITEM_BOOL :
retval = PyBool_FromLong(p_config->i_value);
break;
case CONFIG_ITEM_INTEGER :
retval = PyInt_FromLong((long)p_config->i_value);
break;
case CONFIG_ITEM_KEY :
retval = PyString_FromFormat("A hotkey variable (%d)", p_config->i_value);
break;
case CONFIG_ITEM_FILE :
case CONFIG_ITEM_STRING :
case CONFIG_ITEM_DIRECTORY :
case CONFIG_ITEM_MODULE :
vlc_mutex_lock( p_config->p_lock );
if( p_config->psz_value )
retval = PyString_FromString( p_config->psz_value );
else
retval = PyString_FromString( "" );
vlc_mutex_unlock( p_config->p_lock );
break;
retval = (PyObject*)PyObject_New(vlcObject, &vlcObject_Type);
((vlcObject*)retval)->p_object = value.p_object;
break;
case CONFIG_ITEM_FLOAT :
retval = PyFloat_FromDouble((double)p_config->f_value);
break;
default:
retval = Py_None;
Py_INCREF(retval);
}
return retval;
}
/* Do a var_Set call on the object. Parameter: the variable name. */
/* FIXME: We should make them attributes */
static PyObject * vlcObject_config_set(PyObject *self,
PyObject *args)
{
char *psz_name;
PyObject *py_value;
vlc_object_t *p_obj;
module_config_t *p_config;
if ( !PyArg_ParseTuple(args, "sO", &psz_name, &py_value) )
{
PyErr_SetString(PyExc_StandardError,
"Error: no variable name was given.\n");
Py_INCREF(Py_None);
return Py_None;
}
p_obj = VLCSELF->p_object;
p_config = config_FindConfig( p_obj, psz_name );
/* sanity checks */
if( !p_config )
{
PyErr_SetString(PyExc_StandardError,
"Error: option does not exist.\n");
Py_INCREF(Py_None);
return Py_None;
}
switch (p_config->i_type)
{
case CONFIG_ITEM_BOOL :
case CONFIG_ITEM_INTEGER :
case CONFIG_ITEM_KEY :
config_PutInt(p_obj, psz_name, PyInt_AsLong(py_value));
break;
case CONFIG_ITEM_FILE :
case CONFIG_ITEM_STRING :
case CONFIG_ITEM_DIRECTORY :
case CONFIG_ITEM_MODULE :
config_PutPsz(p_obj, psz_name, PyString_AsString(py_value));
break;
case CONFIG_ITEM_FLOAT :
config_PutFloat(p_obj, psz_name, PyFloat_AsDouble(py_value));
break;
}
Py_INCREF(Py_None);
return Py_None;
}
static PyObject * vlcObject_children(PyObject *self,
PyObject *args)
{
PyObject *retval;
int i_size;
int i_index;
i_size = VLCSELF->p_object->i_children;
retval = PyTuple_New(i_size);
for (i_index = 0 ; i_index < i_size ; i_index++)
{
PyTuple_SetItem(retval, i_index,
Py_BuildValue("i",
VLCSELF->p_object->pp_children[i_index]->i_object_id));
}
/* Py_INCREF(retval); */
return retval;
}
/* Method table */
static PyMethodDef vlcObject_methods[] =
{
{ "get", vlcObject_var_get, METH_VARARGS,
"get(str) -> value Get a variable value."},
{ "set", vlcObject_var_set, METH_VARARGS,
"set(str, value) Set a variable value" },
{ "config_get", vlcObject_config_get, METH_VARARGS,
"get(str) -> value Get an option value." },
{ "config_set", vlcObject_config_set, METH_VARARGS,
"set(str, value) Set an option value" },
{ "type", vlcObject_var_type, METH_VARARGS,
"type(str) -> str Get a variable type" },
{ "list", vlcObject_var_list, METH_VARARGS,
"list() List the available variables" },
{ "children", vlcObject_children, METH_VARARGS,
"children() List the children ids" },
{ "find_object", vlcObject_find_object, METH_VARARGS,
"find_object(str) -> Object Find the object of a given type.\n\nAvailable types are : aout, decoder, input, httpd, intf, playlist, root, vlc, vout"},
{ "find_id", vlcObject_find_id, METH_VARARGS,
"find_id(int) -> Object Find an object by id" },
{ "info", vlcObject_info, METH_VARARGS,
"info() -> dict Return information about the object" },
{ "release", vlcObject_release, METH_VARARGS,
"release() -> Release the VLC Object" },
{ NULL, NULL, 0, NULL },
}; };
static PyTypeObject PyPosition_Type = { static PyTypeObject vlcObject_Type =
{
PyObject_HEAD_INIT(NULL) PyObject_HEAD_INIT(NULL)
0, /*ob_size*/ 0, /*ob_size*/
"vlc.Position", /*tp_name*/ "vlc.Object", /*tp_name*/
sizeof(PyPosition_Type), /*tp_basicsize*/ sizeof(vlcObject_Type), /*tp_basicsize*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/
0, /*tp_dealloc*/ (destructor)vlcObject_dealloc, /*tp_dealloc*/
0, /*tp_print*/ 0, /*tp_print*/
0, /*tp_getattr*/ 0, /*tp_getattr*/
0, /*tp_setattr*/ 0, /*tp_setattr*/
...@@ -118,547 +712,503 @@ static PyTypeObject PyPosition_Type = { ...@@ -118,547 +712,503 @@ static PyTypeObject PyPosition_Type = {
0, /*tp_setattro*/ 0, /*tp_setattro*/
0, /*tp_as_buffer*/ 0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
"Represent a Position with origin, key and value", /* tp_doc */ "Explore VLC objects.", /* tp_doc */
0, /* tp_traverse */ 0, /* tp_traverse */
0, /* tp_clear */ 0, /* tp_clear */
0, /* tp_richcompare */ 0, /* tp_richcompare */
0, /* tp_weaklistoffset */ 0, /* tp_weaklistoffset */
0, /* tp_iter */ 0, /* tp_iter */
0, /* tp_iternext */ 0, /* tp_iternext */
PyPosition_methods, /* tp_methods */ vlcObject_methods, /* tp_methods */
PyPosition_members, /* tp_members */ 0, /* tp_members */
0, /* tp_getset */ 0, /* tp_getset */
0, /* tp_base */ 0, /* tp_base */
0, /* tp_dict */ 0, /* tp_dict */
0, /* tp_descr_get */ 0, /* tp_descr_get */
0, /* tp_descr_set */ 0, /* tp_descr_set */
0, /* tp_dictoffset */ 0, /* tp_dictoffset */
(initproc)PyPosition_init, /* tp_init */ 0, /* tp_init */
0, /* tp_alloc */ 0, /* tp_alloc */
0, /* tp_new */ vlcObject_new, /* tp_new */
}; };
static mediacontrol_PositionKey positionKey_py_to_c( PyObject * py_key ) #endif
{
mediacontrol_PositionKey key_position = mediacontrol_MediaTime;
int key;
if(!PyArg_Parse(py_key, "i", &key))
{
PyErr_SetString (MediaControl_InternalException, "Invalid key value");
return key_position;
}
switch (key)
{
case 0: key = mediacontrol_ByteCount; break;
case 1: key = mediacontrol_SampleCount; break;
case 2: key = mediacontrol_MediaTime; break;
}
return key_position;
}
static mediacontrol_PositionOrigin positionOrigin_py_to_c( PyObject * py_origin )
{
mediacontrol_PositionOrigin origin_position = mediacontrol_AbsolutePosition;
int origin;
if(!PyArg_Parse(py_origin,"i", &origin))
{
PyErr_SetString (MediaControl_InternalException, "Invalid origin value");
return origin_position;
}
switch (origin)
{
case 0: origin_position = mediacontrol_AbsolutePosition; break;
case 1: origin_position = mediacontrol_RelativePosition; break;
case 2: origin_position = mediacontrol_ModuloPosition; break;
}
return origin_position;
}
/* Methods for transforming the Position Python object to Position structure*/
static mediacontrol_Position* position_py_to_c( PyObject * py_position )
{
mediacontrol_Position * a_position = NULL;
PyPosition *pos = (PyPosition*)py_position;
a_position = (mediacontrol_Position*)malloc(sizeof(mediacontrol_Position));
if (! a_position)
{
PyErr_SetString(PyExc_MemoryError, "Out of memory");
return NULL;
}
if (PyObject_IsInstance(py_position, (PyObject*)&PyPosition_Type))
{
a_position->origin = pos->origin;
a_position->key = pos->key;
a_position->value = pos->value;
}
else
{
/* Feature: if we give an integer, it will be considered as
a relative position in mediatime */
a_position->origin = mediacontrol_RelativePosition;
a_position->key = mediacontrol_MediaTime;
a_position->value = PyLong_AsLongLong(py_position);
}
return a_position;
}
static PyPosition* position_c_to_py(mediacontrol_Position *position)
{
PyPosition* py_retval;
py_retval = PyObject_New(PyPosition, &PyPosition_Type);
py_retval->origin = position->origin;
py_retval->key = position->key;
py_retval->value = position->value;
return py_retval; /*****************************************************************************
} * VLC MediaControl object implementation
*****************************************************************************/
/* constructor : create the new type, thread and init */
static PyObject *MediaControl_new(PyTypeObject *type, PyObject *args, PyObject *kwds) static PyObject *MediaControl_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{ {
MediaControl *self; MediaControl *self;
mediacontrol_Exception *exception = NULL; mediacontrol_Exception *exception = NULL;
PyObject* py_list = NULL; PyObject* py_list = NULL;
char** ppsz_args = NULL; char** ppsz_args = NULL;
self = PyObject_New(MediaControl, &MediaControl_Type); self = PyObject_New(MediaControl, &MediaControl_Type);
if (PyArg_ParseTuple(args, "O", &py_list)) if (PyArg_ParseTuple(args, "O", &py_list))
{ {
int i_size; int i_size;
int i_index; int i_index;
Py_INCREF(py_list); Py_INCREF(py_list);
if (! PySequence_Check(py_list)) if (! PySequence_Check(py_list))
{ {
PyErr_SetString(PyExc_TypeError, "Parameter must be a sequence."); PyErr_SetString(PyExc_TypeError, "Parameter must be a sequence.");
return NULL; return NULL;
} }
i_size = PySequence_Size(py_list); i_size = PySequence_Size(py_list);
ppsz_args = malloc(i_size + 1); ppsz_args = malloc(i_size + 1);
if (! ppsz_args) if (! ppsz_args)
{ {
PyErr_SetString(PyExc_MemoryError, "Out of memory"); PyErr_SetString(PyExc_MemoryError, "Out of memory");
return NULL; return NULL;
} }
for (i_index = 0; i_index < i_size; i_index++) for ( i_index = 0; i_index < i_size; i_index++ )
{ {
ppsz_args[i_index]=strdup(PyString_AsString(PyObject_Str(PySequence_GetItem(py_list, ppsz_args[i_index] =
i_index)))); strdup( PyString_AsString( PyObject_Str(
} PySequence_GetItem(py_list,
ppsz_args[i_size] = NULL; i_index ) ) ) );
Py_DECREF(py_list); }
ppsz_args[i_size] = NULL;
Py_DECREF(py_list);
} }
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
MC_TRY; MC_TRY;
self->mc = mediacontrol_new(ppsz_args, exception); self->mc = mediacontrol_new( ppsz_args, exception );
MC_EXCEPT; MC_EXCEPT;
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
Py_INCREF(self); Py_INCREF(self);
return (PyObject *)self; return (PyObject *)self;
} }
static void static void MediaControl_dealloc(PyObject *self)
MediaControl_dealloc(PyObject *self)
{ {
PyMem_DEL(self); PyMem_DEL(self);
} }
/* Returns the current position in the stream. The returned value can /**
* Returns the current position in the stream. The returned value can
be relative or absolute (according to PositionOrigin) and the unit be relative or absolute (according to PositionOrigin) and the unit
is set by PositionKey */ is set by PositionKey
static PyObject * MediaControl_get_media_position(PyObject *self, PyObject *args) */
static PyObject * MediaControl_get_media_position(
PyObject *self, PyObject *args)
{ {
mediacontrol_Position* pos; mediacontrol_Position* pos;
mediacontrol_Exception* exception = NULL; mediacontrol_Exception* exception = NULL;
PyObject *py_origin; PyObject *py_origin;
PyObject *py_key; PyObject *py_key;
PyObject *py_retval; PyObject *py_retval;
mediacontrol_PositionOrigin origin; mediacontrol_PositionOrigin origin;
mediacontrol_PositionKey key; mediacontrol_PositionKey key;
if( !PyArg_ParseTuple(args, "OO", &py_origin, &py_key)) if( !PyArg_ParseTuple( args, "OO", &py_origin, &py_key ) )
return NULL; return NULL;
origin = positionOrigin_py_to_c(py_origin); origin = positionOrigin_py_to_c(py_origin);
key = positionKey_py_to_c(py_key); key = positionKey_py_to_c(py_key);
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
MC_TRY; MC_TRY;
pos = mediacontrol_get_media_position(SELF->mc, origin, key, exception); pos = mediacontrol_get_media_position(SELF->mc, origin, key, exception);
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
MC_EXCEPT; MC_EXCEPT;
py_retval = (PyObject*)position_c_to_py(pos); py_retval = (PyObject*)position_c_to_py(pos);
free(pos); free( pos );
return py_retval; return py_retval;
} }
/* Sets the media position */ /** Sets the media position */
static PyObject *MediaControl_set_media_position(PyObject *self, PyObject *args) static PyObject *MediaControl_set_media_position(
PyObject *self, PyObject *args )
{ {
mediacontrol_Exception* exception = NULL; mediacontrol_Exception* exception = NULL;
mediacontrol_Position *a_position; mediacontrol_Position *a_position;
PyObject *py_pos; PyObject *py_pos;
if( !PyArg_ParseTuple(args, "O", &py_pos) ) if( !PyArg_ParseTuple( args, "O", &py_pos ) )
return NULL; return NULL;
a_position = position_py_to_c(py_pos); a_position = position_py_to_c(py_pos);
if (!a_position) if (!a_position )
{ {
PyErr_SetString(PyExc_MemoryError, "Out of memory"); PyErr_SetString(PyExc_MemoryError, "Out of memory");
return NULL; return NULL;
} }
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
MC_TRY; MC_TRY;
mediacontrol_set_media_position(SELF->mc, a_position, exception); mediacontrol_set_media_position( SELF->mc, a_position, exception );
free(a_position); free( a_position );
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
MC_EXCEPT; MC_EXCEPT;
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
} }
static PyObject *MediaControl_start(PyObject *self, PyObject *args) static PyObject *MediaControl_start(PyObject *self, PyObject *args)
{ {
mediacontrol_Position *a_position; mediacontrol_Position *a_position;
mediacontrol_Exception *exception = NULL; mediacontrol_Exception *exception = NULL;
PyObject *py_pos; PyObject *py_pos;
if( !PyArg_ParseTuple(args, "O", &py_pos)) if( !PyArg_ParseTuple(args, "O", &py_pos ) )
return NULL; return NULL;
a_position = position_py_to_c(py_pos); a_position = position_py_to_c(py_pos);
if (!a_position) if ( !a_position )
return NULL; return NULL;
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
MC_TRY; MC_TRY;
mediacontrol_start(SELF->mc, a_position, exception); mediacontrol_start(SELF->mc, a_position, exception);
free(a_position); free(a_position);
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
MC_EXCEPT; MC_EXCEPT;
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
} }
static PyObject *MediaControl_pause(PyObject *self, PyObject *args) static PyObject *MediaControl_pause(PyObject *self, PyObject *args)
{ {
mediacontrol_Position *a_position; mediacontrol_Position *a_position;
mediacontrol_Exception *exception = NULL; mediacontrol_Exception *exception = NULL;
PyObject *py_pos; PyObject *py_pos;
if( !PyArg_ParseTuple(args, "O", &py_pos)) if( !PyArg_ParseTuple(args, "O", &py_pos ) )
return NULL; return NULL;
a_position = position_py_to_c(py_pos); a_position = position_py_to_c(py_pos);
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
MC_TRY; MC_TRY;
mediacontrol_pause(SELF->mc, a_position, exception); mediacontrol_pause(SELF->mc, a_position, exception);
free(a_position); free(a_position);
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
MC_EXCEPT; MC_EXCEPT;
Py_INCREF(Py_None); Py_INCREF( Py_None );
return Py_None; return Py_None;
} }
static PyObject * MediaControl_resume(PyObject *self, PyObject *args) static PyObject * MediaControl_resume(PyObject *self, PyObject *args)
{ {
mediacontrol_Position *a_position; mediacontrol_Position *a_position;
mediacontrol_Exception *exception = NULL; mediacontrol_Exception *exception = NULL;
PyObject *py_pos; PyObject *py_pos;
if( !PyArg_ParseTuple(args, "O", &py_pos)) if( !PyArg_ParseTuple(args, "O", &py_pos ) )
return NULL; return NULL;
a_position = position_py_to_c(py_pos); a_position = position_py_to_c(py_pos);
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
MC_TRY; MC_TRY;
mediacontrol_start(SELF->mc, a_position, exception); mediacontrol_start(SELF->mc, a_position, exception);
free(a_position); free(a_position);
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
MC_EXCEPT; MC_EXCEPT;
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
} }
static PyObject *MediaControl_stop(PyObject *self, PyObject *args) static PyObject *MediaControl_stop(PyObject *self, PyObject *args)
{ {
mediacontrol_Position *a_position; mediacontrol_Position *a_position;
mediacontrol_Exception *exception = NULL; mediacontrol_Exception *exception = NULL;
PyObject *py_pos; PyObject *py_pos;
if( !PyArg_ParseTuple(args, "O", &py_pos)) if( !PyArg_ParseTuple(args, "O", &py_pos ) )
return NULL; return NULL;
a_position = position_py_to_c(py_pos); a_position = position_py_to_c(py_pos);
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
MC_TRY; MC_TRY;
mediacontrol_stop(SELF->mc, a_position, exception); mediacontrol_stop(SELF->mc, a_position, exception);
free(a_position); free(a_position);
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
MC_EXCEPT; MC_EXCEPT;
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
} }
static PyObject *MediaControl_exit(PyObject *self, PyObject *args) static PyObject *MediaControl_exit(PyObject *self, PyObject *args)
{ {
mediacontrol_exit(SELF->mc); mediacontrol_exit(SELF->mc);
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
} }
static PyObject *MediaControl_playlist_add_item(PyObject *self, PyObject *args) static PyObject *MediaControl_playlist_add_item(PyObject *self, PyObject *args)
{ {
char *psz_file; char *psz_file;
mediacontrol_Exception *exception = NULL; mediacontrol_Exception *exception = NULL;
if ( !PyArg_ParseTuple(args, "s", &psz_file) ) if ( !PyArg_ParseTuple(args, "s", &psz_file) )
return NULL; return NULL;
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
MC_TRY; MC_TRY;
mediacontrol_playlist_add_item(SELF->mc, psz_file, exception); mediacontrol_playlist_add_item(SELF->mc, psz_file, exception);
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
MC_EXCEPT; MC_EXCEPT;
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
} }
static PyObject * MediaControl_playlist_clear(PyObject *self, static PyObject * MediaControl_playlist_clear( PyObject *self,
PyObject *args) PyObject *args)
{ {
mediacontrol_Exception *exception = NULL; mediacontrol_Exception *exception = NULL;
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
MC_TRY; MC_TRY;
mediacontrol_playlist_clear(SELF->mc, exception); mediacontrol_playlist_clear(SELF->mc, exception);
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
MC_EXCEPT; MC_EXCEPT;
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
} }
static PyObject * MediaControl_playlist_get_list(PyObject *self, static PyObject * MediaControl_playlist_get_list( PyObject *self,
PyObject *args) PyObject *args )
{ {
PyObject *py_retval; PyObject *py_retval;
mediacontrol_Exception *exception = NULL; mediacontrol_Exception *exception = NULL;
mediacontrol_PlaylistSeq* pl; mediacontrol_PlaylistSeq* pl;
int i_index; int i_index;
int i_playlist_size; int i_playlist_size;
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
MC_TRY; MC_TRY;
pl = mediacontrol_playlist_get_list(SELF->mc, exception); pl = mediacontrol_playlist_get_list(SELF->mc, exception);
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
MC_EXCEPT; MC_EXCEPT;
i_playlist_size = pl->size; i_playlist_size = pl->size;
py_retval = PyTuple_New(i_playlist_size); py_retval = PyList_New( i_playlist_size );
for (i_index = 0 ; i_index < i_playlist_size ; i_index++) for (i_index = 0 ; i_index < i_playlist_size ; i_index++)
{ {
PyTuple_SetItem(py_retval, i_index, Py_BuildValue("s", pl->data[i_index])); PyList_SetItem( py_retval, i_index,
Py_BuildValue("s", pl->data[i_index] ) );
} }
mediacontrol_PlaylistSeq__free(pl); mediacontrol_PlaylistSeq__free(pl);
return py_retval; return py_retval;
} }
static PyObject * MediaControl_snapshot(PyObject *self, PyObject *args) static PyObject * MediaControl_snapshot(PyObject *self, PyObject *args)
{ {
mediacontrol_RGBPicture *retval = NULL; mediacontrol_RGBPicture *retval = NULL;
mediacontrol_Exception* exception = NULL; mediacontrol_Exception* exception = NULL;
mediacontrol_Position *a_position = NULL; mediacontrol_Position *a_position = NULL;
PyObject *py_pos = NULL; PyObject *py_pos = NULL;
PyObject *py_obj = NULL; PyObject *py_obj = NULL;
if( !PyArg_ParseTuple(args, "O", &py_pos)) if( !PyArg_ParseTuple(args, "O", &py_pos))
return NULL; return NULL;
a_position = position_py_to_c(py_pos); a_position = position_py_to_c(py_pos);
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
MC_TRY; MC_TRY;
retval = mediacontrol_snapshot(SELF->mc, a_position, exception); retval = mediacontrol_snapshot(SELF->mc, a_position, exception);
free(a_position); free( a_position );
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
MC_EXCEPT; MC_EXCEPT;
if( !retval ) { if( !retval )
Py_INCREF( Py_None ); {
return Py_None; Py_INCREF( Py_None );
} return Py_None;
}
/* FIXME: create a real RGBPicture object */
py_obj = PyDict_New(); /* FIXME: create a real RGBPicture object */
py_obj = PyDict_New();
PyDict_SetItemString(py_obj, "width", Py_BuildValue("i", retval->width));
PyDict_SetItemString(py_obj, "height", Py_BuildValue("i", retval->height)); PyDict_SetItemString(py_obj, "width",
PyDict_SetItemString(py_obj, "type", Py_BuildValue("i", retval->type)); Py_BuildValue("i", retval->width) );
PyDict_SetItemString(py_obj, "data", Py_BuildValue("s#", retval->data, retval->size)); PyDict_SetItemString(py_obj, "height",
Py_BuildValue("i", retval->height) );
/* Py_INCREF(py_obj); */ PyDict_SetItemString(py_obj, "type",
return py_obj; Py_BuildValue("i", retval->type) );
PyDict_SetItemString(py_obj, "data",
Py_BuildValue("s#", retval->data, retval->size) );
/* Py_INCREF(py_obj); */
return py_obj;
} }
static PyObject* MediaControl_display_text(PyObject *self, PyObject *args) static PyObject* MediaControl_display_text(PyObject *self, PyObject *args)
{ {
mediacontrol_Exception* exception = NULL; mediacontrol_Exception* exception = NULL;
PyObject *py_begin, *py_end; PyObject *py_begin, *py_end;
char* message; char* message;
mediacontrol_Position * begin; mediacontrol_Position * begin;
mediacontrol_Position * end; mediacontrol_Position * end;
if( !PyArg_ParseTuple(args, "sOO", &message, &py_begin, &py_end)) if( !PyArg_ParseTuple(args, "sOO", &message, &py_begin, &py_end))
return NULL; return NULL;
begin = position_py_to_c(py_begin); begin = position_py_to_c(py_begin);
end = position_py_to_c(py_end); end = position_py_to_c(py_end);
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
MC_TRY; MC_TRY;
mediacontrol_display_text(SELF->mc, message, begin, end, exception); mediacontrol_display_text(SELF->mc, message, begin, end, exception);
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
MC_EXCEPT; MC_EXCEPT;
free(begin); free(begin);
free(end); free(end);
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
} }
static PyObject* MediaControl_get_stream_information(PyObject *self, PyObject *args) static PyObject* MediaControl_get_stream_information(
PyObject *self, PyObject *args)
{ {
mediacontrol_StreamInformation *retval = NULL; mediacontrol_StreamInformation *retval = NULL;
mediacontrol_Exception* exception = NULL; mediacontrol_Exception* exception = NULL;
PyObject *py_obj; PyObject *py_obj;
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
MC_TRY; MC_TRY;
retval = mediacontrol_get_stream_information(SELF->mc, mediacontrol_MediaTime, exception); retval = mediacontrol_get_stream_information(
Py_END_ALLOW_THREADS SELF->mc, mediacontrol_MediaTime, exception);
MC_EXCEPT; Py_END_ALLOW_THREADS
MC_EXCEPT;
py_obj = PyDict_New();
py_obj = PyDict_New();
/* FIXME: create a real StreamInformation object */
PyDict_SetItemString(py_obj, "status", Py_BuildValue("i", retval->streamstatus)); /* FIXME: create a real StreamInformation object */
PyDict_SetItemString(py_obj, "url", Py_BuildValue("s", retval->url)); PyDict_SetItemString(py_obj, "status",
PyDict_SetItemString(py_obj, "position", Py_BuildValue("L", retval->position)); Py_BuildValue("i", retval->streamstatus));
PyDict_SetItemString(py_obj, "length", Py_BuildValue("L", retval->length)); PyDict_SetItemString(py_obj, "url",
Py_BuildValue("s", retval->url));
free(retval->url); PyDict_SetItemString(py_obj, "position",
free(retval); Py_BuildValue("L", retval->position));
PyDict_SetItemString(py_obj, "length",
/* Py_INCREF(py_obj); */ Py_BuildValue("L", retval->length));
return py_obj;
free(retval->url);
free(retval);
/* Py_INCREF(py_obj); */
return py_obj;
} }
static PyObject* MediaControl_sound_set_volume(PyObject *self, PyObject *args) static PyObject* MediaControl_sound_set_volume(PyObject *self, PyObject *args)
{ {
mediacontrol_Exception* exception = NULL; mediacontrol_Exception* exception = NULL;
unsigned short volume; unsigned short volume;
if (!PyArg_ParseTuple(args, "H", &volume)) if (!PyArg_ParseTuple(args, "H", &volume))
return NULL; return NULL;
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
MC_TRY; MC_TRY;
mediacontrol_sound_set_volume(SELF->mc, volume, exception); mediacontrol_sound_set_volume(SELF->mc, volume, exception);
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
MC_EXCEPT; MC_EXCEPT;
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
} }
static PyObject* MediaControl_sound_get_volume(PyObject *self, PyObject *args) static PyObject* MediaControl_sound_get_volume(PyObject *self, PyObject *args)
{ {
mediacontrol_Exception* exception = NULL; mediacontrol_Exception* exception = NULL;
PyObject *py_retval; PyObject *py_retval;
unsigned short volume; unsigned short volume;
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
MC_TRY; MC_TRY;
volume=mediacontrol_sound_get_volume(SELF->mc, exception); volume=mediacontrol_sound_get_volume(SELF->mc, exception);
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
MC_EXCEPT; MC_EXCEPT;
py_retval = Py_BuildValue("H", volume); py_retval = Py_BuildValue("H", volume);
return py_retval; return py_retval;
} }
static PyObject* MediaControl_set_visual(PyObject *self, PyObject *args) static PyObject* MediaControl_set_visual(PyObject *self, PyObject *args)
{ {
mediacontrol_Exception* exception = NULL; mediacontrol_Exception* exception = NULL;
WINDOWHANDLE visual; WINDOWHANDLE visual;
if (!PyArg_ParseTuple(args, "i", &visual))
return NULL;
Py_BEGIN_ALLOW_THREADS
MC_TRY;
mediacontrol_set_visual(SELF->mc, visual, exception);
Py_END_ALLOW_THREADS
MC_EXCEPT;
Py_INCREF(Py_None);
return Py_None;
}
if (!PyArg_ParseTuple(args, "i", &visual))
return NULL;
/* Method table */ Py_BEGIN_ALLOW_THREADS
static PyMethodDef MediaControl_methods[] = { MC_TRY;
{"get_media_position", MediaControl_get_media_position, METH_VARARGS, "get_media_position(origin, key) -> Position Get current media position."}, mediacontrol_set_visual(SELF->mc, visual, exception);
{"set_media_position", MediaControl_set_media_position, METH_VARARGS, "set_media_position(Position) Set media position"}, Py_END_ALLOW_THREADS
{"start", MediaControl_start, METH_VARARGS, "start(Position) Start the player."}, MC_EXCEPT;
{"pause", MediaControl_pause, METH_VARARGS, "pause(Position) Pause the player."},
{"resume", MediaControl_resume, METH_VARARGS, "resume(Position) Resume the player"}, Py_INCREF(Py_None);
{"stop", MediaControl_stop, METH_VARARGS, "stop(Position) Stop the player"}, return Py_None;
{"exit", MediaControl_exit, METH_VARARGS, "exit() Exit the player"}, }
{"playlist_add_item", MediaControl_playlist_add_item, METH_VARARGS, "playlist_add_item(str) Add an item to the playlist"},
{"playlist_get_list", MediaControl_playlist_get_list, METH_VARARGS, "playlist_get_list() -> list Get the contents of the playlist"}, static PyMethodDef MediaControl_methods[] =
{"playlist_clear", MediaControl_playlist_clear, METH_VARARGS, "clear() Clear the playlist."}, {
{"snapshot", MediaControl_snapshot, METH_VARARGS, "snapshot(Position) -> dict Take a snapshot"}, {"get_media_position", MediaControl_get_media_position, METH_VARARGS,
{"display_text", MediaControl_display_text, METH_VARARGS, "display_text(str, Position, Position) Display a text on the video"}, "get_media_position(origin, key) -> Position Get current media position." },
{"get_stream_information", MediaControl_get_stream_information, METH_VARARGS, "get_stream_information() -> dict Get information about the stream"}, { "set_media_position", MediaControl_set_media_position, METH_VARARGS,
{"sound_get_volume", MediaControl_sound_get_volume, METH_VARARGS, "sound_get_volume() -> int Get the volume"}, "set_media_position(Position) Set media position" },
{"sound_set_volume", MediaControl_sound_set_volume, METH_VARARGS, "sound_set_volume(int) Set the volume"}, { "start", MediaControl_start, METH_VARARGS,
{"set_visual", MediaControl_set_visual, METH_VARARGS, "set_visual(int) Set the embedding window visual ID"}, "start(Position) Start the player." },
{NULL, NULL, 0, NULL}, { "pause", MediaControl_pause, METH_VARARGS,
"pause(Position) Pause the player." },
{ "resume", MediaControl_resume, METH_VARARGS,
"resume(Position) Resume the player" },
{ "stop", MediaControl_stop, METH_VARARGS,
"stop(Position) Stop the player" },
{ "exit", MediaControl_exit, METH_VARARGS,
"exit() Exit the player" },
{ "playlist_add_item", MediaControl_playlist_add_item, METH_VARARGS,
"playlist_add_item(str) Add an item to the playlist" },
{ "playlist_get_list", MediaControl_playlist_get_list, METH_VARARGS,
"playlist_get_list() -> list Get the contents of the playlist" },
{ "playlist_clear", MediaControl_playlist_clear, METH_VARARGS,
"clear() Clear the playlist." },
{ "snapshot", MediaControl_snapshot, METH_VARARGS,
"snapshot(Position) -> dict Take a snapshot" },
{ "display_text", MediaControl_display_text, METH_VARARGS,
"display_text(str, Position, Position) Display a text on the video" },
{ "get_stream_information", MediaControl_get_stream_information,
METH_VARARGS,
"get_stream_information() -> dict Get information about the stream"},
{ "sound_get_volume", MediaControl_sound_get_volume, METH_VARARGS,
"sound_get_volume() -> int Get the volume" },
{ "sound_set_volume", MediaControl_sound_set_volume, METH_VARARGS,
"sound_set_volume(int) Set the volume" },
{ "set_visual", MediaControl_set_visual, METH_VARARGS,
"set_visual(int) Set the embedding window visual ID" },
{ NULL, NULL, 0, NULL },
}; };
static PyTypeObject MediaControl_Type = { static PyTypeObject MediaControl_Type =
{
PyObject_HEAD_INIT(NULL) PyObject_HEAD_INIT(NULL)
0, /*ob_size*/ 0, /*ob_size*/
"vlc.MediaControl", /*tp_name*/ "vlc.MediaControl", /*tp_name*/
...@@ -681,12 +1231,12 @@ static PyTypeObject MediaControl_Type = { ...@@ -681,12 +1231,12 @@ static PyTypeObject MediaControl_Type = {
0, /*tp_as_buffer*/ 0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
"Control of a VLC instance.", /* tp_doc */ "Control of a VLC instance.", /* tp_doc */
0, /* tp_traverse */ 0, /* tp_traverse */
0, /* tp_clear */ 0, /* tp_clear */
0, /* tp_richcompare */ 0, /* tp_richcompare */
0, /* tp_weaklistoffset */ 0, /* tp_weaklistoffset */
0, /* tp_iter */ 0, /* tp_iter */
0, /* tp_iternext */ 0, /* tp_iternext */
MediaControl_methods, /* tp_methods */ MediaControl_methods, /* tp_methods */
0, /* tp_members */ 0, /* tp_members */
0, /* tp_getset */ 0, /* tp_getset */
...@@ -700,542 +1250,125 @@ static PyTypeObject MediaControl_Type = { ...@@ -700,542 +1250,125 @@ static PyTypeObject MediaControl_Type = {
MediaControl_new, /* tp_new */ MediaControl_new, /* tp_new */
}; };
#ifdef VLCOBJECT_SUPPORT /***********************************************************************
* Position
/***** vlcObject definitions *****/ ***********************************************************************/
/* constructor : create the new type, thread and init */
static PyObject *vlcObject_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
vlcObject *self;
vlc_object_t *p_object;
int i_id;
self = PyObject_New(vlcObject, &vlcObject_Type);
if ( !PyArg_ParseTuple(args, "i", &i_id) )
return NULL;
/* Maybe we were already initialized */ static int PyPosition_init( PyPosition *self, PyObject *args, PyObject *kwds )
p_object = (vlc_object_t*)vlc_current_object(i_id);
if (! p_object)
{
/* Try to initialize */
i_id = VLC_Create();
p_object = (vlc_object_t*)vlc_current_object(i_id);
}
if (! p_object)
{
PyErr_SetString(PyExc_StandardError, "Unable to get object.");
return NULL;
}
self->p_object = p_object;
Py_INCREF(self); /* Ah bon ? */
return (PyObject *)self;
}
static void
vlcObject_dealloc(PyObject *self)
{ {
vlc_object_release(VLCSELF->p_object); self->origin = mediacontrol_AbsolutePosition;
PyMem_DEL(self); self->key = mediacontrol_MediaTime;
self->value = 0;
return 0;
} }
static PyObject * vlcObject_find_object(PyObject *self, mediacontrol_PositionKey positionKey_py_to_c( PyObject * py_key )
PyObject *args)
{ {
vlcObject *retval; mediacontrol_PositionKey key_position = mediacontrol_MediaTime;
vlc_object_t *p_obj; int key;
char *psz_name;
int i_object_type;
if ( !PyArg_ParseTuple(args, "s", &psz_name) )
return NULL;
/* psz_name is in
(aout, decoder, input, httpd, intf, playlist, root, vlc, vout)
*/
switch (psz_name[0])
{
case 'a':
i_object_type = VLC_OBJECT_AOUT;
break;
case 'd':
i_object_type = VLC_OBJECT_DECODER;
break;
case 'h':
i_object_type = VLC_OBJECT_HTTPD;
break;
case 'i':
if (strlen(psz_name) < 3)
i_object_type = VLC_OBJECT_INTF;
else if (psz_name[2] == 't')
i_object_type = VLC_OBJECT_INTF;
else
i_object_type = VLC_OBJECT_INPUT;
break;
case 'p':
i_object_type = VLC_OBJECT_PLAYLIST;
break;
case 'r':
i_object_type = VLC_OBJECT_ROOT;
break;
case 'v':
if (strlen(psz_name) < 3)
i_object_type = VLC_OBJECT_VLC;
else if (psz_name[1] == 'l')
i_object_type = VLC_OBJECT_VLC;
else
i_object_type = VLC_OBJECT_VOUT;
break;
default:
/* FIXME: raise an exception */
return Py_None;
}
p_obj = vlc_object_find( VLCSELF->p_object, i_object_type, FIND_ANYWHERE );
if (! p_obj)
{
Py_INCREF(Py_None);
return Py_None;
}
retval = PyObject_New(vlcObject, &vlcObject_Type);
retval->p_object = p_obj;
return (PyObject *)retval;
}
static PyObject * vlcObject_info(PyObject *self,
PyObject *args)
{
PyObject *retval;
vlc_object_t *p_obj;
p_obj = VLCSELF->p_object;
/* Return information about the object as a dict. */
retval = PyDict_New();
PyDict_SetItemString(retval, "object-id", Py_BuildValue("l", p_obj->i_object_id));
PyDict_SetItemString(retval, "object-type", Py_BuildValue("s", p_obj->psz_object_type));
PyDict_SetItemString(retval, "object-name", Py_BuildValue("s", p_obj->psz_object_name));
PyDict_SetItemString(retval, "thread", PyBool_FromLong(p_obj->b_thread));
PyDict_SetItemString(retval, "thread-id", PyLong_FromLongLong(p_obj->thread_id));
PyDict_SetItemString(retval, "refcount", PyInt_FromLong(p_obj->i_refcount));
return retval;
}
static PyObject * vlcObject_find_id(PyObject *self,
PyObject *args)
{
vlcObject *retval;
vlc_object_t* p_object;
int i_id;
if ( !PyArg_ParseTuple(args, "i", &i_id) ) if( !PyArg_Parse( py_key, "i", &key ) )
{ {
PyErr_SetString(PyExc_StandardError, "Error: no id was given.\n"); PyErr_SetString (MediaControl_InternalException, "Invalid key value");
return Py_None; return key_position;
} }
p_object = (vlc_object_t*)vlc_current_object(i_id); switch (key)
if (! p_object)
{ {
Py_INCREF(Py_None); case 0: key = mediacontrol_ByteCount; break;
return Py_None; case 1: key = mediacontrol_SampleCount; break;
case 2: key = mediacontrol_MediaTime; break;
} }
return key_position;
retval = PyObject_NEW(vlcObject, &vlcObject_Type);
retval->p_object = p_object;
return (PyObject *)retval;
} }
/* Do a var_Get call on the object. Parameter: the variable name. */ mediacontrol_PositionOrigin positionOrigin_py_to_c( PyObject * py_origin )
/* FIXME: We should make them attributes */
static PyObject * vlcObject_var_get(PyObject *self,
PyObject *args)
{ {
PyObject *retval; mediacontrol_PositionOrigin origin_position =
vlc_value_t value; mediacontrol_AbsolutePosition;
char *psz_name; int origin;
int i_type;
if ( !PyArg_ParseTuple(args, "s", &psz_name) )
{
PyErr_SetString(PyExc_StandardError, "Error: no variable name was given.\n");
Py_INCREF(Py_None);
return Py_None;
}
if( var_Get( VLCSELF->p_object, psz_name, &value ) != VLC_SUCCESS ) if(!PyArg_Parse(py_origin,"i", &origin))
{ {
PyErr_SetString(PyExc_StandardError, "Error: no variable name was given.\n"); PyErr_SetString( MediaControl_InternalException,
Py_INCREF(Py_None); "Invalid origin value");
return Py_None; return origin_position;
} }
i_type = var_Type (VLCSELF->p_object, psz_name);
switch (i_type) switch (origin)
{ {
case VLC_VAR_VOID : case 0: origin_position = mediacontrol_AbsolutePosition; break;
retval = PyString_FromString("A void variable"); case 1: origin_position = mediacontrol_RelativePosition; break;
break; case 2: origin_position = mediacontrol_ModuloPosition; break;
case VLC_VAR_BOOL :
retval = PyBool_FromLong(value.b_bool);
break;
case VLC_VAR_INTEGER :
retval = PyInt_FromLong((long)value.i_int);
break;
case VLC_VAR_HOTKEY :
retval = PyString_FromFormat("A hotkey variable (%d)", value.i_int);
break;
case VLC_VAR_FILE :
case VLC_VAR_STRING :
case VLC_VAR_DIRECTORY :
case VLC_VAR_VARIABLE :
retval = PyString_FromString(value.psz_string);
break;
case VLC_VAR_MODULE :
retval = (PyObject*)PyObject_New(vlcObject, &vlcObject_Type);
((vlcObject*)retval)->p_object = value.p_object;
break;
case VLC_VAR_FLOAT :
retval = PyFloat_FromDouble((double)value.f_float);
break;
case VLC_VAR_TIME :
retval = PyLong_FromLongLong(value.i_time);
break;
case VLC_VAR_ADDRESS :
retval = PyString_FromString("A VLC address (not handled yet)");
break;
case VLC_VAR_LIST :
retval = PyString_FromString("A VLC list (not handled yet)");
break;
case VLC_VAR_MUTEX :
retval = PyString_FromString("A mutex");
break;
default:
retval = Py_None;
} }
Py_INCREF(retval); return origin_position;
return retval;
} }
static PyObject * vlcObject_var_type(PyObject *self, /* Methods for transforming the Position Python object to Position structure*/
PyObject *args) mediacontrol_Position* position_py_to_c( PyObject * py_position )
{ {
char *psz_name; mediacontrol_Position * a_position = NULL;
PyObject *retval; PyPosition *pos = (PyPosition*)py_position;
int i_type;
if ( !PyArg_ParseTuple(args, "s", &psz_name))
{
PyErr_SetString(PyExc_StandardError, "Error: no variable name was given.\n");
Py_INCREF(Py_None);
return Py_None;
}
i_type = var_Type(VLCSELF->p_object, psz_name); a_position = (mediacontrol_Position*)malloc(sizeof(mediacontrol_Position));
if (! a_position)
switch (i_type)
{ {
case VLC_VAR_VOID : PyErr_SetString(PyExc_MemoryError, "Out of memory");
retval = PyString_FromString("Void"); return NULL;
break;
case VLC_VAR_BOOL :
retval = PyString_FromString("Boolean");
break;
case VLC_VAR_INTEGER :
retval = PyString_FromString("Integer");
break;
case VLC_VAR_HOTKEY :
retval = PyString_FromString("Hotkey");
break;
case VLC_VAR_FILE :
retval = PyString_FromString("File");
break;
case VLC_VAR_STRING :
retval = PyString_FromString("String");
break;
case VLC_VAR_DIRECTORY :
retval = PyString_FromString("Directory");
break;
case VLC_VAR_VARIABLE :
retval = PyString_FromString("Variable");
break;
case VLC_VAR_MODULE :
retval = PyString_FromString("Module");
break;
case VLC_VAR_FLOAT :
retval = PyString_FromString("Float");
break;
case VLC_VAR_TIME :
retval = PyString_FromString("Time");
break;
case VLC_VAR_ADDRESS :
retval = PyString_FromString("Address");
break;
case VLC_VAR_LIST :
retval = PyString_FromString("List");
break;
case VLC_VAR_MUTEX :
retval = PyString_FromString("Mutex");
break;
default:
retval = PyString_FromString("Unknown");
} }
return retval;
}
/* Do a var_Set call on the object. Parameter: the variable name. */ if (PyObject_IsInstance(py_position, (PyObject*)&PyPosition_Type))
/* FIXME: We should make them attributes */
static PyObject * vlcObject_var_set(PyObject *self,
PyObject *args)
{
vlc_value_t value;
char *psz_name;
PyObject *py_value;
int i_type;
vlc_object_t *p_obj;
if ( !PyArg_ParseTuple(args, "sO", &psz_name, &py_value) )
{ {
PyErr_SetString(PyExc_StandardError, "Error: no variable name was given.\n"); a_position->origin = pos->origin;
Py_INCREF(Py_None); a_position->key = pos->key;
return Py_None; a_position->value = pos->value;
} }
else
p_obj = VLCSELF->p_object;
i_type = var_Type(p_obj, psz_name);
switch (i_type)
{ {
case VLC_VAR_VOID : /* Feature: if we give an integer, it will be considered as
break; a relative position in mediatime */
case VLC_VAR_BOOL : a_position->origin = mediacontrol_RelativePosition;
value.b_bool = PyInt_AsLong(py_value); a_position->key = mediacontrol_MediaTime;
break; a_position->value = PyLong_AsLongLong(py_position);
case VLC_VAR_INTEGER :
case VLC_VAR_HOTKEY :
value.i_int = PyInt_AsLong(py_value);
break;
case VLC_VAR_FILE :
case VLC_VAR_STRING :
case VLC_VAR_DIRECTORY :
case VLC_VAR_VARIABLE :
value.psz_string = strdup(PyString_AsString(py_value));
break;
case VLC_VAR_MODULE :
/* FIXME: we should check the PyObject type and get its p_object */
value.p_object = ((vlcObject*)p_obj)->p_object;
break;
case VLC_VAR_FLOAT :
value.f_float = PyFloat_AsDouble(py_value);
break;
case VLC_VAR_TIME :
value.i_time = PyLong_AsLongLong(py_value);
break;
case VLC_VAR_ADDRESS :
value.p_address = (char*)PyLong_AsVoidPtr(py_value);
break;
case VLC_VAR_LIST :
/* FIXME */
value.p_list = NULL;
break;
case VLC_VAR_MUTEX :
break;
} }
return a_position;
var_Set(p_obj, psz_name, value);
Py_INCREF(Py_None);
return Py_None;
}
static PyObject * vlcObject_var_list(PyObject *self,
PyObject *args)
{
PyObject *retval;
int i_size;
int i_index;
i_size = VLCSELF->p_object->i_vars;
retval = PyTuple_New(i_size);
for (i_index = 0 ; i_index < i_size ; i_index++)
{
PyTuple_SetItem(retval, i_index,
Py_BuildValue("s", VLCSELF->p_object->p_vars[i_index].psz_name));
}
/* Py_INCREF(retval); */
return retval;
} }
/* Do a config_Get call on the object. Parameter: the variable name. */ PyPosition* position_c_to_py(mediacontrol_Position *position)
static PyObject * vlcObject_config_get(PyObject *self,
PyObject *args)
{ {
PyObject *retval; PyPosition* py_retval;
vlc_value_t value;
char *psz_name;
module_config_t *p_config;
if ( !PyArg_ParseTuple(args, "s", &psz_name) )
{
PyErr_SetString(PyExc_StandardError, "Error: no config variable name was given.\n");
Py_INCREF(Py_None);
return Py_None;
}
p_config = config_FindConfig( VLCSELF->p_object, psz_name );
if( !p_config ) py_retval = PyObject_New(PyPosition, &PyPosition_Type);
{ py_retval->origin = position->origin;
PyErr_SetString(PyExc_StandardError, "Error: config variable does not exist.\n"); py_retval->key = position->key;
Py_INCREF(Py_None); py_retval->value = position->value;
return Py_None;
}
switch (p_config->i_type)
{
case CONFIG_ITEM_BOOL :
retval = PyBool_FromLong(p_config->i_value);
break;
case CONFIG_ITEM_INTEGER :
retval = PyInt_FromLong((long)p_config->i_value);
break;
case CONFIG_ITEM_KEY :
retval = PyString_FromFormat("A hotkey variable (%d)", p_config->i_value);
break;
case CONFIG_ITEM_FILE :
case CONFIG_ITEM_STRING :
case CONFIG_ITEM_DIRECTORY :
case CONFIG_ITEM_MODULE :
vlc_mutex_lock( p_config->p_lock );
if( p_config->psz_value )
retval = PyString_FromString( p_config->psz_value );
else
retval = PyString_FromString( "" );
vlc_mutex_unlock( p_config->p_lock );
break;
retval = (PyObject*)PyObject_New(vlcObject, &vlcObject_Type);
((vlcObject*)retval)->p_object = value.p_object;
break;
case CONFIG_ITEM_FLOAT :
retval = PyFloat_FromDouble((double)p_config->f_value);
break;
default:
retval = Py_None;
Py_INCREF(retval);
}
return retval; return py_retval;
} }
/* Do a var_Set call on the object. Parameter: the variable name. */ static PyMethodDef PyPosition_methods[] =
/* FIXME: We should make them attributes */
static PyObject * vlcObject_config_set(PyObject *self,
PyObject *args)
{ {
char *psz_name; { NULL } /* Sentinel */
PyObject *py_value; };
vlc_object_t *p_obj;
module_config_t *p_config;
if ( !PyArg_ParseTuple(args, "sO", &psz_name, &py_value) )
{
PyErr_SetString(PyExc_StandardError, "Error: no variable name was given.\n");
Py_INCREF(Py_None);
return Py_None;
}
p_obj = VLCSELF->p_object;
p_config = config_FindConfig( p_obj, psz_name );
/* sanity checks */
if( !p_config )
{
PyErr_SetString(PyExc_StandardError, "Error: option does not exist.\n");
Py_INCREF(Py_None);
return Py_None;
}
switch (p_config->i_type)
{
case CONFIG_ITEM_BOOL :
case CONFIG_ITEM_INTEGER :
case CONFIG_ITEM_KEY :
config_PutInt(p_obj, psz_name, PyInt_AsLong(py_value));
break;
case CONFIG_ITEM_FILE :
case CONFIG_ITEM_STRING :
case CONFIG_ITEM_DIRECTORY :
case CONFIG_ITEM_MODULE :
config_PutPsz(p_obj, psz_name, PyString_AsString(py_value));
break;
case CONFIG_ITEM_FLOAT :
config_PutFloat(p_obj, psz_name, PyFloat_AsDouble(py_value));
break;
}
Py_INCREF(Py_None);
return Py_None;
}
static PyObject * vlcObject_children(PyObject *self, static PyMemberDef PyPosition_members[] =
PyObject *args)
{ {
PyObject *retval; { "origin", T_INT, offsetof(PyPosition, origin), 0, "Position origin" },
int i_size; { "key", T_INT, offsetof(PyPosition, key), 0, "Position key" },
int i_index; { "value", T_ULONG, offsetof(PyPosition, value), 0, "Position value" },
{ NULL } /* Sentinel */
i_size = VLCSELF->p_object->i_children;
retval = PyTuple_New(i_size);
for (i_index = 0 ; i_index < i_size ; i_index++)
{
PyTuple_SetItem(retval, i_index,
Py_BuildValue("i", VLCSELF->p_object->pp_children[i_index]->i_object_id));
}
/* Py_INCREF(retval); */
return retval;
}
/* Method table */
static PyMethodDef vlcObject_methods[] = {
{"get", vlcObject_var_get, METH_VARARGS, "get(str) -> value Get a variable value."},
{"set", vlcObject_var_set, METH_VARARGS, "set(str, value) Set a variable value"},
{"config_get", vlcObject_config_get, METH_VARARGS, "get(str) -> value Get an option value."},
{"config_set", vlcObject_config_set, METH_VARARGS, "set(str, value) Set an option value"},
{"type", vlcObject_var_type, METH_VARARGS, "type(str) -> str Get a variable type"},
{"list", vlcObject_var_list, METH_VARARGS, "list() List the available variables"},
{"children", vlcObject_children, METH_VARARGS, "children() List the children ids"},
{"find_object", vlcObject_find_object, METH_VARARGS, "find_object(str) -> Object Find the object of a given type.\n\nAvailable types are : aout, decoder, input, httpd, intf, playlist, root, vlc, vout"},
{"find_id", vlcObject_find_id, METH_VARARGS, "find_id(int) -> Object Find an object by id"},
{"info", vlcObject_info, METH_VARARGS, "info() -> dict Return information about the object"},
{NULL, NULL, 0, NULL},
}; };
static PyTypeObject vlcObject_Type = { static PyTypeObject PyPosition_Type =
{
PyObject_HEAD_INIT(NULL) PyObject_HEAD_INIT(NULL)
0, /*ob_size*/ 0, /*ob_size*/
"vlc.Object", /*tp_name*/ "vlc.Position", /*tp_name*/
sizeof(vlcObject_Type), /*tp_basicsize*/ sizeof(PyPosition_Type), /*tp_basicsize*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/
(destructor)vlcObject_dealloc, /*tp_dealloc*/ 0, /*tp_dealloc*/
0, /*tp_print*/ 0, /*tp_print*/
0, /*tp_getattr*/ 0, /*tp_getattr*/
0, /*tp_setattr*/ 0, /*tp_setattr*/
...@@ -1251,112 +1384,22 @@ static PyTypeObject vlcObject_Type = { ...@@ -1251,112 +1384,22 @@ static PyTypeObject vlcObject_Type = {
0, /*tp_setattro*/ 0, /*tp_setattro*/
0, /*tp_as_buffer*/ 0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
"Explore VLC objects.", /* tp_doc */ "Represent a Position with origin, key and value", /* tp_doc */
0, /* tp_traverse */ 0, /* tp_traverse */
0, /* tp_clear */ 0, /* tp_clear */
0, /* tp_richcompare */ 0, /* tp_richcompare */
0, /* tp_weaklistoffset */ 0, /* tp_weaklistoffset */
0, /* tp_iter */ 0, /* tp_iter */
0, /* tp_iternext */ 0, /* tp_iternext */
vlcObject_methods, /* tp_methods */ PyPosition_methods, /* tp_methods */
0, /* tp_members */ PyPosition_members, /* tp_members */
0, /* tp_getset */ 0, /* tp_getset */
0, /* tp_base */ 0, /* tp_base */
0, /* tp_dict */ 0, /* tp_dict */
0, /* tp_descr_get */ 0, /* tp_descr_get */
0, /* tp_descr_set */ 0, /* tp_descr_set */
0, /* tp_dictoffset */ 0, /* tp_dictoffset */
0, /* tp_init */ (initproc)PyPosition_init, /* tp_init */
0, /* tp_alloc */ 0, /* tp_alloc */
vlcObject_new, /* tp_new */ 0, /* tp_new */
};
/***** End of vlcObject definitions *****/
#endif
/* Module functions */
static PyMethodDef vlc_methods[] = {
{NULL} /* Sentinel */
}; };
#ifndef vlcMODINIT_FUNC /* declarations for DLL import/export */
#define vlcMODINIT_FUNC void
#endif
vlcMODINIT_FUNC
initvlc(void)
{
PyObject* m;
PyPosition_Type.tp_new = PyType_GenericNew;
PyPosition_Type.tp_alloc = PyType_GenericAlloc;
if (PyType_Ready(&PyPosition_Type) < 0)
return;
if (PyType_Ready(&MediaControl_Type) < 0)
return;
#ifdef VLCOBJECT_SUPPORT
if (PyType_Ready(&vlcObject_Type) < 0)
return;
#endif
/* PyEval_InitThreads(); */
/* Have a look at
http://base.bel-epa.com/pyapache/Python/MySQL-python/MySQL-python-0.3.0/_mysqlmodule.c */
m = Py_InitModule3("vlc", vlc_methods, "VideoLan Client embedding module.");
/* Exceptions */
MediaControl_InternalException = PyErr_NewException("vlc.InternalException", NULL, NULL);
PyModule_AddObject(m, "InternalException", MediaControl_InternalException);
MediaControl_PositionKeyNotSupported = PyErr_NewException("vlc.PositionKeyNotSupported",
NULL, NULL);
PyModule_AddObject(m, "PositionKeyNotSupported", MediaControl_PositionKeyNotSupported);
MediaControl_PositionOriginNotSupported=PyErr_NewException("vlc.InvalidPosition", NULL, NULL);
PyModule_AddObject(m, "PositionOriginNotSupported", MediaControl_PositionOriginNotSupported);
MediaControl_InvalidPosition = PyErr_NewException("vlc.InvalidPosition", NULL, NULL);
PyModule_AddObject(m, "InvalidPosition", MediaControl_InvalidPosition);
MediaControl_PlaylistException = PyErr_NewException("vlc.PlaylistException", NULL, NULL);
PyModule_AddObject(m, "PlaylistException", MediaControl_PlaylistException);
/* Types */
Py_INCREF(&PyPosition_Type);
PyModule_AddObject(m, "Position", (PyObject *)&PyPosition_Type);
Py_INCREF(&MediaControl_Type);
PyModule_AddObject(m, "MediaControl", (PyObject *)&MediaControl_Type);
#ifdef VLCOBJECT_SUPPORT
Py_INCREF(&vlcObject_Type);
PyModule_AddObject(m, "Object", (PyObject *)&vlcObject_Type);
#endif
/* Constants */
PyModule_AddIntConstant(m, "AbsolutePosition", mediacontrol_AbsolutePosition);
PyModule_AddIntConstant(m, "RelativePosition", mediacontrol_RelativePosition);
PyModule_AddIntConstant(m, "ModuloPosition", mediacontrol_ModuloPosition);
PyModule_AddIntConstant(m, "ByteCount", mediacontrol_ByteCount);
PyModule_AddIntConstant(m, "SampleCount", mediacontrol_SampleCount);
PyModule_AddIntConstant(m, "MediaTime", mediacontrol_MediaTime);
PyModule_AddIntConstant(m, "PlayingStatus", mediacontrol_PlayingStatus);
PyModule_AddIntConstant(m, "PauseStatus", mediacontrol_PauseStatus);
PyModule_AddIntConstant(m, "ForwardStatus", mediacontrol_ForwardStatus);
PyModule_AddIntConstant(m, "BackwardStatus", mediacontrol_BackwardStatus);
PyModule_AddIntConstant(m, "InitStatus", mediacontrol_InitStatus);
PyModule_AddIntConstant(m, "EndStatus", mediacontrol_EndStatus);
PyModule_AddIntConstant(m, "UndefinedStatus", mediacontrol_UndefinedStatus);
}
/* Make libpostproc happy... */
void * fast_memcpy(void * to, const void * from, size_t len)
{
return memcpy(to, from, len);
}
/*****************************************************************************
* vlcglue.h: Main header for the Python binding
*****************************************************************************
* Copyright (C) 1998-2004 the VideoLAN team
* $Id: vlc.c 12667 2005-09-25 10:19:26Z zorglub $
*
* Authors: Olivier Aubert <oaubert at bat710.univ-lyon1.fr>
* Clment Stenac <zorglub@videolan.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#include <Python.h>
#include "structmember.h"
/* Undefine the following define to disable low-level vlc Object support */
#define VLCOBJECT_SUPPORT 0
#define __VLC__
#include <stdio.h>
#include <vlc/control.h>
#define SELF ((MediaControl*)self)
/**********************************************************************
* Exceptions handling
**********************************************************************/
#define MC_TRY exception=mediacontrol_exception_init(exception)
#define MC_EXCEPT \
if (exception->code) { \
PyObject *py_exc = MediaControl_InternalException; \
switch (exception->code) { \
case mediacontrol_InternalException: \
py_exc = MediaControl_InternalException; \
break; \
case mediacontrol_PlaylistException: \
py_exc = MediaControl_PlaylistException; \
break; \
case mediacontrol_InvalidPosition: \
py_exc = MediaControl_InvalidPosition; \
break; \
case mediacontrol_PositionKeyNotSupported: \
py_exc = MediaControl_PositionKeyNotSupported; \
break; \
case mediacontrol_PositionOriginNotSupported: \
py_exc = MediaControl_PositionOriginNotSupported; \
break; \
} \
PyErr_SetString(py_exc, exception->message); \
mediacontrol_exception_free(exception); \
return NULL; \
} else { mediacontrol_exception_free(exception); }
PyObject *MediaControl_InternalException;
PyObject *MediaControl_PositionKeyNotSupported;
PyObject *MediaControl_PositionOriginNotSupported;
PyObject *MediaControl_InvalidPosition;
PyObject *MediaControl_PlaylistException;
/**********************************************************************
* VLC Object
**********************************************************************/
#ifdef VLCOBJECT_SUPPORT
#define VLCSELF ((vlcObject*)self)
/**********************************************************************
* VLCObject Object
**********************************************************************/
typedef struct
{
PyObject_HEAD
vlc_object_t* p_object;
int b_released;
} vlcObject;
staticforward PyTypeObject vlcObject_Type;
#endif
/**********************************************************************
* MediaControl Object
**********************************************************************/
typedef struct
{
PyObject_HEAD
mediacontrol_Instance* mc;
}MediaControl;
staticforward PyTypeObject MediaControl_Type;
/**********************************************************************
* Position Object
**********************************************************************/
typedef struct
{
PyObject_HEAD
int origin;
int key;
long long value;
} PyPosition;
staticforward PyTypeObject PyPosition_Type;
mediacontrol_PositionKey positionKey_py_to_c( PyObject * py_key );
mediacontrol_PositionOrigin positionOrigin_py_to_c( PyObject * py_origin );
mediacontrol_Position* position_py_to_c( PyObject * py_position );
PyPosition* position_c_to_py(mediacontrol_Position *position);
...@@ -186,7 +186,7 @@ int aout_OutputNew( aout_instance_t * p_aout, ...@@ -186,7 +186,7 @@ int aout_OutputNew( aout_instance_t * p_aout,
p_aout->mixer.mixer.i_format = p_format->i_format; p_aout->mixer.mixer.i_format = p_format->i_format;
} }
aout_FormatPrint( p_aout, "mixer", &p_aout->output.output ); aout_FormatPrint( p_aout, "mixer", &p_aout->mixer.mixer );
/* Create filters. */ /* Create filters. */
p_aout->output.i_nb_filters = 0; p_aout->output.i_nb_filters = 0;
......
...@@ -74,7 +74,8 @@ mediacontrol_Instance* mediacontrol_new_from_object( vlc_object_t* p_object, ...@@ -74,7 +74,8 @@ mediacontrol_Instance* mediacontrol_new_from_object( vlc_object_t* p_object,
retval->vlc_object_id = p_vlc->i_object_id; retval->vlc_object_id = p_vlc->i_object_id;
/* We can keep references on these, which should not change. Is it true ? */ /* We can keep references on these, which should not change. Is it true ? */
retval->p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE ); retval->p_playlist = vlc_object_find( p_vlc,
VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
retval->p_intf = vlc_object_find( p_vlc, VLC_OBJECT_INTF, FIND_ANYWHERE ); retval->p_intf = vlc_object_find( p_vlc, VLC_OBJECT_INTF, FIND_ANYWHERE );
if( ! retval->p_playlist || ! retval->p_intf ) if( ! retval->p_playlist || ! retval->p_intf )
...@@ -272,7 +273,8 @@ mediacontrol_playlist_add_item( mediacontrol_Instance *self, ...@@ -272,7 +273,8 @@ mediacontrol_playlist_add_item( mediacontrol_Instance *self,
return; return;
} }
playlist_Add( self->p_playlist, psz_file, psz_file , PLAYLIST_REPLACE, 0 ); playlist_Add( self->p_playlist, psz_file, psz_file , PLAYLIST_INSERT,
PLAYLIST_END );
} }
void void
......
...@@ -62,7 +62,8 @@ mediacontrol_Instance* mediacontrol_new( char** args, mediacontrol_Exception *ex ...@@ -62,7 +62,8 @@ mediacontrol_Instance* mediacontrol_new( char** args, mediacontrol_Exception *ex
retval->vlc_object_id = p_vlc_id; retval->vlc_object_id = p_vlc_id;
/* We can keep references on these, which should not change. Is it true ? */ /* We can keep references on these, which should not change. Is it true ? */
retval->p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE ); retval->p_playlist = vlc_object_find( p_vlc,
VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
retval->p_intf = vlc_object_find( p_vlc, VLC_OBJECT_INTF, FIND_ANYWHERE ); retval->p_intf = vlc_object_find( p_vlc, VLC_OBJECT_INTF, FIND_ANYWHERE );
if( ! retval->p_playlist || ! retval->p_intf ) if( ! retval->p_playlist || ! retval->p_intf )
...@@ -71,16 +72,19 @@ mediacontrol_Instance* mediacontrol_new( char** args, mediacontrol_Exception *ex ...@@ -71,16 +72,19 @@ mediacontrol_Instance* mediacontrol_new( char** args, mediacontrol_Exception *ex
exception->message = strdup( "No available interface" ); exception->message = strdup( "No available interface" );
return NULL; return NULL;
} }
return retval; return retval;
}; };
void void
mediacontrol_exit( mediacontrol_Instance *self ) mediacontrol_exit( mediacontrol_Instance *self )
{ {
/*
vlc_object_release( (vlc_object_t* )self->p_playlist ); vlc_object_release( (vlc_object_t* )self->p_playlist );
vlc_object_release( (vlc_object_t* )self->p_intf ); vlc_object_release( (vlc_object_t* )self->p_intf );
*/ vlc_object_release( (vlc_object_t*)self->p_vlc );
VLC_CleanUp( self->vlc_object_id ); VLC_CleanUp( self->vlc_object_id );
VLC_Destroy( self->vlc_object_id ); VLC_Destroy( self->vlc_object_id );
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment