Debian Codegraph @

doc/spec/source/snippets/prg_config.cpp

raw
1 /*############################################################################
2 # Copyright (C) 2020 Intel Corporation
3 #
4 # SPDX-License-Identifier: MIT
5 ############################################################################*/
6
7 // Example using Intel® Video Processing Library (Intel® VPL)
8 #include <vector>
9
10 #include <stdlib.h>
11
12 #include "mfxdefs.h"
13 #include "mfxstructures.h"
14 #include "mfxsession.h"
15 #include "mfxvideo.h"
16
17 /* These macro required for code compilation. */
18 #define UNUSED_PARAM(x) (void)(x)
19
20 static mfxSession session;
21 static mfxStatus sts;
22 static std::vector<mfxExtBuffer *>extBufVector;
23
24 static void prg_config1() {
25 /*beg1*/
26
27 // call MFXVideoCORE_GetHandle to obtain mfxConfigInterface
28 mfxConfigInterface *iface = nullptr;
29 sts = MFXVideoCORE_GetHandle(session, MFX_HANDLE_CONFIG_INTERFACE, (mfxHDL *)(&iface));
30
31 // Alternately, we could use the following alias:
32 // sts = MFXGetConfigInterface(session, &iface);
33
34 // pass string parameter which maps to mfxVideoParam
35 mfxVideoParam par = {};
36 mfxExtBuffer extBuf = {};
37 sts = iface->SetParameter(iface, (mfxU8 *)"TargetKbps", (mfxU8 *)"1650", MFX_STRUCTURE_TYPE_VIDEO_PARAM, &par, &extBuf);
38
39 /*end1*/
40 }
41
42 static mfxStatus prg_config2 () {
43 /*beg2*/
44
45 // call MFXGetConfigInterface() to obtain mfxConfigInterface
46 mfxConfigInterface *iface = nullptr;
47 sts = MFXGetConfigInterface(session, &iface);
48
49 // pass string parameter which maps to an Intel® VPL extension buffer
50 mfxVideoParam par = {};
51 mfxExtBuffer extBuf = {};
52 sts = iface->SetParameter(iface, (mfxU8 *)"mfxExtHEVCParam.PicWidthInLumaSamples", (mfxU8 *)"640", MFX_STRUCTURE_TYPE_VIDEO_PARAM, &par, &extBuf);
53
54 // if extension buffer has not already been attached, allocate it and call again
55 if (sts == MFX_ERR_MORE_EXTBUFFER) {
56 // the first call to SetParameter filled in extBuf with the buffer ID and size to allocate
57 mfxExtBuffer *extBufNew = (mfxExtBuffer *)calloc(extBuf.BufferSz, 1);
58 if (!extBufNew)
59 return MFX_ERR_MEMORY_ALLOC;
60
61 extBufNew->BufferId = extBuf.BufferId;
62 extBufNew->BufferSz = extBuf.BufferSz;
63
64 extBufVector.push_back(extBufNew);
65 par.NumExtParam = static_cast<mfxU16>(extBufVector.size());
66 par.ExtParam = extBufVector.data();
67
68 // the correct extension buffer is now attached, so the call should succeed this time
69 sts = iface->SetParameter(iface, (mfxU8 *)"mfxExtHEVCParam.PicWidthInLumaSamples", (mfxU8 *)"640", MFX_STRUCTURE_TYPE_VIDEO_PARAM, &par, &extBuf);
70
71 if (sts != MFX_ERR_NONE)
72 return sts;
73 }
74
75 return MFX_ERR_NONE;
76 /*end2*/
77 }