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

Make libvlcpp header only

parent 6de088e2
project(vlcpp)
project(vlcpptest)
cmake_minimum_required(VERSION 2.8)
set(LIBVLCPP_MAJOR_VERSION 2)
set(LIBVLCPP_MINOR_VERSION 2)
......@@ -19,20 +19,14 @@ include(cpp11)
add_definitions("-Wall -Wextra -pedantic")
EnableCpp11()
add_library (${PROJECT_NAME} SHARED
src/Media.cpp
src/EventManager.cpp
src/MediaLibrary.cpp
src/MediaListPlayer.cpp
src/Instance.cpp
src/MediaDiscoverer.cpp
src/MediaList.cpp
src/MediaPlayer.cpp
src/structures.cpp
add_executable(${PROJECT_NAME}
test/main.cpp
)
include_directories("${CMAKE_SOURCE_DIR}/src/")
file(GLOB LIBVLCPP_PUBLIC_HEADERS "${CMAKE_SOURCE_DIR}/src/*.hpp")
set_target_properties(vlcpp PROPERTIES
set_target_properties(${PROJECT_NAME} PROPERTIES
PUBLIC_HEADER "${LIBVLCPP_PUBLIC_HEADERS}"
)
......@@ -42,19 +36,5 @@ include_directories(${LIBVLC_INCLUDE_DIR})
file(RELATIVE_PATH REL_INCLUDE_DIR "${INSTALL_CMAKE_DIR}" "${INSTALL_INCLUDE_DIR}")
set(CONF_INCLUDE_DIRS "\${LIBVLCPP_CMAKE_DIR}/${REL_INCLUDE_DIR}")
configure_file(${CMAKE_SOURCE_DIR}/cmake/vlcppConfig.cmake.in "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/vlcppConfig.cmake" @ONLY)
configure_file(${CMAKE_SOURCE_DIR}/cmake/vlcppConfigVersion.cmake.in "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/vlcppConfigVersion.cmake" @ONLY)
install(
FILES "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/vlcppConfig.cmake" "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/vlcppConfigVersion.cmake"
DESTINATION lib/${PROJECT_NAME}
COMPONENT dev
)
install(TARGETS vlcpp
LIBRARY DESTINATION lib/${PROJECT_NAME}
ARCHIVE DESTINATION lib/${PROJECT_NAME}
PUBLIC_HEADER DESTINATION include/${PROJECT_NAME}
COMPONENT dev
)
This diff is collapsed.
This diff is collapsed.
/*****************************************************************************
* libvlc_Instance.cpp: Instance implementation
*****************************************************************************
* 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
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include "vlc.hpp"
namespace VLC
{
Instance::Instance(int argc, const char* const* argv)
: Internal{ libvlc_new( argc, argv ), libvlc_release }
{
}
bool Instance::operator==( const Instance& another ) const
{
return m_obj == another.m_obj;
}
int Instance::addIntf( const std::string& name )
{
return libvlc_add_intf( get(), name.c_str() );
}
void Instance::setExitHandler( void(*cb)(void *), void * opaque )
{
libvlc_set_exit_handler( get(), cb, opaque );
}
void Instance::setUserAgent( const std::string& name, const std::string& http )
{
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( get(), id.c_str(), version.c_str(), icon.c_str() );
}
void Instance::logUnset()
{
libvlc_log_unset( get() );
}
void Instance::logSet( libvlc_log_cb cb, void * data )
{
libvlc_log_set(get(), cb, data);
}
void Instance::logSetFile( FILE * stream )
{
libvlc_log_set_file( get(), stream );
}
std::vector<ModuleDescription> Instance::audioFilterList()
{
libvlc_module_description_t* result = libvlc_audio_filter_list_get(get());
std::vector<ModuleDescription> res;
if ( result == NULL )
return res;
libvlc_module_description_t* p = result;
while ( p != NULL )
{
res.push_back( ModuleDescription( p ) );
p = p->p_next;
}
libvlc_module_description_list_release( result );
return res;
}
std::vector<ModuleDescription> Instance::videoFilterList()
{
libvlc_module_description_t* result = libvlc_video_filter_list_get(get());
std::vector<ModuleDescription> res;
if ( result == NULL )
return res;
libvlc_module_description_t* p = result;
while ( p != NULL )
{
res.push_back( ModuleDescription( p ) );
p = p->p_next;
}
libvlc_module_description_list_release( result );
return res;
}
std::vector<AudioOutputDescription> Instance::audioOutputList()
{
libvlc_audio_output_t* result = libvlc_audio_output_list_get(get());
std::vector<AudioOutputDescription> res;
if ( result == NULL )
return res;
libvlc_audio_output_t* p = result;
while ( p != NULL )
{
res.push_back( AudioOutputDescription( p ) );
p = p->p_next;
}
libvlc_audio_output_list_release(result);
return res;
}
std::vector<AudioOutputDeviceDescription> Instance::audioOutputDeviceList(const std::string& aout)
{
libvlc_audio_output_device_t* devices = libvlc_audio_output_device_list_get( get(), aout.c_str() );
std::vector<AudioOutputDeviceDescription> res;
if ( devices == NULL )
return res;
for ( libvlc_audio_output_device_t* p = devices; p != NULL; p = p->p_next )
res.push_back( AudioOutputDeviceDescription( p ) );
libvlc_audio_output_device_list_release( devices );
return res;
}
} // namespace VLC
......@@ -24,12 +24,13 @@
#ifndef LIBVLC_CXX_INSTANCE_H
#define LIBVLC_CXX_INSTANCE_H
#include <string>
#include <vector>
#include "common.hpp"
#include "Internal.hpp"
#include "structures.hpp"
#include <string>
#include <vector>
namespace VLC
{
......@@ -58,14 +59,21 @@ public:
*
* \param argv list of arguments (should be NULL)
*/
Instance(int argc, const char *const * argv);
Instance(int argc, const char *const * argv)
: Internal{ libvlc_new( argc, argv ), libvlc_release }
{
}
/**
* 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;
bool operator==(const Instance& another) const
{
return m_obj == another.m_obj;
}
/**
* Try to start a user interface for the libvlc instance.
......@@ -74,7 +82,10 @@ public:
*
* \return 0 on success, -1 on error.
*/
int addIntf(const std::string& name);
int addIntf(const std::string& name)
{
return libvlc_add_intf( get(), name.c_str() );
}
/**
* Registers a callback for the LibVLC exit event. This is mostly useful
......@@ -95,7 +106,10 @@ public:
* \warning This function and Instance::wait() cannot be used at the same
* time.
*/
void setExitHandler(void(*cb)(void *), void * opaque);
void setExitHandler(void(*cb)(void *), void * opaque)
{
libvlc_set_exit_handler( get(), cb, opaque );
}
/**
* Sets the application name. LibVLC passes this as the user agent string
......@@ -108,7 +122,10 @@ public:
*
* \version LibVLC 1.1.1 or later
*/
void setUserAgent(const std::string& name, const std::string& http);
void setUserAgent(const std::string& name, const std::string& http)
{
libvlc_set_user_agent( get(), name.c_str(), http.c_str() );
}
/**
* Sets some meta-information about the application. See also
......@@ -122,7 +139,10 @@ public:
*
* \version LibVLC 2.1.0 or later.
*/
void setAppId(const std::string& id, const std::string& version, const std::string& icon);
void setAppId(const std::string& id, const std::string& version, const std::string& icon)
{
libvlc_set_app_id( get(), id.c_str(), version.c_str(), icon.c_str() );
}
/**
* Unsets the logging callback for a LibVLC instance. This is rarely
......@@ -133,7 +153,10 @@ public:
*
* \version LibVLC 2.1.0 or later
*/
void logUnset();
void logUnset()
{
libvlc_log_unset( get() );
}
/**
* Sets the logging callback for a LibVLC instance. This function is
......@@ -153,7 +176,10 @@ public:
*
* \version LibVLC 2.1.0 or later
*/
void logSet(libvlc_log_cb cb, void * data);
void logSet(libvlc_log_cb cb, void * data)
{
libvlc_log_set(get(), cb, data);
}
/**
* Sets up logging to a file.
......@@ -163,7 +189,10 @@ public:
*
* \version LibVLC 2.1.0 or later
*/
void logSetFile(FILE * stream);
void logSetFile(FILE * stream)
{
libvlc_log_set_file( get(), stream );
}
/**
* Returns a list of audio filters that are available.
......@@ -176,7 +205,22 @@ public:
*
* \see ModuleDescription::moduleDescriptionListRelease()
*/
std::vector<ModuleDescription> audioFilterList();
std::vector<ModuleDescription> audioFilterList()
{
libvlc_module_description_t* result = libvlc_audio_filter_list_get(get());
std::vector<ModuleDescription> res;
if ( result == NULL )
return res;
libvlc_module_description_t* p = result;
while ( p != NULL )
{
res.push_back( ModuleDescription( p ) );
p = p->p_next;
}
libvlc_module_description_list_release( result );
return res;
}
/**
* Returns a list of video filters that are available.
......@@ -189,7 +233,21 @@ public:
*
* \see ModuleDescription::moduleDescriptionListRelease()
*/
std::vector<ModuleDescription> videoFilterList();
std::vector<ModuleDescription> videoFilterList()
{
libvlc_module_description_t* result = libvlc_video_filter_list_get(get());
std::vector<ModuleDescription> res;
if ( result == NULL )
return res;
libvlc_module_description_t* p = result;
while ( p != NULL )
{
res.push_back( ModuleDescription( p ) );
p = p->p_next;
}
libvlc_module_description_list_release( result );
return res;
}
/**
* Gets the list of available audio output modules.
......@@ -200,7 +258,21 @@ public:
*
* \see AudioOutputDescription . In case of error, NULL is returned.
*/
std::vector<AudioOutputDescription> audioOutputList();
std::vector<AudioOutputDescription> audioOutputList()
{
libvlc_audio_output_t* result = libvlc_audio_output_list_get(get());
std::vector<AudioOutputDescription> res;
if ( result == NULL )
return res;
libvlc_audio_output_t* p = result;
while ( p != NULL )
{
res.push_back( AudioOutputDescription( p ) );
p = p->p_next;
}
libvlc_audio_output_list_release(result);
return res;
}
/**
* Gets a list of audio output devices for a given audio output module,
......@@ -224,7 +296,18 @@ public:
*
* \version LibVLC 2.1.0 or later.
*/
std::vector<AudioOutputDeviceDescription> audioOutputDeviceList(const std::string& aout);
std::vector<AudioOutputDeviceDescription> audioOutputDeviceList(const std::string& aout)
{
libvlc_audio_output_device_t* devices = libvlc_audio_output_device_list_get( get(), aout.c_str() );
std::vector<AudioOutputDeviceDescription> res;
if ( devices == NULL )
return res;
for ( libvlc_audio_output_device_t* p = devices; p != NULL; p = p->p_next )
res.push_back( AudioOutputDeviceDescription( p ) );
libvlc_audio_output_device_list_release( devices );
return res;
}
};
} // namespace VLC
......
/*****************************************************************************
* libvlc_Media.cpp: Media implementation
*****************************************************************************
* 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
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include "vlc.hpp"
#include <stdexcept>
namespace VLC
{
Media::Media(InstancePtr instance, const std::string &mrl, Media::FromType type)
: Internal{ libvlc_media_release }
{
InternalPtr ptr = nullptr;
switch (type)
{
case FromLocation:
ptr = libvlc_media_new_location( instance->get(), mrl.c_str() );
break;
case FromPath:
ptr = libvlc_media_new_path( instance->get(), mrl.c_str() );
break;
case AsNode:
ptr = libvlc_media_new_as_node( instance->get(), mrl.c_str() );
break;
default:
break;
}
if ( ptr == nullptr )
throw std::runtime_error("Failed to construct a media");
m_obj.reset( ptr );
}
Media::Media(InstancePtr instance, int fd)
: Internal { libvlc_media_new_fd( instance->get(), fd ), libvlc_media_release }
{
}
Media::Media(MediaListPtr list)
: Internal{ libvlc_media_list_media( list->get() ), libvlc_media_release }
{
}
bool Media::operator==(const Media& another) const
{
return m_obj == another.m_obj;
}
void Media::addOption(const std::string& psz_options)
{
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(get(), psz_options.c_str(), i_flags);
}
std::string Media::mrl()
{
char* c_result = libvlc_media_get_mrl(get());
if ( c_result == NULL )
return std::string();
std::string result = c_result;
libvlc_free(c_result);
return result;
}
Media Media::duplicate()
{
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(get(), e_meta);
if ( c_result == NULL )
return std::string();
std::string result = c_result;
libvlc_free(c_result);
return result;
}
void Media::setMeta(libvlc_meta_t e_meta, const std::string& psz_value)
{
libvlc_media_set_meta(get(), e_meta, psz_value.c_str());
}
int Media::saveMeta()
{
return libvlc_media_save_meta(get());
}
libvlc_state_t Media::state()
{
return libvlc_media_get_state(get());
}
bool Media::stats(libvlc_media_stats_t * p_stats)
{
return libvlc_media_get_stats(get(), p_stats) != 0;
}
EventManagerPtr Media::eventManager()
{
if ( m_eventManager == NULL )
{
libvlc_event_manager_t* obj = libvlc_media_event_manager(get());
m_eventManager = std::make_shared<EventManager>( obj );
}
return m_eventManager;
}
libvlc_time_t Media::duration()
{
return libvlc_media_get_duration(get());
}
void Media::parse()
{
libvlc_media_parse(get());
}
void Media::parseAsync()
{
libvlc_media_parse_async(get());
}
bool Media::isParsed()
{
return libvlc_media_is_parsed(get()) != 0;
}
void Media::setUserData(void * p_new_user_data)
{
libvlc_media_set_user_data(get(), p_new_user_data);
}
void * Media::userData()
{
return libvlc_media_get_user_data(get());
}
std::vector<MediaTrack> Media::tracks()
{
libvlc_media_track_t** tracks;
uint32_t nbTracks = libvlc_media_tracks_get(get(), &tracks);
std::vector<MediaTrack> res;
if ( nbTracks == 0 )
return res;
for ( uint32_t i = 0; i < nbTracks; ++i )
res.push_back( MediaTrack(tracks[i]));
libvlc_media_tracks_release( tracks, nbTracks );
return res;
}
Media::Media(Internal::InternalPtr ptr, bool incrementRefCount)
: Internal{ ptr, libvlc_media_release }
{
if (incrementRefCount)
retain();
}
void Media::retain()
{
if ( isValid() )
libvlc_media_retain(get());
}
} // namespace VLC
This diff is collapsed.
/*****************************************************************************
* libvlc_MediaDiscoverer.cpp: MediaDiscoverer implementation
*****************************************************************************
* 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
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include "vlc.hpp"
#include "EventManager.hpp"
#include <stdexcept>
#include <memory>
namespace VLC
{
MediaDiscoverer::MediaDiscoverer(InstancePtr inst, const std::string& name )
: Internal{ libvlc_media_discoverer_new_from_name(inst->get(), name.c_str()),
libvlc_media_discoverer_release }
{
}
std::string MediaDiscoverer::localizedName()
{
char* c_result = libvlc_media_discoverer_localized_name(get());
if ( c_result == NULL )
return std::string();
std::string result = c_result;
libvlc_free(c_result);
return result;
}
EventManagerPtr MediaDiscoverer::eventManager()
{
if ( m_eventManager )
{
libvlc_event_manager_t* obj = libvlc_media_discoverer_event_manager( get() );
m_eventManager = std::make_shared<EventManager>( obj );
}
return m_eventManager;
}
bool MediaDiscoverer::isRunning()
{
return libvlc_media_discoverer_is_running(get());
}
} // namespace VLC
......@@ -24,7 +24,8 @@
#ifndef LIBVLC_CXX_MEDIADISCOVERER_H
#define LIBVLC_CXX_MEDIADISCOVERER_H
#include "vlc.hpp"
#include "common.hpp"
#include <string>
namespace VLC
......@@ -45,28 +46,51 @@ public:
* \warning This is returned as a pointer, as this is not refcounter by VLC, and is
* fairly expensive to instantiate.
*/
MediaDiscoverer(InstancePtr inst, const std::string& name);
MediaDiscoverer(InstancePtr inst, const std::string& name)
: Internal{ libvlc_media_discoverer_new_from_name(inst->get(), name.c_str()),
libvlc_media_discoverer_release }
{
}
/**
* Get media service discover object its localized name.
*
* \return localized name
*/
std::string localizedName();
std::string localizedName()
{
char* c_result = libvlc_media_discoverer_localized_name(get());
if ( c_result == NULL )
return std::string();
std::string result = c_result;
libvlc_free(c_result);
return result;
}
/**
* Get event manager from media service discover object.
*
* \return event manager object.
*/
EventManagerPtr eventManager();
EventManagerPtr eventManager()
{
if ( m_eventManager )
{
libvlc_event_manager_t* obj = libvlc_media_discoverer_event_manager( get() );
m_eventManager = std::make_shared<EventManager>( obj );
}
return m_eventManager;
}
/**
* Query if media service discover object is running.
*
* \return true if running, false if not
*/
bool isRunning();
bool isRunning()
{
return libvlc_media_discoverer_is_running(get());
}
private:
EventManagerPtr m_eventManager;
......
/*****************************************************************************
* libvlc_MediaLibrary.cpp: MediaLibrary implementation
*****************************************************************************
* 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
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/