avmedia/source/win/player.cxx | 35 ++++++++++++++++++++++------------- avmedia/source/win/player.hxx | 3 +++ avmedia/source/win/window.cxx | 5 ----- 3 files changed, 25 insertions(+), 18 deletions(-)
New commits: commit 66d04ec31bbf03b839926ab75288ee0955ec6f04 Author: Balazs Varga <balazs.va...@collabora.com> AuthorDate: Mon Aug 4 09:38:03 2025 +0200 Commit: Balazs Varga <balazs.va...@collabora.com> CommitDate: Mon Aug 4 13:41:27 2025 +0200 Related: tdf#62408 tdf#159292 Impress: error handling if media file cannot be played on Windows with new Media Foundation api. Replace avmedia::MediaWindow::executeFormatErrorBox which caused crash. follow up of: 65d72f816afc92a062cf6ad14c1bb4fb0a5829df Change-Id: I03be99ac486f64f1181be69fdcea316b8ac79c98 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/188910 Tested-by: Jenkins Reviewed-by: Balazs Varga <balazs.va...@collabora.com> diff --git a/avmedia/source/win/player.cxx b/avmedia/source/win/player.cxx index 39330ab70829..4ad9711ce843 100644 --- a/avmedia/source/win/player.cxx +++ b/avmedia/source/win/player.cxx @@ -22,13 +22,14 @@ #include <evcode.h> #include <propvarutil.h> #include <propkey.h> +#include <strsafe.h> + // Media Foundation headers #include <mfapi.h> #include <mfidl.h> #include <mfreadwrite.h> #include <avmedia/mediaitem.hxx> -#include <avmedia/mediawindow.hxx> #include "player.hxx" #include "framegrabber.hxx" @@ -135,7 +136,7 @@ void Player::OnMediaPlayerEvent(MFP_EVENT_HEADER* pEventHeader) SAL_WARN("avmedia.win", "Player::OnMediaPlayerEvent failed with error code: " << pEventHeader->hrEvent); - ::avmedia::MediaWindow::executeFormatErrorBox(nullptr); + ShowErrorMessage(L"MediaPlayerEvent error", pEventHeader->hrEvent); return; } @@ -301,7 +302,7 @@ void Player::OnMediaItemCreated(MFP_MEDIAITEM_CREATED_EVENT* pEvent) SAL_WARN("avmedia.win", "Player::OnMediaItemCreated failed with error code: " << hr); - ::avmedia::MediaWindow::executeFormatErrorBox(nullptr); + ShowErrorMessage(L"IMFPMediaPlayer::SetMediaItem failed.", hr); m_state = Closed; } } @@ -328,7 +329,7 @@ void Player::OnMediaItemSet(MFP_MEDIAITEM_SET_EVENT* /*pEvent*/) SAL_WARN("avmedia.win", "Player::OnMediaItemSet failed with error code: " << hr); - ::avmedia::MediaWindow::executeFormatErrorBox(nullptr); + ShowErrorMessage(L"IMFPMediaPlayer::Play failed.", hr); } } @@ -346,6 +347,18 @@ void Player::OnMediaItemEnded(MFP_PLAYBACK_ENDED_EVENT* /*pEvent*/) m_state = Stopped; } +void Player::ShowErrorMessage(PCWSTR format, HRESULT hrErr) +{ + HRESULT hr = S_OK; + TCHAR pszDest[MAX_PATH]; + LPCTSTR pszFormat = TEXT("%s (hr=0x%X)"); + hr = StringCbPrintf(pszDest, sizeof(pszDest), pszFormat, format, hrErr); + if (SUCCEEDED(hr)) + { + MessageBox(mnFrameWnd, pszDest, TEXT("Error"), MB_ICONERROR); + } +} + HRESULT Player::InitializeWindow(bool bAddSoundWindow) { HRESULT hr = S_OK; @@ -430,7 +443,7 @@ void SAL_CALL Player::start( ) SAL_WARN("avmedia.win", "Player::start failed with error code: " << hr); - ::avmedia::MediaWindow::executeFormatErrorBox(nullptr); + ShowErrorMessage(L"Error playing this file.", hr); } } } @@ -562,7 +575,7 @@ void SAL_CALL Player::setMute( sal_Bool bSet ) { ::osl::MutexGuard aGuard(m_aMutex); - if (g_pPlayer && (g_bHasVideo || g_bHasAudio) && + if (g_pPlayer && g_bHasAudio && (mbMuted != static_cast<BOOL>(bSet))) { mbMuted = bSet; @@ -579,7 +592,7 @@ sal_Bool SAL_CALL Player::isMute( ) { ::osl::MutexGuard aGuard(m_aMutex); - if (g_pPlayer && (g_bHasVideo || g_bHasAudio)) + if (g_pPlayer && g_bHasAudio) { HRESULT hr = g_pPlayer->GetMute(&mbMuted); if (FAILED(hr)) @@ -598,7 +611,7 @@ void SAL_CALL Player::setVolumeDB( sal_Int16 nVolumeDB ) mnUnmutedVolume = static_cast< float >( (nVolumeDB / AVMEDIA_DB_RANGE) + 1.0 ); - if ( g_pPlayer && (g_bHasVideo || g_bHasAudio)) + if (g_pPlayer && g_bHasAudio) { HRESULT hr = g_pPlayer->SetVolume(mnUnmutedVolume); if (FAILED(hr)) @@ -613,7 +626,7 @@ sal_Int16 SAL_CALL Player::getVolumeDB( ) { ::osl::MutexGuard aGuard(m_aMutex); - if (g_pPlayer && (g_bHasVideo || g_bHasAudio)) + if (g_pPlayer && g_bHasAudio) { HRESULT hr = g_pPlayer->GetVolume(&mnUnmutedVolume); if (FAILED(hr)) @@ -663,10 +676,6 @@ uno::Reference< ::media::XPlayerWindow > SAL_CALL Player::createPlayerWindow( co } } } - else - { - ::avmedia::MediaWindow::executeFormatErrorBox(nullptr); - } } return xRet; diff --git a/avmedia/source/win/player.hxx b/avmedia/source/win/player.hxx index 04675217881f..0f200245b6d1 100644 --- a/avmedia/source/win/player.hxx +++ b/avmedia/source/win/player.hxx @@ -76,6 +76,9 @@ public: const UINT32 GetVideoWidth() const { return mnFrameWidth; } const UINT32 GetVideoHeight() const { return mnFrameHeight; } + // Error handling + void ShowErrorMessage(PCWSTR format, HRESULT hr); + // IUnknown methods STDMETHODIMP QueryInterface(REFIID iid, void** ppv); STDMETHODIMP_(ULONG) AddRef(); diff --git a/avmedia/source/win/window.cxx b/avmedia/source/win/window.cxx index 4c3100bea864..641bafdea0d7 100644 --- a/avmedia/source/win/window.cxx +++ b/avmedia/source/win/window.cxx @@ -23,7 +23,6 @@ #include <com/sun/star/awt/SystemPointer.hpp> #include <cppuhelper/supportsservice.hxx> #include <avmedia/mediaitem.hxx> -#include <avmedia/mediawindow.hxx> #include "window.hxx" #include "player.hxx" @@ -252,10 +251,6 @@ bool Window::create( const uno::Sequence< uno::Any >& rArguments ) meZoomLevel = media::ZoomLevel_FIT_TO_WINDOW; ImplLayoutVideoWindow(); } - else - { - ::avmedia::MediaWindow::executeFormatErrorBox(nullptr); - } } }