aboutsummaryrefslogtreecommitdiff
path: root/bin/AudioTestClient
blob: 710e34c06e1842f866ea7872a27180450e5fe913 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/perl  -T -I /home/testx/arctica/HACK/convergence/perl/modules
################################################################################
#          _____ _
#         |_   _| |_  ___
#           | | | ' \/ -_)
#           |_| |_||_\___|
#                   _   _             ____            _           _
#    / \   _ __ ___| |_(_) ___ __ _  |  _ \ _ __ ___ (_) ___  ___| |_
#   / _ \ | '__/ __| __| |/ __/ _` | | |_) | '__/ _ \| |/ _ \/ __| __|
#  / ___ \| | | (__| |_| | (_| (_| | |  __/| | | (_) | |  __/ (__| |_
# /_/   \_\_|  \___|\__|_|\___\__,_| |_|   |_|  \___// |\___|\___|\__|
#                                                  |__/
#          The Arctica Modular Remote Computing Framework
#
################################################################################
#
# Copyright (C) 2015-2016 The Arctica Project
# http://arctica-project.org/
#
# This code is dual licensed: strictly GPL-2 or AGPL-3+
#
# GPL-2
# -----
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the
# Free Software Foundation, Inc.,
#
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
#
# AGPL-3+
# -------
# This programm is free software; you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This programm is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program; if not, write to the
# Free Software Foundation, Inc.,
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
#
# Copyright (C) 2015-2017 Guangzhou Nianguan Electronics Technology Co.Ltd.
#                         <opensource@gznianguan.com>
# Copyright (C) 2015-2017 Mike Gabriel <mike.gabriel@das-netzwerkteam.de>
#
################################################################################
use strict;
use Data::Dumper;
use Arctica::Core::eventInit qw(genARandom BugOUT);
use Arctica::Core::JABus::Socket;
use Arctica::Services::Audio::ClientGST;

################################################################################
# Just some stuff to fetch Socket ID from either ARGV or STDIN
# Watch the log output from server to see what ID the server is.
my $argsoc = @ARGV[0];$argsoc =~ s/[\ \n]//g;
if  ($argsoc =~ /^([a-zA-Z0-9]{16,128})$/) {
	$argsoc = $1;
} else {
	print "SOCKET_ID:\t";
	$argsoc = <STDIN>;$argsoc =~ s/[\ \n]//g;
	if  ($argsoc =~ /^([a-zA-Z0-9]{16,128})$/) {
		$argsoc = $1;
	} else {
		die;
	}
}
print "CONNECTING TO SOCKET ID: $argsoc\n";
#
################################################################################
my $ACO = Arctica::Core::eventInit->new({
	app_name=>'audio-client-test',
	app_class =>'amoduletester',
	app_version=>'0.0.1.1'});

my $ClientGST = Arctica::Services::Audio::PulseAudio::ClientGST->new($ACO);
my $JABusClient = Arctica::Core::JABus::Socket->new($ACO,{
	type	=>	"unix",
	destination =>	"local",
	is_client => 1,
	connect_to => $argsoc,
	handle_in_dispatch => {
#			heartbeat => \&heartbeat, #FIXME heartbeat will be intergrated in RTT and persistency code in JABus...
			gstctl => \&gstctl_handler,
	},
	hooks => {
		on_ready => \&my_on_ready,
	},

});


$ACO->{'Glib'}{'MainLoop'}->run;


sub gstctl_handler {
	my $JDATA = $_[0];
#	my $laSock = $_[1];
#	print "GSTCTL_JSON:\n",Dumper($JDATA);
#	print "Action:\t$JDATA->{'action'}\n";
	if  ($JDATA->{'action'} eq "start") {
		BugOUT(8,"JACTION IS START");
		if ($JDATA->{'type'} eq "output") {
			$ClientGST->start_output($JDATA->{'idnum'});
		} elsif ($JDATA->{'type'} eq "input") {
			$ClientGST->start_input($JDATA->{'idnum'});
		}


	} elsif  ($JDATA->{'action'} eq "stop") {
		BugOUT(8,"JACTION IS STOP");
		if ($JDATA->{'type'} eq "output") {
			$ClientGST->stop_output($JDATA->{'idnum'});
		} elsif ($JDATA->{'type'} eq "input") {
			$ClientGST->stop_input($JDATA->{'idnum'});
		}

	}

}

sub my_on_ready {
#	print "YAY READY ($_[0])\n";
	$JABusClient->client_send('init',time);
}