Commit Graph

81 Commits

Author SHA1 Message Date
Martin Pulec
abd758241a debug: move some stuff to utils/debug
The rationale is to separate the config.h-dependent stuff to a separate
file to eliminate the need to transitively include config.h.

+ fix the files that need config.h directly to include it
2024-11-28 11:46:09 +01:00
Martin Pulec
4e13bc903c add MSG_ONCE
refer to GH-411
2024-10-08 12:31:59 +02:00
Martin Pulec
3e791253b4 MSG(): check log_level early
Improve MSG() in a way that LOG() is - check the log_level first and if
not printed, just skip. Previously the eventual arguments were evaluated
and also log_msg() was called (althoug exitted immediately).
2024-09-26 10:02:12 +02:00
Martin Pulec
50812bba34 replacing PACKAGE_BUGREPORT with bug_msg
Where the PACKAGE_BUGREPORT is the only used item from config.h,
use bug_msg(), which can be then removed.

Improved bug_msg() to allow printf-like fomat + arguments.
2024-08-14 15:26:12 +02:00
Martin Pulec
220e8b4744 replace BUG_MSG with bug_msg() fn
used just in DirectShowGrabber
2024-08-14 10:42:01 +02:00
Martin Pulec
1454e66fba debug.h: MSG: allow MOD_NAME to be a varible
Allow the MOD_NAME to be a variable (like (constexpr const char *)). Using
non-standard extension, the standard one would be __VA_OPT__. Although
it is supported with MSVC 2019/2022, it requires the compiler flag
/Zc:preprocessor.

This version doesn't require that so use it for now. The MSVC is used to
compile the CUDA code and AJA wrapper so not to complicate the things now.

This syntax is supported for both GNU and MSVC:
1. https://stackoverflow.com/a/78185169
2. https://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html

refer to GH-375
2024-06-03 16:39:30 +02:00
Martin Pulec
48cbffa345 debug.h: include config.h
DEBUG macro is usedi in this file and it is defined with autoconf in
config.h.
2024-01-12 08:52:22 +01:00
Martin Pulec
7deb2dc24f Logger: appending TERM_RESET before NL fix
Do not crash with out_of_range exception if trying to output empty log
(`LOG(LOG_LEVEL_INFO) << "";`) - either intentionally or by mistake.

Check if output has really size >0 before comparing last char with '\n'.

Rewritten a bit, but only functional change is the above. Eg. it was
slightly counterintuitive comparing msg[msg.size() - sizeof TERM_RESET]
to '\n'. This actually caused the crash on empty string, even though
TERM_RESET was appended. It is because `sizeof TERM_RESET` counts
'\0', which is not counted in C++ string. Semantically better would
have been `strlen(TERM_RESET) - 1`, from which is obvious it will fail
if output string was originally empty.
2023-11-08 12:59:30 +01:00
Martin Pulec
fea0d10f67 improved UG FFmpeg logger
do not prefix messages not starting on new line by timestamps, eg.:

    $ uv -s embedded -t testcard -d file:n=/dev/null -V
    [1698853041.393] [lavc]   Stream #0:0[1698853041.393] : Video: rawvideo, 1 reference frame (UYVY / 0x59565955), uyvy422, 1920x1080 (0x0), q=2-31, 829440 kb/s[1698853041.393] , [1698853041.393] 25 tbn[1698853041.393]

Flush the output only on NL and before it store it in internal
thread-local buffer.

Locking was removed as static data are now thread-local.

this improves 808b3de3
2023-11-01 17:01:31 +01:00
Martin Pulec
d04b1def74 debug.h: added shortcut macro
to save needed characters typed, instead of

`log_msg(LOG_LEVEL_ERROR, MOD_NAME "This is an error!");`

type just

`MSG(ERROR, "This is an error!")`
2023-09-19 11:14:26 +02:00
Martin Pulec
d17c5ea24c removed platform_time.c + references
get_time_in_ns() should be used instead time_since_epoch_in_ms(). Having
both may be misleading and may lead to errors when interchanged.
2023-08-08 15:32:29 +02:00
Martin Piatka
aa0adb152e logger: Add missing initialization
Doesn't really matter since it's set in host.cpp
2023-05-23 13:05:14 +02:00
Martin Pulec
183d175d73 fixed some of new Coverity issues 2023-05-10 08:52:02 +02:00
Martin Pulec
04a0bf581b removed ATTRIBUTE macros
This was unnecessary compat macro, since we always build with a compiler
that understands __attribute__ except of the AJA module in MSW, which
uses MSVC compiler
2023-05-02 15:22:55 +02:00
Martin Pulec
be4659469b log_msg_once updates
use static, not thread_local storage

This has an implications that the message is indeed printed once, even
though is called from 2 threads (this can happen eg. when printed once
during normal operation and then during module deletion, that may happen
in a different thread).
2023-04-24 13:50:33 +02:00
Martin Pulec
653cec55ab log_vprintf: return void instead of int
The returned value was actually incorrect (counting also formatting
escape sequences and terminating nul byte).

Since the return value should not be important for the caller, it is
perhaps better not to complicate and don't return anything.
2023-04-12 12:52:08 +02:00
Martin Pulec
cac1d11190 updated copyrights of files changed in 2023 2023-02-09 09:19:50 +01:00
Martin Pulec
2afcdf3c1f print which pixel format cannot be deinterlaced
Needs adding log_msg_once variable arguments (printf-like).

+ print always error in deinterlace - if user explicitly wants
  deinterlace PP, maybe we should notify loudly
