Commit ce151324 authored by Sergey Radionov's avatar Sergey Radionov Committed by Jean-Baptiste Kempf

ActiveX: switch to vlc_player

Signed-off-by: Jean-Baptiste Kempf's avatarJean-Baptiste Kempf <jb@videolan.org>
parent 0cc7eea5
......@@ -221,9 +221,6 @@ VLCPlugin::VLCPlugin(VLCPluginClass *p_class, LPUNKNOWN pUnkOuter) :
_p_class(p_class),
_i_ref(1UL),
_p_libvlc(NULL),
_p_mlist(NULL),
_p_mplayer(NULL),
_i_midx(-1),
_i_codepage(CP_ACP),
_b_usermode(TRUE)
{
......@@ -307,16 +304,14 @@ VLCPlugin::~VLCPlugin()
SysFreeString(_bstr_mrl);
SysFreeString(_bstr_baseurl);
if( _p_mplayer )
if( vlc_player::is_open() )
{
if( isPlaying() )
playlist_stop();
player_unregister_events();
libvlc_media_player_release(_p_mplayer);
_p_mplayer=NULL;
}
if( _p_mlist ) { libvlc_media_list_release(_p_mlist); _p_mlist=NULL; }
if( _p_libvlc ) { libvlc_release(_p_libvlc); _p_libvlc=NULL; }
_p_class->Release();
......@@ -536,7 +531,10 @@ void VLCPlugin::initVLC()
if( !_p_libvlc )
return;
_p_mlist = libvlc_media_list_new(_p_libvlc);
if( !vlc_player::open(_p_libvlc) )
return;
set_player_window();
// initial playlist item
if( SysStringLen(_bstr_mrl) > 0 )
......@@ -752,9 +750,9 @@ HRESULT VLCPlugin::onActivateInPlace(LPMSG, HWND hwndParent, LPCRECT lprcPosRect
if( FAILED(result) )
return result;
if( get_autoplay() && playlist_select(0) )
if( get_autoplay() )
{
libvlc_media_player_play(_p_mplayer);
vlc_player::play(0);
fireOnPlayEvent();
}
}
......@@ -844,9 +842,9 @@ void VLCPlugin::setTime(int seconds)
if( seconds != _i_time )
{
setStartTime(_i_time);
if( NULL != _p_mplayer )
if( vlc_player::is_open() )
{
libvlc_media_player_set_time(_p_mplayer, _i_time);
vlc_player::set_time(_i_time);
}
}
};
......@@ -1240,76 +1238,17 @@ static void handle_pausable_changed_event(const libvlc_event_t* event, void *par
/* */
bool VLCPlugin::playlist_select( int idx )
{
//In some cases, libvlc may not have been initialized yet.
//So check it and initialize if needed (in getVLC())
libvlc_instance_t* p_libvlc;
HRESULT hr = getVLC(&p_libvlc);
if( FAILED(hr) || !p_libvlc)
return false;
if(!_p_mlist)
return false;//playlist does not exist, nothing to play...
libvlc_media_t *p_m = NULL;
assert(_p_mlist);
libvlc_media_list_lock(_p_mlist);
int count = libvlc_media_list_count(_p_mlist);
if( (idx < 0) || (idx >= count) )
goto bad_unlock;
_i_midx = idx;
p_m = libvlc_media_list_item_at_index(_p_mlist,_i_midx);
libvlc_media_list_unlock(_p_mlist);
if( !p_m )
return false;
if( _p_mplayer )
{
if( isPlaying() )
playlist_stop();
player_unregister_events();
_WindowsManager.LibVlcDetach();
libvlc_media_player_release( _p_mplayer );
_p_mplayer = NULL;
}
_p_mplayer = libvlc_media_player_new_from_media(p_m);
if( _p_mplayer )
{
// initial volume setting
libvlc_audio_set_volume(_p_mplayer, _i_volume);
if( _b_mute )
libvlc_audio_set_mute(_p_mplayer, TRUE);
set_player_window();
player_register_events();
}
libvlc_media_release(p_m);
return _p_mplayer ? true : false;
bad_unlock:
libvlc_media_list_unlock(_p_mlist);
return false;
}
void VLCPlugin::set_player_window()
{
_WindowsManager.LibVlcAttach(_p_mplayer);
_WindowsManager.LibVlcAttach(vlc_player::get_mp());
}
void VLCPlugin::player_register_events()
{
libvlc_event_manager_t *eventManager = NULL;
assert(_p_mplayer);
assert(vlc_player::is_open());
eventManager = libvlc_media_player_event_manager(_p_mplayer);
eventManager = libvlc_media_player_event_manager(vlc_player::get_mp());
if(eventManager) {
libvlc_event_attach(eventManager, libvlc_MediaPlayerNothingSpecial,
handle_input_state_event, this);
......@@ -1346,9 +1285,9 @@ void VLCPlugin::player_register_events()
void VLCPlugin::player_unregister_events()
{
libvlc_event_manager_t *eventManager = NULL;
assert(_p_mplayer);
assert(vlc_player::is_open());
eventManager = libvlc_media_player_event_manager(_p_mplayer);
eventManager = libvlc_media_player_event_manager(vlc_player::get_mp());
if(eventManager) {
libvlc_event_detach(eventManager, libvlc_MediaPlayerNothingSpecial,
handle_input_state_event, this);
......@@ -1381,22 +1320,3 @@ void VLCPlugin::player_unregister_events()
handle_pausable_changed_event, this);
}
}
int VLCPlugin::playlist_add_extended_untrusted(const char *mrl, int optc, const char **optv)
{
int item = -1;
libvlc_media_t *p_m = libvlc_media_new_location(_p_libvlc,mrl);
if( !p_m )
return -1;
for( int i = 0; i < optc; ++i )
libvlc_media_add_option_flag(p_m, optv[i], libvlc_media_option_unique);
libvlc_media_list_lock(_p_mlist);
if( libvlc_media_list_add_media(_p_mlist,p_m) == 0 )
item = libvlc_media_list_count(_p_mlist)-1;
libvlc_media_list_unlock(_p_mlist);
libvlc_media_release(p_m);
return item;
}
......@@ -33,6 +33,7 @@
#include "../common/win32_fullscreen.h"
#include "../common/vlc_player_options.h"
#include "../common/vlc_player.h"
extern "C" const GUID CLSID_VLCPlugin;
extern "C" const GUID CLSID_VLCPlugin2;
......@@ -75,7 +76,8 @@ private:
LPPICTURE _inplace_picture;
};
struct VLCPlugin : public IUnknown, private vlc_player_options
struct VLCPlugin
: public IUnknown, private vlc_player_options, private vlc_player
{
public:
VLCPlugin(VLCPluginClass *p_class, LPUNKNOWN pUnkOuter);
......@@ -90,6 +92,12 @@ public:
REFCLSID getClassID(void) { return _p_class->getClassID(); };
REFIID getDispEventID(void) { return (REFIID)DIID_DVLCEvents; };
vlc_player& get_player()
{
if( !vlc_player::is_open() ) initVLC();
return *static_cast<vlc_player*>(this);
}
vlc_player_options& get_options()
{ return *static_cast<vlc_player_options*>(this); }
const vlc_player_options& get_options() const
......@@ -212,10 +220,9 @@ public:
}
HRESULT getMD(libvlc_media_player_t **pp_md)
{
*pp_md = _p_mplayer;
return _p_mplayer ? S_OK : E_FAIL;
*pp_md = get_player().get_mp();
return *pp_md ? S_OK : E_FAIL;
}
void setErrorInfo(REFIID riid, const char *description);
// control geometry within container
......@@ -223,7 +230,6 @@ public:
inline HWND getInPlaceWindow(void) const { return _inplacewnd; };
void toggleFullscreen();
BOOL isInPlaceActive(void);
/*
......@@ -274,66 +280,51 @@ public:
*/
bool isPlaying()
{
return _p_mplayer && libvlc_media_player_is_playing(_p_mplayer);
return get_player().is_playing();
}
int playlist_get_current_index()
{
return get_player().current_item();
}
int playlist_add_extended_untrusted(const char *mrl, int optc, const char **optv)
{
return get_player().add_item(mrl, optc, optv);
}
int playlist_get_current_index() { return _i_midx; }
int playlist_add_extended_untrusted(const char *, int, const char **);
void playlist_delete_item(int idx)
{
if( _p_mlist )
{
libvlc_media_list_lock(_p_mlist);
libvlc_media_list_remove_index(_p_mlist,idx);
libvlc_media_list_unlock(_p_mlist);
}
get_player().delete_item(idx);
}
void playlist_clear()
{
if( !_p_libvlc )
return;
if( _p_mlist )
libvlc_media_list_release(_p_mlist);
_p_mlist = libvlc_media_list_new(_p_libvlc);
get_player().clear_items();
}
int playlist_count()
{
int r = 0;
if( !_p_mlist )
return 0;
libvlc_media_list_lock(_p_mlist);
r = libvlc_media_list_count(_p_mlist);
libvlc_media_list_unlock(_p_mlist);
return r;
return get_player().items_count();
}
void playlist_pause()
{
if( isPlaying() )
libvlc_media_player_pause(_p_mplayer);
get_player().pause();
}
void playlist_play()
{
if( _p_mplayer || playlist_select(0) )
libvlc_media_player_play(_p_mplayer);
get_player().play();
}
void playlist_play_item(int idx)
{
if( playlist_select(idx) )
libvlc_media_player_play(_p_mplayer);
get_player().play(idx);
}
void playlist_stop()
{
if( _p_mplayer )
libvlc_media_player_stop(_p_mplayer);
get_player().stop();
}
void playlist_next()
{
if( playlist_select( _i_midx+1 ) )
libvlc_media_player_play(_p_mplayer);
get_player().next();
}
void playlist_prev()
{
if( playlist_select( _i_midx-1 ) )
libvlc_media_player_play(_p_mplayer);
get_player().prev();
}
protected:
......@@ -342,7 +333,6 @@ protected:
private:
void initVLC();
bool playlist_select(int i);
void set_player_window();
void player_register_events();
void player_unregister_events();
......@@ -373,9 +363,6 @@ private:
ULONG _i_ref;
libvlc_instance_t *_p_libvlc;
libvlc_media_list_t *_p_mlist;
libvlc_media_player_t *_p_mplayer;
int _i_midx;
UINT _i_codepage;
BOOL _b_usermode;
......
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