summaryrefslogtreecommitdiff
path: root/avmedia
diff options
context:
space:
mode:
authorMinh Ngo <nlminhtl@gmail.com>2013-07-29 23:47:20 +0300
committerMichael Meeks <michael.meeks@suse.com>2013-08-21 10:54:49 +0100
commit569533275a23faa774f6b1c972ff99d872ea8da9 (patch)
treecc6e8c7e6fa229535cc7d8de588a037adcdd7d98 /avmedia
parent872b10fe417a4ff06a14cff0de0ebea9fd12ac4a (diff)
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
Diffstat (limited to 'avmedia')
-rw-r--r--avmedia/Library_avmediavlc.mk1
-rw-r--r--avmedia/source/vlc/vlcframegrabber.cxx72
2 files changed, 67 insertions, 6 deletions
diff --git a/avmedia/Library_avmediavlc.mk b/avmedia/Library_avmediavlc.mk
index 06fb035aab74..f17b18cd2b59 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 a18919095b99..efabd3904e3c 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()