Commit 7445b6bd authored by Damien Fouilleul's avatar Damien Fouilleul

plugin.cpp: auto-detect debbuger and change threading mechanism to avoid VLC...

plugin.cpp: auto-detect debbuger and change threading mechanism to avoid VLC intialization lock when launching a debug session
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
parent ca0ada33
...@@ -133,7 +133,7 @@ STDMETHODIMP VLCConnectionPoint::EnumConnections(IEnumConnections **ppEnum) ...@@ -133,7 +133,7 @@ STDMETHODIMP VLCConnectionPoint::EnumConnections(IEnumConnections **ppEnum)
return (NULL != *ppEnum ) ? S_OK : E_OUTOFMEMORY; return (NULL != *ppEnum ) ? S_OK : E_OUTOFMEMORY;
}; };
void VLCConnectionPoint::fireEvent(DISPID dispId, DISPPARAMS* pDispParams) void VLCConnectionPoint::fireEvent(DISPID dispId, DISPPARAMS *pDispParams)
{ {
vector<CONNECTDATA>::iterator end = _connections.end(); vector<CONNECTDATA>::iterator end = _connections.end();
vector<CONNECTDATA>::iterator iter = _connections.begin(); vector<CONNECTDATA>::iterator iter = _connections.begin();
...@@ -297,9 +297,9 @@ void VLCConnectionPointContainer::freezeEvents(BOOL freeze) ...@@ -297,9 +297,9 @@ void VLCConnectionPointContainer::freezeEvents(BOOL freeze)
while( ! _q_events.empty() ) while( ! _q_events.empty() )
{ {
VLCDispatchEvent *ev = _q_events.front(); VLCDispatchEvent *ev = _q_events.front();
_q_events.pop();
_p_events->fireEvent(ev->_dispId, &ev->_dispParams); _p_events->fireEvent(ev->_dispId, &ev->_dispParams);
delete ev; delete ev;
_q_events.pop();
} }
} }
_b_freeze = freeze; _b_freeze = freeze;
...@@ -307,11 +307,10 @@ void VLCConnectionPointContainer::freezeEvents(BOOL freeze) ...@@ -307,11 +307,10 @@ void VLCConnectionPointContainer::freezeEvents(BOOL freeze)
void VLCConnectionPointContainer::fireEvent(DISPID dispId, DISPPARAMS* pDispParams) void VLCConnectionPointContainer::fireEvent(DISPID dispId, DISPPARAMS* pDispParams)
{ {
VLCDispatchEvent *evt = new VLCDispatchEvent(dispId, *pDispParams);
if( _b_freeze ) if( _b_freeze )
{ {
// queue event for later use when container is ready // 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 ) if( _q_events.size() > 10 )
{ {
// too many events in queue, get rid of older one // too many events in queue, get rid of older one
...@@ -322,7 +321,6 @@ void VLCConnectionPointContainer::fireEvent(DISPID dispId, DISPPARAMS* pDispPara ...@@ -322,7 +321,6 @@ void VLCConnectionPointContainer::fireEvent(DISPID dispId, DISPPARAMS* pDispPara
else else
{ {
_p_events->fireEvent(dispId, pDispParams); _p_events->fireEvent(dispId, pDispParams);
delete evt;
} }
}; };
......
...@@ -474,11 +474,19 @@ HRESULT VLCPlugin::onInit(void) ...@@ -474,11 +474,19 @@ HRESULT VLCPlugin::onInit(void)
{ {
if( 0 == _i_vlc ) if( 0 == _i_vlc )
{ {
#ifdef ACTIVEX_DEBUG _i_vlc = VLC_Create();
char *ppsz_argv[] = { "vlc", "-vv", "--fast-mutex", "--win9x-cv-method=1" }; if( _i_vlc < 0 )
#else {
char *ppsz_argv[] = { "vlc", "-vv" }; _i_vlc = 0;
#endif return E_FAIL;
}
/*
** default initialization options
*/
char *ppsz_argv[10] = { "vlc", "-vv" };
int ppsz_argc = 2;
HKEY h_key; HKEY h_key;
DWORD i_type, i_data = MAX_PATH + 1; DWORD i_type, i_data = MAX_PATH + 1;
char p_data[MAX_PATH + 1]; char p_data[MAX_PATH + 1];
...@@ -497,18 +505,25 @@ HRESULT VLCPlugin::onInit(void) ...@@ -497,18 +505,25 @@ HRESULT VLCPlugin::onInit(void)
RegCloseKey( h_key ); RegCloseKey( h_key );
} }
#if 0 #if 1
ppsz_argv[0] = "C:\\cygwin\\home\\Damien_Fouilleul\\dev\\videolan\\vlc-trunk\\vlc"; ppsz_argv[0] = "C:\\cygwin\\home\\Damien_Fouilleul\\dev\\videolan\\vlc-trunk\\vlc";
#endif #endif
_i_vlc = VLC_Create(); if( IsDebuggerPresent() )
if( _i_vlc < 0 )
{ {
_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); VLC_Destroy(_i_vlc);
_i_vlc = 0; _i_vlc = 0;
...@@ -657,9 +672,10 @@ HRESULT VLCPlugin::onAmbientChanged(LPUNKNOWN pContainer, DISPID dispID) ...@@ -657,9 +672,10 @@ HRESULT VLCPlugin::onAmbientChanged(LPUNKNOWN pContainer, DISPID dispID)
} }
VariantInit(&v); VariantInit(&v);
V_VT(&v) = VT_I4; V_VT(&v) = VT_I4;
if( SUCCEEDED(GetObjectProperty(pContainer, dispID, v)) ) if( SUCCEEDED(GetObjectProperty(pContainer, DISPID_AMBIENT_CODEPAGE, v)) )
{ {
setCodePage(V_I4(&v)); setCodePage(V_I4(&v));
VariantClear(&v);
} }
break; break;
} }
......
...@@ -143,7 +143,14 @@ public: ...@@ -143,7 +143,14 @@ public:
void setFocus(BOOL fFocus); void setFocus(BOOL fFocus);
inline UINT getCodePage(void) { return _i_codepage; }; 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 BOOL isUserMode(void) { return _b_usermode; };
inline void setUserMode(BOOL um) { _b_usermode = um; }; inline void setUserMode(BOOL um) { _b_usermode = um; };
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
using namespace std; using namespace std;
char *CStrFromBSTR(int codePage, BSTR bstr) char *CStrFromBSTR(UINT codePage, BSTR bstr)
{ {
UINT len = SysStringLen(bstr); UINT len = SysStringLen(bstr);
if( len > 0 ) if( len > 0 )
...@@ -49,7 +49,7 @@ char *CStrFromBSTR(int codePage, BSTR bstr) ...@@ -49,7 +49,7 @@ char *CStrFromBSTR(int codePage, BSTR bstr)
return NULL; return NULL;
}; };
BSTR BSTRFromCStr(int codePage, const char *s) BSTR BSTRFromCStr(UINT codePage, LPCSTR s)
{ {
int wideLen = MultiByteToWideChar(codePage, 0, s, -1, NULL, 0); int wideLen = MultiByteToWideChar(codePage, 0, s, -1, NULL, 0);
if( wideLen > 0 ) if( wideLen > 0 )
......
...@@ -28,8 +28,8 @@ ...@@ -28,8 +28,8 @@
#include <vector> #include <vector>
// utilities // utilities
extern char *CStrFromBSTR(int codePage, BSTR bstr); extern char *CStrFromBSTR(UINT codePage, BSTR bstr);
extern BSTR BSTRFromCStr(int codePage, const char *s); extern BSTR BSTRFromCStr(UINT codePage, LPCSTR s);
// properties // properties
extern HRESULT GetObjectProperty(LPUNKNOWN object, DISPID dispID, VARIANT& v); extern HRESULT GetObjectProperty(LPUNKNOWN object, DISPID dispID, VARIANT& v);
......
...@@ -433,16 +433,18 @@ STDMETHODIMP VLCControl::setVariable(BSTR name, VARIANT value) ...@@ -433,16 +433,18 @@ STDMETHODIMP VLCControl::setVariable(BSTR name, VARIANT value)
STDMETHODIMP VLCControl::getVariable( BSTR name, VARIANT *value) STDMETHODIMP VLCControl::getVariable( BSTR name, VARIANT *value)
{ {
if( 0 == SysStringLen(name) )
return E_INVALIDARG;
if( NULL == value ) if( NULL == value )
return E_POINTER; return E_POINTER;
VariantInit(value);
if( 0 == SysStringLen(name) )
return E_INVALIDARG;
int i_vlc = _p_instance->getVLCObject(); int i_vlc = _p_instance->getVLCObject();
if( i_vlc ) if( i_vlc )
{ {
int codePage = _p_instance->getCodePage(); UINT codePage = _p_instance->getCodePage();
char *psz_varname = CStrFromBSTR(codePage, name); char *psz_varname = CStrFromBSTR(codePage, name);
if( NULL == psz_varname ) if( NULL == psz_varname )
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
...@@ -481,7 +483,8 @@ STDMETHODIMP VLCControl::getVariable( BSTR name, VARIANT *value) ...@@ -481,7 +483,8 @@ STDMETHODIMP VLCControl::getVariable( BSTR name, VARIANT *value)
case VLC_VAR_VARIABLE: case VLC_VAR_VARIABLE:
V_VT(value) = VT_BSTR; V_VT(value) = VT_BSTR;
V_BSTR(value) = BSTRFromCStr(codePage, val.psz_string); V_BSTR(value) = BSTRFromCStr(codePage, val.psz_string);
CoTaskMemFree(val.psz_string); if( NULL != val.psz_string)
free(val.psz_string);
break; break;
case VLC_VAR_TIME: case VLC_VAR_TIME:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment