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: 147
Registered: ‎05-31-2013
My Device: BlackBerry Z10 Limited Edition
My Carrier: Bonbon
Accepted Solution

Camera API video callback issue

[ Edited ]

I have examined most if not all Sean's examples of Camera API available publicly.

Some use callbacks and some events.

I am interested in video callback set on camera_start_video() function.

 

What I want to achieve is

  1. - getting each buffer frame timestamp and send it to a list stored in QML. Class doing so is subclassing Container.
  2. - each frame translated and used in ImageView in QML property image.
  3. - If possible, transcode each frame and eventually the video itself to 480x480px resolution (currently used is the only 720x720px one for 1:1 ratio)

So, cherry plucked out of headers and sources:

//header 
public:
    static void vfCallbackEntry(camera_handle_t handle, camera_buffer_t* buf, void* arg);
    void vfCallback(camera_buffer_t* buf);

 

//sources
void VineRecorder::vfCallbackEntry(camera_handle_t handle, camera_buffer_t* buf, void* arg)
{
    (void)handle;
    ((VineRecorder*)arg)->vfCallback(buf);
}

void VineRecorder::vfCallback(camera_buffer_t* buf)
{
	//if (this->capturing()) {
		if (buf->framemetasize == 65536) return;
		if (buf->frametype != CAMERA_FRAMETYPE_NV12) return;

    	quint64 currentFrameTimestamp = (quint64)buf->frametimestamp;
    	//this->setLastFrameTimestamp(currentFrameTimestamp);
   		qDebug() << currentFrameTimestamp;
	//}
}

 

//line where callback is used
err = camera_start_video(mHandle, filename, vfCallbackEntry, NULL, NULL);

 

What is confusing me is that vfCallback is not a static member and yet it doesn't recognise "this" nor anything else outside its local scope.

Application crashes on each of the commented lines in vfCallback.

Did I cast the "arg" wrong perhaps?

Can someone perhaps show an example of non static member used as callback? A function pointer?

 

Thanks for all your discussions, answers and suggestions. Please help, this is very frustrating. :smileyvery-happy:

 

BlackBerry Development Advisor
Posts: 668
Registered: ‎11-29-2011
My Device: developer
My Carrier: other

Re: Camera API video callback issue

show the line where you attach the callback :smileyhappy:

 

Developer
Posts: 147
Registered: ‎05-31-2013
My Device: BlackBerry Z10 Limited Edition
My Carrier: Bonbon

Re: Camera API video callback issue

I'll humbly admit I have no clue about how to attach a callback?

Isn't that the one in 3rd code block? :smileyembarrassed:

BlackBerry Development Advisor
Posts: 668
Registered: ‎11-29-2011
My Device: developer
My Carrier: other

Re: Camera API video callback issue

nope.. I'm the dummy. I missed that part of your post somehow.

anyhow.. your mistake is you passed NULL for arg in camera_start_video().  from the docs:

 

 * @param arg The argument passed to all callback functions, which is the
 *            last argument in the callback functions.

(a bit hard to put into words, but whatever you pass in as the "arg" argument to camera_start_video() is the same argument passed to your callbacks as "arg")

This is shown in most of the samples.

 

Developer
Posts: 147
Registered: ‎05-31-2013
My Device: BlackBerry Z10 Limited Edition
My Carrier: Bonbon

Re: Camera API video callback issue

I think I understand what you mean. I was casting nothing. 

Should I pass this as arg?

BlackBerry Development Advisor
Posts: 668
Registered: ‎11-29-2011
My Device: developer
My Carrier: other

Re: Camera API video callback issue

if you want to be able to retrieve "this", then yes, pass in "this" when registering the callbacks :smileyhappy:

Developer
Posts: 147
Registered: ‎05-31-2013
My Device: BlackBerry Z10 Limited Edition
My Carrier: Bonbon

Re: Camera API video callback issue

[ Edited ]

Yep, got it.

Thank you very much, you just as well saved the whole project. :smileyvery-happy:

 

To make it clear for someone else, my first 2 code blocks are correct, but the 3rd one must be:

err = camera_start_video(mHandle, filename, vfCallbackEntry, NULL, (void*)this);

 

Last parameter "arg" is changed from NULL to (void*)this and then you can manipulate the data as you wish with other functions.

 

Sean, my utmost gratitude and thank you again for your time and patience. :smileyhappy:

BlackBerry Development Advisor
Posts: 668
Registered: ‎11-29-2011
My Device: developer
My Carrier: other

Re: Camera API video callback issue

you might want to be aware that we have a known bug on stopping recording.  the last half second of video or so may get cut off.

just a heads up if you are trying to record with precise timing.

 

another option for you is to just attach the frame callback when you start the viewfinder instead.  you don't need to use camera_start_video() unless you need to record to disk.

 

 

Developer
Posts: 147
Registered: ‎05-31-2013
My Device: BlackBerry Z10 Limited Edition
My Carrier: Bonbon

Re: Camera API video callback issue

Didn't know about that, thanks. 

I compensated already by shear luck when targeting full 6 second range.

I do need to use camera_start_video because I am saving to disk. Separate MP4 files that need to be merged in 1 at the end.

Your opinion, should I encode in H264 after merger or each file and then merge?

BlackBerry Development Advisor
Posts: 668
Registered: ‎11-29-2011
My Device: developer
My Carrier: other

Re: Camera API video callback issue

hmm, the tricky part is that the timing may be a bit off on stopping.. I havent used vine before, so not sure how accurate it's timestamps usually are, so your users might tolerate our bug :smileyhappy:

 

if it's only 6 seconds, at 720p uncompressed, that would be about 250MB.  You might even be able to cache it in memory and then run it through your own encoder at the end.

How are you merging the mp4 files?  have some extra lib or code to do that already?

 

Just curious what you needed a vf callback for, since you are dealing with compressed video ultimately.

 

Cheers,

Sean