-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmfapi.h
4603 lines (3717 loc) · 176 KB
/
mfapi.h
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
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <winapifamily.h>
//*@@@+++@@@@******************************************************************
//
// Microsoft Windows Media Foundation
// Copyright (C) Microsoft Corporation. All rights reserved.
//
//*@@@---@@@@******************************************************************
//
//
// MFAPI.h is the header containing the APIs for using the MF platform.
//
#pragma once
#if !defined(__MFAPI_H__)
#define __MFAPI_H__
#pragma pack(push, mfhrds)
#include <mfobjects.h>
#pragma pack(pop, mfhrds)
#include "mmreg.h"
#include <avrt.h>
#ifndef AVRT_DATA
#define AVRT_DATA
#endif
#ifndef AVRT_BSS
#define AVRT_BSS
#endif
#if !defined(MF_VERSION)
#if (WINVER >= _WIN32_WINNT_WIN7)
#define MF_SDK_VERSION 0x0002
#else // Vista
#define MF_SDK_VERSION 0x0001
#endif // (WINVER >= _WIN32_WINNT_WIN7)
#define MF_API_VERSION 0x0070 // This value is unused in the Win7 release and left at its Vista release value
#define MF_VERSION (MF_SDK_VERSION << 16 | MF_API_VERSION)
#endif //!defined(MF_VERSION)
#define MFSTARTUP_NOSOCKET 0x1
#define MFSTARTUP_LITE (MFSTARTUP_NOSOCKET)
#define MFSTARTUP_FULL 0
#if defined(__cplusplus)
extern "C" {
#endif
////////////////////////////////////////////////////////////////////////////////
/////////////////////////////// Startup/Shutdown ////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
// Initializes the platform object.
// Must be called before using Media Foundation.
// A matching MFShutdown call must be made when the application is done using
// Media Foundation.
// The "Version" parameter should be set to MF_API_VERSION.
// Application should not call MFStartup / MFShutdown from workqueue threads
//
#if defined(__cplusplus)
#pragma region Application Family
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_GAMES)
STDAPI MFStartup( ULONG Version, DWORD dwFlags = MFSTARTUP_FULL );
#endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_GAMES) */
#pragma endregion
#else
#pragma region Application Family
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_GAMES)
STDAPI MFStartup( ULONG Version, DWORD dwFlags );
#endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_GAMES) */
#pragma endregion
#endif
#pragma region Application Family
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_GAMES)
//
// Shuts down the platform object.
// Releases all resources including threads.
// Application should call MFShutdown the same number of times as MFStartup
// Application should not call MFStartup / MFShutdown from workqueue threads
//
STDAPI MFShutdown();
////////////////////////////////////////////////////////////////////////////////
///////////////////////////////// Platform ///////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
// These functions can be used to keep the MF platform object in place.
// Every call to MFLockPlatform should have a matching call to MFUnlockPlatform
//
STDAPI MFLockPlatform();
STDAPI MFUnlockPlatform();
///////////////////////////////////////////////////////////////////////////////
//
// MF workitem functions
//
typedef unsigned __int64 MFWORKITEM_KEY;
#endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_GAMES) */
#pragma endregion
#pragma region Desktop Family
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_GAMES)
STDAPI MFPutWorkItem(
DWORD dwQueue,
IMFAsyncCallback * pCallback,
IUnknown * pState);
#endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_GAMES) */
#pragma endregion
#pragma region Application Family
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_GAMES)
STDAPI MFPutWorkItem2(
DWORD dwQueue,
LONG Priority,
_In_ IMFAsyncCallback * pCallback,
_In_opt_ IUnknown * pState);
#endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_GAMES) */
#pragma endregion
#pragma region Desktop Family
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_GAMES)
STDAPI MFPutWorkItemEx(
DWORD dwQueue,
IMFAsyncResult * pResult);
#endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_GAMES) */
#pragma endregion
#pragma region Application Family
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_GAMES)
STDAPI MFPutWorkItemEx2(
DWORD dwQueue,
LONG Priority,
_In_ IMFAsyncResult * pResult);
STDAPI MFPutWaitingWorkItem (
HANDLE hEvent,
LONG Priority,
_In_ IMFAsyncResult * pResult,
_Out_opt_ MFWORKITEM_KEY * pKey
);
STDAPI MFAllocateSerialWorkQueue (
_In_ DWORD dwWorkQueue,
_Out_ OUT DWORD * pdwWorkQueue);
STDAPI MFScheduleWorkItemEx(
IMFAsyncResult * pResult,
INT64 Timeout,
_Out_opt_ MFWORKITEM_KEY * pKey);
#endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_GAMES) */
#pragma endregion
#pragma region Desktop Family
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_GAMES)
STDAPI MFScheduleWorkItem(
IMFAsyncCallback * pCallback,
IUnknown * pState,
INT64 Timeout,
_Out_opt_ MFWORKITEM_KEY * pKey);
//
// The CancelWorkItem method is used by objects to cancel scheduled operation
// Due to asynchronous nature of timers, application might still get a
// timer callback after MFCancelWorkItem has returned.
//
#endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_GAMES) */
#pragma endregion
#pragma region Application Family
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_GAMES)
STDAPI MFCancelWorkItem(
MFWORKITEM_KEY Key);
#endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_GAMES) */
#pragma endregion
#pragma region Desktop Family
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_GAMES)
///////////////////////////////////////////////////////////////////////////////
//
// MF periodic callbacks
//
STDAPI MFGetTimerPeriodicity(
_Out_ DWORD * Periodicity);
typedef void (*MFPERIODICCALLBACK)(IUnknown* pContext);
STDAPI MFAddPeriodicCallback(
MFPERIODICCALLBACK Callback,
IUnknown * pContext,
_Out_opt_ DWORD * pdwKey);
STDAPI MFRemovePeriodicCallback(
DWORD dwKey);
///////////////////////////////////////////////////////////////////////////////
//
// MF work queues
//
#if (WINVER >= _WIN32_WINNT_WIN7)
//
// MFASYNC_WORKQUEUE_TYPE: types of work queue used by MFAllocateWorkQueueEx
//
typedef enum
{
// MF_STANDARD_WORKQUEUE: Work queue in a thread without Window
// message loop.
MF_STANDARD_WORKQUEUE = 0,
// MF_WINDOW_WORKQUEUE: Work queue in a thread running Window
// Message loop that calls PeekMessage() / DispatchMessage()..
MF_WINDOW_WORKQUEUE = 1,
//
//
MF_MULTITHREADED_WORKQUEUE = 2, // common MT threadpool
} MFASYNC_WORKQUEUE_TYPE;
STDAPI MFAllocateWorkQueueEx(
_In_ MFASYNC_WORKQUEUE_TYPE WorkQueueType,
_Out_ OUT DWORD * pdwWorkQueue);
#endif // (WINVER >= _WIN32_WINNT_WIN7)
//
// Allocate a standard work queue. the behaviour is the same with:
// MFAllocateWorkQueueEx( MF_STANDARD_WORKQUEUE, pdwWorkQueue )
//
STDAPI MFAllocateWorkQueue(
_Out_ OUT DWORD * pdwWorkQueue);
#endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_GAMES) */
#pragma endregion
#pragma region Application Family
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_GAMES)
STDAPI MFLockWorkQueue(
_In_ DWORD dwWorkQueue);
STDAPI MFUnlockWorkQueue(
_In_ DWORD dwWorkQueue);
#endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_GAMES) */
#pragma endregion
#pragma region Desktop Family
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_GAMES)
STDAPI MFBeginRegisterWorkQueueWithMMCSS(
DWORD dwWorkQueueId,
_In_ LPCWSTR wszClass,
DWORD dwTaskId,
_In_ IMFAsyncCallback * pDoneCallback,
_In_ IUnknown * pDoneState );
STDAPI MFBeginRegisterWorkQueueWithMMCSSEx(
DWORD dwWorkQueueId,
_In_ LPCWSTR wszClass,
DWORD dwTaskId,
LONG lPriority,
_In_ IMFAsyncCallback * pDoneCallback,
_In_ IUnknown * pDoneState );
STDAPI MFEndRegisterWorkQueueWithMMCSS(
_In_ IMFAsyncResult * pResult,
_Out_ DWORD * pdwTaskId );
STDAPI MFBeginUnregisterWorkQueueWithMMCSS(
DWORD dwWorkQueueId,
_In_ IMFAsyncCallback * pDoneCallback,
_In_ IUnknown * pDoneState );
STDAPI MFEndUnregisterWorkQueueWithMMCSS(
_In_ IMFAsyncResult * pResult );
STDAPI MFGetWorkQueueMMCSSClass(
DWORD dwWorkQueueId,
_Out_writes_to_opt_(*pcchClass,*pcchClass) LPWSTR pwszClass,
_Inout_ DWORD *pcchClass );
STDAPI MFGetWorkQueueMMCSSTaskId(
DWORD dwWorkQueueId,
_Out_ LPDWORD pdwTaskId );
STDAPI MFRegisterPlatformWithMMCSS(
_In_ PCWSTR wszClass,
_Inout_ DWORD* pdwTaskId,
_In_ LONG lPriority );
STDAPI MFUnregisterPlatformFromMMCSS();
#endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_GAMES) */
#pragma endregion
#pragma region Application Family
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_GAMES)
STDAPI MFLockSharedWorkQueue(
_In_ PCWSTR wszClass,
_In_ LONG BasePriority,
_Inout_ DWORD* pdwTaskId,
_Out_ DWORD* pID );
#endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_GAMES) */
#pragma endregion
#pragma region Desktop Family
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_GAMES)
STDAPI MFGetWorkQueueMMCSSPriority(
DWORD dwWorkQueueId,
_Out_ LONG* lPriority );
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////// Async Model //////////////////////////////
///////////////////////////////////////////////////////////////////////////////
//
// Instantiates the MF-provided Async Result implementation
//
#endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_GAMES) */
#pragma endregion
#pragma region Application Family
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_GAMES)
STDAPI MFCreateAsyncResult(
IUnknown * punkObject,
IMFAsyncCallback * pCallback,
IUnknown * punkState,
_Out_ IMFAsyncResult ** ppAsyncResult );
//
// Helper for calling IMFAsyncCallback::Invoke
//
STDAPI MFInvokeCallback(
IMFAsyncResult * pAsyncResult );
//
// MFASYNCRESULT struct.
// Any implementation of IMFAsyncResult must inherit from this struct;
// the Media Foundation workqueue implementation depends on this.
//
#if defined(__cplusplus) && !defined(CINTERFACE)
typedef struct tagMFASYNCRESULT : public IMFAsyncResult
{
OVERLAPPED overlapped;
IMFAsyncCallback * pCallback;
HRESULT hrStatusResult;
DWORD dwBytesTransferred;
HANDLE hEvent;
} MFASYNCRESULT;
#else /* C style interface */
typedef struct tagMFASYNCRESULT
{
IMFAsyncResult AsyncResult;
OVERLAPPED overlapped;
IMFAsyncCallback * pCallback;
HRESULT hrStatusResult;
DWORD dwBytesTransferred;
HANDLE hEvent;
} MFASYNCRESULT;
#endif /* C style interface */
#endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_GAMES) */
#pragma endregion
#pragma region Desktop Family
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_GAMES)
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////// Files //////////////////////////////
///////////////////////////////////////////////////////////////////////////////
//
// Regardless of the access mode with which the file is opened, the sharing
// permissions will allow shared reading and deleting.
//
STDAPI MFCreateFile(
MF_FILE_ACCESSMODE AccessMode,
MF_FILE_OPENMODE OpenMode,
MF_FILE_FLAGS fFlags,
LPCWSTR pwszFileURL,
_Out_ IMFByteStream **ppIByteStream );
STDAPI MFCreateTempFile(
MF_FILE_ACCESSMODE AccessMode,
MF_FILE_OPENMODE OpenMode,
MF_FILE_FLAGS fFlags,
_Out_ IMFByteStream **ppIByteStream );
STDAPI MFBeginCreateFile(
MF_FILE_ACCESSMODE AccessMode,
MF_FILE_OPENMODE OpenMode,
MF_FILE_FLAGS fFlags,
LPCWSTR pwszFilePath,
IMFAsyncCallback * pCallback,
IUnknown * pState,
_Out_ IUnknown ** ppCancelCookie);
STDAPI MFEndCreateFile(
IMFAsyncResult * pResult,
_Out_ IMFByteStream **ppFile );
STDAPI MFCancelCreateFile(
IUnknown * pCancelCookie);
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////// Buffers //////////////////////////////
///////////////////////////////////////////////////////////////////////////////
//
// Creates an IMFMediaBuffer in memory
//
#endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_GAMES) */
#pragma endregion
#pragma region Application Family
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_GAMES)
STDAPI MFCreateMemoryBuffer(
_In_ DWORD cbMaxLength,
_Out_ IMFMediaBuffer ** ppBuffer );
//
// Creates an IMFMediaBuffer wrapper at the given offset and length
// within an existing IMFMediaBuffer
//
STDAPI MFCreateMediaBufferWrapper(
_In_ IMFMediaBuffer * pBuffer,
_In_ DWORD cbOffset,
_In_ DWORD dwLength,
_Out_ IMFMediaBuffer ** ppBuffer );
#endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_GAMES) */
#pragma endregion
#pragma region Desktop Family
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_GAMES)
//
// Creates a legacy buffer (IMediaBuffer) wrapper at the given offset within
// an existing IMFMediaBuffer.
// pSample is optional. It can point to the original IMFSample from which this
// IMFMediaBuffer came. If provided, then *ppMediaBuffer will succeed
// QueryInterface for IID_IMFSample, from which the original sample's attributes
// can be obtained
//
STDAPI MFCreateLegacyMediaBufferOnMFMediaBuffer(
_In_opt_ IMFSample * pSample,
_In_ IMFMediaBuffer * pMFMediaBuffer,
_In_ DWORD cbOffset,
_Outptr_ IMediaBuffer ** ppMediaBuffer );
//
// Create a DirectX surface buffer
//
#include <dxgiformat.h>
STDAPI_(DXGI_FORMAT) MFMapDX9FormatToDXGIFormat( _In_ DWORD dx9 );
STDAPI_(DWORD) MFMapDXGIFormatToDX9Format( _In_ DXGI_FORMAT dx11 );
#endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_GAMES) */
#pragma endregion
#pragma region Application Family
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_GAMES)
STDAPI MFLockDXGIDeviceManager(
_Out_opt_ UINT* pResetToken,
_Outptr_ IMFDXGIDeviceManager** ppManager
);
STDAPI MFUnlockDXGIDeviceManager();
#endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_GAMES) */
#pragma endregion
#pragma region Desktop Family
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_GAMES)
STDAPI MFCreateDXSurfaceBuffer(
_In_ REFIID riid,
_In_ IUnknown * punkSurface,
_In_ BOOL fBottomUpWhenLinear,
_Outptr_ IMFMediaBuffer ** ppBuffer );
STDAPI MFCreateWICBitmapBuffer(
_In_ REFIID riid,
_In_ IUnknown * punkSurface,
_Outptr_ IMFMediaBuffer ** ppBuffer
);
#endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_GAMES) */
#pragma endregion
#pragma region Application Family
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_GAMES)
STDAPI
MFCreateDXGISurfaceBuffer(
_In_ REFIID riid,
_In_ IUnknown* punkSurface,
_In_ UINT uSubresourceIndex,
_In_ BOOL fBottomUpWhenLinear,
_Outptr_ IMFMediaBuffer** ppBuffer
);
STDAPI MFCreateVideoSampleAllocatorEx(
_In_ REFIID riid,
_Outptr_ void** ppSampleAllocator
);
STDAPI
MFCreateDXGIDeviceManager(
_Out_ UINT* resetToken,
_Outptr_ IMFDXGIDeviceManager** ppDeviceManager
);
#define MF_E_DXGI_DEVICE_NOT_INITIALIZED ((HRESULT)0x80041000L) // DXVA2_E_NOT_INITIALIZED
#define MF_E_DXGI_NEW_VIDEO_DEVICE ((HRESULT)0x80041001L) // DXVA2_E_NEW_VIDEO_DEVICE
#define MF_E_DXGI_VIDEO_DEVICE_LOCKED ((HRESULT)0x80041002L) // DXVA2_E_VIDEO_DEVICE_LOCKED
//
// Create an aligned memory buffer.
// The following constants were chosen for parity with the alignment constants
// in ntioapi.h
//
#define MF_1_BYTE_ALIGNMENT 0x00000000
#define MF_2_BYTE_ALIGNMENT 0x00000001
#define MF_4_BYTE_ALIGNMENT 0x00000003
#define MF_8_BYTE_ALIGNMENT 0x00000007
#define MF_16_BYTE_ALIGNMENT 0x0000000f
#define MF_32_BYTE_ALIGNMENT 0x0000001f
#define MF_64_BYTE_ALIGNMENT 0x0000003f
#define MF_128_BYTE_ALIGNMENT 0x0000007f
#define MF_256_BYTE_ALIGNMENT 0x000000ff
#define MF_512_BYTE_ALIGNMENT 0x000001ff
#define MF_1024_BYTE_ALIGNMENT 0x000003ff
#define MF_2048_BYTE_ALIGNMENT 0x000007ff
#define MF_4096_BYTE_ALIGNMENT 0x00000fff
#define MF_8192_BYTE_ALIGNMENT 0x00001fff
STDAPI MFCreateAlignedMemoryBuffer(
_In_ DWORD cbMaxLength,
_In_ DWORD cbAligment,
_Out_ IMFMediaBuffer ** ppBuffer );
#endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_GAMES) */
#pragma endregion
#pragma region Desktop Family
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_GAMES)
//
// This GUID is used in IMFGetService::GetService calls to retrieve
// interfaces from the buffer. Its value is defined in evr.h
//
EXTERN_C const GUID MR_BUFFER_SERVICE;
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////// Events //////////////////////////////
///////////////////////////////////////////////////////////////////////////////
//
// Instantiates the MF-provided Media Event implementation.
//
#endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_GAMES) */
#pragma endregion
#pragma region Application Family
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_GAMES)
STDAPI MFCreateMediaEvent(
_In_ MediaEventType met,
_In_ REFGUID guidExtendedType,
_In_ HRESULT hrStatus,
_In_opt_ const PROPVARIANT * pvValue,
_Out_ IMFMediaEvent ** ppEvent );
//
// Instantiates an object that implements IMFMediaEventQueue.
// Components that provide an IMFMediaEventGenerator can use this object
// internally to do their Media Event Generator work for them.
// IMFMediaEventGenerator calls should be forwarded to the similar call
// on this object's IMFMediaEventQueue interface (e.g. BeginGetEvent,
// EndGetEvent), and the various IMFMediaEventQueue::QueueEventXXX methods
// can be used to queue events that the caller will consume.
//
STDAPI MFCreateEventQueue(
_Out_ IMFMediaEventQueue **ppMediaEventQueue );
#endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_GAMES) */
#pragma endregion
#pragma region Desktop Family
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_GAMES)
#ifdef INITGUID
#define DEFINE_GUID2(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
EXTERN_C const GUID name __attribute__((section(".rdata"))) = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } }
#else
#define DEFINE_GUID2(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
EXTERN_C const GUID FAR name
#endif
//
// Event attributes
// Some of the common Media Foundation events have associated attributes
// that go in their IMFAttributes stores
//
//
// MESessionCapabilitiesChanged attributes
//
// MF_EVENT_SESSIONCAPS {7E5EBCD0-11B8-4abe-AFAD-10F6599A7F42}
// Type: UINT32
DEFINE_GUID2(MF_EVENT_SESSIONCAPS,
0x7e5ebcd0, 0x11b8, 0x4abe, 0xaf, 0xad, 0x10, 0xf6, 0x59, 0x9a, 0x7f, 0x42);
// MF_EVENT_SESSIONCAPS_DELTA {7E5EBCD1-11B8-4abe-AFAD-10F6599A7F42}
// Type: UINT32
DEFINE_GUID2(MF_EVENT_SESSIONCAPS_DELTA,
0x7e5ebcd1, 0x11b8, 0x4abe, 0xaf, 0xad, 0x10, 0xf6, 0x59, 0x9a, 0x7f, 0x42);
// Session capabilities bitflags
#define MFSESSIONCAP_START 0x00000001
#define MFSESSIONCAP_SEEK 0x00000002
#define MFSESSIONCAP_PAUSE 0x00000004
#define MFSESSIONCAP_RATE_FORWARD 0x00000010
#define MFSESSIONCAP_RATE_REVERSE 0x00000020
#define MFSESSIONCAP_DOES_NOT_USE_NETWORK 0x00000040
//
// MESessionTopologyStatus attributes
//
// Possible values for MF_EVENT_TOPOLOGY_STATUS attribute.
//
// For a given topology, these status values will arrive via
// MESessionTopologyStatus in the order below.
//
// However, there are no guarantees about how these status values will be
// ordered between two consecutive topologies. For example,
// MF_TOPOSTATUS_READY could arrive for topology n+1 before
// MF_TOPOSTATUS_ENDED arrives for topology n if the application called
// IMFMediaSession::SetTopology for topology n+1 well enough in advance of the
// end of topology n. Conversely, if topology n ends before the application
// calls IMFMediaSession::SetTopology for topology n+1, then
// MF_TOPOSTATUS_ENDED will arrive for topology n before MF_TOPOSTATUS_READY
// arrives for topology n+1.
typedef enum
{
// MF_TOPOSTATUS_INVALID: Invalid value; will not be sent
MF_TOPOSTATUS_INVALID = 0,
// MF_TOPOSTATUS_READY: The topology has been put in place and is
// ready to start. All GetService calls to the Media Session will use
// this topology.
MF_TOPOSTATUS_READY = 100,
// MF_TOPOSTATUS_STARTED_SOURCE: The Media Session has started to read
// and process data from the Media Source(s) in this topology.
MF_TOPOSTATUS_STARTED_SOURCE = 200,
#if (WINVER >= _WIN32_WINNT_WIN7)
// MF_TOPOSTATUS_DYNAMIC_CHANGED: The topology has been dynamic changed
// due to the format change.
MF_TOPOSTATUS_DYNAMIC_CHANGED = 210,
#endif // (WINVER >= _WIN32_WINNT_WIN7)
// MF_TOPOSTATUS_SINK_SWITCHED: The Media Sinks in the pipeline have
// switched from a previous topology to this topology.
// Note that this status does not get sent for the first topology;
// applications can assume that the sinks are playing the first
// topology when they receive MESessionStarted.
MF_TOPOSTATUS_SINK_SWITCHED = 300,
// MF_TOPOSTATUS_ENDED: Playback of this topology is complete.
// Before deleting this topology, however, the application should wait
// for either MESessionEnded or the MF_TOPOSTATUS_STARTED_SOURCE status
// on the next topology to ensure that the Media Session is no longer
// using this topology.
MF_TOPOSTATUS_ENDED = 400,
} MF_TOPOSTATUS;
// MF_EVENT_TOPOLOGY_STATUS {30C5018D-9A53-454b-AD9E-6D5F8FA7C43B}
// Type: UINT32 {MF_TOPOLOGY_STATUS}
DEFINE_GUID2(MF_EVENT_TOPOLOGY_STATUS,
0x30c5018d, 0x9a53, 0x454b, 0xad, 0x9e, 0x6d, 0x5f, 0x8f, 0xa7, 0xc4, 0x3b);
//
// MESessionNotifyPresentationTime attributes
//
// MF_EVENT_START_PRESENTATION_TIME {5AD914D0-9B45-4a8d-A2C0-81D1E50BFB07}
// Type: UINT64
DEFINE_GUID2(MF_EVENT_START_PRESENTATION_TIME,
0x5ad914d0, 0x9b45, 0x4a8d, 0xa2, 0xc0, 0x81, 0xd1, 0xe5, 0xb, 0xfb, 0x7);
// MF_EVENT_PRESENTATION_TIME_OFFSET {5AD914D1-9B45-4a8d-A2C0-81D1E50BFB07}
// Type: UINT64
DEFINE_GUID2(MF_EVENT_PRESENTATION_TIME_OFFSET,
0x5ad914d1, 0x9b45, 0x4a8d, 0xa2, 0xc0, 0x81, 0xd1, 0xe5, 0xb, 0xfb, 0x7);
// MF_EVENT_START_PRESENTATION_TIME_AT_OUTPUT {5AD914D2-9B45-4a8d-A2C0-81D1E50BFB07}
// Type: UINT64
DEFINE_GUID2(MF_EVENT_START_PRESENTATION_TIME_AT_OUTPUT,
0x5ad914d2, 0x9b45, 0x4a8d, 0xa2, 0xc0, 0x81, 0xd1, 0xe5, 0xb, 0xfb, 0x7);
//
//
// MESourceStarted attributes
//
// MF_EVENT_SOURCE_FAKE_START {a8cc55a7-6b31-419f-845d-ffb351a2434b}
// Type: UINT32
DEFINE_GUID2(MF_EVENT_SOURCE_FAKE_START,
0xa8cc55a7, 0x6b31, 0x419f, 0x84, 0x5d, 0xff, 0xb3, 0x51, 0xa2, 0x43, 0x4b);
// MF_EVENT_SOURCE_PROJECTSTART {a8cc55a8-6b31-419f-845d-ffb351a2434b}
// Type: UINT64
DEFINE_GUID2(MF_EVENT_SOURCE_PROJECTSTART,
0xa8cc55a8, 0x6b31, 0x419f, 0x84, 0x5d, 0xff, 0xb3, 0x51, 0xa2, 0x43, 0x4b);
// MF_EVENT_SOURCE_ACTUAL_START {a8cc55a9-6b31-419f-845d-ffb351a2434b}
// Type: UINT64
DEFINE_GUID2(MF_EVENT_SOURCE_ACTUAL_START,
0xa8cc55a9, 0x6b31, 0x419f, 0x84, 0x5d, 0xff, 0xb3, 0x51, 0xa2, 0x43, 0x4b);
//
// MEEndOfPresentationSegment attributes
//
// MF_EVENT_SOURCE_TOPOLOGY_CANCELED {DB62F650-9A5E-4704-ACF3-563BC6A73364}
// Type: UINT32
DEFINE_GUID2(MF_EVENT_SOURCE_TOPOLOGY_CANCELED,
0xdb62f650, 0x9a5e, 0x4704, 0xac, 0xf3, 0x56, 0x3b, 0xc6, 0xa7, 0x33, 0x64);
//
// MESourceCharacteristicsChanged attributes
//
// MF_EVENT_SOURCE_CHARACTERISTICS {47DB8490-8B22-4f52-AFDA-9CE1B2D3CFA8}
// Type: UINT32
DEFINE_GUID2(MF_EVENT_SOURCE_CHARACTERISTICS,
0x47db8490, 0x8b22, 0x4f52, 0xaf, 0xda, 0x9c, 0xe1, 0xb2, 0xd3, 0xcf, 0xa8);
// MF_EVENT_SOURCE_CHARACTERISTICS_OLD {47DB8491-8B22-4f52-AFDA-9CE1B2D3CFA8}
// Type: UINT32
DEFINE_GUID2(MF_EVENT_SOURCE_CHARACTERISTICS_OLD,
0x47db8491, 0x8b22, 0x4f52, 0xaf, 0xda, 0x9c, 0xe1, 0xb2, 0xd3, 0xcf, 0xa8);
//
// MESourceRateChangeRequested attributes
//
// MF_EVENT_DO_THINNING {321EA6FB-DAD9-46e4-B31D-D2EAE7090E30}
// Type: UINT32
DEFINE_GUID2(MF_EVENT_DO_THINNING,
0x321ea6fb, 0xdad9, 0x46e4, 0xb3, 0x1d, 0xd2, 0xea, 0xe7, 0x9, 0xe, 0x30);
//
// MEStreamSinkScrubSampleComplete attributes
//
// MF_EVENT_SCRUBSAMPLE_TIME {9AC712B3-DCB8-44d5-8D0C-37455A2782E3}
// Type: UINT64
DEFINE_GUID2(MF_EVENT_SCRUBSAMPLE_TIME,
0x9ac712b3, 0xdcb8, 0x44d5, 0x8d, 0xc, 0x37, 0x45, 0x5a, 0x27, 0x82, 0xe3);
//
// MESinkInvalidated and MESessionStreamSinkFormatChanged attributes
//
// MF_EVENT_OUTPUT_NODE {830f1a8b-c060-46dd-a801-1c95dec9b107}
// Type: UINT64
DEFINE_GUID2(MF_EVENT_OUTPUT_NODE,
0x830f1a8b, 0xc060, 0x46dd, 0xa8, 0x01, 0x1c, 0x95, 0xde, 0xc9, 0xb1, 0x07);
#endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_GAMES) */
#pragma endregion
#pragma region Application Family
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_GAMES)
#if (WINVER >= _WIN32_WINNT_WIN7)
//
// METransformNeedInput attributes
//
// MF_EVENT_MFT_INPUT_STREAM_ID {F29C2CCA-7AE6-42d2-B284-BF837CC874E2}
// Type: UINT32
DEFINE_GUID2(MF_EVENT_MFT_INPUT_STREAM_ID,
0xf29c2cca, 0x7ae6, 0x42d2, 0xb2, 0x84, 0xbf, 0x83, 0x7c, 0xc8, 0x74, 0xe2);
//
// METransformDrainComplete and METransformMarker attributes
//
// MF_EVENT_MFT_CONTEXT {B7CD31F1-899E-4b41-80C9-26A896D32977}
// Type: UINT64
DEFINE_GUID2(MF_EVENT_MFT_CONTEXT,
0xb7cd31f1, 0x899e, 0x4b41, 0x80, 0xc9, 0x26, 0xa8, 0x96, 0xd3, 0x29, 0x77);
#endif // (WINVER >= _WIN32_WINNT_WIN7)
#if (WINVER >= _WIN32_WINNT_WINBLUE)
//
// MEContentProtectionMetadata attributes
//
// MF_EVENT_STREAM_METADATA_KEYDATA {CD59A4A1-4A3B-4BBD-8665-72A40FBEA776}
// Type: BLOB
DEFINE_GUID2(MF_EVENT_STREAM_METADATA_KEYDATA,
0xcd59a4a1, 0x4a3b, 0x4bbd, 0x86, 0x65, 0x72, 0xa4, 0xf, 0xbe, 0xa7, 0x76);
// MF_EVENT_STREAM_METADATA_CONTENT_KEYIDS {5063449D-CC29-4FC6-A75A-D247B35AF85C}
// Type: BLOB
DEFINE_GUID2(MF_EVENT_STREAM_METADATA_CONTENT_KEYIDS,
0x5063449d, 0xcc29, 0x4fc6, 0xa7, 0x5a, 0xd2, 0x47, 0xb3, 0x5a, 0xf8, 0x5c);
// MF_EVENT_STREAM_METADATA_SYSTEMID {1EA2EF64-BA16-4A36-8719-FE7560BA32AD}
// Type: BLOB
DEFINE_GUID2(MF_EVENT_STREAM_METADATA_SYSTEMID,
0x1ea2ef64, 0xba16, 0x4a36, 0x87, 0x19, 0xfe, 0x75, 0x60, 0xba, 0x32, 0xad);
#endif // (WINVER >= _WIN32_WINNT_WINBLUE)
////////////////////////////////////////////////////////////////////////////////
/////////////////////////////// Samples //////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
// Creates an instance of the Media Foundation implementation of IMFSample
//
STDAPI MFCreateSample( _Out_ IMFSample **ppIMFSample );
//
// Sample attributes
// These are the well-known attributes that can be present on an MF Sample's
// IMFAttributes store
//
//@@MFSampleExtension_MaxDecodeFrameSize
/// <summary>
// {D3CC654F-F9F3-4A13-889F-F04EB2B5B957} MFSampleExtension_MaxDecodeFrameSize {UINT64 (HI32(Width),LO32(Height))}
// specify the maxiumum resolution of compressed input bitstream,
// the decoder shall decode any comressed pictures below the specified maximum resolution
// any input compressed pictures beyond the maximum resolution shall not be decoded and dropped by the decoder
// the attribute shall be set on input sample
/// </summary>
DEFINE_GUID2(MFSampleExtension_MaxDecodeFrameSize,
0xd3cc654f, 0xf9f3, 0x4a13, 0x88, 0x9f, 0xf0, 0x4e, 0xb2, 0xb5, 0xb9, 0x57);
//@@MFSampleExtension_AccumulatedNonRefPicPercent
/// <summary>
// {79EA74DF-A740-445B-BC98-C9ED1F260EEE} MFSampleExtension_AccumulatedNonRefPicPercent
// Type: UINT32
// specify the percentage of accumulated non-reference pictures up to this output sample in decoding order
// The most common examples are,
// 1. if the sequence has the GOP structure of IPPPP......, the value will be 0
// 2. if the sequence has the GOP structure of IPBPB......, the percentage will be around 40%~50%. The value is 40~50.
// 3. if the sequence has the GOP structure of IPBBPBB......, the percentage will be around 50%~66%. The value is 50~60.
// where B frames are not used for reference.
// This is some statistic to application or pipeline whether decoder alone can have graceful degradation on quality management
// In the above example,
// 1. Decoder alone can't have graceful quality management. Because it can only have full frame rate or 1/15 of full frame rate when GOP size is 15 frames or 1/30 when GOP size is 30 frames
// 2. Decoder alone can have quality management. Because it can have full frame rate or 1/2 of full frame rate or 1/GOPSize
// 2. Decoder alone can have quality management. Because it can have full frame rate, or down to 1/3 of full frame rate or 1/GOPSize
// the attribute could be set on output sample from decoders
/// </summary>
// {79EA74DF-A740-445B-BC98-C9ED1F260EEE}
DEFINE_GUID2(MFSampleExtension_AccumulatedNonRefPicPercent,
0x79ea74df, 0xa740, 0x445b, 0xbc, 0x98, 0xc9, 0xed, 0x1f, 0x26, 0xe, 0xee);
////////////////////////////////////////////////////////////////////////////////
// Sample extensions for SAMPLE-AES encryption
// MFSampleExtension_Encryption_ProtectionScheme {D054D096-28BB-45DA-87EC-74F351871406}
// Type: UINT32
// Specifies the cipher and mode used to encrypt the content
DEFINE_GUID2(MFSampleExtension_Encryption_ProtectionScheme,
0xd054d096, 0x28bb, 0x45da, 0x87, 0xec, 0x74, 0xf3, 0x51, 0x87, 0x14, 0x6);
typedef enum _MFSampleEncryptionProtectionScheme
{
MF_SAMPLE_ENCRYPTION_PROTECTION_SCHEME_NONE = 0,
MF_SAMPLE_ENCRYPTION_PROTECTION_SCHEME_AES_CTR = 1,
MF_SAMPLE_ENCRYPTION_PROTECTION_SCHEME_AES_CBC = 2,
} MFSampleEncryptionProtectionScheme;
// MFSampleExtension_Encryption_CryptByteBlock {9D84289B-0C7F-4713-AB95-108AB42AD801}
// Type: UINT32
// Represents the number of encrypted blocks in the protection pattern, where each block is 16 bytes.
DEFINE_GUID2(MFSampleExtension_Encryption_CryptByteBlock,
0x9d84289b, 0xc7f, 0x4713, 0xab, 0x95, 0x10, 0x8a, 0xb4, 0x2a, 0xd8, 0x1);
// MFSampleExtension_Encryption_SkipByteBlock {0D550548-8317-4AB1-845F-D06306E293E3}
// Type: UINT32
// Represents the number of unencrypted blocks in the protection pattern, where each block is 16 bytes.
DEFINE_GUID2(MFSampleExtension_Encryption_SkipByteBlock,
0xd550548, 0x8317, 0x4ab1, 0x84, 0x5f, 0xd0, 0x63, 0x6, 0xe2, 0x93, 0xe3);
////////////////////////////////////////////////////////////////////////////////
// Attributes for HW-DRM support
//@@MFSampleExtension_Encryption_SubSample_Mapping
/// <summary>
/// The data blob associated with this attribute should contain an array of byte
/// ranges as DWORDs where every two DWORDs make a set. The first DWORD in each set
/// is the number of clear bytes and the second DWORD of the set is the number of
/// encrypted bytes.
/// Note that a pair of 0s is not a valid set (either value can be 0, but not both).
/// The array of byte ranges that indicate which ranges to decrypt, including the
/// possibility that the entire sample should NOT be decrypted.
/// It must be set on an IMFSample using SetBlob
/// </summary>
DEFINE_GUID2(MFSampleExtension_Encryption_SubSample_Mapping,
0x8444F27A, 0x69A1, 0x48DA, 0xBD, 0x08, 0x11, 0xCE, 0xF3, 0x68, 0x30, 0xD2);
// MFSampleExtension_Encryption_ClearSliceHeaderData {5509A4F4-320D-4E6C-8D1A-94C66DD20CB0}
/*
The MF blob should be parsed in the way below defined in SliceHeaderSet, with proper verifications
=============================================================================================================
Note the slice header data here DO NOT have all bits for all the syntaxes.
Some bits are removed on purpose to send out a lossy compressed slice header in order to be 100% secure
The partial slice header data here SHALL not include any bits for emulation prevention byte 0x03
=============================================================================================================
typedef struct SliceHeader_tag {
WORD dSliceHeaderLen; // indicate the length of the following slice header in byte, it shall not be more than 1024
BYTE SliceHeaderBytes[0]; // slice header data, the last byte might contain some bits not used, leave them random
} SliceHeader;
With dSliceHeaderLen bytes serialized after the SliceHeader struct.
And then use an array of these serialized consecutively,