Class: FormatParser::AACParser

Inherits:
Object
  • Object
show all
Includes:
IOUtils
Defined in:
lib/parsers/aac_parser.rb

Constant Summary collapse

AAC_MIME_TYPE =
'audio/aac'

Constants included from IOUtils

IOUtils::INTEGER_DIRECTIVES

Instance Method Summary collapse

Methods included from IOUtils

#read_bytes, #read_fixed_point, #read_int, #safe_read, #safe_skip, #skip_bytes

Instance Method Details

#call(raw_io) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/parsers/aac_parser.rb', line 12

def call(raw_io)
  io = FormatParser::IOConstraint.new(raw_io)
  header = safe_read(io, 9)
  header_bits = header.unpack('B*').first.split('')

  header_info = FormatParser::AdtsHeaderInfo.parse_adts_header(header_bits)
  return if header_info.nil?

  FormatParser::Audio.new(
    title: nil,
    album: nil,
    artist: nil,
    format: :aac,
    num_audio_channels: header_info.number_of_audio_channels,
    audio_sample_rate_hz: header_info.mpeg4_sampling_frequency,
    media_duration_seconds: nil,
    media_duration_frames: nil,
    intrinsics: nil,
    content_type: AAC_MIME_TYPE
  )
end

#likely_match?(filename) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/parsers/aac_parser.rb', line 8

def likely_match?(filename)
  filename =~ /\.aac$/i
end