Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

H264EncoderNvCodec tests fix #292

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
277 changes: 93 additions & 184 deletions base/test/h264Encodernvcodec_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,57 +20,6 @@

BOOST_AUTO_TEST_SUITE(h264encodernvcodec_tests)



BOOST_AUTO_TEST_CASE(yuv420_640x360,
* utf::precondition(if_h264_encoder_supported()))
{
Logger::setLogLevel("info");
auto cuContext = apracucontext_sp(new ApraCUcontext());

// metadata is known
auto width = 640;
auto height = 360;
uint32_t gopLength = 25;
uint32_t bitRateKbps = 1000;
uint32_t frameRate = 30;
H264EncoderNVCodecProps::H264CodecProfile profile = H264EncoderNVCodecProps::BASELINE;
bool enableBFrames = true;

auto fileReader = boost::shared_ptr<FileReaderModule>(new FileReaderModule(FileReaderModuleProps("./data/Raw_YUV420_640x360/Image???_YUV420.raw")));
auto metadata = framemetadata_sp(new RawImagePlanarMetadata(width, height, ImageMetadata::ImageType::YUV420, size_t(0), CV_8U));

auto rawImagePin = fileReader->addOutputPin(metadata);


auto cudaStream_ = boost::shared_ptr<ApraCudaStream>(new ApraCudaStream());

auto copyProps = CudaMemCopyProps(cudaMemcpyKind::cudaMemcpyHostToDevice, cudaStream_);
copyProps.sync = true;
auto copy = boost::shared_ptr<Module>(new CudaMemCopy(copyProps));
fileReader->setNext(copy);
auto encoder = boost::shared_ptr<Module>(new H264EncoderNVCodec(H264EncoderNVCodecProps(bitRateKbps, cuContext, gopLength, frameRate, profile, enableBFrames)));
copy->setNext(encoder);

auto fileWriter = boost::shared_ptr<Module>(new FileWriterModule(FileWriterModuleProps("./data/testOutput/h264images/Raw_YUV420_640x360????.h264")));
encoder->setNext(fileWriter);

BOOST_TEST(fileReader->init());
BOOST_TEST(copy->init());
BOOST_TEST(encoder->init());
BOOST_TEST(fileWriter->init());

fileReader->play(true);

for (auto i = 0; i < 43; i++)
{
fileReader->step();
copy->step();
encoder->step();
fileWriter->step();
}
}