2023-01-10 16:41:52 +01:00
Martin Pulec
e3574d3d66 one-shot logger updates
On one-shot second and further calls of one-shot message, no output was
producet, yet empty buffer was submitted to Log_output resulting in
false repeate messages:

    Last message repeated <n> times

To simplify the stuff, C++ API was removed and in the C API the Logger
is taken only if actual message will be output. If someone is willing to
use the C++ API, it can be later readded (not really needed now, only
simple message are presented).
2023-01-10 16:17:37 +01:00
Martin Pulec
6233c170dd debug_dump: (const void*) instead of (void*) param 2022-11-10 09:17:39 +01:00
Martin Pulec
6c88f3b971 logger: fixed non-interactive crash when msg size < sizeof TERM_RESET 2022-11-02 10:20:09 +01:00
Martin Piatka
4b6a048752 logging: Wrap thread local buffer initialization in a function
resolves a crash on RPi
2022-10-26 17:05:26 +02:00
Martin Pulec
ab152abb04 audio testcard: error on WAV reading error
If WAV is used, error if size is 0 - it doesn't make any case to
continue and it will fil on floating point exception, anyways.
2022-10-10 09:28:37 +02:00
Martin Pulec
771637a91e added log_vprintf 2022-09-23 15:01:20 +02:00
Martin Pulec
f4f7b0c426 Logger: switch order of TERM_RESET and '\n'
If logged message ends with '\n', put TERM_RESET before it (it prevents
keeping the color if someone writes to stderr directly).
2022-09-15 10:59:40 +02:00
Martin Pulec
383a00844f DEBUG_TIMER: use time_ns_t 2022-08-10 13:45:07 +02:00
Martin Pulec
cf58ff3948 added missing includes 2022-08-10 13:45:07 +02:00
Martin Pulec
128150288b logger: removed preinit
no longer needed to initialize rang here
2022-08-10 10:00:07 +02:00
Martin Pulec
812bcbfc78 logger: remove ANSI seqences if not terminal
This allows use of raw ANSI sequences instead of the rang stuff.
2022-08-10 08:14:07 +02:00
Martin Pulec
7719e8aa47 logger: get rid of rang references 2022-08-10 08:14:07 +02:00
Martin Piatka
ca0421787a keyboard_control: use getter&setter for repeat skipping 2022-08-05 13:44:35 +02:00
Martin Piatka
386ea3ec16 logging: reset style only on tty 2022-08-03 13:16:03 +02:00
Martin Piatka
853015ecec logging: work around stringstream cast
The << operator for stringstream casts the result to basic_ostream
which does not have the .str() method on some compilers. (See C++ defect
report 1023).
2022-08-03 12:00:14 +02:00
Martin Piatka
ddcf2bf399 logging: Add submit_raw 2022-08-03 10:43:43 +02:00
Martin Piatka
332000e4b8 logging: check if output is a terminal only once 2022-08-03 10:43:43 +02:00
Martin Piatka
c0a9db6d0f logging: reserve space in buffer 2022-08-03 10:43:42 +02:00
Martin Piatka
04fbcddfed logging: expose styles as strings 2022-08-03 10:43:42 +02:00
Martin Piatka
c439b05887 logging: Log_out: nicer interface 2022-08-03 10:43:41 +02:00
Martin Piatka
d108c068f4 logging: Log_output: avoid using streams
Avoids an allocation and copy for timestamp
2022-08-03 10:43:41 +02:00
Martin Piatka
b4144ffa5b logging: put style reset into the msg buffer 2022-08-03 10:43:41 +02:00
Martin Piatka
241c930299 logging: Flush stream on msg repeat
Since the repeat msg does not contain a newline we need to flush the
stream to make sure it appears when stream buffering is used
2022-08-03 10:43:40 +02:00
Martin Piatka
e031547a1d logging: use mutex for repeated msg checking
The previous implementation using atomics was not entirely correct,
since the following situation could happen:

1. Thread 1 detects a msg repeat
2. Thread 2 prints a message before thread 1 could print repeat notice
3. Thread 1 outputs "last msg repeated" for the msg from step 1

The stdout stream uses locking internaly anyway, so this should not have
any significant overhead. On the other hand this simplifies the code,
eliminates an allocation and fixes the leak on exit.
2022-08-03 10:43:40 +02:00
Martin Piatka
65d7cf69b8 logging: Split timestamp and repeat functionality into its own class
This will eventually allow better integration with other formatting
functions like color_out, color_printf
2022-08-03 10:41:14 +02:00
Martin Piatka
44294ef0c6 logging: Logger: set color&style in constructor 2022-08-03 10:13:31 +02:00
Martin Pulec
ec20f7877c logger: trigger flush on repeated messages
When the output is line-buffered, the repeated message isn't immediately
printed.
2022-08-03 09:51:07 +02:00
Martin Piatka
d18fb0300e logging: Call preinit before parsing log config
Since help text containing ANSI escape codes can be shown during parsing
(i.e. on error or help text), preinit should be called sooner
2022-07-29 13:03:28 +02:00
Martin Piatka
d496f738f2 logging: setters for timestamp and skip_repeat 2022-07-29 13:03:28 +02:00
Martin Piatka
e1b51bda18 logging: separate config parsing from setting log level 2022-07-29 13:03:27 +02:00
Martin Piatka
07f245c5ec logging: Use enum for timestamp mode 2022-07-29 13:03:27 +02:00
Martin Pulec
a22ff7a5f1 lavc: debug dump spot for converted AVFrame
+ change first parameter of serialize callback to (const void *)
+ renamed "lavd-uncompressed" to "lavd-avframe" - uncompressed is vague
  since there are multiple forms of uncompressed - avframe, ultragrid
  pixfmt...
2021-11-26 12:19:17 +01:00