Qt 4.8
Classes | Functions
qsound_win.cpp File Reference
#include "qsound.h"
#include "qapplication.h"
#include "qapplication_p.h"
#include <qfile.h>
#include "qpointer.h"
#include "qsound_p.h"
#include <qt_windows.h>
#include "qsound_win.moc"

Go to the source code of this file.

Classes

class  QAuServerWindows
 
struct  SoundInfo
 

Functions

QAuServerqt_new_audio_server ()
 
DWORD WINAPI SoundPlayProc (LPVOID param)
 

Function Documentation

◆ qt_new_audio_server()

QAuServer* qt_new_audio_server ( )

Definition at line 196 of file qsound_win.cpp.

197 {
198  return new QAuServerWindows(qApp);
199 }
#define qApp

◆ SoundPlayProc()

DWORD WINAPI SoundPlayProc ( LPVOID  param)

Definition at line 108 of file qsound_win.cpp.

Referenced by QAuServerWindows::playHelper().

109 {
110  SoundInfo *info = (SoundInfo*)param;
111 
112  // copy data before waking up GUI thread
113  QAuServerWindows *server = info->server;
114  QSound *sound = info->sound;
115  int loops = info->loops;
116  QString filename = info->filename;
117  HANDLE mutex = server->mutex;
118  HANDLE event = server->event;
119  info = 0;
120 
121  // server must not be destroyed until thread finishes
122  // and all other sounds have to wait
123  WaitForSingleObject(mutex, INFINITE);
124 
125  if (loops <= 1) {
126  server->current = 0;
127  int flags = SND_FILENAME|SND_ASYNC;
128  if (loops == -1)
129  flags |= SND_LOOP;
130 
131  PlaySound((wchar_t*)filename.utf16(), 0, flags);
132  if (sound && loops == 1)
133  server->decLoop(sound);
134 
135  // GUI thread continues, but we are done as well.
136  SetEvent(event);
137  } else {
138  // signal GUI thread to continue - sound might be reset!
139  QPointer<QSound> guarded_sound = sound;
140  SetEvent(event);
141 
142  for (int l = 0; l < loops && server->current; ++l) {
143  PlaySound((wchar_t*)filename.utf16(), 0, SND_FILENAME | SND_SYNC);
144 
145  if (guarded_sound)
146  server->decLoop(guarded_sound);
147  }
148  server->current = 0;
149  }
150  ReleaseMutex(mutex);
151 
152  return 0;
153 }
static mach_timebase_info_data_t info
EventRef event
QAuServerWindows * server
Definition: qsound_win.cpp:103
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QPointer class is a template class that provides guarded pointers to QObject. ...
Definition: qpointer.h:54
void * HANDLE
Definition: qnamespace.h:1671
QSound * sound
Definition: qsound_win.cpp:102
QString filename
Definition: qsound_win.cpp:104
static QAuServer & server()
Definition: qsound.cpp:79
QFactoryLoader * l
int decLoop(QSound *snd)
Definition: qsound_win.cpp:70
The QSound class provides access to the platform audio facilities.
Definition: qsound.h:57
const ushort * utf16() const
Returns the QString as a &#39;\0\&#39;-terminated array of unsigned shorts.
Definition: qstring.cpp:5290