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 "av_test.h"
     19 
     20 
     21 void av_test::test()
     22 {
     23     fprintf(fileoutput, "Start avtest, proxy %d,Audio SrcFormat:", iUseProxy);
     24 
     25     printFormatString(iAudSrcFormatType);
     26 
     27     fprintf(fileoutput, " Audio SinkFormat:");
     28 
     29     printFormatString(iAudSinkFormatType);
     30 
     31     fprintf(fileoutput, " Video SourceFormat:");
     32 
     33     printFormatString(iVidSrcFormatType);
     34 
     35     fprintf(fileoutput, " Video SinkFormat:");
     36 
     37     printFormatString(iVidSinkFormatType);
     38 
     39     fprintf(fileoutput, "\n");
     40 
     41     int error = 0;
     42 
     43     scheduler = OsclExecScheduler::Current();
     44 
     45     this->AddToScheduler();
     46 
     47     init_mime_strings();
     48 
     49     if (start_async_test())
     50     {
     51         OSCL_TRY(error, scheduler->StartScheduler());
     52         if (error != 0)
     53         {
     54             OSCL_LEAVE(error);
     55         }
     56     }
     57 
     58     this->RemoveFromScheduler();
     59 }
     60 
     61 
     62 void av_test::Run()
     63 {
     64     if (terminal)
     65     {
     66         if (iUseProxy)
     67         {
     68             CPV2WayProxyFactory::DeleteTerminal(terminal);
     69         }
     70         else
     71         {
     72             CPV2WayEngineFactory::DeleteTerminal(terminal);
     73         }
     74         terminal = NULL;
     75     }
     76 
     77     if (timer)
     78     {
     79         delete timer;
     80         timer = NULL;
     81     }
     82 
     83     scheduler->StopScheduler();
     84 }
     85 
     86 void av_test::DoCancel()
     87 {
     88 }
     89 
     90 void av_test::ConnectSucceeded()
     91 {
     92 }
     93 
     94 void av_test::HandleInformationalEvent(const PVAsyncInformationalEvent& aEvent)
     95 {
     96     int error = 0;
     97     switch (aEvent.GetEventType())
     98     {
     99         case PVT_INDICATION_OUTGOING_TRACK:
    100         {
    101             TPVChannelId *channel_id = (TPVChannelId *)(&aEvent.GetLocalBuffer()[4]);
    102             printf("Indication with logical channel #%d ", *channel_id);
    103             if ((aEvent.GetLocalBuffer()[0] == PV_AUDIO) && !iSelAudioSource)
    104             {
    105                 iSelAudioSource = get_audio_source(iAudSrcFormatType);
    106                 if (iSelAudioSource != NULL)
    107                 {
    108                     OSCL_TRY(error, iAudioAddSourceId = terminal->AddDataSource(*channel_id, *iSelAudioSource));
    109                     printf("Audio");
    110                 }
    111             }
    112             else if ((aEvent.GetLocalBuffer()[0] == PV_VIDEO) && !iSelVideoSource)
    113             {
    114                 iSelVideoSource = get_video_source(iVidSrcFormatType);
    115                 if (iSelVideoSource != NULL)
    116                 {
    117                     OSCL_TRY(error, iVideoAddSourceId = terminal->AddDataSource(*channel_id, *iSelVideoSource));
    118                     printf("Video");
    119                 }
    120             }
    121             else
    122             {
    123                 printf("unknown");
    124             }
    125             printf(" outgoing Track\n");
    126             break;
    127         }
    128 
    129         case PVT_INDICATION_INCOMING_TRACK:
    130         {
    131             TPVChannelId *channel_id = (TPVChannelId *)(&aEvent.GetLocalBuffer()[4]);
    132             printf("Indication with logical channel #%d ", *channel_id);
    133             if ((aEvent.GetLocalBuffer()[0] == PV_AUDIO) && !iSelAudioSink)
    134             {
    135                 iSelAudioSink = get_audio_sink(iAudSinkFormatType);
    136                 if (iSelAudioSink != NULL)
    137                 {
    138                     OSCL_TRY(error, iAudioAddSinkId = terminal->AddDataSink(*channel_id, *iSelAudioSink));
    139                     printf("Audio");
    140                 }
    141             }
    142             else if ((aEvent.GetLocalBuffer()[0] == PV_VIDEO) && !iSelVideoSink)
    143             {
    144                 iSelVideoSink = get_video_sink(iVidSinkFormatType);
    145                 if (iSelVideoSink != NULL)
    146                 {
    147                     OSCL_TRY(error, iVideoAddSinkId = terminal->AddDataSink(*channel_id, *iSelVideoSink));
    148                     printf("Video");
    149                 }
    150             }
    151             else
    152             {
    153                 printf("unknown");
    154             }
    155             printf(" incoming Track\n");
    156             break;
    157         }
    158 
    159         case PVT_INDICATION_DISCONNECT:
    160             iAudioSourceAdded = false;
    161             iVideoSourceAdded = false;
    162             iAudioSinkAdded = false;
    163             iVideoSinkAdded = false;
    164             break;
    165 
    166         case PVT_INDICATION_CLOSE_TRACK:
    167             break;
    168 
    169         case PVT_INDICATION_INTERNAL_ERROR:
    170             break;
    171 
    172         default:
    173             break;
    174     }
    175 }
    176 
    177 void av_test::InitFailed()
    178 {
    179     test_is_true(false);
    180     test_base::InitFailed();
    181 }
    182 
    183 void av_test::ConnectFailed()
    184 {
    185 }
    186 
    187 void av_test::AudioAddSinkCompleted()
    188 {
    189     iAudioSinkAdded = true;
    190     if (iAudioSourceAdded && iVideoSourceAdded && iVideoSinkAdded)
    191         timer->RunIfNotReady(TEST_DURATION);
    192 }
    193 
    194 void av_test::AudioAddSourceCompleted()
    195 {
    196     iAudioSourceAdded = true;
    197     if (iAudioSinkAdded && iVideoSourceAdded && iVideoSinkAdded)
    198         timer->RunIfNotReady(TEST_DURATION);
    199 }
    200 
    201 void av_test::VideoAddSinkFailed()
    202 {
    203     VideoAddSinkSucceeded();
    204 }
    205 
    206 void av_test::VideoAddSinkSucceeded()
    207 {
    208     iVideoSinkAdded = true;
    209     if (iVideoSourceAdded && iAudioSourceAdded && iAudioSinkAdded)
    210         timer->RunIfNotReady(TEST_DURATION);
    211 }
    212 void av_test::VideoAddSourceSucceeded()
    213 {
    214     iVideoSourceAdded = true;
    215     if (iVideoSinkAdded && iAudioSourceAdded && iAudioSinkAdded)
    216         timer->RunIfNotReady(TEST_DURATION);
    217 }
    218 void av_test::VideoAddSourceFailed()
    219 {
    220     VideoAddSourceSucceeded();
    221 }
    222 
    223 void av_test::RstCmdCompleted()
    224 {
    225     test_is_true(true);
    226     test_base::RstCmdCompleted();
    227 }
    228 
    229 void av_test::CheckForTimeToDisconnect()
    230 {
    231     if (!iAudioSourceAdded &&
    232             !iAudioSinkAdded &&
    233             !iVideoSourceAdded &&
    234             !iVideoSinkAdded)
    235     {
    236         disconnect();
    237     }
    238 }
    239 
    240 void av_test::AudioRemoveSourceCompleted()
    241 {
    242     iAudioSourceAdded = false;
    243     CheckForTimeToDisconnect();
    244 }
    245 
    246 void av_test::AudioRemoveSinkCompleted()
    247 {
    248     iAudioSinkAdded = false;
    249     CheckForTimeToDisconnect();
    250 }
    251 void av_test::VideoRemoveSourceCompleted()
    252 {
    253     iVideoSourceAdded = false;
    254     CheckForTimeToDisconnect();
    255 }
    256 void av_test::VideoRemoveSinkCompleted()
    257 {
    258     iVideoSinkAdded = false;
    259     CheckForTimeToDisconnect();
    260 }
    261 
    262 
    263 
    264 void av_test::TimerCallback()
    265 {
    266     int error = 0;
    267 
    268     if (iSelVideoSource != NULL)
    269     {
    270         OSCL_TRY(error, iVideoRemoveSourceId = terminal->RemoveDataSource(*iSelVideoSource));
    271     }
    272     if (error)
    273     {
    274         iTestStatus &= false;
    275         disconnect();
    276     }
    277     else
    278     {
    279         error = 1;
    280         if (iSelVideoSink != NULL)
    281         {
    282             OSCL_TRY(error, iVideoRemoveSinkId = terminal->RemoveDataSink(*iSelVideoSink));
    283         }
    284         if (error)
    285         {
    286             iTestStatus &= false;
    287             disconnect();
    288         }
    289     }
    290 
    291     if (iSelAudioSource != NULL)
    292     {
    293         OSCL_TRY(error, iAudioRemoveSourceId = terminal->RemoveDataSource(*iSelAudioSource));
    294     }
    295     if (error)
    296     {
    297         iTestStatus &= false;
    298         disconnect();
    299     }
    300     else
    301     {
    302         error = 1;
    303         if (iSelAudioSink != NULL)
    304         {
    305             OSCL_TRY(error, iAudioRemoveSinkId = terminal->RemoveDataSink(*iSelAudioSink));
    306         }
    307         if (error)
    308         {
    309             iTestStatus &= false;
    310             disconnect();
    311         }
    312     }
    313 }
    314 
    315 bool av_test::start_async_test()
    316 {
    317     timer = new engine_timer(this);
    318     if (timer == NULL)
    319     {
    320         test_is_true(false);
    321         return false;
    322     }
    323     iAudioSourceAdded = false;
    324     iAudioSinkAdded = false;
    325 
    326     timer->AddToScheduler();
    327 
    328 
    329     return test_base::start_async_test();
    330 }
    331 
    332 
    333 
    334 
    335 
    336