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

Re: Camera API video callback issue

No, the green stripe remains in the middle.

 

https://dl.dropboxusercontent.com/u/1874750/frame1.jpg

 

Keep me in the loop please. Smiley Happy

I'll have the next few hours filled with curiosity. Smiley Happy

 

As for the hack-fix for my case,

lets say I only restrict myself for this resolution. I hope after the exact bug has been determined I can work out something to minimize "damage" until real bugfix is released.


 What should I do to have a correct offset?

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

Re: Camera API video callback issue

I think we figured it out.

your math is wrong Smiley Happy

 

you are doing (y*uv_stride) / 2.

for odd lines, this will be uv_stride/2, which is somewhere out in the middle of the row.

 

what you really want is:

(y/2 * uv_stride).

 

If you've seen the code written the other way before, it was possibly being done in a loop like: for (y=0; y<height; y+=2) {}


in which case it wouldn't matter.

 

 

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

Re: Camera API video callback issue

[ Edited ]

hey, just thought of something else you might consider...

starting a video recording causes some dynamic opening of libraries.  you can call camera_init_video_encoder() when your app starts up to do some pre-loading of those things and shave time off of your start-recording latency Smiley Happy

 

Another thing I will mention for you is that BestCamera's video mode works in what I will describe as "lazy-reallocation" mode.  eg. when you rotate the device, it does not re-allocate video buffers.  Instead, it relies on the on-screen effect to show video upright.  Only when you hit the record button does it go off and reallocate buffers for rotated video.  This can cause a blank viewfinder for a short period while buffers are freed and reallocated.  You could always assert the mRequiresUprightVf all the time, and I believe this will cause it to re-allocate when the device is rotated, instead of when you start recording.  Take a look at BestCam::startRecording() where it does something like:

    if (camera_has_feature(mHandle, CAMERA_FEATURE_PREVIEWISVIDEO)) {
        // if the video output uses the same buffers as the viewfinder, then they must both be oriented the same if required
        mRequireUprightVf = mRequireUprightCapture;
        // need to update vf angle to match recording angle
        mDesiredVfAngle = mDesiredCapAngle;
    }
    // apply the changes
    updateVideoAngle();

 

Though since you are working at 720x720 resolution, it's highly probably that there is no reallocation penalty, since the buffer geometry is not changing.  So maybe you can ignore this suggestion...  just some educational info Smiley Happy

 

 

 

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

Re: Camera API video callback issue

Hmm...

I corrected the math I think. I guess.

Planes seem to be in order now, green stripe is gone.

 

Just to be crystal clear on this, this is how the math looks like now.

Is it still wrong? Besides that it needs optimisation. Smiley Very Happy

 

for (int j = 0; j < height; ++j) {
    		for (int i = 0; i < width; ++i) {

    			int Y = buf->framebuf[j*stride + i];
    			int U = buf->framebuf[uv_offset + (j/2*uv_stride) + (i/2)*2];
    			int V = buf->framebuf[uv_offset + (j/2*uv_stride) + (i/2)*2 + 1];

    			float R = ((1.164 * (Y - 16)) + (1.596 * (V - 128)));
    			float G = ((1.164 * (Y - 16)) - (0.813 * (V - 128)) - (0.391 * (U - 128)));
    			float B = ((1.164 * (Y - 16)) + (2.018 * (U - 128)));

    			frameImage.setPixel(i, j, qRgb(clamp(R), clamp(G), clamp(B)));
    		}
    	}

 Sorry for alerting you in such a way. Thanks for all the tips provided. I can surely use them all.

Just have to see how it all fits into my dynamic loading of controls.

 

I can confirmed this resolved by changing the math. Smiley Happy

 

Boy, am I glad my math was wrong. Smiley Very Happy

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

Re: Camera API video callback issue

I do have to say my math brain was stunned on this one and it's probably the reason I didn't see the error of calculation.

To me, it is always the same. y/2*uv_strid and y*uv_stride/2 in math are equal. However, in order of computaional operations, probably isn't.

I'm soaking up any educational info that you are willing to provide.

Thank you very much. Smiley Happy

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

Re: Camera API video callback issue

it's not the order of operations that bit you there, it's the fact that in integer math, there are no fractions.

 

so 3/2*100 = 200, whereas 3*100/2 = 150 (which is what you were getting).

 

The logic looks fine.

I'm basically seeing i/2 and j/2 in the right spots.  if you just remember that U and V planes have half the vertical and horizontal resolution, then this should make perfect sense Smiley Happy

 

Cheers,

Sean

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

Re: Camera API video callback issue


knobtviker wrote:

Boy, am I glad my math was wrong. Smiley Very Happy


You have no idea how glad I am.

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

Re: Camera API video callback issue

camera_init_video_encoder();
Worked as a charm. Shaved off at least half of time delay on start video record. Awesome. Smiley Happy