summaryrefslogtreecommitdiff
path: root/avmedia/source/win/framegrabber.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'avmedia/source/win/framegrabber.cxx')
-rw-r--r--avmedia/source/win/framegrabber.cxx51
1 files changed, 17 insertions, 34 deletions
diff --git a/avmedia/source/win/framegrabber.cxx b/avmedia/source/win/framegrabber.cxx
index 3b03c68e4e67..84e9d1b187e8 100644
--- a/avmedia/source/win/framegrabber.cxx
+++ b/avmedia/source/win/framegrabber.cxx
@@ -38,9 +38,10 @@
#include <vcl/graph.hxx>
#include <vcl/dibtools.hxx>
#include <o3tl/char16_t2wchar_t.hxx>
+#include <systools/win32/oleauto.hxx>
-#define AVMEDIA_WIN_FRAMEGRABBER_IMPLEMENTATIONNAME "com.sun.star.comp.avmedia.FrameGrabber_DirectX"
-#define AVMEDIA_WIN_FRAMEGRABBER_SERVICENAME "com.sun.star.media.FrameGrabber_DirectX"
+constexpr OUStringLiteral AVMEDIA_WIN_FRAMEGRABBER_IMPLEMENTATIONNAME = u"com.sun.star.comp.avmedia.FrameGrabber_DirectX";
+constexpr OUString AVMEDIA_WIN_FRAMEGRABBER_SERVICENAME = u"com.sun.star.media.FrameGrabber_DirectX"_ustr;
using namespace ::com::sun::star;
@@ -48,39 +49,29 @@ namespace avmedia::win {
FrameGrabber::FrameGrabber()
+ : sal::systools::CoInitializeGuard(COINIT_APARTMENTTHREADED, false,
+ sal::systools::CoInitializeGuard::WhenFailed::NoThrow)
{
- ::CoInitializeEx( nullptr, COINIT_APARTMENTTHREADED );
}
-FrameGrabber::~FrameGrabber()
-{
- ::CoUninitialize();
-}
+FrameGrabber::~FrameGrabber() = default;
namespace {
-IMediaDet* implCreateMediaDet( const OUString& rURL )
+sal::systools::COMReference<IMediaDet> implCreateMediaDet( const OUString& rURL )
{
- IMediaDet* pDet = nullptr;
+ sal::systools::COMReference<IMediaDet> pDet;
- if( SUCCEEDED( CoCreateInstance( CLSID_MediaDet, nullptr, CLSCTX_INPROC_SERVER, IID_IMediaDet, reinterpret_cast<void**>(&pDet) ) ) )
+ if( SUCCEEDED(pDet.CoCreateInstance(CLSID_MediaDet, nullptr, CLSCTX_INPROC_SERVER)) )
{
OUString aLocalStr;
if( osl::FileBase::getSystemPathFromFileURL( rURL, aLocalStr )
== osl::FileBase::E_None )
{
- BSTR bstrFilename = SysAllocString(o3tl::toW(aLocalStr.getStr()));
- if( !SUCCEEDED( pDet->put_Filename( bstrFilename ) ) )
- {
- // Shouldn't we free this string unconditionally, not only in case of failure?
- // I cannot find information why do we pass a newly allocated BSTR to the put_Filename
- // and if it frees the string internally
- SysFreeString(bstrFilename);
- pDet->Release();
- pDet = nullptr;
- }
+ if( !SUCCEEDED( pDet->put_Filename(sal::systools::BStr(aLocalStr)) ) )
+ pDet.clear();
}
}
@@ -92,14 +83,8 @@ IMediaDet* implCreateMediaDet( const OUString& rURL )
bool FrameGrabber::create( const OUString& rURL )
{
// just check if a MediaDet interface can be created with the given URL
- IMediaDet* pDet = implCreateMediaDet( rURL );
-
- if( pDet )
- {
+ if (implCreateMediaDet(rURL))
maURL = rURL;
- pDet->Release();
- pDet = nullptr;
- }
else
maURL.clear();
@@ -110,9 +95,7 @@ bool FrameGrabber::create( const OUString& rURL )
uno::Reference< graphic::XGraphic > SAL_CALL FrameGrabber::grabFrame( double fMediaTime )
{
uno::Reference< graphic::XGraphic > xRet;
- IMediaDet* pDet = implCreateMediaDet( maURL );
-
- if( pDet )
+ if (sal::systools::COMReference<IMediaDet> pDet = implCreateMediaDet(maURL))
{
double fLength;
long nStreamCount;
@@ -138,7 +121,8 @@ uno::Reference< graphic::XGraphic > SAL_CALL FrameGrabber::grabFrame( double fMe
( fLength > 0.0 ) && ( fMediaTime >= 0.0 ) && ( fMediaTime <= fLength ) )
{
AM_MEDIA_TYPE aMediaType;
- long nWidth = 0, nHeight = 0, nSize = 0;
+ LONG nWidth = 0, nHeight = 0;
+ long nSize = 0;
if( SUCCEEDED( pDet->get_StreamMediaType( &aMediaType ) ) )
{
@@ -183,7 +167,8 @@ uno::Reference< graphic::XGraphic > SAL_CALL FrameGrabber::grabFrame( double fMe
if( ReadDIB(aBmp, aMemStm, false ) && !aBmp.IsEmpty() )
{
- const Graphic aGraphic( aBmp );
+ BitmapEx aBitmapEx(aBmp);
+ Graphic aGraphic(aBitmapEx);
xRet = aGraphic.GetXGraphic();
}
}
@@ -193,8 +178,6 @@ uno::Reference< graphic::XGraphic > SAL_CALL FrameGrabber::grabFrame( double fMe
}
}
}
-
- pDet->Release();
}
return xRet;