hwcodec 0.1.0

Realtime AV1 and VP9 video encoding and decoding: hardware encoders (NVENC, Quick Sync, AMF, VA-API) and software codecs (SVT-AV1, libvpx, dav1d) behind one interface
Documentation
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
// 
// Notice Regarding Standards.  AMD does not provide a license or sublicense to
// any Intellectual Property Rights relating to any standards, including but not
// limited to any audio and/or video codec technologies such as MPEG-2, MPEG-4;
// AVC/H.264; HEVC/H.265; AAC decode/FFMPEG; AAC encode/FFMPEG; VC-1; and MP3
// (collectively, the "Media Technologies"). For clarity, you will pay any
// royalties due for such third party technologies, which may include the Media
// Technologies that are owed as a result of AMD providing the Software to you.
// 
// MIT license 
// 
// Copyright (c) 2026 Advanced Micro Devices, Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//

#ifndef AMF_Context_h
#define AMF_Context_h
#pragma once

#include "Buffer.h"
#include "AudioBuffer.h"
#include "Surface.h"
#include "Compute.h"
#include "ComputeFactory.h"

#define AMF_SURFACE_MAX_PLANES                     4 
#define AMF_CONTEXT_DISABLE_PLACED_RESOURCES       L"DisablePlacedResources"  // amf_bool, default false; Disable creation of placed resources and create committed resources

#if defined(__cplusplus)
namespace amf
{
#endif
    //----------------------------------------------------------------------------------------------
    // AMFContext interface
    //----------------------------------------------------------------------------------------------
#if defined(__cplusplus)
    class AMF_NO_VTABLE AMFContext : public AMFPropertyStorage
    {
    public:
        AMF_DECLARE_IID(0xa76a13f0, 0xd80e, 0x4fcc, 0xb5, 0x8, 0x65, 0xd0, 0xb5, 0x2e, 0xd9, 0xee)
        
        // Cleanup
        virtual AMF_RESULT          AMF_STD_CALL Terminate() = 0;

        // DX9
        virtual AMF_RESULT          AMF_STD_CALL InitDX9(void* pDX9Device) = 0;
        virtual void*               AMF_STD_CALL GetDX9Device(AMF_DX_VERSION dxVersionRequired = AMF_DX9) = 0;
        virtual AMF_RESULT          AMF_STD_CALL LockDX9() = 0;
        virtual AMF_RESULT          AMF_STD_CALL UnlockDX9() = 0;
        class AMFDX9Locker;

        // DX11
        virtual AMF_RESULT          AMF_STD_CALL InitDX11(void* pDX11Device, AMF_DX_VERSION dxVersionRequired = AMF_DX11_0) = 0;
        virtual void*               AMF_STD_CALL GetDX11Device(AMF_DX_VERSION dxVersionRequired = AMF_DX11_0) = 0;
        virtual AMF_RESULT          AMF_STD_CALL LockDX11() = 0;
        virtual AMF_RESULT          AMF_STD_CALL UnlockDX11() = 0;
        class AMFDX11Locker;

        // OpenCL
        virtual AMF_RESULT          AMF_STD_CALL InitOpenCL(void* pCommandQueue = NULL) = 0;
        virtual void*               AMF_STD_CALL GetOpenCLContext() = 0;
        virtual void*               AMF_STD_CALL GetOpenCLCommandQueue() = 0;
        virtual void*               AMF_STD_CALL GetOpenCLDeviceID() = 0;
        virtual AMF_RESULT          AMF_STD_CALL GetOpenCLComputeFactory(AMFComputeFactory **ppFactory) = 0; // advanced compute - multiple queries
        virtual AMF_RESULT          AMF_STD_CALL InitOpenCLEx(AMFComputeDevice *pDevice) = 0;
        virtual AMF_RESULT          AMF_STD_CALL LockOpenCL() = 0;
        virtual AMF_RESULT          AMF_STD_CALL UnlockOpenCL() = 0;
        class AMFOpenCLLocker;

        // OpenGL
        virtual AMF_RESULT          AMF_STD_CALL InitOpenGL(amf_handle hOpenGLContext, amf_handle hWindow, amf_handle hDC) = 0;
        virtual amf_handle          AMF_STD_CALL GetOpenGLContext() = 0;
        virtual amf_handle          AMF_STD_CALL GetOpenGLDrawable() = 0;
        virtual AMF_RESULT          AMF_STD_CALL LockOpenGL() = 0;
        virtual AMF_RESULT          AMF_STD_CALL UnlockOpenGL() = 0;
        class AMFOpenGLLocker;

        // XV - Linux
        virtual AMF_RESULT          AMF_STD_CALL InitXV(void* pXVDevice) = 0;
        virtual void*               AMF_STD_CALL GetXVDevice() = 0;
        virtual AMF_RESULT          AMF_STD_CALL LockXV() = 0;
        virtual AMF_RESULT          AMF_STD_CALL UnlockXV() = 0;
        class AMFXVLocker;

        // Gralloc - Android
        virtual AMF_RESULT          AMF_STD_CALL InitGralloc(void* pGrallocDevice) = 0;
        virtual void*               AMF_STD_CALL GetGrallocDevice() = 0;
        virtual AMF_RESULT          AMF_STD_CALL LockGralloc() = 0;
        virtual AMF_RESULT          AMF_STD_CALL UnlockGralloc() = 0;
        class AMFGrallocLocker;

        // Allocation
        virtual AMF_RESULT          AMF_STD_CALL AllocBuffer(AMF_MEMORY_TYPE type, amf_size size, AMFBuffer** ppBuffer) = 0;
        virtual AMF_RESULT          AMF_STD_CALL AllocSurface(AMF_MEMORY_TYPE type, AMF_SURFACE_FORMAT format, amf_int32 width, amf_int32 height, AMFSurface** ppSurface) = 0;
        virtual AMF_RESULT          AMF_STD_CALL AllocAudioBuffer(AMF_MEMORY_TYPE type, AMF_AUDIO_FORMAT format, amf_int32 samples, amf_int32 sampleRate, amf_int32 channels, 
                                                    AMFAudioBuffer** ppAudioBuffer) = 0;

        // Wrap existing objects
        virtual AMF_RESULT          AMF_STD_CALL CreateBufferFromHostNative(void* pHostBuffer, amf_size size, AMFBuffer** ppBuffer, AMFBufferObserver* pObserver) = 0;
        virtual AMF_RESULT          AMF_STD_CALL CreateSurfaceFromHostNative(AMF_SURFACE_FORMAT format, amf_int32 width, amf_int32 height, amf_int32 hPitch, amf_int32 vPitch, void* pData, 
                                                     AMFSurface** ppSurface, AMFSurfaceObserver* pObserver) = 0;
        virtual AMF_RESULT          AMF_STD_CALL CreateSurfaceFromDX9Native(void* pDX9Surface, AMFSurface** ppSurface, AMFSurfaceObserver* pObserver) = 0;
        virtual AMF_RESULT          AMF_STD_CALL CreateSurfaceFromDX11Native(void* pDX11Surface, AMFSurface** ppSurface, AMFSurfaceObserver* pObserver) = 0;
        virtual AMF_RESULT          AMF_STD_CALL CreateSurfaceFromOpenGLNative(AMF_SURFACE_FORMAT format, amf_handle hGLTextureID, AMFSurface** ppSurface, AMFSurfaceObserver* pObserver) = 0;
        virtual AMF_RESULT          AMF_STD_CALL CreateSurfaceFromGrallocNative(amf_handle hGrallocSurface, AMFSurface** ppSurface, AMFSurfaceObserver* pObserver) = 0;
        virtual AMF_RESULT          AMF_STD_CALL CreateSurfaceFromOpenCLNative(AMF_SURFACE_FORMAT format, amf_int32 width, amf_int32 height, void** pClPlanes, 
                                                     AMFSurface** ppSurface, AMFSurfaceObserver* pObserver) = 0;
        virtual AMF_RESULT          AMF_STD_CALL CreateBufferFromOpenCLNative(void* pCLBuffer, amf_size size, AMFBuffer** ppBuffer) = 0;

