diff --git a/components/codecs/src/nvpipe_decoder.cpp b/components/codecs/src/nvpipe_decoder.cpp index 79e16f3fa77ca9445faab12e33664243f1247293..4c9f515066870f4519b7148c6acc31e32cb84b11 100644 --- a/components/codecs/src/nvpipe_decoder.cpp +++ b/components/codecs/src/nvpipe_decoder.cpp @@ -22,32 +22,6 @@ NvPipeDecoder::~NvPipeDecoder() { } } -void cropAndScaleUp(cv::Mat &in, cv::Mat &out) { - CHECK(in.type() == out.type()); - - auto isize = in.size(); - auto osize = out.size(); - cv::Mat tmp; - - if (isize != osize) { - double x_scale = ((double) isize.width) / osize.width; - double y_scale = ((double) isize.height) / osize.height; - double x_scalei = 1.0 / x_scale; - double y_scalei = 1.0 / y_scale; - cv::Size sz_crop; - - // assume downscaled image - if (x_scalei > y_scalei) { - sz_crop = cv::Size(isize.width, isize.height * x_scale); - } else { - sz_crop = cv::Size(isize.width * y_scale, isize.height); - } - - tmp = in(cv::Rect(cv::Point2i(0, 0), sz_crop)); - cv::resize(tmp, out, osize); - } -} - bool NvPipeDecoder::decode(const ftl::codecs::Packet &pkt, cv::Mat &out) { cudaSetDevice(0); UNIQUE_LOCK(mutex_,lk); @@ -85,13 +59,14 @@ bool NvPipeDecoder::decode(const ftl::codecs::Packet &pkt, cv::Mat &out) { // TODO: (Nick) Move to member variable to prevent re-creation cv::Mat tmp(cv::Size(ftl::codecs::getWidth(pkt.definition),ftl::codecs::getHeight(pkt.definition)), (is_float_frame) ? CV_16U : CV_8UC4); + // Check for an I-Frame if (pkt.codec == ftl::codecs::codec_t::HEVC) { - // Obtain NAL unit type if (ftl::codecs::hevc::isIFrame(pkt.data)) seen_iframe_ = true; } else if (pkt.codec == ftl::codecs::codec_t::H264) { if (ftl::codecs::h264::isIFrame(pkt.data)) seen_iframe_ = true; } + // No I-Frame yet so don't attempt to decode P-Frames. if (!seen_iframe_) return false; int rc = NvPipe_Decode(nv_decoder_, pkt.data.data(), pkt.data.size(), tmp.data, tmp.cols, tmp.rows); @@ -109,6 +84,7 @@ bool NvPipeDecoder::decode(const ftl::codecs::Packet &pkt, cv::Mat &out) { } else { // Is the received frame the same size as requested output? if (out.rows == ftl::codecs::getHeight(pkt.definition)) { + // Flag 0x1 means frame is in RGB so needs conversion to BGR if (pkt.flags & 0x1) { cv::cvtColor(tmp, out, cv::COLOR_RGBA2BGR); } else { @@ -116,6 +92,7 @@ bool NvPipeDecoder::decode(const ftl::codecs::Packet &pkt, cv::Mat &out) { } } else { LOG(WARNING) << "Resizing decoded frame from " << tmp.size() << " to " << out.size(); + // Flag 0x1 means frame is in RGB so needs conversion to BGR if (pkt.flags & 0x1) { cv::cvtColor(tmp, tmp, cv::COLOR_RGBA2BGR); } else { diff --git a/components/codecs/src/opencv_decoder.cpp b/components/codecs/src/opencv_decoder.cpp index 3bbd82fa21ae4b60fef00b81c409ae9c59311d39..c4156e4f9fe1ace8b950f8c921dfca0911970270 100644 --- a/components/codecs/src/opencv_decoder.cpp +++ b/components/codecs/src/opencv_decoder.cpp @@ -30,6 +30,8 @@ bool OpenCVDecoder::decode(const ftl::codecs::Packet &pkt, cv::Mat &out) { cv::Rect roi(cx,cy,chunk_width,chunk_height); cv::Mat chunkHead = out(roi); + LOG(INFO) << "DECODE JPEG " << (int)pkt.block_number << "/" << chunk_dim; + // Decode in temporary buffers to prevent long locks cv::imdecode(pkt.data, cv::IMREAD_UNCHANGED, &tmp); diff --git a/components/rgbd-sources/src/sources/net/net.cpp b/components/rgbd-sources/src/sources/net/net.cpp index 1843203e190205ebb20a4563ca4a69325168b88d..2e672dc3f0fb9d6710369c9d6a41b2914aecf1f2 100644 --- a/components/rgbd-sources/src/sources/net/net.cpp +++ b/components/rgbd-sources/src/sources/net/net.cpp @@ -366,12 +366,13 @@ void NetSource::_recvPacket(short ttimeoff, const ftl::codecs::StreamPacket &spk } ++frame.chunk_count[channum]; - ++frame.channel_count; + if (frame.chunk_count[channum] == frame.chunk_total[channum]) ++frame.channel_count; if (frame.chunk_count[channum] > frame.chunk_total[channum]) LOG(FATAL) << "TOO MANY CHUNKS"; // Capture tx time of first received chunk - if (frame.channel_count == 1 && frame.chunk_count[channum] == 1) { + // FIXME: This seems broken + if (channum == 1 && frame.chunk_count[channum] == 1) { UNIQUE_LOCK(frame.mtx, flk); if (frame.chunk_count[channum] == 1) { frame.tx_latency = int64_t(ttimeoff);