browserplugins/browseraudiovideoplugin/src/BavpNPObject.cpp
branchRCL_3
changeset 48 8e6fa1719340
parent 0 84ad3b177aa3
equal deleted inserted replaced
47:6385c4c93049 48:8e6fa1719340
       
     1 /*
       
     2 * Copyright (c) 2002-2005 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:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include "BavpNPObject.h"
       
    22 #include "BavpLogger.h"
       
    23 
       
    24 #include <badesca.h>
       
    25 #include <stdlib.h>
       
    26 #include <string.h>
       
    27 #include <npscript.h>
       
    28 
       
    29 #include  "BavpPlugin.h"
       
    30 #include  "BavpController.h"
       
    31 #include  "BavpControllerVideo.h"
       
    32 #include  "BavpControllerAudio.h"
       
    33 
       
    34 
       
    35 const int NUM_METHOD_IDENTIFIERS = 5;
       
    36 const int ID_PLAY = 0;
       
    37 const int ID_STOP = 1;
       
    38 const int ID_PAUSE = 2;
       
    39 const int ID_FASTFORWARD = 3;
       
    40 const int ID_REWIND = 4;
       
    41 static NPIdentifier bavpMethodIdentifiers[NUM_METHOD_IDENTIFIERS];
       
    42 static const NPUTF8 *bavpIdentifierNames[NUM_METHOD_IDENTIFIERS] = {
       
    43     "play",
       
    44     "stop",
       
    45     "pause",
       
    46     "fastforward",
       
    47     "rewind",
       
    48 };
       
    49 
       
    50 const int NUM_PROPERTY_IDENTIFIERS = 10;
       
    51 const int ID_VOLUME = 0;
       
    52 const int ID_POSITION = 1;
       
    53 const int ID_DURATION = 2;
       
    54 const int ID_STATE_CHANGED_CALLBACK = 3;
       
    55 const int ID_STATE = 4;
       
    56 const int ID_ISVIDEOCLIP = 5;
       
    57 const int ID_ISSEEKABLE = 6;
       
    58 const int ID_CLIPNAME = 7;
       
    59 const int ID_FULLSCREENMODE = 8;
       
    60 const int ID_MIMETYPE = 9;
       
    61 static NPIdentifier bavpPropertyIdentifiers[NUM_PROPERTY_IDENTIFIERS];
       
    62 static const NPUTF8 *bavpPropertyIdentifierNames[NUM_PROPERTY_IDENTIFIERS] = {
       
    63     "volume",
       
    64     "position",
       
    65     "duration",
       
    66     "statechangedcallback",
       
    67     "state",
       
    68     "isvideoclip",
       
    69     "isseekable",
       
    70     "clipname",
       
    71     "fullscreenmode",
       
    72     "mimetype",
       
    73 };
       
    74     
       
    75 static bool _initializedIdentifiers = false;    
       
    76 static void initializeIdentifiers()
       
    77 {
       
    78     if (!_initializedIdentifiers) {
       
    79         _initializedIdentifiers = true;
       
    80         NPN_GetStringIdentifiers (bavpPropertyIdentifierNames, NUM_PROPERTY_IDENTIFIERS, bavpPropertyIdentifiers);
       
    81         NPN_GetStringIdentifiers (bavpIdentifierNames, NUM_METHOD_IDENTIFIERS, bavpMethodIdentifiers);
       
    82     }
       
    83 };
       
    84 
       
    85 
       
    86 _LIT8(KNone,"None");
       
    87 _LIT8(KBuffering,"Buffering");
       
    88 _LIT8(KPlaying,"Playing");
       
    89 _LIT8(KPlayComplete,"Playcomplete");
       
    90 _LIT8(KStopped,"Stopped");
       
    91 _LIT8(KPaused,"Paused");
       
    92 _LIT8(KBadContent,"Badcontent");
       
    93 _LIT8(KFastForwarding,"Fastforwarding");
       
    94 _LIT8(KFFComplete,"Fastforward complete");
       
    95 _LIT8(KRewinding,"Rewinding");
       
    96 _LIT8(KRewindComplete,"Rewinding complete");
       
    97 _LIT8(KInvalidState,"Invalid State");
       
    98 
       
    99 
       
   100 static const TPtrC8 getState(int state)
       
   101 {
       
   102     TPtrC8 ret;
       
   103 
       
   104     switch (state)
       
   105     {
       
   106         case EBavpNone:
       
   107             ret.Set(KNone);
       
   108             break;
       
   109             
       
   110         case EBavpBuffering:
       
   111             ret.Set(KBuffering);
       
   112             break;
       
   113             
       
   114         case EBavpPlaying:
       
   115             ret.Set(KPlaying);
       
   116             break;
       
   117             
       
   118         case EBavpPlayComplete:
       
   119             ret.Set(KPlayComplete);
       
   120             break;
       
   121             
       
   122         case EBavpStopped:
       
   123             ret.Set(KStopped);
       
   124             break;
       
   125             
       
   126         case EBavpPaused:
       
   127             ret.Set(KPaused);
       
   128             break;
       
   129             
       
   130         case EBavpBadContent:
       
   131             ret.Set(KBadContent);
       
   132             break;
       
   133             
       
   134         case EBavpFastForwarding:
       
   135             ret.Set(KFastForwarding);
       
   136             break;
       
   137             
       
   138         case EBavpFastForwardComplete:
       
   139             ret.Set(KFFComplete);
       
   140             break;
       
   141             
       
   142         case EBavpRewinding:
       
   143             ret.Set(KRewinding);
       
   144             break;
       
   145             
       
   146         case EBavpRewindComplete:
       
   147             ret.Set(KRewindComplete);
       
   148             break;
       
   149             
       
   150         default:
       
   151             ret.Set(KInvalidState);
       
   152             break;
       
   153     }
       
   154     return ret;
       
   155 }
       
   156 
       
   157 static void reportVolumeResults(int vol,CBavpController *ctlr)
       
   158 {
       
   159     Log(ETrue,_L("SetProperty: Volume"));
       
   160 
       
   161     TInt setvol = ctlr->GetPlayerVolume();
       
   162     Log(ETrue,_L("Requested volume: "), vol);
       
   163     Log(ETrue,_L("Volume set to: "),setvol);
       
   164 
       
   165     
       
   166     if ( setvol == vol || setvol == KCRVolumeMax || setvol == KCRVolume0 )
       
   167     {
       
   168         Log(ETrue,_L("Result: Passed"));
       
   169     }
       
   170     else
       
   171     {
       
   172         Log(ETrue,_L("Result: Failed"));
       
   173     }
       
   174 }
       
   175 
       
   176 static void reportPositionResultsL(int pos, CBavpController *ctlr)
       
   177 {
       
   178     Log(ETrue,_L("SetProperty: Position"));
       
   179     
       
   180     if ( !(ctlr->IsClipSeekable()) && !(ctlr->IsClipLocalMedia()) )
       
   181     {
       
   182         Log(ETrue,_L("Cannot set position for non-seekable and non-local media content"));
       
   183         return;
       
   184     }
       
   185 
       
   186     TTimeIntervalMicroSeconds ms = ctlr->getPositionL();
       
   187     TTimeIntervalMicroSeconds durationms = ctlr->Duration();
       
   188   	
       
   189     int setpos = (int)ms.Int64();
       
   190     int duration = (int)durationms.Int64();
       
   191     
       
   192     Log(ETrue,_L("Requested position: "), pos);
       
   193     Log(ETrue,_L("Position set to: "),setpos);
       
   194     
       
   195     if ( setpos == pos || setpos == duration || setpos == 0)
       
   196     {	
       
   197         Log(ETrue,_L("Result: Passed"));
       
   198     }
       
   199     else
       
   200     {
       
   201         Log(ETrue,_L("Result: Failed"));
       
   202     }	
       
   203 }
       
   204 
       
   205 static void reportPlayResultsL(int initState, CBavpController *ctlr)
       
   206 {
       
   207     if ( ctlr->IsClipVideo())
       
   208     {
       
   209         TPtrC8 expectedState = getState(EBavpPlaying);
       
   210         TPtrC8 expectedState2 = getState(EBavpBuffering);
       
   211         TPtrC8 actualState = getState(ctlr->State());
       
   212     	
       
   213         if ( initState == EBavpStopped ||
       
   214              initState == EBavpPlayComplete ||
       
   215              initState == EBavpRewindComplete ||
       
   216              initState == EBavpFastForwardComplete ||
       
   217              initState == EBavpBadContent)
       
   218         {
       
   219             TTimeIntervalMicroSeconds ms = ctlr->getPositionL();
       
   220             int actualpos = (int)ms.Int64();
       
   221 
       
   222             Log(ETrue,_L("Expected Position: "), 0);
       
   223             Log(ETrue,_L("Actual Position: "),actualpos);
       
   224         	
       
   225             if ( actualpos != 0)
       
   226             {
       
   227                 Log(ETrue,_L("Result: Position test failed"));
       
   228             }
       
   229             else
       
   230             {
       
   231                 Log(ETrue,_L("Result:Position test passed"));
       
   232             }
       
   233         }
       
   234     	
       
   235         if ( ctlr->IsClipOnDemand() && initState == EBavpStopped )
       
   236         {
       
   237             Log(ETrue,_L8("Expected State: "), expectedState2);
       
   238             Log(ETrue,_L8("Actual State: "), actualState);
       
   239         }
       
   240         else
       
   241         {
       
   242             Log(ETrue,_L8("Expected State: "), expectedState);
       
   243             Log(ETrue,_L8("Actual State: "), actualState);	
       
   244         }
       
   245     	
       
   246         if ( actualState.Compare(expectedState) != 0 && actualState.Compare(expectedState2) != 0)
       
   247         {
       
   248             Log(ETrue,_L("Result: State test failed"));
       
   249         }
       
   250         else
       
   251         {
       
   252             Log(ETrue,_L("Result: State test passed"));
       
   253         }
       
   254     }
       
   255     else
       
   256     {
       
   257         TPtrC8 expectedState = getState(EBavpPlaying);
       
   258         TPtrC8 actualState = getState(ctlr->State());
       
   259     	
       
   260         Log(ETrue,_L8("Expected State: "), expectedState);
       
   261         Log(ETrue,_L8("Actual State: "), actualState);
       
   262     	
       
   263         if ( expectedState.Compare(actualState) != 0)
       
   264         {
       
   265             Log(ETrue,_L("Result: Failed"));
       
   266         }
       
   267         else
       
   268         {
       
   269             Log(ETrue,_L("Result: Passed"));
       
   270         }
       
   271     }
       
   272 }
       
   273 
       
   274 static void reportStopResultsL(CBavpController *ctlr)
       
   275 {
       
   276     TPtrC8 expectedState = getState(EBavpStopped);
       
   277     TPtrC8 actualState = getState(ctlr->State());
       
   278     TTimeIntervalMicroSeconds ms = ctlr->getPositionL();
       
   279     int position = (int)ms.Int64();
       
   280 
       
   281     Log(ETrue,_L8("Expected State: "), expectedState);
       
   282     Log(ETrue,_L8("Actual State: "), actualState);
       
   283     Log(ETrue,_L("Current Position: "), position);
       
   284 	
       
   285     if ( (position != 0) || (expectedState.Compare(actualState) != 0) )
       
   286     {
       
   287         Log(ETrue,_L("Result: Failed"));
       
   288     }
       
   289     else
       
   290     {
       
   291         Log(ETrue,_L("Result: Passed"));
       
   292     }
       
   293 }
       
   294 
       
   295 static void reportRewindResults(CBavpController *ctlr)
       
   296 {
       
   297     if ( ctlr->IsClipVideo() )
       
   298     {
       
   299         if ( !(ctlr->IsClipSeekable()) && !(ctlr->IsClipLocalMedia()) )
       
   300         {
       
   301             Log(ETrue,_L("Result: Rewind is not applicable to non-seekable and non-local media content"));
       
   302         }
       
   303         else
       
   304         {
       
   305             TPtrC8 expectedState = getState(EBavpRewinding);
       
   306             TPtrC8 expectedState2 = getState(EBavpRewindComplete);
       
   307             TPtrC8 actualState = getState(ctlr->State());
       
   308 
       
   309             Log(ETrue,_L8("Expected State: "), expectedState);
       
   310             Log(ETrue,_L8("Actual State: "), actualState);
       
   311 
       
   312             if ( (expectedState.Compare(actualState) != 0) && (expectedState2.Compare(actualState) != 0) )
       
   313             {
       
   314                 Log(ETrue,_L("Result: Failed"));
       
   315             }
       
   316             else
       
   317             {
       
   318                 Log(ETrue,_L("Result: Passed"));
       
   319             }
       
   320         }
       
   321     }
       
   322     else
       
   323     {
       
   324         Log(ETrue,_L("Result: Rewind is not applicable to Audio"));
       
   325     }
       
   326 	
       
   327 }
       
   328 
       
   329 static void reportFFResults(CBavpController *ctlr)
       
   330 {
       
   331     if ( ctlr->IsClipVideo() )
       
   332     {
       
   333         if ( !(ctlr->IsClipSeekable()) && !(ctlr->IsClipLocalMedia()) )
       
   334         {
       
   335             Log(ETrue,_L("Result: Fastforward is not applicable to non-seekable and non-local media content"));
       
   336         }
       
   337         else
       
   338         {
       
   339             TPtrC8 expectedState = getState(EBavpFastForwarding);
       
   340             TPtrC8 expectedState2 = getState(EBavpFastForwardComplete);
       
   341             TPtrC8 actualState = getState(ctlr->State());
       
   342 
       
   343             Log(ETrue,_L8("Expected State: "), expectedState);
       
   344             Log(ETrue,_L8("Actual State: "), actualState);
       
   345 
       
   346             if ( (expectedState.Compare(actualState) != 0) && (expectedState2.Compare(actualState) != 0) )
       
   347             {
       
   348                 Log(ETrue,_L("Result: Failed"));
       
   349             }
       
   350             else
       
   351             {
       
   352                 Log(ETrue,_L("Result: Passed"));
       
   353             }
       
   354         }
       
   355     }
       
   356     else
       
   357     {
       
   358         Log(ETrue,_L("Result: Fastforward is not applicable to Audio"));
       
   359     }
       
   360 	
       
   361 }
       
   362 
       
   363 static void reportPauseResultsL(CBavpController *ctlr)
       
   364 {
       
   365     TBool seekablevideo = (ctlr->IsClipSeekable() && ctlr->IsClipVideo());
       
   366     TBool seekableaudio = (ctlr->IsClipSeekable() && !ctlr->IsClipVideo() 
       
   367             && (ctlr->State() == EBavpPaused || ctlr->State() == EBavpPlaying));
       
   368 
       
   369     if ( seekablevideo || seekableaudio )
       
   370     {
       
   371         TPtrC8 expectedState = getState(EBavpPaused);
       
   372         TPtrC8 actualState = getState(ctlr->State());
       
   373 
       
   374         Log(ETrue,_L8("Expected State: "), expectedState);
       
   375         Log(ETrue,_L8("Actual State: "), actualState);
       
   376 
       
   377         if ( (expectedState.Compare(actualState) != 0) )
       
   378         {
       
   379             Log(ETrue,_L("Result: Failed"));
       
   380         }
       
   381         else
       
   382         {
       
   383             Log(ETrue,_L("Result: Passed"));
       
   384         }
       
   385     	
       
   386     }
       
   387     else
       
   388     {
       
   389         reportStopResultsL(ctlr);
       
   390     }
       
   391 }
       
   392     
       
   393 static void BavpDesToNpvariant(TPtrC& string, NPVariant*& variant)
       
   394 {
       
   395     char* newString = NULL;
       
   396     if (string.Length()) {
       
   397         newString = new char[string.Length()];
       
   398     }
       
   399     if (newString) {
       
   400         TPtr8 newStringPtr((unsigned char*)newString, 0, string.Length());
       
   401         newStringPtr.Copy(string);
       
   402         STRINGN_TO_NPVARIANT(newString, string.Length(), *variant);
       
   403     }
       
   404 }
       
   405 
       
   406 static void BavpDesToNpvariant(TPtrC8& string, NPVariant*& variant)
       
   407 {
       
   408     char* newString = NULL;
       
   409     if (string.Length()) {
       
   410         newString = new char[string.Length()];
       
   411     }
       
   412     if (newString) {
       
   413         Mem::Copy(newString, string.Ptr(), string.Length());
       
   414         STRINGN_TO_NPVARIANT(newString, string.Length(), *variant);
       
   415     }
       
   416 }
       
   417     
       
   418 NPObject *BavpAllocate ()
       
   419 {
       
   420     BavpNPObject *newInstance = (BavpNPObject *)User::AllocZ (sizeof(BavpNPObject));   
       
   421     
       
   422     return (NPObject *)newInstance;
       
   423 }
       
   424 
       
   425 void BavpInvalidate ()
       
   426 {
       
   427     // Make sure we've released any remainging references to JavaScript
       
   428     // objects.
       
   429 }
       
   430 
       
   431 void BavpDeallocate (BavpNPObject *obj) 
       
   432 {
       
   433     if (obj->stateChangedCallback)
       
   434         NPN_ReleaseObject((struct NPObject*)obj->stateChangedCallback);  
       
   435     User::Free ((void *)obj);
       
   436 }    
       
   437 
       
   438 bool BavpHasMethod(BavpNPObject */*obj*/, NPIdentifier name)
       
   439 {
       
   440     int i;
       
   441     for (i = 0; i < NUM_METHOD_IDENTIFIERS; i++) {
       
   442         if (name == bavpMethodIdentifiers[i]){
       
   443             return true;
       
   444         }
       
   445     }
       
   446     return false;
       
   447 }
       
   448 
       
   449 
       
   450 bool BavpInvokeL(BavpNPObject *obj, NPIdentifier name, const NPVariant */* args */, uint32_t /* argCount */, NPVariant *result)
       
   451 {
       
   452     if (!obj->plugin) {
       
   453         NULL_TO_NPVARIANT(*result);
       
   454         return true;    
       
   455     }    
       
   456 
       
   457     CBavpController *ctlr = obj->plugin->Controller();
       
   458     
       
   459     if (!ctlr)
       
   460     {
       
   461         NULL_TO_NPVARIANT(*result);
       
   462         return true; 
       
   463     }
       
   464     
       
   465     int initState = ctlr->State();
       
   466     Log( ETrue, _L("\n"));
       
   467     Log( ETrue, _L8("Initial state:"), getState(initState));
       
   468 
       
   469     if (name == bavpMethodIdentifiers[ID_PLAY]) 
       
   470     {
       
   471         Log( ETrue, _L("Method Invoked: Play"));
       
   472         if ( ctlr->State() != EBavpPlaying )
       
   473         {
       
   474             ctlr->PlayL();
       
   475         }
       
   476         VOID_TO_NPVARIANT(*result);
       
   477         reportPlayResultsL(initState,ctlr);
       
   478     }
       
   479     else if (name == bavpMethodIdentifiers[ID_STOP]) 
       
   480     {
       
   481         Log( ETrue, _L("Method Invoked: Stop"));
       
   482         if ( ctlr->State() != EBavpStopped )
       
   483         {
       
   484             ctlr->Stop();
       
   485         }
       
   486         VOID_TO_NPVARIANT(*result);
       
   487         reportStopResultsL(ctlr);
       
   488     }
       
   489     else if (name == bavpMethodIdentifiers[ID_PAUSE]) 
       
   490     {
       
   491         Log( ETrue, _L("Method Invoked: Pause"));
       
   492         if ( ctlr->State() != EBavpPaused )
       
   493         {
       
   494             ctlr->PauseL();
       
   495         }
       
   496         VOID_TO_NPVARIANT(*result);
       
   497         reportPauseResultsL(ctlr);
       
   498     }  
       
   499     else if (name == bavpMethodIdentifiers[ID_FASTFORWARD]) 
       
   500     {
       
   501         Log( ETrue, _L("Method Invoked: FastForward"));
       
   502         if ( ctlr->State() == EBavpRewinding )
       
   503         {
       
   504             ctlr->PauseL();
       
   505         }
       
   506 
       
   507         if ( ctlr->State() != EBavpFastForwarding )
       
   508         {
       
   509             ctlr->FastForwardL();
       
   510         }
       
   511         VOID_TO_NPVARIANT(*result);
       
   512         reportFFResults(ctlr);
       
   513     }  
       
   514     else if (name == bavpMethodIdentifiers[ID_REWIND]) 
       
   515     {
       
   516         Log( ETrue, _L("Method Invoked: Rewind"));
       
   517         if ( ctlr->State() == EBavpFastForwarding )
       
   518         {
       
   519             ctlr->PauseL();
       
   520         }
       
   521 
       
   522         if ( ctlr->State() != EBavpRewinding )
       
   523         {
       
   524             ctlr->RewindL();
       
   525         }
       
   526         VOID_TO_NPVARIANT(*result);
       
   527         reportRewindResults(ctlr);
       
   528     }
       
   529     else
       
   530     {
       
   531         Log( ETrue, _L("Unknown method invoked"));
       
   532         return false;
       
   533     }  
       
   534        
       
   535     return true;
       
   536 }
       
   537     
       
   538 bool BavpHasProperty(BavpNPObject */*obj*/, NPIdentifier name)
       
   539 {
       
   540     int i;
       
   541     for (i = 0; i < NUM_PROPERTY_IDENTIFIERS; i++) 
       
   542     {
       
   543         if (name == bavpPropertyIdentifiers[i]){
       
   544             return true;
       
   545         }
       
   546     }
       
   547     return false;
       
   548 }    
       
   549     
       
   550 bool BavpGetPropertyL (BavpNPObject *obj, NPIdentifier name, NPVariant *variant)
       
   551 {
       
   552     if (!obj->plugin || !(obj->plugin->Controller())){
       
   553         NULL_TO_NPVARIANT(*variant);
       
   554         return false;    
       
   555     }
       
   556     
       
   557     
       
   558     if (name == bavpPropertyIdentifiers[ID_VOLUME]) 
       
   559     {
       
   560         INT32_TO_NPVARIANT(obj->plugin->Controller()->GetPlayerVolume(), *variant);
       
   561     } 
       
   562 
       
   563     else if (name == bavpPropertyIdentifiers[ID_POSITION]) 
       
   564     {
       
   565         TTimeIntervalMicroSeconds ms = obj->plugin->Controller()->getPositionL();
       
   566         int time = (int)ms.Int64();
       
   567         INT32_TO_NPVARIANT(time, *variant);
       
   568     	
       
   569     } 
       
   570 
       
   571     else if (name == bavpPropertyIdentifiers[ID_DURATION]) 
       
   572     {
       
   573         TTimeIntervalMicroSeconds ms = obj->plugin->Controller()->Duration();
       
   574         int time = (int)ms.Int64();
       
   575         INT32_TO_NPVARIANT(time, *variant);
       
   576     } 
       
   577 
       
   578     else if (name == bavpPropertyIdentifiers[ID_STATE_CHANGED_CALLBACK]) 
       
   579     {
       
   580         if (obj->stateChangedCallback)
       
   581             OBJECT_TO_NPVARIANT(obj->stateChangedCallback, *variant);  
       
   582         else
       
   583             NULL_TO_NPVARIANT(*variant);
       
   584     }
       
   585     else if (name == bavpPropertyIdentifiers[ID_STATE])
       
   586     {
       
   587         TPtrC8 state = getState((TInt)(obj->plugin->Controller()->State()));
       
   588         BavpDesToNpvariant(state, variant);
       
   589     }
       
   590     else if (name == bavpPropertyIdentifiers[ID_ISVIDEOCLIP])
       
   591     {
       
   592         BOOLEAN_TO_NPVARIANT(obj->plugin->Controller()->IsClipVideo(), *variant);
       
   593     }
       
   594     else if (name == bavpPropertyIdentifiers[ID_ISSEEKABLE])
       
   595     {
       
   596         BOOLEAN_TO_NPVARIANT(obj->plugin->Controller()->IsClipSeekable(), *variant);
       
   597     }
       
   598     else if (name == bavpPropertyIdentifiers[ID_CLIPNAME])
       
   599     {
       
   600         const HBufC& name = obj->plugin->Controller()->ClipName();
       
   601         
       
   602         TInt lastSlashPos = name.LocateReverse( '/' );
       
   603         //retrieve the clip name
       
   604         if( lastSlashPos == KErrNotFound ) {
       
   605             lastSlashPos = 0;
       
   606         }
       
   607 
       
   608         TInt len = name.Length()-lastSlashPos-1;
       
   609         TPtrC namePtr( name.Right(len));
       
   610         BavpDesToNpvariant(namePtr, variant);
       
   611     }
       
   612     else if (name == bavpPropertyIdentifiers[ID_FULLSCREENMODE])
       
   613     {
       
   614         BOOLEAN_TO_NPVARIANT(obj->plugin->Controller()->IsClipFullScreen(), *variant);
       
   615     }
       
   616     else if (name == bavpPropertyIdentifiers[ID_MIMETYPE])
       
   617     {
       
   618         const HBufC8& name = obj->plugin->Controller()->MimeType();
       
   619         TPtrC8 namePtr(name);
       
   620         BavpDesToNpvariant(namePtr, variant);
       
   621     }
       
   622     else
       
   623     {
       
   624         return false;
       
   625     }
       
   626     
       
   627     return true;
       
   628    
       
   629 }
       
   630 
       
   631 
       
   632 bool BavpSetPropertyL (BavpNPObject *obj, NPIdentifier name, NPVariant *variant)
       
   633 {
       
   634     if (!obj->plugin)
       
   635         return false;
       
   636 
       
   637     CBavpController *ctlr = obj->plugin->Controller();
       
   638     
       
   639     if (!ctlr)
       
   640         return false;
       
   641     
       
   642     Log(ETrue,_L("\n"));
       
   643 
       
   644     if (name == bavpPropertyIdentifiers[ID_VOLUME]) 
       
   645     {
       
   646         int vol = 0;
       
   647 
       
   648         if (NPVARIANT_IS_DOUBLE(*variant))
       
   649             vol = (int)NPVARIANT_TO_DOUBLE(*variant);
       
   650         else if (NPVARIANT_IS_INT32(*variant))
       
   651             vol = NPVARIANT_TO_INT32(*variant); 
       
   652         else
       
   653         {
       
   654             Log(ETrue,_L("SetProperty: Not a valid value for volume"));
       
   655             return false;
       
   656         }
       
   657             
       
   658         ctlr->SetPlayerVolume(vol);
       
   659         reportVolumeResults(vol,ctlr);
       
   660     } 
       
   661 
       
   662     else if (name == bavpPropertyIdentifiers[ID_POSITION]) 
       
   663     {
       
   664         int pos = 0;
       
   665 
       
   666         if (NPVARIANT_IS_DOUBLE(*variant))
       
   667             pos = (int)NPVARIANT_TO_DOUBLE(*variant);
       
   668         else if (NPVARIANT_IS_INT32(*variant))
       
   669             pos = NPVARIANT_TO_INT32(*variant); 
       
   670         else
       
   671         {
       
   672             Log(ETrue,_L("SetProperty: Not a valid value for position"));
       
   673             return false;
       
   674         }
       
   675             
       
   676         TInt64 ms(pos);
       
   677         CBavpController *ctlr = obj->plugin->Controller();
       
   678         int state = ctlr->State();
       
   679 
       
   680         if ( state != EBavpRewinding && state != EBavpFastForwarding )
       
   681         {
       
   682             ctlr->setPositionL(TTimeIntervalMicroSeconds(ms)); 
       
   683         }
       
   684         else
       
   685         {
       
   686             ctlr->Stop();
       
   687             ctlr->setPositionL(TTimeIntervalMicroSeconds(ms));
       
   688         }
       
   689 
       
   690         reportPositionResultsL(pos,ctlr);
       
   691     } 
       
   692 
       
   693     else if (name == bavpPropertyIdentifiers[ID_STATE_CHANGED_CALLBACK]) 
       
   694     {
       
   695         //int count = 0;
       
   696         if (NPVARIANT_IS_NULL(*variant)) 
       
   697         {
       
   698             if (obj->stateChangedCallback) 
       
   699             {
       
   700                 NPN_ReleaseObject((struct NPObject*)obj->stateChangedCallback);  
       
   701                 obj->stateChangedCallback = 0;
       
   702             }            
       
   703         } 
       
   704         else if (NPVARIANT_IS_OBJECT(*variant)) 
       
   705         {
       
   706             NPObject* callback = NPVARIANT_TO_OBJECT(*variant);            
       
   707             if (obj->stateChangedCallback) 
       
   708             {
       
   709                 NPN_ReleaseObject((struct NPObject*)obj->stateChangedCallback);  
       
   710                 obj->stateChangedCallback = 0;
       
   711             }
       
   712             NPN_RetainObject((struct NPObject*)callback);            
       
   713             obj->stateChangedCallback = callback;
       
   714         }
       
   715         return true;  
       
   716     }
       
   717 
       
   718     else if (name == bavpPropertyIdentifiers[ID_FULLSCREENMODE]) 
       
   719     {
       
   720         int   pos = 0;
       
   721         TBool newmode, needtochange;
       
   722         CBavpController *ctlr = obj->plugin->Controller();
       
   723 
       
   724         if ( !(ctlr->IsClipVideo()) )
       
   725         {
       
   726             Log(ETrue,_L("Fullscreenmode not applicable for audio"));
       
   727             return false;
       
   728         }
       
   729         	
       
   730         if (NPVARIANT_IS_INT32(*variant))
       
   731         {
       
   732             pos = NPVARIANT_TO_INT32(*variant); 
       
   733         }
       
   734         else if (NPVARIANT_IS_DOUBLE(*variant))
       
   735         {
       
   736             pos = (int)NPVARIANT_TO_DOUBLE(*variant);
       
   737         }
       
   738         else if (NPVARIANT_IS_BOOLEAN(*variant))
       
   739         {
       
   740             pos = NPVARIANT_TO_BOOLEAN(*variant) ? 1 : 0;
       
   741         }
       
   742         
       
   743         else
       
   744         {
       
   745             Log(ETrue,_L("SetProperty: Not a valid value for fullscreenmode"));
       
   746             return false;
       
   747         }
       
   748 
       
   749         Log(ETrue,_L("SetProperty: Fullscreenmode"));
       
   750             
       
   751         newmode = (pos == 1);
       
   752         needtochange = (ctlr->IsClipFullScreen() != newmode);
       
   753 
       
   754         if ( ctlr->IsClipFullScreen() )
       
   755         {
       
   756             Log(ETrue,_L("Current mode: Fullscreen"));
       
   757         }
       
   758         else
       
   759         {
       
   760             Log(ETrue,_L("Current mode: Normalscreen"));
       
   761         }
       
   762 
       
   763         if ( newmode )
       
   764         {
       
   765             Log(ETrue,_L("Requested mode: Fullscreen"));
       
   766         }
       
   767         else
       
   768         {
       
   769             Log(ETrue,_L("Requested mode: Normalscreen"));
       
   770         }
       
   771 
       
   772          
       
   773         if ( !needtochange )
       
   774         {
       
   775             Log(ETrue,_L("No need for mode change"));
       
   776             return false;
       
   777         }
       
   778 
       
   779         ((CBavpControllerVideo *)ctlr)->HandleCommandL(EBavpCmdPlayFullScreen);   
       
   780     }
       
   781     else
       
   782     {
       
   783         return false;
       
   784     } 
       
   785     
       
   786     return true; 
       
   787 }
       
   788 
       
   789       
       
   790 static NPClass _BavpNPClass = { 
       
   791     0,
       
   792     (NPAllocateFunctionPtr) BavpAllocate, 
       
   793     (NPDeallocateFunctionPtr) BavpDeallocate, 
       
   794     (NPInvalidateFunctionPtr) BavpInvalidate,
       
   795     (NPHasMethodFunctionPtr) BavpHasMethod,
       
   796     (NPInvokeFunctionPtr) BavpInvokeL,
       
   797     (NPInvokeDefaultFunctionPtr) 0,
       
   798     (NPHasPropertyFunctionPtr) BavpHasProperty,
       
   799     (NPGetPropertyFunctionPtr) BavpGetPropertyL,
       
   800     (NPSetPropertyFunctionPtr) BavpSetPropertyL,
       
   801     (NPRemovePropertyFunctionPtr) 0
       
   802 };
       
   803 static NPClass *BavpNPClass = &_BavpNPClass;
       
   804 
       
   805 
       
   806 BavpNPObject* BavpNPObject_new(NPP instance)
       
   807 {
       
   808     initializeIdentifiers();
       
   809     BavpNPObject *self = (BavpNPObject *)NPN_CreateObject (instance, BavpNPClass);  
       
   810     return self;
       
   811 }
       
   812 
       
   813 void BavpNPObject_stateChanged(BavpNPObject* obj, char* state)
       
   814 {
       
   815     if (!obj || !obj->stateChangedCallback)
       
   816         return;
       
   817     NPVariant arg;
       
   818     NPVariant res;    
       
   819     STRINGZ_TO_NPVARIANT(state, arg);
       
   820     NPN_InvokeDefault(obj->nppInstance, obj->stateChangedCallback, &arg, 1, &res);
       
   821 }