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

NPAPI: switch VLCPlugin to vlc_player

Adapted-by: Jean-Baptiste Kempf's avatarJean-Baptiste Kempf <jb@videolan.org>
Signed-off-by: Jean-Baptiste Kempf's avatarJean-Baptiste Kempf <jb@videolan.org>
parent 817ac91d
......@@ -351,10 +351,7 @@ VlcPluginBase::VlcPluginBase( NPP instance, NPuint16_t mode ) :
i_npmode(mode),
b_stream(0),
psz_target(NULL),
playlist_index(-1),
libvlc_instance(NULL),
libvlc_media_list(NULL),
libvlc_media_player(NULL),
p_scriptClass(NULL),
p_browser(instance),
psz_baseURL(NULL)
......@@ -496,7 +493,8 @@ NPError VlcPluginBase::init(int argc, char* const argn[], char* const argv[])
libvlc_instance = libvlc_new(ppsz_argc, ppsz_argv);
if( !libvlc_instance )
return NPERR_GENERIC_ERROR;
libvlc_media_list = libvlc_media_list_new(libvlc_instance);
vlc_player::open(libvlc_instance);
/*
** fetch plugin base URL, which is the URL of the page containing the plugin
......@@ -557,15 +555,14 @@ VlcPluginBase::~VlcPluginBase()
free(psz_baseURL);
free(psz_target);
if( libvlc_media_player )
if( vlc_player::is_open() )
{
if( playlist_isplaying() )
playlist_stop();
events.unhook_manager( this );
libvlc_media_player_release( libvlc_media_player );
vlc_player::close();
}
if( libvlc_media_list )
libvlc_media_list_release( libvlc_media_list );
if( libvlc_instance )
libvlc_release( libvlc_instance );
......@@ -580,130 +577,11 @@ void VlcPluginBase::setWindow(const NPWindow &window)
/*****************************************************************************
* VlcPluginBase playlist replacement methods
*****************************************************************************/
int VlcPluginBase::playlist_add( const char *mrl )
{
int item = -1;
libvlc_media_t *p_m = libvlc_media_new_location(libvlc_instance,mrl);
if( !p_m )
return -1;
assert( libvlc_media_list );
libvlc_media_list_lock(libvlc_media_list);
if( !libvlc_media_list_add_media(libvlc_media_list,p_m) )
item = libvlc_media_list_count(libvlc_media_list)-1;
libvlc_media_list_unlock(libvlc_media_list);
libvlc_media_release(p_m);
return item;
}
int VlcPluginBase::playlist_add_extended_untrusted( const char *mrl, const char *,
int optc, const char **optv )
{
libvlc_media_t *p_m;
int item = -1;
assert( libvlc_media_list );
p_m = libvlc_media_new_location(libvlc_instance, 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(libvlc_media_list);
if( !libvlc_media_list_add_media(libvlc_media_list,p_m) )
item = libvlc_media_list_count(libvlc_media_list)-1;
libvlc_media_list_unlock(libvlc_media_list);
libvlc_media_release(p_m);
return item;
}
bool VlcPluginBase::playlist_select( int idx )
{
libvlc_media_t *p_m = NULL;
assert( libvlc_media_list );
libvlc_media_list_lock(libvlc_media_list);
int count = libvlc_media_list_count(libvlc_media_list);
if( idx<0||idx>=count )
goto bad_unlock;
playlist_index = idx;
p_m = libvlc_media_list_item_at_index(libvlc_media_list,playlist_index);
libvlc_media_list_unlock(libvlc_media_list);
if( !p_m )
return false;
if( libvlc_media_player )
{
if( playlist_isplaying() )
playlist_stop();
events.unhook_manager( this );
on_media_player_release();
libvlc_media_player_release( libvlc_media_player );
libvlc_media_player = NULL;
}
libvlc_media_player = libvlc_media_player_new_from_media( p_m );
if( libvlc_media_player )
{
on_media_player_new();
set_player_window();
libvlc_event_manager_t *p_em;
p_em = libvlc_media_player_event_manager( libvlc_media_player );
events.hook_manager( p_em, this );
}
libvlc_media_release( p_m );
return true;
bad_unlock:
libvlc_media_list_unlock( libvlc_media_list );
return false;
}
int VlcPluginBase::playlist_delete_item( int idx )
{
if( !libvlc_media_list )
return -1;
libvlc_media_list_lock(libvlc_media_list);
int ret = libvlc_media_list_remove_index(libvlc_media_list,idx);
libvlc_media_list_unlock(libvlc_media_list);
return ret;
}
void VlcPluginBase::playlist_clear()
{
if( libvlc_media_list )
libvlc_media_list_release(libvlc_media_list);
libvlc_media_list = libvlc_media_list_new(getVLC());
}
int VlcPluginBase::playlist_count()
{
int items_count = 0;
if( !libvlc_media_list )
return items_count;
libvlc_media_list_lock(libvlc_media_list);
items_count = libvlc_media_list_count(libvlc_media_list);
libvlc_media_list_unlock(libvlc_media_list);
return items_count;
}
bool VlcPluginBase::player_has_vout()
{
bool r = false;
if( playlist_isplaying() )
r = libvlc_media_player_has_vout(libvlc_media_player);
r = libvlc_media_player_has_vout(get_player().get_mp())!=0;
return r;
}
......
......@@ -82,6 +82,7 @@
#include "control/nporuntime.h"
#include "../common/vlc_player_options.h"
#include "../common/vlc_player.h"
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
typedef uint16 NPuint16_t;
......@@ -190,7 +191,7 @@ typedef enum vlc_toolbar_clicked_e {
clicked_Unmute
} vlc_toolbar_clicked_t;
class VlcPluginBase: private vlc_player_options
class VlcPluginBase: private vlc_player_options, private vlc_player
{
protected:
......@@ -198,6 +199,11 @@ public:
VlcPluginBase( NPP, NPuint16_t );
virtual ~VlcPluginBase();
vlc_player& get_player()
{
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
......@@ -208,11 +214,11 @@ public:
{ return libvlc_instance; };
libvlc_media_player_t* getMD()
{
if( !libvlc_media_player )
if( !get_player().is_open() )
{
libvlc_printerr("no mediaplayer");
}
return libvlc_media_player;
return get_player().get_mp();
}
NPP getBrowser()
{ return p_browser; };
......@@ -232,51 +238,53 @@ public:
void playlist_play()
{
if( playlist_isplaying() )
playlist_stop();
if( libvlc_media_player||playlist_select(0) )
libvlc_media_player_play(libvlc_media_player);
get_player().play();
}
void playlist_play_item(int idx)
{
if( playlist_select(idx) )
libvlc_media_player_play(libvlc_media_player);
get_player().play(idx);
}
void playlist_stop()
{
if( libvlc_media_player )
libvlc_media_player_stop(libvlc_media_player);
get_player().stop();
}
void playlist_next()
{
if( playlist_select(playlist_index+1) )
libvlc_media_player_play(libvlc_media_player);
get_player().next();
}
void playlist_prev()
{
if( playlist_select(playlist_index-1) )
libvlc_media_player_play(libvlc_media_player);
get_player().prev();
}
void playlist_pause()
{
if( libvlc_media_player )
libvlc_media_player_pause(libvlc_media_player);
get_player().pause();
}
int playlist_isplaying()
{
int is_playing = 0;
if( libvlc_media_player )
is_playing = libvlc_media_player_is_playing(
libvlc_media_player );
return is_playing;
return get_player().is_playing();
}
int playlist_add( const char * mrl)
{
return get_player().add_item(mrl);
}
int playlist_add_extended_untrusted( const char *mrl, const char *,
int optc, const char **optv )
{
return get_player().add_item(mrl, optc, optv);
}
int playlist_delete_item( int idx)
{
return get_player().delete_item(idx);
}
void playlist_clear()
{
get_player().clear_items() ;
}
int playlist_count()
{
return get_player().items_count();
}
int playlist_add( const char * );
int playlist_add_extended_untrusted( const char *, const char *, int,
const char ** );
int playlist_delete_item( int );
void playlist_clear();
int playlist_count();
void control_handler(vlc_toolbar_clicked_t);
......@@ -311,10 +319,7 @@ protected:
virtual void set_player_window() = 0;
/* VLC reference */
int playlist_index;
libvlc_instance_t *libvlc_instance;
libvlc_media_list_t *libvlc_media_list;
libvlc_media_player_t *libvlc_media_player;
NPClass *p_scriptClass;
/* browser reference */
......
......@@ -60,9 +60,9 @@ VlcPluginGtk::~VlcPluginGtk()
void VlcPluginGtk::set_player_window()
{
libvlc_media_player_set_xwindow(libvlc_media_player,
libvlc_media_player_set_xwindow(get_player().get_mp(),
video_xwindow);
libvlc_video_set_mouse_input(libvlc_media_player, 0);
libvlc_video_set_mouse_input(get_player().get_mp(), 0);
}
void VlcPluginGtk::toggle_fullscreen()
......@@ -360,8 +360,8 @@ static void fullscreen_win_visibility_handler(GtkWidget *widget, gpointer user_d
void VlcPluginGtk::update_controls()
{
if (libvlc_media_player) {
libvlc_state_t state = libvlc_media_player_get_state(libvlc_media_player);
if (get_player().is_open()) {
libvlc_state_t state = libvlc_media_player_get_state(get_player().get_mp());
bool is_stopped = (state == libvlc_Stopped) ||
(state == libvlc_Ended) ||
(state == libvlc_Error);
......@@ -388,16 +388,16 @@ void VlcPluginGtk::update_controls()
}
/* toolbar sensitivity */
gtk_widget_set_sensitive(toolbar, libvlc_media_player != NULL);
gtk_widget_set_sensitive(toolbar, get_player().is_open() );
/* time slider */
if (!libvlc_media_player ||
!libvlc_media_player_is_seekable(libvlc_media_player)) {
if (!get_player().is_open() ||
!libvlc_media_player_is_seekable(get_player().get_mp())) {
gtk_widget_set_sensitive(time_slider, false);
gtk_range_set_value(GTK_RANGE(time_slider), 0);
} else {
gtk_widget_set_sensitive(time_slider, true);
gdouble timepos = 100*libvlc_media_player_get_position(libvlc_media_player);
gdouble timepos = 100*libvlc_media_player_get_position(get_player().get_mp());
if (time_slider_timeout_id == 0) {
/* only set the time if the user is not dragging the slider */
gtk_range_set_value(GTK_RANGE(time_slider), timepos);
......
......@@ -184,6 +184,9 @@ bool VlcPluginWin::create_windows()
_WindowsManager.CreateWindows(drawable);
if( get_player().is_open() )
_WindowsManager.LibVlcAttach(get_player().get_mp());
return true;
}
......@@ -217,7 +220,7 @@ bool VlcPluginWin::destroy_windows()
void VlcPluginWin::on_media_player_new()
{
_WindowsManager.LibVlcAttach(libvlc_media_player);
_WindowsManager.LibVlcAttach(get_player().get_mp());
}
void VlcPluginWin::on_media_player_release()
......
......@@ -42,7 +42,7 @@ VlcPluginXcb::~VlcPluginXcb()
void VlcPluginXcb::set_player_window()
{
libvlc_media_player_set_xwindow(libvlc_media_player,
libvlc_media_player_set_xwindow(get_player().get_mp(),
(uint32_t) video);
}
......@@ -50,21 +50,21 @@ void VlcPluginXcb::toggle_fullscreen()
{
if (!get_options().get_enable_fs()) return;
if (playlist_isplaying())
libvlc_toggle_fullscreen(libvlc_media_player);
libvlc_toggle_fullscreen(get_player().get_mp());
}
void VlcPluginXcb::set_fullscreen(int yes)
{
if (!get_options().get_enable_fs()) return;
if (playlist_isplaying())
libvlc_set_fullscreen(libvlc_media_player,yes);
libvlc_set_fullscreen(get_player().get_mp(),yes);
}
int VlcPluginXcb::get_fullscreen()
{
int r = 0;
if (playlist_isplaying())
r = libvlc_get_fullscreen(libvlc_media_player);
r = libvlc_get_fullscreen(get_player().get_mp());
return r;
}
......
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