        // Access to AMFCompute interface - AMF_MEMORY_OPENCL, AMF_MEMORY_COMPUTE_FOR_DX9, AMF_MEMORY_COMPUTE_FOR_DX11 are currently supported
        virtual AMF_RESULT          AMF_STD_CALL GetCompute(AMF_MEMORY_TYPE eMemType, AMFCompute** ppCompute) = 0;
    };

    //----------------------------------------------------------------------------------------------
    // smart pointer
    //----------------------------------------------------------------------------------------------
    typedef AMFInterfacePtr_T<AMFContext> AMFContextPtr;

    //----------------------------------------------------------------------------------------------
    // AMFContext1 interface
    //----------------------------------------------------------------------------------------------

    class AMF_NO_VTABLE AMFContext1 : public AMFContext
    {
    public:
        AMF_DECLARE_IID(0xd9e9f868, 0x6220, 0x44c6, 0xa2, 0x2f, 0x7c, 0xd6, 0xda, 0xc6, 0x86, 0x46)

        virtual AMF_RESULT          AMF_STD_CALL CreateBufferFromDX11Native(void* pHostBuffer, AMFBuffer** ppBuffer, AMFBufferObserver* pObserver) = 0;

        virtual AMF_RESULT          AMF_STD_CALL AllocBufferEx(AMF_MEMORY_TYPE type, amf_size size, AMF_BUFFER_USAGE usage, AMF_MEMORY_CPU_ACCESS access, AMFBuffer** ppBuffer) = 0;
        virtual AMF_RESULT          AMF_STD_CALL AllocSurfaceEx(AMF_MEMORY_TYPE type, AMF_SURFACE_FORMAT format, amf_int32 width, amf_int32 height, AMF_SURFACE_USAGE usage, AMF_MEMORY_CPU_ACCESS access, AMFSurface** ppSurface) = 0;

        // Vulkan - Windows, Linux
        virtual AMF_RESULT          AMF_STD_CALL InitVulkan(void* pVulkanDevice) = 0;
        virtual void*               AMF_STD_CALL GetVulkanDevice() = 0;
        virtual AMF_RESULT          AMF_STD_CALL LockVulkan() = 0;
        virtual AMF_RESULT          AMF_STD_CALL UnlockVulkan() = 0;

        virtual AMF_RESULT          AMF_STD_CALL CreateSurfaceFromVulkanNative(void* pVulkanImage, AMFSurface** ppSurface, AMFSurfaceObserver* pObserver) = 0;
        virtual AMF_RESULT          AMF_STD_CALL CreateBufferFromVulkanNative(void* pVulkanBuffer, AMFBuffer** ppBuffer, AMFBufferObserver* pObserver) = 0;
        virtual AMF_RESULT          AMF_STD_CALL GetVulkanDeviceExtensions(amf_size *pCount, const char **ppExtensions) = 0;

        
        class AMFVulkanLocker;
    };
    //----------------------------------------------------------------------------------------------
    // smart pointer
    //----------------------------------------------------------------------------------------------
    typedef AMFInterfacePtr_T<AMFContext1> AMFContext1Ptr;

    //----------------------------------------------------------------------------------------------
    // AMFContext2 interface
    //----------------------------------------------------------------------------------------------

    class AMF_NO_VTABLE AMFContext2 : public AMFContext1
    {
    public:
        AMF_DECLARE_IID(0x726241d3, 0xbd46, 0x4e90, 0x99, 0x68, 0x93, 0xe0, 0x7e, 0xa2, 0x98, 0x4d)

        // DX12
        virtual AMF_RESULT          AMF_STD_CALL InitDX12(void* pDX11Device, AMF_DX_VERSION dxVersionRequired = AMF_DX12) = 0;
        virtual void*               AMF_STD_CALL GetDX12Device(AMF_DX_VERSION dxVersionRequired = AMF_DX12) = 0;
        virtual AMF_RESULT          AMF_STD_CALL LockDX12() = 0;
        virtual AMF_RESULT          AMF_STD_CALL UnlockDX12() = 0;
        virtual AMF_RESULT          AMF_STD_CALL CreateSurfaceFromDX12Native(void* pResourceTexture, AMFSurface** ppSurface, AMFSurfaceObserver* pObserver) = 0;
        virtual AMF_RESULT          AMF_STD_CALL CreateBufferFromDX12Native(void* pResourceBuffer, AMFBuffer** ppBuffer, AMFBufferObserver* pObserver) = 0;

        class AMFDX12Locker;
    };
    typedef AMFInterfacePtr_T<AMFContext2> AMFContext2Ptr;

    //----------------------------------------------------------------------------------------------
    // AMFSurface synchronization structure
    //----------------------------------------------------------------------------------------------
    typedef struct AMFSharedFenceResource
    {
        void* pNext;                                        // reserved for extensions
#if defined(_WIN32)
        amf_handle  hFence;
#else
        amf_int32   hFence;
#endif
        amf_uint64  fenceValue;

        amf_bool    bFenceSubmitted;                        // if true - wait for hFence. ignored if timeline. Vulkan usage only.
        amf_bool    bFenceTimeline;                         // if true - this is a timeline semaphore or counter. In DX, this should be always true. 
        amf_bool    bFenceNTHandle;                         // The shared semaphore/fence handle is NT handle.
    } AMFSharedFenceResource;

    //----------------------------------------------------------------------------------------------
    // AMFSurface share handle struct
    //----------------------------------------------------------------------------------------------

