Media (Intel® Video Processing Library, Intel Media SDK)
Access community support with transcoding, decoding, and encoding in applications using media tools like Intel® oneAPI Video Processing Library and Intel® Media SDK
Announcements
The Intel Media SDK project is no longer active. For continued support and access to new features, Intel Media SDK users are encouraged to read the transition guide on upgrading from Intel® Media SDK to Intel® Video Processing Library (VPL), and to move to VPL as soon as possible.
For more information, see the VPL website.

Possible bug with initialization and MFXClose ?

Jack_Chimasera
Beginner
463 Views
Hello
I have added an auto-detection piece of code to our software, where it tries to initialize a hardware encoder, and if that fails, uses a non-intel encoder (mostly for older hardware and non Intel hardware).
The function, as shown below, tries to initialize the encoder, then asks for the implementation (hardware/software). No matter what the result is, when MFXClose is called, the program crashes, while my understanding from the documentation is that it should work fine. What am I missing ?

regards

Jack

UINT8 QSVEncodingAvailable()
{
mfxVersion ver = {0, 1};
mfxSession EncoderSession;
mfxStatus Status=MFXInit (MFX_IMPL_AUTO_ANY,&ver,&EncoderSession);
if (Status!=MFX_ERR_NONE)
{
SHOWMSG(DBGID_ENCODER, DBG_LEVEL_TRACE1, ("QSVEncodingAvailable failed : Init failed=%d\\n", Status));
// Removed, May cause a leak, but it appears to be an intel bug. When not initializing fully, crashes when this line is reached
// MFXClose (EncoderSession);
return false;
}

mfxIMPL Implementation;
Status=MFXQueryIMPL (EncoderSession,&Implementation);
if (Status!=MFX_ERR_NONE)
{
SHOWMSG(DBGID_ENCODER, DBG_LEVEL_TRACE1, ("QSVEncodingAvailable failed : mfxQueryIMPL failed=%d\\n", Status));
// Removed, May cause a leak, but it appears to be an intel bug. When not initializing fully, crashes when this line is reached
// MFXClose (EncoderSession);
return false;
}
// Removed, May cause a leak, but it appears to be an intel bug. When not initializing fully, crashes when this line is reached
//MFXClose (EncoderSession);
//if (Implementation==MFX_IMPL_SOFTWARE)
//{
// SHOWMSG(DBGID_ENCODER, DBG_LEVEL_TRACE1, ("QSVEncodingAvailable failed : Software-only implementation found\\n"));
// return false;
//}
SHOWMSG(DBGID_ENCODER, DBG_LEVEL_TRACE1, ("QSVEncodingAvailable tested and working\\n"));
return true;
}

0 Kudos
8 Replies
Vassili_Yakovlev
Beginner
463 Views
Hi Jack!

May be there is another (global)variable with same name as localEncoderSession also declared globally and which is not initialized?

Kind regards,
0 Kudos
Petter_L_Intel
Employee
463 Views
Jack,

the behavior you describe is certainly strange. We have do not observe any issues using the same set of operations.

What version of Media SDK are you using?

Regards,
Petter
0 Kudos
Jack_Chimasera
Beginner
463 Views
Hello Petter
I use the "gold" version 3.0, A.K.A Media SDK 2012. is there a newer one ?
I have copied the code above into its own project, and encountered the same behaviour (after un-commenting the MFXClode, that is).

regards

Jack
0 Kudos
Petter_L_Intel
Employee
463 Views
Hi Jack,

We have not seen the issues you report with either the Media SDK 2012 or the new Media SDK 2012 R2, which is available on the Media SDK site.

Just as a sanity check I quickly tested this with a derivative of the code you provided. Works on my end without any crash. I'm guessing that something else is getting corrupted in your environment.

[cpp]mfxVersion ver = {0, 1}; 
mfxSession EncoderSession;
mfxStatus Status=MFXInit (MFX_IMPL_AUTO_ANY,&ver,&EncoderSession); 
if (Status!=MFX_ERR_NONE)
{
    MFXClose (EncoderSession);
    return 1;
}
mfxIMPL Implementation;
Status=MFXQueryIMPL (EncoderSession,&Implementation);
if (Status!=MFX_ERR_NONE)
{
    MFXClose (EncoderSession);
    return 1;
}
MFXClose (EncoderSession);
return 0;[/cpp]


Regards,
Petter
0 Kudos
Ariel_G_Intel
Employee
463 Views
Hi,
Here're my 3 cents:
1) Failed to create a session - don't close it, nothing to close. Should be no leak as a session wasn't created. If you see a leak, this is an MSDK bug.
2) You should not assume that data (or handles) are valid if the called function returns with an error.
3) Setting the session handle to NULL at least allows the MSDK to do paramter checks, if it's garbage, it might crash.
0 Kudos
Jack_Chimasera
Beginner
463 Views
Hello Eric

What you say makes sense, and that's how I've done that initially, until I read the following passage in the manual (mediasdk-man.pdf) :

The function MFXInit starts (initializes) an SDK session. MFXClose closes (de-initializes) the SDK session. To avoid memory leaks, always call MFXClose after MFXInit, even if MFXInit returns an error code.

So... perhaps the documentation needs to be corrected ?

regards

Jack
0 Kudos
Petter_L_Intel
Employee
463 Views
Hi Jack,

It is ok to Close the session even though it was not properly initialized. However, it is not necessary as Eric pointed out. There are no memory leaks associated with this.

We will work on improving the manual to avoid confusion on this topic.

Regards,
Petter
0 Kudos
Ariel_G_Intel
Employee
463 Views
Another option is that the init function should zero the session handle on failure. It also indicates to the user that there's nothing to close.
0 Kudos
Reply