Right way to work around Nexus 7 previewFormat bug?

I’ve run into a bug on the Nexus 7, which is that it only supports preview sizes that are 4:3 aspect ratio, even though 16:9 aspect ratio formats appear in the preview format list.

For example, try the androidCameraExample, and set the requested size to 1280x720. You will see that the resulting image is stretched/distorted. This bug occurs with non-openFrameworks apps as well. It is particularly nasty because the camera tells you that the preview format is the size you asked for, but the image that you get back is distorted.

But lots of people have Nexus 7, so I want to support it in my app, even though I’m pretty upset with Google/Asus and the moment. It looks like other apps (e.g. https://chromium.googlesource.com/chromium/src/media/+/40f3381a0ef6b210cfcda3ab98d85b1c39a53d4b/base/android/java/src/org/chromium/media/VideoCapture.java) maintain a list of buggy devices, and then take corrective action. I’m wondering if I ought to hack this into OFVideoGrabber.java …

The other alternative: Is there already a way to access android.os.Build from within openFrameworks? If so, I’ll be able to leave OFVideoGrabber.java alone, and just compensate for the buggy hardware in my app code.

Has anyone else come up with an elegant fix for this device?

I haven’t seen this as an issue. I’m building an OF app for the Nexus 7 right now and everything looks correct to me. I can try a couple things.

do you have some test code I can try?

Note: This is NOT an openFrameworks bug, I’m just wondering about the right way to workaround it when using openFrameworks.

The bug is demonstrated by the Camera example code provided by Google. My steps to reproduce:

  1. Downloaded the latest Android Studio Beta from http://developer.android.com/sdk/installing/studio.html (I was also able to reproduce using Eclipse, both in Java and with openFrameworks)
  2. Let it install the SDK and samples for API level 19
  3. Import the sdk/samples/android-19/legacy/ApiDemos project
  4. Build it and try the Camera demo, under Graphics

Example results are on my Google drive

You will see that in landscape mode the bag is stretched, while in portrait mode it has been squashed.

Hey, by any chance did you find a fix for this? I’m getting the same problem on an Asus Nexus 7, it’s really noticeable when you turn from one orientation to the other. I’ve tried hard coding all different size combinations in setPreviewSize()/OFVideoGrabber.java, but can’t seem to shake the distortion. Feels like 4:3 has the issue as well, but not as noticeable?

Here is what I do:

#include "ofxAndroidUtils.h"

and then

	//This is a workaround for a bug in the Nexus 7
	if(ofxAndroidGetStringRes("model") == "Nexus 7" && ofxAndroidGetStringRes("device") == "flo"){
		grabber.initGrabber(1024, 768);
	} else {

This is inspired by the Chromium code I linked to earlier in the thread. I haven’t found anything more elegant.

I guess settings the grabber to 4:3 is close enough, but not so great when you need a larger image. @theDANtheMAN, can I ask what Nexus version you have?

This might be more of a general question but does your video grabber rotate properly when portrait mode is default orientation (eg. with ofSetOrientation(OF_ORIENTATION_DEFAULT)? My pitch and yaw seem to be swapped and the image is 90 degrees off? Testing with the default androidCameraExample.

I also have some kind of orientation problem that I haven’t figured out yet. Interestingly I have exactly the same problems on iOS and Android, so I suspect I just don’t understand (yet) how openFrameworks handles orientation.

Google actually responded to my bug report! (https://code.google.com/p/android/issues/detail?id=73316)

It appears to be a low-level bug that they don’t intend to fix, but they suggested a work-around. I’m in the process of trying their suggestion, which involves a one-line change to OFAndroidVideoGrabber.java (adding a call to setPictureSize after setPreviewSize)

I’ll submit a pull request with the fix if it works.