merge the formfield patch from ooo-build
[ooovba.git] / avmedia / source / quicktime / framegrabber.cxx
blob51dc28069ccff759231e3f62a3513e544a5b989f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: framegrabber.cxx,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "framegrabber.hxx"
32 #include "player.hxx"
34 #include <tools/stream.hxx>
35 #include <vcl/graph.hxx>
36 #include <vcl/cvtgrf.hxx>
37 #include <unotools/localfilehelper.hxx>
39 #define AVMEDIA_QUICKTIME_FRAMEGRABBER_IMPLEMENTATIONNAME "com.sun.star.comp.avmedia.FrameGrabber_Quicktime"
40 #define AVMEDIA_QUICKTIME_FRAMEGRABBER_SERVICENAME "com.sun.star.media.FrameGrabber_Quicktime"
42 using namespace ::com::sun::star;
44 namespace avmedia { namespace quicktime {
46 // ----------------
47 // - FrameGrabber -
48 // ----------------
50 FrameGrabber::FrameGrabber( const uno::Reference< lang::XMultiServiceFactory >& rxMgr ) :
51 mxMgr( rxMgr )
53 OSErr result;
55 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
56 // check the version of QuickTime installed
57 result = Gestalt(gestaltQuickTime,&mnVersion);
58 if ((result == noErr) && (mnVersion >= QT701))
60 // we have version 7.01 or later, initialize
61 mpMovie = [QTMovie movie];
62 [mpMovie retain];
63 mbInitialized = true;
65 [pool release];
68 // ------------------------------------------------------------------------------
70 FrameGrabber::~FrameGrabber()
72 if( mbInitialized )
74 if( mpMovie )
76 [mpMovie release];
77 mpMovie = nil;
82 // ------------------------------------------------------------------------------
84 bool FrameGrabber::create( const ::rtl::OUString& rURL )
86 bool bRet = false;
87 maURL = rURL;
88 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
89 NSString* aNSStr = [[[NSString alloc] initWithCharacters: rURL.getStr() length: rURL.getLength()]stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] ;
90 NSURL* aURL = [NSURL URLWithString:aNSStr ];
92 // create the Movie
94 mpMovie = [mpMovie initWithURL:aURL error:nil];
95 if(mpMovie)
97 [mpMovie retain];
98 bRet = true;
101 [pool release];
103 return( bRet );
106 // ------------------------------------------------------------------------------
108 uno::Reference< graphic::XGraphic > SAL_CALL FrameGrabber::grabFrame( double fMediaTime )
109 throw (uno::RuntimeException)
111 uno::Reference< graphic::XGraphic > xRet;
113 NSImage* pImage = [mpMovie frameImageAtTime: QTMakeTimeWithTimeInterval(fMediaTime)];
114 NSData *pBitmap = [pImage TIFFRepresentation];
115 long nSize = [pBitmap length];
116 const void* pBitmapData = [pBitmap bytes];
117 SvMemoryStream aMemStm( (char *)pBitmapData, nSize, STREAM_READ | STREAM_WRITE );
118 Graphic aGraphic;
119 if ( GraphicConverter::Import( aMemStm, aGraphic, CVT_TIF ) == ERRCODE_NONE )
121 xRet = aGraphic.GetXGraphic();
124 return xRet;
127 // ------------------------------------------------------------------------------
129 ::rtl::OUString SAL_CALL FrameGrabber::getImplementationName( )
130 throw (uno::RuntimeException)
132 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( AVMEDIA_QUICKTIME_FRAMEGRABBER_IMPLEMENTATIONNAME ) );
135 // ------------------------------------------------------------------------------
137 sal_Bool SAL_CALL FrameGrabber::supportsService( const ::rtl::OUString& ServiceName )
138 throw (uno::RuntimeException)
140 return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( AVMEDIA_QUICKTIME_FRAMEGRABBER_SERVICENAME ) );
143 // ------------------------------------------------------------------------------
145 uno::Sequence< ::rtl::OUString > SAL_CALL FrameGrabber::getSupportedServiceNames( )
146 throw (uno::RuntimeException)
148 uno::Sequence< ::rtl::OUString > aRet(1);
149 aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( AVMEDIA_QUICKTIME_FRAMEGRABBER_SERVICENAME ) );
151 return aRet;
154 } // namespace quicktime
155 } // namespace avmedia