|
1 /* |
|
2 * Copyright (c) 2005-2009 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: Base class implements volume control of AVRCP Controller. |
|
15 * |
|
16 * |
|
17 */ |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <remconbeareravrcp.h> // KRemConBearerAvrcpImplementationUid = 0x1020685f |
|
21 #include <MediaStreamPropertiesPSKeys.h> |
|
22 #include <mmkeybearerscancodes.h> // for volume pubsub |
|
23 #include <mediakeysinternalpskeys.h> |
|
24 #include <remconinterfaceselector.h> |
|
25 #include <remconcoreapicontroller.h> |
|
26 #include <remconaddress.h> |
|
27 #include <sounddevice.h> |
|
28 |
|
29 #include "btrccVolumeLevelControllerBase.h" |
|
30 #include "debug.h" |
|
31 |
|
32 |
|
33 // MODULE DATA STRUCTURES |
|
34 const TInt KVolumeChangeListenerServiceId = 0x01; |
|
35 |
|
36 // ================= MEMBER FUNCTIONS ======================= |
|
37 |
|
38 // ----------------------------------------------------------------------------- |
|
39 // CBTRCCVolumeLevelControllerBase::CBTRCCVolumeLevelController |
|
40 // C++ constructor. |
|
41 // ----------------------------------------------------------------------------- |
|
42 // |
|
43 CBTRCCVolumeLevelControllerBase::CBTRCCVolumeLevelControllerBase(MBTRCCVolumeControllerObserver &aObserver): |
|
44 iObserver(aObserver), iLocalMaxVolume(0), iState(ESubscribePhoneVolume) |
|
45 { |
|
46 } |
|
47 |
|
48 // ----------------------------------------------------------------------------- |
|
49 // CBTRCCVolumeLevelControllerBase::ConstructL |
|
50 // Symbian 2nd phase constructor. |
|
51 // ----------------------------------------------------------------------------- |
|
52 // |
|
53 void CBTRCCVolumeLevelControllerBase::ConstructL() |
|
54 { |
|
55 TRACE_FUNC |
|
56 LEAVE_IF_ERROR(iVolLevelProperty.Attach(KPSUidMediaStreamProperties, KMediaStreamCurrentVolume)) |
|
57 LEAVE_IF_ERROR(iVolKeyEventProperty.Attach(KPSUidMediaKeysEventNotifier, KMediaKeysAccessoryVolumeEvent)) |
|
58 iBtrccActive = CBTRCCActive::NewL(*this, KVolumeChangeListenerServiceId); |
|
59 } |
|
60 |
|
61 // ----------------------------------------------------------------------------- |
|
62 // Destructor. |
|
63 // ----------------------------------------------------------------------------- |
|
64 // |
|
65 CBTRCCVolumeLevelControllerBase::~CBTRCCVolumeLevelControllerBase() |
|
66 { |
|
67 TRACE_FUNC |
|
68 delete iBtrccActive; |
|
69 iVolLevelProperty.Close(); |
|
70 iVolKeyEventProperty.Close(); |
|
71 } |
|
72 |
|
73 // ----------------------------------------------------------------------------- |
|
74 // CBTRCCVolumeLevelControllerBase::Start |
|
75 // ----------------------------------------------------------------------------- |
|
76 // |
|
77 void CBTRCCVolumeLevelControllerBase::Start() |
|
78 { |
|
79 TRACE_FUNC |
|
80 |
|
81 iVolLevelProperty.Subscribe(iBtrccActive->iStatus); |
|
82 iBtrccActive->GoActive(); |
|
83 |
|
84 (void) GetPhoneVolume(iPhoneVolume); |
|
85 if( iPhoneVolume > -1) |
|
86 { |
|
87 DoStart( iPhoneVolume ); |
|
88 } |
|
89 } |
|
90 |
|
91 // ----------------------------------------------------------------------------- |
|
92 // CBTRCCVolumeLevelControllerBase::Stop |
|
93 // ----------------------------------------------------------------------------- |
|
94 // |
|
95 void CBTRCCVolumeLevelControllerBase::Stop() |
|
96 { |
|
97 TRACE_FUNC |
|
98 iBtrccActive->Cancel(); |
|
99 DoStop(); |
|
100 } |
|
101 |
|
102 // ----------------------------------------------------------------------------- |
|
103 // CBTRCCVolumeLevelControllerBase::Reset |
|
104 // ----------------------------------------------------------------------------- |
|
105 // |
|
106 void CBTRCCVolumeLevelControllerBase::Reset() |
|
107 { |
|
108 TRACE_FUNC |
|
109 iBtrccActive->Cancel(); |
|
110 DoReset(); |
|
111 } |
|
112 |
|
113 // ----------------------------------------------------------------------------- |
|
114 // CBTRCCVolumeLevelControllerBase::RegisterVolumeChangeNotification |
|
115 // ----------------------------------------------------------------------------- |
|
116 // |
|
117 void CBTRCCVolumeLevelControllerBase::RegisterVolumeChangeNotification() |
|
118 { |
|
119 TRACE_FUNC |
|
120 return; |
|
121 } |
|
122 |
|
123 // ----------------------------------------------------------------------------- |
|
124 // CBTRCCVolumeLevelControllerBase::GetLocalMaxVolume |
|
125 // ----------------------------------------------------------------------------- |
|
126 // |
|
127 TInt CBTRCCVolumeLevelControllerBase::GetLocalMaxVolume() |
|
128 { |
|
129 TRACE_FUNC |
|
130 if(iLocalMaxVolume == 0) |
|
131 { |
|
132 // fetch max volume from adaptation and cache it. |
|
133 CMMFDevSound* devSound = NULL; |
|
134 TRAPD( err, devSound = CMMFDevSound::NewL() ); |
|
135 if(!err) |
|
136 { |
|
137 iLocalMaxVolume = devSound->MaxVolume(); |
|
138 TRACE_INFO((_L("Maximum volume is %d"), iLocalMaxVolume)) |
|
139 delete devSound; // This is not needed for anything else. |
|
140 } |
|
141 } |
|
142 return iLocalMaxVolume; |
|
143 } |
|
144 |
|
145 // ----------------------------------------------------------------------------- |
|
146 // CBTRCCVolumeLevelControllerBase::AccessoryChangedVolume |
|
147 // ----------------------------------------------------------------------------- |
|
148 // |
|
149 void CBTRCCVolumeLevelControllerBase::AccessoryChangedVolume(TInt aVolumeInPhoneScale) |
|
150 { |
|
151 TRACE_FUNC |
|
152 iRemoteVolume = aVolumeInPhoneScale; |
|
153 TInt vol; |
|
154 TInt err = GetPhoneVolume(vol); |
|
155 if(!err) |
|
156 { |
|
157 iPhoneVolume = vol; |
|
158 SetPhoneVolume(); |
|
159 } |
|
160 } |
|
161 |
|
162 // ----------------------------------------------------------------------------- |
|
163 // CBTRCCVolumeLevelControllerBase::SetPhoneVolume |
|
164 // ----------------------------------------------------------------------------- |
|
165 // |
|
166 void CBTRCCVolumeLevelControllerBase::SetPhoneVolume() |
|
167 { |
|
168 TRACE_FUNC |
|
169 TRACE_INFO((_L("iRemoteVolume = %d, iPhoneVolume = %d"), iRemoteVolume, iPhoneVolume)) |
|
170 if (iRemoteVolume != iPhoneVolume) |
|
171 { |
|
172 TInt event = (iRemoteVolume > iPhoneVolume) ? KPSVolumeUpClicked : KPSVolumeDownClicked; |
|
173 TInt err = iVolKeyEventProperty.Set(event); |
|
174 if (err) |
|
175 { |
|
176 TRACE_ERROR((_L("Set KMediaKeysVolumeKeyEvent err %d"), err)); |
|
177 } |
|
178 iState = ESetPhoneVolume; |
|
179 } |
|
180 else |
|
181 { |
|
182 iState = ESubscribePhoneVolume; |
|
183 } |
|
184 } |
|
185 |
|
186 // ----------------------------------------------------------------------------- |
|
187 // CBTRCCVolumeLevelControllerBase::GetPhoneVolume |
|
188 // ----------------------------------------------------------------------------- |
|
189 // |
|
190 TInt CBTRCCVolumeLevelControllerBase::GetPhoneVolume(TInt &aVol) |
|
191 { |
|
192 aVol = -1; |
|
193 TInt err = iVolLevelProperty.Get(aVol); |
|
194 TRACE_INFO((_L("Get volume P&S ret %d vol %d"), err, aVol)) |
|
195 return err; |
|
196 } |
|
197 |
|
198 // ----------------------------------------------------------------------------- |
|
199 // CBTRCCVolumeLevelControllerBase::GetCurrentLocalVolume |
|
200 // ----------------------------------------------------------------------------- |
|
201 // |
|
202 TInt CBTRCCVolumeLevelControllerBase::GetCurrentLocalVolume() |
|
203 { |
|
204 return iPhoneVolume; |
|
205 } |
|
206 |
|
207 // ----------------------------------------------------------------------------- |
|
208 // CBTRCCVolumeLevelControllerBase::RequestCompletedL |
|
209 // ----------------------------------------------------------------------------- |
|
210 // |
|
211 void CBTRCCVolumeLevelControllerBase::RequestCompletedL(CBTRCCActive& aActive, TInt aErr) |
|
212 { |
|
213 TRACE_FUNC |
|
214 if(aActive.ServiceId() == KVolumeChangeListenerServiceId) |
|
215 { |
|
216 TInt err = GetPhoneVolume(iPhoneVolume); |
|
217 |
|
218 if(!err && !aErr && iPhoneVolume > -1) |
|
219 { |
|
220 switch(iState) |
|
221 { |
|
222 case ESubscribePhoneVolume: |
|
223 // Tell the specialization of the new volume level. |
|
224 AdjustRemoteVolume(iPhoneVolume); |
|
225 break; |
|
226 case ESetPhoneVolume: |
|
227 SetPhoneVolume(); |
|
228 break; |
|
229 } |
|
230 } |
|
231 |
|
232 iVolLevelProperty.Subscribe(iBtrccActive->iStatus); |
|
233 iBtrccActive->GoActive(); |
|
234 } |
|
235 } |
|
236 |
|
237 // ----------------------------------------------------------------------------- |
|
238 // CBTRCCVolumeLevelControllerBase::CancelRequest |
|
239 // ----------------------------------------------------------------------------- |
|
240 // |
|
241 void CBTRCCVolumeLevelControllerBase::CancelRequest(TInt aServiceId) |
|
242 { |
|
243 TRACE_FUNC |
|
244 switch (aServiceId) |
|
245 { |
|
246 case KVolumeChangeListenerServiceId: |
|
247 { |
|
248 iVolLevelProperty.Cancel(); |
|
249 break; |
|
250 } |
|
251 default: |
|
252 break; |
|
253 } |
|
254 } |
|
255 |
|
256 void CBTRCCVolumeLevelControllerBase::VolumeControlError(TInt aError) |
|
257 { |
|
258 iObserver.VolumeControlError(aError); |
|
259 } |
|
260 |
|
261 |
|
262 // End of File |