mmserv/tms/tmsserver/src/tmsdtmftoneplayer.cpp
author hgs
Thu, 12 Aug 2010 20:27:32 -0500
changeset 39 1f58177f6740
parent 33 5e8b14bae8c3
child 53 eabc8c503852
permissions -rw-r--r--
201032
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33
hgs
parents:
diff changeset
     1
/*
hgs
parents:
diff changeset
     2
 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents:
diff changeset
     3
 * All rights reserved.
hgs
parents:
diff changeset
     4
 * This component and the accompanying materials are made available
hgs
parents:
diff changeset
     5
 * under the terms of "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     6
 * which accompanies this distribution, and is available
hgs
parents:
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     8
 *
hgs
parents:
diff changeset
     9
 * Initial Contributors:
hgs
parents:
diff changeset
    10
 * Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    11
 *
hgs
parents:
diff changeset
    12
 * Contributors:
hgs
parents:
diff changeset
    13
 *
hgs
parents:
diff changeset
    14
 * Description: Telephony Multimedia Service
hgs
parents:
diff changeset
    15
 *
hgs
parents:
diff changeset
    16
 */
hgs
parents:
diff changeset
    17
hgs
parents:
diff changeset
    18
// INCLUDE FILES
hgs
parents:
diff changeset
    19
#include "tmsutility.h"
hgs
parents:
diff changeset
    20
#include "tmsdtmftoneplayer.h"
hgs
parents:
diff changeset
    21
hgs
parents:
diff changeset
    22
// CONSTANTS
hgs
parents:
diff changeset
    23
const gint KDTMFMaxBufSize = 64;
hgs
parents:
diff changeset
    24
const gint KMaxVolumeLevel = 10;
hgs
parents:
diff changeset
    25
hgs
parents:
diff changeset
    26
_LIT(KPhoneTone_Asterisk, "*+w");
hgs
parents:
diff changeset
    27
hgs
parents:
diff changeset
    28
//from voip
hgs
parents:
diff changeset
    29
const guint KDTMFToneLengthOn = 250000;
hgs
parents:
diff changeset
    30
const guint KDTMFToneLengthOff = 50000;
hgs
parents:
diff changeset
    31
const guint KDTMFToneLengthPause = 2500000;
hgs
parents:
diff changeset
    32
hgs
parents:
diff changeset
    33
using namespace TMS;
hgs
parents:
diff changeset
    34
hgs
parents:
diff changeset
    35
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    36
// TMSAudioDtmfTonePlayer::NewL
hgs
parents:
diff changeset
    37
// Two-phased constructor.
hgs
parents:
diff changeset
    38
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    39
//
hgs
parents:
diff changeset
    40
TMSAudioDtmfTonePlayer* TMSAudioDtmfTonePlayer::NewL(
hgs
parents:
diff changeset
    41
        TMSDTMFTonePlayerObserver& obsrvr, guint audioPreference,
hgs
parents:
diff changeset
    42
        guint audioPriority)
hgs
parents:
diff changeset
    43
    {
hgs
parents:
diff changeset
    44
    TMSAudioDtmfTonePlayer* self = new (ELeave) TMSAudioDtmfTonePlayer(obsrvr,
hgs
parents:
diff changeset
    45
            audioPreference, audioPriority);
hgs
parents:
diff changeset
    46
hgs
parents:
diff changeset
    47
    CleanupStack::PushL(self);
hgs
parents:
diff changeset
    48
    self->ConstructL();
hgs
parents:
diff changeset
    49
    CleanupStack::Pop(self);
hgs
parents:
diff changeset
    50
    return self;
hgs
parents:
diff changeset
    51
    }
hgs
parents:
diff changeset
    52
hgs
parents:
diff changeset
    53
//Destructor
hgs
parents:
diff changeset
    54
TMSAudioDtmfTonePlayer::~TMSAudioDtmfTonePlayer()
hgs
parents:
diff changeset
    55
    {
hgs
parents:
diff changeset
    56
    TRACE_PRN_FN_ENT;
hgs
parents:
diff changeset
    57
    Cancel();
hgs
parents:
diff changeset
    58
    delete iDTMFPlayer;
hgs
parents:
diff changeset
    59
    TRACE_PRN_FN_EXT;
hgs
parents:
diff changeset
    60
    }
hgs
parents:
diff changeset
    61
hgs
parents:
diff changeset
    62
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    63
// TMSAudioDtmfTonePlayer::TMSAudioDtmfTonePlayer
hgs
parents:
diff changeset
    64
// C++ default constructor can NOT contain any code, that
hgs
parents:
diff changeset
    65
// might leave.
hgs
parents:
diff changeset
    66
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    67
//
hgs
parents:
diff changeset
    68
TMSAudioDtmfTonePlayer::TMSAudioDtmfTonePlayer(
hgs
parents:
diff changeset
    69
        TMSDTMFTonePlayerObserver& obsrvr, guint audioPreference,
hgs
parents:
diff changeset
    70
        guint audioPriority) :
hgs
parents:
diff changeset
    71
    iObserver(obsrvr),
