Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/bta2dpd/bta2dpd With the latest changes, pad(4) wil...



details:   https://anonhg.NetBSD.org/src/rev/d4af99e5035a
branches:  trunk
changeset: 376033:d4af99e5035a
user:      mlelstv <mlelstv%NetBSD.org@localhost>
date:      Sun May 28 07:59:17 2023 +0000

description:
With the latest changes, pad(4) will return partial reads to allow a
more fine grained pacing of audio data. But this broke bta2dpd which
relied on full buffers returned (like reading from a file).

Replace the single read() in bta2dpd with a loop that fetches a full
buffer. This restores the old behaviour but loops in userland instead
of the kernel at the cost of a few extra system calls.

diffstat:

 usr.sbin/bta2dpd/bta2dpd/sbc_encode.c |  27 +++++++++++++++++++++++++--
 1 files changed, 25 insertions(+), 2 deletions(-)

diffs (48 lines):

diff -r 1c1da11d6449 -r d4af99e5035a usr.sbin/bta2dpd/bta2dpd/sbc_encode.c
--- a/usr.sbin/bta2dpd/bta2dpd/sbc_encode.c     Sun May 28 06:21:00 2023 +0000
+++ b/usr.sbin/bta2dpd/bta2dpd/sbc_encode.c     Sun May 28 07:59:17 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sbc_encode.c,v 1.10 2019/09/21 00:01:33 nat Exp $ */
+/* $NetBSD: sbc_encode.c,v 1.11 2023/05/28 07:59:17 mlelstv Exp $ */
 
 /*-
  * Copyright (c) 2015 - 2016 Nathanial Sloss <nathanialsloss%yahoo.com.au@localhost>
@@ -813,6 +813,29 @@ make_frame(uint8_t *frame, int16_t *inpu
        return frame - frameStart;
 }
 
+static ssize_t
+readloop(int fd, void *buf, size_t nbytes)
+{
+       size_t count;
+       ssize_t ret;
+
+       count = 0;
+       while (nbytes > 0) {
+               ret = read(fd, ((char *)buf) + count, nbytes);
+               if (ret < 0) {
+                       if (count == 0)
+                               return ret;
+                       break;
+               }
+               if (ret == 0)
+                       break;
+               count += (size_t)ret;
+               nbytes -= (size_t)ret;
+       }
+
+       return (ssize_t) count;
+}
+
 ssize_t
 stream(int in, int outfd, uint8_t mode, uint8_t freq, uint8_t bands, uint8_t
     blocks, uint8_t alloc_method, uint8_t bitpool, size_t mtu, int volume)
@@ -891,7 +914,7 @@ stream(int in, int outfd, uint8_t mode, 
        pkt_len = 80;
        while (totalSize + ((size_t)pkt_len * 2) <= mtu) {
 
-               len = read(in, music, readsize);
+               len = readloop(in, music, readsize);
                if (len < (int)readsize)
                        break;
 



Home | Main Index | Thread Index | Old Index