add user input
[rtmpclient.git] / app / src / main / jni / UVCCamera.cpp
1 //
2 // Created by Peng Li on 14/5/2018.
3 //
4
5 #include "UVCCamera.h"
6 //#include <jni.h>
7 #include "log.h"
8 #include "libuvc/libuvc.h"
9
10
11
12 UVCCamera::~UVCCamera()
13 {
14 }
15
16 //jint UVCCamera::nativeOnLoad(JavaVM *jvm, void* reserved)
17 //{    
18     // N.B. within the context of a JVM thread here
19     // get a JNIEnv by attempting to get it directly
20 //    JNIEnv *env;
21 //    if (jvm) jvm->GetEnv (reinterpret_cast<void**>(&env), JNI_VERSION_1_2);
22
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));
29
30     // Create the singleton
31 //    singleton.reset (new EccTestApp (jvm, global_ref));
32
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;
36  //   return 0;
37 //}
38
39 void UVCCamera::init()
40 {
41     LOGE("UVCCamera::init");
42 }
43
44 int UVCCamera::open()
45 {
46     LOGE("UVCCamera::open");
47
48     uvc_context_t *ctx;
49     uvc_device_t *dev;
50     uvc_device_handle_t *devh;
51     uvc_error_t res;
52
53     if((res = uvc_init(&ctx, NULL)) < 0){
54         uvc_perror(res, "unc_init");
55         return res;
56     }
57     LOGE("UVC Initialized");
58
59     if ((res = uvc_find_device(ctx, &dev, 0, 0, NULL)) < 0){
60         uvc_perror(res, "uvc_find_device");
61         return res;
62     }
63     LOGE("Device Found");
64     
65     if ((res = uvc_open(dev, &devh)) < 0){
66         uvc_perror(res, "uvc_open");
67         return res;
68     }
69
70     LOGE("Device Opened");
71     uvc_print_diag(devh, stderr);
72
73     uvc_exit(ctx);
74     return 1;
75 }