EMIPLIB
|
00001 /* 00002 00003 This file is a part of EMIPLIB, the EDM Media over IP Library. 00004 00005 Copyright (C) 2006-2011 Hasselt University - Expertise Centre for 00006 Digital Media (EDM) (http://www.edm.uhasselt.be) 00007 00008 This library is free software; you can redistribute it and/or 00009 modify it under the terms of the GNU Lesser General Public 00010 License as published by the Free Software Foundation; either 00011 version 2.1 of the License, or (at your option) any later version. 00012 00013 This library is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 Lesser General Public License for more details. 00017 00018 You should have received a copy of the GNU Lesser General Public 00019 License along with this library; if not, write to the Free Software 00020 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 00021 USA 00022 00023 */ 00024 00029 #ifndef MIPDIRECTSHOWCAPTURE_H 00030 00031 #define MIPDIRECTSHOWCAPTURE_H 00032 00033 #include "mipconfig.h" 00034 00035 #ifdef MIPCONFIG_SUPPORT_DIRECTSHOW 00036 00037 #include "mipcomponent.h" 00038 #include "mipsignalwaiter.h" 00039 #include "miptime.h" 00040 #include <dshow.h> 00041 #include <Qedit.h> 00042 #include <list> 00043 00044 class MIPVideoMessage; 00045 00051 class EMIPLIB_IMPORTEXPORT MIPDirectShowCapture : public MIPComponent 00052 { 00053 public: 00054 MIPDirectShowCapture(); 00055 ~MIPDirectShowCapture(); 00056 00064 bool open(int width, int height, real_t frameRate, int deviceNumber = 0); 00065 00067 bool close(); 00068 00070 int getWidth() const { if (m_pGraph == 0) return -1; return m_width; } 00071 00073 int getHeight() const { if (m_pGraph == 0) return -1; return m_height; } 00074 00076 void setSourceID(uint64_t srcID) { m_sourceID = srcID; } 00077 00079 uint64_t getSourceID() const { return m_sourceID; } 00080 00082 uint32_t getFrameSubtype() const { return m_subType; } 00083 00084 bool push(const MIPComponentChain &chain, int64_t iteration, MIPMessage *pMsg); 00085 bool pull(const MIPComponentChain &chain, int64_t iteration, MIPMessage **pMsg); 00086 private: 00087 void zeroAll(); 00088 void clearNonZero(); 00089 bool initCaptureGraphBuilder(); 00090 bool getCaptureDevice(int deviceNumber); 00091 bool setFormat(int w, int h, real_t rate); 00092 bool listGUIDS(std::list<GUID> &guids); 00093 void copyVideoFrame(); 00094 00095 class GrabCallback : public ISampleGrabberCB 00096 { 00097 public: 00098 GrabCallback(MIPDirectShowCapture *pDSCapt) { m_pDSCapt = pDSCapt; } 00099 STDMETHODIMP_(ULONG) AddRef() { return 2; } 00100 STDMETHODIMP_(ULONG) Release() { return 1; } 00101 00102 STDMETHODIMP QueryInterface(REFIID riid, void ** ppv) 00103 { 00104 if( riid == IID_ISampleGrabberCB || riid == IID_IUnknown ) 00105 { 00106 *ppv = (void *) static_cast<ISampleGrabberCB*> ( this ); 00107 return NOERROR; 00108 } 00109 00110 return E_NOINTERFACE; 00111 } 00112 00113 STDMETHODIMP SampleCB( double SampleTime, IMediaSample * pSample ) 00114 { 00115 return 0; 00116 } 00117 00118 STDMETHODIMP BufferCB( double dblSampleTime, BYTE * pBuffer, long lBufferSize ) 00119 { 00120 size_t minsize = (size_t)lBufferSize; 00121 00122 if (minsize > m_pDSCapt->m_largeFrameSize) 00123 minsize = m_pDSCapt->m_largeFrameSize; 00124 00125 m_pDSCapt->m_frameMutex.Lock(); 00126 memcpy(m_pDSCapt->m_pFullFrame, pBuffer, minsize); 00127 m_pDSCapt->m_gotFrame = false; 00128 m_pDSCapt->m_captureTime = MIPTime::getCurrentTime(); 00129 m_pDSCapt->m_frameMutex.Unlock(); 00130 00131 m_pDSCapt->m_sigWait.signal(); 00132 return 0; 00133 } 00134 private: 00135 MIPDirectShowCapture *m_pDSCapt; 00136 }; 00137 00138 IGraphBuilder *m_pGraph; 00139 ICaptureGraphBuilder2 *m_pBuilder; 00140 IMediaControl *m_pControl; 00141 IBaseFilter *m_pCaptDevice; 00142 IBaseFilter *m_pNullRenderer; 00143 IBaseFilter *m_pSampGrabFilter; 00144 ISampleGrabber *m_pGrabber; 00145 GrabCallback *m_pGrabCallback; 00146 00147 int m_width; 00148 int m_height; 00149 uint8_t *m_pFullFrame; 00150 uint8_t *m_pMsgFrame; 00151 size_t m_largeFrameSize, m_targetFrameSize; 00152 MIPVideoMessage *m_pVideoMsg; 00153 jthread::JMutex m_frameMutex; 00154 MIPSignalWaiter m_sigWait; 00155 bool m_gotMsg; 00156 bool m_gotFrame; 00157 MIPTime m_captureTime; 00158 uint64_t m_sourceID; 00159 00160 GUID m_selectedGuid; 00161 uint32_t m_subType; 00162 }; 00163 00164 #endif // MIPCONFIG_SUPPORT_DIRECTSHOW 00165 00166 #endif // MIPDIRECTSHOWCAPTURE_H