avmedia/source/win/framegrabber.cxx |   24 ++++----------
 avmedia/source/win/player.cxx       |   58 ++++--------------------------------
 avmedia/source/win/player.hxx       |   20 ++++--------
 3 files changed, 23 insertions(+), 79 deletions(-)

New commits:
commit 00eb9b8954a129fb365191ce8cdcbc4cf66a7333
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Mon Dec 20 10:12:13 2021 +0300
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Mon Dec 20 09:22:09 2021 +0100

    Use more sal::systools::COMReference
    
    Change-Id: I29bf304d90db968682c2b0791372d0ea41375096
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127132
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/avmedia/source/win/framegrabber.cxx 
b/avmedia/source/win/framegrabber.cxx
index 6ed07a87935a..b7109b251497 100644
--- a/avmedia/source/win/framegrabber.cxx
+++ b/avmedia/source/win/framegrabber.cxx
@@ -38,6 +38,7 @@
 #include <vcl/graph.hxx>
 #include <vcl/dibtools.hxx>
 #include <o3tl/char16_t2wchar_t.hxx>
+#include <systools/win32/comtools.hxx>
 
 constexpr OUStringLiteral AVMEDIA_WIN_FRAMEGRABBER_IMPLEMENTATIONNAME = 
u"com.sun.star.comp.avmedia.FrameGrabber_DirectX";
 constexpr OUStringLiteral AVMEDIA_WIN_FRAMEGRABBER_SERVICENAME = 
u"com.sun.star.media.FrameGrabber_DirectX";
@@ -60,11 +61,11 @@ FrameGrabber::~FrameGrabber()
 
 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( pDet.CoCreateInstance(CLSID_MediaDet, nullptr, CLSCTX_INPROC_SERVER) )
     {
         OUString aLocalStr;
 
@@ -78,8 +79,7 @@ IMediaDet* implCreateMediaDet( const OUString& rURL )
                 // 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;
+                pDet.clear();
             }
         }
     }
@@ -92,14 +92,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 +104,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;
@@ -195,8 +187,6 @@ uno::Reference< graphic::XGraphic > SAL_CALL 
FrameGrabber::grabFrame( double fMe
                 }
             }
         }
-
-        pDet->Release();
     }
 
     return xRet;
