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

Rework Media construction

parent 1f4781ba
......@@ -4,6 +4,7 @@
* Copyright © 2014 the VideoLAN team
*
* Authors: Alexey Sokolov <alexey@alexeysokolov.co.cc>
* Hugo Beauzée-Luyssen <hugo@beauzee.fr>
*
* 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
......@@ -27,7 +28,47 @@
namespace VLC {
Media::Media(const Media& another)
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);
}
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);
}
Media*Media::fromFileDescriptor(Instance& instance, int fd)
{
InternalPtr ptr = libvlc_media_new_fd( instance, fd );
if ( ptr == NULL )
return NULL;
return new Media( ptr );
}
Media*Media::fromList(MediaList& list)
{
InternalPtr ptr = libvlc_media_list_media( list );
if ( ptr == NULL )
return NULL;
return new Media( ptr );
}
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 );
}
Media::Media(const Media& another)
{
m_obj = another.m_obj;
retain();
......@@ -55,53 +96,6 @@ Media::~Media()
release();
}
Media::Media(Instance& inst, const std::string& s, ConstructorType t) {
m_obj = NULL;
switch (t) {
case Location:
m_obj = libvlc_media_new_location(inst.get_c_object(), s.c_str());
break;
case Path:
m_obj = libvlc_media_new_path(inst.get_c_object(), s.c_str());
break;
case Node:
m_obj = libvlc_media_new_as_node(inst.get_c_object(), s.c_str());
break;
}
if (!m_obj) {
throw Exception();
}
}
Media::Media(Instance & p_instance, const std::string& psz_mrl)
{
m_obj = libvlc_media_new_location(p_instance.get_c_object(), psz_mrl.c_str());
if (!m_obj)
{
throw Exception("Can't construct Media");
}
}
Media::Media(Instance & p_instance, int fd)
{
m_obj = libvlc_media_new_fd(p_instance.get_c_object(), fd);
if (!m_obj)
{
throw Exception("Can't construct Media");
}
}
Media::Media(MediaList & p_ml)
{
m_obj = libvlc_media_list_media(p_ml.get_c_object());
if (!m_obj)
{
throw Exception("Can't construct Media");
}
}
std::vector<MediaTrackInfo> Media::tracksInfo() {
libvlc_media_track_info_t* infos;
int num = libvlc_media_get_tracks_info(m_obj, &infos);
......@@ -224,6 +218,11 @@ unsigned Media::tracks(libvlc_media_track_t *** tracks)
return result;
}
Media::Media(Internal::InternalPtr ptr)
: Internal(ptr)
{
}
void Media::retain()
{
libvlc_media_retain(m_obj);
......
......@@ -4,6 +4,7 @@
* Copyright © 2014 the VideoLAN team
*
* Authors: Alexey Sokolov <alexey@alexeysokolov.co.cc>
* Hugo Beauzée-Luyssen <hugo@beauzee.fr>
*
* 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
......@@ -38,101 +39,93 @@ class Media : public Internal<libvlc_media_t>
{
public:
/**
* 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
*/
const Media& operator=(const Media& another);
/**
* Check if 2 Media objects contain the same libvlc_media_t.
* \param another another Media
* \return true if they contain the same libvlc_media_t
*/
bool operator==(const Media& another) const;
~Media();
enum ConstructorType {
Location,
Path,
Node,
};
// overriden_media_new
/**
* Create a media from a location (URI), a path or as an empty node with
* a given name.
* Create a media for a certain file path.
*
* \param p_inst libvlc instance
*
* \param src wanted location, path, or name
*
* \param t how to create the media - from location, from path or as
* node
* \param instance the instance
* \param path local filesystem path
* \return the newly created media or NULL on error
*/
Media(Instance & p_inst, const std::string& src, ConstructorType t);
static Media* fromPath(Instance& instance, const std::string& path);
// libvlc_media_new_location
/**
* 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 . URI syntax be
* used (see IETF RFC3986). We recommend using libvlc_media_new_path()
* instead when dealing with local files.
* Create a media with a certain given media resource location,
* for instance a valid URL.
*
* \see Media::release()
* \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.
*
* \param p_instance the instance
* \see libvlc_media_release
*
* \param psz_mrl the media location
* \param instance the instance
* \param psz_mrl the media location
* \return the newly created media or NULL on error
*/
Media(Instance & p_instance, const std::string& psz_mrl);
static Media* fromLocation(Instance& instance, const std::string& location);
// libvlc_media_new_fd
/**
* Create a media for an already open file descriptor. The file
* descriptor shall be open for reading (or reading and writing).
* Create a media for an already open file descriptor.
* The file descriptor shall be open for reading (or reading and writing).
*
* Regular file descriptors, pipe read descriptors and character device
* descriptors (including TTYs) are supported on all platforms. Block
* device descriptors are supported where available. Directory
* descriptors are supported on systems that provide fdopendir(). Sockets
* are supported on all platforms where they are file descriptors, i.e.
* all except Windows.
*
* \note This library will automatically close the file descriptor under
* any circumstance. Nevertheless, a file descriptor can usually only be
* descriptors (including TTYs) are supported on all platforms.
* Block device descriptors are supported where available.
* Directory descriptors are supported on systems that provide fdopendir().
* Sockets are supported on all platforms where they are file descriptors,
* i.e. all except Windows.
*
* \note This library will <b>not</b> automatically close the file descriptor
* under any circumstance. Nevertheless, a file descriptor can usually only be
* rendered once in a media player. To render it a second time, the file
* descriptor should probably be rewound to the beginning with lseek().
*
* \see Media::release()
*
* \version LibVLC 1.1.5 and later.
*
* \param p_instance the instance
* \param p_instance the instance
* \param fd open file descriptor
* \return the newly created media or NULL on error
*/
static Media* fromFileDescriptor(Instance& instance, int fd);
/**
* Get media instance from this media list instance. This action will increase
* the refcount on the media instance.
* The libvlc_media_list_lock should NOT be held upon entering this function.
*
* \param fd open file descriptor
* \param p_ml a media list instance
* \return media instance
*/
Media(Instance & p_instance, int fd);
static Media* fromList(MediaList& list );
// libvlc_media_list_media
/**
* Get media instance from this media list instance. This action will
* increase the refcount on the media instance. The
* libvlc_media_list_lock should NOT be held upon entering this function.
* Create a media as an empty node with a given name.
*
* \param p_ml a media list instance
* \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);
/**
* Copy libvlc_media_t from another to new Media object.
* \param another existing Media
*/
Media(MediaList & p_ml);
Media(const Media& another);
/**
* Copy libvlc_media_t from another Media
* to this Media
* \param another existing Media
*/
const Media& operator=(const Media& another);
/**
* Check if 2 Media objects contain the same libvlc_media_t.
* \param another another Media
* \return true if they contain the same libvlc_media_t
*/
bool operator==(const Media& another) const;
~Media();
/**
* Foo bar
......@@ -344,6 +337,7 @@ public:
unsigned tracks(libvlc_media_track_t *** tracks);
private:
Media(InternalPtr ptr);
/**
* Retain a reference to a media descriptor object (libvlc_media_t). Use
* Media::release() to decrement the reference count of a media
......
......@@ -34,19 +34,18 @@ template < typename T >
class Internal
{
public:
typedef T* internalPtr;
T* getInternalPtr()
typedef T* InternalPtr;
InternalPtr getInternalPtr()
{
assert( m_obj != NULL );
return m_obj;
}
operator T*() { return m_obj; }
protected:
Internal() : m_obj( NULL ) {}
Internal(T* obj) : m_obj( obj ) {}
Internal(InternalPtr obj = NULL ) : m_obj( obj ) {}
~Internal(){}
T* m_obj;
InternalPtr m_obj;
};
}
......
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