YARP
Yet Another Robot Platform
ffmpegPortmonitor.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * All rights reserved.
4  *
5  * This software may be modified and distributed under the terms of the
6  * BSD-3-Clause license. See the accompanying LICENSE file for details.
7  */
8 
17 #ifndef YARP_FFMPEG_CARRIER_FFMPEGPORTMONITOR_H
18 #define YARP_FFMPEG_CARRIER_FFMPEGPORTMONITOR_H
19 
20 // YARP imports
21 #include <yarp/os/Bottle.h>
22 #include <yarp/os/Things.h>
23 #include <yarp/sig/Image.h>
24 #include <yarp/os/MonitorObject.h>
25 
26 // Ffmpeg imports
27 extern "C" {
28  #include <libavcodec/avcodec.h>
29 }
30 
36 {
37  public:
45  bool create(const yarp::os::Property& options) override;
46 
51  void destroy(void) override;
52 
53  bool setparam(const yarp::os::Property& params) override;
54  bool getparam(yarp::os::Property& params) override;
55 
63  bool accept(yarp::os::Things& thing) override;
64 
71  yarp::os::Things& update(yarp::os::Things& thing) override;
72 
73  protected:
81  int compress(yarp::sig::Image* img, AVPacket* pkt);
82 
92  int decompress(AVPacket* pkt, int w, int h, int pixelCode);
93 
101  int getParamsFromCommandLine(std::string carrierString, AVCodecID &codecId);
102 
108  int setCommandLineParams();
109 
110  public:
116 
122 
128 
134 
139  std::string codecName;
140 
145  const AVCodec *codec;
146 
151  AVCodecContext *codecContext = NULL;
152 
157  bool firstTime;
158 
163  std::map<std::string, std::string> paramsMap;
164 };
165 
166 #endif
This class extends the MonitorObject class and uses Ffmpeg to compress and decompress video streams w...
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:76
A class for storing options and configuration information.
Definition: Property.h:37
Base class for generic things.
Definition: Things.h:22
Image class with user control of representation details.
Definition: Image.h:403
Base class for storing images.
Definition: Image.h:85