| 1 | package Video::PlaybackMachine::Config; | ||||||||||
| 2 | |||||||||||
| 3 | 3 | our $VERSION = '0.09'; # VERSION | |||||||||
| 4 | |||||||||||
| 5 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 3 | ▶ | use AppConfig qw(:expand :argcount); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 3 | our @ISA = qw(AppConfig); | |||||||||
| 10 | |||||||||||
| 11 | 3 | ▶ | use FindBin '$Bin'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 3 | ▶ | use Log::Log4perl; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | 3 | our @Config_Files = ( | |||||||||
| 16 | "$Bin/../conf/playback_machine.conf", | ||||||||||
| 17 | "$Bin/../Video-PlaybackMachine/conf/playback_machine.conf", | ||||||||||
| 18 | "$Bin/../../Video-PlaybackMachine/conf/playback_machine.conf", | ||||||||||
| 19 | "/etc/playback_machine/playback_machine.conf" | ||||||||||
| 20 | ); | ||||||||||
| 21 | |||||||||||
| 22 | 3 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 23 | |||||||||||
| 24 | 3 | my $config; | |||||||||
| 25 | |||||||||||
| 26 | 3 | ▶ | sub config { | ||||||||
|
Subroutine
config: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||
| 27 | 3 | my $type = shift; | |||||||||
| 28 | 3 | ▶ | defined $config and return $config; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | |||||||||||
| 30 | 3 | $config = $type->new( | |||||||||
| 31 | { | ||||||||||
| 32 | CREATE => 1, | ||||||||||
| 33 | GLOBAL => { EXPAND => EXPAND_ALL } | ||||||||||
| 34 | } | ||||||||||
| 35 | ); | ||||||||||
| 36 | |||||||||||
| 37 | 3 | $config->define( | |||||||||
| 38 | 'database', | ||||||||||
| 39 | { | ||||||||||
| 40 | DEFAULT => 'playback_machine', | ||||||||||
| 41 | ARGS => '=s' | ||||||||||
| 42 | } | ||||||||||
| 43 | ); | ||||||||||
| 44 | |||||||||||
| 45 | 3 | $config->define( 'schedule', { ARGS => '=s' } ); | |||||||||
| 46 | |||||||||||
| 47 | 3 | $config->define( 'stills', { ARGS => '=s' } ); | |||||||||
| 48 | |||||||||||
| 49 | 3 | $config->define( 'music', { ARGS => '=s' } ); | |||||||||
| 50 | |||||||||||
| 51 | 3 | $config->define( 'movies', { ARGS => '=s' } ); | |||||||||
| 52 | |||||||||||
| 53 | 3 | $config->define( 'font_dir', { ARGS => '=s' } ); | |||||||||
| 54 | |||||||||||
| 55 | 3 | $config->define( 'fill', { ARGS => '=s@' } ); | |||||||||
| 56 | |||||||||||
| 57 | 3 | $config->define( 'restart_interval', | |||||||||
| 58 | { ARGS => '=i', DEFAULT => 3 * 60 * 60 } ); | ||||||||||
| 59 | |||||||||||
| 60 | 3 | $config->define('logo=s'); | |||||||||
| 61 | |||||||||||
| 62 | 3 | $config->define( 'disclaimer', { ARGS => '=s' } ); | |||||||||
| 63 | |||||||||||
| 64 | 3 | $config->define('start=s'); | |||||||||
| 65 | |||||||||||
| 66 | 3 | $config->define( | |||||||||
| 67 | 'offset', | ||||||||||
| 68 | { | ||||||||||
| 69 | ARGS => '=i', | ||||||||||
| 70 | DEFAULT => 0 | ||||||||||
| 71 | } | ||||||||||
| 72 | ); | ||||||||||
| 73 | |||||||||||
| 74 | 3 | $config->define( | |||||||||
| 75 | 'skip_tolerance', | ||||||||||
| 76 | { | ||||||||||
| 77 | ARGS => '=i', | ||||||||||
| 78 | DEFAULT => 15 | ||||||||||
| 79 | } | ||||||||||
| 80 | ); | ||||||||||
| 81 | |||||||||||
| 82 | 3 | $config->define( 'max_slides=i', { DEFAULT => 5 } ); | |||||||||
| 83 | |||||||||||
| 84 | 3 | $config->define( 'player_verbose=i', { DEFAULT => 0 } ); | |||||||||
| 85 | |||||||||||
| 86 | 3 | $config->define('stderr_log=s'); | |||||||||
| 87 | |||||||||||
| 88 | 3 | $config->define('log_config=s'); | |||||||||
| 89 | |||||||||||
| 90 | 3 | foreach my $config_file (@Config_Files) { | |||||||||
| 91 | 12 | ▶ | -e $config_file or next; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 92 | 3 | ▶ | $config->file($config_file) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 93 | or die "Couldn't load config file '$config_file': $!; stopped"; | ||||||||||
| 94 | } | ||||||||||
| 95 | |||||||||||
| 96 | 3 | $config->define( 'x_display=s', { DEFAULT => ':0.0' } ); | |||||||||
| 97 | |||||||||||
| 98 | 3 | $config->define( 'time_tick=i', { DEFAULT => 5 } ); | |||||||||
| 99 | |||||||||||
| 100 | 3 | $config->define( 'daemonize!', { DEFAULT => 0 } ); | |||||||||
| 101 | |||||||||||
| 102 | 3 | $config->define( 'time_zone', { DEFAULT => 'America/Los_Angeles' } ); | |||||||||
| 103 | |||||||||||
| 104 | 3 | $config->getopt(); | |||||||||
| 105 | |||||||||||
| 106 | 3 | return $config; | |||||||||
| 107 | } | ||||||||||
| 108 | |||||||||||
| 109 | } | ||||||||||
| 110 | |||||||||||
| 111 | 0 | ▶ | sub init_logging { | ||||||||
|
Subroutine
init_logging: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 112 | 0 | my $type = shift; | |||||||||
| 113 | |||||||||||
| 114 | 0 | my $config = $type->config(); | |||||||||
| 115 | |||||||||||
| 116 | 0 | Log::Log4perl::init_once( \( $config->log_config() ) ); | |||||||||
| 117 | |||||||||||
| 118 | } | ||||||||||
| 119 | |||||||||||
| 120 | 0 | ▶ | sub _producer_table { | ||||||||
|
Subroutine
_producer_table: not called CC=2 SCAR=17.9
| |||||||||||
| 121 | 0 | my $self = shift; | |||||||||
| 122 | 0 | my ($table) = @_; | |||||||||
| 123 | |||||||||||
| 124 | 0 | my $prod_table = { | |||||||||
| 125 | station_id => Video::PlaybackMachine::FillProducer::StillFrame->new( | ||||||||||
| 126 | image => $self->logo(), | ||||||||||
| 127 | time => 6 | ||||||||||
| 128 | ), | ||||||||||
| 129 | |||||||||||
| 130 | slideshow => Video::PlaybackMachine::FillProducer::SlideShow->new( | ||||||||||
| 131 | directory => $self->get('stills'), | ||||||||||
| 132 | music_directory => $self->get('music'), | ||||||||||
| 133 | time => 10, | ||||||||||
| 134 | ), | ||||||||||
| 135 | |||||||||||
| 136 | up_next => Video::PlaybackMachine::FillProducer::UpNext->new( | ||||||||||
| 137 | time => 6, | ||||||||||
| 138 | font_path => [ $self->get('font_dir') ], | ||||||||||
| 139 | ), | ||||||||||
| 140 | |||||||||||
| 141 | # Next 5 programs | ||||||||||
| 142 | next_sched => Video::PlaybackMachine::FillProducer::NextSchedule->new( | ||||||||||
| 143 | time => 8, | ||||||||||
| 144 | font_size => 30, | ||||||||||
| 145 | font_path => [ $self->get('font_dir') ], | ||||||||||
| 146 | ), | ||||||||||
| 147 | |||||||||||
| 148 | |||||||||||
| 149 | }; | ||||||||||
| 150 | |||||||||||
| 151 | 0 | ▶ | if ( $self->get('disclaimer') ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 152 | 0 | $prod_table->{'disclaimer'} = | |||||||||
| 153 | Video::PlaybackMachine::FillProducer::StillFrame->new( | ||||||||||
| 154 | image => $self->get('disclaimer'), | ||||||||||
| 155 | time => 6 | ||||||||||
| 156 | ); | ||||||||||
| 157 | } | ||||||||||
| 158 | |||||||||||
| 159 | 0 | return $prod_table; | |||||||||
| 160 | } | ||||||||||
| 161 | |||||||||||
| 162 | 0 | ▶ | sub get_fill { | ||||||||
|
Subroutine
get_fill: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 163 | 0 | my $self = shift; | |||||||||
| 164 | 0 | my ($table) = @_; | |||||||||
| 165 | |||||||||||
| 166 | 0 | my $pt = $self->_producer_table($table); | |||||||||
| 167 | |||||||||||
| 168 | 0 | my @fill_segs = (); | |||||||||
| 169 | 0 | my $order_idx = 1; | |||||||||
| 170 | 0 | foreach ( @{ $self->fill() } ) { | |||||||||
| 171 | 0 | my ( $name, $priority ) = split( /\t+/, $_, 2 ); | |||||||||
| 172 | 0 | my $producer = $pt->{$name}; | |||||||||
| 173 | 0 | ▶ | unless ( defined $producer ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 174 | 0 | my $logger = | |||||||||
| 175 | Log::Log4perl->get_logger('Video.PlaybackMachine.Config'); | ||||||||||
| 176 | 0 | $logger->warn("No fill producer found named '$name'"); | |||||||||
| 177 | 0 | next; | |||||||||
| 178 | } | ||||||||||
| 179 | 0 | my $segment = Video::PlaybackMachine::FillSegment->new( | |||||||||
| 180 | name => $name, | ||||||||||
| 181 | sequence_order => $order_idx++, | ||||||||||
| 182 | priority_order => $priority, | ||||||||||
| 183 | producer => $producer | ||||||||||
| 184 | ); | ||||||||||
| 185 | 0 | push( @fill_segs, $segment ); | |||||||||
| 186 | |||||||||||
| 187 | } | ||||||||||
| 188 | |||||||||||
| 189 | 0 | my $filler = Video::PlaybackMachine::Filler->new( segments => \@fill_segs ); | |||||||||
| 190 | |||||||||||
| 191 | 0 | return $filler; | |||||||||
| 192 | } | ||||||||||
| 193 | |||||||||||
| 194 | 3 | 1; | |||||||||
| 195 | |||||||||||
| 196 | __END__ | ||||||||||
| 197 | |||||||||||
| 198 | =head1 NAME | ||||||||||
| 199 | |||||||||||
| 200 | Video::PlaybackMachine::Config -- Configuration for Video::PlaybackMachine | ||||||||||
| 201 | |||||||||||
| 202 | =head1 DESCRIPTION | ||||||||||
| 203 | |||||||||||
| 204 | Provides configuration values for Video::PlaybackMachine. Inherits | ||||||||||
| 205 | from AppConfig. | ||||||||||
| 206 | |||||||||||
| 207 | =head1 METHODS | ||||||||||
| 208 | |||||||||||
| 209 | =head2 CLASS METHODS | ||||||||||
| 210 | |||||||||||
| 211 | =head3 config() | ||||||||||
| 212 | |||||||||||
| 213 | Puts together a config object from the configuration file and | ||||||||||
| 214 | command-line parameters and returns it. | ||||||||||
| 215 | |||||||||||
| 216 | =head2 OBJECT METHODS | ||||||||||
| 217 | |||||||||||
| 218 | =head3 init_logging() | ||||||||||
| 219 | |||||||||||
| 220 | Initializes Log::Log4perl based on the 'log_config' parameter. | ||||||||||
| 221 | |||||||||||
| 222 | =head3 get_fill() | ||||||||||
| 223 | |||||||||||
| 224 | Creates the Video::PlaybackMachine::Filler object based on the | ||||||||||
| 225 | configuration and returns it. | ||||||||||
| 226 | |||||||||||
| 227 | |||||||||||
| 228 | =head1 CONFIGURATION PARAMETERS | ||||||||||
| 229 | |||||||||||
| 230 | =head3 database | ||||||||||
| 231 | |||||||||||
| 232 | Name of the database. Defaults to 'playback_machine' | ||||||||||
| 233 | |||||||||||
| 234 | =head3 schedule | ||||||||||
| 235 | |||||||||||
| 236 | String. | ||||||||||
| 237 | |||||||||||
| 238 | Name of the schedule this instance is running. | ||||||||||
| 239 | |||||||||||
| 240 | =head3 stills | ||||||||||
| 241 | |||||||||||
| 242 | String. | ||||||||||
| 243 | |||||||||||
| 244 | =head3 music | ||||||||||
| 245 | |||||||||||
| 246 | String. | ||||||||||
| 247 | |||||||||||
| 248 | =head3 fill | ||||||||||
| 249 | |||||||||||
| 250 | List of strings. | ||||||||||
| 251 | |||||||||||
| 252 | =head3 restart_interval | ||||||||||
| 253 | |||||||||||
| 254 | Integer. | ||||||||||
| 255 | |||||||||||
| 256 | Number of seconds between automated restarts. | ||||||||||
| 257 | |||||||||||
| 258 | =head3 logo | ||||||||||
| 259 | |||||||||||
| 260 | String. | ||||||||||
| 261 | |||||||||||
| 262 | Filename of logo. | ||||||||||
| 263 | |||||||||||
| 264 | =head3 start | ||||||||||
| 265 | |||||||||||
| 266 | String. | ||||||||||
| 267 | |||||||||||
| 268 | =head3 offset | ||||||||||
| 269 | |||||||||||
| 270 | Integer. | ||||||||||
| 271 | |||||||||||
| 272 | Number of seconds to offset from current time. | ||||||||||
| 273 | |||||||||||
| 274 | Default: 0 | ||||||||||
| 275 | |||||||||||
| 276 | =head3 skip_tolerance | ||||||||||
| 277 | |||||||||||
| 278 | Maximum number of seconds to allow skipping of a movie without | ||||||||||
| 279 | considering it unplayable and going to idle. | ||||||||||
| 280 | |||||||||||
| 281 | Default: 15 | ||||||||||
| 282 | |||||||||||
| 283 | =head3 max_slides | ||||||||||
| 284 | |||||||||||
| 285 | Integer. | ||||||||||
| 286 | |||||||||||
| 287 | Maximum number of slides to play in a row. | ||||||||||
| 288 | |||||||||||
| 289 | Default: 5 | ||||||||||
| 290 | |||||||||||
| 291 | =head3 player_verbose | ||||||||||
| 292 | |||||||||||
| 293 | Integer. | ||||||||||
| 294 | |||||||||||
| 295 | Default: 0 | ||||||||||
| 296 | |||||||||||
| 297 | =head3 stderr_log | ||||||||||
| 298 | |||||||||||
| 299 | String. | ||||||||||
| 300 | |||||||||||
| 301 | Filename to which we'll redirect stderr in daemon mode. | ||||||||||
| 302 | |||||||||||
| 303 | =head3 log_config | ||||||||||
| 304 | |||||||||||
| 305 | String. | ||||||||||
| 306 | |||||||||||
| 307 | Configuration text block for Log::Log4perl. | ||||||||||
| 308 | |||||||||||
| 309 | =head3 x_display | ||||||||||
| 310 | |||||||||||
| 311 | String. | ||||||||||
| 312 | |||||||||||
| 313 | The value of the X display to be used by X11::FullScreen. | ||||||||||
| 314 | |||||||||||
| 315 | Default: :0.0 | ||||||||||
| 316 | |||||||||||
| 317 | =head3 time_tick | ||||||||||
| 318 | |||||||||||
| 319 | Integer. | ||||||||||
| 320 | |||||||||||
| 321 | The scheduler will update the 'clock' in the process name (visible in | ||||||||||
| 322 | ps display) every C<time_tick> seconds. | ||||||||||
| 323 | |||||||||||
| 324 | Default: 5 | ||||||||||
| 325 | |||||||||||
| 326 | =cut | ||||||||||
| 327 | |||||||||||