AudioSource.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. ///  Represents a physical connector or source on an 
  16. ///  audio device. This class is used on filters that
  17. ///  support the IAMAudioInputMixer interface such as 
  18. ///  source cards.
  19. /// </summary>
  20. public class AudioSource : Source
  21. {
  22. // --------------------- Private/Internal properties -------------------------
  23. internal IPin Pin; // audio mixer interface (COM object)
  24. // -------------------- Constructors/Destructors ----------------------
  25. /// <summary> Constructor. This class cannot be created directly. </summary>
  26. internal AudioSource( IPin pin )
  27. {
  28. if ( (pin as IAMAudioInputMixer) == null )
  29. throw new NotSupportedException( "The input pin does not support the IAMAudioInputMixer interface" );
  30. this.Pin = pin;
  31. this.name = getName( pin );
  32. }
  33. // ----------------------- Public properties -------------------------
  34. /// <summary> Enable or disable this source. For audio sources it is 
  35. /// usually possible to enable several sources. When setting Enabled=true,
  36. /// set Enabled=false on all other audio sources. </summary>
  37. public override bool Enabled
  38. {
  39. get 
  40. {
  41. IAMAudioInputMixer mix = (IAMAudioInputMixer) Pin;
  42. bool e;
  43. mix.get_Enable( out e );
  44. return( e );
  45. }
  46. set
  47. {
  48. IAMAudioInputMixer mix = (IAMAudioInputMixer) Pin;
  49. mix.put_Enable( value );
  50. }
  51. }
  52. // --------------------------- Private methods ----------------------------
  53. /// <summary> Retrieve the friendly name of a connectorType. </summary>
  54. private string getName( IPin pin )
  55. {
  56. string s = "Unknown pin";
  57. PinInfo pinInfo = new PinInfo();
  58. // Direction matches, so add pin name to listbox
  59. int hr = pin.QueryPinInfo( out pinInfo);
  60. if ( hr == 0 )
  61. s = pinInfo.name + "";
  62. }
  63. else
  64. Marshal.ThrowExceptionForHR( hr );
  65. // The pininfo structure contains a reference to an IBaseFilter,
  66. // so you must release its reference to prevent resource a leak.
  67. if ( pinInfo.filter != null )
  68. Marshal.ReleaseComObject( pinInfo.filter  );  pinInfo.filter  = null;
  69. return( s );
  70. }
  71. // -------------------- IDisposable -----------------------
  72. /// <summary> Release unmanaged resources. </summary>
  73. public override void Dispose()
  74. {
  75. if ( Pin != null )
  76. Marshal.ReleaseComObject( Pin );
  77. Pin = null;
  78. base.Dispose();
  79. }
  80. }
  81. }