Possible bug with initialization and MFXClose ?

Possible bug with initialization and MFXClose ?

Portrait de Jack Chimasera

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;
}

9 posts / 0 nouveau(x)
Dernière contribution
Reportez-vous à notre Notice d'optimisation pour plus d'informations sur les choix et l'optimisation des performances dans les produits logiciels Intel.
Portrait de Vassili Yakovlev

Hi Jack!

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

Kind regards,

Portrait de Petter Larsson (Intel)

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

Portrait de Jack Chimasera

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

Portrait de Petter Larsson (Intel)

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.

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;

Regards, Petter

Portrait de Eric Gur (Intel)

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.

Eric Gur, Intel QuickSync Decoder Author Processor Client Application Engineer Intel Corp.
Portrait de Jack Chimasera

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

Portrait de Petter Larsson (Intel)

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

Portrait de Eric Gur (Intel)

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.

Eric Gur, Intel QuickSync Decoder Author Processor Client Application Engineer Intel Corp.

Connectez-vous pour laisser un commentaire.