# 多设备同步示例-MultiDeviceSync
功能描述:演示多设备同步操作。
>本示例基于C++ low Level API进行演示
配置程序模式
std::cout << "Please select options: " << std::endl;
std::cout << " 0 --> config devices" << std::endl;
std::cout << " 1 --> start stream" << std::endl;
std::cout << "input: ";
int index = -1;
std::cin >> index;
配置多设备同步
exitValue = configMultiDeviceSync();
区分主从设备
streamDevList.clear();
// Query the list of connected devices
auto devList = context.queryDeviceList();
// Get the number of connected devices
int devCount = devList->deviceCount();
for(int i = 0; i < devCount; i++) {
streamDevList.push_back(devList->getDevice(i));
}
if(streamDevList.empty()) {
std::cerr << "Device list is empty. please check device connection state" << std::endl;
return -1;
}
// traverse the device list and create the device
std::vector
std::vector
for(auto dev: streamDevList) {
auto config = dev->getMultiDeviceSyncConfig();
if(config.syncMode == OB_MULTI_DEVICE_SYNC_MODE_PRIMARY) {
primary_devices.push_back(dev);
}
else {
secondary_devices.push_back(dev);
}
}
开启从设备
std::cout << "Secondary devices start..." << std::endl;
int deviceIndex = 0; // Sencondary device display first
for(auto itr = secondary_devices.begin(); itr != secondary_devices.end(); itr++) {
auto depthHolder = createPipelineHolder(*itr, OB_SENSOR_DEPTH, deviceIndex);
pipelineHolderList.push_back(depthHolder);
startStream(depthHolder);
auto colorHolder = createPipelineHolder(*itr, OB_SENSOR_COLOR, deviceIndex);
pipelineHolderList.push_back(colorHolder);
startStream(colorHolder);
deviceIndex++;
}
开启主设备
std::cout << "Primary device start..." << std::endl;
deviceIndex = secondary_devices.size(); // Primary device display after primary devices.
for(auto itr = primary_devices.begin(); itr != primary_devices.end(); itr++) {
auto depthHolder = createPipelineHolder(*itr, OB_SENSOR_DEPTH, deviceIndex);
startStream(depthHolder);
pipelineHolderList.push_back(depthHolder);
auto colorHolder = createPipelineHolder(*itr, OB_SENSOR_COLOR, deviceIndex);
startStream(colorHolder);
pipelineHolderList.push_back(colorHolder);
deviceIndex++;
}
设置多设备同步间隔时间
// Start the multi-device time synchronization function
context.enableDeviceClockSync(3600000); // update and sync every hour
进行多设备测试
testMultiDeviceSync();
关闭数据流
// close data stream
for(auto itr = pipelineHolderList.begin(); itr != pipelineHolderList.end(); itr++) {
stopStream(*itr);
}