reference

This documentation is automatically generated from the openFrameworks source code using doxygen and refers to the most recent release, version 0.12.0.

#include <ofMediaFoundationPlayer.h>

Inheritance diagram for ofMediaFoundationPlayer:
ofBaseVideoPlayer of::MediaEngineNotifyCallback ofBaseVideo ofBaseHasPixels_< unsigned char > ofBaseUpdates ofAbstractHasPixels

Classes

class  MEDXDeviceManager
 
class  METexture
 
class  ofMEEventProcessor
 

Public Member Functions

 ofMediaFoundationPlayer ()
 
 ~ofMediaFoundationPlayer ()
 
bool load (std::string name) override
 Load a video resource by name.
 
void loadAsync (std::string name) override
 Asynchronously load a video resource by name.
 
void close () override
 Close the video source.
 
bool isInitialized () const override
 Returns true if a video is loaded.
 
void update () override
 Update the object's state.
 
bool isFrameNew () const override
 
void play () override
 Play the video from the current playhead position.
 
void stop () override
 Pause and reset the playhead position to the first frame.
 
void setPaused (bool bPause) override
 Set the paused state of the video.
 
bool isLoaded () const override
 Returns true if a video is loaded.
 
bool isPlaying () const override
 Returns true if the loaded video is playing.
 
float getWidth () const override
 Get the width in pixels of the loaded video.
 
float getHeight () const override
 Get the height in pixels of the loaded video.
 
ofTexturegetTexturePtr ()
 Get a pointer to the video texture used internally if it exists.
 
bool isPaused () const override
 Returns true if the video is paused.
 
void setPosition (float pct) override
 Set the position of the playhead.
 
void setSpeed (float speed) override
 Set the video playback speed.
 
void setVolume (float volume) override
 Set the volume of the video player.
 
void setFrame (int frame) override
 Set the current frame by frame number.
 
int getCurrentFrame () const override
 Get the current playhead position as a frame number.
 
int getTotalNumFrames () const override
 Get the total number of frames in the currently loaded video.
 
void setLoopState (ofLoopType state) override
 Set the video loop state.
 
ofLoopType getLoopState () const override
 Get the current loop state of the video.
 
float getPosition () const override
 Get the current playhead position of the loaded video.
 
float getSpeed () const override
 Get the playback speed of the video player.
 
float getDuration () const override
 Get the duration of the loaded video in seconds.
 
bool getIsMovieDone () const override
 Returns true if the loaded video has finished playing.
 
bool hasAudio ()
 
bool hasVideo ()
 
void firstFrame () override
 Set the playhead position to the first frame.
 
void nextFrame () override
 Advance the playhead forward one frame.
 
void previousFrame () override
 Advance the playhead backward one frame.
 
bool setPixelFormat (ofPixelFormat pixelFormat) override
 Set the requested ofPixelFormat.
 
ofPixelFormat getPixelFormat () const override
 
ofPixelsgetPixels () override
 Get a reference to the underlying ofPixels.
 
const ofPixelsgetPixels () const override
 Get a const reference to the underlying ofPixels.
 
void setUsingHWAccel (bool ab)
 
bool isUsingHWAccel ()
 
float getFrameRate ()
 
- Public Member Functions inherited from ofBaseVideoPlayer
virtual ~ofBaseVideoPlayer ()
 Destroys the ofBaseVideoPlayer.
 
- Public Member Functions inherited from ofBaseVideo
virtual ~ofBaseVideo ()
 Destroy the ofBaseVideo.
 
- Public Member Functions inherited from ofBaseHasPixels_< unsigned char >
virtual ~ofBaseHasPixels_ ()
 Destroy the ofAbstractHasPixels.
 
- Public Member Functions inherited from ofAbstractHasPixels
virtual ~ofAbstractHasPixels ()
 Destroy the ofAbstractHasPixels.
 
- Public Member Functions inherited from ofBaseUpdates
virtual ~ofBaseUpdates ()
 Destroy the ofBaseUpdates.
 

