-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathDsUtils.cs
2009 lines (1767 loc) · 72.5 KB
/
DsUtils.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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#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.Collections;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Text;
using System.Reflection;
using System.Security;
using DirectShowLib.Dvd;
#if !USING_NET11
using System.Runtime.InteropServices.ComTypes;
#endif
namespace DirectShowLib
{
#region Declarations
/// <summary>
/// Not from DirectShow
/// </summary>
public enum PinConnectedStatus
{
Unconnected,
Connected
}
/// <summary>
/// From BITMAPINFO
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct BitmapInfo
{
public BitmapInfoHeader bmiHeader;
public int[] bmiColors;
}
/// <summary>
/// From BITMAPINFOHEADER
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 2)]
public class BitmapInfoHeader
{
public int Size;
public int Width;
public int Height;
public short Planes;
public short BitCount;
public int Compression;
public int ImageSize;
public int XPelsPerMeter;
public int YPelsPerMeter;
public int ClrUsed;
public int ClrImportant;
}
/// <summary>
/// From DDPIXELFORMAT
/// </summary>
[StructLayout(LayoutKind.Explicit)]
public struct DDPixelFormat
{
[FieldOffset(0)] public int dwSize;
[FieldOffset(4)] public int dwFlags;
[FieldOffset(8)] public int dwFourCC;
[FieldOffset(12)] public int dwRGBBitCount;
[FieldOffset(12)] public int dwYUVBitCount;
[FieldOffset(12)] public int dwZBufferBitDepth;
[FieldOffset(12)] public int dwAlphaBitDepth;
[FieldOffset(16)] public int dwRBitMask;
[FieldOffset(16)] public int dwYBitMask;
[FieldOffset(20)] public int dwGBitMask;
[FieldOffset(20)] public int dwUBitMask;
[FieldOffset(24)] public int dwBBitMask;
[FieldOffset(24)] public int dwVBitMask;
[FieldOffset(28)] public int dwRGBAlphaBitMask;
[FieldOffset(28)] public int dwYUVAlphaBitMask;
[FieldOffset(28)] public int dwRGBZBitMask;
[FieldOffset(28)] public int dwYUVZBitMask;
}
/// <summary>
/// From CAUUID
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct DsCAUUID
{
public int cElems;
public IntPtr pElems;
/// <summary>
/// Perform a manual marshaling of pElems to retrieve an array of System.Guid.
/// Assume this structure has been already filled by the ISpecifyPropertyPages.GetPages() method.
/// </summary>
/// <returns>A managed representation of pElems (cElems items)</returns>
public Guid[] ToGuidArray()
{
Guid[] retval = new Guid[this.cElems];
for (int i = 0; i < this.cElems; i++)
{
IntPtr ptr = new IntPtr(this.pElems.ToInt64() + (Marshal.SizeOf(typeof(Guid)) * i));
retval[i] = (Guid)Marshal.PtrToStructure(ptr, typeof(Guid));
}
return retval;
}
}
/// <summary>
/// DirectShowLib.DsLong is a wrapper class around a <see cref="System.Int64"/> value type.
/// </summary>
/// <remarks>
/// This class is necessary to enable null paramters passing.
/// </remarks>
[StructLayout(LayoutKind.Sequential)]
public class DsLong
{
private long Value;
/// <summary>
/// Constructor
/// Initialize a new instance of DirectShowLib.DsLong with the Value parameter
/// </summary>
/// <param name="Value">Value to assign to this new instance</param>
public DsLong(long Value)
{
this.Value = Value;
}
/// <summary>
/// Get a string representation of this DirectShowLib.DsLong Instance.
/// </summary>
/// <returns>A string representing this instance</returns>
public override string ToString()
{
return this.Value.ToString();
}
public override int GetHashCode()
{
return this.Value.GetHashCode();
}
/// <summary>
/// Define implicit cast between DirectShowLib.DsLong and System.Int64 for languages supporting this feature.
/// VB.Net doesn't support implicit cast. <see cref="DirectShowLib.DsLong.ToInt64"/> for similar functionality.
/// <code>
/// // Define a new DsLong instance
/// DsLong dsL = new DsLong(9876543210);
/// // Do implicit cast between DsLong and Int64
/// long l = dsL;
///
/// Console.WriteLine(l.ToString());
/// </code>
/// </summary>
/// <param name="g">DirectShowLib.DsLong to be cast</param>
/// <returns>A casted System.Int64</returns>
public static implicit operator long(DsLong l)
{
return l.Value;
}
/// <summary>
/// Define implicit cast between System.Int64 and DirectShowLib.DsLong for languages supporting this feature.
/// VB.Net doesn't support implicit cast. <see cref="DirectShowLib.DsGuid.FromInt64"/> for similar functionality.
/// <code>
/// // Define a new Int64 instance
/// long l = 9876543210;
/// // Do implicit cast between Int64 and DsLong
/// DsLong dsl = l;
///
/// Console.WriteLine(dsl.ToString());
/// </code>
/// </summary>
/// <param name="g">System.Int64 to be cast</param>
/// <returns>A casted DirectShowLib.DsLong</returns>
public static implicit operator DsLong(long l)
{
return new DsLong(l);
}
/// <summary>
/// Get the System.Int64 equivalent to this DirectShowLib.DsLong instance.
/// </summary>
/// <returns>A System.Int64</returns>
public long ToInt64()
{
return this.Value;
}
/// <summary>
/// Get a new DirectShowLib.DsLong instance for a given System.Int64
/// </summary>
/// <param name="g">The System.Int64 to wrap into a DirectShowLib.DsLong</param>
/// <returns>A new instance of DirectShowLib.DsLong</returns>
public static DsLong FromInt64(long l)
{
return new DsLong(l);
}
}
/// <summary>
/// DirectShowLib.DsGuid is a wrapper class around a System.Guid value type.
/// </summary>
/// <remarks>
/// This class is necessary to enable null paramters passing.
/// </remarks>
[StructLayout(LayoutKind.Explicit)]
public class DsGuid
{
[FieldOffset(0)]
private Guid guid;
public static readonly DsGuid Empty = Guid.Empty;
/// <summary>
/// Empty constructor.
/// Initialize it with System.Guid.Empty
/// </summary>
public DsGuid()
{
this.guid = Guid.Empty;
}
/// <summary>
/// Constructor.
/// Initialize this instance with a given System.Guid string representation.
/// </summary>
/// <param name="g">A valid System.Guid as string</param>
public DsGuid(string g)
{
this.guid = new Guid(g);
}
/// <summary>
/// Constructor.
/// Initialize this instance with a given System.Guid.
/// </summary>
/// <param name="g">A System.Guid value type</param>
public DsGuid(Guid g)
{
this.guid = g;
}
/// <summary>
/// Get a string representation of this DirectShowLib.DsGuid Instance.
/// </summary>
/// <returns>A string representing this instance</returns>
public override string ToString()
{
return this.guid.ToString();
}
/// <summary>
/// Get a string representation of this DirectShowLib.DsGuid Instance with a specific format.
/// </summary>
/// <param name="format"><see cref="System.Guid.ToString"/> for a description of the format parameter.</param>
/// <returns>A string representing this instance according to the format parameter</returns>
public string ToString(string format)
{
return this.guid.ToString(format);
}
public override int GetHashCode()
{
return this.guid.GetHashCode();
}
/// <summary>
/// Define implicit cast between DirectShowLib.DsGuid and System.Guid for languages supporting this feature.
/// VB.Net doesn't support implicit cast. <see cref="DirectShowLib.DsGuid.ToGuid"/> for similar functionality.
/// <code>
/// // Define a new DsGuid instance
/// DsGuid dsG = new DsGuid("{33D57EBF-7C9D-435e-A15E-D300B52FBD91}");
/// // Do implicit cast between DsGuid and Guid
/// Guid g = dsG;
///
/// Console.WriteLine(g.ToString());
/// </code>
/// </summary>
/// <param name="g">DirectShowLib.DsGuid to be cast</param>
/// <returns>A casted System.Guid</returns>
public static implicit operator Guid(DsGuid g)
{
return g.guid;
}
/// <summary>
/// Define implicit cast between System.Guid and DirectShowLib.DsGuid for languages supporting this feature.
/// VB.Net doesn't support implicit cast. <see cref="DirectShowLib.DsGuid.FromGuid"/> for similar functionality.
/// <code>
/// // Define a new Guid instance
/// Guid g = new Guid("{B9364217-366E-45f8-AA2D-B0ED9E7D932D}");
/// // Do implicit cast between Guid and DsGuid
/// DsGuid dsG = g;
///
/// Console.WriteLine(dsG.ToString());
/// </code>
/// </summary>
/// <param name="g">System.Guid to be cast</param>
/// <returns>A casted DirectShowLib.DsGuid</returns>
public static implicit operator DsGuid(Guid g)
{
return new DsGuid(g);
}
/// <summary>
/// Get the System.Guid equivalent to this DirectShowLib.DsGuid instance.
/// </summary>
/// <returns>A System.Guid</returns>
public Guid ToGuid()
{
return this.guid;
}
/// <summary>
/// Get a new DirectShowLib.DsGuid instance for a given System.Guid
/// </summary>
/// <param name="g">The System.Guid to wrap into a DirectShowLib.DsGuid</param>
/// <returns>A new instance of DirectShowLib.DsGuid</returns>
public static DsGuid FromGuid(Guid g)
{
return new DsGuid(g);
}
}
/// <summary>
/// DirectShowLib.DsInt is a wrapper class around a <see cref="System.Int32"/> value type.
/// </summary>
/// <remarks>
/// This class is necessary to enable null paramters passing.
/// </remarks>
[StructLayout(LayoutKind.Sequential)]
public class DsInt
{
private int Value;
/// <summary>
/// Constructor
/// Initialize a new instance of DirectShowLib.DsInt with the Value parameter
/// </summary>
/// <param name="Value">Value to assign to this new instance</param>
public DsInt(int Value)
{
this.Value = Value;
}
/// <summary>
/// Get a string representation of this DirectShowLib.DsInt Instance.
/// </summary>
/// <returns>A string representing this instance</returns>
public override string ToString()
{
return this.Value.ToString();
}
public override int GetHashCode()
{
return this.Value.GetHashCode();
}
/// <summary>
/// Define implicit cast between DirectShowLib.DsInt and System.Int64 for languages supporting this feature.
/// VB.Net doesn't support implicit cast. <see cref="DirectShowLib.DsInt.ToInt64"/> for similar functionality.
/// <code>
/// // Define a new DsInt instance
/// DsInt dsI = new DsInt(0x12345678);
/// // Do implicit cast between DsInt and Int32
/// int i = dsI;
///
/// Console.WriteLine(i.ToString());
/// </code>
/// </summary>
/// <param name="g">DirectShowLib.DsInt to be cast</param>
/// <returns>A casted System.Int32</returns>
public static implicit operator int(DsInt l)
{
return l.Value;
}
/// <summary>
/// Define implicit cast between System.Int32 and DirectShowLib.DsInt for languages supporting this feature.
/// VB.Net doesn't support implicit cast. <see cref="DirectShowLib.DsGuid.FromInt32"/> for similar functionality.
/// <code>
/// // Define a new Int32 instance
/// int i = 0x12345678;
/// // Do implicit cast between Int64 and DsInt
/// DsInt dsI = i;
///
/// Console.WriteLine(dsI.ToString());
/// </code>
/// </summary>
/// <param name="g">System.Int32 to be cast</param>
/// <returns>A casted DirectShowLib.DsInt</returns>
public static implicit operator DsInt(int l)
{
return new DsInt(l);
}
/// <summary>
/// Get the System.Int32 equivalent to this DirectShowLib.DsInt instance.
/// </summary>
/// <returns>A System.Int32</returns>
public int ToInt32()
{
return this.Value;
}
/// <summary>
/// Get a new DirectShowLib.DsInt instance for a given System.Int32
/// </summary>
/// <param name="g">The System.Int32 to wrap into a DirectShowLib.DsInt</param>
/// <returns>A new instance of DirectShowLib.DsInt</returns>
public static DsInt FromInt32(int l)
{
return new DsInt(l);
}
}
/// <summary>
/// DirectShowLib.DsShort is a wrapper class around a <see cref="System.Int16"/> value type.
/// </summary>
/// <remarks>
/// This class is necessary to enable null paramters passing.
/// </remarks>
[StructLayout(LayoutKind.Sequential)]
public class DsShort
{
private short Value;
/// <summary>
/// Constructor
/// Initialize a new instance of DirectShowLib.DsShort with the Value parameter
/// </summary>
/// <param name="Value">Value to assign to this new instance</param>
public DsShort(short Value)
{
this.Value = Value;
}
/// <summary>
/// Get a string representation of this DirectShowLib.DsShort Instance.
/// </summary>
/// <returns>A string representing this instance</returns>
public override string ToString()
{
return this.Value.ToString();
}
public override int GetHashCode()
{
return this.Value.GetHashCode();
}
/// <summary>
/// Define implicit cast between DirectShowLib.DsShort and System.Int16 for languages supporting this feature.
/// VB.Net doesn't support implicit cast. <see cref="DirectShowLib.DsShort.ToInt64"/> for similar functionality.
/// <code>
/// // Define a new DsShort instance
/// DsShort dsS = new DsShort(0x1234);
/// // Do implicit cast between DsShort and Int16
/// short s = dsS;
///
/// Console.WriteLine(s.ToString());
/// </code>
/// </summary>
/// <param name="g">DirectShowLib.DsShort to be cast</param>
/// <returns>A casted System.Int16</returns>
public static implicit operator short(DsShort l)
{
return l.Value;
}
/// <summary>
/// Define implicit cast between System.Int16 and DirectShowLib.DsShort for languages supporting this feature.
/// VB.Net doesn't support implicit cast. <see cref="DirectShowLib.DsGuid.FromInt16"/> for similar functionality.
/// <code>
/// // Define a new Int16 instance
/// short s = 0x1234;
/// // Do implicit cast between Int64 and DsShort
/// DsShort dsS = s;
///
/// Console.WriteLine(dsS.ToString());
/// </code>
/// </summary>
/// <param name="g">System.Int16 to be cast</param>
/// <returns>A casted DirectShowLib.DsShort</returns>
public static implicit operator DsShort(short l)
{
return new DsShort(l);
}
/// <summary>
/// Get the System.Int16 equivalent to this DirectShowLib.DsShort instance.
/// </summary>
/// <returns>A System.Int16</returns>
public short ToInt16()
{
return this.Value;
}
/// <summary>
/// Get a new DirectShowLib.DsShort instance for a given System.Int64
/// </summary>
/// <param name="g">The System.Int16 to wrap into a DirectShowLib.DsShort</param>
/// <returns>A new instance of DirectShowLib.DsShort</returns>
public static DsShort FromInt16(short l)
{
return new DsShort(l);
}
}
/// <summary>
/// DirectShowLib.DsRect is a managed representation of the Win32 RECT structure.
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public class DsRect
{
public int left;
public int top;
public int right;
public int bottom;
/// <summary>
/// Empty contructor. Initialize all fields to 0
/// </summary>
public DsRect()
{
this.left = 0;
this.top = 0;
this.right = 0;
this.bottom = 0;
}
/// <summary>
/// A parametred constructor. Initialize fields with given values.
/// </summary>
/// <param name="left">the left value</param>
/// <param name="top">the top value</param>
/// <param name="right">the right value</param>
/// <param name="bottom">the bottom value</param>
public DsRect(int left, int top, int right, int bottom)
{
this.left = left;
this.top = top;
this.right = right;
this.bottom = bottom;
}
/// <summary>
/// A parametred constructor. Initialize fields with a given <see cref="System.Drawing.Rectangle"/>.
/// </summary>
/// <param name="rectangle">A <see cref="System.Drawing.Rectangle"/></param>
/// <remarks>
/// Warning, DsRect define a rectangle by defining two of his corners and <see cref="System.Drawing.Rectangle"/> define a rectangle with his upper/left corner, his width and his height.
/// </remarks>
public DsRect(Rectangle rectangle)
{
this.left = rectangle.Left;
this.top = rectangle.Top;
this.right = rectangle.Right;
this.bottom = rectangle.Bottom;
}
/// <summary>
/// Provide de string representation of this DsRect instance
/// </summary>
/// <returns>A string formated like this : [left, top - right, bottom]</returns>
public override string ToString()
{
return string.Format("[{0}, {1} - {2}, {3}]", this.left, this.top, this.right, this.bottom);
}
public override int GetHashCode()
{
return this.left.GetHashCode() |
this.top.GetHashCode() |
this.right.GetHashCode() |
this.bottom.GetHashCode();
}
public override bool Equals(object obj)
{
if (obj is DsRect)
{
DsRect cmp = (DsRect)obj;
return right == cmp.right && bottom == cmp.bottom && left == cmp.left && top == cmp.top;
}
if (obj is Rectangle)
{
Rectangle cmp = (Rectangle)obj;
return right == cmp.Right && bottom == cmp.Bottom && left == cmp.Left && top == cmp.Top;
}
return false;
}
/// <summary>
/// Define implicit cast between DirectShowLib.DsRect and System.Drawing.Rectangle for languages supporting this feature.
/// VB.Net doesn't support implicit cast. <see cref="DirectShowLib.DsRect.ToRectangle"/> for similar functionality.
/// <code>
/// // Define a new Rectangle instance
/// Rectangle r = new Rectangle(0, 0, 100, 100);
/// // Do implicit cast between Rectangle and DsRect
/// DsRect dsR = r;
///
/// Console.WriteLine(dsR.ToString());
/// </code>
/// </summary>
/// <param name="r">a DsRect to be cast</param>
/// <returns>A casted System.Drawing.Rectangle</returns>
public static implicit operator Rectangle(DsRect r)
{
return r.ToRectangle();
}
/// <summary>
/// Define implicit cast between System.Drawing.Rectangle and DirectShowLib.DsRect for languages supporting this feature.
/// VB.Net doesn't support implicit cast. <see cref="DirectShowLib.DsRect.FromRectangle"/> for similar functionality.
/// <code>
/// // Define a new DsRect instance
/// DsRect dsR = new DsRect(0, 0, 100, 100);
/// // Do implicit cast between DsRect and Rectangle
/// Rectangle r = dsR;
///
/// Console.WriteLine(r.ToString());
/// </code>
/// </summary>
/// <param name="r">A System.Drawing.Rectangle to be cast</param>
/// <returns>A casted DsRect</returns>
public static implicit operator DsRect(Rectangle r)
{
return new DsRect(r);
}
/// <summary>
/// Get the System.Drawing.Rectangle equivalent to this DirectShowLib.DsRect instance.
/// </summary>
/// <returns>A System.Drawing.Rectangle</returns>
public Rectangle ToRectangle()
{
return new Rectangle(this.left, this.top, (this.right - this.left), (this.bottom - this.top));
}
/// <summary>
/// Get a new DirectShowLib.DsRect instance for a given <see cref="System.Drawing.Rectangle"/>
/// </summary>
/// <param name="r">The <see cref="System.Drawing.Rectangle"/> used to initialize this new DirectShowLib.DsGuid</param>
/// <returns>A new instance of DirectShowLib.DsGuid</returns>
public static DsRect FromRectangle(Rectangle r)
{
return new DsRect(r);
}
}
[StructLayout(LayoutKind.Sequential)]
public struct NormalizedRect
{
public float left;
public float top;
public float right;
public float bottom;
public NormalizedRect(float l, float t, float r, float b)
{
this.left = l;
this.top = t;
this.right = r;
this.bottom = b;
}
public NormalizedRect(RectangleF r)
{
this.left = r.Left;
this.top = r.Top;
this.right = r.Right;
this.bottom = r.Bottom;
}
public override string ToString()
{
return string.Format("[{0}, {1} - {2}, {3}]", this.left, this.top, this.right, this.bottom);
}
public override int GetHashCode()
{
return this.left.GetHashCode() |
this.top.GetHashCode() |
this.right.GetHashCode() |
this.bottom.GetHashCode();
}
public static implicit operator RectangleF(NormalizedRect r)
{
return r.ToRectangleF();
}
public static implicit operator NormalizedRect(Rectangle r)
{
return new NormalizedRect(r);
}
public static bool operator ==(NormalizedRect r1, NormalizedRect r2)
{
return ((r1.left == r2.left) && (r1.top == r2.top) && (r1.right == r2.right) && (r1.bottom == r2.bottom));
}
public static bool operator !=(NormalizedRect r1, NormalizedRect r2)
{
return ((r1.left != r2.left) || (r1.top != r2.top) || (r1.right != r2.right) || (r1.bottom != r2.bottom));
}
public override bool Equals(object obj)
{
if (!(obj is NormalizedRect))
return false;
NormalizedRect other = (NormalizedRect)obj;
return (this == other);
}
public RectangleF ToRectangleF()
{
return new RectangleF(this.left, this.top, (this.right - this.left), (this.bottom - this.top));
}
public static NormalizedRect FromRectangle(RectangleF r)
{
return new NormalizedRect(r);
}
}
#endregion
#region Utility Classes
static public class DsResults
{
public const int E_InvalidMediaType = unchecked((int)0x80040200);
public const int E_InvalidSubType = unchecked((int)0x80040201);
public const int E_NeedOwner = unchecked((int)0x80040202);
public const int E_EnumOutOfSync = unchecked((int)0x80040203);
public const int E_AlreadyConnected = unchecked((int)0x80040204);
public const int E_FilterActive = unchecked((int)0x80040205);
public const int E_NoTypes = unchecked((int)0x80040206);
public const int E_NoAcceptableTypes = unchecked((int)0x80040207);
public const int E_InvalidDirection = unchecked((int)0x80040208);
public const int E_NotConnected = unchecked((int)0x80040209);
public const int E_NoAllocator = unchecked((int)0x8004020A);
public const int E_RunTimeError = unchecked((int)0x8004020B);
public const int E_BufferNotSet = unchecked((int)0x8004020C);
public const int E_BufferOverflow = unchecked((int)0x8004020D);
public const int E_BadAlign = unchecked((int)0x8004020E);
public const int E_AlreadyCommitted = unchecked((int)0x8004020F);
public const int E_BuffersOutstanding = unchecked((int)0x80040210);
public const int E_NotCommitted = unchecked((int)0x80040211);
public const int E_SizeNotSet = unchecked((int)0x80040212);
public const int E_NoClock = unchecked((int)0x80040213);
public const int E_NoSink = unchecked((int)0x80040214);
public const int E_NoInterface = unchecked((int)0x80040215);
public const int E_NotFound = unchecked((int)0x80040216);
public const int E_CannotConnect = unchecked((int)0x80040217);
public const int E_CannotRender = unchecked((int)0x80040218);
public const int E_ChangingFormat = unchecked((int)0x80040219);
public const int E_NoColorKeySet = unchecked((int)0x8004021A);
public const int E_NotOverlayConnection = unchecked((int)0x8004021B);
public const int E_NotSampleConnection = unchecked((int)0x8004021C);
public const int E_PaletteSet = unchecked((int)0x8004021D);
public const int E_ColorKeySet = unchecked((int)0x8004021E);
public const int E_NoColorKeyFound = unchecked((int)0x8004021F);
public const int E_NoPaletteAvailable = unchecked((int)0x80040220);
public const int E_NoDisplayPalette = unchecked((int)0x80040221);
public const int E_TooManyColors = unchecked((int)0x80040222);
public const int E_StateChanged = unchecked((int)0x80040223);
public const int E_NotStopped = unchecked((int)0x80040224);
public const int E_NotPaused = unchecked((int)0x80040225);
public const int E_NotRunning = unchecked((int)0x80040226);
public const int E_WrongState = unchecked((int)0x80040227);
public const int E_StartTimeAfterEnd = unchecked((int)0x80040228);
public const int E_InvalidRect = unchecked((int)0x80040229);
public const int E_TypeNotAccepted = unchecked((int)0x8004022A);
public const int E_SampleRejected = unchecked((int)0x8004022B);
public const int E_SampleRejectedEOS = unchecked((int)0x8004022C);
public const int E_DuplicateName = unchecked((int)0x8004022D);
public const int S_DuplicateName = unchecked((int)0x0004022D);
public const int E_Timeout = unchecked((int)0x8004022E);
public const int E_InvalidFileFormat = unchecked((int)0x8004022F);
public const int E_EnumOutOfRange = unchecked((int)0x80040230);
public const int E_CircularGraph = unchecked((int)0x80040231);
public const int E_NotAllowedToSave = unchecked((int)0x80040232);
public const int E_TimeAlreadyPassed = unchecked((int)0x80040233);
public const int E_AlreadyCancelled = unchecked((int)0x80040234);
public const int E_CorruptGraphFile = unchecked((int)0x80040235);
public const int E_AdviseAlreadySet = unchecked((int)0x80040236);
public const int S_StateIntermediate = unchecked((int)0x00040237);
public const int E_NoModexAvailable = unchecked((int)0x80040238);
public const int E_NoAdviseSet = unchecked((int)0x80040239);
public const int E_NoFullScreen = unchecked((int)0x8004023A);
public const int E_InFullScreenMode = unchecked((int)0x8004023B);
public const int E_UnknownFileType = unchecked((int)0x80040240);
public const int E_CannotLoadSourceFilter = unchecked((int)0x80040241);
public const int S_PartialRender = unchecked((int)0x00040242);
public const int E_FileTooShort = unchecked((int)0x80040243);
public const int E_InvalidFileVersion = unchecked((int)0x80040244);
public const int S_SomeDataIgnored = unchecked((int)0x00040245);
public const int S_ConnectionsDeferred = unchecked((int)0x00040246);
public const int E_InvalidCLSID = unchecked((int)0x80040247);
public const int E_InvalidMediaType2 = unchecked((int)0x80040248);
public const int E_BabKey = unchecked((int)0x800403F2);
public const int S_NoMoreItems = unchecked((int)0x00040103);
public const int E_SampleTimeNotSet = unchecked((int)0x80040249);
public const int S_ResourceNotNeeded = unchecked((int)0x00040250);
public const int E_MediaTimeNotSet = unchecked((int)0x80040251);
public const int E_NoTimeFormatSet = unchecked((int)0x80040252);
public const int E_MonoAudioHW = unchecked((int)0x80040253);
public const int S_MediaTypeIgnored = unchecked((int)0x00040254);
public const int E_NoDecompressor = unchecked((int)0x80040255);
public const int E_NoAudioHardware = unchecked((int)0x80040256);
public const int S_VideoNotRendered = unchecked((int)0x00040257);
public const int S_AudioNotRendered = unchecked((int)0x00040258);
public const int E_RPZA = unchecked((int)0x80040259);
public const int S_RPZA = unchecked((int)0x0004025A);
public const int E_ProcessorNotSuitable = unchecked((int)0x8004025B);
public const int E_UnsupportedAudio = unchecked((int)0x8004025C);
public const int E_UnsupportedVideo = unchecked((int)0x8004025D);
public const int E_MPEGNotConstrained = unchecked((int)0x8004025E);
public const int E_NotInGraph = unchecked((int)0x8004025F);
public const int S_Estimated = unchecked((int)0x00040260);
public const int E_NoTimeFormat = unchecked((int)0x80040261);
public const int E_ReadOnly = unchecked((int)0x80040262);
public const int S_Reserved = unchecked((int)0x00040263);
public const int E_BufferUnderflow = unchecked((int)0x80040264);
public const int E_UnsupportedStream = unchecked((int)0x80040265);
public const int E_NoTransport = unchecked((int)0x80040266);
public const int S_StreamOff = unchecked((int)0x00040267);
public const int S_CantCue = unchecked((int)0x00040268);
public const int E_BadVideoCD = unchecked((int)0x80040269);
public const int S_NoStopTime = unchecked((int)0x00040270);
public const int E_OutOfVideoMemory = unchecked((int)0x80040271);
public const int E_VPNegotiationFailed = unchecked((int)0x80040272);
public const int E_DDrawCapsNotSuitable = unchecked((int)0x80040273);
public const int E_NoVPHardware = unchecked((int)0x80040274);
public const int E_NoCaptureHardware = unchecked((int)0x80040275);
public const int E_DVDOperationInhibited = unchecked((int)0x80040276);
public const int E_DVDInvalidDomain = unchecked((int)0x80040277);
public const int E_DVDNoButton = unchecked((int)0x80040278);
public const int E_DVDGraphNotReady = unchecked((int)0x80040279);
public const int E_DVDRenderFail = unchecked((int)0x8004027A);
public const int E_DVDDecNotEnough = unchecked((int)0x8004027B);
public const int E_DDrawVersionNotSuitable = unchecked((int)0x8004027C);
public const int E_CopyProtFailed = unchecked((int)0x8004027D);
public const int S_NoPreviewPin = unchecked((int)0x0004027E);
public const int E_TimeExpired = unchecked((int)0x8004027F);
public const int S_DVDNonOneSequential = unchecked((int)0x00040280);
public const int E_DVDWrongSpeed = unchecked((int)0x80040281);
public const int E_DVDMenuDoesNotExist = unchecked((int)0x80040282);
public const int E_DVDCmdCancelled = unchecked((int)0x80040283);
public const int E_DVDStateWrongVersion = unchecked((int)0x80040284);
public const int E_DVDStateCorrupt = unchecked((int)0x80040285);
public const int E_DVDStateWrongDisc = unchecked((int)0x80040286);
public const int E_DVDIncompatibleRegion = unchecked((int)0x80040287);
public const int E_DVDNoAttributes = unchecked((int)0x80040288);
public const int E_DVDNoGoupPGC = unchecked((int)0x80040289);
public const int E_DVDLowParentalLevel = unchecked((int)0x8004028A);
public const int E_DVDNotInKaraokeMode = unchecked((int)0x8004028B);
public const int S_DVDChannelContentsNotAvailable = unchecked((int)0x0004028C);
public const int S_DVDNotAccurate = unchecked((int)0x0004028D);
public const int E_FrameStepUnsupported = unchecked((int)0x8004028E);
public const int E_DVDStreamDisabled = unchecked((int)0x8004028F);
public const int E_DVDTitleUnknown = unchecked((int)0x80040290);
public const int E_DVDInvalidDisc = unchecked((int)0x80040291);
public const int E_DVDNoResumeInformation = unchecked((int)0x80040292);
public const int E_PinAlreadyBlockedOnThisThread = unchecked((int)0x80040293);
public const int E_PinAlreadyBlocked = unchecked((int)0x80040294);
public const int E_CertificationFailure = unchecked((int)0x80040295);
public const int E_VMRNotInMixerMode = unchecked((int)0x80040296);
public const int E_VMRNoApSupplied = unchecked((int)0x80040297);
public const int E_VMRNoDeinterlace_HW = unchecked((int)0x80040298);
public const int E_VMRNoProcAMPHW = unchecked((int)0x80040299);
public const int E_DVDVMR9IncompatibleDec = unchecked((int)0x8004029A);
public const int E_NoCOPPHW = unchecked((int)0x8004029B);
}
static public class DsError
{
[DllImport("quartz.dll", CharSet = CharSet.Unicode, ExactSpelling = true, EntryPoint = "AMGetErrorTextW"),
SuppressUnmanagedCodeSecurity]
public static extern int AMGetErrorText(int hr, StringBuilder buf, int max);
/// <summary>
/// If hr has a "failed" status code (E_*), throw an exception. Note that status
/// messages (S_*) are not considered failure codes. If DirectShow error text
/// is available, it is used to build the exception, otherwise a generic com error
/// is thrown.
/// </summary>
/// <param name="hr">The HRESULT to check</param>
public static void ThrowExceptionForHR(int hr)
{
// If a severe error has occurred
if (hr < 0)
{
string s = GetErrorText(hr);
// If a string is returned, build a com error from it
if (s != null)
{
throw new COMException(s, hr);
}
else
{
// No string, just use standard com error
Marshal.ThrowExceptionForHR(hr);
}
}
}
/// <summary>
/// Returns a string describing a DS error. Works for both error codes
/// (values < 0) and Status codes (values >= 0)
/// </summary>
/// <param name="hr">HRESULT for which to get description</param>
/// <returns>The string, or null if no error text can be found</returns>
public static string GetErrorText(int hr)
{
const int MAX_ERROR_TEXT_LEN = 160;
// Make a buffer to hold the string
StringBuilder buf = new StringBuilder(MAX_ERROR_TEXT_LEN, MAX_ERROR_TEXT_LEN);
// If a string is returned, build a com error from it
if (AMGetErrorText(hr, buf, MAX_ERROR_TEXT_LEN) > 0)
{
return buf.ToString();
}
return null;
}
}
static public class DsUtils
{
/// <summary>
/// Returns the PinCategory of the specified pin. Usually a member of PinCategory. Not all pins have a category.
/// </summary>
/// <param name="pPin"></param>
/// <returns>Guid indicating pin category or Guid.Empty on no category. Usually a member of PinCategory</returns>
public static Guid GetPinCategory(IPin pPin)
{
Guid guidRet = Guid.Empty;
// Memory to hold the returned guid
int iSize = Marshal.SizeOf(typeof(Guid));
IntPtr ipOut = Marshal.AllocCoTaskMem(iSize);
try
{
int hr;
int cbBytes;
Guid g = PropSetID.Pin;
// Get an IKsPropertySet from the pin
IKsPropertySet pKs = pPin as IKsPropertySet;