Do COM initialization more properly (I think) in the FFMS2 providers.

Originally committed to SVN as r2989.
This commit is contained in:
Karl Blomster 2009-05-25 16:42:33 +00:00
parent 200b3393f9
commit 379f15659a
4 changed files with 21 additions and 7 deletions

View file

@ -49,10 +49,14 @@
///////////
// Constructor
FFmpegSourceAudioProvider::FFmpegSourceAudioProvider(Aegisub::String filename) {
COMInited = false;
#ifdef WIN32
if (!SUCCEEDED(CoInitializeEx(NULL, COINIT_MULTITHREADED))) {
throw _T("FFmpegSource audio provider: COM initialization failure");
}
HRESULT res;
res = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
if (SUCCEEDED(res))
COMInited = true;
else if (res != RPC_E_CHANGED_MODE)
throw _T("FFmpegSource video provider: COM initialization failure");
#endif
FFMS_Init();
@ -182,7 +186,8 @@ void FFmpegSourceAudioProvider::LoadAudio(Aegisub::String filename) {
FFmpegSourceAudioProvider::~FFmpegSourceAudioProvider() {
Close();
#ifdef WIN32
CoUninitialize();
if (COMInited)
CoUninitialize();
#endif
}

View file

@ -51,6 +51,8 @@ private:
unsigned MsgSize;
wxString MsgString;
bool COMInited;
void Close();
void LoadAudio(Aegisub::String filename);

View file

@ -53,10 +53,14 @@
///////////////
// Constructor
FFmpegSourceVideoProvider::FFmpegSourceVideoProvider(Aegisub::String filename, double fps) {
COMInited = false;
#ifdef WIN32
if (!SUCCEEDED(CoInitializeEx(NULL, COINIT_MULTITHREADED))) {
HRESULT res;
res = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
if (SUCCEEDED(res))
COMInited = true;
else if (res != RPC_E_CHANGED_MODE)
throw _T("FFmpegSource video provider: COM initialization failure");
}
#endif
// initialize ffmpegsource
FFMS_Init();
@ -84,7 +88,8 @@ FFmpegSourceVideoProvider::FFmpegSourceVideoProvider(Aegisub::String filename, d
FFmpegSourceVideoProvider::~FFmpegSourceVideoProvider() {
Close();
#ifdef WIN32
CoUninitialize();
if (COMInited)
CoUninitialize();
#endif
}

View file

@ -64,6 +64,8 @@ private:
unsigned MessageSize;
wxString ErrorMsg;
bool COMInited;
void LoadVideo(Aegisub::String filename, double fps);
void Close();