]> git.sesse.net Git - vlc/blob - modules/access/dshow/filter.cpp
* modules/access/dshow/*: compilation fixes.
[vlc] / modules / access / dshow / filter.cpp
1 /*****************************************************************************
2  * filter.c : DirectShow access module for vlc
3  *****************************************************************************
4  * Copyright (C) 2002 VideoLAN
5  * $Id: filter.cpp,v 1.8 2003/11/24 20:45: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 <stdlib.h>
28 #include <stdio.h>
29 #include <string.h>
30
31 #include <vlc/vlc.h>
32 #include <vlc/input.h>
33 #include <vlc/vout.h>
34
35 #include "filter.h"
36
37 #define DEBUG_DSHOW 1
38
39 struct access_sys_t
40 {
41     vlc_mutex_t lock;
42     vlc_cond_t  wait;
43 };
44
45 /*****************************************************************************
46  * DirectShow GUIDs.
47  * Easier to define them hear as mingw doesn't provide them all.
48  *****************************************************************************/
49 const GUID CLSID_SystemDeviceEnum = {0x62be5d10, 0x60eb, 0x11d0, {0xbd, 0x3b, 0x00, 0xa0, 0xc9, 0x11, 0xce, 0x86}};
50 const GUID CLSID_VideoInputDeviceCategory = {0x860BB310,0x5D01,0x11d0,{0xBD,0x3B,0x00,0xA0,0xC9,0x11,0xCE,0x86}};
51 const GUID CLSID_AudioInputDeviceCategory = {0x33d9a762, 0x90c8, 0x11d0, {0xbd, 0x43, 0x00, 0xa0, 0xc9, 0x11, 0xce, 0x86}};
52 const GUID IID_IPropertyBag = {0x55272A00, 0x42CB, 0x11CE, {0x81, 0x35, 0x00, 0xAA, 0x00, 0x4B, 0xB8, 0x51}};
53 const GUID IID_ICreateDevEnum = {0x29840822, 0x5b84, 0x11d0, {0xbd, 0x3b, 0x00, 0xa0, 0xc9, 0x11, 0xce, 0x86}};
54 const GUID IID_IFilterGraph = {0x56a8689f, 0x0ad4, 0x11ce, {0xb0, 0x3a, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70}};
55 const GUID IID_IMediaControl = {0x56a868b1, 0x0ad4, 0x11ce, {0xb0, 0x3a, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70}};
56 const GUID CLSID_FilterGraph = {0xe436ebb3, 0x524f, 0x11ce, {0x9f, 0x53, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70}};
57
58 const GUID IID_IUnknown = {0x00000000, 0x0000, 0x0000, {0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46}};
59 const GUID IID_IPersist = {0x0000010c, 0x0000, 0x0000, {0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46}};
60 const GUID IID_IMediaFilter = {0x56a86899, 0x0ad4, 0x11ce, {0xb0,0x3a, 0x00,0x20,0xaf,0x0b,0xa7,0x70}};
61 const GUID IID_IBaseFilter = {0x56a86895, 0x0ad4, 0x11ce, {0xb0, 0x3a, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70}};
62 const GUID IID_IPin = {0x56a86891, 0x0ad4, 0x11ce, {0xb0,0x3a, 0x00,0x20,0xaf,0x0b,0xa7,0x70}};
63 const GUID IID_IMemInputPin = {0x56a8689d, 0x0ad4, 0x11ce, {0xb0,0x3a, 0x00,0x20,0xaf,0x0b,0xa7,0x70}};
64
65 const GUID IID_IEnumPins = {0x56a86892, 0x0ad4, 0x11ce, {0xb0,0x3a, 0x00,0x20,0xaf,0x0b,0xa7,0x70}};
66 const GUID IID_IEnumMediaTypes = {0x89c31040, 0x846b, 0x11ce, {0x97,0xd3, 0x00,0xaa,0x00,0x55,0x59,0x5a}};
67
68 const GUID IID_IAMBufferNegotiation = {0x56ed71a0, 0xaf5f, 0x11d0, {0xb3, 0xf0, 0x00, 0xaa, 0x00, 0x37, 0x61, 0xc5}};
69
70 /*
71  * MEDIATYPEs and MEDIASUBTYPEs
72  */
73 const GUID MEDIATYPE_Video = {0x73646976, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
74
75 /* Packed RGB formats */
76 const GUID MEDIASUBTYPE_RGB1 = {0xe436eb78, 0x524f, 0x11ce, {0x9f, 0x53, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70}};
77 const GUID MEDIASUBTYPE_RGB4 = {0xe436eb79, 0x524f, 0x11ce, {0x9f, 0x53, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70}};
78 const GUID MEDIASUBTYPE_RGB8 = {0xe436eb7a, 0x524f, 0x11ce, {0x9f, 0x53, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70}};
79 const GUID MEDIASUBTYPE_RGB565 = {0xe436eb7b, 0x524f, 0x11ce, {0x9f, 0x53, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70}};
80 const GUID MEDIASUBTYPE_RGB555 = {0xe436eb7c, 0x524f, 0x11ce, {0x9f, 0x53, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70}};
81 const GUID MEDIASUBTYPE_RGB24 = {0xe436eb7d, 0x524f, 0x11ce, {0x9f, 0x53, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70}};
82 const GUID MEDIASUBTYPE_RGB32 = {0xe436eb7e, 0x524f, 0x11ce, {0x9f, 0x53, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70}};
83 const GUID MEDIASUBTYPE_ARGB32 = {0x773c9ac0, 0x3274, 0x11d0, {0xb7, 0x24, 0x0, 0xaa, 0x0, 0x6c, 0x1a, 0x1}};
84
85 /* Packed YUV formats */
86 const GUID MEDIASUBTYPE_YUYV = {0x56595559, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
87 const GUID MEDIASUBTYPE_Y411 = {0x31313459, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
88 const GUID MEDIASUBTYPE_Y211 = {0x31313259, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
89 const GUID MEDIASUBTYPE_YUY2 = {0x32595559, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
90 const GUID MEDIASUBTYPE_YVYU = {0x55595659, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
91 const GUID MEDIASUBTYPE_UYVY = {0x59565955, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
92
93 /* Planar YUV formats */
94 const GUID MEDIASUBTYPE_YVU9 = {0x39555659, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
95 const GUID MEDIASUBTYPE_YV12 = {0x32315659, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
96 const GUID MEDIASUBTYPE_IYUV = {0x56555949, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}}; /* identical to YV12 */
97 const GUID MEDIASUBTYPE_Y41P = {0x50313459, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
98 const GUID MEDIASUBTYPE_I420 = {0x30323449, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
99
100 const GUID MEDIATYPE_Audio = {0x73647561, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
101 const GUID FORMAT_WaveFormatEx = {0x05589f81, 0xc356, 0x11ce, {0xbf, 0x01, 0x00, 0xaa, 0x00, 0x55, 0x59, 0x5a}};
102 const GUID MEDIASUBTYPE_PCM = {0x00000001, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
103 const GUID MEDIASUBTYPE_IEEE_FLOAT = {0x00000003, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
104
105 /* DV formats */
106 const GUID MEDIASUBTYPE_dvsd = {0x64737664, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
107 const GUID MEDIASUBTYPE_dvhd = {0x64687664, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
108 const GUID MEDIASUBTYPE_dvsl = {0x6c737664, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
109
110 const GUID GUID_NULL = {0x0000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};
111
112 void WINAPI FreeMediaType( AM_MEDIA_TYPE& mt )
113 {
114     if( mt.cbFormat != 0 )
115     {
116         CoTaskMemFree( (PVOID)mt.pbFormat );
117         mt.cbFormat = 0;
118         mt.pbFormat = NULL;
119     }
120     if( mt.pUnk != NULL )
121     {
122         mt.pUnk->Release();
123         mt.pUnk = NULL;
124     }
125 }
126
127 HRESULT WINAPI CopyMediaType( AM_MEDIA_TYPE *pmtTarget,
128                               const AM_MEDIA_TYPE *pmtSource )
129 {
130     *pmtTarget = *pmtSource;
131     if( pmtSource->cbFormat != 0 )
132     {
133         pmtTarget->pbFormat = (PBYTE)CoTaskMemAlloc( pmtSource->cbFormat );
134         if( pmtTarget->pbFormat == NULL )
135         {
136             pmtTarget->cbFormat = 0;
137             return E_OUTOFMEMORY;
138         }
139         else
140         {
141             CopyMemory( (PVOID)pmtTarget->pbFormat, (PVOID)pmtSource->pbFormat,
142                         pmtTarget->cbFormat );
143         }
144     }
145     if( pmtTarget->pUnk != NULL )
146     {
147         pmtTarget->pUnk->AddRef();
148     }
149
150     return S_OK;
151 }
152
153 /****************************************************************************
154  * Implementation of our dummy directshow filter pin class
155  ****************************************************************************/
156
157 CapturePin::CapturePin( input_thread_t * _p_input, CaptureFilter *_p_filter,
158                         AM_MEDIA_TYPE mt )
159   : p_input( _p_input ), p_filter( _p_filter ), p_connected_pin( NULL ),
160     media_type( mt ), i_ref( 1 )
161 {
162 }
163
164 CapturePin::~CapturePin()
165 {
166 }
167
168 HRESULT CapturePin::CustomGetSample( VLCMediaSample *vlc_sample )
169 {
170     if( samples_queue.size() )
171     {
172         *vlc_sample = samples_queue.back();
173         samples_queue.pop_back();
174         return S_OK;
175     }
176     return S_FALSE;
177 }
178
179 AM_MEDIA_TYPE CapturePin::CustomGetMediaType()
180 {
181     return media_type;
182 }
183
184 /* IUnknown methods */
185 STDMETHODIMP CapturePin::QueryInterface(REFIID riid, void **ppv)
186 {
187 #ifdef DEBUG_DSHOW
188     msg_Dbg( p_input, "CapturePin::QueryInterface" );
189 #endif
190
191     if( riid == IID_IUnknown ||
192         riid == IID_IPin )
193     {
194         AddRef();
195         *ppv = (IPin *)this;
196         return NOERROR;
197     }
198     if( riid == IID_IMemInputPin )
199     {
200         AddRef();
201         *ppv = (IMemInputPin *)this;
202         return NOERROR;
203     }
204     else
205     {
206         *ppv = NULL;
207         return E_NOINTERFACE;
208     }
209 }
210 STDMETHODIMP_(ULONG) CapturePin::AddRef()
211 {
212 #ifdef DEBUG_DSHOW
213     msg_Dbg( p_input, "CapturePin::AddRef (ref: %i)", i_ref );
214 #endif
215
216     return i_ref++;
217 };
218 STDMETHODIMP_(ULONG) CapturePin::Release()
219 {
220 #ifdef DEBUG_DSHOW
221     msg_Dbg( p_input, "CapturePin::Release (ref: %i)", i_ref );
222 #endif
223
224     if( !InterlockedDecrement(&i_ref) ) delete this;
225
226     return 0;
227 };
228
229 /* IPin methods */
230 STDMETHODIMP CapturePin::Connect( IPin * pReceivePin,
231                                   const AM_MEDIA_TYPE *pmt )
232 {
233 #ifdef DEBUG_DSHOW
234     msg_Dbg( p_input, "CapturePin::Connect" );
235 #endif
236     return E_NOTIMPL;
237 }
238 STDMETHODIMP CapturePin::ReceiveConnection( IPin * pConnector,
239                                             const AM_MEDIA_TYPE *pmt )
240 {
241 #ifdef DEBUG_DSHOW
242     msg_Dbg( p_input, "CapturePin::ReceiveConnection" );
243 #endif
244
245     if( pmt->majortype == MEDIATYPE_Video )
246     {
247         if( media_type.subtype != GUID_NULL &&
248             media_type.subtype != pmt->subtype )
249             return VFW_E_TYPE_NOT_ACCEPTED;
250
251         if( media_type.pbFormat &&
252             ((VIDEOINFOHEADER *)media_type.pbFormat)->bmiHeader.biHeight &&
253             ((VIDEOINFOHEADER *)media_type.pbFormat)->bmiHeader.biHeight !=
254             ((VIDEOINFOHEADER *)pmt->pbFormat)->bmiHeader.biHeight )
255             return VFW_E_TYPE_NOT_ACCEPTED;
256
257         if( media_type.pbFormat &&
258             ((VIDEOINFOHEADER *)media_type.pbFormat)->bmiHeader.biWidth &&
259             ((VIDEOINFOHEADER *)media_type.pbFormat)->bmiHeader.biWidth !=
260             ((VIDEOINFOHEADER *)pmt->pbFormat)->bmiHeader.biWidth )
261             return VFW_E_TYPE_NOT_ACCEPTED;
262     }
263
264     p_connected_pin = pConnector;
265     p_connected_pin->AddRef();
266
267     FreeMediaType( media_type );
268     return CopyMediaType( &media_type, pmt );
269 }
270 STDMETHODIMP CapturePin::Disconnect()
271 {
272 #ifdef DEBUG_DSHOW
273     msg_Dbg( p_input, "CapturePin::Disconnect" );
274 #endif
275
276     p_connected_pin->Release();
277     p_connected_pin = NULL;
278     FreeMediaType( media_type );
279     return S_OK;
280 }
281 STDMETHODIMP CapturePin::ConnectedTo( IPin **pPin )
282 {
283 #ifdef DEBUG_DSHOW
284     msg_Dbg( p_input, "CapturePin::ConnectedTo" );
285 #endif
286
287     if( !p_connected_pin ) return VFW_E_NOT_CONNECTED;
288
289     p_connected_pin->AddRef();
290     *pPin = p_connected_pin;
291
292     return S_OK;
293 }
294 STDMETHODIMP CapturePin::ConnectionMediaType( AM_MEDIA_TYPE *pmt )
295 {
296 #ifdef DEBUG_DSHOW
297     msg_Dbg( p_input, "CapturePin::ConnectionMediaType" );
298 #endif
299
300     return CopyMediaType( pmt, &media_type );
301 }
302 STDMETHODIMP CapturePin::QueryPinInfo( PIN_INFO * pInfo )
303 {
304 #ifdef DEBUG_DSHOW
305     msg_Dbg( p_input, "CapturePin::QueryPinInfo" );
306 #endif
307
308     pInfo->pFilter = p_filter;
309     if( p_filter ) p_filter->AddRef();
310
311     pInfo->achName[0] = L'\0';
312
313     pInfo->dir = PINDIR_INPUT;
314
315     return NOERROR;
316 }
317 STDMETHODIMP CapturePin::QueryDirection( PIN_DIRECTION * pPinDir )
318 {
319 #ifdef DEBUG_DSHOW
320     msg_Dbg( p_input, "CapturePin::QueryDirection" );
321 #endif
322
323     *pPinDir = PINDIR_INPUT;
324     return NOERROR;
325 }
326 STDMETHODIMP CapturePin::QueryId( LPWSTR * Id )
327 {
328 #ifdef DEBUG_DSHOW
329     msg_Dbg( p_input, "CapturePin::QueryId" );
330 #endif
331     return E_NOTIMPL;
332 }
333 STDMETHODIMP CapturePin::QueryAccept( const AM_MEDIA_TYPE *pmt )
334 {
335 #ifdef DEBUG_DSHOW
336     msg_Dbg( p_input, "CapturePin::QueryAccept" );
337 #endif
338     return E_NOTIMPL;
339 }
340 STDMETHODIMP CapturePin::EnumMediaTypes( IEnumMediaTypes **ppEnum )
341 {
342 #ifdef DEBUG_DSHOW
343     msg_Dbg( p_input, "CapturePin::EnumMediaTypes" );
344 #endif
345
346     *ppEnum = new CaptureEnumMediaTypes( p_input, this, NULL );
347
348     if( *ppEnum == NULL ) return E_OUTOFMEMORY;
349
350     return NOERROR;
351 }
352 STDMETHODIMP CapturePin::QueryInternalConnections( IPin* *apPin, ULONG *nPin )
353 {
354 #ifdef DEBUG_DSHOW
355     msg_Dbg( p_input, "CapturePin::QueryInternalConnections" );
356 #endif
357     return E_NOTIMPL;
358 }
359 STDMETHODIMP CapturePin::EndOfStream( void )
360 {
361 #ifdef DEBUG_DSHOW
362     msg_Dbg( p_input, "CapturePin::EndOfStream" );
363 #endif
364     return E_NOTIMPL;
365 }
366 STDMETHODIMP CapturePin::BeginFlush( void )
367 {
368 #ifdef DEBUG_DSHOW
369     msg_Dbg( p_input, "CapturePin::BeginFlush" );
370 #endif
371     return E_NOTIMPL;
372 }
373 STDMETHODIMP CapturePin::EndFlush( void )
374 {
375 #ifdef DEBUG_DSHOW
376     msg_Dbg( p_input, "CapturePin::EndFlush" );
377 #endif
378     return E_NOTIMPL;
379 }
380 STDMETHODIMP CapturePin::NewSegment( REFERENCE_TIME tStart,
381                                      REFERENCE_TIME tStop,
382                                      double dRate )
383 {
384 #ifdef DEBUG_DSHOW
385     msg_Dbg( p_input, "CapturePin::NewSegment" );
386 #endif
387     return E_NOTIMPL;
388 }
389
390 /* IMemInputPin methods */
391 STDMETHODIMP CapturePin::GetAllocator( IMemAllocator **ppAllocator )
392 {
393 #ifdef DEBUG_DSHOW
394     msg_Dbg( p_input, "CapturePin::GetAllocator" );
395 #endif
396
397     return VFW_E_NO_ALLOCATOR;
398 }
399 STDMETHODIMP CapturePin::NotifyAllocator( IMemAllocator *pAllocator,
400                                           BOOL bReadOnly )
401 {
402 #ifdef DEBUG_DSHOW
403     msg_Dbg( p_input, "CapturePin::NotifyAllocator" );
404 #endif
405
406     return S_OK;
407 }
408 STDMETHODIMP CapturePin::GetAllocatorRequirements( ALLOCATOR_PROPERTIES *pProps )
409 {
410 #ifdef DEBUG_DSHOW
411     msg_Dbg( p_input, "CapturePin::GetAllocatorRequirements" );
412 #endif
413
414     return E_NOTIMPL;
415 }
416 STDMETHODIMP CapturePin::Receive( IMediaSample *pSample )
417 {
418 #ifdef DEBUG_DSHOW
419     //msg_Dbg( p_input, "CapturePin::Receive" );
420 #endif
421
422     pSample->AddRef();
423     mtime_t i_timestamp = mdate() * 10;
424     VLCMediaSample vlc_sample = {pSample, i_timestamp};
425
426     access_sys_t *p_sys = p_input->p_access_data;
427     vlc_mutex_lock( &p_sys->lock );
428     samples_queue.push_front( vlc_sample );
429
430     /* Make sure we don't cache too many samples */
431     if( samples_queue.size() > 10 )
432     {
433         vlc_sample = samples_queue.back();
434         samples_queue.pop_back();
435         msg_Dbg( p_input, "CapturePin::Receive trashing late input sample" );
436         vlc_sample.p_sample->Release();
437     }
438
439     vlc_cond_signal( &p_sys->wait );
440     vlc_mutex_unlock( &p_sys->lock );
441
442     return S_OK;
443 }
444 STDMETHODIMP CapturePin::ReceiveMultiple( IMediaSample **pSamples,
445                                           long nSamples,
446                                           long *nSamplesProcessed )
447 {
448 #ifdef DEBUG_DSHOW
449     msg_Dbg( p_input, "CapturePin::ReceiveMultiple" );
450 #endif
451
452     HRESULT hr = S_OK;
453
454     *nSamplesProcessed = 0;
455     while( nSamples-- > 0 )
456     {
457          hr = Receive( pSamples[*nSamplesProcessed] );
458          if( hr != S_OK ) break;
459          (*nSamplesProcessed)++;
460     }
461     return hr;
462 }
463 STDMETHODIMP CapturePin::ReceiveCanBlock( void )
464 {
465 #ifdef DEBUG_DSHOW
466     msg_Dbg( p_input, "CapturePin::ReceiveCanBlock" );
467 #endif
468
469     return S_FALSE; /* Thou shalt not block */
470 }
471
472 /****************************************************************************
473  * Implementation of our dummy directshow filter class
474  ****************************************************************************/
475
476 CaptureFilter::CaptureFilter( input_thread_t * _p_input, AM_MEDIA_TYPE mt )
477   : p_input( _p_input ), p_pin( new CapturePin( _p_input, this, mt ) ),
478     media_type( mt ), i_ref( 1 )
479 {
480 }
481
482 CaptureFilter::~CaptureFilter()
483 {
484     p_pin->Release();
485 }
486
487 /* IUnknown methods */
488 STDMETHODIMP CaptureFilter::QueryInterface( REFIID riid, void **ppv )
489 {
490 #ifdef DEBUG_DSHOW
491     msg_Dbg( p_input, "CaptureFilter::QueryInterface" );
492 #endif
493
494     if( riid == IID_IUnknown )
495     {
496         AddRef();
497         *ppv = (IUnknown *)this;
498         return NOERROR;
499     }
500     if( riid == IID_IPersist )
501     {
502         AddRef();
503         *ppv = (IPersist *)this;
504         return NOERROR;
505     }
506     if( riid == IID_IMediaFilter )
507     {
508         AddRef();
509         *ppv = (IMediaFilter *)this;
510         return NOERROR;
511     }
512     if( riid == IID_IBaseFilter )
513     {
514         AddRef();
515         *ppv = (IBaseFilter *)this;
516         return NOERROR;
517     }
518     else
519     {
520         *ppv = NULL;
521         return E_NOINTERFACE;
522     }
523 };
524 STDMETHODIMP_(ULONG) CaptureFilter::AddRef()
525 {
526 #ifdef DEBUG_DSHOW
527     msg_Dbg( p_input, "CaptureFilter::AddRef (ref: %i)", i_ref );
528 #endif
529
530     return i_ref++;
531 };
532 STDMETHODIMP_(ULONG) CaptureFilter::Release()
533 {
534 #ifdef DEBUG_DSHOW
535     msg_Dbg( p_input, "CaptureFilter::Release (ref: %i)", i_ref );
536 #endif
537
538     if( !InterlockedDecrement(&i_ref) ) delete this;
539
540     return 0;
541 };
542
543 /* IPersist method */
544 STDMETHODIMP CaptureFilter::GetClassID(CLSID *pClsID)
545 {
546 #ifdef DEBUG_DSHOW
547     msg_Dbg( p_input, "CaptureFilter::GetClassID" );
548 #endif
549     return E_NOTIMPL;
550 };
551
552 /* IMediaFilter methods */
553 STDMETHODIMP CaptureFilter::GetState(DWORD dwMSecs, FILTER_STATE *State)
554 {
555 #ifdef DEBUG_DSHOW
556     msg_Dbg( p_input, "CaptureFilter::GetStat" );
557 #endif
558     return E_NOTIMPL;
559 };
560 STDMETHODIMP CaptureFilter::SetSyncSource(IReferenceClock *pClock)
561 {
562 #ifdef DEBUG_DSHOW
563     msg_Dbg( p_input, "CaptureFilter::SetSyncSource" );
564 #endif
565
566     return NOERROR;
567 };
568 STDMETHODIMP CaptureFilter::GetSyncSource(IReferenceClock **pClock)
569 {
570 #ifdef DEBUG_DSHOW
571     msg_Dbg( p_input, "CaptureFilter::GetSyncSource" );
572 #endif
573
574     *pClock = NULL;
575     return NOERROR;
576 };
577 STDMETHODIMP CaptureFilter::Stop()
578 {
579 #ifdef DEBUG_DSHOW
580     msg_Dbg( p_input, "CaptureFilter::Stop" );
581 #endif
582     return S_OK;
583 };
584 STDMETHODIMP CaptureFilter::Pause()
585 {
586 #ifdef DEBUG_DSHOW
587     msg_Dbg( p_input, "CaptureFilter::Pause" );
588 #endif
589     return S_OK;
590 };
591 STDMETHODIMP CaptureFilter::Run(REFERENCE_TIME tStart)
592 {
593 #ifdef DEBUG_DSHOW
594     msg_Dbg( p_input, "CaptureFilter::Run" );
595 #endif
596     return S_OK;
597 };
598
599 /* IBaseFilter methods */
600 STDMETHODIMP CaptureFilter::EnumPins( IEnumPins ** ppEnum )
601 {
602 #ifdef DEBUG_DSHOW
603     msg_Dbg( p_input, "CaptureFilter::EnumPins" );
604 #endif
605
606     /* Create a new ref counted enumerator */
607     *ppEnum = new CaptureEnumPins( p_input, this, NULL );
608     return *ppEnum == NULL ? E_OUTOFMEMORY : NOERROR;
609 };
610 STDMETHODIMP CaptureFilter::FindPin( LPCWSTR Id, IPin ** ppPin )
611 {
612 #ifdef DEBUG_DSHOW
613     msg_Dbg( p_input, "CaptureFilter::FindPin" );
614 #endif
615     return E_NOTIMPL;
616 };
617 STDMETHODIMP CaptureFilter::QueryFilterInfo( FILTER_INFO * pInfo )
618 {
619 #ifdef DEBUG_DSHOW
620     msg_Dbg( p_input, "CaptureFilter::QueryFilterInfo" );
621 #endif
622
623     pInfo->achName[0] = L'\0';
624
625     pInfo->pGraph = p_graph;
626     if( p_graph ) p_graph->AddRef();
627
628     return NOERROR;
629 };
630 STDMETHODIMP CaptureFilter::JoinFilterGraph( IFilterGraph * pGraph,
631                                              LPCWSTR pName )
632 {
633 #ifdef DEBUG_DSHOW
634     msg_Dbg( p_input, "CaptureFilter::JoinFilterGraph" );
635 #endif
636
637     p_graph = pGraph;
638
639     return NOERROR;
640 };
641 STDMETHODIMP CaptureFilter::QueryVendorInfo( LPWSTR* pVendorInfo )
642 {
643 #ifdef DEBUG_DSHOW
644     msg_Dbg( p_input, "CaptureFilter::QueryVendorInfo" );
645 #endif
646     return E_NOTIMPL;
647 };
648
649 /* Custom methods */
650 CapturePin *CaptureFilter::CustomGetPin()
651 {
652     return p_pin;
653 }
654
655 /****************************************************************************
656  * Implementation of our dummy directshow enumpins class
657  ****************************************************************************/
658
659 CaptureEnumPins::CaptureEnumPins( input_thread_t * _p_input,
660                                   CaptureFilter *_p_filter,
661                                   CaptureEnumPins *pEnumPins )
662   : p_input( _p_input ), p_filter( _p_filter ), i_ref( 1 )
663 {
664     /* Hold a reference count on our filter */
665     p_filter->AddRef();
666
667     /* Are we creating a new enumerator */
668
669     if( pEnumPins == NULL )
670     {
671         i_position = 0;
672     }
673     else
674     {
675         i_position = pEnumPins->i_position;
676     }
677 }
678
679 CaptureEnumPins::~CaptureEnumPins()
680 {
681     p_filter->Release();
682 }
683
684 /* IUnknown methods */
685 STDMETHODIMP CaptureEnumPins::QueryInterface( REFIID riid, void **ppv )
686 {
687 #ifdef DEBUG_DSHOW
688     msg_Dbg( p_input, "CaptureEnumPins::QueryInterface" );
689 #endif
690
691     if( riid == IID_IUnknown ||
692         riid == IID_IEnumPins )
693     {
694         AddRef();
695         *ppv = (IEnumPins *)this;
696         return NOERROR;
697     }
698     else
699     {
700         *ppv = NULL;
701         return E_NOINTERFACE;
702     }
703 };
704 STDMETHODIMP_(ULONG) CaptureEnumPins::AddRef()
705 {
706 #ifdef DEBUG_DSHOW
707     msg_Dbg( p_input, "CaptureEnumPins::AddRef (ref: %i)", i_ref );
708 #endif
709
710     return i_ref++;
711 };
712 STDMETHODIMP_(ULONG) CaptureEnumPins::Release()
713 {
714 #ifdef DEBUG_DSHOW
715     msg_Dbg( p_input, "CaptureEnumPins::Release (ref: %i)", i_ref );
716 #endif
717
718     if( !InterlockedDecrement(&i_ref) ) delete this;
719
720     return 0;
721 };
722
723 /* IEnumPins */
724 STDMETHODIMP CaptureEnumPins::Next( ULONG cPins, IPin ** ppPins,
725                                     ULONG * pcFetched )
726 {
727 #ifdef DEBUG_DSHOW
728     msg_Dbg( p_input, "CaptureEnumPins::Next" );
729 #endif
730
731     *pcFetched = 0;
732
733     if( i_position < 1 && cPins > 0 )
734     {
735         IPin *pPin = p_filter->CustomGetPin();
736         *ppPins = pPin;
737         pPin->AddRef();
738         *pcFetched = 1;
739         i_position++;
740     }
741
742     return *pcFetched == cPins ? NOERROR : S_FALSE;
743 };
744 STDMETHODIMP CaptureEnumPins::Skip( ULONG cPins )
745 {
746 #ifdef DEBUG_DSHOW
747     msg_Dbg( p_input, "CaptureEnumPins::Skip" );
748 #endif
749
750     if( cPins > 1 )
751     {
752         return S_FALSE;
753     }
754
755     i_position += cPins;
756     return NOERROR;
757 };
758 STDMETHODIMP CaptureEnumPins::Reset()
759 {
760 #ifdef DEBUG_DSHOW
761     msg_Dbg( p_input, "CaptureEnumPins::Reset" );
762 #endif
763
764     i_position = 0;
765     return S_OK;
766 };
767 STDMETHODIMP CaptureEnumPins::Clone( IEnumPins **ppEnum )
768 {
769 #ifdef DEBUG_DSHOW
770     msg_Dbg( p_input, "CaptureEnumPins::Clone" );
771 #endif
772
773     *ppEnum = new CaptureEnumPins( p_input, p_filter, this );
774     if( *ppEnum == NULL ) return E_OUTOFMEMORY;
775
776     return NOERROR;
777 };
778
779 /****************************************************************************
780  * Implementation of our dummy directshow enummediatypes class
781  ****************************************************************************/
782
783 CaptureEnumMediaTypes::CaptureEnumMediaTypes( input_thread_t * _p_input,
784                                   CapturePin *_p_pin,
785                                   CaptureEnumMediaTypes *pEnumMediaTypes )
786   : p_input( _p_input ), p_pin( _p_pin ), i_ref( 1 )
787 {
788     /* Hold a reference count on our filter */
789     p_pin->AddRef();
790
791     /* Are we creating a new enumerator */
792     if( pEnumMediaTypes == NULL )
793     {
794         i_position = 0;
795     }
796     else
797     {
798         i_position = pEnumMediaTypes->i_position;
799     }
800 }
801
802 CaptureEnumMediaTypes::~CaptureEnumMediaTypes()
803 {
804     p_pin->Release();
805 }
806
807 /* IUnknown methods */
808 STDMETHODIMP CaptureEnumMediaTypes::QueryInterface( REFIID riid, void **ppv )
809 {
810 #ifdef DEBUG_DSHOW
811     msg_Dbg( p_input, "CaptureEnumMediaTypes::QueryInterface" );
812 #endif
813
814     if( riid == IID_IUnknown ||
815         riid == IID_IEnumMediaTypes )
816     {
817         AddRef();
818         *ppv = (IEnumMediaTypes *)this;
819         return NOERROR;
820     }
821     else
822     {
823         *ppv = NULL;
824         return E_NOINTERFACE;
825     }
826 };
827 STDMETHODIMP_(ULONG) CaptureEnumMediaTypes::AddRef()
828 {
829 #ifdef DEBUG_DSHOW
830     msg_Dbg( p_input, "CaptureEnumMediaTypes::AddRef (ref: %i)", i_ref );
831 #endif
832
833     return i_ref++;
834 };
835 STDMETHODIMP_(ULONG) CaptureEnumMediaTypes::Release()
836 {
837 #ifdef DEBUG_DSHOW
838     msg_Dbg( p_input, "CaptureEnumMediaTypes::Release (ref: %i)", i_ref );
839 #endif
840
841     if( !InterlockedDecrement(&i_ref) ) delete this;
842
843     return 0;
844 };
845
846 /* IEnumMediaTypes */
847 STDMETHODIMP CaptureEnumMediaTypes::Next( ULONG cMediaTypes,
848                                           AM_MEDIA_TYPE ** ppMediaTypes,
849                                           ULONG * pcFetched )
850 {
851 #ifdef DEBUG_DSHOW
852     msg_Dbg( p_input, "CaptureEnumMediaTypes::Next" );
853 #endif
854
855     if( pcFetched ) *pcFetched = 0;
856     return S_FALSE;
857 };
858 STDMETHODIMP CaptureEnumMediaTypes::Skip( ULONG cMediaTypes )
859 {
860 #ifdef DEBUG_DSHOW
861     msg_Dbg( p_input, "CaptureEnumMediaTypes::Skip" );
862 #endif
863
864     return S_FALSE;
865 };
866 STDMETHODIMP CaptureEnumMediaTypes::Reset()
867 {
868 #ifdef DEBUG_DSHOW
869     msg_Dbg( p_input, "CaptureEnumMediaTypes::Reset" );
870 #endif
871
872     i_position = 0;
873     return S_OK;
874 };
875 STDMETHODIMP CaptureEnumMediaTypes::Clone( IEnumMediaTypes **ppEnum )
876 {
877 #ifdef DEBUG_DSHOW
878     msg_Dbg( p_input, "CaptureEnumMediaTypes::Clone" );
879 #endif
880
881     *ppEnum = new CaptureEnumMediaTypes( p_input, p_pin, this );
882     if( *ppEnum == NULL ) return E_OUTOFMEMORY;
883
884     return NOERROR;
885 };