Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MCM logging improvements #197

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions media-proxy/imtl.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,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"
}
]
}
78 changes: 62 additions & 16 deletions media-proxy/include/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,70 @@
#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,
Expand Down
49 changes: 27 additions & 22 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,13 +1150,14 @@ 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__);
Expand Down Expand Up @@ -1186,6 +1188,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 +1203,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 +1239,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 +1280,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 +1316,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 +2663,22 @@ 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);
INFO("%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 +2690,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 +2846,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 +2947,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));
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