From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS22989 209.51.188.0/24 X-Spam-Status: No, score=-3.9 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 50FFC1F852 for ; Tue, 11 Jan 2022 18:20:51 +0000 (UTC) Received: from localhost ([::1]:47768 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n7LlK-00024k-Bp for e@80x24.org; Tue, 11 Jan 2022 13:20:50 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52810) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n7LlF-00020C-Ce for dtas-all@nongnu.org; Tue, 11 Jan 2022 13:20:46 -0500 Received: from dcvr.yhbt.net ([64.71.152.64]:39234) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n7LlB-0002Pv-M2 for dtas-all@nongnu.org; Tue, 11 Jan 2022 13:20:43 -0500 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 33A0B1F852 for ; Tue, 11 Jan 2022 18:20:40 +0000 (UTC) From: Eric Wong To: dtas-all@nongnu.org Subject: [PATCH] player: reduce syscalls when splicing to single target Date: Tue, 11 Jan 2022 18:20:40 +0000 Message-Id: <20220111182040.4103-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=64.71.152.64; envelope-from=e@80x24.org; helo=dcvr.yhbt.net X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: dtas-all@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: duct tape audio suite List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dtas-all-bounces+e=80x24.org@nongnu.org Sender: "dtas-all" 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