home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / mac / SiteBldr / AMOVIE / SDK / _SETUP / COMMON.Z / scope.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-17  |  9.0 KB  |  275 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. /*  Oscilloscope */
  13.  
  14.  
  15. // {35919F40-E904-11ce-8A03-00AA006ECB65}
  16. DEFINE_GUID(CLSID_Scope,
  17. 0x35919f40, 0xe904, 0x11ce, 0x8a, 0x3, 0x0, 0xaa, 0x0, 0x6e, 0xcb, 0x65);
  18.  
  19.  
  20. class CScopeFilter;
  21. class CScopeWindow;
  22.  
  23. /* Class supporting the renderer input pin */
  24.  
  25. //
  26. // This pin is still a separate object in case it wants to have a distinct
  27. // IDispatch....
  28. //
  29. class CScopeInputPin : public CBaseInputPin
  30. {
  31.     friend class CScopeFilter;
  32.     friend class CScopeWindow;
  33.  
  34. private:
  35.  
  36.     CScopeFilter *m_pFilter;         // The renderer that owns us
  37.  
  38. public:
  39.  
  40.     CScopeInputPin(
  41.         CScopeFilter *pTextOutFilter,
  42.         HRESULT *phr,
  43.         LPCWSTR pPinName);
  44.  
  45.     ~CScopeInputPin();
  46.  
  47.     /* Lets us know where a connection ends */
  48.     HRESULT BreakConnect();
  49.  
  50.     /* Check that we can support this input type */
  51.     HRESULT CheckMediaType(const CMediaType *pmt);
  52.  
  53.     /* Actually set the current format */
  54.     HRESULT SetMediaType(const CMediaType *pmt);
  55.  
  56.     /* IMemInputPin virtual methods */
  57.  
  58.     // override so we can show and hide the window
  59.     HRESULT Active(void);
  60.     HRESULT Inactive(void);
  61.  
  62.     /* Here's the next block of data from the stream.
  63.        AddRef it if you are going to hold onto it. */
  64.     STDMETHODIMP Receive(IMediaSample *pSample);
  65.  
  66. };
  67.  
  68.  
  69. /* This class looks after the management of a window. When the class gets
  70.    instantiated the constructor spawns off a worker thread that does all
  71.    the window work. The original thread waits until it is signaled to
  72.    continue. The worker thread first registers the window class if it
  73.    is not already done. Then it creates a window and sets it's size to
  74.    a default iWidth by iHeight dimensions. The worker thread MUST be the
  75.    one who creates the window as it is the one who calls GetMessage. When
  76.    it has done all this it signals the original thread which lets it
  77.    continue, this ensures a window is created and valid before the
  78.    constructor returns. The thread start address is the WindowMessageLoop
  79.    function. This takes as it's initialisation parameter a pointer to the
  80.    CVideoWindow object that created it, the function also initialises it's
  81.    window related member variables such as the handle and device contexts */
  82.  
  83. /* These are the video window styles */
  84.  
  85. const DWORD dwTEXTSTYLES = (WS_POPUP | WS_CAPTION | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CLIPCHILDREN);
  86. const DWORD dwCLASSSTYLES = (CS_HREDRAW | CS_VREDRAW | CS_BYTEALIGNCLIENT | CS_OWNDC);
  87. const LPTSTR RENDERCLASS = TEXT("OscilloscopeWindowClass");
  88. const LPTSTR TITLE = TEXT("Oscilloscope");
  89.  
  90. const int iWIDTH = 320;          /* Initial window width */
  91. const int iHEIGHT = 240;         /* Initial window height */
  92.  
  93. class CScopeWindow : public CCritSec
  94. {
  95.     friend class CScopeInputPin;
  96.     friend class CScopeFilter;
  97. private:
  98.  
  99.     HINSTANCE m_hInstance;          // Global module instance handle
  100.     CScopeFilter *m_pRenderer;      // The owning renderer object
  101.     HWND m_hwndDlg;                 // Handle for our dialog
  102.     HWND m_hwnd;                    // Handle for the graph window
  103.     HBRUSH m_hBrushBackground;
  104.     HPEN m_hPen1;
  105.     HPEN m_hPen2;
  106.     HPEN m_hPenTicks;
  107.     HBITMAP m_hBitmap;
  108.     HANDLE m_hThread;               // Our worker thread
  109.     DWORD m_ThreadID;               // Worker thread ID
  110.     CAMEvent m_SyncWorker;            // Synchronise with worker thread
  111.     CAMEvent m_RenderEvent;           // Signals sample to render
  112.     LONG m_Width;                   // Client window width
  113.     LONG m_Height;                  // Client window height
  114.     BOOL m_bActivated;              // Has the window been activated
  115.     CRefTime m_StartSample;         // Most recent sample start time
  116.     CRefTime m_EndSample;           // And it's associated end time
  117.     BOOL m_bStreaming;              // Are we currently streaming
  118.     POINT *m_pPoints1;              // Array of points to graph Channel1
  119.     POINT *m_pPoints2;              // Array of points to graph Channel2
  120.     int m_nPoints;                  // Size of m_pPoints[1|2]
  121.     int m_nIndex;                   // Index of last sample written
  122.     int m_LastMediaSampleSize;      // Size of last MediaSample
  123.  
  124.     int m_nChannels;                // number of active channels
  125.     int m_nSamplesPerSec;           // SamplesPerSec
  126.     int m_nBitsPerSample;
  127.     int m_nBlockAlign;
  128.     int m_MaxValue;                 // Max Value of the POINTS array
  129.  
  130.     int m_LGain;                    // Left channel control settings
  131.     int m_LOffset;
  132.  
  133.     int m_RGain;                    // Right channel control settings
  134.     int m_ROffset;
  135.  
  136.     int m_nTimebase;                // Timebase settings
  137.     BOOL m_fFreeze;
  138.     int m_TBScroll;
  139.  
  140.     HWND m_hwndLGain;               // Left channel controls
  141.     HWND m_hwndLOffset;
  142.     HWND m_hwndLGainText;
  143.     HWND m_hwndLTitle;
  144.  
  145.     HWND m_hwndRGain;               // Right channel controls
  146.     HWND m_hwndROffset;
  147.     HWND m_hwndRGainText;
  148.     HWND m_hwndRTitle;
  149.  
  150.     HWND m_hwndTimebase;            // Timebase controls
  151.     HWND m_hwndFreeze;
  152.     HWND m_hwndTBScroll;
  153.     HWND m_hwndTBStart;
  154.     HWND m_hwndTBEnd;
  155.     HWND m_hwndTBDelta;
  156.  
  157.     BOOL m_fTriggerPosZeroCrossing;
  158.  
  159.     /* These create and manage a video window on a separate thread */
  160.  
  161.     HRESULT UninitialiseWindow();
  162.     HRESULT InitialiseWindow(HWND hwnd);
  163.     HRESULT MessageLoop();
  164.  
  165.     static DWORD __stdcall WindowMessageLoop(LPVOID lpvThreadParm);
  166.  
  167.     /* Maps windows message loop into C++ virtual methods */
  168.     friend LRESULT CALLBACK WndProc(HWND hwnd,      // Window handle
  169.                                     UINT uMsg,      // Message ID
  170.                                     WPARAM wParam,  // First parameter
  171.                                     LPARAM lParam); // Other parameter
  172.  
  173.     /* Called when we start and stop streaming */
  174.     HRESULT ResetStreamingTimes();
  175.  
  176.     /* Window message handlers */
  177.     BOOL OnClose();
  178.     BOOL OnPaint();
  179.     BOOL OnSize(LONG Width, LONG Height);
  180.  
  181.     /* Draw the waveform */
  182.     void ClearWindow(HDC hdc);
  183.     BOOL AllocWaveBuffers(void);
  184.     void SearchForPosZeroCrossing(int StartPoint, int * IndexEdge);
  185.     void CopyWaveform(IMediaSample *pMediaSample);
  186.     void DrawPartialWaveform(HDC hdc,
  187.             int IndexStart, int IndexEnd,
  188.             int ViewportStart, int ViewportEnd);
  189.     void DrawWaveform(void);
  190.     void SetControlRanges(HWND hDlg);
  191.     void SetHorizScrollRange(HWND hDlg);
  192.     void ProcessVertScrollCommands(HWND hDlg, WPARAM wParam, LPARAM lParam);
  193.     void ProcessHorizScrollCommands(HWND hDlg, WPARAM wParam, LPARAM lParam);
  194.  
  195.     friend BOOL CALLBACK ScopeDlgProc(HWND hwnd,      // Window handle
  196.                                     UINT uMsg,      // Message ID
  197.                                     WPARAM wParam,  // First parameter
  198.                                     LPARAM lParam); // Other parameter
  199.  
  200.  
  201. public:
  202.  
  203.     /* Constructors and destructors */
  204.  
  205.     CScopeWindow(TCHAR *pName, CScopeFilter *pRenderer, HRESULT *phr);
  206.     virtual ~CScopeWindow();
  207.  
  208.     HRESULT StartStreaming();
  209.     HRESULT StopStreaming();
  210.     HRESULT InactivateWindow();
  211.     HRESULT ActivateWindow();
  212.  
  213.     /* Called when the input pin receives a sample */
  214.     HRESULT Receive(IMediaSample * pIn);
  215.  
  216. };
  217.  
  218. /* This is the COM object that represents a simple rendering filter. It
  219.    supports IFilter and IMediaFilter and has a single input stream (pin)
  220.  
  221.    It will also (soon!) support IDispatch to allow it to expose some
  222.    simple properties....
  223.  
  224. */
  225.  
  226. class CScopeFilter : public CBaseFilter, public CCritSec
  227. {
  228.  
  229. public:
  230.     // Implements the IFilter and IMediaFilter interfaces
  231.  
  232.     DECLARE_IUNKNOWN
  233.  
  234.  
  235.     STDMETHODIMP Stop();
  236.     STDMETHODIMP Pause();
  237.     STDMETHODIMP Run(REFERENCE_TIME tStart);
  238.  
  239. public:
  240.  
  241.     CScopeFilter(
  242.         LPUNKNOWN pUnk,
  243.         HRESULT *phr);
  244.  
  245.     virtual ~CScopeFilter();
  246.  
  247.     /* Return the pins that we support */
  248.  
  249.     int GetPinCount();
  250.     CBasePin *GetPin(int n);
  251.  
  252.     /* This goes in the factory template table to create new instances */
  253.  
  254.     static CUnknown *CreateInstance(LPUNKNOWN, HRESULT *);
  255.  
  256.     STDMETHODIMP JoinFilterGraph(IFilterGraph * pGraph, LPCWSTR pName);
  257.  
  258.     // setup helper
  259.     LPAMOVIESETUP_FILTER GetSetupData();
  260.  
  261. private:
  262.  
  263.     /* The nested classes may access our private state */
  264.  
  265.     friend class CScopeInputPin;
  266.     friend class CScopeWindow;
  267.  
  268.     /* Member variables */
  269.     CScopeInputPin *m_pInputPin;   // IPin and IMemInputPin interfaces
  270.  
  271.     BOOL        m_fStopping;
  272.  
  273.     CScopeWindow m_Window;         // Looks after a rendering window
  274. };
  275.