Ocean
Loading...
Searching...
No Matches
Ocean::Media::FFmpeg::FFMMovie Class Reference

This class implements an FFmpeg movie object. More...

#include <FFMMovie.h>

Inheritance diagram for Ocean::Media::FFmpeg::FFMMovie:

Public Member Functions

MediumRef clone () const override
 Clones this movie medium and returns a new independent instance of this medium.
 
double duration () const override
 Returns the duration of the movie medium.
 
double normalDuration () const override
 Returns the duration of the movie medium without speed consideration.
 
double position () const override
 Returns the recent position of the movie medium.
 
bool setPosition (const double position) override
 Sets the recent position of the movie medium.
 
float speed () const override
 Returns the speed of the movie medium.
 
bool setSpeed (const float speed) override
 Sets the speed of the movie medium.
 
float soundVolume () const override
 Returns the volume of the sound in db.
 
bool soundMute () const override
 Returns whether the movie medium is in a mute state.
 
bool setSoundVolume (const float volume) override
 Sets the volume of the sound in db.
 
bool setSoundMute (const bool mute) override
 Sets or unsets the movie medium to a mute state.
 
bool setUseSound (const bool state) override
 Enables or disables the audio in this movie (has no effect if the movie does not have audio).
 
- Public Member Functions inherited from Ocean::Media::FFmpeg::FFMMedium
bool isStarted () const override
 Returns whether the medium is started currently.
 
Timestamp startTimestamp () const override
 Returns the start timestamp.
 
Timestamp pauseTimestamp () const override
 Returns the pause timestamp.
 
Timestamp stopTimestamp () const override
 Returns the stop timestamp.
 
- Public Member Functions inherited from Ocean::Media::Medium
const std::string & url () const
 Returns the url of the medium.
 
bool isValid () const
 Returns whether the medium is valid.
 
const std::string & library () const
 Returns the name of the owner library.
 
Type type () const
 Returns the type of the medium.
 
bool isType (const Type type) const
 Returns whether a medium has a given type.
 
bool isExclusive () const
 Returns whether this medium can be use exclusively.
 
- Public Member Functions inherited from Ocean::Media::Movie
virtual bool useSound () const
 Returns whether the sound of this movie is enabled or disabled.
 
- Public Member Functions inherited from Ocean::Media::FiniteMedium
bool loop () const
 Returns whether the medium is played in a loop.
 
virtual bool setLoop (const bool value)
 Sets whether the medium has to be played in a loop.
 
virtual bool taskFinished () const
 Returns whether a previous task has been finished.
 
- Public Member Functions inherited from Ocean::Media::FrameMedium
 ~FrameMedium () override
 Destructs a frame object.
 
bool hasFrame () const
 Returns whether the object holds a frame.
 
FrameFrequency frameFrequency () const
 Returns the frequency of the frame in Hz.
 
virtual FrameRef frame (SharedAnyCamera *anyCamera=nullptr) const
 Returns the most recent frame.
 
virtual FrameRef frame (const Timestamp timestamp, SharedAnyCamera *anyCamera=nullptr) const
 Returns the frame with a specific timestamp.
 
virtual FrameRef frameTimeout (const double timeout, SharedAnyCamera *anyCamera=nullptr) const
 Waits until the first frame is available.
 
virtual bool hasFrame (const Timestamp timestamp) const
 Returns whether this media object currently holds a frame with specified timestamp.
 
unsigned int preferredFrameWidth () const
 Returns the preferred width of the frame in pixel.
 
unsigned int preferredFrameHeight () const
 Returns the preferred height of the frame in pixel.
 
FrameType::PixelFormat preferredFramePixelFormat () const
 Returns the preferred frame pixel format.
 
FrameFrequency preferredFrameFrequency () const
 Returns the preferred frame frequency in Hz.
 
virtual HomogenousMatrixD4 device_T_camera () const
 Returns the transformation between the camera and device.
 
virtual bool setPreferredFrameDimension (const unsigned int width, const unsigned int height)
 Sets the preferred frame dimension.
 
virtual bool setPreferredFramePixelFormat (const FrameType::PixelFormat format)
 Sets the preferred frame pixel format.
 
