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