Source Code (Use browser search to find items of interest.)
Class Index
kdelibs'SimpleSoundServer_impl (./kdelibs/arts/soundserver/simplesoundserver_impl.h:44)
class SimpleSoundServer_impl : virtual public SimpleSoundServer_skel,
public TimeNotify
{
protected:
Synth_PLAY playSound;
Synth_MULTI_ADD addLeft, addRight;
std::list<Synth_PLAY_WAV> activeWavs;
std::list<ByteStreamToAudio> activeConverters;
std::list<AttachedProducer *> activeProducers;
StereoEffectStack _outstack;
long asCount;
public:
SimpleSoundServer_impl();
~SimpleSoundServer_impl();
void notifyTime();
// streaming audio
void attach(ByteSoundProducer bsp);
void detach(ByteSoundProducer bsp);
// simple soundserver interface
long play(const std::string& s);
// kmedia2
PlayObject createPlayObject(const std::string& filename);
StereoEffectStack outstack();
Object createObject(const std::string& name);
};
kdelibs'SimpleSoundServer_impl::SimpleSoundServer_impl() (./kdelibs/arts/soundserver/simplesoundserver_impl.cc:68)
SimpleSoundServer_impl::SimpleSoundServer_impl()
{
_outstack.setInputs(addLeft,"outvalue",addRight,"outvalue");
_outstack.setOutputs(playSound,"invalue_left",playSound,"invalue_right");
addLeft.start();
addRight.start();
playSound.start();
asCount = 0; // AutoSuspend
Dispatcher::the()->ioManager()->addTimer(200,this);
}
kdelibs'SimpleSoundServer_impl::~SimpleSoundServer_impl() (./kdelibs/arts/soundserver/simplesoundserver_impl.cc:81)
SimpleSoundServer_impl::~SimpleSoundServer_impl()
{
/*
* we don't need to care about the flow system nodes we started, since
* we have put them into Object_var's, which means that they will be
* freed automatically here
*/
Dispatcher::the()->ioManager()->removeTimer(this);
}
kdelibs'SimpleSoundServer_impl::play() (./kdelibs/arts/soundserver/simplesoundserver_impl.cc:91)
long SimpleSoundServer_impl::play(const string& filename)
{
printf("Play '%s'!\n",filename.c_str());
Synth_PLAY_WAV playwav;
connect(playwav,"left",addLeft);
connect(playwav,"right",addRight);
playwav.filename(filename);
playwav.start();
activeWavs.push_back(playwav);
return 1;
}
kdelibs'SimpleSoundServer_impl::attach() (./kdelibs/arts/soundserver/simplesoundserver_impl.cc:107)
void SimpleSoundServer_impl::attach(ByteSoundProducer bsp)
{
printf("Attach ByteSoundProducer!\n");
ByteStreamToAudio convert;
// convert->samplingRate(bsp->samplingRate());
// convert->channels(bsp->channels());
// convert->bits(bsp->bits());
connect(bsp,"outdata",convert,"indata");
connect(convert,"left",addLeft);
connect(convert,"right",addRight);
convert.start();
activeProducers.push_back(new AttachedProducer(bsp,convert));
}
kdelibs'SimpleSoundServer_impl::detach() (./kdelibs/arts/soundserver/simplesoundserver_impl.cc:126)
void SimpleSoundServer_impl::detach(ByteSoundProducer bsp)
{
printf("Detach ByteSoundProducer!\n");
list<AttachedProducer *>::iterator p;
for(p = activeProducers.begin();p != activeProducers.end();p++)
{
AttachedProducer *prod = (*p);
ByteSoundProducer sender = prod->sender();
if(bsp._isEqual(sender))
{
/*
* Hint: the order of the next lines is not unimportant:
*
* delete prod involves _release()ing remote objects,
* and while this is happening, other producers could
* attach/detach and we could end up doing something wrong
*/
activeProducers.erase(p);
activeConverters.push_back(prod->receiver());
delete prod;
return;
}
}
assert(false); // you shouldn't detach things you never attached!
}
kdelibs'SimpleSoundServer_impl::outstack() (./kdelibs/arts/soundserver/simplesoundserver_impl.cc:155)
StereoEffectStack SimpleSoundServer_impl::outstack()
{
return _outstack;
}
kdelibs'SimpleSoundServer_impl::createObject() (./kdelibs/arts/soundserver/simplesoundserver_impl.cc:160)
Object SimpleSoundServer_impl::createObject(const string& name)
{
return Object(SubClass(name));
}
kdelibs'SimpleSoundServer_impl::notifyTime() (./kdelibs/arts/soundserver/simplesoundserver_impl.cc:165)
void SimpleSoundServer_impl::notifyTime()
{
static long lock = 0;
assert(!lock); // paranoid reentrancy check (remove me later)
lock++;
/*
* Three times the same game: look if a certain object is still
* active - if yes, keep, if no, remove
*/
/* look for WAVs which may have terminated by now */
list<Synth_PLAY_WAV>::iterator i;
i = activeWavs.begin();
while(i != activeWavs.end())
{
if(i->finished())
{
activeWavs.erase(i);
cout << "finished" << endl;
i = activeWavs.begin();
}
else i++;
}
/* look for producers which servers have died */
list<AttachedProducer *>::iterator p;
p = activeProducers.begin();
while(p != activeProducers.end())
{
AttachedProducer *prod = (*p);
if(prod->sender().error())
{
activeProducers.erase(p);
cout << "stream closed (client died)" << endl;
activeConverters.push_back(prod->receiver());
delete prod;
p = activeProducers.begin();
}
else p++;
}
/* look for converters which are no longer running */
list<ByteStreamToAudio>::iterator ci;
ci = activeConverters.begin();
while(ci != activeConverters.end())
{
if(!ci->running())
{
activeConverters.erase(ci);
cout << "converter (for stream) finished" << endl;
ci = activeConverters.begin();
}
else ci++;
}
/*
* AutoSuspend
*/
if(Dispatcher::the()->flowSystem()->suspendable() &&
!Dispatcher::the()->flowSystem()->suspended())
{
asCount++;
if(asCount > 300)
{
Dispatcher::the()->flowSystem()->suspend();
cout << "[artsd] suspend" << endl;
}
}
else
asCount = 0;
lock--;
}
kdelibs'SimpleSoundServer_impl::createPlayObject() (./kdelibs/arts/soundserver/simplesoundserver_impl.cc:242)
PlayObject SimpleSoundServer_impl::createPlayObject(const string& filename)
{
string extension="", objectType = "";
if(filename.size()>4)
{
extension = filename.substr(filename.size()-4);
for(int i=1;i<4;i++) extension[i] = toupper(extension[i]);
cout << "extension = " << extension << endl;
}
if(extension == ".WAV") objectType = "WavPlayObject";
/* TODO: write a service which can find out which object decodes what
else if(extension == ".MP3") objectType = "MP3PlayObject";
else if(extension == ".MPG") objectType = "MP3PlayObject";
*/
if(objectType != "")
{
cout << "Creating " << objectType << " to play file." << endl;
PlayObject result = SubClass(objectType);
if(result.loadMedia(filename))
{
// TODO: check for existence of left & right streams
connect(result,"left",addLeft);
connect(result,"right",addRight);
result._node()->start();
return result;
}
else
{
cout << "loadmedia failed." << endl;
}
}
else
{
cout << "can't play this" << endl;
}
return 0;
}