everything related to duct tape audio suite (dtas)
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: dtas-all@nongnu.org
Subject: [PATCH] player: reduce syscalls when splicing to single target
Date: Tue, 11 Jan 2022 18:20:40 +0000	[thread overview]
Message-ID: <20220111182040.4103-1-e@80x24.org> (raw)

splice(2) alone does not give enough information as to whether
the source or destination is blocking.  However, as far as audio
playback chain goes, the sink should ALWAYS be the limiting
factor as decoder sources need to be able to produce data at
least as fast as the audio is being played (otherwise there'll
be audible drops).

Thus, we bias the select(2) into waiting on a targets on if we
splice(2) less than the data we requested.
---
 lib/dtas/buffer/fiddle_splice.rb | 3 ++-
 lib/dtas/buffer/splice.rb        | 3 ++-
 test/test_buffer.rb              | 2 +-
 3 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/lib/dtas/buffer/fiddle_splice.rb b/lib/dtas/buffer/fiddle_splice.rb
index ad007eb..d9232cd 100644
--- a/lib/dtas/buffer/fiddle_splice.rb
+++ b/lib/dtas/buffer/fiddle_splice.rb
@@ -84,7 +84,8 @@ def broadcast_one(targets, limit = nil)
       targets # our one and only target blocked on write
     else
       @bytes_xfer += s
-      :wait_readable # we want to read more from @to_io soon
+      # s < limit means targets[0] is full
+      s < limit ? targets : :wait_readable
     end
   rescue Errno::EPIPE, IOError => e
     __dst_error(targets[0], e)
diff --git a/lib/dtas/buffer/splice.rb b/lib/dtas/buffer/splice.rb
index e5d17ab..b9957ce 100644
--- a/lib/dtas/buffer/splice.rb
+++ b/lib/dtas/buffer/splice.rb
@@ -39,7 +39,8 @@ def broadcast_one(targets, limit = nil)
       targets # our one and only target blocked on write
     else
       @bytes_xfer += s
-      :wait_readable # we want to read more from @to_io soon
+      # s < limit means targets[0] is full
+      s < limit ? targets : :wait_readable
     end
   rescue Errno::EPIPE, IOError => e
     __dst_error(targets[0], e)
diff --git a/test/test_buffer.rb b/test/test_buffer.rb
index 54ee584..b89a090 100644
--- a/test/test_buffer.rb
+++ b/test/test_buffer.rb
@@ -62,7 +62,7 @@ def test_broadcast_1
     buf = new_buffer
     r, w = IO.pipe
     buf.wr.write "HIHI"
-    assert_equal :wait_readable, buf.broadcast([w])
+    assert_equal [w], buf.broadcast([w])
     assert_equal 4, buf.bytes_xfer
     tmp = [w]
     r.close


                 reply	other threads:[~2022-01-11 18:20 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://80x24.org/dtas/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220111182040.4103-1-e@80x24.org \
    --to=e@80x24.org \
    --cc=dtas-all@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/dtas.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).