]> git.sesse.net Git - vlc/commitdiff
plugin.cpp: auto-detect debbuger and change threading mechanism to avoid VLC intializ...
authorDamien Fouilleul <damienf@videolan.org>
Tue, 11 Oct 2005 15:14:08 +0000 (15:14 +0000)
committerDamien Fouilleul <damienf@videolan.org>
Tue, 11 Oct 2005 15:14:08 +0000 (15:14 +0000)
plugin.h: validate container code page before using it
utils.cpp,utils.h: type clean-up
connectioncontainer.cpp: fixed stack corruption (???)  when poping and dispatch an event

activex/connectioncontainer.cpp
activex/plugin.cpp
activex/plugin.h
activex/utils.cpp
activex/utils.h
activex/vlccontrol.cpp

index 308f2645579b46305358aa6f46a3fb184e877a2e..bc63ee4e1f12f3f405896b19100e8f29aad64da0 100644 (file)
@@ -133,7 +133,7 @@ STDMETHODIMP VLCConnectionPoint::EnumConnections(IEnumConnections **ppEnum)
     return (NULL != *ppEnum ) ? S_OK : E_OUTOFMEMORY;
 };
 
-void VLCConnectionPoint::fireEvent(DISPID dispId, DISPPARAMSpDispParams)
+void VLCConnectionPoint::fireEvent(DISPID dispId, DISPPARAMS *pDispParams)
 {
     vector<CONNECTDATA>::iterator end = _connections.end();
     vector<CONNECTDATA>::iterator iter = _connections.begin();
@@ -297,9 +297,9 @@ void VLCConnectionPointContainer::freezeEvents(BOOL freeze)
         while( ! _q_events.empty() )
         {
             VLCDispatchEvent *ev = _q_events.front();
+            _q_events.pop();
             _p_events->fireEvent(ev->_dispId, &ev->_dispParams);
             delete ev;
-            _q_events.pop();
         }
     }
     _b_freeze = freeze;
