summaryrefslogtreecommitdiffstats
path: root/avmedia/source/vlc/wrapper
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 16:51:28 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 16:51:28 +0000
commit940b4d1848e8c70ab7642901a68594e8016caffc (patch)
treeeb72f344ee6c3d9b80a7ecc079ea79e9fba8676d /avmedia/source/vlc/wrapper
parentInitial commit. (diff)
downloadlibreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.tar.xz
libreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.zip
Adding upstream version 1:7.0.4.upstream/1%7.0.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'avmedia/source/vlc/wrapper')
-rw-r--r--avmedia/source/vlc/wrapper/Common.cxx45
-rw-r--r--avmedia/source/vlc/wrapper/EventHandler.cxx42
-rw-r--r--avmedia/source/vlc/wrapper/EventManager.cxx84
-rw-r--r--avmedia/source/vlc/wrapper/Instance.cxx62
-rw-r--r--avmedia/source/vlc/wrapper/Media.cxx109
-rw-r--r--avmedia/source/vlc/wrapper/Player.cxx241
-rw-r--r--avmedia/source/vlc/wrapper/SymbolLoader.hxx126
-rw-r--r--avmedia/source/vlc/wrapper/Types.hxx58
8 files changed, 767 insertions, 0 deletions
diff --git a/avmedia/source/vlc/wrapper/Common.cxx b/avmedia/source/vlc/wrapper/Common.cxx
new file mode 100644
index 000000000..4ee3a2977
--- /dev/null
+++ b/avmedia/source/vlc/wrapper/Common.cxx
@@ -0,0 +1,45 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+#include <wrapper/Common.hxx>
+#include "SymbolLoader.hxx"
+
+namespace
+{
+ const char AVMEDIA_NO_ERROR[] = "No error";
+
+ const char* ( *libvlc_get_version ) ();
+ char * ( * libvlc_errmsg ) ();
+}
+
+namespace avmedia::vlc::wrapper
+{
+bool Common::LoadSymbols()
+{
+ static ApiMap const VLC_COMMON_API[] =
+ {
+ SYM_MAP( libvlc_get_version ),
+ SYM_MAP( libvlc_errmsg )
+ };
+
+ return InitApiMap( VLC_COMMON_API );
+}
+
+const char* Common::Version()
+{
+ return libvlc_get_version();
+}
+
+const char* Common::LastErrorMessage()
+{
+ const char *errorMsg = libvlc_errmsg();
+ return errorMsg == nullptr ? AVMEDIA_NO_ERROR : errorMsg;
+}
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/avmedia/source/vlc/wrapper/EventHandler.cxx b/avmedia/source/vlc/wrapper/EventHandler.cxx
new file mode 100644
index 000000000..a2a0db16e
--- /dev/null
+++ b/avmedia/source/vlc/wrapper/EventHandler.cxx
@@ -0,0 +1,42 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <wrapper/EventHandler.hxx>
+
+namespace avmedia::vlc::wrapper
+{
+EventHandler::EventHandler()
+ : ::osl::Thread()
+{
+}
+
+void EventHandler::stop()
+{
+ mCallbackQueue.push(TCallback());
+ join();
+}
+
+void EventHandler::run()
+{
+ osl_setThreadName("VLC EventHandler");
+
+ TCallback callback;
+ do
+ {
+ mCallbackQueue.pop( callback );
+
+ if ( !callback )
+ return;
+
+ callback();
+ } while ( true );
+}
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/avmedia/source/vlc/wrapper/EventManager.cxx b/avmedia/source/vlc/wrapper/EventManager.cxx
new file mode 100644
index 000000000..27e56603e
--- /dev/null
+++ b/avmedia/source/vlc/wrapper/EventManager.cxx
@@ -0,0 +1,84 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <wrapper/EventManager.hxx>
+#include "SymbolLoader.hxx"
+#include <wrapper/EventHandler.hxx>
+#include "Types.hxx"
+
+namespace
+{
+ libvlc_event_manager_t* ( *libvlc_media_player_event_manager ) ( libvlc_media_player_t *p_mi );
+ int ( *libvlc_event_attach ) ( libvlc_event_manager_t *p_event_manager,
+ libvlc_event_type_t i_event_type,
+ libvlc_callback_t f_callback,
+ void *user_data );
+ void ( *libvlc_event_detach ) ( libvlc_event_manager_t *p_event_manager,
+ libvlc_event_type_t i_event_type,
+ libvlc_callback_t f_callback,
+ void *p_user_data );
+}
+
+namespace avmedia::vlc::wrapper
+{
+void EventManager::Handler( const libvlc_event_t *event, void *pData )
+{
+ EventManager *instance = static_cast<EventManager*>( pData );
+ switch ( event->type )
+ {
+ case libvlc_MediaPlayerPaused:
+ instance->mEventHandler.mCallbackQueue.push( instance->mOnPaused );
+ break;
+ case libvlc_MediaPlayerEndReached:
+ instance->mEventHandler.mCallbackQueue.push( instance->mOnEndReached );
+ break;
+ }
+}
+
+bool EventManager::LoadSymbols()
+{
+ static ApiMap const VLC_EVENT_MANAGER_API[] =
+ {
+ SYM_MAP( libvlc_media_player_event_manager ),
+ SYM_MAP( libvlc_event_attach ),
+ SYM_MAP( libvlc_event_detach )
+ };
+
+ return InitApiMap( VLC_EVENT_MANAGER_API );
+}
+
+EventManager::EventManager( Player& player, EventHandler& eh )
+ : mEventHandler( eh )
+ , mManager( libvlc_media_player_event_manager( player ) )
+{
+
+}
+
+void EventManager::registerSignal( int signal, const Callback& callback )
+{
+ if ( !callback )
+ libvlc_event_detach( mManager, signal, Handler, this );
+ else
+ libvlc_event_attach( mManager, signal, Handler, this );
+}
+
+void EventManager::onPaused( const EventManager::Callback& callback )
+{
+ mOnPaused = callback;
+ registerSignal( libvlc_MediaPlayerPaused, callback );
+}
+
+void EventManager::onEndReached( const Callback& callback )
+{
+ mOnEndReached = callback;
+ registerSignal( libvlc_MediaPlayerEndReached, callback );
+}
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/avmedia/source/vlc/wrapper/Instance.cxx b/avmedia/source/vlc/wrapper/Instance.cxx
new file mode 100644
index 000000000..1226cb7ea
--- /dev/null
+++ b/avmedia/source/vlc/wrapper/Instance.cxx
@@ -0,0 +1,62 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <wrapper/Instance.hxx>
+#include "SymbolLoader.hxx"
+
+namespace
+{
+ libvlc_instance_t* ( *libvlc_new ) ( int argc, const char * const *argv );
+ void ( *libvlc_release ) ( libvlc_instance_t *p_instance );
+ void ( *libvlc_retain ) ( libvlc_instance_t *p_instance );
+}
+
+namespace avmedia::vlc::wrapper
+{
+ bool Instance::LoadSymbols()
+ {
+ static ApiMap const VLC_INSTANCE_API[] =
+ {
+ SYM_MAP( libvlc_new ),
+ SYM_MAP( libvlc_release ),
+ SYM_MAP( libvlc_retain )
+ };
+
+ return InitApiMap( VLC_INSTANCE_API );
+ }
+
+ Instance::Instance( int argc, const char * const argv[] )
+ : mInstance( libvlc_new( argc, argv ) )
+ {
+ if ( mInstance == nullptr)
+ {
+ //TODO: error
+ }
+ }
+
+ Instance::Instance( const Instance& other )
+ {
+ operator=( other );
+ }
+
+ Instance& Instance::operator=( const Instance& other )
+ {
+ libvlc_release( mInstance );
+ mInstance = other.mInstance;
+ libvlc_retain( mInstance );
+ return *this;
+ }
+
+ Instance::~Instance()
+ {
+ libvlc_release( mInstance );
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/avmedia/source/vlc/wrapper/Media.cxx b/avmedia/source/vlc/wrapper/Media.cxx
new file mode 100644
index 000000000..f09aecd76
--- /dev/null
+++ b/avmedia/source/vlc/wrapper/Media.cxx
@@ -0,0 +1,109 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <rtl/ustring.h>
+#include <wrapper/Media.hxx>
+#include "SymbolLoader.hxx"
+#include <wrapper/Instance.hxx>
+#include "Types.hxx"
+#include <wrapper/Common.hxx>
+#include <sal/log.hxx>
+
+struct libvlc_instance_t;
+
+namespace avmedia::vlc::wrapper
+{
+namespace
+{
+ libvlc_media_t* ( *libvlc_media_new_path ) ( libvlc_instance_t *p_instance, const char *path );
+ libvlc_media_t* ( *libvlc_media_new_location ) (libvlc_instance_t *p_instance, const char *psz_mrl);
+ void ( *libvlc_media_release ) ( libvlc_media_t *p_md );
+ void ( *libvlc_media_retain ) ( libvlc_media_t *p_md );
+ libvlc_time_t ( *libvlc_media_get_duration ) ( libvlc_media_t *p_md );
+ void ( *libvlc_media_parse ) ( libvlc_media_t *p_md );
+ int ( *libvlc_media_is_parsed ) ( libvlc_media_t *p_md );
+ char* ( *libvlc_media_get_mrl )(libvlc_media_t *p_md);
+
+
+ libvlc_media_t* InitMedia( const OUString& url, Instance& instance )
+ {
+ OString dest;
+ url.convertToString(&dest, RTL_TEXTENCODING_UTF8, 0);
+
+ return libvlc_media_new_location(instance, dest.getStr());
+ }
+}
+
+bool Media::LoadSymbols()
+{
+ static ApiMap const VLC_MEDIA_API[] =
+ {
+ SYM_MAP( libvlc_media_new_path ),
+ SYM_MAP( libvlc_media_release ),
+ SYM_MAP( libvlc_media_retain ),
+ SYM_MAP( libvlc_media_get_duration ),
+ SYM_MAP( libvlc_media_parse ),
+ SYM_MAP( libvlc_media_is_parsed ),
+ SYM_MAP( libvlc_media_get_mrl ),
+ SYM_MAP( libvlc_media_new_location )
+ };
+
+ return InitApiMap( VLC_MEDIA_API );
+}
+
+Media::Media( const OUString& url, Instance& instance )
+ : mMedia( InitMedia( url, instance ) )
+{
+ if (mMedia == nullptr)
+ {
+ // TODO: Error
+ }
+}
+
+Media::Media( const Media& other )
+{
+ operator=( other );
+}
+
+Media& Media::operator=( const Media& other )
+{
+ libvlc_media_release( mMedia );
+ mMedia = other.mMedia;
+
+ libvlc_media_retain( mMedia );
+ return *this;
+}
+
+int Media::getDuration() const
+{
+ if ( !libvlc_media_is_parsed( mMedia ) )
+ libvlc_media_parse( mMedia );
+
+ const int duration = libvlc_media_get_duration( mMedia );
+ if (duration == -1)
+ {
+ SAL_WARN("avmedia", Common::LastErrorMessage());
+ return 0;
+ }
+ else if (duration == 0)
+ {
+ // A duration must be greater than 0
+ return 1;
+ }
+
+ return duration;
+}
+
+Media::~Media()
+{
+ libvlc_media_release( mMedia );
+}
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/avmedia/source/vlc/wrapper/Player.cxx b/avmedia/source/vlc/wrapper/Player.cxx
new file mode 100644
index 000000000..27e63a21a
--- /dev/null
+++ b/avmedia/source/vlc/wrapper/Player.cxx
@@ -0,0 +1,241 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <rtl/ustring.h>
+#include "Types.hxx"
+#include <wrapper/Player.hxx>
+#include <wrapper/Media.hxx>
+#include "SymbolLoader.hxx"
+#include <wrapper/Common.hxx>
+
+struct libvlc_media_t;
+
+namespace { extern "C" {
+ void ( *libvlc_media_player_retain ) ( libvlc_media_player_t *p_mi );
+ libvlc_media_player_t * ( *libvlc_media_player_new_from_media ) ( libvlc_media_t *p_md );
+ void ( *libvlc_media_player_release ) ( libvlc_media_player_t *p_mi );
+ int ( *libvlc_media_player_play ) ( libvlc_media_player_t *p_mi );
+ void ( *libvlc_media_player_pause ) ( libvlc_media_player_t *p_mi );
+ int ( *libvlc_media_player_is_playing ) ( libvlc_media_player_t *p_mi );
+ void ( *libvlc_media_player_stop ) ( libvlc_media_player_t *p_mi );
+ void ( *libvlc_media_player_set_time ) ( libvlc_media_player_t *p_mi, libvlc_time_t i_time );
+ libvlc_time_t ( *libvlc_media_player_get_time ) ( libvlc_media_player_t *p_mi );
+ float ( *libvlc_media_player_get_rate )( libvlc_media_player_t *p_mi );
+ int ( *libvlc_audio_set_volume ) ( libvlc_media_player_t *p_mi, int i_volume );
+ int ( *libvlc_audio_get_volume ) ( libvlc_media_player_t *p_mi );
+ int ( *libvlc_audio_get_mute ) ( libvlc_media_player_t *p_mi );
+ void ( *libvlc_audio_set_mute ) ( libvlc_media_player_t *p_mi, int status );
+ int ( *libvlc_video_take_snapshot ) ( libvlc_media_player_t *p_mi,
+ unsigned num,
+ const char *psz_filepath,
+ unsigned int i_width,
+ unsigned int i_height );
+#if defined MACOSX
+ void ( *libvlc_media_player_set_nsobject ) ( libvlc_media_player_t *p_mi, void *drawable );
+#elif defined UNX
+ void ( *libvlc_media_player_set_xwindow ) ( libvlc_media_player_t *p_mi, uint32_t drawable );
+#elif defined _WIN32
+ void ( *libvlc_media_player_set_hwnd ) ( libvlc_media_player_t *p_mi, void *drawable );
+#else
+#error unknown OS
+#endif
+ unsigned ( *libvlc_media_player_has_vout ) ( libvlc_media_player_t *p_mi );
+ void ( *libvlc_video_set_mouse_input ) ( libvlc_media_player_t *p_mi, unsigned on );
+ void ( *libvlc_video_set_scale ) ( libvlc_media_player_t *p_mi, float f_factor );
+ int ( *libvlc_video_get_size ) ( libvlc_media_player_t *p_mi, unsigned num,
+ unsigned *px, unsigned *py );
+ int ( *libvlc_video_get_track_count ) ( libvlc_media_player_t *p_mi );
+ int ( *libvlc_video_set_track ) ( libvlc_media_player_t *p_mi, int i_track );
+ libvlc_track_description_t* ( *libvlc_video_get_track_description ) ( libvlc_media_player_t *p_mi );
+
+ int ( *libvlc_audio_get_track ) ( libvlc_media_player_t *p_mi );
+ libvlc_track_description_t * ( *libvlc_audio_get_track_description ) (libvlc_media_player_t *p_mi );
+ int ( *libvlc_audio_set_track ) (libvlc_media_player_t *p_mi, int i_track);
+} }
+
+namespace avmedia::vlc::wrapper
+{
+ bool Player::LoadSymbols()
+ {
+ static ApiMap const VLC_PLAYER_API[] =
+ {
+ SYM_MAP( libvlc_media_player_new_from_media ),
+ SYM_MAP( libvlc_media_player_release ),
+ SYM_MAP( libvlc_media_player_play ),
+ SYM_MAP( libvlc_media_player_pause ),
+ SYM_MAP( libvlc_media_player_is_playing ),
+ SYM_MAP( libvlc_media_player_stop ),
+ SYM_MAP( libvlc_media_player_set_time ),
+ SYM_MAP( libvlc_media_player_get_time ),
+ SYM_MAP( libvlc_media_player_get_rate ),
+ SYM_MAP( libvlc_audio_set_volume ),
+ SYM_MAP( libvlc_audio_get_volume ),
+ SYM_MAP( libvlc_audio_set_mute ),
+ SYM_MAP( libvlc_audio_get_mute ),
+ SYM_MAP( libvlc_video_take_snapshot ),
+#if defined MACOSX
+ SYM_MAP( libvlc_media_player_set_nsobject ),
+#elif defined UNX
+ SYM_MAP( libvlc_media_player_set_xwindow ),
+#elif defined _WIN32
+ SYM_MAP( libvlc_media_player_set_hwnd ),
+#endif
+ SYM_MAP( libvlc_media_player_has_vout ),
+ SYM_MAP( libvlc_video_set_mouse_input ),
+ SYM_MAP( libvlc_media_player_retain ),
+ SYM_MAP( libvlc_video_set_scale ),
+ SYM_MAP( libvlc_video_get_size ),
+ SYM_MAP( libvlc_video_get_track_count ),
+ SYM_MAP( libvlc_video_set_track ),
+ SYM_MAP( libvlc_video_get_track_description ),
+ SYM_MAP( libvlc_audio_get_track ),
+ SYM_MAP( libvlc_audio_get_track_description ),
+ SYM_MAP( libvlc_audio_set_track )
+ };
+
+ return InitApiMap( VLC_PLAYER_API );
+ }
+
+ Player::Player( Media& media )
+ : mPlayer( libvlc_media_player_new_from_media( media ) )
+ {
+ }
+
+ Player::Player( const Player& other )
+ {
+ operator=( other );
+ }
+
+ Player& Player::operator=( const Player& other )
+ {
+ libvlc_media_player_release( mPlayer );
+ mPlayer = other.mPlayer;
+ libvlc_media_player_retain( mPlayer );
+ return *this;
+ }
+
+ Player::~Player()
+ {
+ libvlc_media_player_release( mPlayer );
+ }
+
+ bool Player::play()
+ {
+ const bool status = ( libvlc_media_player_play( mPlayer ) == 0 );
+ if ( libvlc_video_get_track_count( mPlayer ) > 0 )
+ {
+ const libvlc_track_description_t *description = libvlc_video_get_track_description( mPlayer );
+
+ for ( ; description->p_next != nullptr; description = description->p_next );
+
+ libvlc_video_set_track( mPlayer, description->i_id );
+ }
+
+ if ( libvlc_audio_get_track( mPlayer ) > 0 )
+ {
+ const libvlc_track_description_t *description = libvlc_audio_get_track_description( mPlayer );
+
+ for ( ; description->p_next != nullptr; description = description->p_next );
+
+ libvlc_audio_set_track( mPlayer, description->i_id );
+ }
+
+ return status;
+ }
+
+ void Player::pause()
+ {
+ libvlc_media_player_pause( mPlayer );
+ }
+
+ void Player::stop()
+ {
+ libvlc_media_player_stop( mPlayer );
+ }
+
+ void Player::setTime( int time )
+ {
+ libvlc_media_player_set_time( mPlayer, time );
+ }
+
+ int Player::getTime() const
+ {
+ const int time = libvlc_media_player_get_time( mPlayer );
+
+ return ( time == -1 ? 0 : time );
+ }
+
+ void Player::setScale( float factor )
+ {
+ libvlc_video_set_scale( mPlayer, factor );
+ }
+
+ void Player::setMouseHandling(bool flag)
+ {
+ libvlc_video_set_mouse_input( mPlayer, flag );
+ }
+
+ bool Player::isPlaying() const
+ {
+ return libvlc_media_player_is_playing( mPlayer ) == 1;
+ }
+
+ void Player::setVolume( int volume )
+ {
+ libvlc_audio_set_volume( mPlayer, volume );
+ }
+
+ int Player::getVolume() const
+ {
+ return libvlc_audio_get_volume( mPlayer );
+ }
+
+ void Player::setMute( bool mute)
+ {
+ libvlc_audio_set_mute( mPlayer, mute );
+ }
+
+ bool Player::getMute() const
+ {
+ return libvlc_audio_get_mute( mPlayer );
+ }
+
+ void Player::setVideoSize( unsigned width, unsigned )
+ {
+ unsigned currentWidth, currentHeight;
+ libvlc_video_get_size( mPlayer, 0, &currentWidth, &currentHeight );
+ if ( currentWidth != 0 )
+ setScale( static_cast<float>( width ) / currentWidth );
+ }
+
+ void Player::setWindow( intptr_t id )
+ {
+#if defined MACOSX
+ libvlc_media_player_set_nsobject( mPlayer, reinterpret_cast<void*>( id ) );
+#elif defined UNX
+ libvlc_media_player_set_xwindow( mPlayer, static_cast<uint32_t>(id) );
+#elif defined _WIN32
+ libvlc_media_player_set_hwnd( mPlayer, reinterpret_cast<void*>( id ) );
+#endif
+ }
+
+ void Player::takeSnapshot( const OUString& file )
+ {
+ OString dest;
+ file.convertToString( &dest, RTL_TEXTENCODING_UTF8, 0 );
+ libvlc_video_take_snapshot( mPlayer, 0, dest.getStr(), 480, 360 );
+ }
+
+ bool Player::hasVout() const
+ {
+ return libvlc_media_player_has_vout( mPlayer );
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/avmedia/source/vlc/wrapper/SymbolLoader.hxx b/avmedia/source/vlc/wrapper/SymbolLoader.hxx
new file mode 100644
index 000000000..64789b326
--- /dev/null
+++ b/avmedia/source/vlc/wrapper/SymbolLoader.hxx
@@ -0,0 +1,126 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#pragma once
+#if defined(_WIN32)
+#if !defined WIN32_LEAN_AND_MEAN
+# define WIN32_LEAN_AND_MEAN
+#endif
+# include <windows.h>
+# include <winreg.h>
+#endif
+#include <osl/module.h>
+#include <rtl/ustring.hxx>
+#include <sal/log.hxx>
+
+#define SYM_MAP(a) { #a, reinterpret_cast<SymbolFunc *>(&a) }
+
+namespace avmedia
+{
+namespace vlc
+{
+namespace wrapper
+{
+typedef void (*SymbolFunc) (void);
+
+struct ApiMap
+{
+ OUStringLiteral symName;
+ SymbolFunc *refValue;
+};
+
+#if defined( LINUX )
+ const char LibName[] = "libvlc.so.5";
+#elif defined( MACOSX )
+ const char LibName[] = "/Applications/VLC.app/Contents/MacOS/lib/libvlc.dylib";
+#elif defined( _WIN32 )
+ const char LibName[] = "libvlc.dll";
+
+ inline OUString GetVLCPath()
+ {
+ HKEY hKey;
+ sal_Unicode arCurrent[MAX_PATH];
+ DWORD dwType, dwCurrentSize = sizeof( arCurrent );
+
+ //TODO: This one will work only with LibreOffice 32-bit + VLC 32-bit on Win x86_64.
+ const LONG errorCore = ::RegOpenKeyExW( HKEY_LOCAL_MACHINE, L"SOFTWARE\\Wow6432Node\\VideoLAN\\VLC", 0, KEY_READ | KEY_WOW64_64KEY, &hKey );
+ if ( errorCore == ERROR_SUCCESS )
+ {
+ if ( ::RegQueryValueExW( hKey, L"InstallDir", nullptr, &dwType, reinterpret_cast<LPBYTE>(arCurrent), &dwCurrentSize ) == ERROR_SUCCESS &&
+ dwType == REG_SZ )
+ {
+ ::RegCloseKey( hKey );
+ dwCurrentSize -= 2;
+ dwCurrentSize /= 2;
+
+ return OUString( arCurrent, dwCurrentSize ) + "\\";
+ }
+
+ ::RegCloseKey( hKey );
+ }
+
+ return OUString();
+ }
+#endif
+
+ template<size_t N>
+ bool tryLink( oslModule &aModule, const ApiMap ( &pMap )[N] )
+ {
+ for (size_t i = 0; i < N; ++i)
+ {
+ SymbolFunc aMethod = reinterpret_cast<SymbolFunc>(osl_getFunctionSymbol
+ ( aModule, OUString( pMap[ i ].symName ).pData ));
+ if ( !aMethod )
+ {
+ SAL_WARN("avmedia", "Cannot load method " << pMap[ i ].symName);
+ *pMap[ i ].refValue = nullptr;
+ return false;
+ }
+ else
+ *pMap[ i ].refValue = aMethod;
+ }
+
+ return true;
+ }
+
+ template<size_t N>
+ bool InitApiMap( const ApiMap ( &pMap )[N] )
+ {
+#if defined( LINUX ) || defined( MACOSX )
+ OUString const fullPath(LibName);
+#elif defined( _WIN32 )
+ OUString const fullPath(GetVLCPath() + LibName);
+#endif
+ SAL_INFO("avmedia", fullPath);
+
+ oslModule aModule = osl_loadModule( fullPath.pData,
+ SAL_LOADMODULE_DEFAULT );
+
+
+ if( aModule == nullptr)
+ {
+ SAL_WARN("avmedia", "Cannot load libvlc");
+ return false;
+ }
+
+ if (tryLink( aModule, pMap ))
+ {
+ return true;
+ }
+
+ SAL_WARN("avmedia", "Cannot load libvlc");
+ osl_unloadModule( aModule );
+
+ return false;
+ }
+}
+}
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/avmedia/source/vlc/wrapper/Types.hxx b/avmedia/source/vlc/wrapper/Types.hxx
new file mode 100644
index 000000000..c66a88bdc
--- /dev/null
+++ b/avmedia/source/vlc/wrapper/Types.hxx
@@ -0,0 +1,58 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+/* Typedefs and structures that represent the libvlc API / ABI */
+
+#pragma once
+
+#include <sal/config.h>
+
+#if defined(_WIN32)
+ typedef __int64 libvlc_time_t;
+#else
+#include <stdint.h>
+ typedef int64_t libvlc_time_t;
+#endif
+
+extern "C" {
+
+// basic callback / event types we use
+typedef int libvlc_event_type_t;
+typedef struct libvlc_event_manager_t libvlc_event_manager_t;
+typedef void ( *libvlc_callback_t ) ( const struct libvlc_event_t *, void * );
+
+// the enumeration values we use cf. libvlc_events.h
+#define libvlc_MediaPlayerPaused 0x105
+#define libvlc_MediaPlayerEndReached 0x109
+
+// event structure pieces we use
+struct libvlc_event_t
+{
+ int type; // event type
+ void *p_obj; // object emitting that event
+
+ union // so far we don't need this.
+ {
+ struct {
+ const char *dummy1;
+ const char *dummy2;
+ } padding;
+ } u;
+};
+
+struct libvlc_track_description_t
+{
+ int i_id;
+ char *psz_name;
+ libvlc_track_description_t *p_next;
+};
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */