/*****************************************************************************
* vlccontrol.cpp: ActiveX control for VLC
*****************************************************************************
- * Copyright (C) 2005 the VideoLAN team
+ * Copyright (C) 2005-2010 the VideoLAN team
*
* Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>
+ * Jean-Paul Saman <jpsaman@videolan.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include "plugin.h"
*isVisible = _p_instance->getVisible() ? VARIANT_TRUE : VARIANT_FALSE;
- return NOERROR;
+ return S_OK;
};
STDMETHODIMP VLCControl::put_Visible(VARIANT_BOOL isVisible)
{
_p_instance->setVisible(isVisible != VARIANT_FALSE);
- return NOERROR;
+ return S_OK;
};
STDMETHODIMP VLCControl::play(void)
{
- libvlc_instance_t *p_libvlc;
- HRESULT result = _p_instance->getVLC(&p_libvlc);
- if( SUCCEEDED(result) )
- {
- VLC_Play(i_vlc);
- _p_instance->fireOnPlayEvent();
- }
- return result;
+ _p_instance->playlist_play();
+ _p_instance->fireOnPlayEvent();
+ return S_OK;
};
STDMETHODIMP VLCControl::pause(void)
{
- libvlc_instance_t *p_libvlc;
- HRESULT result = _p_instance->getVLC(&p_libvlc);
+ libvlc_media_player_t* p_md;
+ HRESULT result = _p_instance->getMD(&p_md);
if( SUCCEEDED(result) )
{
- VLC_Pause(i_vlc);
+ libvlc_media_player_pause(p_md);
_p_instance->fireOnPauseEvent();
}
return result;
STDMETHODIMP VLCControl::stop(void)
{
- libvlc_instance_t *p_libvlc;
- HRESULT result = _p_instance->getVLC(&p_libvlc);
+ libvlc_media_player_t *p_md;
+ HRESULT result = _p_instance->getMD(&p_md);
if( SUCCEEDED(result) )
{
- VLC_Stop(i_vlc);
+ libvlc_media_player_stop(p_md);
_p_instance->fireOnStopEvent();
}
return result;
if( NULL == isPlaying )
return E_POINTER;
- HRESULT result = NOERROR;
- if( _p_instance->isRunning() )
+ libvlc_media_player_t *p_md;
+ HRESULT result = _p_instance->getMD(&p_md);
+ if( SUCCEEDED(result) )
{
- libvlc_instance_t *p_libvlc;
- result = _p_instance->getVLC(&p_libvlc);
- if( SUCCEEDED(result) )
- {
- if( libvlc_playlist_isplaying(p_libvlc, NULL) )
- *isPlaying = VARIANT_TRUE;
- else
- *isPlaying = VARIANT_FALSE;
- return NOERROR;
- }
- }
- *isPlaying = VARIANT_FALSE;
+ *isPlaying = libvlc_media_player_is_playing(p_md) ?
+ VARIANT_TRUE : VARIANT_FALSE;
+ } else *isPlaying = VARIANT_FALSE;
return result;
};
{
if( NULL == position )
return E_POINTER;
+ *position = 0.0f;
- HRESULT result = E_UNEXPECTED;
- if( _p_instance->isRunning() )
+ libvlc_media_player_t *p_md;
+ HRESULT result = _p_instance->getMD(&p_md);
+ if( SUCCEEDED(result) )
{
- libvlc_instance_t *p_libvlc;
- result = _p_instance->getVLC(&p_libvlc);
- if( SUCCEEDED(result) )
- {
- *position = VLC_PositionGet(i_vlc);
- return NOERROR;
- }
+ *position = libvlc_media_player_get_position(p_md);
}
- *position = 0.0f;
return result;
};
STDMETHODIMP VLCControl::put_Position(float position)
{
- HRESULT result = E_UNEXPECTED;
- if( _p_instance->isRunning() )
+ libvlc_media_player_t *p_md;
+ HRESULT result = _p_instance->getMD(&p_md);
+ if( SUCCEEDED(result) )
{
- libvlc_instance_t *p_libvlc;
- result = _p_instance->getVLC(&p_libvlc);
- if( SUCCEEDED(result) )
- {
- VLC_PositionSet(i_vlc, position);
- }
+ libvlc_media_player_set_position(p_md, position);
}
return result;
};
if( NULL == seconds )
return E_POINTER;
- HRESULT result = NOERROR;
- if( _p_instance->isRunning() )
+ *seconds = 0;
+ libvlc_media_player_t *p_md;
+ HRESULT result = _p_instance->getMD(&p_md);
+ if( SUCCEEDED(result) )
{
- libvlc_instance_t *p_libvlc;
- result = _p_instance->getVLC(&p_libvlc);
- if( SUCCEEDED(result) )
- {
- *seconds = VLC_TimeGet(i_vlc);
- }
+ *seconds = libvlc_media_player_get_time(p_md);
}
- else
- *seconds = _p_instance->getTime();
-
return result;
};
STDMETHODIMP VLCControl::put_Time(int seconds)
{
+ /* setTime function of the plugin sets the time. */
_p_instance->setTime(seconds);
-
- return NOERROR;
+ return S_OK;
};
STDMETHODIMP VLCControl::shuttle(int seconds)
{
- HRESULT result = E_UNEXPECTED;
- if( _p_instance->isRunning() )
+ libvlc_media_player_t *p_md;
+ HRESULT result = _p_instance->getMD(&p_md);
+ if( SUCCEEDED(result) )
{
- libvlc_instance_t *p_libvlc;
- result = _p_instance->getVLC(&p_libvlc);
- if( SUCCEEDED(result) )
- {
- VLC_TimeSet(i_vlc, seconds, true);
- }
+ if( seconds < 0 ) seconds = 0;
+ libvlc_media_player_set_time(p_md, (int64_t)seconds);
}
return result;
+
};
STDMETHODIMP VLCControl::fullscreen(void)
{
- HRESULT result = E_UNEXPECTED;
- if( _p_instance->isRunning() )
+ libvlc_media_player_t *p_md;
+ HRESULT result = _p_instance->getMD(&p_md);
+ if( SUCCEEDED(result) )
{
- libvlc_instance_t *p_libvlc;
- result = _p_instance->getVLC(&p_libvlc);
- if( SUCCEEDED(result) )
+ if( libvlc_media_player_is_playing(p_md) )
{
- if( libvlc_playlist_isplaying(p_libvlc, NULL) )
- {
- libvlc_media_player_t *p_md =
- libvlc_playlist_get_media_player(p_libvlc, NULL);
- if( p_md )
- {
- libvlc_toggle_fullscreen(p_md, NULL);
- libvlc_media_player_release(p_md);
- }
- }
+ libvlc_toggle_fullscreen(p_md);
}
}
return result;
{
if( NULL == seconds )
return E_POINTER;
+ *seconds = 0;
- HRESULT result = NOERROR;
- if( _p_instance->isRunning() )
+ libvlc_media_player_t *p_md;
+ HRESULT result = _p_instance->getMD(&p_md);
+ if( SUCCEEDED(result) )
{
- libvlc_instance_t *p_libvlc;
- result = _p_instance->getVLC(&p_libvlc);
- if( SUCCEEDED(result) )
- {
- *seconds = VLC_LengthGet(i_vlc);
- return NOERROR;
- }
+ *seconds = (double)libvlc_media_player_get_length(p_md);
}
- *seconds = 0;
return result;
+
};
STDMETHODIMP VLCControl::playFaster(void)
{
- HRESULT result = E_UNEXPECTED;
- if( _p_instance->isRunning() )
+ int32_t rate = 2;
+
+ libvlc_media_player_t *p_md;
+ HRESULT result = _p_instance->getMD(&p_md);
+
+ if( SUCCEEDED(result) )
{
- libvlc_instance_t *p_libvlc;
- result = _p_instance->getVLC(&p_libvlc);
- if( SUCCEEDED(result) )
- {
- VLC_SpeedFaster(i_vlc);
- }
+ libvlc_media_player_set_rate(p_md, rate);
}
return result;
};
STDMETHODIMP VLCControl::playSlower(void)
{
- HRESULT result = E_UNEXPECTED;
- if( _p_instance->isRunning() )
+ float rate = 0.5;
+
+ libvlc_media_player_t *p_md;
+ HRESULT result = _p_instance->getMD(&p_md);
+ if( SUCCEEDED(result) )
{
- libvlc_instance_t *p_libvlc;
- result = _p_instance->getVLC(&p_libvlc);
- if( SUCCEEDED(result) )
- {
- VLC_SpeedSlower(i_vlc);
- }
+ libvlc_media_player_set_rate(p_md, rate);
}
return result;
};
return E_POINTER;
*volume = _p_instance->getVolume();
- return NOERROR;
+ return S_OK;
};
STDMETHODIMP VLCControl::put_Volume(int volume)
{
_p_instance->setVolume(volume);
- return NOERROR;
+ return S_OK;
};
STDMETHODIMP VLCControl::toggleMute(void)
{
- libvlc_instance_t *p_libvlc;
- HRESULT result = _p_instance->getVLC(&p_libvlc);
+ libvlc_media_player_t *p_md;
+ HRESULT result = _p_instance->getMD(&p_md);
if( SUCCEEDED(result) )
- {
- VLC_VolumeMute(i_vlc);
- }
+ libvlc_audio_toggle_mute(p_md);
return result;
};
STDMETHODIMP VLCControl::setVariable(BSTR name, VARIANT value)
{
- if( 0 == SysStringLen(name) )
- return E_INVALIDARG;
-
- libvlc_instance_t *p_libvlc;
+ libvlc_instance_t* p_libvlc;
HRESULT result = _p_instance->getVLC(&p_libvlc);
- if( SUCCEEDED(hr) )
+ if( SUCCEEDED(result) )
{
- int codePage = _p_instance->getCodePage();
- char *psz_varname = CStrFromBSTR(codePage, name);
- if( NULL == psz_varname )
- return E_OUTOFMEMORY;
-
- int i_type;
- vlc_value_t val;
-
- if( VLC_SUCCESS == VLC_VariableType(i_vlc, psz_varname, &i_type) )
- {
- VARIANT arg;
- VariantInit(&arg);
-
- switch( i_type )
- {
- case VLC_VAR_BOOL:
- hr = VariantChangeType(&arg, &value, 0, VT_BOOL);
- if( SUCCEEDED(hr) )
- val.b_bool = (VARIANT_TRUE == V_BOOL(&arg)) ? true : false;
- break;
-
- case VLC_VAR_INTEGER:
- case VLC_VAR_HOTKEY:
- hr = VariantChangeType(&arg, &value, 0, VT_I4);
- if( SUCCEEDED(hr) )
- val.i_int = V_I4(&arg);
- break;
-
- case VLC_VAR_FLOAT:
- hr = VariantChangeType(&arg, &value, 0, VT_R4);
- if( SUCCEEDED(hr) )
- val.f_float = V_R4(&arg);
- break;
-
- case VLC_VAR_STRING:
- case VLC_VAR_MODULE:
- case VLC_VAR_FILE:
- case VLC_VAR_DIRECTORY:
- case VLC_VAR_VARIABLE:
- hr = VariantChangeType(&arg, &value, 0, VT_BSTR);
- if( SUCCEEDED(hr) )
- {
- i_type = VLC_VAR_STRING;
- val.psz_string = CStrFromBSTR(codePage, V_BSTR(&arg));
- VariantClear(&arg);
- }
- break;
-
- case VLC_VAR_TIME:
- // use a double value to represent time (base is expressed in seconds)
- hr = VariantChangeType(&arg, &value, 0, VT_R8);
- if( SUCCEEDED(hr) )
- val.i_time = (signed __int64)(V_R8(&arg)*1000000.0);
- break;
-
- default:
- hr = DISP_E_TYPEMISMATCH;
- }
- }
- else {
- // no defined type, use type in VARIANT
- hr = NO_ERROR;
- switch( V_VT(&value) )
- {
- case VT_BOOL:
- val.b_bool = (VARIANT_TRUE == V_BOOL(&value)) ? true : false;
- i_type = VLC_VAR_BOOL;
- break;
- case VT_I4:
- val.i_int = V_I4(&value);
- i_type = VLC_VAR_INTEGER;
- break;
- case VT_R4:
- val.f_float = V_R4(&value);
- i_type = VLC_VAR_FLOAT;
- break;
- case VT_BSTR:
- val.psz_string = CStrFromBSTR(codePage, V_BSTR(&value));
- i_type = VLC_VAR_STRING;
- break;
- case VT_R8:
- // use a double value to represent time (base is expressed in seconds)
- val.i_time = (signed __int64)(V_R8(&value)*1000000.0);
- i_type = VLC_VAR_TIME;
- break;
- default:
- hr = DISP_E_TYPEMISMATCH;
- }
- }
- if( SUCCEEDED(hr) )
- {
- hr = (VLC_SUCCESS == VLC_VariableSet(i_vlc, psz_varname, val)) ? NOERROR : E_FAIL;
-
- if( (VLC_VAR_STRING == i_type) && (NULL != val.psz_string) )
- CoTaskMemFree(val.psz_string);
- }
- CoTaskMemFree(psz_varname);
+ _p_instance->setErrorInfo(IID_IVLCControl,
+ "setVariable() is an unsafe interface to use. "
+ "It has been removed because of security implications." );
}
- return hr;
+ return E_FAIL;
};
-STDMETHODIMP VLCControl::getVariable( BSTR name, VARIANT *value)
+STDMETHODIMP VLCControl::getVariable(BSTR name, VARIANT *value)
{
- if( NULL == value )
- return E_POINTER;
-
- VariantInit(value);
-
- if( 0 == SysStringLen(name) )
- return E_INVALIDARG;
-
- libvlc_instance_t *p_libvlc;
- HRESULT hr = _p_instance->getVLC(&p_libvlc);
- if( SUCCEEDED(hr) )
+ libvlc_instance_t* p_libvlc;
+ HRESULT result = _p_instance->getVLC(&p_libvlc);
+ if( SUCCEEDED(result) )
{
- UINT codePage = _p_instance->getCodePage();
- char *psz_varname = CStrFromBSTR(codePage, name);
- if( NULL == psz_varname )
- return E_OUTOFMEMORY;
-
- hr = E_INVALIDARG;
-
- vlc_value_t val;
- int i_type;
-
- if( (VLC_SUCCESS == VLC_VariableGet(i_vlc, psz_varname, &val))
- && (VLC_SUCCESS == VLC_VariableType(i_vlc, psz_varname, &i_type)) )
- {
- hr = NOERROR;
- switch( i_type )
- {
- case VLC_VAR_BOOL:
- V_VT(value) = VT_BOOL;
- V_BOOL(value) = val.b_bool ? VARIANT_TRUE : VARIANT_FALSE;
- break;
-
- case VLC_VAR_INTEGER:
- case VLC_VAR_HOTKEY:
- V_VT(value) = VT_I4;
- V_I4(value) = val.i_int;
- break;
-
- case VLC_VAR_FLOAT:
- V_VT(value) = VT_R4;
- V_R4(value) = val.f_float;
- break;
-
- case VLC_VAR_STRING:
- case VLC_VAR_MODULE:
- case VLC_VAR_FILE:
- case VLC_VAR_DIRECTORY:
- case VLC_VAR_VARIABLE:
- V_VT(value) = VT_BSTR;
- V_BSTR(value) = BSTRFromCStr(codePage, val.psz_string);
- if( NULL != val.psz_string)
- free(val.psz_string);
- break;
-
- case VLC_VAR_TIME:
- // use a double value to represent time (base is expressed in seconds)
- V_VT(value) = VT_R8;
- V_R8(value) = ((double)val.i_time)/1000000.0;
- break;
-
- default:
- hr = DISP_E_TYPEMISMATCH;
- }
- }
- CoTaskMemFree(psz_varname);
- return hr;
+ _p_instance->setErrorInfo(IID_IVLCControl,
+ "getVariable() is an unsafe interface to use. "
+ "It has been removed because of security implications." );
}
- return hr;
+ return E_FAIL;
};
void VLCControl::FreeTargetOptions(char **cOptions, int cOptionCount)
** for compatibility with some scripting language (JScript)
*/
-STDMETHODIMP VLCControl::addTarget( BSTR uri, VARIANT options, enum VLCPlaylistMode mode, int position)
+STDMETHODIMP VLCControl::addTarget(BSTR uri, VARIANT options, enum VLCPlaylistMode mode, int position)
{
if( 0 == SysStringLen(uri) )
return E_INVALIDARG;
if( FAILED(CreateTargetOptions(CP_UTF8, &options, &cOptions, &cOptionsCount)) )
return E_INVALIDARG;
- if( VLC_SUCCESS <= VLC_AddTarget(i_vlc, cUri, (const char **)cOptions, cOptionsCount, mode, position) )
+ position = _p_instance->playlist_add_extended_untrusted(cUri,
+ cOptionsCount, const_cast<const char**>(cOptions));
+
+ FreeTargetOptions(cOptions, cOptionsCount);
+ CoTaskMemFree(cUri);
+
+ if( position >= 0 )
{
- hr = NOERROR;
- if( mode & PLAYLIST_GO )
+ if( mode & VLCPlayListAppendAndGo )
_p_instance->fireOnPlayEvent();
}
else
{
- hr = E_FAIL;
- if( mode & PLAYLIST_GO )
+ if( mode & VLCPlayListAppendAndGo )
_p_instance->fireOnStopEvent();
}
-
- FreeTargetOptions(cOptions, cOptionsCount);
- CoTaskMemFree(cUri);
}
return hr;
};
if( NULL == index )
return E_POINTER;
+ *index = 0;
libvlc_instance_t *p_libvlc;
HRESULT result = _p_instance->getVLC(&p_libvlc);
if( SUCCEEDED(result) )
{
- *index = VLC_PlaylistIndex(i_vlc);
- return NOERROR;
+ *index = _p_instance->playlist_get_current_index();
}
- *index = 0;
return result;
};
STDMETHODIMP VLCControl::get_PlaylistCount(int *count)
{
- libvlc_instance_t *p_libvlc;
- HRESULT result = _p_instance->getVLC(&p_libvlc);
- if( SUCCEEDED(result) )
- {
- *count = VLC_PlaylistNumberOfItems(i_vlc);
- return NOERROR;
- }
- *count = 0;
- return result;
+ if( NULL == count )
+ return E_POINTER;
+
+ *count = _p_instance->playlist_count();
+ return S_OK;
};
STDMETHODIMP VLCControl::playlistNext(void)
{
- libvlc_instance_t *p_libvlc;
+ libvlc_instance_t* p_libvlc;
HRESULT result = _p_instance->getVLC(&p_libvlc);
if( SUCCEEDED(result) )
{
- VLC_PlaylistNext(i_vlc);
- return NOERROR;
+ _p_instance->playlist_next();
}
return result;
};
STDMETHODIMP VLCControl::playlistPrev(void)
{
- libvlc_instance_t *p_libvlc;
+ libvlc_instance_t* p_libvlc;
HRESULT result = _p_instance->getVLC(&p_libvlc);
if( SUCCEEDED(result) )
{
- VLC_PlaylistPrev(i_vlc);
- return NOERROR;
+ _p_instance->playlist_prev();
}
return result;
};
STDMETHODIMP VLCControl::playlistClear(void)
{
- libvlc_instance_t *p_libvlc;
+ libvlc_instance_t* p_libvlc;
HRESULT result = _p_instance->getVLC(&p_libvlc);
if( SUCCEEDED(result) )
{
- VLC_PlaylistClear(i_vlc);
- return NOERROR;
+ _p_instance->playlist_clear();
}
return result;
};
if( NULL != versionStr )
{
*version = BSTRFromCStr(CP_UTF8, versionStr);
-
- return NULL == *version ? E_OUTOFMEMORY : NOERROR;
+ return (NULL == *version) ? E_OUTOFMEMORY : NOERROR;
}
*version = NULL;
return E_FAIL;
*mrl = SysAllocStringLen(_p_instance->getMRL(),
SysStringLen(_p_instance->getMRL()));
- return NOERROR;
+ return S_OK;
};
STDMETHODIMP VLCControl::put_MRL(BSTR mrl)