1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 #include <boost/bind.hpp>
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
;
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
[] = {
35 "--snapshot-format=png",
36 "--ffmpeg-threads", /* Is deprecated in 2.1.0 */
42 VLCFrameGrabber::VLCFrameGrabber( wrapper::EventHandler
& eh
, const rtl::OUString
& url
)
44 , mInstance( sizeof( VLC_ARGS
) / sizeof( VLC_ARGS
[0] ), VLC_ARGS
)
45 , mMedia( url
, mInstance
)
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
);
70 const TimeValue timeout
= {2, 0};
72 condition
.wait(&timeout
);
74 if ( !mPlayer
.hasVout() )
76 SAL_WARN("avmedia", "Couldn't grab frame");
78 return ::uno::Reference
< css::graphic::XGraphic
>();
81 mPlayer
.takeSnapshot( fileName
);
88 utl::LocalFileHelper::ConvertPhysicalNameToURL( fileName
, url
);
89 boost::shared_ptr
<SvStream
> stream( utl::UcbStreamHelper::CreateStream( url
,
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
;
121 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */