home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / samples / Multimedia / DirectShow / DMO / DMODemo / appstream.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-08  |  4.8 KB  |  175 lines

  1. //------------------------------------------------------------------------------
  2. // File: AppStream.h
  3. //
  4. // Desc: DirectShow sample code - header file for CAppStream class.
  5. //
  6. // Copyright (c) 2000-2001 Microsoft Corporation.  All rights reserved.
  7. //------------------------------------------------------------------------------
  8.  
  9.  
  10. #ifndef __APPSTREAM_H__
  11. #define __APPSTREAM_H__
  12.  
  13. #define DEMO_NAME           "DMO Demo"
  14. #define SafeGlobalFree(p)    if((p)) GlobalFree((p));  \
  15.                             p = NULL
  16.  
  17. #pragma warning(disable:4100)  // Disable C4100: unreferenced formal parameter
  18.  
  19. ///////////////////////////////////////////////////////////////////////////
  20. // The following definitions come from the Platform SDK and are required if
  21. // the application is being compiled with the headers from Visual C++ 6.0.
  22. ///////////////////////////////////////////////////////////////////////////
  23. #ifndef GetWindowLongPtr
  24.   #define GetWindowLongPtrA   GetWindowLongA
  25.   #define GetWindowLongPtrW   GetWindowLongW
  26.   #ifdef UNICODE
  27.     #define GetWindowLongPtr  GetWindowLongPtrW
  28.   #else
  29.     #define GetWindowLongPtr  GetWindowLongPtrA
  30.   #endif // !UNICODE
  31. #endif // !GetWindowLongPtr
  32.  
  33. #ifndef GWLP_HINSTANCE
  34.   #define GWLP_HINSTANCE      (-6)
  35. #endif
  36. ///////////////////////////////////////////////////////////////////////////
  37. // End Platform SDK definitions
  38. ///////////////////////////////////////////////////////////////////////////
  39.  
  40.  
  41.  
  42. class CMediaBuffer;
  43.  
  44. //
  45. // CAppStream - reads audio data out of a WAV file, transforms the data using 
  46. //              a user specified DMO and then returns the data to the user in 
  47. //              a memory buffer
  48. class CAppStream  
  49. {
  50. public:
  51.     CAppStream();
  52.     ~CAppStream();
  53.  
  54.     HRESULT StreamData( LPTSTR lpszFileInput, 
  55.                         REFGUID rclsid, 
  56.                         HWND hDlg,
  57.                         BYTE **pbOutData, 
  58.                         ULONG *cbDataSize, 
  59.                         LPWAVEFORMATEX *pwfx );
  60.  
  61. private:
  62.     HRESULT Init(LPTSTR lpszFileInput, REFGUID rclsid, HWND hDlg );
  63.     HRESULT Stream( BYTE **pbOutData, ULONG *cbDataSize, LPWAVEFORMATEX *pwfx );
  64.     HRESULT ProcessOutputs( BYTE **pbOutData);
  65.  
  66.     IMediaObject        *m_pObject;
  67.     IMediaObjectInPlace *m_pObjectInPlace;
  68.     ULONG               m_uDataSize;    // Size of input data buffer.
  69.     LPWAVEFORMATEX      m_pwfx;         // pointer to input/output waveformatex structure.
  70.     BYTE*               m_pbInData;     // Pointer input data buffer read from wave file.
  71.     DMO_MEDIA_TYPE      m_mt;
  72. };
  73.  
  74. #pragma warning(disable:4512)   // C4512: assignment operator could not be generated
  75.  
  76. //  CMediaBuffer object
  77. class CMediaBuffer : public IMediaBuffer
  78. {
  79. public:
  80.     CMediaBuffer(DWORD cbMaxLength) :
  81.         m_cRef(0),
  82.         m_cbMaxLength(cbMaxLength),
  83.         m_cbLength(0),
  84.         m_pbData(NULL)
  85.     {
  86.     }
  87.  
  88.     ~CMediaBuffer()
  89.     {
  90.         if (m_pbData) {
  91.             delete [] m_pbData;
  92.         }
  93.     }
  94.  
  95.     STDMETHODIMP QueryInterface(REFIID riid, void **ppv)
  96.     {
  97.         if (ppv == NULL) {
  98.             return E_POINTER;
  99.         }
  100.         if (riid == IID_IMediaBuffer || riid == IID_IUnknown) {
  101.             *ppv = static_cast<IMediaBuffer *>(this);
  102.             AddRef();
  103.             return S_OK;
  104.         }
  105.         *ppv = NULL;
  106.         return E_NOINTERFACE;
  107.     }
  108.  
  109.     STDMETHODIMP_(ULONG) AddRef()
  110.     {
  111.         return InterlockedIncrement(&m_cRef);
  112.     }
  113.  
  114.     STDMETHODIMP_(ULONG) Release()
  115.     {
  116.         LONG lRef = InterlockedDecrement(&m_cRef);
  117.         if (lRef == 0) {
  118.             delete this;
  119.         }
  120.         return lRef;
  121.     }
  122.  
  123.     STDMETHODIMP SetLength(DWORD cbLength)
  124.     {
  125.         if (cbLength > m_cbMaxLength) {
  126.             return E_INVALIDARG;
  127.         } else {
  128.             m_cbLength = cbLength;
  129.             return S_OK;
  130.         }
  131.     }
  132.  
  133.     STDMETHODIMP GetMaxLength(DWORD *pcbMaxLength)
  134.     {
  135.         if (pcbMaxLength == NULL) {
  136.             return E_POINTER;
  137.         }
  138.         *pcbMaxLength = m_cbMaxLength;
  139.         return S_OK;
  140.     }
  141.  
  142.     STDMETHODIMP GetBufferAndLength(BYTE **ppbBuffer, DWORD *pcbLength)
  143.     {
  144.         if (ppbBuffer == NULL || pcbLength == NULL) {
  145.             return E_POINTER;
  146.         }
  147.         *ppbBuffer = m_pbData;
  148.         *pcbLength = m_cbLength;
  149.         return S_OK;
  150.     }
  151.  
  152.     HRESULT Init()
  153.     {
  154.         m_pbData = new BYTE[m_cbMaxLength];
  155.         if (NULL == m_pbData) {
  156.             return E_OUTOFMEMORY;
  157.         } else {
  158.             return S_OK;
  159.         }
  160.     }
  161.  
  162.     DWORD        m_cbLength;
  163.     const DWORD  m_cbMaxLength;
  164.     LONG         m_cRef;
  165.     BYTE         *m_pbData;
  166. };
  167.  
  168. #pragma warning(default:4512)   // C4512: assignment operator could not be generated
  169.  
  170. HRESULT CreateBuffer( DWORD cbMaxLength, CMediaBuffer **ppBuffer );
  171.  
  172.  
  173.  
  174. #endif __APPSTREAM_H__
  175.