202508081600
調整Video
This commit is contained in:
parent
068075c89b
commit
234dc63a15
@ -13,7 +13,7 @@ namespace DualScreenDemo
|
|||||||
private static PrimaryForm primaryForm; // 儲存實例的參考
|
private static PrimaryForm primaryForm; // 儲存實例的參考
|
||||||
public static Room room = new Room();
|
public static Room room = new Room();
|
||||||
|
|
||||||
public static string verSion = "Server V2.8 202508081053";
|
public static string verSion = "Server V2.8 202508081600";
|
||||||
|
|
||||||
[STAThread]
|
[STAThread]
|
||||||
static void Main()
|
static void Main()
|
||||||
|
@ -4,7 +4,7 @@ using System.Runtime.InteropServices;
|
|||||||
|
|
||||||
namespace DualScreenDemo.Services
|
namespace DualScreenDemo.Services
|
||||||
{
|
{
|
||||||
public class MediaService
|
public class MediaService : Video
|
||||||
{
|
{
|
||||||
public IGraphBuilder graphBuilder;
|
public IGraphBuilder graphBuilder;
|
||||||
private IMediaControl mediaControl;
|
private IMediaControl mediaControl;
|
||||||
@ -153,71 +153,6 @@ namespace DualScreenDemo.Services
|
|||||||
videoWindow.put_Visible(OABool.True); // 显示窗口
|
videoWindow.put_Visible(OABool.True); // 显示窗口
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IBaseFilter AddFilterByClsid(IGraphBuilder graphBuilder, string name, Guid clsid)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// 获取 CLSID 对应的类型
|
|
||||||
Type filterType = Type.GetTypeFromCLSID(clsid);
|
|
||||||
//Console.WriteLine($"Attempting to create filter of type: {filterType.FullName}");
|
|
||||||
|
|
||||||
// 创建实例
|
|
||||||
object filterObject = Activator.CreateInstance(filterType);
|
|
||||||
|
|
||||||
// 尝试转换为 IBaseFilter
|
|
||||||
IBaseFilter filter = filterObject as IBaseFilter;
|
|
||||||
|
|
||||||
if (filter == null)
|
|
||||||
{
|
|
||||||
// 如果转换失败,使用 IUnknown 获取并转换为 IBaseFilter
|
|
||||||
IntPtr comObjectPointer = Marshal.GetIUnknownForObject(filterObject);
|
|
||||||
filter = (IBaseFilter)Marshal.GetObjectForIUnknown(comObjectPointer);
|
|
||||||
// Console.WriteLine($"Successfully converted COM object to IBaseFilter via IUnknown.");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Console.WriteLine($"Successfully created IBaseFilter directly.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 添加过滤器到图形构建器
|
|
||||||
int hr = graphBuilder.AddFilter(filter, name);
|
|
||||||
if (hr != 0)
|
|
||||||
{
|
|
||||||
// Console.WriteLine($"Failed to add filter {name} with CLSID {clsid}, HRESULT: {hr}");
|
|
||||||
}
|
|
||||||
|
|
||||||
DsError.ThrowExceptionForHR(hr);
|
|
||||||
// Console.WriteLine($"Successfully added filter {name} with CLSID {clsid}");
|
|
||||||
return filter;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"Exception in AddFilterByClsid: {ex.Message}");
|
|
||||||
throw; // Rethrow the exception to handle it further up the call stack
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private IPin FindPin(IBaseFilter filter, string pinName)
|
|
||||||
{
|
|
||||||
IEnumPins enumPins;
|
|
||||||
IPin[] pins = new IPin[1];
|
|
||||||
|
|
||||||
filter.EnumPins(out enumPins);
|
|
||||||
enumPins.Reset();
|
|
||||||
|
|
||||||
while (enumPins.Next(1, pins, IntPtr.Zero) == 0)
|
|
||||||
{
|
|
||||||
PinInfo pinInfo;
|
|
||||||
pins[0].QueryPinInfo(out pinInfo);
|
|
||||||
Console.WriteLine(pinInfo);
|
|
||||||
|
|
||||||
if (pinInfo.name == pinName)
|
|
||||||
{
|
|
||||||
return pins[0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
public void SetVolume(int volume)
|
public void SetVolume(int volume)
|
||||||
{
|
{
|
||||||
if (audioRenderer != null)
|
if (audioRenderer != null)
|
||||||
@ -358,13 +293,5 @@ namespace DualScreenDemo.Services
|
|||||||
Console.WriteLine(ex.Message);
|
Console.WriteLine(ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void SafeRelease<T>(ref T comObject) where T : class
|
|
||||||
{
|
|
||||||
if (comObject != null)
|
|
||||||
{
|
|
||||||
Marshal.ReleaseComObject(comObject);
|
|
||||||
comObject = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,18 +4,18 @@ using System.Runtime.InteropServices;
|
|||||||
|
|
||||||
namespace DualScreenDemo.Services
|
namespace DualScreenDemo.Services
|
||||||
{
|
{
|
||||||
public class MediaServicePrimary
|
public class MediaServicePrimary : Video
|
||||||
{
|
{
|
||||||
IGraphBuilder graphBuilder;
|
IGraphBuilder graphBuilder;
|
||||||
IBaseFilter sourceFilter;
|
|
||||||
IBaseFilter lavSplitter;
|
IBaseFilter lavSplitter;
|
||||||
IBaseFilter lavVideoDecoder;
|
IBaseFilter lavVideoDecoder;
|
||||||
IBaseFilter videoRenderer;
|
IBaseFilter videoRenderer;
|
||||||
IVideoWindow videoWindow;
|
IVideoWindow videoWindow;
|
||||||
IMediaControl mediaControl;
|
IMediaControl mediaControl;
|
||||||
|
IBaseFilter sourceFilter;
|
||||||
|
|
||||||
|
|
||||||
public MediaServicePrimary(){}
|
public MediaServicePrimary() { }
|
||||||
|
|
||||||
public int Run()
|
public int Run()
|
||||||
{
|
{
|
||||||
@ -122,89 +122,6 @@ namespace DualScreenDemo.Services
|
|||||||
Console.WriteLine("Error initializing graph builder for primary monitor: " + ex.Message);
|
Console.WriteLine("Error initializing graph builder for primary monitor: " + ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private static IBaseFilter AddFilterByClsid(IGraphBuilder graphBuilder, string name, Guid clsid)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// 获取 CLSID 对应的类型
|
|
||||||
Type filterType = Type.GetTypeFromCLSID(clsid);
|
|
||||||
//Console.WriteLine($"Attempting to create filter of type: {filterType.FullName}");
|
|
||||||
|
|
||||||
// 创建实例
|
|
||||||
object filterObject = Activator.CreateInstance(filterType);
|
|
||||||
|
|
||||||
// 尝试转换为 IBaseFilter
|
|
||||||
IBaseFilter filter = filterObject as IBaseFilter;
|
|
||||||
|
|
||||||
if (filter == null)
|
|
||||||
{
|
|
||||||
// 如果转换失败,使用 IUnknown 获取并转换为 IBaseFilter
|
|
||||||
IntPtr comObjectPointer = Marshal.GetIUnknownForObject(filterObject);
|
|
||||||
filter = (IBaseFilter)Marshal.GetObjectForIUnknown(comObjectPointer);
|
|
||||||
// Console.WriteLine($"Successfully converted COM object to IBaseFilter via IUnknown.");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Console.WriteLine($"Successfully created IBaseFilter directly.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 添加过滤器到图形构建器
|
|
||||||
int hr = graphBuilder.AddFilter(filter, name);
|
|
||||||
if (hr != 0)
|
|
||||||
{
|
|
||||||
// Console.WriteLine($"Failed to add filter {name} with CLSID {clsid}, HRESULT: {hr}");
|
|
||||||
}
|
|
||||||
|
|
||||||
DsError.ThrowExceptionForHR(hr);
|
|
||||||
// Console.WriteLine($"Successfully added filter {name} with CLSID {clsid}");
|
|
||||||
return filter;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"Exception in AddFilterByClsid: {ex.Message}");
|
|
||||||
throw; // Rethrow the exception to handle it further up the call stack
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private int ConnectFilters(IGraphBuilder graphBuilder, IBaseFilter sourceFilter, string sourcePinName, IBaseFilter destFilter, string destPinName)
|
|
||||||
{
|
|
||||||
IPin outPin = FindPin(sourceFilter, sourcePinName);
|
|
||||||
IPin inPin = FindPin(destFilter, destPinName);
|
|
||||||
if (outPin == null || inPin == null)
|
|
||||||
{
|
|
||||||
Console.WriteLine(String.Format("Cannot find pins: {0} or {1}", sourcePinName, destPinName));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
int hr = graphBuilder.Connect(outPin, inPin);
|
|
||||||
return hr;
|
|
||||||
}
|
|
||||||
private IPin FindPin(IBaseFilter filter, string pinName)
|
|
||||||
{
|
|
||||||
IEnumPins enumPins;
|
|
||||||
IPin[] pins = new IPin[1];
|
|
||||||
|
|
||||||
filter.EnumPins(out enumPins);
|
|
||||||
enumPins.Reset();
|
|
||||||
|
|
||||||
while (enumPins.Next(1, pins, IntPtr.Zero) == 0)
|
|
||||||
{
|
|
||||||
PinInfo pinInfo;
|
|
||||||
pins[0].QueryPinInfo(out pinInfo);
|
|
||||||
Console.WriteLine(pinInfo);
|
|
||||||
|
|
||||||
if (pinInfo.name == pinName)
|
|
||||||
{
|
|
||||||
return pins[0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
private void SafeRelease<T>(ref T comObject) where T : class
|
|
||||||
{
|
|
||||||
if (comObject != null)
|
|
||||||
{
|
|
||||||
Marshal.ReleaseComObject(comObject);
|
|
||||||
comObject = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
75
Services/Video.cs
Normal file
75
Services/Video.cs
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
using DirectShowLib;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
namespace DualScreenDemo.Services
|
||||||
|
{
|
||||||
|
public class Video
|
||||||
|
{
|
||||||
|
protected IBaseFilter AddFilterByClsid(IGraphBuilder graphBuilder, string name, Guid clsid)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Type filterType = Type.GetTypeFromCLSID(clsid);
|
||||||
|
object filterObject = Activator.CreateInstance(filterType);
|
||||||
|
IBaseFilter filter = filterObject as IBaseFilter;
|
||||||
|
|
||||||
|
if (filter == null)
|
||||||
|
{
|
||||||
|
IntPtr comObjectPointer = Marshal.GetIUnknownForObject(filterObject);
|
||||||
|
filter = (IBaseFilter)Marshal.GetObjectForIUnknown(comObjectPointer);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 添加过滤器到图形构建器
|
||||||
|
int hr = graphBuilder.AddFilter(filter, name);
|
||||||
|
DsError.ThrowExceptionForHR(hr);
|
||||||
|
return filter;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Exception in AddFilterByClsid: {ex.Message}");
|
||||||
|
throw; // Rethrow the exception to handle it further up the call stack
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected int ConnectFilters(IGraphBuilder graphBuilder, IBaseFilter sourceFilter, string sourcePinName, IBaseFilter destFilter, string destPinName)
|
||||||
|
{
|
||||||
|
IPin outPin = FindPin(sourceFilter, sourcePinName);
|
||||||
|
IPin inPin = FindPin(destFilter, destPinName);
|
||||||
|
if (outPin == null || inPin == null)
|
||||||
|
{
|
||||||
|
Console.WriteLine(String.Format("Cannot find pins: {0} or {1}", sourcePinName, destPinName));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
int hr = graphBuilder.Connect(outPin, inPin);
|
||||||
|
return hr;
|
||||||
|
}
|
||||||
|
protected IPin FindPin(IBaseFilter filter, string pinName)
|
||||||
|
{
|
||||||
|
IEnumPins enumPins;
|
||||||
|
IPin[] pins = new IPin[1];
|
||||||
|
|
||||||
|
filter.EnumPins(out enumPins);
|
||||||
|
enumPins.Reset();
|
||||||
|
|
||||||
|
while (enumPins.Next(1, pins, IntPtr.Zero) == 0)
|
||||||
|
{
|
||||||
|
PinInfo pinInfo;
|
||||||
|
pins[0].QueryPinInfo(out pinInfo);
|
||||||
|
Console.WriteLine(pinInfo);
|
||||||
|
|
||||||
|
if (pinInfo.name == pinName)
|
||||||
|
{
|
||||||
|
return pins[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
protected void SafeRelease<T>(ref T comObject) where T : class
|
||||||
|
{
|
||||||
|
if (comObject != null)
|
||||||
|
{
|
||||||
|
Marshal.ReleaseComObject(comObject);
|
||||||
|
comObject = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user