Class: M3u8::Scte35

Inherits:
Object
  • Object
show all
Defined in:
lib/m3u8/scte35.rb

Overview

Parses SCTE-35 splice_info_section binary payloads from hex strings

Defined Under Namespace

Classes: ParseError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Scte35

Returns a new instance of Scte35.



11
12
13
14
15
# File 'lib/m3u8/scte35.rb', line 11

def initialize(options = {})
  options.each do |key, value|
    instance_variable_set("@#{key}", value)
  end
end

Instance Attribute Details

#descriptorsObject (readonly)

Returns the value of attribute descriptors.



8
9
10
# File 'lib/m3u8/scte35.rb', line 8

def descriptors
  @descriptors
end

#pts_adjustmentObject (readonly)

Returns the value of attribute pts_adjustment.



8
9
10
# File 'lib/m3u8/scte35.rb', line 8

def pts_adjustment
  @pts_adjustment
end

#splice_commandObject (readonly)

Returns the value of attribute splice_command.



8
9
10
# File 'lib/m3u8/scte35.rb', line 8

def splice_command
  @splice_command
end

#splice_command_typeObject (readonly)

Returns the value of attribute splice_command_type.



8
9
10
# File 'lib/m3u8/scte35.rb', line 8

def splice_command_type
  @splice_command_type
end

#table_idObject (readonly)

Returns the value of attribute table_id.



8
9
10
# File 'lib/m3u8/scte35.rb', line 8

def table_id
  @table_id
end

#tierObject (readonly)

Returns the value of attribute tier.



8
9
10
# File 'lib/m3u8/scte35.rb', line 8

def tier
  @tier
end

Class Method Details

.parse(hex_string) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/m3u8/scte35.rb', line 17

def self.parse(hex_string)
  raw = hex_string.sub(/\A0x/i, '')
  data = [raw].pack('H*')
  reader = Scte35BitReader.new(data)

  header = parse_header(reader)
  command = parse_command(reader, header)
  descriptors = parse_descriptors(reader, header)

  args = header.merge(splice_command: command,
                      descriptors: descriptors, raw: hex_string)
  new(**args)
rescue NoMethodError, ArgumentError => e
  raise ParseError, "invalid SCTE-35 data: #{e.message}"
end

.parse_splice_time(reader) ⇒ Object



67
68
69
70
71
72
73
74
75
# File 'lib/m3u8/scte35.rb', line 67

def self.parse_splice_time(reader)
  unless reader.read_flag # time_specified
    reader.skip_bits(7) # reserved
    return nil
  end

  reader.skip_bits(6) # reserved
  reader.read_bits(33)
end

Instance Method Details

#to_sObject



33
34
35
# File 'lib/m3u8/scte35.rb', line 33

def to_s
  @raw
end