From 5a8d5f77af84d3f790d749dfd2d76a3b487eb06a Mon Sep 17 00:00:00 2001 From: Joerg Mueller Date: Mon, 5 Nov 2012 14:24:35 +0000 Subject: Audaspace: Replacing AUD_Reference with boost::shared_ptr. --- intern/audaspace/OpenAL/AUD_OpenALDevice.cpp | 63 ++++++++++++++++++---------- intern/audaspace/OpenAL/AUD_OpenALDevice.h | 14 +++---- 2 files changed, 47 insertions(+), 30 deletions(-) (limited to 'intern/audaspace/OpenAL') diff --git a/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp b/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp index a114d8b8a87..371e0007bd3 100644 --- a/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp +++ b/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp @@ -67,7 +67,7 @@ static const char* queue_error = "AUD_OpenALDevice: Buffer couldn't be " static const char* bufferdata_error = "AUD_OpenALDevice: Buffer couldn't be " "filled with data."; -AUD_OpenALDevice::AUD_OpenALHandle::AUD_OpenALHandle(AUD_OpenALDevice* device, ALenum format, AUD_Reference reader, bool keep) : +AUD_OpenALDevice::AUD_OpenALHandle::AUD_OpenALHandle(AUD_OpenALDevice* device, ALenum format, boost::shared_ptr reader, bool keep) : m_isBuffered(false), m_reader(reader), m_keep(keep), m_format(format), m_current(0), m_eos(false), m_loopcount(0), m_stop(NULL), m_stop_data(NULL), m_status(AUD_STATUS_PLAYING), m_device(device) @@ -130,14 +130,22 @@ bool AUD_OpenALDevice::AUD_OpenALHandle::pause() if(m_status == AUD_STATUS_PLAYING) { - m_device->m_playingSounds.remove(this); - m_device->m_pausedSounds.push_back(this); + for(AUD_HandleIterator it = m_device->m_playingSounds.begin(); it != m_device->m_playingSounds.end(); it++) + { + if(it->get() == this) + { + boost::shared_ptr This = *it; - alSourcePause(m_source); + m_device->m_playingSounds.erase(it); + m_device->m_pausedSounds.push_back(This); - m_status = AUD_STATUS_PAUSED; + alSourcePause(m_source); - return true; + m_status = AUD_STATUS_PAUSED; + + return true; + } + } } } @@ -152,12 +160,21 @@ bool AUD_OpenALDevice::AUD_OpenALHandle::resume() if(m_status == AUD_STATUS_PAUSED) { - m_device->m_pausedSounds.remove(this); - m_device->m_playingSounds.push_back(this); + for(AUD_HandleIterator it = m_device->m_pausedSounds.begin(); it != m_device->m_pausedSounds.end(); it++) + { + if(it->get() == this) + { + boost::shared_ptr This = *it; - m_device->start(); - m_status = AUD_STATUS_PLAYING; - return true; + m_device->m_pausedSounds.erase(it); + m_device->m_playingSounds.push_back(This); + + m_device->start(); + m_status = AUD_STATUS_PLAYING; + + return true; + } + } } } @@ -184,7 +201,7 @@ bool AUD_OpenALDevice::AUD_OpenALHandle::stop() { if(it->get() == this) { - AUD_Reference This = *it; + boost::shared_ptr This = *it; m_device->m_playingSounds.erase(it); @@ -838,15 +855,15 @@ void AUD_OpenALDevice::start(bool join) void AUD_OpenALDevice::updateStreams() { - AUD_Reference sound; + boost::shared_ptr sound; int length; ALint info; AUD_DeviceSpecs specs = m_specs; ALCenum cerr; - std::list > stopSounds; - std::list > pauseSounds; + std::list > stopSounds; + std::list > pauseSounds; AUD_HandleIterator it; while(1) @@ -1204,32 +1221,32 @@ bool AUD_OpenALDevice::getFormat(ALenum &format, AUD_Specs specs) return valid; } -AUD_Reference AUD_OpenALDevice::play(AUD_Reference reader, bool keep) +boost::shared_ptr AUD_OpenALDevice::play(boost::shared_ptr reader, bool keep) { AUD_Specs specs = reader->getSpecs(); // check format if(specs.channels == AUD_CHANNELS_INVALID) - return AUD_Reference(); + return boost::shared_ptr(); if(m_specs.format != AUD_FORMAT_FLOAT32) - reader = new AUD_ConverterReader(reader, m_specs); + reader = boost::shared_ptr(new AUD_ConverterReader(reader, m_specs)); ALenum format; if(!getFormat(format, specs)) - return AUD_Reference(); + return boost::shared_ptr(); AUD_MutexLock lock(*this); alcSuspendContext(m_context); - AUD_Reference sound; + boost::shared_ptr sound; try { // create the handle - sound = new AUD_OpenALDevice::AUD_OpenALHandle(this, format, reader, keep); + sound = boost::shared_ptr(new AUD_OpenALDevice::AUD_OpenALHandle(this, format, reader, keep)); } catch(AUD_Exception&) { @@ -1244,10 +1261,10 @@ AUD_Reference AUD_OpenALDevice::play(AUD_Reference rea start(); - return AUD_Reference(sound); + return boost::shared_ptr(sound); } -AUD_Reference AUD_OpenALDevice::play(AUD_Reference factory, bool keep) +boost::shared_ptr AUD_OpenALDevice::play(boost::shared_ptr factory, bool keep) { /* AUD_XXX disabled AUD_OpenALHandle* sound = NULL; diff --git a/intern/audaspace/OpenAL/AUD_OpenALDevice.h b/intern/audaspace/OpenAL/AUD_OpenALDevice.h index 0a409b42462..d2a4be227ba 100644 --- a/intern/audaspace/OpenAL/AUD_OpenALDevice.h +++ b/intern/audaspace/OpenAL/AUD_OpenALDevice.h @@ -58,7 +58,7 @@ private: bool m_isBuffered; /// The reader source. - AUD_Reference m_reader; + boost::shared_ptr m_reader; /// Whether to keep the source if end of it is reached. bool m_keep; @@ -105,7 +105,7 @@ private: * \param reader The reader this handle plays. * \param keep Whether to keep the handle alive when the reader ends. */ - AUD_OpenALHandle(AUD_OpenALDevice* device, ALenum format, AUD_Reference reader, bool keep); + AUD_OpenALHandle(AUD_OpenALDevice* device, ALenum format, boost::shared_ptr reader, bool keep); virtual ~AUD_OpenALHandle() {} virtual bool pause(); @@ -150,7 +150,7 @@ private: virtual bool setConeVolumeOuter(float volume); }; - typedef std::list >::iterator AUD_HandleIterator; + typedef std::list >::iterator AUD_HandleIterator; /** * The OpenAL device handle. @@ -175,12 +175,12 @@ private: /** * The list of sounds that are currently playing. */ - std::list > m_playingSounds; + std::list > m_playingSounds; /** * The list of sounds that are currently paused. */ - std::list > m_pausedSounds; + std::list > m_pausedSounds; /** * The list of buffered factories. @@ -255,8 +255,8 @@ public: virtual ~AUD_OpenALDevice(); virtual AUD_DeviceSpecs getSpecs() const; - virtual AUD_Reference play(AUD_Reference reader, bool keep = false); - virtual AUD_Reference play(AUD_Reference factory, bool keep = false); + virtual boost::shared_ptr play(boost::shared_ptr reader, bool keep = false); + virtual boost::shared_ptr play(boost::shared_ptr factory, bool keep = false); virtual void stopAll(); virtual void lock(); virtual void unlock(); -- cgit v1.2.3