1 |
root |
1.1 |
#!/opt/bin/perl |
2 |
|
|
|
3 |
root |
1.2 |
# extract whatever data available in the currently tuned transponder |
4 |
|
|
|
5 |
|
|
# this program is slightly overdesigned as it is was the base for a |
6 |
|
|
# larger program, it still shows how to react to channel changes |
7 |
|
|
# and scan pids and decode si info. |
8 |
|
|
|
9 |
|
|
my $PID = 18; # epg data and more |
10 |
|
|
|
11 |
root |
1.1 |
use Event; |
12 |
|
|
use Linux::DVB; |
13 |
|
|
|
14 |
|
|
use Data::Dumper; |
15 |
|
|
|
16 |
|
|
my $fe = new Linux::DVB::Frontend "/dev/dvb/adapter0/frontend0"; |
17 |
|
|
|
18 |
|
|
sub new_demux { |
19 |
|
|
new Linux::DVB::Demux "/dev/dvb/adapter0/demux0"; |
20 |
|
|
} |
21 |
|
|
|
22 |
|
|
package scanner; |
23 |
|
|
|
24 |
|
|
sub new { |
25 |
|
|
print "new scanner\n"; |
26 |
|
|
my $self = bless { }; |
27 |
|
|
|
28 |
root |
1.2 |
$self->{dmx} = ::new_demux; |
29 |
|
|
$self->{dmx}->sct_filter ($PID, "", ""); |
30 |
|
|
$self->{dmx}->start; |
31 |
|
|
|
32 |
|
|
$self->{w} = Event->io (fd => $self->{dmx}->fh, poll => 'r', cb => sub { |
33 |
|
|
sysread $self->{dmx}->fh, my $data, 8192; |
34 |
|
|
print Data::Dumper::Dumper Linux::DVB::Decode::si $data; |
35 |
root |
1.1 |
}); |
36 |
|
|
} |
37 |
|
|
|
38 |
|
|
sub DESTROY { |
39 |
|
|
my $self = shift; |
40 |
|
|
$self->{w}->cancel; |
41 |
|
|
} |
42 |
|
|
|
43 |
|
|
package main; |
44 |
|
|
|
45 |
|
|
my $frequency = -1; |
46 |
|
|
|
47 |
|
|
sub status_changed { |
48 |
|
|
if ($fe->parameters->{frequency} != $frequency) { |
49 |
|
|
$frequency = $fe->parameters->{frequency}; |
50 |
|
|
undef $scanner; |
51 |
|
|
} |
52 |
|
|
if ($fe->status & FE_HAS_LOCK) { |
53 |
|
|
$scanner ||= new scanner; |
54 |
|
|
} else { |
55 |
|
|
undef $scanner; |
56 |
|
|
} |
57 |
|
|
} |
58 |
|
|
|
59 |
|
|
Event->io (fd => $fe->{fd}, poll => 'e', cb => sub { |
60 |
|
|
my $event = $fe->event; |
61 |
|
|
# tuning event, status changes not reported |
62 |
|
|
status_changed; |
63 |
|
|
}); |
64 |
|
|
|
65 |
|
|
Event->timer (interval => 1, cb => sub { |
66 |
|
|
#print $fe->status & FE_HAS_LOCK, "\n"; |
67 |
|
|
}); |
68 |
|
|
|
69 |
|
|
status_changed; |
70 |
|
|
|
71 |
|
|
Event::loop; |