cleanup
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1988 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,11 +1,8 @@
|
|||||||
//
|
//
|
||||||
// $Id: SoundManager.java,v 1.27 2002/11/23 03:24:26 ray Exp $
|
// $Id: SoundManager.java,v 1.28 2002/11/25 20:02:31 ray Exp $
|
||||||
|
|
||||||
package com.threerings.media;
|
package com.threerings.media;
|
||||||
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@@ -37,7 +34,7 @@ import javax.swing.Timer;
|
|||||||
|
|
||||||
import org.apache.commons.io.StreamUtils;
|
import org.apache.commons.io.StreamUtils;
|
||||||
|
|
||||||
import com.samskivert.util.CollectionUtil;
|
import com.samskivert.util.Config;
|
||||||
import com.samskivert.util.LockableLRUHashMap;
|
import com.samskivert.util.LockableLRUHashMap;
|
||||||
import com.samskivert.util.LRUHashMap;
|
import com.samskivert.util.LRUHashMap;
|
||||||
import com.samskivert.util.Queue;
|
import com.samskivert.util.Queue;
|
||||||
@@ -139,7 +136,7 @@ public class SoundManager
|
|||||||
updateMusicVolume();
|
updateMusicVolume();
|
||||||
|
|
||||||
} else if (DIE == command) {
|
} else if (DIE == command) {
|
||||||
// TODO: clean up more stuff.
|
LineSpooler.shutdown();
|
||||||
shutdownMusic();
|
shutdownMusic();
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -540,8 +537,12 @@ public class SoundManager
|
|||||||
playTopMusic();
|
playTopMusic();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shutdown the music subsystem.
|
||||||
|
*/
|
||||||
protected void shutdownMusic ()
|
protected void shutdownMusic ()
|
||||||
{
|
{
|
||||||
|
_musicStack.clear();
|
||||||
if (_musicPlayer != null) {
|
if (_musicPlayer != null) {
|
||||||
_musicPlayer.stop();
|
_musicPlayer.stop();
|
||||||
_musicPlayer.shutdown();
|
_musicPlayer.shutdown();
|
||||||
@@ -625,13 +626,13 @@ public class SoundManager
|
|||||||
AudioFormat format = stream.getFormat();
|
AudioFormat format = stream.getFormat();
|
||||||
LineSpooler spooler;
|
LineSpooler spooler;
|
||||||
|
|
||||||
for (int ii=0, nn=_available.size(); ii < nn; ii++) {
|
for (int ii=0, nn=_openSpoolers.size(); ii < nn; ii++) {
|
||||||
spooler = (LineSpooler) _available.get(ii);
|
spooler = (LineSpooler) _openSpoolers.get(ii);
|
||||||
|
|
||||||
// we have this thread remove the spooler if it's dead
|
// we have this thread remove the spooler if it's dead
|
||||||
// so that we avoid deadlock conditions
|
// so that we avoid deadlock conditions
|
||||||
if (spooler.isDead()) {
|
if (spooler.isDead()) {
|
||||||
_available.remove(ii--);
|
_openSpoolers.remove(ii--);
|
||||||
nn--;
|
nn--;
|
||||||
|
|
||||||
} else if (spooler.checkPlay(format, stream, volume)) {
|
} else if (spooler.checkPlay(format, stream, volume)) {
|
||||||
@@ -639,17 +640,33 @@ public class SoundManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_available.size() >= MAX_SPOOLERS) {
|
if (_openSpoolers.size() >= MAX_SPOOLERS) {
|
||||||
throw new LineUnavailableException("Exceeded maximum number " +
|
throw new LineUnavailableException("Exceeded maximum number " +
|
||||||
"of narya sound spoolers.");
|
"of narya sound spoolers.");
|
||||||
}
|
}
|
||||||
|
|
||||||
spooler = new LineSpooler(format);
|
spooler = new LineSpooler(format);
|
||||||
_available.add(spooler);
|
_openSpoolers.add(spooler);
|
||||||
spooler.checkPlay(format, stream, volume);
|
spooler.checkPlay(format, stream, volume);
|
||||||
spooler.start();
|
spooler.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shutdown the linespooler subsystem.
|
||||||
|
*/
|
||||||
|
public static void shutdown ()
|
||||||
|
{
|
||||||
|
// this is all that is needed, after 30 seconds each spooler
|
||||||
|
for (int ii=0, nn=_openSpoolers.size(); ii < nn; ii++) {
|
||||||
|
// this will stop playback now
|
||||||
|
((LineSpooler) _openSpoolers.get(ii)).setDead();
|
||||||
|
}
|
||||||
|
// and this will remove all the spoolers. They'll still be
|
||||||
|
// around while they drain their lines and then wait 30 seconds
|
||||||
|
// to die...
|
||||||
|
_openSpoolers.clear();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Private constructor.
|
* Private constructor.
|
||||||
*/
|
*/
|
||||||
@@ -665,6 +682,14 @@ public class SoundManager
|
|||||||
_line.start();
|
_line.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set this line to dead.
|
||||||
|
*/
|
||||||
|
protected void setDead ()
|
||||||
|
{
|
||||||
|
_valid = false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Has this line been closed?
|
* Has this line been closed?
|
||||||
*/
|
*/
|
||||||
@@ -702,7 +727,7 @@ public class SoundManager
|
|||||||
// ignore.
|
// ignore.
|
||||||
}
|
}
|
||||||
if (_stream == null) {
|
if (_stream == null) {
|
||||||
_valid = false;
|
setDead(); // we waited 30 seconds and never got a sound.
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -730,11 +755,12 @@ public class SoundManager
|
|||||||
int count = 0;
|
int count = 0;
|
||||||
byte[] data = new byte[BUFFER_SIZE];
|
byte[] data = new byte[BUFFER_SIZE];
|
||||||
|
|
||||||
while (count != -1) {
|
while (_valid && count != -1) {
|
||||||
try {
|
try {
|
||||||
count = _stream.read(data, 0, data.length);
|
count = _stream.read(data, 0, data.length);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// this shouldn't ever ever happen
|
// this shouldn't ever ever happen because the stream
|
||||||
|
// we're given is from a reliable source
|
||||||
Log.warning("Error reading clip data! [e=" + e + "].");
|
Log.warning("Error reading clip data! [e=" + e + "].");
|
||||||
_stream = null;
|
_stream = null;
|
||||||
return;
|
return;
|
||||||
@@ -791,7 +817,7 @@ public class SoundManager
|
|||||||
protected boolean _valid = true;
|
protected boolean _valid = true;
|
||||||
|
|
||||||
/** The list of all the currently instantiated spoolers. */
|
/** The list of all the currently instantiated spoolers. */
|
||||||
protected static ArrayList _available = new ArrayList();
|
protected static ArrayList _openSpoolers = new ArrayList();
|
||||||
|
|
||||||
/** The maximum time a spooler will wait for a stream before
|
/** The maximum time a spooler will wait for a stream before
|
||||||
* deciding to shut down. */
|
* deciding to shut down. */
|
||||||
|
|||||||
Reference in New Issue
Block a user