filter.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * filter.h : DirectShow access module for vlc
00003  *****************************************************************************
00004  * Copyright (C) 2002 the VideoLAN team
00005  * $Id$
00006  *
00007  * Author: Gildas Bazin <gbazin@videolan.org>
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
00022  *****************************************************************************/
00023 
00024 /*****************************************************************************
00025  * Preamble
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  * Declaration of our dummy directshow filter pin class
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     /* IUnknown methods */
00099     STDMETHODIMP QueryInterface(REFIID riid, void **ppv);
00100     STDMETHODIMP_(ULONG) AddRef();
00101     STDMETHODIMP_(ULONG) Release();
00102 
00103     /* IPin methods */
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     /* IMemInputPin methods */
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     /* Custom methods */
00133     HRESULT CustomGetSample( VLCMediaSample * );
00134     HRESULT CustomGetSamples( deque<VLCMediaSample> &external_queue );
00135 
00136     AM_MEDIA_TYPE &CustomGetMediaType();
00137 };
00138 
00139 /****************************************************************************
00140  * Declaration of our dummy directshow filter class
00141  ****************************************************************************/
00142 class CaptureFilter : public IBaseFilter
00143 {
00144     friend class CapturePin;
00145 
00146     vlc_object_t   *p_input;
00147     CapturePin     *p_pin;
00148     IFilterGraph   *p_graph;
00149     //AM_MEDIA_TYPE  media_type;
00150     FILTER_STATE   state;
00151 
00152     long i_ref;
00153 
00154   public:
00155     CaptureFilter( vlc_object_t *_p_input, access_sys_t *p_sys,
00156                    AM_MEDIA_TYPE *mt, size_t mt_count );
00157     virtual ~CaptureFilter();
00158 
00159     /* IUnknown methods */
00160     STDMETHODIMP QueryInterface(REFIID riid, void **ppv);
00161     STDMETHODIMP_(ULONG) AddRef();
00162     STDMETHODIMP_(ULONG) Release();
00163 
00164     /* IPersist method */
00165     STDMETHODIMP GetClassID(CLSID *pClsID);
00166 
00167     /* IMediaFilter methods */
00168     STDMETHODIMP GetState(DWORD dwMSecs, FILTER_STATE *State);
00169     STDMETHODIMP SetSyncSource(IReferenceClock *pClock);
00170     STDMETHODIMP GetSyncSource(IReferenceClock **pClock);
00171     STDMETHODIMP Stop();
00172     STDMETHODIMP Pause();
00173     STDMETHODIMP Run(REFERENCE_TIME tStart);
00174 
00175     /* IBaseFilter methods */
00176     STDMETHODIMP EnumPins( IEnumPins ** ppEnum );
00177     STDMETHODIMP FindPin( LPCWSTR Id, IPin ** ppPin );
00178     STDMETHODIMP QueryFilterInfo( FILTER_INFO * pInfo );
00179     STDMETHODIMP JoinFilterGraph( IFilterGraph * pGraph, LPCWSTR pName );
00180     STDMETHODIMP QueryVendorInfo( LPWSTR* pVendorInfo );
00181 
00182     /* Custom methods */
00183     CapturePin *CustomGetPin();
00184 };
00185 
00186 /****************************************************************************
00187  * Declaration of our dummy directshow enumpins class
00188  ****************************************************************************/
00189 class CaptureEnumPins : public IEnumPins
00190 {
00191     vlc_object_t *p_input;
00192     CaptureFilter  *p_filter;
00193 
00194     int i_position;
00195     long i_ref;
00196 
00197 public:
00198     CaptureEnumPins( vlc_object_t *_p_input, CaptureFilter *_p_filter,
00199                      CaptureEnumPins *pEnumPins );
00200     virtual ~CaptureEnumPins();
00201 
00202     // IUnknown
00203     STDMETHODIMP QueryInterface( REFIID riid, void **ppv );
00204     STDMETHODIMP_(ULONG) AddRef();
00205     STDMETHODIMP_(ULONG) Release();
00206 
00207     // IEnumPins
00208     STDMETHODIMP Next( ULONG cPins, IPin ** ppPins, ULONG * pcFetched );
00209     STDMETHODIMP Skip( ULONG cPins );
00210     STDMETHODIMP Reset();
00211     STDMETHODIMP Clone( IEnumPins **ppEnum );
00212 };
00213 
00214 /****************************************************************************
00215  * Declaration of our dummy directshow enummediatypes class
00216  ****************************************************************************/
00217 class CaptureEnumMediaTypes : public IEnumMediaTypes
00218 {
00219     vlc_object_t *p_input;
00220     CapturePin     *p_pin;
00221     AM_MEDIA_TYPE cx_media_type;
00222 
00223     size_t i_position;
00224     long i_ref;
00225 
00226 public:
00227     CaptureEnumMediaTypes( vlc_object_t *_p_input, CapturePin *_p_pin,
00228                            CaptureEnumMediaTypes *pEnumMediaTypes );
00229 
00230     virtual ~CaptureEnumMediaTypes();
00231 
00232     // IUnknown
00233     STDMETHODIMP QueryInterface( REFIID riid, void **ppv );
00234     STDMETHODIMP_(ULONG) AddRef();
00235     STDMETHODIMP_(ULONG) Release();
00236 
00237     // IEnumMediaTypes
00238     STDMETHODIMP Next( ULONG cMediaTypes, AM_MEDIA_TYPE ** ppMediaTypes,
00239                        ULONG * pcFetched );
00240     STDMETHODIMP Skip( ULONG cMediaTypes );
00241     STDMETHODIMP Reset();
00242     STDMETHODIMP Clone( IEnumMediaTypes **ppEnum );
00243 };

Generated on Tue May 25 08:04:52 2010 for VLC by  doxygen 1.5.6