Custom Camera PictureCallback does not run if flash used on S4 devices - android

I have written a basic custom camera which I recently changed to use the flash (where available) on the device. Once I had made the change the code ran fine as before on my HTC One Mini 2, but no longer worked on my Galaxy S4. After stepping through I found my jpeg callback is never reached on the S4, instead the raw callback is run but with a null byte[] supplied.
I found this similar question:
S4 Flash Problem
Which seems to confirm there is an issue and solution on these devices but the solution has not been documented.
To re-iterate, the code works fine on the S4 so long as I don't turn on the flash with:
Camera.Parameters p = mCamera.getParameters();
p.setFlashMode(Camera.Parameters.FLASH_MODE_AUTO);//Or FLASH_MODE_ON
mCamera.setParameters(p);
Can anybody with experience on these devices provide the solution?

After a lot of trial and error over the last week I have stumbled upon two possible solutions to this problem, the first of which doesn't make any sense to me at all:
Force the zoom to be greater than x1. For some reason if I set the zoom to x1.2 etc. the camera works again as I would expect.
Ensure the aspect ratio of the selected picture size matches the native aspect ratio of the device. The S4 has a resolution of 1920x1080 so any picture size that matches this 16:9 ratio works with the flash on. This makes a bit more sense but why the flash makes the difference and why anything that isn't supported should be returned by getSupportedPictureSizes() I don't know (albeit they do seem to be without the flash.)
Currently I have chosen to use option 2 and am testing on my other devices.
Might also be worth mentioning that my next step on the S4 was to allow the user to turn the flash on/off/auto themselves but this required destroying and recreating the camera each time.

Related

Android camera preview color issue (red and blue are swapped)

I am observing a strange visual glitch when using a GLSurfaceView to render a camera preview on Android.
The reds and blues appear to be swapped in the Camera preview feed - greens seem ok. See the screen capture below.
I am only seeing this problem on a few devices (all variants of the Samsung Galaxy S4).
The glitch only occurs when using certain resolutions - 720x960 upwards is fine, anything below this exhibits the problem (e.g 640x480).
The problem occurs on both the front and rear camera.
The issue is reproducible in the Grafika Sample application (assuming you have a Samsung Galaxy S4 handy) by changing line 185 of CameraCaptureActivity.java like so:
// openCamera(1280, 720); // change this ...
openCamera(640, 480); // to this
I need to encode H264 at 640x480. I thought I could work around the problem by using a higher resolution (same aspect ratio) but still setting my encoder to run at 640x480 - unfortunately this leads to a horrible blocky video feed, presumably due to re-sampling.
Based on trial & error (and clues found in this answer and here) I was able to figure out that this is caused by turning on the recording hint functionality:
params.setRecordingHint(true); // this causes the problem
I was also having some aspect ratio issues which were solved by turning this off. So it seems that Samsung have messed up the setRecordingHint functionality at a driver or hardware level.
Interestingly, if if set the undocumented "video-size" value then I am able to fix the problem AND keep setRecordingHint turned on.
params.set("video-size", "640x480");
I don't know what this is doing compared to:
params.setPreviewSize(640, 480);
or
params.setPictureSize(640, 480);
but clearly it is having an impact. However since this appears to be undocumented and turning off setRecordingHint doesn't appear to have any affect on performance - I think go with disabling setRecordingHint.

Using Camera without preview or surface in android

I was looking for a method to use the camera on android devices without a surfaceview or a preview. I found out that, it is impossible to take picture without that preview. However, I have found a tutorial which is actually working taking pictures without a preview. Here is the link: http://www.vogella.com/articles/AndroidCamera/article.html
After switching the camera in the code from front to back-facing the app didn't crashed but it gave me an error 100. So it is only working with the front cam at the moment.
I am using a Samsung Galaxy S3(4.1.2) and i will test it on a Galaxy S2 and a Galaxy S3 Mini.
Anyone a good explanation for this?
You cannot take a picture without starting preview.
While some Android devices are more flexible, and allow takePicture to be called without preview running, this is technically against the API specifications.
It won't work on a large number of devices, so please don't rely on it. That tutorial is wrong, and presumably tested only on one of the devices that allows this behavior.
If you don't want a visible preview, see this question for ways to do that in Android versions >= 3.0.
Actually the time interval of question and answer is large, but may help others.
You can try this library to take picture even from service:
https://github.com/kevalpatel2106/android-hidden-camera
It uses a feature to draw over other apps and create a fake surface. Hope it helps.

Android setOrientationHint on HTC Phones

When using setOrientationHint for recording videos, Samsung and Motorola phones simply write this value into the Rotation Metadata.
However, it appears HTC phones do not write this value into the metadata and actually attempt to rotate the video after recording. The phones I have tried on Android 4.0.3 and lower actually rotate it 90 degrees no matter the value and the 4.0.4 phones rotate it as per the value.
Has anyone else noticed this behavior and what is the best way to fix this?
In my experience, there's nothing you can do to unify all devices. Some devices add metadata, some rotate the byte array, and some dismiss it altogether.
Another problem you have with metadata is that just as the recording devices differ, so do the playback devices, in Windows for example you might have noticed that jpeg metadata (EXIF) is ignored and all images are displayed landscape.
I would have hoped by now that the hardware manufacturers would have had certain hoops to jump through with regards to camera hardware but it seems that this is still a problem.

Galaxy S3 Video Recording via API "rolls" or is corrupted in Bright Light

Following the instructions from Google here exactly as it is (QUALITY_HIGH):
http://developer.android.com/guide/topics/media/camera.html#custom-camera
When doing this with a Galaxy S3 (US Version) everything seems fine in indoor lighting. But when the camera goes outside and it is bright (maybe it needs to increase the shutter speed) something strange happens. The video starts "rolling" like a bad TV signal, and the image gets to be very low quality. It almost seems like the image sensor got overloaded and messed up.
I tried recording with the normal camera application and it seems to have no problems under the same condition. But using the API as described here generates this problem. Since the S3 is pretty popular -- anyone run into this problem before?
Is there some kind of hidden setting that the main camera app uses for camera setup? I tried flattening the camera settings to take a look at what's in there and there are tons of settings but i dont know what they all do without documentation. already tried turning off anti-banding and luma-adaptation and that didnt seem to do anything.
Thanks!
I think I figured it out. Need more testing but this seems to do it. There is a hidden setting called "camera-mode" that is normally set to -1. I changed it to a 1 and suddenly it is fine and functioning like the normal camera app.. anyone know what this mode thing actually means?
Camera.Parameters lParam = prCamera.getParameters();
lParam.set("camera-mode",1);
prCamera.setParameters(lParam);
Is what did the trick if anyone else seems to run into the problem.\

getSupportedPreviewSizes() for Motorola Xoom front camera (and other devices)

I have a few questions concerning supported preview sizes for devices with front cameras. Not sure if I should ask here, but not really sure where else I would be able to find this answer. Has to do with an app I'm creating.
My question is, what determines the supported preview sizes? Is it the screen size or is it the camera? Most android devices that have multiple cameras have a 1.3 MP front camera. With that being said, are the supported preview sizes (from a getSupportedPreviewSizes() call) the same for cameras with the same MP? The HTC Evo and HTC Flyer both have a 1.3MP front camera, but have very different screen sizes. Are their supported preview sizes different? Does it depend on the camera hardware, device screen size, or camera MP?
Follow on question: The motorola xoom is the only android device I'm aware of that has 2MP front camera. I'm curious what it's supported preview sizes are. If you have a Xoom, could you post the results of a getSupportedPreviewSizes() call on your front camera here? It would be much appreciated. Thank you.
From experience with back facing cameras, the preview sizes are dependent on the hardware, and not related to the MP. What's more fun is that every manufacturer seems to report the sizes in a different way, sorted backwards or forwards by size, or just completely random (looking at you, Samsung!).
I believe the Galaxy Tab 10.1 also has a 2 mp front facing camera. I have both it and the Xoom at home, so I can report on findings at a later time.

Categories

Resources