blib/lib/MPEG/Audio/Frame.pm

filter: Statementstmt 89.3% 192 / 215 Branchbran 67.0% 59 / 88 Conditioncond 50.9% 27 / 53 MC/DCmcdc 10.7% 3 / 28 Subroutinesub 83.6% 51 / 61 Podpod 93.7% 45 / 48 totaltotal 76.4% 377 / 493 CC 64 SCAR 21.5
CC
64
Cov
78%
read
27.9
broken
8.2
header
6.0
CRAP 8.6
↑ Summary
1 package MPEG::Audio::Frame;
2  
3 # BLECH! With 5.005_04 compatibility the pretty 0b000101001 notation went away,
4 # and now we're stuck using hex. Phooey!
5  
6 31 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 31 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 31 ▶use integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # fields::new is not used because it is very costly in such a tight loop. about 1/4th of the time, according to DProf
11 #use fields qw/
12 # headhash
13 # binhead
14 # header
15 # content
16 # length
17 # bitrate
18 # sample
19 # offset
20 # crc_sum
21 # calculated_sum
22 # broken
23 #/;
24  
25 31 ▶use overload '""' => \&asbin;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 31 ▶use vars qw/$VERSION $free_bitrate $lax $mpeg25/;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 31 $VERSION = '0.10';
29  
30 31 $mpeg25 = 1; # normally support it
31  
32 # constants and tables
33  
34 31 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=8.4
35 31 ▶ if ($] <= 5.006){
Branch: 1 branch
BranchTrueFalseTotal
if ($] <= 5.006) { } 31 0 31
36 31 require Fcntl; Fcntl->import(qw/SEEK_CUR/);
37 } else {
38 0 require POSIX; POSIX->import(qw/SEEK_CUR/);
39 }
40 }
41  
42 31 my @version = (
43 1, # 0b00 MPEG 2.5
44 undef, # 0b01 is reserved
45 1, # 0b10 MPEG 2
46 0, # 0b11 MPEG 1
47 );
48  
49 31 my @layer = (
50 undef, # 0b00 is reserved
51 2, # 0b01 Layer III
52 1, # 0b10 Layer II
53 0, # 0b11 Layer I
54 );
55  
56 31 my @bitrates = (
57 # 0/free 1 10 11 100 101 110 111 1000 1001 1010 1011 1100 1101 1110 # bits
58 [ # mpeg 1
59 [ undef, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448 ], # l1
60 [ undef, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384 ], # l2
61 [ undef, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320 ], # l3
62 ],
63 [ # mpeg 2
64 [ undef, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256 ], # l1
65 [ undef, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160 ], # l3
66 [ undef, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160 ], # l3
67 ],
68 );
69  
70 31 my @samples = (
71 [ # MPEG 2.5
72 11025, # 0b00
73 12000, # 0b01
74 8000, # 0b10
75 undef, # 0b11 is reserved
76 ],
77 undef, # version 0b01 is reserved
78 [ # MPEG 2
79 22050, # 0b00
80 24000, # 0b01
81 16000, # 0b10
82 undef, # 0b11 is reserved
83 ],
84 [ # MPEG 1
85 44100, # 0b00
86 48000, # 0b01
87 32000, # 0b10
88 undef, # 0b11 is reserved
89 ],
90 );
91  
92  
93 # stolen from libmad, bin.c
94 31 my @crc_table = (
95 0x0000, 0x8005, 0x800f, 0x000a, 0x801b, 0x001e, 0x0014, 0x8011,
96 0x8033, 0x0036, 0x003c, 0x8039, 0x0028, 0x802d, 0x8027, 0x0022,
97 0x8063, 0x0066, 0x006c, 0x8069, 0x0078, 0x807d, 0x8077, 0x0072,
98 0x0050, 0x8055, 0x805f, 0x005a, 0x804b, 0x004e, 0x0044, 0x8041,
99 0x80c3, 0x00c6, 0x00cc, 0x80c9, 0x00d8, 0x80dd, 0x80d7, 0x00d2,
100 0x00f0, 0x80f5, 0x80ff, 0x00fa, 0x80eb, 0x00ee, 0x00e4, 0x80e1,
101 0x00a0, 0x80a5, 0x80af, 0x00aa, 0x80bb, 0x00be, 0x00b4, 0x80b1,
102 0x8093, 0x0096, 0x009c, 0x8099, 0x0088, 0x808d, 0x8087, 0x0082,
103  
104 0x8183, 0x0186, 0x018c, 0x8189, 0x0198, 0x819d, 0x8197, 0x0192,
105 0x01b0, 0x81b5, 0x81bf, 0x01ba, 0x81ab, 0x01ae, 0x01a4, 0x81a1,
106 0x01e0, 0x81e5, 0x81ef, 0x01ea, 0x81fb, 0x01fe, 0x01f4, 0x81f1,
107 0x81d3, 0x01d6, 0x01dc, 0x81d9, 0x01c8, 0x81cd, 0x81c7, 0x01c2,
108 0x0140, 0x8145, 0x814f, 0x014a, 0x815b, 0x015e, 0x0154, 0x8151,
109 0x8173, 0x0176, 0x017c, 0x8179, 0x0168, 0x816d, 0x8167, 0x0162,
110 0x8123, 0x0126, 0x012c, 0x8129, 0x0138, 0x813d, 0x8137, 0x0132,
111 0x0110, 0x8115, 0x811f, 0x011a, 0x810b, 0x010e, 0x0104, 0x8101,
112  
113 0x8303, 0x0306, 0x030c, 0x8309, 0x0318, 0x831d, 0x8317, 0x0312,
114 0x0330, 0x8335, 0x833f, 0x033a, 0x832b, 0x032e, 0x0324, 0x8321,
115 0x0360, 0x8365, 0x836f, 0x036a, 0x837b, 0x037e, 0x0374, 0x8371,
116 0x8353, 0x0356, 0x035c, 0x8359, 0x0348, 0x834d, 0x8347, 0x0342,
117 0x03c0, 0x83c5, 0x83cf, 0x03ca, 0x83db, 0x03de, 0x03d4, 0x83d1,
118 0x83f3, 0x03f6, 0x03fc, 0x83f9, 0x03e8, 0x83ed, 0x83e7, 0x03e2,
119 0x83a3, 0x03a6, 0x03ac, 0x83a9, 0x03b8, 0x83bd, 0x83b7, 0x03b2,
120 0x0390, 0x8395, 0x839f, 0x039a, 0x838b, 0x038e, 0x0384, 0x8381,
121  
122 0x0280, 0x8285, 0x828f, 0x028a, 0x829b, 0x029e, 0x0294, 0x8291,
123 0x82b3, 0x02b6, 0x02bc, 0x82b9, 0x02a8, 0x82ad, 0x82a7, 0x02a2,
124 0x82e3, 0x02e6, 0x02ec, 0x82e9, 0x02f8, 0x82fd, 0x82f7, 0x02f2,
125 0x02d0, 0x82d5, 0x82df, 0x02da, 0x82cb, 0x02ce, 0x02c4, 0x82c1,
126 0x8243, 0x0246, 0x024c, 0x8249, 0x0258, 0x825d, 0x8257, 0x0252,
127 0x0270, 0x8275, 0x827f, 0x027a, 0x826b, 0x026e, 0x0264, 0x8261,
128 0x0220, 0x8225, 0x822f, 0x022a, 0x823b, 0x023e, 0x0234, 0x8231,
129 0x8213, 0x0216, 0x021c, 0x8219, 0x0208, 0x820d, 0x8207, 0x0202
130 );
131  
132 sub CRC_POLY () { 0x8005 }
133  
134 ###
135  
136 31 my @protbits = (
137 [ 128, 256 ], # layer one
138 undef,
139 [ 136, 256 ], # layer three
140 );
141  
142  
143 31 my @consts;
144 403 ▶sub B ($) { $_[0] == 12 ? 3 : (1 + ($_[0] / 4)) }
Subroutine B: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_[0] == 12 ? : 31 372 403
145 403 ▶sub M ($) {
Subroutine M: called CC=3 SCAR=11.0
Pod undocumented
146 403 my $s = 0;
147 403 $s += $consts[$_][1] for (0 .. $_[0]-1);
148 403 $s%=8;
149 403 my $v = '';
150 403 vec($v,8-$_,1) = 1 for $s+1 .. $s+$consts[$_[0]][1];
151 403 "0x" . unpack("H*", $v);
152 }
153 403 ▶sub R ($) {
Subroutine R: called CC=2 SCAR=6.9
Pod undocumented
154 403 my $i = 0;
155 403 my $m = eval "M_$consts[$_[0]][0]()";
156 403 ▶ $i++ until (($m >> $i) & 1);
Branch: 1 branch
BranchTrueFalseTotal
$m >> $i & 1 or do { ++$i } 403 961 1364
157 403 $i;
158 }
159  
160 31 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=6.9
161 31 @consts = (
162 # [ $name, $width ]
163 [ SYNC => 3 ],
164 [ VERSION => 2 ],
165 [ LAYER => 2 ],
166 [ CRC => 1 ],
167 [ BITRATE => 4 ],
168 [ SAMPLE => 2 ],
169 [ PAD => 1 ],
170 [ PRIVATE => 1 ],
171 [ CHANMODE => 2 ],
172 [ MODEXT => 2 ],
173 [ COPY => 1 ],
174 [ HOME => 1 ],
175 [ EMPH => 2 ],
176 );
177 31 my $i = 0;
178 31 foreach my $c (@consts){
179 403 my $CONST = $c->[0];
180 403 eval "sub $CONST () { $i }"; # offset in $self->{header}
181 403 eval "sub M_$CONST () { " . M($i) ." }"; # bit mask
182 403 eval "sub B_$CONST () { " . B($i) . " }"; # offset in read()'s @hb
183 403 eval "sub R_$CONST () { " . R($i) . " }"; # amount to right shift
184 403 $i++;
185 }
186 }
187  
188  
189 # constructor and work horse
190 2033 ▶sub read {
Subroutine read: called CC=27 SCAR=33.3
Pod documented
191 2033 ▶ my $pkg = shift || return undef;
Condition50%1/2
shift() || (return undef)
l!l
20330
MC/DC0%0/1
shift() || (return undef)
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
192 2033 ▶ my $fh = shift || return undef; binmode($fh);
Condition50%1/2
shift() || (return undef)
l!l
20330
MC/DC0%0/1
shift() || (return undef)
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
193  
194 2033 local $/ = "\xff"; # get readline to find 8 bits of sync.
195
196 2033 my $offset; # where in the handle
197 my $header; # the binary header data... what a fabulous pun.
198 2033 my @hr; # an array of integer
199  
200 OUTER: {
201 2033 ▶ while (defined(<$fh>)){ # readline, readline, find me a header, make me a header, catch me a header. somewhate wasteful, perhaps. But I don't want to seek.
Branch: 1 branch
BranchTrueFalseTotal
if (defined readline $fh) 2129 1 2130
202 2129 $header = "\xff";
203 2129 ▶ (read $fh, $header, 3, 1 or return undef) == 3 or return undef; # read the rest of the header
Branch: 1 branch
BranchTrueFalseTotal
(CORE::read($fh, $header, 3, 1) || (return undef)) == 3 or return undef 2100 3 2103
Condition100%2/2
CORE::read($fh, $header, 3, 1) || (return undef)
l!l
210326
MC/DC100%1/1
CORE::read($fh, $header, 3, 1) || (return undef)
CORE::read($fh, $header, 3, 1)
Truth table100%2/2
A
A= CORE::read($fh, $header, 3, 1)
Aresult
11
00
204  
205 2100 my @hb = unpack("CCCC",$header); # an array of 4 integers for convenient access, each representing a byte of the header
206 # I wish vec could take non powers of 2 for the bit width param... *sigh*
207 # make sure there are no illegal values in the header
208 2100 ▶ ($hr[SYNC] = ($hb[B_SYNC] & M_SYNC) >> R_SYNC) != 0x07 and next; # see if the sync remains
Branch: 1 branch
BranchTrueFalseTotal
($hr[0] = ($hb[1] & 224) >> 5) != 7 and next 73 2027 2100
209 2027 ▶ ($hr[VERSION] = ($hb[B_VERSION] & M_VERSION) >> R_VERSION) == 0x00 and ($mpeg25 or next);
Branch: 1 branch
BranchTrueFalseTotal
($hr[1] = ($hb[1] & 24) >> 3) == 0 and $MPEG::Audio::Frame::mpeg25 || (next) 21 2006 2027
Condition60%3/5
($hr[1] = ($hb[1] & 24) >> 3) == 0 && ($MPEG::Audio::Frame::mpeg25 || (next))
!ll
2006210
$MPEG::Audio::Frame::mpeg25 or next
l!l
210
MC/DC0%0/2
($hr[1] = ($hb[1] & 24) >> 3) == 0 && ($MPEG::Audio::Frame::mpeg25 || (next))
($hr[1] = ($hb[1] & 24) >> 3) == 0 $MPEG::Audio::Frame::mpeg25
Truth table33%1/3
A && B
A= ($hr[1] = ($hb[1] & 24) >> 3) == 0B= $MPEG::Audio::Frame::mpeg25
ABresult
0X0
100
111
210 2027 ▶ ($hr[VERSION]) == 0x01 and next;
Branch: 1 branch
BranchTrueFalseTotal
$hr[1] == 1 and next 1 2026 2027
211 2026 ▶ ($hr[LAYER] = ($hb[B_LAYER] & M_LAYER) >> R_LAYER) == 0x00 and next;
Branch: 1 branch
BranchTrueFalseTotal
($hr[2] = ($hb[1] & 6) >> 1) == 0 and next 2 2024 2026
212 2024 ▶ ($hr[BITRATE] = ($hb[B_BITRATE] & M_BITRATE) >> R_BITRATE) == 0x0f and next;
Branch: 1 branch
BranchTrueFalseTotal
($hr[4] = ($hb[2] & 240) >> 4) == 15 and next 7 2017 2024
213 2017 ▶ ($hr[SAMPLE] = ($hb[B_SAMPLE] & M_SAMPLE) >> R_SAMPLE) == 0x03 and next;
Branch: 1 branch
BranchTrueFalseTotal
($hr[5] = ($hb[2] & 12) >> 2) == 3 and next 4 2013 2017
214 2013 ▶ ($hr[EMPH] = ($hb[B_EMPH] & M_EMPH) >> R_EMPH) == 0x02 and ($lax or next);
Branch: 1 branch
BranchTrueFalseTotal
($hr[12] = ($hb[3] & 3) >> 0) == 2 and $MPEG::Audio::Frame::lax || (next) 11 2002 2013
Condition80%4/5
($hr[12] = ($hb[3] & 3) >> 0) == 2 && ($MPEG::Audio::Frame::lax || (next))
!ll
2002110
$MPEG::Audio::Frame::lax or next
l!l
110
MC/DC0%0/2
($hr[12] = ($hb[3] & 3) >> 0) == 2 && ($MPEG::Audio::Frame::lax || (next))
($hr[12] = ($hb[3] & 3) >> 0) == 2 $MPEG::Audio::Frame::lax
Truth table66%2/3
A && B
A= ($hr[12] = ($hb[3] & 3) >> 0) == 2B= $MPEG::Audio::Frame::lax
ABresult
0X0
100
111
215 # and drink up all that we don't bother verifying
216 2003 $hr[CRC] = ($hb[B_CRC] & M_CRC) >> R_CRC;
217 2003 $hr[PAD] = ($hb[B_PAD] & M_PAD) >> R_PAD;
218 2003 $hr[PRIVATE] = ($hb[B_PRIVATE] & M_PRIVATE) >> R_PRIVATE;
219 2003 $hr[CHANMODE] = ($hb[B_CHANMODE] & M_CHANMODE) >> R_CHANMODE;
220 2003 $hr[MODEXT] = ($hb[B_MODEXT] & M_MODEXT) >> R_MODEXT;
221 2003 $hr[COPY] = ($hb[B_COPY] & M_COPY) >> R_COPY;
222 2003 $hr[HOME] = ($hb[B_HOME] & M_HOME) >> R_HOME;
223  
224 # record the offset
225 2003 $offset = tell($fh) - 4;
226  
227 2003 last OUTER; # were done reading for the header
228 }
229 1 seek $fh, -3, SEEK_CUR;
230 1 return undef;
231 }
232  
233
234 2003 my $sum = '';
235 2003 ▶ if (!$hr[CRC]){
Branch: 1 branch
BranchTrueFalseTotal
unless ($hr[3]) 607 1396 2003
236 607 ▶ (read $fh, $sum, 2 or return undef) == 2 or return undef;
Branch: 1 branch
BranchTrueFalseTotal
(CORE::read($fh, $sum, 2) || (return undef)) == 2 or return undef 607 0 607
Condition50%1/2
CORE::read($fh, $sum, 2) || (return undef)
l!l
6070
MC/DC0%0/1
CORE::read($fh, $sum, 2) || (return undef)
CORE::read($fh, $sum, 2)
Truth table50%1/2
A
A= CORE::read($fh, $sum, 2)
Aresult
11
00
237 }
238  
239 2003 ▶ my $bitrate = $bitrates[$version[$hr[VERSION]]][$layer[$hr[LAYER]]][$hr[BITRATE]] || $free_bitrate or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $bitrate = $bitrates[$version[$hr[1]]][$layer[$hr[2]]][$hr[4]] || $MPEG::Audio::Frame::free_bitrate or return undef 2003 0 2003
Condition66%2/3
$bitrates[$version[$hr[1]]][$layer[$hr[2]]][$hr[4]] || $MPEG::Audio::Frame::free_bitrate
l!l&&r!l&&!r
1935680
MC/DC0%0/2
$bitrates[$version[$hr[1]]][$layer[$hr[2]]][$hr[4]] || $MPEG::Audio::Frame::free_bitrate
$bitrates[$version[$hr[1]]][$layer[$hr[2]]][$hr[4]] $MPEG::Audio::Frame::free_bitrate
Truth table66%2/3
A || B
A= $bitrates[$version[$hr[1]]][$layer[$hr[2]]][$hr[4]]B= $MPEG::Audio::Frame::free_bitrate
ABresult
1X1
011
000
240 2003 my $sample = $samples[$hr[VERSION]][$hr[SAMPLE]];
241  
242 2003 ▶ my $use_smaller = $hr[VERSION] == 2 || $hr[VERSION] == 0; # FIXME VERSION == 2 means no support for MPEG2 multichannel
Condition100%3/3
$hr[1] == 2 || $hr[1] == 0
l!l&&r!l&&!r
40201943
MC/DC100%2/2
$hr[1] == 2 || $hr[1] == 0
$hr[1] == 2 $hr[1] == 0
Truth table100%3/3
A || B
A= $hr[1] == 2B= $hr[1] == 0
ABresult
1X1
011
000
243 2003 ▶ my $length = $layer[$hr[LAYER]]
Branch: 3 branches
BranchTrueFalseTotal
$layer[$hr[2]] ? : 1596 407 2003
$use_smaller ? : 60 1536 1596
$use_smaller ? : 0 407 407
244 ? (($use_smaller ? 72 : 144) * ($bitrate * 1000) / $sample + $hr[PAD]) # layers 2 & 3
245 : ((($use_smaller ? 6 : 12 ) * ($bitrate * 1000) / $sample + $hr[PAD]) * 4); # layer 1
246
247 2003 ▶ my $clength = $length - 4 - ($hr[CRC] ? 0 : 2);
Branch: 1 branch
BranchTrueFalseTotal
$hr[3] ? : 1396 607 2003
248 2003 ▶ (read $fh, my($content), $clength or return undef) == $clength or return undef; # appearantly header length is included... learned this the hard way.
Branch: 1 branch
BranchTrueFalseTotal
(CORE::read($fh, my $content, $clength) || (return undef)) == $clength or return undef 1989 14 2003
Condition50%1/2
CORE::read($fh, my $content, $clength) || (return undef)
l!l
20030
MC/DC0%0/1
CORE::read($fh, my $content, $clength) || (return undef)
CORE::read($fh, my $content, $clength)
Truth table50%1/2
A
A= CORE::read($fh, my $content, $clength)
Aresult
11
00
249
250 1989 my $self = bless {}, $pkg;
251
252 1989 %$self = (
253 binhead => $header, # binary header
254 header => \@hr, # array of integer header records
255 content => $content, # the actuaol content of the frame, excluding the header and crc
256 length => $length, # the length of the header + content == length($frame->content()) + 4 + ($frame->crc() ? 2 : 0);
257 bitrate => $bitrate, # the bitrate, in kilobits
258 sample => $sample, # the sample rate, in Hz
259 offset => $offset, # the offset where the header was found in the handle, based on tell
260 crc_sum => $sum, # the bytes of the network order short that is the crc sum
261 );
262  
263 1989 $self;
264 }
265  
266 # methods
267  
268 111 ▶sub asbin { # binary representation of the frame
Subroutine asbin: called CC=1 SCAR=0.0
Pod documented
269 111 my $self = shift;
270 $self->{binhead} . $self->{crc_sum} . $self->{content}
271 111 }
272  
273 0 ▶sub content { # byte content of frame, no header, no CRC sum
Subroutine content: not called CC=1 SCAR=6.9
Pod documented
274 0 my $self = shift;
275 $self->{content}
276 0 }
277  
278 0 ▶sub header { # array of records in list context, binary header in scalar context
Subroutine header: not called CC=2 SCAR=17.9
Pod documented
279 0 my $self = shift;
280 wantarray
281 0 ? @{ $self->{header} }
282 : $self->{binhead}
283 0 ▶}
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
284  
285 3 ▶sub crc { # the actual sum bytes
Subroutine crc: called CC=1 SCAR=0.0
Pod documented
286 3 my $self = shift;
287 $self->{crc_sum}
288 3 }
289  
290 2664 ▶sub has_crc { # does a crc exist?
Subroutine has_crc: called CC=1 SCAR=0.0
Pod documented
291 2664 my $self = shift;
292 2664 not $self->{header}[CRC];
293 }
294  
295 112 ▶sub length { # length of frame in bytes, including header and header CRC
Subroutine length: called CC=1 SCAR=0.0
Pod documented
296 112 my $self = shift;
297 $self->{length}
298 112 }
299  
300 1666 ▶sub bitrate { # symbolic bit rate
Subroutine bitrate: called CC=1 SCAR=0.0
Pod documented
301 1666 my $self = shift;
302 $self->{bitrate}
303 1666 }
304  
305 68 ▶sub free_bitrate {
Subroutine free_bitrate: called CC=1 SCAR=0.0
Pod documented
306 68 my $self = shift;
307 68 $self->{header}[BITRATE] == 0;
308 }
309  
310 2087 ▶sub sample { # symbolic sample rate
Subroutine sample: called CC=1 SCAR=0.0
Pod documented
311 2087 my $self = shift;
312 $self->{sample}
313 2087 }
314  
315 2251 ▶sub channels { # the data we want is the data in the header in this case
Subroutine channels: called CC=1 SCAR=0.0
Pod documented
316 2251 my $self = shift;
317 2251 $self->{header}[CHANMODE]
318 }
319  
320 524 ▶sub stereo {
Subroutine stereo: called CC=1 SCAR=0.0
Pod documented
321 524 my $self = shift;
322 524 $self->channels == 0;
323 }
324  
325 551 ▶sub joint_stereo {
Subroutine joint_stereo: called CC=1 SCAR=0.0
Pod documented
326 551 my $self = shift;
327 551 $self->channels == 1;
328 }
329  
330 75 ▶sub dual_channel {
Subroutine dual_channel: called CC=1 SCAR=0.0
Pod documented
331 75 my $self = shift;
332 75 $self->channels == 2;
333 }
334  
335 1052 ▶sub mono {
Subroutine mono: called CC=1 SCAR=0.0
Pod documented
336 1052 my $self = shift;
337 1052 $self->channels == 3;
338 }
339  
340 307 ▶sub modext {
Subroutine modext: called CC=1 SCAR=0.0
Pod documented
341 307 my $self = shift;
342 307 $self->{header}[MODEXT];
343 }
344  
345 240 ▶sub _jmodes {
Subroutine _jmodes: called CC=2 SCAR=7.2
346 240 my $self = shift;
347 240 ▶ $self->layer3 || die "Joint stereo modes only make sense with layer III"
Branch: 1 branch
BranchTrueFalseTotal
$self->layer3 or die "Joint stereo modes only make sense with layer III" 240 0 240
348 }
349  
350 10 ▶sub normal_joint_stereo {
Subroutine normal_joint_stereo: called CC=4 SCAR=17.9
Pod documented
351 10 my $self = shift;
352 10 ▶ $self->_jmodes && $self->joint_stereo && !$self->intensity_stereo && !$self->ms_stereo;
Branch: 1 branch
BranchTrueFalseTotal
$self->_jmodes and $self->joint_stereo and not $self->intensity_stereo and not $self->ms_stereo 10 0 10
Condition33%2/6
$self->_jmodes and $self->joint_stereo and not $self->intensity_stereo
!ll&&!rl&&r
0010
$self->_jmodes and $self->joint_stereo
!ll&&!rl&&r
0010
MC/DC0%0/3
$self->_jmodes and $self->joint_stereo and not $self->intensity_stereo
$self->_jmodes $self->joint_stereo not $self->intensity_stereo
Truth table25%1/4
A and B and not(C)
A= $self->_jmodesB= $self->joint_stereoC= not $self->intensity_stereo
ABCresult
0XX0
10X0
1100
1111
353 }
354  
355 80 ▶sub intensity_stereo {
Subroutine intensity_stereo: called CC=3 SCAR=13.1
Pod documented
356 80 my $self = shift;
357 80 ▶ $self->_jmodes and $self->joint_stereo and $self->modext % 2 == 1;
Branch: 1 branch
BranchTrueFalseTotal
$self->_jmodes and $self->joint_stereo and $self->modext % 2 == 1 80 0 80
Condition33%1/3
$self->_jmodes and $self->joint_stereo
!ll&&!rl&&r
0080
MC/DC0%0/2
$self->_jmodes and $self->joint_stereo
$self->_jmodes $self->joint_stereo
Truth table33%1/3
A and B
A= $self->_jmodesB= $self->joint_stereo
ABresult
0X0
100
111
358 }
359  
360 30 ▶sub intensity_stereo_only {
Subroutine intensity_stereo_only: called CC=3 SCAR=13.1
Pod documented
361 30 my $self = shift;
362 30 ▶ $self->_jmodes && $self->intensity_stereo && !$self->ms_stereo;
Branch: 1 branch
BranchTrueFalseTotal
$self->_jmodes and $self->intensity_stereo and not $self->ms_stereo 30 0 30
Condition33%1/3
$self->_jmodes and $self->intensity_stereo
!ll&&!rl&&r
0030
MC/DC0%0/2
$self->_jmodes and $self->intensity_stereo
$self->_jmodes $self->intensity_stereo
Truth table33%1/3
A and B
A= $self->_jmodesB= $self->intensity_stereo
ABresult
0X0
100
111
363 }
364  
365 80 ▶sub ms_stereo {
Subroutine ms_stereo: called CC=3 SCAR=13.1
Pod documented
366 80 my $self = shift;
367 80 ▶ $self->_jmodes and $self->joint_stereo and $self->modext > 1;
Branch: 1 branch
BranchTrueFalseTotal
$self->_jmodes and $self->joint_stereo and $self->modext > 1 80 0 80
Condition33%1/3
$self->_jmodes and $self->joint_stereo
!ll&&!rl&&r
0080
MC/DC0%0/2
$self->_jmodes and $self->joint_stereo
$self->_jmodes $self->joint_stereo
Truth table33%1/3
A and B
A= $self->_jmodesB= $self->joint_stereo
ABresult
0X0
100
111
368 }
369  
370 10 ▶sub ms_stereo_only {
Subroutine ms_stereo_only: called CC=3 SCAR=14.2
Pod documented
371 10 my $self = shift;
372 10 ▶ $self->_jmodes and $self->ms_stereo && !$self->intensity_stereo;
Branch: 1 branch
BranchTrueFalseTotal
$self->_jmodes and ($self->ms_stereo and not $self->intensity_stereo) 10 0 10
Condition33%2/6
$self->_jmodes && ($self->ms_stereo && !$self->intensity_stereo)
!ll&&!rl&&r
0010
$self->ms_stereo and not $self->intensity_stereo
!ll&&!rl&&r
0010
MC/DC0%0/3
$self->_jmodes && ($self->ms_stereo && !$self->intensity_stereo)
$self->_jmodes $self->ms_stereo not $self->intensity_stereo
Truth table25%1/4
A && B and not(C)
A= $self->_jmodesB= $self->ms_stereoC= not $self->intensity_stereo
ABCresult
0XX0
10X0
1100
1111
373 }
374  
375 30 ▶sub ms_and_intensity_stereo {
Subroutine ms_and_intensity_stereo: called CC=3 SCAR=14.2
Pod documented
376 30 my $self = shift;
377 30 ▶ $self->_jmodes and $self->ms_stereo && $self->intensity_stereo;
Branch: 1 branch
BranchTrueFalseTotal
$self->_jmodes and ($self->ms_stereo and $self->intensity_stereo) 30 0 30
Condition33%2/6
$self->_jmodes && ($self->ms_stereo && $self->intensity_stereo)
!ll&&!rl&&r
0030
$self->ms_stereo and $self->intensity_stereo
!ll&&!rl&&r
0030
MC/DC0%0/3
$self->_jmodes && ($self->ms_stereo && $self->intensity_stereo)
$self->_jmodes $self->ms_stereo $self->intensity_stereo
Truth table25%1/4
A && B and C
A= $self->_jmodesB= $self->ms_stereoC= $self->intensity_stereo
ABCresult
0XX0
10X0
1100
1111
378 }
379 31 *intensity_and_ms_stereo = \&ms_and_intensity_stereo;
380  
381 0 ▶sub _bands {
Subroutine _bands: not called CC=2 SCAR=17.9
382 0 my $self = shift;
383 0 ▶ !$self->layer3 || die "Intensity stereo bands only make sense with layers I I";
Branch: 1 branch
BranchTrueFalseTotal
not $self->layer3 or die "Intensity stereo bands only make sense with layers I I" 0 0 0
384 }
385  
386 0 ▶sub band_4 {
Subroutine band_4: not called CC=2 SCAR=17.9
Pod documented
387 0 my $self = shift;
388 0 ▶ $self->_bands and $self->modext == 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->_bands and $self->modext == 0 0 0 0
389 }
390  
391 0 ▶sub band_8 {
Subroutine band_8: not called CC=2 SCAR=17.9
Pod documented
392 0 my $self = shift;
393 0 ▶ $self->_bands and $self->modext == 1;
Branch: 1 branch
BranchTrueFalseTotal
$self->_bands and $self->modext == 1 0 0 0
394 }
395  
396 0 ▶sub band_12 {
Subroutine band_12: not called CC=2 SCAR=17.9
Pod documented
397 0 my $self = shift;
398 0 ▶ $self->_bands and $self->modext == 2;
Branch: 1 branch
BranchTrueFalseTotal
$self->_bands and $self->modext == 2 0 0 0
399 }
400  
401 0 ▶sub band_16 {
Subroutine band_16: not called CC=2 SCAR=17.9
Pod documented
402 0 my $self = shift;
403 0 ▶ $self->_bands and $self->modext == 3;
Branch: 1 branch
BranchTrueFalseTotal
$self->_bands and $self->modext == 3 0 0 0
404 }
405  
406 147 ▶sub any_stereo {
Subroutine any_stereo: called CC=2 SCAR=6.9
Pod documented
407 147 my $self = shift;
408 147 ▶ $self->stereo or $self->joint_stereo;
Branch: 1 branch
BranchTrueFalseTotal
$self->stereo or $self->joint_stereo 30 117 147
409 }
410  
411 104 ▶sub seconds { # duration in floating point seconds
Subroutine seconds: called CC=4 SCAR=14.6
Pod documented
412 104 my $self = shift;
413  
414 31 ▶ no integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
415 $layer[$self->{header}[LAYER]]
416 ? (($version[$self->{header}[VERSION]] == 0 ? 1152 : 576) / $self->sample())
417 104 ▶ : (($version[$self->{header}[VERSION]] == 0 ? 384 : 192) / $self->sample())
Branch: 3 branches
BranchTrueFalseTotal
$layer[$self->{'header'}[2]] ? : 104 0 104
$version[$self->{'header'}[1]] == 0 ? : 45 59 104
$version[$self->{'header'}[1]] == 0 ? : 0 0 0
418 }
419  
420 0 ▶sub framerate {
Subroutine framerate: not called CC=1 SCAR=0.2
Pod documented
421 31 ▶ no integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
422 0 1 / $_[0]->seconds();
423 }
424  
425 0 ▶sub pad {
Subroutine pad: not called CC=1 SCAR=6.9
Pod documented
426 0 my $self = shift;
427 0 $self->{header}[PAD];
428 }
429  
430 30 ▶sub home {
Subroutine home: called CC=1 SCAR=0.0
Pod documented
431 30 my $self = shift;
432 30 $self->{header}[HOME];
433 }
434  
435 30 ▶sub copyright {
Subroutine copyright: called CC=1 SCAR=0.0
Pod documented
436 30 my $self = shift;
437 30 $self->{header}[COPY];
438 }
439  
440 30 ▶sub private {
Subroutine private: called CC=1 SCAR=0.0
Pod documented
441 30 my $self = shift;
442 30 $self->{header}[PRIVATE];
443 }
444  
445 1978 ▶sub version {
Subroutine version: called CC=1 SCAR=0.0
Pod documented
446 1978 my $self = shift;
447 1978 $self->{header}[VERSION];
448 }
449  
450 1919 ▶sub mpeg1 {
Subroutine mpeg1: called CC=1 SCAR=0.0
Pod documented
451 1919 my $self = shift;
452 1919 $self->version == 3;
453 }
454  
455 40 ▶sub mpeg2 {
Subroutine mpeg2: called CC=1 SCAR=0.0
Pod documented
456 40 my $self = shift;
457 40 $self->version == 2;
458 }
459  
460 19 ▶sub mpeg25 {
Subroutine mpeg25: called CC=1 SCAR=0.0
Pod documented
461 19 my $self = shift;
462 19 $self->version == 0;
463 }
464  
465 2218 ▶sub layer {
Subroutine layer: called CC=1 SCAR=0.0
Pod documented
466 2218 my $self = shift;
467 2218 $self->{header}[LAYER];
468 }
469  
470 405 ▶sub layer1 {
Subroutine layer1: called CC=1 SCAR=0.0
Pod documented
471 405 my $self = shift;
472 405 $self->layer == 3;
473 }
474  
475 320 ▶sub layer2 {
Subroutine layer2: called CC=1 SCAR=0.0
Pod documented
476 320 my $self = shift;
477 320 $self->layer == 2;
478 }
479  
480 1493 ▶sub layer3 {
Subroutine layer3: called CC=1 SCAR=0.0
Pod documented
481 1493 my $self = shift;
482 1493 $self->layer == 1;
483 }
484  
485 30 ▶sub emph {
Subroutine emph: called CC=1 SCAR=0.0
Pod documented
486 30 my $self = shift;
487 30 $self->{header}[EMPH];
488 }
489 31 *emphasize = \&emph;
490 31 *emphasise = \&emph;
491 31 *emphasis = \&emph;
492  
493 3 ▶sub offset { # the position in the handle where the frame was found
Subroutine offset: called CC=1 SCAR=0.0
Pod documented
494 3 my $self = shift;
495 $self->{offset}
496 3 }
497  
498 0 ▶sub crc_ok {
Subroutine crc_ok: not called CC=1 SCAR=6.9
Pod documented
499 0 not shift->broken;
500 }
501  
502 1935 ▶sub broken { # was the crc broken?
Subroutine broken: called CC=8 SCAR=21.0
Pod documented
503 1935 my $self = shift;
504 1935 ▶ if (not defined $self->{broken}){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"broken"}) 1935 0 1935
505 1935 ▶ return $self->{broken} = 0 unless $self->has_crc; # we assume it's OK if we have no CRC at all
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_crc 1328 607 1935
506 607 ▶ return $self->{broken} = 0 unless (($self->{header}[LAYER] & 0x02) == 0x00); # can't sum
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"header"}[2] & 2) == 0 578 29 607
507  
508 29 ▶ my $bits = $protbits[$layer[$self->{header}[LAYER]]][$self->{header}[CHANMODE] == 0x03 ? 0 : 1 ];
Branch: 1 branch
BranchTrueFalseTotal
$self->{'header'}[8] == 3 ? : 0 29 29
509 29 my $i;
510
511 29 my $c = 0xffff;
512
513 29 $c = ($c << 8) ^ $crc_table[(($c >> 8) ^ ord((substr($self->{binhead},2,1)))) & 0xff];
514 29 $c = ($c << 8) ^ $crc_table[(($c >> 8) ^ ord((substr($self->{binhead},3,1)))) & 0xff];
515  
516 29 ▶ for ($i = 0; $bits >= 32; do { $bits-=32; $i+=4 }){
Branch: 1 branch
BranchTrueFalseTotal
if ($bits >= 32) 232 29 261
517 232 my $data = unpack("N",substr($self->{content},$i,4));
518
519 232 $c = ($c << 8) ^ $crc_table[(($c >> 8) ^ ($data >> 24)) & 0xff];
520 232 $c = ($c << 8) ^ $crc_table[(($c >> 8) ^ ($data >> 16)) & 0xff];
521 232 $c = ($c << 8) ^ $crc_table[(($c >> 8) ^ ($data >> 8)) & 0xff];
522 232 $c = ($c << 8) ^ $crc_table[(($c >> 8) ^ ($data >> 0)) & 0xff];
523
524 }
525 29 ▶ while ($bits >= 8){
Branch: 1 branch
BranchTrueFalseTotal
if ($bits >= 8) 0 29 29
526 0 $c = ($c << 8) ^ $crc_table[(($c >> 8) ^ (ord(substr($self->{content},$i++,1)))) & 0xff];
527 0 } continue { $bits -= 8 }
528 29 ▶ $self->{broken} = (( $c & 0xffff ) != unpack("n",$self->{crc_sum})) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
($c & 65535) != unpack('n', $self->{'crc_sum'}) ? : 2 27 29
529 }
530  
531 29 return $self->{broken};
532 }
533  
534  
535 # tie hack
536  
537 1 ▶sub TIEHANDLE { bless \$_[1],$_[0] } # encapsulate the handle to save on unblessing and stuff
Subroutine TIEHANDLE: called CC=1 SCAR=0.0
538 1 ▶sub READLINE { (ref $_[0])->read(${$_[0]}) } # read from the encapsulated handle
Subroutine READLINE: called CC=1 SCAR=0.0
539  
540 31 1; # keep your mother happy
541  
542 __END__
↑ Summary