Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/MP1-4927-BUG-Mixer_rewor…
Browse files Browse the repository at this point in the history
…k_for_Win7_and_Win10'
  • Loading branch information
Sebastiii committed Oct 10, 2018
2 parents 85abcd5 + 5459990 commit 2898c8d
Show file tree
Hide file tree
Showing 12 changed files with 1,459 additions and 638 deletions.
1 change: 1 addition & 0 deletions mediaportal/Core/Core.csproj
Expand Up @@ -376,6 +376,7 @@
<Compile Include="guilib\TextureFrame.cs" />
<Compile Include="guilib\ViewHandler.cs" />
<Compile Include="guilib\XMLSkinFunctionAttribute.cs" />
<Compile Include="Mixer\Mixer10.cs" />
<Compile Include="MusicPlayer\BASS\MixerStream.cs" />
<Compile Include="Player\BDOSDRenderer.cs" />
<Compile Include="Player\BDPlayer.cs" />
Expand Down
25 changes: 16 additions & 9 deletions mediaportal/Core/DShowNET/Helper/DirectShowUtil.cs
Expand Up @@ -91,16 +91,21 @@ public static IBaseFilter AddAudioRendererToGraph(IGraphBuilder graphBuilder, st
{
try
{
Log.Debug("DirectShowUtil: AddAudioRendererToGraph : ({0}) init", strFilterName);
IBaseFilter newFilter = AddAudioRenderer(graphBuilder, strFilterName, setAsReferenceClock);
Log.Debug("DirectShowUtil: AddAudioRendererToGraph : ({0}) loaded", strFilterName);

if (newFilter == null)
{
Log.Info("DirectShowUtil: AddAudioRendererToGraph failed filter: ({0}) not found", strFilterName);
Log.Info("DirectShowUtil: AddAudioRendererToGraph wait 5 secs before trying to adding back audio renderer device");
Thread.Sleep(5000);
Log.Debug("DirectShowUtil: AddAudioRendererToGraph : ({0}) ReloadFilterCollection init", strFilterName);
FilterHelper.ReloadFilterCollection();
Log.Debug("DirectShowUtil: AddAudioRendererToGraph : ({0}) ReloadFilterCollection done", strFilterName);
return AddAudioRenderer(graphBuilder, strFilterName, setAsReferenceClock);
}
Log.Debug("DirectShowUtil: AddAudioRendererToGraph : ({0}) done", strFilterName);
return newFilter;
}
catch (Exception ex)
Expand All @@ -123,18 +128,18 @@ public static IBaseFilter AddAudioRendererToGraph(IGraphBuilder graphBuilder, st
IEnumFilters enumFilters;
HResult hr = new HResult(graphBuilder.EnumFilters(out enumFilters));

Log.Info("DirectShowUtil: Attach volume handler device to audio renderer: " + strFilterName);
if (VolumeHandler.Instance._mixer != null)
Log.Info("DirectShowUtil: AddAudioRenderer - Attach volume handler device to audio renderer: " + strFilterName);
if (OSInfo.OSInfo.Win10OrLater() && VolumeHandler.Instance != null)
{
VolumeHandler.Instance._mixer.ChangeAudioDevice(strFilterName, false);
if (!VolumeHandler.Instance._mixer.DetectedDevice())
VolumeHandler.Instance.ChangeAudioDevice(strFilterName, false);
if (!VolumeHandler.Instance.DetectedDevice())
{
return null;
}
}
GUIGraphicsContext.CurrentAudioRenderer = strFilterName;

Log.Info("DirectShowUtils: First try to insert new audio renderer {0} ", strFilterName);
Log.Info("DirectShowUtil: First try to insert new audio renderer {0} ", strFilterName);

// next add the new one...
foreach (Filter filter in Filters.AudioRenderers)
Expand Down Expand Up @@ -1766,10 +1771,12 @@ public static int RemoveFilter(IGraphBuilder graphBuilder, IBaseFilter filter)

public static void RemoveFilters(IGraphBuilder graphBuilder)
{
RemoveFilters(graphBuilder, String.Empty);

Log.Info("Playback stopped and reverting volume OSD back to default device.");
if (VolumeHandler.Instance._mixer != null) VolumeHandler.Instance._mixer.ChangeAudioDevice(string.Empty, true);
RemoveFilters(graphBuilder, String.Empty);
if (OSInfo.OSInfo.Win10OrLater())
{
Log.Info("Playback stopped and reverting volume OSD back to default device.");
if (VolumeHandler.Instance != null) VolumeHandler.Instance.ChangeAudioDevice(string.Empty, true);
}
GUIGraphicsContext.CurrentAudioRenderer = "";
}

Expand Down
15 changes: 14 additions & 1 deletion mediaportal/Core/DShowNET/Helper/Filters/FilterHelper.cs
Expand Up @@ -22,6 +22,7 @@
using System.Collections;
using System.Runtime.InteropServices.ComTypes;
using DirectShowLib;
using MediaPortal.GUI.Library;

#pragma warning disable 618

Expand Down Expand Up @@ -146,7 +147,19 @@ public static ArrayList GetAudioRenderers()

public static void ReloadFilterCollection()
{
Filters.FilterCollectionReload();
return;
Log.Debug($"FilterHelper: ReloadFilterCollection init");
try
{
Filters.FilterCollectionReload();
Filters.finished.WaitOne(5000);
}
catch (Exception e)
{
Log.Debug($"FilterHelper: {0}", e);
}

Log.Debug($"FilterHelper: ReloadFilterCollection done");
}

public static ArrayList GetDVDNavigators()
Expand Down
36 changes: 25 additions & 11 deletions mediaportal/Core/DShowNET/Helper/Filters/Filters.cs
Expand Up @@ -18,6 +18,9 @@

#endregion

using System.Threading;
using MediaPortal.GUI.Library;

namespace DShowNET.Helper
{
/// <summary>
Expand Down Expand Up @@ -61,19 +64,30 @@ public class Filters
public static FilterCollection BDAReceivers;
public static FilterCollection AllFilters;

public static readonly AutoResetEvent finished = new AutoResetEvent(false);

public static void FilterCollectionReload()
{
VideoInputDevices = new FilterCollection(FilterCategory.VideoInputDevice, true);
AudioInputDevices = new FilterCollection(FilterCategory.AudioInputDevice, true);
VideoCompressors = new FilterCollection(FilterCategory.VideoCompressorCategory, true);
AudioCompressors = new FilterCollection(FilterCategory.AudioCompressorCategory, true);
LegacyFilters = new FilterCollection(FilterCategory.LegacyAmFilterCategory, true);
AudioRenderers = new FilterCollection(FilterCategory.AudioRendererDevice, true);
WDMEncoders = new FilterCollection(FilterCategory.AM_KSEncoder, true);
WDMcrossbars = new FilterCollection(FilterCategory.AM_KSCrossBar, true);
WDMTVTuners = new FilterCollection(FilterCategory.AM_KSTvTuner, true);
BDAReceivers = new FilterCollection(FilterCategory.AM_KS_BDA_RECEIVER_COMPONENT, true);
AllFilters = new FilterCollection(FilterCategory.ActiveMovieCategory, true);
new Thread(() =>
{
Thread.CurrentThread.IsBackground = true;
Thread.CurrentThread.Name = "FilterCollectionReload";
Log.Debug($"Filter: FilterCollectionReload init");
VideoInputDevices = new FilterCollection(FilterCategory.VideoInputDevice, true);
AudioInputDevices = new FilterCollection(FilterCategory.AudioInputDevice, true);
VideoCompressors = new FilterCollection(FilterCategory.VideoCompressorCategory, true);
AudioCompressors = new FilterCollection(FilterCategory.AudioCompressorCategory, true);
LegacyFilters = new FilterCollection(FilterCategory.LegacyAmFilterCategory, true);
AudioRenderers = new FilterCollection(FilterCategory.AudioRendererDevice, true);
WDMEncoders = new FilterCollection(FilterCategory.AM_KSEncoder, true);
WDMcrossbars = new FilterCollection(FilterCategory.AM_KSCrossBar, true);
WDMTVTuners = new FilterCollection(FilterCategory.AM_KSTvTuner, true);
BDAReceivers = new FilterCollection(FilterCategory.AM_KS_BDA_RECEIVER_COMPONENT, true);
AllFilters = new FilterCollection(FilterCategory.ActiveMovieCategory, true);
Log.Debug($"Filter: FilterCollectionReload done");
finished.Set();
}).Start();
}

static Filters()
Expand Down

0 comments on commit 2898c8d

Please sign in to comment.