|
1 // Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 /** |
|
17 @file |
|
18 @internalComponent |
|
19 */ |
|
20 |
|
21 #include <mtp/cmtpobjectmetadata.h> |
|
22 #include <mtp/mmtpdataproviderframework.h> |
|
23 #include <mtp/mmtpobjectmgr.h> |
|
24 |
|
25 #include "cmtpplaybackmap.h" |
|
26 #include "cmtpplaybackcommand.h" |
|
27 #include "cmtpplaybackcontroldp.h" |
|
28 #include "mtpplaybackcontrolpanic.h" |
|
29 |
|
30 |
|
31 // Class constants. |
|
32 __FLOG_STMT(_LIT8(KComponent,"MTPPlaybackMap");) |
|
33 |
|
34 const TInt KPlaybackRatePlay = 1000; |
|
35 const TInt KPlaybackRatePause = 0; |
|
36 const TInt KPlaybackRateFF = 2000; |
|
37 const TInt KPlaybackRateREW = -2000; |
|
38 /** |
|
39 Two-phase constructor. |
|
40 @param aPlugin The data provider plugin |
|
41 @return a pointer to the created playback checker object |
|
42 */ |
|
43 CMTPPlaybackMap* CMTPPlaybackMap::NewL(MMTPDataProviderFramework& aFramework, |
|
44 CMTPPlaybackProperty& aProperty) |
|
45 { |
|
46 CMTPPlaybackMap* self = new (ELeave) CMTPPlaybackMap(aFramework, aProperty); |
|
47 CleanupStack::PushL(self); |
|
48 self->ConstructL(); |
|
49 CleanupStack::Pop(self); |
|
50 return self; |
|
51 } |
|
52 |
|
53 /** |
|
54 Destructor. |
|
55 */ |
|
56 CMTPPlaybackMap::~CMTPPlaybackMap() |
|
57 { |
|
58 __FLOG(_L8("~CMTPPlaybackMap - Entry")); |
|
59 __FLOG(_L8("~CMTPPlaybackMap - Exit")); |
|
60 __FLOG_CLOSE; |
|
61 } |
|
62 |
|
63 /** |
|
64 Constructor. |
|
65 */ |
|
66 CMTPPlaybackMap::CMTPPlaybackMap(MMTPDataProviderFramework& aFramework, |
|
67 CMTPPlaybackProperty& aProperty): |
|
68 iFramework(aFramework),iProperty(aProperty) |
|
69 { |
|
70 } |
|
71 |
|
72 /** |
|
73 Second-phase constructor. |
|
74 */ |
|
75 void CMTPPlaybackMap::ConstructL() |
|
76 { |
|
77 __FLOG_OPEN(KMTPSubsystem, KComponent); |
|
78 __FLOG(_L8("CMTPPlaybackMap: ConstructL - Entry")); |
|
79 __FLOG(_L8("CMTPPlaybackMap: ConstructL - Exit")); |
|
80 } |
|
81 |
|
82 TInt CMTPPlaybackMap::GetPlaybackControlCommand(const TMTPPbCtrlData& aData, |
|
83 CMTPPlaybackCommand** aCmd) |
|
84 { |
|
85 __FLOG(_L8("GetPlaybackControlCommand - Entry")); |
|
86 TInt result = KErrNotSupported; |
|
87 switch(aData.iOptCode) |
|
88 { |
|
89 case EMTPOpCodeSetDevicePropValue: |
|
90 case EMTPOpCodeResetDevicePropValue: |
|
91 { |
|
92 result = HandleSetDevicePropValue(aData, aCmd); |
|
93 } |
|
94 break; |
|
95 case EMTPOpCodeGetDevicePropValue: |
|
96 case EMTPOpCodeGetDevicePropDesc: |
|
97 { |
|
98 result = HandleGetDevicePropValue(aData, aCmd); |
|
99 } |
|
100 break; |
|
101 case EMTPOpCodeSkip: |
|
102 { |
|
103 result = HandleSkip(aData, aCmd); |
|
104 } |
|
105 break; |
|
106 default: |
|
107 break; |
|
108 } |
|
109 __FLOG(_L8("GetPlaybackControlCommand - Exit")); |
|
110 return result; |
|
111 } |
|
112 |
|
113 TInt CMTPPlaybackMap::HandleSetDevicePropValue(const TMTPPbCtrlData& aData, |
|
114 CMTPPlaybackCommand** aCmd) |
|
115 { |
|
116 TRAPD(err, HandleSetDevicePropValueL(aData, aCmd)); |
|
117 return err; |
|
118 } |
|
119 |
|
120 void CMTPPlaybackMap::HandleSetDevicePropValueL(const TMTPPbCtrlData& aData, |
|
121 CMTPPlaybackCommand** aCmd) |
|
122 { |
|
123 __FLOG(_L8("HandleSetDevicePropValueL - Entry")); |
|
124 __ASSERT_DEBUG((aData.iOptCode == EMTPOpCodeSetDevicePropValue) || |
|
125 (aData.iOptCode == EMTPOpCodeResetDevicePropValue), |
|
126 Panic(EMTPPBArgumentErr)); |
|
127 |
|
128 switch(aData.iDevPropCode) |
|
129 { |
|
130 case EMTPDevicePropCodeVolume: |
|
131 { |
|
132 TUint32 val = aData.iPropValUint32.Value(); |
|
133 CMTPPbCmdParam* param = CMTPPbCmdParam::NewL(val); |
|
134 CleanupStack::PushL(param); |
|
135 *aCmd = CMTPPlaybackCommand::NewL(EPlaybackCmdSetVolume, param); |
|
136 CleanupStack::Pop(param); |
|
137 } |
|
138 break; |
|
139 |
|
140 case EMTPDevicePropCodePlaybackRate: |
|
141 { |
|
142 TInt32 val = aData.iPropValInt32.Value(); |
|
143 TMTPPlaybackCommand cmd = EPlaybackCmdNone; |
|
144 switch(val) |
|
145 { |
|
146 case KPlaybackRateFF: |
|
147 cmd = EPlaybackCmdSeekForward; |
|
148 break; |
|
149 case KPlaybackRatePlay: |
|
150 cmd = EPlaybackCmdPlay; |
|
151 break; |
|
152 case KPlaybackRatePause: |
|
153 cmd = EPlaybackCmdPause; |
|
154 break; |
|
155 case KPlaybackRateREW: |
|
156 cmd = EPlaybackCmdSeekBackward; |
|
157 break; |
|
158 default: |
|
159 User::Leave(KErrArgument); |
|
160 break; |
|
161 } |
|
162 if(cmd != EPlaybackCmdNone) |
|
163 { |
|
164 *aCmd = CMTPPlaybackCommand::NewL(cmd, NULL); |
|
165 } |
|
166 else |
|
167 { |
|
168 *aCmd = NULL; |
|
169 } |
|
170 } |
|
171 break; |
|
172 |
|
173 case EMTPDevicePropCodePlaybackObject: |
|
174 { |
|
175 TUint32 handle = aData.iPropValUint32.Value(); |
|
176 if(handle == 0) |
|
177 { |
|
178 *aCmd = CMTPPlaybackCommand::NewL(EPlaybackCmdStop, NULL); |
|
179 } |
|
180 else |
|
181 { |
|
182 TFileName suid; |
|
183 TUint format; |
|
184 GetObjecInfoFromHandleL(handle, suid, format); |
|
185 TMTPPbCategory cat = EMTPPbCatNone; |
|
186 switch(format) |
|
187 { |
|
188 case 0xBA05://Abstract Audio & Video Playlist |
|
189 case 0xBA11://M3U Playlist |
|
190 cat = EMTPPbCatPlayList; |
|
191 break; |
|
192 case 0xBA03://Abstract Audio Album |
|
193 cat = EMTPPbCatAlbum; |
|
194 break; |
|
195 case 0x3009://MP3 |
|
196 case 0xB903://AAC (Advance Audio Coding) |
|
197 case 0xB901://WMA (Windows Media Audio) |
|
198 case 0x3008://WAV (Waveform audio format) |
|
199 cat = EMTPPbCatMusic; |
|
200 break; |
|
201 default: |
|
202 User::Leave(KErrArgument); |
|
203 break; |
|
204 } |
|
205 if(cat != EMTPPbCatNone) |
|
206 { |
|
207 CMTPPbCmdParam* param = CMTPPbCmdParam::NewL(cat, suid); |
|
208 CleanupStack::PushL(param); |
|
209 *aCmd = CMTPPlaybackCommand::NewL(EPlaybackCmdInitObject, param); |
|
210 CleanupStack::Pop(param); |
|
211 } |
|
212 else |
|
213 { |
|
214 *aCmd = NULL; |
|
215 } |
|
216 } |
|
217 } |
|
218 break; |
|
219 |
|
220 case EMTPDevicePropCodePlaybackContainerIndex: |
|
221 { |
|
222 TUint32 index = aData.iPropValUint32.Value(); |
|
223 CMTPPbCmdParam* param = CMTPPbCmdParam::NewL(index); |
|
224 CleanupStack::PushL(param); |
|
225 *aCmd = CMTPPlaybackCommand::NewL(EPlaybackCmdInitIndex, param); |
|
226 CleanupStack::Pop(param); |
|
227 } |
|
228 break; |
|
229 |
|
230 case EMTPDevicePropCodePlaybackPosition: |
|
231 { |
|
232 TUint32 position = aData.iPropValUint32.Value(); |
|
233 CMTPPbCmdParam* param = CMTPPbCmdParam::NewL(position); |
|
234 CleanupStack::PushL(param); |
|
235 *aCmd = CMTPPlaybackCommand::NewL(EPlaybackCmdSetPosition, param); |
|
236 CleanupStack::Pop(param); |
|
237 } |
|
238 break; |
|
239 |
|
240 default: |
|
241 User::Leave(KErrArgument); |
|
242 break; |
|
243 } |
|
244 __FLOG(_L8("HandleSetDevicePropValueL - Exit")); |
|
245 } |
|
246 |
|
247 TInt CMTPPlaybackMap::HandleGetDevicePropValue(const TMTPPbCtrlData& aData, |
|
248 CMTPPlaybackCommand** aCmd) |
|
249 { |
|
250 TRAPD(err, HandleGetDevicePropValueL(aData, aCmd)); |
|
251 return err; |
|
252 } |
|
253 void CMTPPlaybackMap::HandleGetDevicePropValueL(const TMTPPbCtrlData& aData, |
|
254 CMTPPlaybackCommand** aCmd) |
|
255 { |
|
256 __FLOG(_L8("HandleGetDevicePropValueL - Entry")); |
|
257 __ASSERT_DEBUG((aData.iOptCode == EMTPOpCodeGetDevicePropValue) || |
|
258 (aData.iOptCode == EMTPOpCodeGetDevicePropDesc), |
|
259 Panic(EMTPPBArgumentErr)); |
|
260 |
|
261 switch(aData.iDevPropCode) |
|
262 { |
|
263 case EMTPDevicePropCodeVolume: |
|
264 { |
|
265 TMTPPlaybackCommand cmd = EPlaybackCmdGetVolumeSet; |
|
266 if(aData.iOptCode == EMTPOpCodeGetDevicePropValue) |
|
267 { |
|
268 cmd = EPlaybackCmdGetVolume; |
|
269 } |
|
270 *aCmd = CMTPPlaybackCommand::NewL(cmd, NULL); |
|
271 } |
|
272 break; |
|
273 |
|
274 case EMTPDevicePropCodePlaybackRate: |
|
275 { |
|
276 *aCmd = CMTPPlaybackCommand::NewL(EPlaybackCmdGetState, NULL); |
|
277 } |
|
278 break; |
|
279 |
|
280 case EMTPDevicePropCodePlaybackObject: |
|
281 { |
|
282 *aCmd = CMTPPlaybackCommand::NewL(EPlaybackCmdGetObject, NULL); |
|
283 } |
|
284 break; |
|
285 |
|
286 case EMTPDevicePropCodePlaybackContainerIndex: |
|
287 { |
|
288 *aCmd = CMTPPlaybackCommand::NewL(EPlaybackCmdGetIndex, NULL); |
|
289 } |
|
290 break; |
|
291 |
|
292 case EMTPDevicePropCodePlaybackPosition: |
|
293 { |
|
294 *aCmd = CMTPPlaybackCommand::NewL(EPlaybackCmdGetPosition, NULL); |
|
295 } |
|
296 break; |
|
297 |
|
298 default: |
|
299 User::Leave(KErrArgument); |
|
300 break; |
|
301 } |
|
302 __FLOG(_L8("HandleGetDevicePropValueL - Exit")); |
|
303 } |
|
304 |
|
305 TInt CMTPPlaybackMap::HandleSkip(const TMTPPbCtrlData& aData, |
|
306 CMTPPlaybackCommand** aCmd) |
|
307 { |
|
308 TRAPD(err, HandleSkipL(aData, aCmd)); |
|
309 return err; |
|
310 } |
|
311 |
|
312 void CMTPPlaybackMap::HandleSkipL(const TMTPPbCtrlData& aData, |
|
313 CMTPPlaybackCommand** aCmd) |
|
314 { |
|
315 __FLOG(_L8("HandleSkipL - Entry")); |
|
316 TInt32 step = aData.iPropValInt32.Value(); |
|
317 CMTPPbCmdParam* param = CMTPPbCmdParam::NewL(step); |
|
318 CleanupStack::PushL(param); |
|
319 *aCmd = CMTPPlaybackCommand::NewL(EPlaybackCmdSkip, param); |
|
320 CleanupStack::Pop(param); |
|
321 __FLOG(_L8("HandleSkipL - Exit")); |
|
322 } |
|
323 |
|
324 TInt32 CMTPPlaybackMap::PlaybackRateL(TMTPPlaybackState aState) |
|
325 { |
|
326 __FLOG(_L8("PlaybackRate - Entry")); |
|
327 TInt32 rate = KPlaybackRatePause; |
|
328 switch(aState) |
|
329 { |
|
330 case EPlayStateForwardSeeking: |
|
331 rate = KPlaybackRateFF; |
|
332 break; |
|
333 |
|
334 case EPlayStatePlaying: |
|
335 rate = KPlaybackRatePlay; |
|
336 break; |
|
337 |
|
338 case EPlayStatePaused: |
|
339 rate = KPlaybackRatePause; |
|
340 break; |
|
341 |
|
342 case EPlayStateBackwardSeeking: |
|
343 rate = KPlaybackRateREW; |
|
344 break; |
|
345 |
|
346 default: |
|
347 User::Leave(KErrArgument); |
|
348 break; |
|
349 } |
|
350 __FLOG(_L8("PlaybackRate - Exit")); |
|
351 return rate; |
|
352 } |
|
353 |
|
354 TUint32 CMTPPlaybackMap::ObjectHandleL(const TDesC& aSuid) |
|
355 { |
|
356 __FLOG(_L8("ObjectHandleL - Entry")); |
|
357 CMTPObjectMetaData* meta(CMTPObjectMetaData::NewLC()); |
|
358 TBool result = iFramework.ObjectMgr().ObjectL(aSuid, *meta); |
|
359 __ASSERT_ALWAYS(result, User::Leave(KErrBadHandle)); |
|
360 __ASSERT_DEBUG(meta, Panic(EMTPPBDataNullErr)); |
|
361 TUint32 handle = meta->Uint(CMTPObjectMetaData::EHandle); |
|
362 CleanupStack::PopAndDestroy(meta); |
|
363 __FLOG(_L8("ObjectHandleL - Exit")); |
|
364 return handle; |
|
365 } |
|
366 |
|
367 void CMTPPlaybackMap::GetObjecInfoFromHandleL(TUint32 aHandle, TDes& aSuid, TUint& aFormat) const |
|
368 { |
|
369 __FLOG(_L8("GetObjecInfoFromHandleL - Entry")); |
|
370 CMTPObjectMetaData* meta(CMTPObjectMetaData::NewLC()); |
|
371 TBool result = iFramework.ObjectMgr().ObjectL(aHandle, *meta); |
|
372 __ASSERT_ALWAYS(result, User::Leave(KErrBadHandle)); |
|
373 __ASSERT_DEBUG(meta, Panic(EMTPPBDataNullErr)); |
|
374 aSuid = meta->DesC(CMTPObjectMetaData::ESuid); |
|
375 aFormat = meta->Uint(CMTPObjectMetaData::EFormatCode); |
|
376 CleanupStack::PopAndDestroy(meta); |
|
377 __FLOG(_L8("GetObjecInfoFromHandleL - Exit")); |
|
378 } |