HTTP audio servlet: check end of play every 2 seconds (#3695)

Instead of 5s before.
It helps triggering the end of playback earlier for audio sinks in asynchronous mode.

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
pull/3640/merge
lolodomo 2023-07-11 18:46:01 +02:00 committed by GitHub
parent 591b16ff35
commit f0adf76719
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 1 deletions

View File

@ -189,6 +189,9 @@ public class AudioServlet extends HttpServlet implements AudioHTTPServer {
// update timeout with the sound duration :
if (endOfPlayTimestamp != null) {
servedStream.timeout().set(Math.max(servedStream.timeout().get(), endOfPlayTimestamp));
logger.debug(
"doGet endOfPlayTimestamp {} (delay from now {} nanoseconds) => new timeout timestamp {} nanoseconds",
endOfPlayTimestamp, endOfPlayTimestamp - System.nanoTime(), servedStream.timeout().get());
}
resp.flushBuffer();
} catch (final AudioException ex) {
@ -234,7 +237,7 @@ public class AudioServlet extends HttpServlet implements AudioHTTPServer {
if (!servedStreams.isEmpty()) {
if (periodicCleanerLocal == null || periodicCleanerLocal.isDone()) {
// reschedule a clean
periodicCleaner = threadPool.scheduleWithFixedDelay(this::removeTimedOutStreams, 5, 5,
periodicCleaner = threadPool.scheduleWithFixedDelay(this::removeTimedOutStreams, 2, 2,
TimeUnit.SECONDS);
}
} else if (periodicCleanerLocal != null) { // no more stream to serve, shut the periodic cleaning thread:
@ -274,6 +277,7 @@ public class AudioServlet extends HttpServlet implements AudioHTTPServer {
audioStream = createClonableInputStream(originalStream, streamId);
}
long timeOut = System.nanoTime() + TimeUnit.SECONDS.toNanos(seconds);
logger.debug("timeout {} seconds => timestamp {} nanoseconds", seconds, timeOut);
CompletableFuture<@Nullable Void> playEnd = new CompletableFuture<@Nullable Void>();
StreamServed streamToServe = new StreamServed(getRelativeURL(streamId), audioStream, new AtomicInteger(),
new AtomicLong(timeOut), multiTimeStream, playEnd);