Skip to content

Fixes Windows 7 crashes when destroying DirectSound. #985

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/QtAV/private/AudioOutputBackend.h
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ class Q_AV_PRIVATE_EXPORT AudioOutputBackend : public QObject
Q_OBJECT
public:
AudioOutput *audio;
bool available; // default is true. set to false when failed to create backend
volatile bool available; // default is true. set to false when failed to create backend
int buffer_size;
int buffer_count;
AudioFormat format;
16 changes: 11 additions & 5 deletions src/output/audio/AudioOutputDSound.cpp
Original file line number Diff line number Diff line change
@@ -26,6 +26,7 @@
#include <QtCore/QLibrary>
#include <QtCore/QSemaphore>
#include <QtCore/QThread>
#include <QtCore/QPointer>
#include <math.h>
#define DIRECTSOUND_VERSION 0x0600
#include <dsound.h>
@@ -58,7 +59,13 @@ class AudioOutputDSound Q_DECL_FINAL: public AudioOutputBackend
bool unloadDll();
bool init();
bool destroy() {
SafeRelease(&notify);
if (notify_event) {
SetEvent(notify_event);
SafeRelease(&notify);
watcher.wait();
CloseHandle( notify_event ); // FIXME: is it ok if thread is still waiting?
notify_event = NULL;
}
SafeRelease(&prim_buf);
SafeRelease(&stream_buf);
SafeRelease(&dsound);
@@ -77,18 +84,18 @@ class AudioOutputDSound Q_DECL_FINAL: public AudioOutputBackend
int write_offset; ///offset of the write cursor in the direct sound buffer
QAtomicInt buffers_free;
class PositionWatcher : public QThread {
AudioOutputDSound *ao;
QPointer<AudioOutputDSound> ao;
public:
PositionWatcher(AudioOutputDSound* dsound) : ao(dsound) {}
void run() Q_DECL_OVERRIDE {
DWORD dwResult = 0;
while (ao->available) {
while (ao && ao->available) {
dwResult = WaitForSingleObjectEx(ao->notify_event, 2000, FALSE);
if (dwResult != WAIT_OBJECT_0) {
//qWarning("WaitForSingleObjectEx for ao->notify_event error: %#lx", dwResult);
continue;
}
ao->onCallback();
if (ao && ao->available) ao->onCallback();
}
}
};
@@ -192,7 +199,6 @@ bool AudioOutputDSound::close()
{
available = false;
destroy();
CloseHandle(notify_event); // FIXME: is it ok if thread is still waiting?
return true;
}