blib/lib/Video/DVDRip/Audio.pm untested

filter: Statementstmt 0.0% 0 / 143 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 21 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 0.0% 0 / 62 Podpod 0.0% 0 / 58 totaltotal 0.0% 0 / 310 CC 8 SCAR 15.2
CC
8
Cov
0%
info
30.0
new
12.0
set_tc_audio_filter
6.0
CRAP 4.6
1 # $Id: Audio.pm 2187 2006-08-16 19:34:38Z joern $
2  
3 #-----------------------------------------------------------------------
4 # Copyright (C) 2001-2006 Jörn Reder <joern AT zyn.de>.
5 # All Rights Reserved. See file COPYRIGHT for details.
6 #
7 # This module is part of Video::DVDRip, which is free software; you can
8 # redistribute it and/or modify it under the same terms as Perl itself.
9 #-----------------------------------------------------------------------
10  
11 package Video::DVDRip::Audio;
12 use Locale::TextDomain qw (video.dvdrip);
13  
14 use base Video::DVDRip::Base;
15  
16 use Carp;
17 use strict;
18  
19 # Title this track belongs to
20 sub title { shift->{title} }
21 sub set_title { shift->{title} = $_[1] }
22  
23 # Attributes of the audio channel on DVD
24  
25 sub type { shift->{type} }
26 sub lang { shift->{lang} }
27 sub channels { shift->{channels} }
28 sub bitrate { shift->{bitrate} }
29 sub sample_rate { shift->{sample_rate} }
30 sub volume_rescale { shift->{volume_rescale} }
31 sub scan_output { shift->{scan_output} }
32  
33 sub set_type { shift->{type} = $_[1] }
34 sub set_lang { shift->{lang} = $_[1] }
35 sub set_channels { shift->{channels} = $_[1] }
36 sub set_bitrate { shift->{bitrate} = $_[1] }
37 sub set_sample_rate { shift->{sample_rate} = $_[1] }
38 sub set_volume_rescale { shift->{volume_rescale} = $_[1] }
39 sub set_scan_output { shift->{scan_output} = $_[1] }
40  
41 # Options for transcoding the audio channel
42  
43 sub tc_nr { shift->{tc_nr} }
44 sub tc_target_track { shift->{tc_target_track} }
45 sub tc_audio_filter { shift->{tc_audio_filter} }
46 sub tc_option_n { shift->{tc_option_n} }
47 sub tc_volume_rescale { shift->{tc_volume_rescale} }
48  
49 sub set_tc_nr { shift->{tc_nr} = $_[1] }
50 sub set_tc_target_track { shift->{tc_target_track} = $_[1] }
51 #sub set_tc_audio_filter { shift->{tc_audio_filter} = $_[1] }
52 sub set_tc_option_n { shift->{tc_option_n} = $_[1] }
53 sub set_tc_volume_rescale { shift->{tc_volume_rescale} = $_[1] }
54  
55 sub tc_audio_codec { shift->{tc_audio_codec} }
56 sub tc_mp3_bitrate { shift->{tc_mp3_bitrate} }
57 sub tc_mp3_samplerate { shift->{tc_mp3_samplerate} }
58 sub tc_mp3_quality { shift->{tc_mp3_quality} }
59 sub tc_ac3_bitrate { shift->{tc_ac3_bitrate} }
60 sub tc_vorbis_bitrate { shift->{tc_vorbis_bitrate} }
61 sub tc_vorbis_samplerate { shift->{tc_vorbis_samplerate} }
62 sub tc_vorbis_quality { shift->{tc_vorbis_quality} }
63 sub tc_vorbis_quality_enable { shift->{tc_vorbis_quality_enable} }
64 sub tc_mp2_bitrate { shift->{tc_mp2_bitrate} }
65 sub tc_mp2_samplerate { shift->{tc_mp2_samplerate} }
66 sub tc_pcm_bitrate { shift->{tc_pcm_bitrate} }
67  
68 #sub set_tc_audio_codec { shift->{tc_audio_codec} = $_[1] }
69 #sub set_tc_mp3_bitrate { shift->{tc_mp3_bitrate} = $_[1] }
70 sub set_tc_mp3_samplerate { shift->{tc_mp3_samplerate} = $_[1] }
71 sub set_tc_mp3_quality { shift->{tc_mp3_quality} = $_[1] }
72 sub set_tc_ac3_bitrate { shift->{tc_ac3_bitrate} = $_[1] }
73 #sub set_tc_vorbis_bitrate { shift->{tc_vorbis_bitrate} = $_[1] }
74 sub set_tc_vorbis_samplerate { shift->{tc_vorbis_samplerate} = $_[1] }
75 #sub set_tc_vorbis_quality { shift->{tc_vorbis_quality} = $_[1] }
76 #sub set_tc_vorbis_quality_enable{ shift->{tc_vorbis_quality_enable}=$_[1]}
77 #sub set_tc_mp2_bitrate { shift->{tc_mp2_bitrate} = $_[1] }
78 sub set_tc_mp2_samplerate { shift->{tc_mp2_samplerate} = $_[1] }
79 sub set_tc_pcm_bitrate { shift->{tc_pcm_bitrate} = $_[1] }
80  
81 sub set_tc_audio_filter {
82 my $self = shift;
83 my ($value) = @_;
84 $self->{tc_audio_filter} = $value;
85 if ( $value eq 'rescale' ) {
86 $self->set_tc_volume_rescale( $self->volume_rescale );
87 }
88 else {
89 $self->set_tc_volume_rescale("");
90 }
91 return $value;
92 }
93  
94 sub set_tc_audio_codec {
95 my $self = shift;
96 my ($value) = @_;
97 $self->{tc_audio_codec} = $value;
98 $self->title->calc_video_bitrate;
99 return $value;
100 }
101  
102 sub set_tc_mp3_bitrate {
103 my $self = shift;
104 my ($value) = @_;
105 $self->{tc_mp3_bitrate} = $value;
106 $self->title->calc_video_bitrate;
107 return $value;
108 }
109  
110 sub set_tc_mp2_bitrate {
111 my $self = shift;
112 my ($value) = @_;
113 $self->{tc_mp2_bitrate} = $value;
114 $self->title->calc_video_bitrate;
115 return $value;
116 }
117  
118 sub set_tc_vorbis_bitrate {
119 my $self = shift;
120 my ($value) = @_;
121 $self->{tc_vorbis_bitrate} = $value;
122 $self->title->calc_video_bitrate;
123 return $value;
124 }
125  
126 sub set_tc_vorbis_quality {
127 my $self = shift;
128 my ($value) = @_;
129 $self->{tc_vorbis_quality} = $value;
130 $self->title->calc_video_bitrate;
131 return $value;
132 }
133  
134 sub set_tc_vorbis_quality_enable {
135 my $self = shift;
136 my ($value) = @_;
137 $self->{tc_vorbis_quality_enable} = $value;
138 $self->title->calc_video_bitrate;
139 return $value;
140 }
141  
142 sub new {
143 my $class = shift;
144 my %par = @_;
145 my ( $type, $lang, $channels, $bitrate, $volume_rescale )
146 = @par{ 'type', 'lang', 'channels', 'bitrate', 'volume_rescale' };
147 my ( $title, $sample_rate, $scan_output )
148 = @par{ 'title', 'sample_rate', 'scan_output' };
149 my ( $tc_target_track, $tc_audio_codec, $tc_bitrate )
150 = @par{ 'tc_target_track', 'tc_audio_codec', 'tc_bitrate' };
151 my ( $tc_ac3_passthrough, $tc_mp3_quality, $tc_audio_filter )
152 = @par{ 'tc_ac3_passthrough', 'tc_mp3_quality', 'tc_audio_filter' };
153 my ( $tc_option_n, $tc_volume_rescale, $tc_nr )
154 = @par{ 'tc_option_n', 'tc_volume_rescale', 'tc_nr' };
155 my ( $tc_ac3_bitrate, $tc_samplerate )
156 = @par{ 'tc_ac3_bitrate', 'tc_samplerate' };
157  
158 $tc_target_track = -1 if not defined $tc_target_track;
159 $tc_audio_codec = "ac3" if $tc_ac3_passthrough;
160 $tc_audio_codec ||= "mp3";
161 $tc_bitrate ||= 128;
162 $tc_mp3_quality ||= 2;
163 $tc_audio_filter ||= 'rescale';
164 $tc_option_n ||= '';
165 $tc_volume_rescale ||= 0;
166  
167 my $self = {
168 title => $title,
169 type => $type,
170 lang => $lang,
171 channels => $channels,
172 bitrate => $bitrate,
173 sample_rate => $sample_rate,
174 volume_rescale => $volume_rescale,
175 scan_output => $scan_output,
176 tc_nr => $tc_nr,
177 tc_target_track => $tc_target_track,
178 tc_audio_codec => $tc_audio_codec,
179 tc_ac3_bitrate => $tc_ac3_bitrate,
180 tc_mp3_bitrate => $tc_bitrate,
181 tc_mp2_bitrate => $tc_bitrate,
182 tc_vorbis_bitrate => $tc_bitrate,
183 tc_mp3_samplerate => $tc_samplerate,
184 tc_vorbis_samplerate => $tc_samplerate,
185 tc_mp3_quality => $tc_mp3_quality,
186 tc_audio_filter => $tc_audio_filter,
187 tc_option_n => $tc_option_n,
188 tc_volume_rescale => $tc_volume_rescale,
189 tc_vorbis_quality => 3.00,
190 tc_vorbis_quality_enable => 0,
191 };
192  
193 return bless $self, $class;
194 }
195  
196 sub tc_bitrate {
197 my $self = shift;
198 my $audio_codec = $self->tc_audio_codec;
199 my $method = "tc_" . $audio_codec . "_bitrate";
200 return $self->$method();
201 }
202  
203 sub set_tc_bitrate {
204 my $self = shift;
205 my ($val) = @_;
206 my $audio_codec = $self->tc_audio_codec;
207 my $method = "set_tc_" . $audio_codec . "_bitrate";
208 return $self->$method($val);
209 }
210  
211 sub tc_samplerate {
212 my $self = shift;
213 my $audio_codec = $self->tc_audio_codec;
214 my $method = "tc_" . $audio_codec . "_samplerate";
215 return $self->$method();
216 }
217  
218 sub ac3_ok {
219 my $self = shift;
220  
221 my $ok = ( $self->type eq 'ac3' and $self->bitrate ne '' );
222  
223 return $ok;
224 }
225  
226 sub pcm_ok {
227 my $self = shift;
228  
229 my $ok = ( $self->type eq 'lpcm' and $self->bitrate ne '' );
230  
231 return $ok;
232 }
233  
234 sub is_passthrough {
235 my $self = shift;
236 return $self->tc_audio_codec eq 'ac3'
237 || $self->tc_audio_codec eq 'pcm';
238 }
239  
240 sub info {
241 my $self = shift;
242 my %par = @_;
243 my ($with_target) = @par{'with_target'};
244  
245 my $sample_rate = $self->sample_rate;
246 $sample_rate = "48kHz" if $sample_rate == 48000;
247 $sample_rate = "41.1kHz" if $sample_rate == 44100;
248  
249 my $target;
250 if ($with_target) {
251 if ( $self->tc_target_track < 0 ) {
252 $target = " => " . __ "Discard";
253 }
254 else {
255 $target = " => " . ( $self->tc_target_track + 1 );
256 }
257 }
258  
259 return $self->lang . " "
260 . $self->type . " "
261 . "$sample_rate "
262 . $self->channels
263 . "Ch$target";
264 }
265  
266 1;