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     AM_MEDIA_TYPE &CustomGetMediaType();
00135 };
00136 
00137 /****************************************************************************
00138  * Declaration of our dummy directshow filter class
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     //AM_MEDIA_TYPE  media_type;
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     /* IUnknown methods */
00158     STDMETHODIMP QueryInterface(REFIID riid, void **ppv);
00159     STDMETHODIMP_(ULONG) AddRef();
00160     STDMETHODIMP_(ULONG) Release();
00161 
00162     /* IPersist method */
00163     STDMETHODIMP GetClassID(CLSID *pClsID);
00164 
00165     /* IMediaFilter methods */
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     /* IBaseFilter methods */
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     /* Custom methods */
00181     CapturePin *CustomGetPin();
00182 };
00183 
00184 /****************************************************************************
00185  * Declaration of our dummy directshow enumpins class
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     // IUnknown
00201     STDMETHODIMP QueryInterface( REFIID riid, void **ppv );
00202     STDMETHODIMP_(ULONG) AddRef();
00203     STDMETHODIMP_(ULONG) Release();
00204 
00205     // IEnumPins
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  * Declaration of our dummy directshow enummediatypes class
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     // IUnknown
00231     STDMETHODIMP QueryInterface( REFIID riid, void **ppv );
00232     STDMETHODIMP_(ULONG) AddRef();
00233     STDMETHODIMP_(ULONG) Release();
00234 
00235     // IEnumMediaTypes
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 };

Generated on Wed Aug 13 08:02:37 2008 for VLC by  doxygen 1.5.1