From a8f9ff9206b7fa02c643a7e410348f9ad789c748 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20Test=C3=A9?= Date: Mon, 7 Mar 2016 22:57:11 +0100 Subject: [PATCH] Modify the way of creating pipeline to ensure widegt and audio level attachement. --- stream_2016/libre-streamer.py | 45 +++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/stream_2016/libre-streamer.py b/stream_2016/libre-streamer.py index a9951ab..50b5649 100755 --- a/stream_2016/libre-streamer.py +++ b/stream_2016/libre-streamer.py @@ -48,7 +48,7 @@ __status__ = 'Prototype' import sys -from time import time, gmtime, strftime +from time import time, localtime, strftime import gi gi.require_version('Gtk', '3.0') @@ -62,7 +62,7 @@ from gi.repository import GObject import gstconf -formatted_date = strftime('%Y_%m_%d', gmtime()) +formatted_date = strftime('%Y_%m_%d', localtime()) metadata = {'speaker_name':'NC', 'session_title':'NC', 'organisation':'NC',} @@ -142,14 +142,23 @@ class Streamgui(object): self.win.show_all() self.xid = self.videowidget.get_property('window').get_xid() - - self.pipel = gstconf.New_user_pipeline() + self.create_pipeline_instance() + + def create_pipeline_instance(self, feed='main'): + """Creates pipeline instance and attaches it to GUI.""" + self.pipel = gstconf.New_user_pipeline(feed) bus = gstconf.get_gstreamer_bus() bus.connect('sync-message::element', self.on_sync_message) bus.connect('message', self.on_message) - ## Try to use 'sync-message::element' instead of 'message'' - + # Try to use 'sync-message::element' instead of 'message' + + def create_backup_pipeline(self): + labelname = self.stream_button.get_label() + if labelname == 'ON AIR': + self.create_pipeline_instance(feed='backup') + self.pipel.stream_play() + def on_sync_message(self, bus, message): if message.get_structure().get_name() == 'prepare-window-handle': @@ -169,33 +178,27 @@ class Streamgui(object): # Watching for feed loss during streaming: t = message.type if t == Gst.MessageType.ERROR: - self.create_backup_pipeline() - #pass - - def create_backup_pipeline(self): - labelname = self.stream_button.get_label() - if labelname == 'ON AIR': - self.pipel = gstconf.New_user_pipeline(feed='backup',) - bus = gstconf.get_gstreamer_bus() - bus.connect('sync-message::element', self.on_sync_message) - self.pipel.stream_play() - print('[WARNING] Backup pipeline started.') + err, debug = message.parse_error() + if '(651)' not in debug: + self.pipel.stream_stop() + self.create_backup_pipeline() def on_stream_clicked(self, widget): labelname = self.stream_button.get_label() if labelname == 'Stream': + if self.pipel.feed == 'backup': + # Get back to main feed: + self.create_pipeline_instance() self.clean_entry_fields() self.pipel.stream_play() -## self.pipel.get_stream_state() self.stream_button.set_label('ON AIR') start_time = time() elif labelname == 'ON AIR': self.pipel.stream_stop() self.stream_button.set_label('Stream') ## self.build_filename() - - + ## In this state, this function freeze the streaming if the fields are NOT completed def build_filename(self): """Get text in entries, check if empty and apply formatting if needed.""" @@ -225,8 +228,8 @@ class Streamgui(object): self.speakerinfo_entry.set_text('') self.sessioninfo_entry.set_text('') - # Returns the meter deflection percentage given a db value def iec_scale(self, db): + """Returns the meter deflection percentage given a db value.""" pct = 0.0 if db < -70.0: -- 2.25.1