hgs
parents:
diff changeset
    72
    iPref(audioPreference),
hgs
parents:
diff changeset
    73
    iPrior(audioPriority)
hgs
parents:
diff changeset
    74
    {
hgs
parents:
diff changeset
    75
    TRACE_PRN_FN_ENT;
hgs
parents:
diff changeset
    76
    TRACE_PRN_FN_EXT;
hgs
parents:
diff changeset
    77
    }
hgs
parents:
diff changeset
    78
hgs
parents:
diff changeset
    79
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    80
// TMSAudioDtmfTonePlayer::ConstructL
hgs
parents:
diff changeset
    81
// Symbian 2nd phase constructor can leave.
hgs
parents:
diff changeset
    82
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    83
//
hgs
parents:
diff changeset
    84
void TMSAudioDtmfTonePlayer::ConstructL()
hgs
parents:
diff changeset
    85
    {
hgs
parents:
diff changeset
    86
    TRACE_PRN_FN_ENT;
hgs
parents:
diff changeset
    87
hgs
parents:
diff changeset
    88
    TMMFPrioritySettings dtmfClickPlayerPrioritySettings;
hgs
parents:
diff changeset
    89
    iDTMFPlayer = CMMFDevSound::NewL();
hgs
parents:
diff changeset
    90
    iDTMFPlayer->InitializeL(*this, EMMFStateTonePlaying);
hgs
parents:
diff changeset
    91
hgs
parents:
diff changeset
    92
    TRACE_PRN_FN_EXT;
hgs
parents:
diff changeset
    93
    }
hgs
parents:
diff changeset
    94
hgs
parents:
diff changeset
    95
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    96
// TMSAudioDtmfTonePlayer::SetVolume
hgs
parents:
diff changeset
    97
// Sets the volume level that is used when the dtmf tone is played.
hgs
parents:
diff changeset
    98
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    99
//
hgs
parents:
diff changeset
   100
void TMSAudioDtmfTonePlayer::SetVolume(gint volume)
hgs
parents:
diff changeset
   101
    {
hgs
parents:
diff changeset
   102
    TRACE_PRN_FN_ENT;
hgs
parents:
diff changeset
   103
    gint vol = ConvertVolumeLevel(volume);
hgs
parents:
diff changeset
   104
hgs
parents:
diff changeset
   105
    if (vol != iVolume)
hgs
parents:
diff changeset
   106
        {
hgs
parents:
diff changeset
   107
        iVolume = vol;
hgs
parents:
diff changeset
   108
        iDTMFPlayer->SetVolume(iVolume);
hgs
parents:
diff changeset
   109
        }
hgs
parents:
diff changeset
   110
    TRACE_PRN_FN_EXT;
hgs
parents:
diff changeset
   111
    }
hgs
parents:
diff changeset
   112
hgs
parents:
diff changeset
   113
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   114
// TMSAudioDtmfTonePlayer::PlayDtmfTone
hgs
parents:
diff changeset
   115
// Searches the given DTMF tone from iToneArray and calls PlayCurrentTone
hgs
parents:
diff changeset
   116
// member function.
hgs
parents:
diff changeset
   117
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   118
//
hgs
parents:
diff changeset
   119
void TMSAudioDtmfTonePlayer::PlayDtmfTone(TDes& tone)
hgs
parents:
diff changeset
   120
    {
hgs
parents:
diff changeset
   121
    TRACE_PRN_FN_ENT;
hgs
parents:
diff changeset
   122
    Cancel();
hgs
parents:
diff changeset
   123
hgs
parents:
diff changeset
   124
    // DTMF signaling.
hgs
parents:
diff changeset
   125
    if (iDTMFPlayer)
hgs
parents:
diff changeset
   126
        {
hgs
parents:
diff changeset
   127
        TBuf<KDTMFMaxBufSize> key;
hgs
parents:
diff changeset
   128
        key.Append(tone);
hgs
parents:
diff changeset
   129
        TRAP_IGNORE(iDTMFPlayer->PlayDTMFStringL(tone));
hgs
parents:
diff changeset
   130
        }
hgs
parents:
diff changeset
   131
    TRACE_PRN_FN_EXT;
hgs
parents:
diff changeset
   132
    }
hgs
parents:
diff changeset
   133
hgs
parents:
diff changeset
   134
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   135
// TMSAudioDtmfTonePlayer::Cancel
hgs
parents:
diff changeset
   136
// Cancels the currently playing tone.
hgs
parents:
diff changeset
   137
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   138
//
hgs
parents:
diff changeset
   139
void TMSAudioDtmfTonePlayer::Cancel()
hgs
parents:
diff changeset
   140
    {
hgs
parents:
diff changeset
   141
    TRACE_PRN_FN_ENT;
hgs
parents:
diff changeset
   142
    iDTMFPlayer->Stop();
hgs
parents:
diff changeset
   143
    TRACE_PRN_FN_EXT;
hgs
parents:
diff changeset
   144
    }
hgs
parents:
diff changeset
   145
hgs
parents:
diff changeset
   146
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   147
// TMSAudioDtmfTonePlayer::Normalize
hgs
parents:
diff changeset
   148
