Home | History | Annotate | Download | only in single_core
      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 /**
     19  * @file pvaetestinput.cpp
     20  * @brief Test input to PVAuthorEngine unit test, using single core encoders
     21  */
     22 
     23 #ifndef PVAETESTINPUT_H_INCLUDED
     24 #include "pvaetestinput.h"
     25 #endif
     26 #ifndef PVMF_NODE_INTERFACE_H_INCLUDED
     27 #include "pvmf_node_interface.h"
     28 #endif
     29 #ifndef PVMF_MEDIA_INPUT_NODE_FACTORY_H_INCLUDED
     30 #include "pvmf_media_input_node_factory.h"
     31 #endif
     32 #ifndef PVMI_MIO_FILEINPUT_FACTORY_H_INCLUDED
     33 #include "pvmi_mio_fileinput_factory.h"
     34 #endif
     35 #ifndef TEST_PV_AUTHOR_ENGINE_CONFIG_H_INCLUDED
     36 #include "test_pv_author_engine_config.h"
     37 #endif
     38 #ifndef OSCL_UTF8CONV_H
     39 #include "oscl_utf8conv.h"
     40 #endif
     41 
     42 extern const uint32 KVideoTimescale;
     43 extern const uint32 KNum20msFramesPerChunk;
     44 extern const uint32 KTextTimescale;
     45 extern const uint32 KTextFrameWidth;
     46 extern const uint32 KTextFrameHeight;
     47 
     48 
     49 ////////////////////////////////////////////////////////////////////////////
     50 PVAETestInput::PVAETestInput(const PVAETestInput& aInput)
     51 {
     52     Copy(aInput);
     53 }
     54 
     55 ////////////////////////////////////////////////////////////////////////////
     56 PVAETestInput& PVAETestInput::operator=(const PVAETestInput & aInput)
     57 {
     58     Copy(aInput);
     59     return (*this);
     60 }
     61 
     62 ////////////////////////////////////////////////////////////////////////////
     63 bool PVAETestInput::IsTestInputTypeSupported(PVAETestInputType aType)
     64 {
     65     switch (aType)
     66     {
     67         case YUV_FILE:
     68         case H263_FILE:
     69         case H264_FILE:
     70         case AMR_IETF_FILE:
     71         case AAC_ADIF_FILE:
     72         case AAC_ADTS_FILE:
     73         case PCM16_FILE:
     74         case YUV_WRONG_FILE:
     75         case TEXT_FILE:
     76         case AMRWB_IETF_FILE:
     77             return true;
     78 
     79         case M4V_FILE:
     80             return false;
     81 
     82         default:
     83             return false;
     84     }
     85 }
     86 
     87 ////////////////////////////////////////////////////////////////////////////
     88 int PVAETestInput::CreateInputNode(PVAETestInputType aType, const OSCL_wString& aFileName, AVTConfig iAVTConfig)
     89 {
     90     int status = false;
     91     switch (aType)
     92     {
     93         case YUV_FILE:
     94         case H263_FILE:
     95         case H264_FILE:
     96         case AMR_IETF_FILE:
     97         case AAC_ADIF_FILE:
     98         case AAC_ADTS_FILE:
     99         case PCM16_FILE:
    100         case YUV_WRONG_FILE:
    101         case TEXT_FILE:
    102         case AMRWB_IETF_FILE:
    103             status = CreateMIOInputNode(aType, aFileName, iAVTConfig);
    104             break;
    105 
    106         case M4V_FILE:
    107         default:
    108             status = -1;
    109             break;
    110     }
    111 
    112     return status;
    113 }
    114 
    115 ////////////////////////////////////////////////////////////////////////////
    116 bool PVAETestInput::DeleteInputNode()
    117 {
    118     for (uint32 i = 0; i < iExtensions.size(); i++)
    119         iExtensions[i]->removeRef();
    120     iExtensions.clear();
    121 
    122     switch (iType)
    123     {
    124         case YUV_FILE:
    125         case H263_FILE:
    126         case H264_FILE:
    127         case AMR_IETF_FILE:
    128         case AAC_ADIF_FILE:
    129         case AAC_ADTS_FILE:
    130         case PCM16_FILE:
    131         case YUV_WRONG_FILE:
    132         case TEXT_FILE:
    133         case AMRWB_IETF_FILE:
    134             if (iNode)
    135                 PvmfMediaInputNodeFactory::Delete(iNode);
    136             if (iMediaInput)
    137                 PvmiMIOFileInputFactory::Delete(iMediaInput);
    138         case M4V_FILE:
    139         default:
    140             break;
    141     }
    142 
    143     return true;
    144 }
    145 
    146 ////////////////////////////////////////////////////////////////////////////
    147 PVAETestInput::PVAETestInput()
    148 {
    149     iLogger = PVLogger::GetLoggerObject("PVAETestInput");
    150     iNode = NULL;
    151     iType = INVALID_INPUT_TYPE;
    152     iMediaInput = NULL;
    153 }
    154 
    155 ////////////////////////////////////////////////////////////////////////////
    156 void PVAETestInput::Copy(const PVAETestInput& aInput)
    157 {
    158     iNode = aInput.iNode;
    159     iType = aInput.iType;
    160     iSettings = aInput.iSettings;
    161     iExtensions = aInput.iExtensions;
    162     iMediaInput = aInput.iMediaInput;
    163 }
    164 
    165 ////////////////////////////////////////////////////////////////////////////
    166 bool PVAETestInput::CreateMIOInputNode(PVAETestInputType aType, const OSCL_wString& aFileName, AVTConfig iAVTConfig)
    167 {
    168     PVLOGGER_LOGMSG(PVLOGMSG_INST_REL, iLogger, PVLOGMSG_STACK_TRACE,
    169                     (0, "PVAETestInput::CreateMIOInputNode: aType=%d", aType));
    170 
    171     iType = aType;
    172 
    173     if (aFileName.get_size() != 0)
    174     {
    175         iSettings.iFileName = aFileName;
    176     }
    177     switch (aType)
    178     {
    179 
    180         case H263_FILE:
    181             if (aFileName.get_size() == 0)
    182             {
    183                 iSettings.iFileName = KH263TestInput;
    184             }
    185             iSettings.iMediaFormat = PVMF_MIME_H2631998;
    186             iSettings.iLoopInputFile = iAVTConfig.iLoopingEnable;
    187             iSettings.iTimescale = KVideoTimescale;
    188             iSettings.iFrameHeight = iAVTConfig.iHeight; //KVideoFrameHeight;
    189             iSettings.iFrameWidth = iAVTConfig.iWidth;//KVideoFrameWidth;
    190             iSettings.iFrameRate = iAVTConfig.iFps;//KVideoFrameRate;
    191             break;
    192 
    193         case H264_FILE:
    194             if (aFileName.get_size() == 0)
    195             {
    196                 iSettings.iFileName = KH264TestInput;
    197             }
    198             iSettings.iMediaFormat = PVMF_MIME_YUV420;
    199             iSettings.iLoopInputFile = iAVTConfig.iLoopingEnable;
    200             iSettings.iTimescale = KVideoTimescale;
    201             iSettings.iFrameHeight = iAVTConfig.iHeight; //KVideoFrameHeight;
    202             iSettings.iFrameWidth = iAVTConfig.iWidth;//KVideoFrameWidth;
    203             iSettings.iFrameRate = iAVTConfig.iFps;//KVideoFrameRate;
    204             break;
    205 
    206         case YUV_FILE:
    207             if (aFileName.get_size() == 0)
    208             {
    209                 iSettings.iFileName = KYUVTestInput;
    210             }
    211             iSettings.iMediaFormat = PVMF_MIME_YUV420;
    212             iSettings.iLoopInputFile = iAVTConfig.iLoopingEnable;
    213             iSettings.iTimescale = KVideoTimescale;
    214             iSettings.iFrameHeight = iAVTConfig.iHeight;
    215             iSettings.iFrameWidth = iAVTConfig.iWidth;
    216             iSettings.iFrameRate = iAVTConfig.iFps;
    217             break;
    218 
    219         case AMR_IETF_FILE:
    220             if (aFileName.get_size() == 0)
    221             {
    222                 iSettings.iFileName = KAMRTestInput;
    223             }
    224             iSettings.iMediaFormat = PVMF_MIME_AMR_IETF;
    225             iSettings.iLoopInputFile = iAVTConfig.iLoopingEnable;
    226             iSettings.iSamplingFrequency = iAVTConfig.iSamplingRate; //KAudioTimescale;
    227             iSettings.iNumChannels = iAVTConfig.iNumChannels;// KAudioNumChannels;
    228             iSettings.iNum20msFramesPerChunk = KNum20msFramesPerChunk;
    229             break;
    230 
    231         case AMRWB_IETF_FILE:
    232             if (aFileName.get_size() == 0)
    233             {
    234                 iSettings.iFileName = KAMRWBTestInput;
    235             }
    236             iSettings.iMediaFormat = PVMF_MIME_AMRWB_IETF;
    237             iSettings.iLoopInputFile = iAVTConfig.iLoopingEnable;
    238             iSettings.iSamplingFrequency = 16000; //AMR-WB is always sampled at 16KHz
    239             iSettings.iNumChannels = 1; //AMR-WB is always mono
    240             iSettings.iNum20msFramesPerChunk = KNum20msFramesPerChunk;
    241             break;
    242 
    243         case AAC_ADIF_FILE:
    244             if (aFileName.get_size() == 0)
    245             {
    246                 iSettings.iFileName = KAACADIFTestInput;
    247             }
    248             iSettings.iMediaFormat = PVMF_MIME_ADIF;
    249             iSettings.iLoopInputFile = iAVTConfig.iLoopingEnable;
    250             iSettings.iSamplingFrequency = iAVTConfig.iSamplingRate; //KAudioTimescale;
    251             iSettings.iNumChannels = iAVTConfig.iNumChannels;// KAudioNumChannels;
    252             iSettings.iNum20msFramesPerChunk = KNum20msFramesPerChunk;
    253             break;
    254         case AAC_ADTS_FILE:
    255             if (aFileName.get_size() == 0)
    256             {
    257                 iSettings.iFileName = KAACADTSTestInput;
    258             }
    259             iSettings.iMediaFormat = PVMF_MIME_ADTS;
    260             iSettings.iLoopInputFile = iAVTConfig.iLoopingEnable;
    261             iSettings.iSamplingFrequency = iAVTConfig.iSamplingRate; //KAudioTimescale;
    262             iSettings.iNumChannels = iAVTConfig.iNumChannels;// KAudioNumChannels;
    263             iSettings.iNum20msFramesPerChunk = KNum20msFramesPerChunk;
    264             break;
    265 
    266         case TEXT_FILE:
    267             if (aFileName.get_size() == 0)
    268             {
    269                 iSettings.iFileName = KTEXTTestInput;
    270                 iSettings.iLogFileName = KTEXTLogTestInput;
    271                 iSettings.iTextFileName = KTEXTTxtFileTestInput;
    272             }
    273             else
    274             {
    275                 if (iAVTConfig.iTextLogFile.get_size() == 0)
    276                 {
    277                     iSettings.iLogFileName = KTEXTLogTestInput;
    278                 }
    279                 else
    280                 {
    281                     oscl_wchar output1[ARRAY_SIZE];
    282                     oscl_UTF8ToUnicode(iAVTConfig.iTextLogFile.get_cstr(), iAVTConfig.iTextLogFile.get_size(), output1, ARRAY_SIZE);
    283                     iSettings.iLogFileName.set(output1, oscl_strlen(output1));
    284                 }
    285 
    286                 if (iAVTConfig.iTextConfigFile.get_size() == 0)
    287                 {
    288                     iSettings.iTextFileName = KTEXTTxtFileTestInput;
    289                 }
    290                 else
    291                 {
    292                     oscl_wchar output2[ARRAY_SIZE];
    293                     oscl_UTF8ToUnicode(iAVTConfig.iTextConfigFile.get_cstr(), iAVTConfig.iTextConfigFile.get_size(), output2, ARRAY_SIZE);
    294                     iSettings.iTextFileName.set(output2, oscl_strlen(output2));
    295                 }
    296             }
    297             iSettings.iMediaFormat = PVMF_MIME_3GPP_TIMEDTEXT;
    298             iSettings.iLoopInputFile = iAVTConfig.iLoopingEnable;
    299             iSettings.iSamplingFrequency = 0;
    300             iSettings.iNumChannels = 0;
    301             iSettings.iNum20msFramesPerChunk = 0;
    302             iSettings.iTimescale = KTextTimescale;
    303             iSettings.iFrameHeight = KTextFrameWidth;
    304             iSettings.iFrameWidth = KTextFrameHeight;
    305             break;
    306         default:
    307             return false;
    308     }
    309 
    310     iMediaInput = PvmiMIOFileInputFactory::Create(iSettings);
    311     if (!iMediaInput)
    312     {
    313         PVLOGGER_LOGMSG(PVLOGMSG_INST_REL, iLogger, PVLOGMSG_ERR,
    314                         (0, "PVAETestInput::CreateMIOInputNode: Error - PvmiMIOFileInputFactory::Create failed"));
    315         return false;
    316     }
    317 
    318     iNode = PvmfMediaInputNodeFactory::Create(iMediaInput);
    319     if (!iNode)
    320     {
    321         PVLOGGER_LOGMSG(PVLOGMSG_INST_REL, iLogger, PVLOGMSG_ERR,
    322                         (0, "PVAETestInput::CreateMIOInputNode: Error - PvmfMediaInputNodeFactory::Create failed"));
    323         return false;
    324     }
    325 
    326     return true;
    327 }
    328 
    329 
    330 
    331