    typedef struct AMFSharedSurfaceResource
    {
        void* pNext;                                        // reserved for extensions
        amf_bool bCloseSurface;                             // whether call close handle for legacy method e.g. DX11 GetSharedHandle
        amf_bool bUserControl;                              // whether call close handle in destructor
#if defined(_WIN32)
        amf_handle hPlanes[AMF_SURFACE_MAX_PLANES];         // for multi-planar with separate texture allocations 
        amf_handle hHeap[AMF_SURFACE_MAX_PLANES];           // DX12 usage only when AMF_CONTEXT_DISABLE_PLACED_RESOURCES set to false
#else
        amf_int32  hPlanes[AMF_SURFACE_MAX_PLANES];
        amf_int32  hHeap[AMF_SURFACE_MAX_PLANES];
#endif
        AMFSize     planeSize[AMF_SURFACE_MAX_PLANES];      // Surface Resolution for each plane

        // rowPitch is currently only used in Vulkan memory in linear allocation, representing plane row pitch in bytes
        // If the handle is extracted from AMF Vulkan surface, rowPitch should be filled automatically.
        // Can be extracted from vkGetImageSubresourceLayout
        //need to be set from Vulkan handle, other memories(DX) are not required.
        amf_uint64  rowPitch[AMF_SURFACE_MAX_PLANES];

        AMF_SURFACE_FORMAT  eSourceFormat;                  // pixel format of source surface
        AMF_SURFACE_USAGE  eSourceUsage;                    // AMF usage of source surface
        AMF_MEMORY_CPU_ACCESS  eSourceAccess;               // CPU access of source surface
        
        // due to lack of HW support, substitute DXGI/Vulkan formats may be used in AMF surface creation, These are the following AMF formats:
        // AMF_SURFACE_Y210, AMF_SURFACE_Y216, AMF_SURFACE_Y410, AMF_SURFACE_Y416
        // this flag indicates whether the emulated format was used in AMF.
        amf_bool    bEmulatedFormat;                        // if true - substitute format was used

        AMFSharedFenceResource Sync[AMF_SURFACE_MAX_PLANES];

    } AMFSharedSurfaceResource;

    //----------------------------------------------------------------------------------------------
    // AMFContext3 interface
    //----------------------------------------------------------------------------------------------

    class AMF_NO_VTABLE AMFContext3 : public AMFContext2
    {
    public:
        AMF_DECLARE_IID(0x8c926813, 0x206a, 0x47a5, 0xa9, 0x3, 0x2c, 0x36, 0x36, 0x6d, 0x6, 0xb7);

        virtual AMF_RESULT          AMF_STD_CALL CreateSharedResourceFromSurface(AMFSurface* src, AMFSharedSurfaceResource* pResource) = 0;
        virtual AMF_RESULT          AMF_STD_CALL CreateSurfaceFromSharedResource(AMF_MEMORY_TYPE type, const AMFSharedSurfaceResource* pResource, AMFSurface** ppSurface) = 0;
    };
    //----------------------------------------------------------------------------------------------
    // smart pointer
    //----------------------------------------------------------------------------------------------
    typedef AMFInterfacePtr_T<AMFContext3> AMFContext3Ptr;

#else
    typedef struct AMFContext AMFContext;
    AMF_DECLARE_IID(AMFContext, 0xa76a13f0, 0xd80e, 0x4fcc, 0xb5, 0x8, 0x65, 0xd0, 0xb5, 0x2e, 0xd9, 0xee)

    typedef struct AMFContextVtbl
    {
        // AMFInterface interface
        amf_long            (AMF_STD_CALL *Acquire)(AMFContext* pThis);
        amf_long            (AMF_STD_CALL *Release)(AMFContext* pThis);
        enum AMF_RESULT     (AMF_STD_CALL *QueryInterface)(AMFContext* pThis, const struct AMFGuid *interfaceID, void** ppInterface);
        
        // AMFInterface AMFPropertyStorage

        AMF_RESULT          (AMF_STD_CALL *SetProperty)(AMFContext* pThis, const wchar_t* name, AMFVariantStruct value);
        AMF_RESULT          (AMF_STD_CALL *GetProperty)(AMFContext* pThis, const wchar_t* name, AMFVariantStruct* pValue);
        amf_bool            (AMF_STD_CALL *HasProperty)(AMFContext* pThis, const wchar_t* name);
        amf_size            (AMF_STD_CALL *GetPropertyCount)(AMFContext* pThis);
        AMF_RESULT          (AMF_STD_CALL *GetPropertyAt)(AMFContext* pThis, amf_size index, wchar_t* name, amf_size nameSize, AMFVariantStruct* pValue);
        AMF_RESULT          (AMF_STD_CALL *Clear)(AMFContext* pThis);
        AMF_RESULT          (AMF_STD_CALL *AddTo)(AMFContext* pThis, AMFPropertyStorage* pDest, amf_bool overwrite, amf_bool deep);
        AMF_RESULT          (AMF_STD_CALL *CopyTo)(AMFContext* pThis, AMFPropertyStorage* pDest, amf_bool deep);
        void                (AMF_STD_CALL *AddObserver)(AMFContext* pThis, AMFPropertyStorageObserver* pObserver);
        void                (AMF_STD_CALL *RemoveObserver)(AMFContext* pThis, AMFPropertyStorageObserver* pObserver);

        // AMFContext interface
       
        // Cleanup
        AMF_RESULT          (AMF_STD_CALL *Terminate)(AMFContext* pThis);

        // DX9
        AMF_RESULT          (AMF_STD_CALL *InitDX9)(AMFContext* pThis, void* pDX9Device);
        void*               (AMF_STD_CALL *GetDX9Device)(AMFContext* pThis, AMF_DX_VERSION dxVersionRequired);
        AMF_RESULT          (AMF_STD_CALL *LockDX9)(AMFContext* pThis);
        AMF_RESULT          (AMF_STD_CALL *UnlockDX9)(AMFContext* pThis);
        // DX11
        AMF_RESULT          (AMF_STD_CALL *InitDX11)(AMFContext* pThis, void* pDX11Device, AMF_DX_VERSION dxVersionRequired);
        void*               (AMF_STD_CALL *GetDX11Device)(AMFContext* pThis, AMF_DX_VERSION dxVersionRequired);
        AMF_RESULT          (AMF_STD_CALL *LockDX11)(AMFContext* pThis);
        AMF_RESULT          (AMF_STD_CALL *UnlockDX11)(AMFContext* pThis);

        // OpenCL
        AMF_RESULT          (AMF_STD_CALL *InitOpenCL)(AMFContext* pThis, void* pCommandQueue);
        void*               (AMF_STD_CALL *GetOpenCLContext)(AMFContext* pThis);
        void*               (AMF_STD_CALL *GetOpenCLCommandQueue)(AMFContext* pThis);
        void*               (AMF_STD_CALL *GetOpenCLDeviceID)(AMFContext* pThis);
        AMF_RESULT          (AMF_STD_CALL *GetOpenCLComputeFactory)(AMFContext* pThis, AMFComputeFactory **ppFactory); // advanced compute - multiple queries
        AMF_RESULT          (AMF_STD_CALL *InitOpenCLEx)(AMFContext* pThis, AMFComputeDevice *pDevice);
        AMF_RESULT          (AMF_STD_CALL *LockOpenCL)(AMFContext* pThis);
        AMF_RESULT          (AMF_STD_CALL *UnlockOpenCL)(AMFContext* pThis);

        // OpenGL
        AMF_RESULT          (AMF_STD_CALL *InitOpenGL)(AMFContext* pThis, amf_handle hOpenGLContext, amf_handle hWindow, amf_handle hDC);
        amf_handle          (AMF_STD_CALL *GetOpenGLContext)(AMFContext* pThis);
        amf_handle          (AMF_STD_CALL *GetOpenGLDrawable)(AMFContext* pThis);
        AMF_RESULT          (AMF_STD_CALL *LockOpenGL)(AMFContext* pThis);
        AMF_RESULT          (AMF_STD_CALL *UnlockOpenGL)(AMFContext* pThis);
        // XV - Linux
        AMF_RESULT          (AMF_STD_CALL *InitXV)(AMFContext* pThis, void* pXVDevice);
        void*               (AMF_STD_CALL *GetXVDevice)(AMFContext* pThis);
        AMF_RESULT          (AMF_STD_CALL *LockXV)(AMFContext* pThis);
        AMF_RESULT          (AMF_STD_CALL *UnlockXV)(AMFContext* pThis);

        // Gralloc - Android
        AMF_RESULT          (AMF_STD_CALL *InitGralloc)(AMFContext* pThis, void* pGrallocDevice);
        void*               (AMF_STD_CALL *GetGrallocDevice)(AMFContext* pThis);
        AMF_RESULT          (AMF_STD_CALL *LockGralloc)(AMFContext* pThis);
        AMF_RESULT          (AMF_STD_CALL *UnlockGralloc)(AMFContext* pThis);
        // Allocation
        AMF_RESULT          (AMF_STD_CALL *AllocBuffer)(AMFContext* pThis, AMF_MEMORY_TYPE type, amf_size size, AMFBuffer** ppBuffer);
        AMF_RESULT          (AMF_STD_CALL *AllocSurface)(AMFContext* pThis, AMF_MEMORY_TYPE type, AMF_SURFACE_FORMAT format, amf_int32 width, amf_int32 height, AMFSurface** ppSurface);
        AMF_RESULT          (AMF_STD_CALL *AllocAudioBuffer)(AMFContext* pThis, AMF_MEMORY_TYPE type, AMF_AUDIO_FORMAT format, amf_int32 samples, amf_int32 sampleRate, amf_int32 channels, 
                                                    AMFAudioBuffer** ppAudioBuffer);

        // Wrap existing objects
        AMF_RESULT          (AMF_STD_CALL *CreateBufferFromHostNative)(AMFContext* pThis, void* pHostBuffer, amf_size size, AMFBuffer** ppBuffer, AMFBufferObserver* pObserver);
        AMF_RESULT          (AMF_STD_CALL *CreateSurfaceFromHostNative)(AMFContext* pThis, AMF_SURFACE_FORMAT format, amf_int32 width, amf_int32 height, amf_int32 hPitch, amf_int32 vPitch, void* pData, 
                                                     AMFSurface** ppSurface, AMFSurfaceObserver* pObserver);
        AMF_RESULT          (AMF_STD_CALL *CreateSurfaceFromDX9Native)(AMFContext* pThis, void* pDX9Surface, AMFSurface** ppSurface, AMFSurfaceObserver* pObserver);
        AMF_RESULT          (AMF_STD_CALL *CreateSurfaceFromDX11Native)(AMFContext* pThis, void* pDX11Surface, AMFSurface** ppSurface, AMFSurfaceObserver* pObserver);
        AMF_RESULT          (AMF_STD_CALL *CreateSurfaceFromOpenGLNative)(AMFContext* pThis, AMF_SURFACE_FORMAT format, amf_handle hGLTextureID, AMFSurface** ppSurface, AMFSurfaceObserver* pObserver);
        AMF_RESULT          (AMF_STD_CALL *CreateSurfaceFromGrallocNative)(AMFContext* pThis, amf_handle hGrallocSurface, AMFSurface** ppSurface, AMFSurfaceObserver* pObserver);
        AMF_RESULT          (AMF_STD_CALL *CreateSurfaceFromOpenCLNative)(AMFContext* pThis, AMF_SURFACE_FORMAT format, amf_int32 width, amf_int32 height, void** pClPlanes, 
                                                     AMFSurface** ppSurface, AMFSurfaceObserver* pObserver);
        AMF_RESULT          (AMF_STD_CALL *CreateBufferFromOpenCLNative)(AMFContext* pThis, void* pCLBuffer, amf_size size, AMFBuffer** ppBuffer);

        // Access to AMFCompute interface - AMF_MEMORY_OPENCL, AMF_MEMORY_COMPUTE_FOR_DX9, AMF_MEMORY_COMPUTE_FOR_DX11 are currently supported
        AMF_RESULT          (AMF_STD_CALL *GetCompute)(AMFContext* pThis, AMF_MEMORY_TYPE eMemType, AMFCompute** ppCompute);

    } AMFContextVtbl;

