Drop frame if image packet incorrect

This commit is contained in:
John Zhao 2018-04-09 09:24:08 +08:00
parent bb075468ef
commit 71c21d789a
2 changed files with 15 additions and 8 deletions

View File

@ -12,7 +12,7 @@ MYNTEYE_BEGIN_NAMESPACE
namespace { namespace {
void unpack_stereo_img_data( bool unpack_stereo_img_data(
const void *data, const StreamRequest &request, ImgData &img) { // NOLINT const void *data, const StreamRequest &request, ImgData &img) { // NOLINT
CHECK_EQ(request.format, Format::YUYV); CHECK_EQ(request.format, Format::YUYV);
@ -49,7 +49,7 @@ void unpack_stereo_img_data(
LOG(WARNING) << "Image packet header must be 0x3B, but 0x" << std::hex LOG(WARNING) << "Image packet header must be 0x3B, but 0x" << std::hex
<< std::uppercase << std::setw(2) << std::setfill('0') << std::uppercase << std::setw(2) << std::setfill('0')
<< static_cast<int>(img_packet.header) << " now"; << static_cast<int>(img_packet.header) << " now";
return; return false;
} }
std::uint8_t checksum = 0; std::uint8_t checksum = 0;
@ -62,15 +62,16 @@ void unpack_stereo_img_data(
<< static_cast<int>(img_packet.checksum) << ", but 0x" << static_cast<int>(img_packet.checksum) << ", but 0x"
<< std::setw(2) << std::setfill('0') << std::setw(2) << std::setfill('0')
<< static_cast<int>(img_packet.checksum) << " now"; << static_cast<int>(img_packet.checksum) << " now";
return; return false;
} }
img.frame_id = img_packet.frame_id; img.frame_id = img_packet.frame_id;
img.timestamp = img_packet.timestamp; img.timestamp = img_packet.timestamp;
img.exposure_time = img_packet.exposure_time; img.exposure_time = img_packet.exposure_time;
return true;
} }
void unpack_left_img_pixels( bool unpack_left_img_pixels(
const void *data, const StreamRequest &request, const void *data, const StreamRequest &request,
Streams::frame_t &frame) { // NOLINT Streams::frame_t &frame) { // NOLINT
CHECK_EQ(request.format, Format::YUYV); CHECK_EQ(request.format, Format::YUYV);
@ -80,9 +81,10 @@ void unpack_left_img_pixels(
for (std::size_t i = 0; i < n; i++) { for (std::size_t i = 0; i < n; i++) {
frame.data()[i] = *(data_new + (i * 2)); frame.data()[i] = *(data_new + (i * 2));
} }
return true;
} }
void unpack_right_img_pixels( bool unpack_right_img_pixels(
const void *data, const StreamRequest &request, const void *data, const StreamRequest &request,
Streams::frame_t &frame) { // NOLINT Streams::frame_t &frame) { // NOLINT
CHECK_EQ(request.format, Format::YUYV); CHECK_EQ(request.format, Format::YUYV);
@ -92,6 +94,7 @@ void unpack_right_img_pixels(
for (std::size_t i = 0; i < n; i++) { for (std::size_t i = 0; i < n; i++) {
frame.data()[i] = *(data_new + (i * 2 + 1)); frame.data()[i] = *(data_new + (i * 2 + 1));
} }
return true;
} }
} // namespace } // namespace
@ -138,7 +141,11 @@ void Streams::PushStream(const Capabilities &capability, const void *data) {
auto &&left_data = stream_datas_map_[Stream::LEFT].back(); auto &&left_data = stream_datas_map_[Stream::LEFT].back();
auto &&right_data = stream_datas_map_[Stream::RIGHT].back(); auto &&right_data = stream_datas_map_[Stream::RIGHT].back();
// unpack img data // unpack img data
unpack_img_data_map_[Stream::LEFT](data, request, *left_data.img); if (unpack_img_data_map_[Stream::LEFT](data, request, *left_data.img)) {
// TODO(JohnZhao)
} else {
LOG(WARNING) << "Image packet is unaccepted, frame dropped";
}
*right_data.img = *left_data.img; *right_data.img = *left_data.img;
// unpack frame // unpack frame
unpack_img_pixels_map_[Stream::LEFT](data, request, *left_data.frame); unpack_img_pixels_map_[Stream::LEFT](data, request, *left_data.frame);

View File

@ -21,9 +21,9 @@ class Streams {
using stream_data_t = device::StreamData; using stream_data_t = device::StreamData;
using stream_datas_t = std::vector<stream_data_t>; using stream_datas_t = std::vector<stream_data_t>;
using unpack_img_data_t = std::function<void( using unpack_img_data_t = std::function<bool(
const void *data, const StreamRequest &request, ImgData &img)>; // NOLINT const void *data, const StreamRequest &request, ImgData &img)>; // NOLINT
using unpack_img_pixels_t = std::function<void( using unpack_img_pixels_t = std::function<bool(
const void *data, const StreamRequest &request, const void *data, const StreamRequest &request,
frame_t &frame)>; // NOLINT frame_t &frame)>; // NOLINT