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