Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
movie_publisher::MetadataManager Class Reference

Manager of multiple image metadata providers which can cooperate in parsing. More...

#include <metadata_manager.h>

Inheritance diagram for movie_publisher::MetadataManager:
Inheritance graph
[legend]

Public Member Functions

void addExtractor (const std::shared_ptr< MetadataExtractor > &extractor)
 Register a new extractor. More...
 
void clearTimedMetadataCache ()
 Clear all cached timed metadata. More...
 
cras::optional< geometry_msgs::Vector3 > getAcceleration () override
 
cras::optional< geometry_msgs::Vector3 > getAngularVelocity () override
 
cras::optional< compass_msgs::Azimuth > getAzimuth () override
 
std::shared_ptr< MetadataCachegetCache ()
 Return the metadata cache. More...
 
cras::optional< std::string > getCameraGeneralName () override
 
cras::optional< sensor_msgs::CameraInfo > getCameraInfo () override
 
cras::optional< std::string > getCameraMake () override
 
cras::optional< std::string > getCameraModel () override
 
cras::optional< std::string > getCameraSerialNumber () override
 
cras::optional< std::string > getCameraUniqueName () override
 
cras::optional< ros::TimegetCreationTime () override
 
cras::optional< double > getCropFactor () override
 
cras::optional< std::pair< DistortionType, Distortion > > getDistortion () override
 
cras::optional< vision_msgs::Detection2DArray > getFaces () override
 
cras::optional< double > getFocalLength35MM () override
 
cras::optional< double > getFocalLengthMM () override
 
cras::optional< double > getFocalLengthPx () override
 
GNSSFixAndDetail getGNSSPosition () override
 
cras::optional< sensor_msgs::Imu > getImu () override
 
cras::optional< IntrinsicMatrixgetIntrinsicMatrix () override
 
cras::optional< std::string > getLensMake () override
 
cras::optional< std::string > getLensModel () override
 
cras::optional< sensor_msgs::MagneticField > getMagneticField () override
 
std::string getName () const override
 Return the name of the extractor. More...
 
cras::optional< geometry_msgs::Transform > getOpticalFrameTF () override
 
int getPriority () const override
 Return the priority of the extractor (for ordering in MetadataManager). More...
 
cras::optional< RollPitchgetRollPitch () override
 
cras::optional< intgetRotation () override
 
cras::optional< SensorSizegetSensorSizeMM () override
 
cras::optional< geometry_msgs::Transform > getZeroRollPitchTF () override
 
bool hasTimedMetadata () const override
 
void loadExtractorPlugins (const MetadataExtractorParams &params)
 Load all known extractors from plugins. More...
 
 MetadataManager (const cras::LogHelperPtr &log, const MovieOpenConfig &config, const MovieInfo::ConstPtr &info)
 Constructor. Each movie should have its own manager. More...
 
void prepareTimedMetadata (const std::unordered_set< MetadataType > &metadataTypes) override
 Perform any required initialization of the extractor so that it is prepared to extract metadata of the given types. More...
 
void processPacket (const AVPacket *packet) override
 Optional processing of libav packets as they are read from the movie file. More...
 
size_t processTimedMetadata (MetadataType type, const StreamTime &maxTime, bool requireOptional) override
 Process timed metadata up until the time passed as parameter. More...
 
void seekTimedMetadata (const StreamTime &seekTime) override
 Seek timed metadata to the given stream time. More...
 
std::unordered_set< MetadataTypesupportedTimedMetadata (const std::unordered_set< MetadataType > &availableMetadata) const override
 Get a list of timed metadata that are supported by this instance of the extractor based on the given available metadata. More...
 
 ~MetadataManager () override
 
- Public Member Functions inherited from movie_publisher::TimedMetadataExtractor
virtual void addTimedMetadataListener (const std::shared_ptr< TimedMetadataListener > &listener)
 Add a new timed metadata listener. More...
 
 TimedMetadataExtractor (const cras::LogHelperPtr &log)
 
