Permalink
Browse files

Merge remote-tracking branch 'remotes/origin/MP1-4781V14_madVR_based_…

…master'
  • Loading branch information...
Sebastiii committed Oct 10, 2018
2 parents 2898c8d + 30090f3 commit e39b2b2a2cbe642e15b71f9fef7d2e30401019e6
@@ -32,7 +32,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Team MediaPortal")]
[assembly: Guid("6D0386CE-37E6-4f77-B678-07C584105DC6")]
[assembly: AssemblyVersion("2.0.0.0")]
[assembly: AssemblyVersion("2.0.0.1408")]
#if DEBUG

[assembly: AssemblyProduct("Debug Version")]
@@ -56,4 +56,4 @@
#pragma warning disable 612,618
[assembly: SecurityPermission(action: SecurityAction.RequestMinimum, UnmanagedCode = true)]
#pragma warning restore 612,618
[assembly: AssemblyFileVersion("2.0.0.0")]
[assembly: AssemblyFileVersion("2.0.0.1408")]
@@ -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)
@@ -905,6 +933,9 @@ HRESULT MPMadPresenter::Stopping()
return E_FAIL;
}

// Enable DisplayModeChanger is set by using DRR when player goes /leaves fullscreen (if we use profiles)
EnableOriginalDisplayMode(true);

if (m_pORCB)
{
// IOsdRenderCallback
@@ -1536,6 +1567,10 @@ void MPMadPresenter::ReinitOSD(bool type)
{
Log("%s : ReinitOSD from : RenderOsd", __FUNCTION__);
}

// Enable DisplayModeChanger is set by using DRR when player goes /leaves fullscreen (if we use profiles)
EnableOriginalDisplayMode(true);

m_pReInitOSD = false;
m_pMPTextureGui = nullptr;
m_pMPTextureOsd = nullptr;
@@ -1672,6 +1707,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;
@@ -928,6 +928,8 @@ protected virtual void SetSourceDestRectangles(Rectangle source, Rectangle desti

if (GUIGraphicsContext.VideoRenderer == GUIGraphicsContext.VideoRendererType.madVR)
{
// First we need to init rDest.Left and rDest to a fixed value.
_basicVideo.SetDestinationPosition(GUIGraphicsContext.RDestLeft, GUIGraphicsContext.RDestTop, destination.Width, destination.Height);
_basicVideo.SetDestinationPosition(destination.Left, destination.Top, destination.Width, destination.Height);
}
else
@@ -215,6 +215,10 @@ public enum PlayState

protected object lockObj = new object();

protected static DateTime ratioTimer;

protected static bool RatioDetectChange = false;

#endregion

#region ctor/dtor
@@ -867,13 +871,30 @@ public override void Process()
{
if (_basicVideo != null)
{
_basicVideo.SetDestinationPosition(0, 0, GUIGraphicsContext.VideoWindowWidth,
_basicVideo.SetDestinationPosition(GUIGraphicsContext.VideoWindowWidth, GUIGraphicsContext.VideoWindowHeight, GUIGraphicsContext.VideoWindowWidth,
GUIGraphicsContext.VideoWindowHeight);
Log.Debug("TsReader: show video window");
}
}
}
}

// Keep this code if needed but adding a better hack to fix this "align left top" on playback start
//TimeSpan tsRatio = DateTime.Now - ratioTimer;
//// Force VideoPosition change after a detected aspect ratio change by delay it by 2 seconds for madVR filter.
//if (tsRatio.Seconds >= 5)
//{
// if (RatioDetectChange && !GUIGraphicsContext.MadVrOsd)
// {
// RatioDetectChange = false;
// Log.Debug("TSReaderPlayer: Force VideoWindow after aspect ratio detected change");
// // Force VideoWindow to be refreshed with madVR when switching from video size like 16:9 to 4:3
// GUIGraphicsContext.UpdateVideoWindow = true;
// GUIGraphicsContext.VideoWindowChanged();
// // Force a madVR refresh to resize MP window
// g_Player.RefreshMadVrVideo();
// }
//}
}
else
{
@@ -1578,6 +1599,8 @@ protected virtual void SetSourceDestRectangles(Rectangle rSource, Rectangle rDes

if (GUIGraphicsContext.VideoRenderer == GUIGraphicsContext.VideoRendererType.madVR)
{
// First we need to init rDest.Left and rDest to a fixed value.
_basicVideo.SetDestinationPosition(GUIGraphicsContext.RDestLeft, GUIGraphicsContext.RDestTop, rDest.Width, rDest.Height);
_basicVideo.SetDestinationPosition(rDest.Left, rDest.Top, rDest.Width, rDest.Height);
}
else
@@ -1705,6 +1728,11 @@ internal static void OnMessage(GUIMessage message)
_videoFormat.arY = message.Param5;
_videoFormat.bitrate = message.Param6;
_videoFormat.isInterlaced = (message.Param7 == 1);
if (GUIGraphicsContext.VideoRenderer == GUIGraphicsContext.VideoRendererType.madVR)
{
ratioTimer = DateTime.Now;
RatioDetectChange = true;
}
Log.Info("TsReaderPlayer: OnVideoFormatChanged - {0}", _videoFormat.ToString());
break;
}
@@ -1736,6 +1764,11 @@ internal static void OnMessage(GUIMessage message)
_videoFormat.arY = aspectRatioY;
_videoFormat.bitrate = bitrate;
_videoFormat.isInterlaced = (isInterlaced == 1);
if (GUIGraphicsContext.VideoRenderer == GUIGraphicsContext.VideoRendererType.madVR)
{
ratioTimer = DateTime.Now;
RatioDetectChange = true;
}
Log.Info("TsReaderPlayer: OnVideoFormatChanged - {0} MP main thread", _videoFormat.ToString());
}
return 0;
@@ -2224,6 +2224,8 @@ protected virtual void SetSourceDestRectangles(Rectangle source, Rectangle desti

if (GUIGraphicsContext.VideoRenderer == GUIGraphicsContext.VideoRendererType.madVR)
{
// First we need to init rDest.Left and rDest to a fixed value.
_basicVideo.SetDestinationPosition(GUIGraphicsContext.RDestLeft, GUIGraphicsContext.RDestTop, destination.Width, destination.Height);
_basicVideo.SetDestinationPosition(destination.Left, destination.Top, destination.Width, destination.Height);
}
else
@@ -252,6 +252,7 @@ private enum Vmr9PlayState
protected bool UseMadVideoRenderer; // is madVR used?
protected bool UseEVRMadVRForTV;
protected bool UseMadVideoRenderer3D;
protected bool UseEnhancedVideoRenderer;
protected internal DateTime playbackTimer;
protected internal DateTime PlaneSceneMadvrTimer = new DateTime(0);
protected IVideoWindow videoWinMadVr;
@@ -887,6 +888,7 @@ public bool AddVMR9(IGraphBuilder graphBuilder)
UseMadVideoRenderer = xmlreader.GetValueAsBool("general", "useMadVideoRenderer", false);
UseEVRMadVRForTV = xmlreader.GetValueAsBool("general", "useEVRMadVRForTV", false);
UseMadVideoRenderer3D = xmlreader.GetValueAsBool("general", "useMadVideoRenderer3D", false);
UseEnhancedVideoRenderer = xmlreader.GetValueAsBool("general", "useEVRenderer", false);
}
Log.Debug("VMR9: addvmr9 - thread : {0}", Thread.CurrentThread.Name);
if (!_useVmr9)
@@ -918,6 +920,13 @@ public bool AddVMR9(IGraphBuilder graphBuilder)
if (UseEVRMadVRForTV && g_Player.IsTimeShifting)
{
GUIGraphicsContext.VideoRenderer = GUIGraphicsContext.VideoRendererType.EVR;
// Keep current RenderTarget to trying to restore D3D GUI from madVR but release it if already init previously
if (GUIGraphicsContext.MadVrRenderTargetVmr9 != null && !GUIGraphicsContext.MadVrRenderTargetVmr9.Disposed)
{
GUIGraphicsContext.DX9Device?.SetRenderTarget(0, GUIGraphicsContext.MadVrRenderTargetVmr9);
GUIGraphicsContext.MadVrRenderTargetVmr9.Dispose();
GUIGraphicsContext.MadVrRenderTargetVmr9 = null;
}
}
else
{
@@ -1827,7 +1836,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)
{
@@ -2345,6 +2355,20 @@ public void Dispose()
GUIGraphicsContext.Vmr9Active = false;
}

