mmserv/tms/tmsserver/src/tmsaudioinbandtoneplayer.cpp
branchRCL_3
changeset 19 095bea5f582e
equal deleted inserted replaced
18:a36789189b53 19:095bea5f582e
       
     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: Telephony Multimedia Service
       
    15  *
       
    16  */
       
    17 
       
    18 //  INCLUDE FILES
       
    19 
       
    20 #include <tms.h>
       
    21 #include <AudioPreference.h>
       
    22 #include <data_caging_path_literals.hrh>
       
    23 #include <defaultbeep.rsg>
       
    24 #include "tmsutility.h"
       
    25 #include "tmsaudioinbandtoneplayer.h"
       
    26 #include "tmsaudiotoneutilityimpl.h"
       
    27 
       
    28 using namespace TMS;
       
    29 
       
    30 // CONSTANTS
       
    31 const gint KPhoneInbandVolumeMax = 10;
       
    32 const gint KPhoneInbandVolumeMin = 0;
       
    33 
       
    34 // Resourcefile destination.
       
    35 _LIT(KSystemDefaultbeepRscDrive, "Z:");
       
    36 _LIT(KSystemDefaultbeepRscFile, "DEFAULTBEEP.rSC");
       
    37 
       
    38 // -----------------------------------------------------------------------------
       
    39 // TMSAudioInbandTonePlayer::NewL
       
    40 // Two-phased constructor.
       
    41 // -----------------------------------------------------------------------------
       
    42 //
       
    43 TMSAudioInbandTonePlayer* TMSAudioInbandTonePlayer::NewL()
       
    44     {
       
    45     TMSAudioInbandTonePlayer* self = new (ELeave) TMSAudioInbandTonePlayer();
       
    46     CleanupStack::PushL(self);
       
    47     self->ConstructL();
       
    48     CleanupStack::Pop(self);
       
    49     return self;
       
    50     }
       
    51 
       
    52 //Destructor
       
    53 TMSAudioInbandTonePlayer::~TMSAudioInbandTonePlayer()
       
    54     {
       
    55     TRACE_PRN_FN_ENT;
       
    56     iResourceFile.Close();
       
    57     iFsSession.Close();
       
    58     iTones.ResetAndDestroy();
       
    59     iTones.Close();
       
    60     if (iPlayer)
       
    61         {
       
    62         iPlayer->CancelPlay();
       
    63         }
       
    64     delete iPlayer;
       
    65     TRACE_PRN_FN_EXT;
       
    66     }
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // TMSAudioInbandTonePlayer::TMSAudioInbandTonePlayer
       
    70 // C++ default constructor can NOT contain any code, that
       
    71 // might leave.
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 TMSAudioInbandTonePlayer::TMSAudioInbandTonePlayer() :
       
    75     iPlayer(NULL)
       
    76     {
       
    77     }
       
    78 
       
    79 // -----------------------------------------------------------------------------
       
    80 // TMSAudioInbandTonePlayer::ConstructL
       
    81 // Symbian 2nd phase constructor can leave.
       
    82 // -----------------------------------------------------------------------------
       
    83 //
       
    84 void TMSAudioInbandTonePlayer::ConstructL()
       
    85     {
       
    86     TRACE_PRN_FN_ENT;
       
    87     iPlayer = TMSAudioToneUtilityImpl::NewL(*this);
       
    88     iTones.Reset();
       
    89     CreateToneSequencesL();
       
    90     TRACE_PRN_FN_EXT;
       
    91     }
       
    92 
       
    93 // -----------------------------------------------------------------------------
       
    94 // TMSAudioInbandTonePlayer::CreateSequencesL
       
    95 // Create inband tone sequences from resources.
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 void TMSAudioInbandTonePlayer::CreateToneSequencesL()
       
    99     {
       
   100     TRACE_PRN_FN_ENT;
       
   101 
       
   102     iFileName = KSystemDefaultbeepRscDrive;
       
   103     iFileName.Append(KDC_RESOURCE_FILES_DIR);
       
   104     iFileName.Append(KSystemDefaultbeepRscFile);
       
   105     iFsSession.Connect();
       
   106     iResourceFile.OpenL(iFsSession, iFileName);
       
   107 
       
   108     // DO NOT change order of sequence allocation!
       
   109     AllocSeqFromResourceL(R_NET_BUSY);                 //iTones[0]
       
   110     AllocSeqFromResourceL(R_NET_RADIO_NOT_AVAILABLE);  //iTones[1]
       
   111     AllocSeqFromResourceL(R_NET_CONGESTION);           //iTones[2]
       
   112     AllocSeqFromResourceL(R_NET_SPECIAL_INFORMATION);  //iTones[3]
       
   113     AllocSeqFromResourceL(R_NET_REORDER);              //iTones[4]
       
   114     AllocSeqFromResourceL(R_NET_RING_GOING);           //iTones[5]
       
   115     AllocSeqFromResourceL(R_NET_CALL_WAITING);         //iTones[6]
       
   116     AllocSeqFromResourceL(R_DATA_CALL_TONE);           //iTones[7]
       
   117     AllocSeqFromResourceL(R_NO_SOUND_SEQUENCE);        //iTones[8]
       
   118     AllocSeqFromResourceL(R_BEEP_SEQUENCE);            //iTones[9]
       
   119 
       
   120     iResourceFile.Close();
       
   121     iFsSession.Close();
       
   122 
       
   123     TRACE_PRN_FN_EXT;
       
   124     }
       
   125 
       
   126 // -----------------------------------------------------------------------------
       
   127 // TMSAudioInbandTonePlayer::AllocSeqFromResourceL
       
   128 //
       
   129 // -----------------------------------------------------------------------------
       
   130 //
       
   131 void TMSAudioInbandTonePlayer::AllocSeqFromResourceL(const gint resource)
       
   132     {
       
   133     HBufC8* res = iResourceFile.AllocReadLC(resource);
       
   134     iReader.SetBuffer(res);
       
   135     gint length = iReader.ReadInt16();
       
   136     HBufC8* buf = HBufC8::NewL(length);
       
   137     TPtr8 ptr(buf->Des());
       
   138     for (gint i = 0; i < length; i++)
       
   139         {
       
   140         ptr.Append(iReader.ReadUint16());
       
   141         }
       
   142     User::LeaveIfError(iTones.Append(buf));
       
   143     CleanupStack::PopAndDestroy(res);
       
   144     }
       
   145 
       
   146 // -----------------------------------------------------------------------------
       
   147 // TMSAudioInbandTonePlayer::PlayInbandTone
       
   148 // Searches the given Inband tone from iToneArray and calls PlayCurrentTone.
       
   149 // -----------------------------------------------------------------------------
       
   150 //
       
   151 void TMSAudioInbandTonePlayer::PlayInbandTone(TMSInbandToneType tone)
       
   152     {
       
   153     TRACE_PRN_FN_ENT;
       
   154 
       
   155     // First stop any ongoing playback
       
   156     Cancel();
       
   157     UpdateTonePlayerVolume();
       
   158     iToneName = tone;
       
   159 
       
   160     if (iPlayer && (tone >= 0 && tone < iTones.Count()))
       
   161         {
       
   162         iPlayer->PrepareToPlayDesSequence(iTones[tone]->Des());
       
   163         }
       
   164     TRACE_PRN_FN_EXT;
       
   165     }
       
   166 
       
   167 // -----------------------------------------------------------------------------
       
   168 // TMSAudioInbandTonePlayer::Cancel
       
   169 // Cancels the currently playing tone.
       
   170 // (other items were commented in a header).
       
   171 // -----------------------------------------------------------------------------
       
   172 //
       
   173 void TMSAudioInbandTonePlayer::Cancel()
       
   174     {
       
   175     TRACE_PRN_FN_ENT;
       
   176 
       
   177     if (iPlayer)
       
   178         {
       
   179         if (iPlayer->State() == EMdaAudioToneUtilityNotReady)
       
   180             {
       
   181             // Prepare is called, but toneplayer's state is not yet prepare,
       
   182             // then cancel to prepare is needed.
       
   183             iPlayer->CancelPrepare();
       
   184             }
       
   185         else
       
   186             {
       
   187             iPlayer->CancelPlay();
       
   188             }
       
   189         }
       
   190     TRACE_PRN_FN_EXT;
       
   191     }
       
   192 
       
   193 // -----------------------------------------------------------------------------
       
   194 // TMSAudioInbandTonePlayer::PlayCurrentTone
       
   195 // Cancels the currently playing tone.
       
   196 // (other items were commented in a header).
       
   197 // -----------------------------------------------------------------------------
       
   198 //
       
   199 void TMSAudioInbandTonePlayer::PlayCurrentTone()
       
   200     {
       
   201     TRACE_PRN_FN_ENT;
       
   202     if (iPlayer)
       
   203         {
       
   204         if (iPlayer->State() == EMdaAudioToneUtilityPrepared)
       
   205             {
       
   206             UpdateTonePlayerVolume();
       
   207 
       
   208             switch (iToneName)
       
   209                 {
       
   210                 case TMS_INBAND_USER_BUSY:
       
   211                     SetToneAttributes(KAudioPrefBusy);
       
   212                     break;
       
   213                 case TMS_INBAND_RADIO_PATH_NOT_AVAIL:
       
   214                     SetToneAttributes(KAudioPrefRadioNotAvailable);
       
   215                     break;
       
   216                 case TMS_INBAND_CONGESTION:
       
   217                     SetToneAttributes(KAudioPrefCongestion);
       
   218                     break;
       
   219                 case TMS_INBAND_SPECIAL_INFO:
       
   220                     SetToneAttributes(KAudioPrefSpecialInformation);
       
   221                     break;
       
   222                 case TMS_INBAND_REORDER:
       
   223                     SetToneAttributes(KAudioPrefReorder);
       
   224                     break;
       
   225                 case TMS_INBAND_REMOTE_ALEARTING:
       
   226                     SetToneAttributes(KAudioPrefRingGoing);
       
   227                     break;
       
   228                 case TMS_INBAND_CALL_WAITING:
       
   229                     SetToneAttributes(KAudioPrefCallWaiting,
       
   230                             KAudioPriorityNetMsg, 0);
       
   231                     break;
       
   232                 case TMS_INBAND_DATA_CALL:
       
   233                     SetToneAttributes(KAudioPrefIncomingDataCall,
       
   234                             KAudioPriorityPhoneCall);
       
   235 
       
   236             //      if ( iRingingType == EProfileRingingTypeAscending )
       
   237             //           {
       
   238             //           iPlayer->SetVolumeRamp(
       
   239             //               TTimeIntervalMicroSeconds( KPERingingToneRampDuration ) );
       
   240             //           }
       
   241             //       else
       
   242             //          {
       
   243             //          EProfileRingingTypeRinging, EProfileRingingTypeRingingOnce
       
   244                     iPlayer->SetVolumeRamp(TTimeIntervalMicroSeconds(
       
   245                             KPhoneInbandToneZero));
       
   246             //           }
       
   247             //      if ( iRingingType == EProfileRingingTypeRingingOnce )
       
   248             //          {
       
   249             //        iPlayer->SetRepeats(0, TTimeIntervalMicroSeconds(
       
   250             //                KPhoneInbandToneZero));
       
   251                     //          }
       
   252                     break;
       
   253                 case TMS_INBAND_NO_SEQUENCE:
       
   254                 case TMS_INBAND_BEEP_SEQUENCE:
       
   255                     SetToneAttributes(KAudioPrefIncomingCall,
       
   256                             KAudioPriorityPhoneCall);
       
   257 
       
   258                     //iPlayer->SetRepeats(0, TTimeIntervalMicroSeconds(
       
   259                     //        KPhoneInbandToneZero));
       
   260                     iPlayer->SetVolumeRamp(TTimeIntervalMicroSeconds(
       
   261                             KPhoneInbandToneZero));
       
   262                     break;
       
   263                 default:
       
   264                     break;
       
   265                 }
       
   266 #ifndef __WINSCW__
       
   267             //Play the tone
       
   268             iPlayer->Play();
       
   269 #endif
       
   270             }
       
   271         }
       
   272     TRACE_PRN_FN_EXT;
       
   273     }
       
   274 
       
   275 // -----------------------------------------------------------------------------
       
   276 // TMSAudioInbandTonePlayer::SetToneAttributes
       
   277 //
       
   278 // -----------------------------------------------------------------------------
       
   279 //
       
   280 void TMSAudioInbandTonePlayer::SetToneAttributes(const guint pref,
       
   281         const guint priority, const gint repeatTimes, const gint trailSilence)
       
   282     {
       
   283     iPlayer->SetRepeats(repeatTimes, TTimeIntervalMicroSeconds(trailSilence));
       
   284     iPlayer->SetPriority(priority, static_cast<TMdaPriorityPreference> (pref));
       
   285     }
       
   286 
       
   287 // -----------------------------------------------------------------------------
       
   288 // TMSAudioInbandTonePlayer::SetVolume
       
   289 // -----------------------------------------------------------------------------
       
   290 //
       
   291 void TMSAudioInbandTonePlayer::SetVolume(gint volume)
       
   292     {
       
   293     TRACE_PRN_FN_ENT;
       
   294     gint safeVolume = Max(Min(volume, KPhoneInbandVolumeMax),
       
   295             KPhoneInbandVolumeMin);
       
   296 
       
   297     if (iPlayer)
       
   298         {
       
   299         gint mediaServerVolume = CalculateMediaServerVolume(safeVolume);
       
   300         if (EMdaAudioToneUtilityNotReady != iPlayer->State())
       
   301             {
       
   302             iPlayer->SetVolume(mediaServerVolume);
       
   303             }
       
   304         }
       
   305     TRACE_PRN_FN_EXT;
       
   306     }
       
   307 
       
   308 // -----------------------------------------------------------------------------
       
   309 // TMSAudioInbandTonePlayer::MatoPrepareComplete
       
   310 // Updates flag values and plays current inbandtone.
       
   311 // (other items were commented in a header).
       
   312 // -----------------------------------------------------------------------------
       
   313 //
       
   314 void TMSAudioInbandTonePlayer::MatoPrepareComplete(TInt aError)
       
   315     {
       
   316     TRACE_PRN_FN_ENT;
       
   317     if (aError == KErrNone)
       
   318         {
       
   319         PlayCurrentTone();
       
   320         }
       
   321     TRACE_PRN_IF_ERR(aError);
       
   322     TRACE_PRN_FN_EXT;
       
   323     }
       
   324 
       
   325 // -----------------------------------------------------------------------------
       
   326 // TMSAudioInbandTonePlayer::MatoPlayComplete
       
   327 // -
       
   328 // (other items were commented in a header).
       
   329 // -----------------------------------------------------------------------------
       
   330 //
       
   331 void TMSAudioInbandTonePlayer::MatoPlayComplete(
       
   332 #ifdef _DEBUG
       
   333         TInt aError)
       
   334 #else
       
   335         TInt /*aError*/)
       
   336 #endif
       
   337     {
       
   338     TRACE_PRN_FN_ENT;
       
   339     // TODO: process error?
       
   340 #ifdef _DEBUG
       
   341     TRACE_PRN_IF_ERR(aError);
       
   342 #endif
       
   343     TRACE_PRN_FN_EXT;
       
   344     }
       
   345 
       
   346 // -----------------------------------------------------------------------------
       
   347 // TMSAudioInbandTonePlayer::CalculateMediaServerVolume
       
   348 // -----------------------------------------------------------------------------
       
   349 //
       
   350 gint TMSAudioInbandTonePlayer::CalculateMediaServerVolume(gint volume) const
       
   351     {
       
   352     TRACE_PRN_FN_ENT;
       
   353     TRACE_PRN_FN_EXT;
       
   354     // Our volume level scale is 0...10, media server's can be anything.
       
   355     // This scales the volume to correct level.
       
   356     return (iPlayer->MaxVolume() * volume) /
       
   357             (KPhoneInbandVolumeMax - KPhoneInbandVolumeMin);
       
   358     }
       
   359 
       
   360 // -----------------------------------------------------------------------------
       
   361 // TMSAudioInbandTonePlayer::UpdateTonePlayerVolume
       
   362 // -----------------------------------------------------------------------------
       
   363 //
       
   364 void TMSAudioInbandTonePlayer::UpdateTonePlayerVolume()
       
   365     {
       
   366     TRACE_PRN_FN_ENT;
       
   367     gint volume( /*KPhoneInbandVolumeMin*/KPhoneInbandVolumeMax);
       
   368     SetVolume(volume);
       
   369     TRACE_PRN_FN_EXT;
       
   370     }
       
   371