From 340ab727b4eb373ac7c072b855d62634f1b93aa1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20Test=C3=A9?= Date: Mon, 29 Feb 2016 23:19:00 +0100 Subject: [PATCH] Implementing filename creation for each stream launched. --- stream_2016/gstconf.py | 30 +++++++++++++++++++++++--- stream_2016/libre-streamer.py | 40 ++++++++++++++++++++++++++++++----- 2 files changed, 62 insertions(+), 8 deletions(-) diff --git a/stream_2016/gstconf.py b/stream_2016/gstconf.py index ce9f0a7..050200f 100755 --- a/stream_2016/gstconf.py +++ b/stream_2016/gstconf.py @@ -17,11 +17,21 @@ # # Copyright (c) 2016 David Testé +from os import rename + import gi from gi.repository import Gst from gi.repository import GstVideo +# Pathname has to be defined +PATHNAME = '' +AUDIO_DEFAULT = PATHNAME + 'AUDIO_DEFAULT' +RAWVIDEO_DEFAULT = PATHNAME + 'RAWVIDEO_DEFAULT' +STREAM_DEFAULT = PATHNAME + 'STREAM_DEFAULT' + + class New_user_pipeline(): + def __init__(self): self.user_pipeline = self.create_gstreamer_pipeline() @@ -50,11 +60,11 @@ class New_user_pipeline(): """Create storable output elements.""" self.disksink_rawvideo = Gst.ElementFactory.make('filesink') #[TO DO]: File location has to be defined - self.disksink_rawvideo.set_property('location', 'popo_rawvideo') + self.disksink_rawvideo.set_property('location', RAWVIDEO_DEFAULT) self.disksink_audio = Gst.ElementFactory.make('filesink') - self.disksink_audio.set_property('location', 'popo_audio') + self.disksink_audio.set_property('location', AUDIO_DEFAULT) self.disksink_stream = Gst.ElementFactory.make('filesink') - self.disksink_stream.set_property('location', 'popo_stream') + self.disksink_stream.set_property('location', STREAM_DEFAULT) def create_streamsink(self): """Create streamable output elements.""" @@ -300,6 +310,20 @@ class New_user_pipeline(): def get_stream_state(self): print(self.streampipe.get_state(self)) ## return self.streampipe.get_state() + + def set_filenames(self, string): + """Sets filename and location for each sink.""" + filename = string + audio = PATHNAME + filename + '_AUDIO' + rawvideo = PATHNAME + filename + '_RAWVIDEO' + stream = PATHNAME + filename + '_STREAM' + rename(AUDIO_DEFAULT, audio) + rename(RAWVIDEO_DEFAULT, rawvideo) + rename(STREAM_DEFAULT, stream) +## self.disksink_audio.set_property('location', audio) +## self.disksink_rawvideo.set_property('location', rawvideo) +## self.disksink_stream.set_property('location', stream) def get_gstreamer_bus(): return bus + \ No newline at end of file diff --git a/stream_2016/libre-streamer.py b/stream_2016/libre-streamer.py index 7fbd2a1..eaad46d 100755 --- a/stream_2016/libre-streamer.py +++ b/stream_2016/libre-streamer.py @@ -94,8 +94,8 @@ class Streamgui(object): self.speakerinfo_entry = Gtk.Entry() self.sessioninfo_label = Gtk.Label('Session name: ') self.sessioninfo_entry = Gtk.Entry() - self.organisationinfo_label = Gtk.Label('Organisation name: ') - self.organisationinfo_entry = Gtk.Entry() +## self.organisationinfo_label = Gtk.Label('Organisation name: ') +## self.organisationinfo_entry = Gtk.Entry() self.stream_button = Gtk.Button("Stream") self.stream_button.connect("clicked", self.on_stream_clicked) @@ -105,11 +105,11 @@ class Streamgui(object): vbox_labels.pack_start(self.baseinfo_label, True, True, 0) vbox_labels.pack_start(self.speakerinfo_label, True, True, 0) vbox_labels.pack_start(self.sessioninfo_label, True, True, 0) - vbox_labels.pack_start(self.organisationinfo_label, True, True, 0) +## vbox_labels.pack_start(self.organisationinfo_label, True, True, 0) vbox_entries.pack_start(self.baseinfo_entry_label, True, True, 0) vbox_entries.pack_start(self.speakerinfo_entry, True, True, 0) vbox_entries.pack_start(self.sessioninfo_entry, True, True, 0) - vbox_entries.pack_start(self.organisationinfo_entry, True, True, 0) +## vbox_entries.pack_start(self.organisationinfo_entry, True, True, 0) vbox_streaminfo.pack_start(self.stream_button, False, True, 15) hbox_time.pack_start(self.streamtime_label, False, False, 0) hbox_time.pack_start(self.streamtime_value, False, False, 0) @@ -141,7 +141,8 @@ class Streamgui(object): def on_stream_clicked(self, widget): labelname = self.stream_button.get_label() - if labelname == 'Stream': + if labelname == 'Stream': + self.clean_entry_fields() self.pipel.stream_play() ## self.pipel.get_stream_state() self.stream_button.set_label('ON AIR') @@ -149,6 +150,35 @@ class Streamgui(object): elif labelname == 'ON AIR': self.pipel.stream_stop() self.stream_button.set_label('Stream') + self.build_filename() + + def build_filename(self): + """Get text in entries, check if empty and apply formatting if needed.""" + sep = '_' + base = self.baseinfo_entry_label.get_text() + speaker = self.speakerinfo_entry.get_text() + speaker = sep.join(speaker.split()) + session = self.sessioninfo_entry.get_text() + session = sep.join(session.split()) + raw_filename = base + sep + speaker + sep + session + maxlen = 70 + has_all_fields = False + while not has_all_fields: + if speaker and session: + if len(raw_filename) <= maxlen: + has_all_fields = True + else: + offset = len(raw_filename) - maxlen + raw_filename = raw_filename[:-offset] + has_all_fields = True + else: + pass + # One of the field is empty, open a dialogbox to ask for filling the field + self.pipel.set_filenames(raw_filename) + + def clean_entry_fields(self): + self.speakerinfo_entry.set_text('') + self.sessioninfo_entry.set_text('') ## Use threads to refresh the time elapsed sinc the begining of the stream?? def time_elapsed(self, widget): -- 2.25.1