[farsight2/master] Replace codec/codec_done with codecs in fs2-gui-net
Olivier Crête
olivier.crete at collabora.co.uk
Tue Dec 23 15:24:09 PST 2008
---
tests/gui/fs2_gui_net.py | 121 ++++++++++++++++++++++------------------------
1 files changed, 58 insertions(+), 63 deletions(-)
diff --git a/tests/gui/fs2_gui_net.py b/tests/gui/fs2_gui_net.py
index ef3d3fe..07ab5bb 100644
--- a/tests/gui/fs2_gui_net.py
+++ b/tests/gui/fs2_gui_net.py
@@ -48,11 +48,10 @@ import gobject
class FsUIConnect:
ERROR = 0
- CODEC = 1
- CODECS_DONE = 2
- CANDIDATE = 3
- CANDIDATES_DONE = 4
- INTRO = 5
+ CODECS = 1
+ CANDIDATE = 2
+ CANDIDATES_DONE = 3
+ INTRO = 4
def __reset(self):
self.type = None
@@ -98,8 +97,8 @@ class FsUIConnect:
self.data += data
if len(self.data) == self.size:
if self.type is not None:
- if self.type == self.CODEC:
- data = self.__codec_from_string(data)
+ if self.type == self.CODECS:
+ data = self.__codecs_from_string(data)
elif self.type == self.CANDIDATE:
data = self.__candidate_from_string(data)
else:
@@ -145,12 +144,10 @@ class FsUIConnect:
self.__send_data(dest, self.ERROR, src=src)
def send_intro(self, dest, cname, src=None):
self.__send_data(dest, self.INTRO, data=cname, src=src)
- def send_codec(self, dest, media, codec, src=None):
- self.__send_data(dest, self.CODEC,
+ def send_codecs(self, dest, media, codecs, src=None):
+ self.__send_data(dest, self.CODECS,
media=media,
- data=self.__codec_to_string(codec))
- def send_codecs_done(self, dest, media):
- self.__send_data(dest, self.CODECS_DONE, media=media)
+ data=self.__codecs_to_string(codecs))
def send_candidate(self, dest, media, candidate, src=None):
self.__send_data(dest, self.CANDIDATE, media=media,
data=self.__candidate_to_string(candidate), src=src)
@@ -199,27 +196,35 @@ class FsUIConnect:
candidate.type = int(type)
return candidate
- def __codec_to_string(self, codec):
- start = " ".join((str(codec.id),
- codec.encoding_name,
- str(int(codec.media_type)),
- str(codec.clock_rate),
- str(codec.channels)))
- return "".join((start,
- "|",
- ":".join(["=".join(i) for i in codec.optional_params])))
-
-
- def __codec_from_string(self, string):
- (start,end) = string.split("|")
- (id, encoding_name, media_type, clock_rate, channels) = start.split(" ")
- codec = farsight.Codec(int(id), encoding_name, int(media_type),
+ def __codecs_to_string(self, codecs):
+ codec_strings = []
+ for codec in codecs:
+ start = " ".join((str(codec.id),
+ codec.encoding_name,
+ str(int(codec.media_type)),
+ str(codec.clock_rate),
+ str(codec.channels)))
+ codec = "".join((start,
+ "|",
+ ";".join(["=".join(i) for i in codec.optional_params])))
+ codec_strings.append(codec)
+
+ return "\n".join(codec_strings)
+
+
+ def __codecs_from_string(self, string):
+ codecs = []
+ for substring in string.split("\n"):
+ (start,end) = substring.split("|")
+ (id, encoding_name, media_type, clock_rate, channels) = start.split(" ")
+ codec = farsight.Codec(int(id), encoding_name, int(media_type),
int(clock_rate))
- codec.channels = int(channels)
- if len(end):
- codec.optional_params = \
- [tuple(x.split("=",1)) for x in end.split(":") if len(x) > 0]
- return codec
+ codec.channels = int(channels)
+ if len(end):
+ codec.optional_params = \
+ [tuple(x.split("=",1)) for x in end.split(";") if len(x) > 0]
+ codecs.append(codec)
+ return codecs
class FsUIConnectClient (FsUIConnect):
def __init__(self, ip, port, callbacks):
@@ -265,17 +270,14 @@ class FsUIClient:
self.args = args
self.cname = cname
self.connect = FsUIConnectClient(ip, port, (self.__error,
- self.__codec,
- self.__codecs_done,
+ self.__codecs,
self.__candidate,
self.__candidate_done,
self.__intro))
self.connect.send_intro(1, cname)
- def __codec(self, src, dest, media, data):
- self.participants[src].codec(media, data)
- def __codecs_done(self, src, dest, media, data):
- self.participants[src].codecs_done(media)
+ def __codecs(self, src, dest, media, data):
+ self.participants[src].codecs(media, data)
def __candidate(self, src, dest, media, data):
self.participants[src].candidate(media, data)
def __candidate_done(self, src, dest, media, data):
@@ -310,15 +312,12 @@ class FsUIServer:
self.get_participant = get_participant
self.args = args
self.connect = FsUIConnect(sock, (self.__error,
- self.__codec,
- self.__codecs_done,
+ self.__codecs,
self.__candidate,
self.__candidate_done,
self.__intro), 1)
- def __codec(self, src, dest, media, data):
- FsUIServer.participants[src].codec(media, data)
- def __codecs_done(self, src, dest, media, data):
- FsUIServer.participants[src].codecs_done(media)
+ def __codecs(self, src, dest, media, data):
+ FsUIServer.participants[src].codecs(media, data)
def __candidate(self, src, dest, media, data):
if dest == 1:
FsUIServer.participants[src].candidate(media, data)
@@ -381,25 +380,23 @@ if __name__ == "__main__":
print "Got candidate", candidate
def candidates_done(self):
print "Got candidate done"
- def codec(self, codec):
- print "Got codec src:%d dest:%d media:%d src:%s" % (codec.id, int(codec.media_type), codec.clock_rate, codec.encoding_name)
- def codecs_done(self):
- print "Got codecs done from %s for media %s" % (self.pid, self.id)
+ def codecs(self, codecs):
+ for codec in codecs:
+ print "Got codec src:%d dest:%d media:%d src:%s" % (codec.id, int(codec.media_type), codec.clock_rate, codec.encoding_name)
if self.connect.myid != 1:
- self.connect.send_codec(1, self.id,
- farsight.Codec(self.connect.myid,
- "codecs_done",
+ self.connect.send_codecs(1, self.id,
+ [farsight.Codec(self.connect.myid,
+ "codec-name",
self.pid,
- self.id))
- self.connect.send_codecs_done(1, self.id)
+ self.id)])
+
def send_local_codecs(self):
print "Send local codecs to %s for media %s" % (self.pid, self.id)
- self.connect.send_codec(self.pid, self.id,
- farsight.Codec(self.connect.myid,
- "local_codec",
- self.pid,
- self.id))
- self.connect.send_codecs_done(self.pid, self.id)
+ self.connect.send_codecs(self.pid, self.id,
+ [farsight.Codec(self.connect.myid,
+ "local_codec",
+ self.pid,
+ self.id)])
class TestParticipant:
@@ -414,10 +411,8 @@ if __name__ == "__main__":
self.streams[media].candidate(candidate)
def candidates_done(self, media):
self.streams[media].candidates_done()
- def codec(self, media, codec):
- self.streams[media].codec(codec)
- def codecs_done(self, media):
- self.streams[media].codecs_done()
+ def codecs(self, media, codecs):
+ self.streams[media].codecs(codecs)
def send_local_codecs(self):
for id in self.streams:
self.streams[id].send_local_codecs()
--
1.5.6.5
More information about the farsight-commits
mailing list