forked from thedeemon/gep
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MediaTypeForm.cs
97 lines (89 loc) · 3.09 KB
/
MediaTypeForm.cs
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DirectShowLib;
using System.Reflection;
namespace gep
{
partial class MediaTypeForm : Form
{
ISampleGrabber sampleGrabber;
IAMStreamConfig streamConfig;
public MediaTypeForm(ISampleGrabber sg)
{
sampleGrabber = sg;
InitializeComponent();
}
public MediaTypeForm(IAMStreamConfig isc)//not used anymore
{
streamConfig = isc;
InitializeComponent();
}
private void MediaTypeForm_Load(object sender, EventArgs e)
{
AMMediaType mt = new AMMediaType();
Guid majortype = Guid.Empty, subtype = Guid.Empty;
if (sampleGrabber!=null && sampleGrabber.GetConnectedMediaType(mt)==0)
{
majortype = mt.majorType;
subtype = mt.subType;
DsUtils.FreeAMMediaType(mt);
}
if (streamConfig != null && streamConfig.GetFormat(out mt) == 0)
{
majortype = mt.majorType;
subtype = mt.subType;
DsUtils.FreeAMMediaType(mt);
}
WalkClass(typeof(MediaType), comboMajorType, majortype);
WalkClass(typeof(MediaSubType), comboSubType, subtype);
}
static void WalkClass(Type MyType, ComboBox cb, Guid chosen)
{
string s="";
foreach (FieldInfo m in MyType.GetFields())
{
cb.Items.Add(m.Name);
if ((Guid)m.GetValue(null) == chosen)
s = m.Name;
}
for(int i=0;i<cb.Items.Count;i++)
if (cb.Items[i].ToString() == s)
{
cb.SelectedIndex = i;
break;
}
}
private void OnOK(object sender, EventArgs e)
{
AMMediaType mt = new AMMediaType();
string strMajor = comboMajorType.SelectedItem.ToString();
string strSub = comboSubType.SelectedItem.ToString();
foreach (FieldInfo m in typeof(MediaType).GetFields())
if (m.Name == strMajor)
mt.majorType = (Guid)m.GetValue(null);
foreach (FieldInfo m in typeof(MediaSubType).GetFields())
if (m.Name == strSub)
mt.subType = (Guid)m.GetValue(null);
if (sampleGrabber != null)
sampleGrabber.SetMediaType(mt);
if (streamConfig != null)
streamConfig.SetFormat(mt);
DsUtils.FreeAMMediaType(mt);
Close();
}
private void OnCancel(object sender, EventArgs e)
{
Close();
}
private void MediaTypeForm_FormClosing(object sender, FormClosingEventArgs e)
{
sampleGrabber = null;
streamConfig = null;
}
}
}