00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <string>
00028 #include <list>
00029 #include <deque>
00030 using namespace std;
00031
00032 #ifndef _MSC_VER
00033 # include <wtypes.h>
00034 # include <unknwn.h>
00035 # include <ole2.h>
00036 # include <limits.h>
00037 # ifdef _WINGDI_
00038 # undef _WINGDI_
00039 # endif
00040 # define _WINGDI_ 1
00041 # define AM_NOVTABLE
00042 # define _OBJBASE_H_
00043 # undef _X86_
00044 # ifndef _I64_MAX
00045 # define _I64_MAX LONG_LONG_MAX
00046 # endif
00047 # define LONGLONG long long
00048 #endif
00049
00050 #include <dshow.h>
00051
00052 extern const GUID MEDIASUBTYPE_I420;
00053 extern const GUID MEDIASUBTYPE_PREVIEW_VIDEO;
00054
00055 typedef struct VLCMediaSample
00056 {
00057 IMediaSample *p_sample;
00058 mtime_t i_timestamp;
00059
00060 } VLCMediaSample;
00061
00062 class CaptureFilter;
00063
00064 void WINAPI FreeMediaType( AM_MEDIA_TYPE& mt );
00065 HRESULT WINAPI CopyMediaType( AM_MEDIA_TYPE *pmtTarget,
00066 const AM_MEDIA_TYPE *pmtSource );
00067
00068 int GetFourCCFromMediaType(const AM_MEDIA_TYPE &media_type);
00069
00070
00071
00072
00073 class CapturePin: public IPin, public IMemInputPin
00074 {
00075 friend class CaptureEnumMediaTypes;
00076
00077 vlc_object_t *p_input;
00078 access_sys_t *p_sys;
00079 CaptureFilter *p_filter;
00080
00081 IPin *p_connected_pin;
00082
00083 AM_MEDIA_TYPE *media_types;
00084 size_t media_type_count;
00085
00086 AM_MEDIA_TYPE cx_media_type;
00087
00088 deque<VLCMediaSample> samples_queue;
00089
00090 long i_ref;
00091
00092 public:
00093 CapturePin( vlc_object_t *_p_input, access_sys_t *p_sys,
00094 CaptureFilter *_p_filter,
00095 AM_MEDIA_TYPE *mt, size_t mt_count );
00096 virtual ~CapturePin();
00097
00098
00099 STDMETHODIMP QueryInterface(REFIID riid, void **ppv);
00100 STDMETHODIMP_(ULONG) AddRef();
00101 STDMETHODIMP_(ULONG) Release();
00102
00103
00104 STDMETHODIMP Connect( IPin * pReceivePin, const AM_MEDIA_TYPE *pmt );
00105 STDMETHODIMP ReceiveConnection( IPin * pConnector,
00106 const AM_MEDIA_TYPE *pmt );
00107 STDMETHODIMP Disconnect();
00108 STDMETHODIMP ConnectedTo( IPin **pPin );
00109 STDMETHODIMP ConnectionMediaType( AM_MEDIA_TYPE *pmt );
00110 STDMETHODIMP QueryPinInfo( PIN_INFO * pInfo );
00111 STDMETHODIMP QueryDirection( PIN_DIRECTION * pPinDir );
00112 STDMETHODIMP QueryId( LPWSTR * Id );
00113 STDMETHODIMP QueryAccept( const AM_MEDIA_TYPE *pmt );
00114 STDMETHODIMP EnumMediaTypes( IEnumMediaTypes **ppEnum );
00115 STDMETHODIMP QueryInternalConnections( IPin* *apPin, ULONG *nPin );
00116 STDMETHODIMP EndOfStream( void );
00117
00118 STDMETHODIMP BeginFlush( void );
00119 STDMETHODIMP EndFlush( void );
00120 STDMETHODIMP NewSegment( REFERENCE_TIME tStart, REFERENCE_TIME tStop,
00121 double dRate );
00122
00123
00124 STDMETHODIMP GetAllocator( IMemAllocator **ppAllocator );
00125 STDMETHODIMP NotifyAllocator( IMemAllocator *pAllocator, BOOL bReadOnly );
00126 STDMETHODIMP GetAllocatorRequirements( ALLOCATOR_PROPERTIES *pProps );
00127 STDMETHODIMP Receive( IMediaSample *pSample );
00128 STDMETHODIMP ReceiveMultiple( IMediaSample **pSamples, long nSamples,
00129 long *nSamplesProcessed );
00130 STDMETHODIMP ReceiveCanBlock( void );
00131
00132
00133 HRESULT CustomGetSample( VLCMediaSample * );
00134 AM_MEDIA_TYPE &CustomGetMediaType();
00135 };
00136
00137
00138
00139
00140 class CaptureFilter : public IBaseFilter
00141 {
00142 friend class CapturePin;
00143
00144 vlc_object_t *p_input;
00145 CapturePin *p_pin;
00146 IFilterGraph *p_graph;
00147
00148 FILTER_STATE state;
00149
00150 long i_ref;
00151
00152 public:
00153 CaptureFilter( vlc_object_t *_p_input, access_sys_t *p_sys,
00154 AM_MEDIA_TYPE *mt, size_t mt_count );
00155 virtual ~CaptureFilter();
00156
00157
00158 STDMETHODIMP QueryInterface(REFIID riid, void **ppv);
00159 STDMETHODIMP_(ULONG) AddRef();
00160 STDMETHODIMP_(ULONG) Release();
00161
00162
00163 STDMETHODIMP GetClassID(CLSID *pClsID);
00164
00165
00166 STDMETHODIMP GetState(DWORD dwMSecs, FILTER_STATE *State);
00167 STDMETHODIMP SetSyncSource(IReferenceClock *pClock);
00168 STDMETHODIMP GetSyncSource(IReferenceClock **pClock);
00169 STDMETHODIMP Stop();
00170 STDMETHODIMP Pause();
00171 STDMETHODIMP Run(REFERENCE_TIME tStart);
00172
00173
00174 STDMETHODIMP EnumPins( IEnumPins ** ppEnum );
00175 STDMETHODIMP FindPin( LPCWSTR Id, IPin ** ppPin );
00176 STDMETHODIMP QueryFilterInfo( FILTER_INFO * pInfo );
00177 STDMETHODIMP JoinFilterGraph( IFilterGraph * pGraph, LPCWSTR pName );
00178 STDMETHODIMP QueryVendorInfo( LPWSTR* pVendorInfo );
00179
00180
00181 CapturePin *CustomGetPin();
00182 };
00183
00184
00185
00186
00187 class CaptureEnumPins : public IEnumPins
00188 {
00189 vlc_object_t *p_input;
00190 CaptureFilter *p_filter;
00191
00192 int i_position;
00193 long i_ref;
00194
00195 public:
00196 CaptureEnumPins( vlc_object_t *_p_input, CaptureFilter *_p_filter,
00197 CaptureEnumPins *pEnumPins );
00198 virtual ~CaptureEnumPins();
00199
00200
00201 STDMETHODIMP QueryInterface( REFIID riid, void **ppv );
00202 STDMETHODIMP_(ULONG) AddRef();
00203 STDMETHODIMP_(ULONG) Release();
00204
00205
00206 STDMETHODIMP Next( ULONG cPins, IPin ** ppPins, ULONG * pcFetched );
00207 STDMETHODIMP Skip( ULONG cPins );
00208 STDMETHODIMP Reset();
00209 STDMETHODIMP Clone( IEnumPins **ppEnum );
00210 };
00211
00212
00213
00214
00215 class CaptureEnumMediaTypes : public IEnumMediaTypes
00216 {
00217 vlc_object_t *p_input;
00218 CapturePin *p_pin;
00219 AM_MEDIA_TYPE cx_media_type;
00220
00221 size_t i_position;
00222 long i_ref;
00223
00224 public:
00225 CaptureEnumMediaTypes( vlc_object_t *_p_input, CapturePin *_p_pin,
00226 CaptureEnumMediaTypes *pEnumMediaTypes );
00227
00228 virtual ~CaptureEnumMediaTypes();
00229
00230
00231 STDMETHODIMP QueryInterface( REFIID riid, void **ppv );
00232 STDMETHODIMP_(ULONG) AddRef();
00233 STDMETHODIMP_(ULONG) Release();
00234
00235
00236 STDMETHODIMP Next( ULONG cMediaTypes, AM_MEDIA_TYPE ** ppMediaTypes,
00237 ULONG * pcFetched );
00238 STDMETHODIMP Skip( ULONG cMediaTypes );
00239 STDMETHODIMP Reset();
00240 STDMETHODIMP Clone( IEnumMediaTypes **ppEnum );
00241 };