virtual bool setPreferredFrameFrequency (const FrameFrequency frequency)
 Sets the preferred frame frequency in Hz.
 
size_t capacity () const
 Returns the capacity of the frame history of this frame medium object.
 
bool setCapacity (const size_t capacity)
 Sets or changes the capacity of the frame history of this frame medium object.
 
FrameCallbackScopedSubscription addFrameCallback (FrameCallbackFunction &&frameCallbackFunction)
 Adds a callback function which is called whenever a new frame arrives.
 
- Public Member Functions inherited from Ocean::Media::SoundMedium
bool hasSound () const
 Returns whether the object holds a sound.
 
unsigned int soundChannels () const
 Returns the number of sound channels.
 
SoundFrequency soundFrequency () const
 Returns the frequency of the sound in Hz.
 
unsigned int soundBitsPerSample () const
 Returns the number of bits per sample.
 
unsigned int preferredSoundChannels () const
 Returns the preferred number of sound channels.
 
SoundFrequency preferredSoundFrequency () const
 Returns the preferred sound frequency in Hz.
 
unsigned int preferredSoundBitsPerSample () const
 Returns the preferred bits per sound sample.
 
virtual bool setPreferredSoundChannels (const unsigned int channels)
 Sets the preferred number of sound channels.
 
virtual bool setPreferredSoundFrequency (const SoundFrequency frequency)
 Sets the preferred sound frequency in Hz.
 
virtual bool setPreferredSoundBitsPerSample (const unsigned int bits)
 Sets the preferred bits per sound sample.
 

Protected Types

typedef std::unordered_map< int64_t, int64_t > PacketTimestampMap
 Definition of an unordered map mapping frame indices to presentation timestamps.
 
- Protected Types inherited from Ocean::Media::FrameMedium
typedef ScopedSubscriptionCallbackHandlerT< FrameCallbackFunction, FrameMedium, true > FrameCallbackHandler
 Definition of a thread-safe subscription handler for frame callback functions.
 
typedef std::vector< MediaFrameTypeFrameTypes
 Definition of a vector holding frame types.
 
- Protected Types inherited from Ocean::Thread
typedef std::pair< pthread_t, bool > TimedJoinPair
 Definition of a pair holding a thread id and a boolean state.
 
enum  ThreadPriority {
  PRIORITY_IDLE , PRIORTY_BELOW_NORMAL , PRIORTY_NORMAL , PRIORTY_ABOVE_NORMAL ,
  PRIORTY_HIGH , PRIORTY_REALTIME
}
 Definition of different thread priority values. More...
 

Protected Member Functions

 FFMMovie (const std::string &url)
 Creates a new movie by a given url.
 
 ~FFMMovie () override
 Destructs a FFMMovie object.
 
bool internalStart () override
 Internally starts the medium.
 
bool internalPause () override
 Internally pauses the medium.
 
bool internalStop () override
 Internally stops the medium.
 
bool createAndOpenVideoCodec ()
 Creates and opens the video codec.
 
void releaseVideoCodec ()
 Releases the video codec.
 
- Protected Member Functions inherited from Ocean::Media::FFmpeg::FFMMedium
 FFMMedium (const std::string &url)
 Creates a new medium by a given url.
 
 ~FFMMedium () override
 Destructs a FFMMedium object.
 
bool start () override
 Starts the medium.
 
bool pause () override
 Pauses the medium.
 
bool stop () override
 Stops the medium.
 
bool createContextAndOpenFile (const std::string &filename)
 Creates a FFmpeg context and opens a given file.
 
void releaseContext ()
 Releases the FFmpeg context.
 
- Protected Member Functions inherited from Ocean::Media::Medium
 Medium (const Medium &medium)=delete
 Disabled copy constructor.
 
 Medium (const std::string &url)
 Creates a new medium by a given url.
 
virtual ~Medium ()
 Destructs a medium.
 
Mediumoperator= (const Medium &medium)=delete
 Disabled copy operator.
 
- Protected Member Functions inherited from Ocean::Media::Movie
 Movie (const std::string &url)
 Creates a new movie by a given url.
 
- Protected Member Functions inherited from Ocean::Media::FiniteMedium
 FiniteMedium (const std::string &url)
 Creates a new finite medium by a given url.
 
