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

Stop using pointer to describe refcounted classes

parent 3f535ebd
......@@ -26,6 +26,11 @@
namespace VLC
{
Instance::Instance()
: Internal( NULL )
{
}
Instance::Instance( const Instance& another )
: Internal( another )
{
......@@ -54,12 +59,10 @@ Instance::~Instance()
release();
}
Instance* Instance::create( int argc, const char *const * argv )
Instance Instance::create( int argc, const char *const * argv )
{
InternalPtr ptr = libvlc_new( argc, argv );
if ( ptr == NULL )
return NULL;
return new Instance( ptr );
return Instance( ptr );
}
int Instance::addIntf( const std::string& name )
......@@ -164,7 +167,8 @@ Instance::Instance(Internal::InternalPtr ptr)
void Instance::release()
{
libvlc_release(m_obj);
if ( m_obj )
libvlc_release(m_obj);
}
void Instance::retain()
......
......@@ -36,6 +36,7 @@ namespace VLC
class VLCPP_API Instance : public Internal<libvlc_instance_t>
{
public:
Instance();
/**
* Copy libvlc_instance_t from another to new Instance object.
* \param another existing Instance
......@@ -80,7 +81,7 @@ public:
*
* \param argv list of arguments (should be NULL)
*/
static Instance* create(int argc, const char *const * argv);
static Instance create(int argc, const char *const * argv);
/**
* Try to start a user interface for the libvlc instance.
......
......@@ -41,8 +41,9 @@ class Internal
return m_obj;
}
operator T*() { return m_obj; }
bool isValid() const { return m_obj != NULL; }
protected:
Internal(InternalPtr obj = NULL ) : m_obj( obj ) {}
Internal( InternalPtr obj = NULL ) : m_obj( obj ) {}
Internal( const Internal& copied ) : m_obj( copied.m_obj ) {}
~Internal(){}
......
......@@ -26,44 +26,34 @@
namespace VLC
{
Media* Media::fromPath(Instance& instance, const std::string& path)
Media Media::fromPath(Instance& instance, const std::string& path)
{
InternalPtr ptr = libvlc_media_new_path( instance, path.c_str() );
if ( ptr == NULL )
return NULL;
return new Media(ptr);
return Media(ptr);
}
Media*Media::fromLocation(Instance& instance, const std::string& location)
Media Media::fromLocation(Instance& instance, const std::string& location)
{
InternalPtr ptr = libvlc_media_new_location( instance, location.c_str() );
if ( ptr == NULL )
return NULL;
return new Media(ptr);
return Media(ptr);
}
Media*Media::fromFileDescriptor(Instance& instance, int fd)
Media Media::fromFileDescriptor(Instance& instance, int fd)
{
InternalPtr ptr = libvlc_media_new_fd( instance, fd );
if ( ptr == NULL )
return NULL;
return new Media( ptr );
return Media( ptr );
}
Media*Media::fromList(MediaList& list)
Media Media::fromList(MediaList& list)
{
InternalPtr ptr = libvlc_media_list_media( list );
if ( ptr == NULL )
return NULL;
return new Media( ptr );
return Media( ptr );
}
Media*Media::asNode(Instance& instance, const std::string& nodeName)
Media Media::asNode(Instance& instance, const std::string& nodeName)
{
InternalPtr ptr = libvlc_media_new_as_node( instance, nodeName.c_str() );
if ( ptr == NULL )
return NULL;
return new Media( ptr );
return Media( ptr );
}
Media::Media(const Media& another)
......
......@@ -46,7 +46,7 @@ public:
* \param path local filesystem path
* \return the newly created media or NULL on error
*/
static Media* fromPath(Instance& instance, const std::string& path);
static Media fromPath(Instance& instance, const std::string& path);
/**
* Create a media with a certain given media resource location,
......@@ -63,7 +63,7 @@ public:
* \param psz_mrl the media location
* \return the newly created media or NULL on error
*/
static Media* fromLocation(Instance& instance, const std::string& location);
static Media fromLocation(Instance& instance, const std::string& location);
/**
* Create a media for an already open file descriptor.
......@@ -85,7 +85,7 @@ public:
* \param fd open file descriptor
* \return the newly created media or NULL on error
*/
static Media* fromFileDescriptor(Instance& instance, int fd);
static Media fromFileDescriptor(Instance& instance, int fd);
/**
* Get media instance from this media list instance. This action will increase
......@@ -95,7 +95,7 @@ public:
* \param p_ml a media list instance
* \return media instance
*/
static Media* fromList(MediaList& list );
static Media fromList(MediaList& list );
/**
* Create a media as an empty node with a given name.
......@@ -104,7 +104,7 @@ public:
* \param psz_name the name of the node
* \return the new empty media or NULL on error
*/
static Media* asNode(Instance& instance, const std::string& nodeName);
static Media asNode(Instance& instance, const std::string& nodeName);
/**
* Copy libvlc_media_t from another to new Media object.
......
......@@ -44,6 +44,8 @@ public:
* \param p_inst libvlc instance
*
* \param psz_name service name
* \warning This is returned as a pointer, as this is not refcounter by VLC, and is
* fairly expensive to instantiate.
*/
static MediaDiscoverer* create(Instance & inst, const std::string& name);
......
......@@ -26,12 +26,10 @@
namespace VLC
{
MediaLibrary*MediaLibrary::create(Instance& instance)
MediaLibrary MediaLibrary::create(Instance& instance)
{
InternalPtr ptr = libvlc_media_library_new( instance );
if ( ptr == NULL )
return NULL;
return new MediaLibrary(ptr);
return MediaLibrary(ptr);
}
MediaLibrary::MediaLibrary(const MediaLibrary& another)
......
......@@ -38,7 +38,7 @@ public:
*
* \param p_instance the libvlc instance
*/
static MediaLibrary* create(Instance & p_instance);
static MediaLibrary create(Instance & p_instance);
/**
* Copy libvlc_media_library_t from another to new MediaLibrary object.
* \param another existing MediaLibrary
......
......@@ -62,36 +62,28 @@ MediaList::~MediaList()
release();
}
MediaList*MediaList::fromMedia(Media& md)
MediaList MediaList::fromMedia(Media& md)
{
InternalPtr ptr = libvlc_media_subitems( md );
if ( ptr == NULL )
return NULL;
return new MediaList( ptr );
return MediaList( ptr );
}
MediaList* MediaList::fromMediaDiscoverer( MediaDiscoverer& mdis )
MediaList MediaList::fromMediaDiscoverer( MediaDiscoverer& mdis )
{
InternalPtr ptr = libvlc_media_discoverer_media_list( mdis );
if ( ptr == NULL )
return NULL;
return new MediaList( ptr );
return MediaList( ptr );
}
MediaList*MediaList::fromMediaLibrary(MediaLibrary& mlib)
MediaList MediaList::fromMediaLibrary(MediaLibrary& mlib)
{
InternalPtr ptr = libvlc_media_library_media_list( mlib );
if ( ptr == NULL )
return NULL;
return new MediaList( ptr );
return MediaList( ptr );
}
MediaList*MediaList::create( Instance& instance )
MediaList MediaList::create( Instance& instance )
{
InternalPtr ptr = libvlc_media_list_new( instance );
if ( ptr == NULL )
return NULL;
return new MediaList( ptr );
return MediaList( ptr );
}
void MediaList::setMedia( Media &md )
......@@ -121,7 +113,8 @@ int MediaList::count()
Media MediaList::itemAtIndex(int i_pos)
{
return libvlc_media_list_item_at_index(m_obj, i_pos);
Media::InternalPtr ptr = libvlc_media_list_item_at_index(m_obj, i_pos);
return Media( ptr );
}
int MediaList::indexOfItem( Media &md )
......
......@@ -65,7 +65,7 @@ public:
*
* \param p_md media descriptor object
*/
static MediaList* fromMedia(Media &md);
static VLC::MediaList fromMedia(Media &md);
// libvlc_media_discoverer_media_list
/**
......@@ -73,7 +73,7 @@ public:
*
* \param p_mdis media service discover object
*/
static MediaList* fromMediaDiscoverer(MediaDiscoverer & mdis);
static VLC::MediaList fromMediaDiscoverer(MediaDiscoverer & mdis);
// libvlc_media_library_media_list
/**
......@@ -81,7 +81,7 @@ public:
*
* \param p_mlib media library object
*/
static MediaList* fromMediaLibrary( MediaLibrary &mlib );
static VLC::MediaList fromMediaLibrary( MediaLibrary &mlib );
// libvlc_media_list_new
/**
......@@ -89,7 +89,7 @@ public:
*
* \param p_instance libvlc instance
*/
static MediaList* create(Instance &instance);
static VLC::MediaList create(Instance &instance);
/**
* Associate media instance with this media list instance. If another
......
......@@ -59,12 +59,10 @@ MediaListPlayer::~MediaListPlayer()
release();
}
MediaListPlayer* MediaListPlayer::create(Instance& instance)
MediaListPlayer MediaListPlayer::create(Instance& instance)
{
InternalPtr ptr = libvlc_media_list_player_new( instance );
if ( ptr == NULL )
return NULL;
return new MediaListPlayer( ptr );
return MediaListPlayer( ptr );
}
EventManager& MediaListPlayer::eventManager()
......
......@@ -67,7 +67,7 @@ public:
*
* \param p_instance libvlc instance
*/
static MediaListPlayer* create(Instance & instance);
static MediaListPlayer create(Instance & instance);
/**
* Return the event manager of this media_list_player.
......
......@@ -61,20 +61,16 @@ MediaPlayer::~MediaPlayer()
release();
}
MediaPlayer*MediaPlayer::create( Instance& instance )
MediaPlayer MediaPlayer::create( Instance& instance )
{
InternalPtr ptr = libvlc_media_player_new( instance );
if ( ptr == NULL )
return NULL;
return new MediaPlayer( ptr );
return MediaPlayer( ptr );
}
MediaPlayer*MediaPlayer::fromMedia( Media& md )
MediaPlayer MediaPlayer::fromMedia( Media& md )
{
InternalPtr ptr = libvlc_media_player_new_from_media( md );
if ( ptr == NULL )
return NULL;
return new MediaPlayer( ptr );
return MediaPlayer( ptr );
}
void MediaPlayer::setMedia( Media& md )
......@@ -82,10 +78,10 @@ void MediaPlayer::setMedia( Media& md )
libvlc_media_player_set_media( m_obj, md );
}
Media* MediaPlayer::media()
Media MediaPlayer::media()
{
libvlc_media_t* media = libvlc_media_player_get_media(m_obj);
return new Media(media);
return Media(media);
}
EventManager& MediaPlayer::eventManager()
......@@ -672,7 +668,8 @@ std::vector<TrackDescription> MediaPlayer::getTracksDescription(libvlc_track_des
}
void MediaPlayer::release() {
void MediaPlayer::release()
{
libvlc_media_player_release(m_obj);
}
......
......@@ -71,7 +71,7 @@ public:
* \param p_libvlc_instance the libvlc instance in which the Media
* Player should be created.
*/
static MediaPlayer* create( Instance& instance );
static VLC::MediaPlayer create( Instance& instance );
// libvlc_media_player_new_from_media
/**
......@@ -79,7 +79,7 @@ public:
*
* \param p_md the media. Afterwards the p_md can be safely destroyed.
*/
static MediaPlayer* fromMedia( Media &md );
static VLC::MediaPlayer fromMedia( Media &md );
/**
* Set the media that will be used by the media_player. If any, previous
......@@ -95,7 +95,7 @@ public:
* \return the media associated with p_mi, or NULL if no media is
* associated
*/
Media* media();
VLC::Media media();
/**
* Get the Event Manager from which the media player send event.
......
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