提交 88830ea7 编写于 作者: A alitvinov

8168751: Two "Direct Clip" threads are created to play the same "AudioClip"...

8168751: Two "Direct Clip" threads are created to play the same "AudioClip" object, what makes clip sound corrupted
Reviewed-by: serb, amenkov
上级 12f5fbd7
...@@ -1017,15 +1017,15 @@ final class DirectAudioDevice extends AbstractMixer { ...@@ -1017,15 +1017,15 @@ final class DirectAudioDevice extends AbstractMixer {
private static final class DirectClip extends DirectDL private static final class DirectClip extends DirectDL
implements Clip, Runnable, AutoClosingClip { implements Clip, Runnable, AutoClosingClip {
private Thread thread; private volatile Thread thread;
private byte[] audioData = null; private volatile byte[] audioData = null;
private int frameSize; // size of one frame in bytes private volatile int frameSize; // size of one frame in bytes
private int m_lengthInFrames; private volatile int m_lengthInFrames;
private int loopCount; private volatile int loopCount;
private int clipBytePosition; // index in the audioData array at current playback private volatile int clipBytePosition; // index in the audioData array at current playback
private int newFramePosition; // set in setFramePosition() private volatile int newFramePosition; // set in setFramePosition()
private int loopStartFrame; private volatile int loopStartFrame;
private int loopEndFrame; // the last sample included in the loop private volatile int loopEndFrame; // the last sample included in the loop
// auto closing clip support // auto closing clip support
private boolean autoclosing = false; private boolean autoclosing = false;
...@@ -1355,7 +1355,8 @@ final class DirectAudioDevice extends AbstractMixer { ...@@ -1355,7 +1355,8 @@ final class DirectAudioDevice extends AbstractMixer {
// main playback loop // main playback loop
public void run() { public void run() {
if (Printer.trace) Printer.trace(">>> DirectClip: run() threadID="+Thread.currentThread().getId()); if (Printer.trace) Printer.trace(">>> DirectClip: run() threadID="+Thread.currentThread().getId());
while (thread != null) { Thread curThread = Thread.currentThread();
while (thread == curThread) {
// doIO is volatile, but we could check it, then get // doIO is volatile, but we could check it, then get
// pre-empted while another thread changes doIO and notifies, // pre-empted while another thread changes doIO and notifies,
// before we wait (so we sleep in wait forever). // before we wait (so we sleep in wait forever).
...@@ -1363,7 +1364,12 @@ final class DirectAudioDevice extends AbstractMixer { ...@@ -1363,7 +1364,12 @@ final class DirectAudioDevice extends AbstractMixer {
if (!doIO) { if (!doIO) {
try { try {
lock.wait(); lock.wait();
} catch(InterruptedException ie) {} } catch(InterruptedException ie) {
} finally {
if (thread != curThread) {
break;
}
}
} }
} }
while (doIO) { while (doIO) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册