2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS WDM Streaming ActiveMovie Proxy
4 * FILE: dll/directx/ksproxy/input_pin.cpp
5 * PURPOSE: InputPin of Proxy Filter
7 * PROGRAMMERS: Johannes Anderwald (janderwald@reactos.org)
11 const GUID IID_IKsPinPipe
= {0xe539cd90, 0xa8b4, 0x11d1, {0x81, 0x89, 0x00, 0xa0, 0xc9, 0x06, 0x28, 0x02}};
12 const GUID IID_IKsPinEx
= {0x7bb38260L
, 0xd19c, 0x11d2, {0xb3, 0x8a, 0x00, 0xa0, 0xc9, 0x5e, 0xc2, 0x2e}};
17 const GUID KSPROPSETID_Connection
= {0x1D58C920L
, 0xAC9B, 0x11CF, {0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00}};
19 KSPIN_INTERFACE StandardPinInterface
=
21 {STATIC_KSINTERFACESETID_Standard
},
22 KSINTERFACE_STANDARD_STREAMING
,
26 KSPIN_MEDIUM StandardPinMedium
=
28 {STATIC_KSMEDIUMSETID_Standard
},
29 KSMEDIUM_TYPE_ANYINSTANCE
,
35 KSPIN_INTERFACE StandardPinInterface
=
37 STATIC_KSINTERFACESETID_Standard
,
38 KSINTERFACE_STANDARD_STREAMING
,
42 KSPIN_MEDIUM StandardPinMedium
=
44 STATIC_KSMEDIUMSETID_Standard
,
45 KSMEDIUM_TYPE_ANYINSTANCE
,
51 class CInputPin
: public IPin
,
52 public IKsPropertySet
,
59 public IStreamBuilder
,
60 public IKsAggregateControl
,
61 public IQualityControl
,
62 public ISpecifyPropertyPages
65 STDMETHODIMP
QueryInterface( REFIID InterfaceId
, PVOID
* Interface
);
67 STDMETHODIMP_(ULONG
) AddRef()
69 InterlockedIncrement(&m_Ref
);
72 STDMETHODIMP_(ULONG
) Release()
74 InterlockedDecrement(&m_Ref
);
84 HRESULT STDMETHODCALLTYPE
KsGetPinFramingCache(PKSALLOCATOR_FRAMING_EX
*FramingEx
, PFRAMING_PROP FramingProp
, FRAMING_CACHE_OPS Option
);
85 HRESULT STDMETHODCALLTYPE
KsSetPinFramingCache(PKSALLOCATOR_FRAMING_EX FramingEx
, PFRAMING_PROP FramingProp
, FRAMING_CACHE_OPS Option
);
86 IPin
* STDMETHODCALLTYPE
KsGetConnectedPin();
87 IKsAllocatorEx
* STDMETHODCALLTYPE
KsGetPipe(KSPEEKOPERATION Operation
);
88 HRESULT STDMETHODCALLTYPE
KsSetPipe(IKsAllocatorEx
*KsAllocator
);
89 ULONG STDMETHODCALLTYPE
KsGetPipeAllocatorFlag();
90 HRESULT STDMETHODCALLTYPE
KsSetPipeAllocatorFlag(ULONG Flag
);
91 GUID STDMETHODCALLTYPE
KsGetPinBusCache();
92 HRESULT STDMETHODCALLTYPE
KsSetPinBusCache(GUID Bus
);
93 PWCHAR STDMETHODCALLTYPE
KsGetPinName();
94 PWCHAR STDMETHODCALLTYPE
KsGetFilterName();
97 HRESULT STDMETHODCALLTYPE
Connect(IPin
*pReceivePin
, const AM_MEDIA_TYPE
*pmt
);
98 HRESULT STDMETHODCALLTYPE
ReceiveConnection(IPin
*pConnector
, const AM_MEDIA_TYPE
*pmt
);
99 HRESULT STDMETHODCALLTYPE
Disconnect();
100 HRESULT STDMETHODCALLTYPE
ConnectedTo(IPin
**pPin
);
101 HRESULT STDMETHODCALLTYPE
ConnectionMediaType(AM_MEDIA_TYPE
*pmt
);
102 HRESULT STDMETHODCALLTYPE
QueryPinInfo(PIN_INFO
*pInfo
);
103 HRESULT STDMETHODCALLTYPE
QueryDirection(PIN_DIRECTION
*pPinDir
);
104 HRESULT STDMETHODCALLTYPE
QueryId(LPWSTR
*Id
);
105 HRESULT STDMETHODCALLTYPE
QueryAccept(const AM_MEDIA_TYPE
*pmt
);
106 HRESULT STDMETHODCALLTYPE
EnumMediaTypes(IEnumMediaTypes
**ppEnum
);
107 HRESULT STDMETHODCALLTYPE
QueryInternalConnections(IPin
**apPin
, ULONG
*nPin
);
108 HRESULT STDMETHODCALLTYPE
EndOfStream();
109 HRESULT STDMETHODCALLTYPE
BeginFlush();
110 HRESULT STDMETHODCALLTYPE
EndFlush();
111 HRESULT STDMETHODCALLTYPE
NewSegment(REFERENCE_TIME tStart
, REFERENCE_TIME tStop
, double dRate
);
113 // ISpecifyPropertyPages
114 HRESULT STDMETHODCALLTYPE
GetPages(CAUUID
*pPages
);
117 HANDLE STDMETHODCALLTYPE
KsGetObjectHandle();
120 HRESULT STDMETHODCALLTYPE
Set(REFGUID guidPropSet
, DWORD dwPropID
, LPVOID pInstanceData
, DWORD cbInstanceData
, LPVOID pPropData
, DWORD cbPropData
);
121 HRESULT STDMETHODCALLTYPE
Get(REFGUID guidPropSet
, DWORD dwPropID
, LPVOID pInstanceData
, DWORD cbInstanceData
, LPVOID pPropData
, DWORD cbPropData
, DWORD
*pcbReturned
);
122 HRESULT STDMETHODCALLTYPE
QuerySupported(REFGUID guidPropSet
, DWORD dwPropID
, DWORD
*pTypeSupport
);
125 HRESULT STDMETHODCALLTYPE
KsProperty(PKSPROPERTY Property
, ULONG PropertyLength
, LPVOID PropertyData
, ULONG DataLength
, ULONG
* BytesReturned
);
126 HRESULT STDMETHODCALLTYPE
KsMethod(PKSMETHOD Method
, ULONG MethodLength
, LPVOID MethodData
, ULONG DataLength
, ULONG
* BytesReturned
);
127 HRESULT STDMETHODCALLTYPE
KsEvent(PKSEVENT Event
, ULONG EventLength
, LPVOID EventData
, ULONG DataLength
, ULONG
* BytesReturned
);
130 HRESULT STDMETHODCALLTYPE
KsQueryMediums(PKSMULTIPLE_ITEM
* MediumList
);
131 HRESULT STDMETHODCALLTYPE
KsQueryInterfaces(PKSMULTIPLE_ITEM
* InterfaceList
);
132 HRESULT STDMETHODCALLTYPE
KsCreateSinkPinHandle(KSPIN_INTERFACE
& Interface
, KSPIN_MEDIUM
& Medium
);
133 HRESULT STDMETHODCALLTYPE
KsGetCurrentCommunication(KSPIN_COMMUNICATION
*Communication
, KSPIN_INTERFACE
*Interface
, KSPIN_MEDIUM
*Medium
);
134 HRESULT STDMETHODCALLTYPE
KsPropagateAcquire();
135 HRESULT STDMETHODCALLTYPE
KsDeliver(IMediaSample
* Sample
, ULONG Flags
);
136 HRESULT STDMETHODCALLTYPE
KsMediaSamplesCompleted(PKSSTREAM_SEGMENT StreamSegment
);
137 IMemAllocator
* STDMETHODCALLTYPE
KsPeekAllocator(KSPEEKOPERATION Operation
);
138 HRESULT STDMETHODCALLTYPE
KsReceiveAllocator(IMemAllocator
*MemAllocator
);
139 HRESULT STDMETHODCALLTYPE
KsRenegotiateAllocator();
140 LONG STDMETHODCALLTYPE
KsIncrementPendingIoCount();
141 LONG STDMETHODCALLTYPE
KsDecrementPendingIoCount();
142 HRESULT STDMETHODCALLTYPE
KsQualityNotify(ULONG Proportion
, REFERENCE_TIME TimeDelta
);
144 VOID STDMETHODCALLTYPE
KsNotifyError(IMediaSample
* Sample
, HRESULT hr
);
147 HRESULT STDMETHODCALLTYPE
GetAllocator(IMemAllocator
**ppAllocator
);
148 HRESULT STDMETHODCALLTYPE
NotifyAllocator(IMemAllocator
*pAllocator
, BOOL bReadOnly
);
149 HRESULT STDMETHODCALLTYPE
GetAllocatorRequirements(ALLOCATOR_PROPERTIES
*pProps
);
150 HRESULT STDMETHODCALLTYPE
Receive(IMediaSample
*pSample
);
151 HRESULT STDMETHODCALLTYPE
ReceiveMultiple(IMediaSample
**pSamples
, long nSamples
, long *nSamplesProcessed
);
152 HRESULT STDMETHODCALLTYPE
ReceiveCanBlock( void);
155 HRESULT STDMETHODCALLTYPE
KsPinFactory(ULONG
* PinFactory
);
158 HRESULT STDMETHODCALLTYPE
Render(IPin
*ppinOut
, IGraphBuilder
*pGraph
);
159 HRESULT STDMETHODCALLTYPE
Backout(IPin
*ppinOut
, IGraphBuilder
*pGraph
);
161 //IKsAggregateControl
162 HRESULT STDMETHODCALLTYPE
KsAddAggregate(IN REFGUID AggregateClass
);
163 HRESULT STDMETHODCALLTYPE
KsRemoveAggregate(REFGUID AggregateClass
);
166 HRESULT STDMETHODCALLTYPE
Notify(IBaseFilter
*pSelf
, Quality q
);
167 HRESULT STDMETHODCALLTYPE
SetSink(IQualityControl
*piqc
);
169 //---------------------------------------------------------------
170 HRESULT STDMETHODCALLTYPE
CheckFormat(const AM_MEDIA_TYPE
*pmt
);
171 HRESULT STDMETHODCALLTYPE
CreatePin(const AM_MEDIA_TYPE
*pmt
);
172 HRESULT STDMETHODCALLTYPE
CreatePinHandle(PKSPIN_MEDIUM Medium
, PKSPIN_INTERFACE Interface
, const AM_MEDIA_TYPE
*pmt
);
173 CInputPin(IBaseFilter
* ParentFilter
, LPCWSTR PinName
, HANDLE hFilter
, ULONG PinId
, KSPIN_COMMUNICATION Communication
);
174 virtual ~CInputPin(){};
178 IBaseFilter
* m_ParentFilter
;
183 IMemAllocator
* m_MemAllocator
;
185 KSPIN_COMMUNICATION m_Communication
;
186 KSPIN_INTERFACE m_Interface
;
187 KSPIN_MEDIUM m_Medium
;
188 AM_MEDIA_TYPE m_MediaFormat
;
191 IKsInterfaceHandler
* m_InterfaceHandler
;
192 IKsAllocatorEx
* m_KsAllocatorEx
;
193 ULONG m_PipeAllocatorFlag
;
194 BOOL m_bPinBusCacheInitialized
;
197 FRAMING_PROP m_FramingProp
[4];
198 PKSALLOCATOR_FRAMING_EX m_FramingEx
[4];
201 CInputPin::CInputPin(
202 IBaseFilter
* ParentFilter
,
206 KSPIN_COMMUNICATION Communication
) : m_Ref(0),
207 m_ParentFilter(ParentFilter
),
210 m_hPin(INVALID_HANDLE_VALUE
),
214 m_Communication(Communication
),
217 m_InterfaceHandler(0),
219 m_PipeAllocatorFlag(0),
220 m_bPinBusCacheInitialized(0),
223 ZeroMemory(m_FramingProp
, sizeof(m_FramingProp
));
224 ZeroMemory(m_FramingEx
, sizeof(m_FramingEx
));
226 ZeroMemory(&m_MediaFormat
, sizeof(AM_MEDIA_TYPE
));
227 HRESULT hr
= KsGetMediaType(0, &m_MediaFormat
, m_hFilter
, m_PinId
);
233 CInputPin::QueryInterface(
241 if (IsEqualGUID(refiid
, IID_IUnknown
) ||
242 IsEqualGUID(refiid
, IID_IPin
))
244 *Output
= PVOID(this);
245 reinterpret_cast<IUnknown
*>(*Output
)->AddRef();
248 else if (IsEqualGUID(refiid
, IID_IMemInputPin
))
250 if (m_hPin
== INVALID_HANDLE_VALUE
)
252 HRESULT hr
= CreatePin(&m_MediaFormat
);
257 *Output
= (IMemInputPin
*)(this);
258 reinterpret_cast<IMemInputPin
*>(*Output
)->AddRef();
261 else if (IsEqualGUID(refiid
, IID_IKsObject
))
263 *Output
= (IKsObject
*)(this);
264 reinterpret_cast<IKsObject
*>(*Output
)->AddRef();
267 else if (IsEqualGUID(refiid
, IID_IKsPropertySet
))
269 if (m_hPin
== INVALID_HANDLE_VALUE
)
271 HRESULT hr
= CreatePin(&m_MediaFormat
);
276 *Output
= (IKsPropertySet
*)(this);
277 reinterpret_cast<IKsPropertySet
*>(*Output
)->AddRef();
280 else if (IsEqualGUID(refiid
, IID_IKsControl
))
282 *Output
= (IKsControl
*)(this);
283 reinterpret_cast<IKsControl
*>(*Output
)->AddRef();
286 else if (IsEqualGUID(refiid
, IID_IKsPin
) ||
287 IsEqualGUID(refiid
, IID_IKsPinEx
))
289 *Output
= (IKsPinEx
*)(this);
290 reinterpret_cast<IKsPinEx
*>(*Output
)->AddRef();
293 else if (IsEqualGUID(refiid
, IID_IKsPinPipe
))
295 *Output
= (IKsPinPipe
*)(this);
296 reinterpret_cast<IKsPinPipe
*>(*Output
)->AddRef();
299 else if (IsEqualGUID(refiid
, IID_IKsPinFactory
))
301 *Output
= (IKsPinFactory
*)(this);
302 reinterpret_cast<IKsPinFactory
*>(*Output
)->AddRef();
306 else if (IsEqualGUID(refiid
, IID_IStreamBuilder
))
308 *Output
= (IStreamBuilder
*)(this);
309 reinterpret_cast<IStreamBuilder
*>(*Output
)->AddRef();
313 else if (IsEqualGUID(refiid
, IID_IKsAggregateControl
))
315 *Output
= (IKsAggregateControl
*)(this);
316 reinterpret_cast<IKsAggregateControl
*>(*Output
)->AddRef();
319 else if (IsEqualGUID(refiid
, IID_IQualityControl
))
321 *Output
= (IQualityControl
*)(this);
322 reinterpret_cast<IQualityControl
*>(*Output
)->AddRef();
325 else if (IsEqualGUID(refiid
, IID_ISpecifyPropertyPages
))
327 *Output
= (ISpecifyPropertyPages
*)(this);
328 reinterpret_cast<ISpecifyPropertyPages
*>(*Output
)->AddRef();
333 StringFromCLSID(refiid
, &lpstr
);
334 swprintf(Buffer
, L
"CInputPin::QueryInterface: NoInterface for %s\n", lpstr
);
335 OutputDebugStringW(Buffer
);
336 CoTaskMemFree(lpstr
);
338 return E_NOINTERFACE
;
340 //-------------------------------------------------------------------
341 // IQualityControl interface
349 OutputDebugStringW(L
"CInputPin::Notify NotImplemented\n");
356 IQualityControl
*piqc
)
358 OutputDebugStringW(L
"CInputPin::SetSink NotImplemented\n");
363 //-------------------------------------------------------------------
364 // IKsAggregateControl interface
368 CInputPin::KsAddAggregate(
369 IN REFGUID AggregateClass
)
371 OutputDebugStringW(L
"CInputPin::KsAddAggregate NotImplemented\n");
377 CInputPin::KsRemoveAggregate(
378 REFGUID AggregateClass
)
380 OutputDebugStringW(L
"CInputPin::KsRemoveAggregate NotImplemented\n");
384 //-------------------------------------------------------------------
392 IGraphBuilder
*pGraph
)
394 OutputDebugStringW(L
"CInputPin::Render\n");
402 IGraphBuilder
*pGraph
)
404 OutputDebugStringW(L
"CInputPin::Backout\n");
408 //-------------------------------------------------------------------
414 CInputPin::KsPinFactory(
417 OutputDebugStringW(L
"CInputPin::KsPinFactory\n");
418 *PinFactory
= m_PinId
;
422 //-------------------------------------------------------------------
428 CInputPin::KsGetPinFramingCache(
429 PKSALLOCATOR_FRAMING_EX
*FramingEx
,
430 PFRAMING_PROP FramingProp
,
431 FRAMING_CACHE_OPS Option
)
433 if (Option
> Framing_Cache_Write
|| Option
< Framing_Cache_ReadLast
)
439 // get framing properties
440 *FramingProp
= m_FramingProp
[Option
];
441 *FramingEx
= m_FramingEx
[Option
];
448 CInputPin::KsSetPinFramingCache(
449 PKSALLOCATOR_FRAMING_EX FramingEx
,
450 PFRAMING_PROP FramingProp
,
451 FRAMING_CACHE_OPS Option
)
456 if (m_FramingEx
[Option
])
458 for(Index
= 1; Index
< 4; Index
++)
460 if (m_FramingEx
[Index
] == m_FramingEx
[Option
])
466 // existing framing is only used once
467 CoTaskMemFree(m_FramingEx
[Option
]);
472 m_FramingEx
[Option
] = FramingEx
;
473 m_FramingProp
[Option
] = *FramingProp
;
480 CInputPin::KsGetConnectedPin()
487 CInputPin::KsGetPipe(
488 KSPEEKOPERATION Operation
)
490 if (Operation
== KsPeekOperation_AddRef
)
493 m_KsAllocatorEx
->AddRef();
495 return m_KsAllocatorEx
;
500 CInputPin::KsSetPipe(
501 IKsAllocatorEx
*KsAllocator
)
504 KsAllocator
->AddRef();
507 m_KsAllocatorEx
->Release();
509 m_KsAllocatorEx
= KsAllocator
;
515 CInputPin::KsGetPipeAllocatorFlag()
517 return m_PipeAllocatorFlag
;
523 CInputPin::KsSetPipeAllocatorFlag(
526 m_PipeAllocatorFlag
= Flag
;
532 CInputPin::KsGetPinBusCache()
534 if (!m_bPinBusCacheInitialized
)
536 CopyMemory(&m_PinBusCache
, &m_Medium
.Set
, sizeof(GUID
));
537 m_bPinBusCacheInitialized
= TRUE
;
540 return m_PinBusCache
;
545 CInputPin::KsSetPinBusCache(
548 CopyMemory(&m_PinBusCache
, &Bus
, sizeof(GUID
));
554 CInputPin::KsGetPinName()
556 return (PWCHAR
)m_PinName
;
562 CInputPin::KsGetFilterName()
567 //-------------------------------------------------------------------
568 // ISpecifyPropertyPages
573 CInputPin::GetPages(CAUUID
*pPages
)
579 pPages
->pElems
= NULL
;
584 //-------------------------------------------------------------------
591 CInputPin::GetAllocator(IMemAllocator
**ppAllocator
)
593 OutputDebugStringW(L
"CInputPin::GetAllocator\n");
594 return VFW_E_NO_ALLOCATOR
;
599 CInputPin::NotifyAllocator(IMemAllocator
*pAllocator
, BOOL bReadOnly
)
603 ALLOCATOR_PROPERTIES Properties
;
605 hr
= pAllocator
->GetProperties(&Properties
);
606 swprintf(Buffer
, L
"CInputPin::NotifyAllocator hr %lx bReadOnly, %u cbAlign %u cbBuffer %u cbPrefix %u cBuffers %u\n", hr
, bReadOnly
, Properties
.cbAlign
, Properties
.cbBuffer
, Properties
.cbPrefix
, Properties
.cBuffers
);
607 OutputDebugStringW(Buffer
);
611 pAllocator
->AddRef();
616 m_MemAllocator
->Release();
619 m_MemAllocator
= pAllocator
;
620 m_ReadOnly
= bReadOnly
;
626 CInputPin::GetAllocatorRequirements(ALLOCATOR_PROPERTIES
*pProps
)
628 KSALLOCATOR_FRAMING Framing
;
633 Property
.Set
= KSPROPSETID_Connection
;
634 Property
.Id
= KSPROPERTY_CONNECTION_ALLOCATORFRAMING
;
635 Property
.Flags
= KSPROPERTY_TYPE_SET
;
637 hr
= KsProperty(&Property
, sizeof(KSPROPERTY
), (PVOID
)&Framing
, sizeof(KSALLOCATOR_FRAMING
), &BytesReturned
);
640 pProps
->cBuffers
= Framing
.Frames
;
641 pProps
->cbBuffer
= Framing
.FrameSize
;
642 pProps
->cbAlign
= Framing
.FileAlignment
;
643 pProps
->cbPrefix
= 0;
649 swprintf(Buffer
, L
"CInputPin::GetAllocatorRequirements hr %lx m_hPin %p cBuffers %u cbBuffer %u cbAlign %u cbPrefix %u\n", hr
, m_hPin
, pProps
->cBuffers
, pProps
->cbBuffer
, pProps
->cbAlign
, pProps
->cbPrefix
);
650 OutputDebugStringW(Buffer
);
657 CInputPin::Receive(IMediaSample
*pSample
)
659 OutputDebugStringW(L
"CInputPin::Receive NotImplemented\n");
666 CInputPin::ReceiveMultiple(IMediaSample
**pSamples
, long nSamples
, long *nSamplesProcessed
)
668 OutputDebugStringW(L
"CInputPin::ReceiveMultiple NotImplemented\n");
675 CInputPin::ReceiveCanBlock( void)
677 OutputDebugStringW(L
"CInputPin::ReceiveCanBlock NotImplemented\n");
682 //-------------------------------------------------------------------
688 CInputPin::KsQueryMediums(
689 PKSMULTIPLE_ITEM
* MediumList
)
691 return KsGetMultiplePinFactoryItems(m_hFilter
, m_PinId
, KSPROPERTY_PIN_MEDIUMS
, (PVOID
*)MediumList
);
696 CInputPin::KsQueryInterfaces(
697 PKSMULTIPLE_ITEM
* InterfaceList
)
699 return KsGetMultiplePinFactoryItems(m_hFilter
, m_PinId
, KSPROPERTY_PIN_INTERFACES
, (PVOID
*)InterfaceList
);
704 CInputPin::KsCreateSinkPinHandle(
705 KSPIN_INTERFACE
& Interface
,
706 KSPIN_MEDIUM
& Medium
)
708 return CreatePin(&m_MediaFormat
);
713 CInputPin::KsGetCurrentCommunication(
714 KSPIN_COMMUNICATION
*Communication
,
715 KSPIN_INTERFACE
*Interface
,
716 KSPIN_MEDIUM
*Medium
)
720 *Communication
= m_Communication
;
726 return VFW_E_NOT_CONNECTED
;
728 CopyMemory(Interface
, &m_Interface
, sizeof(KSPIN_INTERFACE
));
734 return VFW_E_NOT_CONNECTED
;
736 CopyMemory(Medium
, &m_Medium
, sizeof(KSPIN_MEDIUM
));
743 CInputPin::KsPropagateAcquire()
750 assert(m_hPin
!= INVALID_HANDLE_VALUE
);
752 Property
.Set
= KSPROPSETID_Connection
;
753 Property
.Id
= KSPROPERTY_CONNECTION_STATE
;
754 Property
.Flags
= KSPROPERTY_TYPE_SET
;
756 State
= KSSTATE_ACQUIRE
;
758 hr
= KsProperty(&Property
, sizeof(KSPROPERTY
), (LPVOID
)&State
, sizeof(KSSTATE
), &BytesReturned
);
761 //propagate to connected pin on the pipe
768 CInputPin::KsDeliver(
769 IMediaSample
* Sample
,
777 CInputPin::KsMediaSamplesCompleted(PKSSTREAM_SEGMENT StreamSegment
)
784 CInputPin::KsPeekAllocator(KSPEEKOPERATION Operation
)
786 if (Operation
== KsPeekOperation_AddRef
)
788 // add reference on allocator
789 m_MemAllocator
->AddRef();
792 return m_MemAllocator
;
797 CInputPin::KsReceiveAllocator(IMemAllocator
*MemAllocator
)
802 MemAllocator
->AddRef();
807 m_MemAllocator
->Release();
810 m_MemAllocator
= MemAllocator
;
816 CInputPin::KsRenegotiateAllocator()
823 CInputPin::KsIncrementPendingIoCount()
825 return InterlockedIncrement((volatile LONG
*)&m_IoCount
);
830 CInputPin::KsDecrementPendingIoCount()
832 return InterlockedDecrement((volatile LONG
*)&m_IoCount
);
837 CInputPin::KsQualityNotify(
839 REFERENCE_TIME TimeDelta
)
841 OutputDebugStringW(L
"CInputPin::KsQualityNotify NotImplemented\n");
846 //-------------------------------------------------------------------
852 CInputPin::KsNotifyError(
853 IMediaSample
* Sample
,
856 OutputDebugStringW(L
"CInputPin::KsNotifyError NotImplemented\n");
860 //-------------------------------------------------------------------
865 CInputPin::KsProperty(
866 PKSPROPERTY Property
,
867 ULONG PropertyLength
,
870 ULONG
* BytesReturned
)
872 assert(m_hPin
!= INVALID_HANDLE_VALUE
);
873 return KsSynchronousDeviceControl(m_hPin
, IOCTL_KS_PROPERTY
, (PVOID
)Property
, PropertyLength
, (PVOID
)PropertyData
, DataLength
, BytesReturned
);
883 ULONG
* BytesReturned
)
885 assert(m_hPin
!= INVALID_HANDLE_VALUE
);
886 return KsSynchronousDeviceControl(m_hPin
, IOCTL_KS_METHOD
, (PVOID
)Method
, MethodLength
, (PVOID
)MethodData
, DataLength
, BytesReturned
);
896 ULONG
* BytesReturned
)
898 assert(m_hPin
!= INVALID_HANDLE_VALUE
);
901 return KsSynchronousDeviceControl(m_hPin
, IOCTL_KS_ENABLE_EVENT
, (PVOID
)Event
, EventLength
, (PVOID
)EventData
, DataLength
, BytesReturned
);
903 return KsSynchronousDeviceControl(m_hPin
, IOCTL_KS_DISABLE_EVENT
, (PVOID
)Event
, EventLength
, NULL
, 0, BytesReturned
);
907 //-------------------------------------------------------------------
915 LPVOID pInstanceData
,
916 DWORD cbInstanceData
,
924 PKSPROPERTY Property
= (PKSPROPERTY
)CoTaskMemAlloc(sizeof(KSPROPERTY
) + cbInstanceData
);
926 return E_OUTOFMEMORY
;
928 Property
->Set
= guidPropSet
;
929 Property
->Id
= dwPropID
;
930 Property
->Flags
= KSPROPERTY_TYPE_SET
;
932 CopyMemory((Property
+1), pInstanceData
, cbInstanceData
);
934 HRESULT hr
= KsProperty(Property
, sizeof(KSPROPERTY
) + cbInstanceData
, pPropData
, cbPropData
, &BytesReturned
);
935 CoTaskMemFree(Property
);
942 Property
.Set
= guidPropSet
;
943 Property
.Id
= dwPropID
;
944 Property
.Flags
= KSPROPERTY_TYPE_SET
;
946 HRESULT hr
= KsProperty(&Property
, sizeof(KSPROPERTY
), pPropData
, cbPropData
, &BytesReturned
);
956 LPVOID pInstanceData
,
957 DWORD cbInstanceData
,
966 PKSPROPERTY Property
= (PKSPROPERTY
)CoTaskMemAlloc(sizeof(KSPROPERTY
) + cbInstanceData
);
968 return E_OUTOFMEMORY
;
970 Property
->Set
= guidPropSet
;
971 Property
->Id
= dwPropID
;
972 Property
->Flags
= KSPROPERTY_TYPE_GET
;
974 CopyMemory((Property
+1), pInstanceData
, cbInstanceData
);
976 HRESULT hr
= KsProperty(Property
, sizeof(KSPROPERTY
) + cbInstanceData
, pPropData
, cbPropData
, &BytesReturned
);
977 CoTaskMemFree(Property
);
984 Property
.Set
= guidPropSet
;
985 Property
.Id
= dwPropID
;
986 Property
.Flags
= KSPROPERTY_TYPE_GET
;
988 HRESULT hr
= KsProperty(&Property
, sizeof(KSPROPERTY
), pPropData
, cbPropData
, &BytesReturned
);
995 CInputPin::QuerySupported(
1000 KSPROPERTY Property
;
1001 ULONG BytesReturned
;
1003 Property
.Set
= guidPropSet
;
1004 Property
.Id
= dwPropID
;
1005 Property
.Flags
= KSPROPERTY_TYPE_SETSUPPORT
;
1007 return KsProperty(&Property
, sizeof(KSPROPERTY
), pTypeSupport
, sizeof(DWORD
), &BytesReturned
);
1011 //-------------------------------------------------------------------
1016 CInputPin::KsGetObjectHandle()
1022 //-------------------------------------------------------------------
1027 CInputPin::Connect(IPin
*pReceivePin
, const AM_MEDIA_TYPE
*pmt
)
1029 OutputDebugStringW(L
"CInputPin::Connect NotImplemented\n");
1036 CInputPin::ReceiveConnection(IPin
*pConnector
, const AM_MEDIA_TYPE
*pmt
)
1042 // already connected
1043 return VFW_E_ALREADY_CONNECTED
;
1046 // first check format
1047 hr
= CheckFormat(pmt
);
1050 // format is not supported
1054 hr
= CreatePin(pmt
);
1067 CInputPin::Disconnect( void)
1071 // pin was not connected
1076 //check if filter is active
1081 OutputDebugStringW(L
"CInputPin::Disconnect\n");
1086 CInputPin::ConnectedTo(IPin
**pPin
)
1093 // increment reference count
1100 return VFW_E_NOT_CONNECTED
;
1104 CInputPin::ConnectionMediaType(AM_MEDIA_TYPE
*pmt
)
1107 return VFW_E_NOT_CONNECTED
;
1109 OutputDebugStringW(L
"CInputPin::ConnectionMediaType NotImplemented\n");
1115 CInputPin::QueryPinInfo(PIN_INFO
*pInfo
)
1117 wcscpy(pInfo
->achName
, m_PinName
);
1118 pInfo
->dir
= PINDIR_INPUT
;
1119 pInfo
->pFilter
= m_ParentFilter
;
1120 m_ParentFilter
->AddRef();
1126 CInputPin::QueryDirection(PIN_DIRECTION
*pPinDir
)
1130 *pPinDir
= PINDIR_INPUT
;
1138 CInputPin::QueryId(LPWSTR
*Id
)
1140 *Id
= (LPWSTR
)CoTaskMemAlloc((wcslen(m_PinName
)+1)*sizeof(WCHAR
));
1142 return E_OUTOFMEMORY
;
1144 wcscpy(*Id
, m_PinName
);
1150 CInputPin::QueryAccept(
1151 const AM_MEDIA_TYPE
*pmt
)
1153 return CheckFormat(pmt
);
1157 CInputPin::EnumMediaTypes(IEnumMediaTypes
**ppEnum
)
1160 ULONG MediaTypeCount
= 0, Index
;
1161 AM_MEDIA_TYPE
* MediaTypes
;
1163 // query media type count
1164 hr
= KsGetMediaTypeCount(m_hFilter
, m_PinId
, &MediaTypeCount
);
1165 if (FAILED(hr
) || !MediaTypeCount
)
1168 // allocate media types
1169 MediaTypes
= (AM_MEDIA_TYPE
*)CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE
) * MediaTypeCount
);
1172 // not enough memory
1173 return E_OUTOFMEMORY
;
1177 ZeroMemory(MediaTypes
, sizeof(AM_MEDIA_TYPE
) * MediaTypeCount
);
1179 for(Index
= 0; Index
< MediaTypeCount
; Index
++)
1182 hr
= KsGetMediaType(Index
, &MediaTypes
[Index
], m_hFilter
, m_PinId
);
1186 CoTaskMemFree(MediaTypes
);
1191 return CEnumMediaTypes_fnConstructor(MediaTypeCount
, MediaTypes
, IID_IEnumMediaTypes
, (void**)ppEnum
);
1196 CInputPin::QueryInternalConnections(IPin
**apPin
, ULONG
*nPin
)
1198 OutputDebugStringW(L
"CInputPin::QueryInternalConnections NotImplemented\n");
1203 CInputPin::EndOfStream( void)
1205 OutputDebugStringW(L
"CInputPin::EndOfStream NotImplemented\n");
1210 CInputPin::BeginFlush( void)
1212 OutputDebugStringW(L
"CInputPin::BeginFlush NotImplemented\n");
1217 CInputPin::EndFlush( void)
1219 OutputDebugStringW(L
"CInputPin::EndFlush NotImplemented\n");
1224 CInputPin::NewSegment(REFERENCE_TIME tStart
, REFERENCE_TIME tStop
, double dRate
)
1226 OutputDebugStringW(L
"CInputPin::NewSegment NotImplemented\n");
1231 //-------------------------------------------------------------------
1234 CInputPin::CheckFormat(
1235 const AM_MEDIA_TYPE
*pmt
)
1237 PKSMULTIPLE_ITEM MultipleItem
;
1238 PKSDATAFORMAT DataFormat
;
1244 hr
= KsGetMultiplePinFactoryItems(m_hFilter
, m_PinId
, KSPROPERTY_PIN_DATARANGES
, (PVOID
*)&MultipleItem
);
1248 DataFormat
= (PKSDATAFORMAT
)(MultipleItem
+ 1);
1249 for(ULONG Index
= 0; Index
< MultipleItem
->Count
; Index
++)
1251 if (IsEqualGUID(pmt
->majortype
, DataFormat
->MajorFormat
) &&
1252 IsEqualGUID(pmt
->subtype
, DataFormat
->SubFormat
) &&
1253 IsEqualGUID(pmt
->formattype
, DataFormat
->Specifier
))
1255 // format is supported
1256 CoTaskMemFree(MultipleItem
);
1257 OutputDebugStringW(L
"CInputPin::CheckFormat format OK\n");
1260 DataFormat
= (PKSDATAFORMAT
)((ULONG_PTR
)DataFormat
+ DataFormat
->FormatSize
);
1262 //format is not supported
1263 CoTaskMemFree(MultipleItem
);
1269 CInputPin::CreatePin(
1270 const AM_MEDIA_TYPE
*pmt
)
1272 PKSMULTIPLE_ITEM MediumList
;
1273 PKSMULTIPLE_ITEM InterfaceList
;
1274 PKSPIN_MEDIUM Medium
;
1275 PKSPIN_INTERFACE Interface
;
1276 IKsInterfaceHandler
* InterfaceHandler
;
1279 // query for pin medium
1280 hr
= KsQueryMediums(&MediumList
);
1284 // query for pin interface
1285 hr
= KsQueryInterfaces(&InterfaceList
);
1289 CoTaskMemFree(MediumList
);
1293 if (MediumList
->Count
)
1295 //use first available medium
1296 Medium
= (PKSPIN_MEDIUM
)(MediumList
+ 1);
1300 // default to standard medium
1301 Medium
= &StandardPinMedium
;
1304 if (InterfaceList
->Count
)
1306 //use first available interface
1307 Interface
= (PKSPIN_INTERFACE
)(InterfaceList
+ 1);
1311 // default to standard interface
1312 Interface
= &StandardPinInterface
;
1315 if (m_Communication
!= KSPIN_COMMUNICATION_BRIDGE
&& m_Communication
!= KSPIN_COMMUNICATION_NONE
)
1317 if (!m_InterfaceHandler
)
1319 // now load the IKsInterfaceHandler plugin
1320 hr
= CoCreateInstance(Interface
->Set
, NULL
, CLSCTX_INPROC_SERVER
, IID_IKsInterfaceHandler
, (void**)&InterfaceHandler
);
1323 // failed to load interface handler plugin
1324 OutputDebugStringW(L
"CInputPin::CreatePin failed to load InterfaceHandlerPlugin\n");
1325 CoTaskMemFree(MediumList
);
1326 CoTaskMemFree(InterfaceList
);
1332 hr
= InterfaceHandler
->KsSetPin((IKsPin
*)this);
1335 // failed to load interface handler plugin
1336 OutputDebugStringW(L
"CInputPin::CreatePin failed to initialize InterfaceHandlerPlugin\n");
1337 InterfaceHandler
->Release();
1338 CoTaskMemFree(MediumList
);
1339 CoTaskMemFree(InterfaceList
);
1343 // store interface handler
1344 m_InterfaceHandler
= InterfaceHandler
;
1348 hr
= CreatePinHandle(Medium
, Interface
, pmt
);
1351 m_InterfaceHandler
->Release();
1352 m_InterfaceHandler
= InterfaceHandler
;
1358 swprintf(Buffer
, L
"CInputPin::CreatePin unexpected communication %u %s\n", m_Communication
, m_PinName
);
1359 OutputDebugStringW(Buffer
);
1364 // free medium / interface / dataformat
1365 CoTaskMemFree(MediumList
);
1366 CoTaskMemFree(InterfaceList
);
1373 CInputPin::CreatePinHandle(
1374 PKSPIN_MEDIUM Medium
,
1375 PKSPIN_INTERFACE Interface
,
1376 const AM_MEDIA_TYPE
*pmt
)
1378 PKSPIN_CONNECT PinConnect
;
1379 PKSDATAFORMAT DataFormat
;
1383 if (m_hPin
!= INVALID_HANDLE_VALUE
)
1385 // pin already exists
1386 //CloseHandle(m_hPin);
1387 //m_hPin = INVALID_HANDLE_VALUE;
1393 Length
= sizeof(KSPIN_CONNECT
) + sizeof(KSDATAFORMAT
) + pmt
->cbFormat
;
1395 // allocate pin connect
1396 PinConnect
= (PKSPIN_CONNECT
)CoTaskMemAlloc(Length
);
1400 return E_OUTOFMEMORY
;
1404 CopyMemory(&PinConnect
->Interface
, Interface
, sizeof(KSPIN_INTERFACE
));
1405 CopyMemory(&PinConnect
->Medium
, Medium
, sizeof(KSPIN_MEDIUM
));
1406 PinConnect
->PinId
= m_PinId
;
1407 PinConnect
->PinToHandle
= NULL
;
1408 PinConnect
->Priority
.PriorityClass
= KSPRIORITY_NORMAL
;
1409 PinConnect
->Priority
.PrioritySubClass
= KSPRIORITY_NORMAL
;
1411 // get dataformat offset
1412 DataFormat
= (PKSDATAFORMAT
)(PinConnect
+ 1);
1415 DataFormat
->FormatSize
= sizeof(KSDATAFORMAT
) + pmt
->cbFormat
;
1416 DataFormat
->Flags
= 0;
1417 DataFormat
->SampleSize
= pmt
->lSampleSize
;
1418 DataFormat
->Reserved
= 0;
1419 CopyMemory(&DataFormat
->MajorFormat
, &pmt
->majortype
, sizeof(GUID
));
1420 CopyMemory(&DataFormat
->SubFormat
, &pmt
->subtype
, sizeof(GUID
));
1421 CopyMemory(&DataFormat
->Specifier
, &pmt
->formattype
, sizeof(GUID
));
1425 // copy extended format
1426 CopyMemory((DataFormat
+ 1), pmt
->pbFormat
, pmt
->cbFormat
);
1430 hr
= KsCreatePin(m_hFilter
, PinConnect
, GENERIC_WRITE
, &m_hPin
);
1434 // store current interface / medium
1435 CopyMemory(&m_Medium
, Medium
, sizeof(KSPIN_MEDIUM
));
1436 CopyMemory(&m_Interface
, Interface
, sizeof(KSPIN_INTERFACE
));
1437 CopyMemory(&m_MediaFormat
, pmt
, sizeof(AM_MEDIA_TYPE
));
1439 LPOLESTR pMajor
, pSub
, pFormat
;
1440 StringFromIID(m_MediaFormat
.majortype
, &pMajor
);
1441 StringFromIID(m_MediaFormat
.subtype
, &pSub
);
1442 StringFromIID(m_MediaFormat
.formattype
, &pFormat
);
1444 swprintf(Buffer
, L
"CInputPin::CreatePinHandle Major %s SubType %s Format %s pbFormat %p cbFormat %u\n", pMajor
, pSub
, pFormat
, pmt
->pbFormat
, pmt
->cbFormat
);
1445 CoTaskMemFree(pMajor
);
1446 CoTaskMemFree(pSub
);
1447 CoTaskMemFree(pFormat
);
1448 OutputDebugStringW(Buffer
);
1452 m_MediaFormat
.pbFormat
= (BYTE
*)CoTaskMemAlloc(pmt
->cbFormat
);
1453 if (!m_MediaFormat
.pbFormat
)
1455 CoTaskMemFree(PinConnect
);
1456 m_MediaFormat
.pbFormat
= NULL
;
1457 m_MediaFormat
.cbFormat
= 0;
1458 return E_OUTOFMEMORY
;
1460 CopyMemory(m_MediaFormat
.pbFormat
, pmt
->pbFormat
, pmt
->cbFormat
);
1464 // connect pin pipes
1469 CoTaskMemFree(PinConnect
);
1476 CInputPin_Constructor(
1477 IBaseFilter
* ParentFilter
,
1481 KSPIN_COMMUNICATION Communication
,
1485 CInputPin
* handler
= new CInputPin(ParentFilter
, PinName
, hFilter
, PinId
, Communication
);
1488 return E_OUTOFMEMORY
;
1490 if (FAILED(handler
->QueryInterface(riid
, ppv
)))
1494 return E_NOINTERFACE
;