Refactored mutex use while closing streams in CPortAudioHandle (should fix #320)
This commit is contained in:
1 parent
41cf7a5ac2
commit
4784e57370
1 file changed
+7
-5
@@ -74,13 +74,15 @@ namespace Vocaluxe.Lib.Sound
|
|||||||
}
|
}
|
||||||
lock (_Mutex)
|
lock (_Mutex)
|
||||||
{
|
{
|
||||||
|
if (_Disposed)
|
||||||
|
return;
|
||||||
Debug.Assert(_RefCount > 0);
|
Debug.Assert(_RefCount > 0);
|
||||||
_RefCount--;
|
_RefCount--;
|
||||||
if (_RefCount == 0)
|
if (_RefCount == 0)
|
||||||
PortAudio.Pa_Terminate();
|
PortAudio.Pa_Terminate();
|
||||||
}
|
|
||||||
_Disposed = true;
|
_Disposed = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
@@ -99,12 +101,12 @@ namespace Vocaluxe.Lib.Sound
|
|||||||
public PortAudio.PaError OpenStream(out IntPtr stream, ref PortAudio.PaStreamParameters? inputParameters, ref PortAudio.PaStreamParameters? outputParameters,
|
public PortAudio.PaError OpenStream(out IntPtr stream, ref PortAudio.PaStreamParameters? inputParameters, ref PortAudio.PaStreamParameters? outputParameters,
|
||||||
double sampleRate, uint framesPerBuffer, PortAudio.PaStreamFlags streamFlags,
|
double sampleRate, uint framesPerBuffer, PortAudio.PaStreamFlags streamFlags,
|
||||||
PortAudio.PaStreamCallbackDelegate streamCallback, IntPtr userData)
|
PortAudio.PaStreamCallbackDelegate streamCallback, IntPtr userData)
|
||||||
|
{
|
||||||
|
lock (_Mutex)
|
||||||
{
|
{
|
||||||
if (_Disposed)
|
if (_Disposed)
|
||||||
throw new ObjectDisposedException("PortAudioHandle already disposed");
|
throw new ObjectDisposedException("PortAudioHandle already disposed");
|
||||||
|
|
||||||
lock (_Mutex)
|
|
||||||
{
|
|
||||||
PortAudio.PaError res = PortAudio.Pa_OpenStream(out stream, ref inputParameters, ref outputParameters, sampleRate, framesPerBuffer, streamFlags, streamCallback,
|
PortAudio.PaError res = PortAudio.Pa_OpenStream(out stream, ref inputParameters, ref outputParameters, sampleRate, framesPerBuffer, streamFlags, streamCallback,
|
||||||
userData);
|
userData);
|
||||||
if (res == PortAudio.PaError.paNoError)
|
if (res == PortAudio.PaError.paNoError)
|
||||||
@@ -156,12 +158,12 @@ namespace Vocaluxe.Lib.Sound
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void CloseStream(IntPtr stream)
|
public void CloseStream(IntPtr stream)
|
||||||
|
{
|
||||||
|
lock (_Mutex)
|
||||||
{
|
{
|
||||||
if (_Disposed)
|
if (_Disposed)
|
||||||
throw new ObjectDisposedException("PortAudioHandle already disposed");
|
throw new ObjectDisposedException("PortAudioHandle already disposed");
|
||||||
|
|
||||||
lock (_Mutex)
|
|
||||||
{
|
|
||||||
PortAudio.Pa_CloseStream(stream);
|
PortAudio.Pa_CloseStream(stream);
|
||||||
_Streams.Remove(stream);
|
_Streams.Remove(stream);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user