32#include <VisionX/interface/core/ImageProviderInterface.h>
36#include <Image/ImageProcessor.h>
46 "imageProviderProxyName",
"TestImageProvider",
"Name of the image provider");
48 "imageStreamTopicName",
"ImageStream",
"Name of the image streaming topic");
56 .setCaseInsensitive(
true)
61 "Framerate at which the input images are encoded. Slower or fasting pushing of input "
62 "is possible. Frames will be skipped then. ");
72 srand(
static_cast<unsigned int>(IceUtil::Time::now().toMicroSeconds()));
80 Logging::setTag(
"StreamProvider");
84 this, &StreamProviderI::calculateFps, 995,
true,
"FPSCalcThread");
85 fpsCalculator->start();
105 if (imageFormat.type != visionx::eRgb)
107 throw armarx::LocalException(
"The StreamProvider supports only RGB at the moment.");
110 imgWidth = imageFormat.dimension.width;
111 imgHeight = imageFormat.dimension.height;
112 encodedImgHeight = imgHeight * numberImages;
113 imgType = imageFormat.type;
116 ppInputImages =
new CByteImage*[size_t(numberImages)];
117 for (
int i = 0; i < numberImages; i++)
124 new CByteImage(imageProviderInfo.
imageFormat.dimension.width,
125 imageProviderInfo.
imageFormat.dimension.height * numberImages,
129 x264_param_default_preset(
132 param.i_width = imgWidth;
133 param.i_height = encodedImgHeight;
134 param.i_fps_num = uint32_t(fps);
137 param.i_keyint_max = int(fps);
138 param.b_intra_refresh = 1;
141 param.rc.i_rc_method = X264_RC_CRF;
143 param.rc.f_rf_constant_max = param.rc.f_rf_constant * 1.4f;
150 param.b_repeat_headers = 1;
152 if (x264_param_apply_profile(
157 <<
"' profile for x264 codec";
170 std::cout <<
"exiting StreamProviderI" << std::endl;
173 fpsCalculator->stop();
178 for (
int i = 0; i < numberImages; i++)
180 delete ppInputImages[i];
182 delete[] ppInputImages;
205 armarx::MetaInfoSizeBasePtr info;
206 getImages(imageProviderProxyName, ppInputImages, info);
209 for (
int i = 0; i < numberImages; ++i)
211 int imageByteSize = ppInputImages[i]->width * ppInputImages[i]->height *
212 ppInputImages[i]->bytesPerPixel;
213 memcpy(pImageForEncoder->pixels + i * imageByteSize,
214 ppInputImages[i]->pixels,
215 size_t(imageByteSize));
217 int srcstride = imgWidth * 3;
218 const uint8_t* pixels = pImageForEncoder->pixels;
219 sws_scale(convertCtx,
225 pic_in.img.i_stride);
228 int frameSize = x264_encoder_encode(encoder, &nals, &i_nals, &pic_in, &pic_out);
236 chunk.reserve(
size_t(frameSize));
237 chunk.assign(nals->p_payload, nals->p_payload + frameSize);
238 listener->reportNewStreamData(chunk, info->timeProvided);
251 return "StreamProvider";
262 encoder = x264_encoder_open(¶m);
264 x264_picture_alloc(&pic_in, X264_CSP_I420, imgWidth, encodedImgHeight);
266 convertCtx = sws_getContext(imgWidth,
289 x264_picture_clean(&pic_in);
290 memset(
reinterpret_cast<char*
>(&pic_in), 0,
sizeof(pic_in));
291 memset(
reinterpret_cast<char*
>(&pic_out), 0,
sizeof(pic_out));
293 x264_encoder_close(encoder);
299 sws_freeContext(convertCtx);
300 convertCtx =
nullptr;
311 StreamProviderI::calculateFps()
329 imageWidth = imgWidth;
330 imageHeight = imgHeight;
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
StreamProviderPropertyDefinitions(std::string prefix)
void onStartRecording(const ::Ice::Current &=Ice::emptyCurrent) override
bool startCapture(const ::Ice::Current &=Ice::emptyCurrent) override
starts the capture for the given source
void onConnectImageProcessor() override
Is called once all dependencies of the object have been resolved and Ice connection is established.
void setCompressionRate(::Stream::CompressionRate=COMPRESSIONHIGH, const ::Ice::Current &=Ice::emptyCurrent) override
void onExitImageProcessor() override
Is called once the component terminates.
int getNumberOfImages(const ::Ice::Current &=Ice::emptyCurrent) override
void process() override
Process the vision component.
CodecType getCodecType(const Ice::Current &) override
void onInitImageProcessor() override
Is called once initialization of the ManagedIceObject is done.
void stopCapture(const ::Ice::Current &=Ice::emptyCurrent) override
void getImageInformation(int &imageWidth, int &imageHeight, int &imageType, const Ice::Current &c=Ice::emptyCurrent) override
std::string getDefaultName() const override
Retrieve default name of component.
virtual void onDisConnectImageProcessor()
Is called if a dependency of the object got lost (crash, network error, stopped, ....
TopicProxyType getTopicFromProperty(const std::string &propertyName)
Get a topic proxy whose name is specified by the given property.
void offeringTopicFromProperty(const std::string &propertyName)
Offer a topic whose name is specified by the given property.
Property< PropertyType > getProperty(const std::string &name)
void usingTopic(const std::string &name, bool orderedPublishing=false)
Registers a proxy for subscription after initialization.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
The periodic task executes one thread method repeatedly using the time period specified in the constr...
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
PropertyDefinition< PropertyType > & defineOptionalProperty(const std::string &name, PropertyType defaultValue, const std::string &description="", PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
ImageProcessorPropertyDefinitions(std::string prefix)
void usingImageProvider(std::string name)
Registers a delayed topic subscription and a delayed provider proxy retrieval which all will be avail...
bool waitForImages(int milliseconds=1000)
Wait for new images.
ImageProviderInfo getImageProvider(std::string name, ImageType destinationImageType=eRgb, bool waitForProxy=false)
Select an ImageProvider.
int getImages(CByteImage **ppImages)
Poll images from provider.
void setFramerate(float fps)
int numberImages
Number of images.
ImageFormatInfo imageFormat
Image format struct that contains all necessary image information.
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
#define ARMARX_VERBOSE
The logging level for verbose information.