2009-11-15 20:47:06 +01:00
|
|
|
##
|
|
|
|
## Copyright (C) 2006 Gajim Team
|
|
|
|
##
|
|
|
|
## This program is free software; you can redistribute it and/or modify
|
|
|
|
## it under the terms of the GNU General Public License as published
|
|
|
|
## by the Free Software Foundation; version 2 only.
|
|
|
|
##
|
|
|
|
## This program is distributed in the hope that it will be useful,
|
|
|
|
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
## GNU General Public License for more details.
|
|
|
|
##
|
|
|
|
|
2009-11-26 12:58:12 +01:00
|
|
|
"""
|
|
|
|
Handles Jingle RTP sessions (XEP 0167)
|
|
|
|
"""
|
2009-11-15 20:47:06 +01:00
|
|
|
|
2010-03-23 10:45:58 +01:00
|
|
|
from collections import deque
|
|
|
|
|
2012-12-23 16:23:43 +01:00
|
|
|
from gi.repository import GObject
|
2009-12-10 22:02:03 +01:00
|
|
|
import socket
|
2009-11-15 20:47:06 +01:00
|
|
|
|
2012-12-09 21:37:51 +01:00
|
|
|
import nbxmpp
|
2012-04-01 19:49:52 +02:00
|
|
|
import farstream, gst
|
2009-11-29 22:45:34 +01:00
|
|
|
from glib import GError
|
2009-11-15 20:47:06 +01:00
|
|
|
|
2009-11-29 15:39:26 +01:00
|
|
|
import gajim
|
|
|
|
|
2009-11-15 20:47:06 +01:00
|
|
|
from jingle_transport import JingleTransportICEUDP
|
2009-12-01 22:39:02 +01:00
|
|
|
from jingle_content import contents, JingleContent, JingleContentSetupException
|
2011-11-22 20:08:08 +01:00
|
|
|
from connection_handlers_events import InformationEvent
|
2009-11-15 20:47:06 +01:00
|
|
|
|
|
|
|
|
2010-03-14 22:47:54 +01:00
|
|
|
import logging
|
|
|
|
log = logging.getLogger('gajim.c.jingle_rtp')
|
|
|
|
|
|
|
|
|
2009-11-15 20:47:06 +01:00
|
|
|
class JingleRTPContent(JingleContent):
|
2010-02-08 15:08:40 +01:00
|
|
|
def __init__(self, session, media, transport=None):
|
|
|
|
if transport is None:
|
2010-08-26 13:31:29 +02:00
|
|
|
transport = JingleTransportICEUDP(None)
|
2010-02-08 15:08:40 +01:00
|
|
|
JingleContent.__init__(self, session, transport)
|
|
|
|
self.media = media
|
|
|
|
self._dtmf_running = False
|
2012-04-01 19:49:52 +02:00
|
|
|
self.farstream_media = {'audio': farstream.MEDIA_TYPE_AUDIO,
|
|
|
|
'video': farstream.MEDIA_TYPE_VIDEO}[media]
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2010-05-03 21:59:46 +02:00
|
|
|
self.pipeline = None
|
|
|
|
self.src_bin = None
|
|
|
|
self.stream_failed_once = False
|
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
self.candidates_ready = False # True when local candidates are prepared
|
|
|
|
|
|
|
|
self.callbacks['session-initiate'] += [self.__on_remote_codecs]
|
|
|
|
self.callbacks['content-add'] += [self.__on_remote_codecs]
|
|
|
|
self.callbacks['description-info'] += [self.__on_remote_codecs]
|
2010-08-26 16:56:08 +02:00
|
|
|
self.callbacks['content-accept'] += [self.__on_remote_codecs]
|
|
|
|
self.callbacks['session-accept'] += [self.__on_remote_codecs]
|
2010-02-08 15:08:40 +01:00
|
|
|
self.callbacks['session-terminate'] += [self.__stop]
|
|
|
|
self.callbacks['session-terminate-sent'] += [self.__stop]
|
|
|
|
|
2012-04-01 19:49:52 +02:00
|
|
|
def setup_stream(self, on_src_pad_added):
|
2010-02-08 15:08:40 +01:00
|
|
|
# pipeline and bus
|
|
|
|
self.pipeline = gst.Pipeline()
|
|
|
|
bus = self.pipeline.get_bus()
|
|
|
|
bus.add_signal_watch()
|
|
|
|
bus.connect('message', self._on_gst_message)
|
|
|
|
|
|
|
|
# conference
|
|
|
|
self.conference = gst.element_factory_make('fsrtpconference')
|
|
|
|
self.pipeline.add(self.conference)
|
|
|
|
self.funnel = None
|
|
|
|
|
2012-04-01 19:49:52 +02:00
|
|
|
self.p2psession = self.conference.new_session(self.farstream_media)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2012-04-01 19:49:52 +02:00
|
|
|
participant = self.conference.new_participant()
|
2010-02-08 15:08:40 +01:00
|
|
|
# FIXME: Consider a workaround, here...
|
|
|
|
# pidgin and telepathy-gabble don't follow the XEP, and it won't work
|
|
|
|
# due to bad controlling-mode
|
|
|
|
params = {'controlling-mode': self.session.weinitiate, 'debug': False}
|
|
|
|
if gajim.config.get('use_stun_server'):
|
|
|
|
stun_server = gajim.config.get('stun_server')
|
|
|
|
if not stun_server and self.session.connection._stun_servers:
|
|
|
|
stun_server = self.session.connection._stun_servers[0]['host']
|
|
|
|
if stun_server:
|
|
|
|
try:
|
|
|
|
ip = socket.getaddrinfo(stun_server, 0, socket.AF_UNSPEC,
|
|
|
|
socket.SOCK_STREAM)[0][4][0]
|
2013-01-01 23:18:36 +01:00
|
|
|
except socket.gaierror as e:
|
|
|
|
log.warn('Lookup of stun ip failed: %s' % str(e))
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
|
|
|
params['stun-ip'] = ip
|
|
|
|
|
|
|
|
self.p2pstream = self.p2psession.new_stream(participant,
|
2012-04-01 19:49:52 +02:00
|
|
|
farstream.DIRECTION_RECV)
|
|
|
|
self.p2pstream.connect('src-pad-added', on_src_pad_added)
|
|
|
|
self.p2pstream.set_transmitter('nice', params)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def is_ready(self):
|
2010-05-04 10:31:05 +02:00
|
|
|
return (JingleContent.is_ready(self) and self.candidates_ready)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def make_bin_from_config(self, config_key, pipeline, text):
|
|
|
|
pipeline = pipeline % gajim.config.get(config_key)
|
|
|
|
try:
|
|
|
|
bin = gst.parse_bin_from_description(pipeline, True)
|
|
|
|
return bin
|
2013-01-01 23:18:36 +01:00
|
|
|
except GError as error_str:
|
2011-11-22 19:25:15 +01:00
|
|
|
gajim.nec.push_incoming_event(InformationEvent(None,
|
|
|
|
conn=self.session.connection, level='error',
|
|
|
|
pri_txt=_('%s configuration error') % text.capitalize(),
|
|
|
|
sec_txt=_("Couldn't setup %s. Check your configuration.\n\n"
|
|
|
|
"Pipeline was:\n%s\n\nError was:\n%s") % (text, pipeline,
|
|
|
|
error_str)))
|
2010-02-08 15:08:40 +01:00
|
|
|
raise JingleContentSetupException
|
|
|
|
|
|
|
|
def add_remote_candidates(self, candidates):
|
|
|
|
JingleContent.add_remote_candidates(self, candidates)
|
|
|
|
# FIXME: connectivity should not be etablished yet
|
|
|
|
# Instead, it should be etablished after session-accept!
|
|
|
|
if self.sent:
|
2012-04-01 19:49:52 +02:00
|
|
|
self.p2pstream.add_remote_candidates(candidates)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def batch_dtmf(self, events):
|
|
|
|
"""
|
|
|
|
Send several DTMF tones
|
|
|
|
"""
|
|
|
|
if self._dtmf_running:
|
2010-03-23 08:31:52 +01:00
|
|
|
raise Exception("There is a DTMF batch already running")
|
2010-03-23 10:45:58 +01:00
|
|
|
events = deque(events)
|
2010-02-08 15:08:40 +01:00
|
|
|
self._dtmf_running = True
|
2010-03-23 10:45:58 +01:00
|
|
|
self._start_dtmf(events.popleft())
|
2012-12-23 16:23:43 +01:00
|
|
|
GObject.timeout_add(500, self._next_dtmf, events)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def _next_dtmf(self, events):
|
|
|
|
self._stop_dtmf()
|
|
|
|
if events:
|
2010-03-23 10:45:58 +01:00
|
|
|
self._start_dtmf(events.popleft())
|
2012-12-23 16:23:43 +01:00
|
|
|
GObject.timeout_add(500, self._next_dtmf, events)
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
|
|
|
self._dtmf_running = False
|
|
|
|
|
|
|
|
def _start_dtmf(self, event):
|
|
|
|
if event in ('*', '#'):
|
2012-04-01 19:49:52 +02:00
|
|
|
event = {'*': farstream.DTMF_EVENT_STAR,
|
|
|
|
'#': farstream.DTMF_EVENT_POUND}[event]
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
|
|
|
event = int(event)
|
2012-04-01 19:49:52 +02:00
|
|
|
self.p2psession.start_telephony_event(event, 2)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def _stop_dtmf(self):
|
2012-04-01 19:49:52 +02:00
|
|
|
self.p2psession.stop_telephony_event()
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def _fill_content(self, content):
|
2012-12-09 21:37:51 +01:00
|
|
|
content.addChild(nbxmpp.NS_JINGLE_RTP + ' description',
|
2010-02-08 15:08:40 +01:00
|
|
|
attrs={'media': self.media}, payload=self.iter_codecs())
|
|
|
|
|
|
|
|
def _setup_funnel(self):
|
|
|
|
self.funnel = gst.element_factory_make('fsfunnel')
|
|
|
|
self.pipeline.add(self.funnel)
|
|
|
|
self.funnel.set_state(gst.STATE_PLAYING)
|
|
|
|
self.sink.set_state(gst.STATE_PLAYING)
|
|
|
|
self.funnel.link(self.sink)
|
|
|
|
|
|
|
|
def _on_src_pad_added(self, stream, pad, codec):
|
|
|
|
if not self.funnel:
|
|
|
|
self._setup_funnel()
|
|
|
|
pad.link(self.funnel.get_pad('sink%d'))
|
|
|
|
|
|
|
|
def _on_gst_message(self, bus, message):
|
|
|
|
if message.type == gst.MESSAGE_ELEMENT:
|
|
|
|
name = message.structure.get_name()
|
2010-06-20 22:46:25 +02:00
|
|
|
log.debug('gst element message: %s: %s' % (name, message))
|
2012-04-01 19:49:52 +02:00
|
|
|
if name == 'farstream-new-active-candidate-pair':
|
2010-02-08 15:08:40 +01:00
|
|
|
pass
|
2012-04-01 19:49:52 +02:00
|
|
|
elif name == 'farstream-recv-codecs-changed':
|
2010-02-08 15:08:40 +01:00
|
|
|
pass
|
2012-04-01 19:49:52 +02:00
|
|
|
elif name == 'farstream-codecs-changed':
|
|
|
|
if self.sent and self.p2psession.get_property('codecs'):
|
2010-05-04 10:31:05 +02:00
|
|
|
self.send_description_info()
|
2012-04-01 19:49:52 +02:00
|
|
|
elif name == 'farstream-local-candidates-prepared':
|
2010-02-08 15:08:40 +01:00
|
|
|
self.candidates_ready = True
|
|
|
|
if self.is_ready():
|
|
|
|
self.session.on_session_state_changed(self)
|
2012-04-01 19:49:52 +02:00
|
|
|
elif name == 'farstream-new-local-candidate':
|
2010-02-08 15:08:40 +01:00
|
|
|
candidate = message.structure['candidate']
|
|
|
|
self.transport.candidates.append(candidate)
|
2010-05-03 15:27:56 +02:00
|
|
|
if self.sent:
|
2010-02-08 15:08:40 +01:00
|
|
|
# FIXME: Is this case even possible?
|
|
|
|
self.send_candidate(candidate)
|
2012-04-01 19:49:52 +02:00
|
|
|
elif name == 'farstream-component-state-changed':
|
2010-02-08 15:08:40 +01:00
|
|
|
state = message.structure['state']
|
2012-04-01 19:49:52 +02:00
|
|
|
if state == farstream.STREAM_STATE_FAILED:
|
2012-12-09 21:37:51 +01:00
|
|
|
reason = nbxmpp.Node('reason')
|
2010-02-08 15:08:40 +01:00
|
|
|
reason.setTag('failed-transport')
|
2010-05-04 10:04:53 +02:00
|
|
|
self.session.remove_content(self.creator, self.name, reason)
|
2012-04-01 19:49:52 +02:00
|
|
|
elif name == 'farstream-error':
|
|
|
|
log.error('Farstream error #%d!\nMessage: %s' % (
|
2010-06-20 22:46:25 +02:00
|
|
|
message.structure['error-no'],
|
2012-04-01 19:49:52 +02:00
|
|
|
message.structure['error-msg']))
|
2010-05-03 21:59:46 +02:00
|
|
|
elif message.type == gst.MESSAGE_ERROR:
|
|
|
|
# TODO: Fix it to fallback to videotestsrc anytime an error occur,
|
|
|
|
# or raise an error, Jingle way
|
|
|
|
# or maybe one-sided stream?
|
|
|
|
if not self.stream_failed_once:
|
2011-11-22 19:25:15 +01:00
|
|
|
gajim.nec.push_incoming_event(InformationEvent(None,
|
|
|
|
conn=self.session.connection, level='error',
|
|
|
|
pri_txt=_('GStreamer error'), sec_txt=_('Error: %s\nDebug: '
|
|
|
|
'%s' % (message.structure['gerror'],
|
|
|
|
message.structure['debug']))))
|
2010-05-03 21:59:46 +02:00
|
|
|
|
|
|
|
sink_pad = self.p2psession.get_property('sink-pad')
|
|
|
|
|
|
|
|
# Remove old source
|
|
|
|
self.src_bin.get_pad('src').unlink(sink_pad)
|
2010-05-04 10:04:53 +02:00
|
|
|
self.src_bin.set_state(gst.STATE_NULL)
|
2010-05-03 21:59:46 +02:00
|
|
|
self.pipeline.remove(self.src_bin)
|
|
|
|
|
|
|
|
if not self.stream_failed_once:
|
|
|
|
# Add fallback source
|
|
|
|
self.src_bin = self.get_fallback_src()
|
|
|
|
self.pipeline.add(self.src_bin)
|
|
|
|
self.src_bin.get_pad('src').link(sink_pad)
|
|
|
|
self.stream_failed_once = True
|
|
|
|
else:
|
2012-12-09 21:37:51 +01:00
|
|
|
reason = nbxmpp.Node('reason')
|
2010-05-03 21:59:46 +02:00
|
|
|
reason.setTag('failed-application')
|
2010-05-04 10:04:53 +02:00
|
|
|
self.session.remove_content(self.creator, self.name, reason)
|
2010-05-03 21:59:46 +02:00
|
|
|
|
|
|
|
# Start playing again
|
|
|
|
self.pipeline.set_state(gst.STATE_PLAYING)
|
|
|
|
|
|
|
|
def get_fallback_src(self):
|
|
|
|
return gst.element_factory_make('fakesrc')
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2010-08-26 16:56:08 +02:00
|
|
|
def on_negotiated(self):
|
2010-02-08 15:08:40 +01:00
|
|
|
if self.accepted:
|
|
|
|
if self.transport.remote_candidates:
|
2012-04-01 19:49:52 +02:00
|
|
|
self.p2pstream.add_remote_candidates(self.transport.remote_candidates)
|
2010-02-08 15:08:40 +01:00
|
|
|
self.transport.remote_candidates = []
|
2012-04-01 19:49:52 +02:00
|
|
|
# TODO: farstream.DIRECTION_BOTH only if senders='both'
|
|
|
|
self.p2pstream.set_property('direction', farstream.DIRECTION_BOTH)
|
2010-08-26 16:56:08 +02:00
|
|
|
JingleContent.on_negotiated(self)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def __on_remote_codecs(self, stanza, content, error, action):
|
|
|
|
"""
|
|
|
|
Get peer codecs from what we get from peer
|
|
|
|
"""
|
|
|
|
|
|
|
|
codecs = []
|
|
|
|
for codec in content.getTag('description').iterTags('payload-type'):
|
2010-09-23 13:05:33 +02:00
|
|
|
if not codec['id'] or not codec['name'] or not codec['clockrate']:
|
|
|
|
# ignore invalid payload-types
|
|
|
|
continue
|
2012-04-01 19:49:52 +02:00
|
|
|
c = farstream.Codec(int(codec['id']), codec['name'],
|
|
|
|
self.farstream_media, int(codec['clockrate']))
|
2010-02-08 15:08:40 +01:00
|
|
|
if 'channels' in codec:
|
|
|
|
c.channels = int(codec['channels'])
|
|
|
|
else:
|
|
|
|
c.channels = 1
|
|
|
|
c.optional_params = [(str(p['name']), str(p['value'])) for p in \
|
|
|
|
codec.iterTags('parameter')]
|
|
|
|
codecs.append(c)
|
|
|
|
|
|
|
|
if codecs:
|
|
|
|
# FIXME: Handle this case:
|
|
|
|
# glib.GError: There was no intersection between the remote codecs and
|
|
|
|
# the local ones
|
|
|
|
self.p2pstream.set_remote_codecs(codecs)
|
|
|
|
|
|
|
|
def iter_codecs(self):
|
|
|
|
codecs = self.p2psession.get_property('codecs')
|
|
|
|
for codec in codecs:
|
|
|
|
attrs = {'name': codec.encoding_name,
|
|
|
|
'id': codec.id,
|
|
|
|
'channels': codec.channels}
|
|
|
|
if codec.clock_rate:
|
|
|
|
attrs['clockrate'] = codec.clock_rate
|
|
|
|
if codec.optional_params:
|
2012-12-09 21:37:51 +01:00
|
|
|
payload = (nbxmpp.Node('parameter', {'name': name,
|
|
|
|
'value': value}) for name, value in codec.optional_params)
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
|
|
|
payload = ()
|
2012-12-09 21:37:51 +01:00
|
|
|
yield nbxmpp.Node('payload-type', attrs, payload)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def __stop(self, *things):
|
|
|
|
self.pipeline.set_state(gst.STATE_NULL)
|
|
|
|
|
|
|
|
def __del__(self):
|
|
|
|
self.__stop()
|
|
|
|
|
|
|
|
def destroy(self):
|
|
|
|
JingleContent.destroy(self)
|
|
|
|
self.p2pstream.disconnect_by_func(self._on_src_pad_added)
|
|
|
|
self.pipeline.get_bus().disconnect_by_func(self._on_gst_message)
|
2009-11-15 20:47:06 +01:00
|
|
|
|
|
|
|
|
|
|
|
class JingleAudio(JingleRTPContent):
|
2010-02-08 15:08:40 +01:00
|
|
|
"""
|
|
|
|
Jingle VoIP sessions consist of audio content transported over an ICE UDP
|
|
|
|
protocol
|
|
|
|
"""
|
2009-11-26 12:58:12 +01:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
def __init__(self, session, transport=None):
|
|
|
|
JingleRTPContent.__init__(self, session, 'audio', transport)
|
|
|
|
self.setup_stream()
|
2009-11-15 20:47:06 +01:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
def set_mic_volume(self, vol):
|
|
|
|
"""
|
|
|
|
vol must be between 0 ans 1
|
|
|
|
"""
|
|
|
|
self.mic_volume.set_property('volume', vol)
|
2009-12-02 21:37:21 +01:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
def set_out_volume(self, vol):
|
|
|
|
"""
|
|
|
|
vol must be between 0 ans 1
|
|
|
|
"""
|
|
|
|
self.out_volume.set_property('volume', vol)
|
2010-01-10 16:31:00 +01:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
def setup_stream(self):
|
2012-04-01 19:49:52 +02:00
|
|
|
JingleRTPContent.setup_stream(self, self._on_src_pad_added)
|
2009-11-15 20:47:06 +01:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
# Configure SPEEX
|
|
|
|
# Workaround for psi (not needed since rev
|
|
|
|
# 147aedcea39b43402fe64c533d1866a25449888a):
|
|
|
|
# place 16kHz before 8kHz, as buggy psi versions will take in
|
|
|
|
# account only the first codec
|
2009-11-15 20:47:06 +01:00
|
|
|
|
2012-04-01 19:49:52 +02:00
|
|
|
codecs = [farstream.Codec(farstream.CODEC_ID_ANY, 'SPEEX',
|
|
|
|
farstream.MEDIA_TYPE_AUDIO, 16000),
|
|
|
|
farstream.Codec(farstream.CODEC_ID_ANY, 'SPEEX',
|
|
|
|
farstream.MEDIA_TYPE_AUDIO, 8000)]
|
2010-02-08 15:08:40 +01:00
|
|
|
self.p2psession.set_codec_preferences(codecs)
|
2009-11-15 20:47:06 +01:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
# the local parts
|
|
|
|
# TODO: Add queues?
|
2010-05-03 21:59:46 +02:00
|
|
|
self.src_bin = self.make_bin_from_config('audio_input_device',
|
2010-02-08 15:08:40 +01:00
|
|
|
'%s ! audioconvert', _("audio input"))
|
2009-11-29 15:39:26 +01:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
self.sink = self.make_bin_from_config('audio_output_device',
|
|
|
|
'audioconvert ! volume name=gajim_out_vol ! %s', _("audio output"))
|
2009-11-29 15:39:26 +01:00
|
|
|
|
2010-05-03 21:59:46 +02:00
|
|
|
self.mic_volume = self.src_bin.get_by_name('gajim_vol')
|
2010-02-08 15:08:40 +01:00
|
|
|
self.out_volume = self.sink.get_by_name('gajim_out_vol')
|
2009-11-15 20:47:06 +01:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
# link gst elements
|
2010-05-03 21:59:46 +02:00
|
|
|
self.pipeline.add(self.sink, self.src_bin)
|
2009-11-15 20:47:06 +01:00
|
|
|
|
2010-05-03 21:59:46 +02:00
|
|
|
self.src_bin.get_pad('src').link(self.p2psession.get_property(
|
2010-02-08 15:08:40 +01:00
|
|
|
'sink-pad'))
|
2009-11-15 20:47:06 +01:00
|
|
|
|
2012-04-01 19:49:52 +02:00
|
|
|
# The following is needed for farstream to process ICE requests:
|
2010-02-08 15:08:40 +01:00
|
|
|
self.pipeline.set_state(gst.STATE_PLAYING)
|
2009-11-15 20:47:06 +01:00
|
|
|
|
|
|
|
|
|
|
|
class JingleVideo(JingleRTPContent):
|
2010-02-08 15:08:40 +01:00
|
|
|
def __init__(self, session, transport=None):
|
|
|
|
JingleRTPContent.__init__(self, session, 'video', transport)
|
|
|
|
self.setup_stream()
|
2009-11-15 20:47:06 +01:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
def setup_stream(self):
|
|
|
|
# TODO: Everything is not working properly:
|
|
|
|
# sometimes, one window won't show up,
|
|
|
|
# sometimes it'll freeze...
|
2012-04-01 19:49:52 +02:00
|
|
|
JingleRTPContent.setup_stream(self, self._on_src_pad_added)
|
2009-11-29 15:39:26 +01:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
# the local parts
|
2010-06-19 15:44:10 +02:00
|
|
|
if gajim.config.get('video_framerate'):
|
2012-04-20 16:27:30 +02:00
|
|
|
framerate = 'videorate ! video/x-raw-yuv,framerate=%s ! ' % \
|
|
|
|
gajim.config.get('video_framerate')
|
2010-06-19 15:44:10 +02:00
|
|
|
else:
|
|
|
|
framerate = ''
|
|
|
|
try:
|
|
|
|
w, h = gajim.config.get('video_size').split('x')
|
|
|
|
except:
|
|
|
|
w = h = None
|
|
|
|
if w and h:
|
2012-04-20 16:27:30 +02:00
|
|
|
video_size = 'video/x-raw-yuv,width=%s,height=%s ! ' % (w, h)
|
2010-06-19 15:44:10 +02:00
|
|
|
else:
|
|
|
|
video_size = ''
|
2010-05-03 21:59:46 +02:00
|
|
|
self.src_bin = self.make_bin_from_config('video_input_device',
|
2010-06-19 15:44:10 +02:00
|
|
|
'%%s ! %svideoscale ! %sffmpegcolorspace' % (framerate, video_size),
|
|
|
|
_("video input"))
|
2010-02-08 15:08:40 +01:00
|
|
|
#caps = gst.element_factory_make('capsfilter')
|
|
|
|
#caps.set_property('caps', gst.caps_from_string('video/x-raw-yuv, width=320, height=240'))
|
2009-11-15 20:47:06 +01:00
|
|
|
|
2010-05-03 21:59:46 +02:00
|
|
|
self.pipeline.add(self.src_bin)#, caps)
|
2010-02-08 15:08:40 +01:00
|
|
|
#src_bin.link(caps)
|
2009-11-15 20:47:06 +01:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
self.sink = self.make_bin_from_config('video_output_device',
|
2011-04-06 21:56:42 +02:00
|
|
|
'videoscale ! ffmpegcolorspace ! %s force-aspect-ratio=True',
|
|
|
|
_("video output"))
|
2010-02-08 15:08:40 +01:00
|
|
|
self.pipeline.add(self.sink)
|
2009-11-15 20:47:06 +01:00
|
|
|
|
2011-04-06 21:56:42 +02:00
|
|
|
self.src_bin.get_pad('src').link(self.p2psession.get_property(
|
|
|
|
'sink-pad'))
|
2009-11-15 20:47:06 +01:00
|
|
|
|
2012-04-01 19:49:52 +02:00
|
|
|
# The following is needed for farstream to process ICE requests:
|
2010-02-08 15:08:40 +01:00
|
|
|
self.pipeline.set_state(gst.STATE_PLAYING)
|
2009-11-15 20:47:06 +01:00
|
|
|
|
2010-05-03 21:59:46 +02:00
|
|
|
def get_fallback_src(self):
|
|
|
|
# TODO: Use avatar?
|
|
|
|
pipeline = 'videotestsrc is-live=true ! video/x-raw-yuv,framerate=10/1 ! ffmpegcolorspace'
|
|
|
|
return gst.parse_bin_from_description(pipeline, True)
|
2009-11-15 20:47:06 +01:00
|
|
|
|
|
|
|
def get_content(desc):
|
2010-02-08 15:08:40 +01:00
|
|
|
if desc['media'] == 'audio':
|
|
|
|
return JingleAudio
|
|
|
|
elif desc['media'] == 'video':
|
|
|
|
return JingleVideo
|
2009-11-15 20:47:06 +01:00
|
|
|
|
2012-12-09 21:37:51 +01:00
|
|
|
contents[nbxmpp.NS_JINGLE_RTP] = get_content
|