00001
00002
00003 #ifndef __DSHOWFILE_H
00004 #define __DSHOWFILE_H
00005
00006 #include <atlbase.h>
00007 #include <windows.h>
00008 #include <dshow.h>
00009 #include <qedit.h>
00010
00011 #include "videosource.h"
00012
00014
00016
00017 class CSampleGrabberCB : public ISampleGrabberCB
00018 {
00019
00020 public:
00021
00022
00023
00024 long Width;
00025 long Height;
00026 IplImage *image;
00027 bool frameWanted;
00028
00029 CSampleGrabberCB() {
00030 image=0;
00031 frameWanted=true;
00032 }
00033
00034
00035
00036 STDMETHODIMP_(ULONG) AddRef()
00037 {
00038 return 1;
00039 }
00040
00041 STDMETHODIMP_(ULONG) Release()
00042 {
00043 return 2;
00044 }
00045
00046
00047
00048 STDMETHODIMP QueryInterface(REFIID riid, void ** ppv)
00049 {
00050 if (!ppv) return E_POINTER;
00051
00052 if( riid == IID_ISampleGrabberCB || riid == IID_IUnknown )
00053 {
00054 *ppv = (void *) static_cast<ISampleGrabberCB*> ( this );
00055 return NOERROR;
00056 }
00057
00058 return E_NOINTERFACE;
00059 }
00060
00061
00062
00063
00064 STDMETHODIMP SampleCB( double SampleTime, IMediaSample * pSample )
00065 {
00066 return 0;
00067 }
00068
00069
00070
00071
00072
00073 STDMETHODIMP BufferCB( double SampleTime, BYTE * pBuffer, long BufferSize )
00074 {
00075 while (!frameWanted) {
00076 Sleep(2);
00077 };
00078 if (BufferSize > image->imageSize) {
00079 fprintf(stderr, __FILE__ ": error ! image size too big !!\n");
00080 return 0;
00081 }
00082
00083 memcpy(image->imageData, pBuffer, BufferSize);
00084 cvFlip(image);
00085 frameWanted=false;
00086
00087
00088
00090
00091
00092 return 0;
00093 }
00094 };
00095
00096
00097 class DShowFile : public VideoSource {
00098 public:
00099 virtual bool initialize();
00100 virtual bool getFrame(IplImage *dst);
00101 virtual void getSize(int &width, int &height);
00102 DShowFile(const char *filename);
00103 virtual ~DShowFile();
00104 virtual void start();
00105 virtual void stop();
00106 virtual bool isPlaying() { return g_psCurrent == Playing; };
00107 virtual int getId() { return (int) lastFrame; };
00108 virtual const char *getStreamName() const { return filename ? filename : "DShow live capture"; }
00109 virtual const char *getStreamType() const { return "DShowFile"; }
00110
00111 private:
00112 enum PLAYSTATE {Stopped, Paused, Playing};
00113
00114 CSampleGrabberCB CB;
00115
00116 CComPtr< ISampleGrabber > pGrabber;
00117 CComPtr< IBaseFilter > pSource;
00118 CComPtr< IGraphBuilder > pGraph;
00119 CComPtr< IVideoWindow > pVideoWindow;
00120 IMediaSeeking *pSeeking;
00121
00122 PLAYSTATE g_psCurrent;
00123 const char *filename;
00124
00125 IplImage *image;
00126
00127 int frameCnt;
00128
00129 LONGLONG duration, lastFrame;
00130 };
00131
00132 class DShowFileFactory : public ParticularVSFactory {
00133 public:
00134 DShowFileFactory() { name="DShowFile"; filename=0; };
00135 virtual void registerParameters(ParamSection *sec);
00136 virtual VideoSource *construct();
00137 private:
00138 char *filename;
00139 bool use;
00140 };
00141
00142 void deinterlaceAndResize(IplImage *src, IplImage *dst);
00143
00144 #endif
00145