]> git.sesse.net Git - vlc/blob - modules/access/dshow/filter.h
FSF address change.
[vlc] / modules / access / dshow / filter.h
1 /*****************************************************************************
2  * filter.h : DirectShow access module for vlc
3  *****************************************************************************
4  * Copyright (C) 2002 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 #   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     vlc_object_t *p_input;
73     access_sys_t *p_sys;
74     CaptureFilter  *p_filter;
75
76     IPin *p_connected_pin;
77
78     AM_MEDIA_TYPE *media_types;
79     size_t media_type_count;
80
81     AM_MEDIA_TYPE cx_media_type;
82
83     deque<VLCMediaSample> samples_queue;
84
85     long i_ref;
86
87   public:
88     CapturePin( vlc_object_t *_p_input, access_sys_t *p_sys,
89                 CaptureFilter *_p_filter,
90                 AM_MEDIA_TYPE *mt, size_t mt_count );
91     virtual ~CapturePin();
92
93     /* IUnknown methods */
94     STDMETHODIMP QueryInterface(REFIID riid, void **ppv);
95     STDMETHODIMP_(ULONG) AddRef();
96     STDMETHODIMP_(ULONG) Release();
97
98     /* IPin methods */
99     STDMETHODIMP Connect( IPin * pReceivePin, const AM_MEDIA_TYPE *pmt );
100     STDMETHODIMP ReceiveConnection( IPin * pConnector,
101                                     const AM_MEDIA_TYPE *pmt );
102     STDMETHODIMP Disconnect();
103     STDMETHODIMP ConnectedTo( IPin **pPin );
104     STDMETHODIMP ConnectionMediaType( AM_MEDIA_TYPE *pmt );
105     STDMETHODIMP QueryPinInfo( PIN_INFO * pInfo );
106     STDMETHODIMP QueryDirection( PIN_DIRECTION * pPinDir );
107     STDMETHODIMP QueryId( LPWSTR * Id );
108     STDMETHODIMP QueryAccept( const AM_MEDIA_TYPE *pmt );
109     STDMETHODIMP EnumMediaTypes( IEnumMediaTypes **ppEnum );
110     STDMETHODIMP QueryInternalConnections( IPin* *apPin, ULONG *nPin );
111     STDMETHODIMP EndOfStream( void );
112
113     STDMETHODIMP BeginFlush( void );
114     STDMETHODIMP EndFlush( void );
115     STDMETHODIMP NewSegment( REFERENCE_TIME tStart, REFERENCE_TIME tStop,
116                              double dRate );
117
118     /* IMemInputPin methods */
119     STDMETHODIMP GetAllocator( IMemAllocator **ppAllocator );
120     STDMETHODIMP NotifyAllocator(  IMemAllocator *pAllocator, BOOL bReadOnly );
121     STDMETHODIMP GetAllocatorRequirements( ALLOCATOR_PROPERTIES *pProps );
122     STDMETHODIMP Receive( IMediaSample *pSample );
123     STDMETHODIMP ReceiveMultiple( IMediaSample **pSamples, long nSamples,
124                                   long *nSamplesProcessed );
125     STDMETHODIMP ReceiveCanBlock( void );
126
127     /* Custom methods */
128     HRESULT CustomGetSample( VLCMediaSample * );
129     AM_MEDIA_TYPE &CustomGetMediaType();
130 };
131
132 /****************************************************************************
133  * Declaration of our dummy directshow filter class
134  ****************************************************************************/
135 class CaptureFilter : public IBaseFilter
136 {
137     friend class CapturePin;
138
139     vlc_object_t   *p_input;
140     CapturePin     *p_pin;
141     IFilterGraph   *p_graph;
142     //AM_MEDIA_TYPE  media_type;
143     FILTER_STATE   state;
144
145     long i_ref;
146
147   public:
148     CaptureFilter( vlc_object_t *_p_input, access_sys_t *p_sys,
149                    AM_MEDIA_TYPE *mt, size_t mt_count );
150     virtual ~CaptureFilter();
151
152     /* IUnknown methods */
153     STDMETHODIMP QueryInterface(REFIID riid, void **ppv);
154     STDMETHODIMP_(ULONG) AddRef();
155     STDMETHODIMP_(ULONG) Release();
156
157     /* IPersist method */
158     STDMETHODIMP GetClassID(CLSID *pClsID);
159
160     /* IMediaFilter methods */
161     STDMETHODIMP GetState(DWORD dwMSecs, FILTER_STATE *State);
162     STDMETHODIMP SetSyncSource(IReferenceClock *pClock);
163     STDMETHODIMP GetSyncSource(IReferenceClock **pClock);
164     STDMETHODIMP Stop();
165     STDMETHODIMP Pause();
166     STDMETHODIMP Run(REFERENCE_TIME tStart);
167
168     /* IBaseFilter methods */
169     STDMETHODIMP EnumPins( IEnumPins ** ppEnum );
170     STDMETHODIMP FindPin( LPCWSTR Id, IPin ** ppPin );
171     STDMETHODIMP QueryFilterInfo( FILTER_INFO * pInfo );
172     STDMETHODIMP JoinFilterGraph( IFilterGraph * pGraph, LPCWSTR pName );
173     STDMETHODIMP QueryVendorInfo( LPWSTR* pVendorInfo );
174
175     /* Custom methods */
176     CapturePin *CustomGetPin();
177 };
178
179 /****************************************************************************
180  * Declaration of our dummy directshow enumpins class
181  ****************************************************************************/
182 class CaptureEnumPins : public IEnumPins
183 {
184     vlc_object_t *p_input;
185     CaptureFilter  *p_filter;
186
187     int i_position;
188     long i_ref;
189
190 public:
191     CaptureEnumPins( vlc_object_t *_p_input, CaptureFilter *_p_filter,
192                      CaptureEnumPins *pEnumPins );
193     virtual ~CaptureEnumPins();
194
195     // IUnknown
196     STDMETHODIMP QueryInterface( REFIID riid, void **ppv );
197     STDMETHODIMP_(ULONG) AddRef();
198     STDMETHODIMP_(ULONG) Release();
199
200     // IEnumPins
201     STDMETHODIMP Next( ULONG cPins, IPin ** ppPins, ULONG * pcFetched );
202     STDMETHODIMP Skip( ULONG cPins );
203     STDMETHODIMP Reset();
204     STDMETHODIMP Clone( IEnumPins **ppEnum );
205 };
206
207 /****************************************************************************
208  * Declaration of our dummy directshow enummediatypes class
209  ****************************************************************************/
210 class CaptureEnumMediaTypes : public IEnumMediaTypes
211 {
212     vlc_object_t *p_input;
213     CapturePin     *p_pin;
214     AM_MEDIA_TYPE cx_media_type;
215
216     size_t i_position;
217     long i_ref;
218
219 public:
220     CaptureEnumMediaTypes( vlc_object_t *_p_input, CapturePin *_p_pin,
221                            CaptureEnumMediaTypes *pEnumMediaTypes );
222
223     virtual ~CaptureEnumMediaTypes();
224
225     // IUnknown
226     STDMETHODIMP QueryInterface( REFIID riid, void **ppv );
227     STDMETHODIMP_(ULONG) AddRef();
228     STDMETHODIMP_(ULONG) Release();
229
230     // IEnumMediaTypes
231     STDMETHODIMP Next( ULONG cMediaTypes, AM_MEDIA_TYPE ** ppMediaTypes,
232                        ULONG * pcFetched );
233     STDMETHODIMP Skip( ULONG cMediaTypes );
234     STDMETHODIMP Reset();
235     STDMETHODIMP Clone( IEnumMediaTypes **ppEnum );
236 };