Skip to content

Commit

Permalink
TestSignal Generator Updated Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
VishwanathB45 committed Jul 14, 2023
1 parent 00cbf48 commit f60c507
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 87 deletions.
33 changes: 21 additions & 12 deletions base/include/TestSignalGeneratorSrc.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,44 @@
class TestSignalGeneratorProps : public ModuleProps
{
public:
TestSignalGeneratorProps()
{
}
TestSignalGeneratorProps() {}
TestSignalGeneratorProps(int _width, int _height)
{
width = _width;
height = _height;
}
~TestSignalGeneratorProps()
{
}
: width(_width), height(_height){}

~TestSignalGeneratorProps() {}

int width;
int height;

private:
friend class boost::serialization::access;

template <class Archive>
void serialize(Archive& ar, const unsigned int version)
{
ar & boost::serialization::base_object<ModuleProps>(*this);
ar & width;
ar & height;
}
};

class TestSignalGenerator : public Module
{
public:
TestSignalGenerator(TestSignalGeneratorProps _props);
~TestSignalGenerator();

bool init();
bool term();
void setProps(TestSignalGeneratorProps& props);
TestSignalGeneratorProps getProps();

protected:
bool produce();
bool validateOutputPins();
void setMetadata(framemetadata_sp &metadata);
void setMetadata(framemetadata_sp& metadata);

private:
class Detail;
boost::shared_ptr<Detail> mDetail;
};
};
51 changes: 26 additions & 25 deletions base/src/TestSignalGeneratorSrc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,21 @@
class TestSignalGenerator::Detail
{
public:
Detail(TestSignalGeneratorProps &_props) : mProps(_props)
{
}
Detail(TestSignalGeneratorProps &_props) : mProps(_props), start_shade(0), end_shade(255), current_shade(start_shade){}


~Detail()
{
}
void setProps(TestSignalGeneratorProps _props)
{
mProps = _props;
}
~Detail(){}

bool generate(frame_sp &frame)
{
auto *frame_ptr = frame->data();
int start_shade = 0;
int end_shade = 255;
int steps = mProps.height / 3;
int step = (end_shade - start_shade) / steps;
int current_shade = start_shade;
int *x = static_cast<int *>(frame_ptr);

for (int height = 0; height < steps; height++)
uint8_t *x = static_cast<uint8_t *>(frame_ptr);

for (int height = 0; height < mProps.height; height++)
{
// Loop of rows
memset(x, (uint8_t)current_shade, mProps.width);
memset(x, static_cast<uint8_t>(current_shade), mProps.width);
x += mProps.width;
// Update the shade value
current_shade += step;
current_shade += 1;
if (current_shade > end_shade)
{
current_shade = start_shade;
Expand All @@ -42,8 +29,10 @@ class TestSignalGenerator::Detail
return true;
}

public:
TestSignalGeneratorProps mProps;
int start_shade;
int end_shade;
int current_shade;
};

TestSignalGenerator::TestSignalGenerator(TestSignalGeneratorProps _props)
Expand Down Expand Up @@ -85,7 +74,7 @@ bool TestSignalGenerator::init()

bool TestSignalGenerator::produce()
{
size_t read_size = (mDetail->mProps.width * mDetail->mProps.height * 3) >> 1;
size_t read_size = (getProps().width * getProps().height * 3) >> 1;
auto mPinId = getOutputPinIdByType(FrameMetadata::RAW_IMAGE_PLANAR);
frame_container frames;
frame_sp frame = makeFrame(read_size);
Expand All @@ -106,4 +95,16 @@ void TestSignalGenerator::setMetadata(framemetadata_sp &metadata)
{
return;
}
}
}

TestSignalGeneratorProps TestSignalGenerator::getProps()
{
return mDetail->mProps;
}

void TestSignalGenerator::setProps(TestSignalGeneratorProps& _props)
{
mDetail->mProps = _props;
}


112 changes: 62 additions & 50 deletions base/test/testSignalGeneratorSrc_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,76 +2,88 @@
#include "Module.h"
#include "RawImageMetadata.h"
#include <boost/test/unit_test.hpp>
#include "FileWriterModule.h"
#include <boost/filesystem.hpp>
#include "PipeLine.h"
#include "StatSink.h"
#include "test_utils.h"
#include "ExternalSinkModule.h"
#include "FrameContainerQueue.h"

BOOST_AUTO_TEST_SUITE(TestSignalGenerator_tests)

class SinkModuleProps : public ModuleProps
{
public:
SinkModuleProps() : ModuleProps(){};
};

class SinkModule : public Module
{
public:
SinkModule(SinkModuleProps props) : Module(SINK, "sinkModule", props){};
boost::shared_ptr<FrameContainerQueue> getQue() { return Module::getQue(); }

protected:
bool validateOutputPins()
{
return true;
}
bool validateInputPins()
{
return true;
}
};

BOOST_AUTO_TEST_CASE(Basic)
{
auto source = boost::shared_ptr<TestSignalGenerator>(new TestSignalGenerator(TestSignalGeneratorProps(640, 360)));
auto metadata = framemetadata_sp(new RawImagePlanarMetadata(640, 360, ImageMetadata::ImageType::YUV420, size_t(0), CV_8U));
auto source = boost::shared_ptr<TestSignalGenerator>(new TestSignalGenerator(TestSignalGeneratorProps(400, 400)));
auto metadata = framemetadata_sp(new RawImagePlanarMetadata(400, 400, ImageMetadata::ImageType::YUV420, size_t(0), CV_8U));
source->addOutputPin(metadata);
auto sink = boost::shared_ptr<ExternalSinkModule>(new ExternalSinkModule());
source->setNext(sink);
source->init();
sink->init();
BOOST_TEST(source->init());
BOOST_TEST(sink->init());
source->step();
auto frame = sink->pop();
auto frameMetadata = frame.begin()->second->getMetadata();
BOOST_ASSERT(frameMetadata->getFrameType() == FrameMetadata::RAW_IMAGE_PLANAR);
}

BOOST_AUTO_TEST_CASE(statsink)
{
auto source = boost::shared_ptr<TestSignalGenerator>(new TestSignalGenerator(TestSignalGeneratorProps()));
auto metadata = framemetadata_sp(new RawImagePlanarMetadata(640, 360, ImageMetadata::ImageType::YUV420, size_t(0), CV_8U));
source->addOutputPin(metadata);
auto sink = boost::shared_ptr<Module>(new StatSink());
source->setNext(sink);
boost::shared_ptr<PipeLine> p;
p = boost::shared_ptr<PipeLine>(new PipeLine("test"));
p->appendModule(source);
if (!p->init())
{
throw AIPException(AIP_FATAL, "Engine Pipeline init failed. Check IPEngine Logs for more details.");
}
p->run_all_threaded();
boost::this_thread::sleep_for(boost::chrono::seconds(2));
p->stop();
p->term();
p->wait_for_all();
p.reset();
auto frames = sink->try_pop();
BOOST_TEST(frames.size() == 1);
auto outputFrame = frames.cbegin()->second;
BOOST_TEST(outputFrame->getMetadata()->getFrameType() == FrameMetadata::RAW_IMAGE_PLANAR);
Test_Utils::saveOrCompare("./data/testOutput/TestSample.raw", const_cast<const uint8_t *>(static_cast<uint8_t *>(outputFrame->data())), outputFrame->size(), 0);
}

BOOST_AUTO_TEST_CASE(fileWriterSink)
BOOST_AUTO_TEST_CASE(PropsChange)
{
std::vector<std::string> Files = {"./data/testsample1.raw"};
Test_Utils::FileCleaner f(Files);
auto source = boost::shared_ptr<TestSignalGenerator>(new TestSignalGenerator(TestSignalGeneratorProps(640, 360)));
auto metadata = framemetadata_sp(new RawImagePlanarMetadata(640, 360, ImageMetadata::ImageType::YUV420, size_t(0), CV_8U));
source->addOutputPin(metadata);

auto sink = boost::shared_ptr<FileWriterModule>(new FileWriterModule(FileWriterModuleProps("./data/testsample1.raw")));
auto sink = boost::shared_ptr<SinkModule>(new SinkModule(SinkModuleProps()));
source->setNext(sink);

boost::shared_ptr<PipeLine> p;
p = boost::shared_ptr<PipeLine>(new PipeLine("test"));
p->appendModule(source);
if (!p->init())
{
throw AIPException(AIP_FATAL, "Engine Pipeline init failed. Check IPEngine Logs for more details.");
}
p->run_all_threaded();
boost::this_thread::sleep_for(boost::chrono::seconds(1));
p->stop();
p->term();
p->wait_for_all();
p.reset();
source->init();
sink->init();
source->step();
auto sinkQue = sink->getQue();
auto framedata = sinkQue->pop();
auto frameMetadata = framedata.begin()->second->getMetadata();
auto size = frameMetadata->getDataSize() / 1.5;
auto currentProps = source->getProps();
BOOST_ASSERT(size == currentProps.width * currentProps.height);
BOOST_TEST(framedata.size() == 1);
auto outputFrame = framedata.cbegin()->second;
BOOST_TEST(outputFrame->getMetadata()->getFrameType() == FrameMetadata::RAW_IMAGE_PLANAR);
Test_Utils::saveOrCompare("./data/testOutput/TestSample1.raw", const_cast<const uint8_t *>(static_cast<uint8_t *>(outputFrame->data())), outputFrame->size(), 0);
TestSignalGeneratorProps propsChange(400, 400);
source->setProps(propsChange);
source->step();
source->step();
auto secondque = sink->getQue();
auto framedata2 = secondque->pop();
auto frameMetadata2 = framedata2.begin()->second->getMetadata();
auto size2 = frameMetadata2->getDataSize() / 1.5;
auto currentProps2 = source->getProps();
BOOST_ASSERT(size2 == currentProps2.width * currentProps2.height);
BOOST_TEST(framedata2.size() == 1);
auto outputFrame2 = framedata2.cbegin()->second;
BOOST_TEST(outputFrame2->getMetadata()->getFrameType() == FrameMetadata::RAW_IMAGE_PLANAR);
Test_Utils::saveOrCompare("./data/testOutput/TestSample2.raw", const_cast<const uint8_t *>(static_cast<uint8_t *>(outputFrame2->data())), outputFrame2->size(), 0);
}

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit f60c507

Please sign in to comment.