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 .
23 #include "framegrabber.hxx"
26 using namespace ::com::sun::star;
28 SAL_WNODEPRECATED_DECLARATIONS_PUSH //TODO: 10.9
30 namespace avmedia { namespace quicktime {
32 Player::Player( const uno::Reference< lang::XMultiServiceFactory >& rxMgr ) :
36 mnStopTime( DBL_MAX ), //max double
38 mbInitialized( false )
41 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
57 QTMovie* Player::getMovie()
59 OSL_ASSERT( mpMovie );
64 bool Player::create( const ::rtl::OUString& rURL )
70 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
78 NSString* aNSStr = [[[NSString alloc] initWithCharacters: reinterpret_cast<unichar const *>(rURL.getStr()) length: rURL.getLength()]stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] ;
79 NSURL* aURL = [NSURL URLWithString:aNSStr ];
82 mpMovie = [QTMovie movieWithURL:aURL error:&pErr];
91 SAL_INFO ( "avmedia.quicktime",
92 "NSMovie create failed with error " << (long)[pErr code] <<
93 " (" << [[pErr localizedDescription] UTF8String] << ")"
103 void SAL_CALL Player::start( )
105 SAL_INFO ( "avmedia.quicktime", "Player::start" );
114 void SAL_CALL Player::stop( )
116 SAL_INFO ( "avmedia.quicktime", "Player::stop" );
124 sal_Bool SAL_CALL Player::isPlaying()
130 if ([mpMovie rate] != 0)
140 double SAL_CALL Player::getDuration( )
142 // slideshow checks for non-zero duration, so cheat here
143 double duration = 0.01;
145 if ( mpMovie ) // && mnDuration > 0 ) {
147 QTTime structDuration = [mpMovie duration] ;
148 duration = (double)structDuration.timeValue / (double)structDuration.timeScale;
155 void SAL_CALL Player::setMediaTime( double fTime )
157 SAL_INFO ( "avmedia.quicktime", "Player::setMediaTime" );
161 [mpMovie setCurrentTime: QTMakeTimeWithTimeInterval(fTime)];
166 double SAL_CALL Player::getMediaTime( )
168 double position = 0.0;
172 QTTime structDuration = [mpMovie currentTime] ;
173 position = (double)structDuration.timeValue / (double)structDuration.timeScale;
176 if(isPlaying() && position>mnStopTime)
184 void SAL_CALL Player::setPlaybackLoop( sal_Bool bSet )
186 SAL_INFO ( "avmedia.quicktime",
187 "Player::setPlaybackLoop ? " << ( bSet?"True":"False" ) );
191 [mpMovie setAttribute:[NSNumber numberWithBool:YES] forKey: QTMovieLoopsAttribute] ;
195 [mpMovie setAttribute:[NSNumber numberWithBool:NO] forKey: QTMovieLoopsAttribute] ;
200 sal_Bool SAL_CALL Player::isPlaybackLoop( )
202 bool bRet = [[mpMovie attributeForKey:QTMovieLoopsAttribute] boolValue];
204 SAL_INFO ( "avmedia.quicktime",
205 "Player::isPlaybackLoop ? " << ( bRet?"True":"False" ) );
211 void SAL_CALL Player::setMute( sal_Bool bSet )
213 SAL_INFO ( "avmedia.quicktime",
214 "set mute: " << bSet <<
215 " muted: " << mbMuted <<
216 " unmuted volume: " << mnUnmutedVolume );
218 // change the volume to 0 or the unmuted volume
219 if( mpMovie && mbMuted != bool(bSet) )
221 [mpMovie setMuted: bSet ];
228 sal_Bool SAL_CALL Player::isMute( )
230 SAL_INFO ( "avmedia.quicktime", "Player::isMuted" );
236 void SAL_CALL Player::setVolumeDB( sal_Int16 nVolumeDB )
238 // OOo db volume -40 = QTVolume 0
239 // OOo db volume 0 = QTvolume 1
246 mnUnmutedVolume = pow( 10.0, nVolumeDB / 20.0 );
249 SAL_INFO ( "avmedia.quicktime",
250 "set volume: " << nVolumeDB <<
251 " gst volume: " << mnUnmutedVolume );
254 if( !mbMuted && mpMovie )
256 [mpMovie setVolume: mnUnmutedVolume ];
261 sal_Int16 SAL_CALL Player::getVolumeDB( )
263 sal_Int16 nVolumeDB = 0.0;
269 volume = [mpMovie volume];
270 if(volume>0) //protect from log10(0)
272 nVolumeDB = (sal_Int16) ( 20.0*log10 ( volume ) );
276 nVolumeDB = -40 ; // QT zero volume is no volume, -40db
284 awt::Size SAL_CALL Player::getPreferredPlayerWindowSize( )
286 NSSize nsSize = [[mpMovie attributeForKey:QTMovieNaturalSizeAttribute] sizeValue];
287 awt::Size aSize( nsSize.width, nsSize.height );
292 uno::Reference< ::media::XPlayerWindow > SAL_CALL Player::createPlayerWindow( const uno::Sequence< uno::Any >& aArguments )
294 uno::Reference< ::media::XPlayerWindow > xRet;
295 awt::Size aSize( getPreferredPlayerWindowSize() );
297 SAL_INFO ( "avmedia.quicktime",
298 "Player::createPlayerWindow " << aSize.Width << " x " << aSize.Height <<
299 " length: " << aArguments.getLength() );
301 if( aSize.Width > 0 && aSize.Height > 0 )
304 aArguments[0] >>= nPtr;
305 NSView* pParentView = reinterpret_cast< NSView * >(nPtr);
307 ::avmedia::quicktime::Window* pWindow = new ::avmedia::quicktime::Window( mxMgr, *this, pParentView );
315 uno::Reference< media::XFrameGrabber > SAL_CALL Player::createFrameGrabber( )
317 uno::Reference< media::XFrameGrabber > xRet;
318 SAL_INFO ( "avmedia.quicktime", "Player::createFrameGrabber" );
320 if( !maURL.isEmpty() )
322 FrameGrabber* pGrabber = new FrameGrabber( mxMgr );
326 if( !pGrabber->create( maURL ) )
336 ::rtl::OUString SAL_CALL Player::getImplementationName( )
338 return ::rtl::OUString( AVMEDIA_QUICKTIME_PLAYER_IMPLEMENTATIONNAME );
342 sal_Bool SAL_CALL Player::supportsService( const ::rtl::OUString& ServiceName )
344 return ( ServiceName == AVMEDIA_QUICKTIME_PLAYER_SERVICENAME );
348 uno::Sequence< ::rtl::OUString > SAL_CALL Player::getSupportedServiceNames( )
350 return { AVMEDIA_QUICKTIME_PLAYER_SERVICENAME };
353 } // namespace quicktime
354 } // namespace avmedia
356 SAL_WNODEPRECATED_DECLARATIONS_POP
358 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */