mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-05 05:34:32 +02:00
fix(jpeg): Fix issue that jpeg acquire return NULL when acquire twice
This commit is contained in:
@@ -43,9 +43,9 @@ esp_err_t jpeg_acquire_codec_handle(jpeg_codec_handle_t *jpeg_new_codec)
|
|||||||
jpeg_codec_t *codec = NULL;
|
jpeg_codec_t *codec = NULL;
|
||||||
_lock_acquire(&s_jpeg_platform.mutex);
|
_lock_acquire(&s_jpeg_platform.mutex);
|
||||||
if (!s_jpeg_platform.jpeg_codec) {
|
if (!s_jpeg_platform.jpeg_codec) {
|
||||||
new_codec = true;
|
|
||||||
codec = heap_caps_calloc(1, sizeof(jpeg_codec_t), JPEG_MEM_ALLOC_CAPS);
|
codec = heap_caps_calloc(1, sizeof(jpeg_codec_t), JPEG_MEM_ALLOC_CAPS);
|
||||||
if (codec) {
|
if (codec) {
|
||||||
|
new_codec = true;
|
||||||
s_jpeg_platform.jpeg_codec = codec;
|
s_jpeg_platform.jpeg_codec = codec;
|
||||||
codec->intr_priority = -1;
|
codec->intr_priority = -1;
|
||||||
codec->spinlock = (portMUX_TYPE)portMUX_INITIALIZER_UNLOCKED;
|
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();
|
jpeg_ll_reset_module_register();
|
||||||
}
|
}
|
||||||
#if CONFIG_PM_ENABLE
|
#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
|
#endif
|
||||||
jpeg_hal_init(&codec->hal);
|
jpeg_hal_init(&codec->hal);
|
||||||
} else {
|
} 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++;
|
s_jpeg_platform.count++;
|
||||||
}
|
}
|
||||||
if (new_codec) {
|
if (new_codec) {
|
||||||
ESP_LOGD(TAG, "new jpeg module has been acquired at (%p)", 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);
|
_lock_release(&s_jpeg_platform.mutex);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@@ -13,6 +13,7 @@
|
|||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "esp_private/periph_ctrl.h"
|
#include "esp_private/periph_ctrl.h"
|
||||||
#include "driver/jpeg_encode.h"
|
#include "driver/jpeg_encode.h"
|
||||||
|
#include "driver/jpeg_decode.h"
|
||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "test_jpeg_performance.h"
|
#include "test_jpeg_performance.h"
|
||||||
#include "esp_system.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);
|
free(raw_buf_480p);
|
||||||
TEST_ESP_OK(jpeg_del_encoder_engine(jpeg_handle));
|
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));
|
||||||
|
}
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
CONFIG_PM_ENABLE=y
|
CONFIG_PM_ENABLE=y
|
||||||
CONFIG_FREERTOS_USE_TICKLESS_IDLE=y
|
CONFIG_FREERTOS_USE_TICKLESS_IDLE=y
|
||||||
|
CONFIG_PM_DFS_INIT_AUTO=y
|
||||||
CONFIG_COMPILER_OPTIMIZATION_SIZE=y
|
CONFIG_COMPILER_OPTIMIZATION_SIZE=y
|
||||||
CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE=y
|
CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE=y
|
||||||
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT=y
|
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT=y
|
||||||
|
Reference in New Issue
Block a user