- Protected Member Functions inherited from Ocean::Media::FrameMedium
 FrameMedium (const std::string &url)
 Creates a new frame medium by a given url.
 
virtual bool deliverNewFrame (Frame &&frame, SharedAnyCamera &&anyCamera=SharedAnyCamera())
 Delivers a new frame to this FrameMedium.
 
- Protected Member Functions inherited from Ocean::Media::SoundMedium
 SoundMedium (const std::string &url)
 Creates a new sound medium by a given url.
 
- Protected Member Functions inherited from Ocean::Thread
 Thread (const Thread &thread)=delete
 Disabled copy constructor.
 
void createThread ()
 Creates the thread itself.
 
void destroyThread ()
 Destroys the thread itself.
 
void stopThreadExplicitly (const unsigned int timeout=5000u)
 Tries to stop the thread gracefully.
 
Threadoperator= (const Thread &thread)=delete
 The disabled assign operator.
 
 Thread (const std::string &name=std::string())
 Creates a new thread object.
 
 Thread (const unsigned int randomNumberSeedValue, const std::string &name=std::string())
 Creates a new thread object.
 
virtual ~Thread ()
 Destructs a thread object.
 
bool startThread ()
 Starts the thread.
 
void stopThread ()
 Informs the thread to stop.
 
bool terminateThread ()
 Terminates the thread.
 
bool joinThread (const unsigned int timeout=(unsigned int)(-1))
 Waits until this thread has been stopped.
 
bool shouldThreadStop () const
 Returns whether this thread should stop.
 
bool isThreadInvokedToStart () const
 Returns whether this thread has been invoked to start immediately.
 
bool isThreadActive () const
 Returns whether this thread is active.
 

Static Protected Member Functions

static Frame extractFrame (AVFrame *avFrame, const int avPixelFormat, const int avColorRange)
 Extracts the Ocean frame from a FFmpeg frame.
 
static FrameType::PixelFormat translatePixelFormat (const int avPixelFormat, const int avColorRange)
 Translates a FFmpeg pixel format to an Ocean pixel format.
 
- Static Protected Member Functions inherited from Ocean::Thread
static void sleep (unsigned int ms)
 Sleeps the calling thread for a given time.
 
static void giveUp ()
 Gives up the remaining thread time.
 
static ThreadId currentThreadId ()
 Returns the thread id of the current (calling) thread.
 
static ThreadPriority threadPriority ()
 Returns the priority of the current thread.
 
static bool setThreadPriority (const ThreadPriority priority)
 Sets the priority of the current thread.
 
template<typename TObject , typename TExpectedValue >
static bool waitForValue (TObject &object, const TExpectedValue &expectedValue, const double timeout=-1.0)
 Waits until an object/variable has an expected value.
 
template<typename TObject , typename TExpectedValue >
static bool waitForValue (TObject &object, const TExpectedValue &expectedValue, TemporaryScopedLock &temporaryScopedLock, const double timeout=-1.0)
 Waits until an object/variable has an expected value.
 
static int pthread_timedjoin_np (pthread_t thread, void **retval, const struct timespec *abstime)
 Implements a thread join function with timeout value.
 

Protected Attributes

AVCodecContext * avVideoCodecContext_ = nullptr
 The FFmpeg video codec context.
 
AVStream * avVideoStream_ = nullptr
 The FFmpeg video stream.
 
int avVideoStreamIndex_ = -1
 The index of the FFmpeg video stream.
 
std::atomic< double > position_ = 0.0
 The current playback position in seconds.
 
std::atomic< double > seekPosition_ = -1.0
 The seek playback position in seconds, -1 if not set.
 
double normalDuration_ = -1.0
 The duration of the movie in seconds, for a default speed with 1.0, -1 if unknown.
 
std::atomic< float > speed_ = 1.0f
 The playback speed of the movie.
 
std::atomic< bool > isPaused_ = false
 True, if the movie is paused.
 
- Protected Attributes inherited from Ocean::Media::FFmpeg::FFMMedium
AVFormatContext * avFormatContext_ = nullptr
 FFmpeg's format context object.
 
