Class: FormatParser::OggParser
- Inherits:
-
Object
- Object
- FormatParser::OggParser
show all
- Includes:
- IOUtils
- Defined in:
- lib/parsers/ogg_parser.rb
Overview
Constant Summary
collapse
- MAX_POSSIBLE_PAGE_SIZE =
65307
- OGG_MIME_TYPE =
'audio/ogg'
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
permalink
#call(io) ⇒ Object
[View source]
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/parsers/ogg_parser.rb', line 13
def call(io)
capture_pattern = safe_read(io, 4)
return unless capture_pattern == 'OggS'
io.seek(28)
packet_type, vorbis, _vorbis_version, channels, sample_rate = safe_read(io, 16).unpack('Ca6VCV')
return unless packet_type == 1 && vorbis == 'vorbis'
pos = io.size - MAX_POSSIBLE_PAGE_SIZE
pos = 0 if pos < 0
io.seek(pos)
tail = io.read(MAX_POSSIBLE_PAGE_SIZE)
return unless tail
granule_position = find_last_granule_position(tail)
return unless granule_position
duration = granule_position / sample_rate.to_f
return if duration == Float::INFINITY
FormatParser::Audio.new(
format: :ogg,
audio_sample_rate_hz: sample_rate,
num_audio_channels: channels,
media_duration_seconds: duration,
content_type: OGG_MIME_TYPE,
)
end
|
permalink
#likely_match?(filename) ⇒ Boolean
[View source]
9
10
11
|
# File 'lib/parsers/ogg_parser.rb', line 9
def likely_match?(filename)
filename =~ /\.ogg$/i
end
|