LCOV - code coverage report
Current view: top level - slideshow/source/engine/animationnodes - animationaudionode.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 51 2.0 %
Date: 2015-06-13 12:38:46 Functions: 2 10 20.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : 
      21             : // must be first
      22             : #include <canvas/debug.hxx>
      23             : #include <canvas/verbosetrace.hxx>
      24             : 
      25             : #include "eventqueue.hxx"
      26             : #include "animationaudionode.hxx"
      27             : #include "delayevent.hxx"
      28             : #include "tools.hxx"
      29             : #include "nodetools.hxx"
      30             : #include "boost/bind.hpp"
      31             : 
      32             : using namespace com::sun::star;
      33             : 
      34             : namespace slideshow {
      35             : namespace internal {
      36             : 
      37           0 : AnimationAudioNode::AnimationAudioNode(
      38             :     const uno::Reference< animations::XAnimationNode >& xNode,
      39             :     const BaseContainerNodeSharedPtr&                   rParent,
      40             :     const NodeContext&                                  rContext )
      41             :     : BaseNode( xNode, rParent, rContext ),
      42             :       mxAudioNode( xNode, uno::UNO_QUERY_THROW ),
      43             :       maSoundURL(),
      44           0 :       mpPlayer()
      45             : {
      46           0 :     mxAudioNode->getSource() >>= maSoundURL;
      47             : 
      48             :     OSL_ENSURE( !maSoundURL.isEmpty(),
      49             :                 "could not extract sound source URL/empty URL string" );
      50             : 
      51           0 :     ENSURE_OR_THROW( getContext().mxComponentContext.is(),
      52             :                       "Invalid component context" );
      53           0 : }
      54             : 
      55           0 : void AnimationAudioNode::dispose()
      56             : {
      57           0 :     resetPlayer();
      58           0 :     mxAudioNode.clear();
      59           0 :     BaseNode::dispose();
      60           0 : }
      61             : 
      62           0 : void AnimationAudioNode::activate_st()
      63             : {
      64           0 :     createPlayer();
      65             : 
      66             :     AnimationEventHandlerSharedPtr aHandler(
      67           0 :         boost::dynamic_pointer_cast<AnimationEventHandler>( getSelf() ) );
      68             :     OSL_ENSURE( aHandler,
      69             :                 "could not cast self to AnimationEventHandler?" );
      70           0 :     getContext().mrEventMultiplexer.addCommandStopAudioHandler( aHandler );
      71             : 
      72           0 :     if (mpPlayer && mpPlayer->startPlayback())
      73             :     {
      74             :         // TODO(F2): Handle end time attribute, too
      75           0 :         if( getXAnimationNode()->getDuration().hasValue() )
      76             :         {
      77           0 :             scheduleDeactivationEvent();
      78             :         }
      79             :         else
      80             :         {
      81             :             // no node duration. Take inherent media time, then
      82             :             scheduleDeactivationEvent(
      83           0 :                 makeDelay( boost::bind( &AnimationNode::deactivate, getSelf() ),
      84             :                                         mpPlayer->getDuration(),
      85           0 :                            "AnimationAudioNode::deactivate with delay") );
      86             :         }
      87             :     }
      88             :     else
      89             :     {
      90             :         // deactivate ASAP:
      91             :         scheduleDeactivationEvent(
      92           0 :             makeEvent( boost::bind( &AnimationNode::deactivate, getSelf() ),
      93           0 :                                     "AnimationAudioNode::deactivate without delay") );
      94           0 :     }
      95           0 : }
      96             : 
      97             : // TODO(F2): generate deactivation event, when sound
      98             : // is over
      99             : 
     100           0 : void AnimationAudioNode::deactivate_st( NodeState /*eDestState*/ )
     101             : {
     102             :     AnimationEventHandlerSharedPtr aHandler(
     103           0 :         boost::dynamic_pointer_cast<AnimationEventHandler>( getSelf() ) );
     104             :     OSL_ENSURE( aHandler,
     105             :                 "could not cas self to AnimationEventHandler?" );
     106           0 :     getContext().mrEventMultiplexer.removeCommandStopAudioHandler( aHandler );
     107             : 
     108             :     // force-end sound
     109           0 :     if (mpPlayer)
     110             :     {
     111           0 :         mpPlayer->stopPlayback();
     112           0 :         resetPlayer();
     113             :     }
     114             : 
     115             :     // notify _after_ state change:
     116           0 :     getContext().mrEventQueue.addEvent(
     117           0 :         makeEvent( boost::bind( &EventMultiplexer::notifyAudioStopped,
     118             :                                 boost::ref(getContext().mrEventMultiplexer),
     119             :                                 getSelf() ),
     120           0 :                    "AnimationAudioNode::notifyAudioStopped") );
     121           0 : }
     122             : 
     123           0 : bool AnimationAudioNode::hasPendingAnimation() const
     124             : {
     125             :     // force slide to use the animation framework
     126             :     // (otherwise, a single sound on the slide would
     127             :     // not be played).
     128           0 :     return true;
     129             : }
     130             : 
     131           0 : void AnimationAudioNode::createPlayer() const
     132             : {
     133           0 :     if (mpPlayer)
     134           0 :         return;
     135             : 
     136             :     try
     137             :     {
     138           0 :         mpPlayer = SoundPlayer::create( getContext().mrEventMultiplexer,
     139             :                                         maSoundURL,
     140           0 :                                         getContext().mxComponentContext );
     141             :     }
     142           0 :     catch( lang::NoSupportException& )
     143             :     {
     144             :         // catch possible exceptions from SoundPlayer,
     145             :         // since being not able to playback the sound
     146             :         // is not a hard error here (remainder of the
     147             :         // animations should still work).
     148             :     }
     149             : }
     150             : 
     151           0 : void AnimationAudioNode::resetPlayer() const
     152             : {
     153           0 :     if (mpPlayer)
     154             :     {
     155           0 :         mpPlayer->stopPlayback();
     156           0 :         mpPlayer->dispose();
     157           0 :         mpPlayer.reset();
     158             :     }
     159           0 : }
     160             : 
     161           0 : bool AnimationAudioNode::handleAnimationEvent(
     162             :     const AnimationNodeSharedPtr& /*rNode*/ )
     163             : {
     164             :     // TODO(F2): for now we support only STOPAUDIO events.
     165           0 :     deactivate();
     166           0 :     return true;
     167             : }
     168             : 
     169             : } // namespace internal
     170           3 : } // namespace presentation
     171             : 
     172             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11