1 /*****************************************************************************
2 * filter.h : DirectShow access module for vlc:
3 * CapturePin, CaptureFilter, CaptureEnumPins implementations
4 *****************************************************************************
5 * Copyright (C) 2002-2004, 2008 VLC authors and VideoLAN
8 * Author: Gildas Bazin <gbazin@videolan.org>
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU Lesser General Public License as published by
12 * the Free Software Foundation; either version 2.1 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this program; if not, write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
32 typedef struct VLCMediaSample
34 IMediaSample *p_sample;
40 void WINAPI FreeMediaType( AM_MEDIA_TYPE& mt );
41 HRESULT WINAPI CopyMediaType( AM_MEDIA_TYPE *pmtTarget,
42 const AM_MEDIA_TYPE *pmtSource );
44 int GetFourCCFromMediaType(const AM_MEDIA_TYPE &media_type);
46 /****************************************************************************
47 * Declaration of our dummy directshow filter pin class
48 ****************************************************************************/
50 class CapturePin: public IPin, public IMemInputPin
52 friend class CaptureEnumMediaTypes;
54 vlc_object_t *p_input;
56 CaptureFilter *p_filter;
58 IPin *p_connected_pin;
60 AM_MEDIA_TYPE *media_types;
61 size_t media_type_count;
63 AM_MEDIA_TYPE cx_media_type;
65 deque<VLCMediaSample> samples_queue;
70 CapturePin( vlc_object_t *_p_input, access_sys_t *p_sys,
71 CaptureFilter *_p_filter,
72 AM_MEDIA_TYPE *mt, size_t mt_count );
73 virtual ~CapturePin();
75 /* IUnknown methods */
76 STDMETHODIMP QueryInterface(REFIID riid, void **ppv);
77 STDMETHODIMP_(ULONG) AddRef();
78 STDMETHODIMP_(ULONG) Release();
81 STDMETHODIMP Connect( IPin * pReceivePin, const AM_MEDIA_TYPE *pmt );
82 STDMETHODIMP ReceiveConnection( IPin * pConnector,
83 const AM_MEDIA_TYPE *pmt );
84 STDMETHODIMP Disconnect();
85 STDMETHODIMP ConnectedTo( IPin **pPin );
86 STDMETHODIMP ConnectionMediaType( AM_MEDIA_TYPE *pmt );
87 STDMETHODIMP QueryPinInfo( PIN_INFO * pInfo );
88 STDMETHODIMP QueryDirection( PIN_DIRECTION * pPinDir );
89 STDMETHODIMP QueryId( LPWSTR * Id );
90 STDMETHODIMP QueryAccept( const AM_MEDIA_TYPE *pmt );
91 STDMETHODIMP EnumMediaTypes( IEnumMediaTypes **ppEnum );
92 STDMETHODIMP QueryInternalConnections( IPin* *apPin, ULONG *nPin );
93 STDMETHODIMP EndOfStream( void );
95 STDMETHODIMP BeginFlush( void );
96 STDMETHODIMP EndFlush( void );
97 STDMETHODIMP NewSegment( REFERENCE_TIME tStart, REFERENCE_TIME tStop,
100 /* IMemInputPin methods */
101 STDMETHODIMP GetAllocator( IMemAllocator **ppAllocator );
102 STDMETHODIMP NotifyAllocator( IMemAllocator *pAllocator, BOOL bReadOnly );
103 STDMETHODIMP GetAllocatorRequirements( ALLOCATOR_PROPERTIES *pProps );
104 STDMETHODIMP Receive( IMediaSample *pSample );
105 STDMETHODIMP ReceiveMultiple( IMediaSample **pSamples, long nSamples,
106 long *nSamplesProcessed );
107 STDMETHODIMP ReceiveCanBlock( void );
110 HRESULT CustomGetSample( VLCMediaSample * );
111 HRESULT CustomGetSamples( deque<VLCMediaSample> &external_queue );
113 AM_MEDIA_TYPE &CustomGetMediaType();
116 /****************************************************************************
117 * Declaration of our dummy directshow filter class
118 ****************************************************************************/
119 class CaptureFilter : public IBaseFilter
121 friend class CapturePin;
123 vlc_object_t *p_input;
125 IFilterGraph *p_graph;
126 //AM_MEDIA_TYPE media_type;
132 CaptureFilter( vlc_object_t *_p_input, access_sys_t *p_sys,
133 AM_MEDIA_TYPE *mt, size_t mt_count );
134 virtual ~CaptureFilter();
136 /* IUnknown methods */
137 STDMETHODIMP QueryInterface(REFIID riid, void **ppv);
138 STDMETHODIMP_(ULONG) AddRef();
139 STDMETHODIMP_(ULONG) Release();
141 /* IPersist method */
142 STDMETHODIMP GetClassID(CLSID *pClsID);
144 /* IMediaFilter methods */
145 STDMETHODIMP GetState(DWORD dwMSecs, FILTER_STATE *State);
146 STDMETHODIMP SetSyncSource(IReferenceClock *pClock);
147 STDMETHODIMP GetSyncSource(IReferenceClock **pClock);
149 STDMETHODIMP Pause();
150 STDMETHODIMP Run(REFERENCE_TIME tStart);
152 /* IBaseFilter methods */
153 STDMETHODIMP EnumPins( IEnumPins ** ppEnum );
154 STDMETHODIMP FindPin( LPCWSTR Id, IPin ** ppPin );
155 STDMETHODIMP QueryFilterInfo( FILTER_INFO * pInfo );
156 STDMETHODIMP JoinFilterGraph( IFilterGraph * pGraph, LPCWSTR pName );
157 STDMETHODIMP QueryVendorInfo( LPWSTR* pVendorInfo );
160 CapturePin *CustomGetPin();
163 /****************************************************************************
164 * Declaration of our dummy directshow enumpins class
165 ****************************************************************************/
166 class CaptureEnumPins : public IEnumPins
168 vlc_object_t *p_input;
169 CaptureFilter *p_filter;
175 CaptureEnumPins( vlc_object_t *_p_input, CaptureFilter *_p_filter,
176 CaptureEnumPins *pEnumPins );
177 virtual ~CaptureEnumPins();
180 STDMETHODIMP QueryInterface( REFIID riid, void **ppv );
181 STDMETHODIMP_(ULONG) AddRef();
182 STDMETHODIMP_(ULONG) Release();
185 STDMETHODIMP Next( ULONG cPins, IPin ** ppPins, ULONG * pcFetched );
186 STDMETHODIMP Skip( ULONG cPins );
187 STDMETHODIMP Reset();
188 STDMETHODIMP Clone( IEnumPins **ppEnum );
191 /****************************************************************************
192 * Declaration of our dummy directshow enummediatypes class
193 ****************************************************************************/
194 class CaptureEnumMediaTypes : public IEnumMediaTypes
196 vlc_object_t *p_input;
198 AM_MEDIA_TYPE cx_media_type;
204 CaptureEnumMediaTypes( vlc_object_t *_p_input, CapturePin *_p_pin,
205 CaptureEnumMediaTypes *pEnumMediaTypes );
207 virtual ~CaptureEnumMediaTypes();
210 STDMETHODIMP QueryInterface( REFIID riid, void **ppv );
211 STDMETHODIMP_(ULONG) AddRef();
212 STDMETHODIMP_(ULONG) Release();
215 STDMETHODIMP Next( ULONG cMediaTypes, AM_MEDIA_TYPE ** ppMediaTypes,
217 STDMETHODIMP Skip( ULONG cMediaTypes );
218 STDMETHODIMP Reset();
219 STDMETHODIMP Clone( IEnumMediaTypes **ppEnum );