ForbiddenSoul
ForbiddenSoul

Reputation: 138

IMFSinkWriter : The request is invalid because Shutdown() has been called

Just testing out some simple audio to mp3 stuff.

I am trying to use a IMFSinkWriter, to actually Encode the audio and save it to disk.

I can not even get the IMFSinkWriter created properly. This must be some noob question or a really weird error...

#include <iostream>
#include <mfidl.h>
#include <Mfreadwrite.h>
#pragma comment(lib, "Mfreadwrite.lib")
int main()
{
    IMFSinkWriter* pSinkWriter;
    HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
    std::cout << std::system_category().message(hr) << "\n";
    hr = MFCreateSinkWriterFromURL(L"Recording.mp3", NULL, NULL, &pSinkWriter);
    std::cout << std::system_category().message(hr) << "\n";
    system("pause");
}

Output:

The operation completed successfully.

The request is invalid because Shutdown() has been called.

Press any key to continue . . .

I may need to call "CoCreateInstance(__uuidof(SOMETHING), NULL, CLSCTX_ALL, __uuidof(IMFSinkWriter), (void**)&pSinkWriter);", but I am unsure of what SOMETHING should be, or what other cause it may be.

Thanks.

Upvotes: 2

Views: 729

Answers (1)

ForbiddenSoul
ForbiddenSoul

Reputation: 138

"MFStartup(MF_VERSION)" needed to be called:

IMFSinkWriter* pSinkWriter;
HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
std::cout << std::system_category().message(hr) << "\n";
hr = MFStartup(MF_VERSION);
std::cout << std::system_category().message(hr) << "\n";
hr = MFCreateSinkWriterFromURL(L"Recording.mp3", NULL, NULL, &pSinkWriter);
std::cout << std::system_category().message(hr) << "\n";
system("pause");

Output:

The operation completed successfully.

The operation completed successfully.

The operation completed successfully.

Press any key to continue . . .

Upvotes: 3

Related Questions