diff --git a/modules/EightBitsSampling.cpp b/modules/EightBitsSampling.cpp index 8467b93..dbdd67c 100644 --- a/modules/EightBitsSampling.cpp +++ b/modules/EightBitsSampling.cpp @@ -45,6 +45,7 @@ EightBitsSampling::EightBitsSampling() bool EightBitsSampling::create( std::vector apcFrameList ) { + _BASIC_MODULE_API_2_CHECK_ m_iBitSifting = int( apcFrameList[0]->getBitsPel() ) - m_iNumberOfBits; if( !m_iBitSifting ) return false; diff --git a/modules/FilterComponent.cpp b/modules/FilterComponent.cpp index 9582abc..f8a7ffa 100644 --- a/modules/FilterComponent.cpp +++ b/modules/FilterComponent.cpp @@ -71,6 +71,7 @@ FilterComponentLuma::FilterComponentLuma() bool FilterComponentLuma::create( std::vector apcFrameList ) { + _BASIC_MODULE_API_2_CHECK_ return createFilter( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), apcFrameList[0]->getBitsPel() ); } @@ -88,6 +89,7 @@ FilterComponentChromaU::FilterComponentChromaU() bool FilterComponentChromaU::create( std::vector apcFrameList ) { + _BASIC_MODULE_API_2_CHECK_ if( apcFrameList[0]->getNumberChannels() > 1 ) { return createFilter( apcFrameList[0]->getWidth( CLP_CHROMA_U ), apcFrameList[0]->getHeight( CLP_CHROMA_U ), @@ -111,6 +113,7 @@ FilterComponentChromaV::FilterComponentChromaV() bool FilterComponentChromaV::create( std::vector apcFrameList ) { + _BASIC_MODULE_API_2_CHECK_ if( apcFrameList[0]->getNumberChannels() > 1 ) { return createFilter( apcFrameList[0]->getWidth( CLP_CHROMA_V ), apcFrameList[0]->getHeight( CLP_CHROMA_V ), diff --git a/modules/FrameResampling.cpp b/modules/FrameResampling.cpp index cf42a9d..ef22f20 100644 --- a/modules/FrameResampling.cpp +++ b/modules/FrameResampling.cpp @@ -57,6 +57,7 @@ FrameResampling::FrameResampling() bool FrameResampling::create( std::vector apcFrameList ) { + _BASIC_MODULE_API_2_CHECK_ switch( m_iInterpolation ) { case 2: diff --git a/modules/HEVCIntraPrediction.cpp b/modules/HEVCIntraPrediction.cpp index 730f7f5..1076ff6 100644 --- a/modules/HEVCIntraPrediction.cpp +++ b/modules/HEVCIntraPrediction.cpp @@ -62,6 +62,7 @@ HEVCIntraPrediction::HEVCIntraPrediction() bool HEVCIntraPrediction::create( std::vector apcFrameList ) { + _BASIC_MODULE_API_2_CHECK_ m_pcPredBlock = NULL; m_pcPredBlock = new CalypFrame( m_iBlockSize * 2 + 1, m_iBlockSize * 2 + 1, CLP_GRAY, apcFrameList[0]->getBitsPel() ); diff --git a/modules/ThreeSixtyFaceConcatenation.cpp b/modules/ThreeSixtyFaceConcatenation.cpp index 3a7e86f..3dd01d2 100644 --- a/modules/ThreeSixtyFaceConcatenation.cpp +++ b/modules/ThreeSixtyFaceConcatenation.cpp @@ -43,7 +43,9 @@ ThreeSixtyFaceConcatenation::ThreeSixtyFaceConcatenation() m_pchModuleName = "ThreeSixtyFaceConcatenation"; m_pchModuleTooltip = "Concatenate 360 video faces"; m_uiNumberOfFrames = 1; - m_uiModuleRequirements = CLP_MODULE_REQUIRES_SKIP_WHILE_PLAY | CLP_MODULES_VARIABLE_NUM_FRAMES; + m_uiModuleRequirements = CLP_MODULE_REQUIRES_SKIP_WHILE_PLAY | + CLP_MODULE_REQUIRES_OPTIONS | + CLP_MODULES_VARIABLE_NUM_FRAMES; m_cModuleOptions.addOptions() /**/ ( "projection", m_uiProjectionType, "Projection [1] \n 1: Cubemap (6 faces)" ) /**/ @@ -60,6 +62,8 @@ ThreeSixtyFaceConcatenation::ThreeSixtyFaceConcatenation() bool ThreeSixtyFaceConcatenation::create( std::vector apcFrameList ) { + if( apcFrameList.size() < 1 ) + return false; for( unsigned int i = 0; i < apcFrameList.size(); i++ ) if( !apcFrameList[i] ) return false; @@ -77,9 +81,12 @@ bool ThreeSixtyFaceConcatenation::create( std::vector apcFrameList m_uiFacesY = 2 * m_uiNumberOfPartitionsPerFace; break; default: - assert( 0 ); + return false; } + if( apcFrameList.size() != m_uiFacesX * m_uiFacesY ) + return false; + unsigned int width = apcFrameList[0]->getWidth() * m_uiFacesX; unsigned int height = apcFrameList[0]->getHeight() * m_uiFacesY; diff --git a/modules/tests/CMakeLists.txt b/modules/tests/CMakeLists.txt index 036ebfd..5a59ba3 100644 --- a/modules/tests/CMakeLists.txt +++ b/modules/tests/CMakeLists.txt @@ -11,4 +11,10 @@ FOREACH(module ${MODULES_LIST_NAME}) TARGET_COMPILE_DEFINITIONS(TestModuleCreate_${module} PUBLIC -DCALYP_TEST_MODULE_NAME=\"${module}\") TARGET_LINK_LIBRARIES(TestModuleCreate_${module} ${PROJECT_LIBRARY} CalypModules gtest gtest_main) ADD_TEST(TestModuleCreate_${module} TestModuleCreate_${module}) + + ADD_EXECUTABLE(TestModuleProcessNumberOfFrames_${module} TestModuleProcessNumberOfFrames.cpp) + TARGET_COMPILE_DEFINITIONS(TestModuleProcessNumberOfFrames_${module} PUBLIC -DCALYP_TEST_MODULE_NAME=\"${module}\") + TARGET_LINK_LIBRARIES(TestModuleProcessNumberOfFrames_${module} ${PROJECT_LIBRARY} CalypModules gtest gtest_main) + ADD_TEST(TestModuleProcessNumberOfFrames_${module} TestModuleProcessNumberOfFrames_${module}) + ENDFOREACH(module ${MODULES_LIST_NAME}) diff --git a/modules/tests/TestModuleCreate.cpp b/modules/tests/TestModuleCreate.cpp index a22e880..0defc40 100644 --- a/modules/tests/TestModuleCreate.cpp +++ b/modules/tests/TestModuleCreate.cpp @@ -19,13 +19,14 @@ /** * \file TestModuleCreate.cpp - * \brief CalypModuleIf testing for YUV420p sequences + * \brief CalypModuleIf testing create */ -#include "CalypFrame.h" -#include "CalypModulesFactory.h" -#include "CalypStream.h" #include "gtest/gtest.h" +#include "lib/CalypFrame.h" +#include "lib/CalypModuleIf.h" +#include "lib/CalypStream.h" +#include "modules/CalypModulesFactory.h" class TestModuleCreate : public ::testing::Test { @@ -35,6 +36,8 @@ protected: // Can be omitted if not needed. static void SetUpTestCase() { + ClpString moduleName = CALYP_TEST_MODULE_NAME; + pcStream = new CalypStream; pcStream->open( ClpString( CALYP_TEST_DATA_DIR ) + ClpString( "/BasketballDrill_F10_832x480_yuv420p.yuv" ), 832, 480, 0, 8, CLP_BIG_ENDIAN, 1, true ); @@ -50,66 +53,65 @@ protected: pcStream = NULL; } - // Some expensive resource shared by all tests. - static CalypStream* pcStream; - static CalypFrame* pcFrame; - static CalypModuleIf* pcModule; - static ClpString sModuleName; -}; - -CalypStream* TestModuleCreate::pcStream = NULL; -CalypFrame* TestModuleCreate::pcFrame = NULL; -ClpString TestModuleCreate::sModuleName = CALYP_TEST_MODULE_NAME; - -TEST_F( TestModuleCreate, FIND_MODULE ) -{ - CalypModuleIf* module; - CalypModulesFactoryMap& moduleFactoryMap = CalypModulesFactory::Get()->getMap(); - CalypModulesFactoryMap::iterator it = moduleFactoryMap.begin(); - for( unsigned int i = 0; it != moduleFactoryMap.end(); ++it, i++ ) + // Called before each test + void SetUp() { - if( strcmp( it->first, sModuleName.c_str() ) == 0 ) + ClpString moduleName = CALYP_TEST_MODULE_NAME; + + CalypModulesFactoryMap& moduleFactoryMap = CalypModulesFactory::Get()->getMap(); + CalypModulesFactoryMap::iterator it = moduleFactoryMap.begin(); + for( unsigned int i = 0; it != moduleFactoryMap.end(); ++it, i++ ) { - module = it->second(); - break; + if( strcmp( it->first, moduleName.c_str() ) == 0 ) + { + pcModule = it->second(); + break; + } } } - EXPECT_NE( module, nullptr ); - module->Delete(); + void TearDown() + { + pcModule->Delete(); + } + + CalypModuleIf* pcModule; + + // Some expensive resource shared by all tests. + static CalypStream* pcStream; +}; + +CalypStream* TestModuleCreate::pcStream = NULL; + +TEST_F( TestModuleCreate, FIND_MODULE ) +{ + EXPECT_NE( pcModule, nullptr ); } TEST_F( TestModuleCreate, CREATE_OK ) { - CalypModuleIf* module; - CalypModulesFactoryMap& moduleFactoryMap = CalypModulesFactory::Get()->getMap(); - CalypModulesFactoryMap::iterator it = moduleFactoryMap.begin(); - for( unsigned int i = 0; it != moduleFactoryMap.end(); ++it, i++ ) + bool moduleRequireOptions = false; + if( pcModule->m_uiModuleRequirements & CLP_MODULE_REQUIRES_OPTIONS ) { - if( strcmp( it->first, sModuleName.c_str() ) == 0 ) - { - module = it->second(); - break; - } + moduleRequireOptions = true; } - EXPECT_NE( module, nullptr ); bool moduleCreated = false; std::vector apcFrameList; apcFrameList.clear(); - for( unsigned int i = 0; i < module->m_uiNumberOfFrames; i++ ) + for( unsigned int i = 0; i < pcModule->m_uiNumberOfFrames; i++ ) { apcFrameList.push_back( pcStream->getCurrFrame() ); pcStream->setNextFrame(); pcStream->readNextFrame(); } - if( module->m_iModuleAPI >= CLP_MODULE_API_2 ) + if( pcModule->m_iModuleAPI >= CLP_MODULE_API_2 ) { - moduleCreated = module->create( apcFrameList ); + moduleCreated = pcModule->create( apcFrameList ) | moduleRequireOptions; } - else if( module->m_iModuleAPI == CLP_MODULE_API_1 ) + else if( pcModule->m_iModuleAPI == CLP_MODULE_API_1 ) { - module->create( pcStream->getCurrFrame() ); + pcModule->create( pcStream->getCurrFrame() ); moduleCreated = true; } EXPECT_EQ( moduleCreated, true ); @@ -117,72 +119,47 @@ TEST_F( TestModuleCreate, CREATE_OK ) TEST_F( TestModuleCreate, CREATE_FAIL_LESS_ONE ) { - CalypModuleIf* module; - CalypModulesFactoryMap& moduleFactoryMap = CalypModulesFactory::Get()->getMap(); - CalypModulesFactoryMap::iterator it = moduleFactoryMap.begin(); - for( unsigned int i = 0; it != moduleFactoryMap.end(); ++it, i++ ) + if( pcModule->m_iModuleAPI >= CLP_MODULE_API_2 ) { - if( strcmp( it->first, sModuleName.c_str() ) == 0 ) + std::vector apcFrameList; + apcFrameList.clear(); + for( unsigned int i = 0; i < pcModule->m_uiNumberOfFrames - 1; i++ ) { - module = it->second(); - break; + apcFrameList.push_back( pcStream->getCurrFrame() ); + pcStream->setNextFrame(); + pcStream->readNextFrame(); } + bool moduleCreated = pcModule->create( apcFrameList ); + EXPECT_NE( moduleCreated, true ); } - EXPECT_NE( module, nullptr ); - - bool moduleCreated = false; - std::vector apcFrameList; - apcFrameList.clear(); - for( unsigned int i = 0; i < module->m_uiNumberOfFrames - 1; i++ ) - { - apcFrameList.push_back( pcStream->getCurrFrame() ); - pcStream->setNextFrame(); - pcStream->readNextFrame(); - } - if( module->m_iModuleAPI >= CLP_MODULE_API_2 ) - { - moduleCreated = module->create( apcFrameList ); - } - else if( module->m_iModuleAPI == CLP_MODULE_API_1 ) - { - module->create( pcStream->getCurrFrame() ); - moduleCreated = true; - } - EXPECT_NE( moduleCreated, true ); } TEST_F( TestModuleCreate, CREATE_FAIL_PLUS_ONE ) { - CalypModuleIf* module; - CalypModulesFactoryMap& moduleFactoryMap = CalypModulesFactory::Get()->getMap(); - CalypModulesFactoryMap::iterator it = moduleFactoryMap.begin(); - for( unsigned int i = 0; it != moduleFactoryMap.end(); ++it, i++ ) + if( pcModule->m_iModuleAPI >= CLP_MODULE_API_2 ) { - if( strcmp( it->first, sModuleName.c_str() ) == 0 ) + std::vector apcFrameList; + apcFrameList.clear(); + for( unsigned int i = 0; i < pcModule->m_uiNumberOfFrames + 1; i++ ) { - module = it->second(); - break; + apcFrameList.push_back( NULL ); } + bool moduleCreated = pcModule->create( apcFrameList ); + EXPECT_NE( moduleCreated, true ); } - EXPECT_NE( module, nullptr ); +} - bool moduleCreated = false; - std::vector apcFrameList; - apcFrameList.clear(); - for( unsigned int i = 0; i < module->m_uiNumberOfFrames + 1; i++ ) +TEST_F( TestModuleCreate, CREATE_FAIL_NULL_FRAME ) +{ + if( pcModule->m_iModuleAPI >= CLP_MODULE_API_2 ) { - apcFrameList.push_back( pcStream->getCurrFrame() ); - pcStream->setNextFrame(); - pcStream->readNextFrame(); + std::vector apcFrameList; + apcFrameList.clear(); + for( unsigned int i = 0; i < pcModule->m_uiNumberOfFrames - 1; i++ ) + { + apcFrameList.push_back( NULL ); + } + bool moduleCreated = pcModule->create( apcFrameList ); + EXPECT_NE( moduleCreated, true ); } - if( module->m_iModuleAPI >= CLP_MODULE_API_2 ) - { - moduleCreated = module->create( apcFrameList ); - } - else if( module->m_iModuleAPI == CLP_MODULE_API_1 ) - { - module->create( pcStream->getCurrFrame() ); - moduleCreated = true; - } - EXPECT_NE( moduleCreated, true ); -} \ No newline at end of file +} diff --git a/modules/tests/TestModuleProcessNumberOfFrames.cpp b/modules/tests/TestModuleProcessNumberOfFrames.cpp new file mode 100644 index 0000000..c128d37 --- /dev/null +++ b/modules/tests/TestModuleProcessNumberOfFrames.cpp @@ -0,0 +1,110 @@ +/* This file is a part of plaYUVer project + * Copyright (C) 2014-2021 by Joao Carreira (jfmcarreira@gmail.com) + * Luis Lucas (luisfrlucas@gmail.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/** + * \file TestModuleCreate.cpp + * \brief CalypModuleIf testing for YUV420p sequences + */ + +#include "gtest/gtest.h" +#include "lib/CalypFrame.h" +#include "lib/CalypModuleIf.h" +#include "lib/CalypStream.h" +#include "modules/CalypModulesFactory.h" + +class TestModuleProcessNumberOfFrames : public ::testing::Test +{ +protected: + // Per-test-case set-up. + // Called before the first test in this test case. + // Can be omitted if not needed. + static void SetUpTestCase() + { + ClpString moduleName = CALYP_TEST_MODULE_NAME; + + pcStream = new CalypStream; + pcStream->open( ClpString( CALYP_TEST_DATA_DIR ) + ClpString( "/BasketballDrill_F10_832x480_yuv420p.yuv" ), 832, 480, 0, 8, + CLP_BIG_ENDIAN, 1, true ); + } + + // Per-test-case tear-down. + // Called after the last test in this test case. + // Can be omitted if not needed. + static void TearDownTestCase() + { + pcStream->close(); + delete pcStream; + pcStream = NULL; + } + + // Called before each test + void SetUp() + { + ClpString moduleName = CALYP_TEST_MODULE_NAME; + + pcStream = new CalypStream; + pcStream->open( ClpString( CALYP_TEST_DATA_DIR ) + ClpString( "/BasketballDrill_F10_832x480_yuv420p.yuv" ), 832, 480, 0, 8, + CLP_BIG_ENDIAN, 1, true ); + + CalypModulesFactoryMap& moduleFactoryMap = CalypModulesFactory::Get()->getMap(); + CalypModulesFactoryMap::iterator it = moduleFactoryMap.begin(); + for( unsigned int i = 0; it != moduleFactoryMap.end(); ++it, i++ ) + { + if( strcmp( it->first, moduleName.c_str() ) == 0 ) + { + pcModule = it->second(); + break; + } + } + } + + void TearDown() + { + pcModule->Delete(); + } + + CalypModuleIf* pcModule; + + // Some expensive resource shared by all tests. + static CalypStream* pcStream; +}; + +CalypStream* TestModuleProcessNumberOfFrames::pcStream = NULL; + +TEST_F( TestModuleProcessNumberOfFrames, PROCESS_OK ) +{ + if( pcModule->m_iModuleAPI >= CLP_MODULE_API_2 ) + { + std::vector apcFrameList; + apcFrameList.clear(); + for( unsigned int i = 0; i < pcModule->m_uiNumberOfFrames; i++ ) + { + apcFrameList.push_back( pcStream->getCurrFrame() ); + pcStream->setNextFrame(); + pcStream->readNextFrame(); + } + + // Let's not test the modules that are not able to be created + if( pcModule->create( apcFrameList ) ) + { + CalypFrame* frame = pcModule->process( apcFrameList ); + EXPECT_NE( frame, nullptr ); + } + } +}