def convert_media_codecs(codecs, name): fscodecs = [] media_type = media_types[name] for codec in codecs: fscodec = farsight.Codec(codec.payload, codec.encoding, media_type, codec.clockrate) fscodec.optional_params = codec.params.items() fscodecs.append(fscodec) return fscodecs
def __init__(self, conference, source): self.conference = conference self.source = source self.streams = [] self.fssession = conference.new_session(source.get_type()) self.fssession.uisession = self if source.get_type() == farstream.MEDIA_TYPE_VIDEO: # We prefer H263-1998 because we know it works # We don't know if the others do work # We know H264 doesn't work for now or anything else # that needs to send config data self.fssession.set_codec_preferences( [ \ farstream.Codec(farstream.CODEC_ID_ANY, "THEORA", farstream.MEDIA_TYPE_VIDEO, 90000), farstream.Codec(farstream.CODEC_ID_ANY, "H264", farstream.MEDIA_TYPE_VIDEO, 0), farstream.Codec(farstream.CODEC_ID_ANY, "H263-1998", farstream.MEDIA_TYPE_VIDEO, 0), farstream.Codec(farstream.CODEC_ID_ANY, "H263", farstream.MEDIA_TYPE_VIDEO, 0) ]) elif source.get_type() == farstream.MEDIA_TYPE_AUDIO: self.fssession.set_codec_preferences( [ \ farstream.Codec(farstream.CODEC_ID_ANY, "PCMA", farstream.MEDIA_TYPE_AUDIO, 0), farstream.Codec(farstream.CODEC_ID_ANY, "PCMU", farstream.MEDIA_TYPE_AUDIO, 0), # The gst speexenc element breaks timestamps farstream.Codec(farstream.CODEC_ID_DISABLE, "SPEEX", farstream.MEDIA_TYPE_AUDIO, 16000), # Sadly, vorbis is not currently compatible with live streaming :-( farstream.Codec(farstream.CODEC_ID_DISABLE, "VORBIS", farstream.MEDIA_TYPE_AUDIO, 0), ]) self.sourcepad = self.source.get_src_pad() self.sourcepad.link(self.fssession.get_property("sink-pad"))
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 = farstream.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] codecs.append(codec) return codecs
def get_codecs(self): return [ farstream.Codec(self.connect.myid, "nego-codecs", self.pid, self.id) ]
def send_local_codecs(self): print "Send local codecs to %s for media %s" % (self.pid, self.id) self.connect.send_codecs(self.pid, self.id, [ farstream.Codec(self.connect.myid, "local_codec", self.pid, self.id) ])
def codecs(self, codecs): if self.connect.myid != 1: self.connect.send_codecs(1, self.id, [ farstream.Codec(self.connect.myid, "codec-name", self.pid, self.id) ])
loop = gobject.MainLoop() pipeline = gst.Pipeline() conference = gst.element_factory_make ("fsrtpconference") sdes = conference.get_property("sdes") conference.set_property ("sdes",conference.get_property("sdes").copy().set_value("cname", sys.argv[1] + "@1.2.3.4")) pipeline.add (conference) session = conference.new_session (farstream.MEDIA_TYPE_VIDEO) participant = conference.new_participant () stream = session.new_stream (participant, farstream.DIRECTION_BOTH) stream.set_transmitter("multicast") stream.set_remote_codecs([farstream.Codec(96, "H263-1998", farstream.MEDIA_TYPE_VIDEO, 90000)]) candidate = farstream.Candidate() candidate.ip = "224.0.0.110" candidate.port = 3442 candidate.component_id = farstream.COMPONENT_RTP candidate.proto = farstream.NETWORK_PROTOCOL_UDP candidate.type = farstream.CANDIDATE_TYPE_MULTICAST candidate.ttl = 1 candidate2 = candidate.copy() candidate2.port = 3443 candidate2.component_id = farstream.COMPONENT_RTCP stream.force_remote_candidates ([candidate, candidate2]) videosource = gst.parse_bin_from_description (sys.argv[2] + " ! videoscale", True)
def build_codecs(type): codecs = [] for args in codecs_definitions[type]: codec = farsight.Codec(*args) codecs.append(codec) return codecs
conference = gst.element_factory_make("fsrtpconference") sdes = conference.get_property("sdes") conference.set_property( "sdes", conference.get_property("sdes").copy().set_value("cname", sys.argv[1] + "@1.2.3.4")) pipeline.add(conference) session = conference.new_session(farstream.MEDIA_TYPE_VIDEO) participant = conference.new_participant() stream = session.new_stream(participant, farstream.DIRECTION_BOTH) stream.set_transmitter("multicast") stream.set_remote_codecs( [farstream.Codec(96, "H263-1998", farstream.MEDIA_TYPE_VIDEO, 90000)]) candidate = farstream.Candidate() candidate.ip = "224.0.0.110" candidate.port = 3442 candidate.component_id = farstream.COMPONENT_RTP candidate.proto = farstream.NETWORK_PROTOCOL_UDP candidate.type = farstream.CANDIDATE_TYPE_MULTICAST candidate.ttl = 1 candidate2 = candidate.copy() candidate2.port = 3443 candidate2.component_id = farstream.COMPONENT_RTCP stream.force_remote_candidates([candidate, candidate2]) videosource = gst.parse_bin_from_description(sys.argv[2] + " ! videoscale", True)