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 |
root |
1.5 |
use Fcntl; |
13 |
root |
1.1 |
use Linux::DVB; |
14 |
|
|
|
15 |
|
|
use Data::Dumper; |
16 |
|
|
|
17 |
root |
1.4 |
my $sniff_only = 1; # set to zero to actively tune to a channel |
18 |
|
|
|
19 |
|
|
my $fe = new Linux::DVB::Frontend "/dev/dvb/adapter0/frontend0", $sniff_only ? &O_RDONLY : &O_RDWR; |
20 |
|
|
|
21 |
|
|
unless ($sniff_only) { |
22 |
|
|
$fe->set ( |
23 |
|
|
frequency => 426000000, |
24 |
|
|
symbol_rate => 6900000, |
25 |
|
|
modulation => QAM_64, |
26 |
|
|
fec_inner => FEC_AUTO, |
27 |
|
|
inversion => INVERSION_AUTO, |
28 |
|
|
) or die "frontend->set: $!"; |
29 |
|
|
} |
30 |
root |
1.1 |
|
31 |
|
|
sub new_demux { |
32 |
|
|
new Linux::DVB::Demux "/dev/dvb/adapter0/demux0"; |
33 |
|
|
} |
34 |
|
|
|
35 |
|
|
package scanner; |
36 |
|
|
|
37 |
|
|
sub new { |
38 |
|
|
print "new scanner\n"; |
39 |
|
|
my $self = bless { }; |
40 |
|
|
|
41 |
root |
1.2 |
$self->{dmx} = ::new_demux; |
42 |
|
|
$self->{dmx}->sct_filter ($PID, "", ""); |
43 |
root |
1.3 |
$self->{dmx}->buffer (0x10000); |
44 |
root |
1.2 |
$self->{dmx}->start; |
45 |
|
|
|
46 |
|
|
$self->{w} = Event->io (fd => $self->{dmx}->fh, poll => 'r', cb => sub { |
47 |
root |
1.3 |
sysread $self->{dmx}->fh, my $data, 4096; |
48 |
root |
1.2 |
print Data::Dumper::Dumper Linux::DVB::Decode::si $data; |
49 |
root |
1.1 |
}); |
50 |
|
|
} |
51 |
|
|
|
52 |
|
|
sub DESTROY { |
53 |
|
|
my $self = shift; |
54 |
|
|
$self->{w}->cancel; |
55 |
|
|
} |
56 |
|
|
|
57 |
|
|
package main; |
58 |
|
|
|
59 |
|
|
my $frequency = -1; |
60 |
|
|
|
61 |
|
|
sub status_changed { |
62 |
|
|
if ($fe->parameters->{frequency} != $frequency) { |
63 |
|
|
$frequency = $fe->parameters->{frequency}; |
64 |
|
|
undef $scanner; |
65 |
|
|
} |
66 |
|
|
if ($fe->status & FE_HAS_LOCK) { |
67 |
|
|
$scanner ||= new scanner; |
68 |
|
|
} else { |
69 |
|
|
undef $scanner; |
70 |
|
|
} |
71 |
|
|
} |
72 |
|
|
|
73 |
|
|
Event->io (fd => $fe->{fd}, poll => 'e', cb => sub { |
74 |
|
|
my $event = $fe->event; |
75 |
|
|
# tuning event, status changes not reported |
76 |
|
|
status_changed; |
77 |
|
|
}); |
78 |
|
|
|
79 |
|
|
Event->timer (interval => 1, cb => sub { |
80 |
|
|
#print $fe->status & FE_HAS_LOCK, "\n"; |
81 |
|
|
}); |
82 |
|
|
|
83 |
|
|
status_changed; |
84 |
|
|
|
85 |
|
|
Event::loop; |