diff --git a/cscore/src/main/native/cpp/UsbCameraImpl.cpp b/cscore/src/main/native/cpp/UsbCameraImpl.cpp index 500ab78068..8e5ba5d7cb 100644 --- a/cscore/src/main/native/cpp/UsbCameraImpl.cpp +++ b/cscore/src/main/native/cpp/UsbCameraImpl.cpp @@ -33,6 +33,7 @@ #include #include "Handle.h" +#include "JpegUtil.h" #include "Log.h" #include "Notifier.h" #include "Telemetry.h" @@ -400,12 +401,21 @@ void UsbCameraImpl::CameraThreadMain() { continue; } - PutFrame(static_cast(m_mode.pixelFormat), - m_mode.width, m_mode.height, - wpi::StringRef( - static_cast(m_buffers[buf.index].m_data), - static_cast(buf.bytesused)), - wpi::Now()); // TODO: time + wpi::StringRef image{ + static_cast(m_buffers[buf.index].m_data), + static_cast(buf.bytesused)}; + int width = m_mode.width; + int height = m_mode.height; + bool good = true; + if (m_mode.pixelFormat == VideoMode::kMJPEG && + !GetJpegSize(image, &width, &height)) { + SWARNING("invalid JPEG image received from camera"); + good = false; + } + if (good) { + PutFrame(static_cast(m_mode.pixelFormat), + width, height, image, wpi::Now()); // TODO: time + } } // Requeue buffer