1 --- /dev/null 2006-08-13 17:52:05.000000000 +0200
2 +++ avmedia/source/gstreamer/gstframegrabber.cxx 2006-08-22 11:38:56.000000000 +0200
4 +/*************************************************************************
6 + * OpenOffice.org - a multi-platform office productivity suite
12 + * last change: $Author$ $Date$
14 + * The Contents of this file are made available subject to
15 + * the terms of GNU Lesser General Public License Version 2.1.
18 + * GNU Lesser General Public License Version 2.1
19 + * =============================================
20 + * Copyright 2005 by Sun Microsystems, Inc.
21 + * 901 San Antonio Road, Palo Alto, CA 94303, USA
23 + * This library is free software; you can redistribute it and/or
24 + * modify it under the terms of the GNU Lesser General Public
25 + * License version 2.1, as published by the Free Software Foundation.
27 + * This library is distributed in the hope that it will be useful,
28 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
30 + * Lesser General Public License for more details.
32 + * You should have received a copy of the GNU Lesser General Public
33 + * License along with this library; if not, write to the Free Software
34 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
37 + ************************************************************************/
39 +#include <tools/prewin.h>
46 +#include <tools/postwin.h>
48 +#include "framegrabber.hxx"
49 +#include "player.hxx"
51 +#include <tools/stream.hxx>
52 +#include <vcl/graph.hxx>
53 +#include <unotools/localfilehelper.hxx>
55 +#define AVMEDIA_GST_FRAMEGRABBER_IMPLEMENTATIONNAME "com.sun.star.comp.avmedia.FrameGrabber_GStreamer"
56 +#define AVMEDIA_GST_FRAMEGRABBER_SERVICENAME "com.sun.star.media.FrameGrabber_GStreamer"
58 +using namespace ::com::sun::star;
60 +namespace avmedia { namespace gstreamer {
66 +FrameGrabber::FrameGrabber( const uno::Reference< lang::XMultiServiceFactory >& rxMgr ) :
69 + ::CoInitialize( NULL );
72 +// ------------------------------------------------------------------------------
74 +FrameGrabber::~FrameGrabber()
79 +// ------------------------------------------------------------------------------
81 +IMediaDet* FrameGrabber::implCreateMediaDet( const ::rtl::OUString& rURL ) const
83 + IMediaDet* pDet = NULL;
85 + if( SUCCEEDED( CoCreateInstance( CLSID_MediaDet, NULL, CLSCTX_INPROC_SERVER, IID_IMediaDet, (void**) &pDet ) ) )
89 + if( ::utl::LocalFileHelper::ConvertURLToPhysicalName( rURL, aLocalStr ) && aLocalStr.Len() )
91 + if( !SUCCEEDED( pDet->put_Filename( ::SysAllocString( aLocalStr.GetBuffer() ) ) ) )
102 +// ------------------------------------------------------------------------------
104 +bool FrameGrabber::create( const ::rtl::OUString& rURL )
106 + // just check if a MediaDet interface can be created with the given URL
107 + IMediaDet* pDet = implCreateMediaDet( rURL );
116 + maURL = ::rtl::OUString();
118 + return( maURL.getLength() > 0 );
121 +// ------------------------------------------------------------------------------
123 +uno::Reference< graphic::XGraphic > SAL_CALL FrameGrabber::grabFrame( double fMediaTime )
124 + throw (uno::RuntimeException)
126 + uno::Reference< graphic::XGraphic > xRet;
127 + IMediaDet* pDet = implCreateMediaDet( maURL );
133 + bool bFound = false;
135 + if( SUCCEEDED( pDet->get_OutputStreams( &nStreamCount ) ) )
137 + for( long n = 0; ( n < nStreamCount ) && !bFound; ++n )
141 + if( SUCCEEDED( pDet->put_CurrentStream( n ) ) &&
142 + SUCCEEDED( pDet->get_StreamType( &aMajorType ) ) &&
143 + ( aMajorType == MEDIATYPE_Video ) )
151 + ( S_OK == pDet->get_StreamLength( &fLength ) ) &&
152 + ( fLength > 0.0 ) && ( fMediaTime >= 0.0 ) && ( fMediaTime <= fLength ) )
154 + AM_MEDIA_TYPE aMediaType;
155 + long nWidth = 0, nHeight = 0, nSize = 0;
157 + if( SUCCEEDED( pDet->get_StreamMediaType( &aMediaType ) ) )
159 + if( ( aMediaType.formattype == FORMAT_VideoInfo ) &&
160 + ( aMediaType.cbFormat >= sizeof( VIDEOINFOHEADER ) ) )
162 + VIDEOINFOHEADER* pVih = reinterpret_cast< VIDEOINFOHEADER* >( aMediaType.pbFormat );
164 + nWidth = pVih->bmiHeader.biWidth;
165 + nHeight = pVih->bmiHeader.biHeight;
171 + if( aMediaType.cbFormat != 0 )
173 + ::CoTaskMemFree( (PVOID) aMediaType.pbFormat );
174 + aMediaType.cbFormat = 0;
175 + aMediaType.pbFormat = NULL;
178 + if( aMediaType.pUnk != NULL )
180 + aMediaType.pUnk->Release();
181 + aMediaType.pUnk = NULL;
185 + if( ( nWidth > 0 ) && ( nHeight > 0 ) &&
186 + SUCCEEDED( pDet->GetBitmapBits( 0, &nSize, NULL, nWidth, nHeight ) ) &&
189 + char* pBuffer = new char[ nSize ];
193 + if( SUCCEEDED( pDet->GetBitmapBits( fMediaTime, NULL, pBuffer, nWidth, nHeight ) ) )
195 + SvMemoryStream aMemStm( pBuffer, nSize, STREAM_READ | STREAM_WRITE );
198 + if( aBmp.Read( aMemStm, false ) && !aBmp.IsEmpty() )
200 + const Graphic aGraphic( aBmp );
201 + xRet = aGraphic.GetXGraphic();
219 +// ------------------------------------------------------------------------------
221 +::rtl::OUString SAL_CALL FrameGrabber::getImplementationName( )
222 + throw (uno::RuntimeException)
224 + return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( AVMEDIA_GST_FRAMEGRABBER_IMPLEMENTATIONNAME ) );
227 +// ------------------------------------------------------------------------------
229 +sal_Bool SAL_CALL FrameGrabber::supportsService( const ::rtl::OUString& ServiceName )
230 + throw (uno::RuntimeException)
232 + return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( AVMEDIA_GST_FRAMEGRABBER_SERVICENAME ) );
235 +// ------------------------------------------------------------------------------
237 +uno::Sequence< ::rtl::OUString > SAL_CALL FrameGrabber::getSupportedServiceNames( )
238 + throw (uno::RuntimeException)
240 + uno::Sequence< ::rtl::OUString > aRet(1);
241 + aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( AVMEDIA_GST_FRAMEGRABBER_SERVICENAME ) );
246 +} // namespace gstreamer
247 +} // namespace avmedia