// Lowers case for chars and if its '*','+', or 'w' sets it to asterisk
hgs
parents:
diff changeset
   149
// char ('*').
hgs
parents:
diff changeset
   150
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   151
//
hgs
parents:
diff changeset
   152
void TMSAudioDtmfTonePlayer::Normalize(TChar& tone)
hgs
parents:
diff changeset
   153
    {
hgs
parents:
diff changeset
   154
    TRACE_PRN_FN_ENT;
hgs
parents:
diff changeset
   155
    tone.LowerCase();
hgs
parents:
diff changeset
   156
    TPtrC ast(KPhoneTone_Asterisk);
hgs
parents:
diff changeset
   157
hgs
parents:
diff changeset
   158
    if (ast.Locate(tone) != KErrNotFound)
hgs
parents:
diff changeset
   159
        {
hgs
parents:
diff changeset
   160
        tone = ast[0];
hgs
parents:
diff changeset
   161
        }
hgs
parents:
diff changeset
   162
    TRACE_PRN_FN_EXT;
hgs
parents:
diff changeset
   163
    }
hgs
parents:
diff changeset
   164
hgs
parents:
diff changeset
   165
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   166
// TMSAudioDtmfTonePlayer::InitializeComplete
hgs
parents:
diff changeset
   167
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   168
//
hgs
parents:
diff changeset
   169
void TMSAudioDtmfTonePlayer::InitializeComplete(TInt aError)
hgs
parents:
diff changeset
   170
    {
hgs
parents:
diff changeset
   171
    TRACE_PRN_FN_ENT;
hgs
parents:
diff changeset
   172
hgs
parents:
diff changeset
   173
    if (aError == KErrNone)
hgs
parents:
diff changeset
   174
        {
hgs
parents:
diff changeset
   175
        TMMFPrioritySettings dtmfPlayerSettings;
hgs
parents:
diff changeset
   176
        dtmfPlayerSettings.iPref = iPref;
hgs
parents:
diff changeset
   177
        dtmfPlayerSettings.iPriority = iPrior;
hgs
parents:
diff changeset
   178
        dtmfPlayerSettings.iState = EMMFStateTonePlaying;
hgs
parents:
diff changeset
   179
        iDTMFPlayer->SetPrioritySettings(dtmfPlayerSettings);
hgs
parents:
diff changeset
   180
hgs
parents:
diff changeset
   181
        TTimeIntervalMicroSeconds32 length(KDTMFToneLengthOn);
hgs
parents:
diff changeset
   182
        TTimeIntervalMicroSeconds32 pause(KDTMFToneLengthOff);
hgs
parents:
diff changeset
   183
        TTimeIntervalMicroSeconds32 zero(KDTMFToneLengthPause);
hgs
parents:
diff changeset
   184
        iDTMFPlayer->SetDTMFLengths(length, pause, zero);
hgs
parents:
diff changeset
   185
        iDTMFPlayer->SetVolume(iDTMFPlayer->MaxVolume());
hgs
parents:
diff changeset
   186
        }
hgs
parents:
diff changeset
   187
hgs
parents:
diff changeset
   188
    iObserver.DTMFInitCompleted(aError);
hgs
parents:
diff changeset
   189
    TRACE_PRN_IF_ERR(aError);
hgs
parents:
diff changeset
   190
    TRACE_PRN_FN_EXT;
hgs
parents:
diff changeset
   191
    }
hgs
parents:
diff changeset
   192
hgs
parents:
diff changeset
   193
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   194
// TMSAudioDtmfTonePlayer::ToneFinished
hgs
parents:
diff changeset
   195
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   196
//
hgs
parents:
diff changeset
   197
void TMSAudioDtmfTonePlayer::ToneFinished(TInt aError)
hgs
parents:
diff changeset
   198
    {
hgs
parents:
diff changeset
   199
    TRACE_PRN_FN_ENT;
hgs
parents:
diff changeset
   200
    iObserver.DTMFToneFinished(aError);
hgs
parents:
diff changeset
   201
    TRACE_PRN_IF_ERR(aError);
hgs
parents:
diff changeset
   202
    TRACE_PRN_FN_EXT;
hgs
parents:
diff changeset
   203
    }
hgs
parents:
diff changeset
   204
hgs
parents:
diff changeset
   205
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   206
// TMSAudioDtmfTonePlayer::ConvertVolumeLevel
hgs
parents:
diff changeset
   207
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   208
//
hgs
parents:
diff changeset
   209
gint TMSAudioDtmfTonePlayer::ConvertVolumeLevel(gint volume)
hgs
parents:
diff changeset
   210
    {
hgs
parents:
diff changeset
   211
    TRACE_PRN_FN_ENT;
hgs
parents:
diff changeset
   212
    gint result = iDTMFPlayer->MaxVolume() * volume / KMaxVolumeLevel;
hgs
parents:
diff changeset
   213
    TRACE_PRN_FN_EXT;
hgs
parents:
diff changeset
   214
    return result;
hgs
parents:
diff changeset
   215
    }
hgs
parents:
diff changeset
   216