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>
45 "yarp.carrier.portmonitor.image_compression_ffmpeg",
53 std::istringstream
iss(s);
57 elements.push_back(
item);
100 yCWarning(
FFMPEGMONITOR,
"The specified codec (%s) has unknown available pixel formats. There might be visualization issues.",
codec->name);
124 test =
codec->pix_fmts[i];
138 yCError(
FFMPEGMONITOR,
"The specified codec (%s) is not compatible with the default pixel format AV_PIX_FMT_YUV420P (code %d). "
139 "Try specifying the suggested pixel format of the codec with the option \"pixel_format.%d\". "
140 "The available pixel formats are %s.",
145 yCError(
FFMPEGMONITOR,
"The specified codec (%s) is not compatible with the specified pixel format (code %d). "
146 "The available pixel formats are as follows %s (suggested = %d).",
172#if LIBAVCODEC_VERSION_MAJOR < 61
205 yCError(
FFMPEGMONITOR,
"Expected type Image or Bottle in sender side, but got wrong data type!");
254 yCInfo(
FFMPEGMONITOR,
"Statistics: current bandwidth %s kb/s, codec computational time %s ms",
268 if (img ==
nullptr) {
315 for (
int i = 0; i <
packet->side_data_elems; i++) {
370 packet->side_data_elems = 0;
371 packet->stream_index =
tmp->stream_index;
381 for (
int i = 0; i <
tmp->side_data_elems; i++) {
422 int w = img->
width();
533#if LIBAVCODEC_VERSION_MAJOR >= 61
567 }
else if (
ret < 0) {
709 std::vector<std::string> parameters;
718 for (std::string& param: parameters) {
900 std::string key = x.first;
901 std::string value = x.second;
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 getParamsFromCommandLine(std::string carrierString, const AVCodec *&codecOut, AVPixelFormat &pixelFormatOut, int &frameRate)
This function parses the command line parameters from a string containing the entire command used to ...
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 ¶ms) override
This will be called when the portmonitor carrier parameters are set via YARP admin port.
bool getparam(yarp::os::Property ¶ms) 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.
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.
void add(const Value &value)
Add a Value to the bottle, at the end of the list.
void clear()
Empties the bottle of any objects it contains.
void addInt32(std::int32_t x)
Places a 32-bit integer in the bottle, at the end of the list.
A mini-server for performing network communication in the background.
static LogCallback printCallback()
Get current print callback.
static LogType minimumPrintLevel()
Get current minimum print level.
static bool copyPortable(const PortWriter &writer, PortReader &reader)
Copy one portable to another, via writing and reading.
A class for storing options and configuration information.
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
Base class for generic things.
void setPortWriter(yarp::os::PortWriter *writer)
Set the reference to a PortWriter object.
A single value (typically within a Bottle).
virtual bool asBool() const
Get boolean value.
virtual std::string asString() const
Get string value.
void setPixelCode(int imgPixelCode)
void setPixelSize(size_t imgPixelSize)
Base class for storing images.
size_t width() const
Gets width of image in pixels.
size_t getRowSize() const
Size of the underlying image buffer rows.
unsigned char * getRawImage() const
Access to the internal image buffer.
virtual size_t getPixelSize() const
Gets pixel size in memory in bytes.
void resize(size_t imgWidth, size_t imgHeight)
Reallocate an image to be of a desired size, throwing away its current contents.
void zero()
Set all pixels to 0.
size_t height() const
Gets height of image in pixels.
virtual int getPixelCode() const
Gets pixel type identifier.
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.
static const std::string FFMPEGPORTMONITOR_CL_CODEC_KEY
This string is the "key" value for the codec parameter.
static const std::string FFMPEGPORTMONITOR_CL_CUSTOM_DEC_KEY
This string is the "key" value for the custom decoder parameter.
static const std::vector< std::string > FFMPEGPORTMONITOR_CL_CODECS
This vector contains the only accepted values for the command line parameter "codec".
static std::map< int, int > FFMPEGPORTMONITOR_PIXELMAP
This structure maps YARP pixel format codec into Ffmpeg pixel format codes.
static const std::string FFMPEGPORTMONITOR_CL_PIXEL_FORMAT_KEY
This string is the "key" value for the pixel format parameter.
static const std::string FFMPEGPORTMONITOR_CL_CUSTOM_ENC_KEY
This string is the "key" value for the custom encoder parameter.
static const std::vector< int > FFMPEGPORTMONITOR_CODE_CODECS
This vector contains the codec ids corresponding to the codecs of the FFMPEGPORTMONITOR_CL_CODECS vec...
static const std::string FFMPEGPORTMONITOR_CL_FRAME_RATE_KEY
This string is the "key" value for the frame rate parameter.
static const std::string FFMPEGPORTMONITOR_CL_PRINT_STATISTICS_KEY
This string is the "key" value to enable the print statistics.
static AVPixelFormat FFMPEGPORTMONITOR_DEFAULT_PIXEL_FORMAT
Default pixel format to be used within ffmpeg.
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.
An interface to the operating system, including Port based communication.