[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [51599] trunk/blender/intern/audaspace: Audaspace:

Joerg Mueller nexyon at gmail.com
Wed Oct 24 23:33:47 CEST 2012


Revision: 51599
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=51599
Author:   nexyon
Date:     2012-10-24 21:33:44 +0000 (Wed, 24 Oct 2012)
Log Message:
-----------
Audaspace:

RAII locking implementation. This should fix bug [#32096] Background music stops when playing 3D sounds.

Modified Paths:
--------------
    trunk/blender/intern/audaspace/CMakeLists.txt
    trunk/blender/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp
    trunk/blender/intern/audaspace/intern/AUD_AnimateableProperty.cpp
    trunk/blender/intern/audaspace/intern/AUD_AnimateableProperty.h
    trunk/blender/intern/audaspace/intern/AUD_C-API.cpp
    trunk/blender/intern/audaspace/intern/AUD_IDevice.h
    trunk/blender/intern/audaspace/intern/AUD_SequencerEntry.cpp
    trunk/blender/intern/audaspace/intern/AUD_SequencerEntry.h
    trunk/blender/intern/audaspace/intern/AUD_SequencerFactory.cpp
    trunk/blender/intern/audaspace/intern/AUD_SequencerFactory.h
    trunk/blender/intern/audaspace/intern/AUD_SequencerHandle.cpp
    trunk/blender/intern/audaspace/intern/AUD_SequencerReader.cpp
    trunk/blender/intern/audaspace/intern/AUD_SoftwareDevice.cpp

Added Paths:
-----------
    trunk/blender/intern/audaspace/intern/AUD_ILockable.h
    trunk/blender/intern/audaspace/intern/AUD_MutexLock.h

Modified: trunk/blender/intern/audaspace/CMakeLists.txt
===================================================================
--- trunk/blender/intern/audaspace/CMakeLists.txt	2012-10-24 21:05:44 UTC (rev 51598)
+++ trunk/blender/intern/audaspace/CMakeLists.txt	2012-10-24 21:33:44 UTC (rev 51599)
@@ -94,6 +94,7 @@
 	intern/AUD_IDevice.h
 	intern/AUD_IFactory.h
 	intern/AUD_IHandle.h
+	intern/AUD_ILockable.h
 	intern/AUD_IReader.h
 	intern/AUD_IWriter.h
 	intern/AUD_JOSResampleFactory.cpp
@@ -108,6 +109,7 @@
 	intern/AUD_Mixer.h
 	intern/AUD_MixerFactory.cpp
 	intern/AUD_MixerFactory.h
+	intern/AUD_MutexLock.h
 	intern/AUD_NULLDevice.cpp
 	intern/AUD_NULLDevice.h
 	intern/AUD_PyInit.h

Modified: trunk/blender/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp
===================================================================
--- trunk/blender/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp	2012-10-24 21:05:44 UTC (rev 51598)
+++ trunk/blender/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp	2012-10-24 21:33:44 UTC (rev 51599)
@@ -31,6 +31,7 @@
 #include "AUD_IFactory.h"
 #include "AUD_IReader.h"
 #include "AUD_ConverterReader.h"
+#include "AUD_MutexLock.h"
 
 #include <cstring>
 #include <limits>
@@ -125,7 +126,7 @@
 {
 	if(m_status)
 	{
-		m_device->lock();
+		AUD_MutexLock lock(*m_device);
 
 		if(m_status == AUD_STATUS_PLAYING)
 		{
@@ -135,12 +136,9 @@
 			alSourcePause(m_source);
 
 			m_status = AUD_STATUS_PAUSED;
-			m_device->unlock();
 
 			return true;
 		}
-
-		m_device->unlock();
 	}
 
 	return false;
@@ -150,7 +148,7 @@
 {
 	if(m_status)
 	{
-		m_device->lock();
+		AUD_MutexLock lock(*m_device);
 
 		if(m_status == AUD_STATUS_PAUSED)
 		{
@@ -159,11 +157,8 @@
 
 			m_device->start();
 			m_status = AUD_STATUS_PLAYING;
-			m_device->unlock();
 			return true;
 		}
-
-		m_device->unlock();
 	}
 
 	return false;
@@ -171,11 +166,11 @@
 
 bool AUD_OpenALDevice::AUD_OpenALHandle::stop()
 {
+	AUD_MutexLock lock(*m_device);
+
 	if(!m_status)
 		return false;
 
-	m_device->lock();
-
 	// AUD_XXX Create a reference of our own object so that it doesn't get
 	// deleted before the end of this function
 	AUD_Reference<AUD_OpenALHandle> This = this;
@@ -185,8 +180,6 @@
 	else
 		m_device->m_pausedSounds.remove(This);
 
-	m_device->unlock();
-
 	alDeleteSources(1, &m_source);
 	if(!m_isBuffered)
 		alDeleteBuffers(CYCLE_BUFFERS, m_buffers);
@@ -205,25 +198,23 @@
 
 bool AUD_OpenALDevice::AUD_OpenALHandle::setKeep(bool keep)
 {
+	AUD_MutexLock lock(*m_device);
+
 	if(!m_status)
 		return false;
 
-	m_device->lock();
-
 	m_keep = keep;
 
-	m_device->unlock();
-
 	return true;
 }
 
 bool AUD_OpenALDevice::AUD_OpenALHandle::seek(float position)
 {
+	AUD_MutexLock lock(*m_device);
+
 	if(!m_status)
 		return false;
 
-	m_device->lock();
-
 	if(m_isBuffered)
 		alSourcef(m_source, AL_SEC_OFFSET, position);
 	else
@@ -272,18 +263,16 @@
 		}
 	}
 
-	m_device->unlock();
-
 	return true;
 }
 
 float AUD_OpenALDevice::AUD_OpenALHandle::getPosition()
 {
+	AUD_MutexLock lock(*m_device);
+
 	if(!m_status)
 		return 0.0f;
 
-	m_device->lock();
-
 	float position = 0.0f;
 
 	alGetSourcef(m_source, AL_SEC_OFFSET, &position);
@@ -295,8 +284,6 @@
 					 CYCLE_BUFFERS) / (float)specs.rate;
 	}
 
-	m_device->unlock();
-
 	return position;
 }
 
@@ -309,29 +296,25 @@
 {
 	float result = std::numeric_limits<float>::quiet_NaN();
 
+	AUD_MutexLock lock(*m_device);
+
 	if(!m_status)
 		return result;
 
-	m_device->lock();
-
 	alGetSourcef(m_source, AL_GAIN, &result);
 
-	m_device->unlock();
-
 	return result;
 }
 
 bool AUD_OpenALDevice::AUD_OpenALHandle::setVolume(float volume)
 {
+	AUD_MutexLock lock(*m_device);
+
 	if(!m_status)
 		return false;
 
-	m_device->lock();
-
 	alSourcef(m_source, AL_GAIN, volume);
 
-	m_device->unlock();
-
 	return true;
 }
 
@@ -339,29 +322,25 @@
 {
 	float result = std::numeric_limits<float>::quiet_NaN();
 
+	AUD_MutexLock lock(*m_device);
+
 	if(!m_status)
 		return result;
 
-	m_device->lock();
-
 	alGetSourcef(m_source, AL_PITCH, &result);
 
-	m_device->unlock();
-
 	return result;
 }
 
 bool AUD_OpenALDevice::AUD_OpenALHandle::setPitch(float pitch)
 {
+	AUD_MutexLock lock(*m_device);
+
 	if(!m_status)
 		return false;
 
-	m_device->lock();
-
 	alSourcef(m_source, AL_PITCH, pitch);
 
-	m_device->unlock();
-
 	return true;
 }
 
@@ -382,16 +361,14 @@
 
 bool AUD_OpenALDevice::AUD_OpenALHandle::setStopCallback(stopCallback callback, void* data)
 {
+	AUD_MutexLock lock(*m_device);
+
 	if(!m_status)
 		return false;
 
-	m_device->lock();
-
 	m_stop = callback;
 	m_stop_data = data;
 
-	m_device->unlock();
-
 	return true;
 }
 
@@ -403,16 +380,14 @@
 {
 	AUD_Vector3 result = AUD_Vector3(0, 0, 0);
 
+	AUD_MutexLock lock(*m_device);
+
 	if(!m_status)
 		return result;
 
-	m_device->lock();
-
 	ALfloat p[3];
 	alGetSourcefv(m_source, AL_POSITION, p);
 
-	m_device->unlock();
-
 	result = AUD_Vector3(p[0], p[1], p[2]);
 
 	return result;
@@ -420,15 +395,13 @@
 
 bool AUD_OpenALDevice::AUD_OpenALHandle::setSourceLocation(const AUD_Vector3& location)
 {
+	AUD_MutexLock lock(*m_device);
+
 	if(!m_status)
 		return false;
 
-	m_device->lock();
-
 	alSourcefv(m_source, AL_POSITION, (ALfloat*)location.get());
 
-	m_device->unlock();
-
 	return true;
 }
 
@@ -436,16 +409,14 @@
 {
 	AUD_Vector3 result = AUD_Vector3(0, 0, 0);
 
+	AUD_MutexLock lock(*m_device);
+
 	if(!m_status)
 		return result;
 
-	m_device->lock();
-
 	ALfloat v[3];
 	alGetSourcefv(m_source, AL_VELOCITY, v);
 
-	m_device->unlock();
-
 	result = AUD_Vector3(v[0], v[1], v[2]);
 
 	return result;
@@ -453,15 +424,13 @@
 
 bool AUD_OpenALDevice::AUD_OpenALHandle::setSourceVelocity(const AUD_Vector3& velocity)
 {
+	AUD_MutexLock lock(*m_device);
+
 	if(!m_status)
 		return false;
 
-	m_device->lock();
-
 	alSourcefv(m_source, AL_VELOCITY, (ALfloat*)velocity.get());
 
-	m_device->unlock();
-
 	return true;
 }
 
@@ -472,9 +441,6 @@
 
 bool AUD_OpenALDevice::AUD_OpenALHandle::setSourceOrientation(const AUD_Quaternion& orientation)
 {
-	if(!m_status)
-		return false;
-
 	ALfloat direction[3];
 	direction[0] = -2 * (orientation.w() * orientation.y() +
 						 orientation.x() * orientation.z());
@@ -482,12 +448,14 @@
 						orientation.z() * orientation.y());
 	direction[2] = 2 * (orientation.x() * orientation.x() +
 						orientation.y() * orientation.y()) - 1;
-	m_device->lock();
 
-	alSourcefv(m_source, AL_DIRECTION, direction);
+	AUD_MutexLock lock(*m_device);
 
-	m_device->unlock();
+	if(!m_status)
+		return false;
 
+	alSourcefv(m_source, AL_DIRECTION, direction);
+
 	m_orientation = orientation;
 
 	return true;
@@ -497,29 +465,25 @@
 {
 	int result;
 
+	AUD_MutexLock lock(*m_device);
+
 	if(!m_status)
 		return false;
 
-	m_device->lock();
-
 	alGetSourcei(m_source, AL_SOURCE_RELATIVE, &result);
 
-	m_device->unlock();
-
 	return result;
 }
 
 bool AUD_OpenALDevice::AUD_OpenALHandle::setRelative(bool relative)
 {
+	AUD_MutexLock lock(*m_device);
+
 	if(!m_status)
 		return false;
 
-	m_device->lock();
-
 	alSourcei(m_source, AL_SOURCE_RELATIVE, relative);
 
-	m_device->unlock();
-
 	return true;
 }
 
@@ -527,29 +491,25 @@
 {
 	float result = std::numeric_limits<float>::quiet_NaN();
 
+	AUD_MutexLock lock(*m_device);
+
 	if(!m_status)
 		return result;
 
-	m_device->lock();
-
 	alGetSourcef(m_source, AL_MAX_GAIN, &result);
 
-	m_device->unlock();
-
 	return result;
 }
 
 bool AUD_OpenALDevice::AUD_OpenALHandle::setVolumeMaximum(float volume)
 {
+	AUD_MutexLock lock(*m_device);
+
 	if(!m_status)
 		return false;
 
-	m_device->lock();
-
 	alSourcef(m_source, AL_MAX_GAIN, volume);
 
-	m_device->unlock();
-
 	return true;
 }
 
@@ -557,29 +517,25 @@
 {
 	float result = std::numeric_limits<float>::quiet_NaN();
 
+	AUD_MutexLock lock(*m_device);
+
 	if(!m_status)
 		return result;
 
-	m_device->lock();
-
 	alGetSourcef(m_source, AL_MIN_GAIN, &result);
 
-	m_device->unlock();
-
 	return result;
 }
 
 bool AUD_OpenALDevice::AUD_OpenALHandle::setVolumeMinimum(float volume)
 {
+	AUD_MutexLock lock(*m_device);
+
 	if(!m_status)
 		return false;
 
-	m_device->lock();
-
 	alSourcef(m_source, AL_MIN_GAIN, volume);
 
-	m_device->unlock();
-
 	return true;
 }
 
@@ -587,29 +543,25 @@
 {
 	float result = std::numeric_limits<float>::quiet_NaN();
 
+	AUD_MutexLock lock(*m_device);
+
 	if(!m_status)
 		return result;
 
-	m_device->lock();
-
 	alGetSourcef(m_source, AL_MAX_DISTANCE, &result);
 
-	m_device->unlock();
-
 	return result;
 }
 
 bool AUD_OpenALDevice::AUD_OpenALHandle::setDistanceMaximum(float distance)
 {
+	AUD_MutexLock lock(*m_device);
+
 	if(!m_status)
 		return false;
 
-	m_device->lock();
-
 	alSourcef(m_source, AL_MAX_DISTANCE, distance);
 
-	m_device->unlock();
-
 	return true;
 }
 
@@ -617,29 +569,25 @@
 {
 	float result = std::numeric_limits<float>::quiet_NaN();
 
+	AUD_MutexLock lock(*m_device);
+
 	if(!m_status)
 		return result;
 
-	m_device->lock();
-
 	alGetSourcef(m_source, AL_REFERENCE_DISTANCE, &result);
 
-	m_device->unlock();
-
 	return result;
 }
 
 bool AUD_OpenALDevice::AUD_OpenALHandle::setDistanceReference(float distance)
 {
+	AUD_MutexLock lock(*m_device);
+
 	if(!m_status)
 		return false;
 
-	m_device->lock();
-
 	alSourcef(m_source, AL_REFERENCE_DISTANCE, distance);
 
-	m_device->unlock();
-
 	return true;
 }
 
@@ -647,29 +595,25 @@
 {
 	float result = std::numeric_limits<float>::quiet_NaN();
 
+	AUD_MutexLock lock(*m_device);
+
 	if(!m_status)
 		return result;
 
-	m_device->lock();
-
 	alGetSourcef(m_source, AL_ROLLOFF_FACTOR, &result);
 
-	m_device->unlock();
-
 	return result;
 }
 
 bool AUD_OpenALDevice::AUD_OpenALHandle::setAttenuation(float factor)
 {
+	AUD_MutexLock lock(*m_device);
+
 	if(!m_status)
 		return false;
 
-	m_device->lock();
-
 	alSourcef(m_source, AL_ROLLOFF_FACTOR, factor);
 
-	m_device->unlock();
-
 	return true;
 }
 
@@ -677,29 +621,25 @@
 {
 	float result = std::numeric_limits<float>::quiet_NaN();
 
+	AUD_MutexLock lock(*m_device);
+
 	if(!m_status)
 		return result;
 
-	m_device->lock();
-
 	alGetSourcef(m_source, AL_CONE_OUTER_ANGLE, &result);
 
-	m_device->unlock();
-
 	return result;
 }
 
 bool AUD_OpenALDevice::AUD_OpenALHandle::setConeAngleOuter(float angle)
 {
+	AUD_MutexLock lock(*m_device);
+
 	if(!m_status)
 		return false;
 
-	m_device->lock();
-
 	alSourcef(m_source, AL_CONE_OUTER_ANGLE, angle);
 
-	m_device->unlock();
-
 	return true;
 }
 
@@ -707,29 +647,25 @@
 {
 	float result = std::numeric_limits<float>::quiet_NaN();
 
+	AUD_MutexLock lock(*m_device);
+
 	if(!m_status)
 		return result;
 
-	m_device->lock();
-
 	alGetSourcef(m_source, AL_CONE_INNER_ANGLE, &result);
 
-	m_device->unlock();
-
 	return result;
 }
 
 bool AUD_OpenALDevice::AUD_OpenALHandle::setConeAngleInner(float angle)
 {
+	AUD_MutexLock lock(*m_device);
+
 	if(!m_status)
 		return false;
 
-	m_device->lock();
-
 	alSourcef(m_source, AL_CONE_INNER_ANGLE, angle);
 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list