UVCCamera向USB设备发送命令
Posted 柳鲲鹏
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UVCCamera向USB设备发送命令相关的知识,希望对你有一定的参考价值。
改变亮度
- JAVA
UVCCameraHelper.setModelValue()
UVCCameraHandler.setValue()
UVCCamera.setBrightness()
nativeSetBrightness()
-
nativeSetBrightness
static jint nativeSetBrightness(JNIEnv *env, jobject thiz,
ID_TYPE id_camera, jint brightness)
jint result = JNI_ERR;
ENTER();
UVCCamera *camera = reinterpret_cast<UVCCamera *>(id_camera);
if (LIKELY(camera))
result = camera->setBrightness(brightness);
RETURN(result, jint);
-
setBrightness
int UVCCamera::setBrightness(int brightness)
ENTER();
int ret = UVC_ERROR_IO;
if (mPUSupports & PU_BRIGHTNESS)
ret = internalSetCtrlValue(mBrightness, brightness, uvc_get_brightness, uvc_set_brightness);
RETURN(ret, int);
-
uvc_set_brightness
uvc_error_t uvc_set_brightness(uvc_device_handle_t *devh, short brightness)
uint8_t data[2];
uvc_error_t ret;
SHORT_TO_SW(brightness, data);
ret = libusb_control_transfer(devh->usb_devh, REQ_TYPE_SET, UVC_SET_CUR,
UVC_PU_BRIGHTNESS_CONTROL << 8,
devh->info->ctrl_if.processing_unit_descs->request,
data, sizeof(data), CTRL_TIMEOUT_MILLIS);
if (LIKELY(ret == sizeof(data)))
return UVC_SUCCESS;
else
return ret;
-
libusb_control_transfer
int API_EXPORTED libusb_control_transfer(libusb_device_handle *dev_handle,
uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex,
unsigned char *data, uint16_t wLength, unsigned int timeout)
struct libusb_transfer *transfer = libusb_alloc_transfer(0);
unsigned char *buffer;
int completed = 0;
int r;
if (UNLIKELY(!transfer))
return LIBUSB_ERROR_NO_MEM;
buffer = (unsigned char*) malloc(LIBUSB_CONTROL_SETUP_SIZE + wLength);
if (UNLIKELY(!buffer))
libusb_free_transfer(transfer);
return LIBUSB_ERROR_NO_MEM;
libusb_fill_control_setup(buffer, bmRequestType, bRequest, wValue, wIndex, wLength);
if ((bmRequestType & LIBUSB_ENDPOINT_DIR_MASK) == LIBUSB_ENDPOINT_OUT)
memcpy(buffer + LIBUSB_CONTROL_SETUP_SIZE, data, wLength);
libusb_fill_control_transfer(transfer, dev_handle, buffer,
sync_transfer_cb, &completed, timeout);
transfer->flags = LIBUSB_TRANSFER_FREE_BUFFER;
r = libusb_submit_transfer(transfer);
if (UNLIKELY(r < 0))
libusb_free_transfer(transfer);
return r;
sync_transfer_wait_for_completion(transfer);
if ((bmRequestType & LIBUSB_ENDPOINT_DIR_MASK) == LIBUSB_ENDPOINT_IN)
memcpy(data, libusb_control_transfer_get_data(transfer),
transfer->actual_length);
libusb_free_transfer(transfer);
return r;
- libusb_submit_transfer
r = usbi_backend.submit_transfer(itransfer);
-
op_submit_transfer
LIBUSB_TRANSFER_TYPE_BULK = 2U
submit_bulk_transfer
-
submit_bulk_transfer
ioctl
以上是关于UVCCamera向USB设备发送命令的主要内容,如果未能解决你的问题,请参考以下文章
对UVCCamera的改进----解决某些设备无法识别摄像头等bug
对UVCCamera的改进----解决某些设备无法识别摄像头等bug
解决UVCamera stopPreview阻塞崩溃以及无法识别摄像头等bug