Suhail Doshi
Suhail Doshi

Reputation: 776

ActivateObject: Exception unhandled

I am trying to use Media Foundation Transforms & I hit a snag where when I use MFTEnumEx, get 1 encoder back, and use ActivateObject I get this error: Unhandled exception at 0x00007FF9C7084078 in endec.exe: Microsoft C++ exception: std::runtime_error at memory location 0x00000056FF75CC38. occurred at activate[0]->ActivateObject(IID_PPV_ARGS(&encoder))

Microsoft Windows Server 2016 Datacenter. 10.0.14393 N/A Build 14393. x64.

Code:

IMFTransform* get_encoder() {
    ComPtr<IMFTransform> encoder = NULL;
    IMFActivate **activate = nullptr;

    uint32_t flags = MFT_ENUM_FLAG_HARDWARE | MFT_ENUM_FLAG_SORTANDFILTER;

    // Unused for testing...
    MFT_REGISTER_TYPE_INFO input_info;// = NULL; // NULL pInputType means "match all"
    MFT_REGISTER_TYPE_INFO output_info;

    input_info.guidMajorType = MFMediaType_Video;
    input_info.guidSubtype = MFVideoFormat_ARGB32;

    output_info.guidMajorType = MFMediaType_Video;
    output_info.guidSubtype = MFVideoFormat_NV12;

    CLSID *clsids = NULL;
    uint32_t count = 0;
    _com_error error = NULL;

    //error = MFTEnum(MFT_CATEGORY_VIDEO_PROCESSOR, flags, input_info, &output_info, NULL, &clsids, &count);
    ThrowIfFailed(MFTEnumEx(MFT_CATEGORY_VIDEO_ENCODER, flags, NULL, NULL, &activate, &count), 
        &count, "Unexpected error occurred with finding encoders"); // <--- ERROR

    if (!count && !activate[0]) {
        cout << "Did not find any encoders...\n";
        return nullptr;
    }

    cout << "Number of encoders available: " << count << endl;

    if (!activate[0]) {
        cout << "Couldn't get a valid activate obj\n";
    }

    ThrowIfFailed(activate[0]->ActivateObject(IID_PPV_ARGS(&encoder)), &flags,
        "Wasn't able to activate encoder");

    return encoder.Get();
}

Local variables at time of exception:

+       activate    0x0000016ebc24db20 {0x0000016ebdb1d950 {...}}   IMFActivate * *
+       clsids  0x0000000000000000 <NULL>   _GUID *
        count   1   unsigned int
+       encoder 0x0000000000000000 <NULL>   Microsoft::WRL::ComPtr<IMFTransform>
+       error   {S_OK}  _com_error
        flags   68  unsigned int
+       input_info  {guidMajorType={73646976-0000-0010-8000-00AA00389B71} guidSubtype={00000015-0000-0010-8000-00AA00389B71} }  __MIDL___MIDL_itf_mfobjects_0000_0008_0003
+       output_info {guidMajorType={73646976-0000-0010-8000-00AA00389B71} guidSubtype={3231564E-0000-0010-8000-00AA00389B71} }  __MIDL___MIDL_itf_mfobjects_0000_0008_0003```

Upvotes: 0

Views: 223

Answers (1)

mofo77
mofo77

Reputation: 1515

Did you call CoInitializeEx and MFStartup ?

HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);

and

HRESULT hr = MFStartup(MF_VERSION, MFSTARTUP_LITE);

It's an example, use needed parameters.

At minimum, you need CoInitializeEx for your function "get_encoder".

Possibly, Microsoft Windows Server 2016 Datacenter can't do hardware encoding, because of hardware/software configurations, even if there is a hardware encoder registered.

For example, some multimedia services running missing.

Upvotes: 1

Related Questions