Commit 2fbbe6d5 authored by Damien Fouilleul's avatar Damien Fouilleul

plugin.cpp, plugin.h: delayed initialization of VLC until activation in place in user mode only

    this allows the persistable properties to be fully loaded before initialization and allow
    for control to initialize faster in design mode. AUTOLOOP property now works properly
persistpropbag.cpp, vlccontrol.h: decoupled volume property from VLC so that value can be used
    without having VLC initialized
test.html: added volume control
parent bb48220f
...@@ -161,11 +161,10 @@ STDMETHODIMP VLCPersistPropertyBag::Load(LPPROPERTYBAG pPropBag, LPERRORLOG pErr ...@@ -161,11 +161,10 @@ STDMETHODIMP VLCPersistPropertyBag::Load(LPPROPERTYBAG pPropBag, LPERRORLOG pErr
} }
} }
int i_vlc = _p_instance->getVLCObject();
V_VT(&value) = VT_I4; V_VT(&value) = VT_I4;
if( S_OK == pPropBag->Read(OLESTR("volume"), &value, pErrorLog) ) if( S_OK == pPropBag->Read(OLESTR("volume"), &value, pErrorLog) )
{ {
VLC_VolumeSet(i_vlc, V_I4(&value)); _p_instance->setVolume(V_I4(&value));
VariantClear(&value); VariantClear(&value);
} }
return _p_instance->onLoad(); return _p_instance->onLoad();
...@@ -208,14 +207,10 @@ STDMETHODIMP VLCPersistPropertyBag::Save(LPPROPERTYBAG pPropBag, BOOL fClearDirt ...@@ -208,14 +207,10 @@ STDMETHODIMP VLCPersistPropertyBag::Save(LPPROPERTYBAG pPropBag, BOOL fClearDirt
pPropBag->Write(OLESTR("Visible"), &value); pPropBag->Write(OLESTR("Visible"), &value);
VariantClear(&value); VariantClear(&value);
int i_vlc = _p_instance->getVLCObject(); V_VT(&value) = VT_I4;
if( i_vlc ) V_I4(&value) = _p_instance->getVolume();
{ pPropBag->Write(OLESTR("Volume"), &value);
V_VT(&value) = VT_I4; VariantClear(&value);
V_I4(&value) = VLC_VolumeGet(i_vlc);
pPropBag->Write(OLESTR("Volume"), &value);
VariantClear(&value);
}
if( fClearDirty ) if( fClearDirty )
_p_instance->setDirty(FALSE); _p_instance->setDirty(FALSE);
......
...@@ -244,15 +244,11 @@ STDMETHODIMP VLCPluginClass::LockServer(BOOL fLock) ...@@ -244,15 +244,11 @@ STDMETHODIMP VLCPluginClass::LockServer(BOOL fLock)
VLCPlugin::VLCPlugin(VLCPluginClass *p_class, LPUNKNOWN pUnkOuter) : VLCPlugin::VLCPlugin(VLCPluginClass *p_class, LPUNKNOWN pUnkOuter) :
_inplacewnd(NULL), _inplacewnd(NULL),
_videownd(NULL),
_p_class(p_class), _p_class(p_class),
_i_ref(1UL), _i_ref(1UL),
_i_codepage(CP_ACP), _i_codepage(CP_ACP),
_b_usermode(TRUE), _b_usermode(TRUE),
_bstr_mrl(NULL),
_b_autoplay(TRUE),
_b_autoloop(FALSE),
_b_visible(TRUE),
_b_mute(FALSE),
_i_vlc(0) _i_vlc(0)
{ {
p_class->AddRef(); p_class->AddRef();
...@@ -277,12 +273,8 @@ VLCPlugin::VLCPlugin(VLCPluginClass *p_class, LPUNKNOWN pUnkOuter) : ...@@ -277,12 +273,8 @@ VLCPlugin::VLCPlugin(VLCPluginClass *p_class, LPUNKNOWN pUnkOuter) :
// default picure // default picure
_p_pict = p_class->getInPlacePict(); _p_pict = p_class->getInPlacePict();
// set default/preferred size (320x240) pixels in HIMETRIC // make sure that persistable properties are initialized
HDC hDC = CreateDevDC(NULL); onInit();
_extent.cx = 320;
_extent.cy = 240;
HimetricFromDP(hDC, (LPPOINT)&_extent, 1);
DeleteDC(hDC);
}; };
VLCPlugin::~VLCPlugin() VLCPlugin::~VLCPlugin()
...@@ -474,61 +466,20 @@ HRESULT VLCPlugin::onInit(void) ...@@ -474,61 +466,20 @@ HRESULT VLCPlugin::onInit(void)
{ {
if( 0 == _i_vlc ) if( 0 == _i_vlc )
{ {
_i_vlc = VLC_Create(); // initialize persistable properties
if( _i_vlc < 0 ) _bstr_mrl = NULL;
{ _b_autoplay = TRUE;
_i_vlc = 0; _b_autoloop = FALSE;
return E_FAIL; _b_visible = TRUE;
} _b_mute = FALSE;
_i_volume = 50;
/* // set default/preferred size (320x240) pixels in HIMETRIC
** default initialization options HDC hDC = CreateDevDC(NULL);
*/ _extent.cx = 320;
char *ppsz_argv[10] = { "vlc", "-vv" }; _extent.cy = 240;
int ppsz_argc = 2; HimetricFromDP(hDC, (LPPOINT)&_extent, 1);
DeleteDC(hDC);
HKEY h_key;
DWORD i_type, i_data = MAX_PATH + 1;
char p_data[MAX_PATH + 1];
if( RegOpenKeyEx( HKEY_LOCAL_MACHINE, "Software\\VideoLAN\\VLC",
0, KEY_READ, &h_key ) == ERROR_SUCCESS )
{
if( RegQueryValueEx( h_key, "InstallDir", 0, &i_type,
(LPBYTE)p_data, &i_data ) == ERROR_SUCCESS )
{
if( i_type == REG_SZ )
{
strcat( p_data, "\\vlc" );
ppsz_argv[0] = p_data;
}
}
RegCloseKey( h_key );
}
#if 0
ppsz_argv[0] = "C:\\cygwin\\home\\Damien_Fouilleul\\dev\\videolan\\vlc-trunk\\vlc";
#endif
if( IsDebuggerPresent() )
{
/*
** 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, ppsz_argc, ppsz_argv) )
{
VLC_Destroy(_i_vlc);
_i_vlc = 0;
return E_FAIL;
}
return S_OK; return S_OK;
} }
return CO_E_ALREADYINITIALIZED; return CO_E_ALREADYINITIALIZED;
...@@ -536,9 +487,6 @@ HRESULT VLCPlugin::onInit(void) ...@@ -536,9 +487,6 @@ HRESULT VLCPlugin::onInit(void)
HRESULT VLCPlugin::onLoad(void) HRESULT VLCPlugin::onLoad(void)
{ {
if( _b_mute )
VLC_VolumeMute(_i_vlc);
if( SysStringLen(_bstr_mrl) > 0 ) if( SysStringLen(_bstr_mrl) > 0 )
{ {
/* /*
...@@ -585,23 +533,91 @@ HRESULT VLCPlugin::onLoad(void) ...@@ -585,23 +533,91 @@ HRESULT VLCPlugin::onLoad(void)
} }
pClientSite->Release(); pClientSite->Release();
} }
}
setDirty(FALSE);
return S_OK;
};
HRESULT VLCPlugin::onRun(void)
{
if( ! isRunning() )
{
_i_vlc = VLC_Create();
if( _i_vlc < 0 )
{
_i_vlc = 0;
return E_FAIL;
}
/*
** default initialization options
*/
char *ppsz_argv[10] = { "vlc", };
int ppsz_argc = 1;
HKEY h_key;
DWORD i_type, i_data = MAX_PATH + 1;
char p_data[MAX_PATH + 1];
if( RegOpenKeyEx( HKEY_LOCAL_MACHINE, "Software\\VideoLAN\\VLC",
0, KEY_READ, &h_key ) == ERROR_SUCCESS )
{
if( RegQueryValueEx( h_key, "InstallDir", 0, &i_type,
(LPBYTE)p_data, &i_data ) == ERROR_SUCCESS )
{
if( i_type == REG_SZ )
{
strcat( p_data, "\\vlc" );
ppsz_argv[0] = p_data;
}
}
RegCloseKey( h_key );
}
#if 1
ppsz_argv[0] = "C:\\cygwin\\home\\Damien_Fouilleul\\dev\\videolan\\vlc-trunk\\vlc";
#endif
// make sure plugin isn't affected with VLC single instance mode
ppsz_argv[ppsz_argc++] = "--no-one-instance";
// loop mode is a configuration option only
if( _b_autoloop )
ppsz_argv[ppsz_argc++] = "--loop";
if( IsDebuggerPresent() )
{
/*
** 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, ppsz_argc, ppsz_argv) )
{
VLC_Destroy(_i_vlc);
_i_vlc = 0;
return E_FAIL;
}
VLC_VolumeSet(_i_vlc, _i_volume);
if( _b_mute )
VLC_VolumeMute(_i_vlc);
char *psz_mrl = CStrFromBSTR(CP_UTF8, _bstr_mrl); char *psz_mrl = CStrFromBSTR(CP_UTF8, _bstr_mrl);
if( NULL != psz_mrl ) if( NULL != psz_mrl )
{ {
// add default target to playlist // add default target to playlist
char *cOptions[1]; VLC_AddTarget(_i_vlc, psz_mrl, NULL, 0, PLAYLIST_APPEND, PLAYLIST_END);
int cOptionsCount = 0;
if( _b_autoloop )
{
cOptions[cOptionsCount++] = "loop";
}
VLC_AddTarget(_i_vlc, psz_mrl, (const char **)&cOptions, cOptionsCount, PLAYLIST_APPEND, PLAYLIST_END);
CoTaskMemFree(psz_mrl); CoTaskMemFree(psz_mrl);
} }
} }
setDirty(FALSE);
return S_OK; return S_OK;
}; };
...@@ -665,9 +681,9 @@ HRESULT VLCPlugin::onAmbientChanged(LPUNKNOWN pContainer, DISPID dispID) ...@@ -665,9 +681,9 @@ HRESULT VLCPlugin::onAmbientChanged(LPUNKNOWN pContainer, DISPID dispID)
case DISPID_AMBIENT_TOPTOBOTTOM: case DISPID_AMBIENT_TOPTOBOTTOM:
break; break;
case DISPID_UNKNOWN: case DISPID_UNKNOWN:
/* /*
** multiple property change, look up the ones we are interested in ** multiple property change, look up the ones we are interested in
*/ */
VariantInit(&v); VariantInit(&v);
V_VT(&v) = VT_BOOL; V_VT(&v) = VT_BOOL;
if( SUCCEEDED(GetObjectProperty(pContainer, DISPID_AMBIENT_USERMODE, v)) ) if( SUCCEEDED(GetObjectProperty(pContainer, DISPID_AMBIENT_USERMODE, v)) )
...@@ -687,15 +703,15 @@ HRESULT VLCPlugin::onAmbientChanged(LPUNKNOWN pContainer, DISPID dispID) ...@@ -687,15 +703,15 @@ HRESULT VLCPlugin::onAmbientChanged(LPUNKNOWN pContainer, DISPID dispID)
HRESULT VLCPlugin::onClose(DWORD dwSaveOption) HRESULT VLCPlugin::onClose(DWORD dwSaveOption)
{ {
if( _i_vlc ) if( isInPlaceActive() )
{
onInPlaceDeactivate();
}
if( isRunning() )
{ {
int i_vlc = _i_vlc; int i_vlc = _i_vlc;
_i_vlc = 0; _i_vlc = 0;
if( isInPlaceActive() )
{
onInPlaceDeactivate();
}
vlcDataObject->onClose(); vlcDataObject->onClose();
VLC_CleanUp(i_vlc); VLC_CleanUp(i_vlc);
...@@ -778,30 +794,41 @@ HRESULT VLCPlugin::onActivateInPlace(LPMSG lpMesg, HWND hwndParent, LPCRECT lprc ...@@ -778,30 +794,41 @@ HRESULT VLCPlugin::onActivateInPlace(LPMSG lpMesg, HWND hwndParent, LPCRECT lprc
if( getVisible() ) if( getVisible() )
ShowWindow(_inplacewnd, SW_SHOW); ShowWindow(_inplacewnd, SW_SHOW);
/* set internal video width and height */ if( _b_usermode )
vlc_value_t val;
val.i_int = posRect.right-posRect.left;
VLC_VariableSet(_i_vlc, "conf::width", val);
val.i_int = posRect.bottom-posRect.top;
VLC_VariableSet(_i_vlc, "conf::height", val);
/* set internal video parent window */
/* horrible cast there */
val.i_int = reinterpret_cast<int>(_videownd);
VLC_VariableSet(_i_vlc, "drawable", val);
if( _b_usermode && _b_autoplay & (VLC_PlaylistNumberOfItems(_i_vlc) > 0) )
{ {
VLC_Play(_i_vlc); /* run vlc if not done already */
fireOnPlayEvent(); HRESULT result = onRun();
if( FAILED(result) )
return result;
/* set internal video width and height */
vlc_value_t val;
val.i_int = posRect.right-posRect.left;
VLC_VariableSet(_i_vlc, "conf::width", val);
val.i_int = posRect.bottom-posRect.top;
VLC_VariableSet(_i_vlc, "conf::height", val);
/* set internal video parent window */
/* horrible cast there */
val.i_int = reinterpret_cast<int>(_videownd);
VLC_VariableSet(_i_vlc, "drawable", val);
if( _b_autoplay & (VLC_PlaylistNumberOfItems(_i_vlc) > 0) )
{
VLC_Play(_i_vlc);
fireOnPlayEvent();
}
} }
return S_OK; return S_OK;
}; };
HRESULT VLCPlugin::onInPlaceDeactivate(void) HRESULT VLCPlugin::onInPlaceDeactivate(void)
{ {
VLC_Stop(_i_vlc); if( isRunning() )
fireOnStopEvent(); {
VLC_Stop(_i_vlc);
fireOnStopEvent();
}
DestroyWindow(_videownd); DestroyWindow(_videownd);
_videownd = NULL; _videownd = NULL;
...@@ -819,11 +846,32 @@ void VLCPlugin::setVisible(BOOL fVisible) ...@@ -819,11 +846,32 @@ void VLCPlugin::setVisible(BOOL fVisible)
if( isInPlaceActive() ) if( isInPlaceActive() )
{ {
ShowWindow(_inplacewnd, fVisible ? SW_SHOW : SW_HIDE); ShowWindow(_inplacewnd, fVisible ? SW_SHOW : SW_HIDE);
if( fVisible )
InvalidateRect(_videownd, NULL, TRUE);
} }
setDirty(TRUE);
firePropChangedEvent(DISPID_Visible); firePropChangedEvent(DISPID_Visible);
} }
}; };
void VLCPlugin::setVolume(int volume)
{
if( volume < 0 )
volume = 0;
else if( volume > 200 )
volume = 200;
if( volume != _i_volume )
{
_i_volume = volume;
if( isRunning() )
{
VLC_VolumeSet(_i_vlc, _i_volume);
}
setDirty(TRUE);
}
};
void VLCPlugin::setFocus(BOOL fFocus) void VLCPlugin::setFocus(BOOL fFocus)
{ {
if( fFocus ) if( fFocus )
......
...@@ -109,6 +109,9 @@ public: ...@@ -109,6 +109,9 @@ public:
}; };
inline BOOL getAutoLoop(void) { return _b_autoloop;}; inline BOOL getAutoLoop(void) { return _b_autoloop;};
void setVolume(int volume);
BOOL getVolume(void) { return _i_volume; };
void setVisible(BOOL fVisible); void setVisible(BOOL fVisible);
BOOL getVisible(void) { return _b_visible; }; BOOL getVisible(void) { return _b_visible; };
...@@ -172,6 +175,7 @@ public: ...@@ -172,6 +175,7 @@ public:
*/ */
HRESULT onInit(void); HRESULT onInit(void);
HRESULT onLoad(void); HRESULT onLoad(void);
HRESULT onRun(void);
HRESULT onActivateInPlace(LPMSG lpMesg, HWND hwndParent, LPCRECT lprcPosRect, LPCRECT lprcClipRect); HRESULT onActivateInPlace(LPMSG lpMesg, HWND hwndParent, LPCRECT lprcPosRect, LPCRECT lprcClipRect);
HRESULT onInPlaceDeactivate(void); HRESULT onInPlaceDeactivate(void);
HRESULT onAmbientChanged(LPUNKNOWN pContainer, DISPID dispID); HRESULT onAmbientChanged(LPUNKNOWN pContainer, DISPID dispID);
...@@ -222,19 +226,21 @@ private: ...@@ -222,19 +226,21 @@ private:
VLCPluginClass *_p_class; VLCPluginClass *_p_class;
ULONG _i_ref; ULONG _i_ref;
LPPICTURE _p_pict;
UINT _i_codepage; UINT _i_codepage;
BOOL _b_usermode; BOOL _b_usermode;
int _i_vlc;
RECT _posRect;
// persistable properties
BSTR _bstr_mrl; BSTR _bstr_mrl;
BOOL _b_autoplay; BOOL _b_autoplay;
BOOL _b_autoloop; BOOL _b_autoloop;
BOOL _b_visible; BOOL _b_visible;
BOOL _b_mute; BOOL _b_mute;
BOOL _b_dirty; BOOL _b_dirty;
int _i_vlc; int _i_volume;
SIZEL _extent; SIZEL _extent;
RECT _posRect; LPPICTURE _p_pict;
}; };
#endif #endif
......
...@@ -11,12 +11,17 @@ MRL: ...@@ -11,12 +11,17 @@ MRL:
<!-- <!--
Insert VideoLAN.VLCPlugin.1 activex control Insert VideoLAN.VLCPlugin.1 activex control
--> -->
<OBJECT classid="clsid:E23FE9C6-778E-49D4-B537-38FCDE4887D8" codebase="http://downloads.videolan.org/pub/videolan/vlc/latest/win32/axvlc.cab#Version=0,8,4,0" <OBJECT classid="clsid:E23FE9C6-778E-49D4-B537-38FCDE4887D8"
width="640" height="480" id="vlc" events="True"> codebase="http://downloads.videolan.org/pub/videolan/vlc/latest/win32/axvlc.cab#Version=0,8,4,0"
width="640"
height="480"
id="vlc"
events="True">
<param name="MRL" value="" /> <param name="MRL" value="" />
<param name="ShowDisplay" value="True" /> <param name="ShowDisplay" value="True" />
<param name="AutoLoop" value="False" /> <param name="AutoLoop" value="False" />
<param name="AutoPlay" value="False" /> <param name="AutoPlay" value="False" />
<param name="Volume" value="50" />
</OBJECT> </OBJECT>
</TD></TR> </TD></TR>
<TR><TD> <TR><TD>
...@@ -24,7 +29,10 @@ Insert VideoLAN.VLCPlugin.1 activex control ...@@ -24,7 +29,10 @@ Insert VideoLAN.VLCPlugin.1 activex control
Insert MSComctlLib.Slider.2 activex control Insert MSComctlLib.Slider.2 activex control
--> -->
<OBJECT classid="clsid:F08DF954-8592-11D1-B16A-00C0F0283628" <OBJECT classid="clsid:F08DF954-8592-11D1-B16A-00C0F0283628"
width="540" height="20" id="slider" events="True"> width="540"
height="20"
id="slider"
events="True">
<param name="TickStyle" value="3" /> <param name="TickStyle" value="3" />
<param name="Min" value="0" /> <param name="Min" value="0" />
<param name="Max" value="0" /> <param name="Max" value="0" />
...@@ -37,19 +45,40 @@ Insert MSComctlLib.Slider.2 activex control ...@@ -37,19 +45,40 @@ Insert MSComctlLib.Slider.2 activex control
<TR><TD colspan="2"> <TR><TD colspan="2">
<INPUT type=button id="PlayOrPause" value=" Play " onClick='doPlayOrPause()'> <INPUT type=button id="PlayOrPause" value=" Play " onClick='doPlayOrPause()'>
<INPUT type=button value="Stop" onClick='document.vlc.stop();'> <INPUT type=button value="Stop" onClick='document.vlc.stop();'>
&nbsp;
<INPUT type=button value=" << " onClick='document.vlc.playSlower();'> <INPUT type=button value=" << " onClick='document.vlc.playSlower();'>
<INPUT type=button value=" >> " onClick='document.vlc.playFaster();'> <INPUT type=button value=" >> " onClick='document.vlc.playFaster();'>
<INPUT type=button value="Mute" onClick='document.vlc.toggleMute();'> &nbsp;
<INPUT type=button value="Show" onClick='document.vlc.Visible = true;'> <INPUT type=button value="Show" onClick='document.vlc.Visible = true;'>
<INPUT type=button value="Hide" onClick='document.vlc.Visible = false;'> <INPUT type=button value="Hide" onClick='document.vlc.Visible = false;'>
&nbsp;
<INPUT type=button value="Version" onClick='alert(document.vlc.VersionInfo);'> <INPUT type=button value="Version" onClick='alert(document.vlc.VersionInfo);'>
</TD></TR> <SPAN style="text-align:center">Volume:</SPAN>
<INPUT type=button value=" - " onClick='updateVolume(-10)'>
<SPAN id="volumeTextField" style="text-align: center">--</SPAN>
<INPUT type=button value=" + " onClick='updateVolume(+10)'>
<INPUT type=button value="Mute" onClick='document.vlc.toggleMute();'>
</TD>
</TR>
</TABLE> </TABLE>
<SCRIPT LANGUAGE="JScript"> <SCRIPT LANGUAGE="JScript">
<!-- <!--
var sliderTimerId = 0; var sliderTimerId = 0;
var sliderScrolling = false; var sliderScrolling = false;
document.onreadystatechange=onVLCStateChange;
function onVLCStateChange()
{
if( document.readyState == 'complete' )
{
updateVolume(0);
}
};
function updateVolume(deltaVol)
{
vlc.Volume += deltaVol;
volumeTextField.innerText = vlc.Volume+"%";
};
function formatTime(timeVal) function formatTime(timeVal)
{ {
var timeHour = timeVal; var timeHour = timeVal;
......
...@@ -288,25 +288,14 @@ STDMETHODIMP VLCControl::get_Volume(int *volume) ...@@ -288,25 +288,14 @@ STDMETHODIMP VLCControl::get_Volume(int *volume)
if( NULL == volume ) if( NULL == volume )
return E_POINTER; return E_POINTER;
int i_vlc = _p_instance->getVLCObject(); *volume = _p_instance->getVolume();
if( i_vlc ) return NOERROR;
{
*volume = VLC_VolumeGet(i_vlc);
return NOERROR;
}
*volume = 0;
return E_UNEXPECTED;
}; };
STDMETHODIMP VLCControl::put_Volume(int volume) STDMETHODIMP VLCControl::put_Volume(int volume)
{ {
int i_vlc = _p_instance->getVLCObject(); _p_instance->setVolume(volume);
if( i_vlc ) return NOERROR;
{
VLC_VolumeSet(i_vlc, volume);
return NOERROR;
}
return E_UNEXPECTED;
}; };
STDMETHODIMP VLCControl::toggleMute(void) STDMETHODIMP VLCControl::toggleMute(void)
......
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