Timestamp startTimestamp_ = Timestamp(false)
 Start timestamp.
 
Timestamp pauseTimestamp_ = Timestamp(false)
 Pause timestamp.
 
Timestamp stopTimestamp_ = Timestamp(false)
 Stop timestamp.
 
- Protected Attributes inherited from Ocean::Media::Medium
std::string url_
 Url of the medium.
 
std::string libraryName_
 Name of the owner library.
 
bool isValid_ = false
 Determines whether the medium is valid.
 
Type type_ = MEDIUM
 Type of the medium.
 
Lock lock_
 Medium lock.
 
- Protected Attributes inherited from Ocean::Media::FiniteMedium
bool loop_ = false
 Determines whether the medium is played in a loop.
 
- Protected Attributes inherited from Ocean::Media::FrameMedium
FrameCollection frameCollection_
 Frame collection storing several frames with different timestamps.
 
FrameCallbackHandler frameCallbackHandler_
 The handler for frame callback functions.
 
FrameFrequency recentFrameFrequency_ = FrameFrequency(0)
 Frame frequency.
 
MediaFrameType preferredFrameType_
 Preferred frame type of the medium.
 
- Protected Attributes inherited from Ocean::Media::SoundMedium
SoundType mediumSoundType
 Actual sound type.
 
SoundType mediumPreferredSoundType
 Preferred sound type.
 
Timestamp mediumSoundTimestamp
 Timestamp of the recent sound frame.
 
Timestamp mediumSoundTypeTimestamp
 Timestamp of the recent sound frame type.
 

Private Member Functions

void threadRun () override
 Thread run function.
 

Friends

class FFMLibrary
 

Additional Inherited Members

- Public Types inherited from Ocean::Media::Medium
enum  Type : uint32_t {
  MEDIUM = 0u , FRAME_MEDIUM = 1u << 0u , SOUND_MEDIUM = 1u << 1u , FINITE_MEDIUM = 1u << 2u ,
  LIVE_MEDIUM = 1u << 3u , CONFIG_MEDIUM = 1u << 4u , AUDIO = (1u << 5u) | FINITE_MEDIUM | SOUND_MEDIUM , IMAGE = (1u << 6u) | FRAME_MEDIUM ,
  PIXEL_IMAGE = (1u << 7u) | FRAME_MEDIUM , BUFFER_IMAGE = (1u << 8u) | FRAME_MEDIUM , IMAGE_SEQUENCE = (1u << 9u) | FRAME_MEDIUM | FINITE_MEDIUM , LIVE_AUDIO = (1u << 10u) | LIVE_MEDIUM | SOUND_MEDIUM ,
  LIVE_VIDEO = (1u << 11u) | LIVE_MEDIUM | FRAME_MEDIUM , MICROPHONE = (1u << 12u) | LIVE_MEDIUM , MOVIE = (1u << 13u) | FINITE_MEDIUM | FRAME_MEDIUM | SOUND_MEDIUM
}
 Definition of different medium types. More...
 
- Public Types inherited from Ocean::Media::FrameMedium
typedef double FrameFrequency
 Definition of a frame frequency defined in Hz.
 
typedef std::function< void(const Frame &frame, const SharedAnyCamera &camera)> FrameCallbackFunction
 Definition of a callback function for frame events.
 
typedef ScopedSubscriptionHandler::ScopedSubscriptionType FrameCallbackScopedSubscription
 Definition of a subscription object for frame callback events.
 
- Public Types inherited from Ocean::Media::SoundMedium
typedef float SoundFrequency
 Definition of a sound frequency defined in Hz.
 
- Static Public Member Functions inherited from Ocean::Media::Medium
static std::string convertType (const Type type)
 Converts a medium type to a unique string.
 
static Type convertType (const std::string &type)
 Converts a medium type string to a medium type.
 
- Static Public Member Functions inherited from Ocean::Media::FrameMedium
static bool syncedFrames (const FrameMediumRefs &frameMediums, const Timestamp lastTimestamp, FrameRefs &frames, SharedAnyCameras &cameras, const unsigned int waitTime=2u, bool *timedOut=nullptr, HomogenousMatricesD4 *device_T_cameras=nullptr)
 Extracts most recent frames from several frame medium objects and ensures that the timestamps of all frames are identical.
 
