36#include <osl/file.hxx>
41#include <systools/win32/oleauto.hxx>
52 :
sal::systools::CoInitializeGuard(COINIT_APARTMENTTHREADED, false,
53 sal::systools::CoInitializeGuard::WhenFailed::NoThrow)
62sal::systools::COMReference<IMediaDet> implCreateMediaDet(
const OUString& rURL )
64 sal::systools::COMReference<IMediaDet> pDet;
66 if( SUCCEEDED(pDet.CoCreateInstance(
CLSID_MediaDet,
nullptr, CLSCTX_INPROC_SERVER)) )
70 if( osl::FileBase::getSystemPathFromFileURL( rURL, aLocalStr )
71 == osl::FileBase::E_None )
73 if( !SUCCEEDED( pDet->put_Filename(sal::systools::BStr(aLocalStr)) ) )
86 if (implCreateMediaDet(rURL))
91 return !
maURL.isEmpty();
97 uno::Reference< graphic::XGraphic > xRet;
98 if (sal::systools::COMReference<IMediaDet> pDet = implCreateMediaDet(
maURL))
104 if( SUCCEEDED( pDet->get_OutputStreams( &nStreamCount ) ) )
106 for(
long n = 0; (
n < nStreamCount ) && !bFound; ++
n )
110 if( SUCCEEDED( pDet->put_CurrentStream(
n ) ) &&
111 SUCCEEDED( pDet->get_StreamType( &aMajorType ) ) &&
112 ( aMajorType == MEDIATYPE_Video ) )
120 ( S_OK == pDet->get_StreamLength( &fLength ) ) &&
121 ( fLength > 0.0 ) && ( fMediaTime >= 0.0 ) && ( fMediaTime <= fLength ) )
123 AM_MEDIA_TYPE aMediaType;
124 LONG nWidth = 0, nHeight = 0;
127 if( SUCCEEDED( pDet->get_StreamMediaType( &aMediaType ) ) )
129 if( ( aMediaType.formattype == FORMAT_VideoInfo ) &&
130 ( aMediaType.cbFormat >=
sizeof( VIDEOINFOHEADER ) ) )
132 VIDEOINFOHEADER* pVih =
reinterpret_cast< VIDEOINFOHEADER*
>( aMediaType.pbFormat );
134 nWidth = pVih->bmiHeader.biWidth;
135 nHeight = pVih->bmiHeader.biHeight;
141 if( aMediaType.cbFormat != 0 )
143 ::CoTaskMemFree( aMediaType.pbFormat );
144 aMediaType.cbFormat = 0;
145 aMediaType.pbFormat =
nullptr;
148 if( aMediaType.pUnk !=
nullptr )
150 aMediaType.pUnk->Release();
151 aMediaType.pUnk =
nullptr;
155 if( ( nWidth > 0 ) && ( nHeight > 0 ) &&
156 SUCCEEDED( pDet->GetBitmapBits( 0, &nSize,
nullptr, nWidth, nHeight ) ) &&
159 auto pBuffer = std::make_unique<char[]>(nSize);
163 if( SUCCEEDED( pDet->GetBitmapBits( fMediaTime,
nullptr, pBuffer.get(), nWidth, nHeight ) ) )
165 SvMemoryStream aMemStm( pBuffer.get(), nSize, StreamMode::READ | StreamMode::WRITE );
css::uno::Reference< css::graphic::XGraphic > GetXGraphic() const
constexpr OUStringLiteral AVMEDIA_WIN_FRAMEGRABBER_IMPLEMENTATIONNAME
constexpr OUStringLiteral AVMEDIA_WIN_FRAMEGRABBER_SERVICENAME
const CLSID CLSID_MediaDet
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)