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

Update to new libvlcpp

parent a7209e06
[submodule "src/Backend/VLC/libvlcpp"]
path = src/Backend/VLC/libvlcpp
url = https://code.videolan.org/videolan/libvlcpp.git
......@@ -8,6 +8,11 @@
git clone https://code.videolan.org/videolan/vlmc.git
## Fetch libvlcpp
git submodule init
git submodule update
##Building and packaging VLMC on Linux
A typical way to build VLMC is:
......
......@@ -23,7 +23,7 @@
#ifndef IBACKEND_H
#define IBACKEND_H
class QString;
#include <functional>
namespace Backend
{
......@@ -42,12 +42,12 @@ class IBackend
Error,
None
};
typedef void (*LogHandler)( void* data, LogLevel logLevel, const char* msg);
using LogHandler = std::function<void( LogLevel logLevel, const char* msg )>;
virtual ~IBackend() {}
virtual ~IBackend() = default;
virtual ISource* createSource( const char* path ) = 0;
virtual IMemorySource* createMemorySource() = 0;
virtual void setLogHandler( void* data, LogHandler logHandler) = 0;
virtual void setLogHandler( LogHandler logHandler ) = 0;
};
extern IBackend* getBackend();
......
......@@ -71,7 +71,7 @@ namespace Backend
virtual void nextFrame() = 0;
virtual void previousFrame() = 0;
virtual int volume() const = 0;
virtual int volume() = 0;
virtual void setVolume( int volume ) = 0;
/**
* @brief setOutputWidget Will direct the rendering to the specified widget.
......@@ -94,7 +94,7 @@ namespace Backend
virtual void setOutputAudioNumberChannels( unsigned int nbChannels ) = 0;
virtual void setOutputAudioBitrate( unsigned int aBitrate ) = 0;
virtual int64_t time() const = 0;
virtual int64_t time() = 0;
virtual void setTime( int64_t time ) = 0;
virtual void setPosition( float position ) = 0;
......
/*****************************************************************************
* VLCInstance.cpp: Binding for libvlc instances
*****************************************************************************
* Copyright (C) 2008-2014 VideoLAN
*
* Authors: 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 General Public License
* as published by the Free Software Foundation; either version 2
* 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 "VLCInstance.h"
#include "vlc/vlc.h"
#include <cstdio>
#include <cassert>
using namespace LibVLCpp;
Instance::Instance(int argc, const char **argv)
{
m_internalPtr = libvlc_new( argc, argv );
assert( m_internalPtr != NULL );
}
Instance::~Instance()
{
libvlc_release( m_internalPtr );
}
void
Instance::setLogHook( void* data, libvlc_log_cb hook )
{
libvlc_log_set( m_internalPtr, hook, data );
}
void
Instance::unsetLogHook()
{
libvlc_log_unset( *this );
}
/*****************************************************************************
* VLCInstance.h: Binding for libvlc instance
*****************************************************************************
* Copyright (C) 2008-2014 VideoLAN
*
* Authors: 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 General Public License
* as published by the Free Software Foundation; either version 2
* 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 General Public License for more details.
*
* You should have received a copy of the GNU 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.
*****************************************************************************/
#ifndef VLCINSTANCE_H
#define VLCINSTANCE_H
#include "VLCpp.hpp"
struct libvlc_instance_t;
namespace LibVLCpp
{
/**
* \warning This class should be released after every other LibVLCpp classes.
*/
class Instance : public Internal< libvlc_instance_t >
{
public:
Instance( int argc, const char** argv );
~Instance();
void setLogHook( void *data, libvlc_log_cb hook );
void unsetLogHook();
};
}
#endif // VLCINSTANCE_H
/*****************************************************************************
* VLCMedia.cpp: Binding for libvlc_media
*****************************************************************************
* Copyright (C) 2008-2014 VideoLAN
*
* Authors: 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 General Public License
* as published by the Free Software Foundation; either version 2
* 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 "VLCMedia.h"
#include "VLCInstance.h"
//Allow PRId64 to be defined:
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#include <cstdio>
using namespace LibVLCpp;
Media::Media(LibVLCpp::Instance* instance, const char *filename )
: m_tracks( NULL )
, m_nbTracks( 0 )
, m_mrl( NULL )
{
m_internalPtr = libvlc_media_new_location( *instance, filename);
}
Media::~Media()
{
if ( m_tracks != NULL )
libvlc_media_tracks_release( m_tracks, m_nbTracks );
libvlc_media_release( m_internalPtr );
free( m_mrl );
}
void
Media::addOption( const char* opt )
{
libvlc_media_add_option_flag( m_internalPtr, opt, libvlc_media_option_trusted );
}
void
Media::setVideoLockCallback( void* callback )
{
char param[64];
sprintf( param, ":sout-smem-video-prerender-callback=%" PRIdPTR, (intptr_t)callback );
addOption(param);
}
void
Media::setVideoUnlockCallback( void* callback )
{
char param[64];
sprintf( param, ":sout-smem-video-postrender-callback=%" PRIdPTR, (intptr_t)callback );
addOption( param );
}
void
Media::setAudioLockCallback( void* callback )
{
char param[64];
sprintf( param, ":sout-smem-audio-prerender-callback=%" PRIdPTR, (intptr_t)callback );
addOption(param);
}
void
Media::setAudioUnlockCallback( void* callback )
{
char param[64];
sprintf( param, ":sout-smem-audio-postrender-callback=%" PRIdPTR, (intptr_t)callback );
addOption( param );
}
void
Media::setVideoDataCtx( void* dataCtx )
{
char param[64];
sprintf( param, ":sout-smem-video-data=%" PRIdPTR, (intptr_t)dataCtx );
addOption( param );
}
void
Media::setAudioDataCtx( void* dataCtx )
{
char param[64];
sprintf( param, ":sout-smem-audio-data=%" PRIdPTR, (intptr_t)dataCtx );
addOption( param );
}
const char*
Media::mrl()
{
if ( m_mrl == NULL )
m_mrl = libvlc_media_get_mrl( m_internalPtr );
return m_mrl;
}
void
Media::parse()
{
libvlc_media_parse( *this );
}
void
Media::fetchTrackInfo()
{
m_nbTracks = libvlc_media_tracks_get( *this, &m_tracks );
}
unsigned int
Media::videoCodec() const
{
for ( int i = 0; i < m_nbTracks; ++i )
if ( m_tracks[i]->i_type == libvlc_track_video )
return m_tracks[i]->i_codec;
return 0;
}
unsigned int
Media::audioCodec() const
{
for ( int i = 0; i < m_nbTracks; ++i )
if ( m_tracks[i]->i_type == libvlc_track_video )
return m_tracks[i]->i_codec;
return 0;
}
int64_t
Media::getDuration()
{
return libvlc_media_get_duration( *this );
}
/*****************************************************************************
* VLCMedia.h: Binding for libvlc_media
*****************************************************************************
* Copyright (C) 2008-2014 VideoLAN
*
* Authors: 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 General Public License
* as published by the Free Software Foundation; either version 2
* 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 General Public License for more details.
*
* You should have received a copy of the GNU 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.
*****************************************************************************/
#ifndef VLCMEDIA_H
#define VLCMEDIA_H
#include "vlc/vlc.h"
#include "VLCpp.hpp"
namespace LibVLCpp
{
class Instance;
class Media : public Internal< libvlc_media_t >
{
public:
Media( Instance* instance, const char* filename );
~Media();
void addOption( const char* opt );
void setVideoLockCallback( void* );
void setVideoUnlockCallback( void* );
void setAudioLockCallback( void* );
void setAudioUnlockCallback( void* );
void setVideoDataCtx( void* dataCtx );
void setAudioDataCtx( void* dataCtx );
const char* mrl();
void parse();
void fetchTrackInfo();
unsigned int videoCodec() const;
unsigned int audioCodec() const;
int64_t getDuration();
private:
libvlc_media_track_t **m_tracks;
// this has not to be equal to nb video tracks + nb audio tracks.
// it is only meant to use when iterating over m_tracksInfo
int m_nbTracks;
char* m_mrl;
Media(const Media&);
};
}
#endif // VLCMEDIA_H
/*****************************************************************************
* VLCMediaPlayer.cpp: Binding for libvlc_media_player
*****************************************************************************
* Copyright (C) 2008-2014 VideoLAN
*
* Authors: 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 General Public License
* as published by the Free Software Foundation; either version 2
* 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 "VLCMediaPlayer.h"
#include "VLCInstance.h"
#include "VLCMedia.h"
#include <QtGlobal>
using namespace LibVLCpp;
MediaPlayer::MediaPlayer( Instance* vlcInstance )
{
m_internalPtr = libvlc_media_player_new( *vlcInstance );
// Initialize the event manager
p_em = libvlc_media_player_event_manager( m_internalPtr );
}
MediaPlayer::~MediaPlayer()
{
stop();
libvlc_media_player_release( m_internalPtr );
}
void
MediaPlayer::registerEvents( libvlc_callback_t callback, void* data )
{
libvlc_event_attach( p_em, libvlc_MediaPlayerSnapshotTaken, callback, data );
libvlc_event_attach( p_em, libvlc_MediaPlayerTimeChanged, callback, data );
libvlc_event_attach( p_em, libvlc_MediaPlayerPlaying, callback, data );
libvlc_event_attach( p_em, libvlc_MediaPlayerPaused, callback, data );
libvlc_event_attach( p_em, libvlc_MediaPlayerStopped, callback, data );
libvlc_event_attach( p_em, libvlc_MediaPlayerEndReached, callback, data );
libvlc_event_attach( p_em, libvlc_MediaPlayerPositionChanged, callback, data );
libvlc_event_attach( p_em, libvlc_MediaPlayerLengthChanged, callback, data );
libvlc_event_attach( p_em, libvlc_MediaPlayerEncounteredError, callback, data );
libvlc_event_attach( p_em, libvlc_MediaPlayerPausableChanged, callback, data );
libvlc_event_attach( p_em, libvlc_MediaPlayerSeekableChanged, callback, data );
libvlc_event_attach( p_em, libvlc_MediaPlayerVout, callback, data );
}
void
MediaPlayer::unregisterEvents( libvlc_callback_t callback, void *data )
{
libvlc_event_detach( p_em, libvlc_MediaPlayerSnapshotTaken, callback, data );
libvlc_event_detach( p_em, libvlc_MediaPlayerTimeChanged, callback, data );
libvlc_event_detach( p_em, libvlc_MediaPlayerPlaying, callback, data );
libvlc_event_detach( p_em, libvlc_MediaPlayerPaused, callback, data );
libvlc_event_detach( p_em, libvlc_MediaPlayerStopped, callback, data );
libvlc_event_detach( p_em, libvlc_MediaPlayerEndReached, callback, data );
libvlc_event_detach( p_em, libvlc_MediaPlayerPositionChanged, callback, data );
libvlc_event_detach( p_em, libvlc_MediaPlayerLengthChanged, callback, data );
libvlc_event_detach( p_em, libvlc_MediaPlayerEncounteredError, callback, data );
libvlc_event_detach( p_em, libvlc_MediaPlayerPausableChanged, callback, data );
libvlc_event_detach( p_em, libvlc_MediaPlayerSeekableChanged, callback, data );
libvlc_event_detach( p_em, libvlc_MediaPlayerVout, callback, data );
}
const char*
MediaPlayer::eventName(libvlc_event_type_t event) const
{
return libvlc_event_type_name( event );
}
void
MediaPlayer::play()
{
//vlmcDebug() << "Asking for play media player";
libvlc_media_player_play( m_internalPtr );
}
void
MediaPlayer::pause()
{
libvlc_media_player_pause( m_internalPtr );
}
void
MediaPlayer::setPause( bool isPaused )
{
libvlc_media_player_set_pause( m_internalPtr, isPaused );
}
void
MediaPlayer::stop()
{
//vlmcDebug() << "Asking for stop media player";
libvlc_media_player_stop( m_internalPtr );
}
int
MediaPlayer::getVolume()
{
return libvlc_audio_get_volume( m_internalPtr );
}
int
MediaPlayer::setVolume( int volume )
{
//Returns 0 if the volume was set, -1 if it was out of range
return libvlc_audio_set_volume( m_internalPtr, volume );
}
int64_t
MediaPlayer::getTime()
{
return libvlc_media_player_get_time( m_internalPtr );
}
void
MediaPlayer::setTime( int64_t time )
{
libvlc_media_player_set_time( m_internalPtr, time );
}
float
MediaPlayer::getPosition()
{
return libvlc_media_player_get_position( m_internalPtr );
}
void
MediaPlayer::setPosition( float pos )
{
libvlc_media_player_set_position( m_internalPtr, pos );
}
int64_t
MediaPlayer::getLength()
{
return libvlc_media_player_get_length( m_internalPtr );
}
void
MediaPlayer::takeSnapshot( const char* outputFile, unsigned int width, unsigned int heigth )
{
libvlc_video_take_snapshot( *this, 0, outputFile, width, heigth );
}
bool
MediaPlayer::isPlaying()
{
return ( libvlc_media_player_is_playing( m_internalPtr ) == 1 );
}
bool
MediaPlayer::isSeekable()
{
return ( libvlc_media_player_is_seekable( m_internalPtr ) == 1 );
}
void
MediaPlayer::setDrawable( void* drawable )
{
#if defined ( Q_OS_MAC )
libvlc_media_player_set_nsobject( m_internalPtr, drawable );
#elif defined ( Q_OS_UNIX )
libvlc_media_player_set_xwindow( m_internalPtr, reinterpret_cast<intptr_t>( drawable ) );
#elif defined ( Q_OS_WIN )
libvlc_media_player_set_hwnd( m_internalPtr, drawable );
#endif
}
void
MediaPlayer::setMedia( Media* media )
{
libvlc_media_player_set_media( m_internalPtr, media->getInternalPtr() );
}
void
MediaPlayer::getSize( unsigned int *outWidth, unsigned int *outHeight )
{
libvlc_video_get_size( m_internalPtr, 0, outWidth, outHeight );
}
float
MediaPlayer::getFps()
{
return libvlc_media_player_get_fps( m_internalPtr );
}
void
MediaPlayer::nextFrame()
{
libvlc_media_player_next_frame( m_internalPtr );
}
bool
MediaPlayer::hasVout()
{
return libvlc_media_player_has_vout( m_internalPtr ) > 0;
}
int
MediaPlayer::getNbAudioTrack()
{
return libvlc_audio_get_track_count( m_internalPtr );
}
int
MediaPlayer::getNbVideoTrack()
{
return libvlc_video_get_track_count( m_internalPtr );
}
void
MediaPlayer::setKeyInput( bool enabled )
{
libvlc_video_set_key_input( m_internalPtr, enabled );
}
bool
MediaPlayer::setAudioOutput(const char *module)
{
return libvlc_audio_output_set( m_internalPtr, module ) == 0;
}
void
MediaPlayer::disableTitle()
{
libvlc_media_player_set_video_title_display( *this, libvlc_position_disable, 0 );
}
void
MediaPlayer::setupVmemCallbacks(libvlc_video_lock_cb lock, libvlc_video_unlock_cb unlock, libvlc_video_display_cb display, void *data)
{
libvlc_video_set_callbacks( *this, lock, unlock, display, data );
}
void
MediaPlayer::setupVmem(const char *chroma, unsigned int width, unsigned int height, unsigned int pitch)
{
libvlc_video_set_format( *this, chroma, width, height, pitch );
}
bool
LibVLCpp::MediaPlayer::willPlay()
{
return libvlc_media_player_will_play( *this ) != 0;
}
libvlc_state_t
MediaPlayer::state()
{
return libvlc_media_player_get_state( *this );
}
/*****************************************************************************
* VLCMediaPlayer.h: Binding for libvlc_media_player
*****************************************************************************
* Copyright (C) 2008-2014 VideoLAN
*
* Authors: 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 General Public License
* as published by the Free Software Foundation; either version 2
* 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 General Public License for more details.
*
* You should have received a copy of the GNU 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.
*****************************************************************************/
#ifndef VLCMEDIAPLAYER_H
#define VLCMEDIAPLAYER_H
#include "VLCpp.hpp"
#include "vlc/vlc.h"
struct libvlc_media_player_t;
struct libvlc_event_t;
struct libvlc_event_manager_t;
namespace LibVLCpp
{
class Instance;
class Media;
class MediaPlayer : public Internal< libvlc_media_player_t >
{
public:
typedef bool (*CheckEventCallback)(const MediaPlayer*, const libvlc_event_t*);
MediaPlayer( Instance* vlcInstance );
~MediaPlayer();
void play();
void pause();
void setPause( bool isPaused );
void stop();
int getVolume();
int setVolume( int volume );
int64_t getTime();
void setTime(int64_t time );
float getPosition();
void setPosition( float pos );
/**
\return The length, in milliseconds.
*/
int64_t getLength();
void takeSnapshot( const char* outputFile, unsigned int width, unsigned int heigth );
bool isPlaying();
bool isSeekable();
void setDrawable( void* drawable );
void setMedia(Media* media);
void getSize( unsigned int *outWidth, unsigned int *outHeight);
float getFps();
void nextFrame();
bool hasVout();
int getNbAudioTrack();
int getNbVideoTrack();
void setKeyInput( bool enabled );
bool setAudioOutput(const char* module);
void disableTitle();
void setupVmemCallbacks( libvlc_video_lock_cb lock, libvlc_video_unlock_cb unlock,
libvlc_video_display_cb display, void* data );
void setupVmem( const char* chroma, unsigned int width,
unsigned int height, unsigned int pitch );
bool willPlay();
libvlc_state_t state();