BOOST_AUTO_TEST_CASE(yuv420_640x360_resize,
* utf::precondition(if_h264_encoder_supported()))
{
Expand All @@ -85,7 +34,9 @@ BOOST_AUTO_TEST_CASE(yuv420_640x360_resize,
auto width = 640;
auto height = 360;

auto fileReader = boost::shared_ptr<FileReaderModule>(new FileReaderModule(FileReaderModuleProps("./data/Raw_YUV420_640x360/Image???_YUV420.raw")));
auto fileReaderProps = FileReaderModuleProps("./data/Raw_YUV420_640x360/Image???_YUV420.raw");
fileReaderProps.readLoop = false;
auto fileReader = boost::shared_ptr<FileReaderModule>(new FileReaderModule(fileReaderProps));
auto metadata = framemetadata_sp(new RawImagePlanarMetadata(width, height, ImageMetadata::ImageType::YUV420, size_t(0), CV_8U));

auto rawImagePin = fileReader->addOutputPin(metadata);
Expand All @@ -107,27 +58,28 @@ BOOST_AUTO_TEST_CASE(yuv420_640x360_resize,
auto fileWriter = boost::shared_ptr<Module>(new FileWriterModule(FileWriterModuleProps(outFile[0],true)));
encoder->setNext(fileWriter);

BOOST_TEST(fileReader->init());
BOOST_TEST(copy->init());
BOOST_TEST(resize->init());
BOOST_TEST(sync->init());
BOOST_TEST(encoder->init());
BOOST_TEST(fileWriter->init());
boost::shared_ptr<PipeLine> p;
p = boost::shared_ptr<PipeLine>(new PipeLine("test"));
p->appendModule(fileReader);
if (!p->init())
{
throw AIPException(AIP_FATAL, "Engine Pipeline init failed. Check IPEngine Logs for more details.");
}

fileReader->play(true);
p->run_all_threaded();

Test_Utils::sleep_for_seconds(10);

for (auto i = 0; i < 42; i++)
{
fileReader->step();
copy->step();
resize->step();
sync->step();
encoder->step();
fileWriter->step();
}
p->stop();
p->term();
p->wait_for_all();
p.reset();
std::string fileComparePath = "./data/H264EncoderNvCodecTests/Raw_YUV420_640x360_to_160x90.h264";
uint8_t* frameData;
uint frameSize;
Test_Utils::readFile(outFile[0], (const uint8_t*&)frameData, frameSize);

Test_Utils::saveOrCompare(outFile[0], 0);
Test_Utils::saveOrCompare(fileComparePath.c_str(), (const unsigned char*)frameData, (size_t)frameSize, 0);
}

BOOST_AUTO_TEST_CASE(yuv420_640x360_sync,
Expand All @@ -146,7 +98,9 @@ BOOST_AUTO_TEST_CASE(yuv420_640x360_sync,
auto width = 640;
auto height = 360;

auto fileReader = boost::shared_ptr<FileReaderModule>(new FileReaderModule(FileReaderModuleProps("./data/Raw_YUV420_640x360/Image???_YUV420.raw")));
auto fileReaderProps = FileReaderModuleProps("./data/Raw_YUV420_640x360/Image???_YUV420.raw");
fileReaderProps.readLoop = false;
auto fileReader = boost::shared_ptr<FileReaderModule>(new FileReaderModule(fileReaderProps));
auto metadata = framemetadata_sp(new RawImagePlanarMetadata(width, height, ImageMetadata::ImageType::YUV420, size_t(0), CV_8U));

auto rawImagePin = fileReader->addOutputPin(metadata);
Expand All @@ -164,26 +118,30 @@ BOOST_AUTO_TEST_CASE(yuv420_640x360_sync,
auto fileWriter = boost::shared_ptr<Module>(new FileWriterModule(FileWriterModuleProps(outFile[0],true)));
encoder->setNext(fileWriter);

BOOST_TEST(fileReader->init());
BOOST_TEST(copy->init());
BOOST_TEST(sync->init());
BOOST_TEST(encoder->init());
BOOST_TEST(fileWriter->init());

fileReader->play(true);

boost::shared_ptr<PipeLine> p;
p = boost::shared_ptr<PipeLine>(new PipeLine("test"));
p->appendModule(fileReader);

for (auto i = 0; i < 42; i++)
if (!p->init())
{
fileReader->step();
copy->step();
sync->step();
encoder->step();
fileWriter->step();
throw AIPException(AIP_FATAL, "Engine Pipeline init failed. Check IPEngine Logs for more details.");
}

Test_Utils::saveOrCompare(outFile[0], 0);

p->run_all_threaded();

Test_Utils::sleep_for_seconds(10);

p->stop();
p->term();
p->wait_for_all();
p.reset();

std::string fileComparePath = "./data/H264EncoderNvCodecTests/Raw_YUV420_640x360.h264";
uint8_t* frameData;
uint frameSize;
Test_Utils::readFile(outFile[0], (const uint8_t*&)frameData, frameSize);

Test_Utils::saveOrCompare(fileComparePath.c_str(), (const unsigned char*)frameData, (size_t)frameSize, 0);
}

BOOST_AUTO_TEST_CASE(overlay_1920x960_BGRA,
Expand All @@ -203,7 +161,9 @@ BOOST_AUTO_TEST_CASE(overlay_1920x960_BGRA,
auto width = 1920;
auto height = 960;

auto fileReader = boost::shared_ptr<FileReaderModule>(new FileReaderModule(FileReaderModuleProps("./data/overlay_1920x960_BGRA.raw")));
auto fileReaderProps = FileReaderModuleProps("./data/overlay_1920x960_BGRA.raw");
fileReaderProps.readLoop = false;
auto fileReader = boost::shared_ptr<FileReaderModule>(new FileReaderModule(fileReaderProps));
auto metadata = framemetadata_sp(new RawImageMetadata(width, height, ImageMetadata::ImageType::BGRA, CV_8UC4, 0, CV_8U, FrameMetadata::HOST, true));

auto rawImagePin = fileReader->addOutputPin(metadata);
Expand All @@ -220,24 +180,30 @@ BOOST_AUTO_TEST_CASE(overlay_1920x960_BGRA,
auto fileWriter = boost::shared_ptr<Module>(new FileWriterModule(FileWriterModuleProps(outFile[0],true)));
encoder->setNext(fileWriter);

BOOST_TEST(fileReader->init());
BOOST_TEST(copy->init());
BOOST_TEST(encoder->init());
BOOST_TEST(fileWriter->init());
boost::shared_ptr<PipeLine> p;
p = boost::shared_ptr<PipeLine>(new PipeLine("test"));
p->appendModule(fileReader);

fileReader->play(true);


for (auto i = 0; i < 42; i++)
if (!p->init())
{
fileReader->step();
copy->step();
encoder->step();
fileWriter->step();
throw AIPException(AIP_FATAL, "Engine Pipeline init failed. Check IPEngine Logs for more details.");
}

Test_Utils::saveOrCompare(outFile[0], 0);

p->run_all_threaded();

Test_Utils::sleep_for_seconds(17);

p->stop();
p->term();
p->wait_for_all();
p.reset();

std::string fileComparePath = "./data/H264EncoderNvCodecTests/overlay_1920x960_BGRA.h264";
uint8_t* frameData;
uint frameSize;
Test_Utils::readFile(outFile[0], (const uint8_t*&)frameData, frameSize);

Test_Utils::saveOrCompare(fileComparePath.c_str(), (const unsigned char*)frameData, (size_t)frameSize, 0);
}

BOOST_AUTO_TEST_CASE(mono_1920x960,
Expand All @@ -256,7 +222,9 @@ BOOST_AUTO_TEST_CASE(mono_1920x960,
auto width = 1920;
auto height = 960;

auto fileReader = boost::shared_ptr<FileReaderModule>(new FileReaderModule(FileReaderModuleProps("./data/mono_1920x960.raw")));
auto fileReaderProps = FileReaderModuleProps("./data/mono_1920x960.raw");
fileReaderProps.readLoop = false;
auto fileReader = boost::shared_ptr<FileReaderModule>(new FileReaderModule(FileReaderModuleProps(fileReaderProps)));
auto metadata = framemetadata_sp(new RawImageMetadata(width, height, ImageMetadata::ImageType::MONO, CV_8UC1, 0, CV_8U, FrameMetadata::HOST, true));

auto rawImagePin = fileReader->addOutputPin(metadata);
Expand All @@ -278,87 +246,30 @@ BOOST_AUTO_TEST_CASE(mono_1920x960,
auto fileWriter = boost::shared_ptr<Module>(new FileWriterModule(FileWriterModuleProps(outFile[0],true)));
encoder->setNext(fileWriter);

BOOST_TEST(fileReader->init());
BOOST_TEST(copy->init());
BOOST_TEST(cc->init());
BOOST_TEST(sync->init());
BOOST_TEST(encoder->init());
BOOST_TEST(fileWriter->init());

fileReader->play(true);


for (auto i = 0; i < 42; i++)
boost::shared_ptr<PipeLine> p;
p = boost::shared_ptr<PipeLine>(new PipeLine("test"));
p->appendModule(fileReader);

if (!p->init())
{
fileReader->step();
copy->step();
cc->step();
sync->step();
encoder->step();
fileWriter->step();
throw AIPException(AIP_FATAL, "Engine Pipeline init failed. Check IPEngine Logs for more details.");
}

Test_Utils::saveOrCompare(outFile[0], 0);
}
p->run_all_threaded();

void mono_1920x960_ext_sink_()
{
auto cuContext = apracucontext_sp(new ApraCUcontext());
uint32_t gopLength = 25;
uint32_t bitRateKbps = 1000;
uint32_t frameRate = 30;
H264EncoderNVCodecProps::H264CodecProfile profile = H264EncoderNVCodecProps::BASELINE;
bool enableBFrames = 1;
// metadata is known
auto width = 1920;
auto height = 960;
Test_Utils::sleep_for_seconds(25);

auto fileReader = boost::shared_ptr<FileReaderModule>(new FileReaderModule(FileReaderModuleProps("./data/mono_1920x960.raw")));
auto metadata = framemetadata_sp(new RawImageMetadata(width, height, ImageMetadata::ImageType::MONO, CV_8UC1, 0, CV_8U, FrameMetadata::HOST, true));
p->stop();
p->term();
p->wait_for_all();
p.reset();

auto rawImagePin = fileReader->addOutputPin(metadata);

cudastream_sp cudaStream_ = boost::shared_ptr<ApraCudaStream>(new ApraCudaStream());
auto copyProps = CudaMemCopyProps(cudaMemcpyHostToDevice, cudaStream_);
auto copy = boost::shared_ptr<Module>(new CudaMemCopy(copyProps));
fileReader->setNext(copy);
std::string fileComparePath = "./data/H264EncoderNvCodecTests/mono_1920x960.h264";
uint8_t* frameData;
uint frameSize;
Test_Utils::readFile(outFile[0], (const uint8_t*&)frameData, frameSize);

auto cc = boost::shared_ptr<Module>(new CCNPPI(CCNPPIProps(ImageMetadata::YUV420, cudaStream_)));
copy->setNext(cc);

auto sync = boost::shared_ptr<Module>(new CudaStreamSynchronize(CudaStreamSynchronizeProps(cudaStream_)));
cc->setNext(sync);

auto encoder = boost::shared_ptr<Module>(new H264EncoderNVCodec(H264EncoderNVCodecProps(bitRateKbps, cuContext, gopLength, frameRate, profile, enableBFrames)));
sync->setNext(encoder);

auto sink = boost::shared_ptr<ExternalSinkModule>(new ExternalSinkModule());
encoder->setNext(sink);

BOOST_TEST(fileReader->init());
BOOST_TEST(copy->init());
BOOST_TEST(cc->init());
BOOST_TEST(sync->init());
BOOST_TEST(encoder->init());
BOOST_TEST(sink->init());

fileReader->play(true);

frame_sp frame;

for (auto i = 0; i < 5; i++)
{
fileReader->step();
copy->step();
cc->step();
sync->step();
encoder->step();
auto frames = sink->pop();
BOOST_TEST(frames.size() == 1);
frame = frames.cbegin()->second;
}


Test_Utils::saveOrCompare(fileComparePath.c_str(), (const unsigned char*)frameData, (size_t)frameSize, 0);
}

BOOST_AUTO_TEST_CASE(yuv420_640x360_pipeline, *boost::unit_test::disabled())
Expand All @@ -368,7 +279,7 @@ BOOST_AUTO_TEST_CASE(yuv420_640x360_pipeline, *boost::unit_test::disabled())
// metadata is known
auto width = 640;
auto height = 360;

auto fileReaderProps = FileReaderModuleProps("./data/Raw_YUV420_640x360/Image???_YUV420.raw");
fileReaderProps.fps = 10000;
auto fileReader = boost::shared_ptr<FileReaderModule>(new FileReaderModule(fileReaderProps));
Expand Down Expand Up @@ -397,21 +308,20 @@ BOOST_AUTO_TEST_CASE(yuv420_640x360_pipeline, *boost::unit_test::disabled())
Logger::setLogLevel(boost::log::trivial::severity_level::info);
p.run_all_threaded();

boost::this_thread::sleep_for(boost::chrono::seconds(10));
Logger::setLogLevel(boost::log::trivial::severity_level::error);
boost::this_thread::sleep_for(boost::chrono::seconds(20));
p.stop();
p.term();

p.wait_for_all();

}

BOOST_AUTO_TEST_CASE(mono_1920x960_pipeline, *boost::unit_test::disabled())
{
auto cuContext = apracucontext_sp(new ApraCUcontext());
auto width = 1920;
auto height = 960;

auto fileReaderProps = FileReaderModuleProps("./data/mono_1920x960.raw");
fileReaderProps.fps = 10000;
auto fileReader = boost::shared_ptr<FileReaderModule>(new FileReaderModule(fileReaderProps));
Expand Down Expand Up @@ -445,14 +355,13 @@ BOOST_AUTO_TEST_CASE(mono_1920x960_pipeline, *boost::unit_test::disabled())
Logger::setLogLevel(boost::log::trivial::severity_level::info);
p.run_all_threaded();

boost::this_thread::sleep_for(boost::chrono::seconds(10));
Logger::setLogLevel(boost::log::trivial::severity_level::error);
boost::this_thread::sleep_for(boost::chrono::seconds(20));

p.stop();
p.term();

p.wait_for_all();

}

BOOST_AUTO_TEST_SUITE_END()
Loading