26
|
1 |
/*
|
|
2 |
* Copyright (c) 2005-2007 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: Manipulates the priority of a Player.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
// INCLUDE FILES
|
|
21 |
#include <AudioPreference.h>
|
|
22 |
#include <jdebug.h>
|
|
23 |
#include <cmmamidiplayer.h>
|
|
24 |
#include "cammsprioritycontrol.h"
|
|
25 |
#include <cmmaplayerevent.h>
|
|
26 |
#include <cmmaaudioplayer.h>
|
|
27 |
#include <cmmaemcaudioplayer.h>
|
|
28 |
#include <mmf/common/mmfcontroller.h>
|
|
29 |
#include <midiclientutility.h>
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
const TInt KErrorMessageSize = 32;
|
|
34 |
_LIT(KErrPriorityError, "AMMS PC error: %d");
|
|
35 |
|
|
36 |
// Default AMMS priority.
|
|
37 |
const TInt KAMMSDefaultPriority = 50;
|
|
38 |
|
|
39 |
// Reasonable MMF priorities.
|
|
40 |
const TInt KAMMSMinMMFPriority = 71;
|
|
41 |
const TInt KAMMSMaxMMFPriority = 89;
|
|
42 |
|
|
43 |
#ifdef _DEBUG
|
|
44 |
// CONSTANTS
|
|
45 |
const TInt KAMMSMaxPriority = 100;
|
|
46 |
const TInt KAMMSMinPriority = 0;
|
|
47 |
#endif // _DEBUG
|
|
48 |
|
|
49 |
|
|
50 |
// ============================ MEMBER FUNCTIONS ===============================
|
|
51 |
|
|
52 |
// -----------------------------------------------------------------------------
|
|
53 |
// CAMMSPriorityControl::NewLC
|
|
54 |
// Two-phased constructor.
|
|
55 |
// -----------------------------------------------------------------------------
|
|
56 |
CAMMSPriorityControl* CAMMSPriorityControl::NewLC(CMMAPlayer* aPlayer)
|
|
57 |
{
|
|
58 |
CAMMSPriorityControl* self = new(ELeave) CAMMSPriorityControl(aPlayer);
|
|
59 |
|
|
60 |
CleanupStack::PushL(self);
|
|
61 |
|
|
62 |
self->ConstructL();
|
|
63 |
|
|
64 |
return self;
|
|
65 |
}
|
|
66 |
|
|
67 |
// Destructor
|
|
68 |
CAMMSPriorityControl::~CAMMSPriorityControl()
|
|
69 |
{
|
|
70 |
DEBUG("AMMS::CAMMSPriorityControl::~");
|
|
71 |
}
|
|
72 |
|
|
73 |
// -----------------------------------------------------------------------------
|
|
74 |
// CAMMSPriorityControl::SetPriorityL
|
|
75 |
// Sets the priority using a linear point scale between 0 and 100.
|
|
76 |
// -----------------------------------------------------------------------------
|
|
77 |
//
|
|
78 |
void CAMMSPriorityControl::SetPriorityL(TInt aPriority)
|
|
79 |
{
|
|
80 |
DEBUG_INT("AMMS::CAMMSPriorityControl::SetPriorityL %d", aPriority);
|
|
81 |
|
|
82 |
// Check in debug build that aPriority is within valid range.
|
|
83 |
__ASSERT_DEBUG(
|
|
84 |
(aPriority <= KAMMSMaxPriority) &&
|
|
85 |
(aPriority >= KAMMSMinPriority),
|
|
86 |
User::Invariant());
|
|
87 |
|
|
88 |
// Set a new priority only if it differs from the previous one.
|
|
89 |
if (aPriority != iVisiblePriority)
|
|
90 |
{
|
|
91 |
// Set the new priority to MMF only if the player is PREFETCHED
|
|
92 |
// (otherwise setting will leave). In other states, the new priority
|
|
93 |
// will be set when the player state changes to PREFETCHED.
|
|
94 |
if (iPlayer->State() == CMMAPlayer::EPrefetched)
|
|
95 |
{
|
|
96 |
SetPriorityToMmfL(aPriority);
|
|
97 |
}
|
|
98 |
|
|
99 |
iVisiblePriority = aPriority;
|
|
100 |
}
|
|
101 |
|
|
102 |
DEBUG("AMMS::CAMMSPriorityControl::SetPriorityL -");
|
|
103 |
}
|
|
104 |
|
|
105 |
// -----------------------------------------------------------------------------
|
|
106 |
// CAMMSPriorityControl::Priority
|
|
107 |
// Gets the priority.
|
|
108 |
// -----------------------------------------------------------------------------
|
|
109 |
TInt CAMMSPriorityControl::Priority()
|
|
110 |
{
|
|
111 |
return iVisiblePriority;
|
|
112 |
}
|
|
113 |
|
|
114 |
// -----------------------------------------------------------------------------
|
|
115 |
// CAMMSPriorityControl::StateChanged
|
|
116 |
// Called when player state is changed.
|
|
117 |
// -----------------------------------------------------------------------------
|
|
118 |
void CAMMSPriorityControl::StateChanged(TInt aState)
|
|
119 |
{
|
|
120 |
DEBUG_INT("AMMS::CAMMSPriorityControl::StateChanged +, state = %d",
|
|
121 |
aState);
|
|
122 |
|
|
123 |
// If the state was changed to PREFETCHED, set the buffered priority to
|
|
124 |
// MMF. Set a new priority only if it differs from the previous one.
|
|
125 |
|
|
126 |
if ((aState == CMMAPlayer::EPrefetched) &&
|
|
127 |
(iActualPriority != iVisiblePriority))
|
|
128 |
{
|
|
129 |
TRAPD(err, SetPriorityToMmfL(iVisiblePriority));
|
|
130 |
|
|
131 |
DEBUG_INT("AMMS::CAMMSPriorityControl::StateChanged, err = %d", err);
|
|
132 |
|
|
133 |
if (err != KErrNone)
|
|
134 |
{
|
|
135 |
TBuf<KErrorMessageSize> errorMessage;
|
|
136 |
errorMessage.Format(KErrPriorityError, err);
|
|
137 |
iPlayer->PostStringEvent(CMMAPlayerEvent::EError, errorMessage);
|
|
138 |
}
|
|
139 |
}
|
|
140 |
|
|
141 |
DEBUG("AMMS::CAMMSPriorityControl::StateChanged -");
|
|
142 |
}
|
|
143 |
|
|
144 |
const TDesC& CAMMSPriorityControl::ClassName() const
|
|
145 |
{
|
|
146 |
DEBUG("CAMMSPriorityControl::ClassName");
|
|
147 |
|
|
148 |
return KAMMSPriorityControl;
|
|
149 |
}
|
|
150 |
|
|
151 |
// -----------------------------------------------------------------------------
|
|
152 |
// CAMMSPriorityControl::SetPriorityToMmfL
|
|
153 |
// Scales the given AMMS priority to MMF priority and sets it to MMF.
|
|
154 |
// -----------------------------------------------------------------------------
|
|
155 |
void CAMMSPriorityControl::SetPriorityToMmfL(TInt aAmmsPriority)
|
|
156 |
{
|
|
157 |
DEBUG_INT("AMMS::CAMMSPriorityControl::SetPriorityToMmfL %d",
|
|
158 |
aAmmsPriority);
|
|
159 |
|
|
160 |
// Scale the AMMS priority value to MMF priority value before setting it.
|
|
161 |
// The default priority used by MMA is 80. MMF priority can be between
|
|
162 |
// -100 and 100, but values between 71 and 89 are reasonable ones.
|
|
163 |
TInt newPriority = KAMMSMinMMFPriority + aAmmsPriority *
|
|
164 |
(KAMMSMaxMMFPriority - KAMMSMinMMFPriority) / 100; // CSI: 47 100% for scaled value #
|
|
165 |
|
|
166 |
DEBUG_INT("AMMS::CAMMSPriorityControl::SetPriorityToMmfL, newPriority = %d",
|
|
167 |
newPriority);
|
|
168 |
|
|
169 |
// In case of MIDIPlayer, use CMidiClientUtility, otherwise RMMFController.
|
|
170 |
if (iPlayer->Type() == KMMAMIDIPlayer)
|
|
171 |
{
|
|
172 |
// In case of CMMAMIDIPlayer use CMidiClientUtility
|
|
173 |
CMMAMIDIPlayer* mmaMIDIPlayer =
|
|
174 |
reinterpret_cast< CMMAMIDIPlayer* >(iPlayer);
|
|
175 |
|
|
176 |
CMidiClientUtility* midiClientUtility = mmaMIDIPlayer->MidiClient();
|
|
177 |
|
|
178 |
midiClientUtility->SetPriorityL(newPriority,
|
|
179 |
KMMAMIDIPriorityPreference);
|
|
180 |
}
|
|
181 |
else if (iPlayer->Type() == KMMAAudioPlayer)
|
|
182 |
{
|
|
183 |
CMMAAudioPlayer* mmaAudioPlayer =
|
|
184 |
reinterpret_cast< CMMAAudioPlayer* >(iPlayer);
|
|
185 |
|
|
186 |
RMMFController& rmmfController = mmaAudioPlayer->Controller();
|
|
187 |
|
|
188 |
TMMFPrioritySettings prioritySettings;
|
|
189 |
prioritySettings.iPriority = newPriority;
|
|
190 |
|
|
191 |
User::LeaveIfError(
|
|
192 |
rmmfController.SetPrioritySettings(prioritySettings));
|
|
193 |
}
|
|
194 |
else if (iPlayer->Type() == KMMAEMCAudioPlayer)
|
|
195 |
{
|
|
196 |
MStreamControl* streamControl = (static_cast<CMMAEMCAudioPlayer*>(iPlayer))->StreamControl();
|
|
197 |
User::LeaveIfError(streamControl->SetPriority(newPriority, KMMAEMCPriorityPreference));
|
|
198 |
}
|
|
199 |
|
|
200 |
iActualPriority = aAmmsPriority;
|
|
201 |
|
|
202 |
DEBUG("AMMS::CAMMSPriorityControl::SetPriorityToMmfL -");
|
|
203 |
}
|
|
204 |
|
|
205 |
// -----------------------------------------------------------------------------
|
|
206 |
// CAMMSPriorityControl::CAMMSPriorityControl
|
|
207 |
// C++ default constructor can NOT contain any code, that
|
|
208 |
// might leave.
|
|
209 |
// -----------------------------------------------------------------------------
|
|
210 |
CAMMSPriorityControl::CAMMSPriorityControl(CMMAPlayer* aPlayer)
|
|
211 |
: CAMMSControl(aPlayer),
|
|
212 |
iVisiblePriority(KAMMSDefaultPriority),
|
|
213 |
iActualPriority(KAMMSDefaultPriority)
|
|
214 |
{
|
|
215 |
}
|
|
216 |
|
|
217 |
// -----------------------------------------------------------------------------
|
|
218 |
// CAMMSPlayerStateListener::ConstructL
|
|
219 |
// 2nd phase constructor.
|
|
220 |
// (other items were commented in a header).
|
|
221 |
// -----------------------------------------------------------------------------
|
|
222 |
void CAMMSPriorityControl::ConstructL()
|
|
223 |
{
|
|
224 |
DEBUG("AMMS::CAMMSPriorityControl::ConstructL +");
|
|
225 |
|
|
226 |
iPlayer->AddStateListenerL(this);
|
|
227 |
|
|
228 |
DEBUG("AMMS::CAMMSPriorityControl::ConstructL -");
|
|
229 |
}
|
|
230 |
|
|
231 |
|
|
232 |
// End of File
|