multimediacommsengine/mmceshared/src/mcecomavsink.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2006 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 "mcecomavsink.h"
       
    22 #include "mceavsink.h"
       
    23 #include "mceevents.h"
       
    24 #include "mcecomcodec.h"
       
    25 #include "mcecommediastream.h"
       
    26 #include "mcecomsession.h"
       
    27 #include "mcedisplaysink.h"
       
    28 #include "mcecomdisplaysink.h"
       
    29 #include "mcespeakersink.h"
       
    30 #include "mcecomspeakersink.h"
       
    31 
       
    32 #ifdef MCE_COMMON_SERVER_SIDE
       
    33 
       
    34 #include <mmccinterface.h>
       
    35 #include "mcesdpsession.h"
       
    36 #include "mcemediamanager.h"
       
    37 
       
    38 #endif//MCE_COMMON_SERVER_SIDE
       
    39 
       
    40 // ============================ MEMBER FUNCTIONS ===============================
       
    41 
       
    42 
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 // CMceComAvSink::NewL
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 CMceComAvSink* CMceComAvSink::NewL()
       
    49     {
       
    50     CMceComAvSink* self = NewLC();
       
    51     CleanupStack::Pop( self );
       
    52     return self;
       
    53     }
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // CMceComAvSink::NewLC
       
    57 // -----------------------------------------------------------------------------
       
    58 //
       
    59 CMceComAvSink* CMceComAvSink::NewLC()
       
    60     {
       
    61     CMceComAvSink* self = new (ELeave) CMceComAvSink();
       
    62     CleanupStack::PushL( self );
       
    63     return self;
       
    64     }
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // CMceComAvSink::~CMceComAvSink
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 CMceComAvSink::~CMceComAvSink()
       
    71     {
       
    72     delete iSettings;
       
    73     iProxyClients.Close();
       
    74     
       
    75     }
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // CMceComAvSink::ServesProxyClient
       
    79 // -----------------------------------------------------------------------------
       
    80 //
       
    81 TBool CMceComAvSink::ServesProxyClient( const CMceComEndpoint& aClient ) const
       
    82     {
       
    83     TBool found = EFalse;
       
    84     TInt index = 0;
       
    85     while ( !found && index < iProxyClients.Count() )
       
    86         {
       
    87         found = iProxyClients[ index ++ ]->Id() == aClient.Id();
       
    88         }
       
    89     
       
    90     return found;
       
    91     
       
    92     }
       
    93 
       
    94 
       
    95 // -----------------------------------------------------------------------------
       
    96 // CMceComAvSink::AddProxyClientL
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 void CMceComAvSink::AddProxyClientL( CMceComEndpoint& aClient )
       
   100     {
       
   101     iProxyClients.AppendL( &aClient );
       
   102     ReferenceCount()++;
       
   103     }
       
   104 
       
   105 // -----------------------------------------------------------------------------
       
   106 // CMceComAvSink::RemoveProxyClient
       
   107 // -----------------------------------------------------------------------------
       
   108 //
       
   109 void CMceComAvSink::RemoveProxyClient( CMceComEndpoint& aClient )
       
   110     {
       
   111     TInt index = iProxyClients.Find( &aClient );
       
   112     if ( index >= 0 )
       
   113         {
       
   114         iProxyClients.Remove( index );
       
   115         ReferenceCount()--;
       
   116         }
       
   117     }
       
   118 
       
   119 
       
   120 // -----------------------------------------------------------------------------
       
   121 // CMceComAvSink::CMceComAvSink
       
   122 // -----------------------------------------------------------------------------
       
   123 //
       
   124 CMceComAvSink::CMceComAvSink()
       
   125   : CMceComMediaSink( KMceAvSink )
       
   126     {
       
   127     }
       
   128 
       
   129 // -----------------------------------------------------------------------------
       
   130 // CMceComAvSink::CloneL
       
   131 // -----------------------------------------------------------------------------
       
   132 //
       
   133 CMceComMediaSink* CMceComAvSink::CloneL()
       
   134     {
       
   135     CMceComAvSink* copy = new (ELeave) CMceComAvSink();
       
   136     Mem::Copy( copy, this, sizeof(CMceComAvSink) );
       
   137     copy->Zero();
       
   138     copy->iSettings = 0;
       
   139     return copy;
       
   140         
       
   141     }
       
   142 
       
   143 
       
   144 // -----------------------------------------------------------------------------
       
   145 // CMceComAvSink::InternalizeFlatL
       
   146 // -----------------------------------------------------------------------------
       
   147 //
       
   148 void CMceComAvSink::InternalizeFlatL( RReadStream& aReadStream )
       
   149     {
       
   150     CMceComMediaSink::InternalizeFlatL( aReadStream );
       
   151     }
       
   152 
       
   153 
       
   154 
       
   155 // -----------------------------------------------------------------------------
       
   156 // CMceComAvSink::ExternalizeFlatL
       
   157 // -----------------------------------------------------------------------------
       
   158 //
       
   159 void CMceComAvSink::ExternalizeFlatL( RWriteStream& aWriteStream )
       
   160     {
       
   161     CMceComMediaSink::ExternalizeFlatL( aWriteStream );
       
   162     }
       
   163 
       
   164   
       
   165     
       
   166 // -----------------------------------------------------------------------------
       
   167 // CMceComAvSink::EventReceivedL
       
   168 // -----------------------------------------------------------------------------
       
   169 //
       
   170 TInt CMceComAvSink::EventReceivedL( TMceComEvent& aEvent )
       
   171     {
       
   172     TInt status = CMceComMediaSink::EventReceivedL( aEvent );
       
   173     return status;
       
   174     
       
   175     }
       
   176     
       
   177     
       
   178 // -----------------------------------------------------------------------------
       
   179 // CMceComAvSink::UpdateL
       
   180 // -----------------------------------------------------------------------------
       
   181 //
       
   182 void CMceComAvSink::UpdateL( CMceComMediaSink& aUpdate )
       
   183     {
       
   184     CMceComMediaSink::UpdateL( aUpdate );
       
   185     //CMceComAvSink& update = static_cast<CMceComAvSink&>( aUpdate );
       
   186     }
       
   187     
       
   188 
       
   189 #ifdef MCE_COMMON_SERVER_SIDE
       
   190 
       
   191 // -----------------------------------------------------------------------------
       
   192 // CMceComAvSink::MccType
       
   193 // -----------------------------------------------------------------------------
       
   194 //
       
   195 const TUid CMceComAvSink::MccType()
       
   196     {
       
   197     return KUidMccVideoSink;
       
   198     }
       
   199 
       
   200 
       
   201 
       
   202 
       
   203 // -----------------------------------------------------------------------------
       
   204 // CMceComAvSink::InitParamL
       
   205 // -----------------------------------------------------------------------------
       
   206 //
       
   207 const TDesC8& CMceComAvSink::InitParamL( const CMceComCodec& aCodec )
       
   208     {
       
   209     delete iSettings;
       
   210     iSettings = NULL;
       
   211     
       
   212     CMceComDisplaySink* displaySink = NULL;
       
   213     TInt index = 0;
       
   214     while( index < iProxyClients.Count() && !displaySink )
       
   215         {
       
   216         if ( iProxyClients[ index ]->iType == KMceDisplaySink )
       
   217             {
       
   218             displaySink = static_cast<CMceComDisplaySink*>( iProxyClients[ index ] );
       
   219             }
       
   220         index++;
       
   221         }
       
   222     
       
   223     if ( displaySink )
       
   224         {
       
   225         return displaySink->DoInitParamL( aCodec );
       
   226         }
       
   227     else
       
   228         {
       
   229         iSettings = KNullDesC8().AllocL();
       
   230         }
       
   231         
       
   232     return *iSettings;
       
   233     
       
   234     }
       
   235 
       
   236 // -----------------------------------------------------------------------------
       
   237 // CMceComAvSink::PrepareL
       
   238 // -----------------------------------------------------------------------------
       
   239 //   
       
   240 void CMceComAvSink::PrepareL()
       
   241     {
       
   242     CMceComSpeakerSink* speakerSink = NULL;
       
   243     TInt index = 0;
       
   244     while( index < iProxyClients.Count() && !speakerSink )
       
   245         {
       
   246         if ( iProxyClients[ index ]->iType == KMceSpeakerSink )
       
   247             {
       
   248             speakerSink = static_cast<CMceComSpeakerSink*>( iProxyClients[ index ] );
       
   249             }
       
   250         index++;
       
   251         }
       
   252         
       
   253     if ( speakerSink )
       
   254         {
       
   255         __ASSERT_ALWAYS( speakerSink->MediaStream() && 
       
   256                          speakerSink->MediaStream()->Session(),
       
   257                          User::Leave( KErrNotFound ) );
       
   258         
       
   259         CMceMediaManager& manager = 
       
   260             speakerSink->MediaStream()->Session()->SdpSession().Manager();
       
   261                 
       
   262         if ( speakerSink->iVolume != KMceNotAssignedInt )
       
   263             {
       
   264             // Set initial volume 
       
   265             iVolume = speakerSink->iVolume;
       
   266             manager.SetVolumeL( *speakerSink, iVolume );
       
   267             }
       
   268         else
       
   269             {
       
   270             // Get initial volume
       
   271             manager.GetVolumeL( *speakerSink, iVolume );
       
   272             }
       
   273         }
       
   274     }
       
   275     
       
   276 // -----------------------------------------------------------------------------
       
   277 // CMceComAvSink::ClientEnableL
       
   278 // -----------------------------------------------------------------------------
       
   279 //
       
   280 TBool CMceComAvSink::ClientEnableL( 
       
   281     CMceComEndpoint& aClient, 
       
   282     const CMceComCodec& /*aCodec*/ )
       
   283     {
       
   284     if ( aClient.iType != KMceSpeakerSink )
       
   285         {
       
   286         return KMceSrvStreamDefaultSequence;
       
   287         }
       
   288         
       
   289     __ASSERT_ALWAYS( ServesProxyClient( aClient ), User::Leave( KErrNotFound ) );
       
   290     
       
   291     __ASSERT_ALWAYS( aClient.MediaStream() && aClient.MediaStream()->Session(),
       
   292                      User::Leave( KErrNotFound ) );
       
   293     
       
   294     CMceMediaManager& manager = 
       
   295         aClient.MediaStream()->Session()->SdpSession().Manager();
       
   296     
       
   297     // No need to route command from mediamanager back to here
       
   298     TPckgBuf<TInt> volBuf( iVolume );
       
   299     manager.SetMccParameterL( 
       
   300             static_cast<const CMceComMediaSink&>( aClient ), 
       
   301             KMccSpeakerVolume, 
       
   302             volBuf );
       
   303     
       
   304     return KMceSrvStreamAlternativeSequence;
       
   305     }
       
   306     
       
   307 // -----------------------------------------------------------------------------
       
   308 // CMceComAvSink::ClientDisableL
       
   309 // -----------------------------------------------------------------------------
       
   310 //
       
   311 TBool CMceComAvSink::ClientDisableL( CMceComEndpoint& aClient )
       
   312     {
       
   313     if ( aClient.iType != KMceSpeakerSink )
       
   314         {
       
   315         return KMceSrvStreamDefaultSequence;
       
   316         }
       
   317         
       
   318     __ASSERT_ALWAYS( ServesProxyClient( aClient ), User::Leave( KErrNotFound ) );
       
   319     
       
   320     __ASSERT_ALWAYS( aClient.MediaStream() && aClient.MediaStream()->Session(),
       
   321                      User::Leave( KErrNotFound ) );
       
   322 
       
   323     CMceMediaManager& manager = 
       
   324         aClient.MediaStream()->Session()->SdpSession().Manager();
       
   325     
       
   326     // Disable by setting volume to zero, remember the original volume
       
   327     //
       
   328     manager.GetVolumeL( static_cast<CMceComMediaSink&>( aClient ), iVolume );
       
   329     
       
   330     // No need to route command from mediamanager back to here
       
   331     TPckgBuf<TInt> volBuf( 0 );
       
   332     manager.SetMccParameterL( 
       
   333             static_cast<const CMceComMediaSink&>( aClient ), 
       
   334             KMccSpeakerVolume, 
       
   335             volBuf );
       
   336     
       
   337     return KMceSrvStreamAlternativeSequence;
       
   338     }
       
   339 
       
   340 // -----------------------------------------------------------------------------
       
   341 // CMceComAvSink::SetParameterL
       
   342 // -----------------------------------------------------------------------------
       
   343 //    
       
   344 TBool CMceComAvSink::SetParameterL( 
       
   345     const CMceComEndpoint& aClient, 
       
   346     TUint32 aParam,
       
   347     const TDesC8& aValue )
       
   348     {
       
   349     // At the moment, only supported parameter is volume for speaker
       
   350     //
       
   351     if ( aClient.iType != KMceSpeakerSink || aParam != KMccSpeakerVolume )
       
   352         {
       
   353         return KMceSrvStreamDefaultSequence;
       
   354         }
       
   355     
       
   356     __ASSERT_ALWAYS( ServesProxyClient( aClient ), User::Leave( KErrNotFound ) );
       
   357     
       
   358     __ASSERT_ALWAYS( aClient.MediaStream() && aClient.MediaStream()->Session(),
       
   359                      User::Leave( KErrNotFound ) );
       
   360    
       
   361     CMceMediaManager& manager = 
       
   362         aClient.MediaStream()->Session()->SdpSession().Manager();
       
   363     
       
   364     TPckgBuf<TInt> volBuf;
       
   365     volBuf.Copy( aValue );
       
   366     
       
   367     iVolume = volBuf();
       
   368     
       
   369     if ( aClient.IsEnabled() )
       
   370         {
       
   371         manager.SetMccParameterL( 
       
   372             static_cast<const CMceComMediaSink&>( aClient ), aParam, aValue );
       
   373         }
       
   374         
       
   375     return KMceSrvStreamAlternativeSequence;
       
   376     }
       
   377     
       
   378 #endif//MCE_COMMON_SERVER_SIDE
       
   379