Show
Ignore:
Timestamp:
08/10/07 02:53:30 (17 months ago)
Author:
liori
Message:

Jingle: bindings for farsight, more functions wrapped

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/jingle/src/common/farsight/farsight.override

    r8473 r8485  
    33#include <Python.h> 
    44#include "pygobject.h" 
    5 #include "farsight.h" 
     5#include <gst/gstelement.h> 
     6#include <farsight/farsight.h> 
     7#include <farsight/farsight-transport.h> 
     8 
     9#define GetString(name) PyString_AsString(PyMapping_GetItemString(item, name)) 
     10#define GetLong(name)   PyInt_AsLong(PyMapping_GetItemString(item, name)) 
     11#define GetFloat(name)  PyFloat_AsDouble(PyMapping_GetItemString(item, name)) 
    612%% 
    713modulename farsight 
     
    3541        return ret; 
    3642} 
     43%% 
     44override farsight_stream_get_local_codecs noargs 
     45static PyObject* _wrap_farsight_stream_get_local_codecs(PyGObject *self) 
     46{ 
     47        const GList *list, *tmp; 
     48        PyObject* ret; 
     49 
     50        list=farsight_stream_get_local_codecs(FARSIGHT_STREAM(self->obj)); 
     51 
     52        ret=PyList_New(0); 
     53        for (tmp=list; tmp!=NULL; tmp=g_list_next(tmp)) { 
     54                FarsightCodec *codec = tmp->data; 
     55                PyObject *item = pygobject_new((GObject *) codec); 
     56 
     57                PyList_Append(ret, item); 
     58                Py_DECREF(item); 
     59        } 
     60        // g_list_free(list); (a const list, we don't free it?) 
     61        return ret; 
     62} 
     63%% 
     64override farsight_stream_get_native_candidate_list noargs 
     65static PyObject* _wrap_farsight_stream_get_native_candidate_list(PyGObject *self) 
     66{ 
     67        const GList *list, *tmp; 
     68        PyObject* ret; 
     69 
     70        list=farsight_stream_get_native_candidate_list(FARSIGHT_STREAM(self->obj)); 
     71 
     72        ret=PyList_New(0); 
     73        for (tmp=list; tmp!=NULL; tmp=g_list_next(tmp)) { 
     74                FarsightCodec *codec = tmp->data; 
     75                PyObject *item = pygobject_new((GObject *) codec); 
     76 
     77                PyList_Append(ret, item); 
     78                Py_DECREF(item); 
     79        } 
     80        // g_list_free(list); (a const list, we don't free it?) 
     81        return ret; 
     82} 
     83%% 
     84override farsight_stream_set_codec_preference_list kwargs 
     85static PyObject* _wrap_farsight_stream_set_codec_preference_list(PyGObject *self, 
     86                                                                 PyObject *args, 
     87                                                                 PyObject *kwargs) 
     88{ 
     89        /* one could try to unpack tuples right into the array */ 
     90        static char *kwlist[] = {"codec_pref", NULL}; 
     91        PyObject* list; 
     92        GArray* codec_pref_array; 
     93        FarsightCodecPreference codec_pref; 
     94        int i; 
     95 
     96        if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O", kwlist, &list)) 
     97                return NULL; 
     98         
     99        codec_pref_array = g_array_sized_new(FALSE, FALSE, 
     100                sizeof(FarsightCodecPreference), PySequence_Size(list)); 
     101 
     102        for(i=0; i<PySequence_Size(list); i++) { 
     103                PyArg_ParseTuple(PySequence_GetItem(list, i), "si", 
     104                        &codec_pref.encoding_name, 
     105                        &codec_pref.clock_rate); 
     106                g_array_append_val(codec_pref_array, codec_pref); 
     107        } 
     108 
     109        farsight_stream_set_codec_preference_list(FARSIGHT_STREAM(self->obj), 
     110                (const GArray*) codec_pref_array); 
     111 
     112        g_array_free(codec_pref_array, FALSE); 
     113 
     114        Py_INCREF(Py_None); 
     115        return Py_None; 
     116} 
     117%% 
     118override farsight_stream_set_remote_candidate_list kwargs 
     119static PyObject* _wrap_farsight_stream_set_remote_candidate_list(PyGObject *self, 
     120                                                                 PyObject *args, 
     121                                                                 PyObject *kwargs) 
     122{ 
     123        static char* kwlist[] = {"remote_candidates", NULL}; 
     124        PyObject* list; 
     125        GArray* candidate_array; 
     126        GList* candidate_list=NULL; 
     127        int i, listsize; 
     128 
     129        if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O", kwlist, &list)) 
     130                return NULL; 
     131 
     132        candidate_array=g_array_sized_new(FALSE, TRUE, 
     133                sizeof(FarsightTransportInfo), PySequence_Size(list)); 
     134 
     135        listsize=PySequence_Size(list); 
     136        for(i=0;i<listsize;i++) { 
     137                FarsightTransportInfo fti; 
     138                PyObject* item = PySequence_GetItem(list, listsize-i-1); 
     139 
     140                fti.candidate_id=GetString("candidate_id"); 
     141                fti.component=GetLong("component"); 
     142                fti.ip=GetString("ip"); 
     143                fti.port=GetLong("port"); 
     144                fti.proto=GetLong("proto"); 
     145                fti.proto_subtype=GetString("proto_subtype"); 
     146                fti.proto_profile=GetString("proto_profile"); 
     147                fti.preference=GetFloat("preference"); 
     148                fti.type=GetLong("type"); 
     149                fti.username=GetString("username"); 
     150                fti.password=GetString("password"); 
     151 
     152                g_array_append_val(candidate_array, fti); 
     153                candidate_list = g_list_prepend(candidate_list, 
     154                        &g_array_index(candidate_array, FarsightTransportInfo, i)); 
     155        } 
     156 
     157        farsight_stream_set_remote_candidate_list(FARSIGHT_STREAM(self->obj), candidate_list); 
     158 
     159        g_array_free(candidate_array, FALSE); 
     160        g_list_free(candidate_list); 
     161 
     162        Py_INCREF(Py_None); 
     163        return Py_None; 
     164} 
     165%% 
     166override farsight_stream_set_remote_codecs kwargs 
     167static PyObject* _wrap_farsight_stream_set_remote_codecs(PyGObject *self, 
     168                                                         PyObject *args, 
     169                                                         PyObject *kwargs) 
     170{ 
     171        static char* kwlist[] = {"codecs", NULL}; 
     172        PyObject* list, * item; 
     173        GArray* codecs_array; 
     174        GList* codecs_list; 
     175        int i, listsize; 
     176 
     177        if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O", kwlist, &list)) 
     178                return NULL; 
     179 
     180        codecs_array=g_array_sized_new(FALSE, TRUE, 
     181                sizeof(FarsightCodec), PySequence_Size(list)); 
     182 
     183        listsize=PySequence_Size(list); 
     184        for(i=0;i<listsize;i++) { 
     185                FarsightCodec fc; 
     186                PyObject* item = PySequence_GetItem(list, listsize-i-1); 
     187 
     188                fc.id = GetLong("id"); 
     189                fc.encoding_name = GetString("encoding_name"); 
     190                fc.media_type = GetLong("media_type"); 
     191                fc.clock_rate = GetLong("clock_rate"); 
     192                fc.channels = GetLong("channels"); 
     193 
     194                g_array_append_val(codecs_array, fc); 
     195                codecs_list = g_list_prepend(codecs_list, 
     196                        &g_array_index(codecs_array, FarsightCodec, i)); 
     197        } 
     198 
     199        farsight_stream_set_remote_codecs(FARSIGHT_STREAM(self->obj), codecs_list); 
     200 
     201        g_array_free(codecs_array, FALSE); 
     202        g_list_free(codecs_list); 
     203 
     204        Py_INCREF(Py_None); 
     205        return Py_None; 
     206}