Modifying filename building.
authorDavid Testé <soonum@gnu.org>
Tue, 8 Mar 2016 22:17:47 +0000 (23:17 +0100)
committerDavid Testé <soonum@gnu.org>
Tue, 8 Mar 2016 22:17:47 +0000 (23:17 +0100)
stream_2016/gstconf.py

index ab93f1d501aabffd2f64268f7a364a3f86c4ccaa..fd8dc3e5c2df7da6a78e418733229ec4bc6381f8 100755 (executable)
@@ -31,6 +31,8 @@ AUDIO_DEFAULT = PATHNAME + 'AUDIO_DEFAULT'
 RAWVIDEO_DEFAULT = PATHNAME + 'RAWVIDEO_DEFAULT'
 STREAM_DEFAULT = PATHNAME + 'STREAM_DEFAULT'
 BACKUP_SUFFIX = '_BACKUP'
+FAILED_SUFFIX = '_FAILED_'
+fail_counter = 1
 AUDIO_BACKUP = AUDIO_DEFAULT + BACKUP_SUFFIX
 RAWVIDEO_BACKUP = RAWVIDEO_DEFAULT + BACKUP_SUFFIX
 STREAM_BACKUP = STREAM_DEFAULT + BACKUP_SUFFIX
@@ -46,10 +48,7 @@ class New_user_pipeline():
     
     def __init__(self, feed='main'):
         self.feed = feed
-##        if self.feed == 'main':
         self.user_pipeline = self.create_gstreamer_pipeline()
-##        elif self.feed == 'backup':
-##            self.user_pipeline = self.create_gstreamer_pipeline(feed='backup')
             
     def create_video_sources(self):
         """Create video inputs from various sources."""
@@ -95,7 +94,6 @@ class New_user_pipeline():
     def create_audio_sources(self):
         """Create audio inputs from various sources."""
         self.audiosrc = Gst.ElementFactory.make('pulsesrc', 'audiosrc')
-##        self.videosrc.set_property('latency', 0)
         self.audiosrc.set_property('device', AUDIO_INPUT)
 
     def create_audiolevel_plugin(self):
@@ -112,7 +110,11 @@ class New_user_pipeline():
         self.disksink_audio.set_property('location', AUDIO_DEFAULT)
         self.disksink_stream = Gst.ElementFactory.make('filesink')
         self.disksink_stream.set_property('location', STREAM_DEFAULT)
-        
+        if self.feed == 'backup':
+            self.disksink_rawvideo.set_property('location', RAWVIDEO_BACKUP)
+            self.disksink_audio.set_property('location', AUDIO_BACKUP)
+            self.disksink_stream.set_property('location', STREAM_BACKUP)
+            
     def create_streamsink(self):
         """Create streamable output elements."""
         # To local screen:
@@ -405,25 +407,44 @@ class New_user_pipeline():
         self.streampipe.set_state(Gst.State.NULL)
         print(INFO, gettime(), 'STOPPED State resquested')
         
-    def get_stream_state(self):
-        print(self.streampipe.get_state(self))
-##[FIXME]        return self.streampipe.get_state()
-        
-    def set_filenames(self, string):
+    def set_filenames(self, string, streamfailed=False):
         """Sets filename and location for each sink."""
+        global fail_counter
         filename = string
         audio = PATHNAME + filename + '_AUDIO'
         rawvideo = PATHNAME + filename + '_RAWVIDEO'
         stream = PATHNAME + filename + '_STREAM'
+        print('FEED STATE: ', self.feed) 
         if self.feed == 'main':
-            rename(AUDIO_DEFAULT, audio)
-            rename(RAWVIDEO_DEFAULT, rawvideo)
-            rename(STREAM_DEFAULT, stream)
+            if streamfailed and filename:
+                audio = audio + FAILED_SUFFIX + str(fail_counter)
+                rawvideo = rawvideo + FAILED_SUFFIX + str(fail_counter)
+                stream = stream + FAILED_SUFFIX + str(fail_counter)
+                rename(AUDIO_DEFAULT, audio)
+                rename(RAWVIDEO_DEFAULT, rawvideo)
+                rename(STREAM_DEFAULT, stream)
+                fail_counter += 1
+            elif streamfailed:
+                audio = AUDIO_DEFAULT + FAILED_SUFFIX + str(fail_counter)
+                rawvideo = RAWVIDEO_DEFAULT + FAILED_SUFFIX + str(fail_counter)
+                stream = STREAM_DEFAULT + FAILED_SUFFIX + str(fail_counter)
+                rename(AUDIO_DEFAULT, audio)
+                rename(RAWVIDEO_DEFAULT, rawvideo)
+                rename(STREAM_DEFAULT, stream)
+                fail_counter += 1
+            else:
+                rename(AUDIO_DEFAULT, audio)
+                rename(RAWVIDEO_DEFAULT, rawvideo)
+                rename(STREAM_DEFAULT, stream)
         elif self.feed == 'backup':
+            print('INSIDE BACKUP RENAMING')
             rename(AUDIO_BACKUP, audio)
             rename(RAWVIDEO_BACKUP, rawvideo)
             rename(STREAM_BACKUP, stream)
 
+        def rename_files():
+            pass
+
 def get_gstreamer_bus():
     return bus