mmlibs/mmfw/tsrc/mmfintegrationtest/vclntavi/src/testexternaldisplay.cpp
changeset 4 9d4397b300d1
equal deleted inserted replaced
1:fcaf4606ba4e 4:9d4397b300d1
       
     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 #include "testvideoplayer2.h"
       
    17 #include <bautils.h>
       
    18 
       
    19 // file names used to control plugin through their existence. If any are new files are added make sure
       
    20 // they are also added to TidyFiles().
       
    21 _LIT(KInitExtDisplayHDMI, "c:\\vclntavi\\InitExtDisplayHDMI.txt");
       
    22 _LIT(KInitExtDisplayAnalog, "c:\\vclntavi\\InitExtDisplayAnalog.txt");
       
    23 _LIT(KConnectExtDisplayOverHDMI, "c:\\vclntavi\\ConnectExtDisplayOverHDMI.txt");
       
    24 _LIT(KConnectExtDisplayOverAnalog, "c:\\vclntavi\\ConnectExtDisplayOverAnalog.txt");
       
    25 _LIT(KDisconnectExtDisplay, "c:\\vclntavi\\DisconnectExtDisplay.txt");
       
    26 void TidyFiles()
       
    27     {
       
    28     RFs fs;
       
    29     TInt error= fs.Connect();
       
    30     if(error == KErrNone)
       
    31         {
       
    32         if(BaflUtils::FileExists(fs, KInitExtDisplayHDMI))
       
    33             {
       
    34             fs.Delete(KInitExtDisplayHDMI);
       
    35             }
       
    36         if(BaflUtils::FileExists(fs, KInitExtDisplayAnalog))
       
    37             {
       
    38             fs.Delete(KInitExtDisplayAnalog);
       
    39             }
       
    40         if(BaflUtils::FileExists(fs, KConnectExtDisplayOverHDMI))
       
    41             {
       
    42             fs.Delete(KConnectExtDisplayOverHDMI);
       
    43             }
       
    44         if(BaflUtils::FileExists(fs, KConnectExtDisplayOverAnalog))
       
    45             {
       
    46             fs.Delete(KConnectExtDisplayOverAnalog);
       
    47             }
       
    48         if(BaflUtils::FileExists(fs, KDisconnectExtDisplay))
       
    49             {
       
    50             fs.Delete(KDisconnectExtDisplay);
       
    51             }
       
    52         }
       
    53 }
       
    54 
       
    55 _LIT(KFilename, "filename");
       
    56 
       
    57 //
       
    58 // RTestMediaClientExternalDisplay
       
    59 //
       
    60 
       
    61 /**
       
    62  * RTestMediaClientExternalDisplay::Constructor
       
    63  */
       
    64 RTestMediaClientExternalDisplay::RTestMediaClientExternalDisplay(const TDesC& aTestName)
       
    65     : RTestVclnt2AviPlayerStep(aTestName, aTestName, KFilename, KErrNone)
       
    66     {
       
    67     }
       
    68 
       
    69 /**
       
    70  * RTestMediaClientExternalDisplay::NewL
       
    71  */
       
    72 RTestMediaClientExternalDisplay* RTestMediaClientExternalDisplay::NewL(const TDesC& aTestName)
       
    73     {
       
    74     RTestMediaClientExternalDisplay* self = new (ELeave) RTestMediaClientExternalDisplay(aTestName);
       
    75     return self;
       
    76     }
       
    77 
       
    78 /**
       
    79  * RTestMediaClientExternalDisplay::DoTestStepPreambleL
       
    80  */
       
    81 TVerdict RTestMediaClientExternalDisplay::DoTestStepPreambleL()
       
    82     {
       
    83     TidyFiles();
       
    84 
       
    85     TVerdict verdict = SetInitialConnectionType();
       
    86     if(verdict != EPass)
       
    87         {
       
    88         return verdict;
       
    89         }
       
    90 
       
    91     verdict = SetConnectionTypeNotification();
       
    92     if(verdict != EPass)
       
    93         {
       
    94         return verdict;
       
    95         }
       
    96 
       
    97     verdict = SetExternalDisplayControl();
       
    98     if(verdict != EPass)
       
    99         {
       
   100         return verdict;
       
   101         }
       
   102     
       
   103     return RTestVclnt2AviPlayerStep::DoTestStepPreambleL();
       
   104     }
       
   105 
       
   106 TVerdict RTestMediaClientExternalDisplay::SetInitialConnectionType()
       
   107     {
       
   108     // Create a file as named in ini file. When external display test plugin is constructed it
       
   109     // checks to see what filenames exist and sets inital connection type as appropriate.
       
   110     // If string does not exist in ini file then plugin initialises with exetrnal display disconnected.
       
   111     if(GetStringFromConfig(iSectName, _L("initialExternalDisplayType"), iInitialExternalDisplayTypeFilename))
       
   112         {
       
   113         if(iInitialExternalDisplayTypeFilename.Compare(KInitExtDisplayHDMI) == 0)
       
   114             {
       
   115             INFO_PRINTF2(_L("Creating %S"), &iInitialExternalDisplayTypeFilename);
       
   116             INFO_PRINTF1(_L("External HDMI Display initially connected"));
       
   117             }
       
   118         else if(iInitialExternalDisplayTypeFilename.Compare(KInitExtDisplayAnalog) == 0)
       
   119             {
       
   120             INFO_PRINTF2(_L("Creating %S"), &iInitialExternalDisplayTypeFilename);
       
   121             INFO_PRINTF1(_L("External Analog Display initially connected"));
       
   122             }
       
   123         else
       
   124             {
       
   125             INFO_PRINTF2(_L("External display setting unkown, %S"), &iInitialExternalDisplayTypeFilename);
       
   126             return EInconclusive;
       
   127             }
       
   128 
       
   129         // connect to file system and open file
       
   130         RFs fs;
       
   131         if(fs.Connect() != KErrNone)
       
   132             {
       
   133             return EInconclusive;
       
   134             }
       
   135         RFile file;
       
   136         if(file.Replace(fs, iInitialExternalDisplayTypeFilename, EFileWrite) != KErrNone)
       
   137             {
       
   138             fs.Close();
       
   139             return EInconclusive;
       
   140             }
       
   141         
       
   142         file.Close();
       
   143         fs.Close();
       
   144         }
       
   145     else
       
   146         {
       
   147         INFO_PRINTF1(_L("External Display initially disconnected!"));
       
   148         }
       
   149     
       
   150     return EPass;
       
   151     }
       
   152 
       
   153 TVerdict RTestMediaClientExternalDisplay::SetConnectionTypeNotification()
       
   154     {
       
   155     // Now create file for the next connection type. This is used to emit a connect or disocnnect notification
       
   156     // after a few seconds. Note that if the initial and next connection types are the same the external
       
   157     // display test plugin will not emit a notification.    
       
   158     if(GetStringFromConfig(iSectName, _L("nextExternalDisplayType"), iNextExternalDisplayTypeFilename))
       
   159         {
       
   160         if(iNextExternalDisplayTypeFilename.Compare(KConnectExtDisplayOverHDMI) == 0)
       
   161             {
       
   162             INFO_PRINTF2(_L("Creating %S"), &iNextExternalDisplayTypeFilename);
       
   163             INFO_PRINTF1(_L("External HDMI Display to be connected and notification emitted"));
       
   164             }
       
   165         else if(iNextExternalDisplayTypeFilename.Compare(KConnectExtDisplayOverAnalog) == 0)
       
   166             {
       
   167             INFO_PRINTF2(_L("Creating %S"), &iNextExternalDisplayTypeFilename);
       
   168             INFO_PRINTF1(_L("External Analog Display to be connected and notification emitted"));
       
   169             }
       
   170         else if(iNextExternalDisplayTypeFilename.Compare(KDisconnectExtDisplay) == 0)
       
   171             {
       
   172             INFO_PRINTF2(_L("Creating %S"), &iNextExternalDisplayTypeFilename);
       
   173             INFO_PRINTF1(_L("External Display to be disconnected and notification emitted"));
       
   174             }
       
   175         else
       
   176             {
       
   177             INFO_PRINTF2(_L("External display switch setting unkown, %S"), &iNextExternalDisplayTypeFilename);
       
   178             return EInconclusive;
       
   179             }
       
   180 
       
   181         // connect to file system and open file
       
   182         RFs fs;
       
   183         if(fs.Connect() != KErrNone)
       
   184             {
       
   185             return EInconclusive;
       
   186             }
       
   187         RFile file;
       
   188         if(file.Replace(fs, iNextExternalDisplayTypeFilename, EFileWrite) != KErrNone)
       
   189             {
       
   190             fs.Close();
       
   191             return EInconclusive;
       
   192             }
       
   193         
       
   194         file.Close();
       
   195         fs.Close();
       
   196         }
       
   197     else
       
   198         {
       
   199         INFO_PRINTF1(_L("No External Display switching requested!"));
       
   200         }
       
   201     
       
   202     return EPass;
       
   203     }
       
   204 
       
   205 TVerdict RTestMediaClientExternalDisplay::SetExternalDisplayControl()
       
   206     {
       
   207     if(GetBoolFromConfig(iSectName, _L("externalDisplayControl"), iExternalDisplayControl))
       
   208         {
       
   209         INFO_PRINTF2(_L("External display switch control set to %d"), iExternalDisplayControl);
       
   210         }
       
   211     else
       
   212         {
       
   213         return EInconclusive;
       
   214         }
       
   215     return EPass;
       
   216     }
       
   217     
       
   218 /**
       
   219  * RTestMediaClientExternalDisplay::DoTestStepPostambleL
       
   220  */
       
   221 TVerdict RTestMediaClientExternalDisplay::DoTestStepPostambleL()
       
   222     {
       
   223     RFs fs;
       
   224     // connect to file system and open file
       
   225     User::LeaveIfError(fs.Connect());
       
   226     CleanupClosePushL(fs);
       
   227     
       
   228     if((iInitialExternalDisplayTypeFilename.Length()!= 0) && BaflUtils::FileExists(fs, iInitialExternalDisplayTypeFilename))
       
   229         {
       
   230         User::LeaveIfError(fs.Delete(iInitialExternalDisplayTypeFilename));
       
   231         }
       
   232 
       
   233     if((iNextExternalDisplayTypeFilename.Length()!= 0) && BaflUtils::FileExists(fs, iNextExternalDisplayTypeFilename))
       
   234         {
       
   235         User::LeaveIfError(fs.Delete(iNextExternalDisplayTypeFilename));
       
   236         }
       
   237     
       
   238     CleanupStack::PopAndDestroy(1); //fs
       
   239     
       
   240     return RTestVclnt2AviPlayerStep::DoTestStepPostambleL();        
       
   241     }
       
   242 
       
   243 /**
       
   244  * RTestMediaClientExternalDisplay::FsmL
       
   245  */
       
   246 void RTestMediaClientExternalDisplay::FsmL(TVclntTestPlayEvents aEventCode)
       
   247     {
       
   248     if (FsmCheck(aEventCode))
       
   249         {
       
   250         switch (aEventCode)
       
   251             {
       
   252             case EVPIdle:
       
   253                 HandleIdleL();
       
   254                 break;
       
   255                 
       
   256             case EVPOpenComplete:
       
   257                 HandleOpenCompleteL();
       
   258                 break;
       
   259                 
       
   260             case EVPPrepareComplete:                    
       
   261                 HandlePrepareCompleteL();
       
   262                 break;
       
   263                 
       
   264             case EVPPlayComplete:
       
   265                 HandlePlayCompleteL();
       
   266                 break;
       
   267             }
       
   268         }
       
   269     }
       
   270     
       
   271 void RTestMediaClientExternalDisplay::HandleIdleL()
       
   272     {
       
   273     // Open iVideoPlayer
       
   274     INFO_PRINTF2(_L("iVideoPlayer2->OpenFileL() %S"), &iFilename);
       
   275     iVideoPlayer2->OpenFileL(iFilename, KMmfTestAviPlayControllerUid);
       
   276     PrepareState(EVPOpenComplete, KErrNone);
       
   277     }
       
   278 
       
   279 void RTestMediaClientExternalDisplay::HandleOpenCompleteL()
       
   280     {
       
   281     // Prepare iVideoPlayer2
       
   282     INFO_PRINTF1(_L("iVideoPlayer2->Prepare()"));
       
   283     iVideoPlayer2->Prepare();
       
   284     PrepareState(EVPPrepareComplete, KErrNone);
       
   285     }
       
   286     
       
   287 void RTestMediaClientExternalDisplay::HandlePrepareCompleteL()
       
   288     {
       
   289     // Add display window using default values - ie. video extent & window clipping 
       
   290     // defaulted to whole window
       
   291     INFO_PRINTF1(_L("iVideoPlayer2->AddDisplayWindowL()"));
       
   292     iVideoPlayer2->AddDisplayWindowL(iWs, *iScreen, *iWindow);
       
   293 
       
   294     // set external display control
       
   295     iVideoPlayer2->SetExternalDisplaySwitchingL((*iScreen).GetScreenNumber(), iExternalDisplayControl);
       
   296     
       
   297     // trigger the video to start playing                
       
   298     StartPlayback();
       
   299     }
       
   300 
       
   301 void RTestMediaClientExternalDisplay::HandlePlayCompleteL()
       
   302     {
       
   303     iTestStepResult = EPass;
       
   304     CActiveScheduler::Stop();
       
   305     }
       
   306 
       
   307 void RTestMediaClientExternalDisplay::StartPlayback()
       
   308     {
       
   309     iError = KErrTimedOut;
       
   310     INFO_PRINTF1(_L("iVideoPlayer2->Play()"));
       
   311     PrepareState(EVPPlayComplete, KErrNone);
       
   312     iVideoPlayer2->Play();
       
   313     }
       
   314