]> git.sesse.net Git - vlc/blob - modules/access/dshow/filter.h
* modules/access/dshow/*: PVR support contributed by Marc Nolette.
[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.4 2003/12/02 23:03:31 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 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
132     long i_ref;
133
134   public:
135     CaptureFilter( input_thread_t * _p_input, AM_MEDIA_TYPE mt );
136     virtual ~CaptureFilter();
137
138     /* IUnknown methods */
139     STDMETHODIMP QueryInterface(REFIID riid, void **ppv);
140     STDMETHODIMP_(ULONG) AddRef();
141     STDMETHODIMP_(ULONG) Release();
142
143     /* IPersist method */
144     STDMETHODIMP GetClassID(CLSID *pClsID);
145
146     /* IMediaFilter methods */
147     STDMETHODIMP GetState(DWORD dwMSecs, FILTER_STATE *State);
148     STDMETHODIMP SetSyncSource(IReferenceClock *pClock);
149     STDMETHODIMP GetSyncSource(IReferenceClock **pClock);
150     STDMETHODIMP Stop();
151     STDMETHODIMP Pause();
152     STDMETHODIMP Run(REFERENCE_TIME tStart);
153
154     /* IBaseFilter methods */
155     STDMETHODIMP EnumPins( IEnumPins ** ppEnum );
156     STDMETHODIMP FindPin( LPCWSTR Id, IPin ** ppPin );
157     STDMETHODIMP QueryFilterInfo( FILTER_INFO * pInfo );
158     STDMETHODIMP JoinFilterGraph( IFilterGraph * pGraph, LPCWSTR pName );
159     STDMETHODIMP QueryVendorInfo( LPWSTR* pVendorInfo );
160
161     /* Custom methods */
162     CapturePin *CustomGetPin();
163 };
164
165 /****************************************************************************
166  * Declaration of our dummy directshow enumpins class
167  ****************************************************************************/
168 class CaptureEnumPins : public IEnumPins
169 {
170     input_thread_t * p_input;
171     CaptureFilter  *p_filter;
172
173     int i_position;
174     long i_ref;
175
176 public:
177     CaptureEnumPins( input_thread_t * _p_input, CaptureFilter *_p_filter,
178                      CaptureEnumPins *pEnumPins );
179     virtual ~CaptureEnumPins();
180
181     // IUnknown
182     STDMETHODIMP QueryInterface( REFIID riid, void **ppv );
183     STDMETHODIMP_(ULONG) AddRef();
184     STDMETHODIMP_(ULONG) Release();
185
186     // IEnumPins
187     STDMETHODIMP Next( ULONG cPins, IPin ** ppPins, ULONG * pcFetched );
188     STDMETHODIMP Skip( ULONG cPins );
189     STDMETHODIMP Reset();
190     STDMETHODIMP Clone( IEnumPins **ppEnum );
191 };
192
193 /****************************************************************************
194  * Declaration of our dummy directshow enummediatypes class
195  ****************************************************************************/
196 class CaptureEnumMediaTypes : public IEnumMediaTypes
197 {
198     input_thread_t * p_input;
199     CapturePin     *p_pin;
200
201     int i_position;
202     long i_ref;
203
204 public:
205     CaptureEnumMediaTypes( input_thread_t * _p_input, CapturePin *_p_pin,
206                            CaptureEnumMediaTypes *pEnumMediaTypes );
207
208     virtual ~CaptureEnumMediaTypes();
209
210     // IUnknown
211     STDMETHODIMP QueryInterface( REFIID riid, void **ppv );
212     STDMETHODIMP_(ULONG) AddRef();
213     STDMETHODIMP_(ULONG) Release();
214
215     // IEnumMediaTypes
216     STDMETHODIMP Next( ULONG cMediaTypes, AM_MEDIA_TYPE ** ppMediaTypes,
217                        ULONG * pcFetched );
218     STDMETHODIMP Skip( ULONG cMediaTypes );
219     STDMETHODIMP Reset();
220     STDMETHODIMP Clone( IEnumMediaTypes **ppEnum );
221 };