Home | History | Annotate | Download | only in src
      1 /* ------------------------------------------------------------------
      2  * Copyright (C) 1998-2009 PacketVideo
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
     13  * express or implied.
     14  * See the License for the specific language governing permissions
     15  * and limitations under the License.
     16  * -------------------------------------------------------------------
     17  */
     18 #ifndef TEST_BASE_H_INCLUDED
     19 #include "test_base.h"
     20 #endif
     21 
     22 #ifndef PV_LOGGER_IMPL_H_INCLUDED
     23 #include "pv_logger_impl.h"
     24 #endif
     25 
     26 
     27 #include "pv_mime_string_utils.h"
     28 
     29 #if defined(__linux__) || defined(linux)
     30 #define CONFIG_FILE_PATH _STRLIT("")
     31 #endif
     32 
     33 #define LOG_FILE_NAME _STRLIT("pvlog.txt")
     34 
     35 void test_base::H324MConfigCommandCompletedL(PVMFCmdResp& aResponse)
     36 {
     37     OSCL_UNUSED_ARG(aResponse);
     38 }
     39 
     40 void test_base::H324MConfigHandleInformationalEventL(PVMFAsyncEvent& aNotification)
     41 {
     42     OSCL_UNUSED_ARG(aNotification);
     43 }
     44 
     45 void test_base::CreateH324Component(bool aCreateH324)
     46 {
     47     OSCL_UNUSED_ARG(aCreateH324);
     48 
     49 
     50     // get TSC node
     51     iQueryInterfaceCmdId = terminal->QueryInterface(PVH324MConfigUuid, iTempH324MConfigIterface);
     52 
     53 }
     54 
     55 void test_base::QueryInterfaceSucceeded()
     56 {
     57     if (iH324MConfig)
     58     {
     59         iH324MConfig->SetObserver(this);
     60 
     61         {
     62             PVInterface *componentInterface;
     63 
     64             iH324MConfig->queryInterface(PVUuidH324ComponentInterface, (PVInterface*&)componentInterface);
     65         }
     66     }
     67     // now we have created the component, we can do init.
     68     Init();
     69 }
     70 
     71 bool test_base::Init()
     72 {
     73     int32 error = 0;
     74     OSCL_FastString aStr;
     75 
     76     // Clear formats from prev call if any
     77     iSdkInitInfo.iIncomingAudioFormats.clear();
     78     iSdkInitInfo.iOutgoingAudioFormats.clear();
     79     iSdkInitInfo.iIncomingVideoFormats.clear();
     80     iSdkInitInfo.iOutgoingVideoFormats.clear();
     81 
     82 
     83     iSdkInitInfo.iIncomingAudioFormats.push_back(iAudSinkFormatType.getMIMEStrPtr());
     84 
     85     iSdkInitInfo.iOutgoingAudioFormats.push_back(iAudSrcFormatType.getMIMEStrPtr());
     86 
     87     iSdkInitInfo.iIncomingVideoFormats.push_back(iVidSinkFormatType.getMIMEStrPtr());
     88 
     89     iSdkInitInfo.iOutgoingVideoFormats.push_back(iVidSrcFormatType.getMIMEStrPtr());
     90 
     91     if (pv_mime_strcmp(iVidSinkFormatType.getMIMEStrPtr(), PVMF_MIME_M4V) == 0)
     92     {
     93         iSdkInitInfo.iIncomingVideoFormats.push_back(PVMF_MIME_YUV420);
     94     }
     95 
     96     if (pv_mime_strcmp(iVidSrcFormatType.getMIMEStrPtr(), PVMF_MIME_M4V) == 0)
     97     {
     98         iSdkInitInfo.iOutgoingVideoFormats.push_back(PVMF_MIME_YUV420);
     99     }
    100 
    101 
    102     OSCL_TRY(error, iInitCmdId = terminal->Init(iSdkInitInfo));
    103     if (error)
    104     {
    105         test_is_true(false);
    106 
    107         if (iUseProxy)
    108         {
    109             CPV2WayProxyFactory::DeleteTerminal(terminal);
    110         }
    111         else
    112         {
    113             CPV2WayEngineFactory::DeleteTerminal(terminal);
    114         }
    115 
    116         terminal = NULL;
    117         return false;
    118     }
    119     return true;
    120 }
    121 
    122 
    123 void test_base::InitSucceeded()
    124 {
    125     connect();
    126 }
    127 
    128 void test_base::InitFailed()
    129 {
    130     timer->Cancel();
    131     RunIfNotReady();
    132 }
    133 void test_base::InitCancelled()
    134 {
    135     InitFailed();
    136 }
    137 void test_base::EncoderIFSucceeded()
    138 {
    139 }
    140 
    141 void test_base::EncoderIFFailed()
    142 {
    143 }
    144 
    145 void test_base::ConnectSucceeded()
    146 {
    147     disconnect();
    148 }
    149 
    150 void test_base::ConnectFailed()
    151 {
    152     test_is_true(false);
    153     reset();
    154 }
    155 
    156 void test_base::ConnectCancelled()
    157 {
    158     ConnectFailed();
    159 }
    160 
    161 void test_base::CancelCmdCompleted()
    162 {
    163     test_is_true(true);
    164     RunIfNotReady();
    165 }
    166 
    167 void test_base::RstCmdCompleted()
    168 {
    169     destroy_sink_source();
    170     RunIfNotReady();
    171 }
    172 
    173 void test_base::DisCmdSucceeded()
    174 {
    175     reset();
    176 }
    177 
    178 void test_base::DisCmdFailed()
    179 {
    180     reset();
    181 }
    182 
    183 void test_base::AudioAddSinkCompleted()
    184 {
    185     iAudioSinkAdded = true;
    186     if (iAudioSourceAdded)
    187         timer->RunIfNotReady(TEST_DURATION);
    188 }
    189 
    190 void test_base::AudioAddSourceCompleted()
    191 {
    192     iAudioSourceAdded = true;
    193     if (iAudioSinkAdded)
    194         timer->RunIfNotReady(TEST_DURATION);
    195 }
    196 
    197 void test_base::AudioRemoveSourceCompleted()
    198 {
    199     iAudioSourceAdded = false;
    200     if (!iAudioSinkAdded)
    201         disconnect();
    202 }
    203 
    204 void test_base::AudioRemoveSinkCompleted()
    205 {
    206     iAudioSinkAdded = false;
    207     if (!iAudioSourceAdded)
    208         disconnect();
    209 }
    210 
    211 void test_base::VideoAddSinkSucceeded()
    212 {
    213 }
    214 void test_base::VideoAddSinkFailed()
    215 {
    216     test_is_true(false);
    217     disconnect();
    218 }
    219 void test_base::VideoAddSourceSucceeded()
    220 {
    221 }
    222 void test_base::VideoAddSourceFailed()
    223 {
    224 }
    225 void test_base::VideoRemoveSourceCompleted()
    226 {
    227     int error = 0;
    228     iVideoSourceAdded = false;
    229     if (iSelVideoSink != NULL)
    230     {
    231         OSCL_TRY(error, iVideoRemoveSinkId = terminal->RemoveDataSink(*iSelVideoSink));
    232     }
    233     if (error)
    234     {
    235         test_is_true(false);
    236         disconnect();
    237     }
    238 }
    239 void test_base::VideoRemoveSinkCompleted()
    240 {
    241     iVideoSinkAdded = false;
    242     if (!iVideoSourceAdded)
    243         disconnect();
    244 }
    245 
    246 
    247 void test_base::CommandCompleted(const PVCmdResponse& aResponse)
    248 {
    249     PVCommandId cmdId = aResponse.GetCmdId();
    250     iTestStatus &= (aResponse.GetCmdStatus() == PVMFSuccess) ? true : false;
    251 
    252     if (iQueryInterfaceCmdId == cmdId)
    253     {
    254         if (aResponse.GetCmdStatus() == PVMFSuccess)
    255         {
    256             if (iTempH324MConfigIterface)
    257             {
    258                 iH324MConfig = OSCL_STATIC_CAST(H324MConfigInterface*, iTempH324MConfigIterface);
    259                 iTempH324MConfigIterface = NULL;
    260                 QueryInterfaceSucceeded();
    261             }
    262 
    263         }
    264     }
    265     else if (iInitCmdId == cmdId)
    266     {
    267         if (aResponse.GetCmdStatus() == PVMFSuccess)
    268         {
    269             InitSucceeded();
    270         }
    271         else if (aResponse.GetCmdStatus() == PVMFErrCancelled)
    272         {
    273             InitCancelled();
    274         }
    275         else
    276         {
    277             InitFailed();
    278         }
    279     }
    280     else if (iEncoderIFCommandId == cmdId)
    281     {
    282         if (aResponse.GetCmdStatus() != PVMFSuccess)
    283         {
    284             EncoderIFFailed();
    285         }
    286         else
    287         {
    288             EncoderIFSucceeded();
    289         }
    290     }
    291     else if (iConnectCmdId == cmdId)
    292     {
    293         if (aResponse.GetCmdStatus() == PVMFSuccess)
    294         {
    295             ConnectSucceeded();
    296         }
    297         else if (aResponse.GetCmdStatus() == PVMFErrCancelled)
    298         {
    299             ConnectCancelled();
    300         }
    301         else
    302         {
    303             ConnectFailed();
    304         }
    305     }
    306     else if (iDisCmdId == cmdId)
    307     {
    308         if (aResponse.GetCmdStatus() != PVMFSuccess)
    309         {
    310             DisCmdFailed();
    311         }
    312         else
    313         {
    314             DisCmdSucceeded();
    315         }
    316     }
    317     else if (iRstCmdId == cmdId)
    318     {
    319         RstCmdCompleted();
    320     }
    321     else if (iAudioAddSinkId == cmdId)
    322     {
    323         AudioAddSinkCompleted();
    324     }
    325     else if (iAudioAddSourceId == cmdId)
    326     {
    327         AudioAddSourceCompleted();
    328     }
    329     else if (iAudioRemoveSourceId == cmdId)
    330     {
    331         AudioRemoveSourceCompleted();
    332     }
    333     else if (iAudioRemoveSinkId == cmdId)
    334     {
    335         AudioRemoveSinkCompleted();
    336     }
    337     else if (iVideoAddSinkId == cmdId)
    338     {
    339         if (aResponse.GetCmdStatus() == PVMFSuccess)
    340         {
    341             VideoAddSinkSucceeded();
    342         }
    343         else
    344         {
    345             VideoAddSinkFailed();
    346         }
    347     }
    348     else if (iVideoAddSourceId == cmdId)
    349     {
    350         if (aResponse.GetCmdStatus() == PVMFSuccess)
    351         {
    352             VideoAddSourceSucceeded();
    353         }
    354         else
    355         {
    356             VideoAddSourceFailed();
    357         }
    358     }
    359     else if (iVideoRemoveSourceId == cmdId)
    360     {
    361         VideoRemoveSourceCompleted();
    362     }
    363     else if (iVideoRemoveSinkId == cmdId)
    364     {
    365         VideoRemoveSinkCompleted();
    366     }
    367     else if (iCancelCmdId == cmdId)
    368     {
    369         CancelCmdCompleted();
    370     }
    371 }
    372 
    373 
    374 void test_base::InitializeLogs()
    375 {
    376     uint32 error = 0;
    377     PVLoggerConfigFile obj;
    378     obj.SetConfigFilePath(CONFIG_FILE_PATH);
    379     error = 0;
    380     if (obj.IsLoggerConfigFilePresent())
    381     {
    382         error = obj.SetLoggerSettings(terminal, LOG_FILE_NAME);
    383         if (0 != error)
    384         {
    385             printf("Error Occured in PVLoggerConfigFile::SetLoggerSettings() \n");
    386         }
    387         else
    388         {
    389             //sucess able to set logger settings
    390             return;
    391         }
    392     }
    393 
    394     PVLoggerAppender *lLoggerAppender = 0;
    395     OsclRefCounter *refCounter = NULL;
    396     bool logfile = true;
    397     if (logfile)
    398     {
    399 //File Log
    400         const uint32 TEXT_FILE_APPENDER_CACHE_SIZE = 1024;
    401         lLoggerAppender = TextFileAppender<TimeAndIdLayout, 1024>::CreateAppender(LOG_FILE_NAME,
    402                           TEXT_FILE_APPENDER_CACHE_SIZE);
    403         OsclRefCounter *appenderRefCounter = new OsclRefCounterSA<AppenderDestructDealloc<TextFileAppender<TimeAndIdLayout, 1024> > >(lLoggerAppender);
    404         refCounter = appenderRefCounter;
    405     }
    406     else
    407     {
    408 //Console Log
    409         lLoggerAppender = new StdErrAppender<TimeAndIdLayout, 1024>();
    410         OsclRefCounter *appenderRefCounter = new OsclRefCounterSA<AppenderDestructDealloc<StdErrAppender<TimeAndIdLayout, 1024> > >(lLoggerAppender);
    411         refCounter = appenderRefCounter;
    412     }
    413     OsclSharedPtr<PVLoggerAppender> appenderPtr(lLoggerAppender, refCounter);
    414     terminal->SetLogLevel("", PVLOGMSG_DEBUG, true);
    415     terminal->SetLogAppender("", appenderPtr);
    416 
    417 }
    418 
    419 bool test_base::start_async_test()
    420 {
    421     int error = 0;
    422     if (iUseProxy)
    423     {
    424         OSCL_TRY(error, terminal = CPV2WayProxyFactory::CreateTerminal(PV_324M,
    425                                    (PVCommandStatusObserver *) this,
    426                                    (PVInformationalEventObserver *) this,
    427                                    (PVErrorEventObserver *) this));
    428     }
    429     else
    430     {
    431         OSCL_TRY(error, terminal = CPV2WayEngineFactory::CreateTerminal(iSIP ? PV_SIP : PV_324M,
    432                                    (PVCommandStatusObserver *) this,
    433                                    (PVInformationalEventObserver *) this,
    434                                    (PVErrorEventObserver *) this));
    435     }
    436 
    437     if (error)
    438     {
    439         test_is_true(false);
    440         return false;
    441     }
    442 
    443     InitializeLogs();
    444 
    445     create_sink_source();
    446     iInitCmdId = -1;
    447     iQueryInterfaceCmdId = -1;
    448     CreateH324Component();
    449     return true;
    450 }
    451 
    452