xref: /AOO41X/main/avmedia/source/framework/soundhandler.cxx (revision 144e4e6270fa3bc429c7c0bbb90998a8c234dfbf)
1f39251c4SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3f39251c4SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4f39251c4SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5f39251c4SAndrew Rist  * distributed with this work for additional information
6f39251c4SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7f39251c4SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8f39251c4SAndrew Rist  * "License"); you may not use this file except in compliance
9f39251c4SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11f39251c4SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13f39251c4SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14f39251c4SAndrew Rist  * software distributed under the License is distributed on an
15f39251c4SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16f39251c4SAndrew Rist  * KIND, either express or implied.  See the License for the
17f39251c4SAndrew Rist  * specific language governing permissions and limitations
18f39251c4SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20f39251c4SAndrew Rist  *************************************************************/
21f39251c4SAndrew Rist 
22f39251c4SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir //_________________________________________________________________________________________________________________
25cdf0e10cSrcweir //	my own includes
26cdf0e10cSrcweir //_________________________________________________________________________________________________________________
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #ifndef __FRAMEWORK_DISPATCH_SOUNDHANDLER_HXX_
29cdf0e10cSrcweir #include "soundhandler.hxx"
30cdf0e10cSrcweir #endif
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #ifndef __COMPHELPER_MEDIADESCRIPTOR_HXX_
33cdf0e10cSrcweir #include <comphelper/mediadescriptor.hxx>
34cdf0e10cSrcweir #endif
35cdf0e10cSrcweir 
36cdf0e10cSrcweir //_________________________________________________________________________________________________________________
37cdf0e10cSrcweir //	interface includes
38cdf0e10cSrcweir //_________________________________________________________________________________________________________________
39cdf0e10cSrcweir #include <com/sun/star/io/XInputStream.hpp>
40cdf0e10cSrcweir #include <com/sun/star/frame/DispatchResultState.hpp>
41cdf0e10cSrcweir 
42cdf0e10cSrcweir //_________________________________________________________________________________________________________________
43cdf0e10cSrcweir //	includes of other projects
44cdf0e10cSrcweir //_________________________________________________________________________________________________________________
45cdf0e10cSrcweir #include <comphelper/sequenceashashmap.hxx>
46cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
47cdf0e10cSrcweir 
48cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx>
49cdf0e10cSrcweir #include <cppuhelper/factory.hxx>
50cdf0e10cSrcweir 
51cdf0e10cSrcweir //_________________________________________________________________________________________________________________
52cdf0e10cSrcweir //	namespace
53cdf0e10cSrcweir //_________________________________________________________________________________________________________________
54cdf0e10cSrcweir 
55cdf0e10cSrcweir namespace avmedia{
56cdf0e10cSrcweir 
57cdf0e10cSrcweir //_________________________________________________________________________________________________________________
58cdf0e10cSrcweir //	non exported const
59cdf0e10cSrcweir //_________________________________________________________________________________________________________________
60cdf0e10cSrcweir 
61cdf0e10cSrcweir //_________________________________________________________________________________________________________________
62cdf0e10cSrcweir //	non exported definitions
63cdf0e10cSrcweir //_________________________________________________________________________________________________________________
64cdf0e10cSrcweir 
65cdf0e10cSrcweir //_________________________________________________________________________________________________________________
66cdf0e10cSrcweir //	declarations
67cdf0e10cSrcweir //_________________________________________________________________________________________________________________
68cdf0e10cSrcweir 
69cdf0e10cSrcweir //*****************************************************************************************************************
70cdf0e10cSrcweir //  XInterface, XTypeProvider, XServiceInfo
71cdf0e10cSrcweir //*****************************************************************************************************************
72cdf0e10cSrcweir 
acquire()73cdf0e10cSrcweir void SAL_CALL SoundHandler::acquire() throw()
74cdf0e10cSrcweir {
75cdf0e10cSrcweir        /* Don't use mutex in methods of XInterface! */
76cdf0e10cSrcweir        OWeakObject::acquire();
77cdf0e10cSrcweir }
78cdf0e10cSrcweir 
release()79cdf0e10cSrcweir void SAL_CALL SoundHandler::release() throw()
80cdf0e10cSrcweir {
81cdf0e10cSrcweir        /* Don't use mutex in methods of XInterface! */
82cdf0e10cSrcweir        OWeakObject::release();
83cdf0e10cSrcweir }
84cdf0e10cSrcweir 
queryInterface(const css::uno::Type & aType)85cdf0e10cSrcweir css::uno::Any SAL_CALL SoundHandler::queryInterface( const css::uno::Type& aType ) throw( css::uno::RuntimeException )
86cdf0e10cSrcweir {
87cdf0e10cSrcweir        /* Attention: Don't use mutex or guard in this method!!! Is a method of XInterface.     */
88cdf0e10cSrcweir         /* Ask for my own supported interfaces ...*/
89cdf0e10cSrcweir        css::uno::Any aReturn( ::cppu::queryInterface( aType,
90cdf0e10cSrcweir                static_cast< css::lang::XTypeProvider* >(this),
91cdf0e10cSrcweir                static_cast< css::lang::XServiceInfo* >(this),
92cdf0e10cSrcweir                static_cast< css::frame::XNotifyingDispatch* >(this),
93cdf0e10cSrcweir                static_cast< css::frame::XDispatch* >(this),
94cdf0e10cSrcweir                static_cast< css::document::XExtendedFilterDetection* >(this)));
95cdf0e10cSrcweir        /* If searched interface not supported by this class ... */
96cdf0e10cSrcweir        if ( aReturn.hasValue() == sal_False )
97cdf0e10cSrcweir        {
98cdf0e10cSrcweir                /* ... ask baseclass for interfaces! */
99cdf0e10cSrcweir                aReturn = OWeakObject::queryInterface( aType );
100cdf0e10cSrcweir        }
101cdf0e10cSrcweir         /* Return result of this search. */
102cdf0e10cSrcweir        return aReturn;
103cdf0e10cSrcweir }
104cdf0e10cSrcweir 
getImplementationId()105cdf0e10cSrcweir css::uno::Sequence< sal_Int8 > SAL_CALL SoundHandler::getImplementationId() throw( css::uno::RuntimeException )
106cdf0e10cSrcweir {
107cdf0e10cSrcweir     /* Create one Id for all instances of this class.                                               */
108cdf0e10cSrcweir     /* Use ethernet address to do this! (sal_True)                                                  */
109cdf0e10cSrcweir     /* Optimize this method                                                                         */
110cdf0e10cSrcweir     /* We initialize a static variable only one time. And we don't must use a mutex at every call!  */
111cdf0e10cSrcweir     /* For the first call; pID is NULL - for the second call pID is different from NULL!            */
112cdf0e10cSrcweir     static ::cppu::OImplementationId* pID = NULL ;
113cdf0e10cSrcweir     if ( pID == NULL )
114cdf0e10cSrcweir     {
115cdf0e10cSrcweir         /* Ready for multithreading; get global mutex for first call of this method only! see before   */
116cdf0e10cSrcweir         ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
117cdf0e10cSrcweir         /* Control these pointer again ... it can be, that another instance will be faster then these! */
118cdf0e10cSrcweir         if ( pID == NULL )
119cdf0e10cSrcweir         {
120cdf0e10cSrcweir             /* Create a new static ID ... */
121cdf0e10cSrcweir             static ::cppu::OImplementationId aID( sal_False );
122cdf0e10cSrcweir             /* ... and set his address to static pointer! */
123cdf0e10cSrcweir             pID = &aID ;
124cdf0e10cSrcweir         }
125cdf0e10cSrcweir     }
126cdf0e10cSrcweir     return pID->getImplementationId();
127cdf0e10cSrcweir }
128cdf0e10cSrcweir 
getTypes()129cdf0e10cSrcweir css::uno::Sequence< css::uno::Type > SAL_CALL SoundHandler::getTypes() throw( css::uno::RuntimeException )
130cdf0e10cSrcweir {
131cdf0e10cSrcweir     /* Optimize this method !                                       */
132cdf0e10cSrcweir     /* We initialize a static variable only one time.               */
133cdf0e10cSrcweir     /* And we don't must use a mutex at every call!                 */
134cdf0e10cSrcweir     /* For the first call; pTypeCollection is NULL -                */
135cdf0e10cSrcweir     /* for the second call pTypeCollection is different from NULL!  */
136cdf0e10cSrcweir     static ::cppu::OTypeCollection* pTypeCollection = NULL ;
137cdf0e10cSrcweir     if ( pTypeCollection == NULL )
138cdf0e10cSrcweir     {
139cdf0e10cSrcweir         /* Ready for multithreading; get global mutex for first call of this method only! see before   */
140cdf0e10cSrcweir         ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
141cdf0e10cSrcweir         /* Control these pointer again ... it can be, that another instance will be faster then these! */
142cdf0e10cSrcweir         if ( pTypeCollection == NULL )
143cdf0e10cSrcweir         {
144cdf0e10cSrcweir             /* Create a static typecollection ...           */
145cdf0e10cSrcweir             static ::cppu::OTypeCollection aTypeCollection
146cdf0e10cSrcweir                 (
147cdf0e10cSrcweir                     ::getCppuType(( const ::com::sun::star::uno::Reference< css::lang::XTypeProvider >*)NULL ),
148cdf0e10cSrcweir                     ::getCppuType(( const ::com::sun::star::uno::Reference< css::lang::XServiceInfo >*)NULL ),
149cdf0e10cSrcweir                     ::getCppuType(( const ::com::sun::star::uno::Reference< css::frame::XNotifyingDispatch >*)NULL ),
150cdf0e10cSrcweir                     ::getCppuType(( const ::com::sun::star::uno::Reference< css::frame::XDispatch >*)NULL ),
151cdf0e10cSrcweir                     ::getCppuType(( const ::com::sun::star::uno::Reference< css::document::XExtendedFilterDetection >*)NULL )
152cdf0e10cSrcweir                 );
153cdf0e10cSrcweir             /* ... and set his address to static pointer! */
154cdf0e10cSrcweir             pTypeCollection = &aTypeCollection ;
155cdf0e10cSrcweir         }
156cdf0e10cSrcweir     }
157cdf0e10cSrcweir     return pTypeCollection->getTypes();
158cdf0e10cSrcweir }
159cdf0e10cSrcweir 
160cdf0e10cSrcweir #define DECLARE_ASCII( SASCIIVALUE ) \
161cdf0e10cSrcweir         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SASCIIVALUE ) )
162cdf0e10cSrcweir 
163cdf0e10cSrcweir #define IMPLEMENTATIONNAME_SOUNDHANDLER DECLARE_ASCII("com.sun.star.comp.framework.SoundHandler")
164cdf0e10cSrcweir #define SERVICENAME_CONTENTHANDLER DECLARE_ASCII("com.sun.star.frame.ContentHandler")
165cdf0e10cSrcweir 
166cdf0e10cSrcweir /*===========================================================================================================*/
167cdf0e10cSrcweir /* XServiceInfo */
168cdf0e10cSrcweir /*===========================================================================================================*/
getImplementationName()169cdf0e10cSrcweir ::rtl::OUString SAL_CALL SoundHandler::getImplementationName() throw( css::uno::RuntimeException )
170cdf0e10cSrcweir {
171cdf0e10cSrcweir     return impl_getStaticImplementationName();
172cdf0e10cSrcweir }
173cdf0e10cSrcweir 
174cdf0e10cSrcweir /*===========================================================================================================*/
175cdf0e10cSrcweir /* XServiceInfo */
176cdf0e10cSrcweir /*===========================================================================================================*/
supportsService(const::rtl::OUString & sServiceName)177cdf0e10cSrcweir sal_Bool SAL_CALL SoundHandler::supportsService( const ::rtl::OUString& sServiceName ) throw( css::uno::RuntimeException )
178cdf0e10cSrcweir {
179cdf0e10cSrcweir     /* Set default return value. */
180cdf0e10cSrcweir     sal_Bool bReturn = sal_False ;
181cdf0e10cSrcweir     /* Get names of all supported servicenames. */
182cdf0e10cSrcweir     css::uno::Sequence< ::rtl::OUString >  seqServiceNames =   getSupportedServiceNames();
183cdf0e10cSrcweir     const ::rtl::OUString*                 pArray          =   seqServiceNames.getConstArray();
184cdf0e10cSrcweir     sal_Int32                              nCounter        =   0;
185cdf0e10cSrcweir     sal_Int32                              nLength         =   seqServiceNames.getLength();
186cdf0e10cSrcweir     /* Search for right name in list. */
187cdf0e10cSrcweir     while   (
188cdf0e10cSrcweir               ( nCounter      <       nLength         )       &&
189cdf0e10cSrcweir               ( bReturn       ==      sal_False       )
190cdf0e10cSrcweir             )
191cdf0e10cSrcweir     {
192cdf0e10cSrcweir         /* Is name was found, say "YES, SERVICE IS SUPPORTED." and break loop. */
193cdf0e10cSrcweir         if ( pArray[nCounter] == sServiceName )
194cdf0e10cSrcweir         {
195cdf0e10cSrcweir             bReturn = sal_True ;
196cdf0e10cSrcweir         }
197cdf0e10cSrcweir         /* Else step to next element in list. */
198cdf0e10cSrcweir         ++nCounter;
199cdf0e10cSrcweir     }
200cdf0e10cSrcweir     /* Return state of search. */
201cdf0e10cSrcweir     return bReturn;
202cdf0e10cSrcweir }
203cdf0e10cSrcweir 
204cdf0e10cSrcweir /*===========================================================================================================*/
205cdf0e10cSrcweir /* XServiceInfo */
206cdf0e10cSrcweir /*===========================================================================================================*/
getSupportedServiceNames()207cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > SAL_CALL SoundHandler::getSupportedServiceNames() throw( css::uno::RuntimeException )
208cdf0e10cSrcweir {
209cdf0e10cSrcweir     return impl_getStaticSupportedServiceNames();
210cdf0e10cSrcweir }
211cdf0e10cSrcweir 
212cdf0e10cSrcweir /*===========================================================================================================*/
213cdf0e10cSrcweir /* Helper for XServiceInfo                                                                                   */
214cdf0e10cSrcweir /*===========================================================================================================*/
impl_getStaticSupportedServiceNames()215cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > SoundHandler::impl_getStaticSupportedServiceNames()
216cdf0e10cSrcweir {
217cdf0e10cSrcweir     css::uno::Sequence< ::rtl::OUString > seqServiceNames( 1 );
218cdf0e10cSrcweir     seqServiceNames.getArray() [0] = SERVICENAME_CONTENTHANDLER;
219cdf0e10cSrcweir     return seqServiceNames;
220cdf0e10cSrcweir }
221cdf0e10cSrcweir 
222cdf0e10cSrcweir /*===========================================================================================================*/
223cdf0e10cSrcweir /* Helper for XServiceInfo */
224cdf0e10cSrcweir /*===========================================================================================================*/
impl_getStaticImplementationName()225cdf0e10cSrcweir ::rtl::OUString SoundHandler::impl_getStaticImplementationName()
226cdf0e10cSrcweir {
227cdf0e10cSrcweir     return IMPLEMENTATIONNAME_SOUNDHANDLER;
228cdf0e10cSrcweir }
229cdf0e10cSrcweir 
impl_createInstance(const css::uno::Reference<css::lang::XMultiServiceFactory> & xServiceManager)230cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > SAL_CALL SoundHandler::impl_createInstance( const css::uno::Reference< css::lang::XMultiServiceFactory >& xServiceManager ) throw( css::uno::Exception )
231cdf0e10cSrcweir {
232cdf0e10cSrcweir     /* create new instance of service */
233cdf0e10cSrcweir     SoundHandler* pClass = new SoundHandler( xServiceManager );
234cdf0e10cSrcweir     /* hold it alive by increasing his ref count!!! */
235cdf0e10cSrcweir     css::uno::Reference< css::uno::XInterface > xService( static_cast< ::cppu::OWeakObject* >(pClass), css::uno::UNO_QUERY );
236cdf0e10cSrcweir     /* initialize new service instance ... he can use his own refcount ... we hold it! */
237cdf0e10cSrcweir     pClass->impl_initService();
238cdf0e10cSrcweir     /* return new created service as reference */
239cdf0e10cSrcweir     return xService;
240cdf0e10cSrcweir }
241cdf0e10cSrcweir 
impl_createFactory(const css::uno::Reference<css::lang::XMultiServiceFactory> & xServiceManager)242cdf0e10cSrcweir css::uno::Reference< css::lang::XSingleServiceFactory > SoundHandler::impl_createFactory( const css::uno::Reference< css::lang::XMultiServiceFactory >& xServiceManager )
243cdf0e10cSrcweir {
244cdf0e10cSrcweir     css::uno::Reference< css::lang::XSingleServiceFactory > xReturn ( cppu::createSingleFactory (
245cdf0e10cSrcweir        xServiceManager,
246cdf0e10cSrcweir         SoundHandler::impl_getStaticImplementationName(),
247cdf0e10cSrcweir         SoundHandler::impl_createInstance,
248cdf0e10cSrcweir         SoundHandler::impl_getStaticSupportedServiceNames()
249cdf0e10cSrcweir         )
250cdf0e10cSrcweir     );
251cdf0e10cSrcweir     return xReturn;
252cdf0e10cSrcweir }
253cdf0e10cSrcweir 
impl_initService()254cdf0e10cSrcweir void SAL_CALL SoundHandler::impl_initService()
255cdf0e10cSrcweir {
256cdf0e10cSrcweir }
257cdf0e10cSrcweir 
258cdf0e10cSrcweir 
259cdf0e10cSrcweir /*-************************************************************************************************************//**
260cdf0e10cSrcweir     @short      standard ctor
261cdf0e10cSrcweir     @descr      These initialize a new instance of this class with needed informations for work.
262cdf0e10cSrcweir 
263cdf0e10cSrcweir     @seealso    using at owner
264cdf0e10cSrcweir 
265cdf0e10cSrcweir     @param      "xFactory", reference to service manager for creation of new services
266cdf0e10cSrcweir     @return     -
267cdf0e10cSrcweir 
268cdf0e10cSrcweir     @onerror    Show an assertion and do nothing else.
269cdf0e10cSrcweir     @threadsafe yes
270cdf0e10cSrcweir *//*-*************************************************************************************************************/
SoundHandler(const css::uno::Reference<css::lang::XMultiServiceFactory> & xFactory)271cdf0e10cSrcweir SoundHandler::SoundHandler( const css::uno::Reference< css::lang::XMultiServiceFactory >& xFactory )
272cdf0e10cSrcweir 		//	Init baseclasses first
273cdf0e10cSrcweir         :   ThreadHelpBase      (          )
274cdf0e10cSrcweir         ,   ::cppu::OWeakObject (          )
275cdf0e10cSrcweir         // Init member
276cdf0e10cSrcweir 	,   m_bError		( false    )
277cdf0e10cSrcweir         ,   m_xFactory          ( xFactory )
278cdf0e10cSrcweir {
279cdf0e10cSrcweir     m_aUpdateTimer.SetTimeoutHdl(LINK(this, SoundHandler, implts_PlayerNotify));
280cdf0e10cSrcweir }
281cdf0e10cSrcweir 
282cdf0e10cSrcweir /*-************************************************************************************************************//**
283cdf0e10cSrcweir     @short      standard dtor
284cdf0e10cSrcweir     @descr      -
285cdf0e10cSrcweir 
286cdf0e10cSrcweir     @seealso    -
287cdf0e10cSrcweir 
288cdf0e10cSrcweir     @param      -
289cdf0e10cSrcweir     @return     -
290cdf0e10cSrcweir 
291cdf0e10cSrcweir     @onerror    -
292cdf0e10cSrcweir     @threadsafe -
293cdf0e10cSrcweir *//*-*************************************************************************************************************/
~SoundHandler()294cdf0e10cSrcweir SoundHandler::~SoundHandler()
295cdf0e10cSrcweir {
296cdf0e10cSrcweir     if (m_xListener.is())
297cdf0e10cSrcweir     {
298cdf0e10cSrcweir         css::frame::DispatchResultEvent aEvent;
299cdf0e10cSrcweir         aEvent.State = css::frame::DispatchResultState::FAILURE;
300cdf0e10cSrcweir         m_xListener->dispatchFinished(aEvent);
301cdf0e10cSrcweir         m_xListener = css::uno::Reference< css::frame::XDispatchResultListener >();
302cdf0e10cSrcweir     }
303cdf0e10cSrcweir }
304cdf0e10cSrcweir 
305cdf0e10cSrcweir /*-************************************************************************************************************//**
306cdf0e10cSrcweir     @interface  ::com::sun::star::frame::XDispatch
307cdf0e10cSrcweir 
308cdf0e10cSrcweir     @short      try to load audio file
309cdf0e10cSrcweir     @descr      This method try to load given audio file by URL and play it. We use vcl/Sound class to do that.
310cdf0e10cSrcweir                 Playing of sound is asynchron everytime.
311cdf0e10cSrcweir 
312cdf0e10cSrcweir     @attention  We must hold us alive by ourself ... because we use async. vcl sound player ... but playing is started
313cdf0e10cSrcweir                 in async interface call "dispatch()" too. And caller forget us imediatly. But then our uno ref count
314cdf0e10cSrcweir                 will decreased to 0 and will die. The only solution is to use own reference to our implementation.
315cdf0e10cSrcweir                 But we do it for realy started jobs only and release it during call back of vcl.
316cdf0e10cSrcweir 
317cdf0e10cSrcweir     @seealso    class vcl/Sound
318cdf0e10cSrcweir     @seealso    method implts_PlayerNotify()
319cdf0e10cSrcweir 
320cdf0e10cSrcweir     @param      "aURL"      , URL to dispatch.
321cdf0e10cSrcweir     @param      "lArguments", list of optional arguments.
322cdf0e10cSrcweir     @return     -
323cdf0e10cSrcweir 
324cdf0e10cSrcweir     @onerror    We do nothing.
325cdf0e10cSrcweir     @threadsafe yes
326cdf0e10cSrcweir *//*-*************************************************************************************************************/
dispatchWithNotification(const css::util::URL & aURL,const css::uno::Sequence<css::beans::PropertyValue> & lDescriptor,const css::uno::Reference<css::frame::XDispatchResultListener> & xListener)327cdf0e10cSrcweir void SAL_CALL SoundHandler::dispatchWithNotification(const css::util::URL&                                             aURL      ,
328cdf0e10cSrcweir                                                      const css::uno::Sequence< css::beans::PropertyValue >&            lDescriptor,
329cdf0e10cSrcweir                                                      const css::uno::Reference< css::frame::XDispatchResultListener >& xListener ) throw(css::uno::RuntimeException)
330cdf0e10cSrcweir {
331cdf0e10cSrcweir     // SAFE {
332cdf0e10cSrcweir     const ::vos::OGuard aLock( m_aLock );
333cdf0e10cSrcweir 
334cdf0e10cSrcweir     {
335cdf0e10cSrcweir 	//close streams otherwise on windows we can't reopen the file in the
336cdf0e10cSrcweir 	//media player when we pass the url to directx as it'll already be open
337cdf0e10cSrcweir         ::comphelper::MediaDescriptor aDescriptor(lDescriptor);
338cdf0e10cSrcweir 
339cdf0e10cSrcweir 	css::uno::Reference< css::io::XInputStream > xInputStream =
340cdf0e10cSrcweir 		aDescriptor.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_INPUTSTREAM(),
341cdf0e10cSrcweir 		css::uno::Reference< css::io::XInputStream >());
342cdf0e10cSrcweir 	if (xInputStream.is()) xInputStream->closeInput();
343cdf0e10cSrcweir     }
344cdf0e10cSrcweir 
345cdf0e10cSrcweir     // If player currently used for other dispatch() requests ...
346cdf0e10cSrcweir     // cancel it by calling stop()!
347cdf0e10cSrcweir     m_aUpdateTimer.Stop();
348cdf0e10cSrcweir     if (m_xPlayer.is())
349cdf0e10cSrcweir     {
350cdf0e10cSrcweir         if (m_xPlayer->isPlaying())
351cdf0e10cSrcweir             m_xPlayer->stop();
352cdf0e10cSrcweir         m_xPlayer.clear();
353cdf0e10cSrcweir     }
354cdf0e10cSrcweir 
355cdf0e10cSrcweir     // Try to initialize player.
356cdf0e10cSrcweir     m_xListener = xListener;
357cdf0e10cSrcweir     try
358cdf0e10cSrcweir     {
359cdf0e10cSrcweir         m_bError = false;
360cdf0e10cSrcweir         m_xPlayer.set( avmedia::MediaWindow::createPlayer( aURL.Complete ), css::uno::UNO_QUERY_THROW );
361cdf0e10cSrcweir         // OK- we can start async playing ...
362cdf0e10cSrcweir         // Count this request and initialize self-holder against dieing by uno ref count ...
363cdf0e10cSrcweir         m_xSelfHold = css::uno::Reference< css::uno::XInterface >(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY);
364cdf0e10cSrcweir         m_xPlayer->start();
365cdf0e10cSrcweir         m_aUpdateTimer.SetTimeout( 200 );
366cdf0e10cSrcweir         m_aUpdateTimer.Start();
367cdf0e10cSrcweir     }
368cdf0e10cSrcweir     catch( css::uno::Exception& e )
369cdf0e10cSrcweir     {
370cdf0e10cSrcweir         m_bError = true;
371cdf0e10cSrcweir         (void)e;
372cdf0e10cSrcweir         m_xPlayer.clear();
373cdf0e10cSrcweir     }
374cdf0e10cSrcweir 
375cdf0e10cSrcweir     // } SAFE
376cdf0e10cSrcweir }
377cdf0e10cSrcweir 
dispatch(const css::util::URL & aURL,const css::uno::Sequence<css::beans::PropertyValue> & lArguments)378cdf0e10cSrcweir void SAL_CALL SoundHandler::dispatch( const css::util::URL&                                  aURL       ,
379cdf0e10cSrcweir                                       const css::uno::Sequence< css::beans::PropertyValue >& lArguments ) throw( css::uno::RuntimeException )
380cdf0e10cSrcweir {
381cdf0e10cSrcweir     dispatchWithNotification(aURL, lArguments, css::uno::Reference< css::frame::XDispatchResultListener >());
382cdf0e10cSrcweir }
383cdf0e10cSrcweir 
384cdf0e10cSrcweir /*-************************************************************************************************************//**
385cdf0e10cSrcweir     @interface  ::com::sun::star::document::XExtendedFilterDetection
386cdf0e10cSrcweir 
387cdf0e10cSrcweir     @short      try to detect file (given as argument included in "lDescriptor")
388cdf0e10cSrcweir     @descr      We try to detect, if given file could be handled by this class and is a well known one.
389cdf0e10cSrcweir                 If it is - we return right internal type name - otherwise we return nothing!
390cdf0e10cSrcweir                 So call can search for another detect service and ask him too.
391cdf0e10cSrcweir 
392cdf0e10cSrcweir     @attention  a) We don't need any mutex here ... because we don't use any member!
393cdf0e10cSrcweir                 b) Dont' use internal player instance "m_pPlayer" to detect given sound file!
394cdf0e10cSrcweir                    It's not neccessary to do that ... and we can use temp. variable to do the same.
395cdf0e10cSrcweir                    This way is easy - we don't must synchronize it with currently played sounds!
396cdf0e10cSrcweir                    Another reason to do so ... We are a listener on our internal ma_Player object.
397cdf0e10cSrcweir                    If you would call "IsSoundFile()" on this instance, he would call us back and
398cdf0e10cSrcweir                    we make some uneccssary things ...
399cdf0e10cSrcweir 
400cdf0e10cSrcweir     @seealso    -
401cdf0e10cSrcweir 
402cdf0e10cSrcweir     @param      "lDescriptor", description of file to detect
403cdf0e10cSrcweir     @return     Internal type name which match this file ... or nothing if it is unknown.
404cdf0e10cSrcweir 
405cdf0e10cSrcweir     @onerror    We return nothing.
406cdf0e10cSrcweir     @threadsafe yes
407cdf0e10cSrcweir *//*-*************************************************************************************************************/
detect(css::uno::Sequence<css::beans::PropertyValue> & lDescriptor)408cdf0e10cSrcweir ::rtl::OUString SAL_CALL SoundHandler::detect( css::uno::Sequence< css::beans::PropertyValue >& lDescriptor ) throw( css::uno::RuntimeException )
409cdf0e10cSrcweir {
410cdf0e10cSrcweir     // Our default is "nothing". So we can return it, if detection failed or fily type is realy unknown.
411cdf0e10cSrcweir     ::rtl::OUString sTypeName;
412cdf0e10cSrcweir 
413cdf0e10cSrcweir     // Analyze given descriptor to find filename or input stream or ...
414cdf0e10cSrcweir     ::comphelper::MediaDescriptor aDescriptor(lDescriptor);
415cdf0e10cSrcweir     ::rtl::OUString               sURL       = aDescriptor.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_URL(), ::rtl::OUString());
416cdf0e10cSrcweir 
417cdf0e10cSrcweir     if (
418*144e4e62SHerbert Dürr         !sURL.isEmpty() &&
419cdf0e10cSrcweir         (avmedia::MediaWindow::isMediaURL(sURL))
420cdf0e10cSrcweir        )
421cdf0e10cSrcweir     {
422cdf0e10cSrcweir         // If the file type is supported depends on the OS, so...
423cdf0e10cSrcweir         // I think we can the following ones:
424cdf0e10cSrcweir         //  a) look for given extension of url to map our type decision HARD CODED!!!
425cdf0e10cSrcweir         //  b) return preferred type every time... it's easy :-)
426cdf0e10cSrcweir         sTypeName = ::rtl::OUString::createFromAscii("wav_Wave_Audio_File");
427cdf0e10cSrcweir         aDescriptor[::comphelper::MediaDescriptor::PROP_TYPENAME()] <<= sTypeName;
428cdf0e10cSrcweir         aDescriptor >> lDescriptor;
429cdf0e10cSrcweir     }
430cdf0e10cSrcweir 
431cdf0e10cSrcweir     // Return our decision.
432cdf0e10cSrcweir     return sTypeName;
433cdf0e10cSrcweir }
434cdf0e10cSrcweir 
435cdf0e10cSrcweir /*-************************************************************************************************************//**
436cdf0e10cSrcweir     @short      call back of sound player
437cdf0e10cSrcweir     @descr      Our player call us back to give us some informations.
438cdf0e10cSrcweir                 We use this informations to callback our might existing listener.
439cdf0e10cSrcweir 
440cdf0e10cSrcweir     @seealso    method dispatchWithNotification()
441cdf0e10cSrcweir 
442cdf0e10cSrcweir     @param      -
443cdf0e10cSrcweir     @return     0 everytime ... it doesnt matter for us.
444cdf0e10cSrcweir 
445cdf0e10cSrcweir     @onerror    -
446cdf0e10cSrcweir     @threadsafe yes
447cdf0e10cSrcweir *//*-*************************************************************************************************************/
IMPL_LINK(SoundHandler,implts_PlayerNotify,void *,EMPTYARG)448cdf0e10cSrcweir IMPL_LINK( SoundHandler, implts_PlayerNotify, void*, EMPTYARG )
449cdf0e10cSrcweir {
450cdf0e10cSrcweir     // SAFE {
451cdf0e10cSrcweir     ::vos::OClearableGuard aLock( m_aLock );
452cdf0e10cSrcweir 
453cdf0e10cSrcweir     if (m_xPlayer.is() && m_xPlayer->isPlaying() && m_xPlayer->getMediaTime() < m_xPlayer->getDuration())
454cdf0e10cSrcweir     {
455cdf0e10cSrcweir         m_aUpdateTimer.Start();
456cdf0e10cSrcweir         return 0L;
457cdf0e10cSrcweir     }
458cdf0e10cSrcweir     m_xPlayer.clear();
459cdf0e10cSrcweir 
460cdf0e10cSrcweir     // We use m_xSelfHold to let us die ... but we must live till real finishing of this method too!!!
461cdf0e10cSrcweir     // So we SHOULD use another "self-holder" temp. to provide that ...
462cdf0e10cSrcweir     css::uno::Reference< css::uno::XInterface > xOperationHold = m_xSelfHold;
463cdf0e10cSrcweir     m_xSelfHold = css::uno::Reference< css::uno::XInterface >();
464cdf0e10cSrcweir 
465cdf0e10cSrcweir     // notify might existing listener
466cdf0e10cSrcweir     // And forget this listener!
467cdf0e10cSrcweir     // Because the corresponding dispatch was finished.
468cdf0e10cSrcweir     if (m_xListener.is())
469cdf0e10cSrcweir     {
470cdf0e10cSrcweir         css::frame::DispatchResultEvent aEvent;
471cdf0e10cSrcweir         if (!m_bError)
472cdf0e10cSrcweir             aEvent.State = css::frame::DispatchResultState::SUCCESS;
473cdf0e10cSrcweir         else
474cdf0e10cSrcweir             aEvent.State = css::frame::DispatchResultState::FAILURE;
475cdf0e10cSrcweir         m_xListener->dispatchFinished(aEvent);
476cdf0e10cSrcweir         m_xListener = css::uno::Reference< css::frame::XDispatchResultListener >();
477cdf0e10cSrcweir     }
478cdf0e10cSrcweir 
479cdf0e10cSrcweir     // } SAFE
480cdf0e10cSrcweir 	//release aLock before end of method at which point xOperationHold goes out of scope and pThis dies
481cdf0e10cSrcweir 	aLock.clear();
482cdf0e10cSrcweir     return 0;
483cdf0e10cSrcweir }
484cdf0e10cSrcweir 
485cdf0e10cSrcweir } // namespace framework
486cdf0e10cSrcweir 
487cdf0e10cSrcweir // ------------------------------------------
488cdf0e10cSrcweir // - component_getImplementationEnvironment -
489cdf0e10cSrcweir // ------------------------------------------
490cdf0e10cSrcweir 
component_getImplementationEnvironment(const sal_Char ** ppEnvTypeName,uno_Environment **)491cdf0e10cSrcweir extern "C" void SAL_CALL component_getImplementationEnvironment( const sal_Char ** ppEnvTypeName, uno_Environment ** /*ppEnv*/ )
492cdf0e10cSrcweir {
493cdf0e10cSrcweir        *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
494cdf0e10cSrcweir }
495cdf0e10cSrcweir 
496cdf0e10cSrcweir // ------------------------
497cdf0e10cSrcweir // - component_getFactory -
498cdf0e10cSrcweir // ------------------------
499cdf0e10cSrcweir 
component_getFactory(const sal_Char * pImplementationName,void * pServiceManager,void *)500cdf0e10cSrcweir extern "C" void* SAL_CALL component_getFactory(const sal_Char* pImplementationName, void* pServiceManager, void* /*pRegistryKey*/ )
501cdf0e10cSrcweir {
502cdf0e10cSrcweir     void* pReturn = NULL;
503cdf0e10cSrcweir     if  (pServiceManager !=  NULL )
504cdf0e10cSrcweir     {
505cdf0e10cSrcweir         /* Define variables which are used in following macros. */
506cdf0e10cSrcweir         css::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory > xFactory;
507cdf0e10cSrcweir         css::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xServiceManager;
508cdf0e10cSrcweir             xServiceManager = reinterpret_cast< ::com::sun::star::lang::XMultiServiceFactory* >( pServiceManager )  ;
509cdf0e10cSrcweir 
510cdf0e10cSrcweir         if ( avmedia::SoundHandler::impl_getStaticImplementationName().equals( ::rtl::OUString::createFromAscii( pImplementationName ) ) )
511cdf0e10cSrcweir             xFactory = avmedia::SoundHandler::impl_createFactory( xServiceManager );
512cdf0e10cSrcweir 
513cdf0e10cSrcweir         if ( xFactory.is() == sal_True )
514cdf0e10cSrcweir         {
515cdf0e10cSrcweir             xFactory->acquire();
516cdf0e10cSrcweir             pReturn = xFactory.get();
517cdf0e10cSrcweir         }
518cdf0e10cSrcweir     }
519cdf0e10cSrcweir     /* Return with result of this operation. */
520cdf0e10cSrcweir     return pReturn;
521cdf0e10cSrcweir }
522