Module: FLV::Edit::Processor::Dispatcher
- Included in:
- Add, CommandLine, Join, MetaDataMaker, Update
- Defined in:
- lib/flvedit/processor/dispatcher.rb
Overview
Dispatcher can be included in a processor and will makeit easy to process the chunks according to their type.
Chunks can be Header or Tags. The latter have different types of bodies: Audio, Video or Event. Events store all meta data related information: onMetaData, onCuePoint, …
To tap into the flow of chunks, a processor can define any of the following methods:
on_chunk
on_header
on_tag
on_audio
on_video
on_keyframe
on_interframe
on_disposable_interframe
on_event
on_cue_point
on_other_event
All of these methods will have one argument: the current chunk being processed. For example, if the current chunk is an ‘onMetaData’ event, then the following will be called (from the most specialized to the least).
(chunk)
on_event(chunk)
on_chunk(chunk)
The methods need not return anything. It is assumed that the chunk should be output. If that’s not the case, call #absorb
. To output other tags instead, call #dispatch_instead
.
Note that both #absorb and #dispatch_instead stop the processing for the current chunk, so if #on_video calls #absorb, for example, then there won’t be a call to #on_tag or #on_chunk.
Finally, it’s possible to #stop
the processing of the current source completely.
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- EVENT_TRIGGER =
{ :on_header => :on_chunk, :on_tag => :on_chunk, :on_audio => :on_tag, :on_video => :on_tag, :on_event => :on_tag, :on_meta_data => :on_event, :on_cue_point => :on_event, :on_last_second => :on_event, :on_other_event => :on_event, :on_keyframe => :on_video, :on_interframe => :on_video, :on_disposable_interframe => :on_video }.freeze
- ALL_EVENTS =
(EVENT_TRIGGER.keys | EVENT_TRIGGER.values).freeze
- MAIN_EVENTS =
ALL_EVENTS.reject{ |k| EVENT_TRIGGER.has_value?(k)}.freeze
- EVENT_TRIGGER_LIST =
Hash.new{|h, k| h[k] = [k] + h[EVENT_TRIGGER[k]]}.tap{|h| h[nil] = []; h.values_at(*MAIN_EVENTS)}.freeze
Class Method Summary collapse
-
.included(base) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#absorb ⇒ Object
Stops the processing for the current chunk.
-
#dispatch_instead(*chunks) ⇒ Object
Call #dispatch_instead with a list of chunks.
- #each(&block) ⇒ Object
- #initialize ⇒ Object
-
#stop ⇒ Object
Stops the processing of the current source completely.
Class Method Details
.included(base) ⇒ Object
:nodoc:
108 109 110 |
# File 'lib/flvedit/processor/dispatcher.rb', line 108 def self.included(base) # :nodoc: base.extend ClassMethods end |
Instance Method Details
#absorb ⇒ Object
Stops the processing for the current chunk
52 53 54 |
# File 'lib/flvedit/processor/dispatcher.rb', line 52 def absorb(*) # Note: the (*) is so that we can alias events like on_meta_data throw :absorb end |
#dispatch_instead(*chunks) ⇒ Object
Call #dispatch_instead with a list of chunks. These chunks will not be processed by the current processor but will be output directly. This stops the processing for the current chunk.
73 74 75 76 77 78 |
# File 'lib/flvedit/processor/dispatcher.rb', line 73 def dispatch_instead(*chunks) chunks.each do |chunk| @block.call chunk end absorb end |
#each(&block) ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/flvedit/processor/dispatcher.rb', line 61 def each(&block) return to_enum unless block_given? @block = block catch :stop do super{|chunk| dispatch_chunk(chunk)} end end |
#initialize ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/flvedit/processor/dispatcher.rb', line 43 def initialize(*) super on_calls = self.class.instance_methods(false).select{|m| m.to_s.start_with?("on_")}.map(&:to_sym) #Note: to_s needed for ruby 1.9, to_sym for ruby 1.8 unless (potential_errors = on_calls - ALL_EVENTS).empty? warn "The following are not events: #{potential_errors.join(',')} (class #{self.class})" end end |
#stop ⇒ Object
Stops the processing of the current source completely.
57 58 59 |
# File 'lib/flvedit/processor/dispatcher.rb', line 57 def stop throw :stop end |