-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* TestSignalGenerator code commit * saveOrCompare arguments changed * changed the tolerance of saveOrCompare * Removing test images from data * Adding fresh samples * Updating tolerance to 50 * Increasing tolerance to 100 * added download cap for saveorcompare made verbose * small fix in testcase * path fix for testcase * savefile implementation update * deleted old files * added new data * Fixed test offset mismatch issue * saveorcompare enhanced --------- Co-authored-by: Mradul Dubey <[email protected]> Co-authored-by: Vinayak Bhustali <[email protected]> Co-authored-by: zaki <[email protected]>
- Loading branch information
1 parent
a70b01f
commit 0990cd8
Showing
12 changed files
with
302 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#pragma once | ||
#include "Module.h" | ||
|
||
class TestSignalGeneratorProps : public ModuleProps | ||
{ | ||
public: | ||
TestSignalGeneratorProps() {} | ||
TestSignalGeneratorProps(int _width, int _height) | ||
: width(_width), height(_height) {} | ||
|
||
~TestSignalGeneratorProps() {} | ||
|
||
int width = 0; | ||
int height = 0; | ||
|
||
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); | ||
bool handlePropsChange(frame_sp &frame); | ||
|
||
|
||
private: | ||
class Detail; | ||
boost::shared_ptr<Detail> mDetail; | ||
size_t outputFrameSize; | ||
framemetadata_sp mOutputMetadata; | ||
std::string mOutputPinId; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
#include "TestSignalGeneratorSrc.h" | ||
#include "Module.h" | ||
#include <cstdlib> | ||
#include <cstdint> | ||
|
||
class TestSignalGenerator::Detail | ||
{ | ||
public: | ||
Detail(TestSignalGeneratorProps &_props) | ||
: mProps(_props), start_shade(0), end_shade(255), current_shade(start_shade) {} | ||
|
||
~Detail() {} | ||
|
||
bool generate(frame_sp &frame) | ||
{ | ||
auto frame_ptr = frame->data(); | ||
uint8_t* x = static_cast<uint8_t*>(frame_ptr); | ||
|
||
for (int height = 0; height < mProps.height * 1.5; height++) | ||
{ | ||
memset(x, current_shade, mProps.width); | ||
x += mProps.width; | ||
current_shade += 1; | ||
if (current_shade > end_shade) | ||
{ | ||
current_shade = start_shade; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
void setProps(const TestSignalGeneratorProps &_props) | ||
{ | ||
mProps = _props; | ||
reset(); | ||
} | ||
void reset() | ||
{ | ||
current_shade = start_shade; | ||
} | ||
|
||
TestSignalGeneratorProps mProps; | ||
uint8_t start_shade = 0; | ||
uint8_t end_shade = 255; | ||
uint8_t current_shade = 0; | ||
}; | ||
|
||
TestSignalGenerator::TestSignalGenerator(TestSignalGeneratorProps _props) | ||
: Module(SOURCE, "TestSignalGenerator", _props), outputFrameSize(0) | ||
{ | ||
mDetail.reset(new Detail(_props)); | ||
mOutputMetadata = framemetadata_sp(new RawImagePlanarMetadata(_props.width, _props.height, ImageMetadata::ImageType::YUV420, size_t(0), CV_8U)); | ||
mOutputPinId = addOutputPin(mOutputMetadata); | ||
} | ||
|
||
TestSignalGenerator::~TestSignalGenerator() | ||
{ | ||
mDetail->~Detail(); | ||
} | ||
|
||
bool TestSignalGenerator::validateOutputPins() | ||
{ | ||
if (getNumberOfOutputPins() != 1) | ||
{ | ||
LOG_ERROR << "<" << getId() << ">::validateOutputPins size is expected to be 1. Actual<" << getNumberOfOutputPins() << ">"; | ||
return false; | ||
} | ||
framemetadata_sp metadata = getFirstOutputMetadata(); | ||
auto frameType = metadata->getFrameType(); | ||
if (frameType != FrameMetadata::RAW_IMAGE_PLANAR) | ||
{ | ||
LOG_ERROR << "<" << getId() << ">::validateOutputPins output frameType should be RAW_IMAGE_PLANAR. Actual<" << frameType << ">"; | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
bool TestSignalGenerator::init() | ||
{ | ||
if (!Module::init()) | ||
{ | ||
return false; | ||
} | ||
outputFrameSize = (getProps().width * getProps().height * 3) >> 1; | ||
|
||
return true; | ||
} | ||
|
||
bool TestSignalGenerator::produce() | ||
{ | ||
auto mPinId = getOutputPinIdByType(FrameMetadata::RAW_IMAGE_PLANAR); | ||
frame_container frames; | ||
frame_sp frame = makeFrame(outputFrameSize); | ||
mDetail->generate(frame); | ||
frames.insert(make_pair(mPinId, frame)); | ||
send(frames); | ||
return true; | ||
} | ||
|
||
bool TestSignalGenerator::term() | ||
{ | ||
return Module::term(); | ||
} | ||
|
||
void TestSignalGenerator::setMetadata(framemetadata_sp &metadata) | ||
{ | ||
if (!metadata->isSet()) | ||
{ | ||
return; | ||
} | ||
} | ||
|
||
bool TestSignalGenerator::handlePropsChange(frame_sp &frame) | ||
{ | ||
TestSignalGeneratorProps props; | ||
bool ret = Module::handlePropsChange(frame, props); | ||
mDetail->setProps(props); | ||
outputFrameSize = (props.width * props.height * 3) >> 1; | ||
return ret; | ||
} | ||
|
||
void TestSignalGenerator::setProps(TestSignalGeneratorProps &props) | ||
{ | ||
Module::addPropsToQueue(props); | ||
} | ||
|
||
TestSignalGeneratorProps TestSignalGenerator::getProps() | ||
{ | ||
return mDetail->mProps; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#include "TestSignalGeneratorSrc.h" | ||
#include "Module.h" | ||
#include "RawImageMetadata.h" | ||
#include <boost/test/unit_test.hpp> | ||
#include <boost/filesystem.hpp> | ||
#include "PipeLine.h" | ||
#include "test_utils.h" | ||
#include "ExternalSinkModule.h" | ||
#include "FrameContainerQueue.h" | ||
#include"FileWriterModule.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(400, 400))); | ||
auto sink = boost::shared_ptr<ExternalSinkModule>(new ExternalSinkModule()); | ||
source->setNext(sink); | ||
BOOST_TEST(source->init()); | ||
BOOST_TEST(sink->init()); | ||
source->step(); | ||
auto frames = sink->try_pop(); | ||
BOOST_TEST(frames.size() == 1); | ||
auto outputFrame = frames.cbegin()->second; | ||
BOOST_TEST(outputFrame->getMetadata()->getFrameType() == FrameMetadata::RAW_IMAGE_PLANAR); | ||
const uint8_t* pReadDataTest = const_cast<const uint8_t *>(static_cast<uint8_t *>(outputFrame->data())); | ||
unsigned int readDataSizeTest = outputFrame->size(); | ||
Test_Utils::saveOrCompare("./data/TestSample.raw", pReadDataTest, readDataSizeTest,0); | ||
} | ||
|
||
BOOST_AUTO_TEST_CASE(getSetProps) | ||
{ | ||
auto source = boost::shared_ptr<TestSignalGenerator>(new TestSignalGenerator(TestSignalGeneratorProps(640, 360))); | ||
auto sink = boost::shared_ptr<SinkModule>(new SinkModule(SinkModuleProps())); | ||
source->setNext(sink); | ||
source->init(); | ||
sink->init(); | ||
source->step(); | ||
auto sinkQue = sink->getQue(); | ||
frame_container frames; | ||
frames = sinkQue->pop(); | ||
auto frameMetadata = frames.begin()->second->getMetadata(); | ||
auto currentProps = source->getProps(); | ||
BOOST_TEST(frames.size() == 1); | ||
auto outputFrame = frames.cbegin()->second; | ||
BOOST_TEST(outputFrame->getMetadata()->getFrameType() == FrameMetadata::RAW_IMAGE_PLANAR); | ||
const uint8_t* pReadDataTest = const_cast<const uint8_t *>(static_cast<uint8_t *>(outputFrame->data())); | ||
unsigned int readDataSizeTest = outputFrame->size(); | ||
Test_Utils::saveOrCompare("./data/TestSample1.raw", pReadDataTest,readDataSizeTest, 0); | ||
TestSignalGeneratorProps newProps(400, 400); | ||
source->setProps(newProps); | ||
source->step(); | ||
sinkQue = sink->getQue(); | ||
frames = sinkQue->pop(); | ||
frameMetadata = frames.begin()->second->getMetadata(); | ||
BOOST_TEST(frames.size() == 1); | ||
outputFrame = frames.cbegin()->second; | ||
BOOST_TEST(outputFrame->getMetadata()->getFrameType() == FrameMetadata::RAW_IMAGE_PLANAR); | ||
pReadDataTest = const_cast<const uint8_t *>(static_cast<uint8_t *>(outputFrame->data())); | ||
readDataSizeTest = outputFrame->size(); | ||
Test_Utils::saveOrCompare("./data/TestSample2.raw",pReadDataTest,readDataSizeTest, 0); | ||
} | ||
|
||
BOOST_AUTO_TEST_SUITE_END() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.