Source-Changes-HG archive

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

[src/netbsd-10]: src/usr.sbin/bta2dpd/bta2dpd Pull up following revision(s) (...



details:   https://anonhg.NetBSD.org/src/rev/85e055b8b751
branches:  netbsd-10
changeset: 376050:85e055b8b751
user:      martin <martin%NetBSD.org@localhost>
date:      Sun May 28 10:34:59 2023 +0000

description:
Pull up following revision(s) (requested by nat in ticket #184):

        usr.sbin/bta2dpd/bta2dpd/sbc_encode.c: revision 1.11

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 7af9b81f4608 -r 85e055b8b751 usr.sbin/bta2dpd/bta2dpd/sbc_encode.c
--- a/usr.sbin/bta2dpd/bta2dpd/sbc_encode.c     Sun May 28 10:20:08 2023 +0000
+++ b/usr.sbin/bta2dpd/bta2dpd/sbc_encode.c     Sun May 28 10:34:59 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.10.8.1 2023/05/28 10:34:59 martin 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