37
|
1 |
/*
|
|
2 |
* Copyright (c) 2007-2010 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: Implements the class CSPAudioHandler
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include "cspaudiohandler.h"
|
|
19 |
#include "tmshandler.h"
|
65
|
20 |
#include "csptimer.h"
|
37
|
21 |
#include "csplogger.h"
|
65
|
22 |
#include "mcspaudiohandlerobserver.h"
|
37
|
23 |
|
|
24 |
// ---------------------------------------------------------------------------
|
|
25 |
// CSPAudioHandler::NewL.
|
|
26 |
// ---------------------------------------------------------------------------
|
|
27 |
//
|
|
28 |
CSPAudioHandler* CSPAudioHandler::NewL()
|
|
29 |
{
|
65
|
30 |
CSPLOGSTRING(CSPOBJECT, "CSPAudioHandler::NewL()");
|
37
|
31 |
CSPAudioHandler* self = new (ELeave) CSPAudioHandler();
|
|
32 |
CleanupStack::PushL(self);
|
|
33 |
self->ConstructL();
|
|
34 |
CleanupStack::Pop(self);
|
|
35 |
return self;
|
|
36 |
}
|
|
37 |
|
|
38 |
// ---------------------------------------------------------------------------
|
|
39 |
// Destructs the object by canceling first ongoing monitoring.
|
|
40 |
// ---------------------------------------------------------------------------
|
|
41 |
//
|
|
42 |
CSPAudioHandler::~CSPAudioHandler()
|
|
43 |
{
|
65
|
44 |
CSPLOGSTRING(CSPOBJECT, "CSPAudioHandler::~CSPAudioHandler()");
|
|
45 |
if (iTimer)
|
|
46 |
{
|
|
47 |
iTimer->CancelNotify();
|
|
48 |
delete iTimer;
|
|
49 |
}
|
37
|
50 |
delete iTmsHandler;
|
|
51 |
}
|
|
52 |
|
|
53 |
// ---------------------------------------------------------------------------
|
65
|
54 |
// CSPAudioHandler::SetObserver
|
|
55 |
// ---------------------------------------------------------------------------
|
|
56 |
//
|
|
57 |
void CSPAudioHandler::SetObserver(MCSPAudioHandlerObserver& aObserver)
|
|
58 |
{
|
|
59 |
CSPLOGSTRING(CSPOBJECT, "CSPAudioHandler::SetObserver()");
|
|
60 |
iObserver = &aObserver;
|
|
61 |
}
|
|
62 |
|
|
63 |
// ---------------------------------------------------------------------------
|
37
|
64 |
// CSPAudioHandler::Start
|
65
|
65 |
// Note: Client must pass the observer through SetObserver() prior to calling
|
|
66 |
// Start(), otherwise MTmsHandlerObserver callbacks will be missed.
|
37
|
67 |
// ---------------------------------------------------------------------------
|
|
68 |
//
|
|
69 |
void CSPAudioHandler::Start()
|
|
70 |
{
|
|
71 |
iCallCount++;
|
|
72 |
CSPLOGSTRING2(CSPINT, "CSPAudioHandler::Start callcount: %d", iCallCount);
|
|
73 |
if (iTmsHandler && iCallCount == 1)
|
|
74 |
{
|
65
|
75 |
TInt err = iTmsHandler->StartStreams();
|
|
76 |
if (err != KErrNone)
|
|
77 |
{
|
|
78 |
AudioStreamsError(err);
|
|
79 |
}
|
37
|
80 |
}
|
|
81 |
}
|
|
82 |
|
|
83 |
// ---------------------------------------------------------------------------
|
|
84 |
// CSPAudioHandler::Stop
|
|
85 |
// ---------------------------------------------------------------------------
|
|
86 |
//
|
|
87 |
void CSPAudioHandler::Stop()
|
|
88 |
{
|
|
89 |
CSPLOGSTRING2(CSPINT, "CSPAudioHandler::Stop callcount: %d", iCallCount);
|
65
|
90 |
if (iTimer)
|
|
91 |
{
|
|
92 |
iTimer->CancelNotify();
|
|
93 |
}
|
37
|
94 |
if (iTmsHandler && iCallCount == 1)
|
|
95 |
{
|
|
96 |
iTmsHandler->StopStreams();
|
|
97 |
iCallCount--;
|
|
98 |
}
|
|
99 |
else if (iCallCount > 1)
|
|
100 |
{
|
|
101 |
iCallCount--;
|
|
102 |
}
|
|
103 |
}
|
|
104 |
|
|
105 |
// ---------------------------------------------------------------------------
|
65
|
106 |
// CSPAudioHandler::ReportAudioFailureAfterTimeout
|
|
107 |
// ---------------------------------------------------------------------------
|
|
108 |
//
|
|
109 |
void CSPAudioHandler::ReportAudioFailureAfterTimeout(TInt aTimeout)
|
|
110 |
{
|
|
111 |
CSPLOGSTRING(CSPOBJECT, "CSPAudioHandler::ReportAudioFailureAfterTimeout()");
|
|
112 |
|
|
113 |
if (iTmsHandler)
|
|
114 |
{
|
|
115 |
// Make sure audio streams are not already active, so we don't
|
|
116 |
// accidentaly hangup the call by setting the timer.
|
|
117 |
if (iTimer && !iTmsHandler->AreStreamsStarted())
|
|
118 |
{
|
|
119 |
if (iTimer->IsNotifyOngoing())
|
|
120 |
{
|
|
121 |
iTimer->CancelNotify();
|
|
122 |
}
|
|
123 |
iTimer->NotifyAfter(aTimeout, *this);
|
|
124 |
}
|
|
125 |
}
|
|
126 |
}
|
|
127 |
|
|
128 |
// ---------------------------------------------------------------------------
|
|
129 |
// CSPAudioHandler::AudioStreamsStarted
|
|
130 |
// From MTmsHandlerObserver
|
|
131 |
// ---------------------------------------------------------------------------
|
|
132 |
//
|
|
133 |
void CSPAudioHandler::AudioStreamsStarted()
|
|
134 |
{
|
|
135 |
CSPLOGSTRING(CSPOBJECT, "CSPAudioHandler::AudioStreamsStarted()");
|
|
136 |
if (iTimer)
|
|
137 |
{
|
|
138 |
iTimer->CancelNotify();
|
|
139 |
}
|
|
140 |
}
|
|
141 |
|
|
142 |
// ---------------------------------------------------------------------------
|
|
143 |
// CSPAudioHandler::AudioStreamsError
|
|
144 |
// From MTmsHandlerObserver
|
|
145 |
// ---------------------------------------------------------------------------
|
|
146 |
//
|
|
147 |
void CSPAudioHandler::AudioStreamsError(TInt /*aError*/)
|
|
148 |
{
|
|
149 |
CSPLOGSTRING(CSPOBJECT, "CSPAudioHandler::AudioStreamsError()");
|
|
150 |
if (iTimer)
|
|
151 |
{
|
|
152 |
iTimer->CancelNotify();
|
|
153 |
}
|
|
154 |
|
|
155 |
// Note: The observer must be provided in SetObserver() prior to Start()
|
|
156 |
// request, otherwise error conditions will not be propagated to the client.
|
|
157 |
if (iObserver)
|
|
158 |
{
|
|
159 |
iObserver->AudioStartingFailed();
|
|
160 |
}
|
|
161 |
}
|
|
162 |
|
|
163 |
// ---------------------------------------------------------------------------
|
|
164 |
// CSPAudioHandler::TimerEvent
|
|
165 |
// From MCSPTimerObserver
|
|
166 |
// ---------------------------------------------------------------------------
|
|
167 |
//
|
|
168 |
void CSPAudioHandler::TimerEvent()
|
|
169 |
{
|
|
170 |
CSPLOGSTRING(CSPOBJECT, "CSPAudioHandler::TimerEvent()");
|
|
171 |
if (iObserver)
|
|
172 |
{
|
|
173 |
iObserver->AudioStartingFailed();
|
|
174 |
}
|
|
175 |
if (iTmsHandler)
|
|
176 |
{
|
|
177 |
iTmsHandler->StopStreams();
|
|
178 |
}
|
|
179 |
}
|
|
180 |
|
|
181 |
// ---------------------------------------------------------------------------
|
37
|
182 |
// Constructs the monitor.
|
|
183 |
// ---------------------------------------------------------------------------
|
|
184 |
//
|
|
185 |
CSPAudioHandler::CSPAudioHandler()
|
|
186 |
{
|
|
187 |
CSPLOGSTRING(CSPOBJECT, "CSPAudioHandler::CSPAudioHandler()");
|
|
188 |
iCallCount = 0; // Active calls count
|
|
189 |
}
|
|
190 |
|
|
191 |
// ---------------------------------------------------------------------------
|
|
192 |
// Second phase construction.
|
|
193 |
// ---------------------------------------------------------------------------
|
|
194 |
//
|
|
195 |
void CSPAudioHandler::ConstructL()
|
|
196 |
{
|
65
|
197 |
CSPLOGSTRING(CSPOBJECT, "CSPAudioHandler::ConstructL()");
|
|
198 |
iTmsHandler = TmsHandler::NewL(*this);
|
|
199 |
iTimer = CSPTimer::NewL();
|
37
|
200 |
}
|
|
201 |
|
|
202 |
// End of file
|