Debian Codegraph @

doc/spec/source/snippets/prg_session.cpp

raw
1 /*############################################################################
2 # Copyright (C) 2020 Intel Corporation
3 #
4 # SPDX-License-Identifier: MIT
5 ############################################################################*/
6
7 #include "mfxdefs.h"
8 #include "mfxdispatcher.h"
9 #include "mfxstructures.h"
10
11 #include <iostream>
12 #include <algorithm>
13
14 mfxLoader loader = 0;
15 int idx = 0;
16
17 static void prg_session1 () {
18 /*beg1*/
19 mfxHDL h;
20 // request pointer to the list. Assume that implementation supports that.
21 // Assume that `loader` is configured before.
22 mfxStatus sts = MFXEnumImplementations(loader, idx, MFX_IMPLCAPS_IMPLEMENTEDFUNCTIONS, &h);
23 // break if no idx
24 if (sts != MFX_ERR_NOT_FOUND) {
25 // Cast typeless handle to structure pointer
26 mfxImplementedFunctions *implemented_functions = (mfxImplementedFunctions*)h;
27
28 // print out list of functions' name
29 std::for_each(implemented_functions->FunctionsName, implemented_functions->FunctionsName +
30 implemented_functions->NumFunctions,
31 [](mfxChar* functionName) {
32 std::cout << functionName << " is implemented" << std::endl;
33 });
34 // Release resource
35 MFXDispReleaseImplDescription(loader, h);
36 }
37 /*end1*/
38 }
39
40 static void prg_session2 () {
41 /*beg2*/
42 mfxSession session_handle;
43 loader = mfxLoader();
44
45 // We want to search for the implementation with Decode+VPP domain functions support.
46 // i.e we search for the MFXVideoDECODE_VPP_Init and MFXVideoDECODE_VPP_DecodeFrameAsync
47 // implemented functions
48 mfxConfig init_funct_prop = MFXCreateConfig(loader);
49 mfxVariant value;
50
51 // Filter property for the Init function
52 value.Type = mfxVariantType::MFX_VARIANT_TYPE_PTR;
53 value.Data.Ptr = (mfxHDL)"MFXVideoDECODE_VPP_Init";
54 MFXSetConfigFilterProperty(init_funct_prop, (const mfxU8*)"mfxImplementedFunctions.FunctionsName",
55 value);
56
57 // Filter property for the Process function
58 mfxConfig process_func_prop = MFXCreateConfig(loader);
59 value.Data.Ptr = (mfxHDL)"MFXVideoDECODE_VPP_DecodeFrameAsync";
60 MFXSetConfigFilterProperty(process_func_prop, (const mfxU8*)"mfxImplementedFunctions.FunctionsName",
61 value);
62
63 // create session from first matched implementation
64 MFXCreateSession(loader, 0, &session_handle);
65 /*end2*/
66 }
67
68 static void prg_session3 () {
69 /*beg3*/
70 mfxSession hevc_session_handle;
71 loader = mfxLoader();
72
73 // We want to search for the HEVC decoder implementation
74 mfxConfig hevc_decoder_config = MFXCreateConfig(loader);
75 mfxVariant value;
76
77 // Filter property for the implementations with HEVC decoder
78 value.Type = MFX_VARIANT_TYPE_U32;
79 value.Data.U32 = MFX_CODEC_HEVC;
80
81 MFXSetConfigFilterProperty(hevc_decoder_config
82 , (const mfxU8*)"mfxImplDescription.mfxDecoderDescription.decoder.CodecID"
83 , value);
84
85 // create session from first matched implementation
86 MFXCreateSession(loader, 0, &hevc_session_handle);
87 /*end3*/
88 }
89
90 static void prg_session4 () {
91 /*beg4*/
92 mfxSession mirror_session_handle;
93 loader = mfxLoader();
94
95 // We want to search for the VPP mirror implementation
96 mfxConfig mirror_flt_config = MFXCreateConfig(loader);
97 mfxVariant value;
98
99 // Filter property for the implementations with VPP mirror
100 value.Type = MFX_VARIANT_TYPE_U32;
101 value.Data.U32 = MFX_EXTBUFF_VPP_MIRRORING;
102
103 MFXSetConfigFilterProperty(mirror_flt_config
104 , (const mfxU8*)"mfxImplDescription.mfxVPPDescription.filter.FilterFourCC"
105 , value);
106
107 // create session from first matched implementation
108 MFXCreateSession(loader, 0, &mirror_session_handle);
109 /*end4*/
110 }
111
112 static void prg_session5 () {
113 /*beg5*/
114 mfxHDL h;
115 mfxSession def_session;
116
117 loader = mfxLoader();
118
119 // Create session from the first available implementation.
120 // That's why we no any filters need to be set.
121 // First available implementation has index equal to the 0.
122 MFXCreateSession(loader, 0, &def_session);
123
124 // Get and print out OS path to the loaded shared library
125 // with the implementation. It is absolutely OK to call
126 // MFXEnumImplementations after session creation just need to make
127 // sure that the same index of implementation is provided to the
128 // function call.
129 MFXEnumImplementations(loader, 0, MFX_IMPLCAPS_IMPLPATH, &h);
130 mfxChar* path = reinterpret_cast<mfxChar*>(h);
131
132 // Print out the path
133 std::cout << "Loaded shared library: " << path << std::endl;
134
135 // Release the memory for the string with path.
136 MFXDispReleaseImplDescription(loader, h);
137 /*end5*/
138 }
139
140 mfxSession session;
141
142 static void prg_session6 () {
143 /*beg6*/
144 mfxLoader loader = MFXLoad();
145
146 int i = 0;
147 mfxImplDescription *idesc;
148 mfxStructVersion minVersionEncoderDescription = { {1, 1} };
149 while (MFX_ERR_NONE == MFXEnumImplementations(loader, i, MFX_IMPLCAPS_IMPLDESCSTRUCTURE,
150 reinterpret_cast<mfxHDL *>(&idesc))) {
151 mfxEncoderDescription *enc = &idesc->Enc;
152 for (int codec = 0; codec < enc->NumCodecs; codec++) {
153 printf("%4sCodecID: %u\n", "", enc->Codecs[codec].CodecID);
154 printf("%4sMaxcodecLevel: %hu\n", "", enc->Codecs[codec].MaxcodecLevel);
155 printf("%4sBiDirectionalPrediction: %hu\n", "",
156 enc->Codecs[codec].BiDirectionalPrediction);
157 if (enc->Version.Version >= minVersionEncoderDescription.Version) {
158 if (enc->Codecs[codec].EncExtDesc) {
159 printf("%4sRateControlMethods: ", "");
160 for (int RateControls = 0;
161 RateControls < enc->Codecs[codec].EncExtDesc->NumRateControlMethods;
162 RateControls++) {
163 if (0 != RateControls)
164 printf(", ");
165 printf("%hu", enc->Codecs[codec].EncExtDesc->RateControlMethods[RateControls]);
166 }
167 printf("\n");
168 printf("%4sExtBuffers: ", "");
169 for (int ExtBufs = 0; ExtBufs < enc->Codecs[codec].EncExtDesc->NumExtBufferIDs;
170 ExtBufs++) {
171 if (0 != ExtBufs)
172 printf(", ");
173 printf("%u", enc->Codecs[codec].EncExtDesc->ExtBufferIDs[ExtBufs]);
174 }
175 printf("\n");
176 }
177 }
178 for (int profile = 0; profile < enc->Codecs[codec].NumProfiles; profile++) {
179 printf("%6sProfile: %u\n", "", enc->Codecs[codec].Profiles[profile].Profile);
180 for (int memtype = 0; memtype < enc->Codecs[codec].Profiles[profile].NumMemTypes;
181 memtype++) {
182 printf("%8sMemHandleType: %u\n", "",
183 enc->Codecs[codec].Profiles[profile].MemDesc[memtype].MemHandleType);
184 printf("%10sWidth Min: %u\n", "",
185 enc->Codecs[codec].Profiles[profile].MemDesc[memtype].Width.Min);
186 printf("%10sWidth Max: %u\n", "",
187 enc->Codecs[codec].Profiles[profile].MemDesc[memtype].Width.Max);
188 printf("%10sWidth Step: %u\n", "",
189 enc->Codecs[codec].Profiles[profile].MemDesc[memtype].Width.Step);
190 printf("%10sHeight Min: %u\n", "",
191 enc->Codecs[codec].Profiles[profile].MemDesc[memtype].Height.Min);
192 printf("%10sHeight Max: %u\n", "",
193 enc->Codecs[codec].Profiles[profile].MemDesc[memtype].Height.Max);
194 printf("%10sHeight Step: %u\n", "",
195 enc->Codecs[codec].Profiles[profile].MemDesc[memtype].Height.Step);
196
197 if (enc->Version.Version >= minVersionEncoderDescription.Version) {
198 if (enc->Codecs[codec].Profiles[profile].MemDesc[memtype].MemExtDesc) {
199 printf("%10sTargetMaxBitDepth: %hu\n", "",
200 enc->Codecs[codec].Profiles[profile].MemDesc[memtype]
201 .MemExtDesc->TargetMaxBitDepth);
202 printf("%10sTargetChromaSubsamplings: ", "");
203 for (int ChromaSubsampling = 0;
204 ChromaSubsampling <
205 enc->Codecs[codec].Profiles[profile].MemDesc[memtype]
206 .MemExtDesc->NumTargetChromaSubsamplings;
207 ChromaSubsampling++) {
208 if (0 != ChromaSubsampling)
209 printf(", ");
210 printf("%hu",enc->Codecs[codec].Profiles[profile]
211 .MemDesc[memtype].MemExtDesc
212 ->TargetChromaSubsamplings[ChromaSubsampling]);
213 }
214 printf("\n");
215 }
216 }
217
218 printf("%10sColorFormats: ", "");
219 for (int colorformat = 0;
220 colorformat <
221 enc->Codecs[codec].Profiles[profile].MemDesc[memtype].NumColorFormats;
222 colorformat++) {
223 if (0 != colorformat)
224 printf(", ");
225 printf("%u", enc->Codecs[codec].Profiles[profile]
226 .MemDesc[memtype].ColorFormats[colorformat]);
227 }
228 printf("\n");
229 }
230 }
231 }
232
233 // Release resource
234 MFXDispReleaseImplDescription(loader, idesc);
235
236 i++;
237 }
238
239 // create session from first matched implementation
240 MFXCreateSession(loader, 0, &session);
241
242 /*end6*/
243 }
244
245 static void prg_session7 () {
246 /*beg7*/
247 mfxLoader loader = MFXLoad();
248 mfxConfig cfg = MFXCreateConfig(loader);
249 mfxVariant ImplValue;
250 ImplValue.Type = static_cast<mfxVariantType>(MFX_VARIANT_TYPE_U32 | MFX_VARIANT_TYPE_QUERY);
251 ImplValue.Data.U32 = 0;
252
253 //Only need shallow info for session creation
254 MFXSetConfigFilterProperty(cfg,(const mfxU8 *)"mfxImplDescription",ImplValue);
255
256 // create session from first matched implementation
257 MFXCreateSession(loader, 0, &session);
258 /*end7*/
259 }
260
261 static void prg_session8 () {
262 /*beg8*/
263 mfxLoader loader = MFXLoad();
264 mfxConfig cfg = MFXCreateConfig(loader);
265 mfxVariant ImplValue;
266 ImplValue.Type = static_cast<mfxVariantType>(MFX_VARIANT_TYPE_U32 | MFX_VARIANT_TYPE_QUERY);
267 ImplValue.Data.U32 = 0;
268
269 //Only need shallow info for exploring implementations
270 MFXSetConfigFilterProperty(cfg,(const mfxU8 *)"mfxImplDescription",ImplValue);
271
272 int i = 0;
273 mfxImplDescription *idesc;
274 while (MFX_ERR_NONE == MFXEnumImplementations(loader, i, MFX_IMPLCAPS_IMPLDESCSTRUCTURE,
275 reinterpret_cast<mfxHDL *>(&idesc))) {
276 printf("\nImplementation #%d: %s\n", i, idesc->ImplName);
277
278 printf("%2sApiVersion: %hu.%hu\n", "", idesc->ApiVersion.Major, idesc->ApiVersion.Minor);
279 printf("%2sVendorImplID: 0x%04X\n", "", idesc->VendorImplID);
280 printf("%2sVendorID: 0x%04X\n", "", idesc->VendorID);
281
282 /* mfxDeviceDescription */
283 mfxDeviceDescription *dev = &idesc->Dev;
284 printf("%2smfxDeviceDescription:\n", "");
285 printf("%4sDeviceID: %s\n", "", dev->DeviceID);
286
287 // Release resource
288 MFXDispReleaseImplDescription(loader, idesc);
289
290 i++;
291 }
292 /*end8*/
293 }
294
295 static void prg_session9 () {
296 /*beg9*/
297 mfxLoader loader = MFXLoad();
298 mfxConfig cfg = MFXCreateConfig(loader);
299 mfxVariant ImplValue;
300 ImplValue.Type = static_cast<mfxVariantType>(MFX_VARIANT_TYPE_U32 | MFX_VARIANT_TYPE_QUERY);
301 ImplValue.Data.U32 = 0;
302
303 //To find decoders for session creation
304 MFXSetConfigFilterProperty(cfg,(const mfxU8 *)"mfxImplDescription.mfxDecoderDescription",ImplValue);
305
306 // create session from first matched implementation
307 MFXCreateSession(loader, 0, &session);
308 /*end9*/
309 }
310
311 static void prg_session10 () {
312 /*beg10*/
313 mfxLoader loader = MFXLoad();
314 mfxConfig cfg = MFXCreateConfig(loader);
315 mfxVariant ImplValue;
316 ImplValue.Type = static_cast<mfxVariantType>(MFX_VARIANT_TYPE_U32 | MFX_VARIANT_TYPE_QUERY);
317 ImplValue.Data.U32 = MFX_CODEC_AV1;
318
319 //To find AV1 encoder for session creation
320 MFXSetConfigFilterProperty(cfg,(const mfxU8 *)"mfxImplDescription.mfxEncoderDescription.encoder.CodecID",ImplValue);
321
322 // create session from first matched implementation
323 // which supports AV1 encoder
324 MFXCreateSession(loader, 0, &session);
325 /*end10*/
326 }
327
328 static void prg_session11 () {
329 /*beg11*/
330 mfxLoader loader = MFXLoad();
331 mfxConfig cfg = MFXCreateConfig(loader);
332 mfxVariant ImplValue;
333 ImplValue.Type = static_cast<mfxVariantType>(MFX_VARIANT_TYPE_U32 | MFX_VARIANT_TYPE_QUERY);
334 ImplValue.Data.U32 = 0;
335
336 //To find VPP filters for session creation
337 MFXSetConfigFilterProperty(cfg,(const mfxU8 *)"mfxImplDescription.mfxVPPDescription",ImplValue);
338
339 // create session from first matched implementation
340 MFXCreateSession(loader, 0, &session);
341 /*end11*/
342 }
343
344 static void prg_session12 () {
345 /*beg12*/
346 mfxLoader loader = MFXLoad();
347 mfxConfig cfg = MFXCreateConfig(loader);
348 mfxVariant ImplValue;
349 ImplValue.Type = static_cast<mfxVariantType>(MFX_VARIANT_TYPE_U32 | MFX_VARIANT_TYPE_QUERY);
350 ImplValue.Data.U32 = MFX_CODEC_AV1;
351
352 //To get AV1 encoder capabilities
353 MFXSetConfigFilterProperty(cfg,(const mfxU8 *)"mfxImplDescription.mfxEncoderDescription.encoder.CodecID",ImplValue);
354
355 int i = 0;
356 mfxImplDescription *idesc;
357 while (MFX_ERR_NONE == MFXEnumImplementations(loader, i, MFX_IMPLCAPS_IMPLDESCSTRUCTURE,
358 reinterpret_cast<mfxHDL *>(&idesc))) {
359 mfxEncoderDescription *enc = &idesc->Enc;
360 for (int codec = 0; codec < enc->NumCodecs; codec++) {
361 printf("%4sCodecID: %u\n", "", enc->Codecs[codec].CodecID);
362 printf("%4sMaxcodecLevel: %hu\n", "", enc->Codecs[codec].MaxcodecLevel);
363 printf("%4sBiDirectionalPrediction: %hu\n", "",
364 enc->Codecs[codec].BiDirectionalPrediction);
365 for (int profile = 0; profile < enc->Codecs[codec].NumProfiles; profile++) {
366 printf("%6sProfile: %u\n", "", enc->Codecs[codec].Profiles[profile].Profile);
367 }
368 }
369
370 // Release resource
371 MFXDispReleaseImplDescription(loader, idesc);
372
373 i++;
374 }
375
376 // create session from first matched implementation
377 // which supports AV1 encoder
378 MFXCreateSession(loader, 0, &session);
379 /*end12*/
380 }