From 0d211ab04f7c262a7d926bb4fec636111bcf294d Mon Sep 17 00:00:00 2001 From: Aayush Ahuja Date: Sun, 7 Dec 2014 21:20:09 +0530 Subject: [PATCH 01/13] first commit --- console.py | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 console.py diff --git a/console.py b/console.py new file mode 100644 index 0000000..5cdf43e --- /dev/null +++ b/console.py @@ -0,0 +1,65 @@ +import sys +import os +sys.path.append(os.path.dirname(os.path.realpath(__file__)) + '/python-api') + +import gi +gi.require_version('Gst', '1.0') +from gi.repository import GObject, Gst + +GObject.threads_init() +Gst.init(None) +from gstswitch.server import Server +from gstswitch.helpers import * +from gstswitch.controller import Controller +import time + +import gi +gi.require_version('Gst', '1.0') +path = "tools/" +# s = Server(path) +try: + # s.run() # launches the server default parameters + video_port = 3000 + audio_port = 4000 + # connects a gstreamer module to view the output of the gst-switch-srv + # output = PreviewSinks() + # output.run() + # adding two test video sources + # sources = TestSources(video_port=video_port, audio_port=audio_port) + + # sources.new_test_audio() + # sources.new_test_audio() + + # sources.new_test_video() + # sources.new_test_video() + # sources.new_test_video(timeoverlay=True) + + controller = Controller() + controller.establish_connection() + res = [] + tests_get = [controller.get_compose_port, + controller.get_encode_port, + controller.get_audio_port, + controller.get_preview_ports, + ] + + test_set_composite_mode = controller.set_composite_mode + + # testing random 10 modes + for x in tests_get: + print x.__name__, x() + # time.sleep(1) + modes = [] + # for mode in modes: + # print 'composite mode=', mode + # test_set_composite_mode(mode) + # time.sleep(0.6) + output.terminate() + sources.terminate_video() + sources.terminate_audio() + # s.terminate() + +finally: + # if s.proc: + # s.kill() + pass From 296d13d9b3829f28947c1722ca97009257e8b93a Mon Sep 17 00:00:00 2001 From: Aayush Ahuja Date: Mon, 15 Dec 2014 09:22:17 +0530 Subject: [PATCH 02/13] Random console --- console.py | 84 +++++++++++++++++++++--------------------------------- 1 file changed, 32 insertions(+), 52 deletions(-) diff --git a/console.py b/console.py index 5cdf43e..57c1093 100644 --- a/console.py +++ b/console.py @@ -2,64 +2,44 @@ import os sys.path.append(os.path.dirname(os.path.realpath(__file__)) + '/python-api') -import gi -gi.require_version('Gst', '1.0') -from gi.repository import GObject, Gst - -GObject.threads_init() -Gst.init(None) from gstswitch.server import Server from gstswitch.helpers import * from gstswitch.controller import Controller -import time +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 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() -import gi -gi.require_version('Gst', '1.0') -path = "tools/" -# s = Server(path) -try: - # s.run() # launches the server default parameters - video_port = 3000 - audio_port = 4000 - # connects a gstreamer module to view the output of the gst-switch-srv - # output = PreviewSinks() - # output.run() - # adding two test video sources - # sources = TestSources(video_port=video_port, audio_port=audio_port) + def do_get_preview_ports(self, line): + self.c = Controller() + self.c.establish_connection() + print self.c.get_preview_ports() - # sources.new_test_audio() - # sources.new_test_audio() - - # sources.new_test_video() - # sources.new_test_video() - # sources.new_test_video(timeoverlay=True) + def do_set_composite_mode(self, line): + self.c = Controller() + self.c.establish_connection() + print self.c.set_composite_mode(int(line)) - controller = Controller() - controller.establish_connection() - res = [] - tests_get = [controller.get_compose_port, - controller.get_encode_port, - controller.get_audio_port, - controller.get_preview_ports, - ] - test_set_composite_mode = controller.set_composite_mode - # testing random 10 modes - for x in tests_get: - print x.__name__, x() - # time.sleep(1) - modes = [] - # for mode in modes: - # print 'composite mode=', mode - # test_set_composite_mode(mode) - # time.sleep(0.6) - output.terminate() - sources.terminate_video() - sources.terminate_audio() - # s.terminate() -finally: - # if s.proc: - # s.kill() - pass +if __name__ == '__main__': + con = Console() + con.cmdloop() From 51228b99fe3728b50cd1661d5085a317db725672 Mon Sep 17 00:00:00 2001 From: Aayush Ahuja Date: Wed, 7 Jan 2015 18:18:57 +1300 Subject: [PATCH 03/13] Prevent repeat calling of method supposed to run once --- configure.ac | 11 +++++++++++ tools/Makefile.am | 8 +++++++- tools/gstswitchcontroller.c | 32 +++++++++++++++----------------- 3 files changed, 33 insertions(+), 18 deletions(-) diff --git a/configure.ac b/configure.ac index a5b15bd..22ff70a 100644 --- a/configure.ac +++ b/configure.ac @@ -177,6 +177,17 @@ AC_ARG_ENABLE(speakertrack, [BUILD_SPEAKERTRACK=no]) AM_CONDITIONAL(SPEAKERTRACK_ENABLED, test "x$BUILD_SPEAKERTRACK" = "xyes") +AC_ARG_ENABLE(debug, +AS_HELP_STRING([--enable-debug], + [enable debugging, default: no]), +[case "${enableval}" in + yes) debug=true ;; + no) debug=false ;; + *) AC_MSG_ERROR([bad value ${enableval} for --enable-debug]) ;; +esac], +[debug=false]) + +AM_CONDITIONAL(DEBUG, test x"$debug" = x"true") dnl FIXME: Add the Python-API as an option here dnl === Output ================================================================ diff --git a/tools/Makefile.am b/tools/Makefile.am index 731f530..29343c3 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -15,11 +15,17 @@ GCOV_CFLAGS = GCOV_LFLAGS = endif +if DEBUG +AM_CFLAGS = -g3 -O0 +else +AM_CFLAGS = -O2 +endif + gst_switch_srv_SOURCES = gstworker.c gstswitchserver.c gstcase.c \ gstcomposite.c gstswitchcontroller.c gstrecorder.c \ gio/gsocketinputstream.c gst_switch_srv_CFLAGS = $(GST_CFLAGS) $(GST_BASE_CFLAGS) $(GCOV_CFLAGS) \ - $(GST_PLUGINS_BASE_CFLAGS) -DLOG_PREFIX="\"./tools\"" + $(AM_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS) -DLOG_PREFIX="\"./tools\"" gst_switch_srv_LDFLAGS = $(GCOV_LFLAGS) $(GST_LIBS) $(GST_BASE_LIBS) \ $(GST_PLUGINS_BASE_LIBS) $(GSTPB_BASE_LIBS) gst_switch_srv_LDADD = $(GIO_LIBS) $(LIBM) diff --git a/tools/gstswitchcontroller.c b/tools/gstswitchcontroller.c index d58f5a5..b9d4f76 100644 --- a/tools/gstswitchcontroller.c +++ b/tools/gstswitchcontroller.c @@ -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; } } @@ -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; } @@ -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; @@ -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; } @@ -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) { From 4fd311b588d1ac1a51c2e004f4492cf52569e557 Mon Sep 17 00:00:00 2001 From: Aayush Ahuja Date: Wed, 7 Jan 2015 18:51:44 +1300 Subject: [PATCH 04/13] Remove debug enabling --- configure.ac | 11 ----------- tools/Makefile.am | 8 +------- 2 files changed, 1 insertion(+), 18 deletions(-) diff --git a/configure.ac b/configure.ac index 22ff70a..a5b15bd 100644 --- a/configure.ac +++ b/configure.ac @@ -177,17 +177,6 @@ AC_ARG_ENABLE(speakertrack, [BUILD_SPEAKERTRACK=no]) AM_CONDITIONAL(SPEAKERTRACK_ENABLED, test "x$BUILD_SPEAKERTRACK" = "xyes") -AC_ARG_ENABLE(debug, -AS_HELP_STRING([--enable-debug], - [enable debugging, default: no]), -[case "${enableval}" in - yes) debug=true ;; - no) debug=false ;; - *) AC_MSG_ERROR([bad value ${enableval} for --enable-debug]) ;; -esac], -[debug=false]) - -AM_CONDITIONAL(DEBUG, test x"$debug" = x"true") dnl FIXME: Add the Python-API as an option here dnl === Output ================================================================ diff --git a/tools/Makefile.am b/tools/Makefile.am index 29343c3..731f530 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -15,17 +15,11 @@ GCOV_CFLAGS = GCOV_LFLAGS = endif -if DEBUG -AM_CFLAGS = -g3 -O0 -else -AM_CFLAGS = -O2 -endif - gst_switch_srv_SOURCES = gstworker.c gstswitchserver.c gstcase.c \ gstcomposite.c gstswitchcontroller.c gstrecorder.c \ gio/gsocketinputstream.c gst_switch_srv_CFLAGS = $(GST_CFLAGS) $(GST_BASE_CFLAGS) $(GCOV_CFLAGS) \ - $(AM_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS) -DLOG_PREFIX="\"./tools\"" + $(GST_PLUGINS_BASE_CFLAGS) -DLOG_PREFIX="\"./tools\"" gst_switch_srv_LDFLAGS = $(GCOV_LFLAGS) $(GST_LIBS) $(GST_BASE_LIBS) \ $(GST_PLUGINS_BASE_LIBS) $(GSTPB_BASE_LIBS) gst_switch_srv_LDADD = $(GIO_LIBS) $(LIBM) From a8333f238b3183acdebe26a70e7372e6ec4bb492 Mon Sep 17 00:00:00 2001 From: Aayush Ahuja Date: Sun, 7 Dec 2014 21:20:09 +0530 Subject: [PATCH 05/13] first commit --- console.py | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 console.py diff --git a/console.py b/console.py new file mode 100644 index 0000000..5cdf43e --- /dev/null +++ b/console.py @@ -0,0 +1,65 @@ +import sys +import os +sys.path.append(os.path.dirname(os.path.realpath(__file__)) + '/python-api') + +import gi +gi.require_version('Gst', '1.0') +from gi.repository import GObject, Gst + +GObject.threads_init() +Gst.init(None) +from gstswitch.server import Server +from gstswitch.helpers import * +from gstswitch.controller import Controller +import time + +import gi +gi.require_version('Gst', '1.0') +path = "tools/" +# s = Server(path) +try: + # s.run() # launches the server default parameters + video_port = 3000 + audio_port = 4000 + # connects a gstreamer module to view the output of the gst-switch-srv + # output = PreviewSinks() + # output.run() + # adding two test video sources + # sources = TestSources(video_port=video_port, audio_port=audio_port) + + # sources.new_test_audio() + # sources.new_test_audio() + + # sources.new_test_video() + # sources.new_test_video() + # sources.new_test_video(timeoverlay=True) + + controller = Controller() + controller.establish_connection() + res = [] + tests_get = [controller.get_compose_port, + controller.get_encode_port, + controller.get_audio_port, + controller.get_preview_ports, + ] + + test_set_composite_mode = controller.set_composite_mode + + # testing random 10 modes + for x in tests_get: + print x.__name__, x() + # time.sleep(1) + modes = [] + # for mode in modes: + # print 'composite mode=', mode + # test_set_composite_mode(mode) + # time.sleep(0.6) + output.terminate() + sources.terminate_video() + sources.terminate_audio() + # s.terminate() + +finally: + # if s.proc: + # s.kill() + pass From 54a4aed9d9c5c7a57659a00a3b4405191fcef175 Mon Sep 17 00:00:00 2001 From: Aayush Ahuja Date: Mon, 15 Dec 2014 09:22:17 +0530 Subject: [PATCH 06/13] Random console --- console.py | 84 +++++++++++++++++++++--------------------------------- 1 file changed, 32 insertions(+), 52 deletions(-) diff --git a/console.py b/console.py index 5cdf43e..57c1093 100644 --- a/console.py +++ b/console.py @@ -2,64 +2,44 @@ import os sys.path.append(os.path.dirname(os.path.realpath(__file__)) + '/python-api') -import gi -gi.require_version('Gst', '1.0') -from gi.repository import GObject, Gst - -GObject.threads_init() -Gst.init(None) from gstswitch.server import Server from gstswitch.helpers import * from gstswitch.controller import Controller -import time +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 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() -import gi -gi.require_version('Gst', '1.0') -path = "tools/" -# s = Server(path) -try: - # s.run() # launches the server default parameters - video_port = 3000 - audio_port = 4000 - # connects a gstreamer module to view the output of the gst-switch-srv - # output = PreviewSinks() - # output.run() - # adding two test video sources - # sources = TestSources(video_port=video_port, audio_port=audio_port) + def do_get_preview_ports(self, line): + self.c = Controller() + self.c.establish_connection() + print self.c.get_preview_ports() - # sources.new_test_audio() - # sources.new_test_audio() - - # sources.new_test_video() - # sources.new_test_video() - # sources.new_test_video(timeoverlay=True) + def do_set_composite_mode(self, line): + self.c = Controller() + self.c.establish_connection() + print self.c.set_composite_mode(int(line)) - controller = Controller() - controller.establish_connection() - res = [] - tests_get = [controller.get_compose_port, - controller.get_encode_port, - controller.get_audio_port, - controller.get_preview_ports, - ] - test_set_composite_mode = controller.set_composite_mode - # testing random 10 modes - for x in tests_get: - print x.__name__, x() - # time.sleep(1) - modes = [] - # for mode in modes: - # print 'composite mode=', mode - # test_set_composite_mode(mode) - # time.sleep(0.6) - output.terminate() - sources.terminate_video() - sources.terminate_audio() - # s.terminate() -finally: - # if s.proc: - # s.kill() - pass +if __name__ == '__main__': + con = Console() + con.cmdloop() From 6e5efcea0f34b17d8f83d1c94677bfb94dde4f07 Mon Sep 17 00:00:00 2001 From: Aayush Ahuja Date: Wed, 7 Jan 2015 19:40:26 +1300 Subject: [PATCH 07/13] Renaming composite modes in API --- python-api/gstswitch/controller.py | 6 ++++-- python-api/tests/integrationtests/compare.py | 8 ++++---- .../tests/integrationtests/test_controller.py | 19 +++++++++++++++---- .../tests/unittests/test_controller_unit.py | 4 ++-- 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/python-api/gstswitch/controller.py b/python-api/gstswitch/controller.py index 8e2a6d2..8937853 100644 --- a/python-api/gstswitch/controller.py +++ b/python-api/gstswitch/controller.py @@ -213,9 +213,11 @@ def set_composite_mode(self, mode): """ self.establish_connection() # only modes from 0 to 3 are supported - if mode >= 0 and mode <= 3: + mode_map = {'NONE': 0, 'PIP': 1, 'DUAL_PREVIEW': 2, 'DUAL_EQUAL': 3} + res = None + if mode in mode_map: try: - conn = self.connection.set_composite_mode(mode) + conn = self.connection.set_composite_mode(mode_map[mode]) print conn res = conn.unpack()[0] if res is True: diff --git a/python-api/tests/integrationtests/compare.py b/python-api/tests/integrationtests/compare.py index 48d80d4..6cfbdab 100644 --- a/python-api/tests/integrationtests/compare.py +++ b/python-api/tests/integrationtests/compare.py @@ -32,10 +32,10 @@ class BaseCompareVideo(object): """Base class containing image operations""" TESTS = { - 'composite_mode_0': 0, - 'composite_mode_1': 1, - 'composite_mode_2': 2, - 'composite_mode_3': 3, + 'composite_mode_NONE': 0, + 'composite_mode_PIP': 1, + 'composite_mode_DUAL_PREVIEW': 2, + 'composite_mode_DUAL_EQUAL': 3, 'adjust_pip_4': 4 } REF_FRAME_DIR = os.getcwd() + '/tests/integrationtests/reference_frames' diff --git a/python-api/tests/integrationtests/test_controller.py b/python-api/tests/integrationtests/test_controller.py index 41d049e..f34f7a3 100644 --- a/python-api/tests/integrationtests/test_controller.py +++ b/python-api/tests/integrationtests/test_controller.py @@ -306,7 +306,7 @@ def set_composite_mode(self, mode, generate_frames=False): sources.terminate_video() serv.terminate(1) if not generate_frames: - if mode == 3: + if mode == 'DUAL_EQUAL': assert res is False else: assert res is True @@ -343,10 +343,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('NONE') + + def test_set_composite_mode_pip(self): + """Test set_composite_mode""" + self.set_composite_mode('PIP') + + def test_set_composite_mode_preview(self): + """Test set_composite_mode""" + self.set_composite_mode('DUAL_PREVIEW') + + def test_set_composite_mode_equal(self): + """Test set_composite_mode""" + self.set_composite_mode('DUAL_EQUAL') class TestNewRecord(object): diff --git a/python-api/tests/unittests/test_controller_unit.py b/python-api/tests/unittests/test_controller_unit.py index 199beaa..3650931 100644 --- a/python-api/tests/unittests/test_controller_unit.py +++ b/python-api/tests/unittests/test_controller_unit.py @@ -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('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('NONE') is True class TestSetEncodeMode(object): From 55d651ca698d6fb6441021842afa2b0b3f92ee9f Mon Sep 17 00:00:00 2001 From: Aayush Ahuja Date: Wed, 7 Jan 2015 19:57:26 +1300 Subject: [PATCH 08/13] fix adjust_pip test --- python-api/tests/integrationtests/test_controller.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python-api/tests/integrationtests/test_controller.py b/python-api/tests/integrationtests/test_controller.py index f34f7a3..8087010 100644 --- a/python-api/tests/integrationtests/test_controller.py +++ b/python-api/tests/integrationtests/test_controller.py @@ -436,7 +436,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('PIP') time.sleep(3) res = controller.adjust_pip(xpos, ypos, width, heigth) time.sleep(3) From 4be7a9472b2e7b78ba51736c6e7e869aa091f16d Mon Sep 17 00:00:00 2001 From: Aayush Ahuja Date: Wed, 7 Jan 2015 20:16:59 +1300 Subject: [PATCH 09/13] Console script uses renamed API --- console.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/console.py b/console.py index 57c1093..08acec8 100644 --- a/console.py +++ b/console.py @@ -35,7 +35,7 @@ def do_get_preview_ports(self, line): def do_set_composite_mode(self, line): self.c = Controller() self.c.establish_connection() - print self.c.set_composite_mode(int(line)) + print self.c.set_composite_mode(line) From 471a59c0d1f1681a01a718676a95b0478e7c4ba5 Mon Sep 17 00:00:00 2001 From: Aayush Ahuja Date: Wed, 7 Jan 2015 22:00:39 +1300 Subject: [PATCH 10/13] Better naming of composite modes --- python-api/gstswitch/controller.py | 19 ++++++++++++++----- python-api/tests/integrationtests/compare.py | 8 ++++---- .../tests/integrationtests/test_controller.py | 17 +++++++++++------ .../tests/unittests/test_controller_unit.py | 4 ++-- 4 files changed, 31 insertions(+), 17 deletions(-) diff --git a/python-api/gstswitch/controller.py b/python-api/gstswitch/controller.py index 8937853..7568fe1 100644 --- a/python-api/gstswitch/controller.py +++ b/python-api/gstswitch/controller.py @@ -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, @@ -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: @@ -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 """ diff --git a/python-api/tests/integrationtests/compare.py b/python-api/tests/integrationtests/compare.py index 6cfbdab..48d80d4 100644 --- a/python-api/tests/integrationtests/compare.py +++ b/python-api/tests/integrationtests/compare.py @@ -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' diff --git a/python-api/tests/integrationtests/test_controller.py b/python-api/tests/integrationtests/test_controller.py index 8087010..7d9bb6d 100644 --- a/python-api/tests/integrationtests/test_controller.py +++ b/python-api/tests/integrationtests/test_controller.py @@ -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 @@ -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): @@ -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) diff --git a/python-api/tests/unittests/test_controller_unit.py b/python-api/tests/unittests/test_controller_unit.py index 3650931..394d100 100644 --- a/python-api/tests/unittests/test_controller_unit.py +++ b/python-api/tests/unittests/test_controller_unit.py @@ -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): From 2984fb184e3dbd058fb60766b74526ef34c67b65 Mon Sep 17 00:00:00 2001 From: Aayush Ahuja Date: Wed, 7 Jan 2015 23:50:58 +1300 Subject: [PATCH 11/13] Help methods on console script --- console.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/console.py b/console.py index 08acec8..e63ddc4 100644 --- a/console.py +++ b/console.py @@ -1,3 +1,10 @@ +""" +Usage - + + `python console.py` + (Cmd)help + +""" import sys import os sys.path.append(os.path.dirname(os.path.realpath(__file__)) + '/python-api') @@ -17,6 +24,9 @@ def do_get_compose_port(self, line): 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() From 21177f9d5b61dd13bf927bae4fb5a1c8ae3bdbf1 Mon Sep 17 00:00:00 2001 From: Aayush Ahuja Date: Thu, 8 Jan 2015 00:59:32 +1300 Subject: [PATCH 12/13] Cleaning Up --- .gitignore | 3 +++ console.py | 2 +- python-api/Makefile | 3 +++ python-api/gstswitch/server.py | 2 +- python-api/tests/integrationtests/test_controller.py | 6 +++--- python-api/tests/unittests/test_server_unit.py | 6 +++--- 6 files changed, 14 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index c77dee7..11d7cf9 100644 --- a/.gitignore +++ b/.gitignore @@ -67,6 +67,9 @@ imgurbash.sh.* /transition-strips /record*.dat *.data +*.data.* +*.avi +*.avi.* *.log /tools/gst-switch-ptz test-driver diff --git a/console.py b/console.py index e63ddc4..7ac7dbb 100644 --- a/console.py +++ b/console.py @@ -45,7 +45,7 @@ def do_get_preview_ports(self, line): def do_set_composite_mode(self, line): self.c = Controller() self.c.establish_connection() - print self.c.set_composite_mode(line) + print self.c.set_composite_mode(int(line)) diff --git a/python-api/Makefile b/python-api/Makefile index 07ae2c8..cdbb1c6 100644 --- a/python-api/Makefile +++ b/python-api/Makefile @@ -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 diff --git a/python-api/gstswitch/server.py b/python-api/gstswitch/server.py index b7f6d42..2c30fe6 100644 --- a/python-api/gstswitch/server.py +++ b/python-api/gstswitch/server.py @@ -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__() diff --git a/python-api/tests/integrationtests/test_controller.py b/python-api/tests/integrationtests/test_controller.py index 7d9bb6d..e6bf0d5 100644 --- a/python-api/tests/integrationtests/test_controller.py +++ b/python-api/tests/integrationtests/test_controller.py @@ -382,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() @@ -394,8 +394,8 @@ def test_new_record(self): 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) + test_filename = "test-{0}.data".format(time_str) + alt_test_filename = "test-{0}.data".format(alt_time_str) res = self.new_record() print res diff --git a/python-api/tests/unittests/test_server_unit.py b/python-api/tests/unittests/test_server_unit.py index b938f2a..f98fd14 100644 --- a/python-api/tests/unittests/test_server_unit.py +++ b/python-api/tests/unittests/test_server_unit.py @@ -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""" @@ -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""" @@ -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): From c6c83c712ac85a4bf09b91ed675ef7c87b5f980f Mon Sep 17 00:00:00 2001 From: Aayush Ahuja Date: Thu, 8 Jan 2015 11:25:58 +1300 Subject: [PATCH 13/13] Fix record file format --- python-api/gstswitch/server.py | 2 +- python-api/tests/integrationtests/test_controller.py | 6 +++--- python-api/tests/unittests/test_server_unit.py | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/python-api/gstswitch/server.py b/python-api/gstswitch/server.py index 2c30fe6..6cf6d3a 100644 --- a/python-api/gstswitch/server.py +++ b/python-api/gstswitch/server.py @@ -40,7 +40,7 @@ def __init__( video_port=3000, audio_port=4000, control_port=5000, - record_file='record-%Y-%m-%d %H%M%S.data'): + record_file='record-%Y-%m-%d_%H%M%S.data'): super(Server, self).__init__() diff --git a/python-api/tests/integrationtests/test_controller.py b/python-api/tests/integrationtests/test_controller.py index e6bf0d5..64fe36b 100644 --- a/python-api/tests/integrationtests/test_controller.py +++ b/python-api/tests/integrationtests/test_controller.py @@ -382,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-%Y-%m-%d %H%M%S.data") + serv = Server(path=PATH, record_file="test-%Y-%m-%d_%H%M%S.data") try: serv.run() @@ -392,8 +392,8 @@ 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') + 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) diff --git a/python-api/tests/unittests/test_server_unit.py b/python-api/tests/unittests/test_server_unit.py index f98fd14..0892ef9 100644 --- a/python-api/tests/unittests/test_server_unit.py +++ b/python-api/tests/unittests/test_server_unit.py @@ -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-%Y-%m-%d %H%M%S.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""" @@ -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-%Y-%m-%d %H%M%S.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""" @@ -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-%Y-%m-%d %H%M%S.data".split() +--control-port=5000 --record=record-%Y-%m-%d_%H%M%S.data".split() class TestVideoPort(object):