]> git.sesse.net Git - vlc/commitdiff
plugin.cpp, plugin.h: delayed initialization of VLC until activation in place in...
authorDamien Fouilleul <damienf@videolan.org>
Mon, 20 Mar 2006 14:37:41 +0000 (14:37 +0000)
committerDamien Fouilleul <damienf@videolan.org>
Mon, 20 Mar 2006 14:37:41 +0000 (14:37 +0000)
    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

activex/persistpropbag.cpp
activex/plugin.cpp
activex/plugin.h
activex/test.html
activex/vlccontrol.cpp

index dccb1d4ac0edf6c63b5c9ba824bac604d47f6aa9..3fd06fbf28856877570401f9f4494f417ea6cc70 100644 (file)
@@ -161,11 +161,10 @@ STDMETHODIMP VLCPersistPropertyBag::Load(LPPROPERTYBAG pPropBag, LPERRORLOG pErr
         }
     }
 
-    int i_vlc = _p_instance->getVLCObject();
     V_VT(&value) = VT_I4;
     if( S_OK == pPropBag->Read(OLESTR("volume"), &value, pErrorLog) )
     {
-        VLC_VolumeSet(i_vlc, V_I4(&value));
+        _p_instance->setVolume(V_I4(&value));
         VariantClear(&value);
     }
     return _p_instance->onLoad();
@@ -208,14 +207,10 @@ STDMETHODIMP VLCPersistPropertyBag::Save(LPPROPERTYBAG pPropBag, BOOL fClearDirt
     pPropBag->Write(OLESTR("Visible"), &value);
     VariantClear(&value);
 
-    int i_vlc = _p_instance->getVLCObject();
-    if( i_vlc )
-    {
-        V_VT(&value) = VT_I4;
-        V_I4(&value) = VLC_VolumeGet(i_vlc);
-        pPropBag->Write(OLESTR("Volume"), &value);
-        VariantClear(&value);
-    }
+    V_VT(&value) = VT_I4;
+    V_I4(&value) = _p_instance->getVolume();
+    pPropBag->Write(OLESTR("Volume"), &value);
+    VariantClear(&value);
 
     if( fClearDirty )
         _p_instance->setDirty(FALSE);
index b8c6086f9997d679e28f1c402749370d453032d3..e0a8f349f4c0a6151b55a9776e95787889dadabe 100644 (file)
@@ -244,15 +244,11 @@ STDMETHODIMP VLCPluginClass::LockServer(BOOL fLock)
 
 VLCPlugin::VLCPlugin(VLCPluginClass *p_class, LPUNKNOWN pUnkOuter) :
     _inplacewnd(NULL),
+    _videownd(NULL),
     _p_class(p_class),
     _i_ref(1UL),
     _i_codepage(CP_ACP),
     _b_usermode(TRUE),
-    _bstr_mrl(NULL),
-    _b_autoplay(TRUE),
-    _b_autoloop(FALSE),
-    _b_visible(TRUE),
-    _b_mute(FALSE),
     _i_vlc(0)
 {
     p_class->AddRef();
@@ -277,12 +273,8 @@ VLCPlugin::VLCPlugin(VLCPluginClass *p_class, LPUNKNOWN pUnkOuter) :
     // default picure
     _p_pict = p_class->getInPlacePict();
 
-    // set default/preferred size (320x240) pixels in HIMETRIC
-    HDC hDC = CreateDevDC(NULL);
-    _extent.cx = 320;
-    _extent.cy = 240;
-    HimetricFromDP(hDC, (LPPOINT)&_extent, 1);
-    DeleteDC(hDC);
+    // make sure that persistable properties are initialized
+    onInit();
 };
 
 VLCPlugin::~VLCPlugin()
@@ -474,61 +466,20 @@ HRESULT VLCPlugin::onInit(void)
 {
     if( 0 == _i_vlc )
     {
-        _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];
-        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";
-        }
+        // initialize persistable properties
+        _bstr_mrl = NULL;
+        _b_autoplay = TRUE;
+        _b_autoloop = FALSE;
+        _b_visible = TRUE;
+        _b_mute = FALSE;
+        _i_volume = 50;
+        // set default/preferred size (320x240) pixels in HIMETRIC
+        HDC hDC = CreateDevDC(NULL);
+        _extent.cx = 320;
+        _extent.cy = 240;
+        HimetricFromDP(hDC, (LPPOINT)&_extent, 1);
+        DeleteDC(hDC);
 
-        if( VLC_Init(_i_vlc, ppsz_argc, ppsz_argv) )
-        {
-            VLC_Destroy(_i_vlc);
-            _i_vlc = 0;
-            return E_FAIL;
-        }
         return S_OK;
     }
     return CO_E_ALREADYINITIALIZED;
