multimediacommsengine/mmcesrv/mmcemediamanager/src/mceofferingmedia.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2005 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:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include "mceofferingmedia.h"
       
    22 #include "mcemediamanager.h"
       
    23 #include "mcestartingofferersendstreams.h"
       
    24 #include "mcesdpsession.h"
       
    25 #include "mcecomsession.h"
       
    26 #include "mcemediaobserver.h"
       
    27 #include "mcesrvstreamiterator.h"
       
    28 #include "mceevents.h"
       
    29 #include "mcemmlogs.h"
       
    30 #include <sdpdocument.h>
       
    31 
       
    32 
       
    33 
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // TMceOfferingMedia::SetAsCurrentStateL
       
    37 // -----------------------------------------------------------------------------
       
    38 //
       
    39 void TMceOfferingMedia::SetAsCurrentStateL( CMceComSession& aSession, TBool aFromSubstate )
       
    40     {
       
    41     MCEMM_DEBUG("TMceOfferingMedia::SetAsCurrentStateL() ");
       
    42     
       
    43     if ( !aFromSubstate )
       
    44         {
       
    45         TBool signalling = aSession.SdpSession().SignallingRequired() != KMceNoSignalling ||
       
    46                            aSession.iFcSignallingRequired ||
       
    47                            aSession.iRequireSignalling;
       
    48                            
       
    49         MCEMM_DEBUG_DVALUE( "TMceOfferingMedia: fc signalling required:", 
       
    50                             aSession.iFcSignallingRequired );
       
    51                             
       
    52         MCEMM_DEBUG_DVALUE( "TMceOfferingMedia: signalling required:", 
       
    53                             aSession.iRequireSignalling );
       
    54                             
       
    55         TBool update = MCE_NOT_NULL_PTR( aSession.Backup() );
       
    56         
       
    57         if ( !update )
       
    58             {
       
    59             if ( !signalling )
       
    60                 //wait answer offer
       
    61                 {
       
    62                 MCEMM_DEBUG("TMceOfferingMedia: waiting answer to offer ");
       
    63                 TMceOfferingMedia::TMceMediaReady::SetAsCurrentStateL( aSession );
       
    64                 }
       
    65             else
       
    66                 {
       
    67                 //wait answer re-offer
       
    68                 MCEMM_DEBUG("TMceOfferingMedia: waiting answer to update ");
       
    69                 TMceOfferingMedia::TMceMediaUpdateReady::SetAsCurrentStateL( aSession );
       
    70                 }
       
    71             }
       
    72         else//update
       
    73             {
       
    74             if ( !signalling )
       
    75                 //no signalling pass through
       
    76                 {
       
    77                 MCEMM_DEBUG("TMceOfferingMedia: update - no signalling, no waiting");
       
    78                 TMceStartingOffererSendStreams::SetAsCurrentStateL( aSession );
       
    79                 }
       
    80             else
       
    81                 {
       
    82                 MCEMM_DEBUG("TMceOfferingMedia: update - waiting answer to update ");
       
    83                 TMceOfferingMedia::TMceMediaUpdateReady::SetAsCurrentStateL( aSession );
       
    84                 }
       
    85             }
       
    86         }
       
    87    else
       
    88         {
       
    89         TMceOfferingMedia*
       
    90             self = new (ELeave) TMceOfferingMedia( aSession );
       
    91 
       
    92         CleanupStack::PushL( self );
       
    93         aSession.SetNegotiationStateL( self );
       
    94         CleanupStack::Pop( self );
       
    95         
       
    96         }
       
    97    }
       
    98 
       
    99 
       
   100 // -----------------------------------------------------------------------------
       
   101 // TMceOfferingMedia::TMceMediaReady::SetAsCurrentStateL
       
   102 // -----------------------------------------------------------------------------
       
   103 //
       
   104 void TMceOfferingMedia::TMceMediaReady::SetAsCurrentStateL( CMceComSession& aSession )
       
   105     {
       
   106     MCEMM_DEBUG("TMceOfferingMedia::TMceMediaReady::SetAsCurrentStateL() ");
       
   107     
       
   108     TMceOfferingMedia::TMceMediaReady*
       
   109         self = new (ELeave) TMceOfferingMedia::TMceMediaReady( aSession );
       
   110     
       
   111     CleanupStack::PushL( self );
       
   112     aSession.SetNegotiationStateL( self );
       
   113     CleanupStack::Pop( self );
       
   114     
       
   115     }
       
   116 
       
   117 // -----------------------------------------------------------------------------
       
   118 // TMceOfferingMedia::TMceMediaUpdateReady::SetAsCurrentStateL
       
   119 // -----------------------------------------------------------------------------
       
   120 //
       
   121 void TMceOfferingMedia::TMceMediaUpdateReady::SetAsCurrentStateL( CMceComSession& aSession )
       
   122     {
       
   123     MCEMM_DEBUG("TMceOfferingMedia::TMceMediaUpdateReady::SetAsCurrentStateL() ");
       
   124     
       
   125     TMceOfferingMedia::TMceMediaUpdateReady*
       
   126         self = new (ELeave) TMceOfferingMedia::TMceMediaUpdateReady( aSession );
       
   127 
       
   128     CleanupStack::PushL( self );
       
   129     aSession.SetNegotiationStateL( self );
       
   130     CleanupStack::Pop( self );
       
   131     
       
   132     }
       
   133 
       
   134 // -----------------------------------------------------------------------------
       
   135 // TMceOfferingMedia::TMceWaitingAnswer::SetAsCurrentStateL
       
   136 // -----------------------------------------------------------------------------
       
   137 //
       
   138 void TMceOfferingMedia::TMceWaitingAnswer::SetAsCurrentStateL( CMceComSession& aSession )
       
   139     {
       
   140     MCEMM_DEBUG("TMceOfferingMedia::TMceWaitingAnswer::SetAsCurrentStateL() ");
       
   141 
       
   142     TMceOfferingMedia::TMceWaitingAnswer*
       
   143         self = new (ELeave) TMceOfferingMedia::TMceWaitingAnswer( aSession );
       
   144 
       
   145     CleanupStack::PushL( self );
       
   146     aSession.SetNegotiationStateL( self );
       
   147     CleanupStack::Pop( self );
       
   148 
       
   149     }
       
   150 
       
   151 
       
   152 // -----------------------------------------------------------------------------
       
   153 // TMceOfferingMedia::TMceOfferingMedia
       
   154 // -----------------------------------------------------------------------------
       
   155 //
       
   156 TMceOfferingMedia::TMceOfferingMedia( CMceComSession& aSession )
       
   157     : TMceMediaState( aSession )
       
   158     {
       
   159     }
       
   160 
       
   161 // -----------------------------------------------------------------------------
       
   162 // TMceOfferingMedia::TMceMediaReady::TMceMediaReady
       
   163 // -----------------------------------------------------------------------------
       
   164 //
       
   165 TMceOfferingMedia::TMceMediaReady::TMceMediaReady( CMceComSession& aSession )
       
   166     : TMceMediaState( aSession )
       
   167     {
       
   168     }
       
   169 
       
   170 // -----------------------------------------------------------------------------
       
   171 // TMceOfferingMedia::TMceMediaUpdateReady::TMceMediaUpdateReady
       
   172 // -----------------------------------------------------------------------------
       
   173 //
       
   174 TMceOfferingMedia::TMceMediaUpdateReady::TMceMediaUpdateReady( CMceComSession& aSession )
       
   175     : TMceOfferingMedia::TMceMediaReady( aSession )
       
   176     {
       
   177     }
       
   178 
       
   179 // -----------------------------------------------------------------------------
       
   180 // TMceOfferingMedia::TMceWaitingAnswer::TMceWaitingAnswer
       
   181 // -----------------------------------------------------------------------------
       
   182 //
       
   183 TMceOfferingMedia::TMceWaitingAnswer::TMceWaitingAnswer( CMceComSession& aSession )
       
   184     : TMceMediaState( aSession )
       
   185     {
       
   186     }
       
   187 
       
   188 
       
   189 
       
   190 // -----------------------------------------------------------------------------
       
   191 // TMceOfferingMedia::TMceMediaReady::Callback
       
   192 // -----------------------------------------------------------------------------
       
   193 //
       
   194 void TMceOfferingMedia::TMceMediaReady::Callback()
       
   195     {
       
   196     
       
   197     iSession.MediaObserver().Updated( iSession );
       
   198     
       
   199     }
       
   200 
       
   201 
       
   202 // -----------------------------------------------------------------------------
       
   203 // TMceOfferingMedia::TMceMediaReady::EncodeL
       
   204 // -----------------------------------------------------------------------------
       
   205 //
       
   206 CSdpDocument* TMceOfferingMedia::TMceMediaReady::EncodeL()
       
   207     {
       
   208     MCEMM_DEBUG("TMceOfferingMedia::TMceMediaReady::EncodeL, Entry ");
       
   209 
       
   210     CSdpDocument* sdp = iSession.SdpSession().CreateOfferL( iSession,
       
   211                                                             CMceSdpSession::EFirst );
       
   212     CleanupStack::PushL( sdp );
       
   213     iSession.SdpSession().StockMediaSessionL();
       
   214     TMceOfferingMedia::TMceWaitingAnswer::SetAsCurrentStateL( iSession );
       
   215     CleanupStack::Pop( sdp );
       
   216     
       
   217     MCEMM_DEBUG("TMceOfferingMedia::TMceMediaReady::EncodeL, Exit ");
       
   218     
       
   219     return sdp;
       
   220     
       
   221     }
       
   222 
       
   223 // -----------------------------------------------------------------------------
       
   224 // TMceOfferingMedia::TMceMediaUpdateReady::EncodeL
       
   225 // -----------------------------------------------------------------------------
       
   226 //
       
   227 CSdpDocument* TMceOfferingMedia::TMceMediaUpdateReady::EncodeL()
       
   228     {
       
   229     
       
   230     MCEMM_DEBUG("TMceOfferingMedia::TMceMediaUpdateReady::EncodeL, Entry ");
       
   231     
       
   232     CSdpDocument* sdp = iSession.SdpSession().CreateOfferL( iSession, 
       
   233                                                             CMceSdpSession::EUpdate );
       
   234     
       
   235     // Sdp not pushed, ownership elsewhere
       
   236     TMceOfferingMedia::TMceWaitingAnswer::SetAsCurrentStateL( iSession );
       
   237     
       
   238     MCEMM_DEBUG("TMceOfferingMedia::TMceMediaUpdateReady::EncodeL, Exit ");
       
   239     
       
   240     return sdp;
       
   241 
       
   242     }
       
   243 
       
   244 
       
   245 // -----------------------------------------------------------------------------
       
   246 // TMceOfferingMedia::TMceMediaUpdateReady::NeedToNegotiate
       
   247 // -----------------------------------------------------------------------------
       
   248 //
       
   249 TBool TMceOfferingMedia::TMceMediaUpdateReady::NeedToNegotiate( CSdpDocument* /*aSdpDocument*/ )
       
   250     {
       
   251     MCEMM_DEBUG("TMceOfferingMedia::TMceMediaUpdateReady::NeedToNegotiate() ");
       
   252     
       
   253     return ETrue;
       
   254     }
       
   255 
       
   256 
       
   257 // -----------------------------------------------------------------------------
       
   258 // TMceOfferingMedia::TMceWaitingAnswer::CloneL
       
   259 // -----------------------------------------------------------------------------
       
   260 //
       
   261 TMceMediaState* TMceOfferingMedia::TMceWaitingAnswer::CloneL( CMceComSession& aSession ) const
       
   262     {
       
   263     TMceOfferingMedia::TMceWaitingAnswer*
       
   264         state = new (ELeave) TMceOfferingMedia::TMceWaitingAnswer( aSession );
       
   265     
       
   266     state->SetRole( Role() );
       
   267     state->iStackIndex = iStackIndex;
       
   268     
       
   269     return state;
       
   270     
       
   271     }
       
   272 
       
   273 // -----------------------------------------------------------------------------
       
   274 // TMceOfferingMedia::TMceWaitingAnswer::DecodeL
       
   275 // -----------------------------------------------------------------------------
       
   276 //
       
   277 TMceSipWarningCode TMceOfferingMedia::TMceWaitingAnswer::DecodeL( CSdpDocument& aSdpDocument )
       
   278     {
       
   279     MCEMM_DEBUG("TMceOfferingMedia::TMceWaitingAnswer::DecodeL, Entry ");
       
   280 
       
   281     TMceSipWarningCode status = (TMceSipWarningCode)KErrNone;
       
   282     
       
   283     if ( !iSession.SdpSession().ContextSwitchRequested() )
       
   284         {
       
   285         status = iSession.SdpSession().DecodeAnswerL( aSdpDocument, iSession );
       
   286         TMceOfferingMedia::SetAsCurrentStateL( iSession, KFromSubstate );
       
   287         }
       
   288     else
       
   289         {
       
   290         CMceSdpSession& forkedSdpSession = iSession.SdpSession().ForkL();
       
   291         CMceComSession& forkedSession = *forkedSdpSession.MediaSession();
       
   292         status = forkedSession.NegotiationState().DecodeL( aSdpDocument );
       
   293         }
       
   294 
       
   295     
       
   296     MCEMM_DEBUG("TMceOfferingMedia::TMceWaitingAnswer::DecodeL, Exit ");
       
   297     
       
   298     return status;
       
   299     
       
   300     }
       
   301 
       
   302 // -----------------------------------------------------------------------------
       
   303 // TMceOfferingMedia::TMceMediaReady::NeedToNegotiate
       
   304 // -----------------------------------------------------------------------------
       
   305 //
       
   306 TBool TMceOfferingMedia::TMceWaitingAnswer::NeedToNegotiate( CSdpDocument* /*aSdpDocument*/ )
       
   307     {
       
   308     MCEMM_DEBUG("TMceOfferingMedia::TMceWaitingAnswer::NeedToNegotiate() ");
       
   309     
       
   310     return ETrue;
       
   311     }
       
   312 
       
   313 // -----------------------------------------------------------------------------
       
   314 // TMceOfferingMedia::UpdateL
       
   315 // -----------------------------------------------------------------------------
       
   316 //
       
   317 
       
   318 void TMceOfferingMedia::UpdateL()
       
   319     {
       
   320 
       
   321     MCEMM_DEBUG("TMceOfferingMedia::UpdateL(), Entry ");
       
   322     
       
   323     CMceSrvStream* stream = NULL;
       
   324     
       
   325     // check if non-local media was rejected, if yes then stop the stream
       
   326     iSession.SdpSession().Manager().CleanupL( iSession );
       
   327     
       
   328     //set remote ip address for all non stopped receive only streams (RTP keep alive)
       
   329     TMceSrvStreamIterator recvonlyStreams( iSession.MccStreams(), 
       
   330                                            TMceSrvStreamIterator::EReceive );
       
   331     while( recvonlyStreams.Next( stream, CMceSrvStream::EStopped, 
       
   332                                  TMceSrvStreamIterator::ExactReverseMatch ) )
       
   333                                      
       
   334         {
       
   335         if ( stream->State() != CMceSrvStream::EInactive &&
       
   336              stream->Direction() == CMceComMediaStream::EReceiveOnlyStream )
       
   337             {
       
   338             MCEMM_DEBUG_STREAM( "TMceOfferingMedia::UpdateL(): \
       
   339 setting remote address for downlink stream", *stream );
       
   340             iSession.SdpSession().Manager().SetRemoteAddressL( *stream );
       
   341             }
       
   342         }
       
   343     
       
   344     //do validation & adjustments for all non stopped active send streams
       
   345     TMceSrvStreamIterator sendStreams( iSession.MccStreams(), TMceSrvStreamIterator::ESend );
       
   346     while( sendStreams.Next( stream, CMceSrvStream::EStopped, 
       
   347                              TMceSrvStreamIterator::ExactReverseMatch ) )
       
   348                                      
       
   349         {
       
   350         if ( stream->State() != CMceSrvStream::EInactive &&
       
   351              stream->Codec().iIsNegotiated )
       
   352             { 
       
   353             iSession.SdpSession().Manager().AdjustMccStreamL( *stream );
       
   354             MCEMM_DEBUG_STREAM( "TMceOfferingMedia::UpdateL(): adjusted stream", *stream );
       
   355             }
       
   356         }
       
   357 
       
   358 
       
   359 
       
   360     //set next state, this state will become unusable
       
   361     TMceStartingOffererSendStreams::SetAsCurrentStateL( iSession  );
       
   362     
       
   363     
       
   364     MCEMM_DEBUG("TMceOfferingMedia::UpdateL(), Exit ");
       
   365     }
       
   366