Static Public Member Functions

static std::string MFEventToString (MF_MEDIA_ENGINE_EVENT aevent)
 
static std::string MFErrorToString (MF_MEDIA_ENGINE_ERR aerror)
 
static void setDurationHackEnabled (bool ab)
 
static std::shared_ptr< MEDXDeviceManagergetDxDeviceManager ()
 

Public Attributes

ofEvent< MF_MEDIA_ENGINE_EVENT > MFEngineEvent
 
ofEvent< MF_MEDIA_ENGINE_ERR > MFErrorEvent
 

Protected Member Functions

bool _load (std::string name, bool abAsync)
 
void OnMediaEngineEvent (DWORD aEvent, DWORD_PTR param1, DWORD param2) override
 
void handleMEEvent (DWORD aevent)
 
void updateDuration ()
 

Protected Attributes

std::shared_ptr< METexturemMeTexture
 
bool mBUseHWAccel = true
 
bool mBReady = false
 
bool mBLoaded = false
 
bool mBNewFrame = false
 
double mDuration = 0.0
 
float mWidth = 0.f
 
float mHeight = 0.f
 
bool mBDone = false
 
bool mBPlaying = false
 
bool mBCanSeek = false
 
float mFramerate = 1.f / 30.f
 
int mEstimatedNumFrames = 1
 
ofPixelFormat mPixFormat
 
ofLoopType mLoopType = OF_LOOP_NONE
 
float mTargetSeekPercent = -1.0
 
double mTimeStartedSeek = 0.0
 
double mTimePlayback = 0.0
 
std::shared_ptr< ofMEEventProcessormEventProcessor
 
DXGI_FORMAT m_d3dFormat = DXGI_FORMAT_B8G8R8A8_UNORM
 
Microsoft::WRL::ComPtr< IMFMediaEngine > m_spMediaEngine
 
Microsoft::WRL::ComPtr< IMFMediaEngineEx > m_spEngineEx
 
CRITICAL_SECTION m_critSec
 
std::queue< DWORD > mEventsQueue
 
std::mutex mMutexEvents
 
ofFbo mFbo
 
ofTexture mCopyTex
 
ofPixels mPixels
 
bool mBUpdatePixels = false
 
bool mBLoadAsync = false
 
std::atomic_bool mBIsDoneAtomic
 
std::atomic_bool mBIsClosedAtomic
 
std::condition_variable mWaitCondition
 

Static Protected Attributes

static bool sBAllowDurationHack = true
 
static std::shared_ptr< MEDXDeviceManagersDeviceManager
 

Friends

class ofMediaFoundationSoundPlayer
 

Constructor & Destructor Documentation

◆ ofMediaFoundationPlayer()

ofMediaFoundationPlayer::ofMediaFoundationPlayer ( )

◆ ~ofMediaFoundationPlayer()

ofMediaFoundationPlayer::~ofMediaFoundationPlayer ( )

Member Function Documentation

◆ _load()

bool ofMediaFoundationPlayer::_load ( std::string  name,
bool  abAsync 
)
protected

◆ close()

void ofMediaFoundationPlayer::close ( )
overridevirtual

Close the video source.

Implements ofBaseVideo.

◆ firstFrame()

void ofMediaFoundationPlayer::firstFrame ( )
overridevirtual

Set the playhead position to the first frame.

This is functionally equivalent to setFrame(0) or setPosition(0.0).

Reimplemented from ofBaseVideoPlayer.

◆ getCurrentFrame()

int ofMediaFoundationPlayer::getCurrentFrame ( ) const
overridevirtual

Get the current playhead position as a frame number.

Returns
The current playhead position as a frame number.

Reimplemented from ofBaseVideoPlayer.

◆ getDuration()

float ofMediaFoundationPlayer::getDuration ( ) const
overridevirtual

Get the duration of the loaded video in seconds.

Returns
The duration of the loaded video in seconds.

