Class: FLV::Tag

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/flvedit/flv/tag.rb

Overview

FLV files consists of a single header and a collection of Tags. Tags all have a timestamp and a body; this body can be Audio, Video, or Event.

Constant Summary collapse

CLASS_CODE =
{
  8 => Audio,
  9 => Video,
  18 => Event
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Base

#getters, included, #size, #to_hash

Constructor Details

#initialize(timestamp = 0, body = nil) ⇒ Tag

Returns a new instance of Tag.



12
13
14
15
# File 'lib/flvedit/flv/tag.rb', line 12

def initialize(timestamp = 0, body = nil)
  self.body = body.instance_of?(Hash) ? Event.new(:onMetaData, body) : body
  self.timestamp = timestamp
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*arg, &block) ⇒ Object



55
56
57
58
59
# File 'lib/flvedit/flv/tag.rb', line 55

def method_missing(*arg, &block)
  super
rescue NoMethodError
  body.send(*arg, &block)
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



6
7
8
# File 'lib/flvedit/flv/tag.rb', line 6

def body
  @body
end

#timestampObject

Returns the value of attribute timestamp.



6
7
8
# File 'lib/flvedit/flv/tag.rb', line 6

def timestamp
  @timestamp
end

Instance Method Details

#debug(format, compared_with = nil) ⇒ Object

:nodoc



46
47
48
49
# File 'lib/flvedit/flv/tag.rb', line 46

def debug(format, compared_with = nil) #:nodoc
  format.header("#{timestamp} ", @body.title)
  @body.debug(format) unless compared_with && @body.similar_to?(compared_with.body)
end

#is?(what) ⇒ Boolean

:nodoc

Returns:

  • (Boolean)


51
52
53
# File 'lib/flvedit/flv/tag.rb', line 51

def is?(what) #:nodoc
  super || body.is?(what)
end

#read_packed(io, options) ⇒ Object

:nodoc



36
37
38
39
40
41
42
43
44
# File 'lib/flvedit/flv/tag.rb', line 36

def read_packed(io, options) #:nodoc
  len = io.pos_change do 
       code,    body_len,           timestamp_in_ms,   timestamp_in_ms_ext,  streamid =
    io >>:char  >>:unsigned_24bits  >>:unsigned_24bits  >>:char               >>:unsigned_24bits
    @timestamp = Timestamp.in_milliseconds(timestamp_in_ms + (timestamp_in_ms_ext << 24))
    @body = io.read CLASS_CODE[code] || Body, :bytes => body_len
  end
  FLV::Util.double_check :size, len, io.read(:unsigned_long) #todo
end

#write_packed(io) ⇒ Object

:nodoc



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/flvedit/flv/tag.rb', line 23

def write_packed(io, *) #:nodoc
  packed_body = @body.pack
  len = io.pos_change do
    io  << [CLASS_CODE.key(self.body.class), :char] \
        << [packed_body.length, :unsigned_24bits]     \
        << [@timestamp.in_milliseconds, :unsigned_24bits]       \
        << [@timestamp.in_milliseconds >>24, :char]              \
        << [streamid=0, :unsigned_24bits]             \
        << packed_body
  end
  io << [len, :unsigned_long]
end