App-EventStreamr
view release on metacpan or search on metacpan
bin/station-mgr.pl view on Meta::CPAN
my $did;
# Some device types require different details
if ($type eq "file") {
$did = $id;
} elsif ($type eq "alsa") {
$self->{devices} = $devices->all();
$did = $self->{devices}{$type}{$id}{alsa};
} else {
$did = $self->{devices}{$type}{$id}{device};
}
my %cmd_vars = (
device => $did,
bin => $Bin,
host => $self->{config}{mixer}{host},
port => $self->{config}{mixer}{port},
);
$command =~ s/\$(\w+)/$cmd_vars{$1}/g;
return $command;
}
sub mixer_command {
my ($id,$type) = @_;
my $command = $self->{commands}{dvswitch};
my %cmd_vars = (
port => $self->{config}{mixer}{port},
);
$command =~ s/\$(\w+)/$cmd_vars{$1}/g;
return $command;
}
sub record_command {
my ($id,$type) = @_;
my $command = $self->{commands}{record};
my %cmd_vars = (
host => $self->{config}{mixer}{host},
port => $self->{config}{mixer}{port},
room => $self->{config}{room},
path => $self->{device_control}{$id}{recordpath},
);
$command =~ s/\$(\w+)/$cmd_vars{$1}/g;
return $command;
}
sub stream_command {
my ($id,$type) = @_;
my $command = $self->{commands}{stream};
my %cmd_vars = (
host => $self->{config}{mixer}{host},
port => $self->{config}{mixer}{port},
id => $id,
shost => $self->{config}{stream}{host},
sport => $self->{config}{stream}{port},
spassword => $self->{config}{stream}{password},
stream => $self->{config}{stream}{stream},
);
$command =~ s/\$(\w+)/$cmd_vars{$1}/g;
return $command;
}
sub set_path {
my ($path) = @_;
my %path_vars = (
room => $self->{config}{room},
date => $self->{date},
);
$path =~ s/\$(\w+)/$path_vars{$1}/g;
return $path;
}
# Get Mac Address
sub getmac {
# This is better, but can break if no eth0. We are only using it as a UID - think of something better.
my $macaddress = `ifdata -ph eth0`;
chomp $macaddress;
return $macaddress;
}
sub blank_station {
my $mixer_ipaddr = `ifdata -pa eth0`;
chomp $mixer_ipaddr;
$mixer_ipaddr =~ s/.$/1/;
my $hostname = `hostname`;
chomp $hostname;
my $room = $hostname;
$room =~ s/-\d+$//;
my $json = <<CONFIG;
{
"roles" :
[
],
"nickname" : "$hostname",
"room" : "$room",
"record_path" : "/localbackup/\$room/\$date",
"mixer" :
{
"port":"1234",
"host":"$mixer_ipaddr",
"loop":"/home/av/eventstreamr/baseimage/video/standby.dv"
},
"sync" :
{
"host":"storage.local",
"path":"/storage"
},
"devices" : "all",
"device_control" :
{
},
"run" : "0",
"stream" :
{
"host" : "",
"port" : "",
"password" : "",
"stream" : ""
}
}
CONFIG
my $config = from_json($json);
return $config;
}
sub blank_settings {
my $json = <<CONFIG;
{
"controller" : "http://10.4.4.10:5001"
}
CONFIG
my $config = from_json($json);
return $config;
}
=pod
=encoding UTF-8
=head1 NAME
station-mgr - station-mgr - Core Station Manager script
=head1 VERSION
version 0.5
=head1 SYNOPSIS
Usage:
station-mgr.pl
=head1 AUTHOR
Leon Wright < techman@cpan.org >
=head1 COPYRIGHT AND LICENSE
This software is Copyright (c) 2014 by Leon Wright.
This is free software, licensed under:
The GNU Affero General Public License, Version 3, November 2007
=cut
__END__
(dev) bofh-sider:~/git/eventstreamr/station $ ps waux|grep dv
leon 19898 2.5 0.1 850956 24560 pts/12 Sl+ 11:35 1:21 dvswitch -h localhost -p 1234
leon 20723 0.0 0.0 4404 612 ? S 12:27 0:00 sh -c ffmpeg -f video4linux2 -s vga -r 25 -i /dev/video0 -target pal-dv - | dvsource-file /dev/stdin -h localhost -p 1234
leon 20724 8.0 0.1 130680 24884 ? S 12:27 0:01 ffmpeg -f video4linux2 -s vga -r 25 -i /dev/video0 -target pal-dv -
leon 20725 0.1 0.0 10796 860 ? S 12:27 0:00 dvsource-file /dev/stdin -h localhost -p 1234
leon 20735 0.0 0.0 9396 920 pts/16 S+ 12:28 0:00 grep --color=auto dv
$VAR1 = {
'commands' => {
'alsa' => 'dvsource-alsa -h $host -p $port hw:$device',
'dv' => 'dvsource-firewire -h $host -p $port -c $device',
'record' => 'dvsink-files $device',
'v4l' => 'ffmpeg -f video4linux2 -s vga -r 25 -i $device -target pal-dv - | dvsource-file /dev/stdin -h $host -p $port',
'stream' => 'dvsink-command -- ffmpeg2theora - -f dv -F 25:2 --speedlevel 0 -v 4 --optimize -V 420 --soft-target -a 4 -c 1 -H 44100 -o - | oggfwd $host $port 8000 $password /$stream',
'file' => 'dvsource-file -l $device',
'dvswitch' => 'dvswitch -h 0.0.0.0 -p $port'
},
'config' => {
'roles' => [
{
'role' => 'ingest'
},
{
'role' => 'mixer'
},
{
'role' => 'stream'
}
],
'nickname' => 'test',
'room' => 'room1',
'devices' => [
{
'name' => 'Chicony Electronics Co. Ltd. ASUS USB2.0 Webcam',
'id' => 'video0',
'type' => 'v4l',
'device' => '/dev/video0'
},
{
'name' => 'C-Media Electronics, Inc. ',
'usbid' => '0d8c:0008',
'id' => '2',
'type' => 'alsa',
'device' => '2'
}
],
'device_control' => {
'video0' => {
'run' => '0'
}
},
'run' => '0',
'macaddress' => '00:15:58:d8:85:c7',
'mixer' => {
'port' => '1234',
'host' => 'localhost'
}
},
'dvswitch' => {
'check' => 1
},
'devices' => {
'array' => [
{
'name' => 'Chicony Electronics Co. Ltd. ASUS USB2.0 Webcam',
'id' => 'video0',
'type' => 'v4l',
'device' => '/dev/video0'
},
{
'name' => 'C-Media Electronics, Inc. ',
'usbid' => '0d8c:0008',
'id' => '2',
'type' => 'alsa',
( run in 0.755 second using v1.01-cache-2.11-cpan-df04353d9ac )