Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/cleanup #1

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
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
102 changes: 53 additions & 49 deletions src/ciWMFVideoPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ using namespace std;
using namespace ci;
using namespace ci::app;

typedef std::pair<HWND, ciWMFVideoPlayer*> PlayerItem;
list<PlayerItem> g_WMFVideoPlayers;

LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam );
// Message handlers

Expand All @@ -31,15 +28,6 @@ ciWMFVideoPlayer::ScopedVideoTextureBind::~ScopedVideoTextureBind()
mPlayer->mEVRPresenter->unlockSharedTexture();
}

ciWMFVideoPlayer* findPlayers( HWND hwnd )
{
for each( PlayerItem e in g_WMFVideoPlayers ) {
if( e.first == hwnd ) { return e.second; }
}

return NULL;
}

int ciWMFVideoPlayer::mInstanceCount = 0;

ciWMFVideoPlayer::ciWMFVideoPlayer()
Expand Down Expand Up @@ -85,6 +73,7 @@ ciWMFVideoPlayer::~ciWMFVideoPlayer()
if( mInstanceCount == 0 ) {
MFShutdown();
CI_LOG_I( "Shutting down MF" );
DestroyWindow(mHwnd);
}
}

Expand Down Expand Up @@ -163,10 +152,10 @@ void ciWMFVideoPlayer::draw( int x, int y, int w, int h )
return;
}

mPlayer->mEVRPresenter->lockSharedTexture();
bool success = mPlayer->mEVRPresenter->lockSharedTexture();

if( mTex ) {
Rectf destRect = Rectf( x, y, x + w, y + h );
Rectf destRect = Rectf( float(x), float(y), float(x + w), float(y + h) );

switch( mVideoFill ) {
case VideoFill::FILL:
Expand All @@ -184,20 +173,20 @@ void ciWMFVideoPlayer::draw( int x, int y, int w, int h )

}

mPlayer->mEVRPresenter->unlockSharedTexture();
success = mPlayer->mEVRPresenter->unlockSharedTexture();
}

bool ciWMFVideoPlayer::isPlaying()
bool ciWMFVideoPlayer::isPlaying() const
{
return mPlayer->GetState() == STARTED;
}

bool ciWMFVideoPlayer::isStopped()
bool ciWMFVideoPlayer::isStopped() const
{
return ( mPlayer->GetState() == STOPPED || mPlayer->GetState() == PAUSED );
}

bool ciWMFVideoPlayer::isPaused()
bool ciWMFVideoPlayer::isPaused() const
{
return mPlayer->GetState() == PAUSED;
}
Expand Down Expand Up @@ -238,37 +227,37 @@ void ciWMFVideoPlayer::pause()
mPlayer->Pause();
}

float ciWMFVideoPlayer::getPosition()
double ciWMFVideoPlayer::getPosition() const
{
return mPlayer->getPosition();
}

float ciWMFVideoPlayer::getFrameRate()
double ciWMFVideoPlayer::getFrameRate() const
{
return mPlayer->getFrameRate();
}

float ciWMFVideoPlayer::getDuration()
double ciWMFVideoPlayer::getDuration() const
{
return mPlayer->getDuration();
}

void ciWMFVideoPlayer::setPosition( float pos )
void ciWMFVideoPlayer::setPosition( double pos )
{
mPlayer->setPosition( pos );
}

