* Copyright (C) 2005 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"
STDMETHODIMP VLCControl::play(void)
{
- libvlc_instance_t* p_libvlc;
- HRESULT result = _p_instance->getVLC(&p_libvlc);
- if( SUCCEEDED(result) )
- {
- libvlc_exception_t ex;
- libvlc_exception_init(&ex);
+ libvlc_exception_t ex;
+ libvlc_exception_init(&ex);
- libvlc_playlist_play(p_libvlc, -1, 0, NULL, &ex);
- if( libvlc_exception_raised(&ex) )
- {
- _p_instance->setErrorInfo(IID_IVLCControl,
- libvlc_exception_get_message(&ex));
- libvlc_exception_clear(&ex);
- return E_FAIL;
- }
+ _p_instance->playlist_play(&ex);
+ HRESULT result = exception_bridge(&ex);
+ if( SUCCEEDED(result) )
_p_instance->fireOnPlayEvent();
- return NOERROR;
- }
return result;
};
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) )
{
libvlc_exception_t ex;
libvlc_exception_init(&ex);
- libvlc_playlist_pause(p_libvlc, &ex);
- if( libvlc_exception_raised(&ex) )
- {
- _p_instance->setErrorInfo(IID_IVLCControl,
- libvlc_exception_get_message(&ex));
- libvlc_exception_clear(&ex);
- return E_FAIL;
- }
- _p_instance->fireOnPauseEvent();
- return NOERROR;
+ libvlc_media_player_pause(p_md, &ex);
+ result = exception_bridge(&ex);
+ if( SUCCEEDED(result) )
+ _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) )
{
libvlc_exception_t ex;
libvlc_exception_init(&ex);
- libvlc_playlist_stop(p_libvlc, &ex);
- if( libvlc_exception_raised(&ex) )
- {
- _p_instance->setErrorInfo(IID_IVLCControl,
- libvlc_exception_get_message(&ex));
- libvlc_exception_clear(&ex);
- return E_FAIL;
- }
- return NOERROR;
+ libvlc_media_player_stop(p_md, &ex);
+ result = exception_bridge(&ex);
+ if( SUCCEEDED(result) )
+ _p_instance->fireOnStopEvent();
}
- _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, NULL) ?
+ VARIANT_TRUE : VARIANT_FALSE;
+ } else *isPlaying = VARIANT_FALSE;
return result;
};
return E_POINTER;
*position = 0.0f;
- libvlc_instance_t* p_libvlc;
- HRESULT result = E_UNEXPECTED;
- result = _p_instance->getVLC(&p_libvlc);
+ libvlc_media_player_t *p_md;
+ HRESULT result = _p_instance->getMD(&p_md);
if( SUCCEEDED(result) )
{
libvlc_exception_t ex;
libvlc_exception_init(&ex);
- libvlc_media_player_t *p_md;
- p_md = libvlc_playlist_get_media_player(p_libvlc, &ex);
- if( !libvlc_exception_raised(&ex) )
- {
- *position = libvlc_media_player_get_position(p_md, &ex);
- libvlc_media_player_release(p_md);
- if( ! libvlc_exception_raised(&ex) )
- {
- return NOERROR;
- }
- }
- _p_instance->setErrorInfo(IID_IVLCControl,
- libvlc_exception_get_message(&ex));
- libvlc_exception_clear(&ex);
- return E_FAIL;
+ *position = libvlc_media_player_get_position(p_md, &ex);
+ result = exception_bridge(&ex);
}
return result;
};
STDMETHODIMP VLCControl::put_Position(float position)
{
- HRESULT result = E_UNEXPECTED;
- libvlc_instance_t* p_libvlc;
- result = _p_instance->getVLC(&p_libvlc);
+ libvlc_media_player_t *p_md;
+ HRESULT result = _p_instance->getMD(&p_md);
if( SUCCEEDED(result) )
{
libvlc_exception_t ex;
libvlc_exception_init(&ex);
- libvlc_media_player_t *p_md;
- p_md = libvlc_playlist_get_media_player(p_libvlc, &ex);
- if( ! libvlc_exception_raised(&ex) )
- {
- libvlc_media_player_set_position(p_md, position, &ex);
- libvlc_media_player_release(p_md);
- if( ! libvlc_exception_raised(&ex) )
- {
- return NOERROR;
- }
- }
- _p_instance->setErrorInfo(IID_IVLCControl,
- libvlc_exception_get_message(&ex));
- libvlc_exception_clear(&ex);
- return E_FAIL;
+ libvlc_media_player_set_position(p_md, position, &ex);
+ result = exception_bridge(&ex);
}
return result;
};
return E_POINTER;
*seconds = 0;
- 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) )
{
libvlc_exception_t ex;
libvlc_exception_init(&ex);
- libvlc_media_player_t *p_md;
- p_md = libvlc_playlist_get_media_player(p_libvlc, &ex);
- if( ! libvlc_exception_raised(&ex) )
- {
- *seconds = libvlc_media_player_get_time(p_md, &ex);
- libvlc_media_player_release(p_md);
- if( ! libvlc_exception_raised(&ex) )
- {
- return NOERROR;
- }
- }
- _p_instance->setErrorInfo(IID_IVLCControl,
- libvlc_exception_get_message(&ex));
- libvlc_exception_clear(&ex);
- return E_FAIL;
+ *seconds = libvlc_media_player_get_time(p_md, &ex);
+ result = exception_bridge(&ex);
}
return result;
};
STDMETHODIMP VLCControl::shuttle(int seconds)
{
- 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) )
{
libvlc_exception_t ex;
libvlc_exception_init(&ex);
- libvlc_media_player_t *p_md;
- p_md = libvlc_playlist_get_media_player(p_libvlc, &ex);
- if( ! libvlc_exception_raised(&ex) )
- {
- if( seconds < 0 ) seconds = 0;
- libvlc_media_player_set_time(p_md, (int64_t)seconds, &ex);
- libvlc_media_player_release(p_md);
- if( ! libvlc_exception_raised(&ex) )
- {
- return NOERROR;
- }
- }
- _p_instance->setErrorInfo(IID_IVLCControl,
- libvlc_exception_get_message(&ex));
- libvlc_exception_clear(&ex);
- return E_FAIL;
+ if( seconds < 0 ) seconds = 0;
+ libvlc_media_player_set_time(p_md, (int64_t)seconds, &ex);
+ result = exception_bridge(&ex);
}
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, NULL) )
{
- 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, NULL);
}
}
return result;
return E_POINTER;
*seconds = 0;
- 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) )
{
libvlc_exception_t ex;
libvlc_exception_init(&ex);
- libvlc_media_player_t *p_md;
- p_md = libvlc_playlist_get_media_player(p_libvlc, &ex);
- if( ! libvlc_exception_raised(&ex) )
- {
- *seconds = (double)libvlc_media_player_get_length(p_md, &ex);
- libvlc_media_player_release(p_md);
- if( ! libvlc_exception_raised(&ex) )
- {
- return NOERROR;
- }
- }
- _p_instance->setErrorInfo(IID_IVLCControl,
- libvlc_exception_get_message(&ex));
- libvlc_exception_clear(&ex);
- return E_FAIL;
+ *seconds = (double)libvlc_media_player_get_length(p_md, &ex);
+ result = exception_bridge(&ex);
}
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_exception_t ex;
+ libvlc_exception_init(&ex);
+
+ libvlc_media_player_set_rate(p_md, rate, &ex);
+ result = exception_bridge(&ex);
}
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_exception_t ex;
+ libvlc_exception_init(&ex);
+
+ libvlc_media_player_set_rate(p_md, rate, &ex);
+ result = exception_bridge(&ex);
}
return result;
};
libvlc_exception_init(&ex);
libvlc_audio_toggle_mute(p_libvlc, &ex);
- if( libvlc_exception_raised(&ex) )
- {
- _p_instance->setErrorInfo(IID_IVLCControl,
- libvlc_exception_get_message(&ex));
- libvlc_exception_clear(&ex);
- return E_FAIL;
- }
- return NOERROR;
+ result = exception_bridge(&ex);
}
return result;
};
STDMETHODIMP VLCControl::setVariable(BSTR name, VARIANT 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) )
{
- 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) )
+ libvlc_exception_t ex;
+ libvlc_exception_init(&ex);
+
+ position = _p_instance->playlist_add_extended_untrusted(cUri,
+ cOptionsCount, const_cast<const char**>(cOptions), &ex);
+
+ FreeTargetOptions(cOptions, cOptionsCount);
+ CoTaskMemFree(cUri);
+
+ hr = exception_bridge(&ex);
+ if( SUCCEEDED(hr) )
{
- 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;
+ libvlc_exception_t ex;
+ libvlc_exception_init(&ex);
+
+ *index = _p_instance->playlist_get_current_index(&ex);
+ result = exception_bridge(&ex);
}
- *index = 0;
return result;
};
if( NULL == count )
return E_POINTER;
- *count = 0;
- libvlc_instance_t* p_libvlc;
- HRESULT result = _p_instance->getVLC(&p_libvlc);
- if( SUCCEEDED(result) )
- {
- libvlc_exception_t ex;
- libvlc_exception_init(&ex);
+ libvlc_exception_t ex;
+ libvlc_exception_init(&ex);
- *count = libvlc_playlist_items_count(p_libvlc, &ex);
- if( libvlc_exception_raised(&ex) )
- {
- _p_instance->setErrorInfo(IID_IVLCControl,
- libvlc_exception_get_message(&ex));
- libvlc_exception_clear(&ex);
- return E_FAIL;
- }
- return NOERROR;
- }
- return result;
+ *count = _p_instance->playlist_count(&ex);
+ return exception_bridge(&ex);
};
STDMETHODIMP VLCControl::playlistNext(void)
libvlc_exception_t ex;
libvlc_exception_init(&ex);
- libvlc_playlist_next(p_libvlc, &ex);
- if( libvlc_exception_raised(&ex) )
- {
- _p_instance->setErrorInfo(IID_IVLCControl,
- libvlc_exception_get_message(&ex));
- libvlc_exception_clear(&ex);
- return E_FAIL;
- }
- return NOERROR;
+ _p_instance->playlist_next(&ex);
+ result = exception_bridge(&ex);
}
return result;
};
libvlc_exception_t ex;
libvlc_exception_init(&ex);
- libvlc_playlist_prev(p_libvlc, &ex);
- if( libvlc_exception_raised(&ex) )
- {
- _p_instance->setErrorInfo(IID_IVLCControl,
- libvlc_exception_get_message(&ex));
- libvlc_exception_clear(&ex);
- return E_FAIL;
- }
- return NOERROR;
+ _p_instance->playlist_prev(&ex);
+ result = exception_bridge(&ex);
}
return result;
};
libvlc_exception_t ex;
libvlc_exception_init(&ex);
- libvlc_playlist_clear(p_libvlc, &ex);
- if( libvlc_exception_raised(&ex) )
- {
- _p_instance->setErrorInfo(IID_IVLCControl,
- libvlc_exception_get_message(&ex));
- libvlc_exception_clear(&ex);
- return E_FAIL;
- }
- return NOERROR;
+ _p_instance->playlist_clear(&ex);
+ result = exception_bridge(&ex);
}
return result;
};