From f6b2bff75ea02bf2863456dc22df5daea9dda34c Mon Sep 17 00:00:00 2001 From: Sweidan Omar Date: Mon, 17 Jan 2022 12:43:20 +0000 Subject: [PATCH] git-tfs-id: [http://tfs.userrendszerhaz.hu:8080/tfs/DefaultCollection]$/MediaCube;C32751 --- client/DxPlay/LAVInterfaces.cs | 442 ++++++++++++++++++--------------- 1 file changed, 245 insertions(+), 197 deletions(-) diff --git a/client/DxPlay/LAVInterfaces.cs b/client/DxPlay/LAVInterfaces.cs index 86d6937b..3aab20c6 100644 --- a/client/DxPlay/LAVInterfaces.cs +++ b/client/DxPlay/LAVInterfaces.cs @@ -1,4 +1,5 @@ using DirectShowLib; +using NLog; using System; using System.IO; using System.Reflection; @@ -81,7 +82,7 @@ namespace DxPlay { Codec_VCR1, Codec_Snow, Codec_FFV1, - Codec_v210, + Codec_v210//, //Codec_NB // Number of entrys (do not use when dynamically linking) }; @@ -713,6 +714,8 @@ namespace DxPlay { /// public static object threadSync = new object(); + private static readonly Logger logger = LogManager.GetCurrentClassLogger(); + /// /// Gets the IBaseFilter interface for the LAVVideo filter - you must release this when finished using it with Marshal.ReleaseComObject /// @@ -728,69 +731,76 @@ namespace DxPlay { object oSettings = null; IBaseFilter filter = null; string currentDir = Directory.GetCurrentDirectory(); + // we have the filters in the subdirectory 'codecs' of the running app string path = Path.Combine(Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath), subDir); - try { - // we need to be in the filter directory since it will load a bunch - // of other dlls that are there, and they won't resolve otherwise - Directory.SetCurrentDirectory(path); + if (Directory.Exists(path)) { + try { + // we need to be in the filter directory since it will load a bunch + // of other dlls that are there, and they won't resolve otherwise + Directory.SetCurrentDirectory(path); - path = Path.Combine(path, "LAVVideo.ax"); + path = Path.Combine(path, "LAVVideo.ax"); - IntPtr lavVideoDll = LoadLibrary(path); - IntPtr proc = GetProcAddress(lavVideoDll, "DllGetClassObject"); + IntPtr lavVideoDll = LoadLibrary(path); + IntPtr proc = GetProcAddress(lavVideoDll, "DllGetClassObject"); - var getClassObject = (LavVideoDllGetClassObject)Marshal.GetDelegateForFunctionPointer(proc, typeof(LavVideoDllGetClassObject)); + var getClassObject = (LavVideoDllGetClassObject)Marshal.GetDelegateForFunctionPointer(proc, typeof(LavVideoDllGetClassObject)); - int hr = getClassObject(ILAVVIDEO_GUID, IUNKNOWN_GUID, out oFactory); + int hr = getClassObject(ILAVVIDEO_GUID, IUNKNOWN_GUID, out oFactory); - IClassFactory factory = oFactory as IClassFactory; + IClassFactory factory = oFactory as IClassFactory; - if (factory == null) { - if (oFactory != null) Marshal.ReleaseComObject(oFactory); - throw new Exception("Could not QueryInterface for the IClassFactory interface"); - } + if (factory == null) { + if (oFactory != null) Marshal.ReleaseComObject(oFactory); + throw new Exception("Could not QueryInterface for the IClassFactory interface"); + } - Guid baseFilterGUID = typeof(IBaseFilter).GUID; - hr = factory.CreateInstance(null, baseFilterGUID, out oFilter); + Guid baseFilterGUID = typeof(IBaseFilter).GUID; + hr = factory.CreateInstance(null, baseFilterGUID, out oFilter); - filter = oFilter as IBaseFilter; - if (filter == null) { - if (oFilter != null) Marshal.ReleaseComObject(oFilter); - throw new Exception("Could not QueryInterface for the IBaseFilter interface"); - } + filter = oFilter as IBaseFilter; + if (filter == null) { + if (oFilter != null) Marshal.ReleaseComObject(oFilter); + throw new Exception("Could not QueryInterface for the IBaseFilter interface"); + } - Guid videoSettingsGUID = new Guid("{FA40D6E9-4D38-4761-ADD2-71A9EC5FD32F}"); - hr = factory.CreateInstance(null, videoSettingsGUID, out oSettings); + Guid videoSettingsGUID = new Guid("{FA40D6E9-4D38-4761-ADD2-71A9EC5FD32F}"); + hr = factory.CreateInstance(null, videoSettingsGUID, out oSettings); - settings = oSettings as ILAVVideoSettings; - if (filter == null) { - if (oSettings != null) Marshal.ReleaseComObject(oSettings); - throw new Exception("Could not QueryInterface for the ILAVVideoSettings interface"); - } + settings = oSettings as ILAVVideoSettings; + if (filter == null) { + if (oSettings != null) Marshal.ReleaseComObject(oSettings); + throw new Exception("Could not QueryInterface for the ILAVVideoSettings interface"); + } - } - catch { - // if somehting bad happens give back the path since we will rethrow the exception ater cleanup - Directory.SetCurrentDirectory(currentDir); + } + catch { + // if somehting bad happens give back the path since we will rethrow the exception ater cleanup + Directory.SetCurrentDirectory(currentDir); - if (oFactory != null) - Marshal.FinalReleaseComObject(oFactory); + if (oFactory != null) + Marshal.FinalReleaseComObject(oFactory); - if (oFilter != null) - Marshal.FinalReleaseComObject(oFilter); + if (oFilter != null) + Marshal.FinalReleaseComObject(oFilter); - if (oSettings != null) - Marshal.FinalReleaseComObject(oSettings); - } - finally { - // even if nothing bad happens we need to clenup and give back to the original path - Directory.SetCurrentDirectory(currentDir); + if (oSettings != null) + Marshal.FinalReleaseComObject(oSettings); + } + finally { + // even if nothing bad happens we need to clenup and give back to the original path + Directory.SetCurrentDirectory(currentDir); - if (oFactory != null) - Marshal.FinalReleaseComObject(oFactory); + if (oFactory != null) + Marshal.FinalReleaseComObject(oFactory); + } + } + else + { + logger.Debug("Path does not exists: " + path); } return filter; @@ -818,78 +828,91 @@ namespace DxPlay { string currentDir = Directory.GetCurrentDirectory(); // we have the filters in the subdirectory 'codecs' of the running app string path = Path.Combine(Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath), subDir); - - try { - // we need to be in the filter directory since it will load a bunch - // of other dlls that are there, and they won't resolve otherwise - Directory.SetCurrentDirectory(path); - - path = Path.Combine(path, "LAVAudio.ax"); - - IntPtr lavVideoDll = LoadLibrary(path); - IntPtr proc = GetProcAddress(lavVideoDll, "DllGetClassObject"); - - var getClassObject = (LavVideoDllGetClassObject)Marshal.GetDelegateForFunctionPointer(proc, typeof(LavVideoDllGetClassObject)); - - int hr = getClassObject(ILAVAUDIO_GUID, IUNKNOWN_GUID, out oFactory); - - IClassFactory factory = oFactory as IClassFactory; - - if (factory == null) { - if (oFactory != null) Marshal.ReleaseComObject(oFactory); - throw new Exception("Could not QueryInterface for the IClassFactory interface"); + if (Directory.Exists(path)) + { + try + { + // we need to be in the filter directory since it will load a bunch + // of other dlls that are there, and they won't resolve otherwise + Directory.SetCurrentDirectory(path); + + path = Path.Combine(path, "LAVAudio.ax"); + + IntPtr lavVideoDll = LoadLibrary(path); + IntPtr proc = GetProcAddress(lavVideoDll, "DllGetClassObject"); + + var getClassObject = (LavVideoDllGetClassObject)Marshal.GetDelegateForFunctionPointer(proc, typeof(LavVideoDllGetClassObject)); + + int hr = getClassObject(ILAVAUDIO_GUID, IUNKNOWN_GUID, out oFactory); + + IClassFactory factory = oFactory as IClassFactory; + + if (factory == null) + { + if (oFactory != null) Marshal.ReleaseComObject(oFactory); + throw new Exception("Could not QueryInterface for the IClassFactory interface"); + } + + Guid baseFilterGUID = typeof(IBaseFilter).GUID; + hr = factory.CreateInstance(null, baseFilterGUID, out oFilter); + + filter = oFilter as IBaseFilter; + if (filter == null) + { + if (oFilter != null) Marshal.ReleaseComObject(oFilter); + throw new Exception("Could not QueryInterface for the IBaseFilter interface"); + } + + Guid audioSettingsGUID = typeof(ILAVAudioSettings).GUID; + hr = factory.CreateInstance(null, audioSettingsGUID, out oSettings); + + settings = oSettings as ILAVAudioSettings; + if (filter == null) + { + if (oSettings != null) Marshal.ReleaseComObject(oSettings); + throw new Exception("Could not QueryInterface for the ILAVAudioSettings interface"); + } + + Guid audioStatusGUID = typeof(ILAVAudioStatus).GUID; + hr = factory.CreateInstance(null, audioStatusGUID, out oStatus); + + status = oStatus as ILAVAudioStatus; + if (filter == null) + { + if (oStatus != null) Marshal.ReleaseComObject(oStatus); + throw new Exception("Could not QueryInterface for the ILAVAudioStatus interface"); + } } + catch + { + // if somehting bad happens give back the path since we will rethrow the exception ater cleanup + Directory.SetCurrentDirectory(currentDir); - Guid baseFilterGUID = typeof(IBaseFilter).GUID; - hr = factory.CreateInstance(null, baseFilterGUID, out oFilter); + if (oFactory != null) + Marshal.FinalReleaseComObject(oFactory); - filter = oFilter as IBaseFilter; - if (filter == null) { - if (oFilter != null) Marshal.ReleaseComObject(oFilter); - throw new Exception("Could not QueryInterface for the IBaseFilter interface"); - } + if (oFilter != null) + Marshal.FinalReleaseComObject(oFilter); - Guid audioSettingsGUID = typeof(ILAVAudioSettings).GUID; - hr = factory.CreateInstance(null, audioSettingsGUID, out oSettings); + if (oStatus != null) + Marshal.FinalReleaseComObject(oStatus); - settings = oSettings as ILAVAudioSettings; - if (filter == null) { - if (oSettings != null) Marshal.ReleaseComObject(oSettings); - throw new Exception("Could not QueryInterface for the ILAVAudioSettings interface"); + if (oSettings != null) + Marshal.FinalReleaseComObject(oSettings); } + finally + { + // even if nothing bad happens we need to clenup and give back to the original path + Directory.SetCurrentDirectory(currentDir); - Guid audioStatusGUID = typeof(ILAVAudioStatus).GUID; - hr = factory.CreateInstance(null, audioStatusGUID, out oStatus); + if (oFactory != null) + Marshal.FinalReleaseComObject(oFactory); - status = oStatus as ILAVAudioStatus; - if (filter == null) { - if (oStatus != null) Marshal.ReleaseComObject(oStatus); - throw new Exception("Could not QueryInterface for the ILAVAudioStatus interface"); } } - catch { - // if somehting bad happens give back the path since we will rethrow the exception ater cleanup - Directory.SetCurrentDirectory(currentDir); - - if (oFactory != null) - Marshal.FinalReleaseComObject(oFactory); - - if (oFilter != null) - Marshal.FinalReleaseComObject(oFilter); - - if (oStatus != null) - Marshal.FinalReleaseComObject(oStatus); - - if (oSettings != null) - Marshal.FinalReleaseComObject(oSettings); - } - finally { - // even if nothing bad happens we need to clenup and give back to the original path - Directory.SetCurrentDirectory(currentDir); - - if (oFactory != null) - Marshal.FinalReleaseComObject(oFactory); - + else + { + logger.Debug("Path does not exists: " + path); } return filter; @@ -914,68 +937,81 @@ namespace DxPlay { // we have the filters in the subdirectory 'codecs' of the running app string path = Path.Combine(Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath), subDir); MessageBox.Show(path); - try { - // we need to be in the filter directory since it will load a bunch - // of other dlls that are there, and they won't resolve otherwise - Directory.SetCurrentDirectory(path); + if (Directory.Exists(path)) + { + try + { + // we need to be in the filter directory since it will load a bunch + // of other dlls that are there, and they won't resolve otherwise + Directory.SetCurrentDirectory(path); - path = Path.Combine(path, "LAVSplitter.ax"); + path = Path.Combine(path, "LAVSplitter.ax"); - IntPtr lavVideoDll = LoadLibrary(path); - IntPtr proc = GetProcAddress(lavVideoDll, "DllGetClassObject"); + IntPtr lavVideoDll = LoadLibrary(path); + IntPtr proc = GetProcAddress(lavVideoDll, "DllGetClassObject"); - var getClassObject = (LavVideoDllGetClassObject)Marshal.GetDelegateForFunctionPointer(proc, typeof(LavVideoDllGetClassObject)); + var getClassObject = (LavVideoDllGetClassObject)Marshal.GetDelegateForFunctionPointer(proc, typeof(LavVideoDllGetClassObject)); - int hr = getClassObject(ILAVSPLITTERSOURCE_GUID, IUNKNOWN_GUID, out oFactory); + int hr = getClassObject(ILAVSPLITTERSOURCE_GUID, IUNKNOWN_GUID, out oFactory); - IClassFactory factory = oFactory as IClassFactory; + IClassFactory factory = oFactory as IClassFactory; - if (factory == null) { - if (oFactory != null) Marshal.ReleaseComObject(oFactory); - throw new Exception("Could not QueryInterface for the IClassFactory interface"); - } + if (factory == null) + { + if (oFactory != null) Marshal.ReleaseComObject(oFactory); + throw new Exception("Could not QueryInterface for the IClassFactory interface"); + } - Guid baseFilterGUID = typeof(IFileSourceFilter).GUID; - hr = factory.CreateInstance(null, baseFilterGUID, out oFilter); + Guid baseFilterGUID = typeof(IFileSourceFilter).GUID; + hr = factory.CreateInstance(null, baseFilterGUID, out oFilter); - filter = oFilter as IFileSourceFilter; - if (filter == null) { - if (oFilter != null) Marshal.ReleaseComObject(oFilter); - throw new Exception("Could not QueryInterface for the IFileSourceFilter interface"); - } + filter = oFilter as IFileSourceFilter; + if (filter == null) + { + if (oFilter != null) Marshal.ReleaseComObject(oFilter); + throw new Exception("Could not QueryInterface for the IFileSourceFilter interface"); + } - Guid splitterSettingsGUID = typeof(ILAVSplitterSettings).GUID; - hr = factory.CreateInstance(null, splitterSettingsGUID, out oSettings); + Guid splitterSettingsGUID = typeof(ILAVSplitterSettings).GUID; + hr = factory.CreateInstance(null, splitterSettingsGUID, out oSettings); - settings = oSettings as ILAVSplitterSettings; - if (filter == null) { - if (oSettings != null) Marshal.ReleaseComObject(oSettings); - throw new Exception("Could not QueryInterface for the ILAVSplitterSettings interface"); - } + settings = oSettings as ILAVSplitterSettings; + if (filter == null) + { + if (oSettings != null) Marshal.ReleaseComObject(oSettings); + throw new Exception("Could not QueryInterface for the ILAVSplitterSettings interface"); + } - } - catch { - // if somehting bad happens give back the path since we will rethrow the exception ater cleanup - Directory.SetCurrentDirectory(currentDir); + } + catch + { + // if somehting bad happens give back the path since we will rethrow the exception ater cleanup + Directory.SetCurrentDirectory(currentDir); - if (oFactory != null) - Marshal.FinalReleaseComObject(oFactory); + if (oFactory != null) + Marshal.FinalReleaseComObject(oFactory); - if (oFilter != null) - Marshal.FinalReleaseComObject(oFilter); + if (oFilter != null) + Marshal.FinalReleaseComObject(oFilter); - if (oSettings != null) - Marshal.FinalReleaseComObject(oSettings); + if (oSettings != null) + Marshal.FinalReleaseComObject(oSettings); - throw; - } - finally { - // even if nothing bad happens we need to clenup and give back to the original path - Directory.SetCurrentDirectory(currentDir); + throw; + } + finally + { + // even if nothing bad happens we need to clenup and give back to the original path + Directory.SetCurrentDirectory(currentDir); - if (oFactory != null) - Marshal.FinalReleaseComObject(oFactory); + if (oFactory != null) + Marshal.FinalReleaseComObject(oFactory); + } + } + else + { + logger.Debug("Path does not exists: " + path); } return filter; @@ -1000,68 +1036,80 @@ namespace DxPlay { // we have the filters in the subdirectory 'codecs' of the running app string path = Path.Combine(Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath), subDir); - try { - // we need to be in the filter directory since it will load a bunch - // of other dlls that are there, and they won't resolve otherwise - Directory.SetCurrentDirectory(path); + if (Directory.Exists(path)) + { + try + { + // we need to be in the filter directory since it will load a bunch + // of other dlls that are there, and they won't resolve otherwise + Directory.SetCurrentDirectory(path); - path = Path.Combine(path, "LAVSplitter.ax"); + path = Path.Combine(path, "LAVSplitter.ax"); - IntPtr lavVideoDll = LoadLibrary(path); - IntPtr proc = GetProcAddress(lavVideoDll, "DllGetClassObject"); + IntPtr lavVideoDll = LoadLibrary(path); + IntPtr proc = GetProcAddress(lavVideoDll, "DllGetClassObject"); - var getClassObject = (LavVideoDllGetClassObject)Marshal.GetDelegateForFunctionPointer(proc, typeof(LavVideoDllGetClassObject)); + var getClassObject = (LavVideoDllGetClassObject)Marshal.GetDelegateForFunctionPointer(proc, typeof(LavVideoDllGetClassObject)); - int hr = getClassObject(ILAVSPLITTER_GUID, IUNKNOWN_GUID, out oFactory); + int hr = getClassObject(ILAVSPLITTER_GUID, IUNKNOWN_GUID, out oFactory); - IClassFactory factory = oFactory as IClassFactory; + IClassFactory factory = oFactory as IClassFactory; - if (factory == null) { - if (oFactory != null) Marshal.ReleaseComObject(oFactory); - throw new Exception("Could not QueryInterface for the IClassFactory interface"); - } + if (factory == null) + { + if (oFactory != null) Marshal.ReleaseComObject(oFactory); + throw new Exception("Could not QueryInterface for the IClassFactory interface"); + } - Guid baseFilterGUID = typeof(IBaseFilter).GUID; - hr = factory.CreateInstance(null, baseFilterGUID, out oFilter); + Guid baseFilterGUID = typeof(IBaseFilter).GUID; + hr = factory.CreateInstance(null, baseFilterGUID, out oFilter); - filter = oFilter as IBaseFilter; - if (filter == null) { - if (oFilter != null) Marshal.ReleaseComObject(oFilter); - throw new Exception("Could not QueryInterface for the IBaseFilter interface"); - } + filter = oFilter as IBaseFilter; + if (filter == null) + { + if (oFilter != null) Marshal.ReleaseComObject(oFilter); + throw new Exception("Could not QueryInterface for the IBaseFilter interface"); + } - Guid splitterSettingsGUID = typeof(ILAVSplitterSettings).GUID; - hr = factory.CreateInstance(null, splitterSettingsGUID, out oSettings); + Guid splitterSettingsGUID = typeof(ILAVSplitterSettings).GUID; + hr = factory.CreateInstance(null, splitterSettingsGUID, out oSettings); - settings = oSettings as ILAVSplitterSettings; - if (filter == null) { - if (oSettings != null) Marshal.ReleaseComObject(oSettings); - throw new Exception("Could not QueryInterface for the ILAVSplitterSettings interface"); - } + settings = oSettings as ILAVSplitterSettings; + if (filter == null) + { + if (oSettings != null) Marshal.ReleaseComObject(oSettings); + throw new Exception("Could not QueryInterface for the ILAVSplitterSettings interface"); + } - } - catch { - // if somehting bad happens give back the path since we will rethrow the exception ater cleanup - Directory.SetCurrentDirectory(currentDir); + } + catch + { + // if somehting bad happens give back the path since we will rethrow the exception ater cleanup + Directory.SetCurrentDirectory(currentDir); - if (oFactory != null) - Marshal.FinalReleaseComObject(oFactory); + if (oFactory != null) + Marshal.FinalReleaseComObject(oFactory); - if (oFilter != null) - Marshal.FinalReleaseComObject(oFilter); + if (oFilter != null) + Marshal.FinalReleaseComObject(oFilter); - if (oSettings != null) - Marshal.FinalReleaseComObject(oSettings); - } - finally { - // even if nothing bad happens we need to clenup and give back to the original path - Directory.SetCurrentDirectory(currentDir); + if (oSettings != null) + Marshal.FinalReleaseComObject(oSettings); + } + finally + { + // even if nothing bad happens we need to clenup and give back to the original path + Directory.SetCurrentDirectory(currentDir); - if (oFactory != null) - Marshal.FinalReleaseComObject(oFactory); + if (oFactory != null) + Marshal.FinalReleaseComObject(oFactory); + } } - + else { + logger.Debug("Path does not exists: "+path); + } + return filter; } } -- 2.54.0