Reimplemented from ofBaseVideoPlayer.

◆ getDxDeviceManager()

std::shared_ptr< ofMediaFoundationPlayer::MEDXDeviceManager > ofMediaFoundationPlayer::getDxDeviceManager ( )
static

◆ getFrameRate()

float ofMediaFoundationPlayer::getFrameRate ( )
inline

◆ getHeight()

float ofMediaFoundationPlayer::getHeight ( ) const
overridevirtual

Get the height in pixels of the loaded video.

Returns
The height in pixels of the loaded video or 0 if none is loaded.

Implements ofBaseVideoPlayer.

◆ getIsMovieDone()

bool ofMediaFoundationPlayer::getIsMovieDone ( ) const
overridevirtual

Returns true if the loaded video has finished playing.

Returns
True if the loaded video has finished playing.

Reimplemented from ofBaseVideoPlayer.

◆ getLoopState()

ofLoopType ofMediaFoundationPlayer::getLoopState ( ) const
overridevirtual

Get the current loop state of the video.

See also
ofLoopType

Reimplemented from ofBaseVideoPlayer.

◆ getPixelFormat()

ofPixelFormat ofMediaFoundationPlayer::getPixelFormat ( ) const
overridevirtual
Returns
the current ofPixelFormat.

Implements ofBaseVideo.

◆ getPixels() [1/2]

const ofPixels & ofMediaFoundationPlayer::getPixels ( ) const
overridevirtual

Get a const reference to the underlying ofPixels.

Returns
a const reference the underlying ofPixels.

Implements ofBaseHasPixels_< unsigned char >.

◆ getPixels() [2/2]

ofPixels & ofMediaFoundationPlayer::getPixels ( )
overridevirtual

Get a reference to the underlying ofPixels.

Returns
a reference the underlying ofPixels.

Implements ofBaseHasPixels_< unsigned char >.

◆ getPosition()

float ofMediaFoundationPlayer::getPosition ( ) const
overridevirtual

Get the current playhead position of the loaded video.

This value is a normalized floating point value between 0.0 and 1.0 that represents the position of the playhead. 0.0 maps to the first frame of the loaded video and 1.0 maps to the last frame of the loaded video.

Returns
A value between 0.0 and 1.0 representing playhead position.

Reimplemented from ofBaseVideoPlayer.

◆ getSpeed()

float ofMediaFoundationPlayer::getSpeed ( ) const
overridevirtual

Get the playback speed of the video player.

When the loop state is OF_LOOP_NONE or OF_LOOP_NORMAL, positive speed will scale a forward playback rate while a negative speed will scale a a backward playback rate. When the loop state is OF_LOOP_PALINDROME, the direction of playback will change each loop, but the playback rate will still be scaled by the absolute value of the speed.

Returns
The playback speed of the video player.

Reimplemented from ofBaseVideoPlayer.

◆ getTexturePtr()

ofTexture * ofMediaFoundationPlayer::getTexturePtr ( )
virtual

Get a pointer to the video texture used internally if it exists.

If the video player implementation supports direct-to-texture rendering, this method will return a pointer to the internal texture. If direct-to-texture rendering is not supported, nullptr is returned.

Returns
A valid pointer to the internal texture, otherwise a nullptr.

Reimplemented from ofBaseVideoPlayer.

◆ getTotalNumFrames()

int ofMediaFoundationPlayer::getTotalNumFrames ( ) const
overridevirtual

Get the total number of frames in the currently loaded video.

Returns
The total number of frames in the currently loaded video.

Reimplemented from ofBaseVideoPlayer.

◆ getWidth()

float ofMediaFoundationPlayer::getWidth ( ) const
overridevirtual

Get the width in pixels of the loaded video.

Returns
The width in pixels of the loaded video or 0 if none is loaded.

Implements ofBaseVideoPlayer.

◆ handleMEEvent()

void ofMediaFoundationPlayer::handleMEEvent ( DWORD  aevent)
protected

◆ hasAudio()

