2 // Created by Peng Li on 14/5/2018.
8 #include "libuvc/libuvc.h"
12 UVCCamera::~UVCCamera()
16 //jint UVCCamera::nativeOnLoad(JavaVM *jvm, void* reserved)
18 // N.B. within the context of a JVM thread here
19 // get a JNIEnv by attempting to get it directly
21 // if (jvm) jvm->GetEnv (reinterpret_cast<void**>(&env), JNI_VERSION_1_2);
23 // get a handle to the Java class in the JVM
24 // and cache it becuse FindClass doesn't work in native worker threads because Java is stupid
25 // http://developer.android.com/training/articles/perf-jni.html#faq_FindClass
26 // jclass local_ref = 0;
27 // if (env) local_ref = env->FindClass ("com/cisco/ecc/testapp/EccTestApp");
28 // jclass global_ref = reinterpret_cast<jclass> (env->NewGlobalRef (local_ref));
30 // Create the singleton
31 // singleton.reset (new EccTestApp (jvm, global_ref));
33 // return the JNI version needed. I think we can basicaly return anything other than 1.1 here
34 // unless it turns out we need some specific JNI methods from a later version
35 // return JNI_VERSION_1_2;
39 void UVCCamera::init()
41 LOGE("UVCCamera::init");
44 int UVCCamera::open(int vid, int pid, int fd, int busnum, int devaddr, const char* usbFsName)
46 LOGE("UVCCamera::open");
50 uvc_device_handle_t *devh;
53 char *mUsbFs = strdup(usbFsName);
56 res = uvc_init2(&ctx, NULL, mUsbFs);
58 // if((res = uvc_init(&ctx, NULL)) < 0){
59 uvc_perror(res, "unc_init");
62 LOGE("UVC Initialized");
64 // if ((res = uvc_find_device(ctx, &dev, 0, 0, NULL)) < 0){
65 // uvc_perror(res, "uvc_find_device");
68 // LOGE("Device Found");
71 res = uvc_get_device_with_fd(ctx, &dev, vid, pid, NULL, fd, busnum, devaddr);
73 LOGE("uvc_get_device_with_fd: %d", __LINE__);
74 uvc_perror(res, uvc_strerror(res));
75 LOGE("uvc_get_device_with_fd error: %s(%d)", uvc_strerror(res), res);
78 LOGE("uvc_get_device_with_fd");
80 //uvc_print_diag(mDeviceHandle, stderr);
82 if ((res = uvc_open(dev, &devh)) < 0){
83 uvc_perror(res, uvc_strerror(res));
84 LOGE("uvc_open error: %s(%d)", uvc_strerror(res), res);
87 LOGE("Device Opened");
88 // uvc_print_diag(devh, stderr);