« lib/Video/PlaybackMachine/Player/EventWheel.pm
↑ Summary
lib/Video/PlaybackMachine/ScheduleTable/DB.pm »
| 1 | package Video::PlaybackMachine::Filler; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | our $VERSION = '0.09'; # VERSION | |||||||||
| 4 | |||||||||||
| 5 | #### | ||||||||||
| 6 | #### Video::PlaybackMachine::Filler | ||||||||||
| 7 | #### | ||||||||||
| 8 | #### $Revision$ | ||||||||||
| 9 | #### | ||||||||||
| 10 | #### POE session for the Filler. | ||||||||||
| 11 | #### | ||||||||||
| 12 | |||||||||||
| 13 | 1 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | 1 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | |||||||||||
| 17 | 1 | ▶ | use POE; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | 1 | ▶ | use POE::Session; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | |||||||||||
| 20 | 1 | ▶ | use Time::Duration; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | |||||||||||
| 22 | 1 | ▶ | use Video::PlaybackMachine::TimeManager; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 23 | |||||||||||
| 24 | 1 | with 'Video::PlaybackMachine::Logger'; | |||||||||
| 25 | |||||||||||
| 26 | ############################# Parameters ############################# | ||||||||||
| 27 | |||||||||||
| 28 | 0 | ▶ | has 'segments' => ( is => 'ro', default => sub { [] } ); | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||
| 29 | |||||||||||
| 30 | 1 | has 'time_manager' => ( is => 'rw' ); | |||||||||
| 31 | |||||||||||
| 32 | 1 | has 'scheduler' => ( is => 'rw' ); | |||||||||
| 33 | |||||||||||
| 34 | ############################# Object Methods ############################## | ||||||||||
| 35 | |||||||||||
| 36 | 0 | ▶ | sub spawn { | ||||||||
|
Subroutine
spawn: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 37 | 0 | my $self = shift; | |||||||||
| 38 | |||||||||||
| 39 | POE::Session->create( | ||||||||||
| 40 | inline_states => { | ||||||||||
| 41 | 0 | ▶ | _start => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 42 | 0 | $_[KERNEL]->alias_set('Filler'); | |||||||||
| 43 | } | ||||||||||
| 44 | }, | ||||||||||
| 45 | 0 | object_states => [ $self => [ | |||||||||
| 46 | qw(start_fill fill_done next_fill short_ready stop) | ||||||||||
| 47 | ] ], | ||||||||||
| 48 | ); | ||||||||||
| 49 | |||||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | |||||||||||
| 53 | ############################# Session Methods ############################# | ||||||||||
| 54 | |||||||||||
| 55 | ## | ||||||||||
| 56 | ## start_fill() | ||||||||||
| 57 | ## | ||||||||||
| 58 | ## POE state. | ||||||||||
| 59 | ## | ||||||||||
| 60 | ## Called to start the Filler filling. | ||||||||||
| 61 | ## | ||||||||||
| 62 | 0 | ▶ | sub start_fill { | ||||||||
|
Subroutine
start_fill: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 63 | 0 | my ($self, $heap, $kernel, $scheduler) = @_[OBJECT, HEAP, KERNEL, ARG0]; | |||||||||
| 64 | |||||||||||
| 65 | |||||||||||
| 66 | # Initialize a TimeManager with our FillSegments | ||||||||||
| 67 | 0 | $self->reset_time_manager(); | |||||||||
| 68 | |||||||||||
| 69 | # Store the current schedule | ||||||||||
| 70 | 0 | $self->scheduler($scheduler); | |||||||||
| 71 | |||||||||||
| 72 | 0 | $self->debug("Filling, ttn=", duration($_[ARG0]->get_time_to_next()),"\n"); | |||||||||
| 73 | |||||||||||
| 74 | # View the first segment | ||||||||||
| 75 | 0 | $kernel->yield('next_fill'); | |||||||||
| 76 | |||||||||||
| 77 | } | ||||||||||
| 78 | |||||||||||
| 79 | 0 | ▶ | sub stop { | ||||||||
|
Subroutine
stop: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 80 | 0 | $_[KERNEL]->alarm_remove_all(); | |||||||||
| 81 | 0 | foreach (keys %{$_[HEAP]}) { | |||||||||
| 82 | 0 | delete $_[HEAP]->{$_}; | |||||||||
| 83 | } | ||||||||||
| 84 | } | ||||||||||
| 85 | |||||||||||
| 86 | 0 | ▶ | sub reset_time_manager { | ||||||||
|
Subroutine
reset_time_manager: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 87 | 0 | my ($self) = @_; | |||||||||
| 88 | |||||||||||
| 89 | $self->time_manager( | ||||||||||
| 90 | Video::PlaybackMachine::TimeManager | ||||||||||
| 91 | 0 | ->new( @{ $self->segments } ) | |||||||||
| 92 | ); | ||||||||||
| 93 | |||||||||||
| 94 | 0 | return; | |||||||||
| 95 | } | ||||||||||
| 96 | |||||||||||
| 97 | ## | ||||||||||
| 98 | ## fill_done() | ||||||||||
| 99 | ## | ||||||||||
| 100 | ## Called when the Filler has nothing else to play. | ||||||||||
| 101 | ## Posts a call over to the Scheduler telling it | ||||||||||
| 102 | ## that we're idle. | ||||||||||
| 103 | ## | ||||||||||
| 104 | 0 | ▶ | sub fill_done { | ||||||||
|
Subroutine
fill_done: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 105 | 0 | $_[KERNEL]->alarm('next_fill'); | |||||||||
| 106 | 0 | $_[KERNEL]->post('Scheduler', 'wait_for_scheduled'); | |||||||||
| 107 | } | ||||||||||
| 108 | |||||||||||
| 109 | ## | ||||||||||
| 110 | ## next_fill() | ||||||||||
| 111 | ## | ||||||||||
| 112 | ## Starts the next fill segment. If there are no more segments to be | ||||||||||
| 113 | ## played, we're done. | ||||||||||
| 114 | ## | ||||||||||
| 115 | 0 | ▶ | sub next_fill { | ||||||||
|
Subroutine
next_fill: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||
| 116 | 0 | my ($self, $heap, $kernel) = @_[OBJECT, HEAP, KERNEL]; | |||||||||
| 117 | |||||||||||
| 118 | 0 | ▶ | $self->scheduler() | ||||||||
|
Branch: 1 branch
| |||||||||||
| 119 | or $self->logconfess("Somehow called next_fill on us without calling start_fill"); | ||||||||||
| 120 | |||||||||||
| 121 | 0 | my $time_to_next = $self->scheduler()->get_time_to_next(); | |||||||||
| 122 | |||||||||||
| 123 | 0 | ▶ | if (! defined $time_to_next ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 124 | 0 | $kernel->yield('fill_done'); | |||||||||
| 125 | 0 | return; | |||||||||
| 126 | } | ||||||||||
| 127 | |||||||||||
| 128 | 0 | $self->debug("Time to next: $time_to_next"); | |||||||||
| 129 | |||||||||||
| 130 | my ($segment, $time) = $self->time_manager()->get_segment( $time_to_next ) | ||||||||||
| 131 | 0 | ▶ | or do { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 132 | 0 | $kernel->yield('fill_done'); | |||||||||
| 133 | 0 | return; | |||||||||
| 134 | }; | ||||||||||
| 135 | |||||||||||
| 136 | 0 | $self->debug("Starting fill segment name: ", $segment->name()); | |||||||||
| 137 | |||||||||||
| 138 | 0 | $segment->producer()->start($time); | |||||||||
| 139 | |||||||||||
| 140 | } | ||||||||||
| 141 | |||||||||||
| 142 | ## | ||||||||||
| 143 | ## short_ready() | ||||||||||
| 144 | ## | ||||||||||
| 145 | ## Is called when one of the producers wants the Filler to display | ||||||||||
| 146 | ## moving pictures. | ||||||||||
| 147 | ## | ||||||||||
| 148 | 0 | ▶ | sub short_ready { | ||||||||
|
Subroutine
short_ready: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 149 | 0 | $_[KERNEL]->post('Player', | |||||||||
| 150 | 'play', | ||||||||||
| 151 | $_[SESSION]->postback('next_fill'), | ||||||||||
| 152 | 0, | ||||||||||
| 153 | @_[ARG0 .. $#_]); | ||||||||||
| 154 | |||||||||||
| 155 | } | ||||||||||
| 156 | |||||||||||
| 157 | 1 | ▶ | no Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 158 | |||||||||||
| 159 | |||||||||||
| 160 | 1 | 1; | |||||||||