@@ -536,9 +487,6 @@ HRESULT VLCPlugin::onInit(void)
 
 HRESULT VLCPlugin::onLoad(void)
 {
-    if( _b_mute )
-        VLC_VolumeMute(_i_vlc);
-
     if( SysStringLen(_bstr_mrl) > 0 )
     {
         /*
@@ -585,23 +533,91 @@ HRESULT VLCPlugin::onLoad(void)
             }
             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);
         if( NULL != psz_mrl )
         {
             // add default target to playlist
-            char *cOptions[1];
-            int  cOptionsCount = 0;
-
-            if( _b_autoloop )
-            {
-                cOptions[cOptionsCount++] = "loop";
-            }
-            VLC_AddTarget(_i_vlc, psz_mrl, (const char **)&cOptions, cOptionsCount, PLAYLIST_APPEND, PLAYLIST_END);
+            VLC_AddTarget(_i_vlc, psz_mrl, NULL, 0, PLAYLIST_APPEND, PLAYLIST_END);
             CoTaskMemFree(psz_mrl);
         }
     }
-    setDirty(FALSE);
     return S_OK;
 };
 
@@ -665,9 +681,9 @@ HRESULT VLCPlugin::onAmbientChanged(LPUNKNOWN pContainer, DISPID dispID)
         case DISPID_AMBIENT_TOPTOBOTTOM:
             break;
         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);
             V_VT(&v) = VT_BOOL;
             if( SUCCEEDED(GetObjectProperty(pContainer, DISPID_AMBIENT_USERMODE, v)) )
@@ -687,15 +703,15 @@ HRESULT VLCPlugin::onAmbientChanged(LPUNKNOWN pContainer, DISPID dispID)
 
 HRESULT VLCPlugin::onClose(DWORD dwSaveOption)
 {
-    if( _i_vlc )
+    if( isInPlaceActive() )
+    {
+        onInPlaceDeactivate();
+    }
+    if( isRunning() )
     {
         int i_vlc = _i_vlc;
 
         _i_vlc = 0;
-        if( isInPlaceActive() )
-        {
-            onInPlaceDeactivate();
-        }
         vlcDataObject->onClose();
 
         VLC_CleanUp(i_vlc);
@@ -778,30 +794,41 @@ HRESULT VLCPlugin::onActivateInPlace(LPMSG lpMesg, HWND hwndParent, LPCRECT lprc
     if( getVisible() )
         ShowWindow(_inplacewnd, SW_SHOW);
 
-    /* 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_usermode && _b_autoplay & (VLC_PlaylistNumberOfItems(_i_vlc) > 0) )
+    if( _b_usermode )
     {
-        VLC_Play(_i_vlc);
-        fireOnPlayEvent();
+        /* run vlc if not done already */
+        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;
 };
 
 HRESULT VLCPlugin::onInPlaceDeactivate(void)
 {
-    VLC_Stop(_i_vlc);
-    fireOnStopEvent();
+    if( isRunning() )
+    {
+        VLC_Stop(_i_vlc);
+        fireOnStopEvent();
+    }
 
     DestroyWindow(_videownd);
     _videownd = NULL;
@@ -819,11 +846,32 @@ void VLCPlugin::setVisible(BOOL fVisible)
         if( isInPlaceActive() )
         {
             ShowWindow(_inplacewnd, fVisible ? SW_SHOW : SW_HIDE);
+            if( fVisible )
+                InvalidateRect(_videownd, NULL, TRUE);
         }
+        setDirty(TRUE);
         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)
 {
     if( fFocus )
index 2d10eac433de34fec3ba74873969745ce0d165a4..843bac502fe65f53ed188a647c2d91407bae1625 100644 (file)
@@ -109,6 +109,9 @@ public:
     };
     inline BOOL getAutoLoop(void) { return _b_autoloop;};
 
+    void setVolume(int volume);
+    BOOL getVolume(void) { return _i_volume; };
+
     void setVisible(BOOL fVisible);
     BOOL getVisible(void) { return _b_visible; };
 
@@ -172,6 +175,7 @@ public:
     */
     HRESULT onInit(void);
     HRESULT onLoad(void);
+    HRESULT onRun(void);
     HRESULT onActivateInPlace(LPMSG lpMesg, HWND hwndParent, LPCRECT lprcPosRect, LPCRECT lprcClipRect);
     HRESULT onInPlaceDeactivate(void);
     HRESULT onAmbientChanged(LPUNKNOWN pContainer, DISPID dispID);
@@ -222,19 +226,21 @@ private:
     VLCPluginClass *_p_class;
     ULONG _i_ref;
 
-    LPPICTURE _p_pict;
     UINT _i_codepage;
     BOOL _b_usermode;
+    int  _i_vlc;
+    RECT _posRect;
+
+    // persistable properties
     BSTR _bstr_mrl;
     BOOL _b_autoplay;
     BOOL _b_autoloop;
     BOOL _b_visible;
     BOOL _b_mute;
     BOOL _b_dirty;
-    int  _i_vlc;
-
+    int  _i_volume;
     SIZEL _extent;
-    RECT _posRect;
+    LPPICTURE _p_pict;
 };
 
 #endif