    struct AMFContext
    {
        const AMFContextVtbl *pVtbl;
    };


    typedef struct AMFContext1 AMFContext1;
    AMF_DECLARE_IID(AMFContext1, 0xd9e9f868, 0x6220, 0x44c6, 0xa2, 0x2f, 0x7c, 0xd6, 0xda, 0xc6, 0x86, 0x46)

    typedef struct AMFContext1Vtbl
    {
        // AMFInterface interface
        amf_long            (AMF_STD_CALL *Acquire)(AMFContext1* pThis);
        amf_long            (AMF_STD_CALL *Release)(AMFContext1* pThis);
        enum AMF_RESULT     (AMF_STD_CALL *QueryInterface)(AMFContext1* pThis, const struct AMFGuid *interfaceID, void** ppInterface);
        
        // AMFInterface AMFPropertyStorage

        AMF_RESULT          (AMF_STD_CALL *SetProperty)(AMFContext1* pThis, const wchar_t* name, AMFVariantStruct value);
        AMF_RESULT          (AMF_STD_CALL *GetProperty)(AMFContext1* pThis, const wchar_t* name, AMFVariantStruct* pValue);
        amf_bool            (AMF_STD_CALL *HasProperty)(AMFContext1* pThis, const wchar_t* name);
        amf_size            (AMF_STD_CALL *GetPropertyCount)(AMFContext1* pThis);
        AMF_RESULT          (AMF_STD_CALL *GetPropertyAt)(AMFContext1* pThis, amf_size index, wchar_t* name, amf_size nameSize, AMFVariantStruct* pValue);
        AMF_RESULT          (AMF_STD_CALL *Clear)(AMFContext1* pThis);
        AMF_RESULT          (AMF_STD_CALL *AddTo)(AMFContext1* pThis, AMFPropertyStorage* pDest, amf_bool overwrite, amf_bool deep);
        AMF_RESULT          (AMF_STD_CALL *CopyTo)(AMFContext1* pThis, AMFPropertyStorage* pDest, amf_bool deep);
        void                (AMF_STD_CALL *AddObserver)(AMFContext1* pThis, AMFPropertyStorageObserver* pObserver);
        void                (AMF_STD_CALL *RemoveObserver)(AMFContext1* pThis, AMFPropertyStorageObserver* pObserver);

        // AMFContext interface
       
        // Cleanup
        AMF_RESULT          (AMF_STD_CALL *Terminate)(AMFContext1* pThis);

        // DX9
        AMF_RESULT          (AMF_STD_CALL *InitDX9)(AMFContext1* pThis, void* pDX9Device);
        void*               (AMF_STD_CALL *GetDX9Device)(AMFContext1* pThis, AMF_DX_VERSION dxVersionRequired);
        AMF_RESULT          (AMF_STD_CALL *LockDX9)(AMFContext1* pThis);
        AMF_RESULT          (AMF_STD_CALL *UnlockDX9)(AMFContext1* pThis);
        // DX11
        AMF_RESULT          (AMF_STD_CALL *InitDX11)(AMFContext1* pThis, void* pDX11Device, AMF_DX_VERSION dxVersionRequired);
        void*               (AMF_STD_CALL *GetDX11Device)(AMFContext1* pThis, AMF_DX_VERSION dxVersionRequired);
        AMF_RESULT          (AMF_STD_CALL *LockDX11)(AMFContext1* pThis);
        AMF_RESULT          (AMF_STD_CALL *UnlockDX11)(AMFContext1* pThis);

        // OpenCL
        AMF_RESULT          (AMF_STD_CALL *InitOpenCL)(AMFContext1* pThis, void* pCommandQueue);
        void*               (AMF_STD_CALL *GetOpenCLContext)(AMFContext1* pThis);
        void*               (AMF_STD_CALL *GetOpenCLCommandQueue)(AMFContext1* pThis);
        void*               (AMF_STD_CALL *GetOpenCLDeviceID)(AMFContext1* pThis);
        AMF_RESULT          (AMF_STD_CALL *GetOpenCLComputeFactory)(AMFContext1* pThis, AMFComputeFactory **ppFactory); // advanced compute - multiple queries
        AMF_RESULT          (AMF_STD_CALL *InitOpenCLEx)(AMFContext1* pThis, AMFComputeDevice *pDevice);
        AMF_RESULT          (AMF_STD_CALL *LockOpenCL)(AMFContext1* pThis);
        AMF_RESULT          (AMF_STD_CALL *UnlockOpenCL)(AMFContext1* pThis);

        // OpenGL
        AMF_RESULT          (AMF_STD_CALL *InitOpenGL)(AMFContext1* pThis, amf_handle hOpenGLContext, amf_handle hWindow, amf_handle hDC);
        amf_handle          (AMF_STD_CALL *GetOpenGLContext)(AMFContext1* pThis);
        amf_handle          (AMF_STD_CALL *GetOpenGLDrawable)(AMFContext1* pThis);
        AMF_RESULT          (AMF_STD_CALL *LockOpenGL)(AMFContext1* pThis);
        AMF_RESULT          (AMF_STD_CALL *UnlockOpenGL)(AMFContext1* pThis);
        // XV - Linux
        AMF_RESULT          (AMF_STD_CALL *InitXV)(AMFContext1* pThis, void* pXVDevice);
        void*               (AMF_STD_CALL *GetXVDevice)(AMFContext1* pThis);
        AMF_RESULT          (AMF_STD_CALL *LockXV)(AMFContext1* pThis);
        AMF_RESULT          (AMF_STD_CALL *UnlockXV)(AMFContext1* pThis);

        // Gralloc - Android
        AMF_RESULT          (AMF_STD_CALL *InitGralloc)(AMFContext1* pThis, void* pGrallocDevice);
        void*               (AMF_STD_CALL *GetGrallocDevice)(AMFContext1* pThis);
        AMF_RESULT          (AMF_STD_CALL *LockGralloc)(AMFContext1* pThis);
        AMF_RESULT          (AMF_STD_CALL *UnlockGralloc)(AMFContext1* pThis);
        // Allocation
        AMF_RESULT          (AMF_STD_CALL *AllocBuffer)(AMFContext1* pThis, AMF_MEMORY_TYPE type, amf_size size, AMFBuffer** ppBuffer);
        AMF_RESULT          (AMF_STD_CALL *AllocSurface)(AMFContext1* pThis, AMF_MEMORY_TYPE type, AMF_SURFACE_FORMAT format, amf_int32 width, amf_int32 height, AMFSurface** ppSurface);
        AMF_RESULT          (AMF_STD_CALL *AllocAudioBuffer)(AMFContext1* pThis, AMF_MEMORY_TYPE type, AMF_AUDIO_FORMAT format, amf_int32 samples, amf_int32 sampleRate, amf_int32 channels, 
                                                    AMFAudioBuffer** ppAudioBuffer);

        // Wrap existing objects
        AMF_RESULT          (AMF_STD_CALL *CreateBufferFromHostNative)(AMFContext1* pThis, void* pHostBuffer, amf_size size, AMFBuffer** ppBuffer, AMFBufferObserver* pObserver);
        AMF_RESULT          (AMF_STD_CALL *CreateSurfaceFromHostNative)(AMFContext1* pThis, AMF_SURFACE_FORMAT format, amf_int32 width, amf_int32 height, amf_int32 hPitch, amf_int32 vPitch, void* pData, 
                                                     AMFSurface** ppSurface, AMFSurfaceObserver* pObserver);
        AMF_RESULT          (AMF_STD_CALL *CreateSurfaceFromDX9Native)(AMFContext1* pThis, void* pDX9Surface, AMFSurface** ppSurface, AMFSurfaceObserver* pObserver);
        AMF_RESULT          (AMF_STD_CALL *CreateSurfaceFromDX11Native)(AMFContext1* pThis, void* pDX11Surface, AMFSurface** ppSurface, AMFSurfaceObserver* pObserver);
        AMF_RESULT          (AMF_STD_CALL *CreateSurfaceFromOpenGLNative)(AMFContext1* pThis, AMF_SURFACE_FORMAT format, amf_handle hGLTextureID, AMFSurface** ppSurface, AMFSurfaceObserver* pObserver);
        AMF_RESULT          (AMF_STD_CALL *CreateSurfaceFromGrallocNative)(AMFContext1* pThis, amf_handle hGrallocSurface, AMFSurface** ppSurface, AMFSurfaceObserver* pObserver);
        AMF_RESULT          (AMF_STD_CALL *CreateSurfaceFromOpenCLNative)(AMFContext1* pThis, AMF_SURFACE_FORMAT format, amf_int32 width, amf_int32 height, void** pClPlanes, 
                                                     AMFSurface** ppSurface, AMFSurfaceObserver* pObserver);
        AMF_RESULT          (AMF_STD_CALL *CreateBufferFromOpenCLNative)(AMFContext1* pThis, void* pCLBuffer, amf_size size, AMFBuffer** ppBuffer);

        // Access to AMFCompute interface - AMF_MEMORY_OPENCL, AMF_MEMORY_COMPUTE_FOR_DX9, AMF_MEMORY_COMPUTE_FOR_DX11 are currently supported
        AMF_RESULT          (AMF_STD_CALL *GetCompute)(AMFContext1* pThis, AMF_MEMORY_TYPE eMemType, AMFCompute** ppCompute);

        // AMFContext1 interface

        AMF_RESULT          (AMF_STD_CALL *CreateBufferFromDX11Native)(AMFContext1* pThis, void* pHostBuffer, AMFBuffer** ppBuffer, AMFBufferObserver* pObserver);
        AMF_RESULT          (AMF_STD_CALL *AllocBufferEx)(AMFContext1* pThis, AMF_MEMORY_TYPE type, amf_size size, AMF_BUFFER_USAGE usage, AMF_MEMORY_CPU_ACCESS access, AMFBuffer** ppBuffer);
        AMF_RESULT          (AMF_STD_CALL *AllocSurfaceEx)(AMFContext1* pThis, AMF_MEMORY_TYPE type, AMF_SURFACE_FORMAT format, amf_int32 width, amf_int32 height, AMF_SURFACE_USAGE usage, AMF_MEMORY_CPU_ACCESS access, AMFSurface** ppSurface);

        // Vulkan - Windows, Linux
        AMF_RESULT          (AMF_STD_CALL *InitVulkan)(AMFContext1* pThis, void* pVulkanDevice);
        void*               (AMF_STD_CALL *GetVulkanDevice)(AMFContext1* pThis);
        AMF_RESULT          (AMF_STD_CALL *LockVulkan)(AMFContext1* pThis);
        AMF_RESULT          (AMF_STD_CALL *UnlockVulkan)(AMFContext1* pThis);

        AMF_RESULT          (AMF_STD_CALL *CreateSurfaceFromVulkanNative)(AMFContext1* pThis, void* pVulkanImage, AMFSurface** ppSurface, AMFSurfaceObserver* pObserver);
        AMF_RESULT          (AMF_STD_CALL *CreateBufferFromVulkanNative)(AMFContext1* pThis, void* pVulkanBuffer, AMFBuffer** ppBuffer, AMFBufferObserver* pObserver);
        AMF_RESULT          (AMF_STD_CALL *GetVulkanDeviceExtensions)(AMFContext1* pThis, amf_size *pCount, const char **ppExtensions);

    } AMFContext1Vtbl;

