The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

d/wmr: Bracemaggedon

+36 -16
+36 -16
src/xrt/drivers/wmr/wmr_camera.c
··· 132 132 133 133 for (i = 0; i < cam->config_count; i++) { 134 134 const struct wmr_camera_config *config = &cam->configs[i]; 135 - if (config->purpose != WMR_CAMERA_PURPOSE_HEAD_TRACKING) 135 + if (config->purpose != WMR_CAMERA_PURPOSE_HEAD_TRACKING) { 136 136 continue; 137 + } 137 138 138 139 WMR_CAM_DEBUG(cam, "Found head tracking camera index %d width %d height %d", i, config->sensor_width, 139 140 config->sensor_height); ··· 153 154 F += config->sensor_width * (config->sensor_height + 1); 154 155 } 155 156 156 - if (cams_found == 0) 157 + if (cams_found == 0) { 157 158 return false; 159 + } 158 160 159 - if (width < 1280 || height < 480) 161 + if (width < 1280 || height < 480) { 160 162 return false; 163 + } 161 164 162 165 n_packets = F / (0x6000 - 32); 163 166 leftover = F - n_packets * (0x6000 - 32); ··· 199 202 uint8_t *data; 200 203 201 204 xfer = libusb_alloc_transfer(0); 202 - if (xfer == NULL) 205 + if (xfer == NULL) { 203 206 return LIBUSB_ERROR_NO_MEM; 207 + } 204 208 205 209 data = malloc(len); 206 210 if (data == NULL) { ··· 313 317 } 314 318 315 319 res = libusb_init(&cam->ctx); 316 - if (res < 0) 320 + if (res < 0) { 317 321 goto fail; 322 + } 318 323 319 324 cam->dev = libusb_open_device_with_vid_pid(cam->ctx, dev_holo->vendor_id, dev_holo->product_id); 320 - if (cam->dev == NULL) 325 + if (cam->dev == NULL) { 321 326 goto fail; 327 + } 322 328 323 329 res = libusb_claim_interface(cam->dev, 3); 324 - if (res < 0) 330 + if (res < 0) { 325 331 goto fail; 332 + } 326 333 327 334 cam->usb_complete = 0; 328 335 if (os_thread_helper_start(&cam->usb_thread, wmr_cam_usb_thread, cam) != 0) { ··· 346 353 u_var_add_sink_debug(cam, &cam->debug_sinks[1], "Controllers"); 347 354 348 355 return cam; 356 + 349 357 350 358 fail: 351 359 WMR_CAM_ERROR(cam, "Failed to open camera: %s", libusb_error_name(res)); ··· 372 380 cam->usb_complete = 1; 373 381 os_thread_helper_unlock(&cam->usb_thread); 374 382 375 - if (cam->dev != NULL) 383 + if (cam->dev != NULL) { 376 384 libusb_close(cam->dev); 385 + } 377 386 378 387 os_thread_helper_destroy(&cam->usb_thread); 379 388 ··· 401 410 } 402 411 403 412 res = set_active(cam, false); 404 - if (res < 0) 413 + if (res < 0) { 405 414 goto fail; 415 + } 406 416 407 417 res = set_active(cam, true); 408 - if (res < 0) 418 + if (res < 0) { 409 419 goto fail; 420 + } 410 421 411 422 for (i = 0; i < cam->config_count; i++) { 412 423 const struct wmr_camera_config *config = &cam->configs[i]; 413 - if (config->purpose != WMR_CAMERA_PURPOSE_HEAD_TRACKING) 424 + if (config->purpose != WMR_CAMERA_PURPOSE_HEAD_TRACKING) { 414 425 continue; 426 + } 415 427 416 428 res = wmr_camera_set_gain(cam, config->location, DEFAULT_GAIN); 417 429 if (res < 0) { ··· 427 439 cam->xfers[i]->flags |= LIBUSB_TRANSFER_FREE_BUFFER; 428 440 429 441 res = libusb_submit_transfer(cam->xfers[i]); 430 - if (res < 0) 442 + if (res < 0) { 431 443 goto fail; 444 + } 432 445 } 433 446 434 447 WMR_CAM_INFO(cam, "WMR camera started"); 435 448 436 449 return true; 450 + 437 451 438 452 fail: 439 453 if (res < 0) ··· 447 461 { 448 462 int res, i; 449 463 450 - if (!cam->running) 464 + if (!cam->running) { 451 465 return true; 466 + } 452 467 cam->running = false; 453 468 454 469 for (i = 0; i < NUM_XFERS; i++) { 455 - if (cam->xfers[i] != NULL) 470 + if (cam->xfers[i] != NULL) { 456 471 libusb_cancel_transfer(cam->xfers[i]); 472 + } 457 473 } 458 474 459 475 res = set_active(cam, false); 460 - if (res < 0) 476 + if (res < 0) { 461 477 goto fail; 478 + } 462 479 463 480 WMR_CAM_INFO(cam, "WMR camera stopped"); 464 481 465 482 return true; 466 483 484 + 467 485 fail: 468 - if (res < 0) 486 + if (res < 0) { 469 487 WMR_CAM_ERROR(cam, "Error stopping camera input: %s", libusb_error_name(res)); 488 + } 489 + 470 490 return false; 471 491 } 472 492