Skip to content
Permalink
Browse files

MP1-4941: Audio detection code reworked when audio device is removed

  • Loading branch information...
Sebastiii committed Feb 2, 2019
1 parent 3e787a0 commit 2083d715ad1aa5fae4179bd85cb2801885f4dea7
@@ -42,6 +42,7 @@ namespace DShowNET.Helper
public class DirectShowUtil
{
private const int magicConstant = -759872593;
private static object audioLock = new object();

static DirectShowUtil() {}

@@ -198,20 +199,33 @@ public static IBaseFilter AddAudioRendererToGraph(IGraphBuilder graphBuilder, st

//check first if audio renderer exists!
bool bRendererExists = false;
foreach (Filter filter in Filters.AudioRenderers)
lock (audioLock)
{
Log.Debug("DirectShowUtil: List 'check if already exist' AddAudioRendererToGraph filter: {0} to graph for {1}", filter.Name, strFilterName);
if (String.Compare(filter.Name, strFilterName, StringComparison.OrdinalIgnoreCase) == 0)
foreach (Filter filter in Filters.AudioRenderers)
{
try
{
Log.Debug(
"DirectShowUtil: List 'check if already exist' AddAudioRendererToGraph filter: {0} to graph for {1}",
filter.Name, strFilterName);
if (String.Compare(filter.Name, strFilterName, StringComparison.OrdinalIgnoreCase) == 0)
{
bRendererExists = true;
Log.Info("DirectShowUtil: found audio renderer - {0}", filter.Name);
}
}
catch (Exception e)
{

}
}

if (!bRendererExists)
{
bRendererExists = true;
Log.Info("DirectShowUtil: found audio renderer - {0}", filter.Name);
Log.Error("DirectShowUtil: FAILED: audio renderer:{0} doesnt exists", strFilterName);
return null;
}
}
if (!bRendererExists)
{
Log.Error("DirectShowUtil: FAILED: audio renderer:{0} doesnt exists", strFilterName);
return null;
}

// first remove all audio renderers
bool bAllRemoved = false;
@@ -21,6 +21,7 @@
using System;
using System.Collections;
using System.Runtime.InteropServices.ComTypes;
using System.Threading;
using DirectShowLib;
using MediaPortal.GUI.Library;

@@ -147,7 +148,6 @@ public static ArrayList GetAudioRenderers()

public static void ReloadFilterCollection()
{
return;
Log.Debug($"FilterHelper: ReloadFilterCollection init");
try
{
@@ -73,6 +73,7 @@ public static void FilterCollectionReload()
Thread.CurrentThread.IsBackground = true;
Thread.CurrentThread.Name = "FilterCollectionReload";

Thread.Sleep(500);
Log.Debug($"Filter: FilterCollectionReload init");
VideoInputDevices = new FilterCollection(FilterCategory.VideoInputDevice, true);
AudioInputDevices = new FilterCollection(FilterCategory.AudioInputDevice, true);
@@ -515,7 +515,28 @@ private void OnGraphNotify()
hr = mediaEvt.FreeEventParams(code, p1, p2);
if (code == EventCode.Complete || code == EventCode.ErrorAbort)
{
MovieEnded(false);
if (GUIGraphicsContext.VideoRenderer == GUIGraphicsContext.VideoRendererType.madVR)
{
try
{
Log.Debug("AudioPlayerVMR: EventCode.Complete: {0}", Enum.GetName(typeof(EventCode), code));
Log.Debug("AudioPlayerVMR: VMR9Util.g_vmr9.playbackTimer {0}", VMR9Util.g_vmr9.playbackTimer);
if (VMR9Util.g_vmr9.playbackTimer.Second != 0)
{
MovieEnded(false);
}
}
catch (Exception ex)
{
Log.Error("AudioPlayerVMR: OnGraphNotify exception: {0}", ex);
}
}

if (GUIGraphicsContext.VideoRenderer != GUIGraphicsContext.VideoRendererType.madVR)
{
Log.Debug("AudioPlayerVMR EventCode.Complete: {0}", Enum.GetName(typeof(EventCode), code));
MovieEnded(false);
}
}
} while (hr == 0);
}
@@ -2593,11 +2593,30 @@ protected void OnGraphNotify()
break;
case EventCode.ErrorAbort:
Log.Debug("BDPlayer - GraphNotify: Error: {0}", param1);
MovieEnded();
if (GUIGraphicsContext.VideoRenderer == GUIGraphicsContext.VideoRendererType.madVR)
{
try
{
Log.Debug("BDPlayer: VMR9Util.g_vmr9.playbackTimer {0}", VMR9Util.g_vmr9.playbackTimer);
if (VMR9Util.g_vmr9.playbackTimer.Second != 0)
{
MovieEnded();
}
}
catch (Exception ex)
{
Log.Error("BDPlayer: OnGraphNotify exception: {0}", ex);
}
}

if (GUIGraphicsContext.VideoRenderer != GUIGraphicsContext.VideoRendererType.madVR)
{
MovieEnded();
}
break;
default:
break;
}
}
}
}