    struct AMFContext1
    {
        const AMFContext1Vtbl *pVtbl;
    };

    typedef struct AMFContext2 AMFContext2;
    AMF_DECLARE_IID(AMFContext2, 0xd9e9f868, 0x6220, 0x44c6, 0xa2, 0x2f, 0x7c, 0xd6, 0xda, 0xc6, 0x86, 0x46)

        typedef struct AMFContext2Vtbl
    {
        // AMFInterface interface
        amf_long            (AMF_STD_CALL *Acquire)(AMFContext2* pThis);
        amf_long            (AMF_STD_CALL *Release)(AMFContext2* pThis);
        enum AMF_RESULT     (AMF_STD_CALL *QueryInterface)(AMFContext2* pThis, const struct AMFGuid *interfaceID, void** ppInterface);

        // AMFInterface AMFPropertyStorage

        AMF_RESULT          (AMF_STD_CALL *SetProperty)(AMFContext2* pThis, const wchar_t* name, AMFVariantStruct value);
        AMF_RESULT          (AMF_STD_CALL *GetProperty)(AMFContext2* pThis, const wchar_t* name, AMFVariantStruct* pValue);
        amf_bool            (AMF_STD_CALL *HasProperty)(AMFContext2* pThis, const wchar_t* name);
        amf_size            (AMF_STD_CALL *GetPropertyCount)(AMFContext2* pThis);
        AMF_RESULT          (AMF_STD_CALL *GetPropertyAt)(AMFContext2* pThis, amf_size index, wchar_t* name, amf_size nameSize, AMFVariantStruct* pValue);
        AMF_RESULT          (AMF_STD_CALL *Clear)(AMFContext2* pThis);
        AMF_RESULT          (AMF_STD_CALL *AddTo)(AMFContext2* pThis, AMFPropertyStorage* pDest, amf_bool overwrite, amf_bool deep);
        AMF_RESULT          (AMF_STD_CALL *CopyTo)(AMFContext2* pThis, AMFPropertyStorage* pDest, amf_bool deep);
        void                (AMF_STD_CALL *AddObserver)(AMFContext2* pThis, AMFPropertyStorageObserver* pObserver);
        void                (AMF_STD_CALL *RemoveObserver)(AMFContext2* pThis, AMFPropertyStorageObserver* pObserver);

        // AMFContext interface

        // Cleanup
        AMF_RESULT          (AMF_STD_CALL *Terminate)(AMFContext2* pThis);

        // DX9
        AMF_RESULT          (AMF_STD_CALL *InitDX9)(AMFContext2* pThis, void* pDX9Device);
        void*                         (AMF_STD_CALL *GetDX9Device)(AMFContext2* pThis, AMF_DX_VERSION dxVersionRequired);
        AMF_RESULT          (AMF_STD_CALL *LockDX9)(AMFContext2* pThis);
        AMF_RESULT          (AMF_STD_CALL *UnlockDX9)(AMFContext2* pThis);
        // DX11
        AMF_RESULT          (AMF_STD_CALL *InitDX11)(AMFContext2* pThis, void* pDX11Device, AMF_DX_VERSION dxVersionRequired);
        void*                         (AMF_STD_CALL *GetDX11Device)(AMFContext2* pThis, AMF_DX_VERSION dxVersionRequired);
        AMF_RESULT          (AMF_STD_CALL *LockDX11)(AMFContext2* pThis);
        AMF_RESULT          (AMF_STD_CALL *UnlockDX11)(AMFContext2* pThis);

        // OpenCL
        AMF_RESULT          (AMF_STD_CALL *InitOpenCL)(AMFContext2* pThis, void* pCommandQueue);
        void*               (AMF_STD_CALL *GetOpenCLContext)(AMFContext2* pThis);
        void*               (AMF_STD_CALL *GetOpenCLCommandQueue)(AMFContext2* pThis);
        void*               (AMF_STD_CALL *GetOpenCLDeviceID)(AMFContext2* pThis);
        AMF_RESULT          (AMF_STD_CALL *GetOpenCLComputeFactory)(AMFContext2* pThis, AMFComputeFactory **ppFactory); // advanced compute - multiple queries
        AMF_RESULT          (AMF_STD_CALL *InitOpenCLEx)(AMFContext2* pThis, AMFComputeDevice *pDevice);
        AMF_RESULT          (AMF_STD_CALL *LockOpenCL)(AMFContext2* pThis);
        AMF_RESULT          (AMF_STD_CALL *UnlockOpenCL)(AMFContext2* pThis);

        // OpenGL
        AMF_RESULT          (AMF_STD_CALL *InitOpenGL)(AMFContext2* pThis, amf_handle hOpenGLContext, amf_handle hWindow, amf_handle hDC);
        amf_handle          (AMF_STD_CALL *GetOpenGLContext)(AMFContext2* pThis);
        amf_handle          (AMF_STD_CALL *GetOpenGLDrawable)(AMFContext2* pThis);
        AMF_RESULT          (AMF_STD_CALL *LockOpenGL)(AMFContext2* pThis);
        AMF_RESULT          (AMF_STD_CALL *UnlockOpenGL)(AMFContext2* pThis);
        // XV - Linux
        AMF_RESULT          (AMF_STD_CALL *InitXV)(AMFContext2* pThis, void* pXVDevice);
        void*               (AMF_STD_CALL *GetXVDevice)(AMFContext2* pThis);
        AMF_RESULT          (AMF_STD_CALL *LockXV)(AMFContext2* pThis);
        AMF_RESULT          (AMF_STD_CALL *UnlockXV)(AMFContext2* pThis);

        // Gralloc - Android
        AMF_RESULT          (AMF_STD_CALL *InitGralloc)(AMFContext2* pThis, void* pGrallocDevice);
        void*               (AMF_STD_CALL *GetGrallocDevice)(AMFContext2* pThis);
        AMF_RESULT          (AMF_STD_CALL *LockGralloc)(AMFContext2* pThis);
        AMF_RESULT          (AMF_STD_CALL *UnlockGralloc)(AMFContext2* pThis);
        // Allocation
        AMF_RESULT          (AMF_STD_CALL *AllocBuffer)(AMFContext2* pThis, AMF_MEMORY_TYPE type, amf_size size, AMFBuffer** ppBuffer);
        AMF_RESULT          (AMF_STD_CALL *AllocSurface)(AMFContext2* pThis, AMF_MEMORY_TYPE type, AMF_SURFACE_FORMAT format, amf_int32 width, amf_int32 height, AMFSurface** ppSurface);
        AMF_RESULT          (AMF_STD_CALL *AllocAudioBuffer)(AMFContext2* pThis, AMF_MEMORY_TYPE type, AMF_AUDIO_FORMAT format, amf_int32 samples, amf_int32 sampleRate, amf_int32 channels, AMFAudioBuffer** ppAudioBuffer);

        // Wrap existing objects
        AMF_RESULT          (AMF_STD_CALL *CreateBufferFromHostNative)(AMFContext2* pThis, void* pHostBuffer, amf_size size, AMFBuffer** ppBuffer, AMFBufferObserver* pObserver);
        AMF_RESULT          (AMF_STD_CALL *CreateSurfaceFromHostNative)(AMFContext2* pThis, AMF_SURFACE_FORMAT format, amf_int32 width, amf_int32 height, amf_int32 hPitch, amf_int32 vPitch, void* pData,AMFSurface** ppSurface, AMFSurfaceObserver* pObserver);
        AMF_RESULT          (AMF_STD_CALL *CreateSurfaceFromDX9Native)(AMFContext2* pThis, void* pDX9Surface, AMFSurface** ppSurface, AMFSurfaceObserver* pObserver);
        AMF_RESULT          (AMF_STD_CALL *CreateSurfaceFromDX11Native)(AMFContext2* pThis, void* pDX11Surface, AMFSurface** ppSurface, AMFSurfaceObserver* pObserver);
        AMF_RESULT          (AMF_STD_CALL *CreateSurfaceFromOpenGLNative)(AMFContext2* pThis, AMF_SURFACE_FORMAT format, amf_handle hGLTextureID, AMFSurface** ppSurface, AMFSurfaceObserver* pObserver);
        AMF_RESULT          (AMF_STD_CALL *CreateSurfaceFromGrallocNative)(AMFContext2* pThis, amf_handle hGrallocSurface, AMFSurface** ppSurface, AMFSurfaceObserver* pObserver);
        AMF_RESULT          (AMF_STD_CALL *CreateSurfaceFromOpenCLNative)(AMFContext2* pThis, AMF_SURFACE_FORMAT format, amf_int32 width, amf_int32 height, void** pClPlanes, AMFSurface** ppSurface, AMFSurfaceObserver* pObserver);
        AMF_RESULT          (AMF_STD_CALL *CreateBufferFromOpenCLNative)(AMFContext2* pThis, void* pCLBuffer, amf_size size, AMFBuffer** ppBuffer);

        // Access to AMFCompute interface - AMF_MEMORY_OPENCL, AMF_MEMORY_COMPUTE_FOR_DX9, AMF_MEMORY_COMPUTE_FOR_DX11 are currently supported
        AMF_RESULT          (AMF_STD_CALL *GetCompute)(AMFContext2* pThis, AMF_MEMORY_TYPE eMemType, AMFCompute** ppCompute);

        // AMFContext1 interface

        AMF_RESULT          (AMF_STD_CALL *CreateBufferFromDX11Native)(AMFContext2* pThis, void* pHostBuffer, AMFBuffer** ppBuffer, AMFBufferObserver* pObserver);
        AMF_RESULT          (AMF_STD_CALL *AllocBufferEx)(AMFContext2* pThis, AMF_MEMORY_TYPE type, amf_size size, AMF_BUFFER_USAGE usage, AMF_MEMORY_CPU_ACCESS access, AMFBuffer** ppBuffer);
        AMF_RESULT          (AMF_STD_CALL *AllocSurfaceEx)(AMFContext2* pThis, AMF_MEMORY_TYPE type, AMF_SURFACE_FORMAT format, amf_int32 width, amf_int32 height, AMF_SURFACE_USAGE usage, AMF_MEMORY_CPU_ACCESS access, AMFSurface** ppSurface);

        // Vulkan - Windows, Linux
        AMF_RESULT          (AMF_STD_CALL *InitVulkan)(AMFContext2* pThis, void* pVulkanDevice);
        void*               (AMF_STD_CALL *GetVulkanDevice)(AMFContext2* pThis);
        AMF_RESULT          (AMF_STD_CALL *LockVulkan)(AMFContext2* pThis);
        AMF_RESULT          (AMF_STD_CALL *UnlockVulkan)(AMFContext2* pThis);

        AMF_RESULT          (AMF_STD_CALL *CreateSurfaceFromVulkanNative)(AMFContext2* pThis, void* pVulkanImage, AMFSurface** ppSurface, AMFSurfaceObserver* pObserver);
        AMF_RESULT          (AMF_STD_CALL *CreateBufferFromVulkanNative)(AMFContext2* pThis, void* pVulkanBuffer, AMFBuffer** ppBuffer, AMFBufferObserver* pObserver);
        AMF_RESULT          (AMF_STD_CALL *GetVulkanDeviceExtensions)(AMFContext2* pThis, amf_size *pCount, const char **ppExtensions);

        // AMFContext2 interface
        AMF_RESULT          (AMF_STD_CALL *InitDX12)(AMFContext2* pThis, void* pDX11Device, AMF_DX_VERSION dxVersionRequired);
        void*               (AMF_STD_CALL *GetDX12Device)(AMFContext2* pThis, AMF_DX_VERSION dxVersionRequired);
        AMF_RESULT          (AMF_STD_CALL *LockDX12)(AMFContext2* pThis);
        AMF_RESULT          (AMF_STD_CALL *UnlockDX12)(AMFContext2* pThis);

        AMF_RESULT          (AMF_STD_CALL *CreateSurfaceFromDX12Native)(AMFContext2* pThis, void* pResourceTexture, AMFSurface** ppSurface, AMFSurfaceObserver* pObserver);
        AMF_RESULT          (AMF_STD_CALL *CreateBufferFromDX12Native)(AMFContext2* pThis, void* pResourceBuffer, AMFBuffer** ppBuffer, AMFBufferObserver* pObserver);


    } AMFContext2Vtbl;

