YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
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.
 
void destroy (void) override
 This function is called when the execution is terminated and the object is destroyed.
 
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.
 
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).
 
yarp::os::Thingsupdate (yarp::os::Things &thing) override
 This function is the one that manipulates the incoming packet.
 
- Public Member Functions inherited from yarp::os::MonitorObject
virtual ~MonitorObject ()
 
virtual void trig ()
 This will be called when one of the peer connections to the same import port receives data.
 
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).
 

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).
 
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).
 
yarp::sig::FlexImage imageOut
 The final decompressed image that will be sent to the original destination.
 
yarp::sig::Image imageBottleBuffer
 The final decompressed image that will be sent to the original destination.
 
bool senderSide
 Boolean variable that tells if the current execution is in sender side or not.
 
const AVCodec * codec
 Ffmpeg structure containing all codec information needed for compression / decompression.
 
AVCodecContext * codecContext = NULL
 Ffmpeg structure containing all codec context information needed for compression / decompression.
 
AVPixelFormat pixelFormat {AV_PIX_FMT_YUV420P}
 Ffmpeg pixel format.
 
bool firstTime
 Boolean variable used to check if the current call to the "compression" (or "decompression") function is the first one or not.
 
bool printStatistics
 Boolean variable used to check whether the bandwidth statistics should be printed.
 
double previousFrameTime
 Seconds since epoch of the previous frame;.
 
double bandwidthRunningAverage
 Variable storing the current bandwidth average for statistics.
 
double lagRunningAverage
 Variable storing the current lag for statistics.
 
int statisticsCounter
 Utility counter for printing statistics.
 
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).
 

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.
 
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).
 
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 execute the program and saves the parameters into the attribute paramsMap (std::map<std::string, std::string>).
 
int setCommandLineParams ()
 This function iterates over the attribute paramsMap and sets all the specified parameters into the attribute codecContext.
 
void updateStatistics (yarp::os::Bottle &inputBottle, double currentLag)
 Print some network statistics.
 

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 193 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 415 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 68 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 576 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 166 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 187 of file ffmpegPortmonitor.cpp.

◆ getParamsFromCommandLine()

bool FfmpegMonitorObject::getParamsFromCommandLine ( std::string  carrierString,
const AVCodec *&  codecOut,
AVPixelFormat pixelFormatOut,
int frameRate 
)
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 707 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 894 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 181 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 259 of file ffmpegPortmonitor.cpp.

◆ updateStatistics()

void FfmpegMonitorObject::updateStatistics ( yarp::os::Bottle inputBottle,
double  currentLag 
)
protected

Print some network statistics.

Definition at line 224 of file ffmpegPortmonitor.cpp.

Member Data Documentation

◆ bandwidthRunningAverage

double FfmpegMonitorObject::bandwidthRunningAverage

Variable storing the current bandwidth average for statistics.

Definition at line 182 of file ffmpegPortmonitor.h.

◆ codec

const AVCodec* FfmpegMonitorObject::codec

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

Definition at line 148 of file ffmpegPortmonitor.h.

◆ codecContext

AVCodecContext* FfmpegMonitorObject::codecContext = NULL

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

Definition at line 154 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 124 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 166 of file ffmpegPortmonitor.h.

◆ imageBottleBuffer

yarp::sig::Image FfmpegMonitorObject::imageBottleBuffer

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

Definition at line 136 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 130 of file ffmpegPortmonitor.h.

◆ lagRunningAverage

double FfmpegMonitorObject::lagRunningAverage

Variable storing the current lag for statistics.

Definition at line 187 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 203 of file ffmpegPortmonitor.h.

◆ pixelFormat

AVPixelFormat FfmpegMonitorObject::pixelFormat {AV_PIX_FMT_YUV420P}

Ffmpeg pixel format.

Definition at line 160 of file ffmpegPortmonitor.h.

◆ previousFrameTime

double FfmpegMonitorObject::previousFrameTime

Seconds since epoch of the previous frame;.

Definition at line 177 of file ffmpegPortmonitor.h.

◆ previousStatisticPrintTime

double FfmpegMonitorObject::previousStatisticPrintTime

Utility variable to store the time in which the last time the statistics have been printed.

Definition at line 197 of file ffmpegPortmonitor.h.

◆ printStatistics

bool FfmpegMonitorObject::printStatistics

Boolean variable used to check whether the bandwidth statistics should be printed.

Definition at line 172 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 142 of file ffmpegPortmonitor.h.

◆ statisticsCounter

int FfmpegMonitorObject::statisticsCounter

Utility counter for printing statistics.

Definition at line 192 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 118 of file ffmpegPortmonitor.h.


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