From 2f7cd3127911defb5bcc1ccf9a768b8b049cb94e Mon Sep 17 00:00:00 2001 From: Cao Sen Miao Date: Wed, 10 Apr 2024 18:53:11 +0800 Subject: [PATCH] fix(jpeg): Fix issue that jpeg acquire return NULL when acquire twice --- components/esp_driver_jpeg/jpeg_common.c | 8 +++--- .../jpeg_test_apps/main/test_jpeg_encode.c | 27 +++++++++++++++++++ .../jpeg_test_apps/sdkconfig.ci.release | 1 + 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/components/esp_driver_jpeg/jpeg_common.c b/components/esp_driver_jpeg/jpeg_common.c index 28207536f7..28f9b54a2b 100644 --- a/components/esp_driver_jpeg/jpeg_common.c +++ b/components/esp_driver_jpeg/jpeg_common.c @@ -43,9 +43,9 @@ esp_err_t jpeg_acquire_codec_handle(jpeg_codec_handle_t *jpeg_new_codec) jpeg_codec_t *codec = NULL; _lock_acquire(&s_jpeg_platform.mutex); if (!s_jpeg_platform.jpeg_codec) { - new_codec = true; codec = heap_caps_calloc(1, sizeof(jpeg_codec_t), JPEG_MEM_ALLOC_CAPS); if (codec) { + new_codec = true; s_jpeg_platform.jpeg_codec = codec; codec->intr_priority = -1; codec->spinlock = (portMUX_TYPE)portMUX_INITIALIZER_UNLOCKED; @@ -59,7 +59,7 @@ esp_err_t jpeg_acquire_codec_handle(jpeg_codec_handle_t *jpeg_new_codec) jpeg_ll_reset_module_register(); } #if CONFIG_PM_ENABLE - ESP_RETURN_ON_ERROR(esp_pm_lock_create(ESP_PM_NO_LIGHT_SLEEP, 0, "jpeg_codec", &codec->pm_lock), TAG, "create pm lock failed"); + ESP_RETURN_ON_ERROR(esp_pm_lock_create(ESP_PM_CPU_FREQ_MAX, 0, "jpeg_codec", &codec->pm_lock), TAG, "create pm lock failed"); #endif jpeg_hal_init(&codec->hal); } else { @@ -68,14 +68,14 @@ esp_err_t jpeg_acquire_codec_handle(jpeg_codec_handle_t *jpeg_new_codec) } } - if (codec) { + if (s_jpeg_platform.jpeg_codec) { s_jpeg_platform.count++; } if (new_codec) { ESP_LOGD(TAG, "new jpeg module has been acquired at (%p)", codec); } - *jpeg_new_codec = codec; + *jpeg_new_codec = s_jpeg_platform.jpeg_codec; _lock_release(&s_jpeg_platform.mutex); return ret; } diff --git a/components/esp_driver_jpeg/test_apps/jpeg_test_apps/main/test_jpeg_encode.c b/components/esp_driver_jpeg/test_apps/jpeg_test_apps/main/test_jpeg_encode.c index 24c3eed427..f1612fe7c5 100644 --- a/components/esp_driver_jpeg/test_apps/jpeg_test_apps/main/test_jpeg_encode.c +++ b/components/esp_driver_jpeg/test_apps/jpeg_test_apps/main/test_jpeg_encode.c @@ -13,6 +13,7 @@ #include "freertos/FreeRTOS.h" #include "esp_private/periph_ctrl.h" #include "driver/jpeg_encode.h" +#include "driver/jpeg_decode.h" #include "esp_log.h" #include "test_jpeg_performance.h" #include "esp_system.h" @@ -91,3 +92,29 @@ TEST_CASE("JPEG encode performance test for 480*640 RGB->YUV picture", "[jpeg]") free(raw_buf_480p); TEST_ESP_OK(jpeg_del_encoder_engine(jpeg_handle)); } + +TEST_CASE("jpeg initialize twice test", "[jpeg]") +{ + jpeg_encoder_handle_t encoder_handle = NULL; + + jpeg_encode_engine_cfg_t encode_eng_cfg = { + .intr_priority = 0, + .timeout_ms = 40, + }; + + TEST_ESP_OK(jpeg_new_encoder_engine(&encode_eng_cfg, &encoder_handle)); + assert(encoder_handle != NULL); + + jpeg_decoder_handle_t decoder_handle = NULL; + + jpeg_decode_engine_cfg_t decode_eng_cfg = { + .intr_priority = 0, + .timeout_ms = 40, + }; + + TEST_ESP_OK(jpeg_new_decoder_engine(&decode_eng_cfg, &decoder_handle)); + assert(decoder_handle != NULL); + + TEST_ESP_OK(jpeg_del_encoder_engine(encoder_handle)); + TEST_ESP_OK(jpeg_del_decoder_engine(decoder_handle)); +} diff --git a/components/esp_driver_jpeg/test_apps/jpeg_test_apps/sdkconfig.ci.release b/components/esp_driver_jpeg/test_apps/jpeg_test_apps/sdkconfig.ci.release index 91d93f163e..199b0cf97c 100644 --- a/components/esp_driver_jpeg/test_apps/jpeg_test_apps/sdkconfig.ci.release +++ b/components/esp_driver_jpeg/test_apps/jpeg_test_apps/sdkconfig.ci.release @@ -1,5 +1,6 @@ CONFIG_PM_ENABLE=y CONFIG_FREERTOS_USE_TICKLESS_IDLE=y +CONFIG_PM_DFS_INIT_AUTO=y CONFIG_COMPILER_OPTIMIZATION_SIZE=y CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE=y CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT=y