40 void CapturingImageProvider::startCapture(
float framesPerSecond,
41 const Ice::Current& ctx)
43 std::unique_lock lock(captureMutex);
44 onStartCapture(framesPerSecond);
46 captureEnabled =
true;
47 frameRate = framesPerSecond;
49 ARMARX_INFO <<
"Starting image capture with " << frameRate <<
"fps";
53 void CapturingImageProvider::stopCapture(
const Ice::Current& ctx)
55 std::unique_lock lock(captureMutex);
56 captureEnabled =
false;
63 void CapturingImageProvider::onInitImageProvider()
66 frameRate = hasProperty(
"FPS") ? getProperty<float>(
"FPS").getValue() : 30;
67 captureEnabled =
false;
70 setImageSyncMode(eFpsSynchronization);
73 onInitCapturingImageProvider();
81 void CapturingImageProvider::onConnectImageProvider()
83 onStartCapturingImageProvider();
88 startCapture(frameRate);
92 void CapturingImageProvider::onExitImageProvider()
102 onExitCapturingImageProvider();
106 void CapturingImageProvider::capture()
108 ARMARX_INFO <<
"Starting Image Provider: " << getName();
111 std::chrono::milliseconds td(1);
113 while (!captureTask->isStopped() && !isExiting() && sharedMemoryProvider)
115 auto tmpSharedMemoryProvider = sharedMemoryProvider;
116 if (captureEnabled && tmpSharedMemoryProvider)
119 MetaInfoSizeBasePtr info = tmpSharedMemoryProvider->getMetaInfo();
121 long oldTimestamp = info ? info->timeProvided : 0;
122 bool succeeded = capture(imageBuffers);
126 MetaInfoSizeBasePtr info = tmpSharedMemoryProvider->getMetaInfo();
129 if (!info || info->timeProvided == oldTimestamp)
131 ARMARX_WARNING <<
deactivateSpam(10000000) <<
"The image provider did not set a timestamp - measuring the timestamp now. The ImageProvider implementation should call updateTimestamp()!";
132 updateTimestamp(image_timestamp.toMicroSeconds());
136 image_timestamp = IceUtil::Time::microSeconds(info->timeProvided);
138 auto imageProcessorProxy = this->imageProcessorProxy;
139 recordImages(image_timestamp);
141 imageProcessorProxy->reportImageAvailable(getName());
144 if (imageSyncMode == eFpsSynchronization)
146 fpsCounter.assureFPS(frameRate);
147 setMetaInfo(
"fps",
new Variant(fpsCounter.getFPS()));
148 setMetaInfo(
"minCycleTimeMs",
new Variant(fpsCounter.getMinCycleTimeMS()));
149 setMetaInfo(
"maxCycleTimeMs",
new Variant(fpsCounter.getMaxCycleTimeMS()));
150 auto dimension = getImageFormat().dimension;
156 std::this_thread::sleep_for(td);
166 void CapturingImageProvider::setImageSyncMode(ImageSyncMode imageSyncMode)
168 this->imageSyncMode = imageSyncMode;
171 ImageSyncMode CapturingImageProvider::getImageSyncMode()
173 return imageSyncMode;