-//
-// Created by Peng Li on 14/5/2018.
-//
-
-#include "UVCCamera.h"
-//#include <jni.h>
-#include "log.h"
-#include "libuvc/libuvc.h"
-
-
-
-UVCCamera::~UVCCamera()
-{
-}
-
-//jint UVCCamera::nativeOnLoad(JavaVM *jvm, void* reserved)
-//{
- // N.B. within the context of a JVM thread here
- // get a JNIEnv by attempting to get it directly
-// JNIEnv *env;
-// if (jvm) jvm->GetEnv (reinterpret_cast<void**>(&env), JNI_VERSION_1_2);
-
- // get a handle to the Java class in the JVM
- // and cache it becuse FindClass doesn't work in native worker threads because Java is stupid
- // http://developer.android.com/training/articles/perf-jni.html#faq_FindClass
-// jclass local_ref = 0;
-// if (env) local_ref = env->FindClass ("com/cisco/ecc/testapp/EccTestApp");
-// jclass global_ref = reinterpret_cast<jclass> (env->NewGlobalRef (local_ref));
-
- // Create the singleton
-// singleton.reset (new EccTestApp (jvm, global_ref));
-
- // return the JNI version needed. I think we can basicaly return anything other than 1.1 here
- // unless it turns out we need some specific JNI methods from a later version
-// return JNI_VERSION_1_2;
- // return 0;
-//}
-
-void UVCCamera::init()
-{
- LOGE("UVCCamera::init");
-}
-
-int UVCCamera::open(int vid, int pid, int fd, int busnum, int devaddr, const char* usbFsName)
-{
- LOGE("UVCCamera::open");
-
- uvc_context_t *ctx;
- uvc_device_t *dev;
- uvc_device_handle_t *devh;
- uvc_error_t res;
-
- char *mUsbFs = strdup(usbFsName);
-
- fd = dup(fd);
- res = uvc_init2(&ctx, NULL, mUsbFs);
- if(res < 0){
-// if((res = uvc_init(&ctx, NULL)) < 0){
- uvc_perror(res, "unc_init");
- return res;
- }
- LOGE("UVC Initialized");
-
-// if ((res = uvc_find_device(ctx, &dev, 0, 0, NULL)) < 0){
-// uvc_perror(res, "uvc_find_device");
-// return res;
-// }
-// LOGE("Device Found");
-//
-
- res = uvc_get_device_with_fd(ctx, &dev, vid, pid, NULL, fd, busnum, devaddr);
- if (res < 0){
- LOGE("uvc_get_device_with_fd: %d", __LINE__);
- uvc_perror(res, uvc_strerror(res));
- LOGE("uvc_get_device_with_fd error: %s(%d)", uvc_strerror(res), res);
- return res;
- }
- LOGE("uvc_get_device_with_fd");
-
- //uvc_print_diag(mDeviceHandle, stderr);
-
- if ((res = uvc_open(dev, &devh)) < 0){
- uvc_perror(res, uvc_strerror(res));
- LOGE("uvc_open error: %s(%d)", uvc_strerror(res), res);
- return res;
- }
- LOGE("Device Opened");
-// uvc_print_diag(devh, stderr);
-
- uvc_exit(ctx);
- return 1;
-}