Commit 909b96ec authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

npapi: Start replacing libvlc by libvlcpp

parent 7cf66b81
AM_CPPFLAGS = $(LIBVLC_CFLAGS) AM_CPPFLAGS = $(LIBVLC_CFLAGS) -I$(top_srcdir)/vlcpp
libvlcplugin_common_la_SOURCES = \ libvlcplugin_common_la_SOURCES = \
position.h \ position.h \
......
/***************************************************************************** /*****************************************************************************
* Copyright 2002-2011 VideoLAN and VLC authors * Copyright 2002-2011 VideoLAN and VLC authors
* $Id$ * $Id$
* *
* Authors: Sergey Radionov <rsatom_gmail.com> * Authors: Sergey Radionov <rsatom_gmail.com>
...@@ -22,35 +22,25 @@ ...@@ -22,35 +22,25 @@
#include "vlc_player.h" #include "vlc_player.h"
vlc_player::vlc_player() vlc_player::vlc_player()
:_libvlc_instance(0), _mp(0), _ml(0), _ml_p(0)
{ {
} }
vlc_player::~vlc_player(void) bool vlc_player::open(VLC::Instance& inst)
{
close();
}
bool vlc_player::open(libvlc_instance_t* inst)
{ {
if( !inst ) if( !inst )
return false; return false;
if( is_open() )
close();
_libvlc_instance = inst; _libvlc_instance = inst;
_mp = libvlc_media_player_new(inst); try {
_ml = libvlc_media_list_new(inst); _mp = VLC::MediaPlayer(inst);
_ml_p = libvlc_media_list_player_new(inst); _ml = VLC::MediaList(inst);
_ml_p = VLC::MediaListPlayer(inst);
if( _mp && _ml && _ml_p ) { _ml_p.setMediaList( _ml );
libvlc_media_list_player_set_media_list(_ml_p, _ml); _ml_p.setMediaPlayer( _mp );
libvlc_media_list_player_set_media_player(_ml_p, _mp);
} }
else{ catch (std::runtime_error&) {
close();
return false; return false;
} }
...@@ -59,7 +49,7 @@ bool vlc_player::open(libvlc_instance_t* inst) ...@@ -59,7 +49,7 @@ bool vlc_player::open(libvlc_instance_t* inst)
bool vlc_player::is_playing() bool vlc_player::is_playing()
{ {
return _ml_p && libvlc_media_list_player_is_playing(_ml_p) != 0; return _ml_p && _ml_p.isPlaying() != 0;
} }
libvlc_state_t vlc_player::get_state() libvlc_state_t vlc_player::get_state()
...@@ -67,27 +57,7 @@ libvlc_state_t vlc_player::get_state() ...@@ -67,27 +57,7 @@ libvlc_state_t vlc_player::get_state()
if( !is_open() ) if( !is_open() )
return libvlc_NothingSpecial; return libvlc_NothingSpecial;
return libvlc_media_list_player_get_state(_ml_p); return _ml_p.state();
}
void vlc_player::close()
{
if(_ml_p) {
libvlc_media_list_player_release(_ml_p);
_ml_p = 0;
}
if(_ml) {
libvlc_media_list_release(_ml);
_ml = 0;
}
if(_mp) {
libvlc_media_player_release(_mp);
_mp = 0;
}
_libvlc_instance = 0;
} }
int vlc_player::add_item(const char * mrl, unsigned int optc, const char **optv) int vlc_player::add_item(const char * mrl, unsigned int optc, const char **optv)
...@@ -95,23 +65,21 @@ int vlc_player::add_item(const char * mrl, unsigned int optc, const char **optv) ...@@ -95,23 +65,21 @@ int vlc_player::add_item(const char * mrl, unsigned int optc, const char **optv)
if( !is_open() ) if( !is_open() )
return -1; return -1;
int item = -1; VLC::Media media;
try {
libvlc_media_t* media = libvlc_media_new_location(_libvlc_instance, mrl); media = VLC::Media( _libvlc_instance, mrl, VLC::Media::FromLocation );
if( !media ) }
catch ( std::runtime_error& ) {
return -1; return -1;
}
for( unsigned int i = 0; i < optc; ++i ) for( unsigned int i = 0; i < optc; ++i )
libvlc_media_add_option_flag(media, optv[i], libvlc_media_option_unique); media.addOptionFlag( optv[i], libvlc_media_option_unique );
libvlc_media_list_lock(_ml);
if( 0 == libvlc_media_list_add_media(_ml, media) )
item = libvlc_media_list_count(_ml) - 1;
libvlc_media_list_unlock(_ml);
libvlc_media_release(media); VLC::MediaList::Lock lock( _ml );
if( _ml.addMedia( media ) )
return item; return _ml.count() - 1;
return -1;
} }
int vlc_player::current_item() int vlc_player::current_item()
...@@ -119,12 +87,11 @@ int vlc_player::current_item() ...@@ -119,12 +87,11 @@ int vlc_player::current_item()
if( !is_open() ) if( !is_open() )
return -1; return -1;
libvlc_media_t* media = libvlc_media_player_get_media(_mp); auto media = _mp.media();
if( !media ) if( !media )
return -1; return -1;
return _ml.indexOfItem( *media );
return libvlc_media_list_index_of_item(_ml, media);
} }
int vlc_player::items_count() int vlc_player::items_count()
...@@ -132,10 +99,8 @@ int vlc_player::items_count() ...@@ -132,10 +99,8 @@ int vlc_player::items_count()
if( !is_open() ) if( !is_open() )
return 0; return 0;
libvlc_media_list_lock(_ml); VLC::MediaList::Lock lock( _ml );
int icnt = libvlc_media_list_count(_ml); return _ml.count();
libvlc_media_list_unlock(_ml);
return icnt;
} }
bool vlc_player::delete_item(unsigned int idx) bool vlc_player::delete_item(unsigned int idx)
...@@ -143,11 +108,8 @@ bool vlc_player::delete_item(unsigned int idx) ...@@ -143,11 +108,8 @@ bool vlc_player::delete_item(unsigned int idx)
if( !is_open() ) if( !is_open() )
return false; return false;
libvlc_media_list_lock(_ml); VLC::MediaList::Lock lock( _ml );
bool ret = libvlc_media_list_remove_index(_ml, idx) == 0; return _ml.removeIndex( idx );
libvlc_media_list_unlock(_ml);
return ret;
} }
void vlc_player::clear_items() void vlc_player::clear_items()
...@@ -155,11 +117,10 @@ void vlc_player::clear_items() ...@@ -155,11 +117,10 @@ void vlc_player::clear_items()
if( !is_open() ) if( !is_open() )
return; return;
libvlc_media_list_lock(_ml); VLC::MediaList::Lock lock( _ml );
for( int i = libvlc_media_list_count(_ml); i > 0; --i) { for( int i = _ml.count(); i > 0; --i) {
libvlc_media_list_remove_index(_ml, i - 1); _ml.removeIndex( i - 1 );
} }
libvlc_media_list_unlock(_ml);
} }
void vlc_player::play() void vlc_player::play()
...@@ -173,7 +134,7 @@ void vlc_player::play() ...@@ -173,7 +134,7 @@ void vlc_player::play()
play(0); play(0);
} }
else { else {
libvlc_media_list_player_play(_ml_p); _ml_p.play();
on_player_action(pa_play); on_player_action(pa_play);
} }
} }
...@@ -183,19 +144,17 @@ bool vlc_player::play(unsigned int idx) ...@@ -183,19 +144,17 @@ bool vlc_player::play(unsigned int idx)
if( !is_open() ) if( !is_open() )
return false; return false;
const int r = libvlc_media_list_player_play_item_at_index(_ml_p, idx); if( _ml_p.playItemAtIndex( idx ) ) {
if( 0 == r ) {
on_player_action(pa_play); on_player_action(pa_play);
return true; return true;
} }
return false; return false;
} }
void vlc_player::pause() void vlc_player::pause()
{ {
if( is_open() ) { if( is_open() ) {
libvlc_media_player_set_pause(_mp, true); _mp.setPause( true );
on_player_action(pa_pause); on_player_action(pa_pause);
} }
} }
...@@ -203,7 +162,7 @@ void vlc_player::pause() ...@@ -203,7 +162,7 @@ void vlc_player::pause()
void vlc_player::togglePause() void vlc_player::togglePause()
{ {
if( is_open() ) { if( is_open() ) {
libvlc_media_list_player_pause(_ml_p); _ml_p.pause();
on_player_action(pa_pause); on_player_action(pa_pause);
} }
} }
...@@ -221,12 +180,10 @@ bool vlc_player::next() ...@@ -221,12 +180,10 @@ bool vlc_player::next()
if( !is_open() ) if( !is_open() )
return false; return false;
const int r = libvlc_media_list_player_next(_ml_p); if( _ml_p.next() ) {
if( 0 == r ) {
on_player_action(pa_next); on_player_action(pa_next);
return true; return true;
} }
return false; return false;
} }
...@@ -235,12 +192,11 @@ bool vlc_player::prev() ...@@ -235,12 +192,11 @@ bool vlc_player::prev()
if( !is_open() ) if( !is_open() )
return false; return false;
const int r = libvlc_media_list_player_previous(_ml_p);
if( 0 == r ) { if( _ml_p.previous() ) {
on_player_action(pa_prev); on_player_action(pa_prev);
return true; return true;
} }
return false; return false;
} }
...@@ -249,7 +205,7 @@ float vlc_player::get_rate() ...@@ -249,7 +205,7 @@ float vlc_player::get_rate()
if( !is_open() ) if( !is_open() )
return 1.f; return 1.f;
return libvlc_media_player_get_rate(_mp); return _mp.rate();
} }
void vlc_player::set_rate(float rate) void vlc_player::set_rate(float rate)
...@@ -257,7 +213,7 @@ void vlc_player::set_rate(float rate) ...@@ -257,7 +213,7 @@ void vlc_player::set_rate(float rate)
if( !is_open() ) if( !is_open() )
return; return;
libvlc_media_player_set_rate(_mp, rate); _mp.setRate( rate );
} }
float vlc_player::get_fps() float vlc_player::get_fps()
...@@ -265,7 +221,7 @@ float vlc_player::get_fps() ...@@ -265,7 +221,7 @@ float vlc_player::get_fps()
if( !is_open() ) if( !is_open() )
return 0; return 0;
return libvlc_media_player_get_fps(_mp); return _mp.fps();
} }
bool vlc_player::has_vout() bool vlc_player::has_vout()
...@@ -273,7 +229,7 @@ bool vlc_player::has_vout() ...@@ -273,7 +229,7 @@ bool vlc_player::has_vout()
if( !is_open() ) if( !is_open() )
return false; return false;
return libvlc_media_player_has_vout(_mp) > 0; return _mp.hasVout() > 0;
} }
float vlc_player::get_position() float vlc_player::get_position()
...@@ -281,9 +237,8 @@ float vlc_player::get_position() ...@@ -281,9 +237,8 @@ float vlc_player::get_position()
if( !is_open() ) if( !is_open() )
return 0.f; return 0.f;
float p = libvlc_media_player_get_position(_mp); float p = _mp.position();
return p < 0 ? 0.f : p;
return p<0 ? 0 : p;
} }
void vlc_player::set_position(float p) void vlc_player::set_position(float p)
...@@ -291,7 +246,7 @@ void vlc_player::set_position(float p) ...@@ -291,7 +246,7 @@ void vlc_player::set_position(float p)
if( !is_open() ) if( !is_open() )
return; return;
libvlc_media_player_set_position(_mp, p); _mp.setPosition( p );
} }
libvlc_time_t vlc_player::get_time() libvlc_time_t vlc_player::get_time()
...@@ -299,9 +254,9 @@ libvlc_time_t vlc_player::get_time() ...@@ -299,9 +254,9 @@ libvlc_time_t vlc_player::get_time()
if( !is_open() ) if( !is_open() )
return 0; return 0;
libvlc_time_t t = libvlc_media_player_get_time(_mp); auto t = _mp.time();
return t<0 ? 0 : t ; return t < 0 ? 0 : t;
} }
void vlc_player::set_time(libvlc_time_t t) void vlc_player::set_time(libvlc_time_t t)
...@@ -309,7 +264,7 @@ void vlc_player::set_time(libvlc_time_t t) ...@@ -309,7 +264,7 @@ void vlc_player::set_time(libvlc_time_t t)
if( !is_open() ) if( !is_open() )
return; return;
libvlc_media_player_set_time(_mp, t); _mp.setTime( t );
} }
libvlc_time_t vlc_player::get_length() libvlc_time_t vlc_player::get_length()
...@@ -317,15 +272,14 @@ libvlc_time_t vlc_player::get_length() ...@@ -317,15 +272,14 @@ libvlc_time_t vlc_player::get_length()
if( !is_open() ) if( !is_open() )
return 0; return 0;
libvlc_time_t t = libvlc_media_player_get_length(_mp); auto t = _mp.length();
return t < 0 ? 0 : t;
return t<0 ? 0 : t ;
} }
void vlc_player::set_mode(libvlc_playback_mode_t mode) void vlc_player::set_mode(libvlc_playback_mode_t mode)
{ {
if( is_open() ) if( is_open() )
libvlc_media_list_player_set_playback_mode(_ml_p, mode); _ml_p.setPlaybackMode( mode );
} }
bool vlc_player::is_muted() bool vlc_player::is_muted()
...@@ -333,19 +287,19 @@ bool vlc_player::is_muted() ...@@ -333,19 +287,19 @@ bool vlc_player::is_muted()
if( !is_open() ) if( !is_open() )
return false; return false;
return libvlc_audio_get_mute(_mp) != 0; return _mp.mute();
} }
void vlc_player::toggle_mute() void vlc_player::toggle_mute()
{ {
if( is_open() ) if( is_open() )
libvlc_audio_toggle_mute(_mp); _mp.toggleMute();
} }
void vlc_player::set_mute(bool mute) void vlc_player::set_mute(bool mute)
{ {
if( is_open() ) if( is_open() )
libvlc_audio_set_mute(_mp, mute); _mp.setMute( mute );
} }
unsigned int vlc_player::get_volume() unsigned int vlc_player::get_volume()
...@@ -353,15 +307,14 @@ unsigned int vlc_player::get_volume() ...@@ -353,15 +307,14 @@ unsigned int vlc_player::get_volume()
if( !is_open() ) if( !is_open() )
return 0; return 0;
int v = libvlc_audio_get_volume(_mp); int v = _mp.volume();
return v < 0 ? 0 : v;
return v<0 ? 0 : v;
} }
void vlc_player::set_volume(unsigned int volume) void vlc_player::set_volume(unsigned int volume)
{ {
if( is_open() ) if( is_open() )
libvlc_audio_set_volume(_mp, volume); _mp.setVolume( volume );
} }
unsigned int vlc_player::track_count() unsigned int vlc_player::track_count()
...@@ -369,7 +322,7 @@ unsigned int vlc_player::track_count() ...@@ -369,7 +322,7 @@ unsigned int vlc_player::track_count()
if( !is_open() ) if( !is_open() )
return 0; return 0;
int tc = libvlc_audio_get_track_count(_mp); int tc = _mp.audioTrackCount();
return tc<0 ? 0 : tc ; return tc<0 ? 0 : tc ;
} }
...@@ -381,13 +334,13 @@ unsigned int vlc_player::get_track() ...@@ -381,13 +334,13 @@ unsigned int vlc_player::get_track()
int t = libvlc_audio_get_track(_mp); int t = libvlc_audio_get_track(_mp);
return t<0 ? 0 : t ; return t < 0 ? 0 : t;
} }
void vlc_player::set_track(unsigned int track) void vlc_player::set_track(unsigned int track)
{ {
if( is_open() ) if( is_open() )
libvlc_audio_set_track(_mp, track); _mp.setAudioTrack( track );
} }
unsigned int vlc_player::get_channel() unsigned int vlc_player::get_channel()
...@@ -395,13 +348,11 @@ unsigned int vlc_player::get_channel() ...@@ -395,13 +348,11 @@ unsigned int vlc_player::get_channel()
if( !is_open() ) if( !is_open() )
return 0; return 0;
int c =libvlc_audio_get_channel(_mp); return _mp.channel();
return c<0 ? 0 : c ;
} }
void vlc_player::set_channel(unsigned int channel) void vlc_player::set_channel(unsigned int channel)
{ {
if( is_open() ) if( is_open() )
libvlc_audio_set_channel(_mp, channel); _mp.setChannel( channel );
} }
...@@ -21,7 +21,8 @@ ...@@ -21,7 +21,8 @@
#pragma once #pragma once
#include <vlc/vlc.h> #include <vlcpp/vlc.hpp>
#include <memory>
enum vlc_player_action_e enum vlc_player_action_e
{ {
...@@ -36,12 +37,10 @@ class vlc_player ...@@ -36,12 +37,10 @@ class vlc_player
{ {
public: public:
vlc_player(); vlc_player();
~vlc_player(void);
bool open(libvlc_instance_t* inst); bool open(VLC::Instance& inst);
void close();
bool is_open() const { return _ml_p != 0; } bool is_open() const { return _ml_p.isValid(); }
bool is_playing(); bool is_playing();
libvlc_state_t get_state(); libvlc_state_t get_state();
bool is_stopped() { return libvlc_Stopped == get_state(); } bool is_stopped() { return libvlc_Stopped == get_state(); }
...@@ -95,15 +94,15 @@ public: ...@@ -95,15 +94,15 @@ public:
unsigned int get_channel(); unsigned int get_channel();
void set_channel(unsigned int); void set_channel(unsigned int);
libvlc_media_player_t* get_mp() const VLC::MediaPlayer& get_mp()
{ return _mp; } { return _mp; }
protected: protected:
virtual void on_player_action( vlc_player_action_e ){}; virtual void on_player_action( vlc_player_action_e ){}
private: private:
libvlc_instance_t * _libvlc_instance; VLC::Instance _libvlc_instance;
libvlc_media_player_t* _mp; VLC::MediaPlayer _mp;
libvlc_media_list_t* _ml; VLC::MediaList _ml;
libvlc_media_list_player_t* _ml_p; VLC::MediaListPlayer _ml_p;
};