@@ -1518,8 +1518,30 @@ private void OnGraphNotify()
else */
if (code == EventCode.Complete || code == EventCode.ErrorAbort)
{
//Log.Info("StreamBufferPlayer: event:{0} param1:{1} param2:{2} param1:0x{3:X} param2:0x{4:X}",code.ToString(),p1,p2,p1,p2);
MovieEnded();
if (GUIGraphicsContext.VideoRenderer == GUIGraphicsContext.VideoRendererType.madVR)
{
try
{
Log.Debug("StreamBufferPlayer: EventCode.Complete: {0}", Enum.GetName(typeof(EventCode), code));
Log.Debug("StreamBufferPlayer: VMR9Util.g_vmr9.playbackTimer {0}", VMR9Util.g_vmr9.playbackTimer);
if (VMR9Util.g_vmr9.playbackTimer.Second != 0)
{
//Log.Info("StreamBufferPlayer: event:{0} param1:{1} param2:{2} param1:0x{3:X} param2:0x{4:X}",code.ToString(),p1,p2,p1,p2);
MovieEnded();
}
}
catch (Exception ex)
{
Log.Error("StreamBufferPlayer: OnGraphNotify exception: {0}", ex);
}
}

if (GUIGraphicsContext.VideoRenderer != GUIGraphicsContext.VideoRendererType.madVR)
{
Log.Debug("StreamBufferPlayer.Complete: {0}", Enum.GetName(typeof(EventCode), code));
//Log.Info("StreamBufferPlayer: event:{0} param1:{1} param2:{2} param1:0x{3:X} param2:0x{4:X}",code.ToString(),p1,p2,p1,p2);
MovieEnded();
}
}
//else
//Log.Info("StreamBufferPlayer: event:{0} 0x{1:X} param1:{2} param2:{3} param1:0x{4:X} param2:0x{5:X}",code.ToString(), (int)code,p1,p2,p1,p2);
@@ -2031,17 +2031,48 @@ private void OnGraphNotify()
hr = _mediaEvt.FreeEventParams(code, p1, p2);
if (code == EventCode.Complete || code == EventCode.ErrorAbort)
{
Log.Info("TSReaderPlayer: event:{0} param1:{1} param2:{2} param1:0x{3:X} param2:0x{4:X}", code.ToString(),
p1, p2, p1, p2);
MovieEnded();
if (GUIGraphicsContext.VideoRenderer == GUIGraphicsContext.VideoRendererType.madVR)
{
try
{
Log.Debug("VideoPlayer: EventCode.Complete: {0}", Enum.GetName(typeof(EventCode), code));
Log.Debug("VideoPlayer: VMR9Util.g_vmr9.playbackTimer {0}", VMR9Util.g_vmr9.playbackTimer);
if (VMR9Util.g_vmr9.playbackTimer.Second != 0)
{
Log.Info("TSReaderPlayer: event:{0} param1:{1} param2:{2} param1:0x{3:X} param2:0x{4:X}", code.ToString(),
p1, p2, p1, p2);
MovieEnded();

// Playback was aborted! No sound driver is available!
if (code == EventCode.ErrorAbort && p1 == DSERR_NODRIVER)
{
CloseInterfaces();
ExclusiveMode(false);
_state = PlayState.Ended;
Log.Error("TSReaderPlayer: No sound driver is available!");
}
}
}
catch (Exception ex)
{
Log.Error("TSReaderPlayer: OnGraphNotify exception: {0}", ex);
}
}

// Playback was aborted! No sound driver is available!
if (code == EventCode.ErrorAbort && p1 == DSERR_NODRIVER)
if (GUIGraphicsContext.VideoRenderer != GUIGraphicsContext.VideoRendererType.madVR)
{
CloseInterfaces();
ExclusiveMode(false);
_state = PlayState.Ended;
Log.Error("TSReaderPlayer: No sound driver is available!");
Log.Info("TSReaderPlayer: event:{0} param1:{1} param2:{2} param1:0x{3:X} param2:0x{4:X}", code.ToString(),
p1, p2, p1, p2);
MovieEnded();

// Playback was aborted! No sound driver is available!
if (code == EventCode.ErrorAbort && p1 == DSERR_NODRIVER)
{
CloseInterfaces();
ExclusiveMode(false);
_state = PlayState.Ended;
Log.Error("TSReaderPlayer: No sound driver is available!");
}
}
}
//else
@@ -1286,8 +1286,30 @@ private void OnGraphNotify()
hr = mediaEvt.FreeEventParams(code, p1, p2);
if (code == EventCode.Complete || code == EventCode.ErrorAbort)
{
MovieEnded(false);
return;
if (GUIGraphicsContext.VideoRenderer == GUIGraphicsContext.VideoRendererType.madVR)
{
try
{
Log.Debug("RTSPPlayer: EventCode.Complete: {0}", Enum.GetName(typeof(EventCode), code));
Log.Debug("RTSPPlayer: VMR9Util.g_vmr9.playbackTimer {0}", VMR9Util.g_vmr9.playbackTimer);
if (VMR9Util.g_vmr9.playbackTimer.Second != 0)
{
MovieEnded(false);
return;
}
}
catch (Exception ex)
{
Log.Error("RTSPPlayer: OnGraphNotify exception: {0}", ex);
}
}

if (GUIGraphicsContext.VideoRenderer != GUIGraphicsContext.VideoRendererType.madVR)
{
Log.Debug("RTSPPlayer: EventCode.Complete: {0}", Enum.GetName(typeof(EventCode), code));
MovieEnded(false);
return;
}
}
} while (hr == 0);
}
@@ -30,6 +30,7 @@
using MediaPortal.Configuration;
using MediaPortal.ExtensionMethods;
using MediaPortal.GUI.Library;
using MediaPortal.Player.LAV;
using MediaPortal.Profile;
using MediaPortal.Util;
using Microsoft.DirectX.Direct3D;
@@ -1791,9 +1792,13 @@ public int StartMediaCtrl(IMediaControl mediaCtrl)
{
if (!NoAudioResetCheckBox)
{
ILAVAudioSettings asett = baseFilterLavAudio as ILAVAudioSettings;
asett?.SetAudioDelay(true, 0);
DirectShowUtil.ReleaseComObject(baseFilterLavAudio);
int mAudioDelay = AudioPostEngine.GetInstance().AudioDelay;
if (mAudioDelay == 0)
{
ILAVAudioSettings asett = baseFilterLavAudio as ILAVAudioSettings;
asett?.SetAudioDelay(true, 0);
DirectShowUtil.ReleaseComObject(baseFilterLavAudio);
}
}
}
}
@@ -1834,49 +1839,55 @@ public void Vmr9MediaCtrl(IMediaControl mediaCtrl)
{
try
{
if (mediaCtrl != null)
lock (mediaCtrl)
{
Log.Debug("VMR9: mediaCtrl.Stop() 1");
_isCurrentStopping = true;
int hr;
if (GUIGraphicsContext.VideoRenderer == GUIGraphicsContext.VideoRendererType.madVR)
// Suspending GUIGraphicsContext.State
if (mediaCtrl != null)
{
// Disable Restore Display mode, it is done on C++ side
//RestoreDisplayModeNow();

if (_scene?.WorkerThread != null)
Log.Debug("VMR9: mediaCtrl.Stop() 1");
_isCurrentStopping = true;
int hr;
if (GUIGraphicsContext.VideoRenderer == GUIGraphicsContext.VideoRendererType.madVR)
{
if (_scene.WorkerThread.IsAlive)
// Disable Restore Display mode, it is done on C++ side
//RestoreDisplayModeNow();

if (_scene?.WorkerThread != null)
{
Log.Error("VMR9: Vmr9MediaCtrl madVR Grab thread abort");
_scene.WorkerThread.Abort();
if (_scene.WorkerThread.IsAlive)
{
Log.Error("VMR9: Vmr9MediaCtrl madVR Grab thread abort");
_scene.WorkerThread.Abort();
}
}

hr = mediaCtrl.Stop();
DsError.ThrowExceptionForHR(hr);
Log.Debug("VMR9: Vmr9MediaCtrl MadStopping()");
MadStopping();
//MadDeinit();
}
else
{
hr = mediaCtrl.Stop();
DsError.ThrowExceptionForHR(hr);
}
hr = mediaCtrl.Stop();
DsError.ThrowExceptionForHR(hr);
Log.Debug("VMR9: Vmr9MediaCtrl MadStopping()");
MadStopping();
//MadDeinit();
}
else
{
hr = mediaCtrl.Stop();
DsError.ThrowExceptionForHR(hr);
}
Log.Debug("VMR9: mediaCtrl.Stop() 2");

if (GUIGraphicsContext.InVmr9Render)
{
switch (GUIGraphicsContext.VideoRenderer)
Log.Debug("VMR9: mediaCtrl.Stop() 2");

if (GUIGraphicsContext.InVmr9Render)
{
case GUIGraphicsContext.VideoRendererType.madVR:
GUIGraphicsContext.InVmr9Render = false;
// Disable exclusive mode here to avoid madVR window staying on top
//if (_vmr9Filter != null) MadvrInterface.EnableExclusiveMode(false, _vmr9Filter);
break;
default:
Log.Error("VMR9: {0} in renderer", g_Player.Player.ToString());
break;
switch (GUIGraphicsContext.VideoRenderer)
{
case GUIGraphicsContext.VideoRendererType.madVR:
GUIGraphicsContext.InVmr9Render = false;
// Disable exclusive mode here to avoid madVR window staying on top
//if (_vmr9Filter != null) MadvrInterface.EnableExclusiveMode(false, _vmr9Filter);
break;
default:
Log.Error("VMR9: {0} in renderer", g_Player.Player.ToString());
break;
}
}
}
}
Oops, something went wrong.

0 comments on commit 2083d71

Please sign in to comment.
You can’t perform that action at this time.