Module: MP4::Nolan::Service::Sound

Defined in:
lib/mp4/nolan/service/sound.rb

Class Method Summary collapse

Class Method Details

.compute(cache, segment_index, track:, from_timestamp:, to_timestamp:, sample_timescale:) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/mp4/nolan/service/sound.rb', line 5

def compute(cache, segment_index, track:, from_timestamp:, to_timestamp:, sample_timescale:)
  track_id = track.fetch('track_id')
  relative_from = from_timestamp || 0

  min_chunk_offset = 0
  current_chunk_index = 0

  cache.samples_between_ms(track_id, relative_from, to_timestamp).each_with_index do |original_sample, sample_index_incr|
    if current_chunk_index != original_sample.fetch('chunk_index')
      current_chunk_index = original_sample.fetch('chunk_index')
      min_chunk_offset = original_sample.fetch('offset')
    end

    cache.add_segment_sample(
      track_id: track_id,
      segment_index: segment_index,
      chunk_index: original_sample.fetch('chunk_index'),
      sample_index: sample_index_incr.succ,
      sample_size: original_sample.fetch('size'),
      sample_offset: original_sample.fetch('offset'),
      chunk_offset: min_chunk_offset,
      original_chunk_offset: min_chunk_offset,
      sample_delta: original_sample.fetch('delta'),
      delta_sum: original_sample.fetch('delta_sum'),
      absolute_delta_sum: 0,
      composition_offset: original_sample.fetch('c_delta'),
      is_keyframe: original_sample.fetch('keyframe'),
    )
  end
end