summaryrefslogtreecommitdiffstats
path: root/avmedia
diff options
context:
space:
mode:
authorMinh Ngo <nlminhtl@gmail.com>2013-08-06 00:56:33 +0300
committerMichael Meeks <michael.meeks@suse.com>2013-08-21 10:54:51 +0100
commitd160838b234c75455e26a91c65135cf1381e507a (patch)
tree6a424176030fafd93a3edf034cd909ce635b12a3 /avmedia
parentMedia wrapper (diff)
downloadcore-d160838b234c75455e26a91c65135cf1381e507a.tar.gz
core-d160838b234c75455e26a91c65135cf1381e507a.zip
VLC Player wrapper
Change-Id: I507bbfb0426d003eca7cf0a3331128f8af1aee89
Diffstat (limited to 'avmedia')
-rw-r--r--avmedia/Library_avmediavlc.mk1
-rw-r--r--avmedia/source/vlc/vlcframegrabber.cxx30
-rw-r--r--avmedia/source/vlc/vlcframegrabber.hxx9
-rw-r--r--avmedia/source/vlc/vlcplayer.cxx39
-rw-r--r--avmedia/source/vlc/vlcplayer.hxx3
-rw-r--r--avmedia/source/vlc/wrapper/Media.cxx2
-rw-r--r--avmedia/source/vlc/wrapper/Media.hxx2
-rw-r--r--avmedia/source/vlc/wrapper/Player.cxx147
-rw-r--r--avmedia/source/vlc/wrapper/Player.hxx72
-rw-r--r--avmedia/source/vlc/wrapper/SymbolLoader.hxx6
10 files changed, 268 insertions, 43 deletions
diff --git a/avmedia/Library_avmediavlc.mk b/avmedia/Library_avmediavlc.mk
index a04237b77a91..0f8b0390bef9 100644
--- a/avmedia/Library_avmediavlc.mk
+++ b/avmedia/Library_avmediavlc.mk
@@ -47,6 +47,7 @@ $(eval $(call gb_Library_add_exception_objects,avmediavlc,\
avmedia/source/vlc/vlcframegrabber \
avmedia/source/vlc/wrapper/Instance \
avmedia/source/vlc/wrapper/Media \
+ avmedia/source/vlc/wrapper/Player \
))
# vim: set noet sw=4 ts=4:
diff --git a/avmedia/source/vlc/vlcframegrabber.cxx b/avmedia/source/vlc/vlcframegrabber.cxx
index 4630f15c2f79..4e0eaf92b0f5 100644
--- a/avmedia/source/vlc/vlcframegrabber.cxx
+++ b/avmedia/source/vlc/vlcframegrabber.cxx
@@ -10,9 +10,9 @@
#include "vlcframegrabber.hxx"
#include "vlcplayer.hxx"
+#include "wrapper/Player.hxx"
#include <vlc/libvlc_events.h>
-#include <vlc/libvlc_media_player.h>
using namespace ::com::sun::star;
@@ -23,7 +23,7 @@ const ::rtl::OUString AVMEDIA_VLC_GRABBER_IMPLEMENTATIONNAME = "com.sun.star.com
const ::rtl::OUString AVMEDIA_VLC_GRABBER_SERVICENAME = "com.sun.star.media.VLCFrameGrabber_VLC";
const int MSEC_IN_SEC = 1000;
-SAL_CALL VLCFrameGrabber::VLCFrameGrabber( boost::shared_ptr<libvlc_media_player_t>& player, const rtl::OUString& url )
+SAL_CALL VLCFrameGrabber::VLCFrameGrabber( VLC::Player& player, const rtl::OUString& url )
: FrameGrabber_BASE()
, mPlayer( player )
, mUrl( url )
@@ -48,38 +48,38 @@ namespace
{
osl::Condition condition;
- libvlc_media_player_t *player = mPlayer.get();
- libvlc_event_manager_t *manager = libvlc_media_player_event_manager( player );
+ libvlc_event_manager_t *manager = libvlc_media_player_event_manager( mPlayer );
libvlc_event_attach( manager, libvlc_MediaPlayerPaused, EventHandler, &condition );
- libvlc_audio_set_mute( player, true );
- if ( libvlc_media_player_play( player ) == -1 )
+ mPlayer.setMute( true );
+
+ if ( !mPlayer.play() )
{
std::cerr << "Couldn't play" << std::endl;
}
- libvlc_media_player_set_time( player, ( fMediaTime > 0 ? fMediaTime : 0 ) * MSEC_IN_SEC );
+ mPlayer.setTime( ( fMediaTime > 0 ? fMediaTime : 0 ) * MSEC_IN_SEC );
+ mPlayer.pause();
- libvlc_media_player_pause( player );
const TimeValue timeout = {2, 0};
condition.wait(&timeout);
- if ( mUrl.isEmpty() || !libvlc_media_player_has_vout( player ) )
+ if ( mUrl.isEmpty() || !mPlayer.hasVout() )
{
std::cerr << "Couldn't grab frame" << std::endl;
- libvlc_audio_set_mute( player, false );
+ mPlayer.setMute( false );
libvlc_event_detach( manager, libvlc_MediaPlayerPaused, EventHandler, &condition );
return ::uno::Reference< css::graphic::XGraphic >();
}
const rtl::OUString& fileName = utl::TempFile::CreateTempName();
- rtl::OString dest;
- fileName.convertToString( &dest, RTL_TEXTENCODING_UTF8, 0 );
- libvlc_video_take_snapshot( player, 0, dest.getStr(), 0, 0 );
- libvlc_audio_set_mute( player, false );
- libvlc_media_player_stop( player );
+ mPlayer.takeSnapshot( fileName );
+
+ mPlayer.setMute( false );
+ mPlayer.stop();
+
libvlc_event_detach( manager, libvlc_MediaPlayerPaused, EventHandler, &condition );
rtl::OUString url;
diff --git a/avmedia/source/vlc/vlcframegrabber.hxx b/avmedia/source/vlc/vlcframegrabber.hxx
index 7b83a1c8a6f9..53dce41bcea0 100644
--- a/avmedia/source/vlc/vlcframegrabber.hxx
+++ b/avmedia/source/vlc/vlcframegrabber.hxx
@@ -25,7 +25,10 @@
#include <cppuhelper/implbase2.hxx>
#include "vlccommon.hxx"
-struct libvlc_media_player_t;
+namespace VLC
+{
+ class Player;
+}
namespace avmedia {
namespace vlc {
@@ -35,10 +38,10 @@ typedef ::cppu::WeakImplHelper2< ::com::sun::star::media::XFrameGrabber,
class VLCFrameGrabber : public FrameGrabber_BASE
{
- boost::shared_ptr<libvlc_media_player_t> mPlayer;
+ VLC::Player& mPlayer;
const rtl::OUString& mUrl;
public:
- SAL_CALL VLCFrameGrabber( boost::shared_ptr<libvlc_media_player_t>& player, const rtl::OUString& url );
+ SAL_CALL VLCFrameGrabber( VLC::Player& player, const rtl::OUString& url );
::com::sun::star::uno::Reference< css::graphic::XGraphic > SAL_CALL grabFrame( double fMediaTime );
diff --git a/avmedia/source/vlc/vlcplayer.cxx b/avmedia/source/vlc/vlcplayer.cxx
index f3e3f6924d45..2bf15fbd4321 100644
--- a/avmedia/source/vlc/vlcplayer.cxx
+++ b/avmedia/source/vlc/vlcplayer.cxx
@@ -27,7 +27,7 @@ VLCPlayer::VLCPlayer( const rtl::OUString& url )
: VLC_Base(m_aMutex)
, mInstance( VLC_ARGS )
, mMedia( url, mInstance )
- , mPlayer( libvlc_media_player_new_from_media( mMedia ), libvlc_media_player_release )
+ , mPlayer( mMedia )
, mUrl( url )
, mPlaybackLoop( false )
{
@@ -41,49 +41,49 @@ const rtl::OUString& VLCPlayer::url() const
void SAL_CALL VLCPlayer::start()
{
::osl::MutexGuard aGuard(m_aMutex);
- libvlc_media_player_play( mPlayer.get() );
+ mPlayer.play();
}
void SAL_CALL VLCPlayer::stop()
{
::osl::MutexGuard aGuard(m_aMutex);
- libvlc_media_player_pause( mPlayer.get() );
+ mPlayer.pause();
}
::sal_Bool SAL_CALL VLCPlayer::isPlaying()
{
::osl::MutexGuard aGuard(m_aMutex);
- return (libvlc_media_player_is_playing( mPlayer.get() ) == 1);
+ return mPlayer.isPlaying();
}
double SAL_CALL VLCPlayer::getDuration()
{
::osl::MutexGuard aGuard(m_aMutex);
- return static_cast<double>( libvlc_media_player_get_length( mPlayer.get() ) ) / MS_IN_SEC;
+ return static_cast<double>( mPlayer.getLength() ) / MS_IN_SEC;
}
void SAL_CALL VLCPlayer::setMediaTime( double fTime )
{
::osl::MutexGuard aGuard(m_aMutex);
- if ( fTime < 0.00000001 && !libvlc_media_player_is_playing( mPlayer.get() ) )
+ if ( fTime < 0.00000001 && !mPlayer.isPlaying() )
{
- libvlc_media_player_stop( mPlayer.get() );
+ mPlayer.stop();
}
- libvlc_media_player_set_time( mPlayer.get(), fTime * MS_IN_SEC );
+ mPlayer.setTime( fTime * MS_IN_SEC );
}
double SAL_CALL VLCPlayer::getMediaTime()
{
::osl::MutexGuard aGuard(m_aMutex);
- return static_cast<double>( libvlc_media_player_get_time( mPlayer.get() ) ) / MS_IN_SEC;
+ return static_cast<double>( mPlayer.getTime() ) / MS_IN_SEC;
}
double SAL_CALL VLCPlayer::getRate()
{
::osl::MutexGuard aGuard(m_aMutex);
- return libvlc_media_player_get_rate( mPlayer.get() );
+ return mPlayer.getRate();
}
namespace
@@ -93,9 +93,10 @@ namespace
switch (evemt->type)
{
case libvlc_MediaPlayerEndReached:
- boost::shared_ptr<libvlc_media_player_t> player = *static_cast< boost::shared_ptr<libvlc_media_player_t>* >( pData );
- libvlc_media_player_stop( player.get() );
- libvlc_media_player_play( player.get() );
+ VLC::Player& player = *static_cast< VLC::Player* >( pData );
+
+ player.stop();
+ player.play();
break;
}
}
@@ -106,7 +107,7 @@ void SAL_CALL VLCPlayer::setPlaybackLoop( ::sal_Bool bSet )
::osl::MutexGuard aGuard(m_aMutex);
mPlaybackLoop = bSet;
- libvlc_event_manager_t *manager = libvlc_media_player_event_manager( mPlayer.get() );
+ libvlc_event_manager_t *manager = libvlc_media_player_event_manager( mPlayer );
if ( bSet )
libvlc_event_attach( manager, libvlc_MediaPlayerEndReached, EventHandler, &mPlayer );
@@ -123,25 +124,25 @@ void SAL_CALL VLCPlayer::setPlaybackLoop( ::sal_Bool bSet )
void SAL_CALL VLCPlayer::setVolumeDB( ::sal_Int16 nDB )
{
::osl::MutexGuard aGuard(m_aMutex);
- libvlc_audio_set_volume( mPlayer.get(), static_cast<sal_Int16>( ( nDB + 40 ) * 10.0 / 4 ) );
+ mPlayer.setVolume( static_cast<sal_Int16>( ( nDB + 40 ) * 10.0 / 4 ) );
}
::sal_Int16 SAL_CALL VLCPlayer::getVolumeDB()
{
::osl::MutexGuard aGuard(m_aMutex);
- return static_cast<sal_Int16>( libvlc_audio_get_volume( mPlayer.get() ) / 10.0 * 4 - 40 );
+ return static_cast<sal_Int16>( mPlayer.getVolume() / 10.0 * 4 - 40 );
}
void SAL_CALL VLCPlayer::setMute( ::sal_Bool bSet )
{
::osl::MutexGuard aGuard(m_aMutex);
- libvlc_audio_set_mute( mPlayer.get(), bSet );
+ mPlayer.setMute( bSet );
}
::sal_Bool SAL_CALL VLCPlayer::isMute()
{
::osl::MutexGuard aGuard(m_aMutex);
- return libvlc_audio_get_mute( mPlayer.get() );
+ return mPlayer.getMute();
}
css::awt::Size SAL_CALL VLCPlayer::getPreferredPlayerWindowSize()
@@ -189,7 +190,7 @@ uno::Reference< css::media::XPlayerWindow > SAL_CALL VLCPlayer::createPlayerWind
#if defined(WIN32) && !defined(UNIX)
//TODO: Not works, will be crashed
#else
- libvlc_media_player_set_xwindow( mPlayer.get(), winID );
+ mPlayer.setXWindow( winID );
#endif
}
diff --git a/avmedia/source/vlc/vlcplayer.hxx b/avmedia/source/vlc/vlcplayer.hxx
index e8d3fd0b9e08..230b21906781 100644
--- a/avmedia/source/vlc/vlcplayer.hxx
+++ b/avmedia/source/vlc/vlcplayer.hxx
@@ -29,6 +29,7 @@
#include "wrapper/Instance.hxx"
#include "wrapper/Media.hxx"
+#include "wrapper/Player.hxx"
namespace avmedia {
namespace vlc {
@@ -41,7 +42,7 @@ class VLCPlayer : public ::cppu::BaseMutex,
{
VLC::Instance mInstance;
VLC::Media mMedia;
- boost::shared_ptr<libvlc_media_player_t> mPlayer;
+ VLC::Player mPlayer;
const rtl::OUString mUrl;
bool mPlaybackLoop;
public:
diff --git a/avmedia/source/vlc/wrapper/Media.cxx b/avmedia/source/vlc/wrapper/Media.cxx
index d2cf5c1b6c6c..851a4f5af49a 100644
--- a/avmedia/source/vlc/wrapper/Media.cxx
+++ b/avmedia/source/vlc/wrapper/Media.cxx
@@ -28,7 +28,7 @@ namespace VLC
}
-Media::Media(const rtl::OUString& url, Instance& instance)
+Media::Media( const rtl::OUString& url, Instance& instance )
{
InitApiMap(VLC_MEDIA_API);
mMedia = InitMedia( url, instance );
diff --git a/avmedia/source/vlc/wrapper/Media.hxx b/avmedia/source/vlc/wrapper/Media.hxx
index cbeef02952c4..b513943610bc 100644
--- a/avmedia/source/vlc/wrapper/Media.hxx
+++ b/avmedia/source/vlc/wrapper/Media.hxx
@@ -32,7 +32,7 @@ namespace VLC
class Media
{
public:
- Media(const rtl::OUString& url, Instance& instance);
+ Media( const rtl::OUString& url, Instance& instance );
virtual ~Media();
inline operator libvlc_media_t*()
diff --git a/avmedia/source/vlc/wrapper/Player.cxx b/avmedia/source/vlc/wrapper/Player.cxx
new file mode 100644
index 000000000000..b67f1b265f5c
--- /dev/null
+++ b/avmedia/source/vlc/wrapper/Player.cxx
@@ -0,0 +1,147 @@
+#include <rtl/ustring.h>
+
+#include "Player.hxx"
+#include "Media.hxx"
+#include "SymbolLoader.hxx"
+
+struct libvlc_media_t;
+namespace VLC
+{
+ namespace
+ {
+ typedef int64_t libvlc_time_t;
+
+ 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 );
+ libvlc_time_t ( *libvlc_media_player_get_length ) ( 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 );
+ void ( *libvlc_media_player_set_xwindow ) ( libvlc_media_player_t *p_mi, uint32_t drawable );
+ unsigned ( *libvlc_media_player_has_vout ) ( libvlc_media_player_t *p_mi );
+
+ ApiMap 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_length ),
+ 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 ),
+ SYM_MAP( libvlc_media_player_set_xwindow ),
+ SYM_MAP( libvlc_media_player_has_vout )
+ };
+ }
+
+ Player::Player(Media& media)
+ {
+ InitApiMap(VLC_PLAYER_API);
+ mPlayer = libvlc_media_player_new_from_media( media );
+ }
+
+ Player::~Player()
+ {
+ libvlc_media_player_release( mPlayer );
+ }
+
+ bool Player::play()
+ {
+ return libvlc_media_player_play( mPlayer );
+ }
+
+ 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
+ {
+ return libvlc_media_player_get_time( mPlayer );
+ }
+
+ bool Player::isPlaying() const
+ {
+ return libvlc_media_player_is_playing( mPlayer ) == 1;
+ }
+
+ int Player::getLength() const
+ {
+ return libvlc_media_player_get_length( mPlayer );
+ }
+
+ float Player::getRate() const
+ {
+ return libvlc_media_player_get_rate( mPlayer );
+ }
+
+ 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::setXWindow( int id )
+ {
+ libvlc_media_player_set_xwindow( mPlayer, id );
+ }
+
+ void Player::takeSnapshot(const rtl::OUString& file)
+ {
+ rtl::OString dest;
+ file.convertToString( &dest, RTL_TEXTENCODING_UTF8, 0 );
+ libvlc_video_take_snapshot( mPlayer, 0, dest.getStr(), 0, 0 );
+ }
+
+ bool Player::hasVout() const
+ {
+ return libvlc_media_player_has_vout( mPlayer );
+ }
+
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ \ No newline at end of file
diff --git a/avmedia/source/vlc/wrapper/Player.hxx b/avmedia/source/vlc/wrapper/Player.hxx
new file mode 100644
index 000000000000..e23acb725c49
--- /dev/null
+++ b/avmedia/source/vlc/wrapper/Player.hxx
@@ -0,0 +1,72 @@
+/* -*- 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_PLAYER_HXX
+#define _WRAPPER_PLAYER_HXX
+
+struct libvlc_media_player_t;
+
+namespace rtl
+{
+ class OUString;
+}
+
+namespace VLC
+{
+ class Media;
+ class Player
+ {
+ public:
+ Player(Media& media);
+ virtual ~Player();
+
+ bool play();
+ void pause();
+ void stop();
+ void setTime( int time );
+ int getTime() const;
+ bool isPlaying() const;
+
+ int getLength() const;
+
+ float getRate() const;
+
+ void setVolume( int volume );
+ int getVolume() const;
+
+ void setMute( bool mute);
+ bool getMute() const;
+
+ void setXWindow( int id );
+
+ void takeSnapshot(const rtl::OUString& file);
+
+ bool hasVout() const;
+
+ inline operator libvlc_media_player_t*()
+ {
+ return mPlayer;
+ }
+
+ private:
+ libvlc_media_player_t *mPlayer;
+ };
+}
+
+#endif
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ \ No newline at end of file
diff --git a/avmedia/source/vlc/wrapper/SymbolLoader.hxx b/avmedia/source/vlc/wrapper/SymbolLoader.hxx
index 5e61258a798f..0962a3e92894 100644
--- a/avmedia/source/vlc/wrapper/SymbolLoader.hxx
+++ b/avmedia/source/vlc/wrapper/SymbolLoader.hxx
@@ -39,8 +39,8 @@ namespace
"libvlccore.so.5"
};
- template<size_t N> static bool
- tryLink( oslModule &aModule, const char *pName, const ApiMap ( &pMap )[N] )
+ template<size_t N>
+ bool tryLink( oslModule &aModule, const ApiMap ( &pMap )[N] )
{
for (uint i = 0; i < N; ++i)
{
@@ -70,7 +70,7 @@ bool InitApiMap( const ApiMap ( &pMap )[N] )
if( aModule == NULL)
continue;
- tryLink( aModule, libNames[ j ], pMap );
+ tryLink( aModule, pMap );
osl_unloadModule( aModule );
}