问题
I have one Camera2 NDK code to open the camera and get images.
The code work fine via Android Application/Service, but if I compile and run it as executable the camera opened but I don't get any frames.
Any idea? someone succeeded to do it?
NOTE
- I create my own AImageReader via "AImageReader_new"
- I create my own ANativeWindow via "AImageReader_getWindow"
NOTE2 (ADDED)
The calls is a little different
For Android Application/Service the calls like:
public void onCreate() {
JNIBridge.startPreview(null);
}
public void onDestroy() {
JNIBridge.stopPreview();
}
For the executable:
int main()
{
Java_com_y30_nativecamera2_JNIBridge_startPreview(nullptr, nullptr, nullptr);
for(int i = 0; i < 10; ++i)
{
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
}
Java_com_y30_nativecamera2_JNIBridge_stopPreview(nullptr, nullptr);
return 0;
}
UPDATE
I tested it again on multi Android devices.
S8/S9+ (With Andorid 8.0.0) it's reproduce.("ACameraManager_openCamera" status is OK, but I don't get any frames)
Pixel (With Android 9) the method "ACameraManager_openCamera" failed.
10-09 10:45:04.933 933 1592 I CameraService: CameraService::connect call (PID -1 "", camera ID 0) for HAL version default and Camera API version 2
10-09 10:45:04.933 933 1592 W ServiceManager: Permission failure: android.permission.CAMERA from uid=2000 pid=19606
10-09 10:45:04.933 933 1592 E CameraService: Permission Denial: can't use the camera pid=19606, uid=2000
10-09 10:45:04.933 19606 19606 E ACameraManager: openCamera: connect camera device failed: Status(-8): '1: validateClientPermissionsLocked:906: Caller "" (PID 2000, UID 19606) cannot open camera "0" without camera permission'
UPDATE2
I tested it also with msm8996 EVB (With Android 7.1.1):
(1) I get permission issue like the Pixel2.
(2) I ran it with su and the permission issue fixed (the camera opened) but I already don't get any images.
回答1:
I have not seen your code. From your description, you have done everything right. If you add the following, it should work.
#include <binder/ProcessState.h>
...
main()
{
...
android::ProcessState::self()->startThreadPool();
...
Camera open, AImageReader_new, etc ...
...
Close Camera
...
}
Also add libbinder to Android.mk LOCAL_SHARED_LIBRARIES.
回答2:
In general, the NDK does not support Android shell executables, so its use is probably blocked by your devices SELinux policy in some way.
来源:https://stackoverflow.com/questions/52710811/android-camera2-executable-failed-to-get-frames