How to lock focus in camera2 api, android? - android

I am trying to lock focus after my custom camera finds focus.
First it AF mode set to auto:
builder.set(CaptureRequest.CONTROL_AF_MODE,
CaptureRequest.CONTROL_AF_MODE_AUTO);
And After touching the preview it finds focus distance, and I have to lock AF and AE using this code:
builder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
builder.set(CaptureRequest.CONTROL_AE_LOCK, true);
Locking AE works fine in any devices. Locking AF is working on Nexus5 and Nexus 5x. But as for Samsung S5 and S6, it keeps try to search focus.
What is the best way to lock focus?

In order to lock the AF you have to take care of requesting the AF_TRIGGER only once by using capture() instead of repeatingRequest() (if not it enters in an af request loop and remains always trying to focus, but some nexus fix this in its FW, so some devices as Nexus 5 focus well even it shouldn't)
So, the correct order will be:
Set CONTROL_AF_MODE to CONTROL_AF_MODE_AUTO (via session.setRepeatingRequest()) and the AF_REGIONS and the AE_REGIONS if you want
Wait until you check that the CONTROL_AF_MODE is already in auto by checking the totalCaptureRequest from the CaptureCallback.
Set the AF_TRIGGER_START in the builder along with the CONTROL_AF_MODE_AUTObut this time instead of using session.setRepeatingRequest() use session.capture().
Inmediately after that, set the AF_TRIGGER to set the AF_TRIGGER_IDLE (not cancel!) an use again session.setRepeatingRequest() along with the CONTROL_AF_MODE_AUTO.
Wait until it has focused,you will receive FOCUSED_LOCKED or NOT_FOCUSED_LOCKED.
The PASSIVE_FOCUSED state is only when the CONTROL_AF_MODE is in continuous picture not in auto!
Take care of being really in auto focus mode before performing the trigger.
You should use always session.capture() with all triggers (with CONTROL_AE_PRECAPTURE_TRIGGER too) but always after that remember to put the triggers to IDLE (not cancel) in a session.repeatingRequest()

You can't locus the focus on CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE.
You should put your AF mode on CONTROL_AF_MODE_AUTO adn wait for FOCUSED_LOCKED state during your AF trigger. You can check how the Android focus machine works on enter link description here

Related

C++11 std::chrono::steady_clock issue on Android

I have been using std::chrono::steady_clock for interval calculation in an application i am making for Android platform.
Code:
// On application start
auto timeSinceEpoch = std::chrono::steady_clock::now().time_since_epoch();
auto timeInSec = std::chrono::duration_cast<seconds>(timeSinceEpoch).count();
log("On Enter Start Time Point - %lld", timeInSec);
Output:
On Enter Start Time Point - 521
Now i switch off the phone and restart the phone. I run my application and this time Output is:
On Enter Start Time Point - 114
As per definition at cppreference.com
"Class std::chrono::steady_clock represents a monotonic clock. The time points of this clock cannot decrease as physical time moves forward."
How is the output when i restart the phone giving lesser value?
If anyone has faced this issue please help me out here. Thanks!!
The formal requirement for a steady clock is that the result of a call to now() that happens before another call to now() is always less than or equal to the result of the second call. The happens before relationship only applies to actions within a program run. A steady clock is not required to be steady across different invocations of a program.
On Android, AFAICT steady_clock is the same as (from Java) System.Clock.elapsedRealtime, which resets to zero on boot -- https://developer.android.com/reference/android/os/SystemClock.html
I'm totally failing to dig up the source code for clock_gettime, though. https://android.googlesource.com/platform/ndk.git/+/43255f3d58b03cd931d29d1ee4e5144e86e875ce/sources/cxx-stl/llvm-libc++/libcxx/src/chrono.cpp#124 shows it calling clock_gettime(CLOCK_MONOTONIC), but I'm not sure how to penetrate the veil from there.

Linux/shell command to control screen brightness in android

I am working on a kiosk project using an android tablet.If there is no input power to the kiosk for a long time then, the tablet will eventually shutdown.In order to auto-reboot the tab when the power comes back I modified the code in my tabs battery animation file(ipod) using:
#!/system/bin/sh
sleep 300
/system/bin/reboot
However,during the sleep period(shown above),the tabs screen remains in the ON state (and hence takes longer retries for the tab to charge and bootup).I need to turn the screen OFF.
What is the command I should use prior to the sleep command to turn my tabs screen OFF during the charging/bootup stage. Thanks !
Try this command too,
echo 100 > /sys/devices/platform/nov_cabc.0/leds/lcd-backlight/brightness
or
echo 100 > brightness

Android - callback for MediaRecorder started recording

My app needs to record video with a maximum time of 8 seconds. This is already implemented with MediaRecorder.setMaxDuration(long milliseconds).
The app also needs a progress bar in the top and a label with a count down of the remaining time.
The problem here is that there's an offset between the UI and the MediaRecorder progress, and this leads to confusion in the user. For example, the user thinks that he/she recorded something because the progress in the UI said so, but the media recorder cut off the video a second earlier.
The challenge is to start the progress bar and counter at the exact same time as the recorder actually starts recording.
I've tried starting the timer after MediaRecorder.start(), in a callback when the created file is modified for the first time, but I haven't found a way to achieve this in a correct way. We tried setting a hard coded offset to these values but of course it didn't work the same for every device.
I wish there was a callback from the MediaRecorder to inform that it has actually started to record the video, or maybe the current length.
Is the problem clear? Has someone solved this before?
MediaRecorder has known issues with cutting off audio early. I implemented a recorder with a button - clicking the button to stop the recorder would actually yield an audio file with the last second cut off.
Not sure if your UI offset is a separate issue, but I would try extending the MediaRecorder by half a second after the user attempts to end it. You can either do this by changing the maximum time to 8.5 seconds, or just using this line of code:
android.os.SystemClock.sleep(500);

How is the shutter speed set with the Sony Camera Remote API Beta?

I have a Sony DSC-QX100 with the latest firmware (v3.00) installed. When I send the API call "setShutterSpeed" to the device with any parameter, the result I get is successful return value of 0 in the "result" object of the response JSONArray, which should mean that the call is successful. Yet when I check this with the API call "getShutterSpeed", it always returns the same value ("1/30") as if the shutter speed did not change. Also, when I send the API call "getAvailableShutterSpeed" it always returns an empty list. What could the problem be?
The problem was that the exposure mode was set to "aperture" which means that only the "F number" setting could be manually set. Changing the exposure mode to "shutter" allows the shutter speed to be manually set. Changing it to "intelligent auto" prevents shutter speed, F number, and ISO speed rate from being set manually.

Android - turn off hardware key lights

Inside my app, I need a way to turn off the lights on the standard Android phone keys (Home, Menu, Back, and Search) - how can I do this programmatically?
According to this page, the hardware key backlights can be controlled by writing to a specific file in the filesystem with superuser privileges (i.e. phone must be "rooted"):
Q: How can I control the keyboard
backlight?
A: The keyboard backlight can be
controlled via
/sys/class/leds/keyboard-backlight/brightness.
It appears that it's a simple on-off
control (echoing '0' turns it off,
echoing '1' or higher turns it on).
For some reason, the default system
backlight control stuff seems to set
this to "83", but I don't know why. I
can't seem to see any difference
between 83 and any other number. The
file is readable by anyone, but only
writable by root, so you'll need root
access to the phone to manipulate it
this way.
So to turn off the backlight programmatically, you could invoke exec() on the Runtime like so:
Runtime r = Runtime.getRuntime();
r.exec("echo 0 > /system/class/leds/keyboard-backlight/brightness");
Depends on what you are doing, but would probably be wise to check the result of exec() afterwards to see if a write error occurred.
Note: I tested this on my own phone and it seems to work without acting as root. However, this may not be the case on every phone, so you may have different results.
This is applicable only for the device samsung devices:
To get the BackLight sate:
int backLight = Settings.System.getInt(getContentResolver(), "button_key_light");
// if it return -1 it means that light is on
// if it return 0 the light is off
// some time it will return values like 600(1.5 sec)
if you want to put the backLight as off u can do like this
Settings.System.putInt(getApplicationContext().getContentResolver(), "button_key_light", 0);

Categories

Resources