Skip to content

Commit

Permalink
optimize http stream
Browse files Browse the repository at this point in the history
  • Loading branch information
lxowalle committed May 21, 2024
1 parent 8fb1b82 commit 40b0a13
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion components/vision/include/maix_jpg_stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
15 changes: 12 additions & 3 deletions components/vision/port/maixcam/maix_jpg_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 40b0a13

Please sign in to comment.