    struct AMFContext2
    {
        const AMFContext2Vtbl *pVtbl;
    };
#endif

#if defined(__cplusplus)
    //----------------------------------------------------------------------------------------------
    // Lockers
    //----------------------------------------------------------------------------------------------
    class AMFContext::AMFDX9Locker
    {
    public:
        AMFDX9Locker() : m_Context(NULL)
        {}
        AMFDX9Locker(AMFContext* resources) : m_Context(NULL)
        {
            Lock(resources);
        }
        ~AMFDX9Locker()
        {
            if(m_Context != NULL)
            {
                m_Context->UnlockDX9();
            }
        }
        void Lock(AMFContext* resources)
        {
            if(m_Context != NULL)
            {
                m_Context->UnlockDX9();
            }
            m_Context = resources;
            if(m_Context != NULL)
            {
                m_Context->LockDX9();
            }
        }
    protected:
        AMFContext* m_Context;

    private:
        AMFDX9Locker(const AMFDX9Locker&);
        AMFDX9Locker& operator=(const AMFDX9Locker&);
    };
    //----------------------------------------------------------------------------------------------
    class AMFContext::AMFDX11Locker
    {
    public:
        AMFDX11Locker() : m_Context(NULL)
        {}
        AMFDX11Locker(AMFContext* resources) : m_Context(NULL)
        {
            Lock(resources);
        }
        ~AMFDX11Locker()
        {
            if(m_Context != NULL)
            {
                m_Context->UnlockDX11();
            }
        }
        void Lock(AMFContext* resources)
        {
            if(m_Context != NULL)
            {
                m_Context->UnlockDX11();
            }
            m_Context = resources;
            if(m_Context != NULL)
            {
                m_Context->LockDX11();
            }
        }
    protected:
        AMFContext* m_Context;

