1 /* |
|
2 * Copyright (c) 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 the License "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: Interface to Browser for handling embedded video requests. |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include <BrowserAudioVideoPlugin.rsg> |
|
20 #include <StringLoader.h> |
|
21 #include <data_caging_path_literals.hrh> |
|
22 #include <bautils.h> |
|
23 |
|
24 #include "BavpLogger.h" |
|
25 #include "BavpPlugin.h" |
|
26 #include "BavpView.h" |
|
27 #include "BavpControllerAudio.h" |
|
28 #include "BavpControllerVideo.h" |
|
29 |
|
30 #include <npscript.h> |
|
31 using namespace RT_GestureHelper; |
|
32 |
|
33 // CONSTANTS |
|
34 _LIT( KBrowserAVPluginRscFileZ, "z:BrowserAudioVideoPlugin.rsc" ); |
|
35 _LIT( KBrowserAVPluginRscFile, "\\resource\\BrowserAudioVideoPlugin.rsc"); |
|
36 |
|
37 // ============================ MEMBER FUNCTIONS =============================== |
|
38 |
|
39 // ----------------------------------------------------------------------------- |
|
40 // CBavpPlugin::CBavpPlugin |
|
41 // C++ default constructor can NOT contain any code, that |
|
42 // might leave. |
|
43 // ----------------------------------------------------------------------------- |
|
44 CBavpPlugin::CBavpPlugin() |
|
45 : iError( EFalse ), |
|
46 iMimeType( NULL ), |
|
47 iPauseState ( EFalse ), |
|
48 iIsForeGround ( ETrue ), |
|
49 iPauseInBackground (EFalse), |
|
50 iPlayFromFile(EFalse) |
|
51 { |
|
52 |
|
53 } |
|
54 |
|
55 // ----------------------------------------------------------------------------- |
|
56 // CBavpPlugin::ConstructL |
|
57 // Symbian 2nd phase constructor can leave. |
|
58 // ----------------------------------------------------------------------------- |
|
59 void CBavpPlugin::ConstructL() |
|
60 { |
|
61 TFileName fileName; |
|
62 TParse parse; |
|
63 |
|
64 Dll::FileName (fileName); |
|
65 parse.Set(KBrowserAVPluginRscFile, &fileName, NULL); |
|
66 fileName = parse.FullName(); |
|
67 BaflUtils::NearestLanguageFile(CCoeEnv::Static()->FsSession(), fileName); |
|
68 if ( !BaflUtils::FileExists( CCoeEnv::Static()->FsSession(), fileName ) ) |
|
69 { |
|
70 // Use the Z drive one |
|
71 parse.Set( KBrowserAVPluginRscFileZ, &KDC_RESOURCE_FILES_DIR, NULL ); |
|
72 fileName = parse.FullName(); |
|
73 BaflUtils::NearestLanguageFile( CCoeEnv::Static()->FsSession(),fileName ); |
|
74 } |
|
75 iResourceOffset = CCoeEnv::Static()->AddResourceFileL( fileName ); |
|
76 iDrmHelper = CDRMHelper::NewL( *CCoeEnv::Static() ); |
|
77 } |
|
78 |
|
79 // ----------------------------------------------------------------------------- |
|
80 // CBavpPlugin::NewL |
|
81 // Two-phased constructor. |
|
82 // ----------------------------------------------------------------------------- |
|
83 CBavpPlugin* CBavpPlugin::NewL() |
|
84 { |
|
85 Log( EFalse, _L("CBavpPlugin::NewL") ); |
|
86 |
|
87 CBavpPlugin* self = new (ELeave) CBavpPlugin; |
|
88 CleanupStack::PushL( self ); |
|
89 self->ConstructL(); |
|
90 CleanupStack::Pop( self ); |
|
91 |
|
92 return self; |
|
93 } |
|
94 |
|
95 // ----------------------------------------------------------------------------- |
|
96 // CBavpPlugin::Destructor |
|
97 // ----------------------------------------------------------------------------- |
|
98 CBavpPlugin::~CBavpPlugin() |
|
99 { |
|
100 Log( EFalse, _L("CBavpPlugin::~CBavpPlugin") ); |
|
101 |
|
102 delete iBavpController; |
|
103 |
|
104 delete iFileName; |
|
105 |
|
106 delete iBavpView; |
|
107 |
|
108 delete iDrmHelper; |
|
109 |
|
110 if ( iMimeType ) |
|
111 { |
|
112 delete iMimeType; |
|
113 } |
|
114 |
|
115 |
|
116 if ( iResourceOffset ) |
|
117 { |
|
118 CCoeEnv::Static()->DeleteResourceFile( iResourceOffset ); |
|
119 } |
|
120 if ( iNPObject ) |
|
121 { |
|
122 if (iNPObject->plugin == this) |
|
123 iNPObject->plugin = 0; |
|
124 NPN_ReleaseObject((struct NPObject*)(iNPObject)); |
|
125 } |
|
126 } |
|
127 |
|
128 // ----------------------------------------------------------------------------- |
|
129 // CBavpPlugin::SetWindowL |
|
130 // Handles the creation of the window for the video file. |
|
131 // Called by Browser for window creation. |
|
132 // aPluginAdapter allows callback to Browser. aRect is window size. |
|
133 // ----------------------------------------------------------------------------- |
|
134 void CBavpPlugin::SetWindowL( MPluginAdapter *aPluginAdapter, |
|
135 NPWindow* aWindow, NPP aInstance ) |
|
136 { |
|
137 Log( EFalse, _L("CBavpPlugin::SetWindowL") ); |
|
138 |
|
139 // Set our PluginAdapter |
|
140 iPluginAdapter = aPluginAdapter; |
|
141 iNPP = aInstance; |
|
142 |
|
143 // Check if error occurs last time for setWindowL |
|
144 if ( iError ) |
|
145 { |
|
146 // Stop browser calling NotifyL |
|
147 iPluginAdapter->SetPluginNotifier( NULL ); |
|
148 |
|
149 // Error detected on OpenAndPlayFile |
|
150 return; |
|
151 } |
|
152 |
|
153 if ( !iBavpView ) |
|
154 { |
|
155 iBavpView = CBavpView::NewL( (CCoeControl*)iPluginAdapter->GetParentControl(), TRect(0, 0, 0, 0), this); |
|
156 |
|
157 // Note: The pluginAdapter returns NULL |
|
158 iBavpView->SetObserver( aPluginAdapter->GetParentControlObserver() ); |
|
159 |
|
160 // Register for Browser Notifications |
|
161 iPluginAdapter->SetPluginNotifier( (MPluginNotifier *)this ); |
|
162 |
|
163 // Add option menu handler |
|
164 iPluginAdapter->SetOptionMenuHandler( (MOptionMenuHandler *)iBavpView ); |
|
165 |
|
166 // Notify Browser that plugin has been constructed |
|
167 iPluginAdapter->PluginConstructedL( iBavpView ); |
|
168 } |
|
169 else |
|
170 { |
|
171 // Only setRect() is enough, since it calls SizeChanged() and |
|
172 // inside it refreshes the rect's coordinate |
|
173 iBavpView->SetRect( aWindow ); |
|
174 |
|
175 // If we have a Rtsp scheme, we need to play it (aka start the |
|
176 // BavpControllerVideo). We only do this once |
|
177 if ( iRtspUrl ) |
|
178 { |
|
179 OpenAndPlayUrlL( *iRtspUrl ); |
|
180 delete iRtspUrl; |
|
181 iRtspUrl = NULL; |
|
182 } |
|
183 } |
|
184 } |
|
185 |
|
186 // ----------------------------------------------------------------------------- |
|
187 // CBavpPlugin::OpenAndPlayFileL |
|
188 // Called by Browser when ready for file to be played |
|
189 // ----------------------------------------------------------------------------- |
|
190 void CBavpPlugin::OpenAndPlayFileL( const TDesC& aFilename, const HBufC* originalFileName ) |
|
191 { |
|
192 iPlayFromFile = ETrue; |
|
193 Log( EFalse, _L("CBavpPlugin::OpenAndPlayFileL"), (TInt)this ); |
|
194 |
|
195 if ( !iBavpView ) |
|
196 { |
|
197 // The view is not set yet. |
|
198 // Re-invoke the OpenAndPlayFile after the window has been initialized |
|
199 delete iFileName; |
|
200 iFileName = NULL; |
|
201 iFileName = aFilename.AllocL(); |
|
202 } |
|
203 else |
|
204 { |
|
205 if ( iBavpController ) |
|
206 { |
|
207 // Will stop current audio or video player |
|
208 delete iBavpController; |
|
209 iBavpController = NULL; |
|
210 |
|
211 // Set to null, otherwise, plugin will crash when it switches file |
|
212 iBavpView->SetBavpController( NULL ); |
|
213 } |
|
214 |
|
215 // Determine if file is audio or video, so we can start up an audio |
|
216 // or video controller |
|
217 CBavpMediaRecognizer* mediaRecognizer = CBavpMediaRecognizer::NewL(); |
|
218 CleanupStack::PushL( mediaRecognizer ); |
|
219 TBavpMediaType mediaType = mediaRecognizer->IdentifyMediaTypeL( aFilename ); |
|
220 CleanupStack::PopAndDestroy(); // mediaRecognizer |
|
221 |
|
222 // Do we have audio content, let the audio controller handle it |
|
223 if ( mediaType == ELocalAudioFile || mediaType == ELocalAudioPlaylist ) |
|
224 { |
|
225 iBavpController = CBavpControllerAudio::NewL( iBavpView, |
|
226 iAccessPtId, |
|
227 mediaType, |
|
228 aFilename ); |
|
229 } |
|
230 else |
|
231 { |
|
232 // We got other content, let the video controller handle it. |
|
233 iBavpController = CBavpControllerVideo::NewL( iBavpView, |
|
234 iAccessPtId, |
|
235 mediaType, |
|
236 aFilename ); |
|
237 } |
|
238 |
|
239 // Set the volume and loop from the attribute values |
|
240 iBavpController->SetVolumeFromAttribute( iVolume ); |
|
241 iBavpController->SetLoopFromAttribute( iLoop, iInfiniteFlag ); |
|
242 |
|
243 // Set the original file name & mime type |
|
244 iBavpController->SetOriginalFileName(originalFileName); |
|
245 iBavpController->SetMimeType(iMimeType); |
|
246 |
|
247 iBavpView->SetBavpController( iBavpController ); |
|
248 |
|
249 TRAPD( err, iBavpController->PlayAudioVideoL() ); |
|
250 if ( err ) |
|
251 { |
|
252 Log( EFalse, _L("CBavpPlugin::OpenAndPlayFileL ERROR from PlayAudioVideoL") ); |
|
253 iBavpController->iCurrentState = EBavpBadContent; |
|
254 iBavpView->UpdateView(); |
|
255 User::Leave( err ); |
|
256 } |
|
257 } |
|
258 } |
|
259 |
|
260 // ----------------------------------------------------------------------------- |
|
261 // CBavpPlugin::OpenAndPlayUrlL |
|
262 // Called by Browser when ready for url to be played |
|
263 // ----------------------------------------------------------------------------- |
|
264 void CBavpPlugin::OpenAndPlayUrlL( const TDesC& aUrl ) |
|
265 { |
|
266 iPlayFromFile = EFalse; |
|
267 Log( EFalse, _L("CBavpPlugin::OpenAndPlayUrlL"), (TInt)this ); |
|
268 |
|
269 if ( iBavpController ) |
|
270 { |
|
271 // Will stop current audio or video player |
|
272 delete iBavpController; |
|
273 iBavpController = NULL; |
|
274 |
|
275 // Set to null, otherwise, plugin will crash when it switches file |
|
276 iBavpView->SetBavpController( NULL ); |
|
277 } |
|
278 |
|
279 iBavpController = CBavpControllerVideo::NewL( iBavpView, |
|
280 iAccessPtId, |
|
281 EUrl, |
|
282 aUrl ); |
|
283 |
|
284 // iRtspUrl is used as a flag in SetWindow, which is re-entrant, so delete |
|
285 // once we got a controller for it |
|
286 delete iRtspUrl; |
|
287 iRtspUrl = NULL; |
|
288 |
|
289 // Set the volume and loop from the attribute values |
|
290 iBavpController->SetVolumeFromAttribute( iVolume ); |
|
291 iBavpController->SetLoopFromAttribute( iLoop, iInfiniteFlag ); |
|
292 |
|
293 iBavpView->SetBavpController( iBavpController ); |
|
294 |
|
295 iBavpController->PlayAudioVideoL(); |
|
296 } |
|
297 |
|
298 // ----------------------------------------------------------------------------- |
|
299 // CBavpPlugin::SetAccessPtId |
|
300 // Sets access pt id to be used |
|
301 // ----------------------------------------------------------------------------- |
|
302 void CBavpPlugin::SetAccessPtId( TUint aAccessPtId ) |
|
303 { |
|
304 iAccessPtId = aAccessPtId; |
|
305 } |
|
306 |
|
307 // ----------------------------------------------------------------------------- |
|
308 // CBavpPlugin::SetVolumeAndLoop |
|
309 // Called to set the volume and loop value that we get from the webpage source |
|
310 // to be able to use it later |
|
311 // ----------------------------------------------------------------------------- |
|
312 void CBavpPlugin::SetVolumeAndLoop( TInt aVolume, TInt aLoop, TInt aInfiniteFlag ) |
|
313 { |
|
314 // Save volume attribute value, pass to controller after it initializes |
|
315 iVolume = aVolume; |
|
316 |
|
317 // Save loop attribute values, pass to controller after it initializes |
|
318 iLoop = aLoop; |
|
319 iInfiniteFlag = aInfiniteFlag; |
|
320 } |
|
321 |
|
322 // ----------------------------------------------------------------------------- |
|
323 // CBavpPlugin::SetVolumeAndLoop |
|
324 // Called to set the volume and loop value that we get from the webpage source |
|
325 // to be able to use it later |
|
326 // ----------------------------------------------------------------------------- |
|
327 void CBavpPlugin::SetRtspUriL( const TDesC& aRtspUri ) |
|
328 { |
|
329 iRtspUrl = aRtspUri.AllocL(); |
|
330 } |
|
331 |
|
332 // ----------------------------------------------------------------------------- |
|
333 // CBavpPlugin::NotifyL |
|
334 // MPluginNotifier callback, Browser calls this to inform Plugin of some event. |
|
335 // The biggest use is when the Browser goes in-focus or out-focus. Out-foucus |
|
336 // can happen when other component takes top of CCoeControl stack, such as the |
|
337 // Option Menu, another application, Screen saver, ... |
|
338 // ----------------------------------------------------------------------------- |
|
339 TInt CBavpPlugin::NotifyL( TNotificationType aCallType, void* aParam ) |
|
340 { |
|
341 if(iBavpController) |
|
342 { |
|
343 //if player is paused due to focus change or Visual history back and manually pressed Play, then we need |
|
344 //to clear the pause state. |
|
345 if(EBavpPlaying == iBavpController->State() && iPauseState) |
|
346 { |
|
347 iPauseState = EFalse; |
|
348 } |
|
349 } |
|
350 |
|
351 switch ( aCallType ) |
|
352 { |
|
353 case EApplicationFocusChanged: |
|
354 // The browser has gone in-focus (foreground), or out-focus |
|
355 // (background), i.e. the browser is not on top of CCoeControl stack, |
|
356 // so inform this plugin if it is in-focus or out-focus |
|
357 if ( iBavpController ) |
|
358 { |
|
359 // If Browser out-focus, we send this plugin aParam=EFalse. |
|
360 // If Browser in-focus, we send this plugin aParam=ETrue, if |
|
361 // the plugin is (was) in-focus or activated. |
|
362 iBavpController->HandleBrowserNotification( TBool(aParam) ); |
|
363 if(!aParam) //app background |
|
364 { |
|
365 iIsForeGround = EFalse; |
|
366 //Pause for Live stream will Leave with KErrNotSupported from Helix player |
|
367 //and intern session will be closed. For Live stream Pause should not be done |
|
368 if(EBavpPlaying == iBavpController->State() && ( !iBavpController->IsClipLive()) ) |
|
369 { |
|
370 iPauseState = ETrue; |
|
371 iPauseInBackground = ETrue; |
|
372 iBavpController->PauseL(); |
|
373 } |
|
374 } |
|
375 else //app foreground |
|
376 { |
|
377 iIsForeGround = ETrue; |
|
378 if(EBavpPaused == iBavpController->State() && iPauseInBackground) |
|
379 { |
|
380 iPauseState = EFalse; |
|
381 iPauseInBackground = EFalse; |
|
382 iBavpController->PlayL(); |
|
383 } |
|
384 |
|
385 } |
|
386 |
|
387 } |
|
388 break; |
|
389 |
|
390 case EPluginPause : |
|
391 if( !aParam ) |
|
392 { |
|
393 if(iBavpController && iPauseState && (iBavpController->State() == EBavpPaused) && (iIsForeGround)) |
|
394 { |
|
395 iPauseState = EFalse; |
|
396 iBavpController->PlayL(); |
|
397 } |
|
398 } |
|
399 |
|
400 break; |
|
401 case EPluginInvisible : |
|
402 if( !aParam ) |
|
403 { |
|
404 if ( iBavpController && (!iPauseState) ) //plugin background |
|
405 { |
|
406 //Pause for Live stream will Leave with KErrNotSupported from Helix player |
|
407 //and intern session will be closed. For Live stream Pause should not be done |
|
408 if( (EBavpPlaying == iBavpController->State() ) && ( !iBavpController->IsClipLive()) ) |
|
409 { |
|
410 iPauseState = ETrue; |
|
411 iBavpController->PauseL(); |
|
412 } |
|
413 } |
|
414 } |
|
415 else if(iBavpController && iPauseState && (iBavpController->State() == EBavpPaused) && (iIsForeGround)) |
|
416 { |
|
417 iPauseState = EFalse; |
|
418 iBavpController->PlayL(); |
|
419 } |
|
420 break; |
|
421 case EAccesPointChanged : |
|
422 if (iBavpController && !iPlayFromFile) { |
|
423 bool state = (iBavpController->State() == EBavpPaused || |
|
424 iBavpController->State() == EBavpPlaying || |
|
425 iBavpController->State() == EBavpBuffering || |
|
426 iBavpController->State() == EBavpFastForwarding || |
|
427 iBavpController->State() == EBavpRewinding ); |
|
428 iBavpController->Stop(); |
|
429 if (state) |
|
430 iBavpController->PlayL(); |
|
431 } |
|
432 break; |
|
433 |
|
434 default: |
|
435 // Not implemented |
|
436 break; |
|
437 |
|
438 }; // end of switch |
|
439 |
|
440 return NPERR_NO_ERROR; |
|
441 } |
|
442 |
|
443 // ----------------------------------------------------------------------------- |
|
444 // CBavpPlugin::SetMimeType |
|
445 // Sets the mime name. Used for scripting functionality |
|
446 // ----------------------------------------------------------------------------- |
|
447 void CBavpPlugin::SetMimeType( NPMIMEType type ) |
|
448 { |
|
449 iMimeType = type.Alloc(); |
|
450 } |
|
451 |
|
452 // ----------------------------------------------------------------------------- |
|
453 // CBavpPlugin::HandleGesture |
|
454 // ----------------------------------------------------------------------------- |
|
455 TBool CBavpPlugin::HandleGesture(void* aEvent) |
|
456 { |
|
457 TBool ret = EFalse; |
|
458 TGestureEvent *gesture = static_cast<TGestureEvent*>(aEvent); |
|
459 // Fix crash when iBavpController is null for bug EGUY-7TYHDC |
|
460 if (iBavpController) { |
|
461 ret = iBavpController->HandleGesture(gesture); |
|
462 } |
|
463 |
|
464 return ret; |
|
465 } |
|
466 |
|
467 // ----------------------------------------------------------------------------- |
|
468 // CBavpPlugin::getNPNFuncs |
|
469 // ----------------------------------------------------------------------------- |
|
470 NPNetscapeFuncs* CBavpPlugin::getNPNFuncs() |
|
471 { |
|
472 CBavpPluginEcomMain* npm = (CBavpPluginEcomMain*)Dll::Tls(); |
|
473 return npm ? npm->Funcs() : NULL; |
|
474 } |
|
475 |
|
476 |
|
477 // End of File |
|