Class: Wavify::Core::Stream::ProgressProcessor
- Inherits:
-
Object
- Object
- Wavify::Core::Stream::ProgressProcessor
- Defined in:
- lib/wavify/core/stream.rb
Overview
Passive stream processor that reports cumulative processed frames.
Instance Method Summary collapse
-
#initialize(callback, total_frames:) ⇒ ProgressProcessor
constructor
A new instance of ProgressProcessor.
- #process(chunk) ⇒ Object
- #reset ⇒ Object
Constructor Details
#initialize(callback, total_frames:) ⇒ ProgressProcessor
Returns a new instance of ProgressProcessor.
370 371 372 373 374 |
# File 'lib/wavify/core/stream.rb', line 370 def initialize(callback, total_frames:) @callback = callback @total_frames = total_frames @processed_frames = 0 end |
Instance Method Details
#process(chunk) ⇒ Object
380 381 382 383 384 385 386 387 388 389 390 391 392 393 |
# File 'lib/wavify/core/stream.rb', line 380 def process(chunk) @processed_frames += chunk.sample_frame_count stats = { format: chunk.format, sample_frame_count: @processed_frames, duration: Duration.from_samples(@processed_frames, chunk.format.sample_rate) } stats[:total_frames] = @total_frames if @total_frames stats[:progress] = [@processed_frames.to_f / @total_frames, 1.0].min if @total_frames&.positive? @callback.call(stats) chunk rescue StandardError => e raise UserCodeError, e end |
#reset ⇒ Object
376 377 378 |
# File 'lib/wavify/core/stream.rb', line 376 def reset @processed_frames = 0 end |