Skip to content

Commit

Permalink
MCM st22 fix and logging improvements
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Mionsz committed Sep 23, 2024
1 parent c7b6f9a commit dc7533c
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 57 deletions.
23 changes: 19 additions & 4 deletions media-proxy/imtl.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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"
}
]
}
80 changes: 63 additions & 17 deletions media-proxy/include/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,74 @@
#ifndef __UTILS_H
#define __UTILS_H

#ifndef MCM_LOG_LEVEL
#define MCM_LOG_LEVEL 16
#endif

#include <stdio.h>

#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
66 changes: 36 additions & 30 deletions media-proxy/src/mtl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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 */
Expand All @@ -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__);
Expand All @@ -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 */
Expand All @@ -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 */
Expand All @@ -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;
}

Expand All @@ -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 */
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
}

Expand All @@ -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 */
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down
7 changes: 1 addition & 6 deletions media-proxy/tests/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,14 @@

#include "libmemif.h"
#include "shm_memif.h"
#include "utils.h"

#define FRAME_SIZE 8294400 // yuv422p10le (1920*1080*4)
#define FRAME_COUNT 1

/* 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");
Expand Down

0 comments on commit dc7533c

Please sign in to comment.