From 40b0a13bca5017185bd3cd769dce15d2dae09672 Mon Sep 17 00:00:00 2001 From: lxowalle Date: Tue, 21 May 2024 10:15:41 +0800 Subject: [PATCH] optimize http stream --- components/vision/include/maix_jpg_stream.hpp | 2 +- .../vision/port/maixcam/maix_jpg_stream.cpp | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/components/vision/include/maix_jpg_stream.hpp b/components/vision/include/maix_jpg_stream.hpp index 5dea2320..58ffcd77 100644 --- a/components/vision/include/maix_jpg_stream.hpp +++ b/components/vision/include/maix_jpg_stream.hpp @@ -52,7 +52,7 @@ namespace maix::http /** * @brief Write data to http - * @param img Must be jpeg image + * @param img image object * @return error code, err::ERR_NONE means success, others means failed * @maixpy maix.http.JpegStreamer.write */ diff --git a/components/vision/port/maixcam/maix_jpg_stream.cpp b/components/vision/port/maixcam/maix_jpg_stream.cpp index e25edd89..14721e6e 100644 --- a/components/vision/port/maixcam/maix_jpg_stream.cpp +++ b/components/vision/port/maixcam/maix_jpg_stream.cpp @@ -580,17 +580,26 @@ namespace maix::http err::Err JpegStreamer::write(image::Image *img) { int res = 0; + image::Image *jpg = NULL; if (img->format() != image::Format::FMT_JPEG) { - log::error("Only support jpeg format!\r\n"); - return err::ERR_RUNTIME; + jpg = img->to_jpeg(); + if (jpg == NULL) { + log::error("invert to jpeg failed!\r\n"); + return err::ERR_RUNTIME; + } + } else { + jpg = img; } - if (0 != (res = http_jpeg_server_send(img->data(), img->data_size()))) { + if (0 != (res = http_jpeg_server_send(jpg->data(), jpg->data_size()))) { log::error("http_jpeg_server_send failed! res:%d\r\n", res); return err::ERR_RUNTIME; } + if (img->format() != image::Format::FMT_JPEG) { + delete jpg; + } return err::ERR_NONE; }