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 #include "avi_test.h"
     19 
     20 #define TEST_DURATION 1000
     21 #define AVI_FILE_SOURCE _STRLIT("C:\\data\\testoutput_IYUV_8k_16_mono.avi")
     22 
     23 void avi_test::test()
     24 {
     25     fprintf(fileoutput, "Start avitest, proxy %d,Audio SrcFormat:", iUseProxy);
     26 
     27     printFormatString(iAudSrcFormatType);
     28 
     29     fprintf(fileoutput, " Audio SinkFormat:");
     30 
     31     printFormatString(iAudSinkFormatType);
     32 
     33     fprintf(fileoutput, " Video SourceFormat:");
     34 
     35     printFormatString(iVidSrcFormatType);
     36 
     37     fprintf(fileoutput, " Video SinkFormat:");
     38 
     39     printFormatString(iVidSinkFormatType);
     40 
     41     fprintf(fileoutput, "\n");
     42 
     43     int error = 0;
     44 
     45     scheduler = OsclExecScheduler::Current();
     46 
     47     this->AddToScheduler();
     48 
     49     init_mime_strings();
     50 
     51     if (start_async_test())
     52     {
     53         OSCL_TRY(error, scheduler->StartScheduler());
     54         if (error != 0)
     55         {
     56             OSCL_LEAVE(error);
     57         }
     58     }
     59 
     60     this->RemoveFromScheduler();
     61 }
     62 
     63 
     64 void avi_test::Run()
     65 {
     66     if (terminal)
     67     {
     68         if (iUseProxy)
     69         {
     70             CPV2WayProxyFactory::DeleteTerminal(terminal);
     71         }
     72         else
     73         {
     74             CPV2WayEngineFactory::DeleteTerminal(terminal);
     75         }
     76         terminal = NULL;
     77     }
     78 
     79     if (timer)
     80     {
     81         delete timer;
     82         timer = NULL;
     83     }
     84 
     85     scheduler->StopScheduler();
     86 }
     87 
     88 void avi_test::DoCancel()
     89 {
     90 }
     91 
     92 void avi_test::HandleInformationalEvent(const PVAsyncInformationalEvent& aEvent)
     93 {
     94     int error = 0;
     95     switch (aEvent.GetEventType())
     96     {
     97         case PVT_INDICATION_OUTGOING_TRACK:
     98         {
     99             TPVChannelId *channel_id = (TPVChannelId *)(&aEvent.GetLocalBuffer()[4]);
    100             printf("Indication with logical channel #%d ", *channel_id);
    101             if (aEvent.GetLocalBuffer()[0] == PV_AUDIO && !iSelAudioSource)
    102             {
    103                 iSelAudioSource = PvmfMediaInputNodeFactory::Create(iAudioMediaInput);
    104                 if (iSelAudioSource != NULL)
    105                 {
    106                     OSCL_TRY(error, iAudioAddSourceId = terminal->AddDataSource(*channel_id, *iSelAudioSource));
    107                     printf("Audio");
    108                 }
    109             }
    110             else if (aEvent.GetLocalBuffer()[0] == PV_VIDEO && !iSelVideoSource)
    111             {
    112                 iSelVideoSource = PvmfMediaInputNodeFactory::Create(iVideoMediaInput);
    113                 if (iSelVideoSource != NULL)
    114                 {
    115                     OSCL_TRY(error, iVideoAddSourceId = terminal->AddDataSource(*channel_id, *iSelVideoSource));
    116                     printf("Video");
    117                 }
    118             }
    119             else
    120             {
    121                 printf("unknown");
    122             }
    123             printf(" outgoing Track\n");
    124             break;
    125         }
    126 
    127         case PVT_INDICATION_INCOMING_TRACK:
    128         {
    129             TPVChannelId *channel_id = (TPVChannelId *)(&aEvent.GetLocalBuffer()[4]);
    130             printf("Indication with logical channel #%d ", *channel_id);
    131             if (aEvent.GetLocalBuffer()[0] == PV_AUDIO && !iSelAudioSink)
    132             {
    133                 iSelAudioSink = get_audio_sink(iAudSinkFormatType);
    134                 if (iSelAudioSink != NULL)
    135                 {
    136                     OSCL_TRY(error, iAudioAddSinkId = terminal->AddDataSink(*channel_id, *iSelAudioSink));
    137                     printf("Audio");
    138                 }
    139             }
    140             else if (aEvent.GetLocalBuffer()[0] == PV_VIDEO && !iSelVideoSink)
    141             {
    142                 iSelVideoSink = get_video_sink(iVidSinkFormatType);
    143                 if (iSelVideoSink != NULL)
    144                 {
    145                     OSCL_TRY(error, iVideoAddSinkId = terminal->AddDataSink(*channel_id, *iSelVideoSink));
    146                     printf("Video");
    147                 }
    148             }
    149             else
    150             {
    151                 printf("unknown");
    152             }
    153             printf(" incoming Track\n");
    154             break;
    155         }
    156 
    157         case PVT_INDICATION_DISCONNECT:
    158             iAudioSourceAdded = false;
    159             iVideoSourceAdded = false;
    160             iAudioSinkAdded = false;
    161             iVideoSinkAdded = false;
    162             break;
    163 
    164         case PVT_INDICATION_CLOSE_TRACK:
    165             break;
    166 
    167         case PVT_INDICATION_INTERNAL_ERROR:
    168             break;
    169 
    170         default:
    171             break;
    172     }
    173 }
    174 
    175 void avi_test::CommandCompleted(const PVCmdResponse& aResponse)
    176 {
    177     PVCommandId cmdId = aResponse.GetCmdId();
    178 
    179     if (cmdId == iInitCmdId)
    180     {
    181         if (aResponse.GetCmdStatus() == PVMFSuccess)
    182         {
    183             connect();
    184         }
    185         else
    186         {
    187             test_is_true(false);
    188             timer->Cancel();
    189             RunIfNotReady();
    190         }
    191     }
    192     else if (iConnectCmdId == cmdId)
    193     {
    194     }
    195     else if (iAudioAddSinkId == cmdId)
    196     {
    197         iAudioSinkAdded = true;
    198         if (iAudioSourceAdded && iVideoSourceAdded && iVideoSinkAdded)
    199             timer->RunIfNotReady(TEST_DURATION);
    200 
    201     }
    202     else if (iAudioAddSourceId == cmdId)
    203     {
    204         iAudioSourceAdded = true;
    205         if (iAudioSinkAdded && iVideoSourceAdded && iVideoSinkAdded)
    206             timer->RunIfNotReady(TEST_DURATION);
    207     }
    208     else if (iVideoAddSinkId == cmdId)
    209     {
    210         iVideoSinkAdded = true;
    211         if (iVideoSourceAdded && iAudioSourceAdded && iAudioSinkAdded)
    212             timer->RunIfNotReady(TEST_DURATION);
    213 
    214     }
    215     else if (iVideoAddSourceId == cmdId)
    216     {
    217         iVideoSourceAdded = true;
    218         if (iVideoSinkAdded && iAudioSourceAdded && iAudioSinkAdded)
    219             timer->RunIfNotReady(TEST_DURATION);
    220     }
    221     else if (iDisCmdId == cmdId)
    222     {
    223         printf("Finished disconnecting \n");
    224         //  destroy_sink_source();
    225         reset();
    226     }
    227     else if (iRstCmdId == cmdId)
    228     {
    229         test_is_true(true);
    230         destroy_sink_source();
    231         RunIfNotReady();
    232     }
    233     else
    234     {
    235         printf("Unhandled cmd here %d\n", cmdId);
    236     }
    237 }
    238 
    239 void avi_test::TimerCallback()
    240 {
    241     timer_elapsed = true;
    242     disconnect();
    243 }
    244 
    245 bool avi_test::start_async_test()
    246 {
    247     int error = 0;
    248 
    249     timer = new engine_timer(this);
    250     if (timer == NULL)
    251     {
    252         test_is_true(false);
    253         return false;
    254     }
    255     iAudioSourceAdded = false;
    256     iAudioSinkAdded = false;
    257 
    258     timer->AddToScheduler();
    259 
    260     if (iUseProxy)
    261     {
    262         OSCL_TRY(error, terminal = CPV2WayProxyFactory::CreateTerminal(PV_324M,
    263                                    (PVCommandStatusObserver *) this,
    264                                    (PVInformationalEventObserver *) this,
    265                                    (PVErrorEventObserver *) this));
    266     }
    267     else
    268     {
    269         OSCL_TRY(error, terminal = CPV2WayEngineFactory::CreateTerminal(PV_324M,
    270                                    (PVCommandStatusObserver *) this,
    271                                    (PVInformationalEventObserver *) this,
    272                                    (PVErrorEventObserver *) this));
    273     }
    274     if (error)
    275     {
    276         test_is_true(false);
    277         return false;
    278     }
    279 
    280     create_sink_source();
    281     HandleAvi();
    282     OSCL_TRY(error, iInitCmdId = terminal->Init(iSdkInitInfo));
    283     if (error)
    284     {
    285         test_is_true(false);
    286         if (iUseProxy)
    287         {
    288             CPV2WayProxyFactory::DeleteTerminal(terminal);
    289         }
    290         else
    291         {
    292             CPV2WayEngineFactory::DeleteTerminal(terminal);
    293         }
    294         terminal = NULL;
    295         return false;
    296     }
    297     return true;
    298 }
    299 
    300 bool avi_test::HandleAvi()
    301 {
    302     int32 error = 0;
    303     iFileServer.Connect();
    304     {
    305 
    306         OSCL_TRY(error, iFileParser = PVAviFile::CreateAviFileParser(AVI_FILE_SOURCE, error, &iFileServer););
    307 
    308         if (!iFileParser)
    309         {
    310             return false;
    311         }
    312 
    313         uint32 numStreams = ((PVAviFile*)iFileParser)->GetNumStreams();
    314 
    315         for (uint32 ii = 0; ii < numStreams; ii++)
    316         {
    317             if (oscl_strstr(((PVAviFile*)iFileParser)->GetStreamMimeType(ii).get_cstr(), "audio"))
    318             {
    319                 iAudioNum = ii;
    320                 iPVAviFile = OSCL_STATIC_CAST(PVAviFile*, iFileParser);
    321                 {
    322                     iAudioMediaInput = PvmiMIOAviWavFileFactory::Create(0, false, iAudioNum, (OsclAny*)iPVAviFile, FILE_FORMAT_AVI, error);
    323                     if (!iAudioMediaInput)
    324                     {
    325                         return PVMFFailure;
    326                     }
    327                 }
    328 
    329             }
    330 
    331             if (oscl_strstr(((PVAviFile*)iFileParser)->GetStreamMimeType(ii).get_cstr(), "video"))
    332             {
    333                 iVideoNum = ii;
    334                 {
    335                     iPVAviFile = OSCL_STATIC_CAST(PVAviFile*, iFileParser);
    336                     iVideoMediaInput = PvmiMIOAviWavFileFactory::Create(0, false, iVideoNum, (OsclAny*)iPVAviFile, FILE_FORMAT_AVI, error);
    337                     if (!iVideoMediaInput)
    338                     {
    339                         return PVMFFailure;
    340                     }
    341 
    342                 }
    343 
    344             }
    345 
    346         }
    347     }
    348     return PVMFSuccess;
    349 }
    350 
    351 
    352