1 /*****************************************************************************
2 * filter.c : DirectShow access module for vlc
3 *****************************************************************************
4 * Copyright (C) 2002 VideoLAN
5 * $Id: filter.cpp,v 1.12 2004/01/28 16:46:52 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>
45 /*****************************************************************************
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}};
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}};
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}};
68 const GUID IID_IAMBufferNegotiation = {0x56ed71a0, 0xaf5f, 0x11d0, {0xb3, 0xf0, 0x00, 0xaa, 0x00, 0x37, 0x61, 0xc5}};
70 const GUID IID_ISpecifyPropertyPages = {0xb196b28b, 0xbab4, 0x101a, {0xb6, 0x9c, 0x00, 0xaa, 0x00, 0x34, 0x1d, 0x07}};
73 * MEDIATYPEs and MEDIASUBTYPEs
75 const GUID MEDIATYPE_Video = {0x73646976, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
76 const GUID MEDIASUBTYPE_PREVIEW_VIDEO = {0x2859e1da, 0xb81f, 0x4fbd, {0x94, 0x3b, 0xe2, 0x37, 0x24, 0xa1, 0xab, 0xb3}};
77 const GUID MEDIATYPE_Stream = {0xe436eb83, 0x524f, 0x11ce, {0x9f, 0x53, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70}};
79 /* Packed RGB formats */
80 const GUID MEDIASUBTYPE_RGB1 = {0xe436eb78, 0x524f, 0x11ce, {0x9f, 0x53, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70}};
81 const GUID MEDIASUBTYPE_RGB4 = {0xe436eb79, 0x524f, 0x11ce, {0x9f, 0x53, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70}};
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}};
89 /* Packed YUV formats */
90 const GUID MEDIASUBTYPE_YUYV = {0x56595559, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
91 const GUID MEDIASUBTYPE_Y411 = {0x31313459, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
92 const GUID MEDIASUBTYPE_Y211 = {0x31313259, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
93 const GUID MEDIASUBTYPE_YUY2 = {0x32595559, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
94 const GUID MEDIASUBTYPE_YVYU = {0x55595659, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
95 const GUID MEDIASUBTYPE_UYVY = {0x59565955, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
97 /* Planar YUV formats */
98 const GUID MEDIASUBTYPE_YVU9 = {0x39555659, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
99 const GUID MEDIASUBTYPE_YV12 = {0x32315659, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
100 const GUID MEDIASUBTYPE_IYUV = {0x56555949, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}}; /* identical to YV12 */
101 const GUID MEDIASUBTYPE_Y41P = {0x50313459, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
102 const GUID MEDIASUBTYPE_I420 = {0x30323449, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
104 const GUID MEDIATYPE_Audio = {0x73647561, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
105 const GUID FORMAT_WaveFormatEx = {0x05589f81, 0xc356, 0x11ce, {0xbf, 0x01, 0x00, 0xaa, 0x00, 0x55, 0x59, 0x5a}};
106 const GUID MEDIASUBTYPE_PCM = {0x00000001, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
107 const GUID MEDIASUBTYPE_IEEE_FLOAT = {0x00000003, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
110 const GUID MEDIASUBTYPE_dvsd = {0x64737664, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
111 const GUID MEDIASUBTYPE_dvhd = {0x64687664, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
112 const GUID MEDIASUBTYPE_dvsl = {0x6c737664, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
115 const GUID MEDIASUBTYPE_MPEG2_VIDEO = {0xe06d8026, 0xdb46, 0x11cf, {0xb4, 0xd1, 0x00, 0x80, 0x5f, 0x6c, 0xbb, 0xea}};
116 const GUID MEDIASUBTYPE_MPEG2_PROGRAM = {0xe06d8022, 0xdb46, 0x11cf, {0xb4, 0xd1, 0x00, 0x80, 0x5f, 0x6c, 0xbb, 0xea}};
117 const GUID MEDIASUBTYPE_MPEG2_TRANSPORT = {0xe06d8023, 0xdb46, 0x11cf, {0xb4, 0xd1, 0x00, 0x80, 0x5f, 0x6c, 0xbb, 0xea}};
118 const GUID FORMAT_MPEG2Video = {0xe06d80e3, 0xdb46, 0x11cf, {0xb4, 0xd1, 0x00, 0x80, 0x5f, 0x6c, 0xbb, 0xea}};
120 const GUID GUID_NULL = {0x0000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};
122 void WINAPI FreeMediaType( AM_MEDIA_TYPE& mt )
124 if( mt.cbFormat != 0 )
126 CoTaskMemFree( (PVOID)mt.pbFormat );
130 if( mt.pUnk != NULL )
137 HRESULT WINAPI CopyMediaType( AM_MEDIA_TYPE *pmtTarget,
138 const AM_MEDIA_TYPE *pmtSource )
140 *pmtTarget = *pmtSource;
141 if( pmtSource->cbFormat != 0 )
143 pmtTarget->pbFormat = (PBYTE)CoTaskMemAlloc( pmtSource->cbFormat );
144 if( pmtTarget->pbFormat == NULL )
146 pmtTarget->cbFormat = 0;
147 return E_OUTOFMEMORY;
151 CopyMemory( (PVOID)pmtTarget->pbFormat, (PVOID)pmtSource->pbFormat,
152 pmtTarget->cbFormat );
155 if( pmtTarget->pUnk != NULL )
157 pmtTarget->pUnk->AddRef();
163 /****************************************************************************
164 * Implementation of our dummy directshow filter pin class
165 ****************************************************************************/
167 CapturePin::CapturePin( input_thread_t * _p_input, CaptureFilter *_p_filter,
169 : p_input( _p_input ), p_filter( _p_filter ), p_connected_pin( NULL ),
170 media_type( mt ), i_ref( 1 )
174 CapturePin::~CapturePin()
177 msg_Dbg( p_input, "CapturePin::~CapturePin" );
181 HRESULT CapturePin::CustomGetSample( VLCMediaSample *vlc_sample )
183 #if 0 //def DEBUG_DSHOW
184 msg_Dbg( p_input, "CapturePin::CustomGetSample" );
187 access_sys_t *p_sys = p_input->p_access_data;
188 vlc_mutex_lock( &p_sys->lock );
189 if( samples_queue.size() )
191 *vlc_sample = samples_queue.back();
192 samples_queue.pop_back();
193 vlc_mutex_unlock( &p_sys->lock );
196 vlc_mutex_unlock( &p_sys->lock );
200 AM_MEDIA_TYPE CapturePin::CustomGetMediaType()
205 /* IUnknown methods */
206 STDMETHODIMP CapturePin::QueryInterface(REFIID riid, void **ppv)
209 msg_Dbg( p_input, "CapturePin::QueryInterface" );
212 if( riid == IID_IUnknown ||
219 if( riid == IID_IMemInputPin )
222 *ppv = (IMemInputPin *)this;
228 return E_NOINTERFACE;
231 STDMETHODIMP_(ULONG) CapturePin::AddRef()
234 msg_Dbg( p_input, "CapturePin::AddRef (ref: %i)", i_ref );
239 STDMETHODIMP_(ULONG) CapturePin::Release()
242 msg_Dbg( p_input, "CapturePin::Release (ref: %i)", i_ref );
245 if( !InterlockedDecrement(&i_ref) ) delete this;
251 STDMETHODIMP CapturePin::Connect( IPin * pReceivePin,
252 const AM_MEDIA_TYPE *pmt )
255 msg_Dbg( p_input, "CapturePin::Connect" );
259 STDMETHODIMP CapturePin::ReceiveConnection( IPin * pConnector,
260 const AM_MEDIA_TYPE *pmt )
263 msg_Dbg( p_input, "CapturePin::ReceiveConnection" );
266 if( pmt->majortype == MEDIATYPE_Video )
268 if( media_type.subtype != GUID_NULL &&
269 media_type.subtype != pmt->subtype )
270 return VFW_E_TYPE_NOT_ACCEPTED;
272 if( media_type.pbFormat &&
273 ((VIDEOINFOHEADER *)media_type.pbFormat)->bmiHeader.biHeight &&
274 ((VIDEOINFOHEADER *)media_type.pbFormat)->bmiHeader.biHeight !=
275 ((VIDEOINFOHEADER *)pmt->pbFormat)->bmiHeader.biHeight )
276 return VFW_E_TYPE_NOT_ACCEPTED;
278 if( media_type.pbFormat &&
279 ((VIDEOINFOHEADER *)media_type.pbFormat)->bmiHeader.biWidth &&
280 ((VIDEOINFOHEADER *)media_type.pbFormat)->bmiHeader.biWidth !=
281 ((VIDEOINFOHEADER *)pmt->pbFormat)->bmiHeader.biWidth )
282 return VFW_E_TYPE_NOT_ACCEPTED;
285 p_connected_pin = pConnector;
286 p_connected_pin->AddRef();
288 FreeMediaType( media_type );
289 return CopyMediaType( &media_type, pmt );
291 STDMETHODIMP CapturePin::Disconnect()
294 msg_Dbg( p_input, "CapturePin::Disconnect" );
297 VLCMediaSample vlc_sample;
298 access_sys_t *p_sys = p_input->p_access_data;
300 #if 0 // FIXME: This does seem to create crashes sometimes
301 vlc_mutex_lock( &p_sys->lock );
302 while( samples_queue.size() )
304 vlc_sample = samples_queue.back();
305 samples_queue.pop_back();
306 vlc_sample.p_sample->Release();
308 vlc_mutex_unlock( &p_sys->lock );
311 if( p_connected_pin ) p_connected_pin->Release();
312 p_connected_pin = NULL;
313 FreeMediaType( media_type );
316 STDMETHODIMP CapturePin::ConnectedTo( IPin **pPin )
319 msg_Dbg( p_input, "CapturePin::ConnectedTo" );
322 if( !p_connected_pin ) return VFW_E_NOT_CONNECTED;
324 p_connected_pin->AddRef();
325 *pPin = p_connected_pin;
329 STDMETHODIMP CapturePin::ConnectionMediaType( AM_MEDIA_TYPE *pmt )
332 msg_Dbg( p_input, "CapturePin::ConnectionMediaType" );
335 return CopyMediaType( pmt, &media_type );
337 STDMETHODIMP CapturePin::QueryPinInfo( PIN_INFO * pInfo )
340 msg_Dbg( p_input, "CapturePin::QueryPinInfo" );
343 pInfo->pFilter = p_filter;
344 if( p_filter ) p_filter->AddRef();
346 pInfo->achName[0] = L'\0';
348 pInfo->dir = PINDIR_INPUT;
352 STDMETHODIMP CapturePin::QueryDirection( PIN_DIRECTION * pPinDir )
355 msg_Dbg( p_input, "CapturePin::QueryDirection" );
358 *pPinDir = PINDIR_INPUT;
361 STDMETHODIMP CapturePin::QueryId( LPWSTR * Id )
364 msg_Dbg( p_input, "CapturePin::QueryId" );
368 STDMETHODIMP CapturePin::QueryAccept( const AM_MEDIA_TYPE *pmt )
371 msg_Dbg( p_input, "CapturePin::QueryAccept" );
375 STDMETHODIMP CapturePin::EnumMediaTypes( IEnumMediaTypes **ppEnum )
378 msg_Dbg( p_input, "CapturePin::EnumMediaTypes" );
381 *ppEnum = new CaptureEnumMediaTypes( p_input, this, NULL );
383 if( *ppEnum == NULL ) return E_OUTOFMEMORY;
387 STDMETHODIMP CapturePin::QueryInternalConnections( IPin* *apPin, ULONG *nPin )
390 msg_Dbg( p_input, "CapturePin::QueryInternalConnections" );
394 STDMETHODIMP CapturePin::EndOfStream( void )
397 msg_Dbg( p_input, "CapturePin::EndOfStream" );
401 STDMETHODIMP CapturePin::BeginFlush( void )
404 msg_Dbg( p_input, "CapturePin::BeginFlush" );
408 STDMETHODIMP CapturePin::EndFlush( void )
411 msg_Dbg( p_input, "CapturePin::EndFlush" );
415 STDMETHODIMP CapturePin::NewSegment( REFERENCE_TIME tStart,
416 REFERENCE_TIME tStop,
420 msg_Dbg( p_input, "CapturePin::NewSegment" );
425 /* IMemInputPin methods */
426 STDMETHODIMP CapturePin::GetAllocator( IMemAllocator **ppAllocator )
429 msg_Dbg( p_input, "CapturePin::GetAllocator" );
432 return VFW_E_NO_ALLOCATOR;
434 STDMETHODIMP CapturePin::NotifyAllocator( IMemAllocator *pAllocator,
438 msg_Dbg( p_input, "CapturePin::NotifyAllocator" );
443 STDMETHODIMP CapturePin::GetAllocatorRequirements( ALLOCATOR_PROPERTIES *pProps )
446 msg_Dbg( p_input, "CapturePin::GetAllocatorRequirements" );
451 STDMETHODIMP CapturePin::Receive( IMediaSample *pSample )
453 #if 0 //def DEBUG_DSHOW
454 msg_Dbg( p_input, "CapturePin::Receive" );
458 mtime_t i_timestamp = mdate() * 10;
459 VLCMediaSample vlc_sample = {pSample, i_timestamp};
461 access_sys_t *p_sys = p_input->p_access_data;
462 vlc_mutex_lock( &p_sys->lock );
463 samples_queue.push_front( vlc_sample );
465 /* Make sure we don't cache too many samples */
466 if( samples_queue.size() > 10 )
468 vlc_sample = samples_queue.back();
469 samples_queue.pop_back();
470 msg_Dbg( p_input, "CapturePin::Receive trashing late input sample" );
471 vlc_sample.p_sample->Release();
474 vlc_cond_signal( &p_sys->wait );
475 vlc_mutex_unlock( &p_sys->lock );
479 STDMETHODIMP CapturePin::ReceiveMultiple( IMediaSample **pSamples,
481 long *nSamplesProcessed )
484 msg_Dbg( p_input, "CapturePin::ReceiveMultiple" );
489 *nSamplesProcessed = 0;
490 while( nSamples-- > 0 )
492 hr = Receive( pSamples[*nSamplesProcessed] );
493 if( hr != S_OK ) break;
494 (*nSamplesProcessed)++;
498 STDMETHODIMP CapturePin::ReceiveCanBlock( void )
501 msg_Dbg( p_input, "CapturePin::ReceiveCanBlock" );
504 return S_FALSE; /* Thou shalt not block */
507 /****************************************************************************
508 * Implementation of our dummy directshow filter class
509 ****************************************************************************/
511 CaptureFilter::CaptureFilter( input_thread_t * _p_input, AM_MEDIA_TYPE mt )
512 : p_input( _p_input ), p_pin( new CapturePin( _p_input, this, mt ) ),
513 media_type( mt ), state( State_Stopped ), i_ref( 1 )
517 CaptureFilter::~CaptureFilter()
520 msg_Dbg( p_input, "CaptureFilter::~CaptureFilter" );
525 /* IUnknown methods */
526 STDMETHODIMP CaptureFilter::QueryInterface( REFIID riid, void **ppv )
529 msg_Dbg( p_input, "CaptureFilter::QueryInterface" );
532 if( riid == IID_IUnknown )
535 *ppv = (IUnknown *)this;
538 if( riid == IID_IPersist )
541 *ppv = (IPersist *)this;
544 if( riid == IID_IMediaFilter )
547 *ppv = (IMediaFilter *)this;
550 if( riid == IID_IBaseFilter )
553 *ppv = (IBaseFilter *)this;
559 return E_NOINTERFACE;
562 STDMETHODIMP_(ULONG) CaptureFilter::AddRef()
565 msg_Dbg( p_input, "CaptureFilter::AddRef (ref: %i)", i_ref );
570 STDMETHODIMP_(ULONG) CaptureFilter::Release()
573 msg_Dbg( p_input, "CaptureFilter::Release (ref: %i)", i_ref );
576 if( !InterlockedDecrement(&i_ref) ) delete this;
581 /* IPersist method */
582 STDMETHODIMP CaptureFilter::GetClassID(CLSID *pClsID)
585 msg_Dbg( p_input, "CaptureFilter::GetClassID" );
590 /* IMediaFilter methods */
591 STDMETHODIMP CaptureFilter::GetState(DWORD dwMSecs, FILTER_STATE *State)
594 msg_Dbg( p_input, "CaptureFilter::GetState %i", state );
600 STDMETHODIMP CaptureFilter::SetSyncSource(IReferenceClock *pClock)
603 msg_Dbg( p_input, "CaptureFilter::SetSyncSource" );
608 STDMETHODIMP CaptureFilter::GetSyncSource(IReferenceClock **pClock)
611 msg_Dbg( p_input, "CaptureFilter::GetSyncSource" );
617 STDMETHODIMP CaptureFilter::Stop()
620 msg_Dbg( p_input, "CaptureFilter::Stop" );
623 state = State_Stopped;
626 STDMETHODIMP CaptureFilter::Pause()
629 msg_Dbg( p_input, "CaptureFilter::Pause" );
632 state = State_Paused;
635 STDMETHODIMP CaptureFilter::Run(REFERENCE_TIME tStart)
638 msg_Dbg( p_input, "CaptureFilter::Run" );
641 state = State_Running;
645 /* IBaseFilter methods */
646 STDMETHODIMP CaptureFilter::EnumPins( IEnumPins ** ppEnum )
649 msg_Dbg( p_input, "CaptureFilter::EnumPins" );
652 /* Create a new ref counted enumerator */
653 *ppEnum = new CaptureEnumPins( p_input, this, NULL );
654 return *ppEnum == NULL ? E_OUTOFMEMORY : NOERROR;
656 STDMETHODIMP CaptureFilter::FindPin( LPCWSTR Id, IPin ** ppPin )
659 msg_Dbg( p_input, "CaptureFilter::FindPin" );
663 STDMETHODIMP CaptureFilter::QueryFilterInfo( FILTER_INFO * pInfo )
666 msg_Dbg( p_input, "CaptureFilter::QueryFilterInfo" );
669 pInfo->achName[0] = L'\0';
671 pInfo->pGraph = p_graph;
672 if( p_graph ) p_graph->AddRef();
676 STDMETHODIMP CaptureFilter::JoinFilterGraph( IFilterGraph * pGraph,
680 msg_Dbg( p_input, "CaptureFilter::JoinFilterGraph" );
687 STDMETHODIMP CaptureFilter::QueryVendorInfo( LPWSTR* pVendorInfo )
690 msg_Dbg( p_input, "CaptureFilter::QueryVendorInfo" );
696 CapturePin *CaptureFilter::CustomGetPin()
701 /****************************************************************************
702 * Implementation of our dummy directshow enumpins class
703 ****************************************************************************/
705 CaptureEnumPins::CaptureEnumPins( input_thread_t * _p_input,
706 CaptureFilter *_p_filter,
707 CaptureEnumPins *pEnumPins )
708 : p_input( _p_input ), p_filter( _p_filter ), i_ref( 1 )
710 /* Hold a reference count on our filter */
713 /* Are we creating a new enumerator */
715 if( pEnumPins == NULL )
721 i_position = pEnumPins->i_position;
725 CaptureEnumPins::~CaptureEnumPins()
728 msg_Dbg( p_input, "CaptureEnumPins::~CaptureEnumPins" );
733 /* IUnknown methods */
734 STDMETHODIMP CaptureEnumPins::QueryInterface( REFIID riid, void **ppv )
737 msg_Dbg( p_input, "CaptureEnumPins::QueryInterface" );
740 if( riid == IID_IUnknown ||
741 riid == IID_IEnumPins )
744 *ppv = (IEnumPins *)this;
750 return E_NOINTERFACE;
753 STDMETHODIMP_(ULONG) CaptureEnumPins::AddRef()
756 msg_Dbg( p_input, "CaptureEnumPins::AddRef (ref: %i)", i_ref );
761 STDMETHODIMP_(ULONG) CaptureEnumPins::Release()
764 msg_Dbg( p_input, "CaptureEnumPins::Release (ref: %i)", i_ref );
767 if( !InterlockedDecrement(&i_ref) ) delete this;
773 STDMETHODIMP CaptureEnumPins::Next( ULONG cPins, IPin ** ppPins,
777 msg_Dbg( p_input, "CaptureEnumPins::Next" );
780 unsigned int i_fetched = 0;
782 if( i_position < 1 && cPins > 0 )
784 IPin *pPin = p_filter->CustomGetPin();
791 if( pcFetched ) *pcFetched = i_fetched;
793 return (i_fetched == cPins) ? S_OK : S_FALSE;
795 STDMETHODIMP CaptureEnumPins::Skip( ULONG cPins )
798 msg_Dbg( p_input, "CaptureEnumPins::Skip" );
810 STDMETHODIMP CaptureEnumPins::Reset()
813 msg_Dbg( p_input, "CaptureEnumPins::Reset" );
819 STDMETHODIMP CaptureEnumPins::Clone( IEnumPins **ppEnum )
822 msg_Dbg( p_input, "CaptureEnumPins::Clone" );
825 *ppEnum = new CaptureEnumPins( p_input, p_filter, this );
826 if( *ppEnum == NULL ) return E_OUTOFMEMORY;
831 /****************************************************************************
832 * Implementation of our dummy directshow enummediatypes class
833 ****************************************************************************/
835 CaptureEnumMediaTypes::CaptureEnumMediaTypes( input_thread_t * _p_input,
837 CaptureEnumMediaTypes *pEnumMediaTypes )
838 : p_input( _p_input ), p_pin( _p_pin ), i_ref( 1 )
840 /* Hold a reference count on our filter */
843 /* Are we creating a new enumerator */
844 if( pEnumMediaTypes == NULL )
850 i_position = pEnumMediaTypes->i_position;
854 CaptureEnumMediaTypes::~CaptureEnumMediaTypes()
857 msg_Dbg( p_input, "CaptureEnumMediaTypes::~CaptureEnumMediaTypes" );
862 /* IUnknown methods */
863 STDMETHODIMP CaptureEnumMediaTypes::QueryInterface( REFIID riid, void **ppv )
866 msg_Dbg( p_input, "CaptureEnumMediaTypes::QueryInterface" );
869 if( riid == IID_IUnknown ||
870 riid == IID_IEnumMediaTypes )
873 *ppv = (IEnumMediaTypes *)this;
879 return E_NOINTERFACE;
882 STDMETHODIMP_(ULONG) CaptureEnumMediaTypes::AddRef()
885 msg_Dbg( p_input, "CaptureEnumMediaTypes::AddRef (ref: %i)", i_ref );
890 STDMETHODIMP_(ULONG) CaptureEnumMediaTypes::Release()
893 msg_Dbg( p_input, "CaptureEnumMediaTypes::Release (ref: %i)", i_ref );
896 if( !InterlockedDecrement(&i_ref) ) delete this;
901 /* IEnumMediaTypes */
902 STDMETHODIMP CaptureEnumMediaTypes::Next( ULONG cMediaTypes,
903 AM_MEDIA_TYPE ** ppMediaTypes,
907 msg_Dbg( p_input, "CaptureEnumMediaTypes::Next" );
910 if( pcFetched ) *pcFetched = 0;
913 STDMETHODIMP CaptureEnumMediaTypes::Skip( ULONG cMediaTypes )
916 msg_Dbg( p_input, "CaptureEnumMediaTypes::Skip" );
921 STDMETHODIMP CaptureEnumMediaTypes::Reset()
924 msg_Dbg( p_input, "CaptureEnumMediaTypes::Reset" );
930 STDMETHODIMP CaptureEnumMediaTypes::Clone( IEnumMediaTypes **ppEnum )
933 msg_Dbg( p_input, "CaptureEnumMediaTypes::Clone" );
936 *ppEnum = new CaptureEnumMediaTypes( p_input, p_pin, this );
937 if( *ppEnum == NULL ) return E_OUTOFMEMORY;