about summary refs log tree commit homepage
path: root/lib/dtas/player.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/dtas/player.rb')
-rw-r--r--lib/dtas/player.rb29
1 files changed, 15 insertions, 14 deletions
diff --git a/lib/dtas/player.rb b/lib/dtas/player.rb
index 37f2c96..6ea3aba 100644
--- a/lib/dtas/player.rb
+++ b/lib/dtas/player.rb
@@ -1,8 +1,8 @@
-# Copyright (C) 2013-2016 all contributors <dtas-all@nongnu.org>
+# Copyright (C) all contributors <dtas-all@nongnu.org>
 # License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
 # frozen_string_literal: true
-require 'yaml'
 require 'shellwords'
+require 'yaml'
 require_relative '../dtas'
 require_relative 'xs'
 require_relative 'source'
@@ -37,6 +37,7 @@ class DTAS::Player # :nodoc:
     @paused = false
     @format = DTAS::Format.new
     @bypass = [] # %w(rate bits channels) (not worth Hash overhead)
+    @bypass_next = nil # source_spec
 
     @sinks = {} # { user-defined name => sink }
     @targets = [] # order matters
@@ -123,10 +124,6 @@ class DTAS::Player # :nodoc:
     rv
   end
 
-  def to_omap(hash)
-    YAML::Omap === hash ? hash : YAML::Omap.new.merge!(hash)
-  end
-
   def self.load(hash)
     rv = new
     rv.instance_eval do
@@ -157,7 +154,6 @@ class DTAS::Player # :nodoc:
         @source_map.each do |name, src|
           src_hsh = v[name] or next
           src.load!(src_hsh)
-          src.env = to_omap(src.env)
         end
         source_map_reload
       end
@@ -168,9 +164,8 @@ class DTAS::Player # :nodoc:
 
       if sinks = hash["sinks"]
         sinks.each do |sink_hsh|
-          sink_hsh['name'] = DTAS.dedupe_str(sink_hsh['name'])
+          sink_hsh['name'] = -sink_hsh['name']
           sink = DTAS::Sink.load(sink_hsh)
-          sink.env = to_omap(sink.env)
           @sinks[sink.name] = sink
         end
       end
@@ -208,13 +203,13 @@ class DTAS::Player # :nodoc:
     command = msg.shift
     case command
     when "enq"
-      enq_handler(io, msg[0])
+      enq_handler(io, -msg[0])
     when "enq-cmd"
-      enq_handler(io, { "command" => msg[0]})
+      enq_handler(io, { "command" => -msg[0]})
     when "pause", "play", "play_pause"
       play_pause_handler(io, command)
     when "pwd"
-      io.emit(Dir.pwd)
+      io.emit(-Dir.pwd)
     else
       m = "dpc_#{command.tr('-', '_')}"
       __send__(m, io, msg) if respond_to?(m)
@@ -282,7 +277,7 @@ class DTAS::Player # :nodoc:
     if deleted[0]
       warn("#{sink.name} died unexpectedly: #{status.inspect}")
       deleted.each { |t| drop_target(t) }
-      __current_drop unless @targets[0]
+      do_pause unless @targets[0]
       return # sink stays dead if it died unexpectedly
     end
 
@@ -337,6 +332,7 @@ class DTAS::Player # :nodoc:
 
   # called when the player is leaving idle state
   def spawn_sinks(source_spec)
+    @bypass_next = nil
     return true if @targets[0]
     @sinks.each_value do |sink|
       sink.active or next
@@ -398,6 +394,8 @@ class DTAS::Player # :nodoc:
       if ! @bypass.empty? && pending.respond_to?(:format)
         new_fmt = bypass_match!(@format.dup, pending.format)
         if new_fmt != @format
+          @bypass_next = source_spec
+          return if @sink_buf.inflight > 0
           stop_sinks # we may fail to start below
           format_update!(new_fmt)
         end
@@ -440,6 +438,7 @@ class DTAS::Player # :nodoc:
   end
 
   def stop_sinks
+    @bypass_next = nil
     @targets.each { |t| drop_target(t) }.clear
   end
 
@@ -451,7 +450,7 @@ class DTAS::Player # :nodoc:
   # pull data from sink_buf into @targets, source feeds into sink_buf
   def sink_iter
     wait_iter = broadcast_iter(@sink_buf, @targets)
-    __current_drop if nil == wait_iter # sink error, stop source
+    do_pause if nil == wait_iter # sink error, stop source
     return wait_iter if @current
 
     # no source left to feed sink_buf, drain the remaining data
@@ -464,7 +463,9 @@ class DTAS::Player # :nodoc:
     end
 
     # nothing left inflight, stop the sinks until we have a source
+    bn = @bypass_next
     stop_sinks
+    next_source(bn) if bn # are we restarting for bypass?
     :ignore
   end