Hi,

I have two problems with using Phonon on Windows XP with Direct Sound 9 backend.
I'm using Qt version 4.4.1 that I compiled on my own machine using Visual Studio 2005 SP1. The phonon framework compiled alright and has DS9 backend (DirectX SDK: February 2007).

First problem (and most important):

Whenever I play a sound file (PCM or MP3, doesn't matter) using Phonon, the sound is played successfully, but a thread remains open even after the MediaObject is deleted. This happens every single time a sound is played. I want to be able to play multiple sounds at once, so I create a new path (using a new MediaObject) for each sound file I play. Analyzing the application threads (using ProcessExplorer, or the Visual Studio threads window) I get the following after playing 10 times a sound.

RPCRT4.dll!I_RpcBCacheFree+0x5ea
RPCRT4.dll!I_RpcBCacheFree+0x5ea
PhononMixingTest.exe!WinMainCRTStartup
quartz.dll!CCallbackThread::ThreadProc() + 0xeb bytes
quartz.dll!CCallbackThread::ThreadProc() + 0xeb bytes
quartz.dll!CCallbackThread::ThreadProc() + 0xeb bytes
quartz.dll!CCallbackThread::ThreadProc() + 0xeb bytes
quartz.dll!CCallbackThread::ThreadProc() + 0xeb bytes
quartz.dll!CCallbackThread::ThreadProc() + 0xeb bytes
quartz.dll!CCallbackThread::ThreadProc() + 0xeb bytes
quartz.dll!CCallbackThread::ThreadProc() + 0xeb bytes
quartz.dll!CCallbackThread::ThreadProc() + 0xeb bytes
quartz.dll!CCallbackThread::ThreadProc() + 0xeb bytes
quartz.dll!CCallbackThread::ThreadProc() + 0xeb bytes
ADVAPI32.dll!RegDeleteKeyW+0xfd

The first time I play a sound it leaves 2 hanging threads, after that only 1 for each time a sound is played. In CCallbackThread::ThreadProc() it hangs on a call to WaitForMultipleObjects.

Here is the code that plays the sound file:

Qt Code:
  1. void PhononMixingTest::PlayClicked()
  2. {
  3. QString soundFilePath = ui.fileLineEdit_->text();
  4. if (soundFilePath.isEmpty())
  5. {
  6. return;
  7. }
  8.  
  9. Phonon::AudioOutput* audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this);
  10. Phonon::MediaObject* mediaObject = new Phonon::MediaObject(this);
  11. Phonon::createPath(mediaObject, audioOutput);
  12. connect (mediaObject, SIGNAL(finished()), this, SLOT(SoundFinishedPlaying()));
  13. mediaObject->setCurrentSource(soundFilePath);
  14. mediaObject->play();
  15. }
  16.  
  17. void PhononMixingTest::SoundFinishedPlaying()
  18. {
  19. Phonon::MediaObject* mediaObject = qobject_cast<Phonon::MediaObject*>(sender());
  20. if (mediaObject)
  21. {
  22. mediaObject->stop();
  23. mediaObject->clearQueue();
  24. mediaObject->deleteLater();
  25. }
  26. }
To copy to clipboard, switch view to plain text mode 

I do not know if I'm doing this the right way, because I don't fully understand who is responsible for the ownership of the MediaObject and the AudioOutput. By the way, the threads remain open even after the parent of the MediaObject and AudioOutput is deleted.

Second problem:

Sometimes when playing multiple sounds at once in debug mode, I get the following assert failure:
ASSERT: "!isEmpty()" in file ../../src/corelib/tools/qlist.h, line 230

The call stack is given below:

> QtCored4.dll!qt_message_output(QtMsgType msgType=QtFatalMsg, const char * buf=0x02d1dc40) Line 2035 C++
QtCored4.dll!qFatal(const char * msg=0x67234b2c, ...) Line 2241 + 0xe bytes C++
QtCored4.dll!qt_assert(const char * assertion=0x010b257c, const char * file=0x010b1e78, int line=230) Line 1809 + 0x16 bytes C++
phonon_ds9d4.dll!QList<Phonon::DS9::WorkerThread:: Work>::first() Line 230 + 0x2d bytes C++
phonon_ds9d4.dll!QList<Phonon::DS9::WorkerThread:: Work>::takeFirst() Line 392 + 0x2d bytes C++
phonon_ds9d4.dll!QQueue<Phonon::DS9::WorkerThread: :Work>::dequeue() Line 40 + 0x1c bytes C++
phonon_ds9d4.dll!Phonon::DS9::WorkerThread::dequeu eWork() Line 56 + 0xf bytes C++
phonon_ds9d4.dll!Phonon::DS9::WorkerThread::handle Task() Line 184 + 0xf bytes C++
phonon_ds9d4.dll!Phonon::DS9::WorkerThread::run() Line 79 C++
QtCored4.dll!QThreadPrivate::start(void * arg=0x00b4b5a8) Line 235 C++
msvcr80d.dll!__beginthreadex() + 0x221 bytes
msvcr80d.dll!__beginthreadex() + 0x1c7 bytes
kernel32.dll!_BaseThreadStart@8() + 0x37 bytes

It seems to be some kind of synchronization problem for accessing the phonon work queue.

Maybe I'm using the Phonon framework the wrong way. So if you have any ideea about what I'm doing wrong or what should I try to fix these problems, I would much appreciate your help. Thank you.