|
1 /* |
|
2 * Copyright (c) 2005-2006 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: This class listens to notification coming from Remote Control framework. |
|
15 * BTRCC is interested in only those of initiated by BT Remote Control Plugin. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <remconbeareravrcp.h> // KRemConBearerAvrcpImplementationUid = 0x1020685f |
|
22 #include <MediaStreamPropertiesPSKeys.h> |
|
23 #include <remconinterfaceselector.h> |
|
24 #include <remconaddress.h> |
|
25 |
|
26 #include "btrccAbsoluteVolumeLevelController.h" |
|
27 #include "debug.h" |
|
28 |
|
29 const TInt KAbsoluteVolumeLevelSetServiceId = 0x02; |
|
30 const TInt KMaxRetries = 3; |
|
31 |
|
32 // MODULE DATA STRUCTURES |
|
33 |
|
34 // ================= MEMBER FUNCTIONS ======================= |
|
35 |
|
36 // ----------------------------------------------------------------------------- |
|
37 // CBTRCCAbsoluteVolumeLevelController::NewL |
|
38 // Two-phased constructor. |
|
39 // ----------------------------------------------------------------------------- |
|
40 // |
|
41 CBTRCCAbsoluteVolumeLevelController* CBTRCCAbsoluteVolumeLevelController::NewL(CRemConInterfaceSelector& aInterfaceSelector, MBTRCCVolumeControllerObserver& aObserver) |
|
42 { |
|
43 CBTRCCAbsoluteVolumeLevelController* self = new (ELeave) CBTRCCAbsoluteVolumeLevelController(aObserver); |
|
44 CleanupStack::PushL(self); |
|
45 self->ConstructL(aInterfaceSelector); |
|
46 CleanupStack::Pop(self); |
|
47 return self; |
|
48 } |
|
49 |
|
50 // ----------------------------------------------------------------------------- |
|
51 // CBTRCCAbsoluteVolumeLevelController::CBTRCCAbsoluteVolumeLevelController |
|
52 // C++ constructor. |
|
53 // ----------------------------------------------------------------------------- |
|
54 // |
|
55 CBTRCCAbsoluteVolumeLevelController::CBTRCCAbsoluteVolumeLevelController(MBTRCCVolumeControllerObserver& aObserver) |
|
56 : CBTRCCVolumeLevelControllerBase(aObserver) |
|
57 { |
|
58 } |
|
59 |
|
60 // ----------------------------------------------------------------------------- |
|
61 // CBTRCCAbsoluteVolumeLevelController::ConstructL |
|
62 // Symbian 2nd phase constructor. |
|
63 // ----------------------------------------------------------------------------- |
|
64 // |
|
65 void CBTRCCAbsoluteVolumeLevelController::ConstructL(CRemConInterfaceSelector& aInterfaceSelector) |
|
66 { |
|
67 TRACE_FUNC |
|
68 CBTRCCVolumeLevelControllerBase::ConstructL(); |
|
69 iLocalMaxVolume = GetLocalMaxVolume(); |
|
70 iInterfaceSelector = &aInterfaceSelector; |
|
71 |
|
72 iRemConAbsoluteVolumeController = CRemConAbsoluteVolumeController::NewL(aInterfaceSelector, |
|
73 *this, |
|
74 iLocalMaxVolume); |
|
75 TRACE_INFO((_L("CRemConAbsoluteVolumeController created"))) |
|
76 iBtrccAbsoluteVolumeActive = CBTRCCActive::NewL(*this, KAbsoluteVolumeLevelSetServiceId); |
|
77 TRACE_INFO((_L("CBTRCCActive created"))) |
|
78 } |
|
79 |
|
80 // ----------------------------------------------------------------------------- |
|
81 // Destructor. |
|
82 // ----------------------------------------------------------------------------- |
|
83 // |
|
84 CBTRCCAbsoluteVolumeLevelController::~CBTRCCAbsoluteVolumeLevelController() |
|
85 { |
|
86 TRACE_FUNC |
|
87 delete iBtrccAbsoluteVolumeActive; |
|
88 } |
|
89 |
|
90 // ----------------------------------------------------------------------------- |
|
91 // CBTRCCAbsoluteVolumeLevelController::DoStart |
|
92 // ----------------------------------------------------------------------------- |
|
93 // |
|
94 void CBTRCCAbsoluteVolumeLevelController::DoStart(TInt aInitialVolume) |
|
95 { |
|
96 TRACE_FUNC |
|
97 AdjustRemoteVolume(aInitialVolume); |
|
98 } |
|
99 |
|
100 // ----------------------------------------------------------------------------- |
|
101 // CBTRCCAbsoluteVolumeLevelController::DoStop |
|
102 // ----------------------------------------------------------------------------- |
|
103 // |
|
104 void CBTRCCAbsoluteVolumeLevelController::DoStop() |
|
105 { |
|
106 TRACE_FUNC |
|
107 iRemConAbsoluteVolumeController->CancelAbsoluteVolumeNotification(); |
|
108 iRemConAbsoluteVolumeController->CancelSetAbsoluteVolume(); |
|
109 iBtrccAbsoluteVolumeActive->Cancel(); |
|
110 } |
|
111 |
|
112 // ----------------------------------------------------------------------------- |
|
113 // CBTRCCAbsoluteVolumeLevelController::DoReset |
|
114 // ----------------------------------------------------------------------------- |
|
115 // |
|
116 void CBTRCCAbsoluteVolumeLevelController::DoReset() |
|
117 { |
|
118 } |
|
119 |
|
120 // ----------------------------------------------------------------------------- |
|
121 // CBTRCCAbsoluteVolumeLevelController::AdjustRemoteVolume |
|
122 // ----------------------------------------------------------------------------- |
|
123 // |
|
124 void CBTRCCAbsoluteVolumeLevelController::AdjustRemoteVolume(TInt aVolume) |
|
125 { |
|
126 TRACE_INFO((_L("Setting volume to %d"), aVolume)) |
|
127 |
|
128 if(iBtrccAbsoluteVolumeActive->IsActive()) |
|
129 { |
|
130 iRemConAbsoluteVolumeController->CancelSetAbsoluteVolume(); |
|
131 iBtrccAbsoluteVolumeActive->Cancel(); |
|
132 } |
|
133 |
|
134 //Try to register volume change notification |
|
135 RegisterVolumeChangeNotification(); |
|
136 |
|
137 // iNumRemotes is not needed by us, but the method requires it. |
|
138 iRemConAbsoluteVolumeController->SetAbsoluteVolume(iBtrccAbsoluteVolumeActive->iStatus, |
|
139 aVolume, iNumRemotes); |
|
140 iBtrccAbsoluteVolumeActive->GoActive(); |
|
141 } |
|
142 |
|
143 |
|
144 // ----------------------------------------------------------------------------- |
|
145 // CBTRCCAbsoluteVolumeLevelController::RegisterVolumeChangeNotification |
|
146 // ----------------------------------------------------------------------------- |
|
147 // |
|
148 void CBTRCCAbsoluteVolumeLevelController::RegisterVolumeChangeNotification() |
|
149 { |
|
150 |
|
151 iRemConAbsoluteVolumeController->CancelAbsoluteVolumeNotification(); |
|
152 iRemConAbsoluteVolumeController->RegisterAbsoluteVolumeNotification(); |
|
153 } |
|
154 |
|
155 // ----------------------------------------------------------------------------- |
|
156 // CBTRCCAbsoluteVolumeLevelController::GetPhoneVolume |
|
157 // ----------------------------------------------------------------------------- |
|
158 // |
|
159 TInt CBTRCCAbsoluteVolumeLevelController::GetPhoneVolume(TInt &aVol) |
|
160 { |
|
161 TRACE_FUNC |
|
162 return CBTRCCVolumeLevelControllerBase::GetPhoneVolume(aVol); |
|
163 } |
|
164 |
|
165 // ----------------------------------------------------------------------------- |
|
166 // CBTRCCAbsoluteVolumeLevelController::RequestCompletedL |
|
167 // ----------------------------------------------------------------------------- |
|
168 // |
|
169 void CBTRCCAbsoluteVolumeLevelController::RequestCompletedL(CBTRCCActive& aActive, TInt aErr) |
|
170 { |
|
171 TRACE_FUNC |
|
172 if( aActive.ServiceId() != KAbsoluteVolumeLevelSetServiceId ) |
|
173 { |
|
174 // This is something the base class can handle. |
|
175 CBTRCCVolumeLevelControllerBase::RequestCompletedL(aActive, aErr); |
|
176 } |
|
177 else if(aErr && iRetryCounter < KMaxRetries) // else it is KAbsoluteVolumeLevelSetServiceId |
|
178 { |
|
179 TRACE_INFO((_L("Sending abs vol cmd failed with error %d"), aErr)) |
|
180 iRetryCounter++; |
|
181 AdjustRemoteVolume(GetCurrentLocalVolume()); |
|
182 } |
|
183 else |
|
184 { |
|
185 if(iRetryCounter >= KMaxRetries) |
|
186 { |
|
187 VolumeControlError(EVolumeAdjustmentFailed); |
|
188 } |
|
189 iRetryCounter = 0; |
|
190 } |
|
191 } |
|
192 |
|
193 // ----------------------------------------------------------------------------- |
|
194 // CBTRCCAbsoluteVolumeLevelController::CancelRequest |
|
195 // ----------------------------------------------------------------------------- |
|
196 // |
|
197 void CBTRCCAbsoluteVolumeLevelController::CancelRequest(TInt aServiceId) |
|
198 { |
|
199 TRACE_FUNC |
|
200 if( aServiceId != KAbsoluteVolumeLevelSetServiceId ) |
|
201 { |
|
202 // This is something the base class can handle. |
|
203 CBTRCCVolumeLevelControllerBase::CancelRequest(aServiceId); |
|
204 } |
|
205 } |
|
206 |
|
207 // ----------------------------------------------------------------------------- |
|
208 // CBTRCCAbsoluteVolumeLevelController::MrcavcoCurrentVolume |
|
209 // ----------------------------------------------------------------------------- |
|
210 // |
|
211 void CBTRCCAbsoluteVolumeLevelController::MrcavcoCurrentVolume(TUint32 aVolume, |
|
212 TUint32 aMaxVolume, |
|
213 TInt aError) |
|
214 { |
|
215 TRACE_FUNC |
|
216 AccessoryChangedVolume(aVolume, aMaxVolume, aError); |
|
217 /*if(aError != KErrNone) |
|
218 { |
|
219 // Register again to the notifications. |
|
220 iRemConAbsoluteVolumeController->RegisterAbsoluteVolumeNotification(); |
|
221 }*/ |
|
222 } |
|
223 |
|
224 // ----------------------------------------------------------------------------- |
|
225 // CBTRCCAbsoluteVolumeLevelController::MrcavcoSetAbsoluteVolumeResponse |
|
226 // ----------------------------------------------------------------------------- |
|
227 // |
|
228 void CBTRCCAbsoluteVolumeLevelController::MrcavcoSetAbsoluteVolumeResponse(TUint32 aVolume, |
|
229 TUint32 aMaxVolume, |
|
230 TInt aError) |
|
231 { |
|
232 TRACE_FUNC |
|
233 TRACE_INFO((_L("Accessory volume is %d / %d"), aVolume, aMaxVolume)) |
|
234 AccessoryChangedVolume(aVolume, aMaxVolume, aError); |
|
235 } |
|
236 |
|
237 // ----------------------------------------------------------------------------- |
|
238 // CBTRCCAbsoluteVolumeLevelController::MrcavcoAbsoluteVolumeNotificationError |
|
239 // ----------------------------------------------------------------------------- |
|
240 // |
|
241 void CBTRCCAbsoluteVolumeLevelController::MrcavcoAbsoluteVolumeNotificationError() |
|
242 { |
|
243 TRACE_FUNC |
|
244 // This is called when there's some error with writing the commands. |
|
245 // It means that we can't send notifications or responses to those, so |
|
246 // it's better to stop volume controlling and reset the link. |
|
247 VolumeControlError(ERegisterNotificationsFailed); |
|
248 } |
|
249 // ----------------------------------------------------------------------------- |
|
250 // CBTRCCAbsoluteVolumeLevelController::AccessoryChangedVolume |
|
251 // ----------------------------------------------------------------------------- |
|
252 // |
|
253 void CBTRCCAbsoluteVolumeLevelController::AccessoryChangedVolume(TUint32 aVolume, TUint32 aMaxVolume, TInt aError) |
|
254 { |
|
255 TRACE_FUNC |
|
256 TRACE_INFO((_L("Accessory volume is %d / %d"), aVolume, aMaxVolume)) |
|
257 if( ValidVolumeParams(aVolume, aMaxVolume) && (aError == KErrNone) ) |
|
258 { |
|
259 // Convert volume scale to phone's volume scale. (User reals and round in the end.) |
|
260 TInt volumeInPhoneScale = (TReal)aVolume * ((TReal)iLocalMaxVolume / (TReal)aMaxVolume) + 0.5; |
|
261 ASSERT(volumeInPhoneScale <= iLocalMaxVolume); |
|
262 TRACE_INFO((_L("Volume in phone scale is %d"), volumeInPhoneScale)) |
|
263 CBTRCCVolumeLevelControllerBase::AccessoryChangedVolume(volumeInPhoneScale); |
|
264 } |
|
265 } |
|
266 |
|
267 TBool CBTRCCAbsoluteVolumeLevelController::ValidVolumeParams(TUint32 aVolume, TUint32 aMaxVolume) |
|
268 { |
|
269 return (( aMaxVolume > 0 ) && (aVolume <= aMaxVolume)); |
|
270 } |
|
271 |
|
272 // End of File |