DXi.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #ifndef _DXI_H_
  2. #define _DXI_H_
  3. #if _MSC_VER > 1000
  4. #pragma once
  5. #endif // _MSC_VER > 1000
  6. #include <DeferZeroFill.h>
  7. // DirectX automation helper
  8. #include "MediaParams.h"
  9. ////////////////////////////////////////////////////////////////////////////////
  10. struct AudioBuffer
  11. {
  12. long cSamp; // number of samples in the buffer
  13. long lOffset; // offset into the data to process
  14. IMediaSample* pms; // the raw IMediaSample for this buffer
  15. AudioBuffer() : cSamp(0), lOffset(0), pms(NULL) {}
  16. //----------------------------------------------------------------------------
  17. // Get a pointer to the audio samples, zero-filling if necesssary
  18. float* GetPointer()
  19. {
  20. // Get the raw-pointer
  21. BYTE* pb = NULL;
  22. pms->GetPointer( &pb );
  23. // We cannot defer the zero fill any longer!
  24. if (bZero)
  25. {
  26. IDeferZeroFill* pdzf;
  27. if (SUCCEEDED( pms->QueryInterface( IID_IDeferZeroFill, (void**)&pdzf ) ))
  28. {
  29. // IDeferZeroFill will have taken care of the zero-fill for us, by
  30. // virtue of our calling IMediaSample::GetPointer. Nothing more to do.
  31. pdzf->Release();
  32. }
  33. else
  34. {
  35. // No IDeferZeroFill is available. We must zero-fill the hard way.
  36. memset( pb, 0, cSamp * sizeof(float) );
  37. }
  38. bZero = FALSE;
  39. }
  40. return reinterpret_cast<float*>( pb + lOffset );
  41. }
  42. //----------------------------------------------------------------------------
  43. // Allow buffers to be tagged as being all zeroes, without actually filling
  44. // any data until someone asks for the buffer pointer
  45. BOOL GetZerofill() const { return bZero; }
  46. void SetZerofill( BOOL bZerofill )
  47. {
  48. bZero = bZerofill;
  49. IDeferZeroFill* pdzf;
  50. if (SUCCEEDED( pms->QueryInterface( IID_IDeferZeroFill, (void**)&pdzf ) ))
  51. {
  52. pdzf->put_NeedsZerofill( bZero );
  53. pdzf->Release();
  54. }
  55. }
  56. private:
  57. BOOL bZero;
  58. };
  59. ////////////////////////////////////////////////////////////////////////////////
  60. class CDXi : public CCritSec
  61. {
  62. public:
  63. virtual HRESULT Initialize() = 0;
  64. virtual HRESULT IsValidInputFormat( const WAVEFORMATEX* pwfx ) const = 0;
  65. virtual HRESULT IsValidOutputFormat( const WAVEFORMATEX* pwfx ) const = 0;
  66. virtual HRESULT IsValidTransform( const WAVEFORMATEX* pwfxIn, const WAVEFORMATEX* pwfxOut ) const = 0;
  67. virtual HRESULT SuggestOutputFormat( WAVEFORMATEX* pwfx ) const = 0;
  68. virtual const WAVEFORMATEX* GetInputFormat() const { return &m_wfxIn; }
  69. virtual const WAVEFORMATEX* GetOutputFormat() const { return &m_wfxOut; }
  70. virtual HRESULT Process( LONGLONG llSampAudioTimestamp,
  71. AudioBuffer* pbufIn,
  72. AudioBuffer* pbufOut ) = 0;
  73. virtual HRESULT AllocateResources() = 0;
  74. virtual HRESULT FreeResources() = 0;
  75. virtual int PersistGetSize() const = 0;
  76. virtual HRESULT PersistLoad( IStream* pStream ) = 0;
  77. virtual HRESULT PersistSave( IStream* pStream ) = 0;
  78. protected:
  79. WAVEFORMATEX m_wfxIn;
  80. WAVEFORMATEX m_wfxOut;
  81. CMediaParams* m_pMediaParams;
  82. float GetParamValue( DWORD dwParam ) const
  83. {
  84. return m_pMediaParams->GetParamEnvelope( dwParam ).GetCurrentValue();
  85. }
  86. HRESULT GetParamDeltas( DWORD dwParam, double* pdDelta1, double* pdDelta2 ) const
  87. {
  88. return m_pMediaParams->GetParamEnvelope( dwParam ).GetCurrentDeltas( pdDelta1, pdDelta2 );
  89. }
  90. };
  91. ////////////////////////////////////////////////////////////////////////////////
  92. #endif //_DXI_H_