|
1 /* |
|
2 * Copyright (c) 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: Source file for CUpnpShowTask class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 // upnp stack api |
|
21 #include <upnpitem.h> // CUpnpItem |
|
22 #include <upnpobject.h> // CUpnpObject (cast) |
|
23 |
|
24 // upnpframework / avcontroller api |
|
25 #include "upnpavcontroller.h" // MUPnPAVController |
|
26 #include "upnpavrenderingsession.h" // MUPnPAVRenderingSession |
|
27 #include "upnpavsessionobserverbase.h" |
|
28 |
|
29 // upnpframework / avcontroller helper api |
|
30 #include "upnpconstantdefs.h" // KFilterCommon, KClassVideo |
|
31 #include "upnpitemresolver.h" // MUPnPItemResolver |
|
32 #include "upnpitemresolverobserver.h" // MUPnPItemResolverObserver |
|
33 #include "upnpitemresolverfactory.h" // UPnPItemResolverFactory |
|
34 #include "upnpitemutility.h" // UPnPItemUtility::BelongsToClass |
|
35 |
|
36 // upnpframework / commonui |
|
37 #include "upnpcommonui.h" |
|
38 |
|
39 // command internal |
|
40 #include "upnpfilepipe.h" // CUpnpFilePipe |
|
41 #include "upnptaskhandler.h" // MUpnpTaskHandler |
|
42 #include "upnptaskresourceallocator.h" // CUpnpTaskResourceAllocator |
|
43 #include "upnpimagerenderingengine.h" // CUpnpImageRenderingEngine |
|
44 #include "upnpshowtask.h" |
|
45 #include "upnpcommand.h" |
|
46 #include "upnpnotehandler.h" // CUpnpNoteHandler |
|
47 |
|
48 _LIT( KComponentLogfile, "upnpcommand.log"); |
|
49 #include "upnplog.h" |
|
50 |
|
51 |
|
52 // -------------------------------------------------------------------------- |
|
53 // CUpnpShowTask::NewL |
|
54 // Creates an instance of the implementation. |
|
55 // -------------------------------------------------------------------------- |
|
56 // |
|
57 CUpnpTask* CUpnpShowTask::NewL() |
|
58 { |
|
59 __LOG( "[UpnpCommand]\t CUpnpShowTask::NewL" ); |
|
60 |
|
61 // Create instance |
|
62 CUpnpShowTask* self = new (ELeave) CUpnpShowTask(); |
|
63 CleanupStack::PushL( self ); |
|
64 self->ConstructL(); |
|
65 CleanupStack::Pop( self ); |
|
66 return self; |
|
67 } |
|
68 |
|
69 // -------------------------------------------------------------------------- |
|
70 // CUpnpShowTask::CUpnpShowTask |
|
71 // First phase construction. |
|
72 // -------------------------------------------------------------------------- |
|
73 // |
|
74 CUpnpShowTask::CUpnpShowTask() |
|
75 { |
|
76 __LOG( "[UpnpCommand]\t CUpnpShowTask::Constructor" ); |
|
77 |
|
78 // Initialise member variables |
|
79 iCommonUI = NULL; |
|
80 iPlayingVideo = EFalse; |
|
81 iRenderingSession = NULL; |
|
82 iVideoRenderingSession = NULL; |
|
83 iResourceAllocator = NULL; |
|
84 iRenderingEngine = NULL; |
|
85 } |
|
86 |
|
87 // -------------------------------------------------------------------------- |
|
88 // Destructor. |
|
89 // -------------------------------------------------------------------------- |
|
90 // |
|
91 CUpnpShowTask::~CUpnpShowTask() |
|
92 { |
|
93 __LOG( "[UpnpCommand]\t CUpnpShowTask::Destructor" ); |
|
94 |
|
95 Cleanup(); |
|
96 } |
|
97 |
|
98 // -------------------------------------------------------------------------- |
|
99 // CUpnpShowTask::Cleanup |
|
100 // -------------------------------------------------------------------------- |
|
101 // |
|
102 void CUpnpShowTask::Cleanup() |
|
103 { |
|
104 __LOG( "[UpnpCommand]\t CUpnpShowTask::Cleanup" ); |
|
105 |
|
106 if ( iRenderingEngine ) |
|
107 { |
|
108 delete iRenderingEngine; |
|
109 iRenderingEngine = NULL; |
|
110 } |
|
111 |
|
112 // delete the resource allocator |
|
113 // Local mediaserver and AVController resources will be freed. |
|
114 delete iResourceAllocator; |
|
115 iResourceAllocator = NULL; |
|
116 |
|
117 iRenderingSession = NULL; |
|
118 iVideoRenderingSession = NULL; |
|
119 |
|
120 delete iCommonUI; |
|
121 iCommonUI = NULL; |
|
122 |
|
123 __LOG( "[UpnpCommand]\t CUpnpShowTask::Cleanup - end" ); |
|
124 } |
|
125 |
|
126 // -------------------------------------------------------------------------- |
|
127 // CUpnpShowTask::ConstructL |
|
128 // Perform the second phase of two phase construction. Reserves the Upnp Fw |
|
129 // resources (they are released when the task is destroyed). |
|
130 // -------------------------------------------------------------------------- |
|
131 // |
|
132 void CUpnpShowTask::ConstructL() |
|
133 { |
|
134 __LOG( "[UpnpCommand]\t CUpnpShowTask::ConstructL" ); |
|
135 |
|
136 // create common UI |
|
137 iCommonUI = CUPnPCommonUI::NewL(); |
|
138 |
|
139 // create the resource allocator |
|
140 iResourceAllocator = CUpnpTaskResourceAllocator::NewL( |
|
141 *iCommonUI, |
|
142 CUpnpTaskResourceAllocator::EResourceAvController | |
|
143 CUpnpTaskResourceAllocator::EResourceLocalMediaServer | |
|
144 CUpnpTaskResourceAllocator::EResourceSelectImageRenderer ); |
|
145 |
|
146 iShowPlaybackFailedNote = ETrue; |
|
147 } |
|
148 |
|
149 // -------------------------------------------------------------------------- |
|
150 // CUpnpShowTask::AllocateResourcesL |
|
151 // Allocates the Upnp Fw resources. |
|
152 // -------------------------------------------------------------------------- |
|
153 // |
|
154 void CUpnpShowTask::AllocateResourcesL() |
|
155 { |
|
156 __LOG( "[UpnpCommand]\t CUpnpShowTask::AllocateResourcesL" ); |
|
157 |
|
158 iResourceAllocator->SetNoteHandlerL( NoteHandler() ); |
|
159 |
|
160 NoteHandler()->ResetDrmNoteCount(); |
|
161 |
|
162 // now allocate! |
|
163 iResourceAllocator->AllocateL(); |
|
164 |
|
165 // start a rendering session |
|
166 iRenderingSession = |
|
167 &iResourceAllocator->AVController().StartRenderingSessionL( |
|
168 iResourceAllocator->SelectedDevice() ); |
|
169 |
|
170 // create image rendering engine |
|
171 iRenderingEngine = CUpnpImageRenderingEngine::NewL( |
|
172 iResourceAllocator->AVController(), |
|
173 *iRenderingSession, |
|
174 *this ); |
|
175 } |
|
176 |
|
177 |
|
178 |
|
179 // -------------------------------------------------------------------------- |
|
180 // CUpnpShowTask::ExecuteL |
|
181 // Executes the task. |
|
182 // -------------------------------------------------------------------------- |
|
183 // |
|
184 void CUpnpShowTask::ExecuteL() |
|
185 { |
|
186 __LOG( "[UpnpCommand]\t CUpnpShowTask::ExecuteL" ); |
|
187 // assert that required resources exist |
|
188 __ASSERTD( iRenderingEngine, __FILE__, __LINE__ ); |
|
189 |
|
190 |
|
191 if( iPlayingVideo ) |
|
192 { |
|
193 // if videoplayerdlg is active, we cannot start rendering new file |
|
194 // before user closes the dialog |
|
195 __LOG( "[UpnpCommand]\t CUpnpShowTask::ExecuteL\ |
|
196 video already playing, do nothing" ); |
|
197 } |
|
198 else |
|
199 { |
|
200 // start rendering process on the engine |
|
201 iRenderingEngine->PlayL(); |
|
202 } |
|
203 } |
|
204 |
|
205 |
|
206 // -------------------------------------------------------------------------- |
|
207 // CUpnpShowTask::GetMedia |
|
208 // provide media to be played back |
|
209 // -------------------------------------------------------------------------- |
|
210 MUPnPItemResolver* CUpnpShowTask::GetMedia() |
|
211 { |
|
212 __ASSERTD( FilePipe(), __FILE__, __LINE__ ); |
|
213 |
|
214 MUPnPItemResolver* resolver = 0; |
|
215 |
|
216 if ( FilePipe()->Count() > 0 ) |
|
217 { |
|
218 const TDesC& filename = FilePipe()->FileAt( 0 ); |
|
219 __LOG1( "[UpnpCommand]\t CUpnpShowTask::GetMedia: %S", &filename ); |
|
220 TRAP_IGNORE ( |
|
221 resolver = |
|
222 UPnPItemResolverFactory::NewLocalItemResolverL( |
|
223 filename, |
|
224 iResourceAllocator->AVController(), |
|
225 iSelector, |
|
226 UPnPItemResolverFactory::EOmitLocalMSStart ); |
|
227 ); |
|
228 } |
|
229 |
|
230 return resolver; |
|
231 } |
|
232 |
|
233 // -------------------------------------------------------------------------- |
|
234 // CUpnpShowTask::RenderAck |
|
235 // Callback from image rendering engine. |
|
236 // -------------------------------------------------------------------------- |
|
237 TInt CUpnpShowTask::RenderAck( |
|
238 TInt aError, |
|
239 const CUpnpItem* aItem ) |
|
240 { |
|
241 __LOG1( "[UpnpCommand]\t CUpnpShowTask::RenderAck aError %D", aError ); |
|
242 if ( aError == KErrNotSupported && aItem && |
|
243 UPnPItemUtility::BelongsToClass( *aItem, KClassVideo ) ) |
|
244 { |
|
245 // NOTE! |
|
246 // This is a special case. For video playback we use the image |
|
247 // rendering engine for resolving, and then it fails with |
|
248 // KErrNotSupported, because it is not an image. Now we catch the |
|
249 // error here and play the resolved item. Why that complicated ? |
|
250 // - to keep image rendering engine for image rendering ONLY |
|
251 // and not to mix video UI stuff in there |
|
252 // - to enable image rendering engine reuse in the future |
|
253 // - so that we do not have to rewrite the resolving code in |
|
254 // another place, it already exists in image rendering engine. |
|
255 aError = PlayVideo( *aItem ); |
|
256 } |
|
257 |
|
258 if ( aError != KErrDisconnected ) |
|
259 { |
|
260 // disconnect message is handled in EngineShutdown |
|
261 // other errors are handled here |
|
262 if ( aError == KErrNotSupported || aError == KErrPermissionDenied ) |
|
263 { |
|
264 TRAP_IGNORE( NoteHandler()->ShowDrmNoteL() ); |
|
265 } |
|
266 else if( aError != KErrNone && iShowPlaybackFailedNote ) |
|
267 { |
|
268 // note is shown only once per session |
|
269 TRAP_IGNORE( NoteHandler()->ShowPlaybackFailedNoteL() ); |
|
270 iShowPlaybackFailedNote = EFalse; |
|
271 } |
|
272 |
|
273 // inform observer |
|
274 CommandEvent( UpnpCommand::EEventComplete, aError ); |
|
275 } |
|
276 __LOG1( "[UpnpCommand]\t CUpnpShowTask::RenderAck end, resp=%d", aError ); |
|
277 return aError; |
|
278 } |
|
279 |
|
280 // -------------------------------------------------------------------------- |
|
281 // CUpnpShowTask::EngineShutdown |
|
282 // Callback from image rendering engine. |
|
283 // -------------------------------------------------------------------------- |
|
284 void CUpnpShowTask::EngineShutdown( |
|
285 TInt aError ) |
|
286 { |
|
287 __ASSERTD( iRenderingEngine, __FILE__, __LINE__ ); |
|
288 |
|
289 if ( iPlayingVideo ) |
|
290 { |
|
291 __LOG1( "[UpnpCommand]\t CUpnpShowTask::EngineShutdown(%d)\ |
|
292 while video playing", |
|
293 aError ); |
|
294 TRAP_IGNORE( iCommonUI->DismissDialogL( aError ) ); |
|
295 } |
|
296 else |
|
297 { |
|
298 __LOG1( "[UpnpCommand]\t CUpnpShowTask::EngineShutdown(%d)", |
|
299 aError ); |
|
300 |
|
301 if( aError == KErrDisconnected ) |
|
302 { |
|
303 // check from rendering engine if wlan is active |
|
304 // note shown only in device disappeared cases |
|
305 if( iRenderingEngine->IsWlanActive() ) |
|
306 { |
|
307 TRAP_IGNORE( NoteHandler()->ShowConnectionLostNoteL() ); |
|
308 } |
|
309 } |
|
310 |
|
311 |
|
312 // Inform the observer |
|
313 __ASSERTD( TaskHandler(), __FILE__, __LINE__ ); |
|
314 |
|
315 CommandEvent( UpnpCommand::EEventComplete, aError); |
|
316 } |
|
317 __LOG( "[UpnpCommand]\t CUpnpShowTask::EngineShutdown END" ); |
|
318 } |
|
319 |
|
320 |
|
321 |
|
322 // -------------------------------------------------------------------------- |
|
323 // CUpnpShowTask::PlayVideo |
|
324 // Launches the video player dialog for playing a video file on remote |
|
325 // -------------------------------------------------------------------------- |
|
326 TInt CUpnpShowTask::PlayVideo( const CUpnpItem& aItem ) |
|
327 { |
|
328 __LOG( "[UpnpCommand]\t CUpnpShowTask::CUpnpShowTask::PlayVideo start" ); |
|
329 |
|
330 TInt videoPlayerError = KErrNone; |
|
331 TInt videoStatus = KErrNone; |
|
332 |
|
333 // Update the state |
|
334 iPlayingVideo = ETrue; |
|
335 |
|
336 |
|
337 // Launch the video player dialog to render the item. |
|
338 TRAP( videoPlayerError, |
|
339 |
|
340 // start a rendering session ( used only for video playing ) |
|
341 if( !iVideoRenderingSession ) |
|
342 { |
|
343 iVideoRenderingSession = |
|
344 &iResourceAllocator->AVController().StartRenderingSessionL( |
|
345 iResourceAllocator->SelectedDevice() ); |
|
346 } |
|
347 |
|
348 // inform observer that we are launching dialog |
|
349 __LOG( "[UpnpCommand]\t CUpnpShowTask::CUpnpShowTask::PlayVideo \ |
|
350 launching videoplayerdialog" ); |
|
351 CommandEvent( UpnpCommand::EEventProgress, |
|
352 UpnpCommand::KUpnpCommandStatusStartPlayVideo, EFalse ); |
|
353 |
|
354 // plays video |
|
355 videoStatus = iCommonUI->ExecuteVideoPlayerL( |
|
356 *iVideoRenderingSession, aItem ); |
|
357 ) |
|
358 |
|
359 // Update the state |
|
360 iPlayingVideo = EFalse; |
|
361 |
|
362 // Fix UpnpCommonUi's return value |
|
363 if( videoStatus > 0 ) |
|
364 { |
|
365 videoStatus = KErrNone; |
|
366 } |
|
367 |
|
368 if( videoPlayerError != KErrNone && |
|
369 videoStatus == KErrNone ) |
|
370 { |
|
371 videoStatus = videoPlayerError; |
|
372 } |
|
373 |
|
374 __LOG( "[UpnpCommand]\t CUpnpShowTask::CUpnpShowTask::PlayVideo end" ); |
|
375 |
|
376 // Inform the observer, no matter if the playing succeeded or failed. |
|
377 return videoStatus; |
|
378 } |
|
379 |
|
380 |
|
381 // End of File |