Explorar el Código

codaj12: Add log control by export JPU_DEBUG=<value>

enum
{
    ERR=0,
    WARN,
    TRACE,
    INFO,
    DEBUG,
    MAX_LOG_LEVEL
};

Signed-off-by: sw.multimedia <sw.multimedia@starfivetech.com>
sw.multimedia hace 2 años
padre
commit
8e5ea9f3f7

+ 42 - 0
soft_3rdpart/codaj12/sample/helper/jpulog.c

@@ -40,6 +40,16 @@ static struct termios initial_settings, new_settings;
 static int peek_character = -1;
 #endif
 
+#define ANSI_COLOR_ERR      "\x1b[31m"       // RED
+#define ANSI_COLOR_TRACE    "\x1b[32m"       // GREEN
+#define ANSI_COLOR_WARN     "\x1b[33m"       // YELLOW
+#define ANSI_COLOR_BLUE     "\x1b[34m"       // BLUE
+#define ANSI_COLOR_INFO     ""
+// For future
+#define ANSI_COLOR_MAGENTA  "\x1b[35m"       // MAGENTA
+#define ANSI_COLOR_CYAN     "\x1b[36m"       // CYAN
+#define ANSI_COLOR_RESET    "\x1b[0m"        // RESET
+
 static int log_colors[MAX_LOG_LEVEL] = {
 	0,
 	TERM_COLOR_R|TERM_COLOR_G|TERM_COLOR_B|TERM_COLOR_BRIGHT, 	//INFO
@@ -51,6 +61,7 @@ static int log_colors[MAX_LOG_LEVEL] = {
 static unsigned log_decor = LOG_HAS_TIME | LOG_HAS_FILE | LOG_HAS_MICRO_SEC |
 			    LOG_HAS_NEWLINE |
 			    LOG_HAS_SPACE | LOG_HAS_COLOR;
+static int max_log_level = ERR;
 static FILE *fpLog  = NULL;
 
 #ifdef WIN32
@@ -78,6 +89,16 @@ void DeInitLog()
     }
 }
 
+void SetMaxLogLevel(int level)
+{
+	max_log_level = level;
+}
+
+int GetMaxLogLevel()
+{
+	return max_log_level;
+}
+
 void SetLogColor(int level, int color)
 {
 	log_colors[level] = color;
@@ -102,6 +123,25 @@ void LogMsg(int level, const char *format, ...)
 {
 	va_list ptr;
 	char logBuf[MAX_PRINT_LENGTH] = {0};
+    char*   prefix = "";
+    char*   postfix= "";
+
+    if (level > max_log_level)
+        return;
+#if defined(SUPPORT_SW_UART) || defined(SUPPORT_SW_UART_V2)
+	pthread_mutex_lock(&s_log_mutex);
+#endif
+
+    if ((log_decor & LOG_HAS_COLOR)) {
+        postfix = ANSI_COLOR_RESET;
+        switch (level) {
+        case INFO:  prefix = ANSI_COLOR_INFO;  break;
+        case ERR:   prefix = ANSI_COLOR_ERR "[ERROR]";   break;
+        case TRACE: prefix = ANSI_COLOR_TRACE; break;
+        case WARN:  prefix = ANSI_COLOR_WARN"[WARN ]";  break;
+        default:    prefix = "";               break;
+        }
+    }
 
 	va_start( ptr, format );
 #if defined(WIN32) || defined(__MINGW32__)
@@ -137,6 +177,8 @@ void LogMsg(int level, const char *format, ...)
 	}
 	puts(logBuf);
 #else
+    fputs(prefix,  stderr);
+    fputs(postfix, stderr);
     fprintf(stderr, logBuf);
     //fputs(logBuf, stderr);
 #endif

+ 10 - 1
soft_3rdpart/codaj12/sample/helper/jpulog.h

@@ -33,7 +33,16 @@
 
 
 
-enum {NONE=0, INFO, WARN, ERR, TRACE, MAX_LOG_LEVEL};
+enum
+{
+    ERR=0,
+    WARN,
+    TRACE,
+    INFO,
+    DEBUG,
+    MAX_LOG_LEVEL
+};
+
 enum
 {
     LOG_HAS_DAY_NAME   =    1, /**< Include day name [default: no] 	      */

+ 15 - 0
soft_3rdpart/omx-il/component/image/common/SF_OMX_mjpeg_common.c

@@ -73,6 +73,20 @@ OMX_ERRORTYPE InitMjpegStructorCommon(SF_OMX_COMPONENT *pSfOMXComponent)
     memset(pSfCodaj12Implement->functions, 0, sizeof(SF_CODAJ12_FUNCTIONS));
     sf_get_component_functions(pSfCodaj12Implement->functions, pSfOMXComponent->soHandle);
 
+    // Init JPU log
+    if (pSfCodaj12Implement->functions->SetMaxLogLevel)
+    {
+        strDebugLevel = getenv("JPU_DEBUG");
+        if (strDebugLevel)
+        {
+            debugLevel = atoi(strDebugLevel);
+            if (debugLevel >=0)
+            {
+                pSfCodaj12Implement->functions->SetMaxLogLevel(debugLevel);
+            }
+        }
+    }
+
     if (strstr(pSfOMXComponent->componentName, "sf.dec") != NULL)
     {
         pSfCodaj12Implement->config = malloc(sizeof(DecConfigParam));
@@ -202,6 +216,7 @@ static void sf_get_component_functions(SF_CODAJ12_FUNCTIONS *funcs, OMX_PTR *soh
     funcs->GetFrameBuffer = dlsym(sohandle, "GetFrameBuffer");
     funcs->GetFrameBufferCount = dlsym(sohandle, "GetFrameBufferCount");
     funcs->UpdateFrameBuffers = dlsym(sohandle, "UpdateFrameBuffers");
+    funcs->SetMaxLogLevel = dlsym(sohandle, "SetMaxLogLevel");
     FunctionOut();
 }
 

+ 3 - 0
soft_3rdpart/omx-il/component/image/common/SF_OMX_mjpeg_common.h

@@ -77,6 +77,9 @@ typedef struct _SF_CODAJ12_FUNCTIONS
     Uint32 (*GetFrameBufferCount)(int instIdx);
 
     BOOL (*UpdateFrameBuffers)(Uint32 instIdx, Uint32 num, FRAME_BUF *frameBuf);
+
+    // JPU Log
+    void (*SetMaxLogLevel)(int level);
 } SF_CODAJ12_FUNCTIONS;
 
 typedef struct _THREAD_HANDLE_TYPE {