forked from duzy/gst-switch
-
Notifications
You must be signed in to change notification settings - Fork 10
/
console.py
106 lines (80 loc) · 2.73 KB
/
console.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
"""
Usage -
`python console.py`
(Cmd)help
Autocompletions should work...
"""
import sys
import os
sys.path.append(os.path.dirname(os.path.realpath(__file__)) + '/python-api')
from gstswitch.server import Server
from gstswitch.helpers import *
from gstswitch.controller import Controller
import cmd
import inspect
class Console(cmd.Cmd):
COMPOSITE_MAPPING = {
'none': Controller.COMPOSITE_NONE,
'pip': Controller.COMPOSITE_PIP,
'dual_preview': Controller.COMPOSITE_DUAL_PREVIEW,
'preview': Controller.COMPOSITE_DUAL_PREVIEW,
'equal': Controller.COMPOSITE_DUAL_EQUAL,
'dual_equal': Controller.COMPOSITE_DUAL_EQUAL
}
SWITCH_MAPPING = {
'video-A': Controller.VIDEO_CHANNEL_A,
'video-B': Controller.VIDEO_CHANNEL_B,
'audio': Controller.AUDIO_CHANNEL
}
def do_get_compose_port(self, line):
c = Controller()
c.establish_connection()
print c.get_compose_port()
def help_get_compose_port(self):
print "Get the Compose Port"
def do_get_encode_port(self, line):
c = Controller()
c.establish_connection()
print c.get_encode_port()
def do_get_audio_port(self, line):
c = Controller()
c.establish_connection()
print c.get_audio_port()
def do_get_preview_ports(self, line):
c = Controller()
c.establish_connection()
print c.get_preview_ports()
def do_set_composite_mode(self, line):
try:
val = self.COMPOSITE_MAPPING[line.lower()]
except KeyError:
print "Invalid"
return
c = Controller()
c.establish_connection()
print c.set_composite_mode(val)
def help_set_composite_mode(self):
print "Valid modes - {0}".format(", ".join([i for i in self.COMPOSITE_MAPPING]))
def complete_set_composite_mode(self, text, line, begidx, endidx):
return [i for i in self.COMPOSITE_MAPPING if i.startswith(text)]
def do_adjust_pip(self, line):
c = Controller()
c.establish_connection()
if len(line.split()) != 4:
print "Inavlid number of arguments"
return
print c.adjust_pip(*map(int, line.split()))
def do_switch(self, line):
try:
val = self.SWITCH_MAPPING[line.lower()]
except KeyError:
print "Invalid"
return
c = Controller()
c.establish_connection()
print c.switch(self.SWITCH_MAPPING[line.split()[0]], int(line.split()[1]))
def complete_switch(self, text, line, begidx, endidx):
return [i for i in self.SWITCH_MAPPING if i.startswith(text)]
if __name__ == '__main__':
con = Console()
con.cmdloop()