Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
Posts: 27
Registered: ‎05-15-2012
My Device: Dev Alpha B
My Carrier: Bell
Accepted Solution

BB10 camera viewfinder in ForeignWindow

Hi all,

I am trying to get a viewfinder feed rendered in a foreignwindow...

I make all of the following calls to the api in order (after watching BBJam videos and reading the camera_api.h file), each call returns CAM_EOK which indicates successful completion:

//as shown in ForeignWindow app on Samples Page, works well
createForeignWindow(...foreignWindowGroupId...,foreignWindowId...)

camera_error_t result = camera_open(CAMERA_UNIT_FRONT, CAMERA_MODE_RW, &mFrontCameraHandle);

// some code...



result = camera_open(CAMERA_UNIT_FRONT, CAMERA_MODE_RW, &mFrontCameraHandle);

result = camera_set_photovf_property( mFrontCameraHandle,
                              CAMERA_IMGPROP_WIN_GROUPID,foreignWindowGroupId.toStdString().c_str(),
                              CAMERA_IMGPROP_WIN_ID, foreignWindowId.toStdString().c_str(),
                              //CAMERA_IMGPROP_WIDTH, 768, //Removed, causes CAM_EINVAL
                              //CAMERA_IMGPROP_HEIGHT, 400, //Removed, causes CAM_EINVAL
                              CAMERA_IMGPROP_ROTATION, 90,
                              //CAMERA_IMGPROP_BURSTMODE, 1,
                              CAMERA_IMGPROP_FRAMERATE, (double)15.0,
                              CAMERA_IMGPROP_HWOVERLAY, 0,
                              CAMERA_IMGPROP_ZOOMFACTOR, 20 );

 

result = camera_set_photo_property( mFrontCameraHandle,
                            CAMERA_IMGPROP_FORMAT, CAMERA_FRAMETYPE_JPEG,
                            CAMERA_IMGPROP_ROTATION, 90,
                            CAMERA_IMGPROP_WIDTH, 768,
                            CAMERA_IMGPROP_HEIGHT, 400);

result = camera_start_photo_viewfinder(mFrontCameraHandle, 0, 0, 0);

However, I cant seem to get the viewfinder properly rendered in the foreignWindow. Has anyone successfully launched a viewfinder in a foreignwindow on the device yet?

Thanks,

Martin

------------------------------------------
Macadamian Technologies Inc.
http://www.macadamian.com/
BlackBerry Development Advisor
Posts: 683
Registered: ‎11-29-2011
My Device: PRIV
My Carrier: Rogers

Re: BB10 camera viewfinder in ForeignWindow

Hi,

I will have to ask the appropriate folks with foreign window experience and respond separately.

 

The rest of your code looks fine, although I am surprised that there were no complaints about the photo width/height you were setting below.  You can just exclude those values and the appropriate defaults will be used.  Note that there is an API for querying available resolutions:

camera_get_photo_output_resolutions()

and

camera_get_photo_vf_resolutions()

You will find that on Dev Alpha, the resolutions are relative to the default portrait device orientation (eg. 1152 x 2048 for the front-facing camera, as opposed to 2048x1152).  Similarly, rotation is relative to default portrait orientation.  It is exposed to the user as a camera which produces portrait images.

 

Cheers,

Sean

 

BlackBerry Development Advisor
Posts: 683
Registered: ‎11-29-2011
My Device: PRIV
My Carrier: Rogers

Re: BB10 camera viewfinder in ForeignWindow

Okay, here's the recipe I was just handed.  It sounds like you are missing the on-attached handler.

 

// 1. create a ForeignWindow
m_pForeignWindow = new ForeignWindow();

// 2. make a connection to ForeignWindow to get notified when the viewfinder window joins the window group
QObject::connect(m_pForeignWindowCamera, SIGNAL(windowAttached(unsigned long, const QString &, const QString &)),
                                    this, SLOT(onWindowAttached(unsigned long, const QString &, const QString &)));
 
// 3. Set ForeignWindow properties
    if (m_pForeignWindow) {
        m_pForeignWindow->setWindowId(m_vfWindowId);
        m_pForeignWindow->setWindowHandle(0);
        m_pForeignWindow->setWindowFrameUpdateEnabled(false);
    }
 
// 4. start viewfinder
your camera code here.
 
// 5.  This method will be invoked when the vf window is attached to ForeignWindow
// win : vf window handle, group : window group id, id : window id
void onWindowAttached (unsigned long win, const QString &group, const QString &id)
{
    // From this method, change window properties such as visibility, size and rotation…
}

 

I am unclear how many window properties you will need to configure in onWindowAttached(), however I would suggest at least setting SCREEN_PROPERTY_ZORDER and SCREEN_PROPERTY_VISIBLE.  You are also free to set position and size, however according to the docs, if you use setWindowFrameUpdateEnabled(true) on the ForeignWindow , then the position and size should be handled by cascades for you.

 

The foreign window docs are here:

https://bdsc.webapps.blackberry.com/cascades/reference/bb__cascades__foreignwindow.html

 

Cheers,

Sean

Developer
Posts: 27
Registered: ‎05-15-2012
My Device: Dev Alpha B
My Carrier: Bell

Re: BB10 camera viewfinder in ForeignWindow

Hi Sean,

 

