-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtop_cap.pl
More file actions
executable file
·164 lines (142 loc) · 4.86 KB
/
Copy pathtop_cap.pl
File metadata and controls
executable file
·164 lines (142 loc) · 4.86 KB
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/usr/bin/perl
#
# This script captures and dumps the TOP table (BTT, page 1F0)
#
# 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, either version 3 of the License, or
# (at your option) any later version.
#
# 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, see <http://www.gnu.org/licenses/>.
#
# Copyright 2006,2008 by Tom Zoerner (tomzo at users.sf.net)
#
# $Id: top_cap.pl,v 1.4 2010/04/25 14:23:14 tom Exp $
#
use Video::ZVBI qw(/^VBI_/);
$opt_duration = 0;
$opt_device = "/dev/vbi0";
$opt_dvbpid = undef;
$opt_debug = 0;
ParseArgv();
my $err;
my $srv = VBI_SLICED_TELETEXT_B | VBI_SLICED_VPS;
my $cap;
if (defined($opt_dvbpid)) {
$cap = Video::ZVBI::capture::dvb_new($opt_device, 0, $srv, 0, $err, $opt_debug);
$cap->dvb_filter($opt_dvbpid)
} else {
$cap = Video::ZVBI::capture::v4l2_new($opt_device, 6, $srv, 0, $err, $opt_debug);
}
die "Failed to open capture device: $err\n" unless $cap;
$start_t = time;
$vbi_fd = $cap->fd();
$is_btt = 0;
$is_aip = 0;
$is_mpt = 0;
for(;;) {
my $rin="";
vec($rin, $vbi_fd, 1) = 1;
select($rin, undef, undef, 1);
my ($buf, $lcount, $ts);
my $ret = $cap->pull_sliced($buf, $lcount, $ts, 0);
if (($ret > 0) && ($lcount > 0)) {
for (my $idx = 0; $idx < $lcount; $idx++) {
my @tmpl = Video::ZVBI::get_sliced_line($buf, $idx);
if ($tmpl[1] & VBI_SLICED_TELETEXT_B) {
feed($tmpl[0]);
}
}
exit(0) if ($opt_duration != 0) && ((time - $start_t) > $opt_duration);
}
}
sub feed {
my ($data) = @_;
my $mpag = Video::ZVBI::unham16p($data);
my $mag = $mpag & 7;
my $y = ($mpag & 0xf8) >> 3;
if ($y == 0) {
# teletext page header (packet #0)
my $page = ($mag << 8) | Video::ZVBI::unham16p($data, 2);
$is_btt = ($page == 0x1F0);
$is_mpt = ($page == 0x1F1);
$is_aip = ($page == 0x1F2) || ($page == 0x1F3);
} elsif ($is_btt) {
if (($y >= 1) && ($y <= 20)) {
# lines 1-20: page function (coded Hamming-8/4) - see 9.4.2.1
printf "%03d: ", (($y-1)*40) + 100;
foreach (unpack("x2C40", $data)) {
printf " %d", Video::ZVBI::unham8($_);
}
print "\n";
} elsif (($y >= 21) && ($y <= 23)) {
printf "LINK #%d: ", $y-21;
for (my $i=0; $i < 20; $i++) {
printf "%X,", Video::ZVBI::unham16p($data, 2 + 2*$i)
}
print "\n";
} else {
# ignore
}
} elsif ($is_mpt) {
if (($y >= 1) && ($y <= 20)) {
# lines 1-20: multi-page (coded Hamming-8/4)
printf "%03d: ", ($y-1)*40 + 100;
foreach (unpack("x2C40", $data)) {
printf " %d", Video::ZVBI::unham8($_);
}
print "\n";
}
} elsif ($is_aip) {
if (($y >= 1) && ($y <= 22)) {
my $txt = $data;
Video::ZVBI::unpar_str($txt);
printf "%02d: ", $y;
foreach (unpack("x2C8", $data)) {
printf "%x", Video::ZVBI::unham8($_);
}
printf " %s - ", substr($txt, 2+8, 12);
foreach (unpack("x22C8", $data)) {
printf "%x", Video::ZVBI::unham8($_);
}
printf " %s\n", substr($txt, 2+20+8, 12);
}
}
}
sub ParseArgv {
my $usage = "Usage: $0 [-duration <sec>] [-dev <path>] [-dvbpid <PID>] [-debug]\n".
"Output is written to STDOUT\n";
while ($_ = shift @ARGV) {
# -duration <seconds>: terminate acquisition after the given time
if (/^-duration$/) {
die "Missing argument for $_\n$usage" unless $#ARGV>=0;
$opt_duration = shift @ARGV;
die "$_ requires a numeric argument\n" if $opt_duration !~ m#^[0-9]+$#;
die "Invalid duration valid: $opt_duration\n" if $opt_duration == 0;
# -dev <device>: specify VBI device
} elsif (/^-dev(ice)?$/) {
die "Missing argument for $_\n$usage" unless $#ARGV>=0;
$opt_device = shift @ARGV;
die "-dev $opt_device: doesn't exist\n" unless -e $opt_device;
die "-dev $opt_device: not a character device\n" unless -c $opt_device;
# -dvbpid <number>: capture from DVB device from a stream with the given PID
} elsif (/^-dvbpid$/) {
die "Missing argument for $_\n$usage" unless $#ARGV>=0;
$opt_dvbpid = shift @ARGV;
die "$_ requires a numeric argument\n" if $opt_dvbpid !~ m#^[0-9]+$#;
} elsif (/^-debug$/) {
$opt_debug = 1;
} elsif (/^-(help|\?)$/) {
print STDERR $usage;
exit;
} else {
die "$_: unknown argument\n";
}
}
}