return (*(AVClass **) ptr)->class_name;
}
-void av_log_default_callback(void *avcl, int level, const char *fmt, va_list vl)
+AVClassCategory av_default_get_category(void *ptr)
+{
+ return (*(AVClass **) ptr)->category;
+}
+
+static void sanitize(uint8_t *line){
+ while(*line){
+ if(*line < 0x08 || (*line > 0x0D && *line < 0x20))
+ *line='?';
+ line++;
+ }
+}
+
+static int get_category(void *ptr){
+ AVClass *avc = *(AVClass **) ptr;
+ if( !avc
+ || (avc->version&0xFF)<100
+ || avc->version < (51 << 16 | 59 << 8)
+ || avc->category >= AV_CLASS_CATEGORY_NB) return AV_CLASS_CATEGORY_NA + 16;
+
+ if(avc->get_category)
+ return avc->get_category(ptr) + 16;
+
+ return avc->category + 16;
+}
+
- static void format_line(void *ptr, int level, const char *fmt, va_list vl,
++static void format_line(void *avcl, int level, const char *fmt, va_list vl,
+ AVBPrint part[3], int *print_prefix, int type[2])
{
- AVClass* avc = ptr ? *(AVClass **) ptr : NULL;
- static int print_prefix = 1;
- static int count;
- static char prev[1024];
- char line[1024];
- static int is_atty;
+ AVClass* avc = avcl ? *(AVClass **) avcl : NULL;
- if (level > av_log_level)
- return;
- line[0] = 0;
- if (print_prefix && avc) {
+ av_bprint_init(part+0, 0, 1);
+ av_bprint_init(part+1, 0, 1);
+ av_bprint_init(part+2, 0, 65536);
+
+ if(type) type[0] = type[1] = AV_CLASS_CATEGORY_NA + 16;
+ if (*print_prefix && avc) {
if (avc->parent_log_context_offset) {
- AVClass** parent = *(AVClass ***) (((uint8_t *) ptr) +
+ AVClass** parent = *(AVClass ***) (((uint8_t *) avcl) +
avc->parent_log_context_offset);
if (parent && *parent) {
- snprintf(line, sizeof(line), "[%s @ %p] ",
+ av_bprintf(part+0, "[%s @ %p] ",
(*parent)->item_name(parent), parent);
+ if(type) type[0] = get_category(parent);
}
}
- snprintf(line + strlen(line), sizeof(line) - strlen(line), "[%s @ %p] ",
+ av_bprintf(part+1, "[%s @ %p] ",
- avc->item_name(ptr), ptr);
- if(type) type[1] = get_category(ptr);
+ avc->item_name(avcl), avcl);
++ if(type) type[1] = get_category(avcl);
}
- vsnprintf(line + strlen(line), sizeof(line) - strlen(line), fmt, vl);
+ av_vbprintf(part+2, fmt, vl);
- print_prefix = strlen(line) && line[strlen(line) - 1] == '\n';
+ if(*part[0].str || *part[1].str || *part[2].str) {
+ char lastc = part[2].len && part[2].len <= part[2].size ? part[2].str[part[2].len - 1] : 0;
+ *print_prefix = lastc == '\n' || lastc == '\r';
+ }
+}
+
+void av_log_format_line(void *ptr, int level, const char *fmt, va_list vl,
+ char *line, int line_size, int *print_prefix)
+{
+ AVBPrint part[3];
+ format_line(ptr, level, fmt, vl, part, print_prefix, NULL);
+ snprintf(line, line_size, "%s%s%s", part[0].str, part[1].str, part[2].str);
+ av_bprint_finalize(part+2, NULL);
+}
+
+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[LINE_SZ];
+ AVBPrint part[3];
+ char line[LINE_SZ];
+ static int is_atty;
+ int type[2];
+
+ if (level > av_log_level)
+ return;
+#if HAVE_PTHREADS
+ pthread_mutex_lock(&mutex);
+#endif
+
+ format_line(ptr, level, fmt, vl, part, &print_prefix, type);
+ snprintf(line, sizeof(line), "%s%s%s", part[0].str, part[1].str, part[2].str);
#if HAVE_ISATTY
if (!is_atty)