// Reset video rendere status
if (UseEnhancedVideoRenderer)
{
GUIGraphicsContext.VideoRenderer = GUIGraphicsContext.VideoRendererType.EVR;
}
else if (UseMadVideoRenderer)
{
GUIGraphicsContext.VideoRenderer = GUIGraphicsContext.VideoRendererType.madVR;
}
else
{
GUIGraphicsContext.VideoRenderer = GUIGraphicsContext.VideoRendererType.VMR9;
}

Log.Debug("VMR9: Dispose done");
}

@@ -723,6 +723,8 @@ protected virtual void SetSourceDestRectangles(Rectangle rSource, Rectangle rDes
{
rDest.Height = rDest.Height*2;
}
// First we need to init rDest.Left and rDest to a fixed value.
basicVideo.SetDestinationPosition(GUIGraphicsContext.RDestLeft, GUIGraphicsContext.RDestTop, rDest.Width, rDest.Height);
basicVideo.SetDestinationPosition(rDest.Left, rDest.Top, rDest.Width, rDest.Height);
}
else
@@ -1912,6 +1912,9 @@ public static object RenderMadVrLock
public static bool CurrentAudioRendererDone { get; set; }
// set to true if recreate swap chain is needed
public static bool NeedRecreateSwapChain { get; set; }
// Needed to avoid align TOP/LEFT on start
public static int RDestTop = 480;
public static int RDestLeft = 150;

//public static IntPtr madVRDIB { get; set; }

@@ -2937,31 +2937,32 @@ 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)
{
if (VMR9Util.g_vmr9 != null)
{
if (VMR9Util.g_vmr9.Vmr9Filter != null)
{
MadvrInterface.restoreDisplayModeNow(VMR9Util.g_vmr9.Vmr9Filter);
}
}
// Disabled, it is done on C++ side
//if (VMR9Util.g_vmr9 != null)
//{
// if (VMR9Util.g_vmr9.Vmr9Filter != null)
// {
// MadvrInterface.restoreDisplayModeNow(VMR9Util.g_vmr9.Vmr9Filter);
// }
//}
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 e39b2b2

Please sign in to comment.