[solved] Using the camera api on the n950
Page |
1 |
Hi was anyone successful in using the qml camera api on the n950.
I’m using the following code:
- import QtQuick 1.0
- import QtMultimediaKit 1.1
- Item {
- Camera{
- id: camera_item
- anchors.fill: parent
- focus: true
- flashMode: Camera.FlashRedEyeReduction
- whiteBalanceMode: Camera.WhiteBalanceFlash
- exposureCompensation: -1.0
- onCaptureFailed: console.log("Failed: " + message)
- onStateChanged: console.log("Camera state: " + state)
- onImageCaptured: {
- console.log("Preview url: " + preview)
- //process the image
- }
- onError: console.log("Error: " + errorString)
- }
- MouseArea{
- anchors.fill: parent
- onClicked: {
- console.log("Error: " + camera_item.errorString)
- console.log("Taking image")
- console.log("Unloaded State - " + Camera.UnloadedState)
- console.log("Loaded State - " + Camera.LoadedState)
- console.log("Active State - " + Camera.ActiveState)
- console.log("Current camera state: " + camera_item.cameraState)
- camera_item.captureImage()
- }
- }
- Component.onCompleted: camera_item.start()
- }
I get the following output and the viewfinder is never shown :|
- Error:
- Taking image
- Unloaded State - 0
- Loaded State - 1
- Active State - 2
- Current camera state: 2
- Failed: Camera not ready
Thanks
18 replies
I tried looking into http://doc.qt.nokia.com/qtmobility-1.2/qml-camera.html which (afaik) is the official doc to see if we were missing something to no avail.
Soo, We should either fill a bug report to the API or to the docs..
I tried this example on device using
qmlviewer -opengl -fullscreen cameratest.qml
and it worked fine. I ssh to user account.
This issue is very likely caused by aegis security system, it’s necessary to add file like this
- <aegis>
- <request>
- <credential name="GRP::video" />
- <credential name="GRP::pulse-access" />
- <for path="absolute path to application" />
- </request>
- </aegis>
to debian/appname.aegis
and rebuild/reinstall deb package
Yep, me too BUT then we have another problem.
How do you put the camera in stand by?
I tried adding:
- Connections {
- target: platformWindow
- onActiveChanged: {
- if (platformWindow.active) {
- console.log("Active")
- camera_item.start()
- } else {
- console.log("Inactive")
- camera_item.stop()
- }
- }
- }
But it doesn’t work at all.
This is the output I get when I swipe it to the background:
- ...
- Meego graphics system destroyed
- Inactive
- ResourceSet::proceedIfImFirst()...allowing only request directly.
- ResourceSet::update().... updating...
- ResourceEngine(1)::updateResources() - **************** locking....
- Converted Resource 0x03 to 0x08
- Converted Resource 0x0a to 0x800
- Converted Resource 0x0b to 0x1000
- All resources as bitmask is 0x1808
- ResourceEngine(1) - update 1:5
- ResourceSet::proceedIfImFirst()...queuing request 2.
- ResourceSet::proceedIfImFirst()...queuing request:Acquire.
- Illegal instruction (core dumped)
The weird thing is that Camera.start()/Camera.stop() doesn’t seem to do anything at all.
Actually, if you remove all your calls to start(), the camera is still loaded normally.
Cool isn’t it?
The reason why aegis credentials are not documented properly yet, is that the final set of credentials hasn’t been frozen yet. Proper documentation of which credentials are needed for which functionality, including a complete list of all available credentials will be published later.
Thank you very much dmytro I figured it was some kind of policy missing and was experimenting with aegis :)
but never found the credential names I needed to include.Is there perhaps a document describing the credentials needed for certain features.
Thanks
You can try to use the raster graphics system for application with QGLWidget based viewport to ensure camera doesn’t loose gl context.
The more correct solution would be to stop() or even better unload() the camera when minimized, as suggested before.
I’m also concerned to see “Meego graphics system destroyed” before “Inactive”, it’s better to unload the camera before graphics system is destroyed.
Hi Dmytro,
I am also trying to use QCamera APIs on N950.
My first issue was on making the aegis manifest file but this is now resolved thanks to the community help.
Now I am having other issues:
1) I am trying to grab frames from the camera. I understand (and you provided this solution before) that for this I need to override QAbstractVideoSurface, re-implement supportedPixelFormats() and present(); I have done that and on my custom QAbstractVideoSurface the method is called with the video frames (QVideoFrame param).
How I used it :
- camera = new QCamera;
- videoSurface = new VideoSurface(); // VideoSurface extends QAbstractVideoSurface
- camera->setViewfinder(videoSurface);
- camera->setCaptureMode(QCamera::CaptureVideo);
- camera->start();
As I said this works (present is called with desired QVideoFrame s). However during format negotiation in VideoSurface::supportedPixelFormats() the only pixel format available is QVideoFrame::Format_UYVY. This means that in VideoSurface::present I can not use the provided QVideoFrame param to construct a QImage from the raw frame data and using this QImage display the frames on the screen (viewfinder). Should I implement a custom color space conversion from UYVY to RGB to be able to display the frames? I saw in another post of yours that you suggested using this code to inject the custom video surface (http://developer.qt.nokia.com/forums/viewthread/370):
- QVideoRendererControl *control = camera->service()->requestControl<QVideoRendererControl>();
- if (control) control->setSurface(yourSurface);
(and I suppose that instead of
- camera->setViewfinder(videoSurface);
use
- QCameraViewfinder* viewFinder = new QCameraViewfinder();
- camera->setViewFinder(viewFinder);
- viewFinder->show();
which will correctly display a viewfinder)
BUT, in this line
- QVideoRendererControl* control = camera->service()->requestControl<QVideoRendererControl>();
the returned control is NULL…
So how can I grab QCamera video frames and also present a viewfinder on the screen? The only solution is through colorspace conversion? This is time consuming …
2) Another issue is how to set the desired video resolution? I used a QMediaRecoder and set the desired settings on this object to force desired video resolution on QCamera(even though I am not interested in capturing video on a file, I am only interested of grabbing video frames at certain resolution and FPS):
- camera = new QCamera;
- videoSurface = new VideoSurface(); // VideoSurface extends QAbstractVideoSurface
- camera->setViewfinder(videoSurface);
- camera->setCaptureMode(QCamera::CaptureVideo);
- mediaRecorder = new QMediaRecorder(camera);
- QVideoEncoderSettings videoSettings = mediaRecorder->videoSettings();
- mediaRecorder->setEncodingSettings(mediaRecorder->audioSettings(),videoSettings);
- camera->start();
Thanks & regards,
Ionut Dediu
Hi Ionut,
you spotted two areas I’d like to improve in next versions on QCamera API:
to have access to video frames simultaneously with efficient rendering (this is also related by lesser extent to QMediaPlayer) and viewfinder resolution settings (and probably framerate, not so sure about this).
Hi Dmytro,I am also trying to use QCamera APIs on N950.
My first issue was on making the aegis manifest file but this is now resolved thanks to the community help.Now I am having other issues:
1) I am trying to grab frames from the camera. I understand (and you provided this solution before) that for this I need to override QAbstractVideoSurface, re-implement supportedPixelFormats() and present(); I have done that and on my custom QAbstractVideoSurface the method is called with the video frames (QVideoFrame param).How I used it :
camera = new QCamera; videoSurface = new VideoSurface(); // VideoSurface extends QAbstractVideoSurface camera->setViewfinder(videoSurface); camera->setCaptureMode(QCamera::CaptureVideo); camera->start();As I said this works (present is called with desired QVideoFrame s). However during format negotiation in VideoSurface::supportedPixelFormats() the only pixel format available is QVideoFrame::Format_UYVY. This means that in VideoSurface::present I can not use the provided QVideoFrame param to construct a QImage from the raw frame data and using this QImage display the frames on the screen (viewfinder). Should I implement a custom color space conversion from UYVY to RGB to be able to display the frames?
Colorspace transformation is disabled in camerabin pipeline by default for performance reasons, it’s possible to enable it with
QCameraControl *control = camera->service()->requestControl<QCameraControl>();
control->setProperty(“viewfinderColorSpaceConversion”, true);
This flag is gstreamer backend specific (it should be documented).
You may also try to report a limited supported set of RGB formats, gst colorspace convertor on N950 can convert only to a few RGB formats efficiently.
You can also have a look at qgraphicsvideoitem_maemo5.cpp for a very fast UYVY to RGB16 transformation, if license is suitable for you.
I’m thinking about video frames probe like API to have read only access to video frames in parallel with efficient rendering, and video filter like API to modify video frame before rendering, but I can’t promise when/if it’s done.
Any feedback/ideas in this area are very welcome.
I saw in another post of yours that you suggested using this code to inject the custom video surface (http://developer.qt.nokia.com/forums/viewthread/370):
QVideoRendererControl *control = camera->service()->requestControl<QVideoRendererControl>(); if (control) control->setSurface(yourSurface);(and I suppose that instead of
camera->setViewfinder(videoSurface);use
QCameraViewfinder* viewFinder = new QCameraViewfinder(); camera->setViewFinder(viewFinder); viewFinder->show();
which will correctly display a viewfinder)BUT, in this line
QVideoRendererControl* control = camera->service()->requestControl<QVideoRendererControl>();the returned control is NULL…
Regarding “camera->setViewfinder(videoSurface);” vs request control, those methods should work the same if only one output is used (setViewfinder() detaches previous output) and camera->setViewfinder() is simpler and more preferred.
QMediaService API allows backend to have multiple video outputs attached, but current gstreamer backend doesn’t support this, that’s why requestControl<QVideoRendererControl>() returns NULL.
So how can I grab QCamera video frames and also present a viewfinder on the screen? The only solution is through colorspace conversion? This is time consuming …
2) Another issue is how to set the desired video resolution? I used a QMediaRecoder and set the desired settings on this object to force desired video resolution on QCamera(even though I am not interested in capturing video on a file, I am only interested of grabbing video frames at certain resolution and FPS):
camera = new QCamera; videoSurface = new VideoSurface(); // VideoSurface extends QAbstractVideoSurface camera->setViewfinder(videoSurface); camera->setCaptureMode(QCamera::CaptureVideo); mediaRecorder = new QMediaRecorder(camera); QVideoEncoderSettings videoSettings = mediaRecorder->videoSettings(); mediaRecorder->setEncodingSettings(mediaRecorder->audioSettings(),videoSettings); camera->start();
Unfortunately the current QCamera API doesn’t provide a viewfinder resolution control,
using QMediaRecorder is a valid workaround. It should not have any negative performance impact.
Hi Dmytro,
Thanks a lot for your answers, they were really helpful.
I wanted to post a longer reply to highlight more issues regarding the differences between Symbian and Meego regarding the camera capabilities; I will do this later, maybe it will be useful to you to get more feedback on the usage scenarios for the QCamera APIs.
Right now I wanted to ask you about the method
- bool QAbstractVideoSurface::present ( const QVideoFrame & frame )
What is the lifetime of the frame param? I can not cache it and use it later after returning from the present() method, is this right?
If so, how can I safely make a copy of the frame param into another QVideoFrame object so that I can use it later? I’m thinking of adding the frames into a queue/list and later process these separately from another thread. How can I copy a QVideoFrame?
Thanks & regards,
Ionut
You must log in to post a reply. Not a member yet? Register here!




