Update of /cvsroot/freevo/kaa/xine/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25407/src
Modified Files:
__init__.py audio_port.c audio_port.h stream.c stream.h
video_port.c video_port.h xine.c xine.h
Added Files:
post.c post.h
Log Message:
Added Post type; added skeleton for buffer post plugin (vf_outbuf only
for xine). Keep a mapping of xine objects to python objects. Added a
few more API functions elsewhere.
Index: stream.c
===================================================================
RCS file: /cvsroot/freevo/kaa/xine/src/stream.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** stream.c 16 Jul 2005 03:52:43 -0000 1.1
--- stream.c 18 Jul 2005 03:40:21 -0000 1.2
***************
*** 3,6 ****
--- 3,36 ----
#include "structmember.h"
+ Xine_Stream_PyObject *
+ pyxine_new_stream_pyobject(Xine_PyObject *xine, xine_stream_t *stream,
+ Xine_Audio_Port_PyObject *ao,
+ Xine_Video_Port_PyObject *vo, int owner)
+ {
+ Xine_Stream_PyObject *o = (Xine_Stream_PyObject
*)xine_object_to_pyobject_find(stream);
+ if (o) {
+ Py_INCREF(o);
+ return o;
+ }
+
+ o = (Xine_Stream_PyObject
*)Xine_Stream_PyObject__new(&Xine_Stream_PyObject_Type, NULL, NULL);
+ if (!o)
+ return NULL;
+ o->stream = stream;
+ o->xine_object_owner = owner;
+ o->ao_pyobject = ao;
+ Py_INCREF(ao);
+ o->vo_pyobject = vo;
+ Py_INCREF(vo);
+ o->xine_pyobject = (PyObject *)xine;
+ o->xine = xine->xine;
+ Py_INCREF(xine);
+ xine_object_to_pyobject_register(stream, (PyObject *)o);
+ return o;
+ }
+
+
+
+
static int
Xine_Stream_PyObject__clear(Xine_Stream_PyObject *self)
***************
*** 58,65 ****
self = (Xine_Stream_PyObject *)type->tp_alloc(type, 0);
- self->owns_ref = 0;
self->stream = NULL;
self->xine = NULL;
self->xine_pyobject = NULL;
return (PyObject *)self;
}
--- 88,96 ----
self = (Xine_Stream_PyObject *)type->tp_alloc(type, 0);
self->stream = NULL;
self->xine = NULL;
self->xine_pyobject = NULL;
+ self->wrapper = Py_None;
+ Py_INCREF(Py_None);
return (PyObject *)self;
}
***************
*** 73,76 ****
--- 104,108 ----
static PyMemberDef Xine_Stream_PyObject_members[] = {
+ {"wrapper", T_OBJECT_EX, offsetof(Xine_Stream_PyObject, wrapper), 0,
"Wrapper object"},
{NULL}
};
***************
*** 81,89 ****
{
printf("DEalloc Stream: %x\n", self->xine);
! if (self->stream && self->owns_ref) {
xine_close(self->stream);
xine_dispose(self->stream);
}
Xine_Stream_PyObject__clear(self);
self->ob_type->tp_free((PyObject*)self);
}
--- 113,123 ----
{
printf("DEalloc Stream: %x\n", self->xine);
! if (self->stream && self->xine_object_owner) {
xine_close(self->stream);
xine_dispose(self->stream);
}
+ Py_DECREF(self->wrapper);
Xine_Stream_PyObject__clear(self);
+ xine_object_to_pyobject_unregister(self->stream);
self->ob_type->tp_free((PyObject*)self);
}
***************
*** 134,138 ****
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
! "_xine.XineVideoPort", /* tp_name */
sizeof(Xine_Stream_PyObject), /* tp_basicsize */
0, /* tp_itemsize */
--- 168,172 ----
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
! "_xine.Stream", /* tp_name */
sizeof(Xine_Stream_PyObject), /* tp_basicsize */
0, /* tp_itemsize */
***************
*** 153,157 ****
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*
tp_flags */
! "Xine Video Port Object", /* tp_doc */
(traverseproc)Xine_Stream_PyObject__traverse, /* tp_traverse */
(inquiry)Xine_Stream_PyObject__clear, /* tp_clear */
--- 187,191 ----
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*
tp_flags */
! "Xine Stream Object", /* tp_doc */
(traverseproc)Xine_Stream_PyObject__traverse, /* tp_traverse */
(inquiry)Xine_Stream_PyObject__clear, /* tp_clear */
Index: xine.h
===================================================================
RCS file: /cvsroot/freevo/kaa/xine/src/xine.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** xine.h 16 Jul 2005 03:52:43 -0000 1.1
--- xine.h 18 Jul 2005 03:40:21 -0000 1.2
***************
*** 13,20 ****
PyObject_HEAD
xine_t *xine;
! PyObject *dependencies;
} Xine_PyObject;
extern PyTypeObject Xine_PyObject_Type;
#endif
--- 13,25 ----
PyObject_HEAD
xine_t *xine;
! PyObject *dependencies, *wrapper;
} Xine_PyObject;
extern PyTypeObject Xine_PyObject_Type;
+ void xine_object_to_pyobject_register(void *ptr, PyObject *o);
+ void xine_object_to_pyobject_unregister(void *ptr);
+ PyObject *xine_object_to_pyobject_find(void *ptr);
+
+
#endif
Index: stream.h
===================================================================
RCS file: /cvsroot/freevo/kaa/xine/src/stream.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** stream.h 16 Jul 2005 03:52:43 -0000 1.1
--- stream.h 18 Jul 2005 03:40:21 -0000 1.2
***************
*** 19,23 ****
xine_t *xine;
xine_stream_t *stream;
! int owns_ref;
} Xine_Stream_PyObject;
--- 19,25 ----
xine_t *xine;
xine_stream_t *stream;
! int xine_object_owner;
!
! PyObject *wrapper;
} Xine_Stream_PyObject;
***************
*** 25,28 ****
--- 27,32 ----
PyObject *Xine_Stream_PyObject__new(PyTypeObject *, PyObject *, PyObject *);
+ Xine_Stream_PyObject *pyxine_new_stream_pyobject(Xine_PyObject *,
xine_stream_t *,
+ Xine_Audio_Port_PyObject *ao, Xine_Video_Port_PyObject *vo, int);
Index: __init__.py
===================================================================
RCS file: /cvsroot/freevo/kaa/xine/src/__init__.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** __init__.py 16 Jul 2005 03:52:43 -0000 1.1
--- __init__.py 18 Jul 2005 03:40:21 -0000 1.2
***************
*** 1,5 ****
--- 1,25 ----
+ import weakref
import _xine
from kaa import display
+ XineError = _xine.XineError
+
+ def _wrap_xine_object(obj):
+ if obj.wrapper and obj.wrapper():
+ return obj.wrapper()
+
+ if type(obj) == _xine.VideoPort:
+ o = VideoPort(obj)
+ elif type(obj) == _xine.AudioPort:
+ o = AudioPort(obj)
+ elif type(obj) == _xine.Stream:
+ o = Stream(obj)
+ elif type(obj) == _xine.Post:
+ o = Post(obj)
+
+ obj.wrapper = weakref.ref(o)
+ return o
+
+
class Xine(object):
def __init__(self):
***************
*** 13,22 ****
vo = self._xine.open_video_driver(driver, **kwargs)
! return VideoPort(vo)
def open_audio_driver(self, driver = "auto", **kwargs):
ao = self._xine.open_audio_driver(driver, **kwargs)
! return AudioPort(ao)
--- 33,42 ----
vo = self._xine.open_video_driver(driver, **kwargs)
! return _wrap_xine_object(vo)
def open_audio_driver(self, driver = "auto", **kwargs):
ao = self._xine.open_audio_driver(driver, **kwargs)
! return _wrap_xine_object(ao)
***************
*** 26,30 ****
stream = self._xine.stream_new(audio_port._ao, video_port._vo)
! return Stream(stream)
--- 46,75 ----
stream = self._xine.stream_new(audio_port._ao, video_port._vo)
! return _wrap_xine_object(stream)
!
! def list_video_plugins(self):
! return self._xine.list_plugins("video")
!
! def list_audio_plugins(self):
! return self._xine.list_plugins("audio")
!
! def list_post_plugins(self):
! return self._xine.list_plugins("post")
!
!
! def post_init(self, name, inputs = 0, audio_targets = [], video_targets =
[]):
! assert(type(audio_targets) in (list, tuple))
! assert(type(video_targets) in (list, tuple))
! ao = []
! for item in audio_targets:
! assert(type(item) == AudioPort)
! ao.append(item._ao)
! vo = []
! for item in video_targets:
! assert(type(item) == VideoPort)
! vo.append(item._vo)
!
! post = self._xine.post_init(name, inputs, ao, vo)
! return _wrap_xine_object(post)
***************
*** 49,50 ****
--- 94,123 ----
return self._stream.play(pos, time)
+
+ class Post(object):
+ def __init__(self, post):
+ self._post = post
+
+ def get_video_inputs(self):
+ l = []
+ for item in self._post.get_video_inputs():
+ l.append(_wrap_xine_object(item))
+ return l
+
+ def get_parameters_desc(self):
+ return self._post.get_parameters_desc()
+
+ def get_parameters(self):
+ return self._post.get_parameters()
+
+ def set_parameters(self, values):
+ assert(type(values) == dict)
+ parms = self.get_parameters_desc()
+ for key, value in values.items():
+ assert(key in parms)
+ assert(type(value) == parms[key]["type"])
+
+ return self._post.set_parameters(values)
+
+ def set_parameter(self, param, value):
+ return self.set_parameters({param: value})
Index: audio_port.c
===================================================================
RCS file: /cvsroot/freevo/kaa/xine/src/audio_port.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** audio_port.c 16 Jul 2005 03:52:43 -0000 1.1
--- audio_port.c 18 Jul 2005 03:40:21 -0000 1.2
***************
*** 3,6 ****
--- 3,29 ----
#include "structmember.h"
+
+ Xine_Audio_Port_PyObject *
+ pyxine_new_audio_port_pyobject(Xine_PyObject *xine, xine_audio_port_t *ao,
int owner)
+ {
+ Xine_Audio_Port_PyObject *o = (Xine_Audio_Port_PyObject
*)xine_object_to_pyobject_find(ao);
+ if (o) {
+ Py_INCREF(o);
+ return o;
+ }
+
+ o = (Xine_Audio_Port_PyObject
*)Xine_Audio_Port_PyObject__new(&Xine_Audio_Port_PyObject_Type, NULL, NULL);
+ if (!o)
+ return NULL;
+ o->ao = ao;
+ o->xine_pyobject = (PyObject *)xine;
+ o->xine = xine->xine;
+ o->xine_object_owner = owner;
+ Py_INCREF(xine);
+ xine_object_to_pyobject_register(ao, (PyObject *)o);
+ return o;
+ }
+
+
static int
Xine_Audio_Port_PyObject__clear(Xine_Audio_Port_PyObject *self)
***************
*** 38,44 ****
self = (Xine_Audio_Port_PyObject *)type->tp_alloc(type, 0);
- self->owns_ref = 0;
self->ao = NULL;
self->xine = NULL;
return (PyObject *)self;
}
--- 61,68 ----
self = (Xine_Audio_Port_PyObject *)type->tp_alloc(type, 0);
self->ao = NULL;
self->xine = NULL;
+ self->wrapper = Py_None;
+ Py_INCREF(Py_None);
return (PyObject *)self;
}
***************
*** 51,54 ****
--- 75,79 ----
static PyMemberDef Xine_Audio_Port_PyObject_members[] = {
+ {"wrapper", T_OBJECT_EX, offsetof(Xine_Audio_Port_PyObject, wrapper), 0,
"Wrapper object"},
{NULL}
};
***************
*** 59,66 ****
{
printf("DEalloc Audio Port: %x\n", self->xine);
! if (self->ao && self->owns_ref) {
xine_close_audio_driver(self->xine, self->ao);
}
Xine_Audio_Port_PyObject__clear(self);
self->ob_type->tp_free((PyObject*)self);
}
--- 84,93 ----
{
printf("DEalloc Audio Port: %x\n", self->xine);
! if (self->ao && self->xine_object_owner) {
xine_close_audio_driver(self->xine, self->ao);
}
+ Py_DECREF(self->wrapper);
Xine_Audio_Port_PyObject__clear(self);
+ xine_object_to_pyobject_unregister(self->ao);
self->ob_type->tp_free((PyObject*)self);
}
***************
*** 74,78 ****
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
! "_xine.XineAudioPort", /* tp_name */
sizeof(Xine_Audio_Port_PyObject), /* tp_basicsize */
0, /* tp_itemsize */
--- 101,105 ----
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
! "_xine.AudioPort", /* tp_name */
sizeof(Xine_Audio_Port_PyObject), /* tp_basicsize */
0, /* tp_itemsize */
--- NEW FILE: post.h ---
#ifndef __POST_H_
#define __POST_H_
#include "config.h"
#include <Python.h>
#include <xine.h>
#define Xine_Post_PyObject_Check(v) ((v)->ob_type == &Xine_Post_PyObject_Type)
typedef struct {
PyObject_HEAD
xine_post_t *post;
int xine_object_owner;
PyObject *xine_pyobject;
xine_t *xine;
PyObject *audio_targets, *video_targets;
PyObject *wrapper;
} Xine_Post_PyObject;
extern PyTypeObject Xine_Post_PyObject_Type;
PyObject *Xine_Post_PyObject__new(PyTypeObject *, PyObject *, PyObject *);
Xine_Post_PyObject *pyxine_new_post_pyobject(Xine_PyObject *, xine_post_t *,
PyObject *, PyObject *, int);
#endif
Index: audio_port.h
===================================================================
RCS file: /cvsroot/freevo/kaa/xine/src/audio_port.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** audio_port.h 16 Jul 2005 03:52:43 -0000 1.1
--- audio_port.h 18 Jul 2005 03:40:21 -0000 1.2
***************
*** 11,19 ****
PyObject_HEAD
-
xine_audio_port_t *ao;
! int owns_ref;
PyObject *xine_pyobject;
xine_t *xine;
} Xine_Audio_Port_PyObject;
--- 11,20 ----
PyObject_HEAD
xine_audio_port_t *ao;
! int xine_object_owner;
PyObject *xine_pyobject;
xine_t *xine;
+
+ PyObject *wrapper;
} Xine_Audio_Port_PyObject;
***************
*** 21,24 ****
--- 22,26 ----
PyObject *Xine_Audio_Port_PyObject__new(PyTypeObject *, PyObject *, PyObject
*);
+ Xine_Audio_Port_PyObject *pyxine_new_audio_port_pyobject(Xine_PyObject *,
xine_audio_port_t *, int);
Index: video_port.h
===================================================================
RCS file: /cvsroot/freevo/kaa/xine/src/video_port.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** video_port.h 16 Jul 2005 03:52:43 -0000 1.1
--- video_port.h 18 Jul 2005 03:40:21 -0000 1.2
***************
*** 12,18 ****
PyObject *xine_pyobject;
xine_t *xine;
xine_video_port_t *vo;
! int owns_ref;
} Xine_Video_Port_PyObject;
--- 12,20 ----
PyObject *xine_pyobject;
+ int xine_object_owner;
xine_t *xine;
xine_video_port_t *vo;
!
! PyObject *wrapper;
} Xine_Video_Port_PyObject;
***************
*** 20,23 ****
--- 22,26 ----
PyObject *Xine_Video_Port_PyObject__new(PyTypeObject *, PyObject *, PyObject
*);
+ Xine_Video_Port_PyObject *pyxine_new_video_port_pyobject(Xine_PyObject *,
xine_video_port_t *, int);
--- NEW FILE: post.c ---
#include "xine.h"
#include "video_port.h"
#include "audio_port.h"
#include "post.h"
#include "structmember.h"
Xine_Post_PyObject *
pyxine_new_post_pyobject(Xine_PyObject *xine, xine_post_t *post,
PyObject *audio_targets, PyObject *video_targets,
int owner)
{
Xine_Post_PyObject *o = (Xine_Post_PyObject
*)xine_object_to_pyobject_find(post);
if (o) {
Py_INCREF(o);
return o;
}
o = (Xine_Post_PyObject *)Xine_Post_PyObject__new(&Xine_Post_PyObject_Type,
NULL, NULL);
if (!o)
return NULL;
o->post = post;
o->xine_pyobject = (PyObject *)xine;
o->xine = xine->xine;
o->xine_object_owner = owner;
Py_INCREF(xine);
o->audio_targets = audio_targets;
Py_INCREF(audio_targets);
o->video_targets = video_targets;
Py_INCREF(video_targets);
xine_object_to_pyobject_register(post, (PyObject *)o);
return o;
}
static int
Xine_Post_PyObject__clear(Xine_Post_PyObject *self)
{
PyObject *tmp;
if (self->xine_pyobject) {
tmp = self->xine_pyobject;
self->xine_pyobject = 0;
Py_DECREF(tmp);
}
if (self->audio_targets) {
tmp = self->audio_targets;
self->audio_targets = 0;
Py_DECREF(tmp);
}
if (self->video_targets) {
tmp = self->video_targets;
self->video_targets = 0;
Py_DECREF(tmp);
}
return 0;
}
static int
Xine_Post_PyObject__traverse(Xine_Post_PyObject *self, visitproc visit, void
*arg)
{
int ret;
if (self->xine_pyobject) {
ret = visit((PyObject *)self->xine_pyobject, arg);
if (ret != 0)
return ret;
}
if (self->audio_targets) {
ret = visit((PyObject *)self->audio_targets, arg);
if (ret != 0)
return ret;
}
if (self->video_targets) {
ret = visit((PyObject *)self->video_targets, arg);
if (ret != 0)
return ret;
}
return 0;
}
PyObject *
Xine_Post_PyObject__new(PyTypeObject *type, PyObject * args, PyObject * kwargs)
{
Xine_Post_PyObject *self;
if (args) {
PyErr_SetString(xine_error, "Don't call me directly");
return NULL;
}
self = (Xine_Post_PyObject *)type->tp_alloc(type, 0);
self->post = NULL;
self->xine = NULL;
self->xine_pyobject = NULL;
self->wrapper = Py_None;
Py_INCREF(Py_None);
return (PyObject *)self;
}
static int
Xine_Post_PyObject__init(Xine_Post_PyObject *self, PyObject *args, PyObject
*kwds)
{
return 0;
}
static PyMemberDef Xine_Post_PyObject_members[] = {
{"wrapper", T_OBJECT_EX, offsetof(Xine_Post_PyObject, wrapper), 0, "Wrapper
object"},
{NULL}
};
void
Xine_Post_PyObject__dealloc(Xine_Post_PyObject *self)
{
printf("DEalloc Post: %x\n", self->xine);
if (self->post && self->xine_object_owner) {
// bug in xine?
//xine_post_dispose(self->xine, self->post);
}
Py_DECREF(self->wrapper);
Xine_Post_PyObject__clear(self);
xine_object_to_pyobject_unregister(self->post);
self->ob_type->tp_free((PyObject*)self);
}
PyObject *
Xine_Post_PyObject_get_audio_inputs(Xine_Post_PyObject *self, PyObject *args,
PyObject *kwargs)
{
Xine_PyObject *xine = (Xine_PyObject *)self->xine_pyobject;
PyObject *list = PyList_New(0), *o;
xine_audio_port_t *ao;
int i;
for (i = 0; self->post->audio_input[i]; i++) {
ao = self->post->audio_input[i];
o = (PyObject *)pyxine_new_audio_port_pyobject(xine, ao, 0);
PyList_Append(list, o);
Py_DECREF(o);
}
return list;
}
PyObject *
Xine_Post_PyObject_get_video_inputs(Xine_Post_PyObject *self, PyObject *args,
PyObject *kwargs)
{
Xine_PyObject *xine = (Xine_PyObject *)self->xine_pyobject;
PyObject *list = PyList_New(0), *o;
xine_video_port_t *vo;
int i;
for (i = 0; self->post->video_input[i]; i++) {
vo = self->post->video_input[i];
o = (PyObject *)pyxine_new_video_port_pyobject(xine, vo, 0);
PyList_Append(list, o);
Py_DECREF(o);
}
return list;
}
PyObject *
Xine_Post_PyObject_get_parameters_desc(Xine_Post_PyObject *self, PyObject
*args, PyObject *kwargs)
{
xine_post_in_t *input_api;
xine_post_api_t *api;
xine_post_api_descr_t *desc;
xine_post_api_parameter_t *parm;
int nparm = 0;
PyObject *param_dict = PyDict_New();
input_api = (xine_post_in_t *)xine_post_input(self->post, "parameters");
if (!input_api) {
Py_INCREF(Py_None);
return Py_None;
}
api = (xine_post_api_t *)input_api->data;
desc = api->get_param_descr();
parm = desc->parameter;
while (parm->type != POST_PARAM_TYPE_LAST) {
PyObject *dict = PyDict_New();
PyObject *type = Py_None;
switch(parm->type) {
case POST_PARAM_TYPE_INT:
type = (PyObject *)&PyInt_Type;
break;
case POST_PARAM_TYPE_DOUBLE:
type = (PyObject *)&PyFloat_Type;
break;
case POST_PARAM_TYPE_CHAR:
case POST_PARAM_TYPE_STRING:
type = (PyObject *)&PyString_Type;
break;
case POST_PARAM_TYPE_STRINGLIST:
type = (PyObject *)&PyList_Type;
break;
case POST_PARAM_TYPE_BOOL:
type = (PyObject *)&PyBool_Type;
break;
}
Py_INCREF(type);
PyDict_SetItemString(dict, "type", type);
PyDict_SetItemString(dict, "name", PyString_FromString(parm->name));
PyDict_SetItemString(dict, "offset", PyInt_FromLong(parm->offset));
PyDict_SetItemString(dict, "size", PyInt_FromLong(parm->size));
PyDict_SetItemString(dict, "readonly", PyBool_FromLong(parm->readonly));
PyDict_SetItemString(param_dict, parm->name, dict);
Py_DECREF(dict);
parm++;
}
return param_dict;
}
PyObject *
Xine_Post_PyObject_get_parameters(Xine_Post_PyObject *self, PyObject *args,
PyObject *kwargs)
{
xine_post_in_t *input_api;
xine_post_api_t *api;
xine_post_api_descr_t *desc;
xine_post_api_parameter_t *parm;
char *data;
PyObject *dict= PyDict_New();
input_api = (xine_post_in_t *)xine_post_input(self->post, "parameters");
if (!input_api) {
Py_INCREF(Py_None);
return Py_None;
}
api = (xine_post_api_t *)input_api->data;
desc = api->get_param_descr();
parm = desc->parameter;
data = (void *)malloc(desc->struct_size);
api->get_parameters(self->post, (void *)data);
while (parm->type != POST_PARAM_TYPE_LAST) {
PyObject *value = NULL;
switch(parm->type) {
case POST_PARAM_TYPE_INT:
value = PyInt_FromLong(*(int *)(data + parm->offset));
break;
case POST_PARAM_TYPE_DOUBLE:
value = PyFloat_FromDouble(*(double *)(data + parm->offset));
break;
case POST_PARAM_TYPE_CHAR:
value = PyString_FromString((char *)(data + parm->offset));
break;
case POST_PARAM_TYPE_STRING:
value = PyString_FromString(*(char **)(data + parm->offset));
break;
case POST_PARAM_TYPE_STRINGLIST:
{
int i;
char **strings = (char **)(data + parm->offset);
PyObject *str;
value = PyList_New(0);
for (i = 0; strings[i]; i++) {
str = PyString_FromString(strings[i]);
PyList_Append(value, str);
Py_DECREF(str);
}
break;
}
case POST_PARAM_TYPE_BOOL:
value = PyBool_FromLong(*(int *)(data + parm->offset));
break;
}
if (PyErr_Occurred())
break;
if (value) {
PyDict_SetItemString(dict, parm->name, value);
Py_DECREF(value);
}
parm++;
}
free(data);
if (PyErr_Occurred())
return NULL;
return dict;
}
PyObject *
Xine_Post_PyObject_set_parameters(Xine_Post_PyObject *self, PyObject *args,
PyObject *kwargs)
{
xine_post_in_t *input_api;
xine_post_api_t *api;
xine_post_api_descr_t *desc;
xine_post_api_parameter_t *parm;
char *data;
PyObject *dict;
if (!PyArg_ParseTuple(args, "O!", &PyDict_Type, &dict))
return NULL;
input_api = (xine_post_in_t *)xine_post_input(self->post, "parameters");
if (!input_api) {
Py_INCREF(Py_None);
return Py_None;
}
api = (xine_post_api_t *)input_api->data;
desc = api->get_param_descr();
parm = desc->parameter;
data = (void *)malloc(desc->struct_size);
api->get_parameters(self->post, (void *)data);
while (parm->type != POST_PARAM_TYPE_LAST) {
PyObject *value = PyDict_GetItemString(dict, parm->name);
if (!value) {
parm++;
continue;
}
switch(parm->type) {
case POST_PARAM_TYPE_INT:
*(int *)(data + parm->offset) = PyLong_AsLong(value);
break;
case POST_PARAM_TYPE_DOUBLE:
*(double *)(data + parm->offset) = PyFloat_AsDouble(value);
break;
case POST_PARAM_TYPE_CHAR:
strncpy((char *)(data + parm->offset),
PyString_AsString(value), parm->size);
break;
case POST_PARAM_TYPE_STRING:
{
char *tmp;
tmp = (void *)calloc(1, PySequence_Size(value) + 1);
strcpy(tmp, PyString_AsString(value));
*(char **)(data + parm->offset) = tmp;
break;
}
case POST_PARAM_TYPE_STRINGLIST:
{
int i;
char **strings, *tmp;
strings = (char **)malloc(PyList_Size(value) + 1);
for (i = 0; i < PyList_Size(value); i++) {
PyObject *o = PyList_GetItem(value, i);
tmp = (void *)calloc(1, PySequence_Size(o) + 1);
strcpy(tmp, PyString_AsString(o));
strings[i] = tmp;
Py_DECREF(o);
}
strings[i] = NULL;
*(char **)(data + parm->offset) = (char *)strings;
break;
}
case POST_PARAM_TYPE_BOOL:
*(int *)(data + parm->offset) = PyLong_AsLong(value);
break;
}
parm++;
}
api->set_parameters(self->post, (void *)data);
free(data);
if (PyErr_Occurred())
return NULL;
Py_INCREF(Py_None);
return Py_None;
}
// *INDENT-OFF*
PyMethodDef Xine_Post_PyObject_methods[] = {
{"get_audio_inputs", (PyCFunction) Xine_Post_PyObject_get_audio_inputs,
METH_VARARGS},
{"get_video_inputs", (PyCFunction) Xine_Post_PyObject_get_video_inputs,
METH_VARARGS},
{"get_parameters_desc", (PyCFunction)
Xine_Post_PyObject_get_parameters_desc, METH_VARARGS},
{"get_parameters", (PyCFunction) Xine_Post_PyObject_get_parameters,
METH_VARARGS},
{"set_parameters", (PyCFunction) Xine_Post_PyObject_set_parameters,
METH_VARARGS},
{NULL, NULL}
};
PyTypeObject Xine_Post_PyObject_Type = {
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
"_xine.Post", /* tp_name */
sizeof(Xine_Post_PyObject), /* tp_basicsize */
0, /* tp_itemsize */
(destructor) Xine_Post_PyObject__dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_compare */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
PyObject_GenericGetAttr, /* tp_getattro */
PyObject_GenericSetAttr, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /* tp_flags
*/
"Xine Post Object", /* tp_doc */
(traverseproc)Xine_Post_PyObject__traverse, /* tp_traverse */
(inquiry)Xine_Post_PyObject__clear, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
Xine_Post_PyObject_methods, /* tp_methods */
Xine_Post_PyObject_members, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
(initproc)Xine_Post_PyObject__init, /* tp_init */
0, /* tp_alloc */
Xine_Post_PyObject__new, /* tp_new */
};
Index: video_port.c
===================================================================
RCS file: /cvsroot/freevo/kaa/xine/src/video_port.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** video_port.c 16 Jul 2005 03:52:43 -0000 1.1
--- video_port.c 18 Jul 2005 03:40:21 -0000 1.2
***************
*** 3,10 ****
#include "structmember.h"
static int
! Xine_Video_Port_PyObject__clear(Xine_Video_Port_PyObject *self)
{
PyObject *tmp;
if (self->xine_pyobject) {
tmp = self->xine_pyobject;
--- 3,38 ----
#include "structmember.h"
+ Xine_Video_Port_PyObject *
+ pyxine_new_video_port_pyobject(Xine_PyObject * xine, xine_video_port_t * vo,
int owner)
+ {
+ Xine_Video_Port_PyObject *o = (Xine_Video_Port_PyObject
*)xine_object_to_pyobject_find(vo);
+ if (o) {
+ printf("FOUND EXISTING VIDEO PORT: %x\n", vo);
+ Py_INCREF(o);
+ return o;
+ }
+
+ o = (Xine_Video_Port_PyObject *)
+ Xine_Video_Port_PyObject__new(&Xine_Video_Port_PyObject_Type, NULL,
+ NULL);
+ if (!o)
+ return NULL;
+ printf("REGISTER VO: %x\n", vo);
+ o->vo = vo;
+ o->xine_pyobject = (PyObject *)xine;
+ o->xine = xine->xine;
+ o->xine_object_owner = owner;
+ Py_INCREF(xine);
+ xine_object_to_pyobject_register(vo, (PyObject *)o);
+ return o;
+ }
+
+
+
static int
! Xine_Video_Port_PyObject__clear(Xine_Video_Port_PyObject * self)
{
PyObject *tmp;
+
if (self->xine_pyobject) {
tmp = self->xine_pyobject;
***************
*** 16,24 ****
static int
! Xine_Video_Port_PyObject__traverse(Xine_Video_Port_PyObject *self, visitproc
visit, void *arg)
{
int ret;
if (self->xine_pyobject) {
! ret = visit((PyObject *)self->xine_pyobject, arg);
if (ret != 0)
return ret;
--- 44,54 ----
static int
! Xine_Video_Port_PyObject__traverse(Xine_Video_Port_PyObject * self,
! visitproc visit, void *arg)
{
int ret;
+
if (self->xine_pyobject) {
! ret = visit((PyObject *) self->xine_pyobject, arg);
if (ret != 0)
return ret;
***************
*** 28,32 ****
PyObject *
! Xine_Video_Port_PyObject__new(PyTypeObject *type, PyObject * args, PyObject *
kwargs)
{
Xine_Video_Port_PyObject *self;
--- 58,63 ----
PyObject *
! Xine_Video_Port_PyObject__new(PyTypeObject * type, PyObject * args,
! PyObject * kwargs)
{
Xine_Video_Port_PyObject *self;
***************
*** 37,50 ****
}
! self = (Xine_Video_Port_PyObject *)type->tp_alloc(type, 0);
! self->owns_ref = 0;
self->vo = NULL;
self->xine = NULL;
self->xine_pyobject = NULL;
! return (PyObject *)self;
}
static int
! Xine_Video_Port_PyObject__init(Xine_Video_Port_PyObject *self, PyObject
*args, PyObject *kwds)
{
return 0;
--- 68,83 ----
}
! self = (Xine_Video_Port_PyObject *) type->tp_alloc(type, 0);
self->vo = NULL;
self->xine = NULL;
self->xine_pyobject = NULL;
! self->wrapper = Py_None;
! Py_INCREF(Py_None);
! return (PyObject *) self;
}
static int
! Xine_Video_Port_PyObject__init(Xine_Video_Port_PyObject * self,
! PyObject * args, PyObject * kwds)
{
return 0;
***************
*** 52,55 ****
--- 85,89 ----
static PyMemberDef Xine_Video_Port_PyObject_members[] = {
+ {"wrapper", T_OBJECT_EX, offsetof(Xine_Video_Port_PyObject, wrapper), 0,
"Wrapper object"},
{NULL}
};
***************
*** 57,68 ****
void
! Xine_Video_Port_PyObject__dealloc(Xine_Video_Port_PyObject *self)
{
printf("DEalloc Video Port: %x\n", self->xine);
! if (self->vo && self->owns_ref) {
xine_close_video_driver(self->xine, self->vo);
}
Xine_Video_Port_PyObject__clear(self);
! self->ob_type->tp_free((PyObject*)self);
}
--- 91,104 ----
void
! Xine_Video_Port_PyObject__dealloc(Xine_Video_Port_PyObject * self)
{
printf("DEalloc Video Port: %x\n", self->xine);
! if (self->vo && self->xine_object_owner) {
xine_close_video_driver(self->xine, self->vo);
}
+ Py_DECREF(self->wrapper);
Xine_Video_Port_PyObject__clear(self);
! xine_object_to_pyobject_unregister(self->vo);
! self->ob_type->tp_free((PyObject *) self);
}
***************
*** 75,79 ****
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
! "_xine.XineVideoPort", /* tp_name */
sizeof(Xine_Video_Port_PyObject), /* tp_basicsize */
0, /* tp_itemsize */
--- 111,115 ----
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
! "_xine.VideoPort", /* tp_name */
sizeof(Xine_Video_Port_PyObject), /* tp_basicsize */
0, /* tp_itemsize */
Index: xine.c
===================================================================
RCS file: /cvsroot/freevo/kaa/xine/src/xine.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** xine.c 16 Jul 2005 03:52:43 -0000 1.1
--- xine.c 18 Jul 2005 03:40:21 -0000 1.2
***************
*** 5,10 ****
--- 5,56 ----
#include "audio_port.h"
#include "stream.h"
+ #include "post.h"
+ #include "post/buffer.h"
PyObject *xine_error;
+ // Maps xine object actresses to Xine python objects
+ static PyObject *xine_object_to_pyobject_dict = 0;
+
+
+ ///
+
+ void
+ xine_object_to_pyobject_register(void *ptr, PyObject *o)
+ {
+ PyObject *key = PyLong_FromLong((long)ptr), *val;
+ if (!PyDict_Contains(xine_object_to_pyobject_dict, key)) {
+ val = PyCObject_FromVoidPtr(o, NULL);
+ PyDict_SetItem(xine_object_to_pyobject_dict, key, val);
+ Py_DECREF(val);
+ }
+ Py_DECREF(key);
+ }
+
+ void
+ xine_object_to_pyobject_unregister(void *ptr)
+ {
+ PyObject *key = PyLong_FromLong((long)ptr);
+ if (PyDict_Contains(xine_object_to_pyobject_dict, key)) {
+ PyDict_DelItem(xine_object_to_pyobject_dict, key);
+ }
+ Py_DECREF(key);
+ }
+
+ PyObject *
+ xine_object_to_pyobject_find(void *ptr)
+ {
+ PyObject *key = PyLong_FromLong((long)ptr);
+ PyObject *o = NULL;
+ if (PyDict_Contains(xine_object_to_pyobject_dict, key)) {
+ o = PyDict_GetItem(xine_object_to_pyobject_dict, key);
+ }
+ Py_DECREF(key);
+ if (o)
+ return (PyObject *)PyCObject_AsVoidPtr(o);
+ return NULL;
+ }
+
+ ///
+
static int
***************
*** 38,41 ****
--- 84,89 ----
self = (Xine_PyObject *)type->tp_alloc(type, 0);
self->dependencies = PyList_New(0);
+ self->wrapper = Py_None;
+ Py_INCREF(Py_None);
return (PyObject *)self;
}
***************
*** 59,63 ****
--- 107,113 ----
xine_config_load(xine, cfgfile);
xine_init(xine);
+ xine_register_plugins(xine, xine_buffer_plugin_info);
self->xine = xine;
+ xine_object_to_pyobject_register(xine, (PyObject *)self);
return 0;
}
***************
*** 65,68 ****
--- 115,119 ----
static PyMemberDef Xine_PyObject_members[] = {
{"dependencies", T_OBJECT_EX, offsetof(Xine_PyObject, dependencies), 0,
"Dependencies"},
+ {"wrapper", T_OBJECT_EX, offsetof(Xine_PyObject, wrapper), 0, "Wrapper
object"},
{NULL}
};
***************
*** 76,84 ****
--- 127,164 ----
xine_exit(self->xine);
}
+ Py_DECREF(self->wrapper);
Xine_PyObject__clear(self);
+ xine_object_to_pyobject_unregister(self->xine);
self->ob_type->tp_free((PyObject*)self);
}
+ PyObject *
+ Xine_PyObject_list_plugins(Xine_PyObject *self, PyObject *args, PyObject
*kwargs)
+ {
+ char *type;
+ const char *const *list;
+ PyObject *pylist = NULL;
+ int i;
+
+ if (!PyArg_ParseTuple(args, "s", &type))
+ return NULL;
+ if (!strcmp(type, "video"))
+ list = xine_list_video_output_plugins(self->xine);
+ else if (!strcmp(type, "audio"))
+ list = xine_list_audio_output_plugins(self->xine);
+ else if (!strcmp(type, "post"))
+ list = xine_list_post_plugins(self->xine);
+ else {
+ PyErr_Format(xine_error, "Unknown plugin type: %s", type);
+ return NULL;
+ }
+
+ pylist = PyList_New(0);
+ for (i = 0; list[i] != 0; i++) {
+ PyList_Append(pylist, PyString_FromString(list[i]));
+ }
+ return pylist;
+ }
// XXX Temporary. Obviously. :)
***************
*** 94,98 ****
*dest_height = 480;//height;
*dest_pixel_aspect = 1;
! // printf("frame_output_cb: Video width: %d, heigh: %d, pixel aspect: %f
%x\n", video_width, video_height, video_pixel_aspect, data);
}
--- 174,178 ----
*dest_height = 480;//height;
*dest_pixel_aspect = 1;
! //printf("frame_output_cb: Video width: %d, heigh: %d, pixel aspect: %f
%x\n", video_width, video_height, video_pixel_aspect, data);
}
***************
*** 102,105 ****
--- 182,186 ----
{
char *driver;
+ xine_video_port_t *vo_port = NULL;
if (!PyArg_ParseTuple(args, "s", &driver))
***************
*** 108,114 ****
if (!strcmp(driver, "xv") || !strcmp(driver, "auto")) {
PyObject *window;
- Xine_Video_Port_PyObject *o;
x11_visual_t vis;
- xine_video_port_t *vo_port;
window = PyDict_GetItemString(kwargs, "window");
--- 189,193 ----
***************
*** 118,140 ****
vis.user_data = NULL;
vis.frame_output_cb = frame_output_cb;
!
vo_port = xine_open_video_driver(self->xine, driver,
XINE_VISUAL_TYPE_X11, (void *)&vis);
! if (!vo_port) {
! PyErr_Format(xine_error, "Failed to open driver.");
! return NULL;
! }
! o = (Xine_Video_Port_PyObject
*)Xine_Video_Port_PyObject__new(&Xine_Video_Port_PyObject_Type, NULL, NULL);
! if (!o)
! return NULL;
!
! o->owns_ref = 1;
! o->vo = vo_port;
! o->xine = self->xine;
! o->xine_pyobject = (PyObject *)self;
! Py_INCREF(self);
! return (PyObject *)o;
!
}
! return Py_INCREF(Py_None), Py_None;
}
--- 197,211 ----
vis.user_data = NULL;
vis.frame_output_cb = frame_output_cb;
! vis.user_data = window;
vo_port = xine_open_video_driver(self->xine, driver,
XINE_VISUAL_TYPE_X11, (void *)&vis);
! } else if (!strcmp(driver, "none")) {
! vo_port = xine_open_video_driver(self->xine, driver,
XINE_VISUAL_TYPE_NONE, 0);
}
!
! if (!vo_port) {
! PyErr_Format(xine_error, "Failed to open driver: %s", driver);
! return NULL;
! }
! return (PyObject *)pyxine_new_video_port_pyobject(self, vo_port, 1);
}
***************
*** 156,169 ****
return NULL;
}
- o = (Xine_Audio_Port_PyObject
*)Xine_Audio_Port_PyObject__new(&Xine_Audio_Port_PyObject_Type, NULL, NULL);
- if (!o)
- return NULL;
! o->owns_ref = 1;
! o->ao = ao_port;
! o->xine = self->xine;
! o->xine_pyobject = (PyObject *)self;
! Py_INCREF(self);
! return (PyObject *)o;
}
--- 227,232 ----
return NULL;
}
! return (PyObject *)pyxine_new_audio_port_pyobject(self, ao_port, 1);
}
***************
*** 186,212 ****
return NULL;
}
! o = (Xine_Stream_PyObject
*)Xine_Stream_PyObject__new(&Xine_Stream_PyObject_Type, NULL, NULL);
! if (!o)
return NULL;
! o->stream = stream;
! o->xine = self->xine;
! o->xine_pyobject = (PyObject *)self;
! o->ao_pyobject = ao;
! o->vo_pyobject = vo;
! o->owns_ref = 1;
! Py_INCREF(self);
! Py_INCREF(ao);
! Py_INCREF(vo);
! return (PyObject *)o;
! }
PyMethodDef Xine_PyObject_methods[] = {
{"open_video_driver", (PyCFunction) Xine_PyObject_open_video_driver,
METH_VARARGS | METH_KEYWORDS},
{"open_audio_driver", (PyCFunction) Xine_PyObject_open_audio_driver,
METH_VARARGS | METH_KEYWORDS},
{"stream_new", (PyCFunction) Xine_PyObject_stream_new, METH_VARARGS |
METH_KEYWORDS},
{NULL, NULL}
};
--- 249,309 ----
return NULL;
}
! return (PyObject *)pyxine_new_stream_pyobject(self, stream, ao, vo, 1);
! }
!
! PyObject *
! Xine_PyObject_post_init(Xine_PyObject *self, PyObject *args, PyObject *kwargs)
! {
! char *name;
! int inputs, i;
! PyObject *audio_targets, *video_targets;
! xine_video_port_t **vo;
! xine_audio_port_t **ao;
! xine_post_t *post;
!
! if (!PyArg_ParseTuple(args, "siOO", &name, &inputs, &audio_targets,
! &video_targets))
return NULL;
! ao = (xine_audio_port_t **)malloc((1 + sizeof(xine_audio_port_t *) *
PyList_Size(audio_targets)));
! for (i = 0; i < PyList_Size(audio_targets); i++)
! ao[i] = ((Xine_Audio_Port_PyObject *)PyList_GetItem(audio_targets,
i))->ao;
! ao[i] = NULL;
! vo = (xine_video_port_t **)malloc((1 + sizeof(xine_video_port_t *) *
PyList_Size(video_targets)));
! for (i = 0; i < PyList_Size(video_targets); i++)
! vo[i] = ((Xine_Video_Port_PyObject *)PyList_GetItem(video_targets,
i))->vo;
! vo[i] = NULL;
!
! post = xine_post_init(self->xine, name, inputs, ao, vo);
! free(ao);
! free(vo);
!
! if (!post) {
! PyErr_Format(xine_error, "Failed to initialize post plugin.");
! return NULL;
! }
+ {
+ /*
+ xine_post_in_t *input_api = (xine_post_in_t *) xine_post_input(post,
"parameters");
+ xine_post_api_t *api = (xine_post_api_t *)input_api->data;
+ int data = 142;
+ api->set_parameters(post, &data);
+ printf("POST API: %x\n", input_api);
+ */
+ }
+
+ return (PyObject *)pyxine_new_post_pyobject(self, post, audio_targets,
video_targets, 1);
+
+ }
PyMethodDef Xine_PyObject_methods[] = {
+ {"list_plugins", (PyCFunction) Xine_PyObject_list_plugins, METH_VARARGS |
METH_KEYWORDS},
{"open_video_driver", (PyCFunction) Xine_PyObject_open_video_driver,
METH_VARARGS | METH_KEYWORDS},
{"open_audio_driver", (PyCFunction) Xine_PyObject_open_audio_driver,
METH_VARARGS | METH_KEYWORDS},
{"stream_new", (PyCFunction) Xine_PyObject_stream_new, METH_VARARGS |
METH_KEYWORDS},
+ {"post_init", (PyCFunction) Xine_PyObject_post_init, METH_VARARGS |
METH_KEYWORDS},
{NULL, NULL}
};
***************
*** 316,319 ****
--- 413,424 ----
PyModule_AddObject(m, "Stream", (PyObject *)&Xine_Stream_PyObject_Type);
+ if (PyType_Ready(&Xine_Post_PyObject_Type) < 0)
+ return;
+ Py_INCREF(&Xine_Post_PyObject_Type);
+ PyModule_AddObject(m, "Post", (PyObject *)&Xine_Post_PyObject_Type);
+
+ if (xine_object_to_pyobject_dict == NULL)
+ xine_object_to_pyobject_dict = PyDict_New();
+
#if 1
display_api_ptrs = get_module_api("kaa.display._Display");
-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog