home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / mac / SiteBldr / AMOVIE / SDK / _SETUP / COMMON.Z / source.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-01  |  5.4 KB  |  163 lines

  1. //==========================================================================;
  2. //
  3. //  THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  4. //  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  5. //  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  6. //  PURPOSE.
  7. //
  8. //  Copyright (c) 1992 - 1996  Microsoft Corporation.  All Rights Reserved.
  9. //
  10. //--------------------------------------------------------------------------;
  11.  
  12. // Classes to simplify creation of ActiveX source filters that support
  13. // continuous generation of data. It provides no support for IMediaControl
  14. // or IMediaPosition
  15. //
  16. // Derive your source filter from CSource.
  17. // During construction either:
  18. //    Create some CSourceStream objects to manage your pins
  19. //    Provide the user with a means of doing so eg, an IPersistFile interface.
  20. //
  21. // CSource provides:
  22. //    IFilter interface management
  23. //    IMediaFilter interface management, via CBaseFilter
  24. //    Pin counting for CBaseFilter
  25. //
  26. // Derive a class from CSourceStream to manage your output pin types
  27. //  Implement GetMediaType/1 to return the type you support. If you support multiple
  28. //   types then overide GetMediaType/3, CheckMediaType and GetMediaTypeCount.
  29. //  Implement Fillbuffer() to put data into one buffer.
  30. //
  31. // CSourceStream provides:
  32. //    IPin management via CBaseOutputPin
  33. //    Worker thread management
  34.  
  35. #ifndef __CSOURCE__
  36. #define __CSOURCE__
  37.  
  38. class CSourceStream;  // The class that will handle each pin
  39.  
  40.  
  41. //
  42. // CSource
  43. //
  44. // Override construction to provide a means of creating
  45. // CSourceStream derived objects - ie a way of creating pins.
  46. class CSource : public CBaseFilter {
  47. public:
  48.  
  49.     CSource(TCHAR *pName, LPUNKNOWN lpunk, CLSID clsid, HRESULT *phr);
  50.     ~CSource();
  51.  
  52.     int       GetPinCount(void);
  53.     CBasePin *GetPin(int n);
  54.  
  55.     STDMETHODIMP FindPin(LPCWSTR Id, IPin **ppPin);
  56.  
  57.     int FindPinNumber(IPin *iPin);
  58.  
  59.     // -- Utilities --
  60.  
  61.     CCritSec*    pStateLock(void) { return &m_cStateLock; }    // provide our critical section
  62.  
  63.     HRESULT     AddPin(CSourceStream *);
  64.     HRESULT     RemovePin(CSourceStream *);
  65.  
  66. protected:
  67.  
  68.     int             m_iPins;       // The number of pins on this filter. Updated by CSourceStream
  69.                           // constructors & destructors.
  70.     CSourceStream **m_paStreams;   // the pins on this filter.
  71.  
  72.     CCritSec m_cStateLock;    // Lock this to serialize function accesses to the filter state
  73.  
  74. };
  75.  
  76.  
  77. //
  78. // CSourceStream
  79. //
  80. // Use this class to manage a stream of data that comes from a
  81. // pin.
  82. // Uses a worker thread to put data on the pin.
  83. class CSourceStream : public CThread, public CBaseOutputPin {
  84. public:
  85.  
  86.     CSourceStream(TCHAR *pObjectName,
  87.                   HRESULT *phr,
  88.                   CSource *pms,
  89.                   LPCWSTR pName);
  90.  
  91.     virtual ~CSourceStream(void);  // virtual destructor ensures derived class destructors are called too.
  92.  
  93. protected:
  94.  
  95.     CSource *m_pFilter;    // The parent of this stream
  96.  
  97.     // should it be a STDMETHODIMP???
  98.     STDMETHODIMP QueryId(LPWSTR *Id);
  99.  
  100.     // *
  101.     // * Data Source
  102.     // *
  103.     // * The following three functions: FillBuffer, OnThreadCreate/Destroy, are
  104.     // * called from within the ThreadProc. They are used in the creation of
  105.     // * the media samples this pin will provide
  106.     // *
  107.  
  108.     // Override this to provide the worker thread a means
  109.     // of processing a buffer
  110.     virtual HRESULT FillBuffer(IMediaSample *pSamp) PURE;
  111.  
  112.     // Called as the thread is created/destroyed - use to perform
  113.     // jobs such as start/stop streaming mode
  114.     // If OnThreadCreate returns an error the thread will exit.
  115.     virtual HRESULT OnThreadCreate(void) {return NOERROR;};
  116.     virtual HRESULT OnThreadDestroy(void) {return NOERROR;};
  117.     virtual HRESULT OnThreadStartPlay(void) {return NOERROR;};
  118.  
  119.     // *
  120.     // * Worker Thread
  121.     // *
  122.  
  123.     HRESULT Active(void);    // Starts up the worker thread
  124.     HRESULT Inactive(void);  // Exits the worker thread.
  125.  
  126. public:
  127.     // thread commands
  128.     enum Command {CMD_INIT, CMD_PAUSE, CMD_RUN, CMD_STOP, CMD_EXIT};
  129.     HRESULT Init(void) { return CallWorker(CMD_INIT); }
  130.     HRESULT Exit(void) { return CallWorker(CMD_EXIT); }
  131.     HRESULT Run(void) { return CallWorker(CMD_RUN); }
  132.     HRESULT Pause(void) { return CallWorker(CMD_PAUSE); }
  133.     HRESULT Stop(void) { return CallWorker(CMD_STOP); }
  134.  
  135. protected:
  136.     Command GetRequest(void) { return (Command) CThread::GetRequest(); }
  137.     BOOL    CheckRequest(Command *pCom) { return CThread::CheckRequest( (DWORD *) pCom); }
  138.  
  139.     // override these if you want to add thread commands
  140.     virtual DWORD ThreadProc(void);          // the thread function
  141.  
  142.     virtual HRESULT DoBufferProcessingLoop(void);    // the loop executed whilst running
  143.  
  144.  
  145.     // *
  146.     // * AM_MEDIA_TYPE support
  147.     // *
  148.  
  149.     // If you support more than one media type then override these 2 functions
  150.     virtual HRESULT CheckMediaType(const CMediaType *pMediaType);
  151.     virtual HRESULT GetMediaType(int iPosition, CMediaType *pMediaType);  // List pos. 0-n
  152.  
  153.     // If you support only one type then override this fn.
  154.     // This will only be called by the default implementations
  155.     // of CheckMediaType and GetMediaType(int, CMediaType*)
  156.     // You must override this fn. or the above 2!
  157.     virtual HRESULT GetMediaType(CMediaType *pMediaType) {return E_UNEXPECTED;}
  158.  
  159. };
  160.  
  161. #endif // __CSOURCE__
  162.  
  163.