]> git.sesse.net Git - vlc/blob - modules/access/dshow/filter.h
LGPL
[vlc] / modules / access / dshow / filter.h
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
6  * $Id$
7  *
8  * Author: Gildas Bazin <gbazin@videolan.org>
9  *
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.
14  *
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.
19  *
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  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28
29 #include <deque>
30 using namespace std;
31
32 typedef struct VLCMediaSample
33 {
34     IMediaSample *p_sample;
35     mtime_t i_timestamp;
36
37 } VLCMediaSample;
38
39 /* */
40 void WINAPI FreeMediaType( AM_MEDIA_TYPE& mt );
41 HRESULT WINAPI CopyMediaType( AM_MEDIA_TYPE *pmtTarget,
42                               const AM_MEDIA_TYPE *pmtSource );
43
44 int GetFourCCFromMediaType(const AM_MEDIA_TYPE &media_type);
45
46 /****************************************************************************
47  * Declaration of our dummy directshow filter pin class
48  ****************************************************************************/
49 class CaptureFilter;
50 class CapturePin: public IPin, public IMemInputPin
51 {
52     friend class CaptureEnumMediaTypes;
53
54     vlc_object_t *p_input;
55     access_sys_t *p_sys;
56     CaptureFilter  *p_filter;
57
58     IPin *p_connected_pin;
59
60     AM_MEDIA_TYPE *media_types;
61     size_t media_type_count;
62
63     AM_MEDIA_TYPE cx_media_type;
64
65     deque<VLCMediaSample> samples_queue;
66
67     long i_ref;
68
69   public:
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();
74
75     /* IUnknown methods */
76     STDMETHODIMP QueryInterface(REFIID riid, void **ppv);
77     STDMETHODIMP_(ULONG) AddRef();
78     STDMETHODIMP_(ULONG) Release();
79
80     /* IPin methods */
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 );
94
95     STDMETHODIMP BeginFlush( void );
96     STDMETHODIMP EndFlush( void );
97     STDMETHODIMP NewSegment( REFERENCE_TIME tStart, REFERENCE_TIME tStop,
98                              double dRate );
99
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 );
108
109     /* Custom methods */
110     HRESULT CustomGetSample( VLCMediaSample * );
111     HRESULT CustomGetSamples( deque<VLCMediaSample> &external_queue );
112
113     AM_MEDIA_TYPE &CustomGetMediaType();
114 };
115
116 /****************************************************************************
117  * Declaration of our dummy directshow filter class
118  ****************************************************************************/
119 class CaptureFilter : public IBaseFilter
120 {
121     friend class CapturePin;
122
123     vlc_object_t   *p_input;
124     CapturePin     *p_pin;
125     IFilterGraph   *p_graph;
126     //AM_MEDIA_TYPE  media_type;
127     FILTER_STATE   state;
128
129     long i_ref;
130
131   public:
132     CaptureFilter( vlc_object_t *_p_input, access_sys_t *p_sys,
133                    AM_MEDIA_TYPE *mt, size_t mt_count );
134     virtual ~CaptureFilter();
135
136     /* IUnknown methods */
137     STDMETHODIMP QueryInterface(REFIID riid, void **ppv);
138     STDMETHODIMP_(ULONG) AddRef();
139     STDMETHODIMP_(ULONG) Release();
140
141     /* IPersist method */
142     STDMETHODIMP GetClassID(CLSID *pClsID);
143
144     /* IMediaFilter methods */
145     STDMETHODIMP GetState(DWORD dwMSecs, FILTER_STATE *State);
146     STDMETHODIMP SetSyncSource(IReferenceClock *pClock);
147     STDMETHODIMP GetSyncSource(IReferenceClock **pClock);
148     STDMETHODIMP Stop();
149     STDMETHODIMP Pause();
150     STDMETHODIMP Run(REFERENCE_TIME tStart);
151
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 );
158
159     /* Custom methods */
160     CapturePin *CustomGetPin();
161 };
162
163 /****************************************************************************
164  * Declaration of our dummy directshow enumpins class
165  ****************************************************************************/
166 class CaptureEnumPins : public IEnumPins
167 {
168     vlc_object_t *p_input;
169     CaptureFilter  *p_filter;
170
171     int i_position;
172     long i_ref;
173
174 public:
175     CaptureEnumPins( vlc_object_t *_p_input, CaptureFilter *_p_filter,
176                      CaptureEnumPins *pEnumPins );
177     virtual ~CaptureEnumPins();
178
179     // IUnknown
180     STDMETHODIMP QueryInterface( REFIID riid, void **ppv );
181     STDMETHODIMP_(ULONG) AddRef();
182     STDMETHODIMP_(ULONG) Release();
183
184     // IEnumPins
185     STDMETHODIMP Next( ULONG cPins, IPin ** ppPins, ULONG * pcFetched );
186     STDMETHODIMP Skip( ULONG cPins );
187     STDMETHODIMP Reset();
188     STDMETHODIMP Clone( IEnumPins **ppEnum );
189 };
190
191 /****************************************************************************
192  * Declaration of our dummy directshow enummediatypes class
193  ****************************************************************************/
194 class CaptureEnumMediaTypes : public IEnumMediaTypes
195 {
196     vlc_object_t *p_input;
197     CapturePin     *p_pin;
198     AM_MEDIA_TYPE cx_media_type;
199
200     size_t i_position;
201     long i_ref;
202
203 public:
204     CaptureEnumMediaTypes( vlc_object_t *_p_input, CapturePin *_p_pin,
205                            CaptureEnumMediaTypes *pEnumMediaTypes );
206
207     virtual ~CaptureEnumMediaTypes();
208
209     // IUnknown
210     STDMETHODIMP QueryInterface( REFIID riid, void **ppv );
211     STDMETHODIMP_(ULONG) AddRef();
212     STDMETHODIMP_(ULONG) Release();
213
214     // IEnumMediaTypes
215     STDMETHODIMP Next( ULONG cMediaTypes, AM_MEDIA_TYPE ** ppMediaTypes,
216                        ULONG * pcFetched );
217     STDMETHODIMP Skip( ULONG cMediaTypes );
218     STDMETHODIMP Reset();
219     STDMETHODIMP Clone( IEnumMediaTypes **ppEnum );
220 };