void set_power_state(power_state state) override { uvc_error_t res; uvc_format_t *formats; /* if power became on and it was originally off. open the uvc device. */ if (state == D0 && _state == D3) { res = uvc_find_device(_ctx, &_device, _info.vid, _info.pid, NULL); if (res < 0) { throw linux_backend_exception( "Could not find the device."); } res = uvc_open2(_device, &_device_handle, _interface); if (res < 0) { uvc_unref_device(_device); _device = NULL; throw linux_backend_exception( "Could not open device."); } } else { // we have been asked to close the device. uvc_unref_device(_device); uvc_stop_streaming(_device_handle); _profiles.clear(); uvc_close(_device_handle); _device = NULL; _device_handle = NULL; } _state = state; }
void UVCPreview::do_preview(uvc_stream_ctrl_t *ctrl) { ENTER(); uvc_frame_t *frame = NULL; uvc_error_t result = uvc_start_iso_streaming( mDeviceHandle, ctrl, uvc_preview_frame_callback, (void *)this); if (LIKELY(!result)) { clearPreviewFrame(); pthread_create(&capture_thread, NULL, capture_thread_func, (void *)this); #if LOCAL_DEBUG LOGI("Streaming..."); #endif while (LIKELY(isRunning())) { frame = waitPreviewFrame(); if (LIKELY(frame)) { frame = draw_preview_one(frame, &mPreviewWindow, uvc_any2rgbx, 4); addCaptureFrame(frame); } } pthread_cond_signal(&capture_sync); #if LOCAL_DEBUG LOGI("preview_thread_func:wait for all callbacks complete"); #endif uvc_stop_streaming(mDeviceHandle); #if LOCAL_DEBUG LOGI("Streaming finished"); #endif } else { uvc_perror(result, "failed start_streaming"); } EXIT(); }
void stop_streaming(device & device) { // Stop all streaming for(auto & sub : device.subdevices) { if(sub.handle) uvc_stop_streaming(sub.handle); sub.ctrl = {}; sub.callback = {}; } }
void UvcDriver::Stop() { if(devh_) { uvc_stop_streaming(devh_); devh_ = 0; dev_ = 0; } if (frame_) { uvc_free_frame(frame_); frame_ = 0; } // if (ctx_) { // // Work out how to kill this properly // uvc_exit(ctx_); // ctx_ = 0; // } }
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; }
void UvcVideo::Stop() { if(devh_) { uvc_stop_streaming(devh_); } }