-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDirectShowHelper.cs
More file actions
71 lines (55 loc) · 2.08 KB
/
Copy pathDirectShowHelper.cs
File metadata and controls
71 lines (55 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// !! // TVFox - https://github.com/FoxCouncil/TVFox
// *.-". // MIT License
// | | // Copyright 2020 The Fox Council
using DirectShowLib;
using System;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
namespace TVFox
{
public static class DirectShowHelper
{
/// <summary>Enumerates all filters of the selected category and returns the IBaseFilter for the filter described in friendlyname</summary>
/// <param name="category">Category of the filter</param>
/// <param name="friendlyname">Friendly name of the filter</param>
/// <returns>IBaseFilter for the device</returns>
public static IBaseFilter CreateFilter(Guid category, string friendlyname)
{
object source = null;
var iid = typeof(IBaseFilter).GUID;
foreach (var device in DsDevice.GetDevicesOfCat(category).Where(device => string.Compare(device.Name, friendlyname, StringComparison.Ordinal) == 0))
{
device.Mon.BindToObject(null, null, ref iid, out source);
break;
}
return (IBaseFilter) source;
}
public static string GetName(this IBaseFilter filter)
{
filter.QueryVendorInfo(out var venderInfo);
return venderInfo;
}
public static IPin GetPin(this IBaseFilter filter, string pinname)
{
var hr = filter.EnumPins(out var epins);
DsError.ThrowExceptionForHR(hr);
var pins = new IPin[1];
while (epins.Next(1, pins, out int _) == 0)
{
pins[0].QueryPinInfo(out var pinfo);
var found = pinfo.name == pinname;
DsUtils.FreePinInfo(pinfo);
if (found)
{
return pins[0];
}
}
return null;
}
public static Point Center(this Rectangle rectangle)
{
return new Point(rectangle.Left + rectangle.Width / 2, rectangle.Top + rectangle.Height / 2);
}
}
}