Method: DTAS::Player#next_source

Defined in:
lib/dtas/player.rb

#next_source(source_spec) ⇒ Object



382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
# File 'lib/dtas/player.rb', line 382

def next_source(source_spec)
  @current.respond_to?(:watch_end) and @current.watch_end(@srv)
  @current = nil
  if source_spec
    case source_spec
    when String
      pending = try_file(source_spec) or return
      msg = %W(file #{pending.infile})
    when Array
      pending = try_file(*source_spec) or return
      msg = %W(file #{pending.infile} #{pending.offset_samples}s)
    else
      pending = DTAS::Source::Cmd.new(source_spec["command"])
      msg = %W(command #{pending.command_string})
    end

    if ! @bypass.empty? && pending.respond_to?(:format)
      new_fmt = bypass_match!(@format.dup, pending.format)
      if new_fmt != @format
        stop_sinks # we may fail to start below
        format_update!(new_fmt)
      end
    end

    # restart sinks iff we were idle
    spawn_sinks(source_spec) or return

    dst = @sink_buf
    pending.dst_assoc(dst)
    pending.src_spawn(@format, @rg, out: dst.wr, in: DTAS.null)

    # watch and restart on modifications
    pending.respond_to?(:watch_begin) and
      @srv.wait_ctl(pending.watch_begin(method(:__current_requeue)),
                    :wait_readable)

    @current = pending
    @srv.wait_ctl(dst, :wait_readable)
    wall(msg)
  else
    player_idle
  end
end