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/47e19e6bcaee
branches: netbsd-10
changeset: 378165:47e19e6bcaee
user: martin <martin%NetBSD.org@localhost>
date: Mon Jul 24 17:12:49 2023 +0000
description:
Pull up following revision(s) (requested by nat in ticket #240):
usr.sbin/bta2dpd/bta2dpd/sbc_encode.c: revision 1.12
usr.sbin/bta2dpd/bta2dpd/sbc_encode.c: revision 1.13
Add thottling when playing from file.
This avoids rapid playback when playing from file with affected devices.
Playback using pad(4) is still preferred ad gives a better result.
Playback from pad(4) is unaffected by this change.
Reorder for readability.
No functional change intended.
diffstat:
usr.sbin/bta2dpd/bta2dpd/sbc_encode.c | 22 +++++++++++++++++++++-
1 files changed, 21 insertions(+), 1 deletions(-)
diffs (74 lines):
diff -r 2ac3058faa7a -r 47e19e6bcaee usr.sbin/bta2dpd/bta2dpd/sbc_encode.c
--- a/usr.sbin/bta2dpd/bta2dpd/sbc_encode.c Mon Jul 24 17:08:01 2023 +0000
+++ b/usr.sbin/bta2dpd/bta2dpd/sbc_encode.c Mon Jul 24 17:12:49 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sbc_encode.c,v 1.10.8.1 2023/05/28 10:34:59 martin Exp $ */
+/* $NetBSD: sbc_encode.c,v 1.10.8.2 2023/07/24 17:12:49 martin Exp $ */
/*-
* Copyright (c) 2015 - 2016 Nathanial Sloss <nathanialsloss%yahoo.com.au@localhost>
@@ -32,6 +32,7 @@
*/
#include <sys/cdefs.h>
+#include <sys/time.h>
#include <sys/types.h>
#include <sys/param.h>
#include <errno.h>
@@ -841,6 +842,7 @@ stream(int in, int outfd, uint8_t mode,
blocks, uint8_t alloc_method, uint8_t bitpool, size_t mtu, int volume)
{
struct rtpHeader myHeader;
+ struct timeval myTime;
uint8_t *whole, *frameData;
int16_t music[2048];
ssize_t len, mySize[16], offset, next_pkt;
@@ -849,6 +851,7 @@ stream(int in, int outfd, uint8_t mode,
size_t frequency;
static size_t ts = 0;
static uint16_t seqnumber = 0;
+ static time_t prevTime, readTime, sleepTime, timeNow;
int numpkts, tries;
global_mode = mode;
@@ -912,9 +915,11 @@ stream(int in, int outfd, uint8_t mode,
next_pkt = 0;
len = 0;
pkt_len = 80;
+ readTime = 0;
while (totalSize + ((size_t)pkt_len * 2) <= mtu) {
len = readloop(in, music, readsize);
+ readTime += (time_t)readsize;
if (len < (int)readsize)
break;
@@ -934,6 +939,8 @@ stream(int in, int outfd, uint8_t mode,
return -1;
}
+ readTime = readTime * 1000000 / 2 / global_chan / (time_t)frequency;
+
myHeader.numFrames = (uint8_t)numpkts;
whole = malloc(totalSize);
if (whole == NULL)
@@ -945,6 +952,19 @@ stream(int in, int outfd, uint8_t mode,
memcpy(whole + offset, frameData, (size_t)next_pkt);
free(frameData);
+ /* Wait if necessary to avoid rapid playback. */
+ gettimeofday(&myTime, NULL);
+ timeNow = myTime.tv_sec * 1000000 + myTime.tv_usec;
+ if (prevTime == 0)
+ prevTime = timeNow;
+ else
+ sleepTime += readTime - (timeNow - prevTime);
+ if (sleepTime >= 1000) {
+ usleep(500);
+ sleepTime -= 1000;
+ }
+ prevTime = timeNow;
+
tries = 1;
send_again:
len = write(outfd, whole, totalSize);
Home |
Main Index |
Thread Index |
Old Index