PDA

View Full Version : QMediaPlayer - QThread::start: Failed to create thread



junior-root
16th February 2017, 14:56
I develop an application which the user can play multiple sounds at the same time. For this I use QMediaPlayer in conjunction with a matrix to hold each sound separately. The code is simple, for each sound I use a code like this:


media = new QMediaPlayer();
media->setMedia(QUrl::fromLocalFile(QFileInfo("sound.mp3").absoluteFilePath()));
media->play();

Everything is ok. But around playing the sound 115-125 (simultaneous sounds), the new sounds emit signal error(QMediaPlayer::ResourceError) with error code: QMediaPlayer::ResourceError - A media resource couldn't be resolved. Before emit error signal, it print on output this message: DirectShowPlayerService::doPlay: Unresolved error code 0x80004005 ()

This is not a problem, because I delete those sounds as soon as I detect this error. The problem appears right after a couple of QMediaPlayer::ResourceError. If I create a new sound, an error message appear on output window: QThread::start: Failed to create thread. This error appear just after creating a new QMediaPlayer instance:


qDebug() << "before media = new QMediaPlayer(); (FILE)";
media = new QMediaPlayer();
qDebug() << "after media = new QMediaPlayer(); (FILE)" << media->error

The output:


before media = new QMediaPlayer(); (FILE)
QThread::start: Failed to create thread
after media = new QMediaPlayer(); (FILE) QMediaPlayer::NoError

This last kind of QMediaPlayer instance emit no error. More than that, the state is QMediaPlayer::PlayingState. But if I try to delete it - delete(media) - or to set the media to a null QMediaContent - media->setMedia(QMediaContent()) - to make the player to discard all information relating to the current media source, the application freezes. Those two opperations works fine on he others sounds. If I don't delete this kind of QMediaPlayer, I end to have no room for sounds. Somehow QMediaPlayer has a limited number of instances and every QMediaPlayer that I cannot delete anymore fill this number and let no room for new instances of QMediaPlayer.

The question is: how I can avoid this issue? If I limit the number of simultaneous sounds, what is the correct number of QMediaPlayer instances? If I set a limit, this limit can be too high for other machines. Or how to properly detect this malformed QMediaPlayer and properly delete it?

Also, if I wait for the first QMediaPlayer::ResourceError signal to limit the number of sounds, this is sometimes too late, because the error signal is emitted a bit later and sometimes the application already create a malformed QMediaPlayer that I cannot delete anymore and this prevent the process to close.

d_stranz
16th February 2017, 18:40
Unresolved error code 0x80004005 ... This is not a problem

This error code is due to some failure in a Microsoft COM module, probably DirectShow. Ignoring it probably results in all of the rest of your errors because the service is in an error state. By trying to play so many simultaneous sounds, you have probably reached some resource limit in the DirectShow server.

junior-root
16th February 2017, 19:23
This error code is due to some failure in a Microsoft COM module, probably DirectShow. Ignoring it probably results in all of the rest of your errors because the service is in an error state. By trying to play so many simultaneous sounds, you have probably reached some resource limit in the DirectShow server.

Thanks for the reply.
When I create a new sound using QMediaPlayer() I am not ignoring this error. Like I say before, I delete this new sound because it emit error signal also. My plan was to use this signal to detect maximum number of sounds, but unfortunately this signal is emitted some times too late: user already request a new sound which can not be deleted.

anda_skoa
17th February 2017, 09:54
When you are reaching the limitations of the underlying system, it is sometimes necessary to deal with that limitation on a lower level.

E.g. by using the system framework directly or by using a different low level framework such as GStreamer.

Cheers,
_