mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
fix(jpeg): Fix issue that jpeg acquire return NULL when acquire twice
This commit is contained in:
parent
896cebaf8b
commit
2f7cd31279
@ -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;
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user