fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / avmedia / source / vlc / vlcframegrabber.cxx
blob05a27c28c2955c7c0ede1d270b74895447cde423
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 #include <boost/bind.hpp>
3 #include <iostream>
4 #include <osl/conditn.hxx>
5 #include <vcl/graph.hxx>
6 #include <vcl/bmpacc.hxx>
7 #include <vcl/pngread.hxx>
8 #include <avmedia/mediawindow.hxx>
9 #include <unotools/localfilehelper.hxx>
10 #include <unotools/tempfile.hxx>
11 #include <unotools/ucbstreamhelper.hxx>
12 #include <tools/stream.hxx>
13 #include <cppuhelper/supportsservice.hxx>
15 #include "vlcframegrabber.hxx"
16 #include "vlcplayer.hxx"
17 #include "wrapper/Player.hxx"
18 #include "wrapper/EventManager.hxx"
20 using namespace ::com::sun::star;
22 namespace avmedia {
23 namespace vlc {
25 namespace
27 const ::rtl::OUString AVMEDIA_VLC_GRABBER_IMPLEMENTATIONNAME = "com.sun.star.comp.avmedia.VLCFrameGrabber_VLC";
28 const ::rtl::OUString AVMEDIA_VLC_GRABBER_SERVICENAME = "com.sun.star.media.VLCFrameGrabber_VLC";
29 const int MSEC_IN_SEC = 1000;
31 const char * const VLC_ARGS[] = {
32 "-Vdummy",
33 "--demux",
34 "ffmpeg",
35 "--snapshot-format=png",
36 "--ffmpeg-threads", /* Is deprecated in 2.1.0 */
37 "--verbose=-1",
38 "--no-audio"
42 VLCFrameGrabber::VLCFrameGrabber( wrapper::EventHandler& eh, const rtl::OUString& url )
43 : FrameGrabber_BASE()
44 , mInstance( sizeof( VLC_ARGS ) / sizeof( VLC_ARGS[0] ), VLC_ARGS )
45 , mMedia( url, mInstance )
46 , mPlayer( mMedia )
47 , mEventHandler( eh )
51 ::uno::Reference< css::graphic::XGraphic > SAL_CALL VLCFrameGrabber::grabFrame( double fMediaTime )
52 throw ( ::com::sun::star::uno::RuntimeException, std::exception )
54 osl::Condition condition;
56 const rtl::OUString& fileName = utl::TempFile::CreateTempName();
58 wrapper::EventManager manager( mPlayer, mEventHandler );
59 manager.onPaused(boost::bind(&osl::Condition::set, &condition));
61 if ( !mPlayer.play() )
63 SAL_WARN("avmedia", "Couldn't play when trying to grab frame");
64 return ::uno::Reference< css::graphic::XGraphic >();
67 mPlayer.setTime( ( fMediaTime > 0 ? fMediaTime : 0 ) * MSEC_IN_SEC );
68 mPlayer.pause();
70 const TimeValue timeout = {2, 0};
72 condition.wait(&timeout);
74 if ( !mPlayer.hasVout() )
76 SAL_WARN("avmedia", "Couldn't grab frame");
77 manager.onPaused();
78 return ::uno::Reference< css::graphic::XGraphic >();
81 mPlayer.takeSnapshot( fileName );
82 mPlayer.stop();
84 manager.onPaused();
87 rtl::OUString url;
88 utl::LocalFileHelper::ConvertPhysicalNameToURL( fileName, url );
89 boost::shared_ptr<SvStream> stream( utl::UcbStreamHelper::CreateStream( url,
90 STREAM_STD_READ ) );
92 vcl::PNGReader reader( *stream );
94 const BitmapEx& bitmap = reader.Read();
96 return Graphic( bitmap ).GetXGraphic();
99 ::rtl::OUString SAL_CALL VLCFrameGrabber::getImplementationName() throw ( ::com::sun::star::uno::RuntimeException, std::exception )
101 return AVMEDIA_VLC_GRABBER_IMPLEMENTATIONNAME;
104 sal_Bool SAL_CALL VLCFrameGrabber::supportsService( const ::rtl::OUString& serviceName )
105 throw ( ::com::sun::star::uno::RuntimeException, std::exception )
107 return cppu::supportsService(this, serviceName);
110 ::uno::Sequence< ::rtl::OUString > SAL_CALL VLCFrameGrabber::getSupportedServiceNames()
111 throw ( ::com::sun::star::uno::RuntimeException, std::exception )
113 ::uno::Sequence< OUString > aRet(1);
114 aRet[0] = AVMEDIA_VLC_GRABBER_SERVICENAME;
115 return aRet;
121 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */