Skip to content

Commit

Permalink
Merge branches
Browse files Browse the repository at this point in the history
  • Loading branch information
hyades committed Jan 12, 2015
2 parents f3698c5 + 0a465a9 commit 6c37688
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 16 deletions.
103 changes: 103 additions & 0 deletions console.py
@@ -0,0 +1,103 @@
"""
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 = {
'video1': Controller.SWITCH_VIDEO_1,
'video2': Controller.SWITCH_VIDEO_2,
'audio': Controller.SWITCH_AUDIO
}

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"
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
print c.adjust_pip(*map(int, line.split()))

def do_switch(self, line):
try:
val = self.SWITCH_MAPPING[line.lower()]
except KeyError:
print "Invalid"
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()
1 change: 0 additions & 1 deletion python-api/Makefile
Expand Up @@ -17,7 +17,6 @@ unittests:
@rm -rf reports
@mkdir -p reports/coverage/unittests
py.test --cov gstswitch tests/unittests/ --pep8 -v -s
@make clean

pep8:
pep8 gstswitch
Expand Down
22 changes: 19 additions & 3 deletions python-api/gstswitch/controller.py
Expand Up @@ -18,6 +18,13 @@ class Controller(object):
:param: None
"""
COMPOSITE_NONE = 0
COMPOSITE_PIP = 1
COMPOSITE_DUAL_PREVIEW = 2
COMPOSITE_DUAL_EQUAL = 3
SWITCH_VIDEO_1 = ord('A')
SWITCH_VIDEO_2 = ord('B')
SWITCH_AUDIO = ord('a')

def __init__(
self,
Expand Down Expand Up @@ -206,14 +213,20 @@ def get_preview_ports(self):
'Should return a GVariant tuple')

def set_composite_mode(self, mode):
"""Set the current composite mode. Modes between 0 and 3 are allowed.
"""Set the current composite mode.
Modes allowed are:
- COMPOSITE_NONE
- COMPOSITE_PIP
- COMPOSITE_DUAL_PREVIEW
- COMPOSITE_DUAL_EQUAL
:param mode: new composite mode
:returns: True when requested
"""
self.establish_connection()
# only modes from 0 to 3 are supported
if mode >= 0 and mode <= 3:
res = None
if mode in range(0, 4):
try:
conn = self.connection.set_composite_mode(mode)
print conn
Expand Down Expand Up @@ -293,7 +306,10 @@ def adjust_pip(self, xpos, ypos, width, height):
def switch(self, channel, port):
"""Switch the channel to the target port
:param channel: The channel to be switched, 'A', 'B', 'a'
:param channel: The channel to be switched:
SWITCH_VIDEO_1
SWITCH_VIDEO_2
SWITCH_AUDIO
:param port: The target port number
:returns: True when requested
"""
Expand Down
24 changes: 18 additions & 6 deletions python-api/tests/integrationtests/test_controller.py
Expand Up @@ -306,7 +306,8 @@ def set_composite_mode(self, mode, generate_frames=False):
sources.terminate_video()
serv.terminate(1)
if not generate_frames:
if mode == 3:
controller = Controller()
if mode == Controller.COMPOSITE_DUAL_EQUAL:
assert res is False
else:
assert res is True
Expand Down Expand Up @@ -343,10 +344,21 @@ def verify_output(self, mode, video):
return True
return False

def test_set_composite_mode(self):
def test_set_composite_mode_none(self):
"""Test set_composite_mode"""
for i in range(4):
self.set_composite_mode(i)
self.set_composite_mode(Controller.COMPOSITE_NONE)

def test_set_composite_mode_pip(self):
"""Test set_composite_mode"""
self.set_composite_mode(Controller.COMPOSITE_PIP)

def test_set_composite_mode_preview(self):
"""Test set_composite_mode"""
self.set_composite_mode(Controller.COMPOSITE_DUAL_PREVIEW)

def test_set_composite_mode_equal(self):
"""Test set_composite_mode"""
self.set_composite_mode(Controller.COMPOSITE_DUAL_EQUAL)


class TestNewRecord(object):
Expand Down Expand Up @@ -421,7 +433,7 @@ def adjust_pip(self,
sources.new_test_video(pattern=4)
sources.new_test_video(pattern=5)
controller = Controller()
controller.set_composite_mode(1)
controller.set_composite_mode(Controller.COMPOSITE_PIP)
time.sleep(3)
res = controller.adjust_pip(xpos, ypos, width, heigth)
time.sleep(3)
Expand Down Expand Up @@ -513,7 +525,7 @@ def switch(self, channel, port, index):
def test_switch(self):
"""Test switch"""
dic = [
[65, 3004]
[Controller.SWITCH_VIDEO_1, 3004]
]
start = 5
for i in range(start, 6):
Expand Down
8 changes: 4 additions & 4 deletions python-api/tests/unittests/test_controller_unit.py
Expand Up @@ -284,14 +284,14 @@ def test_unpack(self):
controller.establish_connection = Mock(return_value=None)
controller.connection = MockConnection(True)
with pytest.raises(ConnectionReturnError):
controller.set_composite_mode(1)
controller.set_composite_mode(Controller.COMPOSITE_NONE)

def test_normal_unpack(self):
"""Test if valid"""
controller = Controller(address='unix:abstract=abcdef')
controller.establish_connection = Mock(return_value=None)
controller.connection = MockConnection(False)
assert controller.set_composite_mode(1) is True
assert controller.set_composite_mode(Controller.COMPOSITE_NONE) is True


class TestSetEncodeMode(object):
Expand Down Expand Up @@ -364,14 +364,14 @@ def test_unpack(self):
controller.establish_connection = Mock(return_value=None)
controller.connection = MockConnection(True)
with pytest.raises(ConnectionReturnError):
controller.switch(1, 2)
controller.switch(Controller.SWITCH_VIDEO_1, 2)

def test_normal_unpack(self):
"""Test if valid"""
controller = Controller(address='unix:abstract=abcdef')
controller.establish_connection = Mock(return_value=None)
controller.connection = MockConnection(False)
assert controller.switch(1, 2) is True
assert controller.switch(Controller.SWITCH_VIDEO_1, 2) is True


class TestClickVideo(object):
Expand Down
4 changes: 2 additions & 2 deletions tools/gstswitchcontroller.c
Expand Up @@ -548,6 +548,7 @@ gst_switch_controller_call_client (GstSwitchController * controller,
GDBusConnection * connection, gint role, const gchar * method_name,
GVariant * parameters, const GVariantType * reply_type)
{

GVariant *value = NULL;
GError *error = NULL;

Expand Down Expand Up @@ -580,7 +581,7 @@ gst_switch_controller_call_client (GstSwitchController * controller,
g_variant_unref (value);
return NULL;
}
g_assert (value != NULL);
// g_assert (value != NULL);

return value;
}
Expand All @@ -597,7 +598,6 @@ gst_switch_controller_call_clients (GstSwitchController * controller,
GDBusConnection *connection;
GVariant *value;
GList *ui, *clients = NULL;

g_variant_ref_sink (parameters);

switch (role) {
Expand Down

0 comments on commit 6c37688

Please sign in to comment.