#!/usr/bin/perl -X -T ################################################################################ # _____ _ # |_ _| |_ ___ # | | | ' \/ -_) # |_| |_||_\___| # _ _ ____ _ _ # / \ _ __ ___| |_(_) ___ __ _ | _ \ _ __ ___ (_) ___ ___| |_ # / _ \ | '__/ __| __| |/ __/ _` | | |_) | '__/ _ \| |/ _ \/ __| __| # / ___ \| | | (__| |_| | (_| (_| | | __/| | | (_) | | __/ (__| |_ # /_/ \_\_| \___|\__|_|\___\__,_| |_| |_| \___// |\___|\___|\__| # |__/ # The Arctica Modular Remote Computing Framework # ################################################################################ # # Copyright (C) 2015-2016 The Arctica Project # http://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-2016 Guangzhou Nianguan Electronics Technology Co.Ltd. # # Copyright (C) 2015-2016 Mike Gabriel # ################################################################################ use strict; use Data::Dumper; use Arctica::Core::eventInit qw(genARandom BugOUT); use Arctica::Core::JABus::Socket; use POSIX qw(mkfifo); use Gtk3 -init; use Glib; use Glib::Object::Introspection; Glib::Object::Introspection->setup( basename => "GdkX11", version => "3.0", package => "Gtk3::Gdk"); #my $MPVO = "x11"; my $MPVO = "gl"; my $fmedia_port; if ($ENV{'TEKI_FMEDIA_PORT'} =~ /^(\d{1,5})$/) { $fmedia_port = $1; } else { BugOUT(0,"?"); } my $lastcontact = time; my $ACO = Arctica::Core::eventInit->new({ app_name=>'arctica-mediaplayer-overlay', app_class =>'amoduletester', app_version=>'0.0.0.1'}); my $app_id = @ARGV[0]; my $ttid = @ARGV[1]; my $sock_id; my $tmplnkid; my $rwid; if (@ARGV[2] =~ /^([a-zA-Z0-9]*)$/) { $sock_id = $1; BugOUT(8,"SOC:\t$sock_id"); } else {BugOUT(0,"YOU SOCK!");} if (@ARGV[3] =~ /^([a-zA-Z0-9]*)$/) { $tmplnkid = $1; BugOUT(8,"TMPLNKID:\t$tmplnkid"); } else {BugOUT(0,"YOU SOCK!");} if (@ARGV[4] =~ /^([a-zA-Z0-9]{5,})$/) { $rwid = $1; BugOUT(8,"TMPLNKID:\t$tmplnkid"); } else {BugOUT(0,"YOU SOCK!");} #print "YAY WE GOT IT: $tmplnkid\n"; my $TeKi; $TeKi = Arctica::Core::JABus::Socket->new($ACO,{ type => "unix", destination => "local", # FIX ME (change to remote!!!) is_client => 1, connect_to => $sock_id, handle_in_dispatch => { chtstate => sub {\&chtargetstate(@_)}, # srvcneg => sub {$TeKiClient->c2s_service_neg(@_)}, # appctrl => \&teki_client2s_appctrl, }, hooks => { on_ready => sub {my_ready($app_id,$ttid);}, on_client_errhup => sub {BugOUT(0,"\tLOST CONN!\n");}, }, }); #print "THEDUMP:\t\n",Dumper($TeKi); my $time = time(); my $SlaveFIFO = "/tmp/mpslave_$time.fifo"; if (-e $SlaveFIFO) { unlink($SlaveFIFO); } mkfifo($SlaveFIFO, 0700); unless (-x '/usr/bin/mplayer') {BugOUT(0,'NO /usr/bin/mplayer ?!');} my $pid = open(my $mpFH,"-|",'/usr/bin/mplayer','-slave','-input' ,"file=$SlaveFIFO", '-vo',$MPVO,'-zoom','-framedrop','-fs','-wid',$rwid,'-volume','100', '-identify','-idle','-nolirc','-ss','1', "http://localhost:$fmedia_port/$tmplnkid.lnk","2>&1"); # my $pid = open(my $mpFH,"-|",'/usr/bin/mplayer','-slave','-input' ,"file=$SlaveFIFO", '-vo',$MPVO,'-zoom','-framedrop','-fs','-wid',$rwid,'-volume','100', '-identify','-idle','-nolirc','-ss','1', "/tmp/test.mp4","2>&1"); my $TnW = Glib::IO->add_watch( $mpFH->fileno, 'in', sub {watch_mplayerOutput( $mpFH);}); my $timeout = Glib::Timeout->add(250, sub { #print "\tTime:\t",time,"\n\tLast:\t$lastcontact\n"; if ($lastcontact < (time-3)) { BugOUT(0,"We're an orphan?"); } return 1; }); #print "MP:$pid\n"; $ACO->{'Glib'}{'MainLoop'}->run; sub watch_mplayerOutput { my ($fh,undef) = @_; my $buffer; sysread($fh, $buffer, 4096); # print "YALLA:\t$buffer\n"; } sub chtargetstate { $lastcontact = time; my $data = $_[0]; warn(Dumper($data)); my $x = $data->{'apx'}; my $y = $data->{'apy'}; if ($x and $y) { # $window->move($x,$y); # $window->resize($data->{'w'},$data->{'h'}); } if ($data->{'visible'} eq 1) { if ($x ne 0) {#remove this # $window->map(); } } else { # $window->unmap(); } } sub my_ready { BugOUT(8,"MY READY?"); my $app_id = $_[0]; my $ttid = $_[1]; $TeKi->client_send('treg',{ app_id => $app_id, ttid => $ttid, }); } sub daemonize { fork and exit; POSIX::setsid(); fork and exit; umask 0; chdir '/'; close STDIN; close STDOUT; close STDERR; }