1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "framegrabber.hxx"
23 #include <tools/stream.hxx>
24 #include <vcl/graph.hxx>
25 #include <vcl/cvtgrf.hxx>
26 #include <unotools/localfilehelper.hxx>
28 #define AVMEDIA_QUICKTIME_FRAMEGRABBER_IMPLEMENTATIONNAME "com.sun.star.comp.avmedia.FrameGrabber_Quicktime"
29 #define AVMEDIA_QUICKTIME_FRAMEGRABBER_SERVICENAME "com.sun.star.media.FrameGrabber_Quicktime"
31 using namespace ::com::sun::star;
33 namespace avmedia { namespace quicktime {
39 FrameGrabber::FrameGrabber( const uno::Reference< lang::XMultiServiceFactory >& rxMgr ) :
44 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
45 // check the version of QuickTime installed
46 result = Gestalt(gestaltQuickTime,&mnVersion);
47 if ((result == noErr) && (mnVersion >= QT701))
49 // we have version 7.01 or later, initialize
50 mpMovie = [QTMovie movie];
57 // ------------------------------------------------------------------------------
59 FrameGrabber::~FrameGrabber()
71 // ------------------------------------------------------------------------------
73 bool FrameGrabber::create( const ::rtl::OUString& rURL )
77 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
78 NSString* aNSStr = [[[NSString alloc] initWithCharacters: rURL.getStr() length: rURL.getLength()]stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] ;
79 NSURL* aURL = [NSURL URLWithString:aNSStr ];
83 mpMovie = [mpMovie initWithURL:aURL error:nil];
95 // ------------------------------------------------------------------------------
97 uno::Reference< graphic::XGraphic > SAL_CALL FrameGrabber::grabFrame( double fMediaTime )
98 throw (uno::RuntimeException)
100 uno::Reference< graphic::XGraphic > xRet;
102 NSImage* pImage = [mpMovie frameImageAtTime: QTMakeTimeWithTimeInterval(fMediaTime)];
103 NSData *pBitmap = [pImage TIFFRepresentation];
104 long nSize = [pBitmap length];
105 const void* pBitmapData = [pBitmap bytes];
106 SvMemoryStream aMemStm( (char *)pBitmapData, nSize, STREAM_READ | STREAM_WRITE );
108 if ( GraphicConverter::Import( aMemStm, aGraphic, CVT_TIF ) == ERRCODE_NONE )
110 xRet = aGraphic.GetXGraphic();
116 // ------------------------------------------------------------------------------
118 ::rtl::OUString SAL_CALL FrameGrabber::getImplementationName( )
119 throw (uno::RuntimeException)
121 return ::rtl::OUString( AVMEDIA_QUICKTIME_FRAMEGRABBER_IMPLEMENTATIONNAME );
124 // ------------------------------------------------------------------------------
126 sal_Bool SAL_CALL FrameGrabber::supportsService( const ::rtl::OUString& ServiceName )
127 throw (uno::RuntimeException)
129 return ( ServiceName == AVMEDIA_QUICKTIME_FRAMEGRABBER_SERVICENAME );
132 // ------------------------------------------------------------------------------
134 uno::Sequence< ::rtl::OUString > SAL_CALL FrameGrabber::getSupportedServiceNames( )
135 throw (uno::RuntimeException)
137 uno::Sequence< ::rtl::OUString > aRet(1);
138 aRet[0] = ::rtl::OUString( AVMEDIA_QUICKTIME_FRAMEGRABBER_SERVICENAME );
143 } // namespace quicktime
144 } // namespace avmedia
146 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */