| 819 | } |
| 820 | |
| 821 | bool Freenect2DeviceImpl::open() |
| 822 | { |
| 823 | LOG_INFO << "opening..."; |
| 824 | |
| 825 | if(state_ != Created) return false; |
| 826 | |
| 827 | if(usb_control_.setConfiguration() != UsbControl::Success) return false; |
| 828 | if(!has_usb_interfaces_ && usb_control_.claimInterfaces() != UsbControl::Success) return false; |
| 829 | has_usb_interfaces_ = true; |
| 830 | |
| 831 | if(usb_control_.setIsochronousDelay() != UsbControl::Success) return false; |
| 832 | // TODO: always fails right now with error 6 - TRANSFER_OVERFLOW! |
| 833 | //if(usb_control_.setPowerStateLatencies() != UsbControl::Success) return false; |
| 834 | if(usb_control_.setIrInterfaceState(UsbControl::Disabled) != UsbControl::Success) return false; |
| 835 | if(usb_control_.enablePowerStates() != UsbControl::Success) return false; |
| 836 | if(usb_control_.setVideoTransferFunctionState(UsbControl::Disabled) != UsbControl::Success) return false; |
| 837 | |
| 838 | int max_iso_packet_size; |
| 839 | if(usb_control_.getIrMaxIsoPacketSize(max_iso_packet_size) != UsbControl::Success) return false; |
| 840 | |
| 841 | if(max_iso_packet_size < 0x8400) |
| 842 | { |
| 843 | LOG_ERROR << "max iso packet size for endpoint 0x84 too small! (expected: " << 0x8400 << " got: " << max_iso_packet_size << ")"; |
| 844 | return false; |
| 845 | } |
| 846 | |
| 847 | unsigned rgb_xfer_size = 0x4000; |
| 848 | unsigned rgb_num_xfers = 20; |
| 849 | unsigned ir_pkts_per_xfer = 8; |
| 850 | unsigned ir_num_xfers = 60; |
| 851 | |
| 852 | #if defined(__APPLE__) |
| 853 | ir_pkts_per_xfer = 128; |
| 854 | ir_num_xfers = 4; |
| 855 | #elif defined(_WIN32) || defined(__WIN32__) || defined(__WINDOWS__) |
| 856 | // For multi-Kinect setup, there is a 64 fd limit on poll(). |
| 857 | rgb_xfer_size = 1048576; |
| 858 | rgb_num_xfers = 3; |
| 859 | ir_pkts_per_xfer = 64; |
| 860 | ir_num_xfers = 8; |
| 861 | #endif |
| 862 | |
| 863 | const char *xfer_str; |
| 864 | xfer_str = std::getenv("LIBFREENECT2_RGB_TRANSFER_SIZE"); |
| 865 | if(xfer_str) rgb_xfer_size = std::atoi(xfer_str); |
| 866 | xfer_str = std::getenv("LIBFREENECT2_RGB_TRANSFERS"); |
| 867 | if(xfer_str) rgb_num_xfers = std::atoi(xfer_str); |
| 868 | xfer_str = std::getenv("LIBFREENECT2_IR_PACKETS"); |
| 869 | if(xfer_str) ir_pkts_per_xfer = std::atoi(xfer_str); |
| 870 | xfer_str = std::getenv("LIBFREENECT2_IR_TRANSFERS"); |
| 871 | if(xfer_str) ir_num_xfers = std::atoi(xfer_str); |
| 872 | |
| 873 | LOG_INFO << "transfer pool sizes" |
| 874 | << " rgb: " << rgb_num_xfers << "*" << rgb_xfer_size |
| 875 | << " ir: " << ir_num_xfers << "*" << ir_pkts_per_xfer << "*" << max_iso_packet_size; |
| 876 | rgb_transfer_pool_.allocate(rgb_num_xfers, rgb_xfer_size); |
| 877 | ir_transfer_pool_.allocate(ir_num_xfers, ir_pkts_per_xfer, max_iso_packet_size); |
| 878 |
no test coverage detected