YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
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/os/Time.h>
21#include <yarp/sig/all.h>
22// Standard imports
23#include <cstring>
24#include <cmath>
25#include <algorithm>
26#include <iostream>
27#include <sstream>
28#include <mutex>
29#include <iomanip>
30
31// Ffmpeg imports
32extern "C" {
33 #include <libavcodec/avcodec.h>
34 #include <libavutil/opt.h>
35 #include <libavutil/imgutils.h>
36 #include <libavformat/avformat.h>
37 #include <libswscale/swscale.h>
38}
39
40using namespace yarp::os;
41using namespace yarp::sig;
42
43namespace {
45 "yarp.carrier.portmonitor.image_compression_ffmpeg",
49 nullptr)
50
51} // anonymous namespace
52
53// As per version 5.1.2 of ffmpeg, there seem to be race conditions between sws_scale and
54// sws_freeContext even when called from different instances on different threads.
55// We use a static mutex to prevent segmentation faults when connecting two port monitors
56// to the same sender or receiver.
57static std::mutex instances_mutex;
58
60{
61 // Check if this is sender or not
62 senderSide = (options.find("sender_side").asBool());
63 printStatistics = false;
69
70 // Parse command line parameters and set them into global variable "paramsMap"
71 int frameRate = 15;
73 return false;
74 }
75
76 // Prepare codec context
77 if (codecContext == NULL) {
79 } else {
80 yCError(FFMPEGMONITOR, "Codec context is already allocated");
81 return false;
82 }
83 if (!codecContext) {
84 yCError(FFMPEGMONITOR, "Could not allocate video codec context");
85 return false;
86 }
87
88 // FFmpeg 8 (libavcodec 62) removed AVCodec::pix_fmts; since FFmpeg 7.1
89 // (libavcodec 61.13.100) avcodec_get_supported_config() must be used instead.
90#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(61, 13, 100)
91 const AVPixelFormat* pix_fmts = nullptr;
92 {
93 const void* out = nullptr;
95 pix_fmts = static_cast<const AVPixelFormat*>(out);
96 }
97 }
98#else
99 const AVPixelFormat* pix_fmts = codec->pix_fmts;
100#endif
101
102 if (!pix_fmts)
103 {
104 yCWarning(FFMPEGMONITOR, "The specified codec (%s) has unknown available pixel formats. There might be visualization issues.", codec->name);
105 }
106 else
107 {
108 std::stringstream pixelFormatList;
109 bool found = false;
110 size_t i = 0;
111 AVPixelFormat test = pix_fmts[i];
112
113 if (test == AV_PIX_FMT_NONE)
114 {
115 yCError(FFMPEGMONITOR, "The specified codec (%s) has no available pixel format.", codec->name);
116 return false;
117 }
118
119 pixelFormatList << test;
120 while (test != AV_PIX_FMT_NONE)
121 {
122 if (test == pixelFormat)
123 {
124 found = true;
125 break;
126 }
127 ++i;
128 test = pix_fmts[i];
129
130 if (test != AV_PIX_FMT_NONE)
131 {
132 pixelFormatList << ", " << test;
133 }
134 }
135
136 if (!found)
137 {
139
141 {
142 yCError(FFMPEGMONITOR, "The specified codec (%s) is not compatible with the default pixel format AV_PIX_FMT_YUV420P (code %d). "
143 "Try specifying the suggested pixel format of the codec with the option \"pixel_format.%d\". "
144 "The available pixel formats are %s.",
146 }
147 else
148 {
149 yCError(FFMPEGMONITOR, "The specified codec (%s) is not compatible with the specified pixel format (code %d). "
150 "The available pixel formats are as follows %s (suggested = %d).",
151 codec->name, pixelFormat, pixelFormatList.str().c_str(), suggestedFormat);
152 }
153 return false;
154 }
155 }
156
157 firstTime = true;
158
159 // Set time base parameter
160 codecContext->time_base.num = 1;
161 codecContext->time_base.den = frameRate;
162 // Set command line params
163 if (setCommandLineParams() == -1) {
164 return false;
165 }
166
167 return true;
168}
169
171{
172 paramsMap.clear();
173
174 // Check if codec context is freeable, if yes free it.
175 if (codecContext != NULL) {
176#if LIBAVCODEC_VERSION_MAJOR < 61
177 // See https://github.com/FFmpeg/FFmpeg/blob/n7.0/libavcodec/avcodec.h#L2381-L2384
179#endif
182 }
183}
184
186{
187 yCTrace(FFMPEGMONITOR, "setparam");
188 return false;
189}
190
192{
193 yCTrace(FFMPEGMONITOR, "getparam");
194 return false;
195}
196
198{
199 if (senderSide) {
200 // If sender side
201 yCTrace(FFMPEGMONITOR, "accept - sender");
202 // Try to cast the Thing into an Image
203 Image* img = thing.cast_as< Image >();
204 // If cast fails, try to cast the Thing into a Bottle
205 if(img == nullptr) {
206 Bottle* bt = thing.cast_as<Bottle>();
207 // If cast fails, return error
208 if (bt == nullptr) {
209 yCError(FFMPEGMONITOR, "Expected type Image or Bottle in sender side, but got wrong data type!");
210 return false;
211 }
212 }
213 }
214 else {
215 // If receiver side
216 yCTrace(FFMPEGMONITOR, "accept - receiver");
217 // Try to cast the Thing into a Bottle
218 Bottle* bt = thing.cast_as<Bottle>();
219 // If cast fails, return error
220 if(bt == nullptr){
221 yCError(FFMPEGMONITOR, "Expected type Bottle in receiver side, but got wrong data type!");
222 return false;
223 }
224 }
225 return true;
226}
227
229{
230 double now = yarp::os::Time::now();
231 const double printInterval = 5.0;
232
233 if (statisticsCounter < 0)
234 {
235 previousFrameTime = now;
238 }
239 else
240 {
241 size_t outputData{0};
242 inputBottle.toBinary(&outputData);
243 double dt = now - previousFrameTime;
244 double bandwidth = outputData * 8 / dt /1000;
249
250 }
252 {
255 std::stringstream bandwidthString, lagString;
256 bandwidthString << std::fixed << std::setprecision(2) << bandwidthRunningAverage;
257 lagString << std::fixed << std::setprecision(3) << lagRunningAverage * 1000;
258 yCInfo(FFMPEGMONITOR, "Statistics: current bandwidth %s kb/s, codec computational time %s ms",
259 bandwidthString.str().c_str(), lagString.str().c_str());
260 }
261}
262
264{
265 double startTime = yarp::os::Time::now();
266 if (senderSide) {
267 bool success = true;
268 yCTrace(FFMPEGMONITOR, "update - sender");
269 // Cast Thing into an Image
270 Image* img = thing.cast_as< Image >();
271
272 if (img == nullptr) {
273 Bottle* bot = thing.cast_as<Bottle>();
275 {
276 yCError(FFMPEGMONITOR, "The input type is a Bottle, but it cannot be copied to an Image");
277 success = false;
278 }
279 img = &imageBottleBuffer;
280 }
281
282 // Allocate memory for packet
284 if (packet == NULL) {
285 yCError(FFMPEGMONITOR, "Error in packet allocation");
286 success = false;
287 }
288
289 // Call compress function
290 if (success && compress(img, packet) != 0) {
291 yCError(FFMPEGMONITOR, "Error in compression");
292 success = false;
293 }
294
295 // Insert compressed image into a Bottle to be sent
296 data.clear();
297
298 int successCode = success ? 1 : 0;
300 data.addInt32(img->width());
301 data.addInt32(img->height());
302 data.addInt32(img->getPixelCode());
303 data.addInt32(img->getPixelSize());
304
305 if (success) { // If compression was successful, insert also compressed data
306 // Packet
307 Value p(packet, sizeof(*packet));
308 data.add(p);
309 // Packet data
310 Value d(packet->data, packet->size);
311 data.add(d);
312 // Buffer size
313 data.addInt32(packet->buf->size);
314 // Buffer data
315 Value bd(packet->buf->data, packet->buf->size);
316 data.add(bd);
317
318 // Side data elements
319 for (int i = 0; i < packet->side_data_elems; i++) {
320 data.addInt32(packet->side_data[i].size);
321 data.addInt32(packet->side_data[i].type);
322 Value sd(packet->side_data[i].data, packet->side_data[i].size);
323 data.add(sd);
324 }
325 }
326
327 if (printStatistics)
328 {
330 }
331
333 // Free the memory allocated for the packet
335 }
336 else {
337
338 yCTrace(FFMPEGMONITOR, "update - receiver");
339 // Cast the Thin as a Bottle
341 // Fill the final image with zeros
342 imageOut.zero();
343 // Extract decompression data from the Bottle
344 int width = compressedBottle->get(1).asInt32();
345 int height = compressedBottle->get(2).asInt32();
346 int pixelCode = compressedBottle->get(3).asInt32();
347 int pixelSize = compressedBottle->get(4).asInt32();
348 // Set information into final image
349
351 {
354 imageOut.resize(width, height);
355 }
356 else
357 {
358 yCError(FFMPEGMONITOR, "Invalid input pixel code");
359 }
360
361 // Check if compression was successful
362 if (compressedBottle->get(0).asInt32() == 1) {
363 bool success = true;
364 // Get compressed image from Bottle
365 AVPacket* tmp = (AVPacket*) compressedBottle->get(5).asBlob();
366 // Allocate memory for packet
368 // Set all packet parameters
369 packet->dts = tmp->dts;
370 packet->duration = tmp->duration;
371 packet->flags = tmp->flags;
372 packet->pos = tmp->pos;
373 packet->pts = tmp->pts;
374 packet->side_data_elems = 0;
375 packet->stream_index = tmp->stream_index;
376 packet->size = tmp->size;
377 // Image data
378 packet->data = (uint8_t *) compressedBottle->get(6).asBlob();
379 // Buffer data
380 packet->buf = av_buffer_create((uint8_t *) compressedBottle->get(8).asBlob(),
381 compressedBottle->get(7).asInt32(), av_buffer_default_free,
382 nullptr, AV_BUFFER_FLAG_READONLY);
383
384 // Packet side data
385 for (int i = 0; i < tmp->side_data_elems; i++) {
386
388 (AVPacketSideDataType) compressedBottle->get(10).asInt32(), // Type
389 (uint8_t *) compressedBottle->get(11).asBlob(), // Data
390 compressedBottle->get(9).asInt32()); // Size
391 if (ret < 0) {
392 success = false;
393 break;
394 }
395 }
396
397 // Call to decompress function
398 if (success && decompress(packet, width, height, pixelCode) != 0) {
399 yCError(FFMPEGMONITOR, "Error in decompression");
400 }
401
402 if (printStatistics)
403 {
405 }
406
407 // Free memory allocated for side data and packet
408 av_freep(&packet->side_data);
410
411 }
412
414
415 }
416 return th;
417}
418
420
421 yCTrace(FFMPEGMONITOR, "compress");
424
425 // Get width and height
426 int w = img->width();
427 int h = img->height();
428
429 // Allocate video frame for original frames
431 if (startFrame == NULL) {
432 yCError(FFMPEGMONITOR, "Cannot allocate starting frame!");
433 return -1;
434 }
435
436 // Allocate a video frame for end frame
438 if (endFrame == NULL) {
439 yCError(FFMPEGMONITOR, "Cannot allocate end frame!");
441 return -1;
442 }
443
444 // Allocate space into start frame to contain data
445 int success = av_image_alloc(startFrame->data, startFrame->linesize,
446 w, h,
448
449 if (success < 0) {
450 yCError(FFMPEGMONITOR, "Cannot allocate starting frame buffer!");
453 return -1;
454 }
455
456 // Set Image data into AVFrame
457 startFrame->linesize[0] = img->getRowSize();
458 // Free old pointer (because we will use the buffer contained into img)
459 av_freep(&startFrame->data[0]);
460 startFrame->data[0] = img->getRawImage();
461 startFrame->height = h;
462 startFrame->width = w;
464
465 // Allocate memory for end frame data
466 success = av_image_alloc(endFrame->data, endFrame->linesize,
467 w, h, pixelFormat, 16);
468
469 if (success < 0) {
470 yCError(FFMPEGMONITOR, "Cannot allocate end frame buffer!");
473 return -1;
474 }
475
476 // Set end frame parameters
477 endFrame->height = h;
478 endFrame->width = w;
479 endFrame->format = pixelFormat;
480
481 {
482 std::lock_guard<std::mutex> lock(instances_mutex);
483
484 // Convert the image from start format into end format
485 static struct SwsContext *img_convert_ctx;
486
487 // Allocate context for conversion
490 w, h,
493 NULL, NULL, NULL);
494 if (img_convert_ctx == NULL) {
495 yCError(FFMPEGMONITOR, "Cannot initialize pixel format conversion context!");
496 av_freep(&endFrame->data[0]);
499 return -1;
500 }
501
502 // Perform conversion
503 int ret = sws_scale(img_convert_ctx, startFrame->data, startFrame->linesize, 0,
504 h, endFrame->data, endFrame->linesize);
505
506 if (ret < 0) {
507 yCError(FFMPEGMONITOR, "Could not convert pixel format!");
509 av_freep(&endFrame->data[0]);
512 return -1;
513 }
514
515 if (firstTime) {
516 // If this is the first compression
517
518 // Set codec context parameters
519 codecContext->width = w;
520 codecContext->height = h;
521 codecContext->pix_fmt = pixelFormat;
522
523 // Open codec
525 if (ret < 0) {
526 yCError(FFMPEGMONITOR, "Could not open codec");
528 av_freep(&endFrame->data[0]);
531 return -1;
532 }
533 firstTime = false;
534 }
535
536 // Set presentation timestamp
537#if LIBAVCODEC_VERSION_MAJOR >= 61
538 // See https://github.com/FFmpeg/FFmpeg/commit/6b6f7db81932f94876ff4bcfd2da0582b8ab897e
539 endFrame->pts = codecContext->frame_num;
540#else
541 endFrame->pts = codecContext->frame_number;
542#endif
543
544 // Send image frame to codec
546 if (ret < 0) {
547 yCError(FFMPEGMONITOR, "Error sending a frame for encoding");
549 av_freep(&endFrame->data[0]);
552 return -1;
553 }
554
555 // Receive compressed data into packet
558 av_freep(&endFrame->data[0]);
561
562
563 if (ret == AVERROR(EAGAIN)) {
564 // Not enough data
565 yCError(FFMPEGMONITOR, "Error EAGAIN");
566 return -1;
567 } else if (ret == AVERROR_EOF) {
568 // End of file reached
569 yCError(FFMPEGMONITOR, "Error EOF");
570 return -1;
571 } else if (ret < 0) {
572 yCError(FFMPEGMONITOR, "Error during encoding");
573 return -1;
574 }
575 }
576
577 return 0;
578}
579
581
582 yCTrace(FFMPEGMONITOR, "decompress");
585
586 if (firstTime) {
587 // If this is the first decompression
588
589 // Set codec context parameters
590 codecContext->width = w;
591 codecContext->height = h;
592 codecContext->pix_fmt = pixelFormat;
593
594 // Open codec
596 if (ret < 0) {
597 yCError(FFMPEGMONITOR, "Could not open codec");
598 return -1;
599 }
600 firstTime = false;
601 }
602
603 // Allocate video frame
605 if (startFrame == NULL) {
606 yCError(FFMPEGMONITOR, "Could not allocate start frame!");
607 return -1;
608 }
609
610 // Send compressed packet to codec
612 if (ret < 0) {
613 yCError(FFMPEGMONITOR, "Error sending a frame for decoding");
615 return -1;
616 }
617
618 // Receive decompressed image into an AVFrame
620 if (ret == AVERROR(EAGAIN)) {
621 // No enough data
622 yCError(FFMPEGMONITOR, "Error EAGAIN");
624 return -1;
625 }
626 else if (ret == AVERROR_EOF) {
627 // End of file reached
628 yCError(FFMPEGMONITOR, "Error EOF");
630 return -1;
631 }
632 else if (ret < 0) {
633 yCError(FFMPEGMONITOR, "Error during decoding");
635 return -1;
636 }
637
638 // Allocate a video frame for end frame
640 if (endFrame == NULL) {
641 yCError(FFMPEGMONITOR, "Could not allocate start frame!");
643 return -1;
644 }
645
646 // Allocate memory into end frame to contain data
647 int success = av_image_alloc(endFrame->data, endFrame->linesize,
648 w, h,
650
651 if (success < 0) {
652 yCError(FFMPEGMONITOR, "Error allocating end frame buffer!");
655 return -1;
656 }
657
658 // Set end frame parameters
659 endFrame->height = h;
660 endFrame->width = w;
662
663 {
664 std::lock_guard<std::mutex> lock(instances_mutex);
665
666 // Convert the image into RGB format
667 static struct SwsContext *img_convert_ctx;
668
669 // Allocate conversion context
672 w, h,
675 NULL, NULL, NULL);
676 if (img_convert_ctx == NULL) {
677 yCError(FFMPEGMONITOR, "Cannot initialize the pixel format conversion context!");
678 av_freep(&endFrame->data[0]);
681 return -1;
682 }
683
684 // Perform conversion
685 ret = sws_scale(img_convert_ctx, startFrame->data, startFrame->linesize, 0,
686 h, endFrame->data, endFrame->linesize);
687
688 if (ret < 0) {
689 yCError(FFMPEGMONITOR, "Could not convert pixel format!");
690 av_freep(&endFrame->data[0]);
694 return -1;
695 }
696
697 // Copy decompressed data from end frame to imageOut
698 memcpy(imageOut.getRawImage(), endFrame->data[0], success);
699
700 // Free allocated memory
701 av_freep(&endFrame->data[0]);
705 }
706
707 return 0;
708}
709
711{
712
713 // Set default pixel format
715
716 bool customEnc = false;
717 bool customDec = false;
718
719 // checks for encoder/decoders
721 {
722 yCError(FFMPEGMONITOR, "`decoder` parameter is not allowed on sender side");
723 return false;
724 }
726 {
727 yCError(FFMPEGMONITOR, "`encoder` parameter is not allowed on receiver side");
728 return false;
729 }
730
732 {
733 std::string paramValue = inputoptions.find(FFMPEGPORTMONITOR_CL_ENCODER_KEY).asString();
734
736 if (!codecOut)
737 {
738 yCError(FFMPEGMONITOR, "Can't find encoder %s", paramValue.c_str());
739 codecOut = nullptr;
740 return false;
741 }
742 customEnc = true;
743 }
744
745 // parse for custom decoder
747 {
748 std::string paramValue = inputoptions.find(FFMPEGPORTMONITOR_CL_DECODER_KEY).asString();
749
751 if (!codecOut)
752 {
753 yCError(FFMPEGMONITOR, "Can't find decoder %s", paramValue.c_str());
754 codecOut = nullptr;
755 return false;
756 }
757 customDec = true;
758 }
759
760 //extra options: pixel format
762 {
764 pixelFormatOut = static_cast<AVPixelFormat>(std::atoi(paramValue.c_str()));
765 }
766
767 //extra options: frame rate
769 {
770 std::string paramValue = inputoptions.find(FFMPEGPORTMONITOR_CL_FRAME_RATE_KEY).asString();
771 frameRate = std::atoi(paramValue.c_str());
772 }
773
774 // extra options: statistics printing
776 {
778 printStatistics = std::atoi(paramValue.c_str());
779 }
780
781 // Iterate through all properties and save unknown parameters to paramsMap
783 std::string inputoptionsStr = inputoptions.toString();
785
786 for (size_t i = 0; i < propertyBottle.size(); i++)
787 {
788 Value& element = propertyBottle.get(i);
789 if (!element.isList()) { continue; }
790
791 Bottle* entry = element.asList();
792 if (entry->size() < 2) { continue; }
793
794 std::string key = entry->get(0).asString();
795
796 // Skip known parameters
802 key == "type" ||
803 key == "filename" ||
804 key == "source" ||
805 key == "destination" ||
806 key == "sender_side" ||
807 key == "receiver_side" ||
808 key == "carrier")
809 { continue;}
810
811
812 // Add unknown parameter to params map
813 std::string value = entry->get(1).toString();
814 paramsMap[key] = value;
815 }
816
817 if (!customEnc && senderSide==true)
818 {
819 yCWarning(FFMPEGMONITOR, "No encoder specified, using default codec (mpeg2video).");
820
821 // Set default codec
824 if (!codecOut) {
825 yCError(FFMPEGMONITOR, "Can't find default codec (mpeg2video).");
826 return false;
827 }
828 }
829 if (!customDec && senderSide==false)
830 {
831 yCWarning(FFMPEGMONITOR, "No decoder specified, using default codec (mpeg2video).");
832
833 // Set default codec
836 if (!codecOut) {
837 yCError(FFMPEGMONITOR, "Can't find default codec (mpeg2video).");
838 return false;
839 }
840 }
841
842 return true;
843}
844
846
847 // Iterate over all saved parameters
848 for (auto const& x : paramsMap) {
849
850 // Get key and value
851 std::string key = x.first;
852 std::string value = x.second;
853
854 // Try to set this pair (key, value) into codec context (global parameters).
855 int globalError = av_opt_set(codecContext, key.c_str(), value.c_str(), 0);
856 // Try to set this pair (key, value) into codec context -> priv data (parameters that are specific for a codec).
857 int privError = av_opt_set(codecContext->priv_data, key.c_str(), value.c_str(), 0);
858
859 // If the param exists, but the value is out of range
861 yCError(FFMPEGMONITOR, "Parameter out of range: %s", key.c_str());
862 return -1;
863 }
864 // If the param exists, but the value is invalid
865 else if (globalError == AVERROR(EINVAL) || privError == AVERROR(EINVAL)) {
866 yCError(FFMPEGMONITOR, "Invalid value for parameter: %s", key.c_str());
867 return -1;
868 }
869 // If the param doesn't exists (we check only in sender side because some parameters doesn't exist in the decoders)
871 yCError(FFMPEGMONITOR, "Parameter not found: %s", key.c_str());
872 return -1;
873 }
874
875 }
876 return 0;
877}
@ VOCAB_PIXEL_INVALID
Definition Image.h:41
void updateStatistics(yarp::os::Bottle &inputBottle, double currentLag)
Print some network statistics.
yarp::sig::FlexImage imageOut
The final decompressed image that will be sent to the original destination.
int statisticsCounter
Utility counter for printing statistics.
int compress(yarp::sig::Image *img, AVPacket *pkt)
This function performs all the compression actions on the incoming Image and saves the resulting comp...
AVPixelFormat pixelFormat
Ffmpeg pixel format.
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...
yarp::sig::Image imageBottleBuffer
The final decompressed image that will be sent to the original destination.
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.
double lagRunningAverage
Variable storing the current lag for statistics.
double previousFrameTime
Seconds since epoch of the previous frame;.
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 printStatistics
Boolean variable used to check whether the bandwidth statistics should be printed.
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...
double previousStatisticPrintTime
Utility variable to store the time in which the last time the statistics have been printed.
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.
bool parsePropertyParams(yarp::os::Property inputoptions, const AVCodec *&codecOut, AVPixelFormat &pixelFormatOut, int &frameRate)
This function parses the command line parameters from a string containing the entire command used to ...
AVCodecContext * codecContext
Ffmpeg structure containing all codec context information needed for compression / decompression.
double bandwidthRunningAverage
Variable storing the current bandwidth average for statistics.
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:310
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
A mini-server for performing network communication in the background.
static LogCallback printCallback()
Get current print callback.
Definition Log.cpp:892
static LogType minimumPrintLevel()
Get current minimum print level.
Definition Log.cpp:852
@ LogTypeReserved
Definition Log.h:98
static bool copyPortable(const PortWriter &writer, PortReader &reader)
Copy one portable to another, via writing and reading.
Definition Portable.cpp:16
A class for storing options and configuration information.
Definition Property.h:32
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
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:44
virtual bool asBool() const
Get boolean value.
Definition Value.cpp:186
void setPixelCode(int imgPixelCode)
Definition Image.h:364
void setPixelSize(size_t imgPixelSize)
Definition Image.h:369
Base class for storing images.
Definition Image.h:79
size_t width() const
Gets width of image in pixels.
Definition Image.h:171
size_t getRowSize() const
Size of the underlying image buffer rows.
Definition Image.h:197
unsigned char * getRawImage() const
Access to the internal image buffer.
Definition Image.cpp:462
virtual size_t getPixelSize() const
Gets pixel size in memory in bytes.
Definition Image.cpp:370
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:387
void zero()
Set all pixels to 0.
Definition Image.cpp:380
size_t height() const
Gets height of image in pixels.
Definition Image.h:177
virtual int getPixelCode() const
Gets pixel type identifier.
Definition Image.cpp:375
File containing constans used in FfmpegPortmonitor.cpp.
static std::map< int, int > FFMPEGPORTMONITOR_PIXELMAP
This structure maps YARP pixel format codec into Ffmpeg pixel format codes.
Definition constants.h:84
static const std::string FFMPEGPORTMONITOR_CL_PIXEL_FORMAT_KEY
This string is the "key" value for the pixel format parameter.
Definition constants.h:56
static const std::string FFMPEGPORTMONITOR_CL_FRAME_RATE_KEY
This string is the "key" value for the frame rate parameter.
Definition constants.h:62
static const std::string FFMPEGPORTMONITOR_CL_DECODER_KEY
This string is the "key" value for the custom decoder parameter.
Definition constants.h:50
static const std::string FFMPEGPORTMONITOR_CL_PRINT_STATISTICS_KEY
This string is the "key" value to enable the print statistics.
Definition constants.h:68
static AVPixelFormat FFMPEGPORTMONITOR_DEFAULT_PIXEL_FORMAT
Default pixel format to be used within ffmpeg.
Definition constants.h:96
static const std::string FFMPEGPORTMONITOR_CL_ENCODER_KEY
This string is the "key" value for the custom encoder parameter.
Definition constants.h:44
static std::mutex instances_mutex
Header file of FfmpegPortmonitor: a port monitor for video compression/decompression.
#define yCInfo(component,...)
#define yCError(component,...)
#define yCTrace(component,...)
#define yCWarning(component,...)
#define YARP_LOG_COMPONENT(name,...)
double now()
Return the current time in seconds, relative to an arbitrary starting point.
Definition Time.cpp:121
An interface to the operating system, including Port based communication.