@@ -307,11 +307,10 @@ void VLCConnectionPointContainer::freezeEvents(BOOL freeze)
 
 void VLCConnectionPointContainer::fireEvent(DISPID dispId, DISPPARAMS* pDispParams)
 {
-    VLCDispatchEvent *evt = new VLCDispatchEvent(dispId, *pDispParams);
     if( _b_freeze )
     {
         // queue event for later use when container is ready
-        _q_events.push(evt);
+        _q_events.push(new VLCDispatchEvent(dispId, *pDispParams));
         if( _q_events.size() > 10 )
         {
             // too many events in queue, get rid of older one
@@ -322,7 +321,6 @@ void VLCConnectionPointContainer::fireEvent(DISPID dispId, DISPPARAMS* pDispPara
     else
     {
         _p_events->fireEvent(dispId, pDispParams);
-        delete evt;
     }
 };
 
index 8f14ba989b448f53a223600c69cc9152cd7632d9..370c37cf92709dc17aaae1300f5c2e9c801b31fa 100644 (file)
@@ -474,11 +474,19 @@ HRESULT VLCPlugin::onInit(void)
 {
     if( 0 == _i_vlc )
     {
-#ifdef ACTIVEX_DEBUG
-        char *ppsz_argv[] = { "vlc", "-vv", "--fast-mutex", "--win9x-cv-method=1" };
-#else
-        char *ppsz_argv[] = { "vlc", "-vv" };
-#endif
+        _i_vlc = VLC_Create();
+        if( _i_vlc < 0 )
+        {
+            _i_vlc = 0;
+            return E_FAIL;
+        }
+
+        /*
+        ** default initialization options
+        */
+        char *ppsz_argv[10] = { "vlc", "-vv" };
+        int   ppsz_argc = 2;
+
         HKEY h_key;
         DWORD i_type, i_data = MAX_PATH + 1;
         char p_data[MAX_PATH + 1];
@@ -497,18 +505,25 @@ HRESULT VLCPlugin::onInit(void)
              RegCloseKey( h_key );
         }
 
-#if 0
+#if 1
         ppsz_argv[0] = "C:\\cygwin\\home\\Damien_Fouilleul\\dev\\videolan\\vlc-trunk\\vlc";
 #endif
 
-        _i_vlc = VLC_Create();
-        if( _i_vlc < 0 )
+        if( IsDebuggerPresent() )
         {
-            _i_vlc = 0;
-            return E_FAIL;
+            /*
+            ** VLC default threading mechanism is designed to be as compatible
+            ** with POSIX as possible, however when debugged on win32, threads
+            ** lose signals and eventually VLC get stuck during initialization.
+            ** threading support can be configured to be more debugging friendly
+            ** but it will be less compatible with POSIX.
+            ** This is done by initializing with the following options
+            */
+            ppsz_argv[ppsz_argc++] = "--fast-mutex";
+            ppsz_argv[ppsz_argc++] = "--win9x-cv-method=1";
         }
 
-        if( VLC_Init(_i_vlc, sizeof(ppsz_argv)/sizeof(char*), ppsz_argv) )
+        if( VLC_Init(_i_vlc, ppsz_argc, ppsz_argv) )
         {
             VLC_Destroy(_i_vlc);
             _i_vlc = 0;
@@ -657,9 +672,10 @@ HRESULT VLCPlugin::onAmbientChanged(LPUNKNOWN pContainer, DISPID dispID)
             }
             VariantInit(&v);
             V_VT(&v) = VT_I4;
-            if( SUCCEEDED(GetObjectProperty(pContainer, dispID, v)) )
+            if( SUCCEEDED(GetObjectProperty(pContainer, DISPID_AMBIENT_CODEPAGE, v)) )
             {
                 setCodePage(V_I4(&v));
+                VariantClear(&v);
             }
             break;
     }
index 227773a8aa0fcda2c8a7253f624de64a7db76cdf..800aceb76b9c96ca660389eb0808f75718506585 100644 (file)
@@ -143,7 +143,14 @@ public:
     void setFocus(BOOL fFocus);
 
     inline UINT getCodePage(void) { return _i_codepage; };
-    inline void setCodePage(UINT cp) { _i_codepage = cp; };
+    inline void setCodePage(UINT cp)
+    {
+        // accept new codepage only if it works on this system
+        size_t mblen = WideCharToMultiByte(cp,
+                0, L"test", -1, NULL, 0, NULL, NULL);
+        if( mblen > 0 )
+            _i_codepage = cp;
+    };
 
     inline BOOL isUserMode(void) { return _b_usermode; };
     inline void setUserMode(BOOL um) { _b_usermode = um; };
index 7582adaef0b9b664b0277236bafc6b35e1246241..80c4fd5a74a7b1a86086bd07628168ba4cd45a4b 100644 (file)
@@ -28,7 +28,7 @@
 
 using namespace std;
 
-char *CStrFromBSTR(int codePage, BSTR bstr)
+char *CStrFromBSTR(UINT codePage, BSTR bstr)
 {
     UINT len = SysStringLen(bstr);
     if( len > 0 )
@@ -49,7 +49,7 @@ char *CStrFromBSTR(int codePage, BSTR bstr)
     return NULL;
 };
 
-BSTR BSTRFromCStr(int codePage, const char *s)
+BSTR BSTRFromCStr(UINT codePage, LPCSTR s)
 {
     int wideLen = MultiByteToWideChar(codePage, 0, s, -1, NULL, 0);
     if( wideLen > 0 )
index 070c477c4670342169a33b2f4b75e4591dcaa561..327225d98e37f8bc589995a8a395c4a8011cce4a 100644 (file)
@@ -28,8 +28,8 @@
 #include <vector>
 
 // utilities
-extern char *CStrFromBSTR(int codePage, BSTR bstr);
-extern BSTR BSTRFromCStr(int codePage, const char *s);
+extern char *CStrFromBSTR(UINT codePage, BSTR bstr);
+extern BSTR BSTRFromCStr(UINT codePage, LPCSTR s);
 
 // properties
 extern HRESULT GetObjectProperty(LPUNKNOWN object, DISPID dispID, VARIANT& v);
index 4edaefb4f7412a2fc3c6142ccf3873f1d4791422..cc2c9010b42ebdec14c6bd452af98ad1430050f3 100644 (file)
@@ -433,16 +433,18 @@ STDMETHODIMP VLCControl::setVariable(BSTR name, VARIANT value)
 
 STDMETHODIMP VLCControl::getVariable( BSTR name, VARIANT *value)
 {
-    if( 0 == SysStringLen(name) )
-        return E_INVALIDARG;
-
     if( NULL == value )
         return E_POINTER;
 
+    VariantInit(value);
+
+    if( 0 == SysStringLen(name) )
+        return E_INVALIDARG;
+
     int i_vlc = _p_instance->getVLCObject();
     if( i_vlc )
     {
-        int codePage = _p_instance->getCodePage();
+        UINT codePage = _p_instance->getCodePage();
         char *psz_varname = CStrFromBSTR(codePage, name);
         if( NULL == psz_varname )
             return E_OUTOFMEMORY;
@@ -481,7 +483,8 @@ STDMETHODIMP VLCControl::getVariable( BSTR name, VARIANT *value)
                 case VLC_VAR_VARIABLE:
                     V_VT(value) = VT_BSTR;
                     V_BSTR(value) = BSTRFromCStr(codePage, val.psz_string);
-                    CoTaskMemFree(val.psz_string);
+                    if( NULL != val.psz_string)
+                        free(val.psz_string);
                     break;
 
                 case VLC_VAR_TIME: