From 5ae5a11f2ffbdb65da94e7ec1d54779603bfedb6 Mon Sep 17 00:00:00 2001 From: Minh Ngo Date: Mon, 5 Aug 2013 22:57:02 +0300 Subject: VLC::Instance Wrapper class for libvlc_instance_t Change-Id: I46beb65c13ed349b0faadfab1be888d6cbd10ff9 --- avmedia/Library_avmediavlc.mk | 1 + avmedia/source/vlc/vlcplayer.cxx | 12 ++++----- avmedia/source/vlc/vlcplayer.hxx | 5 ++-- avmedia/source/vlc/wrapper/Instance.cxx | 32 ++++++++++++++++++++++++ avmedia/source/vlc/wrapper/Instance.hxx | 43 +++++++++++++++++++++++++++++++++ 5 files changed, 84 insertions(+), 9 deletions(-) create mode 100644 avmedia/source/vlc/wrapper/Instance.cxx create mode 100644 avmedia/source/vlc/wrapper/Instance.hxx (limited to 'avmedia') diff --git a/avmedia/Library_avmediavlc.mk b/avmedia/Library_avmediavlc.mk index f17b18cd2b59..1c317e355874 100644 --- a/avmedia/Library_avmediavlc.mk +++ b/avmedia/Library_avmediavlc.mk @@ -45,6 +45,7 @@ $(eval $(call gb_Library_add_exception_objects,avmediavlc,\ avmedia/source/vlc/vlcuno \ avmedia/source/vlc/vlcwindow \ avmedia/source/vlc/vlcframegrabber \ + avmedia/source/vlc/wrapper/Instance \ )) # vim: set noet sw=4 ts=4: diff --git a/avmedia/source/vlc/vlcplayer.cxx b/avmedia/source/vlc/vlcplayer.cxx index ca32ef81c356..20ed327bf6bb 100644 --- a/avmedia/source/vlc/vlcplayer.cxx +++ b/avmedia/source/vlc/vlcplayer.cxx @@ -4,6 +4,7 @@ #include "vlcplayer.hxx" #include "vlcwindow.hxx" #include "vlcframegrabber.hxx" +#include "wrapper/Instance.hxx" using namespace ::com::sun::star; @@ -14,31 +15,28 @@ const ::rtl::OUString AVMEDIA_VLC_PLAYER_IMPLEMENTATIONNAME = "com.sun.star.comp const ::rtl::OUString AVMEDIA_VLC_PLAYER_SERVICENAME = "com.sun.star.media.Player_VLC"; const char * const VLC_ARGS[] = { -// "-I", "-Vdummy", "--snapshot-format=png", -// "--ignore-config", "--ffmpeg-threads", "--verbose=-1", -// "--quiet" }; const int MS_IN_SEC = 1000; // Millisec in sec namespace { - libvlc_media_t* InitMedia( const rtl::OUString& url, boost::shared_ptr& instance ) + libvlc_media_t* InitMedia( const rtl::OUString& url, VLC::Instance& instance ) { rtl::OString dest; url.convertToString(&dest, RTL_TEXTENCODING_UTF8, 0); - return libvlc_media_new_path(instance.get(), dest.getStr()); + return libvlc_media_new_path(instance, dest.getStr()); } } VLCPlayer::VLCPlayer( const rtl::OUString& url ) : VLC_Base(m_aMutex) - , mInstance( libvlc_new( sizeof( VLC_ARGS ) / sizeof( VLC_ARGS[0] ), VLC_ARGS ), libvlc_release ) + , mInstance( sizeof( VLC_ARGS ) / sizeof( VLC_ARGS[0] ), VLC_ARGS ) , mMedia( InitMedia( url, mInstance ), libvlc_media_release ) , mPlayer( libvlc_media_player_new_from_media( mMedia.get() ), libvlc_media_player_release ) , mUrl( url ) @@ -108,7 +106,7 @@ namespace case libvlc_MediaPlayerEndReached: boost::shared_ptr player = *static_cast< boost::shared_ptr* >( pData ); libvlc_media_player_stop( player.get() ); - libvlc_media_player_play( player.get() ) + libvlc_media_player_play( player.get() ); break; } } diff --git a/avmedia/source/vlc/vlcplayer.hxx b/avmedia/source/vlc/vlcplayer.hxx index acdee37494fb..b7c4bed70ab0 100644 --- a/avmedia/source/vlc/vlcplayer.hxx +++ b/avmedia/source/vlc/vlcplayer.hxx @@ -27,6 +27,7 @@ #include #include +#include "wrapper/Instance.hxx" namespace avmedia { namespace vlc { @@ -37,7 +38,7 @@ typedef ::cppu::WeakComponentImplHelper2< ::com::sun::star::media::XPlayer, class VLCPlayer : public ::cppu::BaseMutex, public VLC_Base { - boost::shared_ptr mInstance; + VLC::Instance mInstance; boost::shared_ptr mMedia; boost::shared_ptr mPlayer; const rtl::OUString mUrl; @@ -74,4 +75,4 @@ public: #endif -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ \ No newline at end of file +/* 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 000000000000..bc23167210b6 --- /dev/null +++ b/avmedia/source/vlc/wrapper/Instance.cxx @@ -0,0 +1,32 @@ +#include + +#include "Instance.hxx" +#include "SymbolLoader.hxx" + +namespace VLC +{ + namespace + { + libvlc_instance_t *(*libvlc_new) (int argc, const char * const *argv); + void (*libvlc_release) (libvlc_instance_t *p_instance); + + ApiMap VLC_INSTANCE_API[] = + { + SYM_MAP( libvlc_new ), + SYM_MAP( libvlc_release ) + }; + } + + Instance::Instance( int argc, const char * const *argv ) + { + InitApiMap( VLC_INSTANCE_API ); + + mInstance = libvlc_new( argc, argv ); + } + + Instance::~Instance() + { + libvlc_release( mInstance ); + } + +} diff --git a/avmedia/source/vlc/wrapper/Instance.hxx b/avmedia/source/vlc/wrapper/Instance.hxx new file mode 100644 index 000000000000..0cad70558b54 --- /dev/null +++ b/avmedia/source/vlc/wrapper/Instance.hxx @@ -0,0 +1,43 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef _WRAPPER_INSTANCE_HXX +#define _WRAPPER_INSTANCE_HXX + +struct libvlc_instance_t; + +namespace VLC +{ + class Instance + { + public: + Instance( int argc, const char * const *argv ); + virtual ~Instance(); + + inline operator libvlc_instance_t*() + { + return mInstance; + } + + private: + libvlc_instance_t *mInstance; + }; +} + +#endif +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit