2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS WDM Streaming ActiveMovie Proxy
4 * FILE: dll/directx/ksproxy/proxy.cpp
5 * PURPOSE: IKsProxy interface
7 * PROGRAMMERS: Johannes Anderwald (janderwald@reactos.org)
12 const GUID IID_IPersistPropertyBag
= {0x37D84F60, 0x42CB, 0x11CE, {0x81, 0x35, 0x00, 0xAA, 0x00, 0x4B, 0xB8, 0x51}};
13 const GUID GUID_NULL
= {0x00000000L
, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};
14 const GUID IID_ISpecifyPropertyPages
= {0xB196B28B, 0xBAB4, 0x101A, {0xB6, 0x9C, 0x00, 0xAA, 0x00, 0x34, 0x1D, 0x07}};
15 const GUID IID_IPersistStream
= {0x00000109, 0x0000, 0x0000, {0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46}};
16 const GUID KSPROPSETID_MediaSeeking
= {0xEE904F0CL
, 0xD09B, 0x11D0, {0xAB, 0xE9, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96}};
17 const GUID KSPROPSETID_Clock
= {0xDF12A4C0L
, 0xAC17, 0x11CF, {0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00}};
18 const GUID KSEVENTSETID_Clock
= {0x364D8E20L
, 0x62C7, 0x11CF, {0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00}};
19 const GUID KSPROPSETID_Stream
= {0x65aaba60L
, 0x98ae, 0x11cf, {0xa1, 0x0d, 0x00, 0x20, 0xaf, 0xd1, 0x56, 0xe4}};
20 const GUID IID_IPersist
= {0x0000010c, 0x0000, 0x0000, {0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46}};
23 const GUID IID_IBDA_DeviceControl
= {0xFD0A5AF3, 0xB41D, 0x11d2, {0x9C, 0x95, 0x00, 0xC0, 0x4F, 0x79, 0x71, 0xE0}};
24 const GUID IID_IKsAggregateControl
= {0x7F40EAC0, 0x3947, 0x11D2, {0x87, 0x4E, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96}};
25 const GUID IID_IKsClockPropertySet
= {0x5C5CBD84, 0xE755, 0x11D0, {0xAC, 0x18, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96}};
26 const GUID IID_IKsTopology
= {0x28F54683, 0x06FD, 0x11D2, {0xB2, 0x7A, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96}};
27 const GUID IID_IKsClock
= {0x877E4351, 0x6FEA, 0x11D0, {0xB8, 0x63, 0x00, 0xAA, 0x00, 0xA2, 0x16, 0xA1}};
29 Needs IKsClock, IKsNotifyEvent
32 class CKsProxy
: public IBaseFilter
,
34 public IPersistPropertyBag
,
36 public IPersistStream
,
37 public IAMDeviceRemoval
,
38 public ISpecifyPropertyPages
,
39 public IReferenceClock
,
41 public IKsPropertySet
,
43 public IKsClockPropertySet
,
44 public IAMFilterMiscFlags
,
47 public IKsAggregateControl
51 typedef std::vector
<IUnknown
*>ProxyPluginVector
;
52 typedef std::vector
<IPin
*> PinVector
;
54 STDMETHODIMP
QueryInterface( REFIID InterfaceId
, PVOID
* Interface
);
56 STDMETHODIMP_(ULONG
) AddRef()
58 InterlockedIncrement(&m_Ref
);
61 STDMETHODIMP_(ULONG
) Release()
63 InterlockedDecrement(&m_Ref
);
72 // IBaseFilter methods
73 HRESULT STDMETHODCALLTYPE
GetClassID(CLSID
*pClassID
);
74 HRESULT STDMETHODCALLTYPE
Stop( void);
75 HRESULT STDMETHODCALLTYPE
Pause( void);
76 HRESULT STDMETHODCALLTYPE
Run(REFERENCE_TIME tStart
);
77 HRESULT STDMETHODCALLTYPE
GetState(DWORD dwMilliSecsTimeout
, FILTER_STATE
*State
);
78 HRESULT STDMETHODCALLTYPE
SetSyncSource(IReferenceClock
*pClock
);
79 HRESULT STDMETHODCALLTYPE
GetSyncSource(IReferenceClock
**pClock
);
80 HRESULT STDMETHODCALLTYPE
EnumPins(IEnumPins
**ppEnum
);
81 HRESULT STDMETHODCALLTYPE
FindPin(LPCWSTR Id
, IPin
**ppPin
);
82 HRESULT STDMETHODCALLTYPE
QueryFilterInfo(FILTER_INFO
*pInfo
);
83 HRESULT STDMETHODCALLTYPE
JoinFilterGraph(IFilterGraph
*pGraph
, LPCWSTR pName
);
84 HRESULT STDMETHODCALLTYPE
QueryVendorInfo(LPWSTR
*pVendorInfo
);
87 HRESULT STDMETHODCALLTYPE
GetTime(REFERENCE_TIME
*pTime
);
88 HRESULT STDMETHODCALLTYPE
AdviseTime(REFERENCE_TIME baseTime
, REFERENCE_TIME streamTime
, HEVENT hEvent
, DWORD_PTR
*pdwAdviseCookie
);
89 HRESULT STDMETHODCALLTYPE
AdvisePeriodic(REFERENCE_TIME startTime
, REFERENCE_TIME periodTime
, HSEMAPHORE hSemaphore
, DWORD_PTR
*pdwAdviseCookie
);
90 HRESULT STDMETHODCALLTYPE
Unadvise(DWORD_PTR dwAdviseCookie
);
93 HRESULT STDMETHODCALLTYPE
GetCapabilities(DWORD
*pCapabilities
);
94 HRESULT STDMETHODCALLTYPE
CheckCapabilities(DWORD
*pCapabilities
);
95 HRESULT STDMETHODCALLTYPE
IsFormatSupported(const GUID
*pFormat
);
96 HRESULT STDMETHODCALLTYPE
QueryPreferredFormat(GUID
*pFormat
);
97 HRESULT STDMETHODCALLTYPE
GetTimeFormat(GUID
*pFormat
);
98 HRESULT STDMETHODCALLTYPE
IsUsingTimeFormat(const GUID
*pFormat
);
99 HRESULT STDMETHODCALLTYPE
SetTimeFormat(const GUID
*pFormat
);
100 HRESULT STDMETHODCALLTYPE
GetDuration(LONGLONG
*pDuration
);
101 HRESULT STDMETHODCALLTYPE
GetStopPosition(LONGLONG
*pStop
);
102 HRESULT STDMETHODCALLTYPE
GetCurrentPosition(LONGLONG
*pCurrent
);
103 HRESULT STDMETHODCALLTYPE
ConvertTimeFormat(LONGLONG
*pTarget
, const GUID
*pTargetFormat
, LONGLONG Source
, const GUID
*pSourceFormat
);
104 HRESULT STDMETHODCALLTYPE
SetPositions(LONGLONG
*pCurrent
, DWORD dwCurrentFlags
, LONGLONG
*pStop
, DWORD dwStopFlags
);
105 HRESULT STDMETHODCALLTYPE
GetPositions(LONGLONG
*pCurrent
, LONGLONG
*pStop
);
106 HRESULT STDMETHODCALLTYPE
GetAvailable(LONGLONG
*pEarliest
, LONGLONG
*pLatest
);
107 HRESULT STDMETHODCALLTYPE
SetRate(double dRate
);
108 HRESULT STDMETHODCALLTYPE
GetRate(double *pdRate
);
109 HRESULT STDMETHODCALLTYPE
GetPreroll(LONGLONG
*pllPreroll
);
112 HRESULT STDMETHODCALLTYPE
Set(REFGUID guidPropSet
, DWORD dwPropID
, LPVOID pInstanceData
, DWORD cbInstanceData
, LPVOID pPropData
, DWORD cbPropData
);
113 HRESULT STDMETHODCALLTYPE
Get(REFGUID guidPropSet
, DWORD dwPropID
, LPVOID pInstanceData
, DWORD cbInstanceData
, LPVOID pPropData
, DWORD cbPropData
, DWORD
*pcbReturned
);
114 HRESULT STDMETHODCALLTYPE
QuerySupported(REFGUID guidPropSet
, DWORD dwPropID
, DWORD
*pTypeSupport
);
117 ULONG STDMETHODCALLTYPE
GetMiscFlags( void);
120 HRESULT STDMETHODCALLTYPE
KsProperty(PKSPROPERTY Property
, ULONG PropertyLength
, LPVOID PropertyData
, ULONG DataLength
, ULONG
* BytesReturned
);
121 HRESULT STDMETHODCALLTYPE
KsMethod(PKSMETHOD Method
, ULONG MethodLength
, LPVOID MethodData
, ULONG DataLength
, ULONG
* BytesReturned
);
122 HRESULT STDMETHODCALLTYPE
KsEvent(PKSEVENT Event
, ULONG EventLength
, LPVOID EventData
, ULONG DataLength
, ULONG
* BytesReturned
);
125 HRESULT STDMETHODCALLTYPE
CreateNodeInstance(ULONG NodeId
, ULONG Flags
, ACCESS_MASK DesiredAccess
, IUnknown
* UnkOuter
, REFGUID InterfaceId
, LPVOID
* Interface
);
127 //IKsAggregateControl
128 HRESULT STDMETHODCALLTYPE
KsAddAggregate(IN REFGUID AggregateClass
);
129 HRESULT STDMETHODCALLTYPE
KsRemoveAggregate(REFGUID AggregateClass
);
131 //IKsClockPropertySet
132 HRESULT STDMETHODCALLTYPE
KsGetTime(LONGLONG
* Time
);
133 HRESULT STDMETHODCALLTYPE
KsSetTime(LONGLONG Time
);
134 HRESULT STDMETHODCALLTYPE
KsGetPhysicalTime(LONGLONG
* Time
);
135 HRESULT STDMETHODCALLTYPE
KsSetPhysicalTime(LONGLONG Time
);
136 HRESULT STDMETHODCALLTYPE
KsGetCorrelatedTime(KSCORRELATED_TIME
* CorrelatedTime
);
137 HRESULT STDMETHODCALLTYPE
KsSetCorrelatedTime(KSCORRELATED_TIME
* CorrelatedTime
);
138 HRESULT STDMETHODCALLTYPE
KsGetCorrelatedPhysicalTime(KSCORRELATED_TIME
* CorrelatedTime
);
139 HRESULT STDMETHODCALLTYPE
KsSetCorrelatedPhysicalTime(KSCORRELATED_TIME
* CorrelatedTime
);
140 HRESULT STDMETHODCALLTYPE
KsGetResolution(KSRESOLUTION
* Resolution
);
141 HRESULT STDMETHODCALLTYPE
KsGetState(KSSTATE
* State
);
144 //IAMovieSetup methods
145 HRESULT STDMETHODCALLTYPE
Register( void);
146 HRESULT STDMETHODCALLTYPE
Unregister( void);
148 // IPersistPropertyBag methods
149 HRESULT STDMETHODCALLTYPE
InitNew( void);
150 HRESULT STDMETHODCALLTYPE
Load(IPropertyBag
*pPropBag
, IErrorLog
*pErrorLog
);
151 HRESULT STDMETHODCALLTYPE
Save(IPropertyBag
*pPropBag
, BOOL fClearDirty
, BOOL fSaveAllProperties
);
154 HANDLE STDMETHODCALLTYPE
KsGetObjectHandle();
157 HANDLE STDMETHODCALLTYPE
KsGetClockHandle();
160 HRESULT STDMETHODCALLTYPE
DeviceInfo(CLSID
*pclsidInterfaceClass
, LPWSTR
*pwszSymbolicLink
);
161 HRESULT STDMETHODCALLTYPE
Reassociate(void);
162 HRESULT STDMETHODCALLTYPE
Disassociate( void);
165 HRESULT STDMETHODCALLTYPE
IsDirty( void);
166 HRESULT STDMETHODCALLTYPE
Load(IStream
*pStm
);
167 HRESULT STDMETHODCALLTYPE
Save(IStream
*pStm
, BOOL fClearDirty
);
168 HRESULT STDMETHODCALLTYPE
GetSizeMax(ULARGE_INTEGER
*pcbSize
);
170 // ISpecifyPropertyPages
171 HRESULT STDMETHODCALLTYPE
GetPages(CAUUID
*pPages
);
174 CKsProxy() : m_Ref(0), m_pGraph(0), m_ReferenceClock((IReferenceClock
*)this), m_FilterState(State_Stopped
), m_hDevice(0), m_Plugins(), m_Pins(), m_DevicePath(0), m_hClock(0) {};
178 CloseHandle(m_hDevice
);
181 HRESULT STDMETHODCALLTYPE
GetSupportedSets(LPGUID
* pOutGuid
, PULONG NumGuids
);
182 HRESULT STDMETHODCALLTYPE
LoadProxyPlugins(LPGUID pGuids
, ULONG NumGuids
);
183 HRESULT STDMETHODCALLTYPE
GetNumberOfPins(PULONG NumPins
);
184 HRESULT STDMETHODCALLTYPE
GetPinInstanceCount(ULONG PinId
, PKSPIN_CINSTANCES Instances
);
185 HRESULT STDMETHODCALLTYPE
GetPinDataflow(ULONG PinId
, KSPIN_DATAFLOW
* DataFlow
);
186 HRESULT STDMETHODCALLTYPE
GetPinName(ULONG PinId
, KSPIN_DATAFLOW DataFlow
, ULONG PinCount
, LPWSTR
* OutPinName
);
187 HRESULT STDMETHODCALLTYPE
GetPinCommunication(ULONG PinId
, KSPIN_COMMUNICATION
* Communication
);
188 HRESULT STDMETHODCALLTYPE
CreatePins();
189 HRESULT STDMETHODCALLTYPE
GetMediaSeekingFormats(PKSMULTIPLE_ITEM
*FormatList
);
190 HRESULT STDMETHODCALLTYPE
CreateClockInstance();
191 HRESULT STDMETHODCALLTYPE
PerformClockProperty(ULONG PropertyId
, ULONG PropertyFlags
, PVOID OutputBuffer
, ULONG OutputBufferSize
);
192 HRESULT STDMETHODCALLTYPE
SetPinState(KSSTATE State
);
197 IFilterGraph
*m_pGraph
;
198 IReferenceClock
* m_ReferenceClock
;
199 FILTER_STATE m_FilterState
;
201 ProxyPluginVector m_Plugins
;
204 CLSID m_DeviceInterfaceGUID
;
210 CKsProxy::QueryInterface(
216 if (IsEqualGUID(refiid
, IID_IUnknown
) ||
217 IsEqualGUID(refiid
, IID_IBaseFilter
))
219 *Output
= PVOID(this);
220 reinterpret_cast<IUnknown
*>(*Output
)->AddRef();
223 else if (IsEqualGUID(refiid
, IID_IPersistPropertyBag
))
225 *Output
= (IPersistPropertyBag
*)(this);
226 reinterpret_cast<IPersistPropertyBag
*>(*Output
)->AddRef();
229 else if (IsEqualGUID(refiid
, IID_IAMDeviceRemoval
))
231 *Output
= (IAMDeviceRemoval
*)(this);
232 reinterpret_cast<IAMDeviceRemoval
*>(*Output
)->AddRef();
235 else if (IsEqualGUID(refiid
, IID_IPersistStream
))
237 *Output
= (IPersistStream
*)(this);
238 reinterpret_cast<IPersistStream
*>(*Output
)->AddRef();
241 else if (IsEqualGUID(refiid
, IID_IPersist
))
243 *Output
= (IPersistStream
*)(this);
244 reinterpret_cast<IPersist
*>(*Output
)->AddRef();
247 else if (IsEqualGUID(refiid
, IID_IKsObject
))
249 *Output
= (IKsObject
*)(this);
250 reinterpret_cast<IKsObject
*>(*Output
)->AddRef();
253 else if (IsEqualGUID(refiid
, IID_IKsClock
))
255 *Output
= (IKsClock
*)(this);
256 reinterpret_cast<IKsClock
*>(*Output
)->AddRef();
259 else if (IsEqualGUID(refiid
, IID_IReferenceClock
))
263 HRESULT hr
= CreateClockInstance();
268 *Output
= (IReferenceClock
*)(this);
269 reinterpret_cast<IReferenceClock
*>(*Output
)->AddRef();
272 else if (IsEqualGUID(refiid
, IID_IMediaSeeking
))
274 *Output
= (IMediaSeeking
*)(this);
275 reinterpret_cast<IMediaSeeking
*>(*Output
)->AddRef();
278 else if (IsEqualGUID(refiid
, IID_IAMFilterMiscFlags
))
280 *Output
= (IAMFilterMiscFlags
*)(this);
281 reinterpret_cast<IAMFilterMiscFlags
*>(*Output
)->AddRef();
284 else if (IsEqualGUID(refiid
, IID_IKsControl
))
286 *Output
= (IKsControl
*)(this);
287 reinterpret_cast<IKsControl
*>(*Output
)->AddRef();
290 else if (IsEqualGUID(refiid
, IID_IKsPropertySet
))
292 *Output
= (IKsPropertySet
*)(this);
293 reinterpret_cast<IKsPropertySet
*>(*Output
)->AddRef();
296 else if (IsEqualGUID(refiid
, IID_IKsTopology
))
298 *Output
= (IKsTopology
*)(this);
299 reinterpret_cast<IKsTopology
*>(*Output
)->AddRef();
302 else if (IsEqualGUID(refiid
, IID_IKsAggregateControl
))
304 *Output
= (IKsAggregateControl
*)(this);
305 reinterpret_cast<IKsAggregateControl
*>(*Output
)->AddRef();
308 else if (IsEqualGUID(refiid
, IID_IKsClockPropertySet
))
312 HRESULT hr
= CreateClockInstance();
317 *Output
= (IKsClockPropertySet
*)(this);
318 reinterpret_cast<IKsClockPropertySet
*>(*Output
)->AddRef();
321 else if (IsEqualGUID(refiid
, IID_ISpecifyPropertyPages
))
323 *Output
= (ISpecifyPropertyPages
*)(this);
324 reinterpret_cast<ISpecifyPropertyPages
*>(*Output
)->AddRef();
328 for(ULONG Index
= 0; Index
< m_Plugins
.size(); Index
++)
332 HRESULT hr
= m_Plugins
[Index
]->QueryInterface(refiid
, Output
);
337 StringFromCLSID(refiid
, &lpstr
);
338 swprintf(Buffer
, L
"CKsProxy::QueryInterface plugin %lu supports interface %s\n", Index
, lpstr
);
339 OutputDebugStringW(Buffer
);
340 CoTaskMemFree(lpstr
);
346 WCHAR Buffer
[MAX_PATH
];
348 StringFromCLSID(refiid
, &lpstr
);
349 swprintf(Buffer
, L
"CKsProxy::QueryInterface: NoInterface for %s !!!\n", lpstr
);
350 OutputDebugStringW(Buffer
);
351 CoTaskMemFree(lpstr
);
354 return E_NOINTERFACE
;
357 //-------------------------------------------------------------------
358 // ISpecifyPropertyPages
363 CKsProxy::GetPages(CAUUID
*pPages
)
365 OutputDebugStringW(L
"CKsProxy::GetPages NotImplemented\n");
371 pPages
->pElems
= NULL
;
376 //-------------------------------------------------------------------
377 // IKsClockPropertySet interface
382 CKsProxy::CreateClockInstance()
385 HANDLE hPin
= INVALID_HANDLE_VALUE
;
387 PIN_DIRECTION PinDir
;
389 KSCLOCK_CREATE ClockCreate
;
391 // find output pin and handle
392 for(Index
= 0; Index
< m_Pins
.size(); Index
++)
395 IPin
* pin
= m_Pins
[Index
];
400 hr
= pin
->QueryDirection(&PinDir
);
404 // query IKsObject interface
405 hr
= pin
->QueryInterface(IID_IKsObject
, (void**)&pObject
);
411 hPin
= pObject
->KsGetObjectHandle();
416 if (hPin
!= INVALID_HANDLE_VALUE
)
420 if (hPin
== INVALID_HANDLE_VALUE
)
422 // clock can only be instantiated on a pin handle
428 // release clock handle
429 CloseHandle(m_hClock
);
432 //setup clock create request
433 ClockCreate
.CreateFlags
= 0;
435 // setup clock create request
436 hr
= KsCreateClock(hPin
, &ClockCreate
, &m_hClock
); // FIXME KsCreateClock returns NTSTATUS
439 // failed to create clock
440 return MAKE_HRESULT(SEVERITY_ERROR
, FACILITY_WIN32
, GetLastError());
448 CKsProxy::PerformClockProperty(
452 ULONG OutputBufferSize
)
461 hr
= CreateClockInstance();
467 Property
.Set
= KSPROPSETID_Clock
;
468 Property
.Id
= PropertyId
;
469 Property
.Flags
= PropertyFlags
;
471 hr
= KsSynchronousDeviceControl(m_hClock
, IOCTL_KS_PROPERTY
, (PVOID
)&Property
, sizeof(KSPROPERTY
), (PVOID
)OutputBuffer
, OutputBufferSize
, &BytesReturned
);
481 OutputDebugStringW(L
"CKsProxy::KsGetTime\n");
482 return PerformClockProperty(KSPROPERTY_CLOCK_TIME
, KSPROPERTY_TYPE_GET
, (PVOID
)Time
, sizeof(LONGLONG
));
490 OutputDebugStringW(L
"CKsProxy::KsSetTime\n");
491 return PerformClockProperty(KSPROPERTY_CLOCK_TIME
, KSPROPERTY_TYPE_SET
, (PVOID
)&Time
, sizeof(LONGLONG
));
496 CKsProxy::KsGetPhysicalTime(
499 OutputDebugStringW(L
"CKsProxy::KsGetPhysicalTime\n");
500 return PerformClockProperty(KSPROPERTY_CLOCK_PHYSICALTIME
, KSPROPERTY_TYPE_GET
, (PVOID
)Time
, sizeof(LONGLONG
));
505 CKsProxy::KsSetPhysicalTime(
508 OutputDebugStringW(L
"CKsProxy::KsSetPhysicalTime NotImplemented\n");
509 return PerformClockProperty(KSPROPERTY_CLOCK_PHYSICALTIME
, KSPROPERTY_TYPE_SET
, (PVOID
)&Time
, sizeof(LONGLONG
));
514 CKsProxy::KsGetCorrelatedTime(
515 KSCORRELATED_TIME
* CorrelatedTime
)
517 OutputDebugStringW(L
"CKsProxy::KsGetCorrelatedTime\n");
518 return PerformClockProperty(KSPROPERTY_CLOCK_CORRELATEDTIME
, KSPROPERTY_TYPE_GET
, (PVOID
)CorrelatedTime
, sizeof(KSCORRELATED_TIME
));
523 CKsProxy::KsSetCorrelatedTime(
524 KSCORRELATED_TIME
* CorrelatedTime
)
526 OutputDebugStringW(L
"CKsProxy::KsSetCorrelatedTime\n");
527 return PerformClockProperty(KSPROPERTY_CLOCK_CORRELATEDTIME
, KSPROPERTY_TYPE_SET
, (PVOID
)CorrelatedTime
, sizeof(KSCORRELATED_TIME
));
532 CKsProxy::KsGetCorrelatedPhysicalTime(
533 KSCORRELATED_TIME
* CorrelatedTime
)
535 OutputDebugStringW(L
"CKsProxy::KsGetCorrelatedPhysicalTime\n");
536 return PerformClockProperty(KSPROPERTY_CLOCK_CORRELATEDPHYSICALTIME
, KSPROPERTY_TYPE_GET
, (PVOID
)CorrelatedTime
, sizeof(KSCORRELATED_TIME
));
541 CKsProxy::KsSetCorrelatedPhysicalTime(
542 KSCORRELATED_TIME
* CorrelatedTime
)
544 OutputDebugStringW(L
"CKsProxy::KsSetCorrelatedPhysicalTime\n");
545 return PerformClockProperty(KSPROPERTY_CLOCK_CORRELATEDPHYSICALTIME
, KSPROPERTY_TYPE_SET
, (PVOID
)CorrelatedTime
, sizeof(KSCORRELATED_TIME
));
550 CKsProxy::KsGetResolution(
551 KSRESOLUTION
* Resolution
)
553 OutputDebugStringW(L
"CKsProxy::KsGetResolution\n");
554 return PerformClockProperty(KSPROPERTY_CLOCK_RESOLUTION
, KSPROPERTY_TYPE_GET
, (PVOID
)Resolution
, sizeof(KSRESOLUTION
));
559 CKsProxy::KsGetState(
562 OutputDebugStringW(L
"CKsProxy::KsGetState\n");
563 return PerformClockProperty(KSPROPERTY_CLOCK_STATE
, KSPROPERTY_TYPE_GET
, (PVOID
)State
, sizeof(KSSTATE
));
566 //-------------------------------------------------------------------
567 // IReferenceClock interface
572 REFERENCE_TIME
*pTime
)
578 OutputDebugStringW(L
"CKsProxy::GetTime\n");
590 hr
= CreateClockInstance();
596 Property
.Set
= KSPROPSETID_Clock
;
597 Property
.Id
= KSPROPERTY_CLOCK_TIME
;
598 Property
.Flags
= KSPROPERTY_TYPE_GET
;
601 hr
= KsSynchronousDeviceControl(m_hClock
, IOCTL_KS_PROPERTY
, (PVOID
)&Property
, sizeof(KSPROPERTY
), (PVOID
)pTime
, sizeof(REFERENCE_TIME
), &BytesReturned
);
612 CKsProxy::AdviseTime(
613 REFERENCE_TIME baseTime
,
614 REFERENCE_TIME streamTime
,
616 DWORD_PTR
*pdwAdviseCookie
)
621 PKSEVENT_TIME_MARK Event
;
623 OutputDebugStringW(L
"CKsProxy::AdviseTime\n");
629 if (!pdwAdviseCookie
)
635 hr
= CreateClockInstance();
640 // allocate event entry
641 Event
= (PKSEVENT_TIME_MARK
)CoTaskMemAlloc(sizeof(KSEVENT_TIME_MARK
));
645 Property
.Set
= KSEVENTSETID_Clock
;
646 Property
.Id
= KSEVENT_CLOCK_POSITION_MARK
;
647 Property
.Flags
= KSEVENT_TYPE_ENABLE
;
649 Event
->EventData
.NotificationType
= KSEVENTF_EVENT_HANDLE
;
650 Event
->EventData
.EventHandle
.Event
= (HANDLE
)hEvent
;
651 Event
->EventData
.Alignment
.Alignment
[0] = 0;
652 Event
->EventData
.Alignment
.Alignment
[1] = 0;
653 Event
->MarkTime
= baseTime
+ streamTime
;
656 hr
= KsSynchronousDeviceControl(m_hClock
, IOCTL_KS_ENABLE_EVENT
, (PVOID
)&Property
, sizeof(KSEVENT
), (PVOID
)Event
, sizeof(KSEVENT_TIME_MARK
), &BytesReturned
);
659 // store event handle
660 *pdwAdviseCookie
= (DWORD_PTR
)Event
;
664 // failed to enable event
665 CoTaskMemFree(Event
);
678 CKsProxy::AdvisePeriodic(
679 REFERENCE_TIME startTime
,
680 REFERENCE_TIME periodTime
,
681 HSEMAPHORE hSemaphore
,
682 DWORD_PTR
*pdwAdviseCookie
)
687 PKSEVENT_TIME_INTERVAL Event
;
689 OutputDebugStringW(L
"CKsProxy::AdvisePeriodic\n");
695 if (!pdwAdviseCookie
)
701 hr
= CreateClockInstance();
706 // allocate event entry
707 Event
= (PKSEVENT_TIME_INTERVAL
)CoTaskMemAlloc(sizeof(KSEVENT_TIME_INTERVAL
));
711 Property
.Set
= KSEVENTSETID_Clock
;
712 Property
.Id
= KSEVENT_CLOCK_INTERVAL_MARK
;
713 Property
.Flags
= KSEVENT_TYPE_ENABLE
;
715 Event
->EventData
.NotificationType
= KSEVENTF_SEMAPHORE_HANDLE
;
716 Event
->EventData
.SemaphoreHandle
.Semaphore
= (HANDLE
)hSemaphore
;
717 Event
->EventData
.SemaphoreHandle
.Reserved
= 0;
718 Event
->EventData
.SemaphoreHandle
.Adjustment
= 1;
719 Event
->TimeBase
= startTime
;
720 Event
->Interval
= periodTime
;
723 hr
= KsSynchronousDeviceControl(m_hClock
, IOCTL_KS_ENABLE_EVENT
, (PVOID
)&Property
, sizeof(KSEVENT
), (PVOID
)Event
, sizeof(KSEVENT_TIME_INTERVAL
), &BytesReturned
);
726 // store event handle
727 *pdwAdviseCookie
= (DWORD_PTR
)Event
;
731 // failed to enable event
732 CoTaskMemFree(Event
);
746 DWORD_PTR dwAdviseCookie
)
751 OutputDebugStringW(L
"CKsProxy::Unadvise\n");
755 //lets disable the event
756 hr
= KsSynchronousDeviceControl(m_hClock
, IOCTL_KS_DISABLE_EVENT
, (PVOID
)dwAdviseCookie
, sizeof(KSEVENTDATA
), 0, 0, &BytesReturned
);
759 // lets free event data
760 CoTaskMemFree((LPVOID
)dwAdviseCookie
);
765 // no clock available
772 //-------------------------------------------------------------------
773 // IMediaSeeking interface
777 CKsProxy::GetCapabilities(
778 DWORD
*pCapabilities
)
781 ULONG BytesReturned
, Index
;
785 Property
.Set
= KSPROPSETID_MediaSeeking
;
786 Property
.Id
= KSPROPERTY_MEDIASEEKING_CAPABILITIES
;
787 Property
.Flags
= KSPROPERTY_TYPE_GET
;
789 OutputDebugStringW(L
"CKsProxy::GetCapabilities\n");
795 *pCapabilities
= (KS_SEEKING_CanSeekAbsolute
| KS_SEEKING_CanSeekForwards
| KS_SEEKING_CanSeekBackwards
| KS_SEEKING_CanGetCurrentPos
|
796 KS_SEEKING_CanGetStopPos
| KS_SEEKING_CanGetDuration
| KS_SEEKING_CanPlayBackwards
);
798 KsSynchronousDeviceControl(m_hDevice
, IOCTL_KS_PROPERTY
, (PVOID
)&Property
, sizeof(KSPROPERTY
), (PVOID
)&pCapabilities
, sizeof(KS_SEEKING_CAPABILITIES
), &BytesReturned
);
799 // check if plugins support it
800 for(Index
= 0; Index
< m_Plugins
.size(); Index
++)
803 IUnknown
* Plugin
= m_Plugins
[Index
];
808 // query for IMediaSeeking interface
809 IMediaSeeking
*pSeek
= NULL
;
810 hr
= Plugin
->QueryInterface(IID_IMediaSeeking
, (void**)&pSeek
);
819 hr
= pSeek
->GetCapabilities(&TempCaps
);
822 // and with supported flags
823 *pCapabilities
= (*pCapabilities
& TempCaps
);
825 // release IMediaSeeking interface
833 CKsProxy::CheckCapabilities(
834 DWORD
*pCapabilities
)
839 OutputDebugStringW(L
"CKsProxy::CheckCapabilities\n");
847 hr
= GetCapabilities(&Capabilities
);
850 if ((Capabilities
| *pCapabilities
) == Capabilities
)
856 Capabilities
= (Capabilities
& *pCapabilities
);
860 *pCapabilities
= Capabilities
;
863 // no capabilities are present
872 CKsProxy::GetMediaSeekingFormats(
873 PKSMULTIPLE_ITEM
*FormatList
)
879 Property
.Set
= KSPROPSETID_MediaSeeking
;
880 Property
.Id
= KSPROPERTY_MEDIASEEKING_FORMATS
;
881 Property
.Flags
= KSPROPERTY_TYPE_GET
;
883 // query for format size list
884 hr
= KsSynchronousDeviceControl(m_hDevice
, IOCTL_KS_PROPERTY
, (PVOID
)&Property
, sizeof(KSPROPERTY
), NULL
, 0, &BytesReturned
);
886 if (hr
== MAKE_HRESULT(SEVERITY_ERROR
, FACILITY_WIN32
, ERROR_MORE_DATA
))
888 // allocate format list
889 *FormatList
= (PKSMULTIPLE_ITEM
)CoTaskMemAlloc(BytesReturned
);
893 return E_OUTOFMEMORY
;
897 hr
= KsSynchronousDeviceControl(m_hDevice
, IOCTL_KS_PROPERTY
, (PVOID
)&Property
, sizeof(KSPROPERTY
), (PVOID
)*FormatList
, BytesReturned
, &BytesReturned
);
900 // failed to query format list
901 CoTaskMemFree(FormatList
);
909 CKsProxy::IsFormatSupported(
912 PKSMULTIPLE_ITEM FormatList
;
915 HRESULT hr
= S_FALSE
;
919 StringFromCLSID(*pFormat
, &pstr
);
920 swprintf(Buffer
, L
"CKsProxy::IsFormatSupported %s\n",pstr
);
921 OutputDebugStringW(Buffer
);
927 hr
= GetMediaSeekingFormats(&FormatList
);
930 swprintf(Buffer
, L
"CKsProxy::IsFormatSupported NumFormat %lu\n",FormatList
->Count
);
931 OutputDebugStringW(Buffer
);
933 //iterate through format list
934 pGuid
= (LPGUID
)(FormatList
+ 1);
935 for(Index
= 0; Index
< FormatList
->Count
; Index
++)
937 if (IsEqualGUID(*pGuid
, *pFormat
))
939 CoTaskMemFree(FormatList
);
945 CoTaskMemFree(FormatList
);
948 // check if all plugins support it
949 for(Index
= 0; Index
< m_Plugins
.size(); Index
++)
952 IUnknown
* Plugin
= m_Plugins
[Index
];
957 // query for IMediaSeeking interface
958 IMediaSeeking
*pSeek
= NULL
;
959 hr
= Plugin
->QueryInterface(IID_IMediaSeeking
, (void**)&pSeek
);
962 // plugin does not support interface
964 OutputDebugStringW(L
"CKsProxy::IsFormatSupported plugin does not support IMediaSeeking interface\n");
968 // query if it is supported
969 hr
= pSeek
->IsFormatSupported(pFormat
);
973 if (FAILED(hr
) || hr
== S_FALSE
)
982 CKsProxy::QueryPreferredFormat(
985 PKSMULTIPLE_ITEM FormatList
;
989 OutputDebugStringW(L
"CKsProxy::QueryPreferredFormat\n");
994 hr
= GetMediaSeekingFormats(&FormatList
);
997 if (FormatList
->Count
)
999 CopyMemory(pFormat
, (FormatList
+ 1), sizeof(GUID
));
1000 CoTaskMemFree(FormatList
);
1003 CoTaskMemFree(FormatList
);
1005 if (hr
== MAKE_HRESULT(SEVERITY_ERROR
, FACILITY_WIN32
, ERROR_NOT_FOUND
) || hr
== MAKE_HRESULT(SEVERITY_ERROR
, FACILITY_WIN32
, ERROR_SET_NOT_FOUND
))
1007 // check if plugins support it
1008 for(Index
= 0; Index
< m_Plugins
.size(); Index
++)
1011 IUnknown
* Plugin
= m_Plugins
[Index
];
1016 // query for IMediaSeeking interface
1017 IMediaSeeking
*pSeek
= NULL
;
1018 hr
= Plugin
->QueryInterface(IID_IMediaSeeking
, (void**)&pSeek
);
1021 // get preferred time format
1022 hr
= pSeek
->QueryPreferredFormat(pFormat
);
1023 // release IMediaSeeking interface
1038 CKsProxy::GetTimeFormat(
1041 KSPROPERTY Property
;
1042 ULONG BytesReturned
, Index
;
1045 Property
.Set
= KSPROPSETID_MediaSeeking
;
1046 Property
.Id
= KSPROPERTY_MEDIASEEKING_TIMEFORMAT
;
1047 Property
.Flags
= KSPROPERTY_TYPE_GET
;
1049 OutputDebugStringW(L
"CKsProxy::GetTimeFormat\n");
1051 hr
= KsSynchronousDeviceControl(m_hDevice
, IOCTL_KS_PROPERTY
, (PVOID
)&Property
, sizeof(KSPROPERTY
), (PVOID
)pFormat
, sizeof(GUID
), &BytesReturned
);
1052 if (hr
== MAKE_HRESULT(SEVERITY_ERROR
, FACILITY_WIN32
, ERROR_NOT_FOUND
) || hr
== MAKE_HRESULT(SEVERITY_ERROR
, FACILITY_WIN32
, ERROR_SET_NOT_FOUND
))
1054 // check if plugins support it
1055 for(Index
= 0; Index
< m_Plugins
.size(); Index
++)
1059 IUnknown
* Plugin
= m_Plugins
[Index
];
1064 // query for IMediaSeeking interface
1065 IMediaSeeking
*pSeek
= NULL
;
1066 hr
= Plugin
->QueryInterface(IID_IMediaSeeking
, (void**)&pSeek
);
1070 hr
= pSeek
->GetTimeFormat(pFormat
);
1071 // release IMediaSeeking interface
1084 CKsProxy::IsUsingTimeFormat(
1085 const GUID
*pFormat
)
1089 OutputDebugStringW(L
"CKsProxy::IsUsingTimeFormat\n");
1091 if (FAILED(QueryPreferredFormat(&Format
)))
1094 if (IsEqualGUID(Format
, *pFormat
))
1102 CKsProxy::SetTimeFormat(
1103 const GUID
*pFormat
)
1105 KSPROPERTY Property
;
1106 ULONG BytesReturned
, Index
;
1109 Property
.Set
= KSPROPSETID_MediaSeeking
;
1110 Property
.Id
= KSPROPERTY_MEDIASEEKING_TIMEFORMAT
;
1111 Property
.Flags
= KSPROPERTY_TYPE_SET
;
1113 OutputDebugStringW(L
"CKsProxy::SetTimeFormat\n");
1115 hr
= KsSynchronousDeviceControl(m_hDevice
, IOCTL_KS_PROPERTY
, (PVOID
)&Property
, sizeof(KSPROPERTY
), (PVOID
)pFormat
, sizeof(GUID
), &BytesReturned
);
1116 if (hr
== MAKE_HRESULT(SEVERITY_ERROR
, FACILITY_WIN32
, ERROR_NOT_FOUND
) || hr
== MAKE_HRESULT(SEVERITY_ERROR
, FACILITY_WIN32
, ERROR_SET_NOT_FOUND
))
1118 // check if plugins support it
1119 for(Index
= 0; Index
< m_Plugins
.size(); Index
++)
1123 IUnknown
* Plugin
= m_Plugins
[Index
];
1128 // query for IMediaSeeking interface
1129 IMediaSeeking
*pSeek
= NULL
;
1130 hr
= Plugin
->QueryInterface(IID_IMediaSeeking
, (void**)&pSeek
);
1137 hr
= pSeek
->SetTimeFormat(pFormat
);
1138 // release IMediaSeeking interface
1150 CKsProxy::GetDuration(
1151 LONGLONG
*pDuration
)
1153 KSPROPERTY Property
;
1154 ULONG BytesReturned
, Index
;
1157 Property
.Set
= KSPROPSETID_MediaSeeking
;
1158 Property
.Id
= KSPROPERTY_MEDIASEEKING_DURATION
;
1159 Property
.Flags
= KSPROPERTY_TYPE_GET
;
1161 OutputDebugStringW(L
"CKsProxy::GetDuration\n");
1163 hr
= KsSynchronousDeviceControl(m_hDevice
, IOCTL_KS_PROPERTY
, (PVOID
)&Property
, sizeof(KSPROPERTY
), (PVOID
)pDuration
, sizeof(LONGLONG
), &BytesReturned
);
1164 if (hr
== MAKE_HRESULT(SEVERITY_ERROR
, FACILITY_WIN32
, ERROR_NOT_FOUND
) || hr
== MAKE_HRESULT(SEVERITY_ERROR
, FACILITY_WIN32
, ERROR_SET_NOT_FOUND
))
1166 // check if plugins support it
1167 for(Index
= 0; Index
< m_Plugins
.size(); Index
++)
1171 IUnknown
* Plugin
= m_Plugins
[Index
];
1176 // query for IMediaSeeking interface
1177 IMediaSeeking
*pSeek
= NULL
;
1178 hr
= Plugin
->QueryInterface(IID_IMediaSeeking
, (void**)&pSeek
);
1182 hr
= pSeek
->GetStopPosition(pDuration
);
1183 // release IMediaSeeking interface
1186 if (hr
!= S_FALSE
) // plugin implements it
1196 CKsProxy::GetStopPosition(
1199 KSPROPERTY Property
;
1200 ULONG BytesReturned
, Index
;
1203 Property
.Set
= KSPROPSETID_MediaSeeking
;
1204 Property
.Id
= KSPROPERTY_MEDIASEEKING_STOPPOSITION
;
1205 Property
.Flags
= KSPROPERTY_TYPE_GET
;
1207 OutputDebugStringW(L
"CKsProxy::GetStopPosition\n");
1209 hr
= KsSynchronousDeviceControl(m_hDevice
, IOCTL_KS_PROPERTY
, (PVOID
)&Property
, sizeof(KSPROPERTY
), (PVOID
)pStop
, sizeof(LONGLONG
), &BytesReturned
);
1210 if (hr
== MAKE_HRESULT(SEVERITY_ERROR
, FACILITY_WIN32
, ERROR_NOT_FOUND
) || hr
== MAKE_HRESULT(SEVERITY_ERROR
, FACILITY_WIN32
, ERROR_SET_NOT_FOUND
))
1212 // check if plugins support it
1213 for(Index
= 0; Index
< m_Plugins
.size(); Index
++)
1217 IUnknown
* Plugin
= m_Plugins
[Index
];
1222 // query for IMediaSeeking interface
1223 IMediaSeeking
*pSeek
= NULL
;
1224 hr
= Plugin
->QueryInterface(IID_IMediaSeeking
, (void**)&pSeek
);
1227 // get stop position
1228 hr
= pSeek
->GetStopPosition(pStop
);
1229 // release IMediaSeeking interface
1232 if (hr
!= S_FALSE
) // plugin implements it
1242 CKsProxy::GetCurrentPosition(
1245 KSPROPERTY Property
;
1246 ULONG BytesReturned
, Index
;
1249 Property
.Set
= KSPROPSETID_MediaSeeking
;
1250 Property
.Id
= KSPROPERTY_MEDIASEEKING_POSITION
;
1251 Property
.Flags
= KSPROPERTY_TYPE_GET
;
1253 OutputDebugStringW(L
"CKsProxy::GetCurrentPosition\n");
1255 hr
= KsSynchronousDeviceControl(m_hDevice
, IOCTL_KS_PROPERTY
, (PVOID
)&Property
, sizeof(KSPROPERTY
), (PVOID
)pCurrent
, sizeof(LONGLONG
), &BytesReturned
);
1256 if (hr
== MAKE_HRESULT(SEVERITY_ERROR
, FACILITY_WIN32
, ERROR_NOT_FOUND
) || hr
== MAKE_HRESULT(SEVERITY_ERROR
, FACILITY_WIN32
, ERROR_SET_NOT_FOUND
))
1258 // check if plugins support it
1259 for(Index
= 0; Index
< m_Plugins
.size(); Index
++)
1263 IUnknown
* Plugin
= m_Plugins
[Index
];
1268 // query for IMediaSeeking interface
1269 IMediaSeeking
*pSeek
= NULL
;
1270 hr
= Plugin
->QueryInterface(IID_IMediaSeeking
, (void**)&pSeek
);
1273 // get current position
1274 hr
= pSeek
->GetCurrentPosition(pCurrent
);
1275 // release IMediaSeeking interface
1278 if (hr
!= S_FALSE
) // plugin implements it
1288 CKsProxy::ConvertTimeFormat(
1290 const GUID
*pTargetFormat
,
1292 const GUID
*pSourceFormat
)
1294 KSP_TIMEFORMAT Property
;
1295 ULONG BytesReturned
, Index
;
1296 GUID SourceFormat
, TargetFormat
;
1299 Property
.Property
.Set
= KSPROPSETID_MediaSeeking
;
1300 Property
.Property
.Id
= KSPROPERTY_MEDIASEEKING_CONVERTTIMEFORMAT
;
1301 Property
.Property
.Flags
= KSPROPERTY_TYPE_GET
;
1303 OutputDebugStringW(L
"CKsProxy::ConvertTimeFormat\n");
1307 // get current format
1308 hr
= GetTimeFormat(&TargetFormat
);
1312 pTargetFormat
= &TargetFormat
;
1317 // get current format
1318 hr
= GetTimeFormat(&SourceFormat
);
1322 pSourceFormat
= &SourceFormat
;
1325 Property
.SourceFormat
= *pSourceFormat
;
1326 Property
.TargetFormat
= *pTargetFormat
;
1327 Property
.Time
= Source
;
1330 hr
= KsSynchronousDeviceControl(m_hDevice
, IOCTL_KS_PROPERTY
, (PVOID
)&Property
, sizeof(KSP_TIMEFORMAT
), (PVOID
)pTarget
, sizeof(LONGLONG
), &BytesReturned
);
1331 if (hr
== MAKE_HRESULT(SEVERITY_ERROR
, FACILITY_WIN32
, ERROR_NOT_FOUND
) || hr
== MAKE_HRESULT(SEVERITY_ERROR
, FACILITY_WIN32
, ERROR_SET_NOT_FOUND
))
1336 // check if plugins support it
1337 for(Index
= 0; Index
< m_Plugins
.size(); Index
++)
1340 IUnknown
* Plugin
= m_Plugins
[Index
];
1345 // query for IMediaSeeking interface
1346 IMediaSeeking
*pSeek
= NULL
;
1347 hr
= Plugin
->QueryInterface(IID_IMediaSeeking
, (void**)&pSeek
);
1350 // convert time format
1351 hr
= pSeek
->ConvertTimeFormat(pTarget
, pTargetFormat
, Source
, pSourceFormat
);
1352 // release IMediaSeeking interface
1355 if (hr
!= S_FALSE
) // plugin implements it
1366 CKsProxy::SetPositions(
1368 DWORD dwCurrentFlags
,
1372 KSPROPERTY Property
;
1373 KSPROPERTY_POSITIONS Positions
;
1374 ULONG BytesReturned
, Index
;
1377 Property
.Set
= KSPROPSETID_MediaSeeking
;
1378 Property
.Id
= KSPROPERTY_MEDIASEEKING_POSITIONS
;
1379 Property
.Flags
= KSPROPERTY_TYPE_SET
;
1381 Positions
.Current
= *pCurrent
;
1382 Positions
.CurrentFlags
= (KS_SEEKING_FLAGS
)dwCurrentFlags
;
1383 Positions
.Stop
= *pStop
;
1384 Positions
.StopFlags
= (KS_SEEKING_FLAGS
)dwStopFlags
;
1386 OutputDebugStringW(L
"CKsProxy::SetPositions\n");
1388 hr
= KsSynchronousDeviceControl(m_hDevice
, IOCTL_KS_PROPERTY
, (PVOID
)&Property
, sizeof(KSPROPERTY
), (PVOID
)&Positions
, sizeof(KSPROPERTY_POSITIONS
), &BytesReturned
);
1391 if (dwCurrentFlags
& AM_SEEKING_ReturnTime
)
1393 // retrieve current position
1394 hr
= GetCurrentPosition(pCurrent
);
1399 if (dwStopFlags
& AM_SEEKING_ReturnTime
)
1401 // retrieve current position
1402 hr
= GetStopPosition(pStop
);
1407 if (hr
== MAKE_HRESULT(SEVERITY_ERROR
, FACILITY_WIN32
, ERROR_NOT_FOUND
) || hr
== MAKE_HRESULT(SEVERITY_ERROR
, FACILITY_WIN32
, ERROR_SET_NOT_FOUND
))
1411 // check if plugins support it
1412 for(Index
= 0; Index
< m_Plugins
.size(); Index
++)
1415 IUnknown
* Plugin
= m_Plugins
[Index
];
1420 // query for IMediaSeeking interface
1421 IMediaSeeking
*pSeek
= NULL
;
1422 hr
= Plugin
->QueryInterface(IID_IMediaSeeking
, (void**)&pSeek
);
1426 hr
= pSeek
->SetPositions(pCurrent
, dwCurrentFlags
, pStop
, dwStopFlags
);
1427 // release IMediaSeeking interface
1441 CKsProxy::GetPositions(
1447 OutputDebugStringW(L
"CKsProxy::GetPositions\n");
1449 hr
= GetCurrentPosition(pCurrent
);
1451 hr
= GetStopPosition(pStop
);
1458 CKsProxy::GetAvailable(
1459 LONGLONG
*pEarliest
,
1462 KSPROPERTY Property
;
1463 KSPROPERTY_MEDIAAVAILABLE Media
;
1464 ULONG BytesReturned
, Index
;
1467 Property
.Set
= KSPROPSETID_MediaSeeking
;
1468 Property
.Id
= KSPROPERTY_MEDIASEEKING_AVAILABLE
;
1469 Property
.Flags
= KSPROPERTY_TYPE_GET
;
1471 OutputDebugStringW(L
"CKsProxy::GetAvailable\n");
1473 hr
= KsSynchronousDeviceControl(m_hDevice
, IOCTL_KS_PROPERTY
, (PVOID
)&Property
, sizeof(KSPROPERTY
), (PVOID
)&Media
, sizeof(KSPROPERTY_MEDIAAVAILABLE
), &BytesReturned
);
1474 if (hr
== MAKE_HRESULT(SEVERITY_ERROR
, FACILITY_WIN32
, ERROR_NOT_FOUND
) || hr
== MAKE_HRESULT(SEVERITY_ERROR
, FACILITY_WIN32
, ERROR_SET_NOT_FOUND
))
1476 // check if plugins support it
1477 for(Index
= 0; Index
< m_Plugins
.size(); Index
++)
1481 IUnknown
* Plugin
= m_Plugins
[Index
];
1486 // query for IMediaSeeking interface
1487 IMediaSeeking
*pSeek
= NULL
;
1488 hr
= Plugin
->QueryInterface(IID_IMediaSeeking
, (void**)&pSeek
);
1492 hr
= pSeek
->GetAvailable(pEarliest
, pLatest
);
1493 // release IMediaSeeking interface
1496 if (hr
!= S_FALSE
) // plugin implements it
1501 else if (SUCCEEDED(hr
))
1503 *pEarliest
= Media
.Earliest
;
1504 *pLatest
= Media
.Latest
;
1515 OutputDebugStringW(L
"CKsProxy::SetRate\n");
1524 OutputDebugStringW(L
"CKsProxy::GetRate\n");
1530 CKsProxy::GetPreroll(
1531 LONGLONG
*pllPreroll
)
1533 KSPROPERTY Property
;
1534 ULONG BytesReturned
, Index
;
1537 Property
.Set
= KSPROPSETID_MediaSeeking
;
1538 Property
.Id
= KSPROPERTY_MEDIASEEKING_PREROLL
;
1539 Property
.Flags
= KSPROPERTY_TYPE_GET
;
1541 OutputDebugStringW(L
"CKsProxy::GetPreroll\n");
1543 hr
= KsSynchronousDeviceControl(m_hDevice
, IOCTL_KS_PROPERTY
, (PVOID
)&Property
, sizeof(KSPROPERTY
), (PVOID
)pllPreroll
, sizeof(LONGLONG
), &BytesReturned
);
1544 if (hr
== MAKE_HRESULT(SEVERITY_ERROR
, FACILITY_WIN32
, ERROR_NOT_FOUND
) || hr
== MAKE_HRESULT(SEVERITY_ERROR
, FACILITY_WIN32
, ERROR_SET_NOT_FOUND
))
1546 // check if all plugins support it
1547 for(Index
= 0; Index
< m_Plugins
.size(); Index
++)
1550 IUnknown
* Plugin
= m_Plugins
[Index
];
1555 // query for IMediaSeeking interface
1556 IMediaSeeking
*pSeek
= NULL
;
1557 hr
= Plugin
->QueryInterface(IID_IMediaSeeking
, (void**)&pSeek
);
1561 hr
= pSeek
->GetPreroll(pllPreroll
);
1562 // release IMediaSeeking interface
1565 if (hr
!= S_FALSE
) // plugin implements it
1574 //-------------------------------------------------------------------
1575 // IAMFilterMiscFlags interface
1580 CKsProxy::GetMiscFlags()
1585 PIN_DIRECTION PinDirection
;
1586 KSPIN_COMMUNICATION Communication
;
1589 for(Index
= 0; Index
< m_Pins
.size(); Index
++)
1592 IPin
* pin
= m_Pins
[Index
];
1594 hr
= pin
->QueryDirection(&PinDirection
);
1597 if (PinDirection
== PINDIR_INPUT
)
1599 if (SUCCEEDED(GetPinCommunication(Index
, //FIXME verify PinId
1602 if (Communication
== KSPIN_COMMUNICATION_NONE
|| Communication
== KSPIN_COMMUNICATION_BRIDGE
)
1604 Flags
|= AM_FILTER_MISC_FLAGS_IS_SOURCE
;
1611 swprintf(Buffer
, L
"CKsProxy::GetMiscFlags stub Flags %x\n", Flags
);
1612 OutputDebugStringW(Buffer
);
1616 //-------------------------------------------------------------------
1621 CKsProxy::KsProperty(
1622 PKSPROPERTY Property
,
1623 ULONG PropertyLength
,
1624 LPVOID PropertyData
,
1626 ULONG
* BytesReturned
)
1628 assert(m_hDevice
!= 0);
1629 OutputDebugStringW(L
"CKsProxy::KsProperty\n");
1630 return KsSynchronousDeviceControl(m_hDevice
, IOCTL_KS_PROPERTY
, (PVOID
)Property
, PropertyLength
, (PVOID
)PropertyData
, DataLength
, BytesReturned
);
1640 ULONG
* BytesReturned
)
1642 assert(m_hDevice
!= 0);
1643 OutputDebugStringW(L
"CKsProxy::KsMethod\n");
1644 return KsSynchronousDeviceControl(m_hDevice
, IOCTL_KS_METHOD
, (PVOID
)Method
, MethodLength
, (PVOID
)MethodData
, DataLength
, BytesReturned
);
1654 ULONG
* BytesReturned
)
1656 assert(m_hDevice
!= 0);
1657 OutputDebugStringW(L
"CKsProxy::KsEvent\n");
1659 return KsSynchronousDeviceControl(m_hDevice
, IOCTL_KS_ENABLE_EVENT
, (PVOID
)Event
, EventLength
, (PVOID
)EventData
, DataLength
, BytesReturned
);
1661 return KsSynchronousDeviceControl(m_hDevice
, IOCTL_KS_DISABLE_EVENT
, (PVOID
)Event
, EventLength
, NULL
, 0, BytesReturned
);
1665 //-------------------------------------------------------------------
1671 REFGUID guidPropSet
,
1673 LPVOID pInstanceData
,
1674 DWORD cbInstanceData
,
1678 ULONG BytesReturned
;
1680 OutputDebugStringW(L
"CKsProxy::Set\n");
1684 PKSPROPERTY Property
= (PKSPROPERTY
)CoTaskMemAlloc(sizeof(KSPROPERTY
) + cbInstanceData
);
1686 return E_OUTOFMEMORY
;
1688 Property
->Set
= guidPropSet
;
1689 Property
->Id
= dwPropID
;
1690 Property
->Flags
= KSPROPERTY_TYPE_SET
;
1692 CopyMemory((Property
+1), pInstanceData
, cbInstanceData
);
1694 HRESULT hr
= KsProperty(Property
, sizeof(KSPROPERTY
) + cbInstanceData
, pPropData
, cbPropData
, &BytesReturned
);
1695 CoTaskMemFree(Property
);
1700 KSPROPERTY Property
;
1702 Property
.Set
= guidPropSet
;
1703 Property
.Id
= dwPropID
;
1704 Property
.Flags
= KSPROPERTY_TYPE_SET
;
1706 HRESULT hr
= KsProperty(&Property
, sizeof(KSPROPERTY
), pPropData
, cbPropData
, &BytesReturned
);
1714 REFGUID guidPropSet
,
1716 LPVOID pInstanceData
,
1717 DWORD cbInstanceData
,
1722 ULONG BytesReturned
;
1724 OutputDebugStringW(L
"CKsProxy::Get\n");
1728 PKSPROPERTY Property
= (PKSPROPERTY
)CoTaskMemAlloc(sizeof(KSPROPERTY
) + cbInstanceData
);
1730 return E_OUTOFMEMORY
;
1732 Property
->Set
= guidPropSet
;
1733 Property
->Id
= dwPropID
;
1734 Property
->Flags
= KSPROPERTY_TYPE_GET
;
1736 CopyMemory((Property
+1), pInstanceData
, cbInstanceData
);
1738 HRESULT hr
= KsProperty(Property
, sizeof(KSPROPERTY
) + cbInstanceData
, pPropData
, cbPropData
, &BytesReturned
);
1739 CoTaskMemFree(Property
);
1744 KSPROPERTY Property
;
1746 Property
.Set
= guidPropSet
;
1747 Property
.Id
= dwPropID
;
1748 Property
.Flags
= KSPROPERTY_TYPE_GET
;
1750 HRESULT hr
= KsProperty(&Property
, sizeof(KSPROPERTY
), pPropData
, cbPropData
, &BytesReturned
);
1757 CKsProxy::QuerySupported(
1758 REFGUID guidPropSet
,
1760 DWORD
*pTypeSupport
)
1762 KSPROPERTY Property
;
1763 ULONG BytesReturned
;
1765 OutputDebugStringW(L
"CKsProxy::QuerySupported\n");
1767 Property
.Set
= guidPropSet
;
1768 Property
.Id
= dwPropID
;
1769 Property
.Flags
= KSPROPERTY_TYPE_SETSUPPORT
;
1771 return KsProperty(&Property
, sizeof(KSPROPERTY
), pTypeSupport
, sizeof(DWORD
), &BytesReturned
);
1775 //-------------------------------------------------------------------
1776 // IKsTopology interface
1780 CKsProxy::CreateNodeInstance(
1783 ACCESS_MASK DesiredAccess
,
1785 REFGUID InterfaceId
,
1790 OutputDebugStringW(L
"CKsProxy::CreateNodeInstance\n");
1794 if (IsEqualIID(IID_IUnknown
, InterfaceId
) || !UnkOuter
)
1796 hr
= CKsNode_Constructor(UnkOuter
, m_hDevice
, NodeId
, DesiredAccess
, InterfaceId
, Interface
);
1800 // interface not supported
1807 //-------------------------------------------------------------------
1808 // IKsAggregateControl interface
1812 CKsProxy::KsAddAggregate(
1813 IN REFGUID AggregateClass
)
1815 OutputDebugStringW(L
"CKsProxy::KsAddAggregate NotImplemented\n");
1821 CKsProxy::KsRemoveAggregate(
1822 REFGUID AggregateClass
)
1824 OutputDebugStringW(L
"CKsProxy::KsRemoveAggregate NotImplemented\n");
1829 //-------------------------------------------------------------------
1830 // IPersistStream interface
1837 OutputDebugStringW(L
"CKsProxy::IsDirty Notimplemented\n");
1849 AM_MEDIA_TYPE MediaType
;
1850 ULONG BytesReturned
;
1854 LPOLESTR pMajor
, pSub
, pFormat
;
1856 OutputDebugStringW(L
"CKsProxy::Load\n");
1859 ULONG Version
= ReadInt(pStm
, hr
);
1864 hr
= pStm
->Read(&Length
, sizeof(ULONG
), &BytesReturned
);
1865 swprintf(Buffer
, L
"Length hr %x hr length %lu\n", hr
, Length
);
1866 OutputDebugStringW(Buffer
);
1870 hr
= pStm
->Read(&PinId
, sizeof(ULONG
), &BytesReturned
);
1871 swprintf(Buffer
, L
"Read: hr %08x PinId %lx BytesReturned %lu\n", hr
, PinId
, BytesReturned
);
1872 OutputDebugStringW(Buffer
);
1874 if (FAILED(hr
) || !BytesReturned
)
1877 Length
-= BytesReturned
;
1879 hr
= pStm
->Read(&MediaType
, sizeof(AM_MEDIA_TYPE
), &BytesReturned
);
1880 if (FAILED(hr
) || BytesReturned
!= sizeof(AM_MEDIA_TYPE
))
1882 swprintf(Buffer
, L
"Read failed with %lx\n", hr
);
1883 OutputDebugStringW(Buffer
);
1888 StringFromIID(MediaType
.majortype
, &pMajor
);
1889 StringFromIID(MediaType
.subtype
, &pSub
);
1890 StringFromIID(MediaType
.formattype
, &pFormat
);
1892 swprintf(Buffer
, L
"BytesReturned %lu majortype %s subtype %s bFixedSizeSamples %u bTemporalCompression %u lSampleSize %u formattype %s, pUnk %p cbFormat %u pbFormat %p\n", BytesReturned
, pMajor
, pSub
, MediaType
.bFixedSizeSamples
, MediaType
.bTemporalCompression
, MediaType
.lSampleSize
, pFormat
, MediaType
.pUnk
, MediaType
.cbFormat
, MediaType
.pbFormat
);
1893 OutputDebugStringW(Buffer
);
1895 Length
-= BytesReturned
;
1898 if (MediaType
.cbFormat
)
1900 MediaType
.pbFormat
= (BYTE
*)CoTaskMemAlloc(MediaType
.cbFormat
);
1901 if (!MediaType
.pbFormat
)
1902 return E_OUTOFMEMORY
;
1904 hr
= pStm
->Read(&MediaType
.pbFormat
, sizeof(MediaType
.cbFormat
), &BytesReturned
);
1907 swprintf(Buffer
, L
"ReadFormat failed with %lx\n", hr
);
1908 OutputDebugStringW(Buffer
);
1911 Length
-= BytesReturned
;
1926 OutputDebugStringW(L
"CKsProxy::Save Notimplemented\n");
1932 CKsProxy::GetSizeMax(
1933 ULARGE_INTEGER
*pcbSize
)
1935 OutputDebugStringW(L
"CKsProxy::GetSizeMax Notimplemented\n");
1940 //-------------------------------------------------------------------
1941 // IAMDeviceRemoval interface
1946 CKsProxy::DeviceInfo(CLSID
*pclsidInterfaceClass
, LPWSTR
*pwszSymbolicLink
)
1949 OutputDebugStringW(L
"CKsProxy::DeviceInfo\n");
1953 // object not initialized
1954 return MAKE_HRESULT(SEVERITY_ERROR
, FACILITY_WIN32
, ERROR_FILE_NOT_FOUND
);
1957 // copy device interface guid
1958 CopyMemory(pclsidInterfaceClass
, &m_DeviceInterfaceGUID
, sizeof(GUID
));
1960 if (pwszSymbolicLink
)
1962 *pwszSymbolicLink
= (LPWSTR
)CoTaskMemAlloc((wcslen(m_DevicePath
)+1) * sizeof(WCHAR
));
1963 if (!*pwszSymbolicLink
)
1964 return E_OUTOFMEMORY
;
1966 wcscpy(*pwszSymbolicLink
, m_DevicePath
);
1972 CKsProxy::Reassociate(void)
1974 OutputDebugStringW(L
"CKsProxy::Reassociate\n");
1976 if (!m_DevicePath
|| m_hDevice
)
1978 // file path not available
1979 return MAKE_HRESULT(SEVERITY_ERROR
, FACILITY_WIN32
, ERROR_FILE_NOT_FOUND
);
1982 m_hDevice
= CreateFileW(m_DevicePath
, GENERIC_READ
| GENERIC_WRITE
, 0, NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
| FILE_FLAG_OVERLAPPED
, NULL
);
1985 // failed to open device
1986 return MAKE_HRESULT(SEVERITY_ERROR
, FACILITY_WIN32
, GetLastError());
1995 CKsProxy::Disassociate(void)
1997 OutputDebugStringW(L
"CKsProxy::Disassociate\n");
2002 CloseHandle(m_hDevice
);
2007 //-------------------------------------------------------------------
2008 // IKsClock interface
2013 CKsProxy::KsGetClockHandle()
2015 OutputDebugStringW(L
"CKsProxy::KsGetClockHandle\n");
2020 //-------------------------------------------------------------------
2021 // IKsObject interface
2026 CKsProxy::KsGetObjectHandle()
2028 OutputDebugStringW(L
"CKsProxy::KsGetObjectHandle\n");
2032 //-------------------------------------------------------------------
2033 // IPersistPropertyBag interface
2037 CKsProxy::InitNew( void)
2039 OutputDebugStringW(L
"CKsProxy::InitNew\n");
2045 CKsProxy::GetSupportedSets(
2049 KSPROPERTY Property
;
2051 ULONG NumProperty
= 0;
2052 ULONG NumMethods
= 0;
2053 ULONG NumEvents
= 0;
2055 ULONG BytesReturned
;
2058 Property
.Set
= GUID_NULL
;
2060 Property
.Flags
= KSPROPERTY_TYPE_SETSUPPORT
;
2062 KsSynchronousDeviceControl(m_hDevice
, IOCTL_KS_PROPERTY
, (PVOID
)&Property
, sizeof(KSPROPERTY
), NULL
, 0, &NumProperty
);
2063 KsSynchronousDeviceControl(m_hDevice
, IOCTL_KS_METHOD
, (PVOID
)&Property
, sizeof(KSPROPERTY
), NULL
, 0, &NumMethods
);
2064 KsSynchronousDeviceControl(m_hDevice
, IOCTL_KS_ENABLE_EVENT
, (PVOID
)&Property
, sizeof(KSPROPERTY
), NULL
, 0, &NumEvents
);
2066 Length
= NumProperty
+ NumMethods
+ NumEvents
;
2068 // allocate guid buffer
2069 pGuid
= (LPGUID
)CoTaskMemAlloc(Length
);
2073 return E_OUTOFMEMORY
;
2076 NumProperty
/= sizeof(GUID
);
2077 NumMethods
/= sizeof(GUID
);
2078 NumEvents
/= sizeof(GUID
);
2080 // get all properties
2081 hr
= KsSynchronousDeviceControl(m_hDevice
, IOCTL_KS_PROPERTY
, (PVOID
)&Property
, sizeof(KSPROPERTY
), (PVOID
)pGuid
, Length
, &BytesReturned
);
2084 CoTaskMemFree(pGuid
);
2087 Length
-= BytesReturned
;
2092 hr
= KsSynchronousDeviceControl(m_hDevice
, IOCTL_KS_METHOD
, (PVOID
)&Property
, sizeof(KSPROPERTY
), (PVOID
)&pGuid
[NumProperty
], Length
, &BytesReturned
);
2095 CoTaskMemFree(pGuid
);
2098 Length
-= BytesReturned
;
2104 hr
= KsSynchronousDeviceControl(m_hDevice
, IOCTL_KS_ENABLE_EVENT
, (PVOID
)&Property
, sizeof(KSPROPERTY
), (PVOID
)&pGuid
[NumProperty
+NumMethods
], Length
, &BytesReturned
);
2107 CoTaskMemFree(pGuid
);
2110 Length
-= BytesReturned
;
2113 #ifdef KSPROXY_TRACE
2115 swprintf(Buffer
, L
"NumProperty %lu NumMethods %lu NumEvents %lu\n", NumProperty
, NumMethods
, NumEvents
);
2116 OutputDebugStringW(Buffer
);
2120 *NumGuids
= NumProperty
+NumEvents
+NumMethods
;
2126 CKsProxy::LoadProxyPlugins(
2134 IUnknown
* pUnknown
;
2136 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, L
"SYSTEM\\CurrentControlSet\\Control\\MediaInterfaces", 0, KEY_READ
, &hKey
) != ERROR_SUCCESS
)
2138 OutputDebugStringW(L
"CKsProxy::LoadProxyPlugins failed to open MediaInterfaces key\n");
2142 // enumerate all sets
2143 for(Index
= 0; Index
< NumGuids
; Index
++)
2145 // convert to string
2146 hr
= StringFromCLSID(pGuids
[Index
], &pStr
);
2150 // now try open class key
2151 if (RegOpenKeyExW(hKey
, pStr
, 0, KEY_READ
, &hSubKey
) != ERROR_SUCCESS
)
2153 // no plugin for that set exists
2154 CoTaskMemFree(pStr
);
2159 hr
= CoCreateInstance(pGuids
[Index
], (IBaseFilter
*)this, CLSCTX_INPROC_SERVER
, IID_IUnknown
, (void**)&pUnknown
);
2163 m_Plugins
.push_back(pUnknown
);
2166 RegCloseKey(hSubKey
);
2169 // close media interfaces key
2176 CKsProxy::GetNumberOfPins(
2179 KSPROPERTY Property
;
2180 ULONG BytesReturned
;
2183 Property
.Set
= KSPROPSETID_Pin
;
2184 Property
.Id
= KSPROPERTY_PIN_CTYPES
;
2185 Property
.Flags
= KSPROPERTY_TYPE_GET
;
2187 return KsSynchronousDeviceControl(m_hDevice
, IOCTL_KS_PROPERTY
, (PVOID
)&Property
, sizeof(KSPROPERTY
), (PVOID
)NumPins
, sizeof(ULONG
), &BytesReturned
);
2192 CKsProxy::GetPinInstanceCount(
2194 PKSPIN_CINSTANCES Instances
)
2197 ULONG BytesReturned
;
2200 Property
.Property
.Set
= KSPROPSETID_Pin
;
2201 Property
.Property
.Id
= KSPROPERTY_PIN_CINSTANCES
;
2202 Property
.Property
.Flags
= KSPROPERTY_TYPE_GET
;
2203 Property
.PinId
= PinId
;
2204 Property
.Reserved
= 0;
2206 return KsSynchronousDeviceControl(m_hDevice
, IOCTL_KS_PROPERTY
, (PVOID
)&Property
, sizeof(KSP_PIN
), (PVOID
)Instances
, sizeof(KSPIN_CINSTANCES
), &BytesReturned
);
2211 CKsProxy::GetPinCommunication(
2213 KSPIN_COMMUNICATION
* Communication
)
2216 ULONG BytesReturned
;
2219 Property
.Property
.Set
= KSPROPSETID_Pin
;
2220 Property
.Property
.Id
= KSPROPERTY_PIN_COMMUNICATION
;
2221 Property
.Property
.Flags
= KSPROPERTY_TYPE_GET
;
2222 Property
.PinId
= PinId
;
2223 Property
.Reserved
= 0;
2225 return KsSynchronousDeviceControl(m_hDevice
, IOCTL_KS_PROPERTY
, (PVOID
)&Property
, sizeof(KSP_PIN
), (PVOID
)Communication
, sizeof(KSPIN_COMMUNICATION
), &BytesReturned
);
2230 CKsProxy::GetPinDataflow(
2232 KSPIN_DATAFLOW
* DataFlow
)
2235 ULONG BytesReturned
;
2238 Property
.Property
.Set
= KSPROPSETID_Pin
;
2239 Property
.Property
.Id
= KSPROPERTY_PIN_DATAFLOW
;
2240 Property
.Property
.Flags
= KSPROPERTY_TYPE_GET
;
2241 Property
.PinId
= PinId
;
2242 Property
.Reserved
= 0;
2244 return KsSynchronousDeviceControl(m_hDevice
, IOCTL_KS_PROPERTY
, (PVOID
)&Property
, sizeof(KSP_PIN
), (PVOID
)DataFlow
, sizeof(KSPIN_DATAFLOW
), &BytesReturned
);
2249 CKsProxy::GetPinName(
2251 KSPIN_DATAFLOW DataFlow
,
2253 LPWSTR
* OutPinName
)
2257 ULONG BytesReturned
;
2262 Property
.Property
.Set
= KSPROPSETID_Pin
;
2263 Property
.Property
.Id
= KSPROPERTY_PIN_NAME
;
2264 Property
.Property
.Flags
= KSPROPERTY_TYPE_GET
;
2265 Property
.PinId
= PinId
;
2266 Property
.Reserved
= 0;
2268 // #1 try get it from pin directly
2269 hr
= KsSynchronousDeviceControl(m_hDevice
, IOCTL_KS_PROPERTY
, (PVOID
)&Property
, sizeof(KSP_PIN
), NULL
, 0, &BytesReturned
);
2271 if (hr
== MAKE_HRESULT(SEVERITY_ERROR
, FACILITY_WIN32
, ERROR_MORE_DATA
))
2273 // allocate pin name
2274 PinName
= (LPWSTR
)CoTaskMemAlloc(BytesReturned
);
2276 return E_OUTOFMEMORY
;
2278 // retry with allocated buffer
2279 hr
= KsSynchronousDeviceControl(m_hDevice
, IOCTL_KS_PROPERTY
, (PVOID
)&Property
, sizeof(KSP_PIN
), PinName
, BytesReturned
, &BytesReturned
);
2282 *OutPinName
= PinName
;
2287 CoTaskMemFree(PinName
);
2291 // TODO: retrieve pin name from topology node
2294 if (DataFlow
== KSPIN_DATAFLOW_IN
)
2296 swprintf(Buffer
, L
"Input%lu", PinCount
);
2300 swprintf(Buffer
, L
"Output%lu", PinCount
);
2303 // allocate pin name
2304 PinName
= (LPWSTR
)CoTaskMemAlloc((wcslen(Buffer
)+1) * sizeof(WCHAR
));
2306 return E_OUTOFMEMORY
;
2309 wcscpy(PinName
, Buffer
);
2312 *OutPinName
= PinName
;
2319 CKsProxy::CreatePins()
2321 ULONG NumPins
, Index
;
2322 KSPIN_CINSTANCES Instances
;
2323 KSPIN_DATAFLOW DataFlow
;
2324 KSPIN_COMMUNICATION Communication
;
2330 ULONG OutputPin
= 0;
2332 // get number of pins
2333 hr
= GetNumberOfPins(&NumPins
);
2337 for(Index
= 0; Index
< NumPins
; Index
++)
2339 // query current instance count
2340 hr
= GetPinInstanceCount(Index
, &Instances
);
2344 // query pin communication;
2345 hr
= GetPinCommunication(Index
, &Communication
);
2349 if (Instances
.CurrentCount
== Instances
.PossibleCount
)
2351 // already maximum reached for this pin
2355 // get direction of pin
2356 hr
= GetPinDataflow(Index
, &DataFlow
);
2360 if (DataFlow
== KSPIN_DATAFLOW_IN
)
2361 hr
= GetPinName(Index
, DataFlow
, InputPin
, &PinName
);
2363 hr
= GetPinName(Index
, DataFlow
, OutputPin
, &PinName
);
2368 // construct the pins
2369 if (DataFlow
== KSPIN_DATAFLOW_IN
)
2371 hr
= CInputPin_Constructor((IBaseFilter
*)this, PinName
, m_hDevice
, Index
, Communication
, IID_IPin
, (void**)&pPin
);
2374 CoTaskMemFree(PinName
);
2381 hr
= COutputPin_Constructor((IBaseFilter
*)this, PinName
, Index
, Communication
, IID_IPin
, (void**)&pPin
);
2384 CoTaskMemFree(PinName
);
2391 m_Pins
.push_back(pPin
);
2393 swprintf(Buffer
, L
"Index %lu DataFlow %lu Name %s\n", Index
, DataFlow
, PinName
);
2394 OutputDebugStringW(Buffer
);
2402 CKsProxy::Load(IPropertyBag
*pPropBag
, IErrorLog
*pErrorLog
)
2410 SP_DEVICE_INTERFACE_DATA DeviceInterfaceData
;
2412 OutputDebugStringW(L
"CKsProxy::Load\n");
2415 varName
.vt
= VT_BSTR
;
2416 hr
= pPropBag
->Read(L
"DevicePath", &varName
, pErrorLog
);
2420 swprintf(Buffer
, L
"CKsProxy::Load Read %lx\n", hr
);
2421 OutputDebugStringW(Buffer
);
2422 return MAKE_HRESULT(SEVERITY_ERROR
, FACILITY_WIN32
, GetLastError());
2425 OutputDebugStringW(L
"DevicePath: ");
2426 OutputDebugStringW(varName
.bstrVal
);
2427 OutputDebugStringW(L
"\n");
2429 // create device list
2430 hList
= SetupDiCreateDeviceInfoListExW(NULL
, NULL
, NULL
, NULL
);
2431 if (hList
== INVALID_HANDLE_VALUE
)
2433 // failed to create device list
2434 return MAKE_HRESULT(SEVERITY_ERROR
, FACILITY_WIN32
, GetLastError());
2437 DeviceInterfaceData
.cbSize
= sizeof(SP_DEVICE_INTERFACE_DATA
);
2438 if (!SetupDiOpenDeviceInterfaceW(hList
, (PCWSTR
)varName
.bstrVal
, 0, &DeviceInterfaceData
))
2440 // failed to open device interface
2441 SetupDiDestroyDeviceInfoList(hList
);
2444 // FIXME handle device interface links(aliases)
2445 CopyMemory(&m_DeviceInterfaceGUID
, &DeviceInterfaceData
.InterfaceClassGuid
, sizeof(GUID
));
2447 // close device info list
2448 SetupDiDestroyDeviceInfoList(hList
);
2451 m_hDevice
= CreateFileW(varName
.bstrVal
, GENERIC_READ
| GENERIC_WRITE
, 0, NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
| FILE_FLAG_OVERLAPPED
, NULL
);
2453 if (m_hDevice
== INVALID_HANDLE_VALUE
)
2455 // failed to open device
2456 swprintf(Buffer
, L
"CKsProxy:: failed to open device with %lx\n", GetLastError());
2457 OutputDebugStringW(Buffer
);
2459 return MAKE_HRESULT(SEVERITY_ERROR
, FACILITY_WIN32
, GetLastError());
2462 // store device path
2463 m_DevicePath
= varName
.bstrVal
;
2465 // get all supported sets
2466 hr
= GetSupportedSets(&pGuid
, &NumGuids
);
2469 CloseHandle(m_hDevice
);
2474 // load all proxy plugins
2475 hr
= LoadProxyPlugins(pGuid
, NumGuids
);
2478 CloseHandle(m_hDevice
);
2484 CoTaskMemFree(pGuid
);
2486 // now create the input / output pins
2494 CKsProxy::Save(IPropertyBag
*pPropBag
, BOOL fClearDirty
, BOOL fSaveAllProperties
)
2496 OutputDebugStringW(L
"CKsProxy::Save\n");
2500 //-------------------------------------------------------------------
2501 // IBaseFilter interface
2506 CKsProxy::GetClassID(
2509 OutputDebugStringW(L
"CKsProxy::GetClassID\n");
2510 CopyMemory(pClassID
, &CLSID_Proxy
, sizeof(GUID
));
2519 OutputDebugStringW(L
"CKsProxy::Stop : NotImplemented\n");
2529 OutputDebugStringW(L
"CKsProxy::Pause\n");
2531 if (m_FilterState
== State_Stopped
)
2533 hr
= SetPinState(KSSTATE_PAUSE
);
2539 m_FilterState
= State_Paused
;
2547 REFERENCE_TIME tStart
)
2551 OutputDebugStringW(L
"CKsProxy::Run\n");
2553 if (m_FilterState
== State_Stopped
)
2555 // setting filter state to pause
2560 assert(m_FilterState
== State_Paused
);
2563 hr
= SetPinState(KSSTATE_RUN
);
2567 m_FilterState
= State_Running
;
2573 CKsProxy::SetPinState(
2579 ULONG BytesReturned
;
2580 KSPROPERTY Property
;
2582 Property
.Set
= KSPROPSETID_Connection
;
2583 Property
.Id
= KSPROPERTY_CONNECTION_STATE
;
2584 Property
.Flags
= KSPROPERTY_TYPE_SET
;
2586 // set all pins to running state
2587 for(Index
= 0; Index
< m_Pins
.size(); Index
++)
2589 IPin
* Pin
= m_Pins
[Index
];
2593 //check if the pin is connected
2595 hr
= Pin
->ConnectedTo(&TempPin
);
2598 // skip unconnected pins
2602 // release connected pin
2605 //query IKsObject interface
2606 hr
= Pin
->QueryInterface(IID_IKsObject
, (void**)&pObject
);
2609 HANDLE hPin
= pObject
->KsGetObjectHandle();
2612 assert(hPin
&& hPin
!= INVALID_HANDLE_VALUE
);
2615 hr
= KsSynchronousDeviceControl(hPin
, IOCTL_KS_PROPERTY
, (PVOID
)&Property
, sizeof(KSPROPERTY
), (PVOID
)&State
, sizeof(KSSTATE
), &BytesReturned
);
2618 swprintf(Buffer
, L
"CKsProxy::SetPinState Index %u State %u hr %lx\n", Index
, State
, hr
);
2619 OutputDebugStringW(Buffer
);
2630 DWORD dwMilliSecsTimeout
,
2631 FILTER_STATE
*State
)
2633 *State
= m_FilterState
;
2639 CKsProxy::SetSyncSource(
2640 IReferenceClock
*pClock
)
2644 HANDLE hClock
, hPin
;
2647 IKsObject
* pObject
;
2648 KSPROPERTY Property
;
2649 ULONG BytesReturned
;
2650 PIN_DIRECTION PinDir
;
2652 // Plug In Distributor: IKsClock
2653 OutputDebugStringW(L
"CKsProxy::SetSyncSource\n");
2660 hr
= pClock
->QueryInterface(IID_IKsClock
, (void**)&pKsClock
);
2663 hr
= m_ReferenceClock
->QueryInterface(IID_IKsClock
, (void**)&pKsClock
);
2669 hClock
= pKsClock
->KsGetClockHandle();
2671 // release IKsClock interface
2672 pKsClock
->Release();
2682 // distribute clock to all pins
2683 for(Index
= 0; Index
< m_Pins
.size(); Index
++)
2686 pin
= m_Pins
[Index
];
2690 // get IKsObject interface
2691 hr
= pin
->QueryInterface(IID_IKsObject
, (void **)&pObject
);
2695 hPin
= pObject
->KsGetObjectHandle();
2696 if (hPin
!= INVALID_HANDLE_VALUE
&& hPin
)
2699 Property
.Set
= KSPROPSETID_Stream
;
2700 Property
.Id
= KSPROPERTY_STREAM_MASTERCLOCK
;
2701 Property
.Flags
= KSPROPERTY_TYPE_SET
;
2704 hr
= KsSynchronousDeviceControl(hPin
, IOCTL_KS_PROPERTY
, (PVOID
)&Property
, sizeof(KSPROPERTY
), (PVOID
)&m_hClock
, sizeof(HANDLE
), &BytesReturned
);
2708 if (hr
!= MAKE_HRESULT(SEVERITY_ERROR
, FACILITY_WIN32
, ERROR_SET_NOT_FOUND
) &&
2709 hr
!= MAKE_HRESULT(SEVERITY_ERROR
, FACILITY_WIN32
, ERROR_NOT_FOUND
))
2711 // failed to set master clock
2714 swprintf(Buffer
, L
"CKsProxy::SetSyncSource KSPROPERTY_STREAM_MASTERCLOCK failed with %lx\n", hr
);
2715 OutputDebugStringW(Buffer
);
2720 // release IKsObject
2724 // now get the direction
2725 hr
= pin
->QueryDirection(&PinDir
);
2728 if (PinDir
== PINDIR_OUTPUT
)
2731 //CBaseStreamControl::SetSyncSource(pClock)
2741 if (m_ReferenceClock
)
2743 m_ReferenceClock
->Release();
2746 m_ReferenceClock
= pClock
;
2747 OutputDebugStringW(L
"CKsProxy::SetSyncSource done\n");
2753 CKsProxy::GetSyncSource(
2754 IReferenceClock
**pClock
)
2756 OutputDebugStringW(L
"CKsProxy::GetSyncSource\n");
2761 if (m_ReferenceClock
)
2762 m_ReferenceClock
->AddRef();
2764 *pClock
= m_ReferenceClock
;
2773 OutputDebugStringW(L
"CKsProxy::EnumPins\n");
2774 return CEnumPins_fnConstructor(m_Pins
, IID_IEnumPins
, (void**)ppEnum
);
2780 LPCWSTR Id
, IPin
**ppPin
)
2784 OutputDebugStringW(L
"CKsProxy::FindPin\n");
2790 int ret
= swscanf(Id
, L
"%u", &PinId
);
2792 if (!ret
|| ret
== EOF
)
2795 return VFW_E_NOT_FOUND
;
2798 if (PinId
>= m_Pins
.size() || m_Pins
[PinId
] == NULL
)
2801 return VFW_E_NOT_FOUND
;
2805 *ppPin
= m_Pins
[PinId
];
2806 m_Pins
[PinId
]->AddRef();
2814 CKsProxy::QueryFilterInfo(
2820 OutputDebugStringW(L
"CKsProxy::QueryFilterInfo\n");
2822 pInfo
->achName
[0] = L
'\0';
2823 pInfo
->pGraph
= m_pGraph
;
2833 CKsProxy::JoinFilterGraph(
2834 IFilterGraph
*pGraph
,
2837 OutputDebugStringW(L
"CKsProxy::JoinFilterGraph\n");
2841 // joining filter graph
2856 CKsProxy::QueryVendorInfo(
2857 LPWSTR
*pVendorInfo
)
2859 OutputDebugStringW(L
"CKsProxy::QueryVendorInfo\n");
2860 return StringFromCLSID(CLSID_Proxy
, pVendorInfo
);
2863 //-------------------------------------------------------------------
2864 // IAMovieSetup interface
2869 CKsProxy::Register()
2871 OutputDebugStringW(L
"CKsProxy::Register : NotImplemented\n");
2877 CKsProxy::Unregister()
2879 OutputDebugStringW(L
"CKsProxy::Unregister : NotImplemented\n");
2885 CKsProxy_Constructor(
2886 IUnknown
* pUnkOuter
,
2892 StringFromCLSID(riid
, &pstr
);
2893 swprintf(Buffer
, L
"CKsProxy_Constructor pUnkOuter %p riid %s\n", pUnkOuter
, pstr
);
2894 OutputDebugStringW(Buffer
);
2896 CKsProxy
* handler
= new CKsProxy();
2899 return E_OUTOFMEMORY
;
2901 if (FAILED(handler
->QueryInterface(riid
, ppv
)))
2905 return E_NOINTERFACE
;