Skip to content

Commit

Permalink
Merge pull request #183 from MaZderMind/dbus-tcp
Browse files Browse the repository at this point in the history
Dbus tcp
  • Loading branch information
mithro committed Jan 25, 2015
2 parents 42cdae4 + de77871 commit 47600c7
Show file tree
Hide file tree
Showing 21 changed files with 89 additions and 153 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -167,7 +167,7 @@ Application Options:
-r, --record=FILENAME Enable recorder and record into the specified FILENAME
-p, --video-input-port=NUM Specify the video input listen port.
-a, --audio-input-port=NUM Specify the audio input listen port.
--control-port=NUM Specify the control port.
-c, --controller-address=ADDRESS Specify DBus-Address for remote control, defaults to tcp:host=0.0.0.0,port=5000.
```

### Video Input
Expand Down
4 changes: 2 additions & 2 deletions python-api/gstswitch/connection.py
Expand Up @@ -15,15 +15,15 @@ class Connection(object):
"""Class which makes all remote object class.
Deals with lower level connection and remote method invoking
:default bus-address: unix:abstract=gstswitch
:default bus-address: tcp:host=127.0.0.1,port=5000
:param: None
"""
CONNECTION_FLAGS = Gio.DBusConnectionFlags.AUTHENTICATION_CLIENT

def __init__(
self,
address="unix:abstract=gstswitch",
address="tcp:host=127.0.0.1,port=5000",
bus_name='info.duzy.gst.switch.SwitchController',
object_path="/info/duzy/gst/switch/SwitchController",
default_interface=("info.duzy.gst.switch."
Expand Down
2 changes: 1 addition & 1 deletion python-api/gstswitch/controller.py
Expand Up @@ -28,7 +28,7 @@ class Controller(object):

def __init__(
self,
address="unix:abstract=gstswitch",
address="tcp:host=127.0.0.1,port=5000",
bus_name='info.duzy.gst.switch.SwitchController',
object_path="/info/duzy/gst/switch/SwitchController",
default_interface="info.duzy.gst.switch.SwitchControllerInterface"
Expand Down
54 changes: 28 additions & 26 deletions python-api/gstswitch/server.py
Expand Up @@ -28,7 +28,8 @@ class Server(object):
By default looks in the current $PATH.
:param video_port: The video port number - default = 3000
:param audio_port: The audio port number - default = 4000
:param control_port: The control port number - default = 5000
:param controller_address: The DBus-Address for remote control -
default = tcp:host=0.0.0.0,port=5000
:param record_file: The record file format
:returns: nothing
"""
Expand All @@ -39,22 +40,22 @@ def __init__(
path=None,
video_port=3000,
audio_port=4000,
control_port=5000,
controller_address='tcp:host=0.0.0.0,port=5000',
record_file=False):

super(Server, self).__init__()

self._path = None
self._video_port = None
self._audio_port = None
self._control_port = None
self._controller_address = None
self._record_file = None
self.gst_option_string = ''

self.path = path
self.video_port = video_port
self.audio_port = audio_port
self.control_port = control_port
self.controller_address = controller_address
self.record_file = record_file

self.proc = None
Expand Down Expand Up @@ -125,31 +126,32 @@ def audio_port(self, audio_port):
" not '{0}'".format(type(audio_port)))

@property
def control_port(self):
def controller_address(self):
"""Get the control port"""
return self._control_port

@control_port.setter
def control_port(self, control_port):
"""Set Control Port
:raises ValueError: Control Port cannot be left blank
:raises ValueError: Control Port must be in range 1 to 65535
:raises TypeError: Control Port must be a string or a number
return self._controller_address

@controller_address.setter
def controller_address(self, controller_address):
"""Set Control Address
:raises ValueError: Control Address cannot be left blank
:raises ValueError: Control Address must contain at least one Colon
:raises TypeError: Control Address must be a string
"""
if not control_port:
raise ValueError("Control Port '{0}' cannot be blank"
.format(control_port))
if not controller_address:
raise ValueError("Control Address '{0}' cannot be blank"
.format(controller_address))
else:
if not isinstance(controller_address, basestring):
raise TypeError("Control Address must be a string,"
" not '{0}'".format(type(controller_address)))

try:
i = int(control_port)
if i < 1 or i > 65535:
raise ValueError(
'Control Port must be in range 1 to 65535')
else:
self._control_port = control_port
except TypeError:
raise TypeError("Control Port must be a string or a number,"
" not '{0}'".format(type(control_port)))
controller_address.index(':')
self._controller_address = controller_address
except ValueError:
raise ValueError("Control Address must contain at least "
" one Colon. It is '{0}'" \
.format(controller_address))

@property
def record_file(self):
Expand Down Expand Up @@ -215,7 +217,7 @@ def _run_process(self):
cmd += [self.gst_option_string]
cmd.append("--video-input-port={0}".format(self.video_port))
cmd.append("--audio-input-port={0}".format(self.audio_port))
cmd.append("--control-port={0}".format(self.control_port))
cmd.append("--controller-address={0}".format(self.controller_address))
if self.record_file is False:
pass
elif self.record_file is True:
Expand Down
2 changes: 1 addition & 1 deletion python-api/scripts/dbusConnect.py
Expand Up @@ -13,7 +13,7 @@ def main():
loop.run()

if __name__=="__main__":
os.environ["DBUS_SESSION_BUS_ADDRESS"] = "unix:abstract=gstswitch"
os.environ["DBUS_SESSION_BUS_ADDRESS"] = "tcp:host=127.0.0.1,port=5000"
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
main()

4 changes: 2 additions & 2 deletions python-api/scripts/dbusConnect.sh
@@ -1,10 +1,10 @@
dbus-send \
--address="unix:abstract=gstswitch" \
--address="tcp:host=127.0.0.1,port=5000" \
--print-reply=literal \
--dest="info.duzy.gst_switch.SwitchClientInterface" \
/info/duzy/gst_switch/SwitchController \
info.duzy.gst_switch.SwitchControllerInterface.get_compose_port

gdbus introspect --address unix:abstract=gstswitch \
gdbus introspect --address tcp:host=127.0.0.1,port=5000 \
--dest info.duzy.gst.switch.SwitchUIInterface \
--object-path /info/duzy/gst/switch/SwitchUI
2 changes: 1 addition & 1 deletion python-api/scripts/dbusConnect2.py
@@ -1,7 +1,7 @@
from gi.repository import Gio, GLib
from time import sleep

address = "unix:abstract=gstswitch"
address = "tcp:host=127.0.0.1,port=5000"
name = None
object_path = "/info/duzy/gst/switch/SwitchController"

Expand Down
2 changes: 1 addition & 1 deletion python-api/scripts/dbusConnection3.py
@@ -1,7 +1,7 @@
from gi.repository import Gio, GLib
from time import sleep

address = "unix:abstract=gstswitch"
address = "tcp:host=127.0.0.1,port=5000"
name = None
object_path = "/info/duzy/gst/switch/SwitchController"

Expand Down
2 changes: 1 addition & 1 deletion python-api/tests/unittests/test_connection_unit.py
Expand Up @@ -29,7 +29,7 @@ def test_address_colon(self):

def test_address_normal(self):
""""Test if address is valid"""
address = ['unix:abstract=gstswitch', 'unix:temp=/tmp/abcd/xyz']
address = ['tcp:host=127.0.0.1,port=5000', 'unix:temp=/tmp/abcd/xyz']
for addr in address:
conn = Connection(address=addr)
assert conn.address == addr
Expand Down
2 changes: 1 addition & 1 deletion python-api/tests/unittests/test_controller_unit.py
Expand Up @@ -30,7 +30,7 @@ def test_address_colon(self):

def test_address_normal(self):
"""Test if address is valid"""
address = ['unix:abstract=gstswitch', 'unix:temp=/tmp/abcd/xyz']
address = ['tcp:host=127.0.0.1,port=5000', 'unix:temp=/tmp/abcd/xyz']
for addr in address:
conn = Controller(address=addr)
assert conn.address == addr
Expand Down
49 changes: 25 additions & 24 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() == "/usr/gst-switch-srv \
--video-input-port=3000 --audio-input-port=4000 \
--control-port=5000".split()
--controller-address=tcp:host=0.0.0.0,port=5000".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() == "/usr/gst-switch-srv \
--video-input-port=3000 --audio-input-port=4000 \
--control-port=5000".split()
--controller-address=tcp:host=0.0.0.0,port=5000".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() == "/usr/gst-switch-srv \
--video-input-port=3000 --audio-input-port=4000 \
--control-port=5000".split()
--controller-address=tcp:host=0.0.0.0,port=5000".split()


class TestVideoPort(object):
Expand Down Expand Up @@ -119,32 +119,32 @@ def test_invalid_audio_port_range(self):
Server(path=PATH, audio_port=audio_port)


class TestControlPort(object):
class TestControllerAddress(object):

"""Test the control_port parameter"""
# Control Port Tests
"""Test the controller_address parameter"""
# Control Address Tests

def test_invalid_control_port_null(self):
def test_invalid_controller_address_null(self):
"""Test when the control port is null"""
control_ports = [None, '', [], {}]
for control_port in control_ports:
controller_addresses = [None, '', [], {}]
for controller_address in controller_addresses:
with pytest.raises(ValueError):
Server(path=PATH, control_port=control_port)
Server(path=PATH, controller_address=controller_address)

def test_invalid_control_port_type(self):
def test_invalid_controller_address_type(self):
"""Test when the control port is not a valid
integral value"""
control_ports = [[1, 2, 3], {1: 2, 2: 3}]
for control_port in control_ports:
controller_addresses = [[1, 2, 3], {1: 2, 2: 3}]
for controller_address in controller_addresses:
with pytest.raises(TypeError):
Server(path=PATH, control_port=control_port)
Server(path=PATH, controller_address=controller_address)

def test_invalid_control_port_range(self):
"""Test when the control port is not in range"""
control_ports = [-99, -1, 1e6]
for control_port in control_ports:
def test_invalid_controller_address_range(self):
"""Test when the control port does not contain a colon"""
controller_addresses = ['42', 'port=42', '127.0.0.1']
for controller_address in controller_addresses:
with pytest.raises(ValueError):
Server(path=PATH, control_port=control_port)
Server(path=PATH, controller_address=controller_address)


class TestRecordFile(object):
Expand All @@ -162,7 +162,7 @@ def mock_method(arg):
serv._start_process = mock_method
assert serv._run_process() == "/usr/gst-switch-srv \
--video-input-port=3000 --audio-input-port=4000 \
--control-port=5000".split()
--controller-address=tcp:host=0.0.0.0,port=5000".split()

def test_record_file_true(self):
"""Test if record file is True"""
Expand All @@ -174,7 +174,7 @@ def mock_method(arg):
serv._start_process = mock_method
assert serv._run_process() == "/usr/gst-switch-srv \
--video-input-port=3000 --audio-input-port=4000 \
--control-port=5000 -r".split()
--controller-address=tcp:host=0.0.0.0,port=5000 -r".split()

def test_record_file_valid(self):
"""Test if record file is valid"""
Expand All @@ -186,7 +186,7 @@ def mock_method(arg):
serv._start_process = mock_method
assert serv._run_process() == "/usr/gst-switch-srv \
--video-input-port=3000 --audio-input-port=4000 \
--control-port=5000 --record=record.data".split()
--controller-address=tcp:host=0.0.0.0,port=5000 --record=record.data".split()

def test_record_file_valid_date(self):
"""Test if record file is valid"""
Expand All @@ -198,7 +198,7 @@ def mock_method(arg):
serv._start_process = mock_method
assert serv._run_process() == "/usr/gst-switch-srv \
--video-input-port=3000 --audio-input-port=4000 \
--control-port=5000 \
--controller-address=tcp:host=0.0.0.0,port=5000 \
--record=record_%Y.data".split()

def test_record_file_valid_space(self):
Expand All @@ -211,7 +211,8 @@ def mock_method(arg):
serv._start_process = mock_method
assert serv._run_process() == "/usr/gst-switch-srv \
--video-input-port=3000 --audio-input-port=4000 \
--control-port=5000".split() + ["--record=record 1.data"]
--controller-address=tcp:host=0.0.0.0,port=5000".split() + \
["--record=record 1.data"]

def test_record_file_invalid(self):
"""Test when the record_file is invalid"""
Expand Down
2 changes: 1 addition & 1 deletion tests/test_switch_server.c
Expand Up @@ -1032,7 +1032,7 @@ testclient_run (gpointer data)
client->mainloop = g_main_loop_new (NULL, TRUE);

connect_ok =
gst_switch_client_connect (GST_SWITCH_CLIENT (client), CLIENT_ROLE_UI);
gst_switch_client_connect (GST_SWITCH_CLIENT (client), CLIENT_ROLE_UI, "tcp:host=127.0.0.1,port=5000");
g_assert (connect_ok);

client->compose_port0 =
Expand Down
2 changes: 1 addition & 1 deletion tools/gst-switch-srv.sh
Expand Up @@ -9,5 +9,5 @@
--gst-debug="multiqueue:0" \
--video-input-port="3000" \
--audio-input-port="4000" \
--control-port="5000" \
--controller-address="tcp:host=0.0.0.0,port=5000" \
--record="record.dat"
6 changes: 5 additions & 1 deletion tools/gstswitchcapture.c
Expand Up @@ -49,6 +49,7 @@
#define GST_SWITCH_CAPTURE_WORKER_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), GST_TYPE_SWITCH_CAPTURE_WORKER, GstSwitchCaptureWorkerClass))
#define GST_IS_SWITCH_CAPTURE_WORKER(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), GST_TYPE_SWITCH_CAPTURE_WORKER))
#define GST_IS_SWITCH_CAPTURE_WORKER_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), GST_TYPE_SWITCH_CAPTURE_WORKER))
#define GST_SWITCH_CAPTURE_DEFAULT_ADDRESS "tcp:host=127.0.0.1,port=5000"

/**
* @class GstSwitchCaptureWorker
Expand Down Expand Up @@ -80,6 +81,7 @@ G_DEFINE_TYPE (GstSwitchCaptureWorker, gst_switch_capture_worker,
gboolean verbose = FALSE;
const char *device = "/dev/ttyUSB0";
const char *protocol = "visca";
const char *srv_address = GST_SWITCH_CAPTURE_DEFAULT_ADDRESS;
const char **srcsegments = NULL;
int srcsegmentc = 0;

Expand All @@ -89,6 +91,8 @@ static GOptionEntry options[] = {
"PTZ camera control device", "DEVICE"},
{"protocol", 'p', 0, G_OPTION_ARG_STRING, &protocol,
"PTZ camera control protocol", "NAME"},
{"address", 'a', 0, G_OPTION_ARG_STRING, &srv_address,
"Server Control-Adress, defaults to " GST_SWITCH_CAPTURE_DEFAULT_ADDRESS, NULL},
{NULL}
};

Expand Down Expand Up @@ -228,7 +232,7 @@ static void
gst_switch_capture_run (GstSwitchCapture * capture)
{
if (!gst_switch_client_connect (GST_SWITCH_CLIENT (capture),
CLIENT_ROLE_CAPTURE)) {
CLIENT_ROLE_CAPTURE, srv_address)) {
ERROR ("failed to connect to controller");
return;
}
Expand Down

0 comments on commit 47600c7

Please sign in to comment.