- Public Member Functions inherited from movie_publisher::MetadataExtractor
 MetadataExtractor (const cras::LogHelperPtr &log)
 Constructor. More...
 
virtual ~MetadataExtractor ()
 
- Public Member Functions inherited from cras::HasLogger
::cras::LogHelperConstPtr getCrasLogger () const
 
 HasLogger (const ::cras::LogHelperPtr &log)
 
void setCrasLogger (const ::cras::LogHelperPtr &log)
 

Protected Member Functions

template<typename T , typename O = cras::optional<T>>
checkExtractors (const std::string &func, T(MetadataExtractor::*getFn)(), O(LatestMetadataCache::*getFnLatest)(), const std::string &frame="")
 Call the given function in all extractors and return and cache the first valid result. More...
 
bool stopRecursion (const std::string &fn, const MetadataExtractor *extractor) const
 Check for infinite recursion when individual extractors call common methods via this manager. More...
 

Protected Attributes

std::shared_ptr< MetadataCachecache
 Cache of static and timed metadata. More...
 
std::deque< std::pair< std::string, const MetadataExtractor * > > callStack
 The stack of all calls via the manager. More...
 
MovieOpenConfig config
 Configuration of the open movie. More...
 
std::multiset< MetadataExtractor::Ptr, PriorityComparatorextractors
 
size_t height {0u}
 Height of the analyzed movie [px]. More...
 
MovieInfo::ConstPtr info
 Information about the open movie. More...
 
pluginlib::ClassLoader< MetadataExtractorPluginloader
 The extractor plugin loader. More...
 
std::shared_ptr< CachingMetadataListener > metadataListener
 The timed metadata listener proxy passed to all timed extractors to collect and cache their output. More...
 
friend StackGuard
 
std::multiset< TimedMetadataExtractor::Ptr, PriorityComparatortimedExtractors
 Registered timed extractor instances. More...
 
size_t width {0u}
 Width of the analyzed movie [px]. More...
 
- Protected Attributes inherited from movie_publisher::TimedMetadataExtractor
std::vector< TimedMetadataListener::Ptrlisteners
 The listeners whose callbacks should be called. More...
 
- Protected Attributes inherited from cras::HasLogger
::cras::LogHelperPtr log
 

Additional Inherited Members

- Public Types inherited from movie_publisher::TimedMetadataExtractor
using ConstPtr = std::shared_ptr< const TimedMetadataExtractor >
 
using Ptr = std::shared_ptr< TimedMetadataExtractor >
 
- Public Types inherited from movie_publisher::MetadataExtractor
using ConstPtr = std::shared_ptr< const MetadataExtractor >
 
using Ptr = std::shared_ptr< MetadataExtractor >
 

Detailed Description

Manager of multiple image metadata providers which can cooperate in parsing.

The manager itself behaves like a metadata extractor, but it doesn't extract much itself. Most of the work is relayed to the loaded extractor plugins. The manager takes the first valid result and caches it, so that subsequent calls for the same data will just re-use the cache.

If you pass the manager to the extractor plugins, make sure you pass a std::weak_ptr and not normal std::shared_ptr. The weak pointer will break reference cycle which would otherwise be inevitable (because the manager holds pointers to the extractors).

The manager also processes timed metadata. When timed metadata are advanced using processTimedMetadata(), the cached return values of some of the get*() functions will get recomputed so that these functions always return metadata that are closest to the current playback state.

Definition at line 65 of file metadata_manager.h.

Constructor & Destructor Documentation

◆ MetadataManager()

movie_publisher::MetadataManager::MetadataManager ( const cras::LogHelperPtr log,
const MovieOpenConfig config,
const MovieInfo::ConstPtr info 
)

Constructor. Each movie should have its own manager.

Parameters
[in]logLogger.
[in]widthWidth of the parsed movie.
[in]heightHeight of the parsed movie.

◆ ~MetadataManager()

