bytedeco/javacv

Gradually increase of the latency in Java Sound during executions

Open

#1,102 opened on Dec 5, 2018

View on GitHub
 (5 comments) (0 reactions) (0 assignees)Java (1,583 forks)batch import
enhancementhelp wanted

Repository metrics

Stars
 (6,985 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

I'm writing a multi audio and video stream player in Java and I'm experiencing some latency/delays that mostly and gradually shows up if the application is left running for a while. Sometimes it is after just 2 mins or 20 mins or even after 1 hour later.

First I thought it was the SourceDataLine instantiation and I change it to a mixer from this: sdl = (SourceDataLine)AudioSystem.getLine(info); to sdl = (SourceDataLine)mixer.getLine(info);. However, it has the same results.

Initially it behaves as expected with a tiny delay of 250 ms approximately. However if the program is left running for a while then that delay is increased to several seconds.

I tested with different headsets. I tested with Java 8, 9, 10 and it consistently displays the same behaviour. I also experimented with drain() and flush() and so on but the only thing that gets rid of the delay is to close and recreate the SourceDataLine.

Finally I decided to implement an audio meter at the moment that I got an audio frame and I notice that what I heard is what audio meter shows. Therefore, the delay is not in the SourceDataLine but in the Frame frame = grabber.grab();

Then I check the ffplay source code and I found that they have a sync option that can be either one of these three options audio|video|ext. This option sets the audio-video sync type.

The ext type refers to AV_SYNC_EXTERNAL_CLOCK probably this configuration will help to synchronize the stream based on the RTSP clock parameter like in the ffplay implementation.

Probably this must be related to this other issue.

Contributor guide