Skip to content

Commit

Permalink
Merge pull request #326 from MediaPortal/MP1-5223-Improvement_of_Refr…
Browse files Browse the repository at this point in the history
…eshRateChanger

MP1-5223: Improvement of Refresh Rate Changer
  • Loading branch information
andrewjswan authored Jul 30, 2024
2 parents cd19c89 + fb792c1 commit 720e641
Showing 1 changed file with 50 additions and 12 deletions.
62 changes: 50 additions & 12 deletions mediaportal/Core/Player/RefreshRateChanger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,9 @@ private static void FindExtCmdfromSettings(double fps, out double newRR,
newExtCmd = "";
newRRDescription = "";

//Round fps down to 3 decimal places
fps = Math.Round(fps, 3);

foreach (RefreshRateSetting setting in _refreshRateSettings)
{
foreach (double fpsSetting in setting.Fps)
Expand Down Expand Up @@ -1089,30 +1092,65 @@ public static void AdaptRefreshRateFromVideoDecoder(string strFile)
Log.Debug("[AdaptRefreshRateFromVideoDecoder] Video Decoder found.");

DirectShowLib.IPin pin;
int iResult = filter.FindPin("In", out pin);
int iResult = filter.FindPin("Out", out pin);
if (iResult == 0)
{
Log.Debug("[AdaptRefreshRateFromVideoDecoder] Input Pin of Video Decoder retrieved.");
Log.Debug("[AdaptRefreshRateFromVideoDecoder] Output Pin of Video Decoder retrieved.");
DirectShowLib.AMMediaType mediatype = new DirectShowLib.AMMediaType();
iResult = pin.ConnectionMediaType(mediatype);

if (iResult == 0)
{
Log.Debug("[AdaptRefreshRateFromVideoDecoder] AMMediaType: " + mediatype.formatType.ToString());

DirectShowLib.VideoInfoHeader videoHeader = new DirectShowLib.VideoInfoHeader();
Marshal.PtrToStructure(mediatype.formatPtr, videoHeader);
bool bInterlaced = false;
string strGUID = mediatype.formatType.ToString();
Log.Debug("[AdaptRefreshRateFromVideoDecoder] AMMediaType: " + strGUID);

if (videoHeader != null)
if (strGUID.Equals("F72A76A0-EB0A-11D0-ACE4-0000C0CC16BA", StringComparison.OrdinalIgnoreCase) //VIDEOINFOHEADER2
|| strGUID.Equals("E06D80E3-DB46-11CF-B4D1-00805F6CBBEA", StringComparison.OrdinalIgnoreCase)) //WMFORMAT_MPEG2Video
{
DirectShowLib.VideoInfoHeader2 videoHeader = new DirectShowLib.VideoInfoHeader2();
Marshal.PtrToStructure(mediatype.formatPtr, videoHeader);
if (videoHeader != null)
{
bInterlaced = (videoHeader.InterlaceFlags & DirectShowLib.AMInterlace.IsInterlaced) == DirectShowLib.AMInterlace.IsInterlaced;
dFps = Math.Round(10000000F / videoHeader.AvgTimePerFrame, 2);
Log.Debug("[AdaptRefreshRateFromVideoDecoder] AvgTimePerFrame from VideoInfoHeader2: {0}, Interlaced: {1}",
videoHeader.AvgTimePerFrame, bInterlaced);
}
}
else
{
Log.Debug("[AdaptRefreshRateFromVideoDecoder] AvgTimePerFrame from VideoInfoHeader: " + videoHeader.AvgTimePerFrame);
DirectShowLib.VideoInfoHeader videoHeader = new DirectShowLib.VideoInfoHeader();
Marshal.PtrToStructure(mediatype.formatPtr, videoHeader);

if (videoHeader != null)
{
Log.Debug("[AdaptRefreshRateFromVideoDecoder] AvgTimePerFrame from VideoInfoHeader: " + videoHeader.AvgTimePerFrame);
dFps = Math.Round(10000000F / videoHeader.AvgTimePerFrame, 2);
}
}

dFps = Math.Round(10000000F / videoHeader.AvgTimePerFrame, 2);
if (dFps == 23.98)
dFps = 23.976;

if (dFps == 23.98)
dFps = 23.976;
Log.Info("[AdaptRefreshRateFromVideoDecoder] Detected FPS from Video Decoder: " + dFps);

Log.Info("[AdaptRefreshRateFromVideoDecoder] Detected FPS from Video Decoder: " + dFps);
if (bInterlaced)
{
switch (dFps)
{
case 25:
dFps = 50.0;
break;

case 29.97:
dFps = 59.97;
break;

case 30:
dFps = 60.0;
break;
}
}
}
else
Expand Down

0 comments on commit 720e641

Please sign in to comment.