Line data Source code
1 : /* 2 : * Copyright (C) 2004-2024 Savoir-faire Linux Inc. 3 : * 4 : * This program is free software: you can redistribute it and/or modify 5 : * it under the terms of the GNU General Public License as published by 6 : * the Free Software Foundation, either version 3 of the License, or 7 : * (at your option) any later version. 8 : * 9 : * This program is distributed in the hope that it will be useful, 10 : * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 : * GNU General Public License for more details. 13 : * 14 : * You should have received a copy of the GNU General Public License 15 : * along with this program. If not, see <https://www.gnu.org/licenses/>. 16 : */ 17 : 18 : #include <cppunit/TestAssert.h> 19 : #include <cppunit/TestFixture.h> 20 : #include <cppunit/extensions/HelperMacros.h> 21 : 22 : #include "jami.h" 23 : #include "videomanager_interface.h" 24 : #include "media/video/video_scaler.h" 25 : 26 : #include "../../../test_runner.h" 27 : 28 : namespace jami { namespace video { namespace test { 29 : 30 : class VideoScalerTest : public CppUnit::TestFixture { 31 : public: 32 2 : static std::string name() { return "video_scaler"; } 33 : 34 : void setUp(); 35 : void tearDown(); 36 : 37 : private: 38 : void testConvertFrame(); 39 : void testScale(); 40 : void testScaleWithAspect(); 41 : 42 2 : CPPUNIT_TEST_SUITE(VideoScalerTest); 43 1 : CPPUNIT_TEST(testConvertFrame); 44 1 : CPPUNIT_TEST(testScale); 45 1 : CPPUNIT_TEST(testScaleWithAspect); 46 4 : CPPUNIT_TEST_SUITE_END(); 47 : 48 : std::unique_ptr<VideoScaler> scaler_; 49 : }; 50 : 51 : 52 : CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(VideoScalerTest, VideoScalerTest::name()); 53 : 54 : void 55 3 : VideoScalerTest::setUp() 56 : { 57 3 : libjami::init(libjami::InitFlag(libjami::LIBJAMI_FLAG_DEBUG | libjami::LIBJAMI_FLAG_CONSOLE_LOG)); 58 3 : } 59 : 60 : void 61 3 : VideoScalerTest::tearDown() 62 : { 63 3 : libjami::fini(); 64 3 : } 65 : 66 : void 67 1 : VideoScalerTest::testConvertFrame() 68 : { 69 1 : scaler_.reset(new VideoScaler); 70 : 71 1 : libjami::VideoFrame input; 72 1 : input.reserve(AV_PIX_FMT_YUV420P, 100, 100); 73 1 : auto output = scaler_->convertFormat(input, AV_PIX_FMT_RGB24); 74 1 : CPPUNIT_ASSERT(static_cast<AVPixelFormat>(output->format()) == AV_PIX_FMT_RGB24); 75 1 : } 76 : 77 : void 78 1 : VideoScalerTest::testScale() 79 : { 80 1 : scaler_.reset(new VideoScaler); 81 : 82 1 : libjami::VideoFrame input, output; 83 1 : input.reserve(AV_PIX_FMT_YUV420P, 100, 100); 84 1 : output.reserve(AV_PIX_FMT_YUV420P, 200, 200); 85 1 : scaler_->scale(input, output); 86 1 : CPPUNIT_ASSERT(static_cast<AVPixelFormat>(output.format()) == AV_PIX_FMT_YUV420P); 87 1 : CPPUNIT_ASSERT(output.width() == 200); 88 1 : CPPUNIT_ASSERT(output.height() == 200); 89 1 : } 90 : 91 : void 92 1 : VideoScalerTest::testScaleWithAspect() 93 : { 94 1 : scaler_.reset(new VideoScaler); 95 : 96 1 : libjami::VideoFrame input, output; 97 1 : input.reserve(AV_PIX_FMT_YUV420P, 320, 240); // 4:3 98 1 : output.reserve(AV_PIX_FMT_YUV420P, 640, 360); // 16:9 99 1 : scaler_->scale_with_aspect(input, output); 100 1 : CPPUNIT_ASSERT(static_cast<AVPixelFormat>(output.format()) == AV_PIX_FMT_YUV420P); 101 1 : CPPUNIT_ASSERT(output.width() == 640); 102 1 : CPPUNIT_ASSERT(output.height() == 360); 103 1 : } 104 : 105 : }}} // namespace jami::test 106 : 107 1 : RING_TEST_RUNNER(jami::video::test::VideoScalerTest::name());