-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathKinectServer.cpp
625 lines (535 loc) · 20.8 KB
/
KinectServer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
/***********************************************************************
KinectServer - Server to stream 3D video data from one or more Kinect
cameras to remote clients for tele-immersion.
Copyright (c) 2010-2018 Oliver Kreylos
This file is part of the Kinect 3D Video Capture Project (Kinect).
The Kinect 3D Video Capture Project is free software; you can
redistribute it and/or modify it under the terms of the GNU General
Public License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
The Kinect 3D Video Capture Project is distributed in the hope that it
will be useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with the Kinect 3D Video Capture Project; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA
***********************************************************************/
#include "KinectServer.h"
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <iostream>
#include <Misc/SizedTypes.h>
#include <Misc/PrintInteger.h>
#include <Misc/ThrowStdErr.h>
#include <Misc/FunctionCalls.h>
#include <Misc/Time.h>
#include <Misc/StandardValueCoders.h>
#include <Misc/CompoundValueCoders.h>
#include <Misc/ConfigurationFile.h>
#include <USB/DeviceList.h>
#include <IO/File.h>
#include <Geometry/GeometryMarshallers.h>
#include <Video/Config.h>
#include <Kinect/Internal/Config.h>
#include <Kinect/DirectFrameSource.h>
#include <Kinect/OpenDirectFrameSource.h>
#include <Kinect/ColorFrameWriter.h>
#include <Kinect/DepthFrameWriter.h>
#include <Kinect/LossyDepthFrameWriter.h>
/******************************************
Methods of class KinectServer::CameraState:
******************************************/
void KinectServer::CameraState::colorStreamingCallback(const Kinect::FrameBuffer& frame)
{
/* Pass the frame to the color compressor: */
colorCompressor->writeFrame(frame);
/* Store the compressed frame data in the color frame triple buffer: */
CompressedFrame& compressedFrame=colorFrames.startNewValue();
compressedFrame.index=colorFrameIndex;
compressedFrame.timeStamp=frame.timeStamp;
colorFile.storeBuffers(compressedFrame.data);
colorFrames.postNewValue();
++colorFrameIndex;
/* Notify the run loop: */
Misc::UInt32 frameIndex=cameraIndex*2U;
write(framePipeFd,&frameIndex,sizeof(frameIndex));
}
void KinectServer::CameraState::depthStreamingCallback(const Kinect::FrameBuffer& frame)
{
/* Pass the frame to the depth compressor: */
depthCompressor->writeFrame(frame);
/* Store the compressed frame data in the depth frame triple buffer: */
CompressedFrame& compressedFrame=depthFrames.startNewValue();
compressedFrame.index=depthFrameIndex;
compressedFrame.timeStamp=frame.timeStamp;
depthFile.storeBuffers(compressedFrame.data);
depthFrames.postNewValue();
++depthFrameIndex;
/* Notify the run loop: */
Misc::UInt32 frameIndex=cameraIndex*2U+1U;
write(framePipeFd,&frameIndex,sizeof(frameIndex));
}
KinectServer::CameraState::CameraState(const char* serialNumber,bool sLossyDepthCompression)
:camera(Kinect::openDirectFrameSource(serialNumber)),cameraIndex(0U),
depthCorrection(0),framePipeFd(-1),
colorFile(16384),colorCompressor(0),
colorFrameIndex(0),hasSentColorFrame(false),
depthFile(16384),lossyDepthCompression(sLossyDepthCompression),depthCompressor(0),
depthFrameIndex(0),hasSentDepthFrame(false)
{
/* Retrieve the camera's depth correction parameters: */
depthCorrection=camera->getDepthCorrectionParameters();
/* Retrieve the camera's intrinsic and extrinsic parameters: */
ips=camera->getIntrinsicParameters();
eps=camera->getExtrinsicParameters();
/* Create the color and depth frame compressors: */
colorCompressor=new Kinect::ColorFrameWriter(colorFile,camera->getActualFrameSize(Kinect::FrameSource::COLOR));
#if VIDEO_CONFIG_HAVE_THEORA
if(lossyDepthCompression)
depthCompressor=new Kinect::LossyDepthFrameWriter(depthFile,camera->getActualFrameSize(Kinect::FrameSource::DEPTH));
else
depthCompressor=new Kinect::DepthFrameWriter(depthFile,camera->getActualFrameSize(Kinect::FrameSource::DEPTH));
#else
depthCompressor=new Kinect::DepthFrameWriter(depthFile,camera->getActualFrameSize(Kinect::FrameSource::DEPTH));
#endif
/* Extract the color and depth compressors' stream header data: */
colorFile.storeBuffers(colorHeaders);
depthFile.storeBuffers(depthHeaders);
}
KinectServer::CameraState::~CameraState(void)
{
/* Stop streaming: */
camera->stopStreaming();
/* Destroy the color and depth compressors: */
delete colorCompressor;
delete depthCompressor;
/* Destroy the depth correction parameters: */
delete depthCorrection;
/* Destroy the camera: */
delete camera;
}
void KinectServer::CameraState::startStreaming(const Kinect::FrameSource::Time& timeBase)
{
/* Start streaming: */
camera->setTimeBase(timeBase);
camera->startStreaming(Misc::createFunctionCall(this,&KinectServer::CameraState::colorStreamingCallback),Misc::createFunctionCall(this,&KinectServer::CameraState::depthStreamingCallback));
}
void KinectServer::CameraState::writeHeaders(IO::File& sink) const
{
/* Write the stream format versions: */
sink.write<Misc::UInt32>(1);
sink.write<Misc::UInt32>(5);
/* Write the camera's depth correction parameters: */
if(depthCorrection!=0)
depthCorrection->write(sink);
else
{
/* Write a dummy depth correction object: */
int dcSize[2]={1,1};
Kinect::FrameSource::DepthCorrection dc(0,dcSize);
dc.write(sink);
}
/* Check whether the depth stream uses lossy compression: */
#if VIDEO_CONFIG_HAVE_THEORA
sink.write<Misc::UInt8>(lossyDepthCompression?1:0);
#else
sink.write<Misc::UInt8>(0);
#endif
/* Write the depth camera's lens distortion correction parameters to the sink: */
ips.depthLensDistortion.write(sink);
/* Write the camera's intrinsic and extrinsic parameters to the sink: */
Misc::Marshaller<Kinect::FrameSource::IntrinsicParameters::PTransform>::write(ips.colorProjection,sink);
Misc::Marshaller<Kinect::FrameSource::IntrinsicParameters::PTransform>::write(ips.depthProjection,sink);
Misc::Marshaller<Kinect::FrameSource::ExtrinsicParameters>::write(eps,sink);
/* Write the color and depth compression headers: */
colorHeaders.writeToSink(sink);
depthHeaders.writeToSink(sink);
}
namespace {
/**************
Helper classes:
**************/
enum State
{
START,STREAMING
};
}
/******************************************
Methods of class KinectServer::ClientState:
******************************************/
KinectServer::ClientState::ClientState(KinectServer* sServer,Comm::ListeningTCPSocket& listenSocket)
:server(sServer),
pipe(listenSocket),
state(START),
protocolVersion(0),
streaming(false)
{
#ifdef VERBOSE
/* Assemble the client name: */
clientName=pipe.getPeerHostName();
clientName.push_back(':');
char portId[10];
clientName.append(Misc::print(pipe.getPeerPortId(),portId+sizeof(portId)-1));
#endif
}
/*****************************
Methods of class KinectServer:
*****************************/
void KinectServer::newFrameCallback(void)
{
/* Read the camera index and frame type: */
Misc::UInt32 frameIndex;
read(framePipeFds[0],&frameIndex,sizeof(frameIndex));
unsigned int cameraIndex=frameIndex>>1;
/* Check if the frame is a color or depth frame: */
if(frameIndex&0x01U) // New frame is a depth frame
{
/* Check if the camera has not yet sent a depth frame in the current meta frame: */
if(!cameraStates[cameraIndex]->hasSentDepthFrame&&cameraStates[cameraIndex]->depthFrames.lockNewValue())
{
#ifdef VERBOSE2
std::cout<<" depth "<<cameraIndex<<", "<<cameraStates[cameraIndex]->depthFrames.getLockedValue().index<<", "<<cameraStates[cameraIndex]->depthFrames.getLockedValue().timeStamp<<';';
#endif
/* Send the camera's new depth frame to all connected clients: */
for(ClientStateList::iterator csIt=clients.begin();csIt!=clients.end();++csIt)
if((*csIt)->streaming)
{
try
{
/* Write the meta frame index and frame identifier: */
(*csIt)->pipe.write<Misc::UInt32>(metaFrameIndex);
(*csIt)->pipe.write<Misc::UInt32>(frameIndex);
/* Write the compressed depth frame: */
cameraStates[cameraIndex]->depthFrames.getLockedValue().data.writeToSink((*csIt)->pipe);
(*csIt)->pipe.flush();
}
catch(const std::runtime_error& err)
{
#ifdef VERBOSE
std::cout<<"KinectServer: Disconnecting client "<<(*csIt)->clientName<<" due to exception "<<err.what()<<std::endl;
#endif
disconnectClient(*csIt,true,false);
/* Remove the client from the list by moving the last element forward: */
*csIt=clients.back();
--csIt;
clients.pop_back();
}
}
/* Reduce the number of outstanding depth frames in the current meta frame: */
cameraStates[cameraIndex]->hasSentDepthFrame=true;
--numMissingDepthFrames;
}
}
else // New frame is a color frame
{
/* Check if the camera has not yet sent a color frame in the current meta frame: */
if(!cameraStates[cameraIndex]->hasSentColorFrame&&cameraStates[cameraIndex]->colorFrames.lockNewValue())
{
#ifdef VERBOSE2
std::cout<<" color "<<cameraIndex<<", "<<cameraStates[cameraIndex]->colorFrames.getLockedValue().index<<", "<<cameraStates[cameraIndex]->colorFrames.getLockedValue().timeStamp<<';';
#endif
/* Send the camera's new color frame to all connected clients: */
for(ClientStateList::iterator csIt=clients.begin();csIt!=clients.end();++csIt)
if((*csIt)->streaming)
{
try
{
/* Write the meta frame index and frame identifier: */
(*csIt)->pipe.write<Misc::UInt32>(metaFrameIndex);
(*csIt)->pipe.write<Misc::UInt32>(frameIndex);
/* Write the compressed color frame: */
cameraStates[cameraIndex]->colorFrames.getLockedValue().data.writeToSink((*csIt)->pipe);
(*csIt)->pipe.flush();
}
catch(const std::runtime_error& err)
{
#ifdef VERBOSE
std::cout<<"KinectServer: Disconnecting client "<<(*csIt)->clientName<<" due to exception "<<err.what()<<std::endl;
#endif
disconnectClient(*csIt,true,false);
/* Remove the client from the list by moving the last element forward: */
*csIt=clients.back();
--csIt;
clients.pop_back();
}
}
/* Reduce the number of outstanding color frames in the current meta frame: */
cameraStates[cameraIndex]->hasSentColorFrame=true;
--numMissingColorFrames;
}
}
/* Check if the current meta frame is complete: */
if(numMissingDepthFrames==0U&&numMissingColorFrames==0U)
{
/* Start the next meta frame: */
++metaFrameIndex;
for(unsigned int i=0;i<numCameras;++i)
{
cameraStates[i]->hasSentColorFrame=false;
cameraStates[i]->hasSentDepthFrame=false;
}
numMissingColorFrames=numCameras;
numMissingDepthFrames=numCameras;
#ifdef VERBOSE2
std::cout<<std::endl;
std::cout<<"Meta frame "<<metaFrameIndex;
#endif
}
}
bool KinectServer::newConnectionCallback(Threads::EventDispatcher::ListenerKey eventKey,int eventType,void* userData)
{
KinectServer* thisPtr=static_cast<KinectServer*>(userData);
/* Create a new client state object and add it to the list: */
ClientState* newClient=new ClientState(thisPtr,thisPtr->listeningSocket);
#ifdef VERBOSE
std::cout<<"KinectServer: Connecting new client "<<newClient->clientName<<std::endl;
#endif
thisPtr->clients.push_back(newClient);
/* Add an event listener for incoming messages from the client: */
newClient->listenerKey=thisPtr->dispatcher.addIOEventListener(newClient->pipe.getFd(),Threads::EventDispatcher::Read,thisPtr->clientMessageCallback,newClient);
return false;
}
void KinectServer::disconnectClient(KinectServer::ClientState* client,bool removeListener,bool removeFromList)
{
if(removeListener)
{
/* Stop listening on the client's pipe: */
dispatcher.removeIOEventListener(client->listenerKey);
}
/* Check if the client is still streaming: */
if(client->streaming)
--numStreamingClients;
/* Disconnect the client: */
delete client;
if(removeFromList)
{
/* Remove the dead client from the list: */
for(ClientStateList::iterator csIt=clients.begin();csIt!=clients.end();++csIt)
if(*csIt==client)
{
/* Remove it and stop searching: */
*csIt=clients.back();
clients.pop_back();
break;
}
}
}
bool KinectServer::clientMessageCallback(Threads::EventDispatcher::ListenerKey eventKey,int eventType,void* userData)
{
ClientState* client=static_cast<ClientState*>(userData);
KinectServer* thisPtr=client->server;
bool result=false;
try
{
/* Read some data from the socket into the socket's read buffer and check if client hung up: */
if(client->pipe.readSomeData()==0)
throw std::runtime_error("Client terminated connection");
/* Process messages as long as there is data in the read buffer: */
while(!result&&client->pipe.canReadImmediately())
{
switch(client->state)
{
case START:
{
/* Read endianness flag and protocol version from new client: */
Misc::UInt32 endiannessFlag=client->pipe.read<Misc::UInt32>();
if(endiannessFlag==0x78563412U)
client->pipe.setSwapOnRead(true);
else if(endiannessFlag!=0x12345678U)
throw std::runtime_error("Client has unrecognized endianness");
client->protocolVersion=client->pipe.read<Misc::UInt32>();
if(client->protocolVersion>1U)
client->protocolVersion=1U;
/* Send stream initialization states to the new client: */
#ifdef VERBOSE
std::cout<<"KinectServer: Sending stream headers to client "<<client->clientName<<std::endl;
#endif
client->pipe.write<Misc::UInt32>(0x12345678U);
client->pipe.write<Misc::UInt32>(client->protocolVersion);
Kinect::FrameSource::Time now;
client->pipe.write<Misc::Float64>(double(now-thisPtr->timeBase));
client->pipe.write<Misc::UInt32>(thisPtr->numCameras);
for(unsigned i=0;i<thisPtr->numCameras;++i)
thisPtr->cameraStates[i]->writeHeaders(client->pipe);
/* Finish the reply message: */
client->pipe.flush();
/* Increase the number of streaming clients: */
++thisPtr->numStreamingClients;
/* Go to streaming state: */
client->state=STREAMING;
client->streaming=true;
#ifdef VERBOSE
std::cout<<"KinectServer: Client "<<client->clientName<<" entered streaming mode"<<std::endl;
#endif
break;
}
case STREAMING:
{
/* Read a message from the client: */
Misc::UInt32 message=client->pipe.read<Misc::UInt32>();
if(message==0U) // Disconnect request
{
/* Cleanly disconnect this client: */
#ifdef VERBOSE
std::cout<<"KinectServer: Disconnecting client "<<client->clientName<<std::endl;
#endif
thisPtr->disconnectClient(client,false,true);
result=true;
}
else
throw std::runtime_error("Protocol error in STREAMING state");
break;
}
}
}
}
catch(const std::runtime_error& err)
{
#ifdef VERBOSE
std::cout<<"KinectServer: Disconnecting client "<<client->clientName<<" due to exception "<<err.what()<<std::endl;
#endif
thisPtr->disconnectClient(client,false,true);
result=true;
}
return result;
}
KinectServer::KinectServer(Misc::ConfigurationFileSection& configFileSection)
:numCameras(0),cameraStates(0),
listeningSocket(configFileSection.retrieveValue<int>("./listenPortId",26000),5),
numStreamingClients(0)
{
/* Create a pipe to signal arrival of new frames to the run loop: */
if(pipe(framePipeFds)<0)
{
int error=errno;
Misc::throwStdErr("KinectServer: Unable to open frame notification pipe due to error %d (%s)",error,strerror(error));
}
/* Read the list of cameras: */
std::vector<std::string> cameraNames=configFileSection.retrieveValue<std::vector<std::string> >("./cameras",std::vector<std::string>());
numCameras=cameraNames.size();
cameraStates=new CameraState*[numCameras];
/* Connect to all requested Kinect devices: */
unsigned int numFoundCameras=0;
for(unsigned int i=0;i<numCameras;++i)
{
/* Read the camera's serial number: */
Misc::ConfigurationFileSection cameraSection=configFileSection.getSection(cameraNames[i].c_str());
std::string serialNumber=cameraSection.retrieveString("./serialNumber");
try
{
/* Create a streamer for the Kinect device of the requested serial number: */
#ifdef VERBOSE
std::cout<<"KinectServer: Creating streamer for camera with serial number "<<serialNumber<<std::endl;
#endif
cameraStates[numFoundCameras]=new CameraState(serialNumber.c_str(),cameraSection.retrieveValue<bool>("./lossyDepthCompression",false));
/* Check if camera is to remove background: */
if(cameraSection.retrieveValue<bool>("./removeBackground",true))
{
Kinect::DirectFrameSource* camera=cameraStates[numFoundCameras]->camera;
/* Check whether to load a previously saved background file: */
std::string backgroundFile=cameraSection.retrieveValue<std::string>("./backgroundFile",std::string());
if(!backgroundFile.empty())
{
/* Load the background file: */
std::string fullBackgroundFileName=KINECT_INTERNAL_CONFIG_CONFIGDIR;
fullBackgroundFileName.push_back('/');
fullBackgroundFileName.append(backgroundFile);
#ifdef VERBOSE
std::cout<<"KinectServer: Loading background depth image file "<<fullBackgroundFileName<<'-'<<serialNumber<<".background"<<std::endl;
#endif
camera->loadBackground(fullBackgroundFileName.c_str());
}
/* Check whether to capture background: */
unsigned int captureBackgroundFrames=cameraSection.retrieveValue<unsigned int>("./captureBackgroundFrames",0);
if(captureBackgroundFrames>0)
{
/* Request background capture: */
#ifdef VERBOSE
std::cout<<"KinectServer: Capturing "<<captureBackgroundFrames<<" background depth frames"<<std::endl;
#endif
camera->captureBackground(captureBackgroundFrames,false);
}
/* Check whether to set a maximum depth value: */
unsigned int maxDepth=cameraSection.retrieveValue<unsigned int>("./maxDepth",0);
if(maxDepth>0)
{
/* Set the maximum depth: */
#ifdef VERBOSE
std::cout<<"KinectServer: Setting maximum depth value to "<<maxDepth<<std::endl;
#endif
camera->setMaxDepth(maxDepth,false);
}
/* Set the background removal fuzz value: */
int backgroundFuzz=cameraSection.retrieveValue<int>("./backgroundFuzz",camera->getBackgroundRemovalFuzz());
#ifdef VERBOSE
std::cout<<"KinectServer: Setting background depth fuzz value to "<<backgroundFuzz<<std::endl;
#endif
camera->setBackgroundRemovalFuzz(backgroundFuzz);
/* Enable background removal: */
camera->setRemoveBackground(true);
}
++numFoundCameras;
}
catch(const std::runtime_error& err)
{
std::cerr<<"Could not open Kinect camera with serial number "<<serialNumber<<" due to exception "<<err.what()<<std::endl;
}
}
/* Initialize streaming state: */
#ifdef VERBOSE
std::cout<<"KinectServer: "<<numFoundCameras<<" cameras initialized"<<std::endl;
#endif
numCameras=numFoundCameras;
metaFrameIndex=0;
numMissingColorFrames=numCameras;
numMissingDepthFrames=numCameras;
for(unsigned int i=0;i<numCameras;++i)
{
cameraStates[i]->cameraIndex=i;
cameraStates[i]->framePipeFd=framePipeFds[1];
}
/* Add an event listener for frame arrival messages: */
dispatcher.addIOEventListener(framePipeFds[0],Threads::EventDispatcher::Read,newFrameCallbackWrapper,this);
/* Add an event listener for incoming connections on the listening socket: */
#ifdef VERBOSE
std::cout<<"KinectServer: Listening for incoming connections on TCP port "<<listeningSocket.getPortId()<<std::endl;
#endif
dispatcher.addIOEventListener(listeningSocket.getFd(),Threads::EventDispatcher::Read,newConnectionCallback,this);
}
KinectServer::~KinectServer(void)
{
/* Forcefully disconnect all clients: */
#ifdef VERBOSE
std::cout<<"KinectServer: Disconnecting all clients"<<std::endl;
#endif
for(ClientStateList::iterator csIt=clients.begin();csIt!=clients.end();++csIt)
delete *csIt;
/* Delete all camera states: */
#ifdef VERBOSE
std::cout<<"KinectServer: Disconnecting from all cameras"<<std::endl;
#endif
for(unsigned int i=0;i<numCameras;++i)
delete cameraStates[i];
delete[] cameraStates;
/* Close the frame notification pipe: */
for(int i=0;i<2;++i)
close(framePipeFds[i]);
}
void KinectServer::run(void)
{
/* Start streaming on all connected cameras: */
#ifdef VERBOSE
std::cout<<"KinectServer: Starting streaming on "<<numCameras<<" cameras"<<std::endl;
#endif
timeBase.set();
for(unsigned int i=0;i<numCameras;++i)
cameraStates[i]->startStreaming(timeBase);
#ifdef VERBOSE2
std::cout<<"Meta frame "<<metaFrameIndex;
#endif
/* Run the main loop and dispatch events until stopped: */
dispatcher.dispatchEvents();
}