|
1 /* |
|
2 * Copyright (c) 2008 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: Proxy for downloading upnp files and playing locally |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 // INCLUDES |
|
24 #include <upnpitem.h> |
|
25 #include "upnpitemutility.h" // for ResourceFromItemL |
|
26 #include "upnpavcontroller.h" |
|
27 #include "upnpmusicdownloadproxy.h" |
|
28 #include "upnpsingleton.h" |
|
29 #include "upnptrack.h" |
|
30 |
|
31 _LIT( KComponentLogfile, "musicplugins.txt"); |
|
32 #include "upnplog.h" |
|
33 |
|
34 #include "upnppluginserrortranslation.h" |
|
35 |
|
36 // CONSTANTS |
|
37 // ** a message to music player to complete an immediate exit |
|
38 const TInt KMusicPluginMessageExit = 3001; |
|
39 const TUid KLocalPlayerDefinitionUid = { 0x101FFC06 }; |
|
40 |
|
41 // ======== MEMBER FUNCTIONS ======== |
|
42 |
|
43 // -------------------------------------------------------------------------- |
|
44 // CUPnPMusicDownloadProxy::NewL |
|
45 // 1st phase constructor. |
|
46 // -------------------------------------------------------------------------- |
|
47 // |
|
48 CUPnPMusicDownloadProxy* CUPnPMusicDownloadProxy::NewL( |
|
49 MMPXPlaybackPluginObserver& aObs ) |
|
50 { |
|
51 CUPnPMusicDownloadProxy* p = new ( ELeave ) |
|
52 CUPnPMusicDownloadProxy( aObs ); |
|
53 __LOG1( "DownloadProxy: NewL this=%d", p ); |
|
54 CleanupStack::PushL( p ); |
|
55 p->ConstructL(); |
|
56 CleanupStack::Pop(); |
|
57 return p; |
|
58 } |
|
59 |
|
60 // -------------------------------------------------------------------------- |
|
61 // CUPnPMusicDownloadProxy::CUPnPMusicDownloadProxy |
|
62 // Default constructor. |
|
63 // -------------------------------------------------------------------------- |
|
64 // |
|
65 CUPnPMusicDownloadProxy::CUPnPMusicDownloadProxy( |
|
66 MMPXPlaybackPluginObserver& aObs ) |
|
67 : iProxyState( EStateUninitialised ) |
|
68 { |
|
69 iObs = &aObs; |
|
70 iLocalPlayer = NULL; |
|
71 iSingleton = NULL; |
|
72 iTrack = NULL; |
|
73 } |
|
74 |
|
75 // -------------------------------------------------------------------------- |
|
76 // CUPnPMusicDownloadProxy::ConstructL |
|
77 // 1st phase constructor. |
|
78 // -------------------------------------------------------------------------- |
|
79 // |
|
80 void CUPnPMusicDownloadProxy::ConstructL() |
|
81 { |
|
82 __LOG( "DownloadProxy: ConstructL" ); |
|
83 |
|
84 // Construct the underlying local plugin |
|
85 iLocalPlayer = CMPXPlaybackPlugin::NewL( |
|
86 KLocalPlayerDefinitionUid ); |
|
87 |
|
88 // Create handle to singleton |
|
89 iSingleton = CUPnPSingleton::GetInstanceL(); |
|
90 } |
|
91 |
|
92 // -------------------------------------------------------------------------- |
|
93 // CUPnPMusicDownloadProxy::~CUPnPMusicDownloadProxy |
|
94 // Destructor. |
|
95 // -------------------------------------------------------------------------- |
|
96 // |
|
97 CUPnPMusicDownloadProxy::~CUPnPMusicDownloadProxy() |
|
98 { |
|
99 __LOG1( "DownloadProxy: destructor [%d]", |
|
100 this ); |
|
101 Cleanup(); |
|
102 |
|
103 // Free memory of owned members |
|
104 delete iLocalPlayer; |
|
105 CUPnPSingleton::LoseInstance( iSingleton ); |
|
106 } |
|
107 |
|
108 |
|
109 // -------------------------------------------------------------------------- |
|
110 // Methods from CMPXPlaybackPlugin |
|
111 // -------------------------------------------------------------------------- |
|
112 |
|
113 // -------------------------------------------------------------------------- |
|
114 // CUPnPMusicDownloadProxy::InitialiseL |
|
115 // -------------------------------------------------------------------------- |
|
116 // |
|
117 void CUPnPMusicDownloadProxy::InitialiseL( const TDesC& aSong ) |
|
118 { |
|
119 __LOG2( "DownloadProxy::InitialiseL(%S) [%d]", |
|
120 &aSong, this ); |
|
121 |
|
122 __ASSERTD( iProxyState == EStateUninitialised,__FILE__, __LINE__ ); |
|
123 |
|
124 iProxyState = EStatePreparing; |
|
125 |
|
126 // Create local track object to resolving URI |
|
127 delete iTrack; |
|
128 iTrack = 0; |
|
129 iTrack = CUPnPTrack::NewL( iSingleton->AVC() ); |
|
130 iTrack->ResolveURIL( aSong, *this, CUPnPTrack::EDirectionLocal ); |
|
131 iProxyState = EStateDownloading; |
|
132 } |
|
133 |
|
134 // -------------------------------------------------------------------------- |
|
135 // CUPnPMusicDownloadProxy::InitialiseL |
|
136 // -------------------------------------------------------------------------- |
|
137 // |
|
138 void CUPnPMusicDownloadProxy::InitialiseL( RFile& /*aSong*/ ) |
|
139 { |
|
140 // Not used. Only remote file is supported |
|
141 __PANICD( __FILE__, __LINE__ ); |
|
142 User::Leave( KErrNotSupported ); |
|
143 } |
|
144 |
|
145 // -------------------------------------------------------------------------- |
|
146 // CUPnPMusicDownloadProxy::HandleMetaData |
|
147 // from MUPnPTrackMetaDataObserver |
|
148 // -------------------------------------------------------------------------- |
|
149 // |
|
150 void CUPnPMusicDownloadProxy::ResolveURIComplete( TInt aError ) |
|
151 { |
|
152 __LOG1( "DownloadProxy::ResolveURIComplete [%d]", this ); |
|
153 __ASSERTD( iProxyState == EStateDownloading,__FILE__, __LINE__ ); |
|
154 |
|
155 if ( aError == KErrNone ) |
|
156 { |
|
157 TRAPD( initerror, iLocalPlayer->InitialiseL( |
|
158 iTrack->FilePath() ) ); |
|
159 |
|
160 if ( initerror != KErrNone ) |
|
161 { |
|
162 __LOG1( "DownloadProxy:local player init leaves: %d", |
|
163 initerror ); |
|
164 Cleanup(); |
|
165 iProxyState = EStateUninitialised; |
|
166 //translate error |
|
167 initerror = TUpnpPluginsErrorTranslation::ErrorTranslate( |
|
168 initerror ); |
|
169 iObs->HandlePluginEvent( |
|
170 MMPXPlaybackPluginObserver::EPInitialised, 0, initerror ); |
|
171 } |
|
172 else |
|
173 { |
|
174 iProxyState = EStateInitialisingLocally; |
|
175 } |
|
176 } |
|
177 else |
|
178 { |
|
179 __LOG1("DownloadProxy::ResolveURIComplete: error %d", |
|
180 aError ); |
|
181 Cleanup(); |
|
182 iProxyState = EStateUninitialised; |
|
183 aError = TUpnpPluginsErrorTranslation::ErrorTranslate( |
|
184 aError ); |
|
185 iObs->HandlePluginEvent( |
|
186 MMPXPlaybackPluginObserver::EPInitialised, |
|
187 0, aError ); |
|
188 } |
|
189 } |
|
190 |
|
191 // -------------------------------------------------------------------------- |
|
192 // CUPnPMusicDownloadProxy::CommandL |
|
193 // -------------------------------------------------------------------------- |
|
194 // |
|
195 void CUPnPMusicDownloadProxy::CommandL( TMPXPlaybackCommand aCmd, |
|
196 TInt aData ) |
|
197 { |
|
198 __LOG2( "DownloadProxy::CommandL(%d) [%d]", aCmd, this ); |
|
199 |
|
200 if( iProxyState == EStateActive ) |
|
201 { |
|
202 // ACTIVE state: all commands are forwarded to local plugin |
|
203 __LOG( "DownloadProxy: command in active state" ); |
|
204 iLocalPlayer->CommandL( aCmd, aData ); |
|
205 } |
|
206 else if ( iProxyState == EStatePreparing && aCmd == EPbCmdClose ) |
|
207 { |
|
208 __LOG( "DownloadProxy: Close during prepare" ); |
|
209 Cleanup(); |
|
210 iProxyState = EStateUninitialised; |
|
211 iObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPClosed, |
|
212 0, KErrNone ); |
|
213 } |
|
214 else if( iProxyState == EStateDownloading && aCmd == EPbCmdClose ) |
|
215 { |
|
216 __LOG( "DownloadProxy: Close during download" ); |
|
217 Cleanup(); // this will cancel ongoing copy |
|
218 iProxyState = EStateUninitialised; |
|
219 iObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPClosed, |
|
220 0, KErrNone ); |
|
221 } |
|
222 else if( iProxyState == EStateInitialisingLocally && |
|
223 aCmd == EPbCmdClose ) |
|
224 { |
|
225 __LOG( "DownloadProxy: Close when initialising locally" ); |
|
226 iLocalPlayer->CommandL( aCmd, aData ); |
|
227 } |
|
228 else if( iProxyState == EStateUninitialised && aCmd == EPbCmdClose ) |
|
229 { |
|
230 __LOG( "DownloadProxy: Close when uninitialized" ); |
|
231 iObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPClosed, |
|
232 0, KErrNone ); |
|
233 } |
|
234 else if( ( iProxyState == EStatePreparing || |
|
235 iProxyState == EStateDownloading || |
|
236 iProxyState == EStateInitialisingLocally || |
|
237 iProxyState == EStateUninitialised ) && aCmd == EPbCmdStop ) |
|
238 { |
|
239 __LOG( "DownloadProxy: Stop during any state" ); |
|
240 iLocalPlayer->CommandL( aCmd, aData ); |
|
241 } |
|
242 else // Not initialized |
|
243 { |
|
244 __LOG1( "DownloadProxy: Command not supported in this state: %d", |
|
245 iProxyState ); |
|
246 User::Leave( KErrNotReady ); |
|
247 } |
|
248 |
|
249 // check for messages from upnp framework (aData param) |
|
250 if ( aCmd == EPbCmdClose && |
|
251 aData == KMusicPluginMessageExit ) |
|
252 { |
|
253 __LOG( "CommandL(Close, exit) -> cleanup and terminate" ); |
|
254 |
|
255 // cancel things that are ongoing |
|
256 Cleanup(); |
|
257 iLocalPlayer->CancelRequest(); |
|
258 iProxyState = EStateUninitialised; |
|
259 |
|
260 // Create event to user |
|
261 |
|
262 iObs->HandlePluginEvent( |
|
263 MMPXPlaybackPluginObserver::EPPlayerUnavailable, |
|
264 0, KErrDisconnected); |
|
265 } |
|
266 } |
|
267 |
|
268 // -------------------------------------------------------------------------- |
|
269 // CUPnPMusicDownloadProxy::SetL |
|
270 // -------------------------------------------------------------------------- |
|
271 // |
|
272 void CUPnPMusicDownloadProxy::SetL( TMPXPlaybackProperty aProperty, |
|
273 TInt aValue ) |
|
274 { |
|
275 __LOG1( "DownloadProxy::SetL [%d]", this ); |
|
276 __LOG1( "Property=%d", (TInt)aProperty ); |
|
277 iLocalPlayer->SetL( aProperty, aValue ); |
|
278 } |
|
279 |
|
280 // -------------------------------------------------------------------------- |
|
281 // CUPnPMusicDownloadProxy::ValueL |
|
282 // -------------------------------------------------------------------------- |
|
283 // |
|
284 void CUPnPMusicDownloadProxy::ValueL( TMPXPlaybackProperty aProperty ) const |
|
285 { |
|
286 __LOG1( "DownloadProxy::ValueL [%d]", this ); |
|
287 iLocalPlayer->ValueL( aProperty ); |
|
288 } |
|
289 |
|
290 // -------------------------------------------------------------------------- |
|
291 // CUPnPMusicDownloadProxy::SubPlayerNamesL |
|
292 // -------------------------------------------------------------------------- |
|
293 // |
|
294 void CUPnPMusicDownloadProxy::SubPlayerNamesL() |
|
295 { |
|
296 iLocalPlayer->SubPlayerNamesL(); |
|
297 } |
|
298 |
|
299 // -------------------------------------------------------------------------- |
|
300 // CUPnPMusicDownloadProxy::SelectSubPlayerL |
|
301 // -------------------------------------------------------------------------- |
|
302 // |
|
303 void CUPnPMusicDownloadProxy::SelectSubPlayerL( TInt aIndex ) |
|
304 { |
|
305 iLocalPlayer->SelectSubPlayerL( aIndex ); |
|
306 } |
|
307 |
|
308 // -------------------------------------------------------------------------- |
|
309 // CUPnPMusicDownloadProxy::SubPlayerName |
|
310 // Returns current sub player name |
|
311 // -------------------------------------------------------------------------- |
|
312 // |
|
313 const TDesC& CUPnPMusicDownloadProxy::SubPlayerName() |
|
314 { |
|
315 return iLocalPlayer->SubPlayerName(); |
|
316 } |
|
317 |
|
318 // -------------------------------------------------------------------------- |
|
319 // CUPnPMusicDownloadProxy::SubPlayerIndex |
|
320 // -------------------------------------------------------------------------- |
|
321 // |
|
322 TInt CUPnPMusicDownloadProxy::SubPlayerIndex() const |
|
323 { |
|
324 return iLocalPlayer->SubPlayerIndex(); |
|
325 } |
|
326 |
|
327 // -------------------------------------------------------------------------- |
|
328 // CUPnPMusicDownloadProxy::MediaL |
|
329 // -------------------------------------------------------------------------- |
|
330 // |
|
331 void CUPnPMusicDownloadProxy::MediaL( const TArray<TMPXAttribute>& aAttrs ) |
|
332 { |
|
333 // Get metadata from media server |
|
334 if( iTrack ) |
|
335 { |
|
336 __LOG1( "DownloadProxy: Get metadata [%d]", this ); |
|
337 iTrack->GetMetaDataL( aAttrs, *iObs ); |
|
338 } |
|
339 else |
|
340 { |
|
341 __LOG( "DownloadProxy: Get metadata - no track!" ); |
|
342 User::Leave( KErrNotReady ); |
|
343 } |
|
344 } |
|
345 |
|
346 // -------------------------------------------------------------------------- |
|
347 // CUPnPMusicDownloadProxy::CancelRequest |
|
348 // -------------------------------------------------------------------------- |
|
349 // |
|
350 void CUPnPMusicDownloadProxy::CancelRequest() |
|
351 { |
|
352 __LOG( "CUPnPMusicDownloadProxy::CancelRequest" ); |
|
353 if( iProxyState == EStateDownloading ) |
|
354 { |
|
355 Cleanup(); // this will cancel ongoing copy |
|
356 iProxyState = EStateUninitialised; |
|
357 // Send "downloading cancelled" event to the user |
|
358 iObs->HandlePluginEvent( |
|
359 MMPXPlaybackPluginObserver::EPDownloadingCanceled, |
|
360 0, KErrGeneral ); |
|
361 } |
|
362 iLocalPlayer->CancelRequest(); |
|
363 } |
|
364 |
|
365 |
|
366 // -------------------------------------------------------------------------- |
|
367 // CUPnPMusicDownloadProxy::SetObserver |
|
368 // -------------------------------------------------------------------------- |
|
369 // |
|
370 void CUPnPMusicDownloadProxy::SetObserver(MMPXPlaybackPluginObserver& aObs) |
|
371 { |
|
372 CMPXPlaybackPlugin::SetObserver( aObs ); |
|
373 |
|
374 iLocalPlayer->SetObserver( *this ); |
|
375 } |
|
376 |
|
377 // -------------------------------------------------------------------------- |
|
378 // Methods from MMPXPlaybackPluginObserver |
|
379 // -------------------------------------------------------------------------- |
|
380 |
|
381 // -------------------------------------------------------------------------- |
|
382 // CUPnPMusicDownloadProxy::HandlePluginEvent |
|
383 // -------------------------------------------------------------------------- |
|
384 // |
|
385 void CUPnPMusicDownloadProxy::HandlePluginEvent( TEvent aEvent, |
|
386 TInt aData, TInt aError ) |
|
387 { |
|
388 __LOG1( "DownloadProxy::HandlePluginEvent [%d]", this ); |
|
389 |
|
390 switch( aEvent ) |
|
391 { |
|
392 case EPInitialised: |
|
393 { |
|
394 __ASSERTD( iProxyState == EStateInitialisingLocally,__FILE__, |
|
395 __LINE__ ); |
|
396 __LOG1( "DownloadProxy: initialised event, err=%d", |
|
397 aError ); |
|
398 |
|
399 // Proxied local plugin initialized |
|
400 if ( aError == KErrNone ) |
|
401 { |
|
402 iProxyState = EStateActive; |
|
403 |
|
404 iObs->HandlePluginEvent( aEvent, aData, aError ); |
|
405 } |
|
406 else |
|
407 { |
|
408 iProxyState = EStateClosing; |
|
409 TRAP_IGNORE ( |
|
410 iLocalPlayer->CommandL( EPbCmdClose, 0 ) ); |
|
411 } |
|
412 |
|
413 if ( iProxyState == EStateActive ) |
|
414 { |
|
415 TRAP_IGNORE( |
|
416 iTrack->SendMediaChangedEventL( *iObs ); |
|
417 ); |
|
418 } |
|
419 break; |
|
420 } |
|
421 case EPPlaying: // fall through |
|
422 case EPPlayComplete: // fall through |
|
423 case EPPaused: // fall through |
|
424 case EPStopped: // fall through |
|
425 case EPDownloadStarted: // fall through |
|
426 case EPDownloadingComplete: // fall through |
|
427 case EPSubPlayersChanged: // fall through |
|
428 case EPVolumeChanged: // fall through |
|
429 case EPSetComplete: |
|
430 { |
|
431 __LOG2( "DownloadProxy plugin event=%d err=%d", |
|
432 (TInt)aEvent, aError ); |
|
433 |
|
434 // Just forward event to the user. |
|
435 aError = TUpnpPluginsErrorTranslation::ErrorTranslate( |
|
436 aError ); |
|
437 iObs->HandlePluginEvent( aEvent, aData, aError ); |
|
438 break; |
|
439 } |
|
440 case EPClosed: |
|
441 { |
|
442 __LOG( "DownloadProxy: closed event" ); |
|
443 |
|
444 // a Stop command has changed. It will send back a Stopped event |
|
445 // and then a Closed event. Following Pause command will not be |
|
446 // accepted in Uninitialized state and CommandL() will leave. |
|
447 // This change in MPX was necessary to let engine know the file |
|
448 // was closed. One additional aData parameter is passed in |
|
449 // iObs->HandlePluginEvent(MMPXPlaybackPluginObserver::EPClosed, |
|
450 // EPbCmdStop, KErrNone); to know the difference between a |
|
451 // real Close and a Stop/Close. When this happens, EPClosed event |
|
452 // should be ignored. |
|
453 if( aData == EPbCmdStop ) |
|
454 { |
|
455 break; |
|
456 } |
|
457 |
|
458 Cleanup(); |
|
459 |
|
460 // If iProxyState is EStateClosing, initialise of |
|
461 // localplaybackplugin is failed -> send initialised event with |
|
462 // an error code to the user. |
|
463 // Otherwise forward event to the user normally. |
|
464 if( iProxyState == EStateClosing ) |
|
465 { |
|
466 iObs->HandlePluginEvent( |
|
467 MMPXPlaybackPluginObserver::EPInitialised, |
|
468 0, KErrNotSupported ); |
|
469 } |
|
470 else |
|
471 { |
|
472 aError = TUpnpPluginsErrorTranslation::ErrorTranslate( |
|
473 aError ); |
|
474 iObs->HandlePluginEvent( aEvent, aData, aError ); |
|
475 } |
|
476 iProxyState = EStateUninitialised; |
|
477 break; |
|
478 } |
|
479 default: |
|
480 { |
|
481 __LOG( "DownloadProxy: Default event?" ); |
|
482 break; |
|
483 } |
|
484 } |
|
485 } |
|
486 |
|
487 // -------------------------------------------------------------------------- |
|
488 // CUPnPMusicDownloadProxy::HandleProperty |
|
489 // -------------------------------------------------------------------------- |
|
490 // |
|
491 void CUPnPMusicDownloadProxy::HandleProperty( TMPXPlaybackProperty aProperty, |
|
492 TInt aValue, TInt aError ) |
|
493 { |
|
494 __LOG1( "DownloadProxy::HandleProperty [%d]", this ); |
|
495 |
|
496 iObs->HandleProperty( aProperty, aValue, aError ); |
|
497 } |
|
498 |
|
499 // -------------------------------------------------------------------------- |
|
500 // CUPnPMusicDownloadProxy::HandleSubPlayerNames |
|
501 // -------------------------------------------------------------------------- |
|
502 // |
|
503 void CUPnPMusicDownloadProxy::HandleSubPlayerNames( TUid aPlayer, |
|
504 const MDesCArray* aSubPlayers, TBool aComplete, TInt aError ) |
|
505 { |
|
506 iObs->HandleSubPlayerNames( aPlayer, aSubPlayers, aComplete, aError ); |
|
507 } |
|
508 |
|
509 // -------------------------------------------------------------------------- |
|
510 // CUPnPMusicDownloadProxy::HandleMedia |
|
511 // -------------------------------------------------------------------------- |
|
512 // |
|
513 void CUPnPMusicDownloadProxy::HandleMedia( const CMPXMedia& aProperties, |
|
514 TInt aError ) |
|
515 { |
|
516 __LOG1( "DownloadProxy::HandleMedia [%d]", this ); |
|
517 |
|
518 iObs->HandleMedia( aProperties, aError ); |
|
519 } |
|
520 |
|
521 // -------------------------------------------------------------------------- |
|
522 // CUPnPMusicDownloadProxy::CleanUpSession |
|
523 // -------------------------------------------------------------------------- |
|
524 // |
|
525 void CUPnPMusicDownloadProxy::Cleanup() |
|
526 { |
|
527 __LOG1( "DownloadProxy::Cleanup [%d]", this ); |
|
528 if( iTrack ) |
|
529 { |
|
530 delete iTrack; |
|
531 iTrack = 0; |
|
532 } |
|
533 __LOG( "DownloadProxy::Cleanup - End"); |
|
534 } |
|
535 |