]> git.sesse.net Git - vlc/blob - modules/access/dshow/filter.cpp
* modules/access/dshow/*: audio is now supported as well.
[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.2 2003/08/25 21:45:04 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         *ppv = (IPin *)this;
184         return NOERROR;
185     }
186     if( riid == IID_IMemInputPin )
187     {
188         *ppv = (IMemInputPin *)this;
189         return NOERROR;
190     }
191     else
192     {
193         *ppv = NULL;
194         return E_NOINTERFACE;
195     }
196 }
197 STDMETHODIMP_(ULONG) CapturePin::AddRef()
198 {
199 #ifdef DEBUG_DSHOW
200     msg_Dbg( p_input, "CapturePin::AddRef" );
201 #endif
202
203     i_ref++;
204     return NOERROR;
205 };
206 STDMETHODIMP_(ULONG) CapturePin::Release()
207 {
208 #ifdef DEBUG_DSHOW
209     msg_Dbg( p_input, "CapturePin::Release" );
210 #endif
211
212     i_ref--;
213     if( !i_ref ) delete this;
214
215     return NOERROR;
216 };
217
218 /* IPin methods */
219 STDMETHODIMP CapturePin::Connect( IPin * pReceivePin,
220                                   const AM_MEDIA_TYPE *pmt )
221 {
222 #ifdef DEBUG_DSHOW
223     msg_Dbg( p_input, "CapturePin::Connect" );
224 #endif
225     return E_NOTIMPL;
226 }
227 STDMETHODIMP CapturePin::ReceiveConnection( IPin * pConnector,
228                                             const AM_MEDIA_TYPE *pmt )
229 {
230 #ifdef DEBUG_DSHOW
231     msg_Dbg( p_input, "CapturePin::ReceiveConnection" );
232 #endif
233
234     p_connected_pin = pConnector;
235     p_connected_pin->AddRef();
236     return CopyMediaType( &media_type, pmt );
237 }
238 STDMETHODIMP CapturePin::Disconnect()
239 {
240 #ifdef DEBUG_DSHOW
241     msg_Dbg( p_input, "CapturePin::Disconnect" );
242 #endif
243
244     p_connected_pin->Release();
245     p_connected_pin = NULL;
246     FreeMediaType( media_type );
247     return S_OK;
248 }
249 STDMETHODIMP CapturePin::ConnectedTo( IPin **pPin )
250 {
251 #ifdef DEBUG_DSHOW
252     msg_Dbg( p_input, "CapturePin::ConnectedTo" );
253 #endif
254
255     p_connected_pin->AddRef();
256     *pPin = p_connected_pin;
257
258     return S_OK;
259 }
260 STDMETHODIMP CapturePin::ConnectionMediaType( AM_MEDIA_TYPE *pmt )
261 {
262 #ifdef DEBUG_DSHOW
263     msg_Dbg( p_input, "CapturePin::ConnectionMediaType" );
264 #endif
265
266     return CopyMediaType( pmt, &media_type );
267 }
268 STDMETHODIMP CapturePin::QueryPinInfo( PIN_INFO * pInfo )
269 {
270 #ifdef DEBUG_DSHOW
271     msg_Dbg( p_input, "CapturePin::QueryPinInfo" );
272 #endif
273
274     pInfo->pFilter = p_filter;
275     if( p_filter ) p_filter->AddRef();
276
277     pInfo->achName[0] = L'\0';
278
279     pInfo->dir = PINDIR_INPUT;
280
281     return NOERROR;
282 }
283 STDMETHODIMP CapturePin::QueryDirection( PIN_DIRECTION * pPinDir )
284 {
285 #ifdef DEBUG_DSHOW
286     msg_Dbg( p_input, "CapturePin::QueryDirection" );
287 #endif
288
289     *pPinDir = PINDIR_INPUT;
290     return NOERROR;
291 }
292 STDMETHODIMP CapturePin::QueryId( LPWSTR * Id )
293 {
294 #ifdef DEBUG_DSHOW
295     msg_Dbg( p_input, "CapturePin::QueryId" );
296 #endif
297     return E_NOTIMPL;
298 }
299 STDMETHODIMP CapturePin::QueryAccept( const AM_MEDIA_TYPE *pmt )
300 {
301 #ifdef DEBUG_DSHOW
302     msg_Dbg( p_input, "CapturePin::QueryAccept" );
303 #endif
304     return E_NOTIMPL;
305 }
306 STDMETHODIMP CapturePin::EnumMediaTypes( IEnumMediaTypes **ppEnum )
307 {
308 #ifdef DEBUG_DSHOW
309     msg_Dbg( p_input, "CapturePin::EnumMediaTypes" );
310 #endif
311
312     *ppEnum = new CaptureEnumMediaTypes( p_input, this, NULL );
313
314     if( *ppEnum == NULL ) return E_OUTOFMEMORY;
315
316     return NOERROR;
317 }
318 STDMETHODIMP CapturePin::QueryInternalConnections( IPin* *apPin, ULONG *nPin )
319 {
320 #ifdef DEBUG_DSHOW
321     msg_Dbg( p_input, "CapturePin::QueryInternalConnections" );
322 #endif
323     return E_NOTIMPL;
324 }
325 STDMETHODIMP CapturePin::EndOfStream( void )
326 {
327 #ifdef DEBUG_DSHOW
328     msg_Dbg( p_input, "CapturePin::EndOfStream" );
329 #endif
330     return E_NOTIMPL;
331 }
332 STDMETHODIMP CapturePin::BeginFlush( void )
333 {
334 #ifdef DEBUG_DSHOW
335     msg_Dbg( p_input, "CapturePin::BeginFlush" );
336 #endif
337     return E_NOTIMPL;
338 }
339 STDMETHODIMP CapturePin::EndFlush( void )
340 {
341 #ifdef DEBUG_DSHOW
342     msg_Dbg( p_input, "CapturePin::EndFlush" );
343 #endif
344     return E_NOTIMPL;
345 }
346 STDMETHODIMP CapturePin::NewSegment( REFERENCE_TIME tStart,
347                                      REFERENCE_TIME tStop,
348                                      double dRate )
349 {
350 #ifdef DEBUG_DSHOW
351     msg_Dbg( p_input, "CapturePin::NewSegment" );
352 #endif
353     return E_NOTIMPL;
354 }
355
356 /* IMemInputPin methods */
357 STDMETHODIMP CapturePin::GetAllocator( IMemAllocator **ppAllocator )
358 {
359 #ifdef DEBUG_DSHOW
360     msg_Dbg( p_input, "CapturePin::GetAllocator" );
361 #endif
362
363     return VFW_E_NO_ALLOCATOR;
364 }
365 STDMETHODIMP CapturePin::NotifyAllocator( IMemAllocator *pAllocator,
366                                           BOOL bReadOnly )
367 {
368 #ifdef DEBUG_DSHOW
369     msg_Dbg( p_input, "CapturePin::NotifyAllocator" );
370 #endif
371
372     return S_OK;
373 }
374 STDMETHODIMP CapturePin::GetAllocatorRequirements( ALLOCATOR_PROPERTIES *pProps )
375 {
376 #ifdef DEBUG_DSHOW
377     msg_Dbg( p_input, "CapturePin::GetAllocatorRequirements" );
378 #endif
379     return E_NOTIMPL;
380 }
381 STDMETHODIMP CapturePin::Receive( IMediaSample *pSample )
382 {
383 #ifdef DEBUG_DSHOW
384     //msg_Dbg( p_input, "CapturePin::Receive" );
385 #endif
386
387     //pSample->AddRef();
388     mtime_t i_timestamp = mdate() * 10;
389     VLCMediaSample vlc_sample = {pSample, i_timestamp};
390     samples_queue.push_front( vlc_sample );
391
392     /* Make sure we don't cache too many samples */
393     if( samples_queue.size() > 10 )
394     {
395         vlc_sample = samples_queue.back();
396         samples_queue.pop_back();
397         msg_Dbg( p_input, "CapturePin::Receive trashing late input sample" );
398         // vlc_sample.p_sample->Release();
399     }
400
401     return S_OK;
402 }
403 STDMETHODIMP CapturePin::ReceiveMultiple( IMediaSample **pSamples,
404                                           long nSamples,
405                                           long *nSamplesProcessed )
406 {
407 #ifdef DEBUG_DSHOW
408     msg_Dbg( p_input, "CapturePin::ReceiveMultiple" );
409 #endif
410
411     HRESULT hr = S_OK;
412
413     *nSamplesProcessed = 0;
414     while( nSamples-- > 0 )
415     {
416          hr = Receive( pSamples[*nSamplesProcessed] );
417          if( hr != S_OK ) break;
418          (*nSamplesProcessed)++;
419     }
420     return hr;
421 }
422 STDMETHODIMP CapturePin::ReceiveCanBlock( void )
423 {
424 #ifdef DEBUG_DSHOW
425     msg_Dbg( p_input, "CapturePin::ReceiveCanBlock" );
426 #endif
427
428     return S_FALSE; /* Thou shalt not block */
429 }
430
431 /****************************************************************************
432  * Implementation of our dummy directshow filter class
433  ****************************************************************************/
434
435 CaptureFilter::CaptureFilter( input_thread_t * _p_input )
436   : p_input( _p_input ), p_pin( new CapturePin( _p_input, this ) ),
437     i_ref( 1 )
438 {
439 }
440
441 CaptureFilter::~CaptureFilter()
442 {
443     p_pin->Release();
444 }
445
446 /* IUnknown methods */
447 STDMETHODIMP CaptureFilter::QueryInterface( REFIID riid, void **ppv )
448 {
449 #ifdef DEBUG_DSHOW
450     msg_Dbg( p_input, "CaptureFilter::QueryInterface" );
451 #endif
452
453     if( riid == IID_IUnknown )
454     {
455         *ppv = (IUnknown *)this;
456         return NOERROR;
457     }
458     if( riid == IID_IPersist )
459     {
460         *ppv = (IPersist *)this;
461         return NOERROR;
462     }
463     if( riid == IID_IMediaFilter )
464     {
465         *ppv = (IMediaFilter *)this;
466         return NOERROR;
467     }
468     if( riid == IID_IBaseFilter )
469     {
470         *ppv = (IBaseFilter *)this;
471         return NOERROR;
472     }
473     else
474     {
475         *ppv = NULL;
476         return E_NOINTERFACE;
477     }
478 };
479 STDMETHODIMP_(ULONG) CaptureFilter::AddRef()
480 {
481 #ifdef DEBUG_DSHOW
482     msg_Dbg( p_input, "CaptureFilter::AddRef" );
483 #endif
484
485     i_ref++;
486     return NOERROR;
487 };
488 STDMETHODIMP_(ULONG) CaptureFilter::Release()
489 {
490 #ifdef DEBUG_DSHOW
491     msg_Dbg( p_input, "CaptureFilter::Release" );
492 #endif
493
494     i_ref--;
495     if( !i_ref ) delete this;
496
497     return NOERROR;
498 };
499
500 /* IPersist method */
501 STDMETHODIMP CaptureFilter::GetClassID(CLSID *pClsID)
502 {
503 #ifdef DEBUG_DSHOW
504     msg_Dbg( p_input, "CaptureFilter::GetClassID" );
505 #endif
506     return E_NOTIMPL;
507 };
508
509 /* IMediaFilter methods */
510 STDMETHODIMP CaptureFilter::GetState(DWORD dwMSecs, FILTER_STATE *State)
511 {
512 #ifdef DEBUG_DSHOW
513     msg_Dbg( p_input, "CaptureFilter::GetStat" );
514 #endif
515     return E_NOTIMPL;
516 };
517 STDMETHODIMP CaptureFilter::SetSyncSource(IReferenceClock *pClock)
518 {
519 #ifdef DEBUG_DSHOW
520     msg_Dbg( p_input, "CaptureFilter::SetSyncSource" );
521 #endif
522
523     return NOERROR;
524 };
525 STDMETHODIMP CaptureFilter::GetSyncSource(IReferenceClock **pClock)
526 {
527 #ifdef DEBUG_DSHOW
528     msg_Dbg( p_input, "CaptureFilter::GetSyncSource" );
529 #endif
530     return E_NOTIMPL;
531 };
532 STDMETHODIMP CaptureFilter::Stop()
533 {
534 #ifdef DEBUG_DSHOW
535     msg_Dbg( p_input, "CaptureFilter::Stop" );
536 #endif
537     return E_NOTIMPL;
538 };
539 STDMETHODIMP CaptureFilter::Pause()
540 {
541 #ifdef DEBUG_DSHOW
542     msg_Dbg( p_input, "CaptureFilter::Pause" );
543 #endif
544     return E_NOTIMPL;
545 };
546 STDMETHODIMP CaptureFilter::Run(REFERENCE_TIME tStart)
547 {
548 #ifdef DEBUG_DSHOW
549     msg_Dbg( p_input, "CaptureFilter::Run" );
550 #endif
551     return E_NOTIMPL;
552 };
553
554 /* IBaseFilter methods */
555 STDMETHODIMP CaptureFilter::EnumPins( IEnumPins ** ppEnum )
556 {
557 #ifdef DEBUG_DSHOW
558     msg_Dbg( p_input, "CaptureFilter::EnumPins" );
559 #endif
560
561     /* Create a new ref counted enumerator */
562     *ppEnum = new CaptureEnumPins( p_input, this, NULL );
563     return *ppEnum == NULL ? E_OUTOFMEMORY : NOERROR;
564 };
565 STDMETHODIMP CaptureFilter::FindPin( LPCWSTR Id, IPin ** ppPin )
566 {
567 #ifdef DEBUG_DSHOW
568     msg_Dbg( p_input, "CaptureFilter::FindPin" );
569 #endif
570     return E_NOTIMPL;
571 };
572 STDMETHODIMP CaptureFilter::QueryFilterInfo( FILTER_INFO * pInfo )
573 {
574 #ifdef DEBUG_DSHOW
575     msg_Dbg( p_input, "CaptureFilter::QueryFilterInfo" );
576 #endif
577
578     pInfo->achName[0] = L'\0';
579
580     pInfo->pGraph = p_graph;
581     if( p_graph ) p_graph->AddRef();
582
583     return NOERROR;
584 };
585 STDMETHODIMP CaptureFilter::JoinFilterGraph( IFilterGraph * pGraph,
586                                              LPCWSTR pName )
587 {
588 #ifdef DEBUG_DSHOW
589     msg_Dbg( p_input, "CaptureFilter::JoinFilterGraph" );
590 #endif
591
592     p_graph = pGraph;
593
594     return NOERROR;
595 };
596 STDMETHODIMP CaptureFilter::QueryVendorInfo( LPWSTR* pVendorInfo )
597 {
598 #ifdef DEBUG_DSHOW
599     msg_Dbg( p_input, "CaptureFilter::QueryVendorInfo" );
600 #endif
601     return E_NOTIMPL;
602 };
603
604 /* Custom methods */
605 CapturePin *CaptureFilter::CustomGetPin()
606 {
607     return p_pin;
608 }
609
610 /****************************************************************************
611  * Implementation of our dummy directshow enumpins class
612  ****************************************************************************/
613
614 CaptureEnumPins::CaptureEnumPins( input_thread_t * _p_input,
615                                   CaptureFilter *_p_filter,
616                                   CaptureEnumPins *pEnumPins )
617   : p_input( _p_input ), p_filter( _p_filter ), i_ref( 1 )
618 {
619     /* Hold a reference count on our filter */
620     p_filter->AddRef();
621
622     /* Are we creating a new enumerator */
623
624     if( pEnumPins == NULL )
625     {
626         i_position = 0;
627     }
628     else
629     {
630         i_position = pEnumPins->i_position;
631     }
632 }
633
634 CaptureEnumPins::~CaptureEnumPins()
635 {
636     p_filter->Release();
637 }
638
639 /* IUnknown methods */
640 STDMETHODIMP CaptureEnumPins::QueryInterface( REFIID riid, void **ppv )
641 {
642 #ifdef DEBUG_DSHOW
643     msg_Dbg( p_input, "CaptureEnumPins::QueryInterface" );
644 #endif
645
646     if( riid == IID_IUnknown ||
647         riid == IID_IEnumPins )
648     {
649         *ppv = (IEnumPins *)this;
650         return NOERROR;
651     }
652     else
653     {
654         *ppv = NULL;
655         return E_NOINTERFACE;
656     }
657 };
658 STDMETHODIMP_(ULONG) CaptureEnumPins::AddRef()
659 {
660 #ifdef DEBUG_DSHOW
661     msg_Dbg( p_input, "CaptureEnumPins::AddRef" );
662 #endif
663
664     i_ref++;
665     return NOERROR;
666 };
667 STDMETHODIMP_(ULONG) CaptureEnumPins::Release()
668 {
669 #ifdef DEBUG_DSHOW
670     msg_Dbg( p_input, "CaptureEnumPins::Release" );
671 #endif
672
673     i_ref--;
674     if( !i_ref ) delete this;
675
676     return NOERROR;
677 };
678
679 /* IEnumPins */
680 STDMETHODIMP CaptureEnumPins::Next( ULONG cPins, IPin ** ppPins,
681                                     ULONG * pcFetched )
682 {
683 #ifdef DEBUG_DSHOW
684     msg_Dbg( p_input, "CaptureEnumPins::Next" );
685 #endif
686
687     *pcFetched = 0;
688
689     if( i_position < 1 && cPins > 0 )
690     {
691         IPin *pPin = p_filter->CustomGetPin();
692         *ppPins = pPin;
693         pPin->AddRef();
694         *pcFetched = 1;
695         i_position++;
696         return NOERROR;
697     }
698
699     return S_FALSE;
700 };
701 STDMETHODIMP CaptureEnumPins::Skip( ULONG cPins )
702 {
703 #ifdef DEBUG_DSHOW
704     msg_Dbg( p_input, "CaptureEnumPins::Skip" );
705 #endif
706
707     if( cPins > 1 )
708     {
709         return S_FALSE;
710     }
711
712     i_position += cPins;
713     return NOERROR;
714 };
715 STDMETHODIMP CaptureEnumPins::Reset()
716 {
717 #ifdef DEBUG_DSHOW
718     msg_Dbg( p_input, "CaptureEnumPins::Reset" );
719 #endif
720
721     i_position = 0;
722     return S_OK;
723 };
724 STDMETHODIMP CaptureEnumPins::Clone( IEnumPins **ppEnum )
725 {
726 #ifdef DEBUG_DSHOW
727     msg_Dbg( p_input, "CaptureEnumPins::Clone" );
728 #endif
729
730     *ppEnum = new CaptureEnumPins( p_input, p_filter, this );
731     if( *ppEnum == NULL ) return E_OUTOFMEMORY;
732
733     return NOERROR;
734 };
735
736 /****************************************************************************
737  * Implementation of our dummy directshow enummediatypes class
738  ****************************************************************************/
739
740 CaptureEnumMediaTypes::CaptureEnumMediaTypes( input_thread_t * _p_input,
741                                   CapturePin *_p_pin,
742                                   CaptureEnumMediaTypes *pEnumMediaTypes )
743   : p_input( _p_input ), p_pin( _p_pin ), i_ref( 1 )
744 {
745     /* Hold a reference count on our filter */
746     p_pin->AddRef();
747
748     /* Are we creating a new enumerator */
749
750     if( pEnumMediaTypes == NULL )
751     {
752         i_position = 0;
753     }
754     else
755     {
756         i_position = pEnumMediaTypes->i_position;
757     }
758 }
759
760 CaptureEnumMediaTypes::~CaptureEnumMediaTypes()
761 {
762     p_pin->Release();
763 }
764
765 /* IUnknown methods */
766 STDMETHODIMP CaptureEnumMediaTypes::QueryInterface( REFIID riid, void **ppv )
767 {
768 #ifdef DEBUG_DSHOW
769     msg_Dbg( p_input, "CaptureEnumMediaTypes::QueryInterface" );
770 #endif
771
772     if( riid == IID_IUnknown ||
773         riid == IID_IEnumMediaTypes )
774     {
775         *ppv = (IEnumMediaTypes *)this;
776         return NOERROR;
777     }
778     else
779     {
780         *ppv = NULL;
781         return E_NOINTERFACE;
782     }
783 };
784 STDMETHODIMP_(ULONG) CaptureEnumMediaTypes::AddRef()
785 {
786 #ifdef DEBUG_DSHOW
787     msg_Dbg( p_input, "CaptureEnumMediaTypes::AddRef" );
788 #endif
789
790     i_ref++;
791     return NOERROR;
792 };
793 STDMETHODIMP_(ULONG) CaptureEnumMediaTypes::Release()
794 {
795 #ifdef DEBUG_DSHOW
796     msg_Dbg( p_input, "CaptureEnumMediaTypes::Release" );
797 #endif
798
799     i_ref--;
800     if( !i_ref ) delete this;
801
802     return NOERROR;
803 };
804
805 /* IEnumMediaTypes */
806 STDMETHODIMP CaptureEnumMediaTypes::Next( ULONG cMediaTypes,
807                                           AM_MEDIA_TYPE ** ppMediaTypes,
808                                           ULONG * pcFetched )
809 {
810 #ifdef DEBUG_DSHOW
811     msg_Dbg( p_input, "CaptureEnumMediaTypes::Next" );
812 #endif
813
814     *pcFetched = 0;
815
816 #if 0
817     if( i_position < 1 && cMediaTypes > 0 )
818     {
819         IPin *pPin = p_pin->CustomGetPin();
820         *ppMediaTypes = pPin;
821         pPin->AddRef();
822         *pcFetched = 1;
823         i_position++;
824         return NOERROR;
825     }
826 #endif
827
828     return S_FALSE;
829 };
830 STDMETHODIMP CaptureEnumMediaTypes::Skip( ULONG cMediaTypes )
831 {
832 #ifdef DEBUG_DSHOW
833     msg_Dbg( p_input, "CaptureEnumMediaTypes::Skip" );
834 #endif
835
836     if( cMediaTypes > 1 )
837     {
838         return S_FALSE;
839     }
840
841     i_position += cMediaTypes;
842     return NOERROR;
843 };
844 STDMETHODIMP CaptureEnumMediaTypes::Reset()
845 {
846 #ifdef DEBUG_DSHOW
847     msg_Dbg( p_input, "CaptureEnumMediaTypes::Reset" );
848 #endif
849
850     i_position = 0;
851     return S_OK;
852 };
853 STDMETHODIMP CaptureEnumMediaTypes::Clone( IEnumMediaTypes **ppEnum )
854 {
855 #ifdef DEBUG_DSHOW
856     msg_Dbg( p_input, "CaptureEnumMediaTypes::Clone" );
857 #endif
858
859     *ppEnum = new CaptureEnumMediaTypes( p_input, p_pin, this );
860     if( *ppEnum == NULL ) return E_OUTOFMEMORY;
861
862     return NOERROR;
863 };