Pilot/Video/FileDump.pm

filter: Statementstmt 78.5% 33 / 42 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.6% 44 / 67 CC 8 SCAR 14.5
CC
8
Cov
66%
BUILDARGS
6.3
close
6.0
process_h264_frame
4.1
CRAP 4.3
« Pilot/NavCollector/AckEvents.pm ↑ Summary Pilot.pm »
1 # Copyright (c) 2015 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 $UAV::Pilot::Video::FileDump::VERSION = '1.1';
26 1 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 1 with 'UAV::Pilot::Video::H264Handler';
31  
32 1 has 'file' => (
33 is => 'ro',
34 isa => 'Str',
35 );
36 1 has 'single_frame' => (
37 is => 'ro',
38 isa => 'Bool',
39 default => 0,
40 );
41 1 has '_frame_count' => (
42 is => 'rw',
43 isa => 'Int',
44 default => 0,
45 );
46 1 has '_fh' => (
47 is => 'ro',
48 isa => 'Item',
49 );
50  
51  
52 sub BUILDARGS
53 {
54 1 ▶ my ($class, $args) = @_;
Subroutine BUILDARGS: called CC=5 SCAR=18.4
Pod documented
55  
56 1 ▶ if(! $args->{single_frame} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args->{"single_frame"}) 1 0 1
57 1 my $fh;
58 1 ▶ if( defined $args->{file}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args->{'file'}) { } 0 1 1
59 open( my $fh, '>', $args->{file} )
60 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
61 }
62 else {
63 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
64 }
65  
66 1 $args->{'_fh'} = $fh;
67 }
68  
69 1 return $args;
70 }
71  
72 sub process_h264_frame
73 {
74 1 ▶ my ($self, $packet) = @_;
Subroutine process_h264_frame: called CC=3 SCAR=14.2
Pod undocumented
75  
76 1 my $data = pack( 'C*', @$packet );
77 1 ▶ if( $self->single_frame) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->single_frame) { } 0 1 1
78 0 my $base_file = $self->file;
79 0 my $full_file = sprintf(
80 $base_file . '.%05i',
81 $self->_frame_count
82 );
83  
84 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
85 or die "Can't open $full_file: $!\n";
86 0 print $fh $data;
87 0 close $fh;
88 }
89 else {
90 1 my $fh = $self->_fh;
91 1 print $fh $data;
92  
93 }
94  
95 1 $self->_frame_count( $self->_frame_count + 1 );
96 1 return 1;
97 }
98  
99 sub close
100 {
101 0 ▶ my ($self) = @_;
Subroutine close: not called CC=2 SCAR=17.9
Pod undocumented
102 0 ▶ $self->_fh->close if defined $self->_fh;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->_fh 0 0 0
103 0 return 1;
104 }
105  
106  
107 1 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
108 1 __PACKAGE__->meta->make_immutable;
109 1 1;
110 __END__
111  
112  
113 =head1 NAME
114  
115 UAV::Pilot::Video::FileDump
116  
117 =head1 SYNOPSIS
118  
119 open( my $vid_out, '>', 'video.h264' ) or die $!;
120 my $file_dump = UAV::Pilot::Video::FileDump->new({
121 fh => $vid_out,
122 });
123 my $video = UAV::Pilot::Driver::ARDrone::Video->new({
124 handler => $file_dump,
125 ...
126 });
127  
128 =head1 DESCRIPTION
129  
130 Writes the h264 video frames to a file. Afterwords, you should be able to play this file
131 with mplayer or other video players that support h264 without being inside a container
132 format.
133  
134 =cut
« Pilot/NavCollector/AckEvents.pm ↑ Summary Pilot.pm »