Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Video AG Infrastruktur
ffworker
Commits
3e605479
Commit
3e605479
authored
Nov 27, 2017
by
Julian Rother
Browse files
avlogbuf: Collapse repeating messages
parent
22d0d3a1
Changes
1
Show whitespace changes
Inline
Side-by-side
util/avlogbuf.c
View file @
3e605479
...
...
@@ -6,6 +6,9 @@
static
char
*
logbuffer
;
static
size_t
logsize
;
static
FILE
*
logstream
;
static
pthread_mutex_t
mutex
=
PTHREAD_MUTEX_INITIALIZER
;
static
char
prevbuf
[
200
]
=
""
;
static
int
repeats
=
0
;
void
init_avlogbuf
(
void
)
{
...
...
@@ -20,21 +23,39 @@ void avlogbuf_callback(void *class, int level, const char *fmt, va_list ap)
{
int
print_prefix
;
char
buf
[
200
];
if
(
level
>
=
AV_LOG_
VERBOSE
)
if
(
level
>
AV_LOG_
WARNING
)
return
;
print_prefix
=
1
;
av_log_format_line
(
class
,
level
,
fmt
,
ap
,
BL
(
buf
),
&
print_prefix
);
if
(
pthread_mutex_lock
(
&
mutex
))
return
;
if
(
!
strcmp
(
buf
,
prevbuf
))
{
repeats
++
;
pthread_mutex_unlock
(
&
mutex
);
return
;
}
if
(
repeats
)
fprintf
(
logstream
,
"Last message repeated %d times
\n
"
,
repeats
);
repeats
=
0
;
strcpy
(
prevbuf
,
buf
);
fputs
(
buf
,
logstream
);
pthread_mutex_unlock
(
&
mutex
);
}
char
*
get_avlogbuf
(
void
)
{
char
*
p
;
char
*
p
,
*
tmp
;
if
(
!
logstream
)
return
""
;
fclose
(
logstream
);
p
=
logbuffer
;
init_avlogbuf
();
fputs
(
p
,
logstream
);
if
(
repeats
)
{
tmp
=
mprintf
(
"%sLast message repeated %d times
\n
"
,
p
,
repeats
);
free
(
p
);
p
=
tmp
;
}
return
p
;
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment