From dc7533c6a840bdfae274572158b4c3851535114d Mon Sep 17 00:00:00 2001 From: Milosz Linkiewicz Date: Mon, 23 Sep 2024 08:32:53 +0000 Subject: [PATCH] MCM st22 fix and logging improvements MCM st22 fix and logging improvements - added fix for media_proxy exit with segfault - added basic logger levels - imtl.json now to include jpeg xs plugin by default - minor other improvements Signed-off-by: Milosz Linkiewicz --- media-proxy/imtl.json | 23 +++++++++-- media-proxy/include/utils.h | 80 +++++++++++++++++++++++++++++-------- media-proxy/src/mtl.c | 66 ++++++++++++++++-------------- media-proxy/tests/common.h | 7 +--- 4 files changed, 119 insertions(+), 57 deletions(-) diff --git a/media-proxy/imtl.json b/media-proxy/imtl.json index 23140ffe..a0bd72cc 100644 --- a/media-proxy/imtl.json +++ b/media-proxy/imtl.json @@ -1,5 +1,10 @@ { "plugins": [ + { + "enabled": 0, + "name": "intopix_jpegxs_cpu", + "path": "/usr/local/lib/x86_64-linux-gnu/libst_plugin_intopix_cpu.so" + }, { "enabled": 0, "name": "st22_ffmpeg", @@ -11,24 +16,34 @@ "path": "/usr/local/lib64/libst_plugin_st22_ffmpeg.so" }, { - "enabled": 1, + "enabled": 0, "name": "st22_sample", "path": "/usr/local/lib/x86_64-linux-gnu/libst_plugin_st22_sample.so" }, { - "enabled": 1, + "enabled": 0, "name": "st22_sample", "path": "/usr/local/lib64/libst_plugin_st22_sample.so" }, { - "enabled": 0, + "enabled": 1, "name": "convert_sample", "path": "/usr/local/lib/x86_64-linux-gnu/libst_plugin_convert_sample.so" }, { - "enabled": 0, + "enabled": 1, "name": "convert_sample", "path": "/usr/local/lib64/libst_plugin_convert_sample.so" + }, + { + "enabled": 1, + "name": "st22_svt_jpeg_xs", + "path": "/usr/local/lib/x86_64-linux-gnu/libst_plugin_st22_svt_jpeg_xs.so" + }, + { + "enabled": 1, + "name": "st22_svt_jpeg_xs", + "path": "/usr/local/lib64/libst_plugin_st22_svt_jpeg_xs.so" } ] } diff --git a/media-proxy/include/utils.h b/media-proxy/include/utils.h index 4c2692c5..fd6fec82 100644 --- a/media-proxy/include/utils.h +++ b/media-proxy/include/utils.h @@ -7,28 +7,74 @@ #ifndef __UTILS_H #define __UTILS_H +#ifndef MCM_LOG_LEVEL +#define MCM_LOG_LEVEL 16 +#endif + #include -#define INFO(...) \ - do { \ - printf("INFO: " __VA_ARGS__); \ - printf("\n"); \ - } while (0) -#define ERROR(...) \ - do { \ - printf("ERROR: " __VA_ARGS__); \ - printf("\n"); \ - } while (0) - -#define DEBUG(...) \ - do { \ - printf("DEBUG: " __VA_ARGS__); \ - printf("\n"); \ - } while (0) +static void log_default_prefix(char* buf, size_t sz) { + time_t now; + struct tm tm; + + time(&now); + localtime_r(&now, &tm); + strftime(buf, sz, "%Y-%m-%d %H:%M:%S, ", &tm); +} + +#define MCM_LOG(l, format, ...) \ + do { \ + char __prefix[64]; \ + log_default_prefix(__prefix, sizeof(__prefix)); \ + printf("MCM %s: %s" format, l, __prefix, ##__VA_ARGS__); \ + printf("\n"); \ + } while (0) + +// MCM_LOG_LEVEL>=32 +#if (MCM_LOG_LEVEL >= 32) + #define DEBUG(...) do { MCM_LOG("DEBUG", __VA_ARGS__); } while (0) +#else + #define DEBUG(...) do { } while (0) +#endif + +// MCM_LOG_LEVEL>=16 +#if (MCM_LOG_LEVEL >= 16) + #define INFO(...) do { MCM_LOG("INFO", __VA_ARGS__); } while (0) +#else + #define INFO(...) do { } while (0) +#endif + +// MCM_LOG_LEVEL>=8 +#if (MCM_LOG_LEVEL >= 8) + #define NOTICE(...) do { MCM_LOG("NOTICE", __VA_ARGS__); } while (0) +#else + #define NOTICE(...) do { } while (0) +#endif + +// MCM_LOG_LEVEL>=4 +#if (MCM_LOG_LEVEL >= 4) + #define WARNING(...) do { MCM_LOG("WARNING", __VA_ARGS__); } while (0) +#else + #define WARNING(...) do { } while (0) +#endif + +// MCM_LOG_LEVEL>=2 +#if (MCM_LOG_LEVEL >= 2) + #define ERROR(...) do { MCM_LOG("ERROR", __VA_ARGS__); } while (0) +#else + #define ERROR(...) do { } while (0) +#endif + +// MCM_LOG_LEVEL>0 +#if (MCM_LOG_LEVEL > 0) + #define CRITICAL(...) do { MCM_LOG("CRITICAL", __VA_ARGS__); } while (0) +#else + #define ERROR(...) do { } while (0) +#endif enum direction { TX, RX }; -#endif +#endif \ No newline at end of file diff --git a/media-proxy/src/mtl.c b/media-proxy/src/mtl.c index e2c78c5c..48ae2e89 100644 --- a/media-proxy/src/mtl.c +++ b/media-proxy/src/mtl.c @@ -1056,12 +1056,12 @@ int rx_shm_deinit(rx_session_context_t* rx_ctx) err = pthread_cancel(rx_ctx->memif_event_thread); if (err) { - ERROR("%s: Error canceling thread: %s", __func__, strerror(err)); + ERROR("%s: Error canceling thread: (%d) %s", __func__, err, strerror(err)); } err = pthread_join(rx_ctx->memif_event_thread, NULL); if (err && err != ESRCH) { - ERROR("%s: Error joining thread: %s", __func__, strerror(err)); + ERROR("%s: Error joining thread: (%d) %s", __func__, err, strerror(err)); } /* free-up resources */ @@ -1092,12 +1092,12 @@ int tx_shm_deinit(tx_session_context_t* tx_ctx) err = pthread_cancel(tx_ctx->memif_event_thread); if (err) { - ERROR("%s: Error canceling thread: %s", __func__, strerror(err)); + ERROR("%s: Error canceling thread: (%d) %s", __func__, err, strerror(err)); } err = pthread_join(tx_ctx->memif_event_thread, NULL); if (err && err != ESRCH) { - ERROR("%s: Error joining thread: %s", __func__, strerror(err)); + ERROR("%s: Error joining thread: (%d) %s", __func__, err, strerror(err)); } /* free-up resources */ @@ -1120,6 +1120,7 @@ int tx_shm_deinit(tx_session_context_t* tx_ctx) int rx_st22p_shm_deinit(rx_st22p_session_context_t* rx_ctx) { int err; + DEBUG("%s, start %d\n", __func__, rx_ctx->idx); if (rx_ctx == NULL) { ERROR("%s, Illegal parameter.", __func__); @@ -1128,12 +1129,12 @@ int rx_st22p_shm_deinit(rx_st22p_session_context_t* rx_ctx) err = pthread_cancel(rx_ctx->memif_event_thread); if (err) { - ERROR("%s: Error canceling thread: %s", __func__, strerror(err)); + ERROR("%s: Error canceling thread: (%d) %s", __func__, err, strerror(err)); } err = pthread_join(rx_ctx->memif_event_thread, NULL); if (err && err != ESRCH) { - ERROR("%s: Error joining thread: %s", __func__, strerror(err)); + ERROR("%s: Error joining thread: (%d) %s", __func__, err, strerror(err)); } /* free-up resources */ @@ -1149,27 +1150,30 @@ int rx_st22p_shm_deinit(rx_st22p_session_context_t* rx_ctx) free(rx_ctx->shm_bufs); rx_ctx->shm_bufs = NULL; } - + DEBUG("%s, finished\n", __func__); return 0; } int tx_st22p_shm_deinit(tx_st22p_session_context_t* tx_ctx) { int err; + DEBUG("%s, start, tx_ctx->idx=%d", __func__, tx_ctx->idx); if (tx_ctx == NULL) { ERROR("%s, Illegal parameter.", __func__); return -1; } - err = pthread_cancel(tx_ctx->memif_event_thread); - if (err) { - ERROR("%s: Error canceling thread: %s", __func__, strerror(err)); - } + if(!tx_ctx->stop) { + err = pthread_cancel(tx_ctx->memif_event_thread); + if (err) { + ERROR("%s: Error canceling thread: (%d) %s", __func__, err, strerror(err)); + } - err = pthread_join(tx_ctx->memif_event_thread, NULL); - if (err && err != ESRCH) { - ERROR("%s: Error joining thread: %s", __func__, strerror(err)); + err = pthread_join(tx_ctx->memif_event_thread, NULL); + if (err && err != ESRCH) { + ERROR("%s: Error joining thread: (%d) %s", __func__, err, strerror(err)); + } } /* free-up resources */ @@ -1186,6 +1190,7 @@ int tx_st22p_shm_deinit(tx_st22p_session_context_t* tx_ctx) tx_ctx->shm_bufs = NULL; } + DEBUG("%s, finished", __func__); return 0; } @@ -1200,12 +1205,12 @@ int rx_st30_shm_deinit(rx_st30_session_context_t* pctx) err = pthread_cancel(pctx->memif_event_thread); if (err) { - ERROR("%s: Error canceling thread: %s", __func__, strerror(err)); + ERROR("%s: Error canceling thread: (%d) %s", __func__, err, strerror(err)); } err = pthread_join(pctx->memif_event_thread, NULL); if (err && err != ESRCH) { - ERROR("%s: Error joining thread: %s", __func__, strerror(err)); + ERROR("%s: Error joining thread: (%d) %s", __func__, err, strerror(err)); } /* free-up resources */ @@ -1236,12 +1241,12 @@ int tx_st30_shm_deinit(tx_st30_session_context_t* pctx) err = pthread_cancel(pctx->memif_event_thread); if (err) { - ERROR("%s: Error canceling thread: %s", __func__, strerror(err)); + ERROR("%s: Error canceling thread: (%d) %s", __func__, err, strerror(err)); } err = pthread_join(pctx->memif_event_thread, NULL); if (err && err != ESRCH) { - ERROR("%s: Error joining thread: %s", __func__, strerror(err)); + ERROR("%s: Error joining thread: (%d) %s", __func__, err, strerror(err)); } /* free-up resources */ @@ -1277,12 +1282,12 @@ int rx_st40_shm_deinit(rx_st40_session_context_t* pctx) err = pthread_cancel(pctx->memif_event_thread); if (err) { - ERROR("%s: Error canceling thread: %s", __func__, strerror(err)); + ERROR("%s: Error canceling thread: (%d) %s", __func__, err, strerror(err)); } err = pthread_join(pctx->memif_event_thread, NULL); if (err && err != ESRCH) { - ERROR("%s: Error joining thread: %s", __func__, strerror(err)); + ERROR("%s: Error joining thread: (%d) %s", __func__, err, strerror(err)); } /* free-up resources */ @@ -1313,12 +1318,12 @@ int tx_st40_shm_deinit(tx_st40_session_context_t* pctx) err = pthread_cancel(pctx->memif_event_thread); if (err) { - ERROR("%s: Error canceling thread: %s", __func__, strerror(err)); + ERROR("%s: Error canceling thread: (%d) %s", __func__, err, strerror(err)); } err = pthread_join(pctx->memif_event_thread, NULL); if (err && err != ESRCH) { - ERROR("%s: Error joining thread: %s", __func__, strerror(err)); + ERROR("%s: Error joining thread: (%d) %s", __func__, err, strerror(err)); } /* free-up resources */ @@ -2660,21 +2665,21 @@ void mtl_st20p_tx_session_destroy(tx_session_context_t** p_tx_ctx) void mtl_st22p_tx_session_destroy(tx_st22p_session_context_t** p_tx_ctx) { tx_st22p_session_context_t* tx_ctx = NULL; + DEBUG("%s, start", __func__); if (p_tx_ctx == NULL) { - printf("%s:%d Invalid parameter\n", __func__, __LINE__); + ERROR("%s:%d Invalid parameter", __func__, __LINE__); return; } tx_ctx = *p_tx_ctx; if (tx_ctx == NULL || tx_ctx->handle == NULL) { - printf("%s:%d Invalid parameter\n", __func__, __LINE__); + ERROR("%s:%d Invalid parameter", __func__, __LINE__); return; } - printf("%s, fb_send %d\n", __func__, tx_ctx->fb_send); if (st22p_tx_free(tx_ctx->handle) < 0) { - printf("%s, session free failed\n", __func__); + ERROR("%s, session free failed", __func__); return; } @@ -2686,6 +2691,7 @@ void mtl_st22p_tx_session_destroy(tx_st22p_session_context_t** p_tx_ctx) /* FIXME: should be freed. */ free(tx_ctx); + DEBUG("%s, finished", __func__); } /* TX: Stop ST20P session */ @@ -2841,7 +2847,7 @@ void mtl_st40_tx_session_stop(tx_st40_session_context_t* pctx) err = pthread_cancel(pctx->memif_event_thread); if (err) { - ERROR("%s: Error canceling thread: %s", __func__, strerror(err)); + ERROR("%s: Error canceling thread: (%d) %s", __func__, err, strerror(err)); } pctx->stop = true; @@ -2942,12 +2948,12 @@ int rx_udp_h264_shm_deinit(rx_udp_h264_session_context_t* rx_ctx) err = pthread_cancel(rx_ctx->memif_event_thread); if (err) { - ERROR("%s: Error canceling thread: %s", __func__, strerror(err)); + ERROR("%s: Error canceling thread: (%d) %s", __func__, err, strerror(err)); } err = pthread_join(rx_ctx->memif_event_thread, NULL); - if (err && err != ESRCH) { - ERROR("%s: Error joining thread: %s", __func__, strerror(err)); + if (err) { + ERROR("%s: Error joining thread: (%d) %s", __func__, err, strerror(err)); } /* free-up resources */ diff --git a/media-proxy/tests/common.h b/media-proxy/tests/common.h index 22a93b2d..b3c41c4f 100644 --- a/media-proxy/tests/common.h +++ b/media-proxy/tests/common.h @@ -13,6 +13,7 @@ #include "libmemif.h" #include "shm_memif.h" +#include "utils.h" #define FRAME_SIZE 8294400 // yuv422p10le (1920*1080*4) #define FRAME_COUNT 1 @@ -20,12 +21,6 @@ /* maximum tx/rx memif buffers */ #define MAX_MEMIF_BUFS 256 -#define INFO(...) \ - do { \ - printf("INFO: " __VA_ARGS__); \ - printf("\n"); \ - } while (0) - void print_memif_details(memif_conn_handle_t conn) { printf("MEMIF DETAILS\n");