07-20-2012 09:51 AM
Another screen problem is driving me nuts.
I am quite confused as to what are the proper steps to rotate the viewfinder window as the user rotates the device.
I seem to be able to get things working when going from landscape to landscape upside down. But doing anything else gives me basically things that I can't begin to describe. For example, when I go from landscape to portrait, I always get the bottom half of the screen to be pitch dark and the view upside down.
Say vf_win is the viewfinder window and size is the new size for the vf_win and angle is the new device orientation angle.
So do I need to first rotate the window for the view finder via
screen_set_window_property_iv(vf_win, SCREEN_PROPERTY_SOURCE_SIZE, size); screen_set_window_property_iv(vf_win, SCREEN_PROPERTY_BUFFER_SIZE, size); rc = screen_set_window_property_iv(vf_win, SCREEN_PROPERTY_ROTATION, &angle);
and then rotate the camera via
rc = camera_set_device_orientation(handle, angle); rc = camera_set_videovf_property( handle, CAMERA_IMGPROP_ROTATION, &angle);
I think the above is definitely wrong since I couldn't get the results I wanted.
Any help is greatly appreciated.
Solved! Go to Solution.
07-20-2012 10:10 AM
07-21-2012 12:36 AM - edited 07-21-2012 12:40 AM
Stay tuned for more info on rotation.
I will be doing a sample which deals with all possible rotation scenarios (and probably configuration ones too).
The existing samples were kept very basic on purpose.
If you want to toy around, just keep the following concepts in mind:
1. CAMERA_IMGPROP_ROTATION can be applied to a viewfinder or photo output config in order to cause image data to be rendered to the window buffers physically rotated. Use camera_get_xxxxxx_rotations() functions to determine valid values. Not all camera hardware will ultimately support physical buffer rotation, nor under all colour formats. In those cases, metadata and/or screen transforms should be used to correct for display.
2. 0 degrees always refers to what I will call the "home" orientation/rotation. If you configure the camera for 0 degrees rotation, your images will match the scene as photographed when the device is held in it's home orientation (eg. the blackberry logo is right-side-up).
3. camera sensors are not installed the same way in all devices. On the PlayBook, they are installed in landscpe orientation when the device is held in it's home orientation. On Dev Alpha, they are installed in portrait orientation. You will note that when you retrieve available resolutions, the Dev Alpha will report resolutions which are taller than they are wide, which is the opposite of the PlayBook case. This is because we standardized on always reporting abilities relative to the home orientation. For this reason, you will never see 1920x1080 as a valid video resolution on a portrait device, since it is presented to the user as 1080x1920. (Note that this differs slightly from Android which does not provide physical buffer rotation, and instead relies on the app to work out the pixel orientation based on reported installed orientation of the sensor).
4. if you don't care about interpreting actual camera image data (eg. processing the pixels), then you can usually skip out on configuring physical buffer rotation via CAMERA_IMGPROP_ROTATION, and instead can just rotate the resulting viewfinder window using the screen APIs. As mentioned earlier, you may actually need to do this on some platforms and configurations.
I hope this lets you figure out the problem you are having with the PlayBook in 2.1. You have left the default configuration in place (1024x576 viewfinder with buffer rotation set to 0 degrees). As a result, the viewfinder data is rendered to a "landscape" window geometry. If you apply a window rotation using the screen APIs, you will correct this issue. Alternately, you may configure CAMERA_IMGPROP_ROTATION appropriately before starting the viewfinder. You can reconfigure while the VF is running, but there will be a brief interruption while resources are reallocated.
Hope this helps. (seriously... I have a 20+ page slide deck I use internally to try and explain these things to the team, and it is still confusing! I will endeavour to produce an in-depth example and KB/wiki article on this topic).
EDIT: I re-read your first post. You are double-rotating. You should only need to apply either a screen rotation OR a CAMERA_IMGPROP_ROTATION change. It depends on your needs. Also, never try to alter the source buffer size (I don't think it's possible even?).
07-21-2012 12:44 AM
07-21-2012 12:59 PM
I feel a little better knowing that this is non-trivial even for internal people. In fact, after spending hours reading the screens doc and experimenting, I am still not sure how all the screen stuff works.
Before I experiment further, could you explain why the sample app doesn't work when launched in portrait on the playbook?
From what I have read, the viewfinder frames from the playbook are always in 1920 x 1080. Is that true? In that case, how does the image get properly rendered on a window that is 576 x 1024?
When you say CAMERA_IMGPROP_ROTATION rotates the image data, what does that exactly mean? Say I have set my viewfinder window to 1024 x 576 and device orientation is at angle 0. If I issued CAMERA_IMGPROP_ROTATION for 90 degrees on the PlayBook, what is that supposed to do?
07-22-2012 01:38 AM
The sample app doesn't work quite right when launched in portrait on the playbook because the default camera configuration is for landscape. Down in the camera drivers, we don't really know anything about which way the device is being held and what the application/user's intent is, so we rely on the app telling us a bunch of information to sort things out. Keep in mind, this is the lowest level API available for camera access. There is a Cascades Camera API being developed which wraps the C API up and tries to simlify some things at the expense of flexibility.
On PB, the video viewfinder frames are 1920x1080 by default, but several other sizes are supported (all landscape though!). Use camera_get_video_vf_resolutions() to retrieve the full list. If you need to render it into a portrait window, you need to either specify an output rotation using camera_set_videovf_property(handle, CAMERA_IMGPROP_ROTATION, 90 or 270) or by adjusting your screen window rotation using screen_set_window_property_iv(win, SCREEN_PROPERTY_ROTATION, 90 or 270) and possibly resizing the window using SCREEN_PROPERTY_SIZE.
The first option above actually produces a 1080x1920 video frame rendered in a non-rotated screen window. The second option is still dealing with 1920x1080 window buffers but when the window is composited, it is blitted sideways. The reason we have 2 ways to do this is because we have a requirement to be able to record video in portrait sizes without having to rely on metadata hints to display the videos correctly like Apple or Android have to do (this is the reason for the 1st method). The reason for the second method (screen) is because not all applications require the video to be rotated, nor will all hardware platforms necessarily support outputting video in this mode.
To answer your last question -- setting vf resolution to 1024x576 and a rotation of 90 on playbook will yield the following output:
-video output buffers which have a width of 576 and a height of 1024 pixels.
-you can then display this viewfinder in a screen window of size 576x1024 (or however you choose to scale it)
-buffers delivered from the camera sensor would be rotated 90 degrees clockwise before being delivered via these 576x1024 sized buffers
What does this represent visually?
if you held the playbook in it's home orientation and a person stood in front of the camera, the image would be rotated 90 degrees clockwise so that their head is to the right of the frame and feet are to the left.
How is that useful?
If you happened to be holding the playbook oriented 90 degrees counter-clockwise (eg. blackberry logo is on the right hand side) and you displayed that 576x1024 image buffer, the person's head would now be at the top of the screen.
Again, this can easily get somewhat confusing and really benefits greatly from visual aids. I keep a stack of post-it notes handy and am constantly drawing frame lines and stick men on them and rotating them accordingly
07-22-2012 04:08 AM
Thanks for the detailed explanation. The part about Android and iPhone (which I heard from your BB10 Jam video recording) now makes sense.
Yes, this is a bit convoluted. But once understood, it is not that crazy. I wonder if the internal Casacades people are having a hard time with this as well.
Time for some experimentation!
07-22-2012 04:41 PM
Dear devs, I am overjoyed to announce that I finally figured out how to rotate the camera! One problem was that I had a bug in my code. Instead of setting the window size using SCREEN_PROPERTY_SIZE, I was setting the source size, SCREEN_PROPERTY_SOURCE_SIZE. Couldn't believe it.
Anyway, I am quite confident that I've understood the mechanics. Once I've cleaned up my code, I'll post something for the benefits of all!