Info/MPEG.pm

filter: Statementstmt 70.0% 178 / 254 Branchbran 61.5% 48 / 78 Conditioncond 64.2% 9 / 14 MC/DCmcdc 28.5% 2 / 7 Subroutinesub 82.7% 24 / 29 Podpod 11.7% 2 / 17 totaltotal 65.9% 263 / 399 CC 50 SCAR 21.4
CC
50
Cov
68%
parse_seq_ext
20.0
next_start_code
16.1
parse_extension
12.0
CRAP 8.5
« Info/MPEG/System.pm ↑ Summary Info.pm »
1 ##------------------------------------------------------------------------
2 ## Package: MPEG.pm
3 ## Author: Benjamin R. Ginter, Allen Day
4 ## Notice: Copyright (c) 2001 Benjamin R. Ginter, Allen Day
5 ## Purpose: Extract information about MPEG files.
6 ## Comments: None
7 ## CVS: $Id: MPEG.pm,v 1.7 2002/11/13 01:05:17 allenday Exp $
8 ##------------------------------------------------------------------------
9  
10 package Video::Info::MPEG;
11  
12 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 5 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 #use Video::Info;
15 5 ▶use Video::Info::Magic;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 5 ▶use Video::Info::MPEG::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 5 ▶use Video::Info::MPEG::Audio;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 5 ▶use Video::Info::MPEG::Video;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 5 ▶use Video::Info::MPEG::System;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 #use base qw(Video::Info);
22  
23 5 ▶use constant DEBUG => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 use Class::MakeMethods::Emulator::MethodMaker
26 5 ▶ get_set => [
Subroutine BEGIN: called CC=1 SCAR=0.0
27 'type',
28 'copyright',
29 'comments',
30
31 'astreams', #no. of audio streams. can this clash with achans?
32 #this has special behavior, method is below
33 'acodec', #audio codec
34 'acodecraw', #audio codec (numeric)
35 'arate', #audio bitrate
36 'achans', #no. of audio channels. can this clash with astreams?
37 'afrequency',
38
39 'vstreams', #no. of video streams
40 'vcodec', #video codec
41 'vrate', #video bitrate
42 #this has special behavior, method is below
43 #'vframes', #no. of video frames
44
45 'fps', #video frames/second
46 'scale', #quoeth transcode: if(scale!=0) AVI->fps = (double)rate/(double)scale;
47 'duration', #duration of video, in seconds
48
49 'width', #frame width
50 'height', #frame height
51
52 'aspect_raw', #how to handle this? 16:9 scalar, or 16/9 float?
53 'aspect', #not sure what this is. from MPEG
54
55 '_handle', #filehandle to bitstream
56
57 'offset',
58 'last_offset',
59
60 'header_size',
61
62 'filesize',
63 'filename',
64 'audio_system_header',
65 'video_system_header',
66 'version',
67 'context',
68
69 'minutes',
70 'MMSS',
71 'title',
72 'author',
73 'description',
74 'rating',
75 'packets',
76 ],
77 new_with_init => 'new',
78 5 ;
79  
80 #
81 ### Get the file versions in sync with CVS
82 #our $VERSION = do { my @r = (q$Version$ =~ /\d+/g); sprintf " %d."."%02d" x $#r, @r };
83  
84 5 $| = 1;
85  
86 6 ▶sub init {
Subroutine init: called CC=1 SCAR=0.0
Pod undocumented
87 6 my $self = shift;
88  
89 6 $self->offset(0);
90 6 $self->filesize(0);
91 6 $self->audio_system_header(0);
92 6 $self->video_system_header(0);
93 6 $self->version(1);
94  
95 6 $self->init_attributes(@_);
96  
97 6 $self->{audio} = Video::Info::MPEG::Audio->new( -file => $self->filename);
98 6 $self->{video} = Video::Info::MPEG::Video->new( -file => $self->filename);
99 6 $self->{system} = Video::Info::MPEG::System->new(-file => $self->filename);
100 }
101  
102 38 ▶sub init_attributes {
Subroutine init_attributes: called CC=5 SCAR=16.1
Pod undocumented
103 38 my $self = shift;
104 38 my %raw_param = @_;
105 38 my %param;
106 38 foreach(keys %raw_param){/^-?(.+)/;$param{$1} = $raw_param{$_}};
107  
108 38 foreach my $attr (qw(
109 astreams arate achans vstreams vrate fps
110 scale duration width height aspect aspect_raw
111 )
112 ) {
113 456 $self->$attr(0);
114 }
115  
116 38 $self->filename($param{file});
117 38 ▶ $self->filesize(-s $self->filename || 0);
Condition100%2/2
-s $self->filename || 0
l!l
2612
MC/DC100%1/1
-s $self->filename || 0
-s $self->filename
Truth table100%2/2
A
A= -s $self->filename
Aresult
11
00
118 38 ▶ $self->handle($self->filename) if $self->filename;
Branch: 1 branch
BranchTrueFalseTotal
if $self->filename 26 12 38
119 }
120  
121 205459 ▶sub handle {
Subroutine handle: called CC=3 SCAR=11.0
Pod undocumented
122 205459 my($self,$file) = @_;
123  
124 205459 ▶ if(defined $file){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $file) 56 205403 205459
125 56 my $fh = new IO::File;
126 56 ▶ $fh->open($file) or die "couldn't open $file";
Branch: 1 branch
BranchTrueFalseTotal
$fh->open($file) or die "couldn't open $file" 56 0 56
127 56 $self->_handle($fh);
128 }
129 205459 return $self->_handle;
130 }
131  
132 ##------------------------------------------------------------------------
133 ## Extra methods
134 ##
135 ##------------------------------------------------------------------------
136 1 ▶sub minutes {
Subroutine minutes: called CC=1 SCAR=0.0
137 1 my $self = shift;
138 1 my $seconds = int($self->duration) % 60;
139 1 my $minutes = (int($self->duration) - $seconds) / 60;
140 1 return $minutes;
141 }
142  
143 0 ▶sub MMSS {
Subroutine MMSS: not called CC=1 SCAR=6.9
144 0 my $self = shift;
145 0 my $mm = $self->minutes;
146 0 my $ss = int($self->duration) - ($self->minutes * 60);
147  
148 0 my $return = sprintf( "%02d:%02d",$mm,$ss );
149 }
150  
151 ##------------------------------------------------------------------------
152 ## probe()
153 ##
154 ## Probe the file for content type
155 ##------------------------------------------------------------------------
156 8 ▶sub probe {
Subroutine probe: called CC=6 SCAR=17.9
Pod documented
157 8 print "probe()\n" if DEBUG;
158 8 my $self = shift;
159  
160 8 ▶ if ( $self->audio->parse ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($self->audio->parse) { } 2 6 8
elsif ($self->video->parse) { } 3 3 6
elsif ($self->system->parse) { } 3 0 3
161 2 print "MPEG Audio Only\n" if DEBUG;
162 2 $self->type($self->audio->type);
163 2 $self->acodec($self->audio->acodecraw);
164 2 $self->astreams(1); #are you sure? could be multiple audio...
165 2 $self->vstreams(0);
166 2 $self->arate($self->audio->arate);
167 2 $self->achans($self->audio->achans);
168 2 $self->acodecraw($self->audio->acodecraw);
169 2 $self->acodec(acodec2str($self->acodecraw));
170 2 return 1;
171 }
172 elsif ( $self->video->parse ) {
173 3 print "MPEG Video Only\n" if DEBUG;
174 3 $self->vstreams(1); #are you sure? could be multiple video...
175 3 $self->astreams(0);
176 3 ▶ $self->vcodec( 'MPEG1' ) if $self->vcodec eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $self->vcodec eq "" 2 1 3
177 3 $self->height($self->video->height);
178 3 $self->width($self->video->width);
179 3 $self->vrate($self->video->vrate);
180 3 $self->fps($self->video->fps);
181 3 $self->type($self->video->type);
182 3 return 1;
183 }
184 elsif ( $self->system->parse ) {
185 3 print "MPEG Audio/Video\n" if DEBUG;
186 3 $self->astreams(1); #are you sure? could be multiple video...
187 3 $self->vstreams(1); #are you sure? could be multiple video...
188 3 $self->type($self->system->video->type);
189 3 $self->acodecraw($self->system->audio->acodecraw);
190 3 $self->acodec(acodec2str($self->system->audio->acodecraw));
191 3 $self->achans($self->system->audio->achans);
192 3 $self->arate($self->system->audio->arate);
193 3 $self->fps($self->system->video->fps);
194 3 $self->height($self->system->video->height);
195 3 $self->width($self->system->video->width);
196 3 ▶ $self->vcodec( 'MPEG1' ) if $self->vcodec eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $self->vcodec eq "" 2 1 3
197 3 $self->duration($self->system->duration);
198 3 $self->vrate($self->system->video->vrate);
199 3 $self->vframes($self->system->video->vframes);
200 3 $self->comments($self->system->video->comments);
201 3 return 1;
202 }
203  
204 0 return 0;
205 }
206  
207 18 ▶sub audio { $_[0]->{audio} };
Subroutine audio: called CC=1 SCAR=0.0
Pod undocumented
208 39 ▶sub system { $_[0]->{system} };
Subroutine system: called CC=1 SCAR=0.0
Pod undocumented
209 21 ▶sub video { $_[0]->{video} };
Subroutine video: called CC=1 SCAR=0.0
Pod undocumented
210 #sub acodecraw { $_[0]->acodec };
211  
212  
213 ##------------------------------------------------------------------------
214 ## parse_system()
215 ##
216 ## Parse a system stream
217 ##------------------------------------------------------------------------
218 0 ▶sub parse_system {
Subroutine parse_system: not called CC=2 SCAR=17.9
Pod undocumented
219 0 my $self = shift;
220 0 my $fh = $self->handle;
221 0 my $offset = 0;
222  
223 0 my ( $pack_start, $pack_len, $pack_head, $packet_size, $packet_type );
224 # print '-' x 74, "\n", "Parse System\n", '-' x 74, "\n";
225  
226 ## Get the first sequence start code (ssc)
227 0 ▶ if ( !$self->next_start_code( PACK_PKT ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->next_start_code(186)) 0 0 0
228 0 print "Couldn't find packet start code\n" if DEBUG;
229 0 return 0;
230 }
231  
232 0 return 1;
233 }
234  
235 ##------------------------------------------------------------------------
236 ## parse_user_data()
237 ##
238 ## Parse user data (usually encoder version, etc.)
239 ##
240 ## TODO: Can we use this for annotating video?
241 ##------------------------------------------------------------------------
242 2 ▶sub parse_user_data {
Subroutine parse_user_data: called CC=8 SCAR=21.8
Pod undocumented
243 2 my $self = shift;
244 2 my $offset = shift;
245  
246 # print "\n", '-' x 74, "\nParse User Data\n", '-' x 74, "\n";
247  
248 2 $self->next_start_code( undef, $offset + 1 );
249  
250 2 my $all_printable = 1;
251 2 my $size = $self->{last_offset} - $offset - 4;
252  
253 2 ▶ return 0 if $size <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $size <= 0 0 2 2
254  
255 2 ▶ for ( my $i = $offset + 4; $i < $self->{last_offset}; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $self->{"last_offset"}) 146 2 148
256 146 my $char = $self->get_byte( $i );
257 146 ▶ if ( $char < 0x20 && $char != 0x0A && $char != 0x0D ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char < 32 and $char != 10 and $char != 13) 0 146 146
Condition50%3/6
$char < 32 and $char != 10 and $char != 13
!ll&&!rl&&r
14600
$char < 32 and $char != 10
!ll&&!rl&&r
14060
MC/DC0%0/3
$char < 32 and $char != 10 and $char != 13
$char < 32 $char != 10 $char != 13
Truth table50%2/4
A and B and C
A= $char < 32B= $char != 10C= $char != 13
ABCresult
0XX0
10X0
1100
1111
258 0 $all_printable = 0;
259 0 last;
260 }
261 }
262  
263 2 ▶ if ( $all_printable ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($all_printable) 2 0 2
264 2 my $data;
265  
266 2 ▶ for ( my $i = 0; $i < $size; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $size) 146 2 148
267 146 $data .= chr( $self->get_byte( $offset + 4 + $i ) );
268  
269 }
270 2 $self->{userdata} = $data;
271 2 $self->comments( $data );
272 # print $data, "\n";
273 }
274 2 return 1;
275 }
276  
277 ##------------------------------------------------------------------------
278 ## parse_extension()
279 ##
280 ## Parse extensions to MPEG.. hrm, I need some examples to really test
281 ## this.
282 ##------------------------------------------------------------------------
283 0 ▶sub parse_extension {
Subroutine parse_extension: not called CC=3 SCAR=24.8
Pod undocumented
284 0 my $self = shift;
285 0 my $offset = ( shift ) + 4;
286
287 0 my $code = $self->get_byte( $offset ) >> 4;
288
289 0 ▶ if ( $code == 1 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($code == 1) { } 0 0 0
elsif ($code == 2) { } 0 0 0
290 0 return $self->parse_seq_ext( $offset );
291 }
292 elsif ( $code == 2 ) {
293 0 return $self->parse_seq_display_ext( $offset );
294 }
295 else {
296 0 die "Unknown Extension: $code\n";
297 }
298 }
299  
300 ##------------------------------------------------------------------------
301 ## parse_seq_ext()
302 ##
303 ## This stuff gets stored in the hashref $self->{sext}. It will also
304 ## modify width, height, vrate, and fps
305 ##------------------------------------------------------------------------
306 0 ▶sub parse_seq_ext {
Subroutine parse_seq_ext: not called CC=4 SCAR=30.0
Pod undocumented
307 0 my $self = shift;
308 0 my $offset = shift;
309
310 ## We are an MPEG-2 file
311 0 $self->version( 2 );
312  
313 0 my $byte1 = $self->get_byte( $offset + 1 );
314 0 my $byte2 = $self->get_byte( $offset + 2 );
315  
316 ## Progressive scan mode?
317 0 ▶ if ( $byte1 & 0x08 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($byte1 & 8) 0 0 0
318 0 $self->{sext}->{progressive} = 1;
319 }
320
321 ## Chroma format
322 0 $self->{sext}->{chroma_format} = ( $byte1 & 0x06 ) >> 1;
323  
324 ## Width
325 0 my $hsize = ( $byte1 & 0x01 ) << 1;
326 0 $hsize |= ( $byte2 & 80 ) >> 7;
327 0 $hsize <<= 12;
328 0 ▶ return 0 if !$self->{vstreams};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"vstreams"} 0 0 0
329 0 $self->{width} |= $hsize;
330
331 ## Height
332 0 $self->{height} |= ( $byte2 & 0x60 ) << 7;;
333
334 ## Video Bitrate
335 0 my $bitrate = ( $byte2 & 0x1F ) << 7;
336 0 $bitrate |= ( $self->get_byte( $offset + 3 ) & 0xFE ) >> 1;
337 0 $bitrate <<= 18;
338 0 $self->{vrate} |= $bitrate;
339  
340 ## Delay
341 0 ▶ if ( $self->get_byte( $offset + 5 ) & 0x80 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_byte($offset + 5) & 128) { } 0 0 0
342 0 $self->{sext}->{low_delay} = 1;
343 }
344 else {
345 0 $self->{sext}->{low_delay} = 0;
346 }
347  
348 ## Frame Rate
349 0 my $frate_n = ( $self->get_byte( $offset + 5 ) & 0x60 ) >> 5;
350 0 my $frate_d = ( $self->get_byte( $offset + 5 ) & 0x1F );
351
352 0 $frate_n++;
353 0 $frate_d++;
354
355 0 $self->{fps} = ( $self->{fps} * $frate_n ) / $frate_d;
356
357 0 return 1;
358 }
359  
360 ##------------------------------------------------------------------------
361 ## parse_seq_display_ext()
362 ##
363 ## man, some specs would be nice
364 ##------------------------------------------------------------------------
365 0 ▶sub parse_seq_display_ext {
Subroutine parse_seq_display_ext: not called CC=3 SCAR=24.8
Pod undocumented
366 0 my $self = shift;
367 0 my $offset = shift;
368
369 0 my @codes = ();
370
371 0 for ( 0..4 ) {
372 0 push @codes, $self->get_byte( $offset + $_ );
373 }
374  
375 0 $self->{dext}->{video_format} = ( $codes[0] & 0x0E ) >> 1;
376
377 0 ▶ if ( $codes[0] & 0x01 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($codes[0] & 1) { } 0 0 0
378 0 $self->{dext}->{colour_prim} = $codes[1];
379 0 $self->{dext}->{transfer_char} = $codes[2];
380 0 $self->{dext}->{matrix_coeff} = $codes[3];
381 0 $offset += 3;
382 }
383 else {
384 0 $self->{dext}->{color_prim} = 0;
385 0 $self->{dext}->{transfer_char} = 0;
386 0 $self->{dext}->{matrix_coeff} = 0;
387 }
388  
389 0 $self->{dext}->{h_display_size} = $codes[1] << 6;
390 0 $self->{dext}->{h_display_size} |= ( $codes[2] & 0xFC ) >> 2;
391
392 0 $self->{dext}->{v_display_size} = ( $codes[2] & 0x01 ) << 13;
393 0 $self->{dext}->{v_display_size} |= $codes[3] << 5;
394 0 $self->{dext}->{v_display_size} |= ( $codes[4] & 0xF8 ) >> 3;
395  
396 0 return 1;
397 }
398  
399 ##------------------------------------------------------------------------
400 ## next_start_code()
401 ##
402 ## Find the next sequence start code
403 ##------------------------------------------------------------------------
404 32 ▶sub next_start_code {
Subroutine next_start_code: called CC=15 SCAR=27.8
Pod undocumented
405 32 my $self = shift;
406 32 my $start_code = shift;
407 32 my $offset = shift;
408 32 ▶ my $debug = shift || 0;
Condition100%2/2
shift() || 0
l!l
626
MC/DC100%1/1
shift() || 0
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
409  
410 32 my $fh = $self->handle;
411  
412 ## huh?
413 32 ▶ $offset = $self->{offset} if !defined $offset;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $offset 0 32 32
414 32 my $skip = 4;
415 32 ▶ if ( !$offset ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($offset) 3 29 32
416 3 ▶ $skip = 1 if !defined $offset;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $offset 0 3 3
417 }
418  
419 32 if ( DEBUG ) {
420 print "Bytes Per Iteration: $skip\n";
421 print "Got $start_code $offset $debug\n" if defined $start_code;
422 print "Offsets: $offset $self->{offset}\n";
423 print "Seeking to $offset\n" if $offset != $self->{offset};
424 }
425  
426 32 seek $fh, $offset, 0;
427  
428 ## die "CALLER: ", ref( $self ), " OFFSET: $offset\n";
429 32 ▶ while ( $offset <= $self->filesize - 4 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($offset <= $self->filesize - 4) 50373 1 50374
430  
431 #print "Grabbing 4 bytes from $offset\n";
432 #my $code = $self->grab( 4, $offset );
433 #my ( $a, $b, $c, $d ) = unpack( 'C4', pack( "N", $code ) );
434  
435 50373 my $a = $self->get_byte( $offset );
436 50373 ▶ if ( $a != 0x00 ) { $offset++; next; }
Branch: 1 branch
BranchTrueFalseTotal
if ($a != 0) 48608 1765 50373
437
438 1765 my $b = $self->get_byte( $offset + 1 );
439 1765 ▶ if ( $b != 0x00 ) { $offset += 2; next; };
Branch: 1 branch
BranchTrueFalseTotal
if ($b != 0) 1228 537 1765
440  
441 537 my $c = $self->get_byte( $offset + 2 );
442 537 ▶ if ( $c != 0x01 ) { $offset += 3; next; };
Branch: 1 branch
BranchTrueFalseTotal
if ($c != 1) 22 515 537
443  
444 515 my $d = $self->get_byte( $offset + 3 );
445  
446 # printf "Found 0x%02x @ %d\n", $d, $offset + 3;
447 # if ( $a == 0x00 && $b == 0x00 && $c == 0x01 ) {
448 515 ▶ if ( defined $start_code ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $start_code) { } 498 17 515
449 498 ▶ if ( ref( $start_code ) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $start_code eq 'ARRAY') { } 0 498 498
450 0 foreach my $sc ( @$start_code ) {
451 0 ▶ if ( $sc == $d ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sc == $d) 0 0 0
452 # print "Got it @ $offset!\n" if DEBUG;
453 0 $self->{last_offset} = $offset;
454 0 return 1;
455 }
456 }
457 }
458 else {
459 498 ▶ if ( $d == $start_code ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($d == $start_code) 14 484 498
460 # print "Got it @ $offset!\n" if DEBUG;
461 14 $self->{last_offset} = $offset;
462 14 return 1;
463 }
464 }
465 }
466 else {
467 17 $self->{last_offset} = $offset;
468 17 return $d;
469 }
470
471 # printf "Skipping 0x%02x 0x%02x 0x%02x 0x%02x @ offset %d\n", $a, $b, $c, $d, $offset;
472 484 $offset++;
473 }
474
475
476 1 ▶ return 0 if defined $start_code;
Branch: 1 branch
BranchTrueFalseTotal
if defined $start_code 1 0 1
477
478 0 die "No More Sequence Start Codes Found!\n";
479 }
480  
481 ##------------------------------------------------------------------------
482 ## _last_offset
483 ##
484 ## Return the last_offset from a search
485 ##------------------------------------------------------------------------
486 12 ▶sub _last_offset {
Subroutine _last_offset: called CC=1 SCAR=0.0
487 12 my $self = shift;
488 12 return $self->{last_offset};
489 }
490  
491 ##------------------------------------------------------------------------
492 ## grab()
493 ##
494 ## Grab n bytes from current offset
495 ##------------------------------------------------------------------------
496 205362 ▶sub grab {
Subroutine grab: called CC=9 SCAR=23.5
Pod undocumented
497 205362 my $self = shift;
498 205362 ▶ my $bytes = shift || 1;
Condition50%1/2
shift() || 1
l!l
2053620
MC/DC0%0/1
shift() || 1
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
499 205362 my $offset = shift;
500 205362 ▶ my $debug = shift || 0;
Condition50%1/2
shift() || 0
l!l
0205362
MC/DC0%0/1
shift() || 0
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
501  
502 205362 my $data;
503 205362 ▶ my $fh = $self->handle or die "$self: Can't get filehandle: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
my $fh = $self->handle or die "${self}: Can't get filehandle: $!\n" 205362 0 205362
504  
505 205362 ▶ $offset = $self->{offset} if !defined $offset;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $offset 0 205362 205362
506  
507 # print "GRAB: $offset $bytes bytes called from ", ref( $self ), "\n";
508  
509 ## Would it be good to cache the bytes we've read to avoid the penalty
510 ## of a seek() and read() at the expense of memory?
511  
512 # print "grab: seeking to $offset to grab $bytes bytes\n";
513 205362 ▶ if ( tell( $fh ) != $offset ) {
Branch: 1 branch
BranchTrueFalseTotal
if (tell $fh != $offset) 1305 204057 205362
514 1305 seek( $fh, $offset, 0 );
515 }
516
517 205362 read( $fh, $data, $bytes );
518  
519 205362 my $type;
520  
521 205362 ▶ if ( $bytes == 1 ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($bytes == 1) { } 205338 24 205362
elsif ($bytes == 2) { } 24 0 24
elsif ($bytes == 4) { } 0 0 0
522 205338 $type = 'C';
523 # return unpack( 'C', $data );
524 }
525 elsif ( $bytes == 2 ) {
526 24 $type = 'n';
527 # return unpack( 'n', $data );
528 }
529 elsif ( $bytes == 4 ) {
530 0 $type = 'N';
531 # return unpack( 'N', $data );
532 }
533 else {
534 0 return $data;
535 }
536  
537 205362 $data = unpack( $type, $data );
538 # if ( defined $START_CODE->{ $data } ) {
539 # print "START CODE: $START_CODE->{ $data }\n";
540 # }
541 # elsif ( defined $STREAM_ID->{$data} ) {
542 # print "STREAM ID: $STREAM_ID->{ $data }\n";
543 # }
544  
545 205362 return $data;
546 }
547  
548 ##------------------------------------------------------------------------
549 ## get_byte()
550 ##
551 ## Return a byte from the specified offset
552 ##------------------------------------------------------------------------
553 205326 ▶sub get_byte {
Subroutine get_byte: called CC=1 SCAR=0.0
Pod undocumented
554 205326 my $self = shift;
555 205326 return $self->grab( 1, shift );
556 }
557  
558 ##------------------------------------------------------------------------
559 ## get_header()
560 ##
561 ## Grab the four bytes we need for the header
562 ##------------------------------------------------------------------------
563 23 ▶sub get_header {
Subroutine get_header: called CC=1 SCAR=0.0
Pod undocumented
564 23 my $self = shift;
565  
566 ## we only need these four bytes
567 ## should do this differently though :|
568 return [ $self->get_byte( $self->{offset} ),
569 $self->get_byte( $self->{offset} + 1 ),
570 $self->get_byte( $self->{offset} + 2 ),
571 23 $self->get_byte( $self->{offset} + 3 ) ];
572 }
573  
574 ##------------------------------------------------------------------------
575 ## vframes()
576 ## this is just calculated given fps and duration. MPEG doesn't contain
577 ## this information in the file directly
578 ##------------------------------------------------------------------------
579 10 ▶sub vframes {
Subroutine vframes: called CC=2 SCAR=6.9
Pod documented
580 10 my $self = shift;
581 10 ▶ return int($self->duration * $self->fps) if $self->duration;
Branch: 1 branch
BranchTrueFalseTotal
if $self->duration 7 3 10
582 3 return 0;
583 }
584  
585 5 1;
586  
587 __END__
« Info/MPEG/System.pm ↑ Summary Info.pm »