movie_publisher::MetadataManager::~MetadataManager ( )
override

Member Function Documentation

◆ addExtractor()

void movie_publisher::MetadataManager::addExtractor ( const std::shared_ptr< MetadataExtractor > &  extractor)

Register a new extractor.

Parameters
[in]extractorThe new extractor to register.

◆ checkExtractors()

template<typename T , typename O = cras::optional<T>>
T movie_publisher::MetadataManager::checkExtractors ( const std::string &  func,
T(MetadataExtractor::*)()  getFn,
O(LatestMetadataCache::*)()  getFnLatest,
const std::string &  frame = "" 
)
protected

Call the given function in all extractors and return and cache the first valid result.

Template Parameters
TType of the metadata (including cras::optional<>).
OAlways cras::optional<T>. This parameter is only added to help template resolution.
Parameters
[in]funcName of the calling function (used in call stack, should be unique per call site).
[in]getFnFunction that gets the metadata value by calling this manager.
[in]getFnLatestFunction that reads the metadata value from latest values cache.
[in]frameOptional frame_id to be set to the extracted messages (only if they don't specify any frame).

◆ clearTimedMetadataCache()

void movie_publisher::MetadataManager::clearTimedMetadataCache ( )

Clear all cached timed metadata.

◆ getAcceleration()

cras::optional<geometry_msgs::Vector3> movie_publisher::MetadataManager::getAcceleration ( )
overridevirtual
Returns
Acceleration vector acting on the camera when capturing the frame (including gravity) [m/s^2].

Reimplemented from movie_publisher::MetadataExtractor.

◆ getAngularVelocity()

cras::optional<geometry_msgs::Vector3> movie_publisher::MetadataManager::getAngularVelocity ( )
overridevirtual
Returns
Angular velocity acting on the camera when capturing the frame. [rad/s].

Reimplemented from movie_publisher::MetadataExtractor.

◆ getAzimuth()

cras::optional<compass_msgs::Azimuth> movie_publisher::MetadataManager::getAzimuth ( )
overridevirtual
Returns
Azimuth describing global camera heading when capturing the frame. Timestamp is zero.

Reimplemented from movie_publisher::MetadataExtractor.

◆ getCache()

std::shared_ptr<MetadataCache> movie_publisher::MetadataManager::getCache ( )

Return the metadata cache.

Returns
The metadata cache.

◆ getCameraGeneralName()

cras::optional<std::string> movie_publisher::MetadataManager::getCameraGeneralName ( )
overridevirtual
Returns
String describing the complete camera model.

Reimplemented from movie_publisher::MetadataExtractor.

◆ getCameraInfo()

cras::optional<sensor_msgs::CameraInfo> movie_publisher::MetadataManager::getCameraInfo ( )
overridevirtual
Returns
Extracted camera info combined from other fields, or nothing. Timestamp is zero.

Reimplemented from movie_publisher::MetadataExtractor.

◆ getCameraMake()

cras::optional<std::string> movie_publisher::MetadataManager::getCameraMake ( )
overridevirtual
Returns
Camera manufacturer.

Reimplemented from movie_publisher::MetadataExtractor.

◆ getCameraModel()

cras::optional<std::string> movie_publisher::MetadataManager::getCameraModel ( )
overridevirtual
Returns
The camera model name (just the model, without manufacturer).

Reimplemented from movie_publisher::MetadataExtractor.

◆ getCameraSerialNumber()

cras::optional<std::string> movie_publisher::MetadataManager::getCameraSerialNumber ( )
overridevirtual
Returns
The camera's serial number.

Reimplemented from movie_publisher::MetadataExtractor.

◆ getCameraUniqueName()

cras::optional<std::string> movie_publisher::MetadataManager::getCameraUniqueName ( )
overridevirtual
Returns
String describing the camera in a unique way, utilizing serial numbers etc. If unique identification is not possible, nothing is returned.

Reimplemented from movie_publisher::MetadataExtractor.

◆ getCreationTime()

cras::optional<ros::Time> movie_publisher::MetadataManager::getCreationTime ( )
overridevirtual
Returns
The global time corresponding to the first frame of the movie stream.

Reimplemented from movie_publisher::MetadataExtractor.

◆ getCropFactor()

cras::optional<double> movie_publisher::MetadataManager::getCropFactor ( )
overridevirtual
Returns
Crop factor of the camera (i.e. how many times is the sensing area smaller than 36x24 mm).

Reimplemented from movie_publisher::MetadataExtractor.

◆ getDistortion()

cras::optional<std::pair<DistortionType, Distortion> > movie_publisher::MetadataManager::getDistortion ( )
overridevirtual
Returns
Camera distortion coefficients (corresponding to the OpenCV calibration model: 5 or 8 elements).

Reimplemented from movie_publisher::MetadataExtractor.

◆ getFaces()

cras::optional<vision_msgs::Detection2DArray> movie_publisher::MetadataManager::getFaces ( )
overridevirtual
Returns
Faces detected in the scene. Timestamps are zero.

Reimplemented from movie_publisher::MetadataExtractor.

◆ getFocalLength35MM()

cras::optional<double> movie_publisher::MetadataManager::getFocalLength35MM ( )
overridevirtual
Returns
Focal length recomputed to an equivalent 35 mm system.

Reimplemented from movie_publisher::MetadataExtractor.

◆ getFocalLengthMM()

cras::optional<double> movie_publisher::MetadataManager::getFocalLengthMM ( )
overridevirtual
Returns
The focal length in mm.

Reimplemented from movie_publisher::MetadataExtractor.

◆ getFocalLengthPx()

cras::optional<double> movie_publisher::MetadataManager::getFocalLengthPx ( )
overridevirtual
Returns
The focal length in pixels.

Reimplemented from movie_publisher::MetadataExtractor.

◆ getGNSSPosition()

GNSSFixAndDetail movie_publisher::MetadataManager::getGNSSPosition ( )
overridevirtual
Returns
GNSS position of the camera when capturing the frame. Timestamps are zero.

Reimplemented from movie_publisher::MetadataExtractor.

◆ getImu()

cras::optional<sensor_msgs::Imu> movie_publisher::MetadataManager::getImu ( )
overridevirtual
Returns
Extracted IMU info combined from other fields, or nothing. Timestamp is zero.

Reimplemented from movie_publisher::MetadataExtractor.

◆ getIntrinsicMatrix()

cras::optional<IntrinsicMatrix> movie_publisher::MetadataManager::getIntrinsicMatrix ( )
overridevirtual
Returns
The intrinsic calibration matrix of the camera.

Reimplemented from movie_publisher::MetadataExtractor.

◆ getLensMake()

cras::optional<std::string> movie_publisher::MetadataManager::getLensMake ( )
overridevirtual
Returns
Lens manufacturer.

Reimplemented from movie_publisher::MetadataExtractor.

◆ getLensModel()

cras::optional<std::string> movie_publisher::MetadataManager::getLensModel ( )
overridevirtual
Returns
Lens model.

Reimplemented from movie_publisher::MetadataExtractor.

◆ getMagneticField()

cras::optional<sensor_msgs::MagneticField> movie_publisher::MetadataManager::getMagneticField ( )
overridevirtual
Returns
The magnetic field acting on the camera; measurement in X, Y and Z axes [T]. Timestamp is zero.

Reimplemented from movie_publisher::MetadataExtractor.

◆ getName()

std::string movie_publisher::MetadataManager::getName ( ) const
overridevirtual

Return the name of the extractor.

Returns
The name.

Implements movie_publisher::MetadataExtractor.

◆ getOpticalFrameTF()

cras::optional<geometry_msgs::Transform> movie_publisher::MetadataManager::getOpticalFrameTF ( )
overridevirtual
Returns
Optical frame transform, i.e. transform between camera's geometrical and optical frame. It might be affected by image rotation.

Reimplemented from movie_publisher::MetadataExtractor.

◆ getPriority()

int movie_publisher::MetadataManager::getPriority ( ) const
overridevirtual

Return the priority of the extractor (for ordering in MetadataManager).

Returns
The priority. Lower values have more priority. Usually between 0 and 100.

Implements movie_publisher::MetadataExtractor.

◆ getRollPitch()

cras::optional<RollPitch> movie_publisher::MetadataManager::getRollPitch ( )
overridevirtual
Returns
Gravity-aligned roll and pitch of the camera when capturing the frame [rad].

Reimplemented from movie_publisher::MetadataExtractor.

◆ getRotation()

cras::optional<int> movie_publisher::MetadataManager::getRotation ( )
overridevirtual
Returns
Rotation of the image in degrees. Only values 0, 90, 180 and 270 are supported.

Reimplemented from movie_publisher::MetadataExtractor.

◆ getSensorSizeMM()

cras::optional<SensorSize> movie_publisher::MetadataManager::getSensorSizeMM ( )
overridevirtual
Returns
Physical size of the active sensor area that captures the movie (in mm; width, height).

Reimplemented from movie_publisher::MetadataExtractor.

◆ getZeroRollPitchTF()

cras::optional<geometry_msgs::Transform> movie_publisher::MetadataManager::getZeroRollPitchTF ( )
overridevirtual
Returns
The transform from camera body frame to a gravity-aligned frame.

Reimplemented from movie_publisher::MetadataExtractor.

◆ hasTimedMetadata()

bool movie_publisher::MetadataManager::hasTimedMetadata ( ) const
overridevirtual
Returns
Whether the extractor is able to extract some timed metadata from the movie it is bound to.
Note
This is the best guess based on the current knowledge of the extractor. It can still happen that processTimedMetadata() will fail to produce the metadata.
Implementing classes should not call this base method implementation.

Reimplemented from movie_publisher::TimedMetadataExtractor.

◆ loadExtractorPlugins()

void movie_publisher::MetadataManager::loadExtractorPlugins ( const MetadataExtractorParams params)

Load all known extractors from plugins.

Parameters
[in]paramsParameters passed to the plugin initialization methods.

◆ prepareTimedMetadata()

void movie_publisher::MetadataManager::prepareTimedMetadata ( const std::unordered_set< MetadataType > &  metadataTypes)
overridevirtual

Perform any required initialization of the extractor so that it is prepared to extract metadata of the given types.

Parameters
[in]metadataTypesThe types of metadata this extractor should provide.
Note
This method should be called before the first call to processTimedMetadata() and canProduceTimedMetadata().
Implementing classes should not call this base method implementation.

Reimplemented from movie_publisher::TimedMetadataExtractor.

◆ processPacket()

void movie_publisher::MetadataManager::processPacket ( const AVPacket *  packet)
overridevirtual

Optional processing of libav packets as they are read from the movie file.

Parameters
[in]packetThe libav packet.
Note
av_packet_ref() the packet if you want to store it for longer than this call duration.

Reimplemented from movie_publisher::MetadataExtractor.

◆ processTimedMetadata()

size_t movie_publisher::MetadataManager::processTimedMetadata ( MetadataType  type,
const StreamTime maxTime,
bool  requireOptional 
)
overridevirtual

Process timed metadata up until the time passed as parameter.

Parameters
[in]typeType of the requested metadata.
[in]maxTimeThe maximum stream timestamp of the timed metadata that should be passed to listeners.
[in]requireOptionalIf true and the timed metadata are composed of multiple base metadata, treat even optional metadata as required. This is used by the metadata creation loop to first make sure other providers have produced as much as they can before this metadata is asked to be produced even with incomplete optional dependencies.
Returns
The number of produced metadata (corresponds to the number of callbacks called).
Note
It is assumed that maxTime is a sequence of times growing as fast as the video frame timestamps. Use seekTimedMetadata() to inform the extractor that it should seek somewhere (create a discontinuity in this growing sequence of timestamps).
If timed metadata are present and supported, all listeners added by addTimedMetadataListener() will be called with appropriate data.
Implementing classes should not call this base method implementation.

Reimplemented from movie_publisher::TimedMetadataExtractor.

◆ seekTimedMetadata()

void movie_publisher::MetadataManager::seekTimedMetadata ( const StreamTime seekTime)
overridevirtual

Seek timed metadata to the given stream time.

Parameters
[in]seekTimeThe stream timestamp to seek to.
Note
Implementing classes should not call this base method implementation.

Reimplemented from movie_publisher::TimedMetadataExtractor.

◆ stopRecursion()

bool movie_publisher::MetadataManager::stopRecursion ( const std::string &  fn,
const MetadataExtractor extractor 
) const
protected

Check for infinite recursion when individual extractors call common methods via this manager.

Parameters
[in]fnThe stringified name of the called function.
[in]extractorThe extractor that calls the function.
Returns
Whether this extractor would be calling itself recursively if the given function were called.

◆ supportedTimedMetadata()

std::unordered_set<MetadataType> movie_publisher::MetadataManager::supportedTimedMetadata ( const std::unordered_set< MetadataType > &  availableMetadata) const
overridevirtual

Get a list of timed metadata that are supported by this instance of the extractor based on the given available metadata.

Parameters
[in]availableMetadataThe timed metadata that is currently available.
Returns
Supported metadata types.
Note
This function should return a correct result right after the extractor is constructed. It should reflect the actual content of the file the extractor is bound to, and if the extractor doesn't see anything it could decode, it should return an empty value from this function.

Implements movie_publisher::TimedMetadataExtractor.

Member Data Documentation

◆ cache

std::shared_ptr<MetadataCache> movie_publisher::MetadataManager::cache
protected

Cache of static and timed metadata.

Definition at line 171 of file metadata_manager.h.

◆ callStack

std::deque<std::pair<std::string, const MetadataExtractor*> > movie_publisher::MetadataManager::callStack
protected

The stack of all calls via the manager.

Definition at line 165 of file metadata_manager.h.

◆ config

MovieOpenConfig movie_publisher::MetadataManager::config
protected

Configuration of the open movie.

Definition at line 169 of file metadata_manager.h.

◆ extractors

std::multiset<MetadataExtractor::Ptr, PriorityComparator> movie_publisher::MetadataManager::extractors
protected

Registered extractor instances.

Definition at line 162 of file metadata_manager.h.

◆ height

size_t movie_publisher::MetadataManager::height {0u}
protected

Height of the analyzed movie [px].

Definition at line 167 of file metadata_manager.h.

◆ info

MovieInfo::ConstPtr movie_publisher::MetadataManager::info
protected

Information about the open movie.

Definition at line 170 of file metadata_manager.h.

◆ loader

pluginlib::ClassLoader<MetadataExtractorPlugin> movie_publisher::MetadataManager::loader
protected

The extractor plugin loader.

Definition at line 161 of file metadata_manager.h.

◆ metadataListener

std::shared_ptr<CachingMetadataListener> movie_publisher::MetadataManager::metadataListener
protected

The timed metadata listener proxy passed to all timed extractors to collect and cache their output.

Definition at line 174 of file metadata_manager.h.

◆ StackGuard

friend movie_publisher::MetadataManager::StackGuard
protected

Definition at line 176 of file metadata_manager.h.

◆ timedExtractors

std::multiset<TimedMetadataExtractor::Ptr, PriorityComparator> movie_publisher::MetadataManager::timedExtractors
protected

Registered timed extractor instances.

Definition at line 164 of file metadata_manager.h.

◆ width

size_t movie_publisher::MetadataManager::width {0u}
protected

Width of the analyzed movie [px].

Definition at line 166 of file metadata_manager.h.


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


movie_publisher
Author(s): Martin Pecka
autogenerated on Wed May 28 2025 02:07:22