forked from timvideos/gst-switch
-
Notifications
You must be signed in to change notification settings - Fork 1
/
helpers.py
121 lines (105 loc) · 4.03 KB
/
helpers.py
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
from testsource import VideoSrc, Preview
from exception import RangeError
__all__ = ["TestSources", "PreviewSinks"]
class TestSources(object):
"""A Controller of test sources feeding into the
gst-switch-srv
:param width: The width of the output video
:param height: The height of the output video
:param pattern: The videotestsrc pattern of the output video
:param timeoverlay: True to enable a running time over video
:param clockoverlay: True to enable current clock time over video
"""
def __init__(self, video_port):
super(TestSources, self).__init__()
self.running_tests = []
self.video_port = video_port
@property
def video_port(self):
return self._video_port
@video_port.setter
def video_port(self, video_port):
if not video_port:
raise ValueError("video_port: '{0}' cannot be blank"
.format(video_port))
else:
try:
i = int(video_port)
if i < 1 or i > 65535:
raise RangeError('video_port must be in range 1 to 65535')
else:
self._video_port = video_port
except TypeError:
raise TypeError("video_port must be a string or number,"
"not, '{0}'".format(type(video_port)))
except ValueError:
raise TypeError("Port must be a valid number")
def new_test_video(self,
width=300,
height=200,
pattern=None,
timeoverlay=False,
clockoverlay=False):
"""Start a new test video
:param port: The port of where the TCP stream will be sent
Should be same as video port of gst-switch-src
:param width: The width of the output video
:param height: The height of the output video
:param pattern: The videotestsrc pattern of the output video
:param timeoverlay: True to enable a running time over video
:param clockoverlay: True to enable current clock time over video
"""
testsrc = VideoSrc(
self.video_port,
width,
height,
pattern,
timeoverlay,
clockoverlay)
testsrc.run()
self.running_tests.append(testsrc)
def get_test_video(self):
"""Returns a list of processes acting as video test sources running
:returns: A list containing all video test sources running
"""
i = 0
for test in self.running_tests:
print i, "pattern:", test.pattern
i += 1
return self.running_tests
def terminate_index(self, index):
"""Terminate video test source specified by index
:param index: The index of the video source to terminate
Use get_test_video for finding the index
"""
testsrc = self.running_tests[index]
print 'End source with pattern %s' % (str(testsrc.pattern))
testsrc.end()
self.running_tests.remove(self.running_tests[index])
def terminate(self):
"""Terminate all test video sources
"""
print 'TESTS:', self.running_tests
for i in range(len(self.running_tests)):
self.terminate_index(0)
class PreviewSinks(object):
"""A Controller for preview sinks to preview ports of gst-switch-srv
:param preview_port: The preview port to get the preview
"""
# TODO set preview port from dbus call
def __init__(self, preview_port=3001):
super(PreviewSinks, self).__init__()
self.preview_port = preview_port
def run(self):
"""Run the Preview Sink"""
self.preview = Preview(self.preview_port)
self.preview.run()
print 'start preview'
def terminate(self):
"""End/Terminate the Preview Sink"""
try:
self.preview.end()
print 'end preview'
# TODO: Find which error may occur
except OSError:
raise