DXManager.h
上传用户:lijia5631
上传日期:2008-11-10
资源大小:1214k
文件大小:5k
源码类别:

视频捕捉/采集

开发平台:

MultiPlatform

  1. /**   * HandVu - a library for computer vision-based hand gesture   * recognition.   * Copyright (C) 2004 Mathias Kolsch, matz@cs.ucsb.edu   *   * This program is free software; you can redistribute it and/or   * modify it under the terms of the GNU General Public License   * as published by the Free Software Foundation; either version 2   * of the License, or (at your option) any later version.   *   * This program is distributed in the hope that it will be useful,   * but WITHOUT ANY WARRANTY; without even the implied warranty of   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   * GNU General Public License for more details.   *   * You should have received a copy of the GNU General Public License   * along with this program; if not, write to the Free Software   * Foundation, Inc., 59 Temple Place - Suite 330,    * Boston, MA  02111-1307, USA.   *   * $Id: DXManager.h,v 1.8 2005/10/30 23:00:43 matz Exp $ **/ #include "iHandVuFilter.h"
  2. #include "HandVuFilterGUIDs.h"
  3. #include <sys/types.h>
  4. #include <sys/timeb.h>
  5. class DXManager;
  6. class CDXAppView;
  7. class CSourceView : public CScrollView
  8. {
  9. public:
  10.   CSourceView();
  11. DECLARE_DYNCREATE(CSourceView)
  12. virtual ~CSourceView();
  13. // Overrides
  14. public:
  15.   virtual void OnDraw(CDC* pDC) {};  // overridden to draw this view
  16.   virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
  17. virtual void OnInitialUpdate();
  18. protected:
  19.   void SetVideoWindowSize(int width, int height);
  20. // Generated message map functions
  21. protected:
  22. afx_msg void OnSize(UINT nType, int cx, int cy);
  23. DECLARE_MESSAGE_MAP()
  24. public:
  25.   DXManager*      m_pDXManager;
  26. };
  27. class DXManager : public HVFilterEventListener, CameraController
  28. {
  29. public:
  30.   DXManager();
  31.   ~DXManager();
  32. public:
  33.   bool                       BuildGraph(bool two_windows, CDXAppView* parent);
  34.   void                       StopPlayback();
  35.   void                       StartPlayback();
  36.   void                       SetVideoWindowPosition(int left, int top, int width, int height);
  37.   void                       SetSourceVideoWindowPosition(int left, int top, int width, int height);
  38.   void                       GetVideoSourceSize(int* pWidth, int* pHeight);
  39.   IHandVuFilter*             HV();
  40.   void                       ToggleExposureControl();
  41.   void                       SetExposureControl(int on=1); // -1 toggles it
  42.   void                       ToggleFullscreen();
  43.   void                       SetLogfilename(const string& handvu_logfilename) 
  44.                                { m_handvu_logfilename = handvu_logfilename; }
  45.   void                       GetVersion(string& version) const;
  46. // HVFilterEventListener callback:
  47.   virtual void               FrameTransformed(bool processed);
  48. // CameraController
  49.   virtual double             GetCurrentExposure();   virtual bool               SetExposure(double exposure);    virtual bool               SetCameraAutoExposure(bool enable=true);   virtual bool               CanAdjustExposure();
  50. protected:
  51.   bool                       CreateHandVuFilter();
  52.   bool                       InitHandVuFilter();
  53.   bool                       CreateCamera(int idx=0);
  54.   bool                       RealBuildGraph();
  55.   bool                       ConnectFilters();
  56.   void                       DestroyFilterGraph();
  57.   void                       Render(IPin* pPin, CRect& rect);
  58.   void                       NullComPtrs(); // set CComPtr's to NULL
  59.   HRESULT                    AddFilter(IBaseFilter* filter, LPCWSTR name);
  60.   HRESULT                    ConnectPins(IPin* from, IPin* to);
  61. #ifdef DEBUG
  62.   HRESULT                     AddToROT(IUnknown *pUnkGraph, DWORD *pdwRegister);
  63.   void                        RemoveFromROT(DWORD pdwRegister);
  64. #endif
  65.  protected: 
  66.   // DirectShow interface pointers
  67.   CComPtr<IGraphBuilder>     m_GraphBuilder;
  68.   CComPtr<IMediaControl>     m_MediaControl;
  69.   CComPtr<IVideoWindow>      m_VideoWindow;
  70.   CComPtr<IFilterGraph>      m_FilterGraph;
  71.   CComPtr<IMediaEventEx>     m_MediaEventEx;
  72.   CComPtr<IBaseFilter>       m_SourceFilter;
  73.   CComPtr<IAMCameraControl>  m_CameraControl;
  74.   CComPtr<IBaseFilter>       m_HandVuFilter;
  75.   CComPtr<IHandVuFilter>     m_HandVuFilterProp;
  76.   CComPtr<IAMTimecodeReader> m_pIAMTCReader;
  77.   
  78.   double                     m_video_scale;
  79.   int                        m_source_width;
  80.   int                        m_source_height;
  81.   DWORD                      m_ROTregister;
  82.   // source window
  83.   CDXAppView*                m_pParentView;
  84.   CSourceView                m_SourceWin;
  85.   CComPtr<IVideoWindow>      m_SourceVideoWindow;
  86.   bool                       m_two_windows;
  87.   // end DirectShow related
  88.   struct _timeb              m_startTime;
  89.   string                     m_handvu_logfilename;
  90. };
  91. // other prototypes
  92. BOOL 
  93. PinMatchesCategory(CComPtr<IPin> pPin, const GUID& Category);
  94. static CComPtr<IPin> 
  95. GetPin(CComPtr<IBaseFilter> pFilter, PIN_DIRECTION PinDir, 
  96.        int skip=0, const GUID* pCategory=NULL);
  97. static CComPtr<IPin> 
  98. GetVideoPin(CComPtr<IBaseFilter> pFilter, PIN_DIRECTION PinDir);