stream pushing ok without access permission of /dev/video0
[rtmpclient.git] / app / src / main / jni / UVCCamera.cpp
index c7c5146..4fcd525 100644 (file)
@@ -41,7 +41,7 @@ void UVCCamera::init()
     LOGE("UVCCamera::init");
 }
 
-int UVCCamera::open()
+int UVCCamera::open(int vid, int pid, int fd, int busnum, int devaddr, const char* usbFsName)
 {
     LOGE("UVCCamera::open");
 
@@ -50,25 +50,42 @@ int UVCCamera::open()
     uvc_device_handle_t *devh;
     uvc_error_t res;
 
-    if((res = uvc_init(&ctx, NULL)) < 0){
+    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");
+//    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("Device Found");
+    LOGE("uvc_get_device_with_fd");
+
+       //uvc_print_diag(mDeviceHandle, stderr);
     
     if ((res = uvc_open(dev, &devh)) < 0){
-        uvc_perror(res, "uvc_open");
+        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_print_diag(devh, stderr);
 
     uvc_exit(ctx);
     return 1;