1 /*****************************************************************************
2 * filter.c : DirectShow access module for vlc
3 *****************************************************************************
4 * Copyright (C) 2002 VideoLAN
5 * $Id: filter.cpp,v 1.13 2004/02/16 13:33:10 gbazin Exp $
7 * Author: Gildas Bazin <gbazin@netcourrier.com>
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.
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.
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 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
32 #include <vlc/input.h>
36 /* Work-around a bug in w32api-2.5 */
37 # define QACONTAINERFLAGS QACONTAINERFLAGS_SOMETHINGELSE
50 /*****************************************************************************
52 * Easier to define them hear as mingw doesn't provide them all.
53 *****************************************************************************/
54 const GUID CLSID_SystemDeviceEnum = {0x62be5d10, 0x60eb, 0x11d0, {0xbd, 0x3b, 0x00, 0xa0, 0xc9, 0x11, 0xce, 0x86}};
55 const GUID CLSID_VideoInputDeviceCategory = {0x860BB310,0x5D01,0x11d0,{0xBD,0x3B,0x00,0xA0,0xC9,0x11,0xCE,0x86}};
56 const GUID CLSID_AudioInputDeviceCategory = {0x33d9a762, 0x90c8, 0x11d0, {0xbd, 0x43, 0x00, 0xa0, 0xc9, 0x11, 0xce, 0x86}};
57 const GUID IID_IPropertyBag = {0x55272A00, 0x42CB, 0x11CE, {0x81, 0x35, 0x00, 0xAA, 0x00, 0x4B, 0xB8, 0x51}};
58 const GUID IID_ICreateDevEnum = {0x29840822, 0x5b84, 0x11d0, {0xbd, 0x3b, 0x00, 0xa0, 0xc9, 0x11, 0xce, 0x86}};
59 const GUID IID_IFilterGraph = {0x56a8689f, 0x0ad4, 0x11ce, {0xb0, 0x3a, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70}};
60 const GUID IID_IMediaControl = {0x56a868b1, 0x0ad4, 0x11ce, {0xb0, 0x3a, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70}};
61 const GUID CLSID_FilterGraph = {0xe436ebb3, 0x524f, 0x11ce, {0x9f, 0x53, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70}};
63 const GUID IID_IUnknown = {0x00000000, 0x0000, 0x0000, {0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46}};
64 const GUID IID_IPersist = {0x0000010c, 0x0000, 0x0000, {0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46}};
65 const GUID IID_IMediaFilter = {0x56a86899, 0x0ad4, 0x11ce, {0xb0,0x3a, 0x00,0x20,0xaf,0x0b,0xa7,0x70}};
66 const GUID IID_IBaseFilter = {0x56a86895, 0x0ad4, 0x11ce, {0xb0, 0x3a, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70}};
67 const GUID IID_IPin = {0x56a86891, 0x0ad4, 0x11ce, {0xb0,0x3a, 0x00,0x20,0xaf,0x0b,0xa7,0x70}};
68 const GUID IID_IMemInputPin = {0x56a8689d, 0x0ad4, 0x11ce, {0xb0,0x3a, 0x00,0x20,0xaf,0x0b,0xa7,0x70}};
70 const GUID IID_IEnumPins = {0x56a86892, 0x0ad4, 0x11ce, {0xb0,0x3a, 0x00,0x20,0xaf,0x0b,0xa7,0x70}};
71 const GUID IID_IEnumMediaTypes = {0x89c31040, 0x846b, 0x11ce, {0x97,0xd3, 0x00,0xaa,0x00,0x55,0x59,0x5a}};
73 const GUID IID_IAMBufferNegotiation = {0x56ed71a0, 0xaf5f, 0x11d0, {0xb3, 0xf0, 0x00, 0xaa, 0x00, 0x37, 0x61, 0xc5}};
75 const GUID IID_ISpecifyPropertyPages = {0xb196b28b, 0xbab4, 0x101a, {0xb6, 0x9c, 0x00, 0xaa, 0x00, 0x34, 0x1d, 0x07}};
78 * MEDIATYPEs and MEDIASUBTYPEs
80 const GUID MEDIATYPE_Video = {0x73646976, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
81 const GUID MEDIASUBTYPE_PREVIEW_VIDEO = {0x2859e1da, 0xb81f, 0x4fbd, {0x94, 0x3b, 0xe2, 0x37, 0x24, 0xa1, 0xab, 0xb3}};
82 const GUID MEDIATYPE_Stream = {0xe436eb83, 0x524f, 0x11ce, {0x9f, 0x53, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70}};
84 /* Packed RGB formats */
85 const GUID MEDIASUBTYPE_RGB1 = {0xe436eb78, 0x524f, 0x11ce, {0x9f, 0x53, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70}};
86 const GUID MEDIASUBTYPE_RGB4 = {0xe436eb79, 0x524f, 0x11ce, {0x9f, 0x53, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70}};
87 const GUID MEDIASUBTYPE_RGB8 = {0xe436eb7a, 0x524f, 0x11ce, {0x9f, 0x53, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70}};
88 const GUID MEDIASUBTYPE_RGB565 = {0xe436eb7b, 0x524f, 0x11ce, {0x9f, 0x53, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70}};
89 const GUID MEDIASUBTYPE_RGB555 = {0xe436eb7c, 0x524f, 0x11ce, {0x9f, 0x53, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70}};
90 const GUID MEDIASUBTYPE_RGB24 = {0xe436eb7d, 0x524f, 0x11ce, {0x9f, 0x53, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70}};
91 const GUID MEDIASUBTYPE_RGB32 = {0xe436eb7e, 0x524f, 0x11ce, {0x9f, 0x53, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70}};
92 const GUID MEDIASUBTYPE_ARGB32 = {0x773c9ac0, 0x3274, 0x11d0, {0xb7, 0x24, 0x0, 0xaa, 0x0, 0x6c, 0x1a, 0x1}};
94 /* Packed YUV formats */
95 const GUID MEDIASUBTYPE_YUYV = {0x56595559, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
96 const GUID MEDIASUBTYPE_Y411 = {0x31313459, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
97 const GUID MEDIASUBTYPE_Y211 = {0x31313259, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
98 const GUID MEDIASUBTYPE_YUY2 = {0x32595559, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
99 const GUID MEDIASUBTYPE_YVYU = {0x55595659, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
100 const GUID MEDIASUBTYPE_UYVY = {0x59565955, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
102 /* Planar YUV formats */
103 const GUID MEDIASUBTYPE_YVU9 = {0x39555659, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
104 const GUID MEDIASUBTYPE_YV12 = {0x32315659, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
105 const GUID MEDIASUBTYPE_IYUV = {0x56555949, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}}; /* identical to YV12 */
106 const GUID MEDIASUBTYPE_Y41P = {0x50313459, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
107 const GUID MEDIASUBTYPE_I420 = {0x30323449, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
109 const GUID MEDIATYPE_Audio = {0x73647561, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
110 const GUID FORMAT_WaveFormatEx = {0x05589f81, 0xc356, 0x11ce, {0xbf, 0x01, 0x00, 0xaa, 0x00, 0x55, 0x59, 0x5a}};
111 const GUID MEDIASUBTYPE_PCM = {0x00000001, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
112 const GUID MEDIASUBTYPE_IEEE_FLOAT = {0x00000003, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
115 const GUID MEDIASUBTYPE_dvsd = {0x64737664, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
116 const GUID MEDIASUBTYPE_dvhd = {0x64687664, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
117 const GUID MEDIASUBTYPE_dvsl = {0x6c737664, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
120 const GUID MEDIASUBTYPE_MPEG2_VIDEO = {0xe06d8026, 0xdb46, 0x11cf, {0xb4, 0xd1, 0x00, 0x80, 0x5f, 0x6c, 0xbb, 0xea}};
121 const GUID MEDIASUBTYPE_MPEG2_PROGRAM = {0xe06d8022, 0xdb46, 0x11cf, {0xb4, 0xd1, 0x00, 0x80, 0x5f, 0x6c, 0xbb, 0xea}};
122 const GUID MEDIASUBTYPE_MPEG2_TRANSPORT = {0xe06d8023, 0xdb46, 0x11cf, {0xb4, 0xd1, 0x00, 0x80, 0x5f, 0x6c, 0xbb, 0xea}};
123 const GUID FORMAT_MPEG2Video = {0xe06d80e3, 0xdb46, 0x11cf, {0xb4, 0xd1, 0x00, 0x80, 0x5f, 0x6c, 0xbb, 0xea}};
125 const GUID GUID_NULL = {0x0000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};
127 void WINAPI FreeMediaType( AM_MEDIA_TYPE& mt )
129 if( mt.cbFormat != 0 )
131 CoTaskMemFree( (PVOID)mt.pbFormat );
135 if( mt.pUnk != NULL )
142 HRESULT WINAPI CopyMediaType( AM_MEDIA_TYPE *pmtTarget,
143 const AM_MEDIA_TYPE *pmtSource )
145 *pmtTarget = *pmtSource;
146 if( pmtSource->cbFormat != 0 )
148 pmtTarget->pbFormat = (PBYTE)CoTaskMemAlloc( pmtSource->cbFormat );
149 if( pmtTarget->pbFormat == NULL )
151 pmtTarget->cbFormat = 0;
152 return E_OUTOFMEMORY;
156 CopyMemory( (PVOID)pmtTarget->pbFormat, (PVOID)pmtSource->pbFormat,
157 pmtTarget->cbFormat );
160 if( pmtTarget->pUnk != NULL )
162 pmtTarget->pUnk->AddRef();
168 /****************************************************************************
169 * Implementation of our dummy directshow filter pin class
170 ****************************************************************************/
172 CapturePin::CapturePin( input_thread_t * _p_input, CaptureFilter *_p_filter,
174 : p_input( _p_input ), p_filter( _p_filter ), p_connected_pin( NULL ),
175 media_type( mt ), i_ref( 1 )
179 CapturePin::~CapturePin()
182 msg_Dbg( p_input, "CapturePin::~CapturePin" );
186 HRESULT CapturePin::CustomGetSample( VLCMediaSample *vlc_sample )
188 #if 0 //def DEBUG_DSHOW
189 msg_Dbg( p_input, "CapturePin::CustomGetSample" );
192 access_sys_t *p_sys = p_input->p_access_data;
193 vlc_mutex_lock( &p_sys->lock );
194 if( samples_queue.size() )
196 *vlc_sample = samples_queue.back();
197 samples_queue.pop_back();
198 vlc_mutex_unlock( &p_sys->lock );
201 vlc_mutex_unlock( &p_sys->lock );
205 AM_MEDIA_TYPE CapturePin::CustomGetMediaType()
210 /* IUnknown methods */
211 STDMETHODIMP CapturePin::QueryInterface(REFIID riid, void **ppv)
214 msg_Dbg( p_input, "CapturePin::QueryInterface" );
217 if( riid == IID_IUnknown ||
224 if( riid == IID_IMemInputPin )
227 *ppv = (IMemInputPin *)this;
233 return E_NOINTERFACE;
236 STDMETHODIMP_(ULONG) CapturePin::AddRef()
239 msg_Dbg( p_input, "CapturePin::AddRef (ref: %i)", i_ref );
244 STDMETHODIMP_(ULONG) CapturePin::Release()
247 msg_Dbg( p_input, "CapturePin::Release (ref: %i)", i_ref );
250 if( !InterlockedDecrement(&i_ref) ) delete this;
256 STDMETHODIMP CapturePin::Connect( IPin * pReceivePin,
257 const AM_MEDIA_TYPE *pmt )
260 msg_Dbg( p_input, "CapturePin::Connect" );
264 STDMETHODIMP CapturePin::ReceiveConnection( IPin * pConnector,
265 const AM_MEDIA_TYPE *pmt )
268 msg_Dbg( p_input, "CapturePin::ReceiveConnection" );
271 if( pmt->majortype == MEDIATYPE_Video )
273 if( media_type.subtype != GUID_NULL &&
274 media_type.subtype != pmt->subtype )
275 return VFW_E_TYPE_NOT_ACCEPTED;
277 if( media_type.pbFormat &&
278 ((VIDEOINFOHEADER *)media_type.pbFormat)->bmiHeader.biHeight &&
279 ((VIDEOINFOHEADER *)media_type.pbFormat)->bmiHeader.biHeight !=
280 ((VIDEOINFOHEADER *)pmt->pbFormat)->bmiHeader.biHeight )
281 return VFW_E_TYPE_NOT_ACCEPTED;
283 if( media_type.pbFormat &&
284 ((VIDEOINFOHEADER *)media_type.pbFormat)->bmiHeader.biWidth &&
285 ((VIDEOINFOHEADER *)media_type.pbFormat)->bmiHeader.biWidth !=
286 ((VIDEOINFOHEADER *)pmt->pbFormat)->bmiHeader.biWidth )
287 return VFW_E_TYPE_NOT_ACCEPTED;
290 p_connected_pin = pConnector;
291 p_connected_pin->AddRef();
293 FreeMediaType( media_type );
294 return CopyMediaType( &media_type, pmt );
296 STDMETHODIMP CapturePin::Disconnect()
299 msg_Dbg( p_input, "CapturePin::Disconnect" );
302 #if 0 // FIXME: This does seem to create crashes sometimes
303 VLCMediaSample vlc_sample;
304 access_sys_t *p_sys = p_input->p_access_data;
306 vlc_mutex_lock( &p_sys->lock );
307 while( samples_queue.size() )
309 vlc_sample = samples_queue.back();
310 samples_queue.pop_back();
311 vlc_sample.p_sample->Release();
313 vlc_mutex_unlock( &p_sys->lock );
316 if( p_connected_pin ) p_connected_pin->Release();
317 p_connected_pin = NULL;
318 FreeMediaType( media_type );
321 STDMETHODIMP CapturePin::ConnectedTo( IPin **pPin )
324 msg_Dbg( p_input, "CapturePin::ConnectedTo" );
327 if( !p_connected_pin ) return VFW_E_NOT_CONNECTED;
329 p_connected_pin->AddRef();
330 *pPin = p_connected_pin;
334 STDMETHODIMP CapturePin::ConnectionMediaType( AM_MEDIA_TYPE *pmt )
337 msg_Dbg( p_input, "CapturePin::ConnectionMediaType" );
340 return CopyMediaType( pmt, &media_type );
342 STDMETHODIMP CapturePin::QueryPinInfo( PIN_INFO * pInfo )
345 msg_Dbg( p_input, "CapturePin::QueryPinInfo" );
348 pInfo->pFilter = p_filter;
349 if( p_filter ) p_filter->AddRef();
351 pInfo->achName[0] = L'\0';
353 pInfo->dir = PINDIR_INPUT;
357 STDMETHODIMP CapturePin::QueryDirection( PIN_DIRECTION * pPinDir )
360 msg_Dbg( p_input, "CapturePin::QueryDirection" );
363 *pPinDir = PINDIR_INPUT;
366 STDMETHODIMP CapturePin::QueryId( LPWSTR * Id )
369 msg_Dbg( p_input, "CapturePin::QueryId" );
373 STDMETHODIMP CapturePin::QueryAccept( const AM_MEDIA_TYPE *pmt )
376 msg_Dbg( p_input, "CapturePin::QueryAccept" );
380 STDMETHODIMP CapturePin::EnumMediaTypes( IEnumMediaTypes **ppEnum )
383 msg_Dbg( p_input, "CapturePin::EnumMediaTypes" );
386 *ppEnum = new CaptureEnumMediaTypes( p_input, this, NULL );
388 if( *ppEnum == NULL ) return E_OUTOFMEMORY;
392 STDMETHODIMP CapturePin::QueryInternalConnections( IPin* *apPin, ULONG *nPin )
395 msg_Dbg( p_input, "CapturePin::QueryInternalConnections" );
399 STDMETHODIMP CapturePin::EndOfStream( void )
402 msg_Dbg( p_input, "CapturePin::EndOfStream" );
406 STDMETHODIMP CapturePin::BeginFlush( void )
409 msg_Dbg( p_input, "CapturePin::BeginFlush" );
413 STDMETHODIMP CapturePin::EndFlush( void )
416 msg_Dbg( p_input, "CapturePin::EndFlush" );
420 STDMETHODIMP CapturePin::NewSegment( REFERENCE_TIME tStart,
421 REFERENCE_TIME tStop,
425 msg_Dbg( p_input, "CapturePin::NewSegment" );
430 /* IMemInputPin methods */
431 STDMETHODIMP CapturePin::GetAllocator( IMemAllocator **ppAllocator )
434 msg_Dbg( p_input, "CapturePin::GetAllocator" );
437 return VFW_E_NO_ALLOCATOR;
439 STDMETHODIMP CapturePin::NotifyAllocator( IMemAllocator *pAllocator,
443 msg_Dbg( p_input, "CapturePin::NotifyAllocator" );
448 STDMETHODIMP CapturePin::GetAllocatorRequirements( ALLOCATOR_PROPERTIES *pProps )
451 msg_Dbg( p_input, "CapturePin::GetAllocatorRequirements" );
456 STDMETHODIMP CapturePin::Receive( IMediaSample *pSample )
458 #if 0 //def DEBUG_DSHOW
459 msg_Dbg( p_input, "CapturePin::Receive" );
463 mtime_t i_timestamp = mdate() * 10;
464 VLCMediaSample vlc_sample = {pSample, i_timestamp};
466 access_sys_t *p_sys = p_input->p_access_data;
467 vlc_mutex_lock( &p_sys->lock );
468 samples_queue.push_front( vlc_sample );
470 /* Make sure we don't cache too many samples */
471 if( samples_queue.size() > 10 )
473 vlc_sample = samples_queue.back();
474 samples_queue.pop_back();
475 msg_Dbg( p_input, "CapturePin::Receive trashing late input sample" );
476 vlc_sample.p_sample->Release();
479 vlc_cond_signal( &p_sys->wait );
480 vlc_mutex_unlock( &p_sys->lock );
484 STDMETHODIMP CapturePin::ReceiveMultiple( IMediaSample **pSamples,
486 long *nSamplesProcessed )
489 msg_Dbg( p_input, "CapturePin::ReceiveMultiple" );
494 *nSamplesProcessed = 0;
495 while( nSamples-- > 0 )
497 hr = Receive( pSamples[*nSamplesProcessed] );
498 if( hr != S_OK ) break;
499 (*nSamplesProcessed)++;
503 STDMETHODIMP CapturePin::ReceiveCanBlock( void )
506 msg_Dbg( p_input, "CapturePin::ReceiveCanBlock" );
509 return S_FALSE; /* Thou shalt not block */
512 /****************************************************************************
513 * Implementation of our dummy directshow filter class
514 ****************************************************************************/
516 CaptureFilter::CaptureFilter( input_thread_t * _p_input, AM_MEDIA_TYPE mt )
517 : p_input( _p_input ), p_pin( new CapturePin( _p_input, this, mt ) ),
518 media_type( mt ), state( State_Stopped ), i_ref( 1 )
522 CaptureFilter::~CaptureFilter()
525 msg_Dbg( p_input, "CaptureFilter::~CaptureFilter" );
530 /* IUnknown methods */
531 STDMETHODIMP CaptureFilter::QueryInterface( REFIID riid, void **ppv )
534 msg_Dbg( p_input, "CaptureFilter::QueryInterface" );
537 if( riid == IID_IUnknown )
540 *ppv = (IUnknown *)this;
543 if( riid == IID_IPersist )
546 *ppv = (IPersist *)this;
549 if( riid == IID_IMediaFilter )
552 *ppv = (IMediaFilter *)this;
555 if( riid == IID_IBaseFilter )
558 *ppv = (IBaseFilter *)this;
564 return E_NOINTERFACE;
567 STDMETHODIMP_(ULONG) CaptureFilter::AddRef()
570 msg_Dbg( p_input, "CaptureFilter::AddRef (ref: %i)", i_ref );
575 STDMETHODIMP_(ULONG) CaptureFilter::Release()
578 msg_Dbg( p_input, "CaptureFilter::Release (ref: %i)", i_ref );
581 if( !InterlockedDecrement(&i_ref) ) delete this;
586 /* IPersist method */
587 STDMETHODIMP CaptureFilter::GetClassID(CLSID *pClsID)
590 msg_Dbg( p_input, "CaptureFilter::GetClassID" );
595 /* IMediaFilter methods */
596 STDMETHODIMP CaptureFilter::GetState(DWORD dwMSecs, FILTER_STATE *State)
599 msg_Dbg( p_input, "CaptureFilter::GetState %i", state );
605 STDMETHODIMP CaptureFilter::SetSyncSource(IReferenceClock *pClock)
608 msg_Dbg( p_input, "CaptureFilter::SetSyncSource" );
613 STDMETHODIMP CaptureFilter::GetSyncSource(IReferenceClock **pClock)
616 msg_Dbg( p_input, "CaptureFilter::GetSyncSource" );
622 STDMETHODIMP CaptureFilter::Stop()
625 msg_Dbg( p_input, "CaptureFilter::Stop" );
628 state = State_Stopped;
631 STDMETHODIMP CaptureFilter::Pause()
634 msg_Dbg( p_input, "CaptureFilter::Pause" );
637 state = State_Paused;
640 STDMETHODIMP CaptureFilter::Run(REFERENCE_TIME tStart)
643 msg_Dbg( p_input, "CaptureFilter::Run" );
646 state = State_Running;
650 /* IBaseFilter methods */
651 STDMETHODIMP CaptureFilter::EnumPins( IEnumPins ** ppEnum )
654 msg_Dbg( p_input, "CaptureFilter::EnumPins" );
657 /* Create a new ref counted enumerator */
658 *ppEnum = new CaptureEnumPins( p_input, this, NULL );
659 return *ppEnum == NULL ? E_OUTOFMEMORY : NOERROR;
661 STDMETHODIMP CaptureFilter::FindPin( LPCWSTR Id, IPin ** ppPin )
664 msg_Dbg( p_input, "CaptureFilter::FindPin" );
668 STDMETHODIMP CaptureFilter::QueryFilterInfo( FILTER_INFO * pInfo )
671 msg_Dbg( p_input, "CaptureFilter::QueryFilterInfo" );
674 pInfo->achName[0] = L'\0';
676 pInfo->pGraph = p_graph;
677 if( p_graph ) p_graph->AddRef();
681 STDMETHODIMP CaptureFilter::JoinFilterGraph( IFilterGraph * pGraph,
685 msg_Dbg( p_input, "CaptureFilter::JoinFilterGraph" );
692 STDMETHODIMP CaptureFilter::QueryVendorInfo( LPWSTR* pVendorInfo )
695 msg_Dbg( p_input, "CaptureFilter::QueryVendorInfo" );
701 CapturePin *CaptureFilter::CustomGetPin()
706 /****************************************************************************
707 * Implementation of our dummy directshow enumpins class
708 ****************************************************************************/
710 CaptureEnumPins::CaptureEnumPins( input_thread_t * _p_input,
711 CaptureFilter *_p_filter,
712 CaptureEnumPins *pEnumPins )
713 : p_input( _p_input ), p_filter( _p_filter ), i_ref( 1 )
715 /* Hold a reference count on our filter */
718 /* Are we creating a new enumerator */
720 if( pEnumPins == NULL )
726 i_position = pEnumPins->i_position;
730 CaptureEnumPins::~CaptureEnumPins()
733 msg_Dbg( p_input, "CaptureEnumPins::~CaptureEnumPins" );
738 /* IUnknown methods */
739 STDMETHODIMP CaptureEnumPins::QueryInterface( REFIID riid, void **ppv )
742 msg_Dbg( p_input, "CaptureEnumPins::QueryInterface" );
745 if( riid == IID_IUnknown ||
746 riid == IID_IEnumPins )
749 *ppv = (IEnumPins *)this;
755 return E_NOINTERFACE;
758 STDMETHODIMP_(ULONG) CaptureEnumPins::AddRef()
761 msg_Dbg( p_input, "CaptureEnumPins::AddRef (ref: %i)", i_ref );
766 STDMETHODIMP_(ULONG) CaptureEnumPins::Release()
769 msg_Dbg( p_input, "CaptureEnumPins::Release (ref: %i)", i_ref );
772 if( !InterlockedDecrement(&i_ref) ) delete this;
778 STDMETHODIMP CaptureEnumPins::Next( ULONG cPins, IPin ** ppPins,
782 msg_Dbg( p_input, "CaptureEnumPins::Next" );
785 unsigned int i_fetched = 0;
787 if( i_position < 1 && cPins > 0 )
789 IPin *pPin = p_filter->CustomGetPin();
796 if( pcFetched ) *pcFetched = i_fetched;
798 return (i_fetched == cPins) ? S_OK : S_FALSE;
800 STDMETHODIMP CaptureEnumPins::Skip( ULONG cPins )
803 msg_Dbg( p_input, "CaptureEnumPins::Skip" );
815 STDMETHODIMP CaptureEnumPins::Reset()
818 msg_Dbg( p_input, "CaptureEnumPins::Reset" );
824 STDMETHODIMP CaptureEnumPins::Clone( IEnumPins **ppEnum )
827 msg_Dbg( p_input, "CaptureEnumPins::Clone" );
830 *ppEnum = new CaptureEnumPins( p_input, p_filter, this );
831 if( *ppEnum == NULL ) return E_OUTOFMEMORY;
836 /****************************************************************************
837 * Implementation of our dummy directshow enummediatypes class
838 ****************************************************************************/
840 CaptureEnumMediaTypes::CaptureEnumMediaTypes( input_thread_t * _p_input,
842 CaptureEnumMediaTypes *pEnumMediaTypes )
843 : p_input( _p_input ), p_pin( _p_pin ), i_ref( 1 )
845 /* Hold a reference count on our filter */
848 /* Are we creating a new enumerator */
849 if( pEnumMediaTypes == NULL )
855 i_position = pEnumMediaTypes->i_position;
859 CaptureEnumMediaTypes::~CaptureEnumMediaTypes()
862 msg_Dbg( p_input, "CaptureEnumMediaTypes::~CaptureEnumMediaTypes" );
867 /* IUnknown methods */
868 STDMETHODIMP CaptureEnumMediaTypes::QueryInterface( REFIID riid, void **ppv )
871 msg_Dbg( p_input, "CaptureEnumMediaTypes::QueryInterface" );
874 if( riid == IID_IUnknown ||
875 riid == IID_IEnumMediaTypes )
878 *ppv = (IEnumMediaTypes *)this;
884 return E_NOINTERFACE;
887 STDMETHODIMP_(ULONG) CaptureEnumMediaTypes::AddRef()
890 msg_Dbg( p_input, "CaptureEnumMediaTypes::AddRef (ref: %i)", i_ref );
895 STDMETHODIMP_(ULONG) CaptureEnumMediaTypes::Release()
898 msg_Dbg( p_input, "CaptureEnumMediaTypes::Release (ref: %i)", i_ref );
901 if( !InterlockedDecrement(&i_ref) ) delete this;
906 /* IEnumMediaTypes */
907 STDMETHODIMP CaptureEnumMediaTypes::Next( ULONG cMediaTypes,
908 AM_MEDIA_TYPE ** ppMediaTypes,
912 msg_Dbg( p_input, "CaptureEnumMediaTypes::Next" );
915 if( pcFetched ) *pcFetched = 0;
918 STDMETHODIMP CaptureEnumMediaTypes::Skip( ULONG cMediaTypes )
921 msg_Dbg( p_input, "CaptureEnumMediaTypes::Skip" );
926 STDMETHODIMP CaptureEnumMediaTypes::Reset()
929 msg_Dbg( p_input, "CaptureEnumMediaTypes::Reset" );
935 STDMETHODIMP CaptureEnumMediaTypes::Clone( IEnumMediaTypes **ppEnum )
938 msg_Dbg( p_input, "CaptureEnumMediaTypes::Clone" );
941 *ppEnum = new CaptureEnumMediaTypes( p_input, p_pin, this );
942 if( *ppEnum == NULL ) return E_OUTOFMEMORY;