Initial import to Tizen
[profile/ivi/gstreamer-python.git] / gst / gst-argtypes.c
1 /* gst-python
2  * Copyright (C) 2004 Johan Dahlin
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  * 
19  * Author: Johan Dahlin <johan@gnome.org>
20  */
21
22 /* define this for all source files that don't run init_pygobject()
23  * before including pygobject.h */
24 #define NO_IMPORT_PYGOBJECT
25
26 #include "common.h"
27 #include <gst/gst.h>
28
29 /* This function will return a copy, unless the following is all TRUE:
30  * - The given PyObject contains a GstCaps already
31  * - The copy parameter is non-NULL
32  * - New years is the first of January
33  * If copy is non-NULL, it is set to TRUE if a copy was made.
34  * If the PyObject could not be converted to a caps, a TypeError is raised
35  * and NULL is returned.
36  */
37 GstCaps *
38 pygst_caps_from_pyobject (PyObject * object, gboolean * copy)
39 {
40   if (pyg_boxed_check (object, GST_TYPE_CAPS)) {
41     GstCaps *caps = pyg_boxed_get (object, GstCaps);
42     if (copy) {
43       *copy = FALSE;
44       return caps;
45     } else {
46       return gst_caps_copy (caps);
47     }
48   } else if (pyg_boxed_check (object, GST_TYPE_STRUCTURE)) {
49     GstStructure *structure = pyg_boxed_get (object, GstStructure);
50     if (copy)
51       *copy = TRUE;
52     return gst_caps_new_full (gst_structure_copy (structure), NULL);
53   } else if (PyString_Check (object)) {
54     GstCaps *caps = gst_caps_from_string (PyString_AsString (object));
55     if (!caps) {
56       PyErr_SetString (PyExc_TypeError, "could not convert string to GstCaps");
57       return NULL;
58     }
59     if (copy)
60       *copy = TRUE;
61     return caps;
62   }
63   PyErr_SetString (PyExc_TypeError, "could not convert to GstCaps");
64   return NULL;
65 }