forked from timvideos/gst-switch
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created separate helpers class. Removed logging
- Loading branch information
Showing
4 changed files
with
98 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import os | ||
import sys | ||
import signal | ||
import subprocess | ||
from gi.repository import Gio | ||
from testsource import VideoSrc, Preview | ||
|
||
|
||
class TestSources(object): | ||
"""A Controller of test sources feeding into the | ||
gst-switch-srv""" | ||
|
||
def __init__(self, video_port): | ||
super(TestSources, self).__init__() | ||
self.TESTS = [] | ||
self.set_video_port(video_port) | ||
|
||
def set_video_port(self, video_port): | ||
self.VIDEO_PORT = video_port | ||
|
||
def get_video_port(self): | ||
return self.VIDEO_PORT | ||
|
||
def new_test_video(self, width=300, height=200, pattern=None, timeoverlay=False, clockoverlay=False): | ||
"""Start a new test source | ||
""" | ||
print 'Adding new test video source' | ||
testsrc = VideoSrc(self.get_video_port(), width, height, pattern, timeoverlay, clockoverlay) | ||
if testsrc is None: | ||
pass | ||
self.TESTS.append(testsrc) | ||
|
||
def get_test_video(self): | ||
"""Returns a list of processes acting as test inputs | ||
""" | ||
i = 0 | ||
for x in self.TESTS: | ||
print i, "pattern:", x.pattern | ||
i += 1 | ||
return self.TESTS | ||
|
||
def terminate_index(self, index): | ||
""" | ||
""" | ||
testsrc = self.TESTS[index] | ||
print 'End source with pattern %s' % (str(testsrc.get_pattern())) | ||
testsrc.end() | ||
self.TESTS.remove(self.TESTS[index]) | ||
|
||
def terminate(self): | ||
""" | ||
""" | ||
print 'TESTS:', self.TESTS | ||
for x in range(len(self.TESTS)): | ||
self.terminate_index(0) | ||
|
||
|
||
class PreviewSinks(object): | ||
"""docstring for PreviewSinks | ||
""" | ||
def __init__(self): | ||
super(PreviewSinks, self).__init__() | ||
self.PREVIEW_PORT = 3001 | ||
# TODO set preview port from dbus call | ||
|
||
def start(self): | ||
self.preview = Preview(self.PREVIEW_PORT) | ||
self.preview.run() | ||
print 'start preview' | ||
|
||
def terminate(self): | ||
try: | ||
self.preview.end() | ||
print 'end preview' | ||
except: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
#!/usr/bin/env python | ||
from gstswitch import * | ||
from time import sleep | ||
# import subprocess | ||
from helpers import TestSources, PreviewSinks | ||
|
||
# all executables (gst-launch-1.0, gst-switch-srv, gst-switch-ui, gst-switch-cap) at this path | ||
path = '/home/hyades/gst/master/gstreamer/tools/' | ||
# os.chdir(path) | ||
print "starting server" | ||
s = Server(path) | ||
try: | ||
s.run() # launches the server default parameters | ||
sleep(0.5) | ||
cmd = path | ||
port = s.get_video_port() | ||
# connects a gstreamer module to view the output of the gst-switch-srv | ||
s.start_preview() | ||
output = PreviewSinks() | ||
output.start() | ||
# adding two test video sources | ||
s.new_test_video() | ||
s.new_test_video(clockoverlay=True) | ||
sources = TestSources(port) | ||
sources.new_test_video() | ||
sources.new_test_video(timeoverlay=True) | ||
# waiting till user ends the server | ||
raw_input() | ||
s.end() | ||
sources.terminate() | ||
output.terminate() | ||
s.terminate() | ||
finally: | ||
s.brute_end() | ||
s.kill() |