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");
46 LOGE("UVCCamera::open");
50 uvc_device_handle_t *devh;
53 if((res = uvc_init(&ctx, NULL)) < 0){
54 uvc_perror(res, "unc_init");
57 LOGE("UVC Initialized");
59 if ((res = uvc_find_device(ctx, &dev, 0, 0, NULL)) < 0){
60 uvc_perror(res, "uvc_find_device");
65 if ((res = uvc_open(dev, &devh)) < 0){
66 uvc_perror(res, "uvc_open");
70 LOGE("Device Opened");
71 uvc_print_diag(devh, stderr);