Thank you for your responses, however, I have tried your suggestion to no avail; The calls you suggest in the onWindowAttached() slot (window properties such as visibility, size and rotation…) are already set in my application and calls to the doNoise() function from the sample ForeignWindow app are properly rendered on the screen - this leads me to believe that the problem is in my series of calls to the actual camera API.

 

In the onWindowAttached, is there anything else I must initialize apart from what you have suggested in order to get the live camera's feed into the frame?

 

Thanks,

 

Martin

 

------------------------------------------
Macadamian Technologies Inc.
http://www.macadamian.com/
BlackBerry Development Advisor
Posts: 683
Registered: ‎11-29-2011
My Device: PRIV
My Carrier: Rogers

Re: BB10 camera viewfinder in ForeignWindow

I'm sure you're configuring the camera correctly.

Let's try taking cascades out of the equation as much as possible.

Leave setWindowFrameUpdate(false) in there to prevent cascades from messing with the window.

 

in your onWindowAttached() callback, try the following:

 

print out the group and id strings for confirmation.

int size[] = {300, 300};

screen_set_window_property_iv(win, SCREEN_PROPERTY_SIZE, size);

int pos[] = {0, 0};

screen_set_window_property_iv(win, SCREEN_PROPETY_POSITION, pos);

int i = 1;

screen_set_window_property_iv(win, SCREEN_PROPERTY_VISIBLE, &i);

i = 1000;

screen_set_window_property_iv(win, SCREEN_PROPERTY_ZORDER, &i);

 

This should bring a viewfinder window out to the foreground (zorder +1000) way in front of your app.

We also want to confirm that we've caught the correct window, so make sure to print out those strings.

 

Also, have you tried attaching a preview callback when calling camera_start_photo_viewfinder()?  You should be able to confirm whether the viewfinder is running if your preview callback function starts getting invoked.

 

Let me know how that goes?  I expect a 300x300 viewfinder window to pop up in the top-left corner of the screen if you're successful.

 

NOTE: I haven't tested this in any way, as I don't have a cascades environment set up right now.

 

Developer
Posts: 27
Registered: ‎05-15-2012
My Device: Dev Alpha B
My Carrier: Bell

Re: BB10 camera viewfinder in ForeignWindow

Sean,

As per your suggestion, I seem to have the correct win/group/id values within the onWindowAttached(…) context given that I am able to change several parameters including SCREEN_PROPERTY_SIZE there. I am able to verify this by rendering the doNoise() contents in the surface area and I get the expected results.

Each part of my application tells me it is initialized and working correctly, but the viewfinder does not render anything in the window area; I am not so sure where to look into next.

Is it possible that the camera_api does not work with the ForeignWindow object yet? The videos from BBJam showed demonstrations using native windows only. If possible, could a sample of formal calls be provided showing this?

Thanks!

Martin

------------------------------------------
Macadamian Technologies Inc.
http://www.macadamian.com/
BlackBerry Development Advisor
Posts: 683
Registered: ‎11-29-2011
My Device: PRIV
My Carrier: Rogers

Re: BB10 camera viewfinder in ForeignWindow

I know for sure it works because our internal app team is building the BB10 camera app in cascades.

I'll have to get back to you with an example.  Maybe some time this weekend I will have a chance to install the cascades environment and try getting something together.

 

I do have a "take picture" sample app built on top of the native screen example which I can also post, but I just need to clean it up first.  I used this as the basis for all of my Jam demos.

 

Cheers,

Sean

BlackBerry Development Advisor
Posts: 683
Registered: ‎11-29-2011
My Device: PRIV
My Carrier: Rogers

Re: BB10 camera viewfinder in ForeignWindow

if you could zip up your code and send it to me directly - smcveigh at qnx dot com - then it would probably save me some time, and I may be able to pinpoint what's wrong just by eyeballing it.

Developer
Posts: 27
Registered: ‎05-15-2012
My Device: Dev Alpha B
My Carrier: Bell

Re: BB10 camera viewfinder in ForeignWindow

Sean,

 

Sure that would be fantastic, I will send you a zip file with the project. Let me know if you have any feedback that could point me in the correect direction.

 

Thanks!

 

Martin

 

------------------------------------------
Macadamian Technologies Inc.
http://www.macadamian.com/
BlackBerry Development Advisor
Posts: 683
Registered: ‎11-29-2011
My Device: PRIV
My Carrier: Rogers

Re: BB10 camera viewfinder in ForeignWindow

Okay, figured out your problem based on your source code.

 

1. In createForeignWindow(), you were creating a screen window.  Don't do this.  You're creating one window here named X, and then when you start the camera viewfinder, another window with the same name is created by the camera service.  The second window is never being caught by the onWindowAttached() handler.  The example code that you based this on creates it's own screen window, which is not what you want Smiley Happy  You want the window created by the camera service.

 

2. You're configuring some funky photo properties.  768x400 isn't a valid resolution and it messes up the viewfinder.  There should be some extra range-checking happening on these values, but it is not in the 10.0.4 release.  Unless you have a specific need to adjust photo properties, just leave them at their defaults.

 

So to recap... get rid of createForeignWindow() -- the window is created by the camera service -- and get rid of your call to camera_set_photo_property() unless you are going to pick in-range values Smiley Happy

 

I still hope to be able to publish a stripped down cascades camera example.. maybe before this long weekend is over Smiley Happy

 

Cheers,

Sean