Skip to content

Commit

Permalink
Better naming of composite modes
Browse files Browse the repository at this point in the history
  • Loading branch information
hyades committed Jan 7, 2015
1 parent 4be7a94 commit 471a59c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 17 deletions.
19 changes: 14 additions & 5 deletions python-api/gstswitch/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ class Controller(object):
:param: None
"""
COMPOSITE_NONE = 0
COMPOSITE_PIP = 1
COMPOSITE_DUAL_PREVIEW = 2
COMPOSITE_DUAL_EQUAL = 3

def __init__(
self,
Expand Down Expand Up @@ -206,18 +210,22 @@ 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
mode_map = {'NONE': 0, 'PIP': 1, 'DUAL_PREVIEW': 2, 'DUAL_EQUAL': 3}
res = None
if mode in mode_map:
if mode in range(0, 4):
try:
conn = self.connection.set_composite_mode(mode_map[mode])
conn = self.connection.set_composite_mode(mode)
print conn
res = conn.unpack()[0]
if res is True:
Expand Down Expand Up @@ -295,7 +303,8 @@ 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:
'A', 'B', 'a'
:param port: The target port number
:returns: True when requested
"""
Expand Down
8 changes: 4 additions & 4 deletions python-api/tests/integrationtests/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ class BaseCompareVideo(object):
"""Base class containing image operations"""

TESTS = {
'composite_mode_NONE': 0,
'composite_mode_PIP': 1,
'composite_mode_DUAL_PREVIEW': 2,
'composite_mode_DUAL_EQUAL': 3,
'composite_mode_0': 0,
'composite_mode_1': 1,
'composite_mode_2': 2,
'composite_mode_3': 3,
'adjust_pip_4': 4
}
REF_FRAME_DIR = os.getcwd() + '/tests/integrationtests/reference_frames'
Expand Down
17 changes: 11 additions & 6 deletions python-api/tests/integrationtests/test_controller.py
Original file line number Diff line number Diff line change
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 == 'DUAL_EQUAL':
controller = Controller()
if mode == controller.COMPOSITE_DUAL_EQUAL:
assert res is False
else:
assert res is True
Expand Down Expand Up @@ -345,19 +346,23 @@ def verify_output(self, mode, video):

def test_set_composite_mode_none(self):
"""Test set_composite_mode"""
self.set_composite_mode('NONE')
controller = Controller()
self.set_composite_mode(controller.COMPOSITE_NONE)

def test_set_composite_mode_pip(self):
"""Test set_composite_mode"""
self.set_composite_mode('PIP')
controller = Controller()
self.set_composite_mode(controller.COMPOSITE_PIP)

def test_set_composite_mode_preview(self):
"""Test set_composite_mode"""
self.set_composite_mode('DUAL_PREVIEW')
controller = Controller()
self.set_composite_mode(controller.COMPOSITE_DUAL_PREVIEW)

def test_set_composite_mode_equal(self):
"""Test set_composite_mode"""
self.set_composite_mode('DUAL_EQUAL')
controller = Controller()
self.set_composite_mode(controller.COMPOSITE_DUAL_EQUAL)


class TestNewRecord(object):
Expand Down Expand Up @@ -436,7 +441,7 @@ def adjust_pip(self,
sources.new_test_video(pattern=4)
sources.new_test_video(pattern=5)
controller = Controller()
controller.set_composite_mode('PIP')
controller.set_composite_mode(controller.COMPOSITE_PIP)
time.sleep(3)
res = controller.adjust_pip(xpos, ypos, width, heigth)
time.sleep(3)
Expand Down
4 changes: 2 additions & 2 deletions python-api/tests/unittests/test_controller_unit.py
Original file line number Diff line number Diff line change
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('NONE')
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('NONE') is True
assert controller.set_composite_mode(controller.COMPOSITE_NONE) is True


class TestSetEncodeMode(object):
Expand Down

0 comments on commit 471a59c

Please sign in to comment.