Parameter Configuration#

Intel® VPL API 2.10 introduces a new interface for configuring Intel® VPL for encode, decode, or video processing. Applications may optionally use the new function mfxConfigInterface::SetParameter to fill in data structures used for initialization, including mfxVideoParam and extension buffers of type mfxExtBuffer.

mfxConfigInterface::SetParameter accepts as input key-value pairs of char * strings, converts these strings to appropriate C data types, and writes the results into the application-provided initialization structures. This can provide a simpler and more flexible initialization method for applications which accept user input in the form of strings, or which store configuration information in formats such as XML, YAML, or JSON.

Applications may freely mix use of mfxConfigInterface::SetParameter with standard C-style initialization of the same structures. Additionally, the use of mfxConfigInterface::SetParameter facilitates support of new parameters which may be added to Intel® VPL API in the future. When new extension buffers are added to Intel® VPL API, mfxConfigInterface::SetParameter will enable the application to allocate buffers of the appropriate size, and initialize them with the required values, without recompiling the application.

Setting a parameter in mfxVideoParam#

The following code snippet shows an example of setting a parameter in the structure mfxVideoParam.

 1// call MFXVideoCORE_GetHandle to obtain mfxConfigInterface
 2mfxConfigInterface *iface = nullptr;
 3sts = MFXVideoCORE_GetHandle(session, MFX_HANDLE_CONFIG_INTERFACE, (mfxHDL *)(&iface));
 4
 5// Alternately, we could use the following alias:
 6// sts = MFXGetConfigInterface(session, &iface);
 7
 8// pass string parameter which maps to mfxVideoParam
 9mfxVideoParam par   = {};
10mfxExtBuffer extBuf = {};
11sts = iface->SetParameter(iface, (mfxU8 *)"TargetKbps", (mfxU8 *)"1650", MFX_STRUCTURE_TYPE_VIDEO_PARAM, &par, &extBuf);

Setting a parameter in an extension buffer#

The following code snippet shows an example of setting a parameter in the extension buffer mfxExtHEVCParam and attaching it to the structure mfxVideoParam.

When setting a parameter which maps to an extension buffer, the function first checks whether the required extension buffer has been attached to the provided mfxVideoParam. If so, Intel® VPL will update the corresponding field in the extension buffer and return MFX_ERR_NONE.

If the required extension buffer is not attached, Intel® VPL will instead return MFX_ERR_MORE_EXTBUFFER. If this happens, the application is required to allocate an extension buffer whose size and buffer ID are indicated by the ext_buffer parameter returned from the call to mfxConfigInterface::SetParameter. This extension buffer must then be attached to mfxVideoParam, then mfxConfigInterface::SetParameter should be called again with the same arguments. If the key and value strings represent a valid parameter in the newly-attached extension buffer, the function will now return MFX_ERR_NONE.

 1// call MFXGetConfigInterface() to obtain mfxConfigInterface
 2mfxConfigInterface *iface = nullptr;
 3sts = MFXGetConfigInterface(session, &iface);
 4
 5// pass string parameter which maps to an Intel® VPL extension buffer
 6mfxVideoParam par   = {};
 7mfxExtBuffer extBuf = {};
 8sts = iface->SetParameter(iface, (mfxU8 *)"mfxExtHEVCParam.PicWidthInLumaSamples", (mfxU8 *)"640", MFX_STRUCTURE_TYPE_VIDEO_PARAM, &par, &extBuf);
 9
10// if extension buffer has not already been attached, allocate it and call again
11if (sts == MFX_ERR_MORE_EXTBUFFER) {
12    // the first call to SetParameter filled in extBuf with the buffer ID and size to allocate
13    mfxExtBuffer *extBufNew = (mfxExtBuffer *)calloc(extBuf.BufferSz, 1);
14    if (!extBufNew)
15        return MFX_ERR_MEMORY_ALLOC;
16
17    extBufNew->BufferId = extBuf.BufferId;
18    extBufNew->BufferSz = extBuf.BufferSz;
19
20    extBufVector.push_back(extBufNew);
21    par.NumExtParam = static_cast<mfxU16>(extBufVector.size());
22    par.ExtParam    = extBufVector.data();
23
24    // the correct extension buffer is now attached, so the call should succeed this time
25    sts = iface->SetParameter(iface, (mfxU8 *)"mfxExtHEVCParam.PicWidthInLumaSamples", (mfxU8 *)"640", MFX_STRUCTURE_TYPE_VIDEO_PARAM, &par, &extBuf);
26
27    if (sts != MFX_ERR_NONE)
28        return sts;
29    }
30
31return MFX_ERR_NONE;