- Static Public Attributes inherited from Ocean::Media::FiniteMedium
static constexpr float AS_FAST_AS_POSSIBLE = 0.0f
 Definition of a speed value allowing to deliver the media content as fast as possible.
 

Detailed Description

This class implements an FFmpeg movie object.

Member Typedef Documentation

◆ PacketTimestampMap

typedef std::unordered_map<int64_t, int64_t> Ocean::Media::FFmpeg::FFMMovie::PacketTimestampMap
protected

Definition of an unordered map mapping frame indices to presentation timestamps.

Constructor & Destructor Documentation

◆ FFMMovie()

Ocean::Media::FFmpeg::FFMMovie::FFMMovie ( const std::string &  url)
explicitprotected

Creates a new movie by a given url.

Parameters
urlUrl of the movie

◆ ~FFMMovie()

Ocean::Media::FFmpeg::FFMMovie::~FFMMovie ( )
overrideprotected

Destructs a FFMMovie object.

Member Function Documentation

◆ clone()

MediumRef Ocean::Media::FFmpeg::FFMMovie::clone ( ) const
overridevirtual

Clones this movie medium and returns a new independent instance of this medium.

See also
Medium::clone()

Reimplemented from Ocean::Media::Medium.

◆ createAndOpenVideoCodec()

bool Ocean::Media::FFmpeg::FFMMovie::createAndOpenVideoCodec ( )
protected

Creates and opens the video codec.

Returns
True, if succeeded

◆ duration()

double Ocean::Media::FFmpeg::FFMMovie::duration ( ) const
overridevirtual

Returns the duration of the movie medium.

See also
FiniteMedium::duration()

Implements Ocean::Media::FiniteMedium.

◆ extractFrame()

static Frame Ocean::Media::FFmpeg::FFMMovie::extractFrame ( AVFrame *  avFrame,
const int  avPixelFormat,
const int  avColorRange 
)
staticprotected

Extracts the Ocean frame from a FFmpeg frame.

Parameters
avFrameThe FFmpeg frame from which the data will be extracted, must be valid
avPixelFormatThe pixel format of the FFmpeg frame, provided as 'AVPixelFormat', must be valid
avColorRangeThe FFmpeg color range associated with the pixel format, provided as 'AVColorRange'
Returns
The resulting Ocean frame owning the memory, invalid otherwise

◆ internalPause()

bool Ocean::Media::FFmpeg::FFMMovie::internalPause ( )
overrideprotectedvirtual

Internally pauses the medium.

See also
AVFMedium::internalPause()

Implements Ocean::Media::FFmpeg::FFMMedium.

◆ internalStart()

bool Ocean::Media::FFmpeg::FFMMovie::internalStart ( )
overrideprotectedvirtual

Internally starts the medium.

See also
AVFMedium::internalStart()

Implements Ocean::Media::FFmpeg::FFMMedium.

◆ internalStop()

bool Ocean::Media::FFmpeg::FFMMovie::internalStop ( )
overrideprotectedvirtual

Internally stops the medium.

See also
AVFMedium::internalStop()

Implements Ocean::Media::FFmpeg::FFMMedium.

◆ normalDuration()

double Ocean::Media::FFmpeg::FFMMovie::normalDuration ( ) const
overridevirtual

Returns the duration of the movie medium without speed consideration.

See also
FiniteMedium::normalDuration()

Implements Ocean::Media::FiniteMedium.

◆ position()

double Ocean::Media::FFmpeg::FFMMovie::position ( ) const
overridevirtual

Returns the recent position of the movie medium.

See also
FiniteMedium::position()

Implements Ocean::Media::FiniteMedium.

◆ releaseVideoCodec()

void Ocean::Media::FFmpeg::FFMMovie::releaseVideoCodec ( )
protected

Releases the video codec.

◆ setPosition()

bool Ocean::Media::FFmpeg::FFMMovie::setPosition ( const double  position)
overridevirtual

Sets the recent position of the movie medium.

See also
FiniteMedium::setPosition()

Reimplemented from Ocean::Media::FiniteMedium.

◆ setSoundMute()

