Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 124 additions & 21 deletions src/ofxWMFVideoPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);

ofxWMFVideoPlayer* findPlayers(HWND hwnd)
{
for each (PlayerItem e in g_WMFVideoPlayers)
for (PlayerItem e : g_WMFVideoPlayers)
{
if (e.first == hwnd) return e.second;
}
Expand Down Expand Up @@ -63,6 +63,8 @@ ofxWMFVideoPlayer::ofxWMFVideoPlayer() : _player(NULL)
_wantToSetVolume = false;
_currentVolume = 1.0;
_frameRate = 0.0f;
_duration = 0.f;
_totalNumFrames = 0.f;


}
Expand All @@ -71,8 +73,8 @@ ofxWMFVideoPlayer::ofxWMFVideoPlayer() : _player(NULL)
ofxWMFVideoPlayer::~ofxWMFVideoPlayer() {
if (_player)
{
if (_sharedTextureCreated) _player->m_pEVRPresenter->releaseSharedTexture();
_player->Shutdown();
//if (_sharedTextureCreated) _player->m_pEVRPresenter->releaseSharedTexture();
SafeRelease(&_player);
}

Expand Down Expand Up @@ -101,6 +103,9 @@ void ofxWMFVideoPlayer::forceExit()

bool ofxWMFVideoPlayer:: loadMovie(string name)
{
loadEventSent = false;
bLoaded = false;

if (!_player) {
ofLogError("ofxWMFVideoPlayer") << "Player not created. Can't open the movie.";
return false;
Expand Down Expand Up @@ -134,7 +139,7 @@ void ofxWMFVideoPlayer::forceExit()
_width = _player->getWidth();
_height = _player->getHeight();

_tex.allocate(_width,_height,GL_RGBA,true);
_tex.allocate(_width,_height,GL_RGB,true);

_player->m_pEVRPresenter->createSharedTexture(_width, _height,_tex.texData.textureID);
_sharedTextureCreated = true;
Expand All @@ -149,14 +154,19 @@ void ofxWMFVideoPlayer::forceExit()
_width = _player->getWidth();
_height = _player->getHeight();

_tex.allocate(_width,_height,GL_RGBA,true);
_tex.allocate(_width,_height,GL_RGB,true);
_player->m_pEVRPresenter->createSharedTexture(_width, _height,_tex.texData.textureID);

}

}
_waitForLoadedToPlay = false;

_frameRate = _player->getFrameRate();
_duration = _player->getDuration();

_totalNumFrames = _duration * _frameRate;

return false;


Expand All @@ -173,18 +183,37 @@ void ofxWMFVideoPlayer::forceExit()



}

void ofxWMFVideoPlayer::bind() {


_player->m_pEVRPresenter->lockSharedTexture();
_tex.setTextureWrap(GL_CLAMP_TO_BORDER, GL_CLAMP_TO_BORDER);
_tex.bind();



}
void ofxWMFVideoPlayer::unbind() {


_tex.unbind();
_player->m_pEVRPresenter->unlockSharedTexture();



}


bool ofxWMFVideoPlayer:: isPlaying() {
bool ofxWMFVideoPlayer:: isPlaying() const {
return _player->GetState() == Started;
}
bool ofxWMFVideoPlayer:: isStopped() {
bool ofxWMFVideoPlayer:: isStopped() const {
return (_player->GetState() == Stopped || _player->GetState() == Paused);
}

bool ofxWMFVideoPlayer:: isPaused()
{
bool ofxWMFVideoPlayer:: isPaused() const {
return _player->GetState() == Paused;
}

Expand All @@ -208,14 +237,45 @@ void ofxWMFVideoPlayer:: update() {

if ((_wantToSetVolume))
{
_player->setVolume(_currentVolume);
setVolume(_currentVolume);

}
return;
}

bool ofxWMFVideoPlayer::getIsMovieDone() const
{
int currentFrame = getCurrentFrame();
int finalFrame = _totalNumFrames - (_frameRate / 5.f);

return (currentFrame >= finalFrame);
}

bool ofxWMFVideoPlayer::isLoaded() const {
if(_player == NULL){ return false; }
PlayerState ps = _player->GetState();
return ps == PlayerState::Paused || ps == PlayerState::Stopped || ps == PlayerState::Started;
}

bool ofxWMFVideoPlayer::setPixelFormat(ofPixelFormat pixelFormat){
return (pixelFormat == OF_PIXELS_RGB);
}

ofPixelFormat ofxWMFVideoPlayer::getPixelFormat() const {
return OF_PIXELS_RGB;
}

bool ofxWMFVideoPlayer::isFrameNew() const {
return true;//TODO fix this
}

void ofxWMFVideoPlayer::setPaused( bool bPause )
{
if ( bPause == true )
pause() ;
else
play() ;
}

void ofxWMFVideoPlayer:: play()
{
Expand All @@ -235,18 +295,40 @@ void ofxWMFVideoPlayer:: pause()
_player->Pause();
}

void ofxWMFVideoPlayer::setLoopState( ofLoopType loopType )
{
switch ( loopType )
{
case OF_LOOP_NONE :
setLoop( false ) ;
break ;
case OF_LOOP_NORMAL :
setLoop( true ) ;
break;
default :
ofLogError ( "ofxWMFVideoPlayer::setLoopState LOOP TYPE NOT SUPPORTED" ) << loopType << endl ;
break ;
}
}

float ofxWMFVideoPlayer::getPosition() const
{
return ( _player->getPosition() / getDuration() );
//this returns it in seconds
// return _player->getPosition();
}

float ofxWMFVideoPlayer:: getPosition() {
return _player->getPosition();
int ofxWMFVideoPlayer::getCurrentFrame() const {
return getPosition() * _totalNumFrames;
}

float ofxWMFVideoPlayer:: getDuration() {
return _player->getDuration();
float ofxWMFVideoPlayer::getDuration() const {
return _duration;
}

void ofxWMFVideoPlayer::setPosition(float pos)
{
_player->setPosition(pos);
_player->setPosition(pos * getDuration());
}

void ofxWMFVideoPlayer::setVolume(float vol)
Expand All @@ -262,20 +344,24 @@ void ofxWMFVideoPlayer::setVolume(float vol)

}

float ofxWMFVideoPlayer::getVolume()
float ofxWMFVideoPlayer::getVolume() const
{
return _player->getVolume();
}

float ofxWMFVideoPlayer::getFrameRate()
float ofxWMFVideoPlayer::getFrameRate() const
{
if (!_player) return 0.0f;
if (_frameRate == 0.0f) _frameRate = _player->getFrameRate();
return _frameRate;
}

float ofxWMFVideoPlayer::getHeight() { return _player->getHeight(); }
float ofxWMFVideoPlayer::getWidth() { return _player->getWidth(); }

int ofxWMFVideoPlayer::getTotalNumFrames() const
{
return _totalNumFrames;
}

float ofxWMFVideoPlayer::getHeight() const { return _player->getHeight(); }
float ofxWMFVideoPlayer::getWidth() const { return _player->getWidth(); }

void ofxWMFVideoPlayer::setLoop(bool isLooping) { _isLooping = isLooping; _player->setLooping(isLooping); }

Expand All @@ -286,13 +372,30 @@ void ofxWMFVideoPlayer::setLoop(bool isLooping) { _isLooping = isLooping; _play
//-----------------------------------



// Handler for Media Session events.
void ofxWMFVideoPlayer::OnPlayerEvent(HWND hwnd, WPARAM pUnkPtr)
{
HRESULT hr = _player->HandleEvent(pUnkPtr);
PlayerState state;

if (_player->GetState() == 3)
{

if (!loadEventSent){
bLoaded = true;
ofNotifyEvent(videoLoadEvent,bLoaded,this);
loadEventSent = true;
}
}

if (FAILED(hr))
{
if (!loadEventSent){
bLoaded = false;
ofNotifyEvent(videoLoadEvent,bLoaded,this);
loadEventSent = true;
}

ofLogError("ofxWMFVideoPlayer", "An error occurred.");
}
}
Expand Down
Loading