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");
665 CInputPin::ReceiveMultiple(IMediaSample
**pSamples
, long nSamples
, long *nSamplesProcessed
)
667 OutputDebugStringW(L
"CInputPin::ReceiveMultiple NotImplemented\n");
673 CInputPin::ReceiveCanBlock( void)
675 OutputDebugStringW(L
"CInputPin::ReceiveCanBlock NotImplemented\n");
679 //-------------------------------------------------------------------
685 CInputPin::KsQueryMediums(
686 PKSMULTIPLE_ITEM
* MediumList
)
688 return KsGetMultiplePinFactoryItems(m_hFilter
, m_PinId
, KSPROPERTY_PIN_MEDIUMS
, (PVOID
*)MediumList
);
693 CInputPin::KsQueryInterfaces(
694 PKSMULTIPLE_ITEM
* InterfaceList
)
696 return KsGetMultiplePinFactoryItems(m_hFilter
, m_PinId
, KSPROPERTY_PIN_INTERFACES
, (PVOID
*)InterfaceList
);
701 CInputPin::KsCreateSinkPinHandle(
702 KSPIN_INTERFACE
& Interface
,
703 KSPIN_MEDIUM
& Medium
)
705 return CreatePin(&m_MediaFormat
);
710 CInputPin::KsGetCurrentCommunication(
711 KSPIN_COMMUNICATION
*Communication
,
712 KSPIN_INTERFACE
*Interface
,
713 KSPIN_MEDIUM
*Medium
)
717 *Communication
= m_Communication
;
723 return VFW_E_NOT_CONNECTED
;
725 CopyMemory(Interface
, &m_Interface
, sizeof(KSPIN_INTERFACE
));
731 return VFW_E_NOT_CONNECTED
;
733 CopyMemory(Medium
, &m_Medium
, sizeof(KSPIN_MEDIUM
));
740 CInputPin::KsPropagateAcquire()
747 OutputDebugStringW(L
"CInputPin::KsPropagateAcquire\n");
749 assert(m_hPin
!= INVALID_HANDLE_VALUE
);
751 Property
.Set
= KSPROPSETID_Connection
;
752 Property
.Id
= KSPROPERTY_CONNECTION_STATE
;
753 Property
.Flags
= KSPROPERTY_TYPE_SET
;
755 State
= KSSTATE_ACQUIRE
;
757 hr
= KsProperty(&Property
, sizeof(KSPROPERTY
), (LPVOID
)&State
, sizeof(KSSTATE
), &BytesReturned
);
760 //propagate to connected pin on the pipe
767 CInputPin::KsDeliver(
768 IMediaSample
* Sample
,
776 CInputPin::KsMediaSamplesCompleted(PKSSTREAM_SEGMENT StreamSegment
)
783 CInputPin::KsPeekAllocator(KSPEEKOPERATION Operation
)
785 if (Operation
== KsPeekOperation_AddRef
)
787 // add reference on allocator
788 m_MemAllocator
->AddRef();
791 return m_MemAllocator
;
796 CInputPin::KsReceiveAllocator(IMemAllocator
*MemAllocator
)
801 MemAllocator
->AddRef();
806 m_MemAllocator
->Release();
809 m_MemAllocator
= MemAllocator
;
815 CInputPin::KsRenegotiateAllocator()
822 CInputPin::KsIncrementPendingIoCount()
824 return InterlockedIncrement((volatile LONG
*)&m_IoCount
);
829 CInputPin::KsDecrementPendingIoCount()
831 return InterlockedDecrement((volatile LONG
*)&m_IoCount
);
836 CInputPin::KsQualityNotify(
838 REFERENCE_TIME TimeDelta
)
840 OutputDebugStringW(L
"CInputPin::KsQualityNotify NotImplemented\n");
844 //-------------------------------------------------------------------
850 CInputPin::KsNotifyError(
851 IMediaSample
* Sample
,
854 OutputDebugStringW(L
"CInputPin::KsNotifyError NotImplemented\n");
858 //-------------------------------------------------------------------
863 CInputPin::KsProperty(
864 PKSPROPERTY Property
,
865 ULONG PropertyLength
,
868 ULONG
* BytesReturned
)
870 assert(m_hPin
!= INVALID_HANDLE_VALUE
);
871 return KsSynchronousDeviceControl(m_hPin
, IOCTL_KS_PROPERTY
, (PVOID
)Property
, PropertyLength
, (PVOID
)PropertyData
, DataLength
, BytesReturned
);
881 ULONG
* BytesReturned
)
883 assert(m_hPin
!= INVALID_HANDLE_VALUE
);
884 return KsSynchronousDeviceControl(m_hPin
, IOCTL_KS_METHOD
, (PVOID
)Method
, MethodLength
, (PVOID
)MethodData
, DataLength
, BytesReturned
);
894 ULONG
* BytesReturned
)
896 assert(m_hPin
!= INVALID_HANDLE_VALUE
);
899 return KsSynchronousDeviceControl(m_hPin
, IOCTL_KS_ENABLE_EVENT
, (PVOID
)Event
, EventLength
, (PVOID
)EventData
, DataLength
, BytesReturned
);
901 return KsSynchronousDeviceControl(m_hPin
, IOCTL_KS_DISABLE_EVENT
, (PVOID
)Event
, EventLength
, NULL
, 0, BytesReturned
);
905 //-------------------------------------------------------------------
913 LPVOID pInstanceData
,
914 DWORD cbInstanceData
,
922 PKSPROPERTY Property
= (PKSPROPERTY
)CoTaskMemAlloc(sizeof(KSPROPERTY
) + cbInstanceData
);
924 return E_OUTOFMEMORY
;
926 Property
->Set
= guidPropSet
;
927 Property
->Id
= dwPropID
;
928 Property
->Flags
= KSPROPERTY_TYPE_SET
;
930 CopyMemory((Property
+1), pInstanceData
, cbInstanceData
);
932 HRESULT hr
= KsProperty(Property
, sizeof(KSPROPERTY
) + cbInstanceData
, pPropData
, cbPropData
, &BytesReturned
);
933 CoTaskMemFree(Property
);
940 Property
.Set
= guidPropSet
;
941 Property
.Id
= dwPropID
;
942 Property
.Flags
= KSPROPERTY_TYPE_SET
;
944 HRESULT hr
= KsProperty(&Property
, sizeof(KSPROPERTY
), pPropData
, cbPropData
, &BytesReturned
);
954 LPVOID pInstanceData
,
955 DWORD cbInstanceData
,
964 PKSPROPERTY Property
= (PKSPROPERTY
)CoTaskMemAlloc(sizeof(KSPROPERTY
) + cbInstanceData
);
966 return E_OUTOFMEMORY
;
968 Property
->Set
= guidPropSet
;
969 Property
->Id
= dwPropID
;
970 Property
->Flags
= KSPROPERTY_TYPE_GET
;
972 CopyMemory((Property
+1), pInstanceData
, cbInstanceData
);
974 HRESULT hr
= KsProperty(Property
, sizeof(KSPROPERTY
) + cbInstanceData
, pPropData
, cbPropData
, &BytesReturned
);
975 CoTaskMemFree(Property
);
982 Property
.Set
= guidPropSet
;
983 Property
.Id
= dwPropID
;
984 Property
.Flags
= KSPROPERTY_TYPE_GET
;
986 HRESULT hr
= KsProperty(&Property
, sizeof(KSPROPERTY
), pPropData
, cbPropData
, &BytesReturned
);
993 CInputPin::QuerySupported(
1001 Property
.Set
= guidPropSet
;
1002 Property
.Id
= dwPropID
;
1003 Property
.Flags
= KSPROPERTY_TYPE_SETSUPPORT
;
1005 return KsProperty(&Property
, sizeof(KSPROPERTY
), pTypeSupport
, sizeof(DWORD
), &BytesReturned
);
1009 //-------------------------------------------------------------------
1014 CInputPin::KsGetObjectHandle()
1020 //-------------------------------------------------------------------
1025 CInputPin::Connect(IPin
*pReceivePin
, const AM_MEDIA_TYPE
*pmt
)
1027 OutputDebugStringW(L
"CInputPin::Connect NotImplemented\n");
1033 CInputPin::ReceiveConnection(IPin
*pConnector
, const AM_MEDIA_TYPE
*pmt
)
1039 // already connected
1040 return VFW_E_ALREADY_CONNECTED
;
1043 // first check format
1044 hr
= CheckFormat(pmt
);
1047 // format is not supported
1051 hr
= CreatePin(pmt
);
1064 CInputPin::Disconnect( void)
1068 // pin was not connected
1073 //check if filter is active
1078 OutputDebugStringW(L
"CInputPin::Disconnect\n");
1083 CInputPin::ConnectedTo(IPin
**pPin
)
1090 // increment reference count
1097 return VFW_E_NOT_CONNECTED
;
1101 CInputPin::ConnectionMediaType(AM_MEDIA_TYPE
*pmt
)
1104 return VFW_E_NOT_CONNECTED
;
1106 OutputDebugStringW(L
"CInputPin::ConnectionMediaType NotImplemented\n");
1111 CInputPin::QueryPinInfo(PIN_INFO
*pInfo
)
1113 wcscpy(pInfo
->achName
, m_PinName
);
1114 pInfo
->dir
= PINDIR_INPUT
;
1115 pInfo
->pFilter
= m_ParentFilter
;
1116 m_ParentFilter
->AddRef();
1122 CInputPin::QueryDirection(PIN_DIRECTION
*pPinDir
)
1126 *pPinDir
= PINDIR_INPUT
;
1134 CInputPin::QueryId(LPWSTR
*Id
)
1136 *Id
= (LPWSTR
)CoTaskMemAlloc((wcslen(m_PinName
)+1)*sizeof(WCHAR
));
1138 return E_OUTOFMEMORY
;
1140 wcscpy(*Id
, m_PinName
);
1146 CInputPin::QueryAccept(
1147 const AM_MEDIA_TYPE
*pmt
)
1149 return CheckFormat(pmt
);
1153 CInputPin::EnumMediaTypes(IEnumMediaTypes
**ppEnum
)
1156 ULONG MediaTypeCount
= 0, Index
;
1157 AM_MEDIA_TYPE
* MediaTypes
;
1159 // query media type count
1160 hr
= KsGetMediaTypeCount(m_hFilter
, m_PinId
, &MediaTypeCount
);
1161 if (FAILED(hr
) || !MediaTypeCount
)
1164 // allocate media types
1165 MediaTypes
= (AM_MEDIA_TYPE
*)CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE
) * MediaTypeCount
);
1168 // not enough memory
1169 return E_OUTOFMEMORY
;
1173 ZeroMemory(MediaTypes
, sizeof(AM_MEDIA_TYPE
) * MediaTypeCount
);
1175 for(Index
= 0; Index
< MediaTypeCount
; Index
++)
1178 hr
= KsGetMediaType(Index
, &MediaTypes
[Index
], m_hFilter
, m_PinId
);
1182 CoTaskMemFree(MediaTypes
);
1187 return CEnumMediaTypes_fnConstructor(MediaTypeCount
, MediaTypes
, IID_IEnumMediaTypes
, (void**)ppEnum
);
1192 CInputPin::QueryInternalConnections(IPin
**apPin
, ULONG
*nPin
)
1194 OutputDebugStringW(L
"CInputPin::QueryInternalConnections NotImplemented\n");
1199 CInputPin::EndOfStream( void)
1201 OutputDebugStringW(L
"CInputPin::EndOfStream NotImplemented\n");
1206 CInputPin::BeginFlush( void)
1208 OutputDebugStringW(L
"CInputPin::BeginFlush NotImplemented\n");
1213 CInputPin::EndFlush( void)
1215 OutputDebugStringW(L
"CInputPin::EndFlush NotImplemented\n");
1220 CInputPin::NewSegment(REFERENCE_TIME tStart
, REFERENCE_TIME tStop
, double dRate
)
1222 OutputDebugStringW(L
"CInputPin::NewSegment NotImplemented\n");
1227 //-------------------------------------------------------------------
1230 CInputPin::CheckFormat(
1231 const AM_MEDIA_TYPE
*pmt
)
1233 PKSMULTIPLE_ITEM MultipleItem
;
1234 PKSDATAFORMAT DataFormat
;
1240 hr
= KsGetMultiplePinFactoryItems(m_hFilter
, m_PinId
, KSPROPERTY_PIN_DATARANGES
, (PVOID
*)&MultipleItem
);
1244 DataFormat
= (PKSDATAFORMAT
)(MultipleItem
+ 1);
1245 for(ULONG Index
= 0; Index
< MultipleItem
->Count
; Index
++)
1247 if (IsEqualGUID(pmt
->majortype
, DataFormat
->MajorFormat
) &&
1248 IsEqualGUID(pmt
->subtype
, DataFormat
->SubFormat
) &&
1249 IsEqualGUID(pmt
->formattype
, DataFormat
->Specifier
))
1251 // format is supported
1252 CoTaskMemFree(MultipleItem
);
1253 OutputDebugStringW(L
"CInputPin::CheckFormat format OK\n");
1256 DataFormat
= (PKSDATAFORMAT
)((ULONG_PTR
)DataFormat
+ DataFormat
->FormatSize
);
1258 //format is not supported
1259 CoTaskMemFree(MultipleItem
);
1265 CInputPin::CreatePin(
1266 const AM_MEDIA_TYPE
*pmt
)
1268 PKSMULTIPLE_ITEM MediumList
;
1269 PKSMULTIPLE_ITEM InterfaceList
;
1270 PKSPIN_MEDIUM Medium
;
1271 PKSPIN_INTERFACE Interface
;
1272 IKsInterfaceHandler
* InterfaceHandler
;
1275 // query for pin medium
1276 hr
= KsQueryMediums(&MediumList
);
1280 // query for pin interface
1281 hr
= KsQueryInterfaces(&InterfaceList
);
1285 CoTaskMemFree(MediumList
);
1289 if (MediumList
->Count
)
1291 //use first available medium
1292 Medium
= (PKSPIN_MEDIUM
)(MediumList
+ 1);
1296 // default to standard medium
1297 Medium
= &StandardPinMedium
;
1300 if (InterfaceList
->Count
)
1302 //use first available interface
1303 Interface
= (PKSPIN_INTERFACE
)(InterfaceList
+ 1);
1307 // default to standard interface
1308 Interface
= &StandardPinInterface
;
1311 if (m_Communication
!= KSPIN_COMMUNICATION_BRIDGE
&& m_Communication
!= KSPIN_COMMUNICATION_NONE
)
1313 if (!m_InterfaceHandler
)
1315 // now load the IKsInterfaceHandler plugin
1316 hr
= CoCreateInstance(Interface
->Set
, NULL
, CLSCTX_INPROC_SERVER
, IID_IKsInterfaceHandler
, (void**)&InterfaceHandler
);
1319 // failed to load interface handler plugin
1320 OutputDebugStringW(L
"CInputPin::CreatePin failed to load InterfaceHandlerPlugin\n");
1321 CoTaskMemFree(MediumList
);
1322 CoTaskMemFree(InterfaceList
);
1328 hr
= InterfaceHandler
->KsSetPin((IKsPin
*)this);
1331 // failed to load interface handler plugin
1332 OutputDebugStringW(L
"CInputPin::CreatePin failed to initialize InterfaceHandlerPlugin\n");
1333 InterfaceHandler
->Release();
1334 CoTaskMemFree(MediumList
);
1335 CoTaskMemFree(InterfaceList
);
1339 // store interface handler
1340 m_InterfaceHandler
= InterfaceHandler
;
1344 hr
= CreatePinHandle(Medium
, Interface
, pmt
);
1347 m_InterfaceHandler
->Release();
1348 m_InterfaceHandler
= InterfaceHandler
;
1354 swprintf(Buffer
, L
"CInputPin::CreatePin unexpected communication %u %s\n", m_Communication
, m_PinName
);
1355 OutputDebugStringW(Buffer
);
1360 // free medium / interface / dataformat
1361 CoTaskMemFree(MediumList
);
1362 CoTaskMemFree(InterfaceList
);
1369 CInputPin::CreatePinHandle(
1370 PKSPIN_MEDIUM Medium
,
1371 PKSPIN_INTERFACE Interface
,
1372 const AM_MEDIA_TYPE
*pmt
)
1374 PKSPIN_CONNECT PinConnect
;
1375 PKSDATAFORMAT DataFormat
;
1379 if (m_hPin
!= INVALID_HANDLE_VALUE
)
1381 // pin already exists
1382 //CloseHandle(m_hPin);
1383 //m_hPin = INVALID_HANDLE_VALUE;
1389 Length
= sizeof(KSPIN_CONNECT
) + sizeof(KSDATAFORMAT
) + pmt
->cbFormat
;
1391 // allocate pin connect
1392 PinConnect
= (PKSPIN_CONNECT
)CoTaskMemAlloc(Length
);
1396 return E_OUTOFMEMORY
;
1400 CopyMemory(&PinConnect
->Interface
, Interface
, sizeof(KSPIN_INTERFACE
));
1401 CopyMemory(&PinConnect
->Medium
, Medium
, sizeof(KSPIN_MEDIUM
));
1402 PinConnect
->PinId
= m_PinId
;
1403 PinConnect
->PinToHandle
= NULL
;
1404 PinConnect
->Priority
.PriorityClass
= KSPRIORITY_NORMAL
;
1405 PinConnect
->Priority
.PrioritySubClass
= KSPRIORITY_NORMAL
;
1407 // get dataformat offset
1408 DataFormat
= (PKSDATAFORMAT
)(PinConnect
+ 1);
1411 DataFormat
->FormatSize
= sizeof(KSDATAFORMAT
) + pmt
->cbFormat
;
1412 DataFormat
->Flags
= 0;
1413 DataFormat
->SampleSize
= pmt
->lSampleSize
;
1414 DataFormat
->Reserved
= 0;
1415 CopyMemory(&DataFormat
->MajorFormat
, &pmt
->majortype
, sizeof(GUID
));
1416 CopyMemory(&DataFormat
->SubFormat
, &pmt
->subtype
, sizeof(GUID
));
1417 CopyMemory(&DataFormat
->Specifier
, &pmt
->formattype
, sizeof(GUID
));
1421 // copy extended format
1422 CopyMemory((DataFormat
+ 1), pmt
->pbFormat
, pmt
->cbFormat
);
1426 hr
= KsCreatePin(m_hFilter
, PinConnect
, GENERIC_WRITE
, &m_hPin
);
1430 // store current interface / medium
1431 CopyMemory(&m_Medium
, Medium
, sizeof(KSPIN_MEDIUM
));
1432 CopyMemory(&m_Interface
, Interface
, sizeof(KSPIN_INTERFACE
));
1433 CopyMemory(&m_MediaFormat
, pmt
, sizeof(AM_MEDIA_TYPE
));
1435 LPOLESTR pMajor
, pSub
, pFormat
;
1436 StringFromIID(m_MediaFormat
.majortype
, &pMajor
);
1437 StringFromIID(m_MediaFormat
.subtype
, &pSub
);
1438 StringFromIID(m_MediaFormat
.formattype
, &pFormat
);
1440 swprintf(Buffer
, L
"CInputPin::CreatePinHandle Major %s SubType %s Format %s pbFormat %p cbFormat %u\n", pMajor
, pSub
, pFormat
, pmt
->pbFormat
, pmt
->cbFormat
);
1441 CoTaskMemFree(pMajor
);
1442 CoTaskMemFree(pSub
);
1443 CoTaskMemFree(pFormat
);
1444 OutputDebugStringW(Buffer
);
1448 m_MediaFormat
.pbFormat
= (BYTE
*)CoTaskMemAlloc(pmt
->cbFormat
);
1449 if (!m_MediaFormat
.pbFormat
)
1451 CoTaskMemFree(PinConnect
);
1452 m_MediaFormat
.pbFormat
= NULL
;
1453 m_MediaFormat
.cbFormat
= 0;
1454 return E_OUTOFMEMORY
;
1456 CopyMemory(m_MediaFormat
.pbFormat
, pmt
->pbFormat
, pmt
->cbFormat
);
1460 // connect pin pipes
1465 CoTaskMemFree(PinConnect
);
1472 CInputPin_Constructor(
1473 IBaseFilter
* ParentFilter
,
1477 KSPIN_COMMUNICATION Communication
,
1481 CInputPin
* handler
= new CInputPin(ParentFilter
, PinName
, hFilter
, PinId
, Communication
);
1484 return E_OUTOFMEMORY
;
1486 if (FAILED(handler
->QueryInterface(riid
, ppv
)))
1490 return E_NOINTERFACE
;