YARP
Yet Another Robot Platform
FfmpegMonitorObject Class Reference

image_compression_ffmpeg: This portmonitor uses Ffmpeg to compress and decompress video streams with a specified codec. More...

#include </home/runner/work/yarp-documentation/yarp-documentation/yarp/src/portmonitors/image_compression_ffmpeg/ffmpegPortmonitor.h>

+ Inheritance diagram for FfmpegMonitorObject:

Public Member Functions

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. More...
 
void destroy (void) override
 This function is called when the execution is terminated and the object is destroyed. More...
 
bool setparam (const yarp::os::Property &params) override
 This will be called when the portmonitor carrier parameters are set via YARP admin port. More...
 
bool getparam (yarp::os::Property &params) override
 This will be called when the portmonitor carrier parameters are requested via YARP admin port. More...
 
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 to cast it to the right type). More...
 
yarp::os::Thingsupdate (yarp::os::Things &thing) override
 This function is the one that manipulates the incoming packet. More...
 
- Public Member Functions inherited from yarp::os::MonitorObject
virtual ~MonitorObject ()
 
virtual bool create (const yarp::os::Property &options)
 This will be called when the dll is properly loaded by the portmonitor carrier. More...
 
virtual void destroy ()
 This will be called when the portmonitor object destroyes. More...
 
virtual bool setparam (const yarp::os::Property &params)
 This will be called when the portmonitor carrier parameters are set via YARP admin port. More...
 
virtual bool getparam (yarp::os::Property &params)
 This will be called when the portmonitor carrier parameters are requested via YARP admin port. More...
 
virtual void trig ()
 This will be called when one of the peer connections to the same import port receives data. More...
 
virtual bool accept (yarp::os::Things &thing)
 This will be called when the data reach the portmonitor object. More...
 
virtual yarp::os::Thingsupdate (yarp::os::Things &thing)
 After data get accpeted in the accept() callback, an instance of that is given to the update function where the data can be accessed and modified. More...
 
virtual yarp::os::ThingsupdateReply (yarp::os::Things &thing)
 The updateReply makes it possible to modify a reply from a port when the portmonitor object is attached to a two-ways connection (e.g., RPC). More...
 

Public Attributes

yarp::os::Things th
 The object returned by the "update" function; it can be a yarp::os::Bottle (sender side) or a yarp::sig::Image (receiver side). More...
 
yarp::os::Bottle data
 The bottle that is filled with compressed image and all the information needed for decompression (it will be sent from sender to receiver). More...
 
yarp::sig::FlexImage imageOut
 The final decompressed image that will be sent to the original destination. More...
 
bool senderSide
 Boolean variable that tells if the current execution is in sender side or not. More...
 
std::string codecName
 The string containing codec name. More...
 
const AVCodec * codec
 Ffmpeg structure containing all codec information needed for compression / decompression. More...
 
AVCodecContext * codecContext = NULL
 Ffmpeg structure containing all codec context information needed for compression / decompression. More...
 
bool firstTime
 Boolean variable used to check if the current call to the "compression" (or "decompression") function is the first one or not. More...
 
std::map< std::string, std::string > paramsMap
 Structure that maps every parameter inserted from command line into its value (both as strings). More...
 

Protected Member Functions

int compress (yarp::sig::Image *img, AVPacket *pkt)
 This function performs all the compression actions on the incoming Image and saves the resulting compressed data into the AVPacket passed as parameter. More...
 
int decompress (AVPacket *pkt, int w, int h, int pixelCode)
 This function decompresses the incoming AVPacket passed as parameter and saves decompressed data into the attribute imageOut (yarp::sig::FlexImage). More...
 
int getParamsFromCommandLine (std::string carrierString, AVCodecID &codecId)
 This function parses the command line parameters from a string containing the entire command used to execute the program and saves the parameters into the attribute paramsMap (std::map<std::string, std::string>). More...
 
int setCommandLineParams ()
 This function iterates over the attribute paramsMap and sets all the specified parameters into the attribute codecContext. More...
 

Detailed Description

image_compression_ffmpeg: This portmonitor uses Ffmpeg to compress and decompress video streams with a specified codec.

Definition at line 33 of file ffmpegPortmonitor.h.

Member Function Documentation

◆ accept()

bool FfmpegMonitorObject::accept ( yarp::os::Things thing)
overridevirtual

This function is used by the port monitor to decide if an incoming packet can be accepted (it tries to cast it to the right type).

The accepted packets are then handled by the function "update"; the others are discarded.

Parameters
thingThe incoming packet; must be a yarp::sig::Image in sender side, must be a yarp::sig::Bottle in receiver side.
Returns
true If the packet was successfully cast.
false Otherwise.

Reimplemented from yarp::os::MonitorObject.

Definition at line 141 of file ffmpegPortmonitor.cpp.

◆ compress()

int FfmpegMonitorObject::compress ( yarp::sig::Image img,
AVPacket *  pkt 
)
protected

This function performs all the compression actions on the incoming Image and saves the resulting compressed data into the AVPacket passed as parameter.

Parameters
imgThe incoming image.
pktThe packet containing all the compressed data.
Returns
int 0 on success, -1 otherwise.

Definition at line 293 of file ffmpegPortmonitor.cpp.

◆ create()

bool FfmpegMonitorObject::create ( const yarp::os::Property options)
overridevirtual

This function is called when the object is created and it is used to initialize all its attributes.

It is called both on sender and receiver side, and it performs different initializations basing on side check.

Parameters
optionsParameters passed to the object to initialize it (e.g. command line parameters).
Returns
true If the creation was successful and all needed variables are correctly initialized.
false Otherwise.

