phoneapp/phoneringingtoneplayer/src/cphoneringingtoneplayer.cpp
changeset 21 92ab7f8d0eab
child 22 6bb1b21d2484
equal deleted inserted replaced
4:c84cf270c54f 21:92ab7f8d0eab
       
     1 /*
       
     2 * Copyright (c) 2009 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 #include <cntdef.h>
       
    19 #include <f32file.h>
       
    20 #include <featmgr.h>
       
    21 #include <utility.h>
       
    22 #include <AudioPreference.h>
       
    23 #include <ProfileEngineDomainCRKeys.h>
       
    24 // <-- QT PHONE START -->
       
    25 //#include <musicplayerdomaincrkeys.h>
       
    26 // <-- QT PHONE END -->
       
    27 #include <DRMHelperServerInternalCRKeys.h>
       
    28 #include <DRMHelper.h>
       
    29 #include <activeidle2domainpskeys.h>
       
    30 #include <data_caging_path_literals.hrh>
       
    31 #include "cphoneringingtoneplayer.h"
       
    32 #include "cphoneaudioplayer.h"
       
    33 #include "cphoneringingtone.h"
       
    34 #include "phonelogger.h"
       
    35 #include "cphonecenrepproxy.h"
       
    36 #include "cphonepubsubproxy.h"
       
    37 #include "cphonetimer.h"
       
    38 #include "phoneconstants.h"
       
    39 #include "phoneui.pan"
       
    40 
       
    41 // CONSTANTS
       
    42 
       
    43 // <-- QT PHONE START -->
       
    44 // Minimum acceptable length of parsed DRM message.
       
    45 
       
    46 //const TInt KPhoneMinDRMTextLength = 3;
       
    47 // <-- QT PHONE END -->
       
    48 
       
    49 CPhoneRingingtonePlayer::CPhoneRingingtonePlayer():
       
    50 CActive( CActive::EPriorityStandard ), iAsyncDeletePlayers( EPlayerCount )
       
    51 {
       
    52     CActiveScheduler::Add( this );
       
    53 }
       
    54 
       
    55 CPhoneRingingtonePlayer::~CPhoneRingingtonePlayer()
       
    56     {
       
    57     iAsyncDeletePlayers.ResetAndDestroy();
       
    58     iAsyncDeletePlayers.Close();
       
    59         
       
    60     delete iTimer;
       
    61     
       
    62     CleanupPlayers();
       
    63     
       
    64     Cancel();
       
    65     }
       
    66 
       
    67 // -----------------------------------------------------------------------------
       
    68 // 
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 void CPhoneRingingtonePlayer::CleanupPlayers()
       
    72     {
       
    73     __LOGMETHODSTARTEND( EPhoneControl, "CPhoneRingingtonePlayer::CleanupPlayers()" );
       
    74     
       
    75     delete iAudioPlayer;
       
    76     iAudioPlayer = NULL;
       
    77     delete iDefaultPlayer;
       
    78     iDefaultPlayer = NULL;
       
    79     delete iBeepOncePlayer;
       
    80     iBeepOncePlayer = NULL;
       
    81     delete iSilentPlayer;
       
    82     iSilentPlayer = NULL;
       
    83     delete iBackupPlayer;
       
    84     iBackupPlayer = NULL;
       
    85     delete iMdaServer;
       
    86     iMdaServer = NULL;
       
    87     }
       
    88 // -----------------------------------------------------------------------------
       
    89 // 
       
    90 // -----------------------------------------------------------------------------
       
    91 //
       
    92 CPhoneRingingtonePlayer* CPhoneRingingtonePlayer::NewL()
       
    93     {
       
    94     CPhoneRingingtonePlayer* self = 
       
    95         new ( ELeave ) CPhoneRingingtonePlayer();
       
    96     
       
    97     CleanupStack::PushL( self );
       
    98     self->ConstructL();
       
    99     CleanupStack::Pop( self );
       
   100 
       
   101     return self;
       
   102     }
       
   103 
       
   104 // -----------------------------------------------------------------------------
       
   105 // 
       
   106 // -----------------------------------------------------------------------------
       
   107 //
       
   108 void CPhoneRingingtonePlayer::ConstructL()
       
   109     {
       
   110     
       
   111     // Construct timer.
       
   112     iTimer = CPhoneTimer::NewL();
       
   113     
       
   114     for ( TInt i = EPlayerFirst; i <= EPlayerLast; i++ )
       
   115         {
       
   116         User::LeaveIfError( 
       
   117             iAsyncDeletePlayers.Append( NULL ) );
       
   118         }
       
   119     
       
   120  
       
   121     // <-- QT PHONE START -->
       
   122        // Checks if DRM extend security is needed
       
   123     //TInt extSecNeeded = KErrNone;
       
   124 /*
       
   125     TInt err = CPhoneCenRepProxy::Instance()->GetInt(
       
   126         KCRUidMusicPlayerFeatures,
       
   127         KRequireDRMInPlayback,
       
   128         extSecNeeded );
       
   129 */
       
   130 
       
   131     //disabling the DRM for the TB10.1wk46 release. Lets see if need to put it back and how.
       
   132     //iExtSecNeeded = ( ( err == KErrNone ) && extSecNeeded ) ? ETrue : EFalse;
       
   133     iExtSecNeeded = EFalse; 
       
   134     
       
   135     
       
   136     /*CPhoneCenRepProxy::Instance()->NotifyChangeL(
       
   137         KCRUidDRMHelperServer, 
       
   138         KDRMHelperServerNotificationPassive,
       
   139         this );*/
       
   140     // <-- QT PHONE END-->        
       
   141     
       
   142     // Construct players.
       
   143     if ( !iMdaServer )
       
   144         {
       
   145         iMdaServer = CMdaServer::NewL();
       
   146         }
       
   147     
       
   148     // Backup player. 
       
   149     ConstructBackupPlayer();
       
   150     // <-- QT PHONE START-->
       
   151     ConstructDefaultPlayerL();
       
   152     // <-- QT PHONE END-->
       
   153     }
       
   154 
       
   155 // -----------------------------------------------------------------------------
       
   156 // 
       
   157 // -----------------------------------------------------------------------------
       
   158 //
       
   159 void CPhoneRingingtonePlayer::PlayProfileBasedTone( CPhoneRingingTone* aAudioVideoRingingTone )
       
   160     {
       
   161     iAudioVideoRingingTone = aAudioVideoRingingTone;
       
   162     // Construct player for line 1.
       
   163      if ( !iAudioPlayer )
       
   164          {
       
   165          iAudioPlayer = ConstructTonePlayer( 
       
   166              *iAudioVideoRingingTone, 
       
   167              EPlayerAudio );
       
   168          if ( !iTimer->IsActive() )
       
   169              {
       
   170              // Start timer, since the player is constructed.
       
   171              iTimer->After( KPhoneMaxRingingWaiting, this );
       
   172              }
       
   173          }
       
   174 
       
   175      // Start playing.
       
   176      if ( !iAudioPlayer )
       
   177          {
       
   178          iTimer->Cancel();
       
   179          PlayDefaultTone( aAudioVideoRingingTone->Volume(), 
       
   180                           aAudioVideoRingingTone->RingingType() );
       
   181          }
       
   182      else
       
   183          {
       
   184          __PHONELOG( 
       
   185              EBasic, 
       
   186              EPhoneControl, 
       
   187              "CPhoneRingingtonePlayer::PlayAudioRingTone - Start playing audio" );
       
   188          iVolume = aAudioVideoRingingTone->Volume();
       
   189          iRingingType = aAudioVideoRingingTone->RingingType();
       
   190          //AddTtsPlaybackIfNeeded( aRingingType );
       
   191          iTonePlayingStatus = EAudioTonePlaying;
       
   192          iAudioPlayer->Play( 
       
   193              ConvertRingingType( aAudioVideoRingingTone->RingingType() ),
       
   194              aAudioVideoRingingTone->Volume(),
       
   195              aAudioVideoRingingTone->TtsToneToBePlayed());
       
   196          }
       
   197     }
       
   198 // -----------------------------------------------------------------------------
       
   199 // 
       
   200 // -----------------------------------------------------------------------------
       
   201 //
       
   202 void CPhoneRingingtonePlayer::PlayBeepOnce( TInt aVolume )
       
   203     {
       
   204     __LOGMETHODSTARTEND( EPhoneControl, "CPhoneRingingtonePlayer::BeepOnce()" );
       
   205     __PHONELOG1( EBasic, EPhoneControl, "CPhoneRingingtonePlayer::BeepOnce - aVolume(%d)",
       
   206         aVolume );
       
   207 
       
   208     if ( !iBeepOncePlayer )
       
   209         {
       
   210         ConstructSequencePlayer( EPlayerBeepOnce );
       
   211         }
       
   212 
       
   213     if ( iBeepOncePlayer )
       
   214         {
       
   215         __PHONELOG( 
       
   216             EBasic, 
       
   217             EPhoneControl, 
       
   218             "CPhoneRingingtonePlayer::BeepOnce - Play" );
       
   219         iTonePlayingStatus = EBeepOnce;
       
   220         iBeepOncePlayer->Play( CPhoneAudioPlayer::ETypeRingingOnce, 
       
   221             aVolume, EFalse );        
       
   222         }
       
   223     }
       
   224 
       
   225 // -----------------------------------------------------------------------------
       
   226 //
       
   227 // -----------------------------------------------------------------------------
       
   228 //
       
   229 void CPhoneRingingtonePlayer::PlaySilentTone()
       
   230     {
       
   231     __LOGMETHODSTARTEND( EPhoneControl, "CPhoneRingingtonePlayer::PlaySilentTone()" );
       
   232 
       
   233     if ( !iSilentPlayer )
       
   234         {
       
   235         ConstructSequencePlayer( EPlayerSilent );
       
   236         }
       
   237 
       
   238     if ( iSilentPlayer )
       
   239         {
       
   240         __PHONELOG( 
       
   241             EBasic, 
       
   242             EPhoneControl, 
       
   243             "CPhoneRingingtonePlayer::PlaySilentTone - play" );
       
   244         iTonePlayingStatus = ESilentTonePlaying;
       
   245         iSilentPlayer->Play( CPhoneAudioPlayer::ETypeRinging, 0, EFalse );        
       
   246         }
       
   247     }
       
   248 
       
   249 // -----------------------------------------------------------------------------
       
   250 // 
       
   251 // -----------------------------------------------------------------------------
       
   252 //
       
   253 void CPhoneRingingtonePlayer::PlayDefaultTone( 
       
   254     TInt aVolume, 
       
   255     TProfileRingingType aRingingType )
       
   256     {
       
   257     __LOGMETHODSTARTEND( EPhoneControl, "CPhoneRingingtonePlayer::PlayDefaultTone()" );
       
   258 
       
   259     if( aRingingType == EProfileRingingTypeSilent ||
       
   260         aRingingType == EProfileRingingTypeBeepOnce )
       
   261         {
       
   262         return;
       
   263         }
       
   264         
       
   265     if ( !iDefaultRingingTone )
       
   266         {
       
   267         __PHONELOG( EBasic, EPhoneControl, "CPhoneRingingtonePlayer::PlayDefaultTone - default tone does not exist, play backup..." );
       
   268         PlayBackupTone( aVolume, aRingingType );
       
   269         return;    
       
   270         }
       
   271 
       
   272     // Construct player.
       
   273     if ( !iDefaultPlayer )
       
   274         {
       
   275         iDefaultPlayer = ConstructTonePlayer( 
       
   276             *iDefaultRingingTone, 
       
   277             EPlayerDefault );
       
   278         if ( !iTimer->IsActive() )
       
   279             {
       
   280             iTimer->After( KPhoneMaxRingingWaiting, this );
       
   281             }
       
   282         }
       
   283 
       
   284     // Start playing backup.
       
   285     if ( !iDefaultPlayer )
       
   286         {
       
   287         __PHONELOG( EBasic, EPhoneControl, "CPhoneRingingtonePlayer::PlayDefaultTone - player not constructed, play backup..." );
       
   288         iTimer->Cancel();
       
   289         PlayBackupTone( aVolume, aRingingType );
       
   290         }
       
   291     else
       
   292         {
       
   293         __PHONELOG( EBasic, EPhoneControl, "CPhoneRingingtonePlayer::PlayDefaultTone - play" );
       
   294         iVolume = aVolume;
       
   295         iRingingType = aRingingType;
       
   296         iTonePlayingStatus = EDefaultTonePlaying;
       
   297         iDefaultPlayer->Play( 
       
   298             ConvertRingingType( aRingingType ), aVolume,
       
   299             iAudioVideoRingingTone->TtsToneToBePlayed());
       
   300         }
       
   301 
       
   302     }
       
   303 
       
   304 // -----------------------------------------------------------------------------
       
   305 // CPhoneRingingtonePlayer::PlayBackupTone
       
   306 // -----------------------------------------------------------------------------
       
   307 //
       
   308 void CPhoneRingingtonePlayer::PlayBackupTone( 
       
   309     TInt aVolume, 
       
   310     TProfileRingingType aRingingType )
       
   311     {
       
   312     __LOGMETHODSTARTEND( EPhoneControl, "CPhoneRingingtonePlayer::PlayBackupTone()" );
       
   313     __ASSERT_DEBUG( iBackupPlayer, Panic( EPhoneViewGeneralError ) );
       
   314 
       
   315     if ( !iBackupPlayer )
       
   316         {
       
   317         ConstructBackupPlayer();
       
   318         }
       
   319 
       
   320     if ( iBackupPlayer )
       
   321         {
       
   322         __PHONELOG( EBasic, EPhoneControl, "CPhoneRingingtonePlayer::PlayBackupTone - play" );
       
   323         iTonePlayingStatus = EBackupTonePlaying;
       
   324 /*
       
   325         // playing text-to-speech, if necessary
       
   326         iTtsToneToBePlayed = EFalse;
       
   327         iTTsTimeOutCounter = 0;
       
   328         iTtsDelayTimer->Cancel();
       
   329         if ( iTtsPlayer )
       
   330             {
       
   331             iTtsPlayer->StopPlaying();
       
   332             delete iTtsPlayer;
       
   333             iTtsPlayer = NULL;
       
   334             }*/
       
   335 
       
   336         iBackupPlayer->Play( 
       
   337             ConvertRingingType( aRingingType ), aVolume, EFalse );        
       
   338         }
       
   339     }
       
   340 
       
   341 
       
   342 // -----------------------------------------------------------------------------
       
   343 // 
       
   344 // -----------------------------------------------------------------------------
       
   345 //
       
   346 void CPhoneRingingtonePlayer::StopPlaying()
       
   347     {
       
   348     __LOGMETHODSTARTEND( EPhoneControl, "CPhoneRingingtonePlayer::StopPlaying()" );
       
   349 
       
   350     iTimer->Cancel();
       
   351 
       
   352     switch( iTonePlayingStatus )
       
   353         {
       
   354         case EAudioTonePlaying:
       
   355             if( iAudioPlayer )
       
   356                 {
       
   357                 iAudioPlayer->StopPlaying();
       
   358                 delete iAudioPlayer;
       
   359                 iAudioPlayer = NULL;
       
   360                 }
       
   361             break;
       
   362         case EDefaultTonePlaying:
       
   363             if ( iDefaultPlayer )
       
   364                 {
       
   365                 iDefaultPlayer->StopPlaying();
       
   366                 delete iDefaultPlayer;
       
   367                 iDefaultPlayer = NULL;
       
   368                 }
       
   369             break;
       
   370         case EBeepOnce:
       
   371             if( iBeepOncePlayer )
       
   372                 {
       
   373                 iBeepOncePlayer->StopPlaying();
       
   374                 delete iBeepOncePlayer;
       
   375                 iBeepOncePlayer = NULL;
       
   376                 }
       
   377             break;
       
   378         case EBackupTonePlaying:
       
   379             if( iBackupPlayer )
       
   380                 {
       
   381                 iBackupPlayer->StopPlaying();
       
   382                 }
       
   383             break;
       
   384         case ESilentTonePlaying:
       
   385             if( iSilentPlayer )
       
   386                 {
       
   387                 iSilentPlayer->StopPlaying();
       
   388                 delete iSilentPlayer;
       
   389                 iSilentPlayer = NULL;
       
   390                 }
       
   391             break;
       
   392         case EVideoTonePlaying: // video ringing tone
       
   393         case EPersonalVideoTonePlaying:
       
   394         case ESilentVideoTonePlaying:
       
   395             if ( iBeepOncePlayer )
       
   396                 {
       
   397                 iBeepOncePlayer->StopPlaying();
       
   398                 delete iBeepOncePlayer;
       
   399                 iBeepOncePlayer = NULL;                    
       
   400                 }
       
   401                 
       
   402             if ( iSilentPlayer )
       
   403                 {
       
   404                 iSilentPlayer->StopPlaying();
       
   405                 delete iSilentPlayer;
       
   406                 iSilentPlayer = NULL;                    
       
   407                 }    
       
   408             /*if ( iVideoPlayer )
       
   409                 {
       
   410                 iVideoPlayer->StopVideoRingTone();
       
   411                 }*/
       
   412             if ( iAudioVideoRingingTone )
       
   413                 {
       
   414                 delete iAudioVideoRingingTone;
       
   415                 iAudioVideoRingingTone = NULL;    
       
   416                 }
       
   417             break;
       
   418         case EIdle:
       
   419             // Do nothing here.
       
   420             return;
       
   421         default:
       
   422             Panic( EPhoneViewCaseNotHandled );
       
   423             break;
       
   424         }
       
   425 
       
   426     iTonePlayingStatus = EIdle;
       
   427     }
       
   428 // -----------------------------------------------------------------------------
       
   429 // 
       
   430 // -----------------------------------------------------------------------------
       
   431 //
       
   432 CPhoneAudioPlayer* CPhoneRingingtonePlayer::ConstructTonePlayer( 
       
   433     const CPhoneRingingTone& aRingingTone,
       
   434     TInt aId )
       
   435     {
       
   436     __LOGMETHODSTARTEND( EPhoneControl, "CPhoneRingingtonePlayer::ConstructTonePlayer()" );
       
   437     return CPhoneAudioPlayer::New(
       
   438         aRingingTone, 
       
   439         KAudioPriorityPhoneCall, 
       
   440         KAudioPrefIncomingCall,
       
   441         *this, 
       
   442         aId,
       
   443         iMdaServer,
       
   444         aId == EPlayerDefault ? EFalse : iExtSecNeeded );
       
   445     }
       
   446 
       
   447 // -----------------------------------------------------------------------------
       
   448 // 
       
   449 // -----------------------------------------------------------------------------
       
   450 //
       
   451 TInt CPhoneRingingtonePlayer::ConstructBackupPlayer()
       
   452     {
       
   453     __LOGMETHODSTARTEND( EPhoneControl, "CPhoneRingingtonePlayer::ConstructBackupPlayer()" );
       
   454     TRAPD( err, ConstructBackupPlayerL() );
       
   455     return err;
       
   456     }
       
   457 // -----------------------------------------------------------------------------
       
   458 //
       
   459 // -----------------------------------------------------------------------------
       
   460 //
       
   461 void CPhoneRingingtonePlayer::ConstructBackupPlayerL()
       
   462     {
       
   463     __LOGMETHODSTARTEND( EPhoneControl, "CPhoneRingingtonePlayer::ConstructBackupPlayerL()" );
       
   464 
       
   465     // Construct Backup player.
       
   466     if ( !iBackupPlayer )
       
   467         {
       
   468         TFileName defaultSoundFile( KDriveZ );
       
   469         defaultSoundFile.Append( KPhoneDefaultSoundFile );
       
   470         iBackupPlayer = CPhoneAudioPlayer::NewL( 
       
   471             defaultSoundFile,
       
   472             KAudioPriorityPhoneCall,
       
   473             KAudioPrefIncomingCall,
       
   474             *this,
       
   475             EPlayerBackup,
       
   476             iMdaServer 
       
   477             );
       
   478         }
       
   479     }
       
   480 
       
   481 // -----------------------------------------------------------------------------
       
   482 // 
       
   483 // -----------------------------------------------------------------------------
       
   484 //
       
   485 void CPhoneRingingtonePlayer::ConstructDefaultPlayerL()
       
   486     {
       
   487     // Construct the default ringing tone
       
   488     TBuf<KMaxFileName> defaultTone;
       
   489 // <-- QT PHONE START-->
       
   490     /*TInt err = CPhoneCenRepProxy::Instance()->GetString(            
       
   491         KCRUidProfileEngine,
       
   492         KProEngDefaultRingingTone,
       
   493         defaultTone );*/
       
   494     defaultTone = _L("z:\\data\\sounds\\digital\\Nokia tune.aac");        
       
   495     TInt err(KErrNone);
       
   496 // <-- QT PHONE END-->    
       
   497     
       
   498     if ( err == KErrNone )
       
   499         {
       
   500         iDefaultRingingTone = CPhoneRingingTone::NewL( defaultTone );
       
   501         }
       
   502     }
       
   503 // -----------------------------------------------------------------------------
       
   504 // 
       
   505 // -----------------------------------------------------------------------------
       
   506 //
       
   507 void CPhoneRingingtonePlayer::ConstructSequencePlayer( TPlayerId aId )
       
   508     {
       
   509     __LOGMETHODSTARTEND( EPhoneControl, "CPhoneRingingtonePlayer::ConstructSequencePlayer()" );
       
   510 
       
   511     // Construct players.
       
   512     TRAPD( err, ConstructSequencePlayerL( aId ) );
       
   513     if ( err )
       
   514         {
       
   515         __PHONELOG1( EBasic, EPhoneControl, 
       
   516         "CPhoneRingingtonePlayer::ConstructSequencePlayer - err(%d)", err );    
       
   517         }
       
   518     }
       
   519 // -----------------------------------------------------------------------------
       
   520 //
       
   521 // -----------------------------------------------------------------------------
       
   522 //
       
   523 void CPhoneRingingtonePlayer::ConstructSequencePlayerL( TPlayerId aId )
       
   524     {
       
   525     __LOGMETHODSTARTEND( EPhoneControl, "CPhoneRingingtonePlayer::ConstructSequencePlayerL()" );
       
   526     // Construct beep once player
       
   527     if ( aId == EPlayerBeepOnce )
       
   528         {
       
   529 #ifdef __WINS__    
       
   530         TParse* fp = new (ELeave) TParse();
       
   531         fp->Set( KPhoneBeepOnceSoundFile, &KDC_RESOURCE_FILES_DIR, NULL ); 
       
   532         TFileName fileName( fp->FullName() );
       
   533         delete fp;
       
   534 
       
   535         iBeepOncePlayer = CPhoneAudioPlayer::NewL(
       
   536             fileName, 
       
   537             KAudioPriorityPhoneCall,
       
   538             KAudioPrefIncomingCall,
       
   539             *this, 
       
   540             EPlayerBeepOnce );
       
   541 #else
       
   542         iBeepOncePlayer = CPhoneAudioPlayer::NewSeqL(
       
   543             KPhoneBeepSequence(),
       
   544             KAudioPriorityPhoneCall,
       
   545             KAudioPrefIncomingCall,
       
   546             *this, 
       
   547             EPlayerBeepOnce );
       
   548 #endif // __WINS__
       
   549         }
       
   550 
       
   551     // Construct Silent Player.
       
   552     else if ( aId == EPlayerSilent )
       
   553         {
       
   554 #ifdef __WINS__
       
   555         TParse* fp = new (ELeave) TParse();
       
   556         fp->Set( KPhoneSilentSoundFile, &KDC_RESOURCE_FILES_DIR, NULL ); 
       
   557         TFileName fileName( fp->FullName() );
       
   558         delete fp;
       
   559 
       
   560         iSilentPlayer = CPhoneAudioPlayer::NewL( 
       
   561             fileName, 
       
   562             KAudioPriorityPhoneCall,
       
   563             KAudioPrefIncomingCall,
       
   564             *this, 
       
   565             EPlayerSilent );
       
   566 #else
       
   567         iSilentPlayer = CPhoneAudioPlayer::NewSeqL(
       
   568             KPhoneNoSoundSequence(),
       
   569             KAudioPriorityPhoneCall,
       
   570             KAudioPrefIncomingCall,
       
   571             *this,
       
   572             EPlayerSilent );
       
   573 #endif // __WINS__
       
   574         }        
       
   575     }
       
   576 
       
   577 // -----------------------------------------------------------------------------
       
   578 // 
       
   579 // -----------------------------------------------------------------------------
       
   580 //
       
   581 void CPhoneRingingtonePlayer::HandleAudioPlayerError( 
       
   582     TPhoneAudioPlayerErrorEvent /*aEvent*/, 
       
   583     TInt aError, 
       
   584     TInt /*aId*/ )
       
   585     {
       
   586     __LOGMETHODSTARTEND( EPhoneControl, "CPhoneRingingtonePlayer::HandleAudioPlayerError()" );
       
   587     // This is called from CPhoneAudioPlayer - we do not 
       
   588     // want to delete instances from which this method
       
   589     // is called.
       
   590     
       
   591      __PHONELOG1( EBasic, 
       
   592                  EPhoneControl, 
       
   593                  "CPhoneRingingtonePlayer::HandleAudioPlayerError - error (%d)",
       
   594                  aError ); 
       
   595 
       
   596     const TBool deleteAll = ( aError == KErrServerTerminated );
       
   597 
       
   598     if ( deleteAll )
       
   599         {
       
   600         // KErrServerTerminated is considered as fatal error. So we
       
   601         // need to delete everything.
       
   602 
       
   603         for ( TInt i = EPlayerFirst; i <= EPlayerLast; i++ )
       
   604             {
       
   605             DeletePlayerAsync( static_cast< TPlayerId >( i ) );
       
   606             }
       
   607 
       
   608         // Now all member audio players point to NULL, except
       
   609         // those players in iAsyncDeletePlayers. Recreate 
       
   610         // players.
       
   611 
       
   612         ConstructBackupPlayer(); // Ignore error code.
       
   613         }
       
   614 
       
   615     iTimer->Cancel();
       
   616     DoHandlePlayerError( !deleteAll, EFalse );
       
   617     }
       
   618 
       
   619 // -----------------------------------------------------------------------------
       
   620 // 
       
   621 // -----------------------------------------------------------------------------
       
   622 //
       
   623 void CPhoneRingingtonePlayer::HandleAudioPlayerInitComplete( TInt aId )
       
   624     {
       
   625     __LOGMETHODSTARTEND( EPhoneControl, "CPhoneRingingtonePlayer::HandleAudioPlayerInitComplete()" );
       
   626     // This is called from CPhoneAudioPlayer - we do not 
       
   627     // want to delete instances from which this method
       
   628     // is called. 
       
   629 
       
   630     if ( iTonePlayingStatus == EAudioTonePlaying && aId == EPlayerAudio ||
       
   631         iTonePlayingStatus == EDefaultTonePlaying && aId == EPlayerDefault )
       
   632         {
       
   633         iTimer->Cancel();
       
   634         }
       
   635     }
       
   636 
       
   637 // -----------------------------------------------------------------------------
       
   638 // CPhoneRingingtonePlayer::HandlePlayingComplete
       
   639 // -----------------------------------------------------------------------------
       
   640 //
       
   641 void CPhoneRingingtonePlayer::HandlePlayingComplete( TInt /*aId*/ )
       
   642     {
       
   643     __LOGMETHODSTARTEND( EPhoneControl, "CPhoneRingingtonePlayer::HandlePlayingComplete()" );
       
   644     // This is called from CPhoneAudioPlayer - we do not 
       
   645     // want to delete instances from which this method
       
   646     // is called. 
       
   647 
       
   648 
       
   649     __PHONELOG1( EBasic, EPhoneControl, "CPhoneRingingtonePlayer::HandlePlayingComplete - delete player - iTonePlayingStatus(%d)",
       
   650         iTonePlayingStatus ); 
       
   651 /*    if (iAudioVideoRingingTone->TtsToneToBePlayed() &&
       
   652         iAudioVideoRingingTone->RingingType() == EProfileRingingTypeRinging )
       
   653         {
       
   654         __PHONELOG( EBasic, EPhoneControl, "CPhoneRingingtonePlayer::HandlePlayingComplete - return" ); 
       
   655         return;
       
   656         }*/
       
   657     
       
   658     switch( iTonePlayingStatus )
       
   659         {
       
   660         case EAudioTonePlaying:
       
   661             DeletePlayerAsync( EPlayerAudio );
       
   662             iAudioPlayer = NULL;
       
   663             break;
       
   664             
       
   665         case EDefaultTonePlaying:
       
   666             DeletePlayerAsync( EPlayerDefault );
       
   667             iDefaultPlayer = NULL;
       
   668             break;
       
   669             
       
   670         case ESilentTonePlaying:
       
   671             DeletePlayerAsync( EPlayerSilent );
       
   672             iSilentPlayer = NULL;
       
   673             break;
       
   674             
       
   675         case EBeepOnce:
       
   676             DeletePlayerAsync( EPlayerBeepOnce );
       
   677             iBeepOncePlayer = NULL;
       
   678             break;
       
   679             
       
   680         case EVideoTonePlaying:
       
   681         case EPersonalVideoTonePlaying:
       
   682             DeletePlayerAsync( EPlayerBeepOnce );
       
   683             iBeepOncePlayer = NULL;
       
   684             return; // beep once + video
       
   685             
       
   686         case EBackupTonePlaying:
       
   687             break;
       
   688             
       
   689         default:
       
   690             Panic( EPhoneViewCaseNotHandled );
       
   691             break;
       
   692         }
       
   693 
       
   694     iTonePlayingStatus = EIdle;
       
   695     }
       
   696 
       
   697 // -----------------------------------------------------------------------------
       
   698 // 
       
   699 // -----------------------------------------------------------------------------
       
   700 //
       
   701 void CPhoneRingingtonePlayer::DeletePlayerAsync( TPlayerId aPlayer )
       
   702     {
       
   703     __LOGMETHODSTARTEND( EPhoneControl, "CPhoneRingingtonePlayer::DeletePlayerAsync()" );
       
   704     __ASSERT_DEBUG( aPlayer >= EPlayerFirst && aPlayer < iAsyncDeletePlayers.Count(),
       
   705         Panic( EPhoneViewInvariant ) );
       
   706         
       
   707     // Player is not deleted here, but in RunL.
       
   708     Cancel();
       
   709 
       
   710     if ( iAsyncDeletePlayers[ aPlayer ] ) 
       
   711         {
       
   712         delete iAsyncDeletePlayers[ aPlayer ];
       
   713         iAsyncDeletePlayers[ aPlayer ] = NULL;
       
   714         }
       
   715 
       
   716     CPhoneAudioPlayer** players[] =
       
   717         {
       
   718         &iAudioPlayer,
       
   719         &iBeepOncePlayer,
       
   720         &iSilentPlayer,
       
   721         &iDefaultPlayer,
       
   722         &iBackupPlayer,
       
   723         &iTtsPlayer
       
   724         };
       
   725 
       
   726     __ASSERT_DEBUG( iAsyncDeletePlayers.Count() > aPlayer, Panic( EPhoneUtilsIndexOutOfBounds ) );
       
   727     iAsyncDeletePlayers[ aPlayer ] = 
       
   728         *(players[ aPlayer ]);
       
   729     *(players[ aPlayer ]) = NULL;
       
   730 
       
   731     iState = EDeletingAudioPlayer;
       
   732 
       
   733     TRequestStatus* status = &iStatus;
       
   734     User::RequestComplete( status, KErrNone );
       
   735     SetActive();
       
   736     }
       
   737 
       
   738 // -----------------------------------------------------------------------------
       
   739 //
       
   740 // -----------------------------------------------------------------------------
       
   741 //
       
   742 void CPhoneRingingtonePlayer::RunL()
       
   743     {
       
   744     __LOGMETHODSTARTEND( EPhoneControl, "CPhoneRingingtonePlayer::RunL()" );
       
   745 
       
   746     switch ( iState )
       
   747         {
       
   748         case EDeletingAudioPlayer:
       
   749             {
       
   750             for ( TInt i = EPlayerFirst; i <= EPlayerLast; i++ )
       
   751                 {
       
   752                 delete iAsyncDeletePlayers[ i ];
       
   753                 iAsyncDeletePlayers[ i ] = NULL;
       
   754                 }
       
   755             }
       
   756             break;
       
   757 
       
   758       case EPlayingDefaultVideo:
       
   759             {
       
   760             //PlayAudioRingTone( iVolume, iRingingType );
       
   761             }
       
   762             break;
       
   763 
       
   764         case EIdleState:  
       
   765         default:
       
   766             break;
       
   767         } // switch iState
       
   768     
       
   769     iState = EIdleState;
       
   770     }
       
   771 // -----------------------------------------------------------------------------
       
   772 // 
       
   773 // -----------------------------------------------------------------------------
       
   774 //
       
   775 void CPhoneRingingtonePlayer::DoCancel()
       
   776     {
       
   777     __LOGMETHODSTARTEND( EPhoneControl, "CPhoneRingingtonePlayer::DoCancel()" );
       
   778     // Request is completed immediately before SetActive.
       
   779     }
       
   780 
       
   781 
       
   782 // -----------------------------------------------------------
       
   783 // CPhoneRingingtonePlayer::HandleCenRepChangeL
       
   784 // -----------------------------------------------------------
       
   785 //
       
   786 void CPhoneRingingtonePlayer::HandleCenRepChangeL( 
       
   787     const TUid& aUid,
       
   788     const TUint /*aId*/ )
       
   789     {
       
   790     __LOGMETHODSTARTEND( EPhoneControl, "CPhoneRingingtonePlayer::HandleCenRepChangeL()");
       
   791     
       
   792     if ( aUid == KCRUidDRMHelperServer )
       
   793         {
       
   794 // <-- QT PHONE START --> 
       
   795         /*
       
   796         TBuf<256> tempBuf16( KNullDesC );
       
   797         
       
   798         User::LeaveIfError( CPhoneCenRepProxy::Instance()->GetString(
       
   799             KCRUidDRMHelperServer,
       
   800             KDRMHelperServerNotificationPassive,
       
   801             tempBuf16 ) );         
       
   802        
       
   803         const TBool idleIsTopApp = CPhonePubSubProxy::Instance()->Value(
       
   804             KPSUidAiInformation, KActiveIdleState ) == EPSAiForeground;
       
   805        
       
   806         // Quick validity check and    
       
   807         // The first Tuint8 is the times the content has been informed.
       
   808         // Note should not shown until Idle.
       
   809         if ( idleIsTopApp && tempBuf16.Length() >= KPhoneMinDRMTextLength )
       
   810             { 
       
   811             TBuf8<256> tempBuf8;
       
   812             TPtrC8 ptr((TUint8*)tempBuf16.Ptr(), tempBuf16.Size());
       
   813             HBufC8* buf8 = HBufC8::NewLC( 256 );
       
   814             buf8->Des().Copy(ptr);  
       
   815             // Extract URI etc. 
       
   816             // buf8 format:
       
   817             //<TUint8 aTimes><TUint8 aExpirationMark>
       
   818             //<TUint8 aPermissionType>
       
   819             //<TUint8 aAutomatedContentType><TDesC8 aContentID>
       
   820             TInt8 count = (TInt8)(*(buf8->Ptr())); 
       
   821             TChar mark = (TChar)(*(buf8->Ptr()+1));
       
   822             TInt8 permtype = (TChar)(*(buf8->Ptr()+2));
       
   823             TInt8 automcontenttype = (TChar)(*(buf8->Ptr()+3)); 
       
   824             TBuf8<256> curi = buf8->Right( buf8->Length()-4);
       
   825             
       
   826             if (curi.Ptr()[curi.Size()-1] == 0)
       
   827                 {
       
   828                 // The last character in the descriptor is 0, which means
       
   829                 // that the original 16-bit desc was padded so
       
   830                 // remove the last char...
       
   831                 curi.SetLength(curi.Size()-1);
       
   832                 }
       
   833                     
       
   834             // Create DRM helper.     
       
   835             CDRMHelper* drmHelper = CDRMHelper::NewLC();            
       
   836             // Show notification.
       
   837             drmHelper->SetAutomatedType( (CDRMHelper::TDRMHelperAutomatedType)automcontenttype );
       
   838             TInt error = drmHelper->CheckRightsAmountL( curi );
       
   839 
       
   840             __PHONELOG1( EBasic, EPhoneControl, 
       
   841                 "CPhoneRingingtonePlayer::HandleCenRepChangeL > CheckRightsAmountL, error: %d"
       
   842                 , error );
       
   843                            
       
   844             CleanupStack::PopAndDestroy( drmHelper ); 
       
   845             CleanupStack::PopAndDestroy( buf8 ); 
       
   846             } */
       
   847 // <-- QT PHONE END --> 
       
   848         }
       
   849     }
       
   850 
       
   851 // -----------------------------------------------------------------------------
       
   852 // 
       
   853 // -----------------------------------------------------------------------------
       
   854 //
       
   855 void CPhoneRingingtonePlayer::HandleTimeOutL()
       
   856     {
       
   857     __LOGMETHODSTARTEND( EPhoneControl, "CPhoneRingingtonePlayer::HandleTimeOutL()" );
       
   858    /* if( iActiveCoverUICommand )
       
   859         {
       
   860         iMediatorSender->CancelCommand( 
       
   861             EPhoneCmdCoverUiShowMultimediaRingingTone );
       
   862         PlayDefaultTone( iVolume, iRingingType );
       
   863         iActiveCoverUICommand = EFalse;
       
   864         }*/
       
   865 
       
   866     // Guarding timer for startup has expired
       
   867     if ( iTonePlayingStatus == EVideoTonePlaying ||
       
   868          iTonePlayingStatus == ESilentVideoTonePlaying ||   
       
   869          iTonePlayingStatus == EPersonalVideoTonePlaying )
       
   870         {
       
   871         //iVideoPlayer->CancelVideoRingTone(); // close video ringtone display
       
   872         PlayDefaultTone( iVolume, iRingingType );
       
   873         }
       
   874     else
       
   875         {
       
   876         // Start new audio player synchronously.
       
   877         DoHandlePlayerError( ETrue, ETrue );
       
   878         }           
       
   879     
       
   880     }
       
   881 // -----------------------------------------------------------------------------
       
   882 // 
       
   883 // -----------------------------------------------------------------------------
       
   884 //
       
   885 void CPhoneRingingtonePlayer::DoHandlePlayerError(TBool aDelete, TBool aSync )
       
   886     {
       
   887     __LOGMETHODSTARTEND( EPhoneControl, "CPhoneRingingtonePlayer::DoHandlePlayerError()" );
       
   888     switch ( iTonePlayingStatus )
       
   889         {
       
   890         case EAudioTonePlaying:
       
   891             if ( aDelete )
       
   892                 {
       
   893                 if ( aSync )
       
   894                     {
       
   895                     delete iAudioPlayer;
       
   896                     }
       
   897                 else
       
   898                     {
       
   899                     DeletePlayerAsync( EPlayerAudio );
       
   900                     }
       
   901 
       
   902                 iAudioPlayer = NULL;
       
   903                 }
       
   904 
       
   905 #ifdef __WINS__
       
   906             //PlayAudioRingTone( iVolume, iRingingType );
       
   907             iTonePlayingStatus = EDefaultTonePlaying;
       
   908 #else
       
   909             PlayDefaultTone( iVolume, iRingingType );
       
   910 #endif
       
   911             break;
       
   912         case EDefaultTonePlaying:
       
   913             if ( aDelete )
       
   914                 {
       
   915                 if ( aSync )
       
   916                     {
       
   917                     delete iDefaultPlayer;
       
   918                     }
       
   919                 else
       
   920                     {
       
   921                     DeletePlayerAsync( EPlayerDefault );
       
   922                     }
       
   923 
       
   924                 iDefaultPlayer = NULL;
       
   925                 }
       
   926 
       
   927             PlayBackupTone( iVolume, iRingingType );
       
   928             break;
       
   929         case ESilentTonePlaying:
       
   930         case EBeepOnce:
       
   931         case EBackupTonePlaying:
       
   932             break;
       
   933         default:
       
   934             break;
       
   935         }
       
   936     }
       
   937 // -----------------------------------------------------------------------------
       
   938 // 
       
   939 // -----------------------------------------------------------------------------
       
   940 //
       
   941 CPhoneAudioPlayer::TRingingType CPhoneRingingtonePlayer::ConvertRingingType(
       
   942     TProfileRingingType aRingingType )
       
   943     {
       
   944     __LOGMETHODSTARTEND( EPhoneControl, "CPhoneRingingtonePlayer::ConvertRingingType()" );
       
   945 
       
   946     CPhoneAudioPlayer::TRingingType ringingType = 
       
   947         CPhoneAudioPlayer::ETypeRinging;
       
   948     switch ( aRingingType )
       
   949         {
       
   950         case EProfileRingingTypeRinging:
       
   951             ringingType = CPhoneAudioPlayer::ETypeRinging;
       
   952             break;
       
   953 
       
   954         case EProfileRingingTypeAscending:
       
   955             ringingType = CPhoneAudioPlayer::ETypeAscending;
       
   956             break;
       
   957 
       
   958         case EProfileRingingTypeRingingOnce:
       
   959             ringingType = CPhoneAudioPlayer::ETypeRingingOnce;
       
   960             break;
       
   961 
       
   962         default:
       
   963             break;
       
   964         }
       
   965     return ringingType;
       
   966     }
       
   967 
       
   968 // -----------------------------------------------------------------------------
       
   969 // 
       
   970 // -----------------------------------------------------------------------------
       
   971 //    
       
   972 CPhoneAudioPlayer* 
       
   973 CPhoneRingingtonePlayer::GetCurrentlyActiveAudioPlayer()
       
   974     {    
       
   975     __LOGMETHODSTARTEND( EPhoneControl, "CPhoneRingingtonePlayer::GetCurrentlyActiveAudioPlayerWithTTs()" );
       
   976 
       
   977     if( iAudioPlayer )
       
   978         {
       
   979         __PHONELOG( EBasic, EPhoneControl, "CPhoneRingingtonePlayer::GetCurrentlyActiveAudioPlayerWithTTs - audio player" ); 
       
   980         return iAudioPlayer;         
       
   981         }
       
   982     else if ( iDefaultPlayer )
       
   983         {
       
   984         __PHONELOG( EBasic, EPhoneControl, "CPhoneRingingtonePlayer::GetCurrentlyActiveAudioPlayerWithTTs - default player" ); 
       
   985         return iDefaultPlayer;     
       
   986         }
       
   987     else if( iBackupPlayer )
       
   988         {
       
   989         __PHONELOG( EBasic, EPhoneControl, "CPhoneRingingtonePlayer::GetCurrentlyActiveAudioPlayerWithTTs - backup player" ); 
       
   990         return iBackupPlayer;
       
   991         }
       
   992     else
       
   993         {
       
   994         return NULL;
       
   995         }
       
   996     }
       
   997 
       
   998 // -----------------------------------------------------------------------------
       
   999 // 
       
  1000 // -----------------------------------------------------------------------------
       
  1001 //
       
  1002 void CPhoneRingingtonePlayer::MuteActiveAudioPlayer()
       
  1003     {
       
  1004     __LOGMETHODSTARTEND( EPhoneControl, "CPhoneRingingtonePlayer::ActiveAudioPlayer()" );
       
  1005 
       
  1006     switch( iTonePlayingStatus )
       
  1007         {
       
  1008         case EAudioTonePlaying:
       
  1009             if( iAudioPlayer )
       
  1010                 {
       
  1011                 iAudioPlayer->MutePlaying();
       
  1012                 }
       
  1013             break;
       
  1014             
       
  1015         case EDefaultTonePlaying:
       
  1016             if ( iDefaultPlayer )
       
  1017                 {
       
  1018                 return iDefaultPlayer->MutePlaying();
       
  1019                 }
       
  1020             break;
       
  1021             
       
  1022         case EBeepOnce:
       
  1023             if( iBeepOncePlayer )
       
  1024                 {
       
  1025                 return iBeepOncePlayer->MutePlaying();
       
  1026                 }
       
  1027             break;
       
  1028             
       
  1029         case EBackupTonePlaying:
       
  1030             if( iBackupPlayer )
       
  1031                 {
       
  1032                 return iBackupPlayer->MutePlaying();
       
  1033                 }
       
  1034             break;
       
  1035             
       
  1036         case ESilentTonePlaying:
       
  1037             if( iSilentPlayer )
       
  1038                 {
       
  1039                 return iSilentPlayer->MutePlaying();
       
  1040                 }
       
  1041             break;
       
  1042             
       
  1043         case EVideoTonePlaying: // video ringing tone
       
  1044         case EPersonalVideoTonePlaying:
       
  1045         case ESilentVideoTonePlaying:
       
  1046             if ( iBeepOncePlayer )
       
  1047                 {
       
  1048                 return iBeepOncePlayer->MutePlaying();                    
       
  1049                 }    
       
  1050             else if ( iSilentPlayer )
       
  1051                 {
       
  1052                 return iSilentPlayer->MutePlaying();                    
       
  1053                 }    
       
  1054             break;
       
  1055             
       
  1056         default:
       
  1057             break;
       
  1058         }      
       
  1059     }