]> git.sesse.net Git - vlc/blob - modules/access/dshow/filter.h
d42b9496603f73d0d16776f0e85eb857b4288148
[vlc] / modules / access / dshow / filter.h
1 /*****************************************************************************
2  * filter.h : DirectShow access module for vlc
3  *****************************************************************************
4  * Copyright (C) 2002 VideoLAN
5  * $Id$
6  *
7  * Author: Gildas Bazin <gbazin@videolan.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <string>
28 #include <list>
29 #include <deque>
30 using namespace std;
31
32 #ifndef _MSC_VER
33 #   include <wtypes.h>
34 #   include <unknwn.h>
35 #   include <ole2.h>
36 #   include <limits.h>
37 #   define _WINGDI_ 1
38 #   define AM_NOVTABLE
39 #   define _OBJBASE_H_
40 #   undef _X86_
41 #   define _I64_MAX LONG_LONG_MAX
42 #   define LONGLONG long long
43 #endif
44
45 #include <dshow.h>
46
47 extern const GUID MEDIASUBTYPE_I420;
48 extern const GUID MEDIASUBTYPE_PREVIEW_VIDEO;
49
50 typedef struct VLCMediaSample
51 {
52     IMediaSample *p_sample;
53     mtime_t i_timestamp;
54
55 } VLCMediaSample;
56
57 class CaptureFilter;
58
59 void WINAPI FreeMediaType( AM_MEDIA_TYPE& mt );
60 HRESULT WINAPI CopyMediaType( AM_MEDIA_TYPE *pmtTarget,
61                               const AM_MEDIA_TYPE *pmtSource );
62
63 int GetFourCCFromMediaType(const AM_MEDIA_TYPE &media_type);
64
65 /****************************************************************************
66  * Declaration of our dummy directshow filter pin class
67  ****************************************************************************/
68 class CapturePin: public IPin, public IMemInputPin
69 {
70     friend class CaptureEnumMediaTypes;
71
72     input_thread_t *p_input;
73     CaptureFilter  *p_filter;
74
75     IPin *p_connected_pin;
76
77     AM_MEDIA_TYPE *media_types;
78     size_t media_type_count;
79
80     AM_MEDIA_TYPE cx_media_type;
81
82     deque<VLCMediaSample> samples_queue;
83
84     long i_ref;
85
86   public:
87     CapturePin( input_thread_t * _p_input, CaptureFilter *_p_filter,
88                 AM_MEDIA_TYPE *mt, size_t mt_count );
89     virtual ~CapturePin();
90
91     /* IUnknown methods */
92     STDMETHODIMP QueryInterface(REFIID riid, void **ppv);
93     STDMETHODIMP_(ULONG) AddRef();
94     STDMETHODIMP_(ULONG) Release();
95
96     /* IPin methods */
97     STDMETHODIMP Connect( IPin * pReceivePin, const AM_MEDIA_TYPE *pmt );
98     STDMETHODIMP ReceiveConnection( IPin * pConnector,
99                                     const AM_MEDIA_TYPE *pmt );
100     STDMETHODIMP Disconnect();
101     STDMETHODIMP ConnectedTo( IPin **pPin );
102     STDMETHODIMP ConnectionMediaType( AM_MEDIA_TYPE *pmt );
103     STDMETHODIMP QueryPinInfo( PIN_INFO * pInfo );
104     STDMETHODIMP QueryDirection( PIN_DIRECTION * pPinDir );
105     STDMETHODIMP QueryId( LPWSTR * Id );
106     STDMETHODIMP QueryAccept( const AM_MEDIA_TYPE *pmt );
107     STDMETHODIMP EnumMediaTypes( IEnumMediaTypes **ppEnum );
108     STDMETHODIMP QueryInternalConnections( IPin* *apPin, ULONG *nPin );
109     STDMETHODIMP EndOfStream( void );
110
111     STDMETHODIMP BeginFlush( void );
112     STDMETHODIMP EndFlush( void );
113     STDMETHODIMP NewSegment( REFERENCE_TIME tStart, REFERENCE_TIME tStop,
114                              double dRate );
115
116     /* IMemInputPin methods */
117     STDMETHODIMP GetAllocator( IMemAllocator **ppAllocator );
118     STDMETHODIMP NotifyAllocator(  IMemAllocator *pAllocator, BOOL bReadOnly );
119     STDMETHODIMP GetAllocatorRequirements( ALLOCATOR_PROPERTIES *pProps );
120     STDMETHODIMP Receive( IMediaSample *pSample );
121     STDMETHODIMP ReceiveMultiple( IMediaSample **pSamples, long nSamples,
122                                   long *nSamplesProcessed );
123     STDMETHODIMP ReceiveCanBlock( void );
124
125     /* Custom methods */
126     HRESULT CustomGetSample( VLCMediaSample * );
127     AM_MEDIA_TYPE &CustomGetMediaType();
128 };
129
130 /****************************************************************************
131  * Declaration of our dummy directshow filter class
132  ****************************************************************************/
133 class CaptureFilter : public IBaseFilter
134 {
135     friend class CapturePin;
136
137     input_thread_t *p_input;
138     CapturePin     *p_pin;
139     IFilterGraph   *p_graph;
140     //AM_MEDIA_TYPE  media_type;
141     FILTER_STATE   state;
142
143     long i_ref;
144
145   public:
146     CaptureFilter( input_thread_t * _p_input, AM_MEDIA_TYPE *mt, size_t mt_count );
147     virtual ~CaptureFilter();
148
149     /* IUnknown methods */
150     STDMETHODIMP QueryInterface(REFIID riid, void **ppv);
151     STDMETHODIMP_(ULONG) AddRef();
152     STDMETHODIMP_(ULONG) Release();
153
154     /* IPersist method */
155     STDMETHODIMP GetClassID(CLSID *pClsID);
156
157     /* IMediaFilter methods */
158     STDMETHODIMP GetState(DWORD dwMSecs, FILTER_STATE *State);
159     STDMETHODIMP SetSyncSource(IReferenceClock *pClock);
160     STDMETHODIMP GetSyncSource(IReferenceClock **pClock);
161     STDMETHODIMP Stop();
162     STDMETHODIMP Pause();
163     STDMETHODIMP Run(REFERENCE_TIME tStart);
164
165     /* IBaseFilter methods */
166     STDMETHODIMP EnumPins( IEnumPins ** ppEnum );
167     STDMETHODIMP FindPin( LPCWSTR Id, IPin ** ppPin );
168     STDMETHODIMP QueryFilterInfo( FILTER_INFO * pInfo );
169     STDMETHODIMP JoinFilterGraph( IFilterGraph * pGraph, LPCWSTR pName );
170     STDMETHODIMP QueryVendorInfo( LPWSTR* pVendorInfo );
171
172     /* Custom methods */
173     CapturePin *CustomGetPin();
174 };
175
176 /****************************************************************************
177  * Declaration of our dummy directshow enumpins class
178  ****************************************************************************/
179 class CaptureEnumPins : public IEnumPins
180 {
181     input_thread_t * p_input;
182     CaptureFilter  *p_filter;
183
184     int i_position;
185     long i_ref;
186
187 public:
188     CaptureEnumPins( input_thread_t * _p_input, CaptureFilter *_p_filter,
189                      CaptureEnumPins *pEnumPins );
190     virtual ~CaptureEnumPins();
191
192     // IUnknown
193     STDMETHODIMP QueryInterface( REFIID riid, void **ppv );
194     STDMETHODIMP_(ULONG) AddRef();
195     STDMETHODIMP_(ULONG) Release();
196
197     // IEnumPins
198     STDMETHODIMP Next( ULONG cPins, IPin ** ppPins, ULONG * pcFetched );
199     STDMETHODIMP Skip( ULONG cPins );
200     STDMETHODIMP Reset();
201     STDMETHODIMP Clone( IEnumPins **ppEnum );
202 };
203
204 /****************************************************************************
205  * Declaration of our dummy directshow enummediatypes class
206  ****************************************************************************/
207 class CaptureEnumMediaTypes : public IEnumMediaTypes
208 {
209     input_thread_t * p_input;
210     CapturePin     *p_pin;
211
212     int i_position;
213     long i_ref;
214
215 public:
216     CaptureEnumMediaTypes( input_thread_t * _p_input, CapturePin *_p_pin,
217                            CaptureEnumMediaTypes *pEnumMediaTypes );
218
219     virtual ~CaptureEnumMediaTypes();
220
221     // IUnknown
222     STDMETHODIMP QueryInterface( REFIID riid, void **ppv );
223     STDMETHODIMP_(ULONG) AddRef();
224     STDMETHODIMP_(ULONG) Release();
225
226     // IEnumMediaTypes
227     STDMETHODIMP Next( ULONG cMediaTypes, AM_MEDIA_TYPE ** ppMediaTypes,
228                        ULONG * pcFetched );
229     STDMETHODIMP Skip( ULONG cMediaTypes );
230     STDMETHODIMP Reset();
231     STDMETHODIMP Clone( IEnumMediaTypes **ppEnum );
232 };