diff --git a/avmedia/source/win/player.cxx b/avmedia/source/win/player.cxx
index 4d764d4a4fa6..ab2c9c8eb20d 100644
--- a/avmedia/source/win/player.cxx
+++ b/avmedia/source/win/player.cxx
@@ -64,16 +64,6 @@ static LRESULT CALLBACK MediaPlayerWndProc_2( HWND hWnd,UINT 
nMsg, WPARAM nPar1,
 
 Player::Player() :
     Player_BASE(m_aMutex),
-    mpGB( nullptr ),
-    mpOMF( nullptr ),
-    mpMC( nullptr ),
-    mpME( nullptr ),
-    mpMS( nullptr ),
-    mpMP( nullptr ),
-    mpBA( nullptr ),
-    mpBV( nullptr ),
-    mpVW( nullptr ),
-    mpEV( nullptr ),
     mnUnmutedVolume( 0 ),
     mnFrameWnd( nullptr ),
     mbMuted( false ),
@@ -97,47 +87,16 @@ void SAL_CALL Player::disposing()
 {
     ::osl::MutexGuard aGuard(m_aMutex);
     stop();
-    if( mpBA )
-        mpBA->Release();
-
-    if( mpBV )
-        mpBV->Release();
-
-    if( mpVW )
-        mpVW->Release();
-
-    if( mpMP )
-        mpMP->Release();
-
-    if( mpMS )
-        mpMS->Release();
-
     if( mpME )
-    {
         mpME->SetNotifyWindow( 0, WM_GRAPHNOTIFY, 0);
-        mpME->Release();
-    }
-
-    if( mpMC )
-        mpMC->Release();
-
-    if( mpEV )
-        mpEV->Release();
-
-    if( mpOMF )
-        mpOMF->Release();
-
-    if( mpGB )
-        mpGB->Release();
 }
 
 
 bool Player::create( const OUString& rURL )
 {
-    HRESULT hR;
     bool    bRet = false;
 
-    if( SUCCEEDED( hR = CoCreateInstance( CLSID_FilterGraph, nullptr, 
CLSCTX_INPROC_SERVER, IID_IGraphBuilder, reinterpret_cast<void**>(&mpGB) ) ) )
+    if( mpGB.CoCreateInstance(CLSID_FilterGraph, nullptr, 
CLSCTX_INPROC_SERVER) )
     {
         // Don't use the overlay mixer on Windows Vista
         // It disables the desktop composition as soon as RenderFile is called
@@ -149,18 +108,17 @@ bool Player::create( const OUString& rURL )
         if (aFile.startsWithIgnoreAsciiCase("file:"))
             osl::FileBase::getSystemPathFromFileURL(rURL, aFile);
 
-        if( SUCCEEDED( hR = mpGB->RenderFile( o3tl::toW(aFile.getStr()), 
nullptr ) ) &&
-            SUCCEEDED( hR = mpGB->QueryInterface( IID_IMediaControl, 
reinterpret_cast<void**>(&mpMC) ) ) &&
-            SUCCEEDED( hR = mpGB->QueryInterface( IID_IMediaEventEx, 
reinterpret_cast<void**>(&mpME) ) ) &&
-            SUCCEEDED( hR = mpGB->QueryInterface( IID_IMediaSeeking, 
reinterpret_cast<void**>(&mpMS) ) ) &&
-            SUCCEEDED( hR = mpGB->QueryInterface( IID_IMediaPosition, 
reinterpret_cast<void**>(&mpMP) ) ) )
+        if( SUCCEEDED( mpGB->RenderFile( o3tl::toW(aFile.getStr()), nullptr ) 
) &&
+            mpMC.set(mpGB, sal::systools::COM_QUERY) &&
+            mpME.set(mpGB, sal::systools::COM_QUERY) &&
+            mpMP.set(mpGB, sal::systools::COM_QUERY) )
         {
             // Video interfaces
-            mpGB->QueryInterface( IID_IVideoWindow, 
reinterpret_cast<void**>(&mpVW) );
-            mpGB->QueryInterface( IID_IBasicVideo, 
reinterpret_cast<void**>(&mpBV) );
+            mpVW.set(mpGB, sal::systools::COM_QUERY);
+            mpBV.set(mpGB, sal::systools::COM_QUERY);
 
             // Audio interface
-            mpGB->QueryInterface( IID_IBasicAudio, 
reinterpret_cast<void**>(&mpBA) );
+            mpBA.set(mpGB, sal::systools::COM_QUERY);
 
             if( mpBA )
                 mpBA->put_Volume( mnUnmutedVolume );
diff --git a/avmedia/source/win/player.hxx b/avmedia/source/win/player.hxx
index 84e2689c0397..20806251c8bc 100644
--- a/avmedia/source/win/player.hxx
+++ b/avmedia/source/win/player.hxx
@@ -29,6 +29,7 @@
 
 #include <cppuhelper/compbase.hxx>
 #include <cppuhelper/basemutex.hxx>
+#include <systools/win32/comtools.hxx>
 
 struct IGraphBuilder;
 struct IBaseFilter;
@@ -92,23 +93,18 @@ public:
 private:
 
     OUString                maURL;
-    IGraphBuilder*          mpGB;
-    IBaseFilter*            mpOMF;
-    IMediaControl*          mpMC;
-    IMediaEventEx*          mpME;
-    IMediaSeeking*          mpMS;
-    IMediaPosition*         mpMP;
-    IBasicAudio*            mpBA;
-    IBasicVideo*            mpBV;
-    IVideoWindow*           mpVW;
-    IDDrawExclModeVideo*    mpEV;
+    sal::systools::COMReference<IGraphBuilder>          mpGB;
+    sal::systools::COMReference<IMediaControl>          mpMC;
+    sal::systools::COMReference<IMediaEventEx>          mpME;
+    sal::systools::COMReference<IMediaPosition>         mpMP;
+    sal::systools::COMReference<IBasicAudio>            mpBA;
+    sal::systools::COMReference<IBasicVideo>            mpBV;
+    sal::systools::COMReference<IVideoWindow>           mpVW;
     long                    mnUnmutedVolume;
     HWND                    mnFrameWnd;
     bool                    mbMuted;
     bool                    mbLooping;
     bool                    mbAddWindow;
-
-    void                    ImplLayoutVideoWindow();
 };
 
 } // namespace avmedia::win

Reply via email to