summaryrefslogtreecommitdiff
path: root/voctocore/experiments
diff options
context:
space:
mode:
authorMaZderMind <github@mazdermind.de>2014-08-05 22:05:38 +0200
committerMaZderMind <github@mazdermind.de>2014-08-05 22:05:38 +0200
commit82a2030e26eed6501f98c442ac28aa89407b26b5 (patch)
treedbea17ca36df7e782b84c8427cba106aef61ef80 /voctocore/experiments
parent800f2e4bca2a8c04784aa4eac1a4f64dd5edc57a (diff)
use a appsrc to get more control over the socket
Diffstat (limited to 'voctocore/experiments')
-rwxr-xr-xvoctocore/experiments/failovertest.py69
1 files changed, 47 insertions, 22 deletions
diff --git a/voctocore/experiments/failovertest.py b/voctocore/experiments/failovertest.py
index 3149197..5ebaa9a 100755
--- a/voctocore/experiments/failovertest.py
+++ b/voctocore/experiments/failovertest.py
@@ -1,7 +1,10 @@
#!/usr/bin/python3
import gi
+import time
import signal
+from http.client import HTTPConnection
from termcolor import colored
+from threading import Timer, Thread
# import GStreamer and GTK-Helper classes
gi.require_version('Gst', '1.0')
@@ -12,38 +15,60 @@ GObject.threads_init()
Gst.init(None)
loop = GLib.MainLoop()
-def busfunc(bus, message):
- print(colored(message.src.get_name(), 'green'), message.type, message)
- if message.type == Gst.MessageType.ERROR:
- (err, debug) = message.parse_error()
- print(colored(err, 'red'))
- print(colored(debug, 'yellow'))
-
- if message.src.get_name() == 'http':
- failover = p.get_by_name('failover')
- failover.set_property('active-pad', failover.get_static_pad('sink_1'))
-
# make killable by ctrl-c
signal.signal(signal.SIGINT, signal.SIG_DFL)
-print("parse_launch")
+# parse_launch
p = Gst.parse_launch("""
input-selector name=failover ! autovideosink
- videotestsrc ! video/x-raw,width=1280,height=720 ! failover.sink_1
- souphttpsrc name=http location="http://localhost/~peter/ED_1280.avi" ! decodebin ! failover.sink_0
+ appsrc name=src blocksize=4096 is-live=true block=true ! multipartdemux name=demux ! jpegparse ! jpegdec ! videoconvert ! failover.sink_1
+ videotestsrc ! video/x-raw,width=500,height=375 ! failover.sink_0
""")
-print("add_watch")
-bus = p.get_bus()
-bus.add_signal_watch()
-bus.connect('message', busfunc)
+def failsafeVideoSource():
+ src = p.get_by_name('src')
+ dec = p.get_by_name('dec')
+ demux = p.get_by_name('demux')
+ failover = p.get_by_name('failover')
+ srcActive = True
+
+ while True:
+ print('connecting to framegrabber')
+ try:
+ con = HTTPConnection('beachcam.kdhnc.com', 80, timeout=3)
+ req = con.request('GET', '/mjpg/video.mjpg?camera=1')
+ res = con.getresponse()
+ srcActive = True
+
+ print('connected, switching to video')
+ failover.set_property('active-pad', failover.get_static_pad('sink_1'))
+
+ while srcActive:
+ chunk = res.read(4094)
+ chunklen = len(chunk)
+ print('read ', len(chunk), ' of ', 4096, ', closed=', res.isclosed())
+
+ if chunklen > 0:
+ src.emit('push-buffer', Gst.Buffer.new_wrapped(chunk))
+ else:
+ srcActive = False
+ except:
+ print('exception')
+ srcActive = False
+
+ print('switching to failsave')
+ failover.set_property('active-pad', failover.get_static_pad('sink_0'))
+
+ print('sleeping before retry')
+ time.sleep(1)
-# print("add_watch")
-# httpbus = p.get_by_name('http').get_bus()
-# httpbus.add_watch(0, busfunc, None)
+fsThread = Thread(target=failsafeVideoSource)
+fsThread.deamon = True
+fsThread.start()
-print("set_state(PLAYING)")
+# set playing
p.set_state(Gst.State.PLAYING)
+# start mainloop
loop.run()