void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl) { static int print_prefix = 1; static int count; static char prev[1024]; char line[1024]; static int is_atty; if (level > av_log_level) return; av_log_format_line(ptr, level, fmt, vl, line, sizeof(line), &print_prefix); #if HAVE_ISATTY if (!is_atty) is_atty = isatty(2) ? 1 : -1; #endif #undef fprintf if (print_prefix && (flags & AV_LOG_SKIP_REPEATED) && !strcmp(line, prev)){ count++; if (is_atty == 1) fprintf(stderr, " Last message repeated %d times\r", count); return; } if (count > 0) { fprintf(stderr, " Last message repeated %d times\n", count); count = 0; } strcpy(prev, line); sanitize(line); colored_fputs(av_clip(level >> 3, 0, 6), line); }
void LibAvW_ErrorCallback(void* ptr, int level, const char* fmt, va_list vl) { int print_prefix = 1; char line[1024]; // we only want warning, error, fatal and panic if (!libav_print) return; if (level > AV_LOG_WARNING) return; #ifdef LIBAV95 vsprintf_s(line, sizeof(line), fmt, vl); #else av_log_format_line(ptr, level, fmt, vl, line, sizeof(line), &print_prefix); #endif sanitize(line); if (level == AV_LOG_WARNING) libav_print(LIBAVW_PRINT_WARNING, line); else if (level == AV_LOG_ERROR) libav_print(LIBAVW_PRINT_ERROR, line); else if (level == AV_LOG_FATAL) libav_print(LIBAVW_PRINT_FATAL, line); else libav_print(LIBAVW_PRINT_PANIC, line); }
// TODO, remove static variables to support multi-instances void nam_av_log_callback(void* ptr, int level, const char* fmt, va_list vl) { static int print_prefix = 1; static int count; static char prev[1024]; char line[1024]; static int is_atty; if (level > av_log_get_level()) return; av_log_format_line(ptr, level, fmt, vl, line, sizeof(line), &print_prefix); if (print_prefix && (flags & AV_LOG_SKIP_REPEATED) && !strcmp(line, prev)){ count++; return; } if (count > 0) { LOGI("Last message repeated %d times\n", count); count = 0; } strcpy(prev, line); sanitize((uint8_t *)line); #if 0 LOGI("%s", line); #else #define LOG_BUF_SIZE 1024 static char g_msg[LOG_BUF_SIZE]; static int g_msg_len = 0; int saw_lf, check_len; do { check_len = g_msg_len + strlen(line) + 1; if (check_len <= LOG_BUF_SIZE) { /* lf: Line feed ('\n') */ saw_lf = (strchr(line, '\n') != NULL) ? 1 : 0; strncpy(g_msg + g_msg_len, line, strlen(line)); g_msg_len += strlen(line); if (!saw_lf) { /* skip */ return; } else { /* attach the line feed */ g_msg_len += 1; g_msg[g_msg_len] = '\n'; } } else { /* trace is fragmented */ g_msg_len += 1; g_msg[g_msg_len] = '\n'; } LOGI("%s", g_msg); /* reset g_msg and g_msg_len */ memset(g_msg, 0, LOG_BUF_SIZE); g_msg_len = 0; } while (check_len > LOG_BUF_SIZE); #endif }
static void log(void *avcl, int level, const char *fmt, va_list args) { return ; char line[1024]; int print_prefix = 1; av_log_format_line(avcl, level, fmt, args, line, sizeof(line), &print_prefix); qDebug(line); }
static void plex_log_callback(void* ptr, int level, const char* fmt, va_list vl) { int print_prefix = 1; char line[1024]; va_list vl2; #if HAVE_PTHREADS char *cur_line; pthread_once(&key_once, make_keys); #else static __thread char cur_line[LOG_LINE_SIZE] = {0}; static __thread int logging = 0; #endif va_copy(vl2, vl); av_log_default_callback(ptr, level, fmt, vl2); if (level > av_log_level_plex) return; //Avoid recusive logging #if HAVE_PTHREADS if (pthread_getspecific(logging_key)) return; cur_line = pthread_getspecific(cur_line_key); if (!cur_line) { cur_line = av_mallocz(LOG_LINE_SIZE); if (!cur_line) return; pthread_setspecific(cur_line_key, cur_line); } pthread_setspecific(logging_key, (void*)1); #else if (logging) return; logging = 1; #endif av_log_format_line(ptr, level, fmt, vl, line, sizeof(line), &print_prefix); av_strlcat(cur_line, line, LOG_LINE_SIZE); if (print_prefix) { int len = strlen(cur_line); if (len) { cur_line[len - 1] = 0; PMS_Log(level < AV_LOG_ERROR ? LOG_LEVEL_ERROR : (level / 8) - 2, "%s", cur_line); cur_line[0] = 0; } } #if HAVE_PTHREADS pthread_setspecific(logging_key, NULL); #else logging = 0; #endif }
static void av_qsv_log_callback(void *ptr, int level, const char *fmt, va_list vl) { if (auto pQSVLog = g_pQSVLog.lock()) { const int qsv_log_level = log_level_av2rgy(level); if (qsv_log_level >= pQSVLog->getLogLevel() && pQSVLog->logFileAvail()) { char mes[4096]; av_log_format_line(ptr, level, fmt, vl, mes, sizeof(mes), &print_prefix); pQSVLog->write_log(qsv_log_level, char_to_tstring(mes, CP_UTF8).c_str(), true); } } av_log_default_callback(ptr, level, fmt, vl); }
static void log_callback_report(void *ptr, int level, const char *fmt, va_list vl) { va_list vl2; char line[1024]; static int print_prefix = 1; va_copy(vl2, vl); av_log_default_callback(ptr, level, fmt, vl); av_log_format_line(ptr, level, fmt, vl2, line, sizeof(line), &print_prefix); va_end(vl2); fputs(line, report_file); fflush(report_file); }
static void ffmpeg_log_callback(void* context, int level, const char* format, va_list args) { if (format == NULL) return; struct log_context *log_context = create_or_fetch_log_context(context); char *str = log_context->str; av_log_format_line(context, level, format, args, str + strlen(str), (int)(sizeof(log_context->str) - strlen(str)), &log_context->print_prefix); int obs_level; switch (level) { case AV_LOG_PANIC: case AV_LOG_FATAL: obs_level = LOG_ERROR; break; case AV_LOG_ERROR: case AV_LOG_WARNING: obs_level = LOG_WARNING; break; case AV_LOG_INFO: case AV_LOG_VERBOSE: obs_level = LOG_INFO; break; case AV_LOG_DEBUG: default: obs_level = LOG_DEBUG; } if (!log_context->print_prefix) return; char *str_end = str + strlen(str) - 1; while(str < str_end) { if (*str_end != '\n') break; *str_end-- = '\0'; } if (str_end <= str) goto cleanup; blog(obs_level, "[ffmpeg] %s", str); cleanup: destroy_log_context(log_context); }
void callbackToWriteInFile(void* ptr, int level, const char* fmt, va_list vl) { std::ofstream outputFile; outputFile.open(LOG_FILE, std::ios::out | std::ios::app); #ifdef AVTRANSCODER_FFMPEG_DEPENDENCY // Format a line of log the same way as the default callback char line[1024]; static int print_prefix = 1; av_log_format_line(ptr, level, fmt, vl, line, sizeof(line), &print_prefix); // only available with ffmpeg outputFile << line; #else outputFile << "Warning: currently can't log in file with avtranscoder when depending on libav" << std::endl; #endif outputFile.close(); }
void log_ffmpeg(void* ptr, int level, const char* fmt, va_list vl) { static int print_prefix = 1; char line[1024]; #ifndef MCUDEBUG if (level > AV_LOG_ERROR) return; #endif //Format the av_log_format_line(ptr, level, fmt, vl, line, sizeof(line), &print_prefix); //Remove buffer errors if (strstr(line,"vbv buffer overflow")!=NULL) //exit return; //Log Log(line); }
//------------------------------------------------------------------------------ // This is a slightly modified version of the default ffmpeg log callback void log_callback(void* ptr, int level, const char* fmt, va_list vl) { static int print_prefix = 1; static int count; static char prev[1024]; char line[1024]; std::string message = ""; // Do not get logs we do not want if (level > av_log_get_level()) { return; } // Let FFmpeg do the line formatting av_log_format_line(ptr, level, fmt, vl, line, 1024, &print_prefix); // We do not want repeated messages, just count them if (print_prefix && !strcmp(line, prev) && *line && line[strlen(line) - 1] != '\r') { count++; return; } if (count > 0) { message.append(" Last message repeated " + boost::lexical_cast<std::string>(count) + " times\n"); count = 0; } strcpy(prev, line); message.append(line); // Print/log the message if (!staticOgreLog) { std::cout << message << std::endl; } else { staticOgreLog->logMessage(message, Ogre::LML_NORMAL); } }
void record_show_function_result(void* avcl, int level, const char* fmt, ...) { int len; char * record; va_list ap; va_start(ap, fmt); UNUSED(avcl); UNUSED(level); memset(record_line, '\0', RECORD_LINE_SZ); av_log_format_line(NULL, AV_LOG_INFO, fmt, ap, record_line, RECORD_LINE_SZ, &print_prefix); len = strlen(record_line); record = record_result + show_function_result_position; strncpy(record, record_line, len); show_function_result_position += len; if (show_function_result_position >= MAX_SIZE) { show_function_result_position -= len; record_result[show_function_result_position] = '\0'; } va_end(ap); }