[Libreoffice-commits] core.git: Branch 'feature/vlc' - 2 commits - avmedia/Library_avmediavlc.mk avmedia/source
Minh Ngo
nlminhtl at gmail.com
Mon Jul 29 13:49:47 PDT 2013
avmedia/Library_avmediavlc.mk | 1
avmedia/source/vlc/vlcframegrabber.cxx | 72 ++++++++++++++++++++++++++++++---
avmedia/source/vlc/vlcmanager.cxx | 9 ++--
avmedia/source/vlc/vlcmanager.hxx | 1
avmedia/source/vlc/vlcplayer.cxx | 13 ++++-
avmedia/source/vlc/vlcplayer.hxx | 2
6 files changed, 86 insertions(+), 12 deletions(-)
New commits:
commit 74f86ac6510189000d5508f81b9f8c20c3f92fa2
Author: Minh Ngo <nlminhtl at gmail.com>
Date: Mon Jul 29 23:49:18 2013 +0300
Optimizing VLC player initialization process.
Manager checks if an URL is the same or empty.
Change-Id: I4ab2db31f73fef45feff1973fa82452dc579ef9d
diff --git a/avmedia/source/vlc/vlcmanager.cxx b/avmedia/source/vlc/vlcmanager.cxx
index 0b2ad6a..a3e762b 100644
--- a/avmedia/source/vlc/vlcmanager.cxx
+++ b/avmedia/source/vlc/vlcmanager.cxx
@@ -21,10 +21,13 @@ Manager::~Manager()
uno::Reference< media::XPlayer > SAL_CALL Manager::createPlayer( const rtl::OUString& rURL )
throw (uno::RuntimeException)
{
- VLCPlayer* pPlayer( new VLCPlayer( rURL/*, mxMgr */ ) );
- uno::Reference< media::XPlayer > xRet( pPlayer );
+ if ( !rURL.isEmpty() || (mPlayer.is() && dynamic_cast<VLCPlayer*>( mPlayer.get() )->url() != rURL))
+ {
+ VLCPlayer* pPlayer( new VLCPlayer( rURL/*, mxMgr */ ) );
+ mPlayer = uno::Reference< media::XPlayer >( pPlayer );
+ }
- return xRet;
+ return mPlayer;
}
rtl::OUString SAL_CALL Manager::getImplementationName()
diff --git a/avmedia/source/vlc/vlcmanager.hxx b/avmedia/source/vlc/vlcmanager.hxx
index 2e81a35..9417480 100644
--- a/avmedia/source/vlc/vlcmanager.hxx
+++ b/avmedia/source/vlc/vlcmanager.hxx
@@ -42,6 +42,7 @@ public:
private:
::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > mxMgr;
+ ::com::sun::star::uno::Reference< ::com::sun::star::media::XPlayer > mPlayer;
};
}
diff --git a/avmedia/source/vlc/vlcplayer.cxx b/avmedia/source/vlc/vlcplayer.cxx
index 34ebb00..c4628ed 100644
--- a/avmedia/source/vlc/vlcplayer.cxx
+++ b/avmedia/source/vlc/vlcplayer.cxx
@@ -14,11 +14,13 @@ 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",
+// "-I",
"-Vdummy",
- "--ignore-config",
+ "--snapshot-format=png",
+// "--ignore-config",
+ "--ffmpeg-threads",
"--verbose=-1",
- "--quiet"
+// "--quiet"
};
const int MS_IN_SEC = 1000; // Millisec in sec
@@ -43,6 +45,11 @@ VLCPlayer::VLCPlayer( const rtl::OUString& url )
{
}
+const rtl::OUString& VLCPlayer::url() const
+{
+ return mUrl;
+}
+
void SAL_CALL VLCPlayer::start()
{
::osl::MutexGuard aGuard(m_aMutex);
diff --git a/avmedia/source/vlc/vlcplayer.hxx b/avmedia/source/vlc/vlcplayer.hxx
index 00a55eb..8113602 100644
--- a/avmedia/source/vlc/vlcplayer.hxx
+++ b/avmedia/source/vlc/vlcplayer.hxx
@@ -44,6 +44,8 @@ class VLCPlayer : public ::cppu::BaseMutex,
public:
VLCPlayer( const rtl::OUString& url );
+ const rtl::OUString& url() const;
+
void SAL_CALL start();
void SAL_CALL stop();
::sal_Bool SAL_CALL isPlaying();
commit f5845bf20f10ae17326879e9b5f6d078e6d86c67
Author: Minh Ngo <nlminhtl at gmail.com>
Date: Mon Jul 29 23:47:20 2013 +0300
Upd frame grabber. Will work with this patch [1][2].
[1] vlc git 5a43de506f31e1fa5460f8b62e25a1d640136597
[2] http://git.videolan.org/gitweb.cgi/vlc.git/?p=vlc.git;a=commitdiff_plain;h=5a43de506f31e1fa5460f8b62e25a1d640136597
Change-Id: I2aa0b4c579ff534e20a425919f0efba59101d7af
diff --git a/avmedia/Library_avmediavlc.mk b/avmedia/Library_avmediavlc.mk
index 06fb035..f17b18c 100644
--- a/avmedia/Library_avmediavlc.mk
+++ b/avmedia/Library_avmediavlc.mk
@@ -35,6 +35,7 @@ $(eval $(call gb_Library_use_libraries,avmediavlc,\
sal \
tl \
vcl \
+ utl \
$(gb_UWINAPI) \
))
diff --git a/avmedia/source/vlc/vlcframegrabber.cxx b/avmedia/source/vlc/vlcframegrabber.cxx
index a189190..efabd39 100644
--- a/avmedia/source/vlc/vlcframegrabber.cxx
+++ b/avmedia/source/vlc/vlcframegrabber.cxx
@@ -1,11 +1,18 @@
#include <osl/conditn.hxx>
-#include <vcl/bmpacc.hxx>
#include <vcl/graph.hxx>
+#include <vcl/bmpacc.hxx>
+#include <vcl/pngread.hxx>
#include <avmedia/mediawindow.hxx>
+#include <unotools/localfilehelper.hxx>
+#include <unotools/tempfile.hxx>
+#include <unotools/ucbstreamhelper.hxx>
+#include <tools/stream.hxx>
+
#include "vlcframegrabber.hxx"
#include "vlcplayer.hxx"
+
+#include <vlc/libvlc_events.h>
#include <vlc/libvlc_media_player.h>
-#include <boost/bind.hpp>
using namespace ::com::sun::star;
@@ -23,15 +30,68 @@ SAL_CALL VLCFrameGrabber::VLCFrameGrabber( boost::shared_ptr<libvlc_media_player
{
}
+namespace
+{
+ void EventHandler( const libvlc_event_t *evemt, void *pData )
+ {
+ switch (evemt->type)
+ {
+ case libvlc_MediaPlayerPaused:
+ osl::Condition *condition = static_cast<osl::Condition*>( pData );
+ condition->set();
+ break;
+ }
+ }
+}
+
::uno::Reference< css::graphic::XGraphic > SAL_CALL VLCFrameGrabber::grabFrame( double fMediaTime )
{
- if ( mUrl.isEmpty() )
+ osl::Condition condition;
+
+ libvlc_media_player_t *player = mPlayer.get();
+ libvlc_event_manager_t *manager = libvlc_media_player_event_manager( player );
+ libvlc_event_attach( manager, libvlc_MediaPlayerPaused, EventHandler, &condition );
+
+ libvlc_audio_set_mute( player, true );
+ if (libvlc_media_player_play( player ) == -1)
+ {
+ std::cerr << "Couldn't play" << std::endl;
+ }
+
+ libvlc_media_player_set_time( player, ( fMediaTime > 0 ? fMediaTime : 0 ) * MSEC_IN_SEC );
+
+ libvlc_media_player_pause( player );
+ const TimeValue timeout = {2, 0};
+ condition.wait(&timeout);
+
+ if ( mUrl.isEmpty() || !libvlc_media_player_has_vout( player ) )
+ {
+ std::cerr << "Couldn't grab frame" << std::endl;
+ libvlc_audio_set_mute( player, 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 );
+ libvlc_event_detach( manager, libvlc_MediaPlayerPaused, EventHandler, &condition );
+
+ rtl::OUString url;
+ utl::LocalFileHelper::ConvertPhysicalNameToURL( fileName, url );
+ boost::shared_ptr<SvStream> stream( utl::UcbStreamHelper::CreateStream( url,
+ STREAM_STD_READ ) );
+
+ vcl::PNGReader reader( *stream );
- // libvlc_video_take_snapshot must be used, but it doesn't work for PNG files
- //
+ const BitmapEx& bitmap = reader.Read();
- return ::uno::Reference< css::graphic::XGraphic >();
+ return Graphic( bitmap ).GetXGraphic();
}
::rtl::OUString SAL_CALL VLCFrameGrabber::getImplementationName()
More information about the Libreoffice-commits
mailing list