Permalink
Browse files

First step for dynamic refresh for streaming protocol (need optimizat…

…ion)
  • Loading branch information...
1 parent f823e40 commit 2cf11f831226f35b154d65446727039168fdf112 @Sebastiii Sebastiii committed Nov 26, 2012
Showing with 131 additions and 53 deletions.
  1. +95 −40 mediaportal/Core/Player/RefreshRateChanger.cs
  2. +36 −13 mediaportal/Core/Player/g_player.cs
@@ -525,7 +525,7 @@ private static void GetRefreshRateConfiguration()
{
foreach (double fpsSetting in setting.Fps)
{
- if (fps == fpsSetting)
+ if (Math.Abs(fps - fpsSetting) < 0.1)
{
newRR = setting.Hz;
newExtCmd = setting.ExtCmd;
@@ -638,7 +638,7 @@ public static void ResetRefreshRateState()
_refreshrateChangeCurrentRR = 0;
}
- public static void SetRefreshRateBasedOnFPS(double fps, string strFile, MediaType type)
+ public static bool SetRefreshRateBasedOnFPS(double fps, string strFile, MediaType type)
{
int currentScreenNr = GUIGraphicsContext.currentScreenNumber;
double currentRR = 0;
@@ -665,7 +665,7 @@ public static void SetRefreshRateBasedOnFPS(double fps, string strFile, MediaTyp
if (!enabled)
{
Log.Info("RefreshRateChanger.SetRefreshRateBasedOnFPS: 'auto refreshrate changer' disabled");
- return;
+ return false;
}
force_refresh_rate = xmlreader.GetValueAsBool("general", "force_refresh_rate", false);
deviceReset = xmlreader.GetValueAsBool("general", "devicereset", false);
@@ -709,16 +709,96 @@ public static void SetRefreshRateBasedOnFPS(double fps, string strFile, MediaTyp
Log.Info(
"RefreshRateChanger.SetRefreshRateBasedOnFPS: could not find a matching refreshrate based on {0} fps (check config)",
fps);
+ return false;
}
else
{
Log.Info(
"RefreshRateChanger.SetRefreshRateBasedOnFPS: no refreshrate change required. current is {0}hz, desired is {1}",
currentRR, newRR);
+ return false;
}
}
+ return true;
}
+ public static void DelayedRefreshrateChanger(string strFile, MediaPortal.Player.g_Player.MediaType type)
+ {
+
+ Log.Info("RefreshRateChanger.DelayedRefreshrateChanger: using delayed framerate detection");
+ double fps = -1;
+ int maxretries = 100;
+
+ // wait until graph is build
+ while (VMR9Util.g_vmr9 == null)
+ {
+ Thread.Sleep(200);
+ }
+
+ // wait that the video file is played a while
+ Thread.Sleep(2000);
+
+ do
+ {
+ if (VMR9Util.g_vmr9 != null)
+ {
+ fps = VMR9Util.g_vmr9.GetEVRVideoFPS(0);
+ if (fps > 1)
+ {
+ break;
+ }
+ }
+ Thread.Sleep(200);
+ } while (--maxretries > 0);
+
+ int verify = 2;
+ while (fps > 1 || --verify > 0)
+ {
+ Log.Info("RefreshRateChanger.DelayedRefreshrateChanger: detected new render framerate of:{0} fps", fps);
+
+ // refreshrate change done here.
+ bool rchanged = RefreshRateChanger.AdaptRefreshRate(strFile, (RefreshRateChanger.MediaType)(int)type, fps);
+
+ if (RefreshRateChanger.RefreshRateChangePending)
+ {
+ TimeSpan ts = DateTime.Now - RefreshRateChanger.RefreshRateChangeExecutionTime;
+ if (ts.TotalSeconds > RefreshRateChanger.WAIT_FOR_REFRESHRATE_RESET_MAX)
+ {
+ Log.Info(
+ "RefreshRateChanger.DelayedRefreshrateChanger: waited {0}s for refreshrate change, but it never took place (check your config). Proceeding with playback.",
+ RefreshRateChanger.WAIT_FOR_REFRESHRATE_RESET_MAX);
+ RefreshRateChanger.ResetRefreshRateState();
+ }
+ else
+ {
+ Log.Info("RefreshRateChanger.DelayedRefreshrateChanger: waited {0}s for refreshrate change. Proceeding with playback.", ts.TotalSeconds);
+ }
+ }
+
+ if (rchanged && VMR9Util.g_vmr9 != null)
+ {
+ Thread.Sleep(500);
+ Log.Info("RefreshRateChanger.DelayedRefreshrateChanger: UpdateEVRDisplayFPS");
+ VMR9Util.g_vmr9.UpdateEVRDisplayFPS();
+ }
+
+ // recheck the fps rate
+ Thread.Sleep(10000);
+
+ double newfps = VMR9Util.g_vmr9.GetEVRVideoFPS(0);
+ Log.Info("RefreshRateChanger.DelayedRefreshrateChanger: verify refresh rate new render framerate: {0} fps old {1} fps", newfps, fps);
+ if (Math.Abs(fps - newfps) > 1 && VMR9Util.g_vmr9 != null)
+ {
+ // seems that the refreshrate we detected first has now changed again
+ fps = newfps;
+ }
+ else
+ {
+ // end while no new changed needed
+ fps = 0;
+ }
+ }
+ }
// defaults the refreshrate
public static void AdaptRefreshRate()
@@ -783,23 +863,18 @@ public static void AdaptRefreshRate()
}
// change screen refresh rate based on media framerate
- public static void AdaptRefreshRate(string strFile, MediaType type)
+ public static bool AdaptRefreshRate(string strFile, MediaType type, double fps)
{
if (_refreshrateChangePending)
{
- return;
+ return true;
}
bool isTV = Util.Utils.IsLiveTv(strFile);
- bool isDVD = Util.Utils.IsDVD(strFile);
- bool isVideo = Util.Utils.IsVideo(strFile);
+ //bool isDVD = Util.Utils.IsDVD(strFile);
+ //bool isVideo = Util.Utils.IsVideo(strFile);
bool isRTSP = Util.Utils.IsRTSP(strFile); //rtsp users for live TV and recordings.
- if (!isTV && !isDVD && !isVideo && !isRTSP)
- {
- return;
- }
-
bool enabled = false;
NumberFormatInfo provider = new NumberFormatInfo();
provider.NumberDecimalSeparator = ".";
@@ -812,7 +887,7 @@ public static void AdaptRefreshRate(string strFile, MediaType type)
if (!enabled)
{
Log.Info("RefreshRateChanger.AdaptRefreshRate: 'auto refreshrate changer' disabled");
- return;
+ return false;
}
deviceReset = xmlreader.GetValueAsBool("general", "devicereset", false);
@@ -825,46 +900,26 @@ public static void AdaptRefreshRate(string strFile, MediaType type)
{
Log.Error(
"RefreshRateChanger.AdaptRefreshRate: TV section not found in mediaportal.xml, please delete file and reconfigure.");
- return;
+ return false;
}
- List<double> tvFPS = setting.Fps;
- double fps = -1;
-
- if ((isVideo || isDVD) && (!isRTSP && !isTV))
- {
- if (g_Player.MediaInfo != null)
- {
- fps = g_Player.MediaInfo.Framerate;
- }
- else
- {
- StackTrace st = new StackTrace(true);
- StackFrame sf = st.GetFrame(0);
-
- Log.Error("RefreshRateChanger.AdaptRefreshRate: g_Player.MediaInfo was null. file: {0} st: {1}", strFile,
- sf.GetMethod().Name);
- return;
- }
- }
- else if (isTV || isRTSP)
+ if ((isTV || isRTSP) && fps <= 0)
{
+ List<double> tvFPS = setting.Fps;
if (tvFPS.Count > 0)
{
fps = tvFPS[0];
}
}
- if (fps < 1)
+ if (fps <= 0)
{
Log.Info("RefreshRateChanger.AdaptRefreshRate: unable to guess framerate on file {0}", strFile);
- }
- else
- {
- Log.Info("RefreshRateChanger.AdaptRefreshRate: framerate on file {0} is {1}", strFile, fps);
+ return false;
}
- SetRefreshRateBasedOnFPS(fps, strFile, type);
+ Log.Info("RefreshRateChanger.AdaptRefreshRate: framerate on file {0} is {1}", strFile, fps);
+ return SetRefreshRateBasedOnFPS(fps, strFile, type);
}
#endregion
@@ -38,6 +38,7 @@
using Un4seen.Bass.AddOn.Cd;
using Action = MediaPortal.GUI.Library.Action;
using MediaPortal.Player.Subtitles;
+using System.Threading;
namespace MediaPortal.Player
{
@@ -67,6 +68,7 @@ public enum DriveType
#region variables
private static MediaInfoWrapper _mediaInfo = null;
+ private static Thread _delayedrefreshratechanger = null;
private static int _currentStep = 0;
private static int _currentStepIndex = -1;
private static DateTime _seekTimer = DateTime.MinValue;
@@ -596,6 +598,11 @@ private static void doStop(bool keepTimeShifting, bool keepExclusiveModeOn)
}
if (_player != null)
{
+ if (_delayedrefreshratechanger != null)
+ {
+ _delayedrefreshratechanger.Abort();
+ _delayedrefreshratechanger = null;
+ }
Log.Debug("g_Player.doStop() keepTimeShifting = {0} keepExclusiveModeOn = {1}", keepTimeShifting,
keepExclusiveModeOn);
// Get playing file for unmount handling
@@ -1280,6 +1287,12 @@ public static bool Play(string strFile, MediaType type, TextReader chapters, boo
ChangeDriveSpeed(strFile, DriveType.CD);
}
+ if (_delayedrefreshratechanger != null)
+ {
+ _delayedrefreshratechanger.Abort();
+ _delayedrefreshratechanger = null;
+ }
+
if (!playingRemoteUrl) // MediaInfo can only be used on files (local or SMB)
{
_mediaInfo = new MediaInfoWrapper(strFile);
@@ -1293,25 +1306,35 @@ public static bool Play(string strFile, MediaType type, TextReader chapters, boo
type = MediaType.Video;
}
- // Refreshrate change done here. Blu-ray player will handle the refresh rate changes by itself
- if (strFile.ToUpper().IndexOf(@"\BDMV\INDEX.BDMV") == -1)
+ if (_mediaInfo == null || _mediaInfo.Framerate <= 0)
{
- RefreshRateChanger.AdaptRefreshRate(strFile, (RefreshRateChanger.MediaType)(int)type);
+ // using DelayedRefreshrateChanger
+ _delayedrefreshratechanger = new Thread(delegate() { RefreshRateChanger.DelayedRefreshrateChanger(strFile, type); });
+ _delayedrefreshratechanger.Start();
}
-
- if (RefreshRateChanger.RefreshRateChangePending)
+ else
{
- TimeSpan ts = DateTime.Now - RefreshRateChanger.RefreshRateChangeExecutionTime;
- if (ts.TotalSeconds > RefreshRateChanger.WAIT_FOR_REFRESHRATE_RESET_MAX)
+ // Refreshrate change done here. Blu-ray player will handle the refresh rate changes by itself
+ if (strFile.ToUpper().IndexOf(@"\BDMV\INDEX.BDMV") == -1)
{
- Log.Info(
- "g_Player.Play - waited {0}s for refreshrate change, but it never took place (check your config). Proceeding with playback.",
- RefreshRateChanger.WAIT_FOR_REFRESHRATE_RESET_MAX);
- RefreshRateChanger.ResetRefreshRateState();
+ RefreshRateChanger.AdaptRefreshRate(strFile, (RefreshRateChanger.MediaType) (int) type,
+ _mediaInfo.Framerate);
}
- else
+
+ if (RefreshRateChanger.RefreshRateChangePending)
{
- return true;
+ TimeSpan ts = DateTime.Now - RefreshRateChanger.RefreshRateChangeExecutionTime;
+ if (ts.TotalSeconds > RefreshRateChanger.WAIT_FOR_REFRESHRATE_RESET_MAX)
+ {
+ Log.Info(
+ "g_Player.Play - waited {0}s for refreshrate change, but it never took place (check your config). Proceeding with playback.",
+ RefreshRateChanger.WAIT_FOR_REFRESHRATE_RESET_MAX);
+ RefreshRateChanger.ResetRefreshRateState();
+ }
+ else
+ {
+ return true;
+ }
}
}
}

0 comments on commit 2cf11f8

Please sign in to comment.