From 706cdc1e05345bb62ab9ab4cc69b227169630f23 Mon Sep 17 00:00:00 2001 From: linxu Date: Tue, 24 Sep 2024 12:00:07 +0800 Subject: [PATCH] esp_new_jpeg: Update esp_jpeg to esp_new_jpeg (breaking change) --- components/esp-adf-libs | 2 +- .../esp_peripherals/driver/i2c_bus/i2c_bus.h | 188 ++++++++--------- .../driver/i2c_bus/i2c_bus_v2.c | 2 +- .../display/lcd_camera/main/CMakeLists.txt | 1 + .../display/lcd_camera/main/img_convert.c | 189 ++++++++++++++++++ .../display/lcd_camera/main/img_convert.h | 36 ++++ .../display/lcd_camera/main/lcd_camera_main.c | 3 +- examples/display/lcd_jpeg/main/decode_image.c | 19 +- .../components/av_record/av_record.c | 19 +- .../components/av_stream/av_stream.c | 25 ++- .../esp-rtc/partitions_esp_rtc_demo.csv | 4 +- 11 files changed, 362 insertions(+), 126 deletions(-) create mode 100644 examples/display/lcd_camera/main/img_convert.c create mode 100644 examples/display/lcd_camera/main/img_convert.h diff --git a/components/esp-adf-libs b/components/esp-adf-libs index f1b8cdbf9..6ee243445 160000 --- a/components/esp-adf-libs +++ b/components/esp-adf-libs @@ -1 +1 @@ -Subproject commit f1b8cdbf9986402fbd9a743704eb699a3521900a +Subproject commit 6ee2434453ff9a4b41481894300f05bb84bf2d41 diff --git a/components/esp_peripherals/driver/i2c_bus/i2c_bus.h b/components/esp_peripherals/driver/i2c_bus/i2c_bus.h index 781c7b3e0..88bda9fc2 100644 --- a/components/esp_peripherals/driver/i2c_bus/i2c_bus.h +++ b/components/esp_peripherals/driver/i2c_bus/i2c_bus.h @@ -1,38 +1,38 @@ /* - * ESPRESSIF MIT License - * - * Copyright (c) 2017 - * - * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case, - * it is free of charge, to any person obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the Software is furnished - * to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - */ + * ESPRESSIF MIT License + * + * Copyright (c) 2017 + * + * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case, + * it is free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ #ifndef _IOT_I2C_BUS_H_ #define _IOT_I2C_BUS_H_ #ifdef __cplusplus extern "C" { -#endif +#endif /* __cplusplus */ #include "audio_idf_version.h" #if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 0)) #include "driver/i2c_master.h" -#endif +#endif /* (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 0)) */ #include "driver/i2c.h" @@ -40,13 +40,13 @@ typedef void *i2c_bus_handle_t; typedef void (*i2c_run_cb_t)(i2c_port_t port, void *arg); /** - * @brief Create and init I2C bus and return a I2C bus handle + * @brief Create and init I2C bus and return a I2C bus handle * - * @param port I2C port number - * @param conf Pointer to I2C parameters + * @param port I2C port number + * @param conf Pointer to I2C parameters * * @return - * - I2C bus handle + * - I2C bus handle */ i2c_bus_handle_t i2c_bus_create(i2c_port_t port, i2c_config_t *conf); @@ -54,159 +54,159 @@ i2c_bus_handle_t i2c_bus_create(i2c_port_t port, i2c_config_t *conf); /** * @brief Set I2S master bus handle * - * @param port I2C port number - * @param master_handle I2C master bus handle. + * @param port I2C port number + * @param master_handle I2C master bus handle. * * @return - * - ESP_OK on success + * - ESP_OK on success */ esp_err_t i2c_bus_set_master_handle(i2c_port_t port, i2c_master_bus_handle_t master_handle); /** * @brief Get I2S master bus handle * - * @param port I2C port number + * @param port I2C port number * * @return - * - I2C master bus handle. + * - I2C master bus handle. */ i2c_master_bus_handle_t i2c_bus_get_master_handle(i2c_port_t port); /** * @brief Read certain bytes of data from I2C bus by address * - * ___________________________________________________ - * | start | slave_addr + rd_bit + ack | ..... | stop | - * --------|---------------------------|-- -----|------| + * ___________________________________________________ + * | start | slave_addr + rd_bit + ack | ..... | stop | + * --------|---------------------------|-- -----|------| * * @note Directly reads the data in the registers address without a write action * - * @param bus I2C bus handle - * @param addr The address of the device - * @param outdata The outdata pointer - * @param datalen The length of outdata + * @param bus I2C bus handle + * @param addr The address of the device + * @param outdata The outdata pointer + * @param datalen The length of outdata * * @return * - ESP_OK Success * - ESP_FAIL Fail */ -esp_err_t i2c_bus_read_bytes_directly(i2c_bus_handle_t bus, int addr, uint8_t *outdata, int datalen); +esp_err_t i2c_bus_read_bytes_directly(i2c_bus_handle_t bus, int addr, uint8_t *outdata, int datalen); /** * @brief Set I2C bus clock frequency * * @note This function need called before any i2c bus read or write operation * - * @param bus I2C bus handle - * @param clk_speed I2C clk frequency + * @param bus I2C bus handle + * @param clk_speed I2C clk frequency * * @return - * - ESP_OK Success - * - ESP_FAIL Fail + * - ESP_OK Success + * - ESP_FAIL Fail */ esp_err_t i2c_bus_set_clk(i2c_bus_handle_t bus, uint32_t clk_speed); #else /** - * @brief I2C start sending buffered commands + * @brief I2C start sending buffered commands * - * @param bus I2C bus handle - * @param cmd I2C cmd handle - * @param ticks_to_wait Maximum blocking time + * @param bus I2C bus handle + * @param cmd I2C cmd handle + * @param ticks_to_wait Maximum blocking time * * @return - * - ESP_OK Success - * - ESP_FAIL Fail + * - ESP_OK Success + * - ESP_FAIL Fail */ esp_err_t i2c_bus_cmd_begin(i2c_bus_handle_t bus, i2c_cmd_handle_t cmd, portBASE_TYPE ticks_to_wait); -#endif /* ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 0) */ +#endif /* (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 0)) */ /** - * @brief Write bytes to I2C bus + * @brief Write bytes to I2C bus * - * @param bus I2C bus handle - * @param addr The address of the device - * @param reg The register of the device - * @param regLen The length of register - * @param data The data pointer - * @param datalen The length of data + * @param bus I2C bus handle + * @param addr The address of the device + * @param reg The register of the device + * @param regLen The length of register + * @param data The data pointer + * @param datalen The length of data * * @return - * - NULL Fail - * - Others Success + * - NULL Fail + * - Others Success */ esp_err_t i2c_bus_write_bytes(i2c_bus_handle_t bus, int addr, uint8_t *reg, int regLen, uint8_t *data, int datalen); /** - * @brief Write data to I2C bus + * @brief Write data to I2C bus * - * @param bus I2C bus handle - * @param addr The address of the device - * @param data The data pointer - * @param datalen The length of data + * @param bus I2C bus handle + * @param addr The address of the device + * @param data The data pointer + * @param datalen The length of data * * @return - * - NULL Fail - * - Others Success + * - NULL Fail + * - Others Success */ esp_err_t i2c_bus_write_data(i2c_bus_handle_t bus, int addr, uint8_t *data, int datalen); /** - * @brief Read bytes to I2C bus + * @brief Read bytes to I2C bus * - * @param bus I2C bus handle - * @param addr The address of the device - * @param reg The register of the device - * @param regLen The length of register - * @param outdata The outdata pointer - * @param datalen The length of outdata + * @param bus I2C bus handle + * @param addr The address of the device + * @param reg The register of the device + * @param regLen The length of register + * @param outdata The outdata pointer + * @param datalen The length of outdata * * @return - * - NULL Fail - * - Others Success + * - NULL Fail + * - Others Success */ esp_err_t i2c_bus_read_bytes(i2c_bus_handle_t bus, int addr, uint8_t *reg, int reglen, uint8_t *outdata, int datalen); /** - * @brief Delete and release the I2C bus object + * @brief Delete and release the I2C bus object * - * @param bus I2C bus handle + * @param bus I2C bus handle * * @return - * - ESP_OK Success - * - ESP_FAIL Fail + * - ESP_OK Success + * - ESP_FAIL Fail */ esp_err_t i2c_bus_delete(i2c_bus_handle_t bus); /** - * @brief Auto probe the I2C device + * @brief Auto probe the I2C device * - * @param bus I2C bus handle - * @param addr I2C adress + * @param bus I2C bus handle + * @param addr I2C 8bit address * * @return - * - ESP_OK Found a I2C device - * - ESP_FAIL Fail + * - ESP_OK Found a I2C device + * - ESP_FAIL Fail */ esp_err_t i2c_bus_probe_addr(i2c_bus_handle_t bus, uint8_t addr); /** - * @brief Lock the I2C bus while executing the given callback + * @brief Lock the I2C bus while executing the given callback * - * @param bus I2C bus handle - * @param cb The callback to execute - * @param arg The argument for the callback + * @param bus I2C bus handle + * @param cb The callback to execute + * @param arg The argument for the callback * * @return - * - ESP_OK Done calling callback function - * - ESP_FAIL Fail + * - ESP_OK Done calling callback function + * - ESP_FAIL Fail */ esp_err_t i2c_bus_run_cb(i2c_bus_handle_t bus, i2c_run_cb_t cb, void *arg); #ifdef __cplusplus } -#endif +#endif /* __cplusplus */ -#endif +#endif /* _IOT_I2C_BUS_H_ */ diff --git a/components/esp_peripherals/driver/i2c_bus/i2c_bus_v2.c b/components/esp_peripherals/driver/i2c_bus/i2c_bus_v2.c index 504cddac4..cd4034b9a 100644 --- a/components/esp_peripherals/driver/i2c_bus/i2c_bus_v2.c +++ b/components/esp_peripherals/driver/i2c_bus/i2c_bus_v2.c @@ -239,7 +239,7 @@ esp_err_t i2c_bus_probe_addr(i2c_bus_handle_t bus, uint8_t addr) i2c_bus_info_t *bus_info = (i2c_bus_info_t *)bus; esp_err_t ret = ESP_OK; mutex_lock(master[bus_info->port].bus_lock); - ret = i2c_master_probe(master[bus_info->port].master_handle, addr, DEFAULT_I2C_TRANS_TIMEOUT); + ret = i2c_master_probe(master[bus_info->port].master_handle, addr >> 1, DEFAULT_I2C_TRANS_TIMEOUT); mutex_unlock(master[bus_info->port].bus_lock); return ret; } diff --git a/examples/display/lcd_camera/main/CMakeLists.txt b/examples/display/lcd_camera/main/CMakeLists.txt index deea6a928..a7f555048 100755 --- a/examples/display/lcd_camera/main/CMakeLists.txt +++ b/examples/display/lcd_camera/main/CMakeLists.txt @@ -4,5 +4,6 @@ idf_component_register( SRCS "lcd_camera_main.c" + "img_convert.c" INCLUDE_DIRS ".") diff --git a/examples/display/lcd_camera/main/img_convert.c b/examples/display/lcd_camera/main/img_convert.c new file mode 100644 index 000000000..c30b62518 --- /dev/null +++ b/examples/display/lcd_camera/main/img_convert.c @@ -0,0 +1,189 @@ +/* + This code convert YUV data to RGB data. + + This example code is in the Public Domain (or CC0 licensed, at your option.) + + Unless required by applicable law or agreed to in writing, this + software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + CONDITIONS OF ANY KIND, either express or implied. +*/ + +#include +#include +#include "esp_heap_caps.h" +#include "img_convert.h" + +#define COVERT_YUV_TO_RGB(y, u, v, r, g, b) \ + int rdif = 5743 * (v - 128) >> 12; \ + int gdif = (1409 * (u - 128) + 2925 * (v - 128)) >> 12; \ + int bdif = 7259 * (u - 128) >> 12; \ + r = BYTECLIP(y + rdif); \ + g = BYTECLIP(y - gdif); \ + b = BYTECLIP(y + bdif); + +static inline uint8_t BYTECLIP(int16_t val) +{ + if (val < 0) { + val = 0; + } + if (val > 255) { + val = 255; + } + return (uint8_t)val; +} + +static void yuv4442rgb888(int16_t *ybuf, int16_t *ubuf, int16_t *vbuf, int yuv_line_size, int height, int16_t width, uint8_t *rgb_out) +{ + int r, g, b; + for (int j = 0; j < height; j++) { + for (int i = 0; i < width; i++) { + COVERT_YUV_TO_RGB(ybuf[i], ubuf[i], vbuf[i], r, g, b); + *rgb_out++ = r; + *rgb_out++ = g; + *rgb_out++ = b; + } + ybuf += yuv_line_size; + ubuf += yuv_line_size; + vbuf += yuv_line_size; + } +} + +static void yuv4442rgb565_be(int16_t *ybuf, int16_t *ubuf, int16_t *vbuf, int yuv_line_size, int height, int16_t width, uint8_t *rgb_out) +{ + int r, g, b; + for (int j = 0; j < height; j++) { + for (int i = 0; i < width; i++) { + COVERT_YUV_TO_RGB(ybuf[i], ubuf[i], vbuf[i], r, g, b); + *rgb_out++ = (r & 0xf8) | (g >> 5); + *rgb_out++ = ((g & 0x1c) << 3) | (b >> 3); + } + ybuf += yuv_line_size; + ubuf += yuv_line_size; + vbuf += yuv_line_size; + } +} + +static void yuv4442rgb565_le(int16_t *ybuf, int16_t *ubuf, int16_t *vbuf, int yuv_line_size, int height, int16_t width, uint8_t *rgb_out) +{ + int r, g, b; + for (int j = 0; j < height; j++) { + for (int i = 0; i < width; i++) { + COVERT_YUV_TO_RGB(ybuf[i], ubuf[i], vbuf[i], r, g, b); + *rgb_out++ = ((g & 0x1c) << 3) | (b >> 3); + *rgb_out++ = (r & 0xf8) | (g >> 5); + } + ybuf += yuv_line_size; + ubuf += yuv_line_size; + vbuf += yuv_line_size; + } +} + +jpeg_error_t jpeg_yuv2rgb(jpeg_subsampling_t sub_sample, jpeg_pixel_format_t raw_type, uint8_t *yuv_image, int width, int height, uint8_t *rgb_image) +{ + /* allocate buffer */ + if (width == 0 || height == 0 || yuv_image == NULL || rgb_image == NULL) { + return JPEG_ERR_INVALID_PARAM; + } + int buf_size = (width + 15) & (~0xf); + int16_t *u_data = NULL; + int16_t *v_data = NULL; + int16_t *y_data = heap_caps_malloc_prefer(buf_size * sizeof(int16_t), 2, MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL, MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM); + if (y_data == NULL) { + goto trans_error; + } + u_data = heap_caps_malloc_prefer(buf_size * sizeof(int16_t), 2, MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL, MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM); + if (u_data == NULL) { + goto trans_error; + } + v_data = heap_caps_malloc_prefer(buf_size * sizeof(int16_t), 2, MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL, MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM); + if (v_data == NULL) { + goto trans_error; + } + for (size_t row = 0; row < height; row++) { + /* for one line */ + // first data type conversion + int col_index = 0; + switch (sub_sample) { + case JPEG_SUBSAMPLE_444: + for (int col = 0; col < (width * 3);) { + y_data[col_index] = yuv_image[col++]; + u_data[col_index] = yuv_image[col++]; + v_data[col_index] = yuv_image[col++]; + col_index++; + } + yuv_image += width * 3; + break; + case JPEG_SUBSAMPLE_422: + for (int col = 0; col < (width * 2);) { + y_data[col_index] = yuv_image[col++]; // y + u_data[col_index] = yuv_image[col++]; // u + u_data[col_index + 1] = u_data[col_index]; + y_data[col_index + 1] = yuv_image[col++]; // y + v_data[col_index] = yuv_image[col++]; // v + v_data[col_index + 1] = v_data[col_index]; + col_index += 2; + } + yuv_image += width * 2; + break; + case JPEG_SUBSAMPLE_420: + for (int col = 0; col < (width * 1.5);) { + y_data[col_index] = yuv_image[col++]; // y + u_data[col_index] = yuv_image[col++]; // u + u_data[col_index + 1] = u_data[col_index]; + u_data[col_index + 2] = u_data[col_index]; + u_data[col_index + 3] = u_data[col_index]; + y_data[col_index + 1] = yuv_image[col++]; // y + y_data[col_index + 2] = yuv_image[col++]; // y + u_data[col_index + 4] = yuv_image[col++]; // u + u_data[col_index + 5] = u_data[col_index]; + u_data[col_index + 6] = u_data[col_index]; + u_data[col_index + 7] = u_data[col_index]; + y_data[col_index + 3] = yuv_image[col++]; // y + y_data[col_index + 4] = yuv_image[col++]; // y + v_data[col_index] = yuv_image[col++]; // v + v_data[col_index + 1] = v_data[col_index]; + v_data[col_index + 2] = v_data[col_index]; + v_data[col_index + 3] = v_data[col_index]; + y_data[col_index + 5] = yuv_image[col++]; // y + y_data[col_index + 6] = yuv_image[col++]; // y + v_data[col_index + 4] = yuv_image[col++]; // v + v_data[col_index + 5] = v_data[col_index]; + v_data[col_index + 6] = v_data[col_index]; + v_data[col_index + 7] = v_data[col_index]; + y_data[col_index + 7] = yuv_image[col++]; // y + col_index += 8; + } + yuv_image += (int)(width * 1.5); + break; + default: + goto trans_error; + } + // second color conversion + switch (raw_type) { + case JPEG_PIXEL_FORMAT_RGB888: + yuv4442rgb888(y_data, u_data, v_data, buf_size, 1, width, rgb_image); + rgb_image += width * 3; + break; + case JPEG_PIXEL_FORMAT_RGB565_BE: + yuv4442rgb565_be(y_data, u_data, v_data, buf_size, 1, width, rgb_image); + rgb_image += width << 1; + break; + case JPEG_PIXEL_FORMAT_RGB565_LE: + yuv4442rgb565_le(y_data, u_data, v_data, buf_size, 1, width, rgb_image); + rgb_image += width << 1; + break; + default: + goto trans_error; + } + } + /* free buffer */ + heap_caps_free(y_data); + heap_caps_free(u_data); + heap_caps_free(v_data); + return JPEG_ERR_OK; +trans_error: + heap_caps_free(y_data); + heap_caps_free(u_data); + heap_caps_free(v_data); + return JPEG_ERR_FAIL; +} diff --git a/examples/display/lcd_camera/main/img_convert.h b/examples/display/lcd_camera/main/img_convert.h new file mode 100644 index 000000000..792c492ab --- /dev/null +++ b/examples/display/lcd_camera/main/img_convert.h @@ -0,0 +1,36 @@ +/* + This example code is in the Public Domain (or CC0 licensed, at your option.) + + Unless required by applicable law or agreed to in writing, this + software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + CONDITIONS OF ANY KIND, either express or implied. +*/ + +#pragma once + +#include +#include "esp_jpeg_common.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** + * @brief Convert YUV to RGB + * + * @param[in] sub_sample Chroma subsampling factors. Grayscale is un-supported. The others are supported. + * @param[in] raw_type Raw data type. RGB888 and RGB565 are supported. The others are un-supported. + * @param[in] yuv_image Input YUV image data. The buffer must be aligned 16 byte. + * @param[in] width Image width + * @param[in] height Image height + * @param[out] rgb_image Output RGB image data + * + * @return + * - JPEG_ERR_OK On success + * - Others Error occurs + */ +jpeg_error_t jpeg_yuv2rgb(jpeg_subsampling_t sub_sample, jpeg_pixel_format_t raw_type, uint8_t *yuv_image, int width, int height, uint8_t *rgb_image); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ diff --git a/examples/display/lcd_camera/main/lcd_camera_main.c b/examples/display/lcd_camera/main/lcd_camera_main.c index fe95c26ee..bee576b5f 100755 --- a/examples/display/lcd_camera/main/lcd_camera_main.c +++ b/examples/display/lcd_camera/main/lcd_camera_main.c @@ -12,6 +12,7 @@ #include "board.h" #include "audio_mem.h" #include "esp_jpeg_common.h" +#include "img_convert.h" static const char *TAG = "LCD_Camera"; @@ -94,7 +95,7 @@ static esp_err_t example_lcd_rgb_draw(esp_lcd_panel_handle_t panel_handle, uint8 /* example: YUV422 -> RGB565 -> LCD */ static esp_err_t example_lcd_yuv422_draw(esp_lcd_panel_handle_t panel_handle, uint8_t *image) { - jpeg_yuv2rgb(JPEG_SUB_SAMPLE_YUV422, JPEG_RAW_TYPE_RGB565_BE, image, EXAMPLE_LCD_H_RES, EXAMPLE_LCD_V_RES, rgb_buffer); + jpeg_yuv2rgb(JPEG_SUBSAMPLE_422, JPEG_PIXEL_FORMAT_RGB565_BE, image, EXAMPLE_LCD_H_RES, EXAMPLE_LCD_V_RES, rgb_buffer); example_lcd_rgb_draw(panel_handle, rgb_buffer); return ESP_OK; } diff --git a/examples/display/lcd_jpeg/main/decode_image.c b/examples/display/lcd_jpeg/main/decode_image.c index d9518d0bb..f1f31283e 100644 --- a/examples/display/lcd_jpeg/main/decode_image.c +++ b/examples/display/lcd_jpeg/main/decode_image.c @@ -30,13 +30,19 @@ const char *TAG = "ImageDec"; int decode_image(uint16_t ***pixels) { + int ret = 0; + // Generate default configuration jpeg_dec_config_t config = DEFAULT_JPEG_DEC_CONFIG(); - config.output_type = JPEG_RAW_TYPE_RGB565_BE; + config.output_type = JPEG_PIXEL_FORMAT_RGB565_BE; // Empty handle to jpeg_decoder jpeg_dec_handle_t jpeg_dec = NULL; // Create jpeg_dec - jpeg_dec = jpeg_dec_open(&config); + ret = jpeg_dec_open(&config, &jpeg_dec); + if (ret < 0) { + ESP_LOGE(TAG, "Got an error by jpeg_dec_open, ret:%d", ret); + return ret; + } // Create io_callback handle jpeg_dec_io_t *jpeg_io = calloc(1, sizeof(jpeg_dec_io_t)); if (jpeg_io == NULL) { @@ -53,7 +59,6 @@ int decode_image(uint16_t ***pixels) jpeg_io->inbuf = (unsigned char *)image_jpg_start; jpeg_io->inbuf_len = image_jpg_end - image_jpg_start; - int ret = 0; // Parse jpeg picture header and get picture for user and decoder ret = jpeg_dec_parse_header(jpeg_dec, jpeg_io, out_info); if (ret < 0) { @@ -62,16 +67,16 @@ int decode_image(uint16_t ***pixels) } // Calloc out_put data buffer and update inbuf ptr and inbuf_len int outbuf_len; - if (config.output_type == JPEG_RAW_TYPE_RGB565_LE - || config.output_type == JPEG_RAW_TYPE_RGB565_BE) { + if (config.output_type == JPEG_PIXEL_FORMAT_RGB565_LE + || config.output_type == JPEG_PIXEL_FORMAT_RGB565_BE) { outbuf_len = out_info->height * out_info->width * 2; - } else if (config.output_type == JPEG_RAW_TYPE_RGB888) { + } else if (config.output_type == JPEG_PIXEL_FORMAT_RGB888) { outbuf_len = out_info->height * out_info->width * 3; } else { return ESP_FAIL; } ESP_LOGI(TAG, "The image size is %d bytes, width:%d, height:%d", outbuf_len, out_info->width, out_info->height); - unsigned char *out_buf = jpeg_malloc_align(outbuf_len, 16); + unsigned char *out_buf = jpeg_calloc_align(outbuf_len, 16); jpeg_io->outbuf = out_buf; int inbuf_consumed = jpeg_io->inbuf_len - jpeg_io->inbuf_remain; jpeg_io->inbuf = (unsigned char *)(image_jpg_start + inbuf_consumed); diff --git a/examples/protocols/components/av_record/av_record.c b/examples/protocols/components/av_record/av_record.c index 090a86981..54d799425 100644 --- a/examples/protocols/components/av_record/av_record.c +++ b/examples/protocols/components/av_record/av_record.c @@ -142,18 +142,19 @@ static bool start_frame_synced() static int start_video_encoder() { + int ret = -1; uint16_t width = 0, height = 0; av_record_get_video_size(av_record.record_cfg.video_quality, &width, &height); if (av_record.record_cfg.video_fmt == AV_RECORD_VIDEO_FMT_MJPEG) { - jpeg_enc_info_t info = DEFAULT_JPEG_ENC_CONFIG(); - info.width = width; - info.height = height; - info.src_type = JPEG_RAW_TYPE_YCbYCr; - info.subsampling = JPEG_SUB_SAMPLE_YUV420; - info.quality = 40; - av_record.video_enc = jpeg_enc_open(&info); + jpeg_enc_config_t config = DEFAULT_JPEG_ENC_CONFIG(); + config.width = width; + config.height = height; + config.src_type = JPEG_PIXEL_FORMAT_YCbYCr; + config.subsampling = JPEG_SUBSAMPLE_420; + config.quality = 40; + ret = jpeg_enc_open(&config, &av_record.video_enc); if (av_record.video_enc == NULL) { - ESP_LOGE(TAG, "Fail to create jpeg encoder"); + ESP_LOGE(TAG, "Fail to create jpeg encoder %d", ret); return ESP_MEDIA_ERR_NOT_SUPPORT; } } else if (av_record.record_cfg.video_fmt == AV_RECORD_VIDEO_FMT_H264) { @@ -165,7 +166,7 @@ static int start_video_encoder() .gop_size = av_record.record_cfg.video_fps * 3, .target_bitrate = 400000, }; - int ret = esp_h264_enc_open(&cfg, (esp_h264_enc_t*)&av_record.video_enc); + ret = esp_h264_enc_open(&cfg, (esp_h264_enc_t *)&av_record.video_enc); if (av_record.video_enc == NULL) { ESP_LOGE(TAG, "Fail to create h264 encoder %d", ret); return ESP_MEDIA_ERR_NOT_SUPPORT; diff --git a/examples/protocols/components/av_stream/av_stream.c b/examples/protocols/components/av_stream/av_stream.c index a4dee7482..1443718f2 100644 --- a/examples/protocols/components/av_stream/av_stream.c +++ b/examples/protocols/components/av_stream/av_stream.c @@ -714,14 +714,14 @@ int av_audio_get_vol(av_stream_handle_t av_stream, int *vol) static void init_jpeg_encoder(av_stream_handle_t av_stream) { - jpeg_enc_info_t info = DEFAULT_JPEG_ENC_CONFIG(); - info.width = av_resolution[av_stream->config.hal.video_framesize].width; - info.height = av_resolution[av_stream->config.hal.video_framesize].height; - info.src_type = JPEG_RAW_TYPE_YCbYCr; - info.subsampling = JPEG_SUB_SAMPLE_YUV420; - // info.rotate = JPEG_ROTATE_0D; - info.quality = 40; - av_stream->video_enc = jpeg_enc_open(&info); + jpeg_enc_config_t config = DEFAULT_JPEG_ENC_CONFIG(); + config.width = av_resolution[av_stream->config.hal.video_framesize].width; + config.height = av_resolution[av_stream->config.hal.video_framesize].height; + config.src_type = JPEG_PIXEL_FORMAT_YCbYCr; + config.subsampling = JPEG_SUBSAMPLE_420; + // config.rotate = JPEG_ROTATE_0D; + config.quality = 40; + jpeg_enc_open(&config, &av_stream->video_enc); } static int init_h264_encoder(av_stream_handle_t av_stream) @@ -872,8 +872,11 @@ int av_video_dec_start(av_stream_handle_t av_stream) AUDIO_NULL_CHECK(TAG, av_stream, return ESP_ERR_INVALID_ARG); if (av_stream->jpeg_dec == NULL) { jpeg_dec_config_t config = DEFAULT_JPEG_DEC_CONFIG(); - config.output_type = JPEG_RAW_TYPE_RGB565_BE; - av_stream->jpeg_dec = jpeg_dec_open(&config); + config.output_type = JPEG_PIXEL_FORMAT_RGB565_BE; + jpeg_dec_open(&config, &av_stream->jpeg_dec); + if (av_stream->jpeg_dec == NULL) { + return ESP_FAIL; + } av_stream->jpeg_dec_io = audio_calloc(1, sizeof(jpeg_dec_io_t)); if (av_stream->jpeg_dec_io == NULL) { return ESP_FAIL; @@ -882,7 +885,7 @@ int av_video_dec_start(av_stream_handle_t av_stream) if (av_stream->out_info == NULL) { return ESP_FAIL; } - av_stream->vdec_buf = jpeg_malloc_align(VIDEO_DEC_SIZE, 16); + av_stream->vdec_buf = jpeg_calloc_align(VIDEO_DEC_SIZE, 16); } return ESP_OK; } diff --git a/examples/protocols/esp-rtc/partitions_esp_rtc_demo.csv b/examples/protocols/esp-rtc/partitions_esp_rtc_demo.csv index 34420a482..a4efa6485 100644 --- a/examples/protocols/esp-rtc/partitions_esp_rtc_demo.csv +++ b/examples/protocols/esp-rtc/partitions_esp_rtc_demo.csv @@ -2,5 +2,5 @@ # Note: if you change the phy_init or app partition offset, make sure to change the offset in Kconfig.projbuild nvs, data, nvs, 0x9000, 0x6000, phy_init, data, phy, 0xf000, 0x1000, -factory, app, factory, 0x10000, 0x210000, -flash_tone,data, 0xff, 0x220000 , 500K, +factory, app, factory, 0x10000, 0x220000, +flash_tone,data, 0xff, 0x230000 , 500K,