2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS WDM Streaming ActiveMovie Proxy
4 * FILE: dll/directx/ksproxy/input_cpp.cpp
5 * PURPOSE: InputPin of Proxy Filter
7 * PROGRAMMERS: Johannes Anderwald (janderwald@reactos.org)
12 const GUID IID_IKsPinFactory
= {0xCD5EBE6BL
, 0x8B6E, 0x11D1, {0x8A, 0xE0, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96}};
15 class COutputPin
: public IPin
,
17 public IKsPropertySet
,
18 public IStreamBuilder
,
20 public ISpecifyPropertyPages
,
24 public IQualityControl,
26 public IKsAggregateControl
28 public IAMStreamConfig,
29 public IMemAllocatorNotifyCallbackTemp
33 STDMETHODIMP
QueryInterface( REFIID InterfaceId
, PVOID
* Interface
);
35 STDMETHODIMP_(ULONG
) AddRef()
37 InterlockedIncrement(&m_Ref
);
40 STDMETHODIMP_(ULONG
) Release()
42 InterlockedDecrement(&m_Ref
);
52 HRESULT STDMETHODCALLTYPE
KsGetPinFramingCache(PKSALLOCATOR_FRAMING_EX
*FramingEx
, PFRAMING_PROP FramingProp
, FRAMING_CACHE_OPS Option
);
53 HRESULT STDMETHODCALLTYPE
KsSetPinFramingCache(PKSALLOCATOR_FRAMING_EX FramingEx
, PFRAMING_PROP FramingProp
, FRAMING_CACHE_OPS Option
);
54 IPin
* STDMETHODCALLTYPE
KsGetConnectedPin();
55 IKsAllocatorEx
* STDMETHODCALLTYPE
KsGetPipe(KSPEEKOPERATION Operation
);
56 HRESULT STDMETHODCALLTYPE
KsSetPipe(IKsAllocatorEx
*KsAllocator
);
57 ULONG STDMETHODCALLTYPE
KsGetPipeAllocatorFlag();
58 HRESULT STDMETHODCALLTYPE
KsSetPipeAllocatorFlag(ULONG Flag
);
59 GUID STDMETHODCALLTYPE
KsGetPinBusCache();
60 HRESULT STDMETHODCALLTYPE
KsSetPinBusCache(GUID Bus
);
61 PWCHAR STDMETHODCALLTYPE
KsGetPinName();
62 PWCHAR STDMETHODCALLTYPE
KsGetFilterName();
65 HRESULT STDMETHODCALLTYPE
Connect(IPin
*pReceivePin
, const AM_MEDIA_TYPE
*pmt
);
66 HRESULT STDMETHODCALLTYPE
ReceiveConnection(IPin
*pConnector
, const AM_MEDIA_TYPE
*pmt
);
67 HRESULT STDMETHODCALLTYPE
Disconnect();
68 HRESULT STDMETHODCALLTYPE
ConnectedTo(IPin
**pPin
);
69 HRESULT STDMETHODCALLTYPE
ConnectionMediaType(AM_MEDIA_TYPE
*pmt
);
70 HRESULT STDMETHODCALLTYPE
QueryPinInfo(PIN_INFO
*pInfo
);
71 HRESULT STDMETHODCALLTYPE
QueryDirection(PIN_DIRECTION
*pPinDir
);
72 HRESULT STDMETHODCALLTYPE
QueryId(LPWSTR
*Id
);
73 HRESULT STDMETHODCALLTYPE
QueryAccept(const AM_MEDIA_TYPE
*pmt
);
74 HRESULT STDMETHODCALLTYPE
EnumMediaTypes(IEnumMediaTypes
**ppEnum
);
75 HRESULT STDMETHODCALLTYPE
QueryInternalConnections(IPin
**apPin
, ULONG
*nPin
);
76 HRESULT STDMETHODCALLTYPE
EndOfStream();
77 HRESULT STDMETHODCALLTYPE
BeginFlush();
78 HRESULT STDMETHODCALLTYPE
EndFlush();
79 HRESULT STDMETHODCALLTYPE
NewSegment(REFERENCE_TIME tStart
, REFERENCE_TIME tStop
, double dRate
);
81 // ISpecifyPropertyPages
82 HRESULT STDMETHODCALLTYPE
GetPages(CAUUID
*pPages
);
85 HANDLE STDMETHODCALLTYPE
KsGetObjectHandle();
88 HRESULT STDMETHODCALLTYPE
Set(REFGUID guidPropSet
, DWORD dwPropID
, LPVOID pInstanceData
, DWORD cbInstanceData
, LPVOID pPropData
, DWORD cbPropData
);
89 HRESULT STDMETHODCALLTYPE
Get(REFGUID guidPropSet
, DWORD dwPropID
, LPVOID pInstanceData
, DWORD cbInstanceData
, LPVOID pPropData
, DWORD cbPropData
, DWORD
*pcbReturned
);
90 HRESULT STDMETHODCALLTYPE
QuerySupported(REFGUID guidPropSet
, DWORD dwPropID
, DWORD
*pTypeSupport
);
93 HRESULT STDMETHODCALLTYPE
KsProperty(PKSPROPERTY Property
, ULONG PropertyLength
, LPVOID PropertyData
, ULONG DataLength
, ULONG
* BytesReturned
);
94 HRESULT STDMETHODCALLTYPE
KsMethod(PKSMETHOD Method
, ULONG MethodLength
, LPVOID MethodData
, ULONG DataLength
, ULONG
* BytesReturned
);
95 HRESULT STDMETHODCALLTYPE
KsEvent(PKSEVENT Event
, ULONG EventLength
, LPVOID EventData
, ULONG DataLength
, ULONG
* BytesReturned
);
98 HRESULT STDMETHODCALLTYPE
Render(IPin
*ppinOut
, IGraphBuilder
*pGraph
);
99 HRESULT STDMETHODCALLTYPE
Backout(IPin
*ppinOut
, IGraphBuilder
*pGraph
);
102 HRESULT STDMETHODCALLTYPE
KsPinFactory(ULONG
* PinFactory
);
104 COutputPin(IBaseFilter
* ParentFilter
, LPCWSTR PinName
, ULONG PinId
);
105 virtual ~COutputPin();
109 IBaseFilter
* m_ParentFilter
;
113 IKsObject
* m_KsObjectParent
;
117 COutputPin::~COutputPin()
119 if (m_KsObjectParent
)
120 m_KsObjectParent
->Release();
123 COutputPin::COutputPin(
124 IBaseFilter
* ParentFilter
,
126 ULONG PinId
) : m_Ref(0), m_ParentFilter(ParentFilter
), m_PinName(PinName
), m_hPin(INVALID_HANDLE_VALUE
), m_PinId(PinId
), m_KsObjectParent(0), m_Pin(0)
130 hr
= m_ParentFilter
->QueryInterface(IID_IKsObject
, (LPVOID
*)&m_KsObjectParent
);
137 COutputPin::QueryInterface(
142 if (IsEqualGUID(refiid
, IID_IUnknown
) ||
143 IsEqualGUID(refiid
, IID_IPin
))
145 *Output
= PVOID(this);
146 reinterpret_cast<IUnknown
*>(*Output
)->AddRef();
149 else if (IsEqualGUID(refiid
, IID_IKsObject
))
151 *Output
= (IKsObject
*)(this);
152 reinterpret_cast<IKsObject
*>(*Output
)->AddRef();
155 else if (IsEqualGUID(refiid
, IID_IKsPropertySet
))
157 *Output
= (IKsPropertySet
*)(this);
158 reinterpret_cast<IKsPropertySet
*>(*Output
)->AddRef();
161 else if (IsEqualGUID(refiid
, IID_IKsControl
))
163 *Output
= (IKsControl
*)(this);
164 reinterpret_cast<IKsControl
*>(*Output
)->AddRef();
167 else if (IsEqualGUID(refiid
, IID_IStreamBuilder
))
169 *Output
= (IStreamBuilder
*)(this);
170 reinterpret_cast<IStreamBuilder
*>(*Output
)->AddRef();
173 else if (IsEqualGUID(refiid
, IID_IKsPinFactory
))
175 *Output
= (IKsPinFactory
*)(this);
176 reinterpret_cast<IKsPinFactory
*>(*Output
)->AddRef();
179 else if (IsEqualGUID(refiid
, IID_ISpecifyPropertyPages
))
181 *Output
= (ISpecifyPropertyPages
*)(this);
182 reinterpret_cast<ISpecifyPropertyPages
*>(*Output
)->AddRef();
185 else if (IsEqualGUID(refiid
, IID_IBaseFilter
))
187 OutputDebugStringW(L
"COutputPin::QueryInterface query IID_IBaseFilter\n");
191 WCHAR Buffer
[MAX_PATH
];
193 StringFromCLSID(refiid
, &lpstr
);
194 swprintf(Buffer
, L
"COutputPin::QueryInterface: NoInterface for %s\n", lpstr
);
195 OutputDebugStringW(Buffer
);
196 CoTaskMemFree(lpstr
);
198 return E_NOINTERFACE
;
201 //-------------------------------------------------------------------
202 // ISpecifyPropertyPages
207 COutputPin::GetPages(CAUUID
*pPages
)
209 OutputDebugStringW(L
"COutputPin::GetPages NotImplemented\n");
215 pPages
->pElems
= NULL
;
220 //-------------------------------------------------------------------
226 COutputPin::KsPinFactory(
229 *PinFactory
= m_PinId
;
234 //-------------------------------------------------------------------
242 IGraphBuilder
*pGraph
)
251 IGraphBuilder
*pGraph
)
255 //-------------------------------------------------------------------
260 COutputPin::KsGetObjectHandle()
266 //-------------------------------------------------------------------
271 COutputPin::KsProperty(
272 PKSPROPERTY Property
,
273 ULONG PropertyLength
,
276 ULONG
* BytesReturned
)
279 return KsSynchronousDeviceControl(m_hPin
, IOCTL_KS_PROPERTY
, (PVOID
)Property
, PropertyLength
, (PVOID
)PropertyData
, DataLength
, BytesReturned
);
284 COutputPin::KsMethod(
289 ULONG
* BytesReturned
)
292 return KsSynchronousDeviceControl(m_hPin
, IOCTL_KS_METHOD
, (PVOID
)Method
, MethodLength
, (PVOID
)MethodData
, DataLength
, BytesReturned
);
302 ULONG
* BytesReturned
)
307 return KsSynchronousDeviceControl(m_hPin
, IOCTL_KS_ENABLE_EVENT
, (PVOID
)Event
, EventLength
, (PVOID
)EventData
, DataLength
, BytesReturned
);
309 return KsSynchronousDeviceControl(m_hPin
, IOCTL_KS_DISABLE_EVENT
, (PVOID
)Event
, EventLength
, NULL
, 0, BytesReturned
);
313 //-------------------------------------------------------------------
321 LPVOID pInstanceData
,
322 DWORD cbInstanceData
,
330 PKSPROPERTY Property
= (PKSPROPERTY
)CoTaskMemAlloc(sizeof(KSPROPERTY
) + cbInstanceData
);
332 return E_OUTOFMEMORY
;
334 Property
->Set
= guidPropSet
;
335 Property
->Id
= dwPropID
;
336 Property
->Flags
= KSPROPERTY_TYPE_SET
;
338 CopyMemory((Property
+1), pInstanceData
, cbInstanceData
);
340 HRESULT hr
= KsProperty(Property
, sizeof(KSPROPERTY
) + cbInstanceData
, pPropData
, cbPropData
, &BytesReturned
);
341 CoTaskMemFree(Property
);
348 Property
.Set
= guidPropSet
;
349 Property
.Id
= dwPropID
;
350 Property
.Flags
= KSPROPERTY_TYPE_SET
;
352 HRESULT hr
= KsProperty(&Property
, sizeof(KSPROPERTY
), pPropData
, cbPropData
, &BytesReturned
);
362 LPVOID pInstanceData
,
363 DWORD cbInstanceData
,
372 PKSPROPERTY Property
= (PKSPROPERTY
)CoTaskMemAlloc(sizeof(KSPROPERTY
) + cbInstanceData
);
374 return E_OUTOFMEMORY
;
376 Property
->Set
= guidPropSet
;
377 Property
->Id
= dwPropID
;
378 Property
->Flags
= KSPROPERTY_TYPE_GET
;
380 CopyMemory((Property
+1), pInstanceData
, cbInstanceData
);
382 HRESULT hr
= KsProperty(Property
, sizeof(KSPROPERTY
) + cbInstanceData
, pPropData
, cbPropData
, &BytesReturned
);
383 CoTaskMemFree(Property
);
390 Property
.Set
= guidPropSet
;
391 Property
.Id
= dwPropID
;
392 Property
.Flags
= KSPROPERTY_TYPE_GET
;
394 HRESULT hr
= KsProperty(&Property
, sizeof(KSPROPERTY
), pPropData
, cbPropData
, &BytesReturned
);
401 COutputPin::QuerySupported(
409 Property
.Set
= guidPropSet
;
410 Property
.Id
= dwPropID
;
411 Property
.Flags
= KSPROPERTY_TYPE_SETSUPPORT
;
413 return KsProperty(&Property
, sizeof(KSPROPERTY
), pTypeSupport
, sizeof(DWORD
), &BytesReturned
);
417 //-------------------------------------------------------------------
422 COutputPin::Connect(IPin
*pReceivePin
, const AM_MEDIA_TYPE
*pmt
)
424 AM_MEDIA_TYPE MediaType
;
428 OutputDebugStringW(L
"COutputPin::Connect called\n");
431 hr
= pReceivePin
->QueryAccept(pmt
);
437 // get parent filter handle
438 hFilter
= m_KsObjectParent
->KsGetObjectHandle();
440 // get media type count
441 ZeroMemory(&MediaType
, sizeof(AM_MEDIA_TYPE
));
442 hr
= KsGetMediaType(0, &MediaType
, hFilter
, m_PinId
);
447 hr
= pReceivePin
->QueryAccept(&MediaType
);
454 //FIXME create pin handle
456 // receive connection;
457 hr
= pReceivePin
->ReceiveConnection((IPin
*)this, pmt
);
460 // increment reference count
461 pReceivePin
->AddRef();
463 OutputDebugStringW(L
"COutputPin::Connect success\n");
471 COutputPin::ReceiveConnection(IPin
*pConnector
, const AM_MEDIA_TYPE
*pmt
)
477 COutputPin::Disconnect( void)
481 // pin was not connected
486 //check if filter is active
491 OutputDebugStringW(L
"COutputPin::Disconnect\n");
496 COutputPin::ConnectedTo(IPin
**pPin
)
503 // increment reference count
510 return VFW_E_NOT_CONNECTED
;
514 COutputPin::ConnectionMediaType(AM_MEDIA_TYPE
*pmt
)
516 OutputDebugStringW(L
"COutputPin::ConnectionMediaType called\n");
521 COutputPin::QueryPinInfo(PIN_INFO
*pInfo
)
523 wcscpy(pInfo
->achName
, m_PinName
);
524 pInfo
->dir
= PINDIR_OUTPUT
;
525 pInfo
->pFilter
= m_ParentFilter
;
526 m_ParentFilter
->AddRef();
532 COutputPin::QueryDirection(PIN_DIRECTION
*pPinDir
)
536 *pPinDir
= PINDIR_OUTPUT
;
544 COutputPin::QueryId(LPWSTR
*Id
)
546 *Id
= (LPWSTR
)CoTaskMemAlloc((wcslen(m_PinName
)+1)*sizeof(WCHAR
));
548 return E_OUTOFMEMORY
;
550 wcscpy(*Id
, m_PinName
);
555 COutputPin::QueryAccept(const AM_MEDIA_TYPE
*pmt
)
557 OutputDebugStringW(L
"COutputPin::QueryAccept called\n");
562 COutputPin::EnumMediaTypes(IEnumMediaTypes
**ppEnum
)
565 ULONG MediaTypeCount
= 0, Index
;
566 AM_MEDIA_TYPE
* MediaTypes
;
569 OutputDebugStringW(L
"COutputPin::EnumMediaTypes called\n");
571 if (!m_KsObjectParent
)
574 return E_NOINTERFACE
;
577 // get parent filter handle
578 hFilter
= m_KsObjectParent
->KsGetObjectHandle();
580 // query media type count
581 hr
= KsGetMediaTypeCount(hFilter
, m_PinId
, &MediaTypeCount
);
582 if (FAILED(hr
) || !MediaTypeCount
)
584 OutputDebugStringW(L
"COutputPin::EnumMediaTypes failed1\n");
588 // allocate media types
589 MediaTypes
= (AM_MEDIA_TYPE
*)CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE
) * MediaTypeCount
);
593 OutputDebugStringW(L
"COutputPin::EnumMediaTypes CoTaskMemAlloc\n");
594 return E_OUTOFMEMORY
;
598 ZeroMemory(MediaTypes
, sizeof(AM_MEDIA_TYPE
) * MediaTypeCount
);
600 for(Index
= 0; Index
< MediaTypeCount
; Index
++)
603 hr
= KsGetMediaType(Index
, &MediaTypes
[Index
], hFilter
, m_PinId
);
607 CoTaskMemFree(MediaTypes
);
608 OutputDebugStringW(L
"COutputPin::EnumMediaTypes failed2\n");
613 return CEnumMediaTypes_fnConstructor(MediaTypeCount
, MediaTypes
, IID_IEnumMediaTypes
, (void**)ppEnum
);
617 COutputPin::QueryInternalConnections(IPin
**apPin
, ULONG
*nPin
)
619 OutputDebugStringW(L
"COutputPin::QueryInternalConnections called\n");
624 COutputPin::EndOfStream( void)
626 OutputDebugStringW(L
"COutputPin::EndOfStream called\n");
631 COutputPin::BeginFlush( void)
633 OutputDebugStringW(L
"COutputPin::BeginFlush called\n");
638 COutputPin::EndFlush( void)
640 OutputDebugStringW(L
"COutputPin::EndFlush called\n");
645 COutputPin::NewSegment(REFERENCE_TIME tStart
, REFERENCE_TIME tStop
, double dRate
)
647 OutputDebugStringW(L
"COutputPin::NewSegment called\n");
653 COutputPin_Constructor(
654 IBaseFilter
* ParentFilter
,
660 COutputPin
* handler
= new COutputPin(ParentFilter
, PinName
, PinId
);
663 return E_OUTOFMEMORY
;
665 if (FAILED(handler
->QueryInterface(riid
, ppv
)))
669 return E_NOINTERFACE
;