bool Ocean::Media::FFmpeg::FFMMovie::setSoundMute ( const bool  mute)
overridevirtual

Sets or unsets the movie medium to a mute state.

See also
SoundMedium::setSoundMute()

Implements Ocean::Media::SoundMedium.

◆ setSoundVolume()

bool Ocean::Media::FFmpeg::FFMMovie::setSoundVolume ( const float  volume)
overridevirtual

Sets the volume of the sound in db.

See also
SoundMedium::setSoundVolume()

Implements Ocean::Media::SoundMedium.

◆ setSpeed()

bool Ocean::Media::FFmpeg::FFMMovie::setSpeed ( const float  speed)
overridevirtual

Sets the speed of the movie medium.

See also
FiniteMedium::setSpeed()

Reimplemented from Ocean::Media::FiniteMedium.

◆ setUseSound()

bool Ocean::Media::FFmpeg::FFMMovie::setUseSound ( const bool  state)
overridevirtual

Enables or disables the audio in this movie (has no effect if the movie does not have audio).

See also
Movie::setUseSound()

Reimplemented from Ocean::Media::Movie.

◆ soundMute()

bool Ocean::Media::FFmpeg::FFMMovie::soundMute ( ) const
overridevirtual

Returns whether the movie medium is in a mute state.

See also
SoundMedium::soundMute()

Implements Ocean::Media::SoundMedium.

◆ soundVolume()

float Ocean::Media::FFmpeg::FFMMovie::soundVolume ( ) const
overridevirtual

Returns the volume of the sound in db.

See also
SoundMedium::soundVolume()

Implements Ocean::Media::SoundMedium.

◆ speed()

float Ocean::Media::FFmpeg::FFMMovie::speed ( ) const
overridevirtual

Returns the speed of the movie medium.

See also
FiniteMedium::speed()

Implements Ocean::Media::FiniteMedium.

◆ threadRun()

void Ocean::Media::FFmpeg::FFMMovie::threadRun ( )
overrideprivatevirtual

Thread run function.

Implements Ocean::Thread.

◆ translatePixelFormat()

static FrameType::PixelFormat Ocean::Media::FFmpeg::FFMMovie::translatePixelFormat ( const int  avPixelFormat,
const int  avColorRange 
)
staticprotected

Translates a FFmpeg pixel format to an Ocean pixel format.

Parameters
avPixelFormatThe FFmpeg pixel format to translate, provided as 'AVPixelFormat'
avColorRangeThe FFmpeg color range associated with the pixel format, provided as 'AVColorRange'
Returns
The corresponding Ocean pixel format, FORMAT_UNDEFINED if no corresponding pixel format exists

Friends And Related Symbol Documentation

◆ FFMLibrary

friend class FFMLibrary
friend

Field Documentation

◆ avVideoCodecContext_

AVCodecContext* Ocean::Media::FFmpeg::FFMMovie::avVideoCodecContext_ = nullptr
protected

The FFmpeg video codec context.

◆ avVideoStream_

AVStream* Ocean::Media::FFmpeg::FFMMovie::avVideoStream_ = nullptr
protected

The FFmpeg video stream.

◆ avVideoStreamIndex_

int Ocean::Media::FFmpeg::FFMMovie::avVideoStreamIndex_ = -1
protected

The index of the FFmpeg video stream.

◆ isPaused_

std::atomic<bool> Ocean::Media::FFmpeg::FFMMovie::isPaused_ = false
protected

True, if the movie is paused.

◆ normalDuration_

double Ocean::Media::FFmpeg::FFMMovie::normalDuration_ = -1.0
protected

The duration of the movie in seconds, for a default speed with 1.0, -1 if unknown.

◆ position_

std::atomic<double> Ocean::Media::FFmpeg::FFMMovie::position_ = 0.0
protected

The current playback position in seconds.

◆ seekPosition_

std::atomic<double> Ocean::Media::FFmpeg::FFMMovie::seekPosition_ = -1.0
protected

The seek playback position in seconds, -1 if not set.

◆ speed_

std::atomic<float> Ocean::Media::FFmpeg::FFMMovie::speed_ = 1.0f
protected

The playback speed of the movie.


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