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

Revert to using constructors & exceptions to signal errors

parent f845e7e0
......@@ -26,9 +26,9 @@
namespace VLC
{
Instance::Instance()
: Internal( NULL )
Instance::Instance(int argc, const char* const* argv)
{
m_obj = libvlc_new( argc, argv );
}
Instance::Instance( const Instance& another )
......@@ -59,12 +59,6 @@ Instance::~Instance()
release();
}
Instance Instance::create( int argc, const char *const * argv )
{
InternalPtr ptr = libvlc_new( argc, argv );
return Instance( ptr, false );
}
int Instance::addIntf( const std::string& name )
{
return libvlc_add_intf( m_obj, name.c_str() );
......@@ -160,13 +154,6 @@ std::vector<AudioOutputDeviceDescription> Instance::audioOutputDeviceList(const
return res;
}
Instance::Instance( Internal::InternalPtr ptr, bool increaseRefCount )
: Internal( ptr )
{
if ( increaseRefCount )
retain();
}
void Instance::release()
{
if ( isValid() )
......
......@@ -36,29 +36,6 @@ 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
*/
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
* \return true if they contain the same libvlc_instance_t
*/
bool operator==(const Instance& another) const;
~Instance();
/**
* Create and initialize a libvlc instance. This functions accept a list
* of "command line" arguments similar to the main(). These arguments
......@@ -81,7 +58,29 @@ public:
*
* \param argv list of arguments (should be NULL)
*/
static Instance create(int argc, const char *const * argv);
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
* \return true if they contain the same libvlc_instance_t
*/
bool operator==(const Instance& another) const;
~Instance();
/**
* Try to start a user interface for the libvlc instance.
......
......@@ -22,44 +22,45 @@
*****************************************************************************/
#include "vlc.hpp"
#include <stdexcept>
namespace VLC
{
Media::Media()
Media::Media(Instance &instance, const std::string &mrl, Media::FromType type)
: Internal( NULL )
, m_eventManager( NULL )
{
}
Media Media::fromPath(Instance& instance, const std::string& path)
{
InternalPtr ptr = libvlc_media_new_path( instance, path.c_str() );
return Media( ptr, false );
}
Media Media::fromLocation(Instance& instance, const std::string& location)
{
InternalPtr ptr = libvlc_media_new_location( instance, location.c_str() );
return Media( ptr, false );
switch (type)
{
case FromLocation:
m_obj = libvlc_media_new_location( instance, mrl.c_str() );
break;
case FromPath:
m_obj = libvlc_media_new_path( instance, mrl.c_str() );
break;
case AsNode:
m_obj = libvlc_media_new_as_node( instance, mrl.c_str() );
break;
default:
break;
}
if ( m_obj == NULL )
throw std::runtime_error("Failed to construct a media");
}
Media Media::fromFileDescriptor(Instance& instance, int fd)
{
InternalPtr ptr = libvlc_media_new_fd( instance, fd );
return Media( ptr, false );
}
Media Media::fromList(MediaList& list)
Media::Media(Instance& instance, int fd)
{
InternalPtr ptr = libvlc_media_list_media( list );
return Media( ptr, false );
m_obj = libvlc_media_new_fd( instance, fd );
if ( m_obj == NULL )
throw std::runtime_error("Failed to construct a media");
}
Media Media::asNode(Instance& instance, const std::string& nodeName)
Media::Media(MediaList& list)
{
InternalPtr ptr = libvlc_media_new_as_node( instance, nodeName.c_str() );
return Media( ptr, false );
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)
......
......@@ -39,32 +39,36 @@ class EventManager;
class VLCPP_API Media : public Internal<libvlc_media_t>
{
public:
Media();
/**
* Create a media for a certain file path.
*
* \param instance the instance
* \param path local filesystem path
* \return the newly created media or NULL on error
*/
static Media fromPath(Instance& instance, const std::string& path);
enum FromType
{
/**
* Create a media for a certain file path.
*/
FromPath,
/**
* Create a media with a certain given media resource location,
* for instance a valid URL.
*
* \note To refer to a local file with this function,
* the file://... URI syntax <b>must</b> be used (see IETF RFC3986).
* We recommend using FromPath instead when dealing with
* local files.
*/
FromLocation,
/**
* Create a media as an empty node with a given name.
*/
AsNode,
};
/**
* Create a media with a certain given media resource location,
* for instance a valid URL.
*
* \note To refer to a local file with this function,
* the file://... URI syntax <b>must</b> be used (see IETF RFC3986).
* We recommend using libvlc_media_new_path() instead when dealing with
* local files.
*
* \see libvlc_media_release
*
* \param instance the instance
* \param psz_mrl the media location
* \return the newly created media or NULL on error
* @brief Media Constructs a libvlc Media instance
* @param instance A libvlc instance
* @param mrl A path, location, or node name, depending on the 3rd parameter
* @param type The type of the 2nd argument. \sa{FromType}
*/
static Media fromLocation(Instance& instance, const std::string& location);
Media(Instance& instance, const std::string& mrl, FromType type);
/**
* Create a media for an already open file descriptor.
......@@ -86,7 +90,7 @@ public:
* \param fd open file descriptor
* \return the newly created media or NULL on error
*/
static Media fromFileDescriptor(Instance& instance, int fd);
Media(Instance& instance, int fd);
/**
* Get media instance from this media list instance. This action will increase
......@@ -96,16 +100,7 @@ public:
* \param p_ml a media list instance
* \return media instance
*/
static Media fromList(MediaList& list );
/**
* Create a media as an empty node with a given name.
*
* \param p_instance the instance
* \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);
Media(MediaList& list );
/**
* Copy libvlc_media_t from another to new Media object.
......
......@@ -24,6 +24,7 @@
#include "vlc.hpp"
#include "EventManager.hpp"
#include <stdexcept>
namespace VLC
{
......@@ -34,12 +35,11 @@ MediaDiscoverer::~MediaDiscoverer()
release();
}
MediaDiscoverer* MediaDiscoverer::create( Instance &inst, const std::string& name )
MediaDiscoverer::MediaDiscoverer( Instance &inst, const std::string& name )
{
InternalPtr ptr = libvlc_media_discoverer_new_from_name(inst, name.c_str());
if ( ptr == NULL )
return NULL;
return new MediaDiscoverer( ptr );
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()
......
......@@ -26,6 +26,7 @@
#include "common.hpp"
#include "Internal.hpp"
#include <string>
namespace VLC
{
......@@ -47,7 +48,7 @@ public:
* \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);
MediaDiscoverer(Instance & inst, const std::string& name);
/**
* Get media service discover object its localized name.
......
......@@ -23,13 +23,16 @@
#include "vlc.hpp"
#include <stdexcept>
namespace VLC
{
MediaLibrary MediaLibrary::create(Instance& instance)
MediaLibrary::MediaLibrary(Instance& instance)
{
InternalPtr ptr = libvlc_media_library_new( instance );
return MediaLibrary(ptr);
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)
......
......@@ -38,7 +38,7 @@ public:
*
* \param p_instance the libvlc instance
*/
static MediaLibrary create(Instance & p_instance);
MediaLibrary(Instance & p_instance);
/**
* Copy libvlc_media_library_t from another to new MediaLibrary object.
* \param another existing MediaLibrary
......
......@@ -25,6 +25,8 @@
#include "EventManager.hpp"
#include <stdexcept>
namespace VLC
{
......@@ -65,28 +67,36 @@ MediaList::~MediaList()
release();
}
MediaList MediaList::fromMedia(Media& md)
MediaList::MediaList(Media& md)
: m_eventManager( NULL )
{
InternalPtr ptr = libvlc_media_subitems( md );
return MediaList( ptr );
m_obj = libvlc_media_subitems( md );
if ( m_obj == NULL )
throw std::runtime_error("Failed to construct a media list");
}
MediaList MediaList::fromMediaDiscoverer( MediaDiscoverer& mdis )
MediaList::MediaList( MediaDiscoverer& mdis )
: m_eventManager( NULL )
{
InternalPtr ptr = libvlc_media_discoverer_media_list( mdis );
return MediaList( ptr );
m_obj = libvlc_media_discoverer_media_list( mdis );
if ( m_obj == NULL )
throw std::runtime_error("Failed to construct a media list");
}
MediaList MediaList::fromMediaLibrary(MediaLibrary& mlib)
MediaList::MediaList(MediaLibrary& mlib)
: m_eventManager( NULL )
{
InternalPtr ptr = libvlc_media_library_media_list( mlib );
return MediaList( ptr );
if ( m_obj == NULL )
throw std::runtime_error("Failed to construct a media list");
}
MediaList MediaList::create( Instance& instance )
MediaList::MediaList( Instance& instance )
: m_eventManager( NULL )
{
InternalPtr ptr = libvlc_media_list_new( instance );
return MediaList( ptr );
m_obj = libvlc_media_list_new( instance );
if ( m_obj == NULL )
throw std::runtime_error("Failed to construct a media list");
}
void MediaList::setMedia( Media &md )
......@@ -150,12 +160,6 @@ EventManager& MediaList::eventManager()
return *m_eventManager;
}
MediaList::MediaList( Internal::InternalPtr ptr )
: Internal( ptr )
, m_eventManager( NULL )
{
}
void MediaList::release()
{
libvlc_media_list_release(m_obj);
......
......@@ -65,7 +65,7 @@ public:
*
* \param p_md media descriptor object
*/
static VLC::MediaList fromMedia(Media &md);
MediaList(Media &md);
// libvlc_media_discoverer_media_list
/**
......@@ -73,7 +73,7 @@ public:
*
* \param p_mdis media service discover object
*/
static VLC::MediaList fromMediaDiscoverer(MediaDiscoverer & mdis);
MediaList(MediaDiscoverer & mdis);
// libvlc_media_library_media_list
/**
......@@ -81,7 +81,7 @@ public:
*
* \param p_mlib media library object
*/
static VLC::MediaList fromMediaLibrary( MediaLibrary &mlib );
MediaList( MediaLibrary &mlib );
// libvlc_media_list_new
/**
......@@ -89,7 +89,7 @@ public:
*
* \param p_instance libvlc instance
*/
static VLC::MediaList create(Instance &instance);
MediaList(Instance &instance);
/**
* Associate media instance with this media list instance. If another
......
......@@ -23,6 +23,8 @@
#include "vlc.hpp"
#include <stdexcept>
namespace VLC
{
......@@ -62,10 +64,12 @@ MediaListPlayer::~MediaListPlayer()
release();
}
MediaListPlayer MediaListPlayer::create( Instance& instance )
MediaListPlayer::MediaListPlayer( Instance& instance )
: m_eventManager( NULL )
{
InternalPtr ptr = libvlc_media_list_player_new( instance );
return MediaListPlayer( ptr );
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()
......
......@@ -67,7 +67,7 @@ public:
*
* \param p_instance libvlc instance
*/
static MediaListPlayer create(Instance & instance);
MediaListPlayer(Instance & instance);
/**
* Return the event manager of this media_list_player.
......
......@@ -24,6 +24,7 @@
#include "vlc.hpp"
#include "EventManager.hpp"
#include <stdexcept>
namespace VLC
{
......@@ -71,16 +72,20 @@ MediaPlayer::~MediaPlayer()
release();
}
MediaPlayer MediaPlayer::create( Instance& instance )
MediaPlayer::MediaPlayer( Instance& instance )
: m_eventManager( NULL )
{
InternalPtr ptr = libvlc_media_player_new( instance );
return MediaPlayer( ptr, false );
m_obj = libvlc_media_player_new( instance );
if ( m_obj == NULL )
throw std::runtime_error("Failed to construct a media player");
}
MediaPlayer MediaPlayer::fromMedia( Media& md )
MediaPlayer::MediaPlayer( Media& md )
: m_eventManager( NULL )
{
InternalPtr ptr = libvlc_media_player_new_from_media( md );
return MediaPlayer( ptr, false );
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 )
......
......@@ -72,7 +72,7 @@ public:
* \param p_libvlc_instance the libvlc instance in which the Media
* Player should be created.
*/
static VLC::MediaPlayer create( Instance& instance );
MediaPlayer( Instance& instance );
// libvlc_media_player_new_from_media
/**
......@@ -80,7 +80,7 @@ public:
*
* \param p_md the media. Afterwards the p_md can be safely destroyed.
*/
static VLC::MediaPlayer fromMedia( Media &md );
MediaPlayer( Media &md );
/**
* Set the media that will be used by the media_player. If any, previous
......
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