Tuner.cs
Upload User: wuming6209
Upload Date: 2013-06-06
Package Size: 161k
Code Size: 3k
Category:

Video Capture

Development Platform:

Visual C++

  1. // ------------------------------------------------------------------
  2. // DirectX.Capture
  3. //
  4. // History:
  5. // 2003-Jan-24 BL - created
  6. //
  7. // Copyright (c) 2003 Brian Low
  8. // ------------------------------------------------------------------
  9. using System;
  10. using System.Runtime.InteropServices;
  11. using DShowNET;
  12. namespace DirectX.Capture
  13. {
  14. /// <summary>
  15. ///  Specify the frequency of the TV tuner.
  16. /// </summary>
  17. public enum TunerInputType
  18. {
  19. /// <summary> Cable frequency </summary>
  20. Cable,
  21. /// <summary> Antenna frequency </summary>
  22. Antenna
  23. }
  24. /// <summary>
  25. ///  Control and query a hardware TV Tuner.
  26. /// </summary>
  27. public class Tuner : IDisposable
  28. {
  29. // ---------------- Private Properties ---------------
  30. protected IAMTVTuner tvTuner = null;
  31. // ------------------- Constructors ------------------
  32. /// <summary> Initialize this object with a DirectShow tuner </summary>
  33. public Tuner(IAMTVTuner tuner)
  34. {
  35. tvTuner = tuner;
  36. }
  37. // ---------------- Public Properties ---------------
  38. /// <summary>
  39. ///  Get or set the TV Tuner channel.
  40. /// </summary>
  41. public int Channel
  42. {
  43. get
  44. {
  45. int channel;
  46. int v, a;
  47. int hr = tvTuner.get_Channel( out channel, out v, out a );
  48. if ( hr != 0 ) Marshal.ThrowExceptionForHR( hr );
  49. return( channel );
  50. }
  51. set
  52. {
  53. int hr = tvTuner.put_Channel( value, AMTunerSubChannel.Default, AMTunerSubChannel.Default );
  54. if ( hr != 0 ) Marshal.ThrowExceptionForHR( hr );
  55. }
  56. }
  57. /// <summary>
  58. ///  Get or set the tuner frequency (cable or antenna).
  59. /// </summary>
  60. public TunerInputType InputType
  61. {
  62. get
  63. {
  64. DShowNET.TunerInputType t;
  65. int hr = tvTuner.get_InputType( 0, out t );
  66. if ( hr != 0 ) Marshal.ThrowExceptionForHR( hr );
  67. return( (TunerInputType) t );
  68. }
  69. set
  70. {
  71. DShowNET.TunerInputType t = (DShowNET.TunerInputType) value;
  72. int hr = tvTuner.put_InputType( 0, t );
  73. if ( hr != 0 ) Marshal.ThrowExceptionForHR( hr );
  74. }
  75. }
  76. /// <summary>
  77. ///  Indicates whether a signal is present on the current channel.
  78. ///  If the signal strength cannot be determined, a NotSupportedException
  79. ///  is thrown.
  80. /// </summary>
  81. public bool SignalPresent
  82. {
  83. get
  84. {
  85. AMTunerSignalStrength sig;
  86. int hr = tvTuner.SignalPresent( out sig );
  87. if ( hr != 0 ) Marshal.ThrowExceptionForHR( hr );
  88. if ( sig == AMTunerSignalStrength.NA ) throw new NotSupportedException("Signal strength not available.");
  89. return( sig == AMTunerSignalStrength.SignalPresent );
  90. }
  91. }
  92. // ---------------- Public Methods ---------------
  93. public void Dispose()
  94. {
  95. if ( tvTuner != null )
  96. Marshal.ReleaseComObject( tvTuner ); tvTuner = null;
  97. }
  98. }
  99. }