1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
|
//*@@@+++@@@@******************************************************************
//
// Microsoft Windows Media Foundation
// Copyright (C) Microsoft Corporation. All rights reserved.
//
//*@@@---@@@@******************************************************************
//
#pragma once
#include "common.h"
#include "mftpeventgenerator.h"
#include "basepin.h"
#include "custompin.h"
#include "multipinmfthelpers.h"
//
// The Below GUID is needed to transfer photoconfirmation sample successfully in the pipeline
// It is used to propagate the mediatype of the sample to the pipeline which will consume the sample
// This attribute is known to the OS, but not publicly defined.
//
DEFINE_GUID(MFSourceReader_SampleAttribute_MediaType_priv,
0x0ea5c1e8, 0x9845, 0x41e0, 0xa2, 0x43, 0x72, 0x32, 0x07, 0xfc, 0x78, 0x1f);
interface IDirect3DDeviceManager9;
//
// Forward declarations
//
class CMFAttributes;
class CPinCreationFactory;
//
// CMultipinMft class:
// Implements a device proxy MFT.
//
class CMultipinMft :
public IMFDeviceTransform
#if defined (MF_DEVICEMFT_ALLOW_MFT0_LOAD) && defined (MFT_UNIQUE_METHOD_NAMES)
, public IMFTransform
#endif
, public IMFShutdown
, public CMediaEventGenerator
, public IMFRealTimeClientEx
, public IKsControl
#if defined (MF_DEVICEMFT_PHTOTOCONFIRMATION)
, public IMFCapturePhotoConfirmation
, public IMFGetService
#endif
, public CDMFTModuleLifeTimeManager
#if ((defined NTDDI_WIN10_VB) && (NTDDI_VERSION >= NTDDI_WIN10_VB))
, public IMFSampleAllocatorControl
#endif
{
friend class CPinCreationFactory;
public:
CMultipinMft(
void );
virtual ~CMultipinMft();
//
// IUnknown
//
STDMETHOD_(ULONG, AddRef)(
void );
STDMETHOD_(ULONG, Release)(
void );
STDMETHOD(QueryInterface)(
_In_ REFIID iid,
_COM_Outptr_ void** ppv);
//
// IMFDeviceTransform functions
//
STDMETHOD(GetStreamCount)(
_Inout_ DWORD *pdwInputStreams,
_Inout_ DWORD *pdwOutputStreams);
STDMETHOD(GetStreamIDs)(
_In_ DWORD dwInputIDArraySize,
_When_(dwInputIDArraySize >= m_InputPinCount, _Out_writes_(dwInputIDArraySize)) DWORD* pdwInputIDs,
_In_ DWORD dwOutputIDArraySize,
_When_(dwOutputIDArraySize >= m_OutputPinCount && (pdwInputIDs && (dwInputIDArraySize > 0)),
_Out_writes_(dwOutputIDArraySize)) _On_failure_(_Valid_) DWORD* pdwOutputIDs
);
STDMETHOD(GetInputStreamAttributes)(
_In_ DWORD dwInputStreamID,
_COM_Outptr_result_maybenull_ IMFAttributes** ppAttributes);
STDMETHOD(GetOutputStreamAttributes)(
_In_ DWORD dwOutputStreamID,
_Out_ IMFAttributes** ppAttributes);
STDMETHOD(GetInputAvailableType)(
_In_ DWORD dwInputStreamID,
_In_ DWORD dwTypeIndex,
_Out_ IMFMediaType** ppType);
STDMETHOD(GetOutputAvailableType)(
_In_ DWORD dwOutputStreamID,
_In_ DWORD dwTypeIndex,
_Out_ IMFMediaType** ppMediaType);
STDMETHOD(GetInputCurrentType)(
_In_ DWORD dwInputStreamID,
_COM_Outptr_result_maybenull_ IMFMediaType** ppMediaType);
STDMETHOD(GetOutputCurrentType)(
_In_ DWORD dwOutputStreamID,
_Out_ IMFMediaType** ppMediaType);
STDMETHOD(ProcessMessage)(
_In_ MFT_MESSAGE_TYPE eMessage,
_In_ ULONG_PTR ulParam );
STDMETHOD(ProcessEvent)(
_In_ DWORD dwInputStreamID,
_In_ IMFMediaEvent *pEvent);
STDMETHOD(ProcessInput)(
_In_ DWORD dwInputStreamID,
_In_ IMFSample* pSample,
_In_ DWORD dwFlags );
STDMETHOD(ProcessOutput)(
_In_ DWORD dwFlags,
_In_ DWORD cOutputBufferCount,
_Inout_updates_(cOutputBufferCount) MFT_OUTPUT_DATA_BUFFER *pOutputSamples,
_Out_ DWORD *pdwStatus );
//
// IMFRealTimeClientEx
//
STDMETHOD(RegisterThreadsEx)(
_Inout_ DWORD* pdwTaskIndex,
_In_ LPCWSTR wszClassName,
_In_ LONG lBasePriority )
{
UNREFERENCED_PARAMETER(pdwTaskIndex);
UNREFERENCED_PARAMETER(wszClassName);
UNREFERENCED_PARAMETER(lBasePriority);
return S_OK;
}
STDMETHOD(UnregisterThreads)()
{
return S_OK;
}
STDMETHOD(SetWorkQueueEx)(
_In_ DWORD dwWorkQueueId,
_In_ LONG lWorkItemBasePriority );
//
// IMFShutdown
//
STDMETHOD(Shutdown)(
void );
STDMETHOD(GetShutdownStatus)(
MFSHUTDOWN_STATUS *pStatus)
{
UNREFERENCED_PARAMETER(pStatus);
return(m_eShutdownStatus);
};
//
// IMFDeviceTransform function declarations
//
STDMETHODIMP InitializeTransform(
_In_ IMFAttributes *pAttributes );
_Requires_no_locks_held_
STDMETHODIMP SetInputStreamState(
_In_ DWORD dwStreamID,
_In_ IMFMediaType *pMediaType,
_In_ DeviceStreamState value,
_In_ DWORD dwFlags );
STDMETHODIMP GetInputStreamState(
_In_ DWORD dwStreamID,
_Out_ DeviceStreamState *value );
STDMETHODIMP SetOutputStreamState(
_In_ DWORD dwStreamID,
_In_ IMFMediaType *pMediaType,
_In_ DeviceStreamState value,
_In_ DWORD dwFlags );
STDMETHODIMP GetOutputStreamState(
_In_ DWORD dwStreamID,
_Out_ DeviceStreamState *value );
STDMETHODIMP GetInputStreamPreferredState(
_In_ DWORD dwStreamID,
_Inout_ DeviceStreamState *value,
_Outptr_opt_result_maybenull_ IMFMediaType **ppMediaType );
STDMETHODIMP FlushInputStream(
_In_ DWORD dwStreamIndex,
_In_ DWORD dwFlags );
STDMETHODIMP FlushOutputStream(
_In_ DWORD dwStreamIndex,
_In_ DWORD dwFlags );
STDMETHODIMP_(VOID) FlushAllStreams(
VOID
);
//
//IKSControl Inferface function declarations
//
STDMETHOD(KsEvent)(
_In_reads_bytes_(ulEventLength) PKSEVENT pEvent,
_In_ ULONG ulEventLength,
_Inout_updates_bytes_opt_(ulDataLength) LPVOID pEventData,
_In_ ULONG ulDataLength,
_Inout_ ULONG* pBytesReturned
);
STDMETHOD(KsProperty)(
_In_reads_bytes_(ulPropertyLength) PKSPROPERTY pProperty,
_In_ ULONG ulPropertyLength,
_Inout_updates_bytes_(ulDataLength) LPVOID pPropertyData,
_In_ ULONG ulDataLength,
_Inout_ ULONG* pBytesReturned
);
STDMETHOD(KsMethod)(
_In_reads_bytes_(ulPropertyLength) PKSMETHOD pProperty,
_In_ ULONG ulPropertyLength,
_Inout_updates_bytes_(ulDataLength) LPVOID pPropertyData,
_In_ ULONG ulDataLength,
_Inout_ ULONG* pBytesReturned
);
#if defined (MF_DEVICEMFT_PHTOTOCONFIRMATION)
//
// The Below functions are needed for photoconfirmation
//
//
STDMETHOD(GetService)(
__in REFGUID guidService,
__in REFIID riid,
__deref_out LPVOID* ppvObject
);
//
//IMFCapturePhotoConfirmation Inferface function declarations
//
STDMETHOD(SetPhotoConfirmationCallback)(
_In_ IMFAsyncCallback* pNotificationCallback
);
STDMETHOD(SetPixelFormat)(
_In_ GUID subtype
);
STDMETHOD(GetPixelFormat)(
_Out_ GUID* subtype
);
__inline BOOL IsPhotoConfirmationEnabled()
{
return (m_spPhotoConfirmationCallback != nullptr);
}
STDMETHODIMP ProcessCapturePhotoConfirmationCallBack(
_In_ IMFMediaType* pMediaType,
_In_ IMFSample* pSample
);
__inline VOID SetPhotoConfirmationCallBack(_In_ IMFAsyncCallback *Callback)
{
m_spPhotoConfirmationCallback = Callback;
}
#endif
#if ((defined NTDDI_WIN10_VB) && (NTDDI_VERSION >= NTDDI_WIN10_VB))
//
// IMFSampleAllocatorControl Inferface function declarations
//
STDMETHOD(SetDefaultAllocator)(
_In_ DWORD dwOutputStreamID,
_In_ IUnknown *pAllocator
);
STDMETHOD(GetAllocatorUsage)(
_In_ DWORD dwOutputStreamID,
_Out_ DWORD* pdwInputStreamID,
_Out_ MFSampleAllocatorUsage* peUsage
);
#endif
static STDMETHODIMP CreateInstance(
REFIID iid, void **ppMFT);
__inline BOOL isPhotoModePhotoSequence()
{
return m_PhotoModeIsPhotoSequence;
}
_inline DWORD GetQueueId()
{
return m_dwWorkQueueId;
}
//
//Will be used from Pins to get the D3D manager once set!!!
//
__inline STDMETHODIMP_(VOID) GetD3DDeviceManager(
IUnknown** ppDeviceManagerUnk
)
{
m_spDeviceManagerUnk.CopyTo( ppDeviceManagerUnk );
}
HRESULT SendEventToManager(
_In_ MediaEventType,
_In_ REFGUID,
_In_ UINT32
);
protected:
//
//Helper functions
//
HRESULT SetStreamingStateCustomPins(
_In_ DeviceStreamState
);
CInPin* GetInPin(
_In_ DWORD dwStreamID
);
COutPin* GetOutPin(
_In_ DWORD dwStreamID
);
HRESULT GetConnectedInpin(_In_ ULONG ulOutpin, _Out_ ULONG &ulInPin);
__requires_lock_held(m_critSec)
HRESULT ChangeMediaTypeEx(
_In_ ULONG pinId,
_In_opt_ IMFMediaType *pMediaType,
_In_ DeviceStreamState newState
);
HRESULT BridgeInputPinOutputPin(
_In_ CInPin* pInPin,
_In_ COutPin* pOutPin);
#if defined (MF_DEVICEMFT_WARMSTART_HANDLING)
HRESULT CMultipinMft::WarmStartHandler(
_In_ PKSPROPERTY Property,
_In_ ULONG ulPropertyLength,
_In_ LPVOID pData,
_In_ ULONG ulOutputBufferLength,
_Inout_ PULONG pulBytesReturned
);
#endif
#if defined (MF_DEVICEMFT_ALLOW_MFT0_LOAD) && defined (MFT_UNIQUE_METHOD_NAMES)
STDMETHODIMP CMultipinMft::GetAttributes(
_COM_Outptr_opt_result_maybenull_ IMFAttributes** ppAttributes
);
#endif
#if (defined (MF_DEVICEMFT_ALLOW_MFT0_LOAD) && defined (MFT_UNIQUE_METHOD_NAMES))
_DEFINE_DEVICEMFT_MFT0HELPER_IMPL__
#endif
//
//Inline functions
//
__inline IMFDeviceTransform* Parent()
{
return m_spSourceTransform.Get();
}
__inline VOID SetStreamingState(DeviceStreamState state)
{
InterlockedExchange((LONG*)&m_StreamingState, state);
}
__inline DeviceStreamState GetStreamingState()
{
return (DeviceStreamState)InterlockedCompareExchange((LONG*)&m_StreamingState, 0L, 0L);
}
__inline BOOL IsStreaming()
{
return (InterlockedCompareExchange((LONG*)&m_StreamingState, DeviceStreamState_Run, DeviceStreamState_Run) == DeviceStreamState_Run);
}
private:
ULONG m_InputPinCount;
ULONG m_OutputPinCount;
ULONG m_CustomPinCount;
DeviceStreamState m_StreamingState;
CBasePinArray m_OutPins;
CBasePinArray m_InPins;
BOOL m_PhotoModeIsPhotoSequence; // used to store if the filter is in photo sequence or not
long m_nRefCount; // Reference count
CCritSec m_critSec; // Control lock.. taken only durign state change operations
ComPtr <IUnknown> m_spDeviceManagerUnk; // D3D Manager set, when MFT_MESSAGE_SET_D3D_MANAGER is called through ProcessMessage
ComPtr<IMFDeviceTransform> m_spSourceTransform; // The sources transform. This is the pipeline DevProxy
MFSHUTDOWN_STATUS m_eShutdownStatus;
DWORD m_dwWorkQueueId;
LONG m_lWorkQueuePriority;
UINT32 m_punValue;
ComPtr<IKsControl> m_spIkscontrol;
ComPtr<IMFAttributes> m_spAttributes;
map<int, int> m_outputPinMap; // How output pins are connected to input pins i-><0..outpins>
CDMFTEventHandler m_eventHandler;
PWCHAR m_SymbolicLink;
#if defined (MF_DEVICEMFT_PHTOTOCONFIRMATION)
ComPtr<IMFAsyncCallback> m_spPhotoConfirmationCallback; //Photo Confirmation related definitions
GUID m_guidPhotoConfirmationSubtype;
BOOL m_firePhotoConfirmation;
#endif
#if defined (MF_DEVICEMFT_WARMSTART_HANDLING)
VOID SetWarmStart(DWORD dwPinId, BOOL state)
{
m_dwWarmStartMask ^= (-state ^ m_dwWarmStartMask) & (1UL << dwPinId);
}
BOOLEAN GetWarmStart(_In_ DWORD dwPinId)
{
return ((m_dwWarmStartMask >> dwPinId) & 1UL);
}
DWORD m_dwWarmStartMask;
#endif
};
inline HRESULT MFT_CreateInstance(REFIID riid, void **ppv)
{
return CMultipinMft::CreateInstance(riid, ppv);
}
|