    private:
        AMFDX11Locker(const AMFDX11Locker&);
        AMFDX11Locker& operator=(const AMFDX11Locker&);
    };
    //----------------------------------------------------------------------------------------------
    class AMFContext::AMFOpenCLLocker
    {
    public:
        AMFOpenCLLocker() : m_Context(NULL)
        {}
        AMFOpenCLLocker(AMFContext* resources) : m_Context(NULL)
        {
            Lock(resources);
        }
        ~AMFOpenCLLocker()
        {
            if(m_Context != NULL)
            {
                m_Context->UnlockOpenCL();
            }
        }
        void Lock(AMFContext* resources)
        {
            if(m_Context != NULL)
            {
                m_Context->UnlockOpenCL();
            }
            m_Context = resources;
            if(m_Context != NULL)
            {
                m_Context->LockOpenCL();
            }
        }
    protected:
        AMFContext* m_Context;
    private:
        AMFOpenCLLocker(const AMFOpenCLLocker&);
        AMFOpenCLLocker& operator=(const AMFOpenCLLocker&);
    };
    //----------------------------------------------------------------------------------------------
    class AMFContext::AMFOpenGLLocker
    {
    public:
        AMFOpenGLLocker(AMFContext* pContext) : m_pContext(pContext),
            m_GLLocked(false)
        {
            if(m_pContext != NULL)
            {
                if(m_pContext->LockOpenGL() == AMF_OK)
                {
                    m_GLLocked = true;
                }
            }
        }
        ~AMFOpenGLLocker()
        {
            if(m_GLLocked)
            {
                m_pContext->UnlockOpenGL();
            }
        }
    private:
        AMFContext* m_pContext;
        amf_bool m_GLLocked; ///< AMFOpenGLLocker can be called when OpenGL is not initialized yet
                             ///< in this case don't call UnlockOpenGL
        AMFOpenGLLocker(const AMFOpenGLLocker&);
        AMFOpenGLLocker& operator=(const AMFOpenGLLocker&);
    };
    //----------------------------------------------------------------------------------------------
    class AMFContext::AMFXVLocker
    {
    public:
        AMFXVLocker() : m_pContext(NULL)
        {}
        AMFXVLocker(AMFContext* pContext) : m_pContext(NULL)
        {
            Lock(pContext);
        }
        ~AMFXVLocker()
        {
            if(m_pContext != NULL)
            {
                m_pContext->UnlockXV();
            }
        }
        void Lock(AMFContext* pContext)
        {
            if((pContext != NULL) && (pContext->GetXVDevice() != NULL))
            {
                m_pContext = pContext;
                m_pContext->LockXV();
            }
        }
    protected:
        AMFContext* m_pContext;
    private:
        AMFXVLocker(const AMFXVLocker&);
        AMFXVLocker& operator=(const AMFXVLocker&);
    };
    //----------------------------------------------------------------------------------------------
    class AMFContext::AMFGrallocLocker
    {
    public:
        AMFGrallocLocker() : m_pContext(NULL)
        {}
        AMFGrallocLocker(AMFContext* pContext) : m_pContext(NULL)
        {
            Lock(pContext);
        }
        ~AMFGrallocLocker()
        {
            if(m_pContext != NULL)
            {
                m_pContext->UnlockGralloc();
            }
        }
        void Lock(AMFContext* pContext)
        {
            if((pContext != NULL) && (pContext->GetGrallocDevice() != NULL))
            {
                m_pContext = pContext;
                m_pContext->LockGralloc();
            }
        }
    protected:
        AMFContext* m_pContext;
    private:
        AMFGrallocLocker(const AMFGrallocLocker&);
        AMFGrallocLocker& operator=(const AMFGrallocLocker&);
    };
    //----------------------------------------------------------------------------------------------
    class AMFContext1::AMFVulkanLocker
    {
    public:
        AMFVulkanLocker() : m_pContext(NULL)
        {}
        AMFVulkanLocker(AMFContext1* pContext) : m_pContext(NULL)
        {
            Lock(pContext);
        }
        ~AMFVulkanLocker()
        {
            if(m_pContext != NULL)
            {
                m_pContext->UnlockVulkan();
            }
        }
        void Lock(AMFContext1* pContext)
        {
            if((pContext != NULL) && (pContext->GetVulkanDevice() != NULL))
            {
                m_pContext = pContext;
                m_pContext->LockVulkan();
            }
        }
    protected:
        AMFContext1* m_pContext;
    private:
        AMFVulkanLocker(const AMFVulkanLocker&);
        AMFVulkanLocker& operator=(const AMFVulkanLocker&);
    };
    //----------------------------------------------------------------------------------------------
    class AMFContext2::AMFDX12Locker
    {
    public:
        AMFDX12Locker() : m_Context(NULL)
        {}
        AMFDX12Locker(AMFContext2* resources) : m_Context(NULL)
        {
            Lock(resources);
        }
        ~AMFDX12Locker()
        {
            if (m_Context != NULL)
            {
                m_Context->UnlockDX12();
            }
        }
        void Lock(AMFContext2* resources)
        {
            if (m_Context != NULL)
            {
                m_Context->UnlockDX12();
            }
            m_Context = resources;
            if (m_Context != NULL)
            {
                m_Context->LockDX12();
            }
        }
    protected:
        AMFContext2* m_Context;

    private:
        AMFDX12Locker(const AMFDX12Locker&);
        AMFDX12Locker& operator=(const AMFDX12Locker&);
    };
    //----------------------------------------------------------------------------------------------
    //----------------------------------------------------------------------------------------------
    //----------------------------------------------------------------------------------------------
#endif
#if defined(__cplusplus)
}
#endif
enum AMF_CONTEXT_DEVICETYPE_ENUM
{
    AMF_CONTEXT_DEVICE_TYPE_GPU = 0,
    AMF_CONTEXT_DEVICE_TYPE_CPU
};
#define AMF_CONTEXT_DEVICE_TYPE  L"AMF_Context_DeviceType" //Value type: amf_int64; Values : AMF_CONTEXT_DEVICE_TYPE_GPU for GPU (default) , AMF_CONTEXT_DEVICE_TYPE_CPU for CPU.
#endif //#ifndef AMF_Context_h