Skip to content

Commit 0da5a7f

Browse files
authored
solve issue #1761 (AssertionError in ALAudioRenderer) (#1762)
* solve issue #1761 (AssertionError in ALAudioRenderer) * add a test for issue #1761
1 parent c183ff0 commit 0da5a7f

File tree

2 files changed

+91
-15
lines changed

2 files changed

+91
-15
lines changed

jme3-core/src/main/java/com/jme3/audio/openal/ALAudioRenderer.java

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -989,21 +989,11 @@ public void updateInDecoderThread(float tpf) {
989989
// Keep filling data (even if we are stopped / paused)
990990
boolean buffersWereFilled = fillStreamingSource(sourceId, stream, src.isLooping());
991991

992-
if (buffersWereFilled) {
993-
if (oalStatus == Status.Stopped && jmeStatus == Status.Playing) {
994-
// The source got stopped due to buffer starvation.
995-
// Start it again.
996-
logger.log(Level.WARNING, "Buffer starvation "
997-
+ "occurred while playing stream");
998-
al.alSourcePlay(sourceId);
999-
} else {
1000-
// Buffers were filled, stream continues to play.
1001-
if (oalStatus == Status.Playing && jmeStatus == Status.Playing) {
1002-
// Nothing to do.
1003-
} else {
1004-
throw new AssertionError();
1005-
}
1006-
}
992+
if (buffersWereFilled && oalStatus == Status.Stopped && jmeStatus == Status.Playing) {
993+
// The source got stopped due to buffer starvation.
994+
// Start it again.
995+
logger.log(Level.WARNING, "Buffer starvation occurred while playing stream");
996+
al.alSourcePlay(sourceId);
1007997
}
1008998
}
1009999

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* Copyright (c) 2009-2022 jMonkeyEngine
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are
7+
* met:
8+
*
9+
* * Redistributions of source code must retain the above copyright
10+
* notice, this list of conditions and the following disclaimer.
11+
*
12+
* * Redistributions in binary form must reproduce the above copyright
13+
* notice, this list of conditions and the following disclaimer in the
14+
* documentation and/or other materials provided with the distribution.
15+
*
16+
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
17+
* may be used to endorse or promote products derived from this software
18+
* without specific prior written permission.
19+
*
20+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22+
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
*/
32+
package jme3test.audio;
33+
34+
import com.jme3.app.SimpleApplication;
35+
import com.jme3.asset.plugins.UrlLocator;
36+
import com.jme3.audio.AudioData;
37+
import com.jme3.audio.AudioNode;
38+
import java.util.Random;
39+
40+
/**
41+
* Stress test to reproduce JME issue #1761 (AssertionError in ALAudioRenderer).
42+
*
43+
* <p>After some network delay, a song will play,
44+
* albeit slowly and in a broken fashion.
45+
* If the issue is solved, the song will play all the way through.
46+
* If the issue is present, an AssertionError will be thrown, usually within a
47+
* second of the song starting.
48+
*/
49+
public class TestIssue1761 extends SimpleApplication {
50+
51+
private AudioNode audioNode;
52+
final private Random random = new Random();
53+
54+
/**
55+
* Main entry point for the TestIssue1761 application.
56+
*
57+
* @param unused array of command-line arguments
58+
*/
59+
public static void main(String[] unused) {
60+
TestIssue1761 test = new TestIssue1761();
61+
test.start();
62+
}
63+
64+
@Override
65+
public void simpleInitApp() {
66+
assetManager.registerLocator(
67+
"https://web.archive.org/web/20170625151521if_/http://www.vorbis.com/music/",
68+
UrlLocator.class);
69+
audioNode = new AudioNode(assetManager, "Lumme-Badloop.ogg",
70+
AudioData.DataType.Stream);
71+
audioNode.setPositional(false);
72+
audioNode.play();
73+
}
74+
75+
@Override
76+
public void simpleUpdate(float tpf) {
77+
/*
78+
* Randomly pause and restart the audio.
79+
*/
80+
if (random.nextInt(2) == 0) {
81+
audioNode.pause();
82+
} else {
83+
audioNode.play();
84+
}
85+
}
86+
}

0 commit comments

Comments
 (0)