YARP
Yet Another Robot Platform
ffmpegPortmonitor.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
15// Local imports
16#include "ffmpegPortmonitor.h"
17#include "constants.h"
18// YARP imports
20#include <yarp/sig/all.h>
21// Standard imports
22#include <cstring>
23#include <cmath>
24#include <algorithm>
25#include <iostream>
26
27// Ffmpeg imports
28extern "C" {
29 #include <libavcodec/avcodec.h>
30 #include <libavutil/opt.h>
31 #include <libavutil/imgutils.h>
32 #include <libavformat/avformat.h>
33 #include <libswscale/swscale.h>
34}
35
36using namespace yarp::os;
37using namespace yarp::sig;
38
39namespace {
40
41// YARP logging component
42YARP_LOG_COMPONENT(FFMPEGMONITOR,
43 "yarp.carrier.portmonitor.image_compression_ffmpeg",
47 nullptr)
48}
49
58void split(const std::string &s, char delim, std::vector<std::string> &elements) {
59 std::istringstream iss(s);
60 std::string item;
61 while (std::getline(iss, item, delim)) {
62 elements.push_back(item);
63 }
64}
65
67{
68 // Check if this is sender or not
69 senderSide = (options.find("sender_side").asBool());
70
71 // Set default codec
72 AVCodecID codecId = AV_CODEC_ID_MPEG2VIDEO;
73 codecName = "mpeg2video";
74
75 // Parse command line parameters and set them into global variable "paramsMap"
76 std::string str = options.find("carrier").asString();
77 if (getParamsFromCommandLine(str, codecId) == -1) {
78 return false;
79 }
80
81 // Find encoder/decoder
82 if (senderSide) {
83 codec = avcodec_find_encoder(codecId);
84 } else {
85 codec = avcodec_find_decoder(codecId);
86 }
87 if (!codec) {
88 yCError(FFMPEGMONITOR, "Can't find codec %s", codecName.c_str());
89 return false;
90 }
91
92 // Prepare codec context
93 if (codecContext == NULL) {
94 codecContext = avcodec_alloc_context3(codec);
95 } else {
96 yCError(FFMPEGMONITOR, "Codec context is already allocated");
97 return false;
98 }
99 if (!codecContext) {
100 yCError(FFMPEGMONITOR, "Could not allocate video codec context");
101 return false;
102 }
103
104 firstTime = true;
105
106 // Set time base parameter
107 codecContext->time_base.num = 1;
108 codecContext->time_base.den = 15;
109 // Set command line params
110 if (setCommandLineParams() == -1) {
111 return false;
112 }
113
114 return true;
115}
116
118{
119 paramsMap.clear();
120
121 // Check if codec context is freeable, if yes free it.
122 if (codecContext != NULL) {
123 avcodec_close(codecContext);
124 avcodec_free_context(&codecContext);
125 codecContext = NULL;
126 }
127}
128
130{
131 yCTrace(FFMPEGMONITOR, "setparam");
132 return false;
133}
134
136{
137 yCTrace(FFMPEGMONITOR, "getparam");
138 return false;
139}
140
142{
143 if (senderSide) {
144 // If sender side
145 yCTrace(FFMPEGMONITOR, "accept - sender");
146 // Try to cast the Thing into an Image
147 Image* img = thing.cast_as< Image >();
148 // If cast fails, return error
149 if(img == nullptr) {
150 yCError(FFMPEGMONITOR, "Expected type Image in sender side, but got wrong data type!");
151 return false;
152 }
153 }
154 else {
155 // If receiver side
156 yCTrace(FFMPEGMONITOR, "accept - receiver");
157 // Try to cast the Thing into a Bottle
158 Bottle* bt = thing.cast_as<Bottle>();
159 // If cast fails, return error
160 if(bt == nullptr){
161 yCError(FFMPEGMONITOR, "Expected type Bottle in receiver side, but got wrong data type!");
162 return false;
163 }
164 }
165 return true;
166}
167
169{
170 if (senderSide) {
171 bool success = true;
172 yCTrace(FFMPEGMONITOR, "update - sender");
173 // Cast Thing into an Image
174 Image* img = thing.cast_as< Image >();
175 // Allocate memory for packet
176 AVPacket *packet = av_packet_alloc();
177 if (packet == NULL) {
178 yCError(FFMPEGMONITOR, "Error in packet allocation");
179 success = false;
180 }
181
182 // Call compress function
183 if (success && compress(img, packet) != 0) {
184 yCError(FFMPEGMONITOR, "Error in compression");
185 success = false;
186 }
187
188 // Insert compressed image into a Bottle to be sent
189 data.clear();
190
191 int successCode = success ? 1 : 0;
192 data.addInt32(successCode);
193 data.addInt32(img->width());
194 data.addInt32(img->height());
195 data.addInt32(img->getPixelCode());
196 data.addInt32(img->getPixelSize());
197
198 if (success) { // If compression was successful, insert also compressed data
199 // Packet
200 Value p(packet, sizeof(*packet));
201 data.add(p);
202 // Packet data
203 Value d(packet->data, packet->size);
204 data.add(d);
205 // Buffer size
206 data.addInt32(packet->buf->size);
207 // Buffer data
208 Value bd(packet->buf->data, packet->buf->size);
209 data.add(bd);
210
211 // Side data elements
212 for (int i = 0; i < packet->side_data_elems; i++) {
213 data.addInt32(packet->side_data[i].size);
214 data.addInt32(packet->side_data[i].type);
215 Value sd(packet->side_data[i].data, packet->side_data[i].size);
216 data.add(sd);
217 }
218 }
220 // Free the memory allocated for the packet
221 av_packet_unref(packet);
222 }
223 else {
224
225 yCTrace(FFMPEGMONITOR, "update - receiver");
226 // Cast the Thin as a Bottle
227 Bottle* compressedBottle = thing.cast_as<Bottle>();
228 // Fill the final image with zeros
229 imageOut.zero();
230 // Extract decompression data from the Bottle
231 int width = compressedBottle->get(1).asInt32();
232 int height = compressedBottle->get(2).asInt32();
233 int pixelCode = compressedBottle->get(3).asInt32();
234 int pixelSize = compressedBottle->get(4).asInt32();
235 // Set information into final image
236 imageOut.setPixelCode(pixelCode);
237 imageOut.setPixelSize(pixelSize);
238 imageOut.resize(width, height);
239
240 // Check if compression was successful
241 if (compressedBottle->get(0).asInt32() == 1) {
242 bool success = true;
243 // Get compressed image from Bottle
244 AVPacket* tmp = (AVPacket*) compressedBottle->get(5).asBlob();
245 // Allocate memory for packet
246 AVPacket* packet = av_packet_alloc();
247 // Set all packet parameters
248 packet->dts = tmp->dts;
249 packet->duration = tmp->duration;
250 packet->flags = tmp->flags;
251 packet->pos = tmp->pos;
252 packet->pts = tmp->pts;
253 packet->side_data_elems = 0;
254 packet->stream_index = tmp->stream_index;
255 packet->size = tmp->size;
256 // Image data
257 packet->data = (uint8_t *) compressedBottle->get(6).asBlob();
258 // Buffer data
259 packet->buf = av_buffer_create((uint8_t *) compressedBottle->get(8).asBlob(),
260 compressedBottle->get(7).asInt32(), av_buffer_default_free,
261 nullptr, AV_BUFFER_FLAG_READONLY);
262
263 // Packet side data
264 for (int i = 0; i < tmp->side_data_elems; i++) {
265
266 int ret = av_packet_add_side_data(packet,
267 (AVPacketSideDataType) compressedBottle->get(10).asInt32(), // Type
268 (uint8_t *) compressedBottle->get(11).asBlob(), // Data
269 compressedBottle->get(9).asInt32()); // Size
270 if (ret < 0) {
271 success = false;
272 break;
273 }
274 }
275
276 // Call to decompress function
277 if (success && decompress(packet, width, height, pixelCode) != 0) {
278 yCError(FFMPEGMONITOR, "Error in decompression");
279 success = false;
280 }
281
282 // Free memory allocated for side data and packet
283 av_freep(&packet->side_data);
284 av_freep(&packet);
285
286 }
288
289 }
290 return th;
291}
292
293int FfmpegMonitorObject::compress(Image* img, AVPacket *pkt) {
294
295 yCTrace(FFMPEGMONITOR, "compress");
296 AVFrame *startFrame;
297 AVFrame *endFrame;
298
299 // Get width and height
300 int w = img->width();
301 int h = img->height();
302
303 // Allocate video frame for original frames
304 startFrame = av_frame_alloc();
305 if (startFrame == NULL) {
306 yCError(FFMPEGMONITOR, "Cannot allocate starting frame!");
307 return -1;
308 }
309
310 // Allocate a video frame for end frame
311 endFrame = av_frame_alloc();
312 if (endFrame == NULL) {
313 yCError(FFMPEGMONITOR, "Cannot allocate end frame!");
314 av_frame_free(&startFrame);
315 return -1;
316 }
317
318 // Allocate space into start frame to contain data
319 int success = av_image_alloc(startFrame->data, startFrame->linesize,
320 w, h,
321 (AVPixelFormat) FFMPEGPORTMONITOR_PIXELMAP[img->getPixelCode()], 16);
322
323 if (success < 0) {
324 yCError(FFMPEGMONITOR, "Cannot allocate starting frame buffer!");
325 av_frame_free(&startFrame);
326 av_frame_free(&endFrame);
327 return -1;
328 }
329
330 // Set Image data into AVFrame
331 startFrame->linesize[0] = img->getRowSize();
332 // Free old pointer (because we will use the buffer contained into img)
333 av_freep(&startFrame->data[0]);
334 startFrame->data[0] = img->getRawImage();
335 startFrame->height = h;
336 startFrame->width = w;
337 startFrame->format = (AVPixelFormat) FFMPEGPORTMONITOR_PIXELMAP[img->getPixelCode()];
338
339 // Allocate memory for end frame data
340 success = av_image_alloc(endFrame->data, endFrame->linesize,
341 w, h,
342 (AVPixelFormat) FFMPEGPORTMONITOR_CODECPIXELMAP[codecContext->codec_id], 16);
343
344 if (success < 0) {
345 yCError(FFMPEGMONITOR, "Cannot allocate end frame buffer!");
346 av_frame_free(&startFrame);
347 av_frame_free(&endFrame);
348 return -1;
349 }
350
351 // Set end frame parameters
352 endFrame->height = h;
353 endFrame->width = w;
354 endFrame->format = (AVPixelFormat) FFMPEGPORTMONITOR_CODECPIXELMAP[codecContext->codec_id];
355
356 // Convert the image from start format into end format
357 static struct SwsContext *img_convert_ctx;
358
359 // Allocate context for conversion
360 img_convert_ctx = sws_getContext(w, h,
361 (AVPixelFormat) FFMPEGPORTMONITOR_PIXELMAP[img->getPixelCode()],
362 w, h,
363 (AVPixelFormat) FFMPEGPORTMONITOR_CODECPIXELMAP[codecContext->codec_id],
364 SWS_BICUBIC,
365 NULL, NULL, NULL);
366 if (img_convert_ctx == NULL) {
367 yCError(FFMPEGMONITOR, "Cannot initialize pixel format conversion context!");
368 av_freep(&endFrame->data[0]);
369 av_frame_free(&startFrame);
370 av_frame_free(&endFrame);
371 return -1;
372 }
373
374 // Perform conversion
375 int ret = sws_scale(img_convert_ctx, startFrame->data, startFrame->linesize, 0,
376 h, endFrame->data, endFrame->linesize);
377
378 if (ret < 0) {
379 yCError(FFMPEGMONITOR, "Could not convert pixel format!");
380 sws_freeContext(img_convert_ctx);
381 av_freep(&endFrame->data[0]);
382 av_frame_free(&startFrame);
383 av_frame_free(&endFrame);
384 return -1;
385 }
386
387 if (firstTime) {
388 // If this is the first compression
389
390 // Set codec context parameters
391 codecContext->width = w;
392 codecContext->height = h;
393 codecContext->pix_fmt = (AVPixelFormat) FFMPEGPORTMONITOR_CODECPIXELMAP[codecContext->codec_id];
394
395 // Open codec
396 ret = avcodec_open2(codecContext, codec, NULL);
397 if (ret < 0) {
398 yCError(FFMPEGMONITOR, "Could not open codec");
399 sws_freeContext(img_convert_ctx);
400 av_freep(&endFrame->data[0]);
401 av_frame_free(&startFrame);
402 av_frame_free(&endFrame);
403 return -1;
404 }
405 firstTime = false;
406 }
407
408 // Set presentation timestamp
409 endFrame->pts = codecContext->frame_number;
410
411 // Send image frame to codec
412 ret = avcodec_send_frame(codecContext, endFrame);
413 if (ret < 0) {
414 yCError(FFMPEGMONITOR, "Error sending a frame for encoding");
415 sws_freeContext(img_convert_ctx);
416 av_freep(&endFrame->data[0]);
417 av_frame_free(&startFrame);
418 av_frame_free(&endFrame);
419 return -1;
420 }
421
422 // Receive compressed data into packet
423 ret = avcodec_receive_packet(codecContext, pkt);
424 sws_freeContext(img_convert_ctx);
425 av_freep(&endFrame->data[0]);
426 av_frame_free(&startFrame);
427 av_frame_free(&endFrame);
428
429 if (ret == AVERROR(EAGAIN)) {
430 // Not enough data
431 yCError(FFMPEGMONITOR, "Error EAGAIN");
432 return -1;
433 } else if (ret == AVERROR_EOF) {
434 // End of file reached
435 yCError(FFMPEGMONITOR, "Error EOF");
436 return -1;
437 } else if (ret < 0) {
438 yCError(FFMPEGMONITOR, "Error during encoding");
439 return -1;
440 }
441
442 return 0;
443}
444
445int FfmpegMonitorObject::decompress(AVPacket* pkt, int w, int h, int pixelCode) {
446
447 yCTrace(FFMPEGMONITOR, "decompress");
448 AVFrame *startFrame;
449 AVFrame *endFrame;
450
451 if (firstTime) {
452 // If this is the first decompression
453
454 // Set codec context parameters
455 codecContext->width = w;
456 codecContext->height = h;
457 codecContext->pix_fmt = (AVPixelFormat) FFMPEGPORTMONITOR_CODECPIXELMAP[codecContext->codec_id];
458
459 // Open codec
460 int ret = avcodec_open2(codecContext, codec, NULL);
461 if (ret < 0) {
462 yCError(FFMPEGMONITOR, "Could not open codec");
463 return -1;
464 }
465 firstTime = false;
466 }
467
468 // Allocate video frame
469 startFrame = av_frame_alloc();
470 if (startFrame == NULL) {
471 yCError(FFMPEGMONITOR, "Could not allocate start frame!");
472 return -1;
473 }
474
475 // Send compressed packet to codec
476 int ret = avcodec_send_packet(codecContext, pkt);
477 if (ret < 0) {
478 yCError(FFMPEGMONITOR, "Error sending a frame for encoding");
479 av_frame_free(&startFrame);
480 return -1;
481 }
482
483 // Receive decompressed image into an AVFrame
484 ret = avcodec_receive_frame(codecContext, startFrame);
485 if (ret == AVERROR(EAGAIN)) {
486 // No enough data
487 yCError(FFMPEGMONITOR, "Error EAGAIN");
488 av_frame_free(&startFrame);
489 return -1;
490 }
491 else if (ret == AVERROR_EOF) {
492 // End of file reached
493 yCError(FFMPEGMONITOR, "Error EOF");
494 av_frame_free(&startFrame);
495 return -1;
496 }
497 else if (ret < 0) {
498 yCError(FFMPEGMONITOR, "Error during encoding");
499 av_frame_free(&startFrame);
500 return -1;
501 }
502
503 // Allocate a video frame for end frame
504 endFrame = av_frame_alloc();
505 if (endFrame == NULL) {
506 yCError(FFMPEGMONITOR, "Could not allocate start frame!");
507 av_frame_free(&startFrame);
508 return -1;
509 }
510
511 // Allocate memory into end frame to contain data
512 int success = av_image_alloc(endFrame->data, endFrame->linesize,
513 w, h,
514 (AVPixelFormat) FFMPEGPORTMONITOR_PIXELMAP[pixelCode], 16);
515
516 if (success < 0) {
517 yCError(FFMPEGMONITOR, "Error allocating end frame buffer!");
518 av_frame_free(&startFrame);
519 av_frame_free(&endFrame);
520 return -1;
521 }
522
523 // Set end frame parameters
524 endFrame->height = h;
525 endFrame->width = w;
526 endFrame->format = (AVPixelFormat) FFMPEGPORTMONITOR_PIXELMAP[pixelCode];
527
528 // Convert the image into RGB format
529 static struct SwsContext *img_convert_ctx;
530
531 // Allocate conversion context
532 img_convert_ctx = sws_getContext(w, h,
533 (AVPixelFormat) FFMPEGPORTMONITOR_CODECPIXELMAP[codecContext->codec_id],
534 w, h,
535 (AVPixelFormat) FFMPEGPORTMONITOR_PIXELMAP[pixelCode],
536 SWS_BICUBIC,
537 NULL, NULL, NULL);
538 if (img_convert_ctx == NULL) {
539 yCError(FFMPEGMONITOR, "Cannot initialize the pixel format conversion context!");
540 av_freep(&endFrame->data[0]);
541 av_frame_free(&endFrame);
542 av_frame_free(&startFrame);
543 return -1;
544 }
545
546 // Perform conversion
547 ret = sws_scale(img_convert_ctx, startFrame->data, startFrame->linesize, 0,
548 h, endFrame->data, endFrame->linesize);
549
550 if (ret < 0) {
551 yCError(FFMPEGMONITOR, "Could not convert pixel format!");
552 av_freep(&endFrame->data[0]);
553 av_frame_free(&endFrame);
554 av_frame_free(&startFrame);
555 sws_freeContext(img_convert_ctx);
556 return -1;
557 }
558
559 // Copy decompressed data from end frame to imageOut
560 memcpy(imageOut.getRawImage(), endFrame->data[0], success);
561
562 // Free allocated memory
563 av_freep(&endFrame->data[0]);
564 av_frame_free(&endFrame);
565 av_frame_free(&startFrame);
566 sws_freeContext(img_convert_ctx);
567
568 return 0;
569
570}
571
572int FfmpegMonitorObject::getParamsFromCommandLine(std::string carrierString, AVCodecID &codecId) {
573
574 std::vector<std::string> parameters;
575 // Split command line string using '+' delimiter
576 split(carrierString, '+', parameters);
577
578 // Iterate over result strings
579 for (std::string param: parameters) {
580
581 // Skip YARP initial parameters
583 continue;
584 }
585
586 // If there is no '.', the param is bad formatted, return error
587 auto pointPosition = param.find('.');
588 if (pointPosition == std::string::npos) {
589 yCError(FFMPEGMONITOR, "Error parsing parameters!");
590 return -1;
591 }
592
593 // Otherwise, separate key and value
594 std::string paramKey = param.substr(0, pointPosition);
595 std::string paramValue = param.substr(pointPosition + 1, param.length());
596
597 // Parsing codec
598 if (paramKey == FFMPEGPORTMONITOR_CL_CODEC_KEY) {
599 bool found = false;
600 // Iterate over codecs command line possibilities
601 for (size_t i = 0; i < FFMPEGPORTMONITOR_CL_CODECS.size(); i++) {
602 // If found
603 if (paramValue == FFMPEGPORTMONITOR_CL_CODECS[i]) {
604 // Set codec id basing on codec command line name
605 codecId = (AVCodecID) FFMPEGPORTMONITOR_CODE_CODECS[i];
606 codecName = paramValue;
607 found = true;
608 break;
609 }
610 }
611
612 // If not found, unrecognized codec, return error
613 if (!found) {
614 yCError(FFMPEGMONITOR, "Unrecognized codec: %s", paramValue.c_str());
615 return -1;
616 } else {
617 continue;
618 }
619
620 }
621
622 // Save param into params map
623 paramsMap.insert( std::pair<std::string, std::string>(paramKey, paramValue) );
624 }
625 return 0;
626
627}
628
630
631 // Iterate over all saved parameters
632 for (auto const& x : paramsMap) {
633
634 // Get key and value
635 std::string key = x.first;
636 std::string value = x.second;
637
638 // Try to set this pair (key, value) into codec context (global parameters).
639 int globalError = av_opt_set(codecContext, key.c_str(), value.c_str(), 0);
640 // Try to set this pair (key, value) into codec context -> priv data (parameters that are specific for a codec).
641 int privError = av_opt_set(codecContext->priv_data, key.c_str(), value.c_str(), 0);
642
643 // If the param exists, but the value is out of range
644 if (globalError == AVERROR(ERANGE) || privError == AVERROR(ERANGE)) {
645 yCError(FFMPEGMONITOR, "Parameter out of range: %s", key.c_str());
646 return -1;
647 }
648 // If the param exists, but the value is invalid
649 else if (globalError == AVERROR(EINVAL) || privError == AVERROR(EINVAL)) {
650 yCError(FFMPEGMONITOR, "Invalid value for parameter: %s", key.c_str());
651 return -1;
652 }
653 // If the param doesn't exists (we check only in sender side because some parameters doesn't exist in the decoders)
654 else if (senderSide && globalError == AVERROR_OPTION_NOT_FOUND && privError == AVERROR_OPTION_NOT_FOUND) {
655 yCError(FFMPEGMONITOR, "Parameter not found: %s", key.c_str());
656 return -1;
657 }
658
659 }
660 return 0;
661}
bool ret
int getParamsFromCommandLine(std::string carrierString, AVCodecID &codecId)
This function parses the command line parameters from a string containing the entire command used to ...
yarp::sig::FlexImage imageOut
The final decompressed image that will be sent to the original destination.
int compress(yarp::sig::Image *img, AVPacket *pkt)
This function performs all the compression actions on the incoming Image and saves the resulting comp...
bool accept(yarp::os::Things &thing) override
This function is used by the port monitor to decide if an incoming packet can be accepted (it tries t...
int setCommandLineParams()
This function iterates over the attribute paramsMap and sets all the specified parameters into the at...
bool firstTime
Boolean variable used to check if the current call to the "compression" (or "decompression") function...
std::string codecName
The string containing codec name.
yarp::os::Things & update(yarp::os::Things &thing) override
This function is the one that manipulates the incoming packet.
yarp::os::Bottle data
The bottle that is filled with compressed image and all the information needed for decompression (it ...
const AVCodec * codec
Ffmpeg structure containing all codec information needed for compression / decompression.
yarp::os::Things th
The object returned by the "update" function; it can be a yarp::os::Bottle (sender side) or a yarp::s...
bool senderSide
Boolean variable that tells if the current execution is in sender side or not.
bool create(const yarp::os::Property &options) override
This function is called when the object is created and it is used to initialize all its attributes.
bool setparam(const yarp::os::Property &params) override
This will be called when the portmonitor carrier parameters are set via YARP admin port.
bool getparam(yarp::os::Property &params) override
This will be called when the portmonitor carrier parameters are requested via YARP admin port.
int decompress(AVPacket *pkt, int w, int h, int pixelCode)
This function decompresses the incoming AVPacket passed as parameter and saves decompressed data into...
std::map< std::string, std::string > paramsMap
Structure that maps every parameter inserted from command line into its value (both as strings).
void destroy(void) override
This function is called when the execution is terminated and the object is destroyed.
AVCodecContext * codecContext
Ffmpeg structure containing all codec context information needed for compression / decompression.
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:64
void add(const Value &value)
Add a Value to the bottle, at the end of the list.
Definition: Bottle.cpp:336
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
Definition: Bottle.cpp:246
void clear()
Empties the bottle of any objects it contains.
Definition: Bottle.cpp:121
void addInt32(std::int32_t x)
Places a 32-bit integer in the bottle, at the end of the list.
Definition: Bottle.cpp:140
static LogCallback printCallback()
Get current print callback.
Definition: Log.cpp:880
static LogType minimumPrintLevel()
Get current minimum print level.
Definition: Log.cpp:833
@ LogTypeReserved
Definition: Log.h:97
A class for storing options and configuration information.
Definition: Property.h:33
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
Definition: Property.cpp:1051
Base class for generic things.
Definition: Things.h:18
T * cast_as()
Definition: Things.h:53
void setPortWriter(yarp::os::PortWriter *writer)
Set the reference to a PortWriter object.
Definition: Things.cpp:26
A single value (typically within a Bottle).
Definition: Value.h:43
virtual bool asBool() const
Get boolean value.
Definition: Value.cpp:186
virtual std::int32_t asInt32() const
Get 32-bit integer value.
Definition: Value.cpp:204
virtual const char * asBlob() const
Get binary data value.
Definition: Value.cpp:261
virtual std::string asString() const
Get string value.
Definition: Value.cpp:234
void setPixelCode(int imgPixelCode)
Definition: Image.h:414
void setPixelSize(size_t imgPixelSize)
Definition: Image.h:419
Base class for storing images.
Definition: Image.h:79
size_t width() const
Gets width of image in pixels.
Definition: Image.h:163
size_t getRowSize() const
Size of the underlying image buffer rows.
Definition: Image.h:189
unsigned char * getRawImage() const
Access to the internal image buffer.
Definition: Image.cpp:542
virtual size_t getPixelSize() const
Gets pixel size in memory in bytes.
Definition: Image.cpp:436
void resize(size_t imgWidth, size_t imgHeight)
Reallocate an image to be of a desired size, throwing away its current contents.
Definition: Image.cpp:453
void zero()
Set all pixels to 0.
Definition: Image.cpp:446
size_t height() const
Gets height of image in pixels.
Definition: Image.h:169
virtual int getPixelCode() const
Gets pixel type identifier.
Definition: Image.cpp:441
File containing constans used in FfmpegPortmonitor.cpp.
static const std::vector< std::string > FFMPEGPORTMONITOR_IGNORE_PARAMS
This vector contains all parameters that have to be ignored while parsing command line string.
Definition: constants.h:34
static const std::string FFMPEGPORTMONITOR_CL_CODEC_KEY
This string is the "key" value for the codec parameter.
Definition: constants.h:48
static std::map< int, int > FFMPEGPORTMONITOR_CODECPIXELMAP
This structure maps Ffmpeg video codecs with their needed Ffmpeg pixel format code.
Definition: constants.h:86
static const std::vector< std::string > FFMPEGPORTMONITOR_CL_CODECS
This vector contains the only accepted values for the command line parameter "codec".
Definition: constants.h:54
static std::map< int, int > FFMPEGPORTMONITOR_PIXELMAP
This structure maps YARP pixel format codec into Ffmpeg pixel format codes.
Definition: constants.h:74
static const std::vector< int > FFMPEGPORTMONITOR_CODE_CODECS
This vector contains the codec ids corresponding to the codecs of the FFMPEGPORTMONITOR_CL_CODECS vec...
Definition: constants.h:64
void split(const std::string &s, char delim, std::vector< std::string > &elements)
This function simply splits a string into a vector of strings basing on a delimiter character.
Header file of FfmpegPortmonitor: a port monitor for video compression/decompression.
#define yCError(component,...)
Definition: LogComponent.h:213
#define yCTrace(component,...)
Definition: LogComponent.h:84
#define YARP_LOG_COMPONENT(name,...)
Definition: LogComponent.h:76
An interface to the operating system, including Port based communication.