Permalink
Browse files

MP1-4781V14 : madVR V485 (Trying back to stop playback on suspend to …

…avoid crash on resume when media is playing by using DRR change when player goes/leaves fullscreen)
  • Loading branch information...
Sebastiii committed Sep 30, 2018
1 parent d0635be commit 940bc368f543a99c319e9dde6d02393922c36006
@@ -649,6 +649,34 @@ void MPMadPresenter::EnableExclusive(bool bEnable)
}
};

void MPMadPresenter::EnableOriginalDisplayMode(bool bEnable)
{
if (m_pMad)
{
if (Com::SmartQIPtr<IMadVRSettings> m_pSettings = m_pMad)
{
// Read DisplayModeChanger settings
BOOL m_enableDisplayModeChanger;
BOOL m_enableDisplayModeRestore;
m_pSettings->SettingsGetBoolean(L"enableDisplayModeChanger", &m_enableDisplayModeChanger);
m_pSettings->SettingsGetBoolean(L"restoreDisplayMode", &m_enableDisplayModeRestore);

if (m_enableDisplayModeChanger)
{
m_pSettings->SettingsSetBoolean(L"enableDisplayModeChanger", true);
m_pSettings->SettingsSetBoolean(L"changeDisplayModeOnPlay", false);
}

if (m_enableDisplayModeRestore)
{
m_pSettings->SettingsSetBoolean(L"restoreDisplayMode", true);
m_pSettings->SettingsSetBoolean(L"restoreDisplayModeOnClose", false);
}
m_pSettings.Release(); // WIP release
}
}
};

void MPMadPresenter::ConfigureMadvr()
{
if (m_pMad)
@@ -1672,6 +1700,9 @@ HRESULT MPMadPresenter::SetDeviceOsd(IDirect3DDevice9* pD3DDev)
}
// Authorize OSD placement
m_pReInitOSD = true;

// Enable DisplayModeChanger is set by using DRR when player goes /leaves fullscreen
EnableOriginalDisplayMode(true);
return hr;
}
Log("MPMadPresenter::SetDeviceOsd() init madVR Window");
@@ -282,6 +282,7 @@ class MPMadPresenter : public CUnknown, public CCritSec
STDMETHODIMP SetStopEvent();

virtual void EnableExclusive(bool bEnable);
virtual void EnableOriginalDisplayMode(bool bEnable);

bool m_pShutdown = false;
bool m_pInitOSD = false;
@@ -1814,7 +1814,8 @@ public void Vmr9MediaCtrl(IMediaControl mediaCtrl)
int hr;
if (GUIGraphicsContext.VideoRenderer == GUIGraphicsContext.VideoRendererType.madVR)
{
RestoreDisplayModeNow();
// Disable Restore Display mode, it is done on C++ side
//RestoreDisplayModeNow();

if (_scene?.WorkerThread != null)
{
@@ -1897,6 +1897,7 @@ private bool OnSysCommand(ref Message msg)
/// <param name="msg"></param>
private bool OnPowerBroadcast(ref Message msg)
{
bool result = true;
try
{
Log.Info("Main: WM_POWERBROADCAST ({0})", Enum.GetName(typeof(PBT_EVENT), msg.WParam.ToInt32()));
@@ -1910,6 +1911,10 @@ private bool OnPowerBroadcast(ref Message msg)
_delayedResume = false;
_suspended = true;

SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS | EXECUTION_STATE.ES_SYSTEM_REQUIRED);
msg.Result = (IntPtr)1;
result = false;

// Suspending GUIGraphicsContext when going to S3
if (GUIGraphicsContext.CurrentState == GUIGraphicsContext.State.RUNNING)
{
@@ -2138,7 +2143,7 @@ private bool OnPowerBroadcast(ref Message msg)
{
Log.Error("Main: Exception catch on OnPowerBroadcast : {0}", ex);
}
return true;
return result;
}

private bool CheckDelayedResume()
@@ -2929,8 +2934,9 @@ private void OnSuspend()
{
// stop playback
Log.Debug("Main: OnSuspend - stopping playback");
if (GUIGraphicsContext.IsPlaying)
if (g_Player.Playing || GUIGraphicsContext.IsPlaying)
{
SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS | EXECUTION_STATE.ES_SYSTEM_REQUIRED);
Currentmodulefullscreen();
if (GUIGraphicsContext.VideoRenderer == GUIGraphicsContext.VideoRendererType.madVR)
{
@@ -2942,18 +2948,17 @@ private void OnSuspend()
}
}
Currentmodulefullscreen();
var action = new Action(Action.ActionType.ACTION_STOP, 0, 0);
GUIGraphicsContext.OnAction(action);
// Disable this to avoid crash on resume - V468 added it to try to avoid deadlock on stop.
//var action = new Action(Action.ActionType.ACTION_STOP, 0, 0);
//GUIGraphicsContext.OnAction(action);
}
else
g_Player.Stop();
while (GUIGraphicsContext.IsPlaying || g_Player.Player != null)
{
g_Player.Stop();
while (GUIGraphicsContext.IsPlaying)
{
// This could lead into OS putting system into sleep before MP completes OnSuspend().
// OS gives only 2 seconds time to application to react power events (>= Vista)
Thread.Sleep(100);
}
// This could lead into OS putting system into sleep before MP completes OnSuspend().
// OS gives only 2 seconds time to application to react power events (>= Vista)
Thread.Sleep(100);
Log.Debug("Main: player not null");
}
}
SaveLastActiveModule();

0 comments on commit 940bc36

Please sign in to comment.