Skip to content

Commit

Permalink
HTTP audio servlet: check end of play every 2 seconds (#3695)
Browse files Browse the repository at this point in the history
Instead of 5s before.
It helps triggering the end of playback earlier for audio sinks in asynchronous mode.

Signed-off-by: Laurent Garnier <[email protected]>
  • Loading branch information
lolodomo authored Jul 11, 2023
1 parent 591b16f commit f0adf76
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se
// 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) {
Expand Down Expand Up @@ -234,7 +237,7 @@ private synchronized void removeTimedOutStreams() {
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:
Expand Down Expand Up @@ -274,6 +277,7 @@ public StreamServed serve(AudioStream originalStream, int seconds, boolean multi
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);
Expand Down

0 comments on commit f0adf76

Please sign in to comment.