Skip to content
Open
Show file tree
Hide file tree
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
Expand Up @@ -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;
Expand Down
16 changes: 11 additions & 5 deletions src/output/audio/AudioOutputDSound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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);
Expand All @@ -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();
}
}
};
Expand Down Expand Up @@ -192,7 +199,6 @@ bool AudioOutputDSound::close()
{
available = false;
destroy();
CloseHandle(notify_event); // FIXME: is it ok if thread is still waiting?
return true;
}

Expand Down