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 // Constructor
FFmpegSourceAudioProvider::FFmpegSourceAudioProvider(Aegisub::String filename) { FFmpegSourceAudioProvider::FFmpegSourceAudioProvider(Aegisub::String filename) {
COMInited = false;
#ifdef WIN32 #ifdef WIN32
if (!SUCCEEDED(CoInitializeEx(NULL, COINIT_MULTITHREADED))) { HRESULT res;
throw _T("FFmpegSource audio provider: COM initialization failure"); 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 #endif
FFMS_Init(); FFMS_Init();
@ -182,6 +186,7 @@ void FFmpegSourceAudioProvider::LoadAudio(Aegisub::String filename) {
FFmpegSourceAudioProvider::~FFmpegSourceAudioProvider() { FFmpegSourceAudioProvider::~FFmpegSourceAudioProvider() {
Close(); Close();
#ifdef WIN32 #ifdef WIN32
if (COMInited)
CoUninitialize(); CoUninitialize();
#endif #endif
} }

View File

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

View File

@ -53,10 +53,14 @@
/////////////// ///////////////
// Constructor // Constructor
FFmpegSourceVideoProvider::FFmpegSourceVideoProvider(Aegisub::String filename, double fps) { FFmpegSourceVideoProvider::FFmpegSourceVideoProvider(Aegisub::String filename, double fps) {
COMInited = false;
#ifdef WIN32 #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"); throw _T("FFmpegSource video provider: COM initialization failure");
}
#endif #endif
// initialize ffmpegsource // initialize ffmpegsource
FFMS_Init(); FFMS_Init();
@ -84,6 +88,7 @@ FFmpegSourceVideoProvider::FFmpegSourceVideoProvider(Aegisub::String filename, d
FFmpegSourceVideoProvider::~FFmpegSourceVideoProvider() { FFmpegSourceVideoProvider::~FFmpegSourceVideoProvider() {
Close(); Close();
#ifdef WIN32 #ifdef WIN32
if (COMInited)
CoUninitialize(); CoUninitialize();
#endif #endif
} }

View File

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