gstreamer/gst/gstelement.override

638 lines
17 KiB
Text
Raw Normal View History

/* -*- Mode: C; c-basic-offset: 8 -*- */
/* gst-python
* Copyright (C) 2005 Johan Dahlin
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* Author: Johan Dahlin <johan@gnome.org>
*/
%%
ignore
gst_element_get
gst_element_set
gst_element_get_property
gst_element_set_property
%%
override gst_element_get_pad_template args
static PyObject *
_wrap_gst_element_get_pad_template(PyGObject *self, PyObject *args)
{
PyObject *ret;
gchar *name;
GstPadTemplate *tmpl;
if (!PyArg_ParseTuple(args, "s:GstElement.get_pad_template", &name))
return NULL;
pyg_begin_allow_threads;
tmpl = gst_element_class_get_pad_template
(GST_ELEMENT_GET_CLASS (self->obj), name);
pyg_end_allow_threads;
if (tmpl) {
ret = pygobject_new (G_OBJECT (tmpl));
} else {
ret = Py_None;
Py_INCREF (ret);
}
return ret;
}
%%
override gst_element_set_state kwargs
static PyObject *
_wrap_gst_element_set_state(PyGObject *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = { "state", NULL };
PyObject *py_state = NULL;
GstState state;
gint ret;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:GstElement.set_state", kwlist, &py_state))
return NULL;
if (pyg_enum_get_value(GST_TYPE_STATE, py_state, (gint *)&state))
return NULL;
pyg_begin_allow_threads;
ret = gst_element_set_state(GST_ELEMENT(self->obj), state);
pyg_end_allow_threads;
return pyg_enum_from_gtype(GST_TYPE_STATE_CHANGE_RETURN, ret);
}
%%
override gst_element_get_state kwargs
static PyObject *
_wrap_gst_element_get_state(PyGObject *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = { "timeout", NULL };
GstState state;
GstState pending;
GstStateChangeReturn ret;
GstClockTime timeout = GST_CLOCK_TIME_NONE;
PyObject *tuple;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"|K:GstElement.get_state", kwlist,
&timeout)) {
PyErr_SetString(PyExc_RuntimeError, "Timeout not specified correctly");
return NULL;
}
pyg_begin_allow_threads;
ret = gst_element_get_state(GST_ELEMENT (self->obj), &state, &pending,
timeout);
pyg_end_allow_threads;
tuple = Py_BuildValue("(OOO)",
pyg_enum_from_gtype (GST_TYPE_STATE_CHANGE_RETURN, ret),
pyg_enum_from_gtype (GST_TYPE_STATE, state),
pyg_enum_from_gtype (GST_TYPE_STATE, pending));
return tuple;
}
%%
override gst_element_link_many args
static PyObject *
_wrap_gst_element_link_many(PyObject *self, PyObject *args)
{
PyGObject *element, *element2;
int i, len;
len = PyTuple_Size(args);
if (len < 2)
{
PyErr_SetString(PyExc_TypeError, "gst.element_link_many requires at least two argument");
return NULL;
}
for (i = 0; i < len; i++)
{
element = (PyGObject*)PyTuple_GetItem(args, i);
if (!pygobject_check(element, &PyGstElement_Type))
{
PyErr_SetString(PyExc_TypeError, "argument must be a GstElement");
return NULL;
}
}
/* Mimic the real gst_element_link_many */
element = (PyGObject*)PyTuple_GetItem(args, 0);
element2 = (PyGObject*)PyTuple_GetItem(args, 1);
i = 2;
while (1) {
gboolean res;
pyg_begin_allow_threads;
res = gst_element_link(GST_ELEMENT(element->obj),
GST_ELEMENT(element2->obj));
pyg_end_allow_threads;
if (!res)
{
PyErr_Format(PyGstExc_LinkError,
"failed to link %s with %s",
GST_ELEMENT_NAME(element->obj),
GST_ELEMENT_NAME(element2->obj));
return NULL;
}
if (i >= len)
break;
element = element2;
element2 = (PyGObject*)PyTuple_GetItem(args, i);
i++;
}
Py_INCREF(Py_True);
return Py_True;
}
%%
override gst_element_link kwargs
static PyObject *
_wrap_gst_element_link(PyGObject *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = { "dest", "filtercaps", NULL };
PyGObject *dest;
PyObject *py_caps = NULL;
int ret;
GstCaps *caps = NULL;
gboolean caps_is_copy;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!|O:GstElement.link",
kwlist, &PyGstElement_Type, &dest, &py_caps))
return NULL;
if (py_caps == NULL)
caps = NULL;
else {
caps = pygst_caps_from_pyobject (py_caps, &caps_is_copy);
if (caps == NULL)
/* an error happened, propagate up */
return NULL;
}
pyg_begin_allow_threads;
ret = gst_element_link_filtered(GST_ELEMENT(self->obj), GST_ELEMENT(dest->obj), caps);
pyg_end_allow_threads;
if (caps && caps_is_copy)
gst_caps_unref (caps);
if (!ret) {
PyErr_Format(PyGstExc_LinkError,
"failed to link %s with %s",
GST_ELEMENT_NAME(self->obj),
GST_ELEMENT_NAME(dest->obj));
return NULL;
}
return PyBool_FromLong(ret);
}
%%
override gst_element_link_filtered kwargs
static PyObject *
_wrap_gst_element_link_filtered(PyGObject *self, PyObject *args,
PyObject *kwargs)
{
if (PyErr_Warn(PyExc_DeprecationWarning, "element.link_filtered is deprecated, use element.link") < 0)
return NULL;
return _wrap_gst_element_link (self, args, kwargs);
}
%%
override gst_element_link_pads kwargs
static gboolean
pad_name_from_object (PyObject *object, const gchar **name)
{
if (object == Py_None) {
*name = NULL;
return TRUE;
} else if (PyString_Check (object)) {
*name = PyString_AsString (object);
return TRUE;
} else if (pygobject_check (object, &PyGstPad_Type)) {
GstObject *obj = GST_OBJECT (pygobject_get (object));
pyg_begin_allow_threads;
*name = gst_object_get_name (obj);
pyg_end_allow_threads;
return TRUE;
}
PyErr_SetString(PyExc_TypeError, "argument could not be converted to a pad");
return FALSE;
}
static PyObject *
_wrap_gst_element_link_pads(PyGObject *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = { "srcpadname", "dest", "destpadname", NULL };
const char *srcpadname, *destpadname;
PyGObject *dest;
PyObject *srcpad, *destpad;
int ret;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"OO!O:GstElement.link_pads", kwlist,
&srcpad, &PyGstElement_Type, &dest,
&destpad))
return NULL;
if (!pad_name_from_object (srcpad, &srcpadname) ||
!pad_name_from_object (destpad, &destpadname))
return NULL;
pyg_begin_allow_threads;
ret = gst_element_link_pads(GST_ELEMENT(self->obj), srcpadname,
GST_ELEMENT(dest->obj), destpadname);
pyg_end_allow_threads;
if (!ret) {
PyErr_SetString(PyGstExc_LinkError, "link failed");
return NULL;
}
return PyBool_FromLong(ret);
}
%%
override gst_element_link_pads_filtered kwargs
static PyObject *
_wrap_gst_element_link_pads_filtered(PyGObject *self, PyObject *args,
PyObject *kwargs)
{
static char *kwlist[] = { "srcpadname", "dest", "destpadname",
"filtercaps", NULL };
char *srcpadname, *destpadname;
PyGObject *dest;
int ret;
PyObject *py_filtercaps;
GstCaps *filtercaps = NULL;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"sO!sO:GstElement.link_pads_filtered",
kwlist, &srcpadname, &PyGstElement_Type,
&dest, &destpadname, &py_filtercaps))
return NULL;
if (pyg_boxed_check(py_filtercaps, GST_TYPE_CAPS))
filtercaps = pyg_boxed_get(py_filtercaps, GstCaps);
else {
PyErr_SetString(PyExc_TypeError, "filtercaps should be a GstCaps");
return NULL;
}
pyg_begin_allow_threads;
ret = gst_element_link_pads_filtered(GST_ELEMENT(self->obj), srcpadname,
GST_ELEMENT(dest->obj), destpadname,
filtercaps);
pyg_end_allow_threads;
if (!ret) {
PyErr_SetString(PyGstExc_LinkError, "link failed");
return NULL;
}
return PyBool_FromLong(ret);
}
%%
override gst_element_unlink_many args
static PyObject *
_wrap_gst_element_unlink_many(PyObject *self, PyObject *args)
{
PyGObject *element, *element2;
int i, len;
len = PyTuple_Size(args);
if (len < 2)
{
PyErr_SetString(PyExc_TypeError, "gst.element_unlink_many requires at least two arguments");
return NULL;
}
for (i = 0; i < len; i++)
{
element = (PyGObject*)PyTuple_GetItem(args, i);
if (!pygobject_check(element, &PyGstElement_Type))
{
PyErr_SetString(PyExc_TypeError, "argument must be a GstElement");
return NULL;
}
}
/* Mimic the real gst_element_unlink_many */
element = (PyGObject*)PyTuple_GetItem(args, 0);
element2 = (PyGObject*)PyTuple_GetItem(args, 1);
i = 2;
while (1) {
pyg_begin_allow_threads;
gst_element_unlink(GST_ELEMENT(element->obj), GST_ELEMENT(element2->obj));
pyg_end_allow_threads;
if (i >= len)
break;
element = element2;
element2 = (PyGObject*)PyTuple_GetItem(args, i);
i++;
}
Py_INCREF(Py_None);
return Py_None;
}
%%
override gst_element_send_event kwargs
static PyObject *
_wrap_gst_element_send_event(PyGObject *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = { "event", NULL };
PyObject *py_event;
int ret;
GstEvent *event = NULL;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:GstElement.send_event", kwlist, &py_event))
return NULL;
if (pygstminiobject_check (py_event, &PyGstEvent_Type)) {
event = GST_EVENT (pygstminiobject_get (py_event));
} else {
PyErr_SetString(PyExc_TypeError, "event should be a GstEvent");
return NULL;
}
/* The pipeline unrefs the event, but we want to keep the ownership */
gst_event_ref(event);
pyg_begin_allow_threads;
ret = gst_element_send_event(GST_ELEMENT(self->obj), event);
pyg_end_allow_threads;
return PyBool_FromLong(ret);
}
%%
override gst_element_query_position args
static PyObject *
_wrap_gst_element_query_position (PyGObject *self, PyObject *args)
{
gint64 cur;
gint format;
PyObject *pformat;
gboolean res;
pformat = (PyObject*)PyTuple_GetItem(args, 0);
if (pyg_enum_get_value (GST_TYPE_FORMAT, pformat, &format)) {
PyErr_SetString(PyExc_TypeError, "argument should be a GstFormat");
return NULL;
}
pyg_begin_allow_threads;
res = gst_element_query_position(GST_ELEMENT (self->obj), (GstFormat*) &format, &cur);
pyg_end_allow_threads;
if (!res) {
PyErr_Format(PyGstExc_QueryError,
"query failed");
return NULL;
2005-07-12 09:45:58 +00:00
}
return Py_BuildValue("(LO)", cur,
pyg_enum_from_gtype(GST_TYPE_FORMAT, format));
}
%%
override gst_element_query_duration args
static PyObject *
_wrap_gst_element_query_duration (PyGObject *self, PyObject *args)
{
gint64 cur;
gint format;
PyObject *pformat;
gboolean res;
pformat = (PyObject*)PyTuple_GetItem(args, 0);
if (pyg_enum_get_value (GST_TYPE_FORMAT, pformat, &format)) {
PyErr_SetString(PyExc_TypeError, "argument should be a GstFormat");
return NULL;
}
pyg_begin_allow_threads;
res = gst_element_query_duration(GST_ELEMENT (self->obj), (GstFormat*) &format, &cur);
pyg_end_allow_threads;
if (!res) {
PyErr_Format(PyGstExc_QueryError,
"query failed");
return NULL;
}
return Py_BuildValue("(LO)", cur,
pyg_enum_from_gtype(GST_TYPE_FORMAT, format));
2005-07-12 09:45:58 +00:00
}
%%
override gst_element_query_convert kwargs
static PyObject *
_wrap_gst_element_query_convert (PyGObject *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = { "fromformat", "fromvalue", "destformat", NULL };
PyObject *pfromformat, *pdestformat;
GstFormat srcformat, destformat;
gint64 fromval, dstval;
gboolean res;
2005-07-12 09:45:58 +00:00
/* Input : src_format, src_val, dst_format */
/* Returns : dst_format, dst_val OR None */
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"OLO:GstElement.query_convert",
2005-07-12 09:45:58 +00:00
kwlist, &pfromformat, &fromval, &pdestformat))
return NULL;
2005-07-12 09:45:58 +00:00
if (pyg_enum_get_value(GST_TYPE_FORMAT, pfromformat, (gint *) &srcformat)) {
PyErr_SetString(PyExc_TypeError, "argument should be a GstFormat");
return NULL;
}
if (pyg_enum_get_value(GST_TYPE_FORMAT, pdestformat, (gint *) &destformat)) {
PyErr_SetString(PyExc_TypeError, "argument should be a GstFormat");
return NULL;
}
pyg_begin_allow_threads;
res = gst_element_query_convert (GST_ELEMENT(self->obj),
2005-07-12 09:45:58 +00:00
srcformat, fromval,
&destformat, &dstval);
pyg_end_allow_threads;
if (!res) {
2005-07-12 09:45:58 +00:00
Py_INCREF(Py_None);
return Py_None;
}
return Py_BuildValue("(OL)",
pyg_enum_from_gtype(GST_TYPE_FORMAT, destformat),
dstval);
}
2005-07-12 09:45:58 +00:00
%%
override gst_element_get_query_types noargs
static PyObject *
_wrap_gst_element_get_query_types (PyGObject *self)
{
PyObject *ret;
PyObject *item;
int i;
GstQueryType *tab;
pyg_begin_allow_threads;
2005-07-12 09:45:58 +00:00
tab = (GstQueryType*) gst_element_get_query_types(GST_ELEMENT(self->obj));
pyg_end_allow_threads;
2005-07-12 09:45:58 +00:00
if (tab == NULL) {
Py_INCREF(Py_None);
return Py_None;
}
ret = PyList_New(0);
for (i = 0; tab[i] != 0; i++) {
item = pyg_enum_from_gtype (GST_TYPE_QUERY_TYPE, tab[i]);
PyList_Append(ret, item);
}
return ret;
}
%%
override-slot GstElement.tp_iter
static PyObject *
_wrap_gst_element_tp_iter(PyGObject *self)
{
return _wrap_gst_element_iterate_pads(self);
}
%%
override gst_element_get_pad_template_list noargs
static PyObject *
_wrap_gst_element_get_pad_template_list(PyGObject *self)
{
PyObject *ret;
GList *res = NULL;
guint i;
pyg_begin_allow_threads;
res = gst_element_class_get_pad_template_list
(GST_ELEMENT_GET_CLASS (self->obj));
pyg_end_allow_threads;
if (res) {
i = g_list_length (res);
ret = PyList_New (i);
for (i = 0 ; res ; res = g_list_next (res), i++) {
GstPadTemplate * tmpl = (GstPadTemplate *) res->data;
PyList_SetItem (ret, i, pygobject_new (G_OBJECT (tmpl)));
}
} else {
ret = Py_None;
Py_INCREF (ret);
}
return ret;
}
%%
override GstElement__proxy_do_request_new_pad
static GstPad*
_wrap_GstElement__proxy_do_request_new_pad(GstElement *self, GstPadTemplate*templ, const gchar*name)
{
PyGILState_STATE __py_state;
PyObject *py_self;
PyObject *py_templ = NULL;
PyObject *py_name;
GstPad* retval;
PyObject *py_retval;
PyObject *py_args;
PyObject *py_method;
__py_state = pyg_gil_state_ensure();
py_self = pygobject_new((GObject *) self);
if (!py_self) {
if (PyErr_Occurred())
PyErr_Print();
pyg_gil_state_release(__py_state);
return NULL;
}
if (templ)
py_templ = pygobject_new((GObject *) templ);
else {
Py_INCREF(Py_None);
py_templ = Py_None;
}
if (name == NULL) {
Py_INCREF(Py_None);
py_name = Py_None;
} else {
py_name = PyString_FromString(name);
if (!py_name) {
if (PyErr_Occurred())
PyErr_Print();
Py_DECREF(py_templ);
Py_DECREF(py_self);
pyg_gil_state_release(__py_state);
return NULL;
}
}
py_args = PyTuple_New(2);
PyTuple_SET_ITEM(py_args, 0, py_templ);
PyTuple_SET_ITEM(py_args, 1, py_name);
py_method = PyObject_GetAttrString(py_self, "do_request_new_pad");
if (!py_method) {
if (PyErr_Occurred())
PyErr_Print();
Py_DECREF(py_args);
Py_DECREF(py_self);
pyg_gil_state_release(__py_state);
return NULL;
}
py_retval = PyObject_CallObject(py_method, py_args);
if (!py_retval) {
if (PyErr_Occurred())
PyErr_Print();
Py_DECREF(py_method);
Py_DECREF(py_args);
Py_DECREF(py_self);
pyg_gil_state_release(__py_state);
return NULL;
}
if (!PyObject_TypeCheck(py_retval, &PyGObject_Type)) {
PyErr_SetString(PyExc_TypeError, "retval should be a GObject");
PyErr_Print();
Py_DECREF(py_retval);
Py_DECREF(py_method);
Py_DECREF(py_args);
Py_DECREF(py_self);
pyg_gil_state_release(__py_state);
return NULL;
}
retval = (GstPad*) pygobject_get(py_retval);
g_object_ref((GObject *) retval);
Py_DECREF(py_retval);
Py_DECREF(py_method);
Py_DECREF(py_args);
Py_DECREF(py_self);
pyg_gil_state_release(__py_state);
return retval;
}