]> git.sesse.net Git - vlc/blob - modules/access/dshow/filter.h
DShow: update Copyright years
[vlc] / modules / access / dshow / filter.h
1 /*****************************************************************************
2  * filter.h : DirectShow access module for vlc
3  *****************************************************************************
4  * Copyright (C) 2002-2004, 2008 the VideoLAN team
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, 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 #   ifdef _WINGDI_
38 #      undef _WINGDI_
39 #   endif
40 #   define _WINGDI_ 1
41 #   define AM_NOVTABLE
42 #   define _OBJBASE_H_
43 #   undef _X86_
44 #   ifndef _I64_MAX
45 #     define _I64_MAX LONG_LONG_MAX
46 #   endif
47 #   define LONGLONG long long
48 #endif
49
50 #include <dshow.h>
51
52 extern const GUID MEDIASUBTYPE_I420;
53 extern const GUID MEDIASUBTYPE_PREVIEW_VIDEO;
54
55 typedef struct VLCMediaSample
56 {
57     IMediaSample *p_sample;
58     mtime_t i_timestamp;
59
60 } VLCMediaSample;
61
62 class CaptureFilter;
63
64 void WINAPI FreeMediaType( AM_MEDIA_TYPE& mt );
65 HRESULT WINAPI CopyMediaType( AM_MEDIA_TYPE *pmtTarget,
66                               const AM_MEDIA_TYPE *pmtSource );
67
68 int GetFourCCFromMediaType(const AM_MEDIA_TYPE &media_type);
69
70 /****************************************************************************
71  * Declaration of our dummy directshow filter pin class
72  ****************************************************************************/
73 class CapturePin: public IPin, public IMemInputPin
74 {
75     friend class CaptureEnumMediaTypes;
76
77     vlc_object_t *p_input;
78     access_sys_t *p_sys;
79     CaptureFilter  *p_filter;
80
81     IPin *p_connected_pin;
82
83     AM_MEDIA_TYPE *media_types;
84     size_t media_type_count;
85
86     AM_MEDIA_TYPE cx_media_type;
87
88     deque<VLCMediaSample> samples_queue;
89
90     long i_ref;
91
92   public:
93     CapturePin( vlc_object_t *_p_input, access_sys_t *p_sys,
94                 CaptureFilter *_p_filter,
95                 AM_MEDIA_TYPE *mt, size_t mt_count );
96     virtual ~CapturePin();
97
98     /* IUnknown methods */
99     STDMETHODIMP QueryInterface(REFIID riid, void **ppv);
100     STDMETHODIMP_(ULONG) AddRef();
101     STDMETHODIMP_(ULONG) Release();
102
103     /* IPin methods */
104     STDMETHODIMP Connect( IPin * pReceivePin, const AM_MEDIA_TYPE *pmt );
105     STDMETHODIMP ReceiveConnection( IPin * pConnector,
106                                     const AM_MEDIA_TYPE *pmt );
107     STDMETHODIMP Disconnect();
108     STDMETHODIMP ConnectedTo( IPin **pPin );
109     STDMETHODIMP ConnectionMediaType( AM_MEDIA_TYPE *pmt );
110     STDMETHODIMP QueryPinInfo( PIN_INFO * pInfo );
111     STDMETHODIMP QueryDirection( PIN_DIRECTION * pPinDir );
112     STDMETHODIMP QueryId( LPWSTR * Id );
113     STDMETHODIMP QueryAccept( const AM_MEDIA_TYPE *pmt );
114     STDMETHODIMP EnumMediaTypes( IEnumMediaTypes **ppEnum );
115     STDMETHODIMP QueryInternalConnections( IPin* *apPin, ULONG *nPin );
116     STDMETHODIMP EndOfStream( void );
117
118     STDMETHODIMP BeginFlush( void );
119     STDMETHODIMP EndFlush( void );
120     STDMETHODIMP NewSegment( REFERENCE_TIME tStart, REFERENCE_TIME tStop,
121                              double dRate );
122
123     /* IMemInputPin methods */
124     STDMETHODIMP GetAllocator( IMemAllocator **ppAllocator );
125     STDMETHODIMP NotifyAllocator(  IMemAllocator *pAllocator, BOOL bReadOnly );
126     STDMETHODIMP GetAllocatorRequirements( ALLOCATOR_PROPERTIES *pProps );
127     STDMETHODIMP Receive( IMediaSample *pSample );
128     STDMETHODIMP ReceiveMultiple( IMediaSample **pSamples, long nSamples,
129                                   long *nSamplesProcessed );
130     STDMETHODIMP ReceiveCanBlock( void );
131
132     /* Custom methods */
133     HRESULT CustomGetSample( VLCMediaSample * );
134     HRESULT CustomGetSamples( deque<VLCMediaSample> &external_queue );
135
136     AM_MEDIA_TYPE &CustomGetMediaType();
137 };
138
139 /****************************************************************************
140  * Declaration of our dummy directshow filter class
141  ****************************************************************************/
142 class CaptureFilter : public IBaseFilter
143 {
144     friend class CapturePin;
145
146     vlc_object_t   *p_input;
147     CapturePin     *p_pin;
148     IFilterGraph   *p_graph;
149     //AM_MEDIA_TYPE  media_type;
150     FILTER_STATE   state;
151
152     long i_ref;
153
154   public:
155     CaptureFilter( vlc_object_t *_p_input, access_sys_t *p_sys,
156                    AM_MEDIA_TYPE *mt, size_t mt_count );
157     virtual ~CaptureFilter();
158
159     /* IUnknown methods */
160     STDMETHODIMP QueryInterface(REFIID riid, void **ppv);
161     STDMETHODIMP_(ULONG) AddRef();
162     STDMETHODIMP_(ULONG) Release();
163
164     /* IPersist method */
165     STDMETHODIMP GetClassID(CLSID *pClsID);
166
167     /* IMediaFilter methods */
168     STDMETHODIMP GetState(DWORD dwMSecs, FILTER_STATE *State);
169     STDMETHODIMP SetSyncSource(IReferenceClock *pClock);
170     STDMETHODIMP GetSyncSource(IReferenceClock **pClock);
171     STDMETHODIMP Stop();
172     STDMETHODIMP Pause();
173     STDMETHODIMP Run(REFERENCE_TIME tStart);
174
175     /* IBaseFilter methods */
176     STDMETHODIMP EnumPins( IEnumPins ** ppEnum );
177     STDMETHODIMP FindPin( LPCWSTR Id, IPin ** ppPin );
178     STDMETHODIMP QueryFilterInfo( FILTER_INFO * pInfo );
179     STDMETHODIMP JoinFilterGraph( IFilterGraph * pGraph, LPCWSTR pName );
180     STDMETHODIMP QueryVendorInfo( LPWSTR* pVendorInfo );
181
182     /* Custom methods */
183     CapturePin *CustomGetPin();
184 };
185
186 /****************************************************************************
187  * Declaration of our dummy directshow enumpins class
188  ****************************************************************************/
189 class CaptureEnumPins : public IEnumPins
190 {
191     vlc_object_t *p_input;
192     CaptureFilter  *p_filter;
193
194     int i_position;
195     long i_ref;
196
197 public:
198     CaptureEnumPins( vlc_object_t *_p_input, CaptureFilter *_p_filter,
199                      CaptureEnumPins *pEnumPins );
200     virtual ~CaptureEnumPins();
201
202     // IUnknown
203     STDMETHODIMP QueryInterface( REFIID riid, void **ppv );
204     STDMETHODIMP_(ULONG) AddRef();
205     STDMETHODIMP_(ULONG) Release();
206
207     // IEnumPins
208     STDMETHODIMP Next( ULONG cPins, IPin ** ppPins, ULONG * pcFetched );
209     STDMETHODIMP Skip( ULONG cPins );
210     STDMETHODIMP Reset();
211     STDMETHODIMP Clone( IEnumPins **ppEnum );
212 };
213
214 /****************************************************************************
215  * Declaration of our dummy directshow enummediatypes class
216  ****************************************************************************/
217 class CaptureEnumMediaTypes : public IEnumMediaTypes
218 {
219     vlc_object_t *p_input;
220     CapturePin     *p_pin;
221     AM_MEDIA_TYPE cx_media_type;
222
223     size_t i_position;
224     long i_ref;
225
226 public:
227     CaptureEnumMediaTypes( vlc_object_t *_p_input, CapturePin *_p_pin,
228                            CaptureEnumMediaTypes *pEnumMediaTypes );
229
230     virtual ~CaptureEnumMediaTypes();
231
232     // IUnknown
233     STDMETHODIMP QueryInterface( REFIID riid, void **ppv );
234     STDMETHODIMP_(ULONG) AddRef();
235     STDMETHODIMP_(ULONG) Release();
236
237     // IEnumMediaTypes
238     STDMETHODIMP Next( ULONG cMediaTypes, AM_MEDIA_TYPE ** ppMediaTypes,
239                        ULONG * pcFetched );
240     STDMETHODIMP Skip( ULONG cMediaTypes );
241     STDMETHODIMP Reset();
242     STDMETHODIMP Clone( IEnumMediaTypes **ppEnum );
243 };