index 36425b84f0b5b6e9b190914ad692ba853f6609b4..bf593290f626dd047c3f3c8fa55607337288d89b 100644 (file)
@@ -11,12 +11,17 @@ MRL:
 <!--
 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"
-        width="640" height="480" id="vlc" events="True">
+<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"
+        width="640"
+        height="480"
+        id="vlc"
+        events="True">
 <param name="MRL" value="" />
 <param name="ShowDisplay" value="True" />
 <param name="AutoLoop" value="False" />
 <param name="AutoPlay" value="False" />
+<param name="Volume" value="50" />
 </OBJECT>
 </TD></TR>
 <TR><TD>
@@ -24,7 +29,10 @@ Insert VideoLAN.VLCPlugin.1 activex control
 Insert MSComctlLib.Slider.2 activex control
 -->
 <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="Min" value="0" />
 <param name="Max" value="0" />
@@ -37,19 +45,40 @@ Insert MSComctlLib.Slider.2 activex control
 <TR><TD colspan="2">
 <INPUT type=button id="PlayOrPause" value=" Play " onClick='doPlayOrPause()'>
 <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.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="Hide" onClick='document.vlc.Visible = false;'>
+&nbsp;
 <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>
 <SCRIPT LANGUAGE="JScript">
 <!--
 var sliderTimerId = 0;
 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)
 {
     var timeHour = timeVal;
index cbd467946d61a3840e20d9490ce26b534c06050f..39e2fd6899f722c4bf187872ee51318fda814124 100644 (file)
@@ -288,25 +288,14 @@ STDMETHODIMP VLCControl::get_Volume(int *volume)
     if( NULL == volume )
         return E_POINTER;
 
-    int i_vlc = _p_instance->getVLCObject();
-    if( i_vlc )
-    {
-        *volume  = VLC_VolumeGet(i_vlc);
-        return NOERROR;
-    }
-    *volume = 0;
-    return E_UNEXPECTED;
+    *volume  = _p_instance->getVolume();
+    return NOERROR;
 };
         
 STDMETHODIMP VLCControl::put_Volume(int volume)
 {
-    int i_vlc = _p_instance->getVLCObject();
-    if( i_vlc )
-    {
-        VLC_VolumeSet(i_vlc, volume);
-        return NOERROR;
-    }
-    return E_UNEXPECTED;
+    _p_instance->setVolume(volume);
+    return NOERROR;
 };
         
 STDMETHODIMP VLCControl::toggleMute(void)