gstelement.override 13.6 KB
Newer Older
Andy Wingo Wingo's avatar
Andy Wingo Wingo committed
1
/* -*- Mode: C; c-basic-offset: 8 -*- */
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
/* 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
%%
Andy Wingo Wingo's avatar
Andy Wingo Wingo committed
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
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;

        tmpl = gst_element_class_get_pad_template
            (GST_ELEMENT_GET_CLASS (self->obj), name);

        if (tmpl) {
44
                ret = pygstobject_new (G_OBJECT (tmpl));
Andy Wingo Wingo's avatar
Andy Wingo Wingo committed
45 46 47 48 49 50 51 52
        } else {
                ret = Py_None;
                Py_INCREF (ret);
        }

        return ret;
}
%%
53 54 55 56 57 58
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;
59
	GstState state;
60 61 62 63
	gint ret;

	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:GstElement.set_state", kwlist, &py_state))
		return NULL;
64
	if (pyg_enum_get_value(GST_TYPE_STATE, py_state, (gint *)&state))
65 66 67 68 69 70 71 72
		return NULL;

	pyg_begin_allow_threads;
    
	ret = gst_element_set_state(GST_ELEMENT(self->obj), state);
    
	pyg_end_allow_threads;

73
	return pyg_enum_from_gtype(GST_TYPE_STATE_CHANGE_RETURN, ret);
74 75
}
%%
76 77 78 79
override gst_element_get_state kwargs
static PyObject *
_wrap_gst_element_get_state(PyGObject *self, PyObject *args, PyObject *kwargs)
{
80
    static char *kwlist[] = { "timeout", NULL };
81
    GstState state;
82 83
    GstState pending;
    GstStateChangeReturn ret;
Edward Hervey's avatar
Edward Hervey committed
84
    GstClockTime timeout = GST_CLOCK_TIME_NONE;
85
    PyObject *tuple;
86

87
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
Edward Hervey's avatar
Edward Hervey committed
88
                                     "|K:GstElement.get_state", kwlist,
89 90 91
                                     &timeout)) {
	PyErr_SetString(PyExc_RuntimeError, "Timeout not specified correctly");
        return NULL;
92
    }
93

94 95
    pyg_begin_allow_threads;

96
    ret = gst_element_get_state(GST_ELEMENT (self->obj), &state, &pending,
Edward Hervey's avatar
Edward Hervey committed
97
        timeout);
98

99 100
    pyg_end_allow_threads;

101 102 103 104 105 106
    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;
107 108
}
%%
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
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) {

		if (!gst_element_link(GST_ELEMENT(element->obj),
                                      GST_ELEMENT(element2->obj)))
                {
                    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;
}


Edward Hervey's avatar
Edward Hervey committed
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
%%
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);
    ret = gst_element_link_filtered(GST_ELEMENT(self->obj), GST_ELEMENT(dest->obj), caps);
    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);
}
207 208 209

%%
override gst_element_link_pads kwargs
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
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)) {
    *name = gst_object_get_name (GST_OBJECT (pygobject_get (object)));
    return TRUE;
  }
  PyErr_SetString(PyExc_TypeError, "argument could not be converted to a pad");
  return FALSE;
}

227 228 229 230
static PyObject *
_wrap_gst_element_link_pads(PyGObject *self, PyObject *args, PyObject *kwargs)
{
    static char *kwlist[] = { "srcpadname", "dest", "destpadname", NULL };
231
    const char *srcpadname, *destpadname;
232
    PyGObject *dest;
233
    PyObject *srcpad, *destpad;
234 235 236
    int ret;

    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
237 238 239
                                     "OO!O:GstElement.link_pads", kwlist,
                                     &srcpad, &PyGstElement_Type, &dest,
                                     &destpad))
240
        return NULL;
241 242 243
    if (!pad_name_from_object (srcpad, &srcpadname) ||
        !pad_name_from_object (destpad, &destpadname))
	return NULL;
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
    ret = gst_element_link_pads(GST_ELEMENT(self->obj), srcpadname,
                                GST_ELEMENT(dest->obj), destpadname);
    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;
    }
    ret = gst_element_link_pads_filtered(GST_ELEMENT(self->obj), srcpadname,
                                         GST_ELEMENT(dest->obj), destpadname,
                                         filtercaps);
    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) {
		gst_element_unlink(GST_ELEMENT(element->obj), GST_ELEMENT(element2->obj));

		if (i >= len)
			break;
		
		element = element2;
		element2 = (PyGObject*)PyTuple_GetItem(args, i);
	
		i++;
	}
	Py_INCREF(Py_None);
	return Py_None;
}
Edward Hervey's avatar
Edward Hervey committed
334 335 336 337 338 339 340 341 342 343 344 345
%%
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;
346 347 348
    if (pygstminiobject_check (py_event, &PyGstEvent_Type)) {
        event = GST_EVENT (pygstminiobject_get (py_event));
    } else {
Edward Hervey's avatar
Edward Hervey committed
349 350 351 352 353 354
        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);
355
    
Edward Hervey's avatar
Edward Hervey committed
356 357
    ret = gst_element_send_event(GST_ELEMENT(self->obj), event);
    return PyBool_FromLong(ret);
358

Edward Hervey's avatar
Edward Hervey committed
359
}
360 361 362 363 364
%%
override gst_element_query_position args
static PyObject *
_wrap_gst_element_query_position (PyGObject *self, PyObject *args)
{
365
    gint64	cur;
366 367 368 369 370 371 372 373 374 375
    gint	format;
    PyObject	*pformat;
    PyObject	*ret;

    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;
    }

376 377 378 379
    if (!(gst_element_query_position(GST_ELEMENT (self->obj), (GstFormat*) &format, &cur))) {
	PyErr_Format(PyGstExc_QueryError,
		     "query failed");
        return NULL;
Edward Hervey's avatar
Edward Hervey committed
380 381
    }

382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412
    ret = PyList_New(2);
    PyList_SetItem(ret, 0, PyLong_FromLongLong(cur));
    PyList_SetItem(ret, 1, pyg_enum_from_gtype (GST_TYPE_FORMAT, format ));

    return ret;
}
%%
override gst_element_query_duration args
static PyObject *
_wrap_gst_element_query_duration (PyGObject *self, PyObject *args)
{
    gint64	cur;
    gint	format;
    PyObject	*pformat;
    PyObject	*ret;

    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;
    }

    if (!(gst_element_query_duration(GST_ELEMENT (self->obj), (GstFormat*) &format, &cur))) {
	PyErr_Format(PyGstExc_QueryError,
		     "query failed");
        return NULL;
    }

    ret = PyList_New(2);
    PyList_SetItem(ret, 0, PyLong_FromLongLong(cur));
    PyList_SetItem(ret, 1, pyg_enum_from_gtype (GST_TYPE_FORMAT, format ));
413

Edward Hervey's avatar
Edward Hervey committed
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430
    return ret;
}
%%
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;
    PyObject	*ret;

    /* Input : src_format, src_val, dst_format */
    /* Returns : dst_format, dst_val OR None */

    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
431
				     "OLO:GstElement.query_convert",
Edward Hervey's avatar
Edward Hervey committed
432 433
				     kwlist, &pfromformat, &fromval, &pdestformat))
	return NULL;
434

Edward Hervey's avatar
Edward Hervey committed
435 436 437 438 439 440 441 442 443 444 445 446 447 448
    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;
    }

    if (!(gst_element_query_convert (GST_ELEMENT(self->obj),
				     srcformat, fromval,
				     &destformat, &dstval))) {
	Py_INCREF(Py_None);
	return Py_None;
449
    }
Edward Hervey's avatar
Edward Hervey committed
450
    
451 452 453
    ret = PyList_New(2);
    PyList_SetItem(ret, 0, pyg_enum_from_gtype (GST_TYPE_FORMAT, destformat));
    PyList_SetItem(ret, 1, PyLong_FromLongLong(dstval));
454 455 456

    return ret;
}
Edward Hervey's avatar
Edward Hervey committed
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480
%%
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;

    tab = (GstQueryType*) gst_element_get_query_types(GST_ELEMENT(self->obj));
    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;
}
481 482 483 484 485 486 487
%%
override-slot GstElement.tp_iter
static PyObject *
_wrap_gst_element_tp_iter(PyGObject *self)
{
    return _wrap_gst_element_iterate_pads(self);
}