Dear visitor, welcome to VDR Portal. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

This post has been edited 2 times, last edit by "gonz" (Aug 3rd 2004, 9:05pm)
Quoted
Original von Grégoire
Die Idee ist sehr gut, leider bei mir ist die Qualität des Video nicht so gut wie xawtv, und ich kann tvtime nicht immer starten :
Quoted
DEBUG: tvtime exited.
Ich glaube tvtime kann gut werden, aber zur Zeit ist es zu jung![]()
|
|
Source code |
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 |
#!/usr/bin/perl
use Socket;
$tvtime = '/usr/bin/tvtime --slave';
$tvtimecmd = '/usr/bin/tvtime-command';
$mapfile = '/etc/tvtime/map.txt';
$svdrpsend = '/usr/bin/svdrpsend.pl';
my %mapped;
my $timeout = 0;
open(IN, "<$mapfile") || die "cannot open mapfile: $mapfile";
while(<IN>)
{
chomp;
my @line = split( /\t/, $_ );
$mapped{$line[0]} = $line[1];
}
close(IN);
$Dest = "127.0.0.1";
$Port = 2001;
$| = 1;
open(IN, "$tvtime|") || die "cannot open pipe";
MainLoop();
sub MainLoop ()
{
print STDOUT "DEBUG Mainloop\n";
do {
OpenSocket();
while(<IN>)
{
chomp;
next if /^\0$/;
if ( $mapped{$_} eq "" ) { $mapped{$_} = $_ }
if ( $mapped{$_} =~ /TVTIME_/)
{
$cmd = $mapped{$_};
$cmd =~ s/TVTIME_//;
SendTvtime($cmd);
}
else
{
SendKey($mapped{$_});
}
}
} while (TimeOut);
Send("quit");
close(SOCK) || Error("close: $!");
close(IN);
print "DEBUG: tvtime exited.\n";
}
sub TimeOut
{
print STDOUT "TIMEOUT $timeout\n";
if ($timeout) {$timeout = 0; return 1;}
return 0;
}
sub SendTvtime
{
system("$tvtimecmd KEY_EVENT $cmd")
}
sub Send
{
my $cmd = shift || Error("no key to send");
print SOCK "HITK $cmd\n";
Receive();
}
sub SendKey
{
my $cmd = shift || Error("no key to send");
print SOCK "HITK $cmd\n";
Receive();
}
sub OpenSocket
{
$iaddr = inet_aton($Dest) || Error("no host: $Dest");
$paddr = sockaddr_in($Port, $iaddr);
$proto = getprotobyname('tcp');
close(SOCK);
socket(SOCK, PF_INET, SOCK_STREAM, $proto) || Error("socket: $!");
connect(SOCK, $paddr) || Error("connect: $!");
select(SOCK) || Error ;
$| = 1;
Receive();
}
sub Receive
{
while (<SOCK>)
{
if ( $_ =~ /^221/)
{
print STDOUT "timeout detected\n";
$timeout = 1;
OpenSocket();
return;
}
print STDOUT $_;
last if substr($_, 3, 1) ne "-";
}
}
sub Error
{
print STDERR "@_\n";
close(SOCK);
exit(0);
}
|
This post has been edited 3 times, last edit by "Tyger" (Aug 2nd 2004, 2:28am)
|
|
Source code |
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 |
#!/usr/bin/perl
use Socket;
use Time::HiRes qw(setitimer ITIMER_VIRTUAL);
$tvtime = '/usr/bin/tvtime --slave';
$tvtimecmd = '/usr/bin/tvtime-command';
$mapfile = '/etc/tvtime/map.txt';
$svdrpsend = '/usr/bin/svdrpsend.pl';
$timeout = 250;
my %mapped;
open(IN, "<$mapfile") || die "cannot open mapfile: $mapfile";
while(<IN>)
{
chomp;
my @line = split( /\t/, $_ );
$mapped{$line[0]} = $line[1];
}
close(IN);
$Dest = "127.0.0.1";
$Port = 2001;
$| = 1;
open(IN, "$tvtime @ARGV |") || die "cannot open pipe";
OpenSocket();
# keep alive
$SIG{ALRM} = sub { SendVDR("HELP"); };
setitimer(ITIMER_PROF, $timeout, $timeout);
$tvtimealive = 1;
while($tvtimealive)
{
chomp($key=<IN>);
printf(STDOUT "Key $key %d\n", ord($key));
next if $key =~ /^\0$/;
if ( ord($key) == 0 )
{
$tvtimealive = 0;
next;
}
if ( $mapped{$key} eq "" ) { $mapped{$key} = $key }
if ( $mapped{$key} =~ /TVTIME_/)
{
$cmd = $mapped{$key};
$cmd =~ s/TVTIME_//;
SendTvtime("KEY_EVENT $cmd");
}
else
{
SendVDR("HITK $mapped{$key}");
}
}
SendVDR("quit");
close(VDRSOCK) || Error("close: $!");
close(IN);
print STDOUT "DEBUG: tvtime exited.\n";
exit(0);
sub SendTvtime
{
$cmd = shift || Error("no key to send");
system("$tvtimecmd $cmd")
}
sub SendVDR
{
my $cmd = shift || Error("no key to send");
print VDRSOCK "$cmd\n";
Receive();
}
sub OpenSocket
{
$iaddr = inet_aton($Dest) || Error("no host: $Dest");
$paddr = sockaddr_in($Port, $iaddr);
$proto = getprotobyname('tcp');
socket(VDRSOCK, PF_INET, SOCK_STREAM, $proto) || Error("socket: $!");
connect(VDRSOCK, $paddr) || Error("connect: $!");
select(VDRSOCK) || Error ;
$| = 1;
Receive();
}
sub Receive
{
while (<VDRSOCK>)
{
if ( $_ =~ /^221.*timeout/)
{
print STDOUT "timeout detected\n";
OpenSocket();
return;
}
print STDOUT "$_";
last if substr($_, 3, 1) ne "-";
}
}
sub Error
{
print STDERR "@_\n";
close(VDRSOCK);
exit(0);
}
|
