Unsolved Camera QML element and multiple QMediaService
-
Hello,
I have implemented my own QMediaService providing my own camera (a camera simulator). The service is implemented as a plugin very similarly as the Qt's directshow plugin. Now I want to display my camera in Camera item (QML). The QML is as follows:ApplicationWindow { visible: true width: 640 height: 480 Camera { id: camera } VideoOutput { anchors.fill: parent source: camera } ListView { anchors.fill: parent model: QtMultimedia.availableCameras delegate: Text { text: modelData.displayName MouseArea { anchors.fill: parent onClicked: camera.deviceId = modelData.deviceId } } } }
It's an example I found somewhere in the Qt Doc. It allows to switch between cameras connected to the PC and display their outputs (live image) on the screen. I have connected two cameras (the first is built-in camera and the second is and USB live cam). The application correctly displays three camera names: the two connected I mentioned and the third is my camera simulator - the QtMultimedia::availableCameras works well. The problem is that when I click on the item with my own camera (the simulator), nothing happens because QMediaServiceProviderPlugin::create() in my plugin is never called. I investigated the QT source codes and I probably found the problem:
When the Camera element is created by the QtQuick, the QCamera(QObject *parent) constructor is called and it then calls the FIRST QMediaServiceProviderPlugin loaded (the directshow plugin in this case) to create the QMediaService instance. My QMediaService is never created.
When I try:
Camera { id: camera deviceId: QtMultimedia.availableCameras[2].deviceId }
it doesn't work from the same reason - the directshow plugin is used to create the QMediaService.
My question:
Is there a way how to make the QML program above work for multiple QMediaServiceProviderPlugin loaded?Thanks for any usefull help.
-
Hi,
One alternative that you can try is to use a wrapper object that provides the QCamera to your VideoOutput.
-
@SGaist
Thanks for reply. Please could you be more concrete? I don't know how to implement it. A hint would help.... -
You have to create a QObject subclass that has a property called mediaObject that will return you camera instance.
-
This post is deleted! -
I'm playing around with the gphoto plugin and this hit me. It seems Qt does not handle the case with multiple QMediaService camera plugins properly.
-
You're right. I tried some hacks but finally I gave up using QML Camera, QMediaService etc. and implemented my own framework for cameras.
-
@oniongarlic said in Camera QML element and multiple QMediaService:
I'm playing around with the gphoto plugin and this hit me. It seems Qt does not handle the case with multiple QMediaService camera plugins properly.
That's a bit too vague. I've written applications using several different custom QtMultimedia backends at the same time and it worked nicely.
-
Well, the issue is with camera selection. If the gphoto plugin, https://github.com/dept2/qtmultimedia-gphoto , and Qts own (gst/v4l2)camera plugin are both available it will load them both, QtMultimedia.availableCameras will contain all cameras available. So far so good.
But assigning a id to the Camera deviceId property only works for cameras from the first loaded plugin, so for example if gphoto plugin is loaded first it is not possible to switch to a v4l2 camera. Plugins seems to be loaded in a-z order so gphoto will be first in case it is installed.
And looking at the code, afaik, it only uses the first QMediaService when the property is changed and does not check other QMediaService camera sources.
-
That's clearer now.
Do you have the same problem if you provide the devices you select through C++ ?
-
I haven't used the camera trough C++ yet.