Jingle: still farsight -- first test program in python work

This commit is contained in:
Tomasz Melcer 2007-08-10 20:01:45 +00:00
parent 1b3d3aefe4
commit 5fce20024c
3 changed files with 125 additions and 6 deletions

View File

@ -1,4 +1,4 @@
CFLAGS=`pkg-config --cflags farsight-0.1 pygtk-2.0` -I /usr/include/python2.5 -I. -I farsight/
CFLAGS=-g `pkg-config --cflags farsight-0.1 pygtk-2.0` -I /usr/include/python2.5 -I. -I farsight/
LDFLAGS=`pkg-config --libs farsight-0.1`
farsight.so: farsight.o farsightmodule.o

View File

@ -9,6 +9,28 @@ headers
#define GetString(name) PyString_AsString(PyMapping_GetItemString(item, name))
#define GetLong(name) PyInt_AsLong(PyMapping_GetItemString(item, name))
#define GetFloat(name) PyFloat_AsDouble(PyMapping_GetItemString(item, name))
static PyObject* farsight_codec_to_dict(FarsightCodec* fc) {
PyObject* dict = PyDict_New();
PyObject* item;
PyDict_SetItemString(dict, "id", item=PyInt_FromLong(fc->id));
Py_DECREF(item);
PyDict_SetItemString(dict, "encoding_name", item=PyString_FromString(fc->encoding_name));
Py_DECREF(item);
PyDict_SetItemString(dict, "media_type", item=PyInt_FromLong(fc->media_type));
Py_DECREF(item);
PyDict_SetItemString(dict, "clock_rate", item=PyInt_FromLong(fc->clock_rate));
Py_DECREF(item);
PyDict_SetItemString(dict, "channels", item=PyInt_FromLong(fc->channels));
Py_DECREF(item);
return dict;
}
%%
modulename farsight
%%
@ -32,7 +54,7 @@ static PyObject* _wrap_farsight_session_list_supported_codecs(PyGObject *self)
ret=PyList_New(0);
for (tmp=list; tmp!=NULL; tmp=tmp->next) {
FarsightCodec *codec = tmp->data;
PyObject *item = pygobject_new((GObject *) codec);
PyObject *item = farsight_codec_to_dict(codec);
PyList_Append(ret, item);
Py_DECREF(item);
@ -49,10 +71,11 @@ static PyObject* _wrap_farsight_stream_get_local_codecs(PyGObject *self)
list=farsight_stream_get_local_codecs(FARSIGHT_STREAM(self->obj));
ret=PyList_New(0);
for (tmp=list; tmp!=NULL; tmp=g_list_next(tmp)) {
FarsightCodec *codec = tmp->data;
PyObject *item = pygobject_new((GObject *) codec);
PyObject *item = farsight_codec_to_dict(codec);
PyList_Append(ret, item);
Py_DECREF(item);
@ -135,6 +158,7 @@ static PyObject* _wrap_farsight_stream_set_remote_candidate_list(PyGObject *self
listsize=PySequence_Size(list);
for(i=0;i<listsize;i++) {
FarsightTransportInfo fti;
PyObject* item = PySequence_GetItem(list, listsize-i-1);
fti.candidate_id=GetString("candidate_id");
@ -146,10 +170,11 @@ static PyObject* _wrap_farsight_stream_set_remote_candidate_list(PyGObject *self
fti.proto_profile=GetString("proto_profile");
fti.preference=GetFloat("preference");
fti.type=GetLong("type");
fti.username=GetString("username");
fti.password=GetString("password");
fti.username="";
fti.password="";
g_array_append_val(candidate_array, fti);
candidate_list = g_list_prepend(candidate_list,
&g_array_index(candidate_array, FarsightTransportInfo, i));
}
@ -171,7 +196,7 @@ static PyObject* _wrap_farsight_stream_set_remote_codecs(PyGObject *self,
static char* kwlist[] = {"codecs", NULL};
PyObject* list, * item;
GArray* codecs_array;
GList* codecs_list;
GList* codecs_list=NULL;
int i, listsize;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O", kwlist, &list))
@ -190,6 +215,7 @@ static PyObject* _wrap_farsight_stream_set_remote_codecs(PyGObject *self,
fc.media_type = GetLong("media_type");
fc.clock_rate = GetLong("clock_rate");
fc.channels = GetLong("channels");
fc.optional_params = NULL;
g_array_append_val(codecs_array, fc);
codecs_list = g_list_prepend(codecs_list,

93
src/common/farsight/test.py Executable file
View File

@ -0,0 +1,93 @@
#!/usr/bin/python
# hack
import sys, dl, gst, gobject
sys.setdlopenflags(dl.RTLD_NOW | dl.RTLD_GLOBAL)
import farsight
FARSIGHT_MEDIA_TYPE_AUDIO=0
FARSIGHT_STREAM_DIRECTION_BOTH=3
FARSIGHT_NETWORK_PROTOCOL_UDP=0
FARSIGHT_CANDIDATE_TYPE_LOCAL=0
# callbacks
def stream_error(stream, error, debug):
print "stream error: stream=%r, error=%s" % (stream, error)
def session_error(stream, error, debug):
print "session error: session=%r, error=%s" % (session, error)
def new_active_candidate_pair(stream, native_candidate, remote_candidate):
print "new-native-canditate-pair: stream=%r" % (stream,)
def codec_changed(stream, codec_id):
print "codec-changed: stream=%r, codec=%d" % (stream, codec_id)
def native_candidates_prepared(stream):
print "preparation-complete: stream=%r" % (stream,)
transport_candidates = stream.get_native_candidate_list()
for candidate in candidates:
print "Local transport candidate: %s %d %s %s %s:%d, pref %f" % \
(candidate.candidate_id, candidate.component,
"UDP" if candidate.proto==FARSIGHT_NETWORK_PROTOCOL_UDP else "TCP",
candidate.proto_subtype, candidate.ip, candidate.port,
candidate.preference)
def state_changed(stream, state, dir):
print "state-changed: stream=%r, %d, %d" % (stream, state, dir)
# setups
def setup_rtp_session():
session = farsight.farsight_session_factory_make("rtp")
# no error checking
# no protocol details printed
session.connect('error', session_error)
return session
def setup_rtp_stream(session):
stream = session.create_stream(FARSIGHT_MEDIA_TYPE_AUDIO, FARSIGHT_STREAM_DIRECTION_BOTH)
stream.transmitter = "rawudp"
stream.connect("error", stream_error);
stream.connect("new-active-candidate-pair", new_active_candidate_pair);
stream.connect("codec-changed", codec_changed);
stream.connect("native-candidates-prepared", native_candidates_prepared);
stream.connect("state-changed", state_changed);
possible_codecs=stream.get_local_codecs()
for codec in possible_codecs:
print "codec: %d: %s/%d found" % (codec['id'], codec['encoding_name'], codec['clock_rate'])
stream.prepare_transports()
return stream
# main
def main():
if len(sys.argv)!=3:
print >>sys.stderr, "usage: test remoteip remoteport"
return
session = setup_rtp_session()
stream = setup_rtp_stream(session)
stream.set_remote_candidate_list([
{'candidate_id': 'L1',
'component': 1,
'ip': sys.argv[1],
'port': int(sys.argv[2]),
'proto': FARSIGHT_NETWORK_PROTOCOL_UDP,
'proto_subtype': 'RTP',
'proto_profile': 'AVP',
'preference': 1.0,
'type': FARSIGHT_CANDIDATE_TYPE_LOCAL}])
stream.set_remote_codecs(stream.get_local_codecs())
gobject.MainLoop().run()
main()