bool ofMediaFoundationPlayer::hasAudio ( )

◆ hasVideo()

bool ofMediaFoundationPlayer::hasVideo ( )

◆ isFrameNew()

bool ofMediaFoundationPlayer::isFrameNew ( ) const
overridevirtual
Returns
true if the pixel data was updated since the last call to update().

Implements ofBaseVideo.

◆ isInitialized()

bool ofMediaFoundationPlayer::isInitialized ( ) const
overridevirtual

Returns true if a video is loaded.

This is helpful when loading a video with loadAsync(). This is also an alias of isLoaded().

See also
loadAsync()
Returns
True if a video is loaded.

Reimplemented from ofBaseVideoPlayer.

◆ isLoaded()

bool ofMediaFoundationPlayer::isLoaded ( ) const
overridevirtual

Returns true if a video is loaded.

This is helpful when loading a video with loadAsync(). This is also an alias of isInitialized().

See also
loadAsync()
Returns
True if a video is loaded.

Implements ofBaseVideoPlayer.

◆ isPaused()

bool ofMediaFoundationPlayer::isPaused ( ) const
overridevirtual

Returns true if the video is paused.

Returns
True if the video is paused.

Implements ofBaseVideoPlayer.

◆ isPlaying()

bool ofMediaFoundationPlayer::isPlaying ( ) const
overridevirtual

Returns true if the loaded video is playing.

Returns
True if the loaded video is playing.

Implements ofBaseVideoPlayer.

◆ isUsingHWAccel()

bool ofMediaFoundationPlayer::isUsingHWAccel ( )
inline

◆ load()

bool ofMediaFoundationPlayer::load ( std::string  name)
overridevirtual

Load a video resource by name.

