|
1 | 1 | /************************************************************************************************** |
2 | 2 | * THE OMICRON PROJECT |
3 | 3 | *------------------------------------------------------------------------------------------------- |
4 | | -* Copyright 2010-2016 Electronic Visualization Laboratory, University of Illinois at Chicago |
| 4 | +* Copyright 2010-2019 Electronic Visualization Laboratory, University of Illinois at Chicago |
5 | 5 | * Authors: |
6 | 6 | * Arthur Nishimoto [email protected] |
7 | 7 | *------------------------------------------------------------------------------------------------- |
8 | | -* Copyright (c) 2010-2016, Electronic Visualization Laboratory, University of Illinois at Chicago |
| 8 | +* Copyright (c) 2010-2019, Electronic Visualization Laboratory, University of Illinois at Chicago |
9 | 9 | * All rights reserved. |
10 | 10 | * Redistribution and use in source and binary forms, with or without modification, are permitted |
11 | 11 | * provided that the following conditions are met: |
@@ -72,7 +72,7 @@ MSKinectService::MSKinectService(){ |
72 | 72 | void MSKinectService::setup(Setting& settings) |
73 | 73 | { |
74 | 74 | myUpdateInterval = Config::getFloatValue("updateInterval", settings, 0.01f); |
75 | | - myCheckKinectInterval = Config::getFloatValue("checkInterval", settings, 2.00f); |
| 75 | + myCheckKinectInterval = Config::getFloatValue("imageStreamInterval", settings, 0.2f); |
76 | 76 |
|
77 | 77 | m_bSeatedMode = Config::getBoolValue("seatedMode", settings, false); |
78 | 78 |
|
@@ -145,13 +145,57 @@ void MSKinectService::poll() |
145 | 145 | { |
146 | 146 | pollBody(); |
147 | 147 | } |
148 | | - if (enableKinectColor) |
| 148 | + |
| 149 | + float lastt = lastUpdateTime; |
| 150 | + |
| 151 | + float curt = (float)((double)clock() / CLOCKS_PER_SEC); |
| 152 | + if (curt - lastt > mysInstance->myUpdateInterval) |
149 | 153 | { |
150 | | - pollColor(); |
| 154 | + if (!color_pImageReady) |
| 155 | + { |
| 156 | + if (enableKinectColor) |
| 157 | + { |
| 158 | + pollColor(); |
| 159 | + } |
| 160 | + } |
| 161 | + |
| 162 | + if (enableKinectDepth) |
| 163 | + { |
| 164 | + pollDepth(); |
| 165 | + } |
| 166 | + lastUpdateTime = curt; |
151 | 167 | } |
152 | | - if (enableKinectDepth) |
| 168 | + |
| 169 | + if (color_pImageReady && curt - lastSendTime > mysInstance->myCheckKinectInterval) |
153 | 170 | { |
154 | | - pollDepth(); |
| 171 | + unsigned long pImageSize = cColorWidth * cColorHeight * sizeof(RGBQUAD); |
| 172 | + |
| 173 | + int nPackets = 270; // 1920 * 1080 = 2073600 * 4 = 8294400 / 256 = 32400 (max imageBuffer size = 41472) |
| 174 | + int dataPacketSize = pImageSize / nPackets; |
| 175 | + |
| 176 | + int eventsPerUpdate = 10; |
| 177 | + |
| 178 | + for (int i = 0; i < eventsPerUpdate; i++) |
| 179 | + { |
| 180 | + memcpy(imageEventBuffer, &color_pImage[currentPacket * dataPacketSize], dataPacketSize); |
| 181 | + Event* evt = mysInstance->writeHead(); |
| 182 | + evt->reset(Event::Update, Service::Generic, currentFrameTimestamp); |
| 183 | + evt->setPosition(cColorWidth, cColorHeight, 0); // Position: imageWidth, imageHeight, typeFlag (Color = 0, Depth = 1) |
| 184 | + evt->setFlags(currentPacket); |
| 185 | + |
| 186 | + evt->setExtraData(EventBase::ExtraDataString, dataPacketSize, 1, imageEventBuffer); |
| 187 | + mysInstance->unlockEvents(); |
| 188 | + currentPacket++; |
| 189 | + |
| 190 | + if (currentPacket > nPackets - 1) |
| 191 | + { |
| 192 | + currentPacket = 0; |
| 193 | + color_pImageReady = false; |
| 194 | + break; |
| 195 | + } |
| 196 | + } |
| 197 | + |
| 198 | + lastSendTime = curt; |
155 | 199 | } |
156 | 200 | #ifdef OMICRON_USE_KINECT_FOR_WINDOWS_AUDIO |
157 | 201 | if( enableKinectAudio ) |
@@ -283,22 +327,13 @@ void MSKinectService::pollColor() |
283 | 327 |
|
284 | 328 | if (SUCCEEDED(hr)) |
285 | 329 | { |
286 | | - BYTE* pImage = reinterpret_cast<BYTE*>(pBuffer); |
287 | | - unsigned long pImageSize = cColorWidth * cColorHeight * sizeof(RGBQUAD); |
| 330 | + color_pImage = reinterpret_cast<BYTE*>(pBuffer); |
288 | 331 |
|
289 | | - int nPackets = 270; // 1920 * 1080 = 2073600 * 4 = 8294400 / 256 = 32400 (max imageBuffer size = 41472) |
290 | | - int dataPacketSize = pImageSize / nPackets; |
291 | | - |
292 | | - for (int i = 0; i < nPackets; i++) |
293 | | - { |
294 | | - memcpy(imageBuffer, &pImage[i * dataPacketSize], dataPacketSize); |
295 | | - Event* evt = mysInstance->writeHead(); |
296 | | - evt->reset(Event::Update, Service::Generic, 0); |
297 | | - evt->setFlags(i); |
| 332 | + color_pImageReady = true; |
298 | 333 |
|
299 | | - evt->setExtraData(EventBase::ExtraDataString, dataPacketSize, 1, imageBuffer); |
300 | | - mysInstance->unlockEvents(); |
301 | | - } |
| 334 | + timeb tb; |
| 335 | + ftime(&tb); |
| 336 | + currentFrameTimestamp = tb.millitm + (tb.time & 0xfffff) * 1000; |
302 | 337 | } |
303 | 338 |
|
304 | 339 | SafeRelease(pFrameDescription); |
@@ -417,14 +452,19 @@ void MSKinectService::pollDepth() |
417 | 452 | int nPackets = 32; // 512 * 424 = 217088 * 4 = 868352 / 32 = 27136 (max imageBuffer size = 41472) |
418 | 453 | int dataPacketSize = pImageSize / nPackets; |
419 | 454 |
|
| 455 | + timeb tb; |
| 456 | + ftime(&tb); |
| 457 | + int timestamp = tb.millitm + (tb.time & 0xfffff) * 1000; |
| 458 | + |
420 | 459 | for (int i = 0; i < nPackets; i++) |
421 | 460 | { |
422 | | - memcpy(imageBuffer, &pImage[i * dataPacketSize], dataPacketSize); |
| 461 | + memcpy(imageEventBuffer, &pImage[i * dataPacketSize], dataPacketSize); |
423 | 462 | Event* evt = mysInstance->writeHead(); |
424 | | - evt->reset(Event::Update, Service::Generic, 1); |
| 463 | + evt->reset(Event::Update, Service::Generic, timestamp); |
| 464 | + evt->setPosition(cDepthWidth, cDepthHeight, 1); // Position: imageWidth, imageHeight, typeFlag (Color = 0, Depth = 1) |
425 | 465 | evt->setFlags(i); |
426 | 466 |
|
427 | | - evt->setExtraData(EventBase::ExtraDataString, dataPacketSize, 1, imageBuffer); |
| 467 | + evt->setExtraData(EventBase::ExtraDataString, dataPacketSize, 1, imageEventBuffer); |
428 | 468 | mysInstance->unlockEvents(); |
429 | 469 | } |
430 | 470 | } |
|
0 commit comments