Pilot/Video/FileDump.pm

filter: Statementstmt 78.0% 32 / 41 Branchbran 25.0% 3 / 12 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 85.7% 6 / 7 Podpod 33.3% 1 / 3 totaltotal 65.1% 43 / 66 CC 8 SCAR 14.5
CC
8
Cov
65%
BUILDARGS
6.3
close
6.0
process_h264_frame
4.1
CRAP 4.3
« Pilot/NavCollector/AckEvents.pm ↑ Summary Pilot.pm »
1 # Copyright (c) 2014 Timm Murray
2 # All rights reserved.
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are met:
6 #
7 # * Redistributions of source code must retain the above copyright notice,
8 # this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above copyright
10 # notice, this list of conditions and the following disclaimer in the
11 # documentation and/or other materials provided with the distribution.
12 #
13 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
14 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
17 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
23 # POSSIBILITY OF SUCH DAMAGE.
24 package UAV::Pilot::Video::FileDump;
25 1 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 1 with 'UAV::Pilot::Video::H264Handler';
30  
31 1 has 'file' => (
32 is => 'ro',
33 isa => 'Str',
34 );
35 1 has 'single_frame' => (
36 is => 'ro',
37 isa => 'Bool',
38 default => 0,
39 );
40 1 has '_frame_count' => (
41 is => 'rw',
42 isa => 'Int',
43 default => 0,
44 );
45 1 has '_fh' => (
46 is => 'ro',
47 isa => 'Item',
48 );
49  
50  
51 sub BUILDARGS
52 {
53 1 ▶ my ($class, $args) = @_;
Subroutine BUILDARGS: called CC=5 SCAR=18.4
Pod documented
54  
55 1 ▶ if(! $args->{single_frame} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args->{"single_frame"}) 1 0 1
56 1 my $fh;
57 1 ▶ if( defined $args->{file}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args->{'file'}) { } 0 1 1
58 open( my $fh, '>', $args->{file} )
59 0 ▶ or die "Can't open $$args{file}: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $args->{"file"} or die qq[Can't open $args->{"file"}: $!\n] 0 0 0
60 }
61 else {
62 1 ▶ $fh = $args->{fh} // \*STDOUT;
Condition50%1/2
$args->{"fh"} // \*STDOUT
l!l
10
MC/DC0%0/1
$args->{"fh"} // \*STDOUT
$args->{"fh"}
Truth table50%1/2
A
A= $args->{"fh"}
Aresult
11
00
63 }
64  
65 1 $args->{'_fh'} = $fh;
66 }
67  
68 1 return $args;
69 }
70  
71 sub process_h264_frame
72 {
73 1 ▶ my ($self, $packet) = @_;
Subroutine process_h264_frame: called CC=3 SCAR=14.2
Pod undocumented
74  
75 1 my $data = pack( 'C*', @$packet );
76 1 ▶ if( $self->single_frame) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->single_frame) { } 0 1 1
77 0 my $base_file = $self->file;
78 0 my $full_file = sprintf(
79 $base_file . '.%05i',
80 $self->_frame_count
81 );
82  
83 0 ▶ open( my $fh, '>', $full_file )
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $full_file or die "Can't open ${full_file}: $!\n" 0 0 0
84 or die "Can't open $full_file: $!\n";
85 0 print $fh $data;
86 0 close $fh;
87 }
88 else {
89 1 my $fh = $self->_fh;
90 1 print $fh $data;
91  
92 }
93  
94 1 $self->_frame_count( $self->_frame_count + 1 );
95 1 return 1;
96 }
97  
98 sub close
99 {
100 0 ▶ my ($self) = @_;
Subroutine close: not called CC=2 SCAR=17.9
Pod undocumented
101 0 ▶ $self->_fh->close if defined $self->_fh;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->_fh 0 0 0
102 0 return 1;
103 }
104  
105  
106 1 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
107 1 __PACKAGE__->meta->make_immutable;
108 1 1;
109 __END__
110  
111  
112 =head1 NAME
113  
114 UAV::Pilot::Video::FileDump
115  
116 =head1 SYNOPSIS
117  
118 open( my $vid_out, '>', 'video.h264' ) or die $!;
119 my $file_dump = UAV::Pilot::Video::FileDump->new({
120 fh => $vid_out,
121 });
122 my $video = UAV::Pilot::Driver::ARDrone::Video->new({
123 handler => $file_dump,
124 ...
125 });
126  
127 =head1 DESCRIPTION
128  
129 Writes the h264 video frames to a file. Afterwords, you should be able to play this file
130 with mplayer or other video players that support h264 without being inside a container
131 format.
132  
133 =cut
« Pilot/NavCollector/AckEvents.pm ↑ Summary Pilot.pm »