The list of supported video types and sources (e.g. rtsp:// sources) is implementation dependent.

Parameters
nameThe name of the video resource to load.
Returns
True if the video was loaded successfully.
See also
loadAsync()

Implements ofBaseVideoPlayer.

◆ loadAsync()

void ofMediaFoundationPlayer::loadAsync ( std::string  name)
overridevirtual

Asynchronously load a video resource by name.

The list of supported video types and sources (e.g. rtsp:// sources) is implementation dependent.

When this method is used to load a video resouce, users can determine when the video is loaded by calling isLoaded().

Parameters
nameThe name of the video resource to load.
See also
isLoaded()

Reimplemented from ofBaseVideoPlayer.

◆ MFErrorToString()

std::string ofMediaFoundationPlayer::MFErrorToString ( MF_MEDIA_ENGINE_ERR  aerror)
static

◆ MFEventToString()

std::string ofMediaFoundationPlayer::MFEventToString ( MF_MEDIA_ENGINE_EVENT  aevent)
static

◆ nextFrame()

void ofMediaFoundationPlayer::nextFrame ( )
overridevirtual

Advance the playhead forward one frame.

This allows the user to advance through the video manually one frame at a time without calling play().

Reimplemented from ofBaseVideoPlayer.

◆ OnMediaEngineEvent()

void ofMediaFoundationPlayer::OnMediaEngineEvent ( DWORD  aEvent,
DWORD_PTR  param1,
DWORD  param2 
)
overrideprotectedvirtual

◆ play()

void ofMediaFoundationPlayer::play ( )
overridevirtual

Play the video from the current playhead position.

See also
getPosition()
setPostion()

Implements ofBaseVideoPlayer.

◆ previousFrame()

void ofMediaFoundationPlayer::previousFrame ( )
overridevirtual

Advance the playhead backward one frame.

This allows the user to advance backward through the video manually one frame at a time without calling play().

Reimplemented from ofBaseVideoPlayer.

◆ setDurationHackEnabled()

void ofMediaFoundationPlayer::setDurationHackEnabled ( bool  ab)
static

◆ setFrame()

void ofMediaFoundationPlayer::setFrame ( int  frame)
overridevirtual

Set the current frame by frame number.

Similar to setPosition(), but accepts a frame number instead of a normalized floating point value. Frame count begins with the first frame as 0 and the last frame as getTotalNumFrames() - 1.

Parameters
frameThe frame number to set the new playhead to.

Reimplemented from ofBaseVideoPlayer.

◆ setLoopState()

void ofMediaFoundationPlayer::setLoopState ( ofLoopType  state)
overridevirtual

Set the video loop state.

Parameters
stateThe loop state of the video.
See also
ofLoopType

Reimplemented from ofBaseVideoPlayer.

◆ setPaused()

void ofMediaFoundationPlayer::setPaused ( bool  bPause)
overridevirtual

Set the paused state of the video.

Parameters
bPauseTrue to pause the video, false to play.

Reimplemented from ofBaseVideoPlayer.

◆ setPixelFormat()

bool ofMediaFoundationPlayer::setPixelFormat ( ofPixelFormat  pixelFormat)
overridevirtual

Set the requested ofPixelFormat.

Parameters
pixelFormatthe requested ofPixelFormat.
Returns
true if the format was successfully changed.

Implements ofBaseVideo.

◆ setPosition()

void ofMediaFoundationPlayer::setPosition ( float  pct)
overridevirtual

Set the position of the playhead.

This value is a normalized floating point value between 0.0 and 1.0 that represents the position of the playhead. 0.0 maps to the first frame of the loaded video and 1.0 maps to the last frame of the loaded video.

Parameters
pctA value between 0.0 and 1.0 representing playhead position.

Reimplemented from ofBaseVideoPlayer.

◆ setSpeed()

void ofMediaFoundationPlayer::setSpeed ( float  speed)
overridevirtual

Set the video playback speed.

When the loop state is OF_LOOP_NONE or OF_LOOP_NORMAL, positive speed will scale a forward playback rate while a negative speed will scale a a backward playback rate. When the loop state is OF_LOOP_PALINDROME, the direction of playback will change each loop, but the playback rate will still be scaled by the absolute value of the speed.

To play a video forward at normal speed, set the loop state to OF_LOOP_NONE or OF_LOOP_NORMAL and a speed of 1.0. To double the playback rate, set the speed to 2.0. To play a video backward, set the speed to a negative number. A speed 0.25 will play the video at 1/4 the the normal rate and a rate of 0.0 will effectively stop playback.

Parameters
speedThe desired playback speed of the video.

Reimplemented from ofBaseVideoPlayer.

◆ setUsingHWAccel()

void ofMediaFoundationPlayer::setUsingHWAccel ( bool  ab)
inline

◆ setVolume()

void ofMediaFoundationPlayer::setVolume ( float  volume)
overridevirtual

Set the volume of the video player.

This value is a normalized floating point value between 0.0 and 1.0 that represents the video player volume. 0.0 maps to silence and 1.0 maps to maximum volume.

Parameters
volumeA value between 0.0 and 1.0 representing volume.

Reimplemented from ofBaseVideoPlayer.

◆ stop()

void ofMediaFoundationPlayer::stop ( )
overridevirtual

Pause and reset the playhead position to the first frame.

Implements ofBaseVideoPlayer.

◆ update()

void ofMediaFoundationPlayer::update ( )
overridevirtual

Update the object's state.

Implements ofBaseUpdates.

◆ updateDuration()

void ofMediaFoundationPlayer::updateDuration ( )
protected

Friends And Related Symbol Documentation

◆ ofMediaFoundationSoundPlayer

friend class ofMediaFoundationSoundPlayer
friend

Member Data Documentation

◆ m_critSec

CRITICAL_SECTION ofMediaFoundationPlayer::m_critSec
protected

◆ m_d3dFormat

DXGI_FORMAT ofMediaFoundationPlayer::m_d3dFormat = DXGI_FORMAT_B8G8R8A8_UNORM
protected

◆ m_spEngineEx

Microsoft::WRL::ComPtr<IMFMediaEngineEx> ofMediaFoundationPlayer::m_spEngineEx
protected

◆ m_spMediaEngine

Microsoft::WRL::ComPtr<IMFMediaEngine> ofMediaFoundationPlayer::m_spMediaEngine
protected

◆ mBCanSeek

bool ofMediaFoundationPlayer::mBCanSeek = false
protected

◆ mBDone

bool ofMediaFoundationPlayer::mBDone = false
protected

◆ mBIsClosedAtomic

std::atomic_bool ofMediaFoundationPlayer::mBIsClosedAtomic
protected

◆ mBIsDoneAtomic

std::atomic_bool ofMediaFoundationPlayer::mBIsDoneAtomic
protected

◆ mBLoadAsync

bool ofMediaFoundationPlayer::mBLoadAsync = false
protected

◆ mBLoaded

bool ofMediaFoundationPlayer::mBLoaded = false
protected

◆ mBNewFrame

bool ofMediaFoundationPlayer::mBNewFrame = false
protected

◆ mBPlaying

bool ofMediaFoundationPlayer::mBPlaying = false
protected

◆ mBReady

bool ofMediaFoundationPlayer::mBReady = false
protected

◆ mBUpdatePixels

bool ofMediaFoundationPlayer::mBUpdatePixels = false
mutableprotected

◆ mBUseHWAccel

bool ofMediaFoundationPlayer::mBUseHWAccel = true
protected

◆ mCopyTex

ofTexture ofMediaFoundationPlayer::mCopyTex
protected

◆ mDuration

double ofMediaFoundationPlayer::mDuration = 0.0
mutableprotected

◆ mEstimatedNumFrames

int ofMediaFoundationPlayer::mEstimatedNumFrames = 1
protected

◆ mEventProcessor

std::shared_ptr<ofMEEventProcessor> ofMediaFoundationPlayer::mEventProcessor
protected

◆ mEventsQueue

std::queue<DWORD> ofMediaFoundationPlayer::mEventsQueue
protected

◆ mFbo

ofFbo ofMediaFoundationPlayer::mFbo
protected

◆ MFEngineEvent

ofEvent<MF_MEDIA_ENGINE_EVENT> ofMediaFoundationPlayer::MFEngineEvent

◆ MFErrorEvent

ofEvent<MF_MEDIA_ENGINE_ERR> ofMediaFoundationPlayer::MFErrorEvent

◆ mFramerate

float ofMediaFoundationPlayer::mFramerate = 1.f / 30.f
protected

◆ mHeight

float ofMediaFoundationPlayer::mHeight = 0.f
protected

◆ mLoopType

ofLoopType ofMediaFoundationPlayer::mLoopType = OF_LOOP_NONE
protected

◆ mMeTexture

std::shared_ptr<METexture> ofMediaFoundationPlayer::mMeTexture
protected

◆ mMutexEvents

std::mutex ofMediaFoundationPlayer::mMutexEvents
protected

◆ mPixels

ofPixels ofMediaFoundationPlayer::mPixels
protected

◆ mPixFormat

ofPixelFormat ofMediaFoundationPlayer::mPixFormat
protected

◆ mTargetSeekPercent

float ofMediaFoundationPlayer::mTargetSeekPercent = -1.0
protected

◆ mTimePlayback

double ofMediaFoundationPlayer::mTimePlayback = 0.0
protected

◆ mTimeStartedSeek

double ofMediaFoundationPlayer::mTimeStartedSeek = 0.0
protected

◆ mWaitCondition

std::condition_variable ofMediaFoundationPlayer::mWaitCondition
protected

◆ mWidth

float ofMediaFoundationPlayer::mWidth = 0.f
protected

◆ sBAllowDurationHack

bool ofMediaFoundationPlayer::sBAllowDurationHack = true
staticprotected

◆ sDeviceManager

std::shared_ptr< ofMediaFoundationPlayer::MEDXDeviceManager > ofMediaFoundationPlayer::sDeviceManager
staticprotected

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