forked from thedeemon/gep
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MediaTypeProps.cs
199 lines (170 loc) · 8.5 KB
/
MediaTypeProps.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
using System;
using System.Collections.Generic;
using DirectShowLib;
using System.ComponentModel;
using System.Reflection;
using System.Runtime.InteropServices;
namespace gep
{
[TypeConverterAttribute(typeof(ExpandableObjectConverter)),
ReadOnlyAttribute(true)]
class MediaTypeProps
{
protected AMMediaType mt;
protected MediaTypeProps(AMMediaType pmt)
{
mt = pmt;
}
public override string ToString()
{
return DsToString.AMMediaTypeToString(mt).Replace('\0', ' ');
}
[ReadOnlyAttribute(true),
DescriptionAttribute("Do all samples have same size?")]
public bool FixedSizeSamples { get { return mt.fixedSizeSamples; } }
//[ReadOnlyAttribute(true),
//DescriptionAttribute("Format")]
//public string Format { get { return "formad"; } }
[ReadOnlyAttribute(true),
DescriptionAttribute("Size of format.")]
public int FormatSize { get { return mt.formatSize; } }
[ReadOnlyAttribute(true),
DescriptionAttribute("Format type guid.")]
public string FormatType { get { return DsToString.MediaFormatTypeToString(mt.formatType); }}
[ReadOnlyAttribute(true),
DescriptionAttribute("Major type.")]
public string MajorType { get { return DsToString.MediaTypeToString(mt.majorType); } }
[ReadOnlyAttribute(true),
DescriptionAttribute("Size of one sample.")]
public int SampleSize { get { return mt.sampleSize; } }
[ReadOnlyAttribute(true),
DescriptionAttribute("Media SubType")]
public string SubType { get { return DsToString.MediaSubTypeToString(mt.subType); } }
[ReadOnlyAttribute(true),
DescriptionAttribute("Media SubType GUID")]
public string SubTypeGUID { get { return Graph.GuidToString(mt.subType); } }
[ReadOnlyAttribute(true),
DescriptionAttribute("Do some samples depend on others?")]
public bool TemporalCompression { get { return mt.temporalCompression; } }
public static MediaTypeProps CreateMTProps(AMMediaType pmt)
{
if (pmt.formatType==DirectShowLib.FormatType.VideoInfo)
return new MTProps<VideoInfoHeader>(pmt, pmt.formatPtr);
if (pmt.formatType == DirectShowLib.FormatType.VideoInfo2)
return new MTProps<VideoInfoHeader2>(pmt, pmt.formatPtr);
if (pmt.formatType == DirectShowLib.FormatType.WaveEx)
return new MTProps<WaveFormatEx>(pmt, pmt.formatPtr);
if (pmt.formatType == DirectShowLib.FormatType.MpegVideo)
return new MTProps<MPEG1VideoInfo>(pmt, pmt.formatPtr);
if (pmt.formatType == DirectShowLib.FormatType.AnalogVideo)
return new MTProps<AnalogVideoInfo>(pmt, pmt.formatPtr);
if (pmt.formatType == DirectShowLib.FormatType.DvInfo)
return new MTProps<DVInfo>(pmt, pmt.formatPtr);
if (pmt.formatType == DirectShowLib.FormatType.Mpeg2Video)
return new MTProps<MPEG2VideoInfo>(pmt, pmt.formatPtr);
//if (pmt.formatType == DirectShowLib.FormatType.None)
// return new MTProps<VideoInfoHeader2>(pmt, pmt.formatPtr); //usual mediatype props
//if (pmt.formatType == DirectShowLib.FormatType.Null)
// return new MTProps<VideoInfoHeader2>(pmt, pmt.formatPtr);
/*if (pmt.formatType == DirectShowLib.FormatType.DolbyAC3) //not described in DX SDK
return new MTProps<VideoInfoHeader2>(pmt, pmt.formatPtr);
if (pmt.formatType == DirectShowLib.FormatType.Mpeg2Audio)
return new MTProps<VideoInfoHeader2>(pmt, pmt.formatPtr);
if (pmt.formatType == DirectShowLib.FormatType.MpegStreams)
return new MTProps<VideoInfoHeader2>(pmt, pmt.formatPtr);
if (pmt.formatType == DirectShowLib.FormatType.WSS525)
return new MTProps<VideoInfoHeader2>(pmt, pmt.formatPtr);*/
return new MediaTypeProps(pmt);
}
/*public virtual IEnumerable<KeyValuePair<string, string>> FormatFields(bool show_zeroes, bool cs_enums)
{
//System.Windows.Forms.MessageBox.Show("FormatFields in base class");
return new List<KeyValuePair<string, string>>(); //empty list
}*/
public delegate void format_fields_del(string fldname, string fldvalue);
public virtual void IterFormatFields(bool cs_enums, format_fields_del del)
{
}
public virtual string FormatClass() { return "?"; }
}//class
[TypeConverterAttribute(typeof(ExpandableObjectConverter)),
ReadOnlyAttribute(true)]
class MTProps<T> : MediaTypeProps
{
T format;
FieldsToPropertiesProxyTypeDescriptor format_ftp;
public MTProps(AMMediaType pmt, IntPtr pFormat)
: base(pmt)
{
format = (T)Marshal.PtrToStructure(pFormat, typeof(T));
format_ftp = new FieldsToPropertiesProxyTypeDescriptor(format);
}
[ReadOnlyAttribute(true),
DescriptionAttribute("Format"),
TypeConverterAttribute(typeof(ExpandableObjectConverter))]
public object Format
{
get { return format_ftp; }
}
public override string ToString()
{
return string.Format("{0} {1} {2} {3} {4} {5} SampleSize={6}",
DsToString.MediaTypeToString(mt.majorType).Replace('\0', ' '),
DsToString.MediaSubTypeToString(mt.subType).Replace('\0', ' '),
DsToString.MediaFormatTypeToString(mt.formatType).Replace('\0', ' '),
format_ftp.ToString(),
(mt.fixedSizeSamples ? "FixedSamples" : "NotFixedSamples"),
(mt.temporalCompression ? "TemporalCompression" : "NotTemporalCompression"),
mt.sampleSize.ToString());
}
public override string FormatClass() { return typeof(T).Name; }
/*public override IEnumerable<KeyValuePair<string, string>> FormatFields(bool show_zeroes, bool cs_enums)
{
List<KeyValuePair<string, string>> fields = new List<KeyValuePair<string, string>>();
DumpFields(format, fields, "", show_zeroes, cs_enums);
return fields;
}*/
//public delegate void format_fields_del(string fldname, string fldvalue);
public override void IterFormatFields(bool cs_enums, format_fields_del del)
{
List<KeyValuePair<string, string>> fields = new List<KeyValuePair<string, string>>();
DumpFields(format, fields, "", false, cs_enums);
foreach (KeyValuePair<string, string> p in fields)
del(p.Key, p.Value);
}
void DumpFields(object o, List<KeyValuePair<string, string>> fields, string prefix, bool show_zeroes, bool cs_enums)
{
foreach (FieldInfo field in o.GetType().GetFields())
{
object val = field.GetValue(o);
if (field.FieldType.IsPrimitive)
{
string s = val.ToString().ToLowerInvariant();
if (show_zeroes || s!="0")
fields.Add(new KeyValuePair<string, string>(prefix + field.Name, s));
}
else
if (field.FieldType.IsEnum)
{
string s = val.ToString();
string str;
if (cs_enums)
{
if (s[0] >= '0' && s[0] <= '9')
str = string.Format("({1}) 0x{0:X}", val, field.FieldType.Name);
else
str = field.FieldType.Name + "." + val.ToString();
}
else
str = string.Format("0x{0:X}", val); // Enum.Format(field.FieldType, val, "X"));
fields.Add(new KeyValuePair<string, string>(prefix + field.Name, str));
}
else
{
fields.Add(new KeyValuePair<string, string>(prefix + field.Name, "new " + field.FieldType.Name + "()"));
DumpFields(val, fields, prefix + field.Name + ".", show_zeroes, cs_enums);
}
}
}
} // end of class
} // end of namespace