PDA

View Full Version : Phonon on multiple threads



Savignon
20th February 2009, 23:21
Hi all,
yesterday i got multiple instances of phonon playing on the same main thread without problems, but if this happen on differents threads, its simply crash:

X Error: BadDrawable (invalid Pixmap or Window parameter) 9
Extension: 140 (Uknown extension)
Minor opcode: 9 (Unknown request)
Resource id: 0x3400590

What do i need to get it working properly?
protect X11 from concurrent rendering?

** Im using phonon-4.2 with gstreamer backend.

thanks in advance,
Rafael Savignon.

wysota
21st February 2009, 13:28
You can't access widgets (like the VideoWidget from Phonon) from non-main thread and there is no way around it currently. You have to do the playing in the main thread.

Savignon
25th February 2009, 17:57
I was taking a look at phonon backend implementation of gstreamer and it's seems to be using pixmap in some way to render video frames on to VideoWidget, and this could be the reason why this kind of problem is happening, maybe another backend could use diferent rendering mechanism to avoid this concurrence problem, like using non-platform dependent rendering resource, as same as we use QImage instead of QPixmap for rendering ?

thanks,
Rafael.

wysota
25th February 2009, 19:47
QImage doesn't use GUI resources, it's just a data object. With Phonon eventually you'll have to access gui resources which is a straight way to a crash when done from a worker thread. Why do you need to do use Phonon from another thread?

Savignon
4th March 2009, 02:54
My application has a "event thread" that creates several "media objects", which are phonon objects. Thus, they will be child of that "event thread" and not of the gui-thread.

I was wondering, if i move the phonon objects to gui-thread could solve my problem, calling:

phononObj->moveToThread(QApplication::instance()->thread());

catch the QEvent::ThreadChange , notifying QApplication Thread that its has a new QObject on its adress space, after that controll the moved phononObj trought signals/slots.

is it possible ?, if yes does exist any other way to bypass it ?
many thanks,
Rafael.

wysota
6th March 2009, 22:17
My application has a "event thread" that creates several "media objects", which are phonon objects. Thus, they will be child of that "event thread" and not of the gui-thread.
They will be handled by the thread you tell Qt to use.


I was wondering, if i move the phonon objects to gui-thread could solve my problem, calling:

phononObj->moveToThread(QApplication::instance()->thread());
Yes, you can. Just make sure the object doesn't have a parent and delete it when you don't need it to avoid a memory leak (or reparent it to an object from within the main thread).