forked from xiaozhi/xiaozhi-esp32
feat: support JPEG input (#1455)
This commit is contained in:
@@ -426,6 +426,19 @@ static bool encode_with_esp_new_jpeg(const uint8_t* src, size_t src_len, uint16_
|
||||
|
||||
bool image_to_jpeg(uint8_t* src, size_t src_len, uint16_t width, uint16_t height, v4l2_pix_fmt_t format,
|
||||
uint8_t quality, uint8_t** out, size_t* out_len) {
|
||||
#ifdef CONFIG_XIAOZHI_CAMERA_ALLOW_JPEG_INPUT
|
||||
if (format == V4L2_PIX_FMT_JPEG) {
|
||||
uint8_t * out_data = (uint8_t*)heap_caps_malloc(src_len, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
|
||||
if (!out_data) {
|
||||
ESP_LOGE(TAG, "Failed to allocate memory for JPEG output");
|
||||
return false;
|
||||
}
|
||||
memcpy(out_data, src, src_len);
|
||||
*out = out_data;
|
||||
*out_len = src_len;
|
||||
return true;
|
||||
}
|
||||
#endif // CONFIG_XIAOZHI_CAMERA_ALLOW_JPEG_INPUT
|
||||
#if CONFIG_XIAOZHI_ENABLE_HARDWARE_JPEG_ENCODER
|
||||
if (encode_with_hw_jpeg(src, src_len, width, height, format, quality, out, out_len, NULL, NULL)) {
|
||||
return true;
|
||||
@@ -437,6 +450,13 @@ bool image_to_jpeg(uint8_t* src, size_t src_len, uint16_t width, uint16_t height
|
||||
|
||||
bool image_to_jpeg_cb(uint8_t* src, size_t src_len, uint16_t width, uint16_t height, v4l2_pix_fmt_t format,
|
||||
uint8_t quality, jpg_out_cb cb, void* arg) {
|
||||
#ifdef CONFIG_XIAOZHI_CAMERA_ALLOW_JPEG_INPUT
|
||||
if (format == V4L2_PIX_FMT_JPEG) {
|
||||
cb(arg, 0, src, src_len);
|
||||
cb(arg, 1, nullptr, 0); // end signal
|
||||
return true;
|
||||
}
|
||||
#endif // CONFIG_XIAOZHI_CAMERA_ALLOW_JPEG_INPUT
|
||||
#if CONFIG_XIAOZHI_ENABLE_HARDWARE_JPEG_ENCODER
|
||||
if (encode_with_hw_jpeg(src, src_len, width, height, format, quality, NULL, NULL, cb, arg)) {
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user