phoneapp/phoneuiview/inc/cphoneringingtoneplayerao.h
changeset 0 5f000ab63145
child 15 2a26698d78ba
equal deleted inserted replaced
-1:000000000000 0:5f000ab63145
       
     1 /*
       
     2 * Copyright (c) 2002-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:  Active object which implements ringing tone functionality
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef CPHONERINGINGTONEPLAYERAO_H
       
    20 #define CPHONERINGINGTONEPLAYERAO_H
       
    21 
       
    22 // INCLUDES
       
    23 #include <e32base.h>
       
    24 #include <Profile.hrh>
       
    25 #include "mphoneaudioplayerobserver.h"
       
    26 #include "mphonevideoplayerobserver.h"
       
    27 #include "mphonecenrepobserver.h"
       
    28 #include "cphoneaudioplayer.h"
       
    29 #include "mphonetimer.h"
       
    30 #include "mphonevideoplayer.h"
       
    31 
       
    32 // FORWARD DECLARATIONS
       
    33 //class MPhoneRingingToneObserver;
       
    34 class CPhoneAudioPlayer;
       
    35 class CPhoneTimer;
       
    36 class CMdaServer;
       
    37 class MPhoneDisplayProvider;
       
    38 class CPhoneRingingTone;
       
    39 class TPhoneCommandParam;
       
    40 
       
    41 // CLASS DECLARATION
       
    42 
       
    43 /**
       
    44 * It implements ringing tone functionality. 
       
    45 * Note that when issuing Play-command to audio side, ALWAYS set the tone type
       
    46 * before the Play() is called. This is to ensure that correct tone is tried to
       
    47 * be played. 
       
    48 *
       
    49 * @since 1.0
       
    50 */
       
    51 class CPhoneRingingTonePlayerAO :
       
    52     public CActive,
       
    53     public MPhoneCenRepObserver,
       
    54     private MPhoneAudioPlayerObserver,
       
    55     private MPhoneTimer,
       
    56     private MPhoneVideoPlayerObserver
       
    57     {
       
    58     public:
       
    59         // States for this active object
       
    60         enum TState
       
    61             {
       
    62             EIdleState,  
       
    63             EDeletingAudioPlayer,
       
    64             EDeletingVideoPlayer,
       
    65             EPlayingDefaultVideo
       
    66             };
       
    67 
       
    68     public:
       
    69         
       
    70         /**
       
    71         * Two-phased constructor.
       
    72         * @return new instance.
       
    73         */
       
    74         static CPhoneRingingTonePlayerAO* NewL();
       
    75         
       
    76         /**
       
    77         * Destructor.
       
    78         */
       
    79         ~CPhoneRingingTonePlayerAO();
       
    80 
       
    81         /**
       
    82         * Play ring tone
       
    83         * @param aCommandParam a command param
       
    84         */
       
    85         void PlayRingToneL( TPhoneCommandParam *aCommandParam );
       
    86 
       
    87         /**
       
    88         * Play audio ring tone 
       
    89         */
       
    90         void PlayAudioRingTone( 
       
    91             TInt aVolume, 
       
    92             TProfileRingingType aRingingType );
       
    93 
       
    94         /**
       
    95         * Playing the Beep once.
       
    96         * @param aVolume volume used to play the ringing tone.
       
    97         */
       
    98         void BeepOnce( TInt aVolume );
       
    99 
       
   100         /**
       
   101         * Play silent tone. No_sound.wav will be played. If vibration alert
       
   102         * is ON, it will vibrate.
       
   103         */
       
   104         void PlaySilentTone();
       
   105 
       
   106         /**
       
   107         * Play unsecure VoIP tone.
       
   108         * Play tone if secure call fails and call is changed to unsecure call
       
   109         * @since    S60 5.0
       
   110         */
       
   111         void PlayUnsecureVoIPTone();
       
   112         
       
   113         /**
       
   114         * Stops playing the ringing tone.
       
   115         * Method does not do anything if ringing tone is not playing.
       
   116         */
       
   117         void StopPlaying();
       
   118 
       
   119         /**
       
   120         * Continues video playback ( and ringing tone ) with volume 0
       
   121         * Stream not closed ( If music player was ongoing ) 
       
   122         */
       
   123         void MuteRingingToneOnAnswer();
       
   124           
       
   125         /**
       
   126         * Continues video playback with muted audio.
       
   127         * Ringing tone is stopped.
       
   128         */
       
   129         void MuteRingingTone();
       
   130           
       
   131         /**
       
   132         * Sets video player.
       
   133         * @since Series 60 v3.2
       
   134         * @param aVideoPlayer Video player reference.
       
   135         */
       
   136         void SetVideoPlayer( MPhoneVideoPlayer* aVideoPlayer );
       
   137 
       
   138 
       
   139         /**
       
   140         * Play TTS tone simultaneously with Personal or Default tones.
       
   141         * This method does not command phone to play TTS immediately. Instead 
       
   142         * it registers a request to play TTS, when Personal or default tones 
       
   143         * are played.
       
   144         *
       
   145         * @since Series 60 3.0
       
   146         * @param aTextToSay Text, that should be pronounced by the 
       
   147         * Text-To-Speech engine. This is normal descriptor, no UTF-8 
       
   148         * and no "(tts)" prefix
       
   149         * @param aVolume Volume for the TTS-tone, Does not effect the volume 
       
   150         * of the normal tone, that will be played simulteneously with the TTS
       
   151         * @param aRingingType ringing type.
       
   152         */
       
   153         void PlayTtsTone(
       
   154             const TDesC& aTextToSay,
       
   155             TInt aVolume,
       
   156             TProfileRingingType aRingingType );
       
   157 
       
   158         /**
       
   159         * Play video ring tone.
       
   160         * @since Series 60 3.1
       
   161         * @param aRingingTone Ringing tone to be played.
       
   162         * @param aVolume Volume used to play the ringing tone.
       
   163         * @param aRingingType Ringing type.
       
   164         */
       
   165         void PlayVideoRingingTone( 
       
   166             const CPhoneRingingTone& aRingingTone, 
       
   167             TInt aVolume, 
       
   168             TProfileRingingType aRingingType,
       
   169             TBool aPersonalTone = EFalse );
       
   170 
       
   171         /**
       
   172         * Checks if extended security required.
       
   173         * @since Series 60 3.1
       
   174         * @return ETrue if extended security is required.
       
   175         */
       
   176         TBool ExtendedSecurity() const;
       
   177    
       
   178         /**
       
   179         * This function is called when Mediator receives response to the sent
       
   180         * ShowMultiMediaRingingTone command.
       
   181         * @param aStatus - Standard Symbian error code indicating the
       
   182         *                  success of the command.
       
   183         */
       
   184 		    void ShowMultimediaRingingToneResponseL( TInt aStatus );
       
   185 		
       
   186     public: // From MPhoneCenRepObserver
       
   187 
       
   188         /**
       
   189         * Handle the change of the setting from Central Repository
       
   190         * @param aUid identifing the central repository UID.
       
   191         * @param aId central repository ID.
       
   192         */
       
   193         virtual void HandleCenRepChangeL( 
       
   194             const TUid& aUid,
       
   195             const TUint aId );
       
   196 
       
   197 
       
   198     private:
       
   199 
       
   200         /**
       
   201         * Handle the error of audio file player.
       
   202         */
       
   203         virtual void HandleAudioPlayerError( 
       
   204             TPhoneAudioPlayerErrorEvent aEvent, 
       
   205             TInt aError, 
       
   206             TInt aId = KPhoneAudioPlayerNotSpecified );
       
   207 
       
   208         /**
       
   209         * Handle audio player initialize complete.
       
   210         */
       
   211         virtual void HandleAudioPlayerInitComplete(
       
   212             TInt aId = KPhoneAudioPlayerNotSpecified );
       
   213 
       
   214         /**
       
   215         * Handle auido file playing complete successfully.
       
   216         */
       
   217         virtual void HandlePlayingComplete( 
       
   218             TInt aId = KPhoneAudioPlayerNotSpecified );
       
   219 
       
   220         /**
       
   221         * @see MPhoneTimer
       
   222         */
       
   223         virtual void HandleTimeOutL();
       
   224 
       
   225         /**
       
   226         * HandleVideoPlayerError
       
   227         */
       
   228         virtual void HandleVideoPlayerError( 
       
   229             TPhoneVideoPlayerErrorEvent aEvent,
       
   230             TInt aError );
       
   231 
       
   232         /**
       
   233         * HandleVideoPlayerInitComplete
       
   234         */
       
   235         virtual void HandleVideoPlayerInitComplete();
       
   236 
       
   237         /**
       
   238         * HandleVideoPlayerPlayingComplete
       
   239         */
       
   240         virtual void HandleVideoPlayerPlayingComplete();
       
   241 
       
   242         /** 
       
   243         * Enumerates identifiers for each player:
       
   244         * EPlayerAudio - audio
       
   245         * EPlayerBeepOnce - beep once
       
   246         * EPlayerSilent - silent
       
   247         * EPlayerDefault - default
       
   248         * EPlayerBackup - backup
       
   249         *
       
   250         * EPlayerFirst and EPlayerLast are alias
       
   251         * to other identifiers.
       
   252         * EPlayerFirst - first player
       
   253         * EPlayerLast - last player
       
   254         */
       
   255         enum TPlayerId
       
   256             {
       
   257             EPlayerFirst,
       
   258             EPlayerAudio = EPlayerFirst,
       
   259             EPlayerBeepOnce,
       
   260             EPlayerSilent,
       
   261             EPlayerUnsecureVoIP,
       
   262             EPlayerDefault,
       
   263             EPlayerBackup,
       
   264             EPlayerTts, 
       
   265             EPlayerLast = EPlayerTts,
       
   266             EPlayerCount
       
   267             };
       
   268             
       
   269         /**
       
   270         * Enumerates how many times TTs is played
       
   271         * ESaidOnce -once
       
   272         * ESaidTwice twice 
       
   273         */    
       
   274         enum TTtsStatus
       
   275             {
       
   276             ESaidOnce,
       
   277             ESaidTwice
       
   278             };
       
   279 
       
   280         /**
       
   281         * C++ default constructor.
       
   282         */
       
   283         CPhoneRingingTonePlayerAO();
       
   284 
       
   285         /**
       
   286         * By default Symbian OS constructor is private.
       
   287         */
       
   288         void ConstructL();
       
   289 
       
   290         /**
       
   291         * Play default tone.
       
   292         * @param aVolume volume used for the playing.
       
   293         * @param aRingingType ringing type.
       
   294         */
       
   295         void PlayDefaultTone( 
       
   296             TInt aVolume, 
       
   297             TProfileRingingType aRingingType );
       
   298 
       
   299         /**
       
   300         * Play backup tone.
       
   301         * @param aVolume volume used for the playing.
       
   302         * @param aRingingType ringing type.
       
   303         */
       
   304         void PlayBackupTone( 
       
   305             TInt aVolume, 
       
   306             TProfileRingingType aRingingType );
       
   307 
       
   308         /**
       
   309         * Do construct tone.
       
   310         * @param aRingingTone Ringing tone.
       
   311         * @return The instance of the player. NULL is returned if it's failed.
       
   312         */
       
   313         CPhoneAudioPlayer* ConstructTonePlayer( 
       
   314             const CPhoneRingingTone& aRingingTone,
       
   315             TInt aId );
       
   316 
       
   317         /**
       
   318         * Handle audio player error.
       
   319         * @param aDelete ETrue if deletion of the player allowed, 
       
   320         *                EFalse otherwise.
       
   321         * @param aSync ETrue if synchronous deletion of players is allowed,
       
   322         *              EFalse otherwise.
       
   323         */
       
   324         void DoHandlePlayerError(
       
   325             TBool aDelete,
       
   326             TBool aSync );
       
   327 
       
   328         /**
       
   329         * Convert ringing type from PhoneAppEnging to the ringing type in 
       
   330         * CPhoneAudioPlayer.
       
   331         * @param aRingingType the ringing type form PhoneAppEngine.
       
   332         * @return ringing type of CPhoneAudioPlayer.
       
   333         */
       
   334         CPhoneAudioPlayer::TRingingType ConvertRingingType(
       
   335             TProfileRingingType aRingingType );
       
   336 
       
   337         /**
       
   338         * Convert ringing type from PhoneAppEnging to the ringing type in 
       
   339         * MPhoneVideoPlayer.
       
   340         * @since Series 60 3.1
       
   341         * @param aRingingType the ringing type form PhoneAppEngine.
       
   342         * @return ringing type of MPhoneVideoPlayer.
       
   343         */
       
   344         MPhoneVideoPlayer::TPlayMode ConvertVideoRingingType(
       
   345             TProfileRingingType aRingingType );
       
   346 
       
   347         /**
       
   348         * Construct media server and backup tone player.
       
   349         */
       
   350         TInt ConstructPlayers();
       
   351 
       
   352         /**
       
   353         * Construct media server and backup tone player.
       
   354         */
       
   355         void ConstructPlayersL();
       
   356 
       
   357         /**
       
   358         * Construct sequence players.
       
   359         * @param aPlayer player to be constructed.
       
   360         */
       
   361         void ConstructSequencePlayer(
       
   362             TPlayerId aPlayer );
       
   363 
       
   364         /**
       
   365         * Construct sequence players.
       
   366         * @param aPlayer player to be constructed.
       
   367         */
       
   368         void ConstructSequencePlayerL(
       
   369             TPlayerId aPlayer );
       
   370 
       
   371         /**
       
   372         * Cleanup players.
       
   373         */
       
   374         void CleanupPlayers();
       
   375 
       
   376         /**
       
   377         * Deletes player asynchronoysly.
       
   378         * @param aPlayer player to be deleted.
       
   379         */
       
   380         void DeletePlayerAsync(
       
   381             TPlayerId aPlayer );
       
   382        /**
       
   383         * Plays default L1 or L2 video ring tone asynchronously.
       
   384         * @since Series 60 3.1
       
   385         */
       
   386         void PlayDefaultVideoAsync();
       
   387 
       
   388         /**
       
   389         * Deletes video player and plays default L1 or L2
       
   390         * tone asynchronously.
       
   391         * @since Series 60 3.1
       
   392         */
       
   393         void DeleteVideoPlayerAndPlayDefaultAsync();
       
   394 
       
   395         /**
       
   396         * @see CActive::RunL.
       
   397         */
       
   398         void RunL();
       
   399 
       
   400         /**
       
   401         * @see CActive::DoCancel.
       
   402         */
       
   403         void DoCancel();
       
   404         
       
   405         /**
       
   406         * Wrapper of DoHandleTtsDelayTimeout, that can be used as TCallback. 
       
   407         * Immediately passes control to DoHandleTtsDelayTimeout method.
       
   408         * @since Series 60 3.0
       
   409         * @param object Object to call DoHandleTtsDelayTimeout() on, . 
       
   410         *        instance of CPhoneRingingTonePlayer.
       
   411         * @return KErrNone.
       
   412         */
       
   413         static TInt HandleTtsDelayTimeout( TAny* object );
       
   414         
       
   415         /**
       
   416         * It is called after TTS delay elapsed. Starts playing TTS.
       
   417         */
       
   418         void DoHandleTtsDelayTimeout();
       
   419         
       
   420         /**
       
   421         * Checks if TTS component should be played for the current ringtone 
       
   422         * playback and initializes the TTS playback. This method is to be 
       
   423         * called from within PlayXXXXTone methods
       
   424         * @since Series 60 3.0
       
   425         * @param aRingingType ringing type
       
   426         */
       
   427         void AddTtsPlaybackIfNeeded( TProfileRingingType aRingingType );
       
   428              
       
   429         /**
       
   430         * Returns currently active player which is used wit TTS player.
       
   431         * @return pointer to CPhoneAudioPlayer.
       
   432         */
       
   433         CPhoneAudioPlayer* GetCurrentlyActiveAudioPlayerWithTTs();   
       
   434          
       
   435         /**
       
   436         * TTs cases only. Calculates new volume and ramptimes
       
   437         * for Ascending TTS ringing case and normal TTS ringing case.
       
   438         * @param aStatus -status of TTs player.
       
   439         */         
       
   440         void SolveNewVolumeAndRamptime( TTtsStatus aStatus );   
       
   441         
       
   442         /**
       
   443         * Retarts currently active ringingtone player.
       
   444         */
       
   445         void ReStartRingingTonePlayer();
       
   446         
       
   447          /**
       
   448          * Checks if ringing tone file's size is larger than the size limit.
       
   449          * If size limit is exceeded, default tone is played instead.
       
   450          * @since 3.1
       
   451          * @param aRingingTone  Tone to check.
       
   452          * @return EFalse if the limit was exceeded and thus default tone played.
       
   453          *         ETrue  if tone file's size was valid and the checked tone 
       
   454          *                can be played.
       
   455          */
       
   456         TBool CheckAndHandleToneSizeLimit( CPhoneRingingTone* aRingingTone );
       
   457 
       
   458          /**
       
   459          * Checks if ringing tone file's size is larger than the size limit.
       
   460          * @since 3.1
       
   461          * @param aFile   File to check.
       
   462          *        aSizeLimitKB  the size limit in kB is set to this variable.
       
   463          * @return KErrNone        if the file can be used as a ringing tone.
       
   464          *         KErrTooBig        if the file size limit is exceeded.
       
   465          *         Other error value if error happened during size checking.
       
   466          */
       
   467         TInt CheckToneFileSize( const TDesC& aFile, TInt aSizeLimitKB );
       
   468         
       
   469          /**
       
   470          * Reads from central repository the file size limit of following tones:
       
   471          * -contact's personal ringing tone
       
   472          * -voice call line1
       
   473          * -voice call line2
       
   474          * Value 0 means all sizes are allowed.
       
   475          * @since 3.1
       
   476          * @param aSizeLimitKB  the size limit in kB is read to this variable.
       
   477          * @return leaves on error.
       
   478          */
       
   479         void GetMaxToneFileSizeL( TInt& aSizeLimitKB ) const;
       
   480         
       
   481         /**
       
   482         * Returns currently active audio player.
       
   483         * @return Currently active audio player or NULL if none active.
       
   484         */
       
   485         CPhoneAudioPlayer* ActiveAudioPlayer();
       
   486         
       
   487         /**
       
   488         * Mutes the ringing tone.
       
   489         */
       
   490         void DoMuteRingingTone();
       
   491         
       
   492 
       
   493     private:    // Data
       
   494         
       
   495         // Audio ring tone player. Memory allocated during construction.
       
   496         // After constructed, no leave may be caused during audio playing
       
   497         CPhoneAudioPlayer* iAudioPlayer;
       
   498 
       
   499         // Audio player for beep once.
       
   500         CPhoneAudioPlayer* iBeepOncePlayer;
       
   501 
       
   502         // Audio player for silent tone.
       
   503         CPhoneAudioPlayer* iSilentPlayer;
       
   504         
       
   505         // Audio player for unsecure VoIP tone.
       
   506         CPhoneAudioPlayer* iUnsecureVoIPTonePlayer;
       
   507         
       
   508         // Default player.
       
   509         CPhoneAudioPlayer* iDefaultPlayer;
       
   510         
       
   511         // Tts player.
       
   512         CPhoneAudioPlayer* iTtsPlayer;
       
   513 
       
   514         // Backup ringing tone. Incase all default player failed.
       
   515         CPhoneAudioPlayer* iBackupPlayer;
       
   516         
       
   517 		// Default player
       
   518         CPhoneRingingTone* iDefaultRingingTone;
       
   519         
       
   520         // Media server.
       
   521         CMdaServer* iMdaServer;
       
   522 
       
   523         // Indicate which tone is playing or need to be played:
       
   524         // EIdle - idle,
       
   525         // EAudioTonePlaying - audio playing,
       
   526         // EBeepOnce - beep once playing,
       
   527         // ESilentTonePlaying - silent tone playing,
       
   528         // EUnsecureVoIPTonePlaying - unsecure tone playing (VoIP),
       
   529         // EDefaultTonePlaying - default tone playing,
       
   530         // EBackupTonePlaying - backup tone playing,
       
   531         // EVideoTonePlaying - playing video ringing tone
       
   532         // ESilentVideoTonePlaying  - silent playing video ringing tone
       
   533         // EPersonalVideoTonePlaying - personal playing video ringing tone
       
   534         enum TTonePlayingStatus
       
   535             {
       
   536             EIdle,
       
   537             EAudioTonePlaying,
       
   538             EBeepOnce,
       
   539             ESilentTonePlaying,
       
   540             EUnsecureVoIPTonePlaying,
       
   541             EDefaultTonePlaying,
       
   542             EBackupTonePlaying,
       
   543             EVideoTonePlaying,
       
   544             ESilentVideoTonePlaying,
       
   545             EPersonalVideoTonePlaying
       
   546             };
       
   547 
       
   548         // Current playing status.
       
   549         TTonePlayingStatus iTonePlayingStatus;
       
   550         
       
   551         // True if Tts is currently playing. Is different from 
       
   552         // iTonePlayingStatus, because TTS is played in
       
   553         // parallel with the other tone types
       
   554         TBool iTtsTonePlaying;
       
   555         
       
   556         // Index of the TTS delay that is "executed" currently or is to be 
       
   557         // "executed" after the current playing of the TTS tone. Is zero based
       
   558         TInt iTtsDelayIndex;
       
   559         
       
   560         // True if TTS tone should be played when the next playing of the 
       
   561         // default or personal tone is fired.
       
   562         TBool iTtsToneToBePlayed;
       
   563 
       
   564         // Audio/Video tone, not owned
       
   565         CPhoneRingingTone* iAudioVideoRingingTone;
       
   566 
       
   567         // Volume for backup tone playing.
       
   568         TInt iVolume;
       
   569         
       
   570         // Volume of the text pronounced by the TTS engine
       
   571         TInt iTtsVolume;
       
   572 
       
   573         // Ringing type for backup tone playing.
       
   574         TProfileRingingType iRingingType;
       
   575 
       
   576         // Timer.
       
   577         CPhoneTimer* iTimer;
       
   578 
       
   579         // Timer, that tracks delays before playing TTS
       
   580         CPhoneTimer* iTtsDelayTimer;
       
   581 
       
   582         // Number of times TTS tone should be played for the CURRENT ringtone
       
   583         // If ringing tone is to be played just once, iTtsDelayCount == 1,
       
   584         // otherwise iTtsDelayCount == KTtsDelayCount
       
   585         TInt iTtsDelaysCount;
       
   586 
       
   587         // Player to be deleted asynchronously.
       
   588         RPointerArray<CPhoneAudioPlayer> iAsyncDeletePlayers;
       
   589 
       
   590         // DRM extend security
       
   591         TBool iExtSecNeeded;
       
   592  
       
   593         // Video ringing tone player
       
   594         MPhoneVideoPlayer* iVideoPlayer;
       
   595     
       
   596         // State of this active object
       
   597         TState iState;
       
   598               
       
   599         // RingingType for TtsPlayer only.
       
   600         TProfileRingingType iTtsRingingType;
       
   601         
       
   602         // Counter for TTs timeouts
       
   603         TInt iTTsTimeOutCounter;
       
   604         
       
   605         // Voice call ringing tone file size max value.
       
   606         TInt iToneFileSizeLimitKB;             
       
   607 
       
   608         // Flag. Indicates video scaling capability of the device.
       
   609         TBool iArbitraryVideoScaling;
       
   610 
       
   611     };
       
   612 
       
   613 #endif      // CPHONERINGINGTONEPLAYERAO_H
       
   614             
       
   615 // End of File