CameraDriver::~CameraDriver() {
  if (rgb_frame_)
    uvc_free_frame(rgb_frame_);

  if (ctx_)
    uvc_exit(ctx_);  // Destroys dev_, devh_, etc.
}
Example #2
0
UVCCamera::~UVCCamera() {
	ENTER();
	release();
	if (mContext) {
		uvc_exit(mContext);
		mContext = NULL;
	}
	if (mUsbFs) {
		free(mUsbFs);
		mUsbFs = NULL;
	}
	EXIT();
}
void CameraDriver::Stop() {
  boost::recursive_mutex::scoped_lock(mutex_);

  assert(state_ != kInitial);

  if (state_ == kRunning)
    CloseCamera();

  assert(state_ == kStopped);

  uvc_exit(ctx_);
  ctx_ = NULL;

  state_ = kInitial;
}
Example #4
0
void RealSenseDriver::Stop()
{
  std::cout << "Stopping RealSense driver" << std::endl;

  /*
    if(streamh_rgb) {
        uvc_stream_close(streamh_rgb);
    }

    if(streamh_d) {
        uvc_stream_close(streamh_d);
    }
  */
    std::cout << "Closed streams" << std::endl;

    if (frame_rgb) {
        uvc_free_frame(frame_rgb);
        frame_rgb = 0;
    }    

    if (frame_d) {
        uvc_free_frame(frame_d);
        frame_d = 0;
    }
  
    std::cout << "Released frames" << std::endl;

    /* Release the device descriptor, shutdown UVC */
    uvc_close(devh_rgb);
    uvc_close(devh_d);

    std::cout << "Closed devices" << std::endl;

    
    uvc_unref_device(dev_);
    std::cout << "Unreffed device" << std::endl;


    uvc_exit(ctx_);
    dev_ = 0;

    std::cout << "Stop of RealSense driver complete" << std::endl;
 
}
Example #5
0
            /* query UVC devices on the system */
            std::vector<uvc_device_info> query_uvc_devices() const override
            {
                uvc_error_t res;
                uvc_context_t *ctx;

                // init libUVC.
                res = uvc_init(&ctx, NULL);

                if (res < 0) {
                    throw linux_backend_exception("fail to initialize libuvc");
                }
                // build a list of uvc devices.
                std::vector<uvc_device_info> results;
                libuvc_uvc_device::foreach_uvc_device(ctx,
                        [&results](const uvc_device_info& i, const std::string&)
                        {
                            results.push_back(i);
                        });

                uvc_exit(ctx);
                return results;
            }
int main(int argc, char **argv) {
  uvc_context_t *ctx;
  uvc_device_t *dev;
  uvc_device_handle_t *devh;
  uvc_stream_ctrl_t ctrl;
  uvc_error_t res;
  uvc_device_t **list;

  /* Initialize a UVC service context. Libuvc will set up its own libusb
   * context. Replace NULL with a libusb_context pointer to run libuvc
   * from an existing libusb context. */
  res = uvc_init(&ctx, NULL);


  if (res < 0) {
    uvc_perror(res, "uvc_init");
    return res;
  }
  puts("UVC initialized");
  res = uvc_get_device_list(ctx, &list);
  if (res < 0) {
    uvc_perror(res, "uvc_get_device_list");
    return res;
  }

/*  for(int i = 0; i < 1; i++) {
	 res = uvc_open(list[i], &devh);
	 uvc_print_diag(devh, stderr);
	 uvc_close(devh);
  }
  uchar x;
  uvc_free_device_list(list, x);
*/
  /* Locates the first attached UVC device, stores in dev */
  res = uvc_find_device(
      ctx, &dev,
      0, 0, NULL); /* filter devices: vendor_id, product_id, "serial_num" */

  if (res < 0) {
    uvc_perror(res, "uvc_find_device"); /* no devices found */
  } else {
    puts("Device found");

    /* Try to open the device: requires exclusive access */
    res = uvc_open(dev, &devh);

    if (res < 0) {
      uvc_perror(res, "uvc_open"); /* unable to open device */
      printf("Unable to open device");
    } else {
      puts("Device opened");

      /* Print out a message containing all the information that libuvc
       * knows about the device */
      uvc_print_diag(devh, stderr);

      /* Try to negotiate a 640x480 30 fps YUYV stream profile */
      res = uvc_get_stream_ctrl_format_size(
          devh, &ctrl, /* result stored in ctrl */
          UVC_FRAME_FORMAT_YUYV, /* YUV 422, aka YUV 4:2:2. try _COMPRESSED */
          640, 480, 30 /* width, height, fps */
      );

      /* Print out the result */
      uvc_print_stream_ctrl(&ctrl, stderr);

      if (res < 0) {
        uvc_perror(res, "get_mode"); /* device doesn't provide a matching stream */
      } else {
        /* Start the video stream. The library will call user function cb:
         *   cb(frame, (void*) 12345)
         */
        res = uvc_start_streaming(devh, &ctrl, cb, (void*)12345, 0);

        if (res < 0) {
          uvc_perror(res, "start_streaming"); /* unable to start stream */
        } else {
          puts("Streaming...");

          uvc_set_ae_mode(devh, 0); /* e.g., turn on auto exposure */

          sleep(10); /* stream for 10 seconds */

          /* End the stream. Blocks until last callback is serviced */
          uvc_stop_streaming(devh);
          puts("Done streaming.");
        }
      }

      /* Release our handle on the device */
      uvc_close(devh);
      puts("Device closed");
    }

    /* Release the device descriptor */
    uvc_unref_device(dev);
  }

  /* Close the UVC context. This closes and cleans up any existing device handles,
   * and it closes the libusb context if one was not provided. */
  uvc_exit(ctx);
  puts("UVC exited");

  return 0;
}
Example #7
0
 ~libuvc_uvc_device()
 {
     _is_capturing = false;
     uvc_exit(_ctx);
 }
Example #8
0
 ~context() { if(ctx) uvc_exit(ctx); }