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