Repository navigation
Expand file tree
/
Copy pathsyncstream.py
More file actions
executable file
·98 lines (75 loc) · 2.53 KB
/
Copy pathsyncstream.py
File metadata and controls
executable file
·98 lines (75 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/python3
import gi, signal, logging, sys
# import GStreamer and GLib-Helper classes
gi.require_version('Gst', '1.0')
from gi.repository import Gst, GObject, GstNet
# check min-version
minGst = (1, 0)
minPy = (3, 0)
Gst.init([])
if Gst.version() < minGst:
raise Exception("GStreamer version", Gst.version(), 'is too old, at least', minGst, 'is required')
if sys.version_info < minPy:
raise Exception("Python version", sys.version_info, 'is too old, at least', minPy, 'is required')
# init GObject & Co. before importing local classes
GObject.threads_init()
# import local classes
from lib.args import Args
from lib.pipeline import Pipeline, TCPSource
from lib.netclock import NetClock
from lib.loghandler import LogHandler
from lib.mainloop import MainLoop
# main class
class SyncStream(object):
def __init__(self):
self.log = logging.getLogger('SyncStream')
# initialize subsystem
self.log.debug('creating A/V-Pipeline')
self.pipeline = Pipeline()
self.source = TCPSource(9999)
self.netclock = NetClock(self.pipeline, None, 10000)
self.do_run = True
def run(self):
self.pipeline.configure()
self.pipeline.start()
self.netclock.start()
self.do_run = True
self.log.info('running GObject-MainLoop')
MainLoop.run()
def quit(self):
self.do_run = False
self.log.info('stopping Pipeline')
self.pipeline.stop()
self.log.info('quitting GObject-MainLoop')
MainLoop.quit()
def reload(self):
self.log.info('reloading pipeline')
self.pipeline.stop()
self.pipeline.configure()
self.pipeline.start()
# run mainclass
def main():
# configure logging
docolor = (Args.color == 'always') or (Args.color == 'auto' and sys.stderr.isatty())
handler = LogHandler(docolor)
logging.root.addHandler(handler)
if Args.verbose >= 2:
level = logging.DEBUG
elif Args.verbose == 1:
level = logging.INFO
else:
level = logging.WARNING
level = logging.DEBUG
logging.root.setLevel(level)
# make killable by ctrl-c
logging.debug('setting SIGINT handler')
signal.signal(signal.SIGINT, signal.SIG_DFL)
logging.info('Python Version: %s', sys.version_info)
logging.info('GStreamer Version: %s', Gst.version())
# init main-class and main-loop
logging.debug('initializing SyncStream')
syncstream = SyncStream()
logging.debug('running SyncStream')
syncstream.run()
if __name__ == '__main__':
main()