Reimplemented from yarp::os::MonitorObject.

Definition at line 66 of file ffmpegPortmonitor.cpp.

◆ decompress()

int FfmpegMonitorObject::decompress ( AVPacket *  pkt,
int  w,
int  h,
int  pixelCode 
)
protected

This function decompresses the incoming AVPacket passed as parameter and saves decompressed data into the attribute imageOut (yarp::sig::FlexImage).

Parameters
pktThe incoming packet containing all the compressed data.
wThe width of the image (in pixels).
hThe height of the image (in pixels).
pixelCodeThe YARP pixel format code of the image.
Returns
int 0 on success, -1 otherwise.

Definition at line 445 of file ffmpegPortmonitor.cpp.

◆ destroy()

void FfmpegMonitorObject::destroy ( void  )
overridevirtual

This function is called when the execution is terminated and the object is destroyed.

It frees the memory allocated during the "create" function.

Reimplemented from yarp::os::MonitorObject.

Definition at line 117 of file ffmpegPortmonitor.cpp.

◆ getparam()

bool FfmpegMonitorObject::getparam ( yarp::os::Property params)
overridevirtual

This will be called when the portmonitor carrier parameters are requested via YARP admin port.

Parameters
paramsThe Property
Returns
Returns true of any parameter is available

Reimplemented from yarp::os::MonitorObject.

Definition at line 135 of file ffmpegPortmonitor.cpp.

◆ getParamsFromCommandLine()

int FfmpegMonitorObject::getParamsFromCommandLine ( std::string  carrierString,
AVCodecID &  codecId 
)
protected

This function parses the command line parameters from a string containing the entire command used to execute the program and saves the parameters into the attribute paramsMap (std::map<std::string, std::string>).

Parameters
carrierStringThe entire command used to execute the program.
codecIdThe codec for video compression / decompression.
Returns
int 0 on success, -1 otherwise.

Definition at line 572 of file ffmpegPortmonitor.cpp.

◆ setCommandLineParams()

int FfmpegMonitorObject::setCommandLineParams ( )
protected

This function iterates over the attribute paramsMap and sets all the specified parameters into the attribute codecContext.

Returns
int 0 on success, -1 otherwise.

Definition at line 629 of file ffmpegPortmonitor.cpp.

◆ setparam()

bool FfmpegMonitorObject::setparam ( const yarp::os::Property params)
overridevirtual

This will be called when the portmonitor carrier parameters are set via YARP admin port.

Parameters
paramsThe Property
Returns
Returns true if parameters are correctly set

Reimplemented from yarp::os::MonitorObject.

Definition at line 129 of file ffmpegPortmonitor.cpp.

◆ update()

yarp::os::Things & FfmpegMonitorObject::update ( yarp::os::Things thing)
overridevirtual

This function is the one that manipulates the incoming packet.

In sender side, it takes the Image and sends it to the "compress" function. Then it fills a Bottle containing the compressed Image and all the information needed for decompression. In receiver side, it takes the incoming Bottle and unpacks it; then it sends all compressed data to the "decompress" function; it finally creates a new Image object filled with decompressed data.

Parameters
thingThe incoming packet; it is a yarp::sig::Image in sender side, a yarp::sig::Bottle in receiver side.
Returns
yarp::os::Things& The newly created object; it is a yarp::sig::Bottle in sender side (containing compressed data to be sent to receiver); it is a yarp::sig::FlexImage in receiver side (to be sent to the original destination).

Reimplemented from yarp::os::MonitorObject.

Definition at line 168 of file ffmpegPortmonitor.cpp.

Member Data Documentation

◆ codec

const AVCodec* FfmpegMonitorObject::codec

Ffmpeg structure containing all codec information needed for compression / decompression.

Definition at line 143 of file ffmpegPortmonitor.h.

◆ codecContext

AVCodecContext* FfmpegMonitorObject::codecContext = NULL

Ffmpeg structure containing all codec context information needed for compression / decompression.

Definition at line 149 of file ffmpegPortmonitor.h.

◆ codecName

std::string FfmpegMonitorObject::codecName

The string containing codec name.

Definition at line 137 of file ffmpegPortmonitor.h.

◆ data

yarp::os::Bottle FfmpegMonitorObject::data

The bottle that is filled with compressed image and all the information needed for decompression (it will be sent from sender to receiver).

Definition at line 119 of file ffmpegPortmonitor.h.

◆ firstTime

bool FfmpegMonitorObject::firstTime

Boolean variable used to check if the current call to the "compression" (or "decompression") function is the first one or not.

Definition at line 155 of file ffmpegPortmonitor.h.

◆ imageOut

yarp::sig::FlexImage FfmpegMonitorObject::imageOut

The final decompressed image that will be sent to the original destination.

Definition at line 125 of file ffmpegPortmonitor.h.

◆ paramsMap

std::map<std::string, std::string> FfmpegMonitorObject::paramsMap

Structure that maps every parameter inserted from command line into its value (both as strings).

Definition at line 161 of file ffmpegPortmonitor.h.

◆ senderSide

bool FfmpegMonitorObject::senderSide

Boolean variable that tells if the current execution is in sender side or not.

Definition at line 131 of file ffmpegPortmonitor.h.

◆ th

yarp::os::Things FfmpegMonitorObject::th

The object returned by the "update" function; it can be a yarp::os::Bottle (sender side) or a yarp::sig::Image (receiver side).

Definition at line 113 of file ffmpegPortmonitor.h.


The documentation for this class was generated from the following files: