-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathMpeg2Structs.cs
314 lines (271 loc) · 7.8 KB
/
Mpeg2Structs.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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
#region license
/*
DirectShowLib - Provide access to DirectShow interfaces via .NET
Copyright (C) 2007
http://sourceforge.net/projects/directshownet/
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#endregion
using System;
using System.Runtime.InteropServices;
namespace DirectShowLib.BDA
{
#region Declarations
// From Mpeg2Bits.h
/// <summary>
/// From PID_BITS & PID_BITS_MIDL
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 2)]
public struct PidBits
{
public short Bits;
public short Reserved
{
get { return (short)((int)Bits & 0x0007); }
}
public short ProgramId
{
get { return (short)(((int)Bits & 0xfff8) >> 3); }
}
}
/// <summary>
/// From MPEG_HEADER_BITS & MPEG_HEADER_BITS_MIDL
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 2)]
public struct MpegHeaderBits
{
public short Bits;
public short SectionLength
{
get { return (short)((int)Bits & 0x0fff); }
}
public short Reserved
{
get { return (short)(((int)Bits & 0x3000) >> 12); }
}
public short PrivateIndicator
{
get { return (short)(((int)Bits & 0x4000) >> 14); }
}
public short SectionSyntaxIndicator
{
get { return (short)(((int)Bits & 0x8000) >> 15); }
}
}
/// <summary>
/// From MPEG_HEADER_VERSION_BITS & MPEG_HEADER_VERSION_BITS_MIDL
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct MpegHeaderVersionBits
{
public byte Bits;
public byte CurrentNextIndicator
{
get { return (byte)((int)Bits & 0x1); }
}
public byte VersionNumber
{
get { return (byte)(((int)Bits & 0x3e) >> 1); }
}
public byte Reserved
{
get { return (byte)(((int)Bits & 0xc0) >> 6); }
}
}
#if ALLOW_UNTESTED_INTERFACES
/// <summary>
/// From MPEG_CURRENT_NEXT_BIT, MPEG_SECTION_IS_*
/// </summary>
public enum MpegSectionIs
{
Next = 0,
Current = 1
}
/// <summary>
/// From TID_EXTENSION
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 2)]
public struct TidExtension
{
public short wTidExt;
public short wCount;
}
/// <summary>
/// From SECTION
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct Section
{
public short TableId;
public MpegHeaderBits Header;
public byte SectionData; // Must be marshalled manually
}
/// <summary>
/// From LONG_SECTION
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct LongSection
{
public short TableId;
public MpegHeaderBits Header;
public short TableIdExtension;
public MpegHeaderVersionBits Version;
public byte SectionNumber;
public byte LastSectionNumber;
public byte RemainingData; // Must be marshalled manually
}
/// <summary>
/// From DSMCC_SECTION
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct DsmccSection
{
public short TableId;
public MpegHeaderBits Header;
public short TableIdExtension;
public MpegHeaderVersionBits Version;
public byte SectionNumber;
public byte LastSectionNumber;
public byte ProtocolDiscriminator;
public byte DsmccType;
public short MessageId;
public int TransactionId;
public byte Reserved;
public byte AdaptationLength;
public short MessageLength;
public byte RemainingData; // Must be marshalled manually
}
/// <summary>
/// From MPEG_RQST_PACKET
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 4)]
public struct MpegRqstPacket
{
public int dwLength;
[MarshalAs(UnmanagedType.LPStruct)]
public Section pSection;
}
/// <summary>
/// From MPEG_DATE
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct MpegDate
{
public byte Date;
public byte Month;
public short Year;
public DateTime ToDateTime()
{
return new DateTime(this.Year, this.Month, this.Date);
}
}
/// <summary>
/// From MPEG_SERVICE_REQUEST
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public class MpegServiceRequest
{
public MPEGRequestType Type;
public MPEGContext Context;
public short Pid;
public byte TableId;
public MPEG2Filter Filter;
public int Flags;
}
/// <summary>
/// From MPEG_SERVICE_RESPONSE
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 2)]
public class MpegServiceResponse
{
public int IPAddress;
public short Port;
}
/// <summary>
/// From MPEG_STREAM_FILTER
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct MpegStreamFilter
{
public short wPidValue;
public int dwFilterSize;
[MarshalAs(UnmanagedType.Bool)]
public bool fCrcEnabled;
[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.U1, SizeConst = 16)]
public byte[] rgchFilter;
[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.U1, SizeConst = 16)]
public byte[] rgchMask;
}
#endif
/// <summary>
/// From MPEG_DURATION & MPEG_TIME
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct MpegDuration
{
public byte Hours;
public byte Minutes;
public byte Seconds;
public TimeSpan ToTimeSpan()
{
return new TimeSpan(this.Hours, this.Minutes, this.Seconds);
}
}
/// <summary>
/// From MPEG_DATE_AND_TIME
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct MpegDateAndTime
{
//public MpegDate D;
//public MpegTime T;
// Marshaling is faster like that...
public byte Date;
public byte Month;
public short Year;
public byte Hours;
public byte Minutes;
public byte Seconds;
public DateTime ToDateTime()
{
return new DateTime(this.Year, this.Month, this.Date, this.Hours, this.Minutes, this.Seconds);
}
}
/// <summary>
/// From DSMCC_ELEMENT
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public class DsmccElement
{
public short pid;
public byte bComponentTag;
public int dwCarouselId;
public int dwTransactionId;
public DsmccElement pNext;
}
/// <summary>
/// From MPE_ELEMENT
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public class MpeElement
{
public short pid;
public byte bComponentTag;
public MpeElement pNext;
}
#endregion
#region Interfaces
#if ALLOW_UNTESTED_INTERFACES
#endif
#endregion
}