From 6de088e22cab5811712aace6cdacf8c98d10e70c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20Beauz=C3=A9e-Luyssen?= Date: Wed, 11 Feb 2015 23:53:15 +0100 Subject: [PATCH] Use shared/unique pointers to manage vlcpp/libvlc objects --- src/EventManager.cpp | 51 +++---- src/EventManager.hpp | 28 ++-- src/Instance.cpp | 59 ++------ src/Instance.hpp | 29 ---- src/Internal.hpp | 35 +++-- src/Media.cpp | 113 +++++---------- src/Media.hpp | 43 ++---- src/MediaDiscoverer.cpp | 40 ++---- src/MediaDiscoverer.hpp | 22 +-- src/MediaLibrary.cpp | 46 +----- src/MediaLibrary.hpp | 32 +---- src/MediaList.cpp | 111 ++++----------- src/MediaList.hpp | 50 ++----- src/MediaListPlayer.cpp | 92 ++++-------- src/MediaListPlayer.hpp | 41 +----- src/MediaPlayer.cpp | 303 ++++++++++++++++------------------------ src/MediaPlayer.hpp | 45 +----- src/common.hpp | 26 ++++ src/vlc.hpp | 8 +- 19 files changed, 354 insertions(+), 820 deletions(-) diff --git a/src/EventManager.cpp b/src/EventManager.cpp index 117b2f1..01e60c1 100644 --- a/src/EventManager.cpp +++ b/src/EventManager.cpp @@ -27,18 +27,13 @@ namespace VLC { -EventManager::EventManager(const EventManager& em) - : Internal( em ) -{ -} - bool EventManager::attach(libvlc_event_type_t type, IMediaEventCb* cb) { if ( cb == NULL ) return false; if ( type < libvlc_MediaMetaChanged || type > libvlc_MediaSubItemTreeAdded ) return false; - libvlc_event_attach( *this, type, &handleMediaEvent, cb ); + libvlc_event_attach( get(), type, &handleMediaEvent, cb ); return true; } @@ -48,7 +43,7 @@ bool EventManager::attach(libvlc_event_type_t type, IMediaPlayerEventCb* cb) return false; if ( type < libvlc_MediaPlayerMediaChanged || type > libvlc_MediaPlayerESSelected ) return false; - libvlc_event_attach( *this, type, &handleMediaPlayerEvent, cb ); + libvlc_event_attach( get(), type, &handleMediaPlayerEvent, cb ); return true; } @@ -58,7 +53,7 @@ bool EventManager::attach(libvlc_event_type_t type, IMediaListEventCb* cb) return false; if ( type < libvlc_MediaListItemAdded || type > libvlc_MediaListWillDeleteItem ) return false; - libvlc_event_attach( *this, type, &handleMediaListEvent, cb ); + libvlc_event_attach( get(), type, &handleMediaListEvent, cb ); return true; } @@ -68,7 +63,7 @@ bool EventManager::attach(libvlc_event_type_t type, IMediaListPlayerEventCb* cb) return false; if ( type < libvlc_MediaListPlayerPlayed || type > libvlc_MediaListPlayerStopped ) return false; - libvlc_event_attach( *this, type, &handleMediaListPlayerEvent, cb ); + libvlc_event_attach( get(), type, &handleMediaListPlayerEvent, cb ); return true; } @@ -78,7 +73,7 @@ bool EventManager::attach(libvlc_event_type_t type, IMediaDiscovererEventCb* cb) return false; if ( type < libvlc_MediaDiscovererStarted || type > libvlc_MediaDiscovererEnded ) return false; - libvlc_event_attach( *this, type, &handleMediaDiscovererEvent, cb ); + libvlc_event_attach( get(), type, &handleMediaDiscovererEvent, cb ); return true; } @@ -88,38 +83,38 @@ bool EventManager::attach( libvlc_event_type_t type, IVLMEventCb* cb ) return false; if ( type < libvlc_VlmMediaAdded || type > libvlc_VlmMediaInstanceStatusError ) return false; - libvlc_event_attach( *this, type, &handleVLMEvent, cb ); + libvlc_event_attach( get(), type, &handleVLMEvent, cb ); return true; } void EventManager::detach(libvlc_event_type_t type, IMediaEventCb* cb) { - libvlc_event_detach( *this, type, &handleMediaEvent, cb ); + libvlc_event_detach( get(), type, &handleMediaEvent, cb ); } void EventManager::detach(libvlc_event_type_t type, IMediaPlayerEventCb* cb) { - libvlc_event_detach( *this, type, &handleMediaPlayerEvent, cb ); + libvlc_event_detach( get(), type, &handleMediaPlayerEvent, cb ); } void EventManager::detach(libvlc_event_type_t type, IMediaListEventCb* cb) { - libvlc_event_detach( *this, type, &handleMediaListEvent, cb ); + libvlc_event_detach( get(), type, &handleMediaListEvent, cb ); } void EventManager::detach(libvlc_event_type_t type, IMediaListPlayerEventCb* cb) { - libvlc_event_detach( *this, type, &handleMediaListPlayerEvent, cb ); + libvlc_event_detach( get(), type, &handleMediaListPlayerEvent, cb ); } void EventManager::detach(libvlc_event_type_t type, IMediaDiscovererEventCb* cb) { - libvlc_event_detach( *this, type, &handleMediaDiscovererEvent, cb ); + libvlc_event_detach( get(), type, &handleMediaDiscovererEvent, cb ); } void EventManager::detach(libvlc_event_type_t type, IVLMEventCb* cb) { - libvlc_event_detach( *this, type, &handleVLMEvent, cb ); + libvlc_event_detach( get(), type, &handleVLMEvent, cb ); } void EventManager::handleMediaEvent(const libvlc_event_t* event, void* data) @@ -131,7 +126,7 @@ void EventManager::handleMediaEvent(const libvlc_event_t* event, void* data) cb->metaChanged( event->u.media_meta_changed.meta_type ); break; case libvlc_MediaSubItemAdded: - cb->subItemAdded( Media( event->u.media_subitem_added.new_child, true ) ); + cb->subItemAdded( std::make_shared( event->u.media_subitem_added.new_child, true ) ); break; case libvlc_MediaDurationChanged: cb->durationChanged( event->u.media_duration_changed.new_duration ); @@ -140,13 +135,13 @@ void EventManager::handleMediaEvent(const libvlc_event_t* event, void* data) cb->parsedChanged( event->u.media_parsed_changed.new_status != 0 ); break; case libvlc_MediaFreed: - cb->freed( Media( event->u.media_freed.md, true ) ); + cb->freed( std::make_shared( event->u.media_freed.md, true ) ); break; case libvlc_MediaStateChanged: cb->stateChanged( event->u.media_state_changed.new_state ); break; case libvlc_MediaSubItemTreeAdded: - cb->subItemTreeAdded( Media( event->u.media_subitemtree_added.item, true ) ); + cb->subItemTreeAdded( std::make_shared( event->u.media_subitemtree_added.item, true ) ); break; default: assert(false); @@ -159,7 +154,7 @@ void EventManager::handleMediaPlayerEvent(const libvlc_event_t* event, void* dat switch ( event->type ) { case libvlc_MediaPlayerMediaChanged: - cb->mediaChanged( Media( event->u.media_player_media_changed.new_media, true ) ); + cb->mediaChanged( std::make_shared( event->u.media_player_media_changed.new_media, true ) ); break; case libvlc_MediaPlayerNothingSpecial: cb->nothingSpecial(); @@ -238,16 +233,16 @@ void EventManager::handleMediaListEvent(const libvlc_event_t* event, void* data) switch ( event->type ) { case libvlc_MediaListItemAdded: - cb->itemAdded( Media( event->u.media_list_item_added.item, true ), event->u.media_list_item_added.index ); + cb->itemAdded( std::make_shared( event->u.media_list_item_added.item, true ), event->u.media_list_item_added.index ); break; case libvlc_MediaListWillAddItem: - cb->willAddItem( Media( event->u.media_list_will_add_item.item, true ), event->u.media_list_will_add_item.index ); + cb->willAddItem( std::make_shared( event->u.media_list_will_add_item.item, true ), event->u.media_list_will_add_item.index ); break; case libvlc_MediaListItemDeleted: - cb->itemDeleted( Media( event->u.media_list_item_deleted.item, true ), event->u.media_list_item_deleted.index ); + cb->itemDeleted( std::make_shared( event->u.media_list_item_deleted.item, true ), event->u.media_list_item_deleted.index ); break; case libvlc_MediaListWillDeleteItem: - cb->willDeleteItem( Media( event->u.media_list_will_delete_item.item, true ), event->u.media_list_will_delete_item.index ); + cb->willDeleteItem( std::make_shared( event->u.media_list_will_delete_item.item, true ), event->u.media_list_will_delete_item.index ); break; default: assert(false); @@ -263,7 +258,7 @@ void EventManager::handleMediaListPlayerEvent(const libvlc_event_t* event, void* cb->played(); break; case libvlc_MediaListPlayerNextItemSet: - cb->nextItemSet( Media( event->u.media_list_player_next_item_set.item, true ) ); + cb->nextItemSet( std::make_shared( event->u.media_list_player_next_item_set.item, true ) ); break; case libvlc_MediaListPlayerStopped: cb->stopped(); @@ -334,8 +329,8 @@ void EventManager::handleVLMEvent(const libvlc_event_t* event, void* data) } } -EventManager::EventManager( InternalPtr obj) - : Internal( obj ) +EventManager::EventManager(Internal::InternalPtr ptr) + : Internal{ ptr, [](InternalPtr){ /* No-op; EventManager's are handled by their respective objects */ } } { } diff --git a/src/EventManager.hpp b/src/EventManager.hpp index 7bf5e6a..2d546e6 100644 --- a/src/EventManager.hpp +++ b/src/EventManager.hpp @@ -37,19 +37,19 @@ class IMediaEventCb public: virtual ~IMediaEventCb() {} virtual void metaChanged( libvlc_meta_t ) {} - virtual void subItemAdded( const Media& ) {} + virtual void subItemAdded( MediaPtr ) {} virtual void durationChanged( int64_t ) {} virtual void parsedChanged( bool ) {} - virtual void freed( const Media& ) {} + virtual void freed( MediaPtr ) {} virtual void stateChanged( libvlc_state_t ) {} - virtual void subItemTreeAdded( const Media& ) {} + virtual void subItemTreeAdded( MediaPtr ) {} }; class IMediaPlayerEventCb { public: virtual ~IMediaPlayerEventCb(){} - virtual void mediaChanged( const Media& ) {} + virtual void mediaChanged( MediaPtr ) {} virtual void nothingSpecial() {} virtual void opening() {} virtual void buffering( float ) {} @@ -78,10 +78,10 @@ class IMediaListEventCb { public: virtual ~IMediaListEventCb() {} - virtual void itemAdded( const Media&, int ) {} - virtual void willAddItem( const Media&, int ) {} - virtual void itemDeleted( const Media&, int ) {} - virtual void willDeleteItem( const Media&, int ) {} + virtual void itemAdded( MediaPtr, int ) {} + virtual void willAddItem( MediaPtr, int ) {} + virtual void itemDeleted( MediaPtr, int ) {} + virtual void willDeleteItem( MediaPtr, int ) {} }; // MediaListView events are not being sent by VLC, so we don't implement them here @@ -91,7 +91,7 @@ class IMediaListPlayerEventCb public: virtual ~IMediaListPlayerEventCb() {} virtual void played() {} - virtual void nextItemSet( const Media& ) {} + virtual void nextItemSet( MediaPtr ) {} virtual void stopped() {} }; @@ -123,7 +123,8 @@ class IVLMEventCb class VLCPP_API EventManager : public Internal { public: - EventManager( const EventManager& em ); + EventManager(InternalPtr ptr); + bool attach( libvlc_event_type_t type, IMediaEventCb* cb ); bool attach( libvlc_event_type_t type, IMediaPlayerEventCb* cb ); bool attach( libvlc_event_type_t type, IMediaListEventCb* cb ); @@ -147,13 +148,6 @@ class VLCPP_API EventManager : public Internal static void handleVLMEvent( const libvlc_event_t* event, void* data ); static void handleEvent( const libvlc_event_t* event, void* data ); - - EventManager(InternalPtr obj ); - friend class Media; - friend class MediaDiscoverer; - friend class MediaList; - friend class MediaListPlayer; - friend class MediaPlayer; }; } diff --git a/src/Instance.cpp b/src/Instance.cpp index eff348d..7f7a710 100644 --- a/src/Instance.cpp +++ b/src/Instance.cpp @@ -27,26 +27,8 @@ namespace VLC { Instance::Instance(int argc, const char* const* argv) + : Internal{ libvlc_new( argc, argv ), libvlc_release } { - m_obj = libvlc_new( argc, argv ); -} - -Instance::Instance( const Instance& another ) - : Internal( another ) -{ - retain(); -} - -Instance& Instance::operator=( const Instance& another ) -{ - if ( this == &another ) - { - return *this; - } - release(); - m_obj = another.m_obj; - retain(); - return *this; } bool Instance::operator==( const Instance& another ) const @@ -54,49 +36,44 @@ bool Instance::operator==( const Instance& another ) const return m_obj == another.m_obj; } -Instance::~Instance() -{ - release(); -} - int Instance::addIntf( const std::string& name ) { - return libvlc_add_intf( m_obj, name.c_str() ); + return libvlc_add_intf( get(), name.c_str() ); } void Instance::setExitHandler( void(*cb)(void *), void * opaque ) { - libvlc_set_exit_handler( m_obj, cb, opaque ); + libvlc_set_exit_handler( get(), cb, opaque ); } void Instance::setUserAgent( const std::string& name, const std::string& http ) { - libvlc_set_user_agent( m_obj, name.c_str(), http.c_str() ); + libvlc_set_user_agent( get(), name.c_str(), http.c_str() ); } void Instance::setAppId( const std::string& id, const std::string& version, const std::string& icon ) { - libvlc_set_app_id( m_obj, id.c_str(), version.c_str(), icon.c_str() ); + libvlc_set_app_id( get(), id.c_str(), version.c_str(), icon.c_str() ); } void Instance::logUnset() { - libvlc_log_unset( m_obj ); + libvlc_log_unset( get() ); } void Instance::logSet( libvlc_log_cb cb, void * data ) { - libvlc_log_set(m_obj, cb, data); + libvlc_log_set(get(), cb, data); } void Instance::logSetFile( FILE * stream ) { - libvlc_log_set_file( m_obj, stream ); + libvlc_log_set_file( get(), stream ); } std::vector Instance::audioFilterList() { - libvlc_module_description_t* result = libvlc_audio_filter_list_get(m_obj); + libvlc_module_description_t* result = libvlc_audio_filter_list_get(get()); std::vector res; if ( result == NULL ) return res; @@ -112,7 +89,7 @@ std::vector Instance::audioFilterList() std::vector Instance::videoFilterList() { - libvlc_module_description_t* result = libvlc_video_filter_list_get(m_obj); + libvlc_module_description_t* result = libvlc_video_filter_list_get(get()); std::vector res; if ( result == NULL ) return res; @@ -128,7 +105,7 @@ std::vector Instance::videoFilterList() std::vector Instance::audioOutputList() { - libvlc_audio_output_t* result = libvlc_audio_output_list_get(m_obj); + libvlc_audio_output_t* result = libvlc_audio_output_list_get(get()); std::vector res; if ( result == NULL ) return res; @@ -144,7 +121,7 @@ std::vector Instance::audioOutputList() std::vector Instance::audioOutputDeviceList(const std::string& aout) { - libvlc_audio_output_device_t* devices = libvlc_audio_output_device_list_get( m_obj, aout.c_str() ); + libvlc_audio_output_device_t* devices = libvlc_audio_output_device_list_get( get(), aout.c_str() ); std::vector res; if ( devices == NULL ) return res; @@ -154,17 +131,5 @@ std::vector Instance::audioOutputDeviceList(const return res; } -void Instance::release() -{ - if ( isValid() ) - libvlc_release(m_obj); -} - -void Instance::retain() -{ - if ( isValid() ) - libvlc_retain(m_obj); -} - } // namespace VLC diff --git a/src/Instance.hpp b/src/Instance.hpp index 42f7f79..cb253c1 100644 --- a/src/Instance.hpp +++ b/src/Instance.hpp @@ -60,19 +60,6 @@ public: */ Instance(int argc, const char *const * argv); - /** - * Copy libvlc_instance_t from another to new Instance object. - * \param another existing Instance - */ - Instance(const Instance& another); - - /** - * Copy libvlc_instance_t from another Instance - * to this Instance - * \param another existing Instance - */ - Instance& operator=(const Instance& another); - /** * Check if 2 Instance objects contain the same libvlc_instance_t. * \param another another Instance @@ -80,8 +67,6 @@ public: */ bool operator==(const Instance& another) const; - ~Instance(); - /** * Try to start a user interface for the libvlc instance. * @@ -240,20 +225,6 @@ public: * \version LibVLC 2.1.0 or later. */ std::vector audioOutputDeviceList(const std::string& aout); - -private: - explicit Instance( InternalPtr ptr, bool increaseRefCount ); - /** - * Decrement the reference count of a libvlc instance, and destroy it if - * it reaches zero. - */ - void release(); - - /** - * Increments the reference count of a libvlc instance. The initial - * reference count is 1 after Instance::Instance() returns. - */ - void retain(); }; } // namespace VLC diff --git a/src/Internal.hpp b/src/Internal.hpp index de1da9b..2311bbe 100644 --- a/src/Internal.hpp +++ b/src/Internal.hpp @@ -26,31 +26,36 @@ #include #include #include +#include +#include namespace VLC { -template < typename T > +template class Internal { public: - typedef T* InternalPtr; - InternalPtr getInternalPtr() + using InternalType = T; + using InternalPtr = T*; + using Pointer = std::unique_ptr; + + InternalPtr get() { return m_obj.get(); } + bool isValid() const { return (bool)m_obj; } + protected: + Internal( InternalPtr obj, Releaser releaser ) + : m_obj{ obj, releaser } + { + if ( obj == nullptr ) + throw std::runtime_error("Wrapping a NULL instance"); + } + Internal(Releaser releaser) + : m_obj{ nullptr, releaser } { - assert( m_obj != NULL ); - return m_obj; } - operator T*() { return m_obj; } - bool isValid() const { return m_obj != NULL; } - protected: - Internal( InternalPtr obj = NULL ) : m_obj( obj ) {} - Internal( const Internal& copied ) : m_obj( copied.m_obj ) {} - ~Internal(){} - - InternalPtr m_obj; - private: - Internal& operator=(const Internal&); + protected: + Pointer m_obj; }; } diff --git a/src/Media.cpp b/src/Media.cpp index db57b3c..cda800f 100644 --- a/src/Media.cpp +++ b/src/Media.cpp @@ -27,66 +27,38 @@ namespace VLC { -Media::Media(Instance &instance, const std::string &mrl, Media::FromType type) - : Internal( NULL ) +Media::Media(InstancePtr instance, const std::string &mrl, Media::FromType type) + : Internal{ libvlc_media_release } { + InternalPtr ptr = nullptr; switch (type) { case FromLocation: - m_obj = libvlc_media_new_location( instance, mrl.c_str() ); + ptr = libvlc_media_new_location( instance->get(), mrl.c_str() ); break; case FromPath: - m_obj = libvlc_media_new_path( instance, mrl.c_str() ); + ptr = libvlc_media_new_path( instance->get(), mrl.c_str() ); break; case AsNode: - m_obj = libvlc_media_new_as_node( instance, mrl.c_str() ); + ptr = libvlc_media_new_as_node( instance->get(), mrl.c_str() ); break; default: break; } - if ( m_obj == NULL ) + if ( ptr == nullptr ) throw std::runtime_error("Failed to construct a media"); + m_obj.reset( ptr ); } -Media::Media(Instance& instance, int fd) +Media::Media(InstancePtr instance, int fd) + : Internal { libvlc_media_new_fd( instance->get(), fd ), libvlc_media_release } { - m_obj = libvlc_media_new_fd( instance, fd ); - if ( m_obj == NULL ) - throw std::runtime_error("Failed to construct a media"); -} - -Media::Media(MediaList& list) -{ - m_obj = libvlc_media_list_media( list ); - if ( m_obj == NULL ) - throw std::runtime_error("Failed to construct a media"); } -Media::Media(const Media& another) - : Internal(another) - , m_eventManager( NULL ) +Media::Media(MediaListPtr list) + : Internal{ libvlc_media_list_media( list->get() ), libvlc_media_release } { - retain(); - if ( another.m_eventManager != NULL ) - m_eventManager = new EventManager( *another.m_eventManager ); -} - -Media& Media::operator=(const Media& another) -{ - if (this == &another) - { - return *this; - } - release(); - m_obj = another.m_obj; - delete m_eventManager; - if ( another.m_eventManager != NULL ) - m_eventManager = new EventManager( *another.m_eventManager ); - else - m_eventManager = NULL; - retain(); - return *this; } bool Media::operator==(const Media& another) const @@ -94,25 +66,19 @@ bool Media::operator==(const Media& another) const return m_obj == another.m_obj; } -Media::~Media() -{ - delete m_eventManager; - release(); -} - void Media::addOption(const std::string& psz_options) { - libvlc_media_add_option(m_obj, psz_options.c_str()); + libvlc_media_add_option(get(), psz_options.c_str()); } void Media::addOptionFlag(const std::string& psz_options, unsigned i_flags) { - libvlc_media_add_option_flag(m_obj, psz_options.c_str(), i_flags); + libvlc_media_add_option_flag(get(), psz_options.c_str(), i_flags); } std::string Media::mrl() { - char* c_result = libvlc_media_get_mrl(m_obj); + char* c_result = libvlc_media_get_mrl(get()); if ( c_result == NULL ) return std::string(); std::string result = c_result; @@ -122,13 +88,13 @@ std::string Media::mrl() Media Media::duplicate() { - InternalPtr obj = libvlc_media_duplicate(m_obj); + InternalPtr obj = libvlc_media_duplicate(get()); return Media( obj, true ); } std::string Media::meta(libvlc_meta_t e_meta) { - char* c_result = libvlc_media_get_meta(m_obj, e_meta); + char* c_result = libvlc_media_get_meta(get(), e_meta); if ( c_result == NULL ) return std::string(); std::string result = c_result; @@ -138,68 +104,68 @@ std::string Media::meta(libvlc_meta_t e_meta) void Media::setMeta(libvlc_meta_t e_meta, const std::string& psz_value) { - libvlc_media_set_meta(m_obj, e_meta, psz_value.c_str()); + libvlc_media_set_meta(get(), e_meta, psz_value.c_str()); } int Media::saveMeta() { - return libvlc_media_save_meta(m_obj); + return libvlc_media_save_meta(get()); } libvlc_state_t Media::state() { - return libvlc_media_get_state(m_obj); + return libvlc_media_get_state(get()); } bool Media::stats(libvlc_media_stats_t * p_stats) { - return libvlc_media_get_stats(m_obj, p_stats) != 0; + return libvlc_media_get_stats(get(), p_stats) != 0; } -EventManager& Media::eventManager() +EventManagerPtr Media::eventManager() { if ( m_eventManager == NULL ) { - libvlc_event_manager_t* obj = libvlc_media_event_manager(m_obj); - m_eventManager = new EventManager( obj ); + libvlc_event_manager_t* obj = libvlc_media_event_manager(get()); + m_eventManager = std::make_shared( obj ); } - return *m_eventManager; + return m_eventManager; } libvlc_time_t Media::duration() { - return libvlc_media_get_duration(m_obj); + return libvlc_media_get_duration(get()); } void Media::parse() { - libvlc_media_parse(m_obj); + libvlc_media_parse(get()); } void Media::parseAsync() { - libvlc_media_parse_async(m_obj); + libvlc_media_parse_async(get()); } bool Media::isParsed() { - return libvlc_media_is_parsed(m_obj) != 0; + return libvlc_media_is_parsed(get()) != 0; } void Media::setUserData(void * p_new_user_data) { - libvlc_media_set_user_data(m_obj, p_new_user_data); + libvlc_media_set_user_data(get(), p_new_user_data); } void * Media::userData() { - return libvlc_media_get_user_data(m_obj); + return libvlc_media_get_user_data(get()); } std::vector Media::tracks() { libvlc_media_track_t** tracks; - uint32_t nbTracks = libvlc_media_tracks_get(m_obj, &tracks); + uint32_t nbTracks = libvlc_media_tracks_get(get(), &tracks); std::vector res; if ( nbTracks == 0 ) @@ -211,24 +177,17 @@ std::vector Media::tracks() return res; } -Media::Media(Internal::InternalPtr ptr, bool increaseRefCount ) - : Internal(ptr) - , m_eventManager( NULL ) +Media::Media(Internal::InternalPtr ptr, bool incrementRefCount) + : Internal{ ptr, libvlc_media_release } { - if ( increaseRefCount ) + if (incrementRefCount) retain(); } void Media::retain() { if ( isValid() ) - libvlc_media_retain(m_obj); -} - -void Media::release() -{ - if ( isValid() ) - libvlc_media_release(m_obj); + libvlc_media_retain(get()); } } // namespace VLC diff --git a/src/Media.hpp b/src/Media.hpp index 5bea581..088e3b9 100644 --- a/src/Media.hpp +++ b/src/Media.hpp @@ -25,9 +25,7 @@ #define LIBVLC_CXX_MEDIA_H #include -#include "common.hpp" -#include "Internal.hpp" -#include "structures.hpp" +#include "vlc.hpp" namespace VLC { @@ -68,7 +66,7 @@ public: * @param mrl A path, location, or node name, depending on the 3rd parameter * @param type The type of the 2nd argument. \sa{FromType} */ - Media(Instance& instance, const std::string& mrl, FromType type); + Media(InstancePtr instance, const std::string& mrl, FromType type); /** * Create a media for an already open file descriptor. @@ -90,7 +88,7 @@ public: * \param fd open file descriptor * \return the newly created media or NULL on error */ - Media(Instance& instance, int fd); + Media(InstancePtr instance, int fd); /** * Get media instance from this media list instance. This action will increase @@ -100,20 +98,9 @@ public: * \param p_ml a media list instance * \return media instance */ - Media(MediaList& list ); + Media(MediaListPtr list ); - /** - * Copy libvlc_media_t from another to new Media object. - * \param another existing Media - */ - Media(const Media& another); - - /** - * Copy libvlc_media_t from another Media - * to this Media - * \param another existing Media - */ - Media& operator=(const Media& another); + explicit Media(InternalPtr ptr, bool incrementRefCount); /** * Check if 2 Media objects contain the same libvlc_media_t. @@ -122,8 +109,6 @@ public: */ bool operator==(const Media& another) const; - ~Media(); - /** * Add an option to the media. * @@ -242,7 +227,7 @@ public: * * \return event manager object */ - EventManager& eventManager(); + EventManagerPtr eventManager(); /** * Get duration (in ms) of media descriptor object item. @@ -325,7 +310,7 @@ public: std::vector tracks(); private: - explicit Media(InternalPtr ptr, bool increaseRefCount ); + /** * Retain a reference to a media descriptor object (libvlc_media_t). Use * Media::release() to decrement the reference count of a media @@ -333,21 +318,9 @@ private: */ void retain(); - /** - * Decrement the reference count of a media descriptor object. If the - * reference count is 0, then Media::release() will release the media - * descriptor object. It will send out an libvlc_MediaFreed event to all - * listeners. If the media descriptor object has been released it should - * not be used again. - */ - void release(); private: - EventManager* m_eventManager; - - friend class MediaList; - friend class MediaPlayer; - friend class EventManager; + EventManagerPtr m_eventManager; }; } // namespace VLC diff --git a/src/MediaDiscoverer.cpp b/src/MediaDiscoverer.cpp index fe0dc12..ef8e10a 100644 --- a/src/MediaDiscoverer.cpp +++ b/src/MediaDiscoverer.cpp @@ -25,26 +25,20 @@ #include "EventManager.hpp" #include +#include namespace VLC { -MediaDiscoverer::~MediaDiscoverer() +MediaDiscoverer::MediaDiscoverer(InstancePtr inst, const std::string& name ) + : Internal{ libvlc_media_discoverer_new_from_name(inst->get(), name.c_str()), + libvlc_media_discoverer_release } { - delete m_eventManager; - release(); -} - -MediaDiscoverer::MediaDiscoverer( Instance &inst, const std::string& name ) -{ - m_obj = libvlc_media_discoverer_new_from_name(inst, name.c_str()); - if ( m_obj == NULL ) - throw std::runtime_error("Failed to construct a media discover"); } std::string MediaDiscoverer::localizedName() { - char* c_result = libvlc_media_discoverer_localized_name(m_obj); + char* c_result = libvlc_media_discoverer_localized_name(get()); if ( c_result == NULL ) return std::string(); std::string result = c_result; @@ -52,31 +46,19 @@ std::string MediaDiscoverer::localizedName() return result; } -EventManager& MediaDiscoverer::eventManager() +EventManagerPtr MediaDiscoverer::eventManager() { - if ( m_eventManager == NULL ) + if ( m_eventManager ) { - libvlc_event_manager_t* obj = libvlc_media_discoverer_event_manager( m_obj ); - m_eventManager = new EventManager( obj ); + libvlc_event_manager_t* obj = libvlc_media_discoverer_event_manager( get() ); + m_eventManager = std::make_shared( obj ); } - return *m_eventManager; + return m_eventManager; } bool MediaDiscoverer::isRunning() { - return libvlc_media_discoverer_is_running(m_obj); -} - -MediaDiscoverer::MediaDiscoverer( Internal::InternalPtr ptr ) - : Internal( ptr ) - , m_eventManager( NULL ) -{ - assert( ptr != NULL ); -} - -void MediaDiscoverer::release() -{ - libvlc_media_discoverer_release( m_obj ); + return libvlc_media_discoverer_is_running(get()); } } // namespace VLC diff --git a/src/MediaDiscoverer.hpp b/src/MediaDiscoverer.hpp index 49cd852..08093f9 100644 --- a/src/MediaDiscoverer.hpp +++ b/src/MediaDiscoverer.hpp @@ -24,8 +24,7 @@ #ifndef LIBVLC_CXX_MEDIADISCOVERER_H #define LIBVLC_CXX_MEDIADISCOVERER_H -#include "common.hpp" -#include "Internal.hpp" +#include "vlc.hpp" #include namespace VLC @@ -36,8 +35,6 @@ class EventManager; class VLCPP_API MediaDiscoverer : public Internal { public: - ~MediaDiscoverer(); - // libvlc_media_discoverer_new_from_name /** * Discover media service by name. @@ -48,7 +45,7 @@ public: * \warning This is returned as a pointer, as this is not refcounter by VLC, and is * fairly expensive to instantiate. */ - MediaDiscoverer(Instance & inst, const std::string& name); + MediaDiscoverer(InstancePtr inst, const std::string& name); /** * Get media service discover object its localized name. @@ -62,7 +59,7 @@ public: * * \return event manager object. */ - EventManager& eventManager(); + EventManagerPtr eventManager(); /** * Query if media service discover object is running. @@ -72,18 +69,7 @@ public: bool isRunning(); private: - explicit MediaDiscoverer(InternalPtr ptr); - /** - * Release media discover object. If the reference count reaches 0, then - * the object will be released. - */ - void release(); - - MediaDiscoverer(const MediaDiscoverer& another); - MediaDiscoverer& operator=(const MediaDiscoverer& another); - -private: - EventManager* m_eventManager; + EventManagerPtr m_eventManager; }; } // namespace VLC diff --git a/src/MediaLibrary.cpp b/src/MediaLibrary.cpp index a9cbff1..04fe078 100644 --- a/src/MediaLibrary.cpp +++ b/src/MediaLibrary.cpp @@ -28,29 +28,9 @@ namespace VLC { -MediaLibrary::MediaLibrary(Instance& instance) +MediaLibrary::MediaLibrary(InstancePtr instance) + : Internal{ libvlc_media_library_new( instance->get() ), libvlc_media_library_release } { - m_obj = libvlc_media_library_new( instance ); - if (m_obj == NULL) - throw std::runtime_error("Failed to construct a media library"); -} - -MediaLibrary::MediaLibrary(const MediaLibrary& another) - : Internal( another ) -{ - retain(); -} - -MediaLibrary& MediaLibrary::operator=(const MediaLibrary& another) -{ - if (this == &another) - { - return *this; - } - release(); - m_obj = another.m_obj; - retain(); - return *this; } bool MediaLibrary::operator==(const MediaLibrary& another) const @@ -58,29 +38,9 @@ bool MediaLibrary::operator==(const MediaLibrary& another) const return m_obj == another.m_obj; } -MediaLibrary::~MediaLibrary() -{ - release(); -} - int MediaLibrary::load() { - return libvlc_media_library_load(m_obj); -} - -MediaLibrary::MediaLibrary(Internal::InternalPtr ptr) - : Internal( ptr ) -{ -} - -void MediaLibrary::release() -{ - libvlc_media_library_release(m_obj); -} - -void MediaLibrary::retain() -{ - libvlc_media_library_retain(m_obj); + return libvlc_media_library_load(get()); } } // namespace VLC diff --git a/src/MediaLibrary.hpp b/src/MediaLibrary.hpp index 31c7ba2..98de3b3 100644 --- a/src/MediaLibrary.hpp +++ b/src/MediaLibrary.hpp @@ -38,19 +38,7 @@ public: * * \param p_instance the libvlc instance */ - MediaLibrary(Instance & p_instance); - /** - * Copy libvlc_media_library_t from another to new MediaLibrary object. - * \param another existing MediaLibrary - */ - MediaLibrary(const MediaLibrary& another); - - /** - * Copy libvlc_media_library_t from another MediaLibrary - * to this MediaLibrary - * \param another existing MediaLibrary - */ - MediaLibrary& operator=(const MediaLibrary& another); + MediaLibrary(InstancePtr p_instance); /** * Check if 2 MediaLibrary objects contain the same libvlc_media_library_t. @@ -59,30 +47,12 @@ public: */ bool operator==(const MediaLibrary& another) const; - ~MediaLibrary(); - /** * Load media library. * * \return 0 on success, -1 on error */ int load(); - -private: - explicit MediaLibrary(InternalPtr ptr); - /** - * Release media library object. This functions decrements the reference - * count of the media library object. If it reaches 0, then the object - * will be released. - */ - void release(); - - /** - * Retain a reference to a media library object. This function will - * increment the reference counting for this object. Use - * MediaLibrary::release() to decrement the reference count. - */ - void retain(); }; } // namespace VLC diff --git a/src/MediaList.cpp b/src/MediaList.cpp index 890baea..24d9647 100644 --- a/src/MediaList.cpp +++ b/src/MediaList.cpp @@ -23,151 +23,96 @@ #include "vlc.hpp" -#include "EventManager.hpp" - #include +#include namespace VLC { -MediaList::MediaList(const MediaList& another) - : Internal( another ) - , m_eventManager( NULL ) -{ - if ( another.m_eventManager ) - m_eventManager = new EventManager( *another.m_eventManager ); - retain(); -} - -MediaList& MediaList::operator=(const MediaList& another) -{ - if (this == &another) - { - return *this; - } - release(); - m_obj = another.m_obj; - delete m_eventManager; - if ( another.m_eventManager != NULL ) - m_eventManager = new EventManager( *another.m_eventManager ); - else - m_eventManager = NULL; - retain(); - return *this; -} - bool MediaList::operator==(const MediaList& another) const { return m_obj == another.m_obj; } -MediaList::~MediaList() +MediaList::MediaList(MediaPtr md) + : Internal{ libvlc_media_subitems( md->get() ), libvlc_media_list_release } { - delete m_eventManager; - release(); } -MediaList::MediaList(Media& md) - : m_eventManager( NULL ) +MediaList::MediaList(MediaDiscovererPtr mdis ) + : Internal{ libvlc_media_discoverer_media_list( mdis->get() ), libvlc_media_list_release } { - m_obj = libvlc_media_subitems( md ); - if ( m_obj == NULL ) - throw std::runtime_error("Failed to construct a media list"); } -MediaList::MediaList( MediaDiscoverer& mdis ) - : m_eventManager( NULL ) +MediaList::MediaList(MediaLibraryPtr mlib) + : Internal{ libvlc_media_library_media_list( mlib->get() ), libvlc_media_list_release } { - m_obj = libvlc_media_discoverer_media_list( mdis ); - if ( m_obj == NULL ) - throw std::runtime_error("Failed to construct a media list"); } -MediaList::MediaList(MediaLibrary& mlib) - : m_eventManager( NULL ) +MediaList::MediaList( InstancePtr instance ) + : Internal{ libvlc_media_list_new( instance->get() ), libvlc_media_list_release } { - InternalPtr ptr = libvlc_media_library_media_list( mlib ); - if ( m_obj == NULL ) - throw std::runtime_error("Failed to construct a media list"); } -MediaList::MediaList( Instance& instance ) - : m_eventManager( NULL ) +void MediaList::setMedia( MediaPtr md ) { - m_obj = libvlc_media_list_new( instance ); - if ( m_obj == NULL ) - throw std::runtime_error("Failed to construct a media list"); + libvlc_media_list_set_media( get(), md->get() ); } -void MediaList::setMedia( Media &md ) +int MediaList::addMedia(MediaPtr p_md) { - libvlc_media_list_set_media( m_obj, md ); + return libvlc_media_list_add_media( get(), p_md->get() ); } -int MediaList::addMedia(Media& p_md) +int MediaList::insertMedia( MediaPtr md, int pos ) { - return libvlc_media_list_add_media( m_obj, p_md ); -} - -int MediaList::insertMedia( Media& md, int pos ) -{ - return libvlc_media_list_insert_media( m_obj, md, pos ); + return libvlc_media_list_insert_media( get(), md->get(), pos ); } int MediaList::removeIndex(int i_pos) { - return libvlc_media_list_remove_index(m_obj, i_pos); + return libvlc_media_list_remove_index(get(), i_pos); } int MediaList::count() { - return libvlc_media_list_count(m_obj); + return libvlc_media_list_count(get()); } Media MediaList::itemAtIndex(int i_pos) { - Media::InternalPtr ptr = libvlc_media_list_item_at_index(m_obj, i_pos); + Media::InternalPtr ptr = libvlc_media_list_item_at_index(get(), i_pos); return Media( ptr, false ); } -int MediaList::indexOfItem( Media &md ) +int MediaList::indexOfItem( MediaPtr md ) { - return libvlc_media_list_index_of_item( m_obj, md ); + return libvlc_media_list_index_of_item( get(), md->get() ); } bool MediaList::isReadonly() { - return libvlc_media_list_is_readonly(m_obj); + return libvlc_media_list_is_readonly(get()); } void MediaList::lock() { - libvlc_media_list_lock(m_obj); + libvlc_media_list_lock(get()); } void MediaList::unlock() { - libvlc_media_list_unlock(m_obj); + libvlc_media_list_unlock(get()); } -EventManager& MediaList::eventManager() +EventManagerPtr MediaList::eventManager() { - if ( m_eventManager == NULL ) + if ( m_eventManager ) { - libvlc_event_manager_t* obj = libvlc_media_list_event_manager( *this ); - m_eventManager = new EventManager( obj ); + libvlc_event_manager_t* obj = libvlc_media_list_event_manager( get() ); + m_eventManager = std::make_shared( obj ); } - return *m_eventManager; -} - -void MediaList::release() -{ - libvlc_media_list_release(m_obj); -} - -void MediaList::retain() -{ - libvlc_media_list_retain(m_obj); + return m_eventManager; } } // namespace VLC diff --git a/src/MediaList.hpp b/src/MediaList.hpp index 1153524..ba9613f 100644 --- a/src/MediaList.hpp +++ b/src/MediaList.hpp @@ -24,8 +24,7 @@ #ifndef LIBVLC_CXX_MEDIALIST_H #define LIBVLC_CXX_MEDIALIST_H -#include "common.hpp" -#include "Internal.hpp" +#include "vlc.hpp" namespace VLC { @@ -35,19 +34,6 @@ class EventManager; class VLCPP_API MediaList : public Internal { public: - /** - * Copy libvlc_media_list_t from another to new MediaList object. - * \param another existing MediaList - */ - MediaList(const MediaList& another); - - /** - * Copy libvlc_media_list_t from another MediaList - * to this MediaList - * \param another existing MediaList - */ - MediaList& operator=(const MediaList& another); - /** * Check if 2 MediaList objects contain the same libvlc_media_list_t. * \param another another MediaList @@ -55,8 +41,6 @@ public: */ bool operator==(const MediaList& another) const; - ~MediaList(); - // libvlc_media_subitems /** * Get subitems of media descriptor object. This will increment the @@ -65,7 +49,7 @@ public: * * \param p_md media descriptor object */ - MediaList(Media &md); + MediaList(MediaPtr md); // libvlc_media_discoverer_media_list /** @@ -73,7 +57,7 @@ public: * * \param p_mdis media service discover object */ - MediaList(MediaDiscoverer & mdis); + MediaList(MediaDiscovererPtr mdis); // libvlc_media_library_media_list /** @@ -81,7 +65,7 @@ public: * * \param p_mlib media library object */ - MediaList( MediaLibrary &mlib ); + MediaList(MediaLibraryPtr mlib ); // libvlc_media_list_new /** @@ -89,7 +73,7 @@ public: * * \param p_instance libvlc instance */ - MediaList(Instance &instance); + MediaList(InstancePtr instance); /** * Associate media instance with this media list instance. If another @@ -98,7 +82,7 @@ public: * * \param p_md media instance to add */ - void setMedia(Media & p_md); + void setMedia(MediaPtr p_md); /** * Add media instance to media list The libvlc_media_list_lock should be @@ -108,7 +92,7 @@ public: * * \return 0 on success, -1 if the media list is read-only */ - int addMedia(Media & p_md); + int addMedia(MediaPtr p_md); /** * Insert media instance in media list on a position The @@ -120,7 +104,7 @@ public: * * \return 0 on success, -1 if the media list is read-only */ - int insertMedia(Media & md, int pos); + int insertMedia(MediaPtr md, int pos); /** * Remove media instance from media list on a position The @@ -162,7 +146,7 @@ public: * * \return position of media instance or -1 if media not found */ - int indexOfItem(Media & md); + int indexOfItem(MediaPtr md); /** * This indicates if this media list is read-only from a user point of @@ -189,22 +173,10 @@ public: * * \return libvlc_event_manager */ - VLC::EventManager& eventManager(); - -private: - explicit MediaList(InternalPtr ptr); - /** - * Release media list created with MediaList::MediaList() . - */ - void release(); - - /** - * Retain reference to a media list - */ - void retain(); + EventManagerPtr eventManager(); private: - EventManager* m_eventManager; + EventManagerPtr m_eventManager; }; } // namespace VLC diff --git a/src/MediaListPlayer.cpp b/src/MediaListPlayer.cpp index e7aaa04..5ba8892 100644 --- a/src/MediaListPlayer.cpp +++ b/src/MediaListPlayer.cpp @@ -24,138 +24,94 @@ #include "vlc.hpp" #include +#include namespace VLC { -MediaListPlayer::MediaListPlayer(const MediaListPlayer& another) - : Internal( another ) - , m_eventManager( NULL ) -{ - if ( another.m_eventManager ) - m_eventManager = new EventManager( *another.m_eventManager ); - retain(); -} - -MediaListPlayer& MediaListPlayer::operator=(const MediaListPlayer& another) -{ - if (this == &another) - { - return *this; - } - release(); - m_obj = another.m_obj; - delete m_eventManager; - if ( another.m_eventManager ) - m_eventManager = new EventManager( *another.m_eventManager ); - else - m_eventManager = NULL; - retain(); - return *this; -} - bool MediaListPlayer::operator==(const MediaListPlayer& another) const { return m_obj == another.m_obj; } -MediaListPlayer::~MediaListPlayer() +MediaListPlayer::MediaListPlayer( InstancePtr instance ) + : Internal{ libvlc_media_list_player_new( instance->get() ), libvlc_media_list_player_release } { - release(); } -MediaListPlayer::MediaListPlayer( Instance& instance ) - : m_eventManager( NULL ) +EventManagerPtr MediaListPlayer::eventManager() { - m_obj = libvlc_media_list_player_new( instance ); - if ( m_obj == NULL ) - throw std::runtime_error("Failed to construct a medialist player"); -} - -EventManager& MediaListPlayer::eventManager() -{ - if ( m_eventManager == NULL ) + if ( m_eventManager ) { - libvlc_event_manager_t* obj = libvlc_media_list_player_event_manager(m_obj); - m_eventManager = new EventManager( obj ); + libvlc_event_manager_t* obj = libvlc_media_list_player_event_manager(get()); + m_eventManager = std::make_shared( obj ); } - return *m_eventManager; + return m_eventManager; } -void MediaListPlayer::setMediaPlayer( MediaPlayer &mi ) +void MediaListPlayer::setMediaPlayer( MediaPlayerPtr mi ) { - libvlc_media_list_player_set_media_player( m_obj, mi ); + libvlc_media_list_player_set_media_player( get(), mi->get() ); } -void MediaListPlayer::setMediaList( MediaList &mlist ) +void MediaListPlayer::setMediaList( MediaListPtr mlist ) { - libvlc_media_list_player_set_media_list( m_obj, mlist ); + libvlc_media_list_player_set_media_list( get(), mlist->get() ); } void MediaListPlayer::play() { - libvlc_media_list_player_play(m_obj); + libvlc_media_list_player_play(get()); } void MediaListPlayer::pause() { - libvlc_media_list_player_pause(m_obj); + libvlc_media_list_player_pause(get()); } bool MediaListPlayer::isPlaying() { - return libvlc_media_list_player_is_playing(m_obj) != 0; + return libvlc_media_list_player_is_playing(get()) != 0; } libvlc_state_t MediaListPlayer::state() { - return libvlc_media_list_player_get_state( m_obj ); + return libvlc_media_list_player_get_state( get() ); } int MediaListPlayer::playItemAtIndex(int i_index) { - return libvlc_media_list_player_play_item_at_index(m_obj, i_index); + return libvlc_media_list_player_play_item_at_index(get(), i_index); } -int MediaListPlayer::playItem(Media & p_md) +int MediaListPlayer::playItem(MediaPtr p_md) { - return libvlc_media_list_player_play_item( m_obj, p_md ); + return libvlc_media_list_player_play_item( get(), p_md->get() ); } void MediaListPlayer::stop() { - libvlc_media_list_player_stop(m_obj); + libvlc_media_list_player_stop(get()); } int MediaListPlayer::next() { - return libvlc_media_list_player_next(m_obj); + return libvlc_media_list_player_next(get()); } int MediaListPlayer::previous() { - return libvlc_media_list_player_previous(m_obj); + return libvlc_media_list_player_previous(get()); } void MediaListPlayer::setPlaybackMode(libvlc_playback_mode_t e_mode) { - libvlc_media_list_player_set_playback_mode(m_obj, e_mode); + libvlc_media_list_player_set_playback_mode(get(), e_mode); } MediaListPlayer::MediaListPlayer( InternalPtr ptr ) - : Internal( ptr ) - , m_eventManager( NULL ) -{ -} - -void MediaListPlayer::release() -{ - libvlc_media_list_player_release(m_obj); -} - -void MediaListPlayer::retain() + : Internal{ ptr, libvlc_media_list_player_release } { - libvlc_media_list_player_retain(m_obj); } } // namespace VLC diff --git a/src/MediaListPlayer.hpp b/src/MediaListPlayer.hpp index d3989cf..4428db8 100644 --- a/src/MediaListPlayer.hpp +++ b/src/MediaListPlayer.hpp @@ -27,7 +27,6 @@ #include #include "common.hpp" -#include "Internal.hpp" namespace VLC { @@ -39,19 +38,6 @@ class MediaList; class VLCPP_API MediaListPlayer : public Internal { public: - /** - * Copy libvlc_media_list_player_t from another to new MediaListPlayer object. - * \param another existing MediaListPlayer - */ - MediaListPlayer(const MediaListPlayer& another); - - /** - * Copy libvlc_media_list_player_t from another MediaListPlayer - * to this MediaListPlayer - * \param another existing MediaListPlayer - */ - MediaListPlayer& operator=(const MediaListPlayer& another); - /** * Check if 2 MediaListPlayer objects contain the same libvlc_media_list_player_t. * \param another another MediaListPlayer @@ -61,34 +47,33 @@ public: ~MediaListPlayer(); - // libvlc_media_list_player_new /** * Create new media_list_player. * * \param p_instance libvlc instance */ - MediaListPlayer(Instance & instance); + MediaListPlayer(InstancePtr instance); /** * Return the event manager of this media_list_player. * * \return the event manager */ - EventManager& eventManager(); + EventManagerPtr eventManager(); /** * Replace media player in media_list_player with this instance. * * \param p_mi media player instance */ - void setMediaPlayer(MediaPlayer & p_mi); + void setMediaPlayer(MediaPlayerPtr p_mi); /** * Set the media list associated with the player * * \param p_mlist list of media */ - void setMediaList(MediaList & mlist); + void setMediaList(MediaListPtr mlist); /** * Play media list @@ -130,7 +115,7 @@ public: * * \return 0 upon success, -1 if the media is not part of the media list */ - int playItem(Media & p_md); + int playItem(MediaPtr p_md); /** * Stop playing media list @@ -160,23 +145,9 @@ public: private: explicit MediaListPlayer(InternalPtr ptr); - /** - * Release a media_list_player after use Decrement the reference count of - * a media player object. If the reference count is 0, then - * MediaListPlayer::release() will release the media player object. If - * the media player object has been released, then it should not be used - * again. - */ - void release(); - - /** - * Retain a reference to a media player list object. Use - * MediaListPlayer::release() to decrement reference count. - */ - void retain(); private: - EventManager* m_eventManager; + EventManagerPtr m_eventManager; }; diff --git a/src/MediaPlayer.cpp b/src/MediaPlayer.cpp index 03ef866..0e51bef 100644 --- a/src/MediaPlayer.cpp +++ b/src/MediaPlayer.cpp @@ -23,340 +23,296 @@ #include "vlc.hpp" -#include "EventManager.hpp" #include +#include namespace VLC { -MediaPlayer::MediaPlayer() - : Internal( NULL ) - , m_eventManager( NULL ) -{ -} - -MediaPlayer::MediaPlayer(const MediaPlayer& another) - : Internal( another ) - , m_eventManager( NULL ) -{ - if ( another.m_eventManager != NULL ) - m_eventManager = new EventManager( *another.m_eventManager ); - retain(); -} - -MediaPlayer& MediaPlayer::operator=(const MediaPlayer& another) -{ - if (this == &another) - { - return *this; - } - release(); - m_obj = another.m_obj; - delete m_eventManager; - if ( another.m_eventManager != NULL ) - m_eventManager = new EventManager( *another.m_eventManager ); - else - m_eventManager = NULL; - retain(); - return *this; -} - bool MediaPlayer::operator==(const MediaPlayer& another) const { return m_obj == another.m_obj; } -MediaPlayer::~MediaPlayer() -{ - delete m_eventManager; - release(); -} - -MediaPlayer::MediaPlayer( Instance& instance ) - : m_eventManager( NULL ) +MediaPlayer::MediaPlayer( InstancePtr instance ) + : Internal{ libvlc_media_player_new( instance->get() ), libvlc_media_player_release } { - m_obj = libvlc_media_player_new( instance ); - if ( m_obj == NULL ) - throw std::runtime_error("Failed to construct a media player"); } -MediaPlayer::MediaPlayer( Media& md ) - : m_eventManager( NULL ) +MediaPlayer::MediaPlayer( MediaPtr md ) + : Internal{ libvlc_media_player_new_from_media( md->get() ), libvlc_media_player_release } { - m_obj = libvlc_media_player_new_from_media( md ); - if ( m_obj == NULL ) - throw std::runtime_error("Failed to construct a media player"); } -void MediaPlayer::setMedia( Media& md ) +void MediaPlayer::setMedia( MediaPtr md ) { - libvlc_media_player_set_media( m_obj, md ); + libvlc_media_player_set_media( get(), md->get() ); } -Media MediaPlayer::media() +MediaPtr MediaPlayer::media() { - libvlc_media_t* media = libvlc_media_player_get_media(m_obj); - return Media( media, false ); + libvlc_media_t* media = libvlc_media_player_get_media(get()); + return std::make_shared( media, true ); } -EventManager& MediaPlayer::eventManager() +EventManagerPtr MediaPlayer::eventManager() { if ( m_eventManager == NULL ) { - libvlc_event_manager_t* obj = libvlc_media_player_event_manager( m_obj ); - m_eventManager = new EventManager( obj ); + libvlc_event_manager_t* obj = libvlc_media_player_event_manager( get() ); + m_eventManager = std::make_shared( obj ); } - return *m_eventManager; + return m_eventManager; } bool MediaPlayer::isPlaying() { - return libvlc_media_player_is_playing(m_obj) != 0; + return libvlc_media_player_is_playing(get()) != 0; } int MediaPlayer::play() { - return libvlc_media_player_play(m_obj); + return libvlc_media_player_play(get()); } void MediaPlayer::setPause(int do_pause) { - libvlc_media_player_set_pause(m_obj, do_pause); + libvlc_media_player_set_pause(get(), do_pause); } void MediaPlayer::pause() { - libvlc_media_player_pause(m_obj); + libvlc_media_player_pause(get()); } void MediaPlayer::stop() { - libvlc_media_player_stop(m_obj); + libvlc_media_player_stop(get()); } void MediaPlayer::setNsobject(void * drawable) { - libvlc_media_player_set_nsobject(m_obj, drawable); + libvlc_media_player_set_nsobject(get(), drawable); } void * MediaPlayer::nsobject() { - return libvlc_media_player_get_nsobject(m_obj); + return libvlc_media_player_get_nsobject(get()); } void MediaPlayer::setAgl(uint32_t drawable) { - libvlc_media_player_set_agl(m_obj, drawable); + libvlc_media_player_set_agl(get(), drawable); } uint32_t MediaPlayer::agl() { - return libvlc_media_player_get_agl(m_obj); + return libvlc_media_player_get_agl(get()); } void MediaPlayer::setXwindow(uint32_t drawable) { - libvlc_media_player_set_xwindow(m_obj, drawable); + libvlc_media_player_set_xwindow(get(), drawable); } uint32_t MediaPlayer::xwindow() { - return libvlc_media_player_get_xwindow(m_obj); + return libvlc_media_player_get_xwindow(get()); } void MediaPlayer::setHwnd(void * drawable) { - libvlc_media_player_set_hwnd(m_obj, drawable); + libvlc_media_player_set_hwnd(get(), drawable); } void * MediaPlayer::hwnd() { - return libvlc_media_player_get_hwnd(m_obj); + return libvlc_media_player_get_hwnd(get()); } libvlc_time_t MediaPlayer::length() { - return libvlc_media_player_get_length(m_obj); + return libvlc_media_player_get_length(get()); } libvlc_time_t MediaPlayer::time() { - return libvlc_media_player_get_time(m_obj); + return libvlc_media_player_get_time(get()); } void MediaPlayer::setTime(libvlc_time_t i_time) { - libvlc_media_player_set_time(m_obj, i_time); + libvlc_media_player_set_time(get(), i_time); } float MediaPlayer::position() { - return libvlc_media_player_get_position(m_obj); + return libvlc_media_player_get_position(get()); } void MediaPlayer::setPosition(float f_pos) { - libvlc_media_player_set_position(m_obj, f_pos); + libvlc_media_player_set_position(get(), f_pos); } void MediaPlayer::setChapter(int i_chapter) { - libvlc_media_player_set_chapter(m_obj, i_chapter); + libvlc_media_player_set_chapter(get(), i_chapter); } int MediaPlayer::chapter() { - return libvlc_media_player_get_chapter(m_obj); + return libvlc_media_player_get_chapter(get()); } int MediaPlayer::chapterCount() { - return libvlc_media_player_get_chapter_count(m_obj); + return libvlc_media_player_get_chapter_count(get()); } bool MediaPlayer::willPlay() { - return libvlc_media_player_will_play(m_obj) != 0; + return libvlc_media_player_will_play(get()) != 0; } int MediaPlayer::chapterCountForTitle(int i_title) { - return libvlc_media_player_get_chapter_count_for_title(m_obj, i_title); + return libvlc_media_player_get_chapter_count_for_title(get(), i_title); } void MediaPlayer::setTitle(int i_title) { - libvlc_media_player_set_title(m_obj, i_title); + libvlc_media_player_set_title(get(), i_title); } int MediaPlayer::title() { - return libvlc_media_player_get_title(m_obj); + return libvlc_media_player_get_title(get()); } int MediaPlayer::titleCount() { - return libvlc_media_player_get_title_count(m_obj); + return libvlc_media_player_get_title_count(get()); } void MediaPlayer::previousChapter() { - libvlc_media_player_previous_chapter(m_obj); + libvlc_media_player_previous_chapter(get()); } void MediaPlayer::nextChapter() { - libvlc_media_player_next_chapter(m_obj); + libvlc_media_player_next_chapter(get()); } float MediaPlayer::rate() { - return libvlc_media_player_get_rate(m_obj); + return libvlc_media_player_get_rate(get()); } int MediaPlayer::setRate(float rate) { - return libvlc_media_player_set_rate(m_obj, rate); + return libvlc_media_player_set_rate(get(), rate); } libvlc_state_t MediaPlayer::state() { - return libvlc_media_player_get_state(m_obj); + return libvlc_media_player_get_state(get()); } float MediaPlayer::fps() { - return libvlc_media_player_get_fps(m_obj); + return libvlc_media_player_get_fps(get()); } unsigned MediaPlayer::hasVout() { - return libvlc_media_player_has_vout(m_obj); + return libvlc_media_player_has_vout(get()); } bool MediaPlayer::isSeekable() { - return libvlc_media_player_is_seekable(m_obj) != 0; + return libvlc_media_player_is_seekable(get()) != 0; } bool MediaPlayer::canPause() { - return libvlc_media_player_can_pause(m_obj) != 0; + return libvlc_media_player_can_pause(get()) != 0; } bool MediaPlayer::programScrambled() { - return libvlc_media_player_program_scrambled(m_obj) != 0; + return libvlc_media_player_program_scrambled(get()) != 0; } void MediaPlayer::nextFrame() { - libvlc_media_player_next_frame(m_obj); + libvlc_media_player_next_frame(get()); } void MediaPlayer::navigate(unsigned navigate) { - libvlc_media_player_navigate(m_obj, navigate); + libvlc_media_player_navigate(get(), navigate); } void MediaPlayer::setVideoTitleDisplay(libvlc_position_t position, unsigned int timeout) { - libvlc_media_player_set_video_title_display(m_obj, position, timeout); + libvlc_media_player_set_video_title_display(get(), position, timeout); } void MediaPlayer::toggleFullscreen() { - libvlc_toggle_fullscreen(m_obj); + libvlc_toggle_fullscreen(get()); } void MediaPlayer::setFullscreen(int b_fullscreen) { - libvlc_set_fullscreen(m_obj, b_fullscreen); + libvlc_set_fullscreen(get(), b_fullscreen); } bool MediaPlayer::fullscreen() { - return libvlc_get_fullscreen(m_obj) != 0; + return libvlc_get_fullscreen(get()) != 0; } void MediaPlayer::toggleTeletext() { - libvlc_toggle_teletext(m_obj); + libvlc_toggle_teletext(get()); } int MediaPlayer::setEqualizer(libvlc_equalizer_t * p_equalizer) { - return libvlc_media_player_set_equalizer(m_obj, p_equalizer); + return libvlc_media_player_set_equalizer(get(), p_equalizer); } void MediaPlayer::setAudioCallbacks(libvlc_audio_play_cb play, libvlc_audio_pause_cb pause, libvlc_audio_resume_cb resume, libvlc_audio_flush_cb flush, libvlc_audio_drain_cb drain, void * opaque) { - libvlc_audio_set_callbacks(m_obj, play, pause, resume, flush, drain, opaque); + libvlc_audio_set_callbacks(get(), play, pause, resume, flush, drain, opaque); } void MediaPlayer::setVolumeCallback(libvlc_audio_set_volume_cb set_volume) { - libvlc_audio_set_volume_callback(m_obj, set_volume); + libvlc_audio_set_volume_callback(get(), set_volume); } void MediaPlayer::setAudioFormatCallbacks(libvlc_audio_setup_cb setup, libvlc_audio_cleanup_cb cleanup) { - libvlc_audio_set_format_callbacks(m_obj, setup, cleanup); + libvlc_audio_set_format_callbacks(get(), setup, cleanup); } void MediaPlayer::setAudioFormat(const std::string& format, unsigned rate, unsigned channels) { - libvlc_audio_set_format(m_obj, format.c_str(), rate, channels); + libvlc_audio_set_format(get(), format.c_str(), rate, channels); } int MediaPlayer::setAudioOutput(const std::string& psz_name) { - return libvlc_audio_output_set(m_obj, psz_name.c_str()); + return libvlc_audio_output_set(get(), psz_name.c_str()); } std::vector MediaPlayer::outputDeviceEnum() { - libvlc_audio_output_device_t* devices = libvlc_audio_output_device_enum(m_obj); + libvlc_audio_output_device_t* devices = libvlc_audio_output_device_enum(get()); std::vector res; if ( devices == NULL ) return res; @@ -368,123 +324,123 @@ std::vector MediaPlayer::outputDeviceEnum() void MediaPlayer::outputDeviceSet(const std::string& module, const std::string& device_id) { - libvlc_audio_output_device_set(m_obj, module.c_str(), device_id.c_str()); + libvlc_audio_output_device_set(get(), module.c_str(), device_id.c_str()); } void MediaPlayer::toggleMute() { - libvlc_audio_toggle_mute(m_obj); + libvlc_audio_toggle_mute(get()); } int MediaPlayer::mute() { - return libvlc_audio_get_mute(m_obj); + return libvlc_audio_get_mute(get()); } void MediaPlayer::setMute(int status) { - libvlc_audio_set_mute(m_obj, status); + libvlc_audio_set_mute(get(), status); } int MediaPlayer::volume() { - return libvlc_audio_get_volume(m_obj); + return libvlc_audio_get_volume(get()); } int MediaPlayer::setVolume(int i_volume) { - return libvlc_audio_set_volume(m_obj, i_volume); + return libvlc_audio_set_volume(get(), i_volume); } int MediaPlayer::audioTrackCount() { - return libvlc_audio_get_track_count(m_obj); + return libvlc_audio_get_track_count(get()); } std::vector MediaPlayer::audioTrackDescription() { - libvlc_track_description_t* result = libvlc_audio_get_track_description( m_obj ); + libvlc_track_description_t* result = libvlc_audio_get_track_description( get() ); return getTracksDescription( result ); } int MediaPlayer::audioTrack() { - return libvlc_audio_get_track(m_obj); + return libvlc_audio_get_track(get()); } int MediaPlayer::setAudioTrack(int i_track) { - return libvlc_audio_set_track(m_obj, i_track); + return libvlc_audio_set_track(get(), i_track); } int MediaPlayer::channel() { - return libvlc_audio_get_channel(m_obj); + return libvlc_audio_get_channel(get()); } int MediaPlayer::setChannel(int channel) { - return libvlc_audio_set_channel(m_obj, channel); + return libvlc_audio_set_channel(get(), channel); } int64_t MediaPlayer::delay() { - return libvlc_audio_get_delay(m_obj); + return libvlc_audio_get_delay(get()); } int MediaPlayer::setDelay(int64_t i_delay) { - return libvlc_audio_set_delay(m_obj, i_delay); + return libvlc_audio_set_delay(get(), i_delay); } void MediaPlayer::setVideoCallbacks(libvlc_video_lock_cb lock, libvlc_video_unlock_cb unlock, libvlc_video_display_cb display, void * opaque) { - libvlc_video_set_callbacks(m_obj, lock, unlock, display, opaque); + libvlc_video_set_callbacks(get(), lock, unlock, display, opaque); } void MediaPlayer::setVideoFormat(const std::string& chroma, unsigned width, unsigned height, unsigned pitch) { - libvlc_video_set_format(m_obj, chroma.c_str(), width, height, pitch); + libvlc_video_set_format(get(), chroma.c_str(), width, height, pitch); } void MediaPlayer::setVideoFormatCallbacks(libvlc_video_format_cb setup, libvlc_video_cleanup_cb cleanup) { - libvlc_video_set_format_callbacks(m_obj, setup, cleanup); + libvlc_video_set_format_callbacks(get(), setup, cleanup); } void MediaPlayer::setKeyInput(unsigned on) { - libvlc_video_set_key_input(m_obj, on); + libvlc_video_set_key_input(get(), on); } void MediaPlayer::setMouseInput(unsigned on) { - libvlc_video_set_mouse_input(m_obj, on); + libvlc_video_set_mouse_input(get(), on); } int MediaPlayer::size(unsigned num, unsigned * px, unsigned * py) { - return libvlc_video_get_size(m_obj, num, px, py); + return libvlc_video_get_size(get(), num, px, py); } int MediaPlayer::cursor(unsigned num, int * px, int * py) { - return libvlc_video_get_cursor(m_obj, num, px, py); + return libvlc_video_get_cursor(get(), num, px, py); } float MediaPlayer::scale() { - return libvlc_video_get_scale(m_obj); + return libvlc_video_get_scale(get()); } void MediaPlayer::setScale(float f_factor) { - libvlc_video_set_scale(m_obj, f_factor); + libvlc_video_set_scale(get(), f_factor); } std::string MediaPlayer::aspectRatio() { - char* c_result = libvlc_video_get_aspect_ratio(m_obj); + char* c_result = libvlc_video_get_aspect_ratio(get()); if ( c_result == NULL ) return std::string(); std::string result = c_result; @@ -494,60 +450,60 @@ std::string MediaPlayer::aspectRatio() void MediaPlayer::setAspectRatio(const std::string& psz_aspect) { - libvlc_video_set_aspect_ratio(m_obj, psz_aspect.c_str()); + libvlc_video_set_aspect_ratio(get(), psz_aspect.c_str()); } int MediaPlayer::spu() { - return libvlc_video_get_spu(m_obj); + return libvlc_video_get_spu(get()); } int MediaPlayer::spuCount() { - return libvlc_video_get_spu_count(m_obj); + return libvlc_video_get_spu_count(get()); } std::vector MediaPlayer::spuDescription() { - libvlc_track_description_t* result = libvlc_video_get_spu_description( m_obj ); + libvlc_track_description_t* result = libvlc_video_get_spu_description( get() ); return getTracksDescription( result ); } int MediaPlayer::setSpu(int i_spu) { - return libvlc_video_set_spu(m_obj, i_spu); + return libvlc_video_set_spu(get(), i_spu); } int MediaPlayer::setSubtitleFile(const std::string& psz_subtitle) { - return libvlc_video_set_subtitle_file(m_obj, psz_subtitle.c_str()); + return libvlc_video_set_subtitle_file(get(), psz_subtitle.c_str()); } int64_t MediaPlayer::spuDelay() { - return libvlc_video_get_spu_delay(m_obj); + return libvlc_video_get_spu_delay(get()); } int MediaPlayer::setSpuDelay(int64_t i_delay) { - return libvlc_video_set_spu_delay(m_obj, i_delay); + return libvlc_video_set_spu_delay(get(), i_delay); } std::vector MediaPlayer::titleDescription() { - libvlc_track_description_t* result = libvlc_video_get_title_description( m_obj ); + libvlc_track_description_t* result = libvlc_video_get_title_description( get() ); return getTracksDescription( result ); } std::vector MediaPlayer::chapterDescription(int i_title) { - libvlc_track_description_t* result = libvlc_video_get_chapter_description( m_obj, i_title ); + libvlc_track_description_t* result = libvlc_video_get_chapter_description( get(), i_title ); return getTracksDescription( result ); } std::string MediaPlayer::cropGeometry() { - char* c_result = libvlc_video_get_crop_geometry(m_obj); + char* c_result = libvlc_video_get_crop_geometry(get()); if ( c_result == NULL ) return std::string(); std::string result = c_result; @@ -557,58 +513,58 @@ std::string MediaPlayer::cropGeometry() void MediaPlayer::setCropGeometry(const std::string& psz_geometry) { - libvlc_video_set_crop_geometry(m_obj, psz_geometry.c_str()); + libvlc_video_set_crop_geometry(get(), psz_geometry.c_str()); } int MediaPlayer::teletext() { - return libvlc_video_get_teletext(m_obj); + return libvlc_video_get_teletext(get()); } void MediaPlayer::setTeletext(int i_page) { - libvlc_video_set_teletext(m_obj, i_page); + libvlc_video_set_teletext(get(), i_page); } int MediaPlayer::videoTrackCount() { - return libvlc_video_get_track_count(m_obj); + return libvlc_video_get_track_count(get()); } std::vector MediaPlayer::videoTrackDescription() { - libvlc_track_description_t* result = libvlc_video_get_track_description( m_obj ); + libvlc_track_description_t* result = libvlc_video_get_track_description( get() ); return getTracksDescription( result ); } int MediaPlayer::videoTrack() { - return libvlc_video_get_track(m_obj); + return libvlc_video_get_track(get()); } int MediaPlayer::setVideoTrack(int i_track) { - return libvlc_video_set_track(m_obj, i_track); + return libvlc_video_set_track(get(), i_track); } int MediaPlayer::takeSnapshot(unsigned num, const std::string& psz_filepath, unsigned int i_width, unsigned int i_height) { - return libvlc_video_take_snapshot(m_obj, num, psz_filepath.c_str(), i_width, i_height); + return libvlc_video_take_snapshot(get(), num, psz_filepath.c_str(), i_width, i_height); } void MediaPlayer::setDeinterlace(const std::string& psz_mode) { - libvlc_video_set_deinterlace(m_obj, psz_mode.c_str()); + libvlc_video_set_deinterlace(get(), psz_mode.c_str()); } int MediaPlayer::marqueeInt(unsigned option) { - return libvlc_video_get_marquee_int(m_obj, option); + return libvlc_video_get_marquee_int(get(), option); } std::string MediaPlayer::marqueeString(unsigned option) { - char* c_result = libvlc_video_get_marquee_string(m_obj, option); + char* c_result = libvlc_video_get_marquee_string(get(), option); if ( c_result == NULL ) return std::string(); std::string result = c_result; @@ -618,63 +574,49 @@ std::string MediaPlayer::marqueeString(unsigned option) void MediaPlayer::setMarqueeInt(unsigned option, int i_val) { - libvlc_video_set_marquee_int(m_obj, option, i_val); + libvlc_video_set_marquee_int(get(), option, i_val); } void MediaPlayer::setMarqueeString(unsigned option, const std::string& psz_text) { - libvlc_video_set_marquee_string(m_obj, option, psz_text.c_str()); + libvlc_video_set_marquee_string(get(), option, psz_text.c_str()); } int MediaPlayer::logoInt(unsigned option) { - return libvlc_video_get_logo_int(m_obj, option); + return libvlc_video_get_logo_int(get(), option); } void MediaPlayer::setLogoInt(unsigned option, int value) { - libvlc_video_set_logo_int(m_obj, option, value); + libvlc_video_set_logo_int(get(), option, value); } void MediaPlayer::setLogoString(unsigned option, const std::string& psz_value) { - libvlc_video_set_logo_string(m_obj, option, psz_value.c_str()); + libvlc_video_set_logo_string(get(), option, psz_value.c_str()); } int MediaPlayer::adjustInt(unsigned option) { - return libvlc_video_get_adjust_int(m_obj, option); + return libvlc_video_get_adjust_int(get(), option); } void MediaPlayer::setAdjustInt(unsigned option, int value) { - libvlc_video_set_adjust_int(m_obj, option, value); + libvlc_video_set_adjust_int(get(), option, value); } float MediaPlayer::adjustFloat(unsigned option) { - float c_result = libvlc_video_get_adjust_float(m_obj, option); + float c_result = libvlc_video_get_adjust_float(get(), option); float result = c_result; return result; } void MediaPlayer::setAdjustFloat(unsigned option, float value) { - libvlc_video_set_adjust_float(m_obj, option, value); -} - -MediaPlayer::MediaPlayer( InternalPtr ptr, bool increaseRefCount ) - : Internal( ptr ) - , m_eventManager( NULL ) -{ - if ( increaseRefCount ) - retain(); -} - -void MediaPlayer::retain() -{ - if ( isValid() ) - libvlc_media_player_retain( m_obj ); + libvlc_video_set_adjust_float(get(), option, value); } std::vector MediaPlayer::getTracksDescription(libvlc_track_description_t* tracks) const @@ -692,12 +634,5 @@ std::vector MediaPlayer::getTracksDescription(libvlc_track_des return result; } - -void MediaPlayer::release() -{ - if ( isValid() ) - libvlc_media_player_release( m_obj ); -} - } // namespace VLC diff --git a/src/MediaPlayer.hpp b/src/MediaPlayer.hpp index 488c3e9..17b88b2 100644 --- a/src/MediaPlayer.hpp +++ b/src/MediaPlayer.hpp @@ -27,8 +27,7 @@ #include #include -#include "common.hpp" -#include "Internal.hpp" +#include "vlc.hpp" namespace VLC { @@ -43,18 +42,6 @@ class VLCPP_API MediaPlayer : public Internal { public: MediaPlayer(); - /** - * Copy libvlc_media_player_t from another to new MediaPlayer object. - * \param another existing MediaPlayer - */ - MediaPlayer(const MediaPlayer& another); - - /** - * Copy libvlc_media_player_t from another MediaPlayer - * to this MediaPlayer - * \param another existing MediaPlayer - */ - MediaPlayer& operator=(const MediaPlayer& another); /** * Check if 2 MediaPlayer objects contain the same libvlc_media_player_t. @@ -63,8 +50,6 @@ public: */ bool operator==(const MediaPlayer& another) const; - ~MediaPlayer(); - // libvlc_media_player_new /** * Create an empty Media Player object @@ -72,7 +57,7 @@ public: * \param p_libvlc_instance the libvlc instance in which the Media * Player should be created. */ - MediaPlayer( Instance& instance ); + MediaPlayer(InstancePtr instance ); // libvlc_media_player_new_from_media /** @@ -80,7 +65,7 @@ public: * * \param p_md the media. Afterwards the p_md can be safely destroyed. */ - MediaPlayer( Media &md ); + MediaPlayer(MediaPtr md ); /** * Set the media that will be used by the media_player. If any, previous @@ -88,7 +73,7 @@ public: * * \param p_md the Media. Afterwards the p_md can be safely destroyed. */ - void setMedia(Media & md); + void setMedia(MediaPtr md); /** * Get the media used by the media_player. @@ -96,14 +81,14 @@ public: * \return the media associated with p_mi, or NULL if no media is * associated */ - VLC::Media media(); + MediaPtr media(); /** * Get the Event Manager from which the media player send event. * * \return the event manager associated with p_mi */ - VLC::EventManager& eventManager(); + EventManagerPtr eventManager(); /** * is_playing @@ -1211,26 +1196,10 @@ public: void setAdjustFloat(unsigned option, float value); private: - explicit MediaPlayer( InternalPtr ptr, bool increaseRefCount ); - /** - * Release a media_player after use Decrement the reference count of a - * media player object. If the reference count is 0, then - * MediaPlayer::release() will release the media player object. If the - * media player object has been released, then it should not be used - * again. - */ - void release(); - - /** - * Retain a reference to a media player object. Use - * MediaPlayer::release() to decrement reference count. - */ - void retain(); - std::vector getTracksDescription( libvlc_track_description_t* tracks ) const; private: - EventManager* m_eventManager; + EventManagerPtr m_eventManager; }; diff --git a/src/common.hpp b/src/common.hpp index 433e741..7de1f22 100644 --- a/src/common.hpp +++ b/src/common.hpp @@ -40,4 +40,30 @@ # define VLCPP_API #endif +#include + +namespace VLC +{ + class EventManager; + using EventManagerPtr = std::shared_ptr; + + class Media; + using MediaPtr = std::shared_ptr; + + class Instance; + using InstancePtr = std::shared_ptr; + + class MediaDiscoverer; + using MediaDiscovererPtr = std::shared_ptr; + + class MediaPlayer; + using MediaPlayerPtr = std::shared_ptr; + + class MediaList; + using MediaListPtr = std::shared_ptr; + + class MediaLibrary; + using MediaLibraryPtr = std::shared_ptr; +} + #endif diff --git a/src/vlc.hpp b/src/vlc.hpp index 8456864..fb63788 100644 --- a/src/vlc.hpp +++ b/src/vlc.hpp @@ -4,6 +4,7 @@ * Copyright © 2014 the VideoLAN team * * Authors: Alexey Sokolov + * Hugo Beauzée-Luyssen * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by @@ -20,10 +21,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ -/* This file is autogenerated */ - - - #ifndef LIBVLC_CXX_VLC_H #define LIBVLC_CXX_VLC_H @@ -35,5 +32,8 @@ #include "MediaLibrary.hpp" #include "MediaList.hpp" #include "EventManager.hpp" +#include "structures.hpp" + +#include #endif -- GitLab