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
, ULONG PinId
, KSPIN_COMMUNICATION Communication
);
174 virtual ~CInputPin(){};
178 IBaseFilter
* m_ParentFilter
;
182 IMemAllocator
* m_MemAllocator
;
184 KSPIN_COMMUNICATION m_Communication
;
185 KSPIN_INTERFACE m_Interface
;
186 KSPIN_MEDIUM m_Medium
;
187 AM_MEDIA_TYPE m_MediaFormat
;
190 IKsInterfaceHandler
* m_InterfaceHandler
;
191 IKsAllocatorEx
* m_KsAllocatorEx
;
192 ULONG m_PipeAllocatorFlag
;
193 BOOL m_bPinBusCacheInitialized
;
196 FRAMING_PROP m_FramingProp
[4];
197 PKSALLOCATOR_FRAMING_EX m_FramingEx
[4];
200 CInputPin::CInputPin(
201 IBaseFilter
* ParentFilter
,
204 KSPIN_COMMUNICATION Communication
) : m_Ref(0),
205 m_ParentFilter(ParentFilter
),
207 m_hPin(INVALID_HANDLE_VALUE
),
211 m_Communication(Communication
),
214 m_InterfaceHandler(0),
216 m_PipeAllocatorFlag(0),
217 m_bPinBusCacheInitialized(0),
220 ZeroMemory(m_FramingProp
, sizeof(m_FramingProp
));
221 ZeroMemory(m_FramingEx
, sizeof(m_FramingEx
));
224 IKsObject
* KsObjectParent
;
227 hr
= m_ParentFilter
->QueryInterface(IID_IKsObject
, (LPVOID
*)&KsObjectParent
);
230 hFilter
= KsObjectParent
->KsGetObjectHandle();
233 KsObjectParent
->Release();
236 ZeroMemory(&m_MediaFormat
, sizeof(AM_MEDIA_TYPE
));
237 hr
= KsGetMediaType(0, &m_MediaFormat
, hFilter
, m_PinId
);
243 CInputPin::QueryInterface(
251 if (IsEqualGUID(refiid
, IID_IUnknown
) ||
252 IsEqualGUID(refiid
, IID_IPin
))
254 *Output
= PVOID(this);
255 reinterpret_cast<IUnknown
*>(*Output
)->AddRef();
258 else if (IsEqualGUID(refiid
, IID_IMemInputPin
))
260 if (m_hPin
== INVALID_HANDLE_VALUE
)
262 HRESULT hr
= CreatePin(&m_MediaFormat
);
267 *Output
= (IMemInputPin
*)(this);
268 reinterpret_cast<IMemInputPin
*>(*Output
)->AddRef();
271 else if (IsEqualGUID(refiid
, IID_IKsObject
))
273 *Output
= (IKsObject
*)(this);
274 reinterpret_cast<IKsObject
*>(*Output
)->AddRef();
277 else if (IsEqualGUID(refiid
, IID_IKsPropertySet
))
279 if (m_hPin
== INVALID_HANDLE_VALUE
)
281 HRESULT hr
= CreatePin(&m_MediaFormat
);
286 *Output
= (IKsPropertySet
*)(this);
287 reinterpret_cast<IKsPropertySet
*>(*Output
)->AddRef();
290 else if (IsEqualGUID(refiid
, IID_IKsControl
))
292 *Output
= (IKsControl
*)(this);
293 reinterpret_cast<IKsControl
*>(*Output
)->AddRef();
296 else if (IsEqualGUID(refiid
, IID_IKsPin
) ||
297 IsEqualGUID(refiid
, IID_IKsPinEx
))
299 *Output
= (IKsPinEx
*)(this);
300 reinterpret_cast<IKsPinEx
*>(*Output
)->AddRef();
303 else if (IsEqualGUID(refiid
, IID_IKsPinPipe
))
305 *Output
= (IKsPinPipe
*)(this);
306 reinterpret_cast<IKsPinPipe
*>(*Output
)->AddRef();
309 else if (IsEqualGUID(refiid
, IID_IKsPinFactory
))
311 *Output
= (IKsPinFactory
*)(this);
312 reinterpret_cast<IKsPinFactory
*>(*Output
)->AddRef();
316 else if (IsEqualGUID(refiid
, IID_IStreamBuilder
))
318 *Output
= (IStreamBuilder
*)(this);
319 reinterpret_cast<IStreamBuilder
*>(*Output
)->AddRef();
323 else if (IsEqualGUID(refiid
, IID_IKsAggregateControl
))
325 *Output
= (IKsAggregateControl
*)(this);
326 reinterpret_cast<IKsAggregateControl
*>(*Output
)->AddRef();
329 else if (IsEqualGUID(refiid
, IID_IQualityControl
))
331 *Output
= (IQualityControl
*)(this);
332 reinterpret_cast<IQualityControl
*>(*Output
)->AddRef();
335 else if (IsEqualGUID(refiid
, IID_ISpecifyPropertyPages
))
337 *Output
= (ISpecifyPropertyPages
*)(this);
338 reinterpret_cast<ISpecifyPropertyPages
*>(*Output
)->AddRef();
343 StringFromCLSID(refiid
, &lpstr
);
344 swprintf(Buffer
, L
"CInputPin::QueryInterface: NoInterface for %s\n", lpstr
);
345 OutputDebugStringW(Buffer
);
346 CoTaskMemFree(lpstr
);
348 return E_NOINTERFACE
;
350 //-------------------------------------------------------------------
351 // IQualityControl interface
359 OutputDebugStringW(L
"CInputPin::Notify NotImplemented\n");
366 IQualityControl
*piqc
)
368 OutputDebugStringW(L
"CInputPin::SetSink NotImplemented\n");
373 //-------------------------------------------------------------------
374 // IKsAggregateControl interface
378 CInputPin::KsAddAggregate(
379 IN REFGUID AggregateClass
)
381 OutputDebugStringW(L
"CInputPin::KsAddAggregate NotImplemented\n");
387 CInputPin::KsRemoveAggregate(
388 REFGUID AggregateClass
)
390 OutputDebugStringW(L
"CInputPin::KsRemoveAggregate NotImplemented\n");
394 //-------------------------------------------------------------------
402 IGraphBuilder
*pGraph
)
404 OutputDebugStringW(L
"CInputPin::Render\n");
412 IGraphBuilder
*pGraph
)
414 OutputDebugStringW(L
"CInputPin::Backout\n");
418 //-------------------------------------------------------------------
424 CInputPin::KsPinFactory(
427 OutputDebugStringW(L
"CInputPin::KsPinFactory\n");
428 *PinFactory
= m_PinId
;
432 //-------------------------------------------------------------------
438 CInputPin::KsGetPinFramingCache(
439 PKSALLOCATOR_FRAMING_EX
*FramingEx
,
440 PFRAMING_PROP FramingProp
,
441 FRAMING_CACHE_OPS Option
)
443 if (Option
> Framing_Cache_Write
|| Option
< Framing_Cache_ReadLast
)
449 // get framing properties
450 *FramingProp
= m_FramingProp
[Option
];
451 *FramingEx
= m_FramingEx
[Option
];
458 CInputPin::KsSetPinFramingCache(
459 PKSALLOCATOR_FRAMING_EX FramingEx
,
460 PFRAMING_PROP FramingProp
,
461 FRAMING_CACHE_OPS Option
)
466 if (m_FramingEx
[Option
])
468 for(Index
= 1; Index
< 4; Index
++)
470 if (m_FramingEx
[Index
] == m_FramingEx
[Option
])
476 // existing framing is only used once
477 CoTaskMemFree(m_FramingEx
[Option
]);
482 m_FramingEx
[Option
] = FramingEx
;
483 m_FramingProp
[Option
] = *FramingProp
;
490 CInputPin::KsGetConnectedPin()
497 CInputPin::KsGetPipe(
498 KSPEEKOPERATION Operation
)
500 if (Operation
== KsPeekOperation_AddRef
)
503 m_KsAllocatorEx
->AddRef();
505 return m_KsAllocatorEx
;
510 CInputPin::KsSetPipe(
511 IKsAllocatorEx
*KsAllocator
)
514 KsAllocator
->AddRef();
517 m_KsAllocatorEx
->Release();
519 m_KsAllocatorEx
= KsAllocator
;
525 CInputPin::KsGetPipeAllocatorFlag()
527 return m_PipeAllocatorFlag
;
533 CInputPin::KsSetPipeAllocatorFlag(
536 m_PipeAllocatorFlag
= Flag
;
542 CInputPin::KsGetPinBusCache()
544 if (!m_bPinBusCacheInitialized
)
546 CopyMemory(&m_PinBusCache
, &m_Medium
.Set
, sizeof(GUID
));
547 m_bPinBusCacheInitialized
= TRUE
;
550 return m_PinBusCache
;
555 CInputPin::KsSetPinBusCache(
558 CopyMemory(&m_PinBusCache
, &Bus
, sizeof(GUID
));
564 CInputPin::KsGetPinName()
566 return (PWCHAR
)m_PinName
;
572 CInputPin::KsGetFilterName()
577 //-------------------------------------------------------------------
578 // ISpecifyPropertyPages
583 CInputPin::GetPages(CAUUID
*pPages
)
589 pPages
->pElems
= NULL
;
594 //-------------------------------------------------------------------
601 CInputPin::GetAllocator(IMemAllocator
**ppAllocator
)
603 OutputDebugStringW(L
"CInputPin::GetAllocator\n");
604 return VFW_E_NO_ALLOCATOR
;
609 CInputPin::NotifyAllocator(IMemAllocator
*pAllocator
, BOOL bReadOnly
)
613 ALLOCATOR_PROPERTIES Properties
;
615 hr
= pAllocator
->GetProperties(&Properties
);
616 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
);
617 OutputDebugStringW(Buffer
);
621 pAllocator
->AddRef();
626 m_MemAllocator
->Release();
629 m_MemAllocator
= pAllocator
;
630 m_ReadOnly
= bReadOnly
;
636 CInputPin::GetAllocatorRequirements(ALLOCATOR_PROPERTIES
*pProps
)
638 KSALLOCATOR_FRAMING Framing
;
643 Property
.Set
= KSPROPSETID_Connection
;
644 Property
.Id
= KSPROPERTY_CONNECTION_ALLOCATORFRAMING
;
645 Property
.Flags
= KSPROPERTY_TYPE_SET
;
647 hr
= KsProperty(&Property
, sizeof(KSPROPERTY
), (PVOID
)&Framing
, sizeof(KSALLOCATOR_FRAMING
), &BytesReturned
);
650 pProps
->cBuffers
= Framing
.Frames
;
651 pProps
->cbBuffer
= Framing
.FrameSize
;
652 pProps
->cbAlign
= Framing
.FileAlignment
;
653 pProps
->cbPrefix
= 0;
659 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
);
660 OutputDebugStringW(Buffer
);
667 CInputPin::Receive(IMediaSample
*pSample
)
669 OutputDebugStringW(L
"CInputPin::Receive NotImplemented\n");
676 CInputPin::ReceiveMultiple(IMediaSample
**pSamples
, long nSamples
, long *nSamplesProcessed
)
678 OutputDebugStringW(L
"CInputPin::ReceiveMultiple NotImplemented\n");
685 CInputPin::ReceiveCanBlock( void)
687 OutputDebugStringW(L
"CInputPin::ReceiveCanBlock NotImplemented\n");
692 //-------------------------------------------------------------------
698 CInputPin::KsQueryMediums(
699 PKSMULTIPLE_ITEM
* MediumList
)
702 IKsObject
* KsObjectParent
;
705 hr
= m_ParentFilter
->QueryInterface(IID_IKsObject
, (LPVOID
*)&KsObjectParent
);
709 hFilter
= KsObjectParent
->KsGetObjectHandle();
711 KsObjectParent
->Release();
716 return KsGetMultiplePinFactoryItems(hFilter
, m_PinId
, KSPROPERTY_PIN_MEDIUMS
, (PVOID
*)MediumList
);
721 CInputPin::KsQueryInterfaces(
722 PKSMULTIPLE_ITEM
* InterfaceList
)
725 IKsObject
* KsObjectParent
;
728 hr
= m_ParentFilter
->QueryInterface(IID_IKsObject
, (LPVOID
*)&KsObjectParent
);
732 hFilter
= KsObjectParent
->KsGetObjectHandle();
734 KsObjectParent
->Release();
739 return KsGetMultiplePinFactoryItems(hFilter
, m_PinId
, KSPROPERTY_PIN_INTERFACES
, (PVOID
*)InterfaceList
);
744 CInputPin::KsCreateSinkPinHandle(
745 KSPIN_INTERFACE
& Interface
,
746 KSPIN_MEDIUM
& Medium
)
748 return CreatePin(&m_MediaFormat
);
753 CInputPin::KsGetCurrentCommunication(
754 KSPIN_COMMUNICATION
*Communication
,
755 KSPIN_INTERFACE
*Interface
,
756 KSPIN_MEDIUM
*Medium
)
760 *Communication
= m_Communication
;
766 return VFW_E_NOT_CONNECTED
;
768 CopyMemory(Interface
, &m_Interface
, sizeof(KSPIN_INTERFACE
));
774 return VFW_E_NOT_CONNECTED
;
776 CopyMemory(Medium
, &m_Medium
, sizeof(KSPIN_MEDIUM
));
783 CInputPin::KsPropagateAcquire()
790 assert(m_hPin
!= INVALID_HANDLE_VALUE
);
792 Property
.Set
= KSPROPSETID_Connection
;
793 Property
.Id
= KSPROPERTY_CONNECTION_STATE
;
794 Property
.Flags
= KSPROPERTY_TYPE_SET
;
796 State
= KSSTATE_ACQUIRE
;
798 hr
= KsProperty(&Property
, sizeof(KSPROPERTY
), (LPVOID
)&State
, sizeof(KSSTATE
), &BytesReturned
);
801 //propagate to connected pin on the pipe
808 CInputPin::KsDeliver(
809 IMediaSample
* Sample
,
817 CInputPin::KsMediaSamplesCompleted(PKSSTREAM_SEGMENT StreamSegment
)
824 CInputPin::KsPeekAllocator(KSPEEKOPERATION Operation
)
826 if (Operation
== KsPeekOperation_AddRef
)
828 // add reference on allocator
829 m_MemAllocator
->AddRef();
832 return m_MemAllocator
;
837 CInputPin::KsReceiveAllocator(IMemAllocator
*MemAllocator
)
842 MemAllocator
->AddRef();
847 m_MemAllocator
->Release();
850 m_MemAllocator
= MemAllocator
;
856 CInputPin::KsRenegotiateAllocator()
863 CInputPin::KsIncrementPendingIoCount()
865 return InterlockedIncrement((volatile LONG
*)&m_IoCount
);
870 CInputPin::KsDecrementPendingIoCount()
872 return InterlockedDecrement((volatile LONG
*)&m_IoCount
);
877 CInputPin::KsQualityNotify(
879 REFERENCE_TIME TimeDelta
)
881 OutputDebugStringW(L
"CInputPin::KsQualityNotify NotImplemented\n");
886 //-------------------------------------------------------------------
892 CInputPin::KsNotifyError(
893 IMediaSample
* Sample
,
896 OutputDebugStringW(L
"CInputPin::KsNotifyError NotImplemented\n");
900 //-------------------------------------------------------------------
905 CInputPin::KsProperty(
906 PKSPROPERTY Property
,
907 ULONG PropertyLength
,
910 ULONG
* BytesReturned
)
912 assert(m_hPin
!= INVALID_HANDLE_VALUE
);
913 return KsSynchronousDeviceControl(m_hPin
, IOCTL_KS_PROPERTY
, (PVOID
)Property
, PropertyLength
, (PVOID
)PropertyData
, DataLength
, BytesReturned
);
923 ULONG
* BytesReturned
)
925 assert(m_hPin
!= INVALID_HANDLE_VALUE
);
926 return KsSynchronousDeviceControl(m_hPin
, IOCTL_KS_METHOD
, (PVOID
)Method
, MethodLength
, (PVOID
)MethodData
, DataLength
, BytesReturned
);
936 ULONG
* BytesReturned
)
938 assert(m_hPin
!= INVALID_HANDLE_VALUE
);
941 return KsSynchronousDeviceControl(m_hPin
, IOCTL_KS_ENABLE_EVENT
, (PVOID
)Event
, EventLength
, (PVOID
)EventData
, DataLength
, BytesReturned
);
943 return KsSynchronousDeviceControl(m_hPin
, IOCTL_KS_DISABLE_EVENT
, (PVOID
)Event
, EventLength
, NULL
, 0, BytesReturned
);
947 //-------------------------------------------------------------------
955 LPVOID pInstanceData
,
956 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_SET
;
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_SET
;
986 HRESULT hr
= KsProperty(&Property
, sizeof(KSPROPERTY
), pPropData
, cbPropData
, &BytesReturned
);
996 LPVOID pInstanceData
,
997 DWORD cbInstanceData
,
1002 ULONG BytesReturned
;
1006 PKSPROPERTY Property
= (PKSPROPERTY
)CoTaskMemAlloc(sizeof(KSPROPERTY
) + cbInstanceData
);
1008 return E_OUTOFMEMORY
;
1010 Property
->Set
= guidPropSet
;
1011 Property
->Id
= dwPropID
;
1012 Property
->Flags
= KSPROPERTY_TYPE_GET
;
1014 CopyMemory((Property
+1), pInstanceData
, cbInstanceData
);
1016 HRESULT hr
= KsProperty(Property
, sizeof(KSPROPERTY
) + cbInstanceData
, pPropData
, cbPropData
, &BytesReturned
);
1017 CoTaskMemFree(Property
);
1022 KSPROPERTY Property
;
1024 Property
.Set
= guidPropSet
;
1025 Property
.Id
= dwPropID
;
1026 Property
.Flags
= KSPROPERTY_TYPE_GET
;
1028 HRESULT hr
= KsProperty(&Property
, sizeof(KSPROPERTY
), pPropData
, cbPropData
, &BytesReturned
);
1035 CInputPin::QuerySupported(
1036 REFGUID guidPropSet
,
1038 DWORD
*pTypeSupport
)
1040 KSPROPERTY Property
;
1041 ULONG BytesReturned
;
1043 Property
.Set
= guidPropSet
;
1044 Property
.Id
= dwPropID
;
1045 Property
.Flags
= KSPROPERTY_TYPE_SETSUPPORT
;
1047 return KsProperty(&Property
, sizeof(KSPROPERTY
), pTypeSupport
, sizeof(DWORD
), &BytesReturned
);
1051 //-------------------------------------------------------------------
1056 CInputPin::KsGetObjectHandle()
1062 //-------------------------------------------------------------------
1067 CInputPin::Connect(IPin
*pReceivePin
, const AM_MEDIA_TYPE
*pmt
)
1069 OutputDebugStringW(L
"CInputPin::Connect NotImplemented\n");
1076 CInputPin::ReceiveConnection(IPin
*pConnector
, const AM_MEDIA_TYPE
*pmt
)
1082 // already connected
1083 return VFW_E_ALREADY_CONNECTED
;
1086 // first check format
1087 hr
= CheckFormat(pmt
);
1090 // format is not supported
1094 hr
= CreatePin(pmt
);
1107 CInputPin::Disconnect( void)
1111 // pin was not connected
1116 //check if filter is active
1121 OutputDebugStringW(L
"CInputPin::Disconnect\n");
1126 CInputPin::ConnectedTo(IPin
**pPin
)
1133 // increment reference count
1140 return VFW_E_NOT_CONNECTED
;
1144 CInputPin::ConnectionMediaType(AM_MEDIA_TYPE
*pmt
)
1147 return VFW_E_NOT_CONNECTED
;
1149 OutputDebugStringW(L
"CInputPin::ConnectionMediaType NotImplemented\n");
1155 CInputPin::QueryPinInfo(PIN_INFO
*pInfo
)
1157 wcscpy(pInfo
->achName
, m_PinName
);
1158 pInfo
->dir
= PINDIR_INPUT
;
1159 pInfo
->pFilter
= m_ParentFilter
;
1160 m_ParentFilter
->AddRef();
1166 CInputPin::QueryDirection(PIN_DIRECTION
*pPinDir
)
1170 *pPinDir
= PINDIR_INPUT
;
1178 CInputPin::QueryId(LPWSTR
*Id
)
1180 *Id
= (LPWSTR
)CoTaskMemAlloc((wcslen(m_PinName
)+1)*sizeof(WCHAR
));
1182 return E_OUTOFMEMORY
;
1184 wcscpy(*Id
, m_PinName
);
1190 CInputPin::QueryAccept(
1191 const AM_MEDIA_TYPE
*pmt
)
1193 return CheckFormat(pmt
);
1197 CInputPin::EnumMediaTypes(IEnumMediaTypes
**ppEnum
)
1200 ULONG MediaTypeCount
= 0, Index
;
1201 AM_MEDIA_TYPE
* MediaTypes
;
1202 IKsObject
* KsObjectParent
;
1205 hr
= m_ParentFilter
->QueryInterface(IID_IKsObject
, (LPVOID
*)&KsObjectParent
);
1209 hFilter
= KsObjectParent
->KsGetObjectHandle();
1211 KsObjectParent
->Release();
1217 // query media type count
1218 hr
= KsGetMediaTypeCount(hFilter
, m_PinId
, &MediaTypeCount
);
1219 if (FAILED(hr
) || !MediaTypeCount
)
1222 // allocate media types
1223 MediaTypes
= (AM_MEDIA_TYPE
*)CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE
) * MediaTypeCount
);
1226 // not enough memory
1227 return E_OUTOFMEMORY
;
1231 ZeroMemory(MediaTypes
, sizeof(AM_MEDIA_TYPE
) * MediaTypeCount
);
1233 for(Index
= 0; Index
< MediaTypeCount
; Index
++)
1236 hr
= KsGetMediaType(Index
, &MediaTypes
[Index
], hFilter
, m_PinId
);
1240 CoTaskMemFree(MediaTypes
);
1245 return CEnumMediaTypes_fnConstructor(MediaTypeCount
, MediaTypes
, IID_IEnumMediaTypes
, (void**)ppEnum
);
1250 CInputPin::QueryInternalConnections(IPin
**apPin
, ULONG
*nPin
)
1252 OutputDebugStringW(L
"CInputPin::QueryInternalConnections NotImplemented\n");
1257 CInputPin::EndOfStream( void)
1259 OutputDebugStringW(L
"CInputPin::EndOfStream NotImplemented\n");
1264 CInputPin::BeginFlush( void)
1266 OutputDebugStringW(L
"CInputPin::BeginFlush NotImplemented\n");
1271 CInputPin::EndFlush( void)
1273 OutputDebugStringW(L
"CInputPin::EndFlush NotImplemented\n");
1278 CInputPin::NewSegment(REFERENCE_TIME tStart
, REFERENCE_TIME tStop
, double dRate
)
1280 OutputDebugStringW(L
"CInputPin::NewSegment NotImplemented\n");
1285 //-------------------------------------------------------------------
1288 CInputPin::CheckFormat(
1289 const AM_MEDIA_TYPE
*pmt
)
1291 PKSMULTIPLE_ITEM MultipleItem
;
1292 PKSDATAFORMAT DataFormat
;
1294 IKsObject
* KsObjectParent
;
1300 hr
= m_ParentFilter
->QueryInterface(IID_IKsObject
, (LPVOID
*)&KsObjectParent
);
1304 hFilter
= KsObjectParent
->KsGetObjectHandle();
1306 KsObjectParent
->Release();
1312 hr
= KsGetMultiplePinFactoryItems(hFilter
, m_PinId
, KSPROPERTY_PIN_DATARANGES
, (PVOID
*)&MultipleItem
);
1316 DataFormat
= (PKSDATAFORMAT
)(MultipleItem
+ 1);
1317 for(ULONG Index
= 0; Index
< MultipleItem
->Count
; Index
++)
1319 if (IsEqualGUID(pmt
->majortype
, DataFormat
->MajorFormat
) &&
1320 IsEqualGUID(pmt
->subtype
, DataFormat
->SubFormat
) &&
1321 IsEqualGUID(pmt
->formattype
, DataFormat
->Specifier
))
1323 // format is supported
1324 CoTaskMemFree(MultipleItem
);
1325 OutputDebugStringW(L
"CInputPin::CheckFormat format OK\n");
1328 DataFormat
= (PKSDATAFORMAT
)((ULONG_PTR
)DataFormat
+ DataFormat
->FormatSize
);
1330 //format is not supported
1331 CoTaskMemFree(MultipleItem
);
1337 CInputPin::CreatePin(
1338 const AM_MEDIA_TYPE
*pmt
)
1340 PKSMULTIPLE_ITEM MediumList
;
1341 PKSMULTIPLE_ITEM InterfaceList
;
1342 PKSPIN_MEDIUM Medium
;
1343 PKSPIN_INTERFACE Interface
;
1344 IKsInterfaceHandler
* InterfaceHandler
;
1347 // query for pin medium
1348 hr
= KsQueryMediums(&MediumList
);
1352 // query for pin interface
1353 hr
= KsQueryInterfaces(&InterfaceList
);
1357 CoTaskMemFree(MediumList
);
1361 if (MediumList
->Count
)
1363 //use first available medium
1364 Medium
= (PKSPIN_MEDIUM
)(MediumList
+ 1);
1368 // default to standard medium
1369 Medium
= &StandardPinMedium
;
1372 if (InterfaceList
->Count
)
1374 //use first available interface
1375 Interface
= (PKSPIN_INTERFACE
)(InterfaceList
+ 1);
1379 // default to standard interface
1380 Interface
= &StandardPinInterface
;
1383 if (m_Communication
!= KSPIN_COMMUNICATION_BRIDGE
&& m_Communication
!= KSPIN_COMMUNICATION_NONE
)
1385 if (!m_InterfaceHandler
)
1387 // now load the IKsInterfaceHandler plugin
1388 hr
= CoCreateInstance(Interface
->Set
, NULL
, CLSCTX_INPROC_SERVER
, IID_IKsInterfaceHandler
, (void**)&InterfaceHandler
);
1391 // failed to load interface handler plugin
1392 OutputDebugStringW(L
"CInputPin::CreatePin failed to load InterfaceHandlerPlugin\n");
1393 CoTaskMemFree(MediumList
);
1394 CoTaskMemFree(InterfaceList
);
1400 hr
= InterfaceHandler
->KsSetPin((IKsPin
*)this);
1403 // failed to load interface handler plugin
1404 OutputDebugStringW(L
"CInputPin::CreatePin failed to initialize InterfaceHandlerPlugin\n");
1405 InterfaceHandler
->Release();
1406 CoTaskMemFree(MediumList
);
1407 CoTaskMemFree(InterfaceList
);
1411 // store interface handler
1412 m_InterfaceHandler
= InterfaceHandler
;
1416 hr
= CreatePinHandle(Medium
, Interface
, pmt
);
1419 m_InterfaceHandler
->Release();
1420 m_InterfaceHandler
= InterfaceHandler
;
1426 swprintf(Buffer
, L
"CInputPin::CreatePin unexpected communication %u %s\n", m_Communication
, m_PinName
);
1427 OutputDebugStringW(Buffer
);
1432 // free medium / interface / dataformat
1433 CoTaskMemFree(MediumList
);
1434 CoTaskMemFree(InterfaceList
);
1441 CInputPin::CreatePinHandle(
1442 PKSPIN_MEDIUM Medium
,
1443 PKSPIN_INTERFACE Interface
,
1444 const AM_MEDIA_TYPE
*pmt
)
1446 PKSPIN_CONNECT PinConnect
;
1447 PKSDATAFORMAT DataFormat
;
1450 IKsObject
* KsObjectParent
;
1456 hr
= m_ParentFilter
->QueryInterface(IID_IKsObject
, (LPVOID
*)&KsObjectParent
);
1460 hFilter
= KsObjectParent
->KsGetObjectHandle();
1462 KsObjectParent
->Release();
1468 if (m_hPin
!= INVALID_HANDLE_VALUE
)
1470 // pin already exists
1471 //CloseHandle(m_hPin);
1472 //m_hPin = INVALID_HANDLE_VALUE;
1478 Length
= sizeof(KSPIN_CONNECT
) + sizeof(KSDATAFORMAT
) + pmt
->cbFormat
;
1480 // allocate pin connect
1481 PinConnect
= (PKSPIN_CONNECT
)CoTaskMemAlloc(Length
);
1485 return E_OUTOFMEMORY
;
1489 CopyMemory(&PinConnect
->Interface
, Interface
, sizeof(KSPIN_INTERFACE
));
1490 CopyMemory(&PinConnect
->Medium
, Medium
, sizeof(KSPIN_MEDIUM
));
1491 PinConnect
->PinId
= m_PinId
;
1492 PinConnect
->PinToHandle
= NULL
;
1493 PinConnect
->Priority
.PriorityClass
= KSPRIORITY_NORMAL
;
1494 PinConnect
->Priority
.PrioritySubClass
= KSPRIORITY_NORMAL
;
1496 // get dataformat offset
1497 DataFormat
= (PKSDATAFORMAT
)(PinConnect
+ 1);
1500 DataFormat
->FormatSize
= sizeof(KSDATAFORMAT
) + pmt
->cbFormat
;
1501 DataFormat
->Flags
= 0;
1502 DataFormat
->SampleSize
= pmt
->lSampleSize
;
1503 DataFormat
->Reserved
= 0;
1504 CopyMemory(&DataFormat
->MajorFormat
, &pmt
->majortype
, sizeof(GUID
));
1505 CopyMemory(&DataFormat
->SubFormat
, &pmt
->subtype
, sizeof(GUID
));
1506 CopyMemory(&DataFormat
->Specifier
, &pmt
->formattype
, sizeof(GUID
));
1510 // copy extended format
1511 CopyMemory((DataFormat
+ 1), pmt
->pbFormat
, pmt
->cbFormat
);
1515 hr
= KsCreatePin(hFilter
, PinConnect
, GENERIC_WRITE
, &m_hPin
);
1519 // store current interface / medium
1520 CopyMemory(&m_Medium
, Medium
, sizeof(KSPIN_MEDIUM
));
1521 CopyMemory(&m_Interface
, Interface
, sizeof(KSPIN_INTERFACE
));
1522 CopyMemory(&m_MediaFormat
, pmt
, sizeof(AM_MEDIA_TYPE
));
1524 LPOLESTR pMajor
, pSub
, pFormat
;
1525 StringFromIID(m_MediaFormat
.majortype
, &pMajor
);
1526 StringFromIID(m_MediaFormat
.subtype
, &pSub
);
1527 StringFromIID(m_MediaFormat
.formattype
, &pFormat
);
1529 swprintf(Buffer
, L
"CInputPin::CreatePinHandle Major %s SubType %s Format %s pbFormat %p cbFormat %u\n", pMajor
, pSub
, pFormat
, pmt
->pbFormat
, pmt
->cbFormat
);
1530 CoTaskMemFree(pMajor
);
1531 CoTaskMemFree(pSub
);
1532 CoTaskMemFree(pFormat
);
1533 OutputDebugStringW(Buffer
);
1537 m_MediaFormat
.pbFormat
= (BYTE
*)CoTaskMemAlloc(pmt
->cbFormat
);
1538 if (!m_MediaFormat
.pbFormat
)
1540 CoTaskMemFree(PinConnect
);
1541 m_MediaFormat
.pbFormat
= NULL
;
1542 m_MediaFormat
.cbFormat
= 0;
1543 return E_OUTOFMEMORY
;
1545 CopyMemory(m_MediaFormat
.pbFormat
, pmt
->pbFormat
, pmt
->cbFormat
);
1549 // connect pin pipes
1554 CoTaskMemFree(PinConnect
);
1561 CInputPin_Constructor(
1562 IBaseFilter
* ParentFilter
,
1566 KSPIN_COMMUNICATION Communication
,
1570 CInputPin
* handler
= new CInputPin(ParentFilter
, PinName
, PinId
, Communication
);
1573 return E_OUTOFMEMORY
;
1575 if (FAILED(handler
->QueryInterface(riid
, ppv
)))
1579 return E_NOINTERFACE
;