home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Game Programming for Teens / VBGPFT.cdr / DirectX8 / dx8a_sdk.exe / samples / multimedia / directshow / dmo / dmodemo / appstream.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-10-02  |  3.7 KB  |  147 lines

  1. //------------------------------------------------------------------------------
  2. // File: AppStream.h
  3. //
  4. // Desc: DirectShow sample code - header file for CAppStream class.
  5. //
  6. // Copyright (c) 2000, 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. class CMediaBuffer;
  18.  
  19. //
  20. // CAppStream - reads audio data out of a WAV file, transforms the data using 
  21. //              a user specified DMO and then returns the data to the user in 
  22. //              a memory buffer
  23. class CAppStream  
  24. {
  25. public:
  26.     CAppStream();
  27.     ~CAppStream();
  28.  
  29.     HRESULT StreamData( LPTSTR lpszFileInput, 
  30.                         REFGUID rclsid, 
  31.                         HWND hDlg,
  32.                         BYTE **pbOutData, 
  33.                         ULONG *cbDataSize, 
  34.                         LPWAVEFORMATEX *pwfx );
  35.  
  36. private:
  37.     HRESULT Init(LPTSTR lpszFileInput, REFGUID rclsid, HWND hDlg );
  38.     HRESULT Stream( BYTE **pbOutData, ULONG *cbDataSize, LPWAVEFORMATEX *pwfx );
  39.     HRESULT ProcessOutputs( BYTE **pbOutData);
  40.  
  41.     IMediaObject        *m_pObject;
  42.     IMediaObjectInPlace *m_pObjectInPlace;
  43.     ULONG               m_uDataSize;    // Size of input data buffer.
  44.     LPWAVEFORMATEX      m_pwfx;         // pointer to input/output waveformatex structure.
  45.     BYTE*               m_pbInData;     // Pointer input data buffer read from wave file.
  46.     DMO_MEDIA_TYPE      m_mt;
  47. };
  48.  
  49.  
  50. //  CMediaBuffer object
  51. class CMediaBuffer : public IMediaBuffer
  52. {
  53. public:
  54.     CMediaBuffer(DWORD cbMaxLength) :
  55.         m_cRef(0),
  56.         m_cbMaxLength(cbMaxLength),
  57.         m_cbLength(0),
  58.         m_pbData(NULL)
  59.     {
  60.     }
  61.  
  62.     ~CMediaBuffer()
  63.     {
  64.         if (m_pbData) {
  65.             delete [] m_pbData;
  66.         }
  67.     }
  68.  
  69.     STDMETHODIMP QueryInterface(REFIID riid, void **ppv)
  70.     {
  71.         if (ppv == NULL) {
  72.             return E_POINTER;
  73.         }
  74.         if (riid == IID_IMediaBuffer || riid == IID_IUnknown) {
  75.             *ppv = static_cast<IMediaBuffer *>(this);
  76.             AddRef();
  77.             return S_OK;
  78.         }
  79.         *ppv = NULL;
  80.         return E_NOINTERFACE;
  81.     }
  82.  
  83.     STDMETHODIMP_(ULONG) AddRef()
  84.     {
  85.         return InterlockedIncrement(&m_cRef);
  86.     }
  87.  
  88.     STDMETHODIMP_(ULONG) Release()
  89.     {
  90.         LONG lRef = InterlockedDecrement(&m_cRef);
  91.         if (lRef == 0) {
  92.             delete this;
  93.         }
  94.         return lRef;
  95.     }
  96.  
  97.     STDMETHODIMP SetLength(DWORD cbLength)
  98.     {
  99.         if (cbLength > m_cbMaxLength) {
  100.             return E_INVALIDARG;
  101.         } else {
  102.             m_cbLength = cbLength;
  103.             return S_OK;
  104.         }
  105.     }
  106.  
  107.     STDMETHODIMP GetMaxLength(DWORD *pcbMaxLength)
  108.     {
  109.         if (pcbMaxLength == NULL) {
  110.             return E_POINTER;
  111.         }
  112.         *pcbMaxLength = m_cbMaxLength;
  113.         return S_OK;
  114.     }
  115.  
  116.     STDMETHODIMP GetBufferAndLength(BYTE **ppbBuffer, DWORD *pcbLength)
  117.     {
  118.         if (ppbBuffer == NULL || pcbLength == NULL) {
  119.             return E_POINTER;
  120.         }
  121.         *ppbBuffer = m_pbData;
  122.         *pcbLength = m_cbLength;
  123.         return S_OK;
  124.     }
  125.  
  126.     HRESULT Init()
  127.     {
  128.         m_pbData = new BYTE[m_cbMaxLength];
  129.         if (NULL == m_pbData) {
  130.             return E_OUTOFMEMORY;
  131.         } else {
  132.             return S_OK;
  133.         }
  134.     }
  135.  
  136.     DWORD        m_cbLength;
  137.     const DWORD  m_cbMaxLength;
  138.     LONG         m_cRef;
  139.     BYTE         *m_pbData;
  140. };
  141.  
  142. HRESULT CreateBuffer( DWORD cbMaxLength, CMediaBuffer **ppBuffer );
  143.  
  144.  
  145.  
  146. #endif __APPSTREAM_H__
  147.