115 lines
2.8 KiB
C++
115 lines
2.8 KiB
C++
#include "attach_linux/kinect_export.h"
|
|
|
|
#include "contract/contract.h"
|
|
#include "synth/synth.h"
|
|
|
|
namespace attach::linux_attach {
|
|
namespace {
|
|
|
|
using nui::protocol::UsbFunction;
|
|
|
|
constexpr uint16_t kVendorMicrosoft = 0x045e;
|
|
constexpr uint16_t kProductCamera = 0x02ae;
|
|
constexpr uint16_t kProductAudio = 0x02ad;
|
|
constexpr uint16_t kProductMotor = 0x02b0;
|
|
constexpr uint16_t kBcdDevice1414 = 0x010b;
|
|
constexpr uint32_t kSpeedHigh = 3; // Linux enum usb_device_speed::USB_SPEED_HIGH
|
|
|
|
usbip::ExportedDevice camera_device(uint32_t busnum) {
|
|
return usbip::ExportedDevice{
|
|
"/virtual/kinect-v1/camera",
|
|
"1-1",
|
|
busnum,
|
|
1,
|
|
kSpeedHigh,
|
|
kVendorMicrosoft,
|
|
kProductCamera,
|
|
kBcdDevice1414,
|
|
0xff,
|
|
0xff,
|
|
0xff,
|
|
1,
|
|
1,
|
|
{usbip::InterfaceDescriptor{0xff, 0xff, 0xff}},
|
|
};
|
|
}
|
|
|
|
usbip::ExportedDevice audio_device(uint32_t busnum) {
|
|
return usbip::ExportedDevice{
|
|
"/virtual/kinect-v1/audio",
|
|
"1-2",
|
|
busnum,
|
|
2,
|
|
kSpeedHigh,
|
|
kVendorMicrosoft,
|
|
kProductAudio,
|
|
kBcdDevice1414,
|
|
0xff,
|
|
0xff,
|
|
0xff,
|
|
1,
|
|
1,
|
|
{usbip::InterfaceDescriptor{0xff, 0xff, 0xff}, usbip::InterfaceDescriptor{0xff, 0xff, 0xff}},
|
|
};
|
|
}
|
|
|
|
usbip::ExportedDevice motor_device(uint32_t busnum) {
|
|
return usbip::ExportedDevice{
|
|
"/virtual/kinect-v1/motor",
|
|
"1-3",
|
|
busnum,
|
|
3,
|
|
kSpeedHigh,
|
|
kVendorMicrosoft,
|
|
kProductMotor,
|
|
kBcdDevice1414,
|
|
0xff,
|
|
0xff,
|
|
0xff,
|
|
1,
|
|
1,
|
|
{usbip::InterfaceDescriptor{0xff, 0xff, 0xff}},
|
|
};
|
|
}
|
|
|
|
} // namespace
|
|
|
|
ExportSet default_export_set(uint32_t busnum) {
|
|
return ExportSet{{camera_device(busnum), audio_device(busnum), motor_device(busnum)}};
|
|
}
|
|
|
|
UsbFunction function_for_busid(const ExportSet& set, const std::string& busid) {
|
|
for (std::size_t i = 0; i < set.devices.size(); ++i) {
|
|
if (set.devices[i].busid == busid) {
|
|
return static_cast<UsbFunction>(i);
|
|
}
|
|
}
|
|
return UsbFunction::camera;
|
|
}
|
|
|
|
const usbip::ExportedDevice* device_for_busid(const ExportSet& set, const std::string& busid) {
|
|
for (const auto& device : set.devices) {
|
|
if (device.busid == busid) {
|
|
return &device;
|
|
}
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
std::shared_ptr<const nui::protocol::SynthFrame> placeholder_frame_source() {
|
|
static const std::shared_ptr<const nui::protocol::SynthFrame> frame = [] {
|
|
auto built = std::make_shared<nui::protocol::SynthFrame>();
|
|
nui::synth::DepthRasterizer rasterizer;
|
|
built->depth = rasterizer.rasterize(
|
|
nui::synth::SegmentationMask{},
|
|
nui::contract::SkeletonFrame{},
|
|
nui::synth::DepthRasterRequest{{640, 480}, 0});
|
|
built->color = nui::synth::passthrough_color(nui::synth::BgraFrame{}, {640, 480});
|
|
built->metadata.frame_number = 0;
|
|
return built;
|
|
}();
|
|
return frame;
|
|
}
|
|
|
|
} // namespace attach::linux_attach
|