]> git.sesse.net Git - vlc/blob - modules/access/dshow/filter.h
* modules/access/dshow/*: fixes and optimizations. Also changed all the parameters...
[vlc] / modules / access / dshow / filter.h
1 /*****************************************************************************
2  * filter.h : DirectShow access module for vlc
3  *****************************************************************************
4  * Copyright (C) 2002 VideoLAN
5  * $Id: filter.h,v 1.3 2003/10/18 20:09:23 gbazin Exp $
6  *
7  * Author: Gildas Bazin <gbazin@netcourrier.com>
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
49 typedef struct VLCMediaSample
50 {
51     IMediaSample *p_sample;
52     mtime_t i_timestamp;
53
54 } VLCMediaSample;
55
56 class CaptureFilter;
57
58 void WINAPI FreeMediaType( AM_MEDIA_TYPE& mt );
59 HRESULT WINAPI CopyMediaType( AM_MEDIA_TYPE *pmtTarget,
60                               const AM_MEDIA_TYPE *pmtSource );
61
62 /****************************************************************************
63  * Declaration of our dummy directshow filter pin class
64  ****************************************************************************/
65 class CapturePin: public IPin, public IMemInputPin
66 {
67     input_thread_t *p_input;
68     CaptureFilter  *p_filter;
69
70     IPin *p_connected_pin;
71     AM_MEDIA_TYPE media_type;
72
73     deque<VLCMediaSample> samples_queue;
74
75     long i_ref;
76
77   public:
78     CapturePin( input_thread_t * _p_input, CaptureFilter *_p_filter,
79                 AM_MEDIA_TYPE mt );
80     virtual ~CapturePin();
81
82     /* IUnknown methods */
83     STDMETHODIMP QueryInterface(REFIID riid, void **ppv);
84     STDMETHODIMP_(ULONG) AddRef();
85     STDMETHODIMP_(ULONG) Release();
86
87     /* IPin methods */
88     STDMETHODIMP Connect( IPin * pReceivePin, const AM_MEDIA_TYPE *pmt );
89     STDMETHODIMP ReceiveConnection( IPin * pConnector,
90                                     const AM_MEDIA_TYPE *pmt );
91     STDMETHODIMP Disconnect();
92     STDMETHODIMP ConnectedTo( IPin **pPin );
93     STDMETHODIMP ConnectionMediaType( AM_MEDIA_TYPE *pmt );
94     STDMETHODIMP QueryPinInfo( PIN_INFO * pInfo );
95     STDMETHODIMP QueryDirection( PIN_DIRECTION * pPinDir );
96     STDMETHODIMP QueryId( LPWSTR * Id );
97     STDMETHODIMP QueryAccept( const AM_MEDIA_TYPE *pmt );
98     STDMETHODIMP EnumMediaTypes( IEnumMediaTypes **ppEnum );
99     STDMETHODIMP QueryInternalConnections( IPin* *apPin, ULONG *nPin );
100     STDMETHODIMP EndOfStream( void );
101
102     STDMETHODIMP BeginFlush( void );
103     STDMETHODIMP EndFlush( void );
104     STDMETHODIMP NewSegment( REFERENCE_TIME tStart, REFERENCE_TIME tStop,
105                              double dRate );
106
107     /* IMemInputPin methods */
108     STDMETHODIMP GetAllocator( IMemAllocator **ppAllocator );
109     STDMETHODIMP NotifyAllocator(  IMemAllocator *pAllocator, BOOL bReadOnly );
110     STDMETHODIMP GetAllocatorRequirements( ALLOCATOR_PROPERTIES *pProps );
111     STDMETHODIMP Receive( IMediaSample *pSample );
112     STDMETHODIMP ReceiveMultiple( IMediaSample **pSamples, long nSamples,
113                                   long *nSamplesProcessed );
114     STDMETHODIMP ReceiveCanBlock( void );
115
116     /* Custom methods */
117     HRESULT CustomGetSample( VLCMediaSample * );
118     AM_MEDIA_TYPE CustomGetMediaType();
119 };
120
121 /****************************************************************************
122  * Declaration of our dummy directshow filter class
123  ****************************************************************************/
124 class CaptureFilter : public IBaseFilter
125 {
126     input_thread_t *p_input;
127     CapturePin     *p_pin;
128     IFilterGraph   *p_graph;
129     AM_MEDIA_TYPE  media_type;
130
131     long i_ref;
132
133   public:
134     CaptureFilter( input_thread_t * _p_input, AM_MEDIA_TYPE mt );
135     virtual ~CaptureFilter();
136
137     /* IUnknown methods */
138     STDMETHODIMP QueryInterface(REFIID riid, void **ppv);
139     STDMETHODIMP_(ULONG) AddRef();
140     STDMETHODIMP_(ULONG) Release();
141
142     /* IPersist method */
143     STDMETHODIMP GetClassID(CLSID *pClsID);
144
145     /* IMediaFilter methods */
146     STDMETHODIMP GetState(DWORD dwMSecs, FILTER_STATE *State);
147     STDMETHODIMP SetSyncSource(IReferenceClock *pClock);
148     STDMETHODIMP GetSyncSource(IReferenceClock **pClock);
149     STDMETHODIMP Stop();
150     STDMETHODIMP Pause();
151     STDMETHODIMP Run(REFERENCE_TIME tStart);
152
153     /* IBaseFilter methods */
154     STDMETHODIMP EnumPins( IEnumPins ** ppEnum );
155     STDMETHODIMP FindPin( LPCWSTR Id, IPin ** ppPin );
156     STDMETHODIMP QueryFilterInfo( FILTER_INFO * pInfo );
157     STDMETHODIMP JoinFilterGraph( IFilterGraph * pGraph, LPCWSTR pName );
158     STDMETHODIMP QueryVendorInfo( LPWSTR* pVendorInfo );
159
160     /* Custom methods */
161     CapturePin *CustomGetPin();
162 };
163
164 /****************************************************************************
165  * Declaration of our dummy directshow enumpins class
166  ****************************************************************************/
167 class CaptureEnumPins : public IEnumPins
168 {
169     input_thread_t * p_input;
170     CaptureFilter  *p_filter;
171
172     int i_position;
173     long i_ref;
174
175 public:
176     CaptureEnumPins( input_thread_t * _p_input, CaptureFilter *_p_filter,
177                      CaptureEnumPins *pEnumPins );
178     virtual ~CaptureEnumPins();
179
180     // IUnknown
181     STDMETHODIMP QueryInterface( REFIID riid, void **ppv );
182     STDMETHODIMP_(ULONG) AddRef();
183     STDMETHODIMP_(ULONG) Release();
184
185     // IEnumPins
186     STDMETHODIMP Next( ULONG cPins, IPin ** ppPins, ULONG * pcFetched );
187     STDMETHODIMP Skip( ULONG cPins );
188     STDMETHODIMP Reset();
189     STDMETHODIMP Clone( IEnumPins **ppEnum );
190 };
191
192 /****************************************************************************
193  * Declaration of our dummy directshow enummediatypes class
194  ****************************************************************************/
195 class CaptureEnumMediaTypes : public IEnumMediaTypes
196 {
197     input_thread_t * p_input;
198     CapturePin     *p_pin;
199
200     int i_position;
201     long i_ref;
202
203 public:
204     CaptureEnumMediaTypes( input_thread_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 };