void ciWMFVideoPlayer::stepForward()
{
if (mPlayer->GetState() == STOPPED) {
if( mPlayer->GetState() == STOPPED ) {
return;
}

mPlayer->Pause();
float fps = mPlayer->getFrameRate();
float step = 1 / fps;
float currentVidPos = mPlayer->getPosition();
float targetVidPos = currentVidPos + step;
double fps = mPlayer->getFrameRate();
double step = 1.0 / fps;
double currentVidPos = mPlayer->getPosition();
double targetVidPos = currentVidPos + step;

if (mPlayer->GetState() == PAUSED) {
play();
Expand Down Expand Up @@ -339,14 +328,23 @@ bool ciWMFVideoPlayer::setSpeed( float speed, bool useThinning )

PresentationEndedSignal& ciWMFVideoPlayer::getPresentationEndedSignal()
{
if( mPlayer ) {
return mPlayer->getPresentationEndedSignal();
}
assert( mPlayer );
return mPlayer->getPresentationEndedSignal();
}

float ciWMFVideoPlayer::getHeight() { return mPlayer->getHeight(); }
float ciWMFVideoPlayer::getWidth() { return mPlayer->getWidth(); }
void ciWMFVideoPlayer::setLoop( bool isLooping ) { mIsLooping = isLooping; mPlayer->setLooping( isLooping ); }
int ciWMFVideoPlayer::getHeight() const
{
return mPlayer->getHeight();
}
int ciWMFVideoPlayer::getWidth() const
{
return mPlayer->getWidth();
}
void ciWMFVideoPlayer::setLoop( bool isLooping )
{
mIsLooping = isLooping;
mPlayer->setLooping( isLooping );
}

//-----------------------------------
// Prvate Functions
Expand All @@ -364,19 +362,27 @@ void ciWMFVideoPlayer::OnPlayerEvent( HWND hwnd, WPARAM pUnkPtr )

LRESULT CALLBACK WndProcDummy( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
{
ciWMFVideoPlayer *impl = NULL;

// If the message is WM_NCCREATE we need to hide 'this' in the window long.
if( message == WM_NCCREATE ) {
impl = reinterpret_cast<ciWMFVideoPlayer*>( ( (LPCREATESTRUCT)lParam )->lpCreateParams );
::SetWindowLongPtr( hwnd, GWLP_USERDATA, (__int3264)(LONG_PTR)impl );
}
else
impl = reinterpret_cast<ciWMFVideoPlayer*>( ::GetWindowLongPtr( hwnd, GWLP_USERDATA ) );

switch( message ) {
case WM_CREATE: {
return DefWindowProc( hwnd, message, wParam, lParam );
}

default: {
ciWMFVideoPlayer* myPlayer = findPlayers( hwnd );

if( !myPlayer ) {
if( !impl ) {
return DefWindowProc( hwnd, message, wParam, lParam );
}

return myPlayer->WndProc( hwnd, message, wParam, lParam );
return impl->WndProc( hwnd, message, wParam, lParam );
}
}

Expand Down Expand Up @@ -405,7 +411,6 @@ LRESULT ciWMFVideoPlayer::WndProc( HWND hwnd, UINT message, WPARAM wParam, LPAR
BOOL ciWMFVideoPlayer::InitInstance()
{
PCWSTR szWindowClass = L"MFBASICPLAYBACK" ;
HWND hwnd;
WNDCLASSEX wcex;

// g_hInstance = hInst; // Store the instance handle.
Expand All @@ -425,28 +430,27 @@ BOOL ciWMFVideoPlayer::InitInstance()
}

// Create the application window.
hwnd = CreateWindow( szWindowClass, L"", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, NULL, NULL );
mHwnd = CreateWindow( szWindowClass, L"", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, NULL, reinterpret_cast<LPVOID>( this ) );

if( hwnd == 0 ) {
if( mHwnd == 0 ) {
return FALSE;
}

g_WMFVideoPlayers.push_back( std::pair<HWND, ciWMFVideoPlayer*>( hwnd, this ) );
HRESULT hr = CPlayer::CreateInstance( hwnd, hwnd, &mPlayer );
HRESULT hr = CPlayer::CreateInstance( mHwnd, mHwnd, &mPlayer );

LONG style2 = ::GetWindowLong( hwnd, GWL_STYLE );
LONG style2 = ::GetWindowLong( mHwnd, GWL_STYLE );
style2 &= ~WS_DLGFRAME;
style2 &= ~WS_CAPTION;
style2 &= ~WS_BORDER;
style2 &= WS_POPUP;
LONG exstyle2 = ::GetWindowLong( hwnd, GWL_EXSTYLE );
LONG exstyle2 = ::GetWindowLong( mHwnd, GWL_EXSTYLE );
exstyle2 &= ~WS_EX_DLGMODALFRAME;
::SetWindowLong( hwnd, GWL_STYLE, style2 );
::SetWindowLong( hwnd, GWL_EXSTYLE, exstyle2 );
::SetWindowLong( mHwnd, GWL_STYLE, style2 );
::SetWindowLong( mHwnd, GWL_EXSTYLE, exstyle2 );

mHWNDPlayer = hwnd;
UpdateWindow( hwnd );
mHWNDPlayer = mHwnd;
UpdateWindow( mHwnd );

return TRUE;
}
Expand Down
21 changes: 12 additions & 9 deletions src/ciWMFVideoPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class ciWMFVideoPlayer

BOOL InitInstance();
void OnPlayerEvent( HWND hwnd, WPARAM pUnkPtr );
HWND mHwnd;

public:
friend struct ScopedVideoTextureBind;
Expand Down Expand Up @@ -81,19 +82,21 @@ class ciWMFVideoPlayer
void stop();
void pause();

float getPosition();
float getDuration();
float getFrameRate();
double getPosition() const;
double getDuration() const;
double getFrameRate() const;

void setPosition( float pos );
void setPosition( double pos );
void stepForward();

float getHeight();
float getWidth();
int getHeight() const;
int getWidth() const;

bool isPlaying();
bool isStopped();
bool isPaused();
bool isPlaying() const;
bool isStopped() const;
bool isPaused() const;

bool hasTexture() const { return ( mPlayer && mTex ); }

bool setSpeed( float speed, bool useThinning = false ); //thinning drops delta frames for faster playback though appears to be choppy, default is false
float getSpeed();
Expand Down
34 changes: 17 additions & 17 deletions src/ciWMFVideoPlayerUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ HRESULT CPlayer::Stop()
return hr;
}

HRESULT CPlayer::setPosition( float pos )
HRESULT CPlayer::setPosition( double pos )
{
if( mState == OPEN_PENDING ) {
CI_LOG_E( "Error cannot seek during opening" );
Expand All @@ -451,7 +451,7 @@ HRESULT CPlayer::setPosition( float pos )
PlayerState curState = mState;
PropVariantInit( &varStart );
varStart.vt = VT_I8;
varStart.hVal.QuadPart = pos * 10000000.0; //i.e. seeking to pos // should be MFTIME and not float :(
varStart.hVal.QuadPart = (LONGLONG)(pos * 10000000.0); //i.e. seeking to pos // should be MFTIME and not float :(

HRESULT hr = mSession->Start( &GUID_NULL, &varStart );

Expand Down Expand Up @@ -493,7 +493,7 @@ HRESULT CPlayer::setVolume( float vol )
UINT32 nChannels;
mVolumeControl->GetChannelCount( &nChannels );

for( int i = 0; i < nChannels; i++ ) {
for( UINT32 i = 0; i < nChannels; i++ ) {
mVolumeControl->SetChannelVolume( i, vol );
}

Expand Down Expand Up @@ -1367,9 +1367,9 @@ HRESULT AddToPlaybackTopology(
/// Extra functions
//---------------

float CPlayer::getDuration()
double CPlayer::getDuration() const
{
float duration = 0.0;
double duration = 0.0;

if( mSource == NULL ) {
return 0.0;
Expand All @@ -1383,17 +1383,17 @@ float CPlayer::getDuration()
hr = pDescriptor->GetUINT64( MF_PD_DURATION, &longDuration );

if( SUCCEEDED( hr ) ) {
duration = ( float )longDuration / 10000000.0;
duration = (double)longDuration / 10000000.0;
}
}

SafeRelease( &pDescriptor );
return duration;
}

float CPlayer::getPosition()
double CPlayer::getPosition() const
{
float position = 0.0;
double position = 0.0;

if( mSession == NULL ) {
return 0.0;
Expand All @@ -1407,17 +1407,17 @@ float CPlayer::getPosition()
hr = pClock->GetTime( &longPosition );

if( SUCCEEDED( hr ) ) {
position = ( float )longPosition / 10000000.0;
position = (double)longPosition / 10000000.0;
}
}

SafeRelease( &pClock );
return position;
}

float CPlayer::getFrameRate()
double CPlayer::getFrameRate() const
{
float fps = 0.0;
double fps = 0.0;

if( mSource == NULL ) {
return 0.0;
Expand All @@ -1433,7 +1433,7 @@ float CPlayer::getFrameRate()

if FAILED( pDescriptor->GetStreamDescriptorCount( &nStream ) ) { goto done; }

for( int i = 0; i < nStream; i++ ) {
for( DWORD i = 0; i < nStream; i++ ) {
BOOL selected;
GUID type;

Expand All @@ -1457,7 +1457,7 @@ float CPlayer::getFrameRate()
);

if( denum != 0 ) {
fps = ( float ) num / ( float ) denum;
fps = (double) num / (double) denum;
mNumFrames = denum;
}
}
Expand All @@ -1477,12 +1477,12 @@ float CPlayer::getFrameRate()
return fps;
}

int CPlayer::getCurrentFrame()
int CPlayer::getCurrentFrame() const
{
int frame = 0;

if( mSource == NULL ) {
return 0.0;
return 0;
}

IMFPresentationDescriptor* pDescriptor = NULL;
Expand All @@ -1495,7 +1495,7 @@ int CPlayer::getCurrentFrame()

if FAILED( pDescriptor->GetStreamDescriptorCount( &nStream ) ) { goto done; }

for( int i = 0; i < nStream; i++ ) {
for( DWORD i = 0; i < nStream; i++ ) {
BOOL selected;
GUID type;

Expand Down Expand Up @@ -1638,7 +1638,7 @@ HRESULT CPlayer::SetPlaybackRate( BOOL bThin, float rateRequested )
return hr;
}

float CPlayer::GetPlaybackRate()
float CPlayer::GetPlaybackRate() const
{
HRESULT hr = S_OK;
IMFRateControl* pRateControl = NULL;
Expand Down
Loading