diff options
Diffstat (limited to 'avmedia/source/win/player.cxx')
-rw-r--r-- | avmedia/source/win/player.cxx | 140 |
1 files changed, 123 insertions, 17 deletions
diff --git a/avmedia/source/win/player.cxx b/avmedia/source/win/player.cxx index d27b2b55ff93..56efbe6b107b 100644 --- a/avmedia/source/win/player.cxx +++ b/avmedia/source/win/player.cxx @@ -52,6 +52,30 @@ using namespace ::com::sun::star; namespace avmedia { namespace win { +LRESULT CALLBACK MediaPlayerWndProc_2( HWND hWnd,UINT nMsg, WPARAM nPar1, LPARAM nPar2 ) +{ + Player* pPlayer = (Player*) ::GetWindowLong( hWnd, 0 ); + bool bProcessed = true; + + if( pPlayer ) + { + switch( nMsg ) + { + case( WM_GRAPHNOTIFY ): + pPlayer->processEvent(); + break; + default: + bProcessed = false; + break; + } + } + else + bProcessed = false; + + return( bProcessed ? 0 : DefWindowProc( hWnd, nMsg, nPar1, nPar2 ) ); +} + + bool isWindowsVistaOrHigher() { // POST: return true if we are at least on Windows Vista @@ -59,10 +83,7 @@ bool isWindowsVistaOrHigher() ZeroMemory(&osvi, sizeof(osvi)); osvi.dwOSVersionInfoSize = sizeof(osvi); GetVersionEx(&osvi); - if ( osvi.dwMajorVersion >= 6 ) - return true; - - return false; + return osvi.dwMajorVersion >= 6; } // ---------------- @@ -70,6 +91,7 @@ bool isWindowsVistaOrHigher() // ---------------- Player::Player( const uno::Reference< lang::XMultiServiceFactory >& rxMgr ) : + Player_BASE(m_aMutex), mxMgr( rxMgr ), mpGB( NULL ), mpOMF( NULL ), @@ -82,8 +104,10 @@ Player::Player( const uno::Reference< lang::XMultiServiceFactory >& rxMgr ) : mpVW( NULL ), mpEV( NULL ), mnUnmutedVolume( 0 ), + mnFrameWnd( 0 ), mbMuted( false ), - mbLooping( false ) + mbLooping( false ), + mbAddWindow(sal_True) { ::CoInitialize( NULL ); } @@ -92,6 +116,18 @@ Player::Player( const uno::Reference< lang::XMultiServiceFactory >& rxMgr ) : Player::~Player() { + if( mnFrameWnd ) + ::DestroyWindow( (HWND) mnFrameWnd ); + + ::CoUninitialize(); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Player::disposing() +{ + ::osl::MutexGuard aGuard(m_aMutex); + stop(); if( mpBA ) mpBA->Release(); @@ -108,7 +144,11 @@ Player::~Player() mpMS->Release(); if( mpME ) + { + mpME->SetNotifyWindow( 0, WM_GRAPHNOTIFY, 0); mpME->Release(); + } + if( mpMC ) mpMC->Release(); @@ -121,12 +161,8 @@ Player::~Player() if( mpGB ) mpGB->Release(); - - ::CoUninitialize(); } - // ------------------------------------------------------------------------------ - bool Player::create( const ::rtl::OUString& rURL ) { HRESULT hR; @@ -137,15 +173,12 @@ bool Player::create( const ::rtl::OUString& rURL ) // Don't use the overlay mixer on Windows Vista // It disables the desktop composition as soon as RenderFile is called // also causes some other problems: video rendering is not reliable - if( !isWindowsVistaOrHigher() ) + if( !isWindowsVistaOrHigher() && SUCCEEDED( CoCreateInstance( CLSID_OverlayMixer, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void**) &mpOMF ) ) ) { - if( SUCCEEDED( CoCreateInstance( CLSID_OverlayMixer, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void**) &mpOMF ) ) ) - { - mpGB->AddFilter( mpOMF, L"com_sun_star_media_OverlayMixerFilter" ); + mpGB->AddFilter( mpOMF, L"com_sun_star_media_OverlayMixerFilter" ); - if( !SUCCEEDED( mpOMF->QueryInterface( IID_IDDrawExclModeVideo, (void**) &mpEV ) ) ) - mpEV = NULL; - } + if( !SUCCEEDED( mpOMF->QueryInterface( IID_IDDrawExclModeVideo, (void**) &mpEV ) ) ) + mpEV = NULL; } if( SUCCEEDED( hR = mpGB->RenderFile( reinterpret_cast<LPCWSTR>(rURL.getStr()), NULL ) ) && @@ -187,6 +220,7 @@ const IVideoWindow* Player::getVideoWindow() const void Player::setNotifyWnd( int nNotifyWnd ) { + mbAddWindow = sal_False; if( mpME ) mpME->SetNotifyWindow( (OAHWND) nNotifyWnd, WM_GRAPHNOTIFY, reinterpret_cast< LONG_PTR>( this ) ); } @@ -208,7 +242,7 @@ long Player::processEvent() { long nCode, nParam1, nParam2; - if( mpME && SUCCEEDED( mpME->GetEvent( &nCode, &nParam1, &nParam2, 0 ) ) ) + while( mpME && SUCCEEDED( mpME->GetEvent( &nCode, &nParam1, &nParam2, 0 ) ) ) { if( EC_COMPLETE == nCode ) { @@ -235,8 +269,44 @@ long Player::processEvent() void SAL_CALL Player::start( ) throw (uno::RuntimeException) { + ::osl::MutexGuard aGuard(m_aMutex); if( mpMC ) + { + if ( mbAddWindow ) + { + static WNDCLASS* mpWndClass = NULL; + if ( !mpWndClass ) + { + mpWndClass = new WNDCLASS; + + memset( mpWndClass, 0, sizeof( *mpWndClass ) ); + mpWndClass->hInstance = GetModuleHandle( NULL ); + mpWndClass->cbWndExtra = sizeof( DWORD ); + mpWndClass->lpfnWndProc = MediaPlayerWndProc_2; + mpWndClass->lpszClassName = "com_sun_star_media_Sound_Player"; + mpWndClass->hbrBackground = (HBRUSH) ::GetStockObject( BLACK_BRUSH ); + mpWndClass->hCursor = ::LoadCursor( NULL, IDC_ARROW ); + + ::RegisterClass( mpWndClass ); + } + if ( !mnFrameWnd ) + { + mnFrameWnd = (int) ::CreateWindow( mpWndClass->lpszClassName, NULL, + 0, + 0, 0, 0, 0, + (HWND) NULL, NULL, mpWndClass->hInstance, 0 ); + if ( mnFrameWnd ) + { + ::ShowWindow((HWND) mnFrameWnd, SW_HIDE); + ::SetWindowLong( (HWND) mnFrameWnd, 0, (DWORD) this ); + // mpVW->put_Owner( (OAHWND) mnFrameWnd ); + setNotifyWnd( mnFrameWnd ); + } + } + } + mpMC->Run(); + } } // ------------------------------------------------------------------------------ @@ -244,6 +314,8 @@ void SAL_CALL Player::start( ) void SAL_CALL Player::stop( ) throw (uno::RuntimeException) { + ::osl::MutexGuard aGuard(m_aMutex); + if( mpMC ) mpMC->Stop(); } @@ -253,6 +325,8 @@ void SAL_CALL Player::stop( ) sal_Bool SAL_CALL Player::isPlaying() throw (uno::RuntimeException) { + ::osl::MutexGuard aGuard(m_aMutex); + OAFilterState eFilterState; bool bRet = false; @@ -267,6 +341,8 @@ sal_Bool SAL_CALL Player::isPlaying() double SAL_CALL Player::getDuration( ) throw (uno::RuntimeException) { + ::osl::MutexGuard aGuard(m_aMutex); + REFTIME aRefTime( 0.0 ); if( mpMP ) @@ -280,6 +356,8 @@ double SAL_CALL Player::getDuration( ) void SAL_CALL Player::setMediaTime( double fTime ) throw (uno::RuntimeException) { + ::osl::MutexGuard aGuard(m_aMutex); + if( mpMP ) { const bool bPlaying = isPlaying(); @@ -296,6 +374,8 @@ void SAL_CALL Player::setMediaTime( double fTime ) double SAL_CALL Player::getMediaTime( ) throw (uno::RuntimeException) { + ::osl::MutexGuard aGuard(m_aMutex); + REFTIME aRefTime( 0.0 ); if( mpMP ) @@ -309,6 +389,8 @@ double SAL_CALL Player::getMediaTime( ) void SAL_CALL Player::setStopTime( double fTime ) throw (uno::RuntimeException) { + ::osl::MutexGuard aGuard(m_aMutex); + if( mpMP ) mpMP->put_StopTime( fTime ); } @@ -318,6 +400,8 @@ void SAL_CALL Player::setStopTime( double fTime ) double SAL_CALL Player::getStopTime( ) throw (uno::RuntimeException) { + ::osl::MutexGuard aGuard(m_aMutex); + REFTIME aRefTime( 0.0 ); if( mpMP ) @@ -331,6 +415,8 @@ double SAL_CALL Player::getStopTime( ) void SAL_CALL Player::setRate( double fRate ) throw (uno::RuntimeException) { + ::osl::MutexGuard aGuard(m_aMutex); + if( mpMP ) mpMP->put_Rate( fRate ); } @@ -340,6 +426,8 @@ void SAL_CALL Player::setRate( double fRate ) double SAL_CALL Player::getRate( ) throw (uno::RuntimeException) { + ::osl::MutexGuard aGuard(m_aMutex); + double fRet( 0.0 ); if( mpMP ) @@ -353,6 +441,8 @@ double SAL_CALL Player::getRate( ) void SAL_CALL Player::setPlaybackLoop( sal_Bool bSet ) throw (uno::RuntimeException) { + ::osl::MutexGuard aGuard(m_aMutex); + mbLooping = bSet; } @@ -361,6 +451,8 @@ void SAL_CALL Player::setPlaybackLoop( sal_Bool bSet ) sal_Bool SAL_CALL Player::isPlaybackLoop( ) throw (uno::RuntimeException) { + ::osl::MutexGuard aGuard(m_aMutex); + return mbLooping; } @@ -369,6 +461,8 @@ sal_Bool SAL_CALL Player::isPlaybackLoop( ) void SAL_CALL Player::setMute( sal_Bool bSet ) throw (uno::RuntimeException) { + ::osl::MutexGuard aGuard(m_aMutex); + if( mpBA && ( mbMuted != bSet ) ) { mbMuted = bSet; @@ -381,6 +475,8 @@ void SAL_CALL Player::setMute( sal_Bool bSet ) sal_Bool SAL_CALL Player::isMute( ) throw (uno::RuntimeException) { + ::osl::MutexGuard aGuard(m_aMutex); + return mbMuted; } @@ -389,6 +485,8 @@ sal_Bool SAL_CALL Player::isMute( ) void SAL_CALL Player::setVolumeDB( sal_Int16 nVolumeDB ) throw (uno::RuntimeException) { + ::osl::MutexGuard aGuard(m_aMutex); + mnUnmutedVolume = static_cast< long >( nVolumeDB ) * 100; if( !mbMuted && mpBA ) @@ -400,6 +498,8 @@ void SAL_CALL Player::setVolumeDB( sal_Int16 nVolumeDB ) sal_Int16 SAL_CALL Player::getVolumeDB( ) throw (uno::RuntimeException) { + ::osl::MutexGuard aGuard(m_aMutex); + return( static_cast< sal_Int16 >( mnUnmutedVolume / 100 ) ); } @@ -408,6 +508,8 @@ sal_Int16 SAL_CALL Player::getVolumeDB( ) awt::Size SAL_CALL Player::getPreferredPlayerWindowSize( ) throw (uno::RuntimeException) { + ::osl::MutexGuard aGuard(m_aMutex); + awt::Size aSize( 0, 0 ); if( mpBV ) @@ -427,6 +529,8 @@ awt::Size SAL_CALL Player::getPreferredPlayerWindowSize( ) uno::Reference< ::media::XPlayerWindow > SAL_CALL Player::createPlayerWindow( const uno::Sequence< uno::Any >& aArguments ) throw (uno::RuntimeException) { + ::osl::MutexGuard aGuard(m_aMutex); + uno::Reference< ::media::XPlayerWindow > xRet; awt::Size aSize( getPreferredPlayerWindowSize() ); @@ -448,6 +552,8 @@ uno::Reference< ::media::XPlayerWindow > SAL_CALL Player::createPlayerWindow( co uno::Reference< media::XFrameGrabber > SAL_CALL Player::createFrameGrabber( ) throw (uno::RuntimeException) { + ::osl::MutexGuard aGuard(m_aMutex); + uno::Reference< media::XFrameGrabber > xRet; if( maURL.getLength() > 0 ) |