Skip to content
Snippets Groups Projects
Commit 6d8b75c8 authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Remove use of definition in encoder

parent 2b1b2b17
No related branches found
No related tags found
1 merge request!311Resolves #296 removal of NvPipe
This commit is part of merge request !311. Comments created here will be created in the context of that merge request.
...@@ -36,18 +36,14 @@ struct IndexHeader { ...@@ -36,18 +36,14 @@ struct IndexHeader {
*/ */
struct Packet { struct Packet {
ftl::codecs::codec_t codec; ftl::codecs::codec_t codec;
ftl::codecs::definition_t definition; // Data resolution
union { union {
[[deprecated]] uint8_t block_total; // v1-3 Packets expected per frame [[deprecated]] ftl::codecs::definition_t definition; // Data resolution
uint8_t frame_count; // v4+ Frames included in this packet uint8_t reserved=0;
}; };
union { uint8_t frame_count; // v4+ Frames included in this packet
[[deprecated]] uint8_t block_number; // v1-3 This packets number within a frame
uint8_t bitrate=0; // v4+ For multi-bitrate encoding, 0=highest uint8_t bitrate=0; // v4+ For multi-bitrate encoding, 0=highest
};
uint8_t flags; // Codec dependent flags (eg. I-Frame or P-Frame) uint8_t flags; // Codec dependent flags (eg. I-Frame or P-Frame)
std::vector<uint8_t> data; std::vector<uint8_t> data;
......
...@@ -104,8 +104,8 @@ static ftl::codecs::NvidiaEncoder::Parameters generateParams(const cv::cuda::Gpu ...@@ -104,8 +104,8 @@ static ftl::codecs::NvidiaEncoder::Parameters generateParams(const cv::cuda::Gpu
return params; return params;
} }
static uint64_t calculateBitrate(definition_t def, float ratescale) { static uint64_t calculateBitrate(int64_t pixels, float ratescale) {
float bitrate = 1.0f; // Megabits /*float bitrate = 1.0f; // Megabits
switch (def) { switch (def) {
case definition_t::UHD4k : bitrate = 40.0f; break; case definition_t::UHD4k : bitrate = 40.0f; break;
case definition_t::HTC_VIVE : bitrate = 32.0f; break; case definition_t::HTC_VIVE : bitrate = 32.0f; break;
...@@ -115,9 +115,11 @@ static uint64_t calculateBitrate(definition_t def, float ratescale) { ...@@ -115,9 +115,11 @@ static uint64_t calculateBitrate(definition_t def, float ratescale) {
case definition_t::SD480 : bitrate = 4.0f; break; case definition_t::SD480 : bitrate = 4.0f; break;
case definition_t::LD360 : bitrate = 2.0f; break; case definition_t::LD360 : bitrate = 2.0f; break;
default : bitrate = 16.0f; default : bitrate = 16.0f;
} }*/
float bitrate = 8.0f * float(pixels);
bitrate *= 1000.0f*1000.0f; //bitrate *= 1000.0f*1000.0f;
float minrate = 0.05f * bitrate; float minrate = 0.05f * bitrate;
return uint64_t((bitrate - minrate)*ratescale + minrate); return uint64_t((bitrate - minrate)*ratescale + minrate);
} }
...@@ -147,19 +149,19 @@ static bool validate(const cv::cuda::GpuMat &in, ftl::codecs::Packet &pkt) { ...@@ -147,19 +149,19 @@ static bool validate(const cv::cuda::GpuMat &in, ftl::codecs::Packet &pkt) {
} }
if (pkt.frame_count == 0) { if (pkt.frame_count == 0) {
pkt.definition = definition_t::Invalid; //pkt.definition = definition_t::Invalid;
return false; return false;
} }
auto [tx,ty] = ftl::codecs::chooseTileConfig(pkt.frame_count); /*auto [tx,ty] = ftl::codecs::chooseTileConfig(pkt.frame_count);
pkt.definition = (pkt.definition == definition_t::Any) ? ftl::codecs::findDefinition(in.cols/tx, in.rows/ty) : pkt.definition; pkt.definition = (pkt.definition == definition_t::Any) ? ftl::codecs::findDefinition(in.cols/tx, in.rows/ty) : pkt.definition;
if (pkt.definition == definition_t::Invalid || pkt.definition == definition_t::Any) { if (pkt.definition == definition_t::Invalid || pkt.definition == definition_t::Any) {
LOG(ERROR) << "Could not find appropriate definition"; LOG(ERROR) << "Could not find appropriate definition";
return false; return false;
} }*/
auto width = ftl::codecs::getWidth(pkt.definition)*tx; auto width = in.cols; //ftl::codecs::getWidth(pkt.definition)*tx;
auto height = ftl::codecs::getHeight(pkt.definition)*ty; auto height = in.rows; //ftl::codecs::getHeight(pkt.definition)*ty;
if (in.empty()) { if (in.empty()) {
LOG(WARNING) << "No data"; LOG(WARNING) << "No data";
...@@ -172,12 +174,12 @@ static bool validate(const cv::cuda::GpuMat &in, ftl::codecs::Packet &pkt) { ...@@ -172,12 +174,12 @@ static bool validate(const cv::cuda::GpuMat &in, ftl::codecs::Packet &pkt) {
return false; return false;
} }
if (width != in.cols || height != in.rows) { /*if (width != in.cols || height != in.rows) {
// TODO: Resize if lower definition requested... // TODO: Resize if lower definition requested...
LOG(ERROR) << "Input size does not match expected: " << in.cols << " != " << width; LOG(ERROR) << "Input size does not match expected: " << in.cols << " != " << width;
pkt.definition = definition_t::Invalid; pkt.definition = definition_t::Invalid;
return false; return false;
} }*/
return true; return true;
} }
...@@ -226,7 +228,7 @@ bool NvidiaEncoder::_createEncoder(const cv::cuda::GpuMat &in, const ftl::codecs ...@@ -226,7 +228,7 @@ bool NvidiaEncoder::_createEncoder(const cv::cuda::GpuMat &in, const ftl::codecs
Parameters params = generateParams(in, pkt); Parameters params = generateParams(in, pkt);
if (nvenc_ && (params == params_)) return true; if (nvenc_ && (params == params_)) return true;
uint64_t bitrate = calculateBitrate(pkt.definition, float(pkt.bitrate)/255.0f) * pkt.frame_count; uint64_t bitrate = calculateBitrate(in.cols*in.rows, float(pkt.bitrate)/255.0f) * pkt.frame_count;
LOG(INFO) << "Calculated bitrate " << ((params.is_float) ? "(float)" : "(rgb)") << ": " << bitrate; LOG(INFO) << "Calculated bitrate " << ((params.is_float) ? "(float)" : "(rgb)") << ": " << bitrate;
params_ = params; params_ = params;
......
...@@ -279,8 +279,6 @@ void Receiver::_processVideo(const StreamPacket &spkt, const Packet &pkt) { ...@@ -279,8 +279,6 @@ void Receiver::_processVideo(const StreamPacket &spkt, const Packet &pkt) {
cv::waitKey(1); cv::waitKey(1);
}*/ }*/
bool apply_Y_filter = value("apply_Y_filter", true);
// Mark a frameset as being partial // Mark a frameset as being partial
if (pkt.flags & ftl::codecs::kFlagPartial) { if (pkt.flags & ftl::codecs::kFlagPartial) {
builder_[spkt.streamID].markPartial(spkt.timestamp); builder_[spkt.streamID].markPartial(spkt.timestamp);
...@@ -301,18 +299,6 @@ void Receiver::_processVideo(const StreamPacket &spkt, const Packet &pkt) { ...@@ -301,18 +299,6 @@ void Receiver::_processVideo(const StreamPacket &spkt, const Packet &pkt) {
LOG(WARNING) << "Previous frame not complete: " << spkt.timestamp; LOG(WARNING) << "Previous frame not complete: " << spkt.timestamp;
} }
{
// This ensures that if previous frames are unfinished then they
// are discarded.
/*UNIQUE_LOCK(vidstate.mutex, lk);
if (frame.timestamp != spkt.timestamp && frame.timestamp != -1) {
frame.frame.reset();
frame.completed.clear();
LOG(WARNING) << "Frames out-of-phase by: " << spkt.timestamp - frame.timestamp;
}
frame.timestamp = spkt.timestamp;*/
}
// Add channel to frame and allocate memory if required // Add channel to frame and allocate memory if required
const cv::Size size = cv::Size(width, height); const cv::Size size = cv::Size(width, height);
frame.getBuffer<cv::cuda::GpuMat>(spkt.channel).create(size, ftl::codecs::type(spkt.channel)); //(isFloatChannel(rchan) ? CV_32FC1 : CV_8UC4)); frame.getBuffer<cv::cuda::GpuMat>(spkt.channel).create(size, ftl::codecs::type(spkt.channel)); //(isFloatChannel(rchan) ? CV_32FC1 : CV_8UC4));
...@@ -320,29 +306,6 @@ void Receiver::_processVideo(const StreamPacket &spkt, const Packet &pkt) { ...@@ -320,29 +306,6 @@ void Receiver::_processVideo(const StreamPacket &spkt, const Packet &pkt) {
cv::Rect roi((i % tx)*width, (i / tx)*height, width, height); cv::Rect roi((i % tx)*width, (i / tx)*height, width, height);
cv::cuda::GpuMat sroi = surface(roi); cv::cuda::GpuMat sroi = surface(roi);
sroi.copyTo(frame.getBuffer<cv::cuda::GpuMat>(spkt.channel), cvstream); sroi.copyTo(frame.getBuffer<cv::cuda::GpuMat>(spkt.channel), cvstream);
// Do colour conversion
/*if (isFloatChannel(rchan) && (pkt.flags & 0x2)) {
cv::Rect croi((i % tx)*width, ty*height+(i / tx)*height/2, width, height/2);
cv::cuda::GpuMat csroi = surface(croi);
// Smooth Y channel around discontinuities
// Lerp the uv channels / smooth over a small kernal size.
//if (value("apply_bilateral", true)) {
// cv::cuda::split
// Apply disparity bilateral to the luminance channel
// cv::cuda::merge or overload vuya_to_depth
//}
//if (apply_Y_filter) ftl::cuda::smooth_y(sroi, cvstream);
ftl::cuda::vuya_to_depth(frame.getBuffer<cv::cuda::GpuMat>(spkt.channel), sroi, csroi, 16.0f, cvstream);
} else if (isFloatChannel(rchan)) {
sroi.convertTo(frame.getBuffer<cv::cuda::GpuMat>(spkt.channel), CV_32FC1, 1.0f/1000.0f, cvstream);
} else if (sroi.type() == CV_8UC1) {
sroi.copyTo(frame.getBuffer<cv::cuda::GpuMat>(spkt.channel), cvstream);
} else {
cv::cuda::cvtColor(sroi, frame.getBuffer<cv::cuda::GpuMat>(spkt.channel), cv::COLOR_RGBA2BGRA, 0, cvstream);
}*/
} }
// Must ensure all processing is finished before completing a frame. // Must ensure all processing is finished before completing a frame.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment