sipvoipprovider/svphold/src/svpholdmediahandler.cpp
changeset 0 a4daefaec16c
equal deleted inserted replaced
-1:000000000000 0:a4daefaec16c
       
     1 /*
       
     2 * Copyright (c) 2006-2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Pauses and resumes audio stream.
       
    15 *
       
    16 */
       
    17 
       
    18 #include    <e32cmn.h>
       
    19 
       
    20 #include    <mcesession.h>
       
    21 #include    <mcemediastream.h>
       
    22 #include    <mceaudiostream.h>
       
    23 #include    <mcemediasource.h>
       
    24 #include    <mcemicsource.h>
       
    25 #include    <mcemediasink.h>
       
    26 #include    <mcespeakersink.h>
       
    27 #include    <mcertpsource.h>
       
    28 #include    <mcertpsink.h>
       
    29 
       
    30 #include    "svpholdcontext.h"
       
    31 #include    "svpholdmediahandler.h"
       
    32 #include    "svplogger.h"
       
    33 #include    "svpaudioutility.h"
       
    34 
       
    35 // ---------------------------------------------------------------------------
       
    36 // CSVPHoldMediaHandler::CSVPHoldMediaHandler
       
    37 // ---------------------------------------------------------------------------
       
    38 //
       
    39 CSVPHoldMediaHandler::CSVPHoldMediaHandler()
       
    40     {
       
    41     }
       
    42 
       
    43 
       
    44 // ---------------------------------------------------------------------------
       
    45 // CSVPHoldMediaHandler::NewL
       
    46 // ---------------------------------------------------------------------------
       
    47 //
       
    48 CSVPHoldMediaHandler* CSVPHoldMediaHandler::NewL()
       
    49     {
       
    50     CSVPHoldMediaHandler* self = new ( ELeave ) CSVPHoldMediaHandler;
       
    51     return self;
       
    52     }
       
    53 
       
    54 
       
    55 // ---------------------------------------------------------------------------
       
    56 // CSVPHoldMediaHandler::~CSVPHoldMediaHandler
       
    57 // ---------------------------------------------------------------------------
       
    58 //
       
    59 CSVPHoldMediaHandler::~CSVPHoldMediaHandler()
       
    60     {
       
    61     }
       
    62 
       
    63 // ---------------------------------------------------------------------------
       
    64 // CSVPHoldMediaHandler::PerformMediaActionL
       
    65 // ---------------------------------------------------------------------------
       
    66 //
       
    67 void CSVPHoldMediaHandler::PerformMediaActionL( CMceMediaStream& aMediaStream,
       
    68                                                 TSVPHoldRequestType aRequest )
       
    69     {
       
    70     SVPDEBUG1( "CSVPHoldMediaHandler::PerformMediaActionL - IN" );
       
    71 
       
    72     CMceMediaStream& boundStream = aMediaStream.BoundStreamL();
       
    73     
       
    74     // Always set the priorites because MCE/MCC must have those correctly
       
    75     // all the time. This is due to the fact that we may do session update
       
    76     // later and then the priority settings need to be correct.
       
    77     SVPAudioUtility::SetAudioStreamPrioritiesL( aMediaStream, boundStream );
       
    78     
       
    79     switch ( aRequest )
       
    80         {
       
    81         case ESVPLocalHold:
       
    82         case ESVPLocalDoubleHold:
       
    83             {            
       
    84             HandleLocalHoldingL( aMediaStream, boundStream );
       
    85             break;
       
    86             }
       
    87             
       
    88         case ESVPLocalResume:
       
    89         case ESVPLocalDoubleHoldResume:
       
    90             {
       
    91             HandleLocalResumingL( aMediaStream, boundStream, aRequest );
       
    92             break;
       
    93             }
       
    94                         
       
    95         case ESVPRemoteHold:
       
    96         case ESVPRemoteDoubleHold:
       
    97             {
       
    98             HandleRemoteHoldingL( aMediaStream, boundStream, aRequest );
       
    99             break;
       
   100             }
       
   101         
       
   102         case ESVPRemoteResume:
       
   103         case ESVPRemoteDoubleHoldResume:
       
   104             {
       
   105             HandleRemoteResumingL( aMediaStream, boundStream, aRequest );
       
   106             break;
       
   107             }
       
   108 
       
   109         default:
       
   110             {
       
   111             SVPDEBUG1( "CSVPHoldMediaHandler::PerformMediaActionL: Leave" );
       
   112             User::Leave( KErrNotFound );            
       
   113             }
       
   114         }
       
   115     SVPDEBUG1( "CSVPHoldMediaHandler::PerformMediaActionL - Out" );
       
   116     }
       
   117     
       
   118 // ---------------------------------------------------------------------------
       
   119 // CSVPHoldMediaHandler::HandleLocalHoldingL
       
   120 // ---------------------------------------------------------------------------
       
   121 //
       
   122 void CSVPHoldMediaHandler::
       
   123 HandleLocalHoldingL( CMceMediaStream& aMediaStream,
       
   124                      CMceMediaStream& aBoundStream )
       
   125     {
       
   126     SVPDEBUG1( "CSVPHoldMediaHandler::HandleLocalHoldingL - In" );
       
   127     
       
   128     // In case of local hold RTP source must be disabled
       
   129     if ( aMediaStream.Source() &&
       
   130          KMceRTPSource == aMediaStream.Source()->Type() )
       
   131         {
       
   132         aMediaStream.DisableL();
       
   133         }
       
   134     else if ( aBoundStream.Source() &&
       
   135               KMceRTPSource == aBoundStream.Source()->Type() )
       
   136         {
       
   137         aBoundStream.DisableL();
       
   138         }
       
   139     else
       
   140         {
       
   141         SVPDEBUG1( "CSVPHoldMediaHandler::HandleLocalHoldingL:" );
       
   142         SVPDEBUG1( "Local hold: No stream - User::Leave" );
       
   143         User::Leave( KErrNotFound );
       
   144         }
       
   145     
       
   146     SVPDEBUG1( "CSVPHoldMediaHandler::HandleLocalHoldingL - Out" );
       
   147     }
       
   148 
       
   149 // ---------------------------------------------------------------------------
       
   150 // CSVPHoldMediaHandler::HandleLocalResumingL
       
   151 // ---------------------------------------------------------------------------
       
   152 //
       
   153 void CSVPHoldMediaHandler::
       
   154 HandleLocalResumingL( CMceMediaStream& aMediaStream,
       
   155                       CMceMediaStream& aBoundStream,
       
   156                       TSVPHoldRequestType aRequest )
       
   157     {
       
   158     SVPDEBUG1( "CSVPHoldMediaHandler::HandleLocalResumingL - In" );
       
   159     
       
   160     switch ( aRequest )
       
   161         {
       
   162         case ESVPLocalResume:
       
   163             {
       
   164             // In case of local resume disabled stream must be enabled              
       
   165             SVPDEBUG1( "CSVPHoldMediaHandler::HandleLocalResumingL - LocalResume" );
       
   166             if ( !aBoundStream.IsEnabled() )
       
   167                 {
       
   168                 aBoundStream.EnableL();
       
   169                 }
       
   170                 
       
   171             if ( !aMediaStream.IsEnabled() )
       
   172                 {
       
   173                 aMediaStream.EnableL();
       
   174                 }
       
   175             
       
   176             break;
       
   177             }
       
   178             
       
   179         case ESVPLocalDoubleHoldResume:
       
   180             {
       
   181             // In case of localDH resume RTP source must be enabled
       
   182             if ( KMceRTPSource == aMediaStream.Source()->Type() )
       
   183                 {
       
   184                 aMediaStream.EnableL();
       
   185                 }
       
   186                 
       
   187             else if ( KMceRTPSource == aBoundStream.Source()->Type() )
       
   188                 {
       
   189                 aBoundStream.EnableL();
       
   190                 }
       
   191                 
       
   192             else
       
   193                 {
       
   194                 SVPDEBUG1( "CSVPHoldMediaHandler::HandleLocalResumingL:" );
       
   195                 SVPDEBUG1( "Local DH resume: No stream - User::Leave" );
       
   196                 User::Leave( KErrNotFound );
       
   197                 }            
       
   198 
       
   199             break;
       
   200             }
       
   201             
       
   202         default:
       
   203             {
       
   204             User::Leave( KErrNotFound );
       
   205             }
       
   206         }
       
   207     
       
   208     SVPDEBUG1( "CSVPHoldMediaHandler::HandleLocalResumingL - Out" );
       
   209     }
       
   210 
       
   211 // ---------------------------------------------------------------------------
       
   212 // CSVPHoldMediaHandler::HandleRemoteHoldingL
       
   213 // ---------------------------------------------------------------------------
       
   214 //
       
   215 void CSVPHoldMediaHandler::
       
   216 HandleRemoteHoldingL( CMceMediaStream& aMediaStream,
       
   217                       CMceMediaStream& aBoundStream,
       
   218                       TSVPHoldRequestType aRequest )
       
   219     {
       
   220     SVPDEBUG1( "CSVPHoldMediaHandler::HandleRemoteHoldingL - In" );
       
   221     
       
   222     // In case of remote hold RTP sink must be disabled    
       
   223     if ( KMceRTPSource == aMediaStream.Source()->Type() )
       
   224         {
       
   225         aBoundStream.DisableL();
       
   226         if ( ESVPRemoteDoubleHold == aRequest )
       
   227             {
       
   228             aMediaStream.DisableL();
       
   229             }
       
   230         }
       
   231         
       
   232     else if ( KMceRTPSource == aBoundStream.Source()->Type() )
       
   233         {
       
   234         aMediaStream.DisableL();
       
   235         if ( ESVPRemoteDoubleHold == aRequest )
       
   236             {
       
   237             aBoundStream.DisableL();
       
   238             }
       
   239         }
       
   240         
       
   241     else
       
   242         {
       
   243         SVPDEBUG1( "CSVPHoldMediaHandler::HandleRemoteHoldingL:" );
       
   244         SVPDEBUG1( "Remote hold: No stream - User::Leave" );
       
   245         User::Leave( KErrNotFound );
       
   246         }    
       
   247 
       
   248     SVPDEBUG1( "CSVPHoldMediaHandler::HandleRemoteHoldingL - Out" );
       
   249     }
       
   250 
       
   251 // ---------------------------------------------------------------------------
       
   252 // CSVPHoldMediaHandler::HandleRemoteResumingL
       
   253 // ---------------------------------------------------------------------------
       
   254 //
       
   255 void CSVPHoldMediaHandler::
       
   256 HandleRemoteResumingL( CMceMediaStream& aMediaStream,
       
   257                        CMceMediaStream& aBoundStream,
       
   258                        TSVPHoldRequestType aRequest )
       
   259     {
       
   260     SVPDEBUG1( "CSVPHoldMediaHandler::HandleRemoteResumingL - In" )
       
   261     
       
   262     switch ( aRequest )
       
   263         {
       
   264         case ESVPRemoteResume:
       
   265             {
       
   266             SVPDEBUG2( "CSVPHoldMediaHandler::HandleRemoteResumingL aBound ena: %d",
       
   267                 aBoundStream.IsEnabled() )
       
   268             
       
   269             SVPDEBUG2( "CSVPHoldMediaHandler::HandleRemoteResumingL aMedia ena: %d",
       
   270                 aMediaStream.IsEnabled() )
       
   271             
       
   272             // In case of remote resume disabled stream(s) must be enabled
       
   273             if ( !aBoundStream.IsEnabled() )
       
   274                 {
       
   275                 SVPDEBUG1( "CSVPHoldMediaHandler::HandleRemoteResumingL RR 1st ena/dis" )
       
   276                 
       
   277                 aBoundStream.EnableL();
       
   278                 aMediaStream.DisableL();
       
   279                 }
       
   280                 
       
   281             if ( !aMediaStream.IsEnabled() )
       
   282                 {
       
   283                 SVPDEBUG1( "CSVPHoldMediaHandler::HandleRemoteResumingL RR 2nd ena/dis" )
       
   284                 
       
   285                 aMediaStream.EnableL();
       
   286                 aBoundStream.DisableL();
       
   287                 }
       
   288             
       
   289             break;
       
   290             }
       
   291             
       
   292         case ESVPRemoteDoubleHoldResume:
       
   293             {
       
   294             // In case of remoteDH resume RTP sink must be enabled                    
       
   295             if ( KMceRTPSource == aMediaStream.Source()->Type() )
       
   296                 {
       
   297                 aBoundStream.EnableL();
       
   298                 aMediaStream.DisableL();
       
   299                 }
       
   300             
       
   301             else if ( KMceRTPSource == aBoundStream.Source()->Type() )
       
   302                 {
       
   303                 aMediaStream.EnableL();
       
   304                 aBoundStream.DisableL();
       
   305                 }
       
   306             
       
   307             else
       
   308                 {
       
   309                 SVPDEBUG1( "CSVPHoldMediaHandler::HandleRemoteResumingL:" );
       
   310                 SVPDEBUG1( "Remote DH resume: No stream - User::Leave" );
       
   311                 User::Leave( KErrNotFound );
       
   312                 }
       
   313             
       
   314             break;
       
   315             }
       
   316             
       
   317         default:
       
   318             {
       
   319             User::Leave( KErrNotFound );
       
   320             }
       
   321         }
       
   322     
       
   323     SVPDEBUG1( "CSVPHoldMediaHandler::HandleRemoteResumingL - Out" )
       
   324     }
       
   325 
       
   326 // ---------------------------------------------------------------------------
       
   327 // CSVPHoldMediaHandler::DisableAudioL
       
   328 // ---------------------------------------------------------------------------
       
   329 //
       
   330 void CSVPHoldMediaHandler::DisableAudioL( CSVPHoldContext& aContext,
       
   331                                           TBool aLeaveSpeakerEnabled )
       
   332     {
       
   333     if ( aContext.AudioHandlingAllowed() )
       
   334         {
       
   335         // Disable speaker & microphone
       
   336         SVPDEBUG1( "CSVPHoldMediaHandler::DisableAudioL - Disabling audio..." );
       
   337         CMceSession* session = aContext.SessionObject();
       
   338         const RPointerArray< CMceMediaStream >& streams = session->Streams();
       
   339         TInt streamCount = streams.Count();
       
   340         for ( TInt i = 0; i < streamCount; i++ )
       
   341             {
       
   342             CMceMediaStream* mediaStream = streams[ i ];
       
   343             TMceMediaType mediaType = mediaStream->Type();
       
   344             if ( KMceAudio == mediaType )
       
   345                 {
       
   346                 TSVPHoldRequestType request = aContext.HoldRequest();
       
   347                 
       
   348                 CMceMediaStream& boundStream = mediaStream->BoundStreamL();
       
   349                 DisableAudioStreamL( boundStream, aLeaveSpeakerEnabled );
       
   350                 DisableAudioStreamL( *mediaStream, aLeaveSpeakerEnabled );
       
   351                 SVPDEBUG1( "CSVPHoldMediaHandler::DisableAudioL - Audio disabled" );
       
   352                 }
       
   353             }
       
   354         }
       
   355     }
       
   356 
       
   357 // ---------------------------------------------------------------------------
       
   358 // CSVPHoldMediaHandler::DisableAudioStreamL
       
   359 // ---------------------------------------------------------------------------
       
   360 //
       
   361 void CSVPHoldMediaHandler::DisableAudioStreamL( CMceMediaStream& aAudioStream,
       
   362                                                 TBool aLeaveSpeakerEnabled )
       
   363     {
       
   364     SVPDEBUG1( "CSVPHoldMediaHandler::DisableAudioL - In" );
       
   365     
       
   366     SVPAudioUtility::DisableMicSourceL( aAudioStream );
       
   367     if ( !aLeaveSpeakerEnabled )
       
   368         {
       
   369         SVPAudioUtility::DisableSpeakerSinkL( aAudioStream.Sinks() );
       
   370         }
       
   371     
       
   372     SVPDEBUG1( "CSVPHoldMediaHandler::DisableAudioL - Out" );
       
   373     }
       
   374 
       
   375 // ---------------------------------------------------------------------------
       
   376 // CSVPHoldMediaHandler::EnableAudioL
       
   377 // ---------------------------------------------------------------------------
       
   378 //
       
   379 void CSVPHoldMediaHandler::EnableAudioL( CSVPHoldContext& aContext )
       
   380     {
       
   381     if ( aContext.AudioHandlingAllowed() )
       
   382         {
       
   383         // Enable speaker & microphone
       
   384         SVPDEBUG1( "CSVPHoldMediaHandler::EnableAudioL - Enabling audio..." );
       
   385         
       
   386         const RPointerArray< CMceMediaStream >& streams =
       
   387             aContext.SessionObject()->Streams();
       
   388         const TInt streamCount = streams.Count();
       
   389         for ( TInt i = 0; i < streamCount; i++ )
       
   390             {
       
   391             CMceMediaStream* mediaStream = streams[ i ];
       
   392             if ( KMceAudio == mediaStream->Type() )
       
   393                 {
       
   394                 EnableAudioL( *mediaStream, aContext );
       
   395                 }
       
   396             }
       
   397         }
       
   398     }
       
   399 
       
   400 
       
   401 // ---------------------------------------------------------------------------
       
   402 // CSVPHoldMediaHandler::EnableAudioL (private)
       
   403 // ---------------------------------------------------------------------------
       
   404 //
       
   405 void CSVPHoldMediaHandler::EnableAudioL( CMceMediaStream& aMediaStream,
       
   406                                          CSVPHoldContext& aContext )
       
   407     {
       
   408     SVPDEBUG1( "CSVPHoldMediaHandler::EnableAudioL - Audio enabled In" );
       
   409 
       
   410     TBool muted = aContext.Muted();
       
   411     TBool mobileOriginated = aContext.IsMobileOriginated();
       
   412 
       
   413     // Now enable the audio streams.
       
   414     if ( !muted )
       
   415         {
       
   416         // Normal case, audio not muted
       
   417         SVPDEBUG1( "CSVPHoldMediaHandler::EnableAudioL - no mute" );
       
   418         EnableAudioStreamL( aMediaStream.BoundStreamL() );
       
   419         EnableAudioStreamL( aMediaStream );
       
   420         }
       
   421         
       
   422     else
       
   423         {
       
   424         // Enabling depends on the direction of muted stream
       
   425         if ( mobileOriginated || aContext.IsRemoteRequest() )
       
   426             {
       
   427             SVPDEBUG1( "CSVPHoldMediaHandler::EnableAudioL - Bound" );
       
   428             EnableAudioStreamL( aMediaStream.BoundStreamL(), EFalse );
       
   429             EnableAudioStreamL( aMediaStream, EFalse );
       
   430             // Make sure that mic is disabled
       
   431             SVPAudioUtility::DisableMicSourceL( *( aMediaStream.Source() ) );
       
   432             SVPAudioUtility::DisableMicSourceL( *( aMediaStream.BoundStreamL().
       
   433                                                                   Source() ) );
       
   434             }
       
   435         else
       
   436             {
       
   437             SVPDEBUG1( "CSVPHoldMediaHandler::EnableAudioL - Main" );
       
   438             EnableAudioStreamL( aMediaStream, EFalse );
       
   439             EnableAudioStreamL( aMediaStream.BoundStreamL(), EFalse );
       
   440             // Make sure that mic is disabled
       
   441             SVPAudioUtility::DisableMicSourceL( aMediaStream );
       
   442             SVPAudioUtility::DisableMicSourceL( aMediaStream.BoundStreamL() );
       
   443             }
       
   444         }
       
   445 
       
   446     SVPDEBUG1( "CSVPHoldMediaHandler::EnableAudioL - Audio enabled Out" );    
       
   447     }
       
   448 
       
   449 
       
   450 // ---------------------------------------------------------------------------
       
   451 // CSVPHoldMediaHandler::EnableAudioStreamL
       
   452 // ---------------------------------------------------------------------------
       
   453 //
       
   454 void CSVPHoldMediaHandler::EnableAudioStreamL( CMceMediaStream& aAudioStream,
       
   455                                                TBool aAllowMicEnable )
       
   456     {
       
   457     SVPDEBUG1( "CSVPHoldMediaHandler::EnableAudioStreamL - In" );
       
   458     
       
   459 
       
   460     const RPointerArray< CMceMediaSink >& sinks = aAudioStream.Sinks();
       
   461     TInt snkCount( sinks.Count() );
       
   462 
       
   463     // Go throug every sink that is associated to that stream
       
   464     for ( TInt i = 0; i < snkCount; i++ )
       
   465         {
       
   466         SVPDEBUG2( "CSVPHoldMediaHandler::EnableAudioStreamL -  Check sink # %d", i );
       
   467         if ( !sinks[ i ]->IsEnabled() )
       
   468             {
       
   469             SVPDEBUG1( "CSVPHoldMediaHandler::EnableAudioStreamL - disabled" )
       
   470             sinks[ i ]->EnableL();            
       
   471             SVPDEBUG1( "CSVPHoldMediaHandler::EnableAudioStreamL - ENABLED" )
       
   472             }
       
   473         }
       
   474 
       
   475     if ( aAudioStream.Source() &&
       
   476          ( KMceMicSource == aAudioStream.Source()->Type() ||
       
   477            KMceRTPSource == aAudioStream.Source()->Type() ) )
       
   478         {
       
   479         CMceMediaSource* source = aAudioStream.Source();
       
   480         if ( !source->IsEnabled() && aAllowMicEnable )
       
   481             {
       
   482             // Enable source
       
   483             source->EnableL();
       
   484             SVPDEBUG1( "CSVPHoldMediaHandler::EnableAudioStreamL - Source" );
       
   485             }
       
   486         }
       
   487     
       
   488     SVPDEBUG1( "CSVPHoldMediaHandler::EnableAudioStreamL - Out" );
       
   489     }
       
   490 
       
   491