lib/Video/PlaybackMachine.pm

filter: Statementstmt 90.0% 18 / 20 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 92.5% 25 / 27 CC 1 SCAR 0.4
CC
1
Cov
90%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« lib/Video/PlaybackMachine/Player.pm ↑ Summary lib/Video/PlaybackMachine/TimeLayout/FixedTimeLayout.pm »
1 package Video::PlaybackMachine;
2  
3 1 ▶use 5.10.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 our $VERSION = '0.09'; # VERSION
8  
9 1 ▶use POE;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use POE::Kernel;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶use Video::PlaybackMachine::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Video::PlaybackMachine::ScheduleTable::DB;
Subroutine BEGIN: called CC=1 SCAR=2.6
14 use Video::PlaybackMachine::FillSegment;
15 use Video::PlaybackMachine::Filler;
16 use Video::PlaybackMachine::Scheduler;
17 use Video::PlaybackMachine::FillProducer::SlideShow;
18 use Video::PlaybackMachine::FillProducer::StillFrame;
19 use Video::PlaybackMachine::FillProducer::UpNext;
20 use Video::PlaybackMachine::FillProducer::NextSchedule;
21  
22 my $config = Video::PlaybackMachine::Config->config();
23  
24 Video::PlaybackMachine::Config->init_logging();
25  
26 sub run {
27 my $type = shift;
28 my ($start_time, $start_at_beginning) = @_;
29  
30 defined $start_time or $start_time = time();
31  
32 my $schedule_name = $config->schedule();
33  
34 my $table =
35 Video::PlaybackMachine::ScheduleTable::DB->new(
36 schedule_name => $schedule_name );
37  
38 my $offset;
39
40 if ($start_at_beginning) {
41 my $first = $table->get_first_entry();
42 $offset = $first->start_time() - ( time() + 10 );
43 }
44 else {
45 $offset = $type->get_offset($start_time, $table);
46 }
47  
48 my $scheduler = Video::PlaybackMachine::Scheduler->new(
49 skip_tolerance => $config->skip_tolerance(),
50 schedule_table => $table,
51 filler => $config->get_fill($table),
52 offset => $offset
53 );
54  
55 $scheduler->spawn();
56  
57 POE::Kernel->run();
58  
59 }
60  
61 sub get_offset {
62 my $type = shift;
63 my ($start_time, $table) = @_;
64  
65 my $offset = 0;
66 my $date = $config->start();
67  
68 if ( $config->offset() > 0 || defined($date) ) {
69 $offset = $config->offset() - ( time() - $start_time );
70  
71 if ( defined($date) ) {
72 if ( $date eq 'first' ) {
73 $offset += $table->get_offset_to_first() + 1;
74 }
75 else {
76 $offset += $table->get_offset($date);
77 }
78 }
79  
80 }
81  
82 return $offset;
83 }
84  
85 1;
86 __END__
87  
88 =head1 NAME
89  
90 Video::PlaybackMachine - Perl extension for creating a television station
91  
92 =head1 DESCRIPTION
93  
94 PlaybackMachine is a television broadcast system. You can tell it to
95 play AVI files at specific times, and it will do so. Whenever nothing
96 is scheduled to be playing, it will create filler from a variety of
97 sources.
98  
99 For example, let's say that I've scheduled "Plan Nine From Outer
100 Space" at 3:00 PM on Saturday, January 12th, 2008, and scheduled "The
101 X From Outer Space" at 5:00 PM on the same day. I start the Playback
102 Machine on Friday night. Until 3:00 on Saturday, it shows slides,
103 plays background music, tells the audience that "Plan Nine" is next,
104 and plays short films. On 3:00 it runs "Plan Nine". When Ed Wood's
105 masterpiece is finished, it fills time again until 5:00.
106  
107 Potential uses include:
108  
109 =over
110  
111 =item *
112  
113 Automating a television station
114  
115 =item *
116  
117 Running movies at a convention
118  
119 =item *
120  
121 Kiosks
122  
123 =back
124  
125 The Playback Machine uses L<Video::Xine> (and hence libxine) to play
126 movies and music. Any video format that Xine is comfortable with is
127 perfectly OK to Playback Machine.
128  
129 =head1 METHODS
130  
131 =head2 CLASS METHODS
132  
133 =head3 run()
134  
135 run( $start_time )
136  
137 Runs the Playback Machine according to the current
138 configuration. C<$start_time> should be the time when the Playback
139 Machine session started; it defaults to time().
140  
141 =head3 get_offset()
142  
143 get_offset( $start_time, $table )
144  
145 Calculates the schedule offset from the configuration. The C<$table>
146 parameter is a Video::PlaybackMachine::ScheduleTable::DB object, and
147 is used to calculate the start time when the 'start' config parameter
148 is set to 'first'.
149  
150 =head1 SEE ALSO
151  
152 playback_machine.pl(1)
153  
154 xine-lib, http://www.xinehq.de
155  
156 L<Video::Xine>
157  
158 "How Perl Saved BayCon TV", http://perlmonks.org/?node_id=601001
159  
160 =head1 AUTHOR
161  
162 Stephen Nelson, E<lt>stephen@cpan.org<gt>
163  
164 =head1 COPYRIGHT AND LICENSE
165  
166 Copyright 2003-2008 by Stephen Nelson
167  
168 This library is free software; you can redistribute it and/or modify
169 it under the same terms as Perl itself.
170  
171 =cut
« lib/Video/PlaybackMachine/Player.pm ↑ Summary lib/Video/PlaybackMachine/TimeLayout/FixedTimeLayout.pm »