Skip to content

Commit

Permalink
Merge c6c83c7 into 6e7d900
Browse files Browse the repository at this point in the history
  • Loading branch information
hyades committed Jan 7, 2015
2 parents 6e7d900 + c6c83c7 commit cb1c5fe
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 36 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -67,6 +67,9 @@ imgurbash.sh.*
/transition-strips
/record*.dat
*.data
*.data.*
*.avi
*.avi.*
*.log
/tools/gst-switch-ptz
test-driver
55 changes: 55 additions & 0 deletions console.py
@@ -0,0 +1,55 @@
"""
Usage -
`python console.py`
(Cmd)help
"""
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):

def do_get_compose_port(self, line):
self.c = Controller()
self.c.establish_connection()
print self.c.get_compose_port()

def help_get_compose_port(self):
print "Get the Compose Port"

def do_get_encode_port(self, line):
self.c = Controller()
self.c.establish_connection()
print self.c.get_encode_port()

def do_get_audio_port(self, line):
self.c = Controller()
self.c.establish_connection()
print self.c.get_audio_port()

def do_get_preview_ports(self, line):
self.c = Controller()
self.c.establish_connection()
print self.c.get_preview_ports()

def do_set_composite_mode(self, line):
self.c = Controller()
self.c.establish_connection()
print self.c.set_composite_mode(int(line))




if __name__ == '__main__':
con = Console()
con.cmdloop()
3 changes: 3 additions & 0 deletions python-api/Makefile
Expand Up @@ -46,6 +46,9 @@ clean:
rm -rf .cache
rm -rf reports
rm -f *.data
rm -f *.avi
rm -f *.avi.*
rm -f *.data.*
rm -f tests/integrationtests/*.data
rm -f *.log
rm -f *.html
Expand Down
17 changes: 14 additions & 3 deletions python-api/gstswitch/controller.py
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,14 +210,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 +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
2 changes: 1 addition & 1 deletion python-api/gstswitch/server.py
Expand Up @@ -40,7 +40,7 @@ def __init__(
video_port=3000,
audio_port=4000,
control_port=5000,
record_file='record.data'):
record_file='record-%Y-%m-%d_%H%M%S.data'):

super(Server, self).__init__()

Expand Down
36 changes: 26 additions & 10 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,25 @@ 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)
controller = Controller()
self.set_composite_mode(controller.COMPOSITE_NONE)

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

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

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


class TestNewRecord(object):
Expand All @@ -366,7 +382,7 @@ def new_record(self):
def test_new_record(self):
"""Test new_record"""
for _ in range(self.NUM):
serv = Server(path=PATH, record_file="test.data")
serv = Server(path=PATH, record_file="test-%Y-%m-%d_%H%M%S.data")
try:
serv.run()

Expand All @@ -376,10 +392,10 @@ def test_new_record(self):

curr_time = datetime.datetime.now()
alt_curr_time = curr_time + datetime.timedelta(0, 1)
time_str = curr_time.strftime('%Y-%m-%d %H%M%S')
alt_time_str = alt_curr_time.strftime('%Y-%m-%d %H%M%S')
test_filename = "test {0}.data".format(time_str)
alt_test_filename = "test {0}.data".format(alt_time_str)
time_str = curr_time.strftime('%Y-%m-%d_%H%M%S')
alt_time_str = alt_curr_time.strftime('%Y-%m-%d_%H%M%S')
test_filename = "test-{0}.data".format(time_str)
alt_test_filename = "test-{0}.data".format(alt_time_str)

res = self.new_record()
print res
Expand Down Expand Up @@ -425,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(1)
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
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
6 changes: 3 additions & 3 deletions python-api/tests/unittests/test_server_unit.py
Expand Up @@ -29,7 +29,7 @@ def mock_method(arg):
serv._start_process = mock_method
assert serv._run_process().split() == "/usr/gst-switch-srv \
--video-input-port=3000 --audio-input-port=4000 \
--control-port=5000 --record=record.data".split()
--control-port=5000 --record=record-%Y-%m-%d_%H%M%S.data".split()

def test_path_provided_no_slash(self):
"""Test if a path is provided"""
Expand All @@ -41,7 +41,7 @@ def mock_method(arg):
serv._start_process = mock_method
assert serv._run_process().split() == "/usr/gst-switch-srv \
--video-input-port=3000 --audio-input-port=4000 \
--control-port=5000 --record=record.data".split()
--control-port=5000 --record=record-%Y-%m-%d_%H%M%S.data".split()

def test_path_empty(self, monkeypatch):
"""Test if null path is given"""
Expand All @@ -60,7 +60,7 @@ def mockreturn(path):
serv._start_process = mock_method
assert serv._run_process().split() == "/usr/gst-switch-srv \
--video-input-port=3000 --audio-input-port=4000 \
--control-port=5000 --record=record.data".split()
--control-port=5000 --record=record-%Y-%m-%d_%H%M%S.data".split()


class TestVideoPort(object):
Expand Down
32 changes: 15 additions & 17 deletions tools/gstswitchcontroller.c
Expand Up @@ -355,20 +355,18 @@ gst_switch_controller_add_new_client (GstSwitchAddNewClientParams * params)
GDBusConnection *connection = params->connection;
GstSwitchController *controller = params->controller;
gint role = CLIENT_ROLE_NONE;
{
gint tests[] = { CLIENT_ROLE_UI, CLIENT_ROLE_CAPTURE, };
GVariant *parameters = NULL, *res = NULL;
int n = 0;
for (; n < sizeof (tests); ++n) {
role = CLIENT_ROLE_NONE;
parameters = g_variant_new ("()");
res = gst_switch_controller_call_client (controller,
connection, tests[n], "role", parameters, G_VARIANT_TYPE ("(i)"));
if (res) {
g_variant_get (res, "(i)", &role);
g_variant_unref (res);
break;
}
gint tests[] = { CLIENT_ROLE_UI, CLIENT_ROLE_CAPTURE, };
GVariant *parameters = NULL, *res = NULL;
int n = 0;
for (; n < sizeof (tests); ++n) {
role = CLIENT_ROLE_NONE;
parameters = g_variant_new ("()");
res = gst_switch_controller_call_client (controller,
connection, tests[n], "role", parameters, G_VARIANT_TYPE ("(i)"));
if (res) {
g_variant_get (res, "(i)", &role);
g_variant_unref (res);
break;
}
}

Expand Down Expand Up @@ -434,7 +432,7 @@ gst_switch_controller_on_new_connection (GDBusServer * server,
params->connection = connection;
g_object_ref (connection);

g_timeout_add (500, (GSourceFunc) gst_switch_controller_add_new_client,
g_timeout_add (100000, (GSourceFunc) gst_switch_controller_add_new_client,
params);
return TRUE;
}
Expand Down Expand Up @@ -550,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 @@ -582,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 @@ -599,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 cb1c5fe

Please sign in to comment.