Commit graph

86 commits

Author SHA1 Message Date
Nick Steel b7b5352353 log: Log trait adapter around the GStreamer debug system
Allows usage of normal `log` crate macros, and for other crates
using those macros to have their log messages go to the GStreamer
debug logs.

This implementation is based on the one found in Servo.

Fixes #187

DebugCategoryLogger is optional via 'log' feature
check category above threshold
skip_assert_initialized for constructor and helper

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1426>
2024-04-29 16:16:47 +01:00
Bilal Elmoussaoui aaea288abf Adapt to no longer re-exported traits
Some of the traits were moved to prelude or translate
and no longer in the main scope of the crate

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1382>
2024-02-03 10:48:37 +01:00
Sebastian Dröge 193bcbf055 Switch from once_cell to std::sync::OnceLock where it makes sense
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1379>
2024-01-31 14:59:54 +02:00
Guillaume Desmottes f255b82b55 gstreamer: move debug_* functions to their own module
Better namespacing so the API is more Rust-y.

Fix #500

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1355>
2023-12-04 12:46:59 +01:00
Sebastian Dröge 83a562e227 Fix/silence various 1.72 clippy warnings
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1306>
2023-08-28 16:50:41 +00:00
Bilal Elmoussaoui f9fa7f55fc Use re-exported once_cell
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1293>
2023-07-06 16:50:35 +03:00
Sebastian Dröge adea2428af gstreamer: Only retrieve the debug category once per log call
Each retrieval would go through the one-time-initialization check, i.e.
yet another branch, so let's avoid that.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1263>
2023-05-13 20:44:42 +03:00
Sebastian Dröge 4f8862e15b gstreamer: Remove unnecessary clone() in debug logging macros
The macro called from them is already doing the `clone()` itself.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1263>
2023-05-13 20:44:42 +03:00
Sebastian Dröge 074a2b1578 gstreamer: Use temporary GStr for the debug category constructors
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1263>
2023-05-13 20:44:42 +03:00
Sebastian Dröge 4384934b32 gstreamer: Mark DebugCategory as repr(transparent)
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1263>
2023-05-13 14:06:58 +03:00
François Laignel 13f0483a44 gst: Manually impl Bin & Pipeline constructors
Set `Bin` & `Pipeline` constructors to manual implementation to remove
optional `name` argument (use builder to specify name).

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1255>
2023-05-12 10:55:46 +00:00
Sebastian Dröge 33d4969493 gstreamer: Get function name for logging outside the internal closure
Otherwise the function name will include the name of the closure.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1260>
2023-05-10 11:14:21 +03:00
Sebastian Dröge 3699da7314 Remove dox feature and replace by docsrs configuration
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1256>
2023-05-04 09:19:29 +03:00
Sebastian Dröge f24b38470b Fix various new clippy warnings
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1203>
2023-01-25 10:18:33 +02:00
Sebastian Dröge 37bfb78fdc Change some assertions to debug assertions
These assertions can only trigger because of bugs in the bindings
implementation or in the C code and not because of bugs in calling code,
so using debug assertions is perfectly fine for them and reduces the
number of assertions inlined everywhere in release builds.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1188>
2023-01-14 17:13:46 +02:00
Sebastian Dröge f235dc987d Inline various trivial functions
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1177>
2023-01-11 11:33:54 +02:00
Sebastian Dröge 567ce0a3bf Group and merge imports in all manual code
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1182>
2023-01-04 13:25:17 +02:00
Sebastian Dröge ae688406f8 gstreamer: Allocate debug messages up to 256 bytes on the stack and only then spill over into the heap
With this, debug logging from Rust is completely allocation-less for
short messages and string literals.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1179>
2023-01-03 10:28:43 +00:00
Sebastian Dröge 06a0dbacba gstreamer: Don't inline debug logging function
It's relatively big and increases code size and stack usage quite a bit,
and having a function call for logging is not going to make much of a
difference as it happens *after* filtering for the debug level
threshold.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1179>
2023-01-03 10:28:43 +00:00
Sebastian Dröge 882513d33a Make use of the new TransparentType / TransparentPtrType traits
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1178>
2023-01-02 19:07:24 +02:00
Sebastian Dröge 146b4fc08e gstreamer: Fix glib::GStr API changes 2022-12-25 00:25:42 +02:00
Sebastian Dröge 0fa8d0d62f gstreamer: Fix formatting if a string literal needs formatting
E.g. "blabla {some_variable}" is a string literal but needs formatting,
so we can't just pass it as a literal to the logger.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1161>
2022-12-11 12:20:35 +02:00
Sebastian Dröge 2a935320e7 gstreamer: Replace some generic function parameters with impl trait
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1160>
2022-12-10 20:18:11 +02:00
Sebastian Dröge ef5d5f50e4 gstreamer: Actually log the function name instead of the module name
As there is no way to get the function name as a string literal
currently, we have to copy locally into a NUL-terminated array.
Up to 256 bytes this is managed on the stack, otherwise a heap
allocation is necessary.

For the <256 bytes case the compiler is optimizing most of this away.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1160>
2022-12-10 20:18:11 +02:00
Sebastian Dröge 355ebc243f gstreamer: Add DebugCategory::above_threshold() to check if the category's threshold is above the given level
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1160>
2022-12-10 20:18:11 +02:00
Sebastian Dröge b58d518aa3 gstreamer: Use glib::GStr for DebugMessage string API too
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1160>
2022-12-10 20:18:11 +02:00
Sebastian Dröge de04e3f827 gstreamer: Reduce allocations in custom logging functions for the file/function strings
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1160>
2022-12-10 20:18:11 +02:00
Sebastian Dröge 0e7f5a19df gstreamer: Require using a NUL-terminated UTF-8 string or a string literal for the logging ID
Otherwise each log will involve a new allocation just for the ID.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1160>
2022-12-10 20:18:11 +02:00
Sebastian Dröge 2be477b753 gstreamer: Make logging of messages from a string literal allocation-free if using GStreamer 1.20 or newer
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1160>
2022-12-10 20:18:11 +02:00
Sebastian Dröge 3a61276cdd gstreamer: Reduce some allocations for passing the filename/module name to the logging functions
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1160>
2022-12-10 20:18:11 +02:00
Sebastian Dröge 750422d8eb gstreamer: Reduce some code duplication in the logging code
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1160>
2022-12-10 15:48:02 +02:00
Sebastian Dröge 3ab7bc7648 gstreamer: Add bindings for new 1.22 debug log ID API
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1159>
2022-12-09 17:37:01 +02:00
Sebastian Dröge a54c234fc6 gstreamer: Directly use fields for DebugCategory getters
This allows for better optimizations as it doesn't go through an opaque
FFI function.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1159>
2022-12-09 17:37:01 +02:00
Sebastian Dröge 90b8ee2022 Move from imp.instance() to imp.obj()
It's doing the same thing and is shorter.
2022-10-23 23:06:44 +03:00
François Laignel 87ea535bc1 gst/log: accept non-ref obj in macros 2022-10-23 20:44:38 +02:00
Sebastian Dröge f17781e188 Change *Impl trait methods to only take &self and not Self::Type in addition 2022-10-10 15:01:07 +03:00
Sebastian Dröge 25c53c4276 gstreamer: Implement new logging variants that work ObjectSubclass values 2022-10-10 15:01:07 +03:00
François Laignel b8e1c25c85 gst/log: log arg eval fix non regression test 2022-09-21 17:20:43 +00:00
François Laignel f294339240 log: differ formatted args evaluation
When the `format_args!` macro is used, formatted args are evaluated
in order to form the argument collection that ends up being formatted
when requested to do so.

For the log macro, this means that any argument that is an expression
was evaluated even if the log level was below current threshold. This
can be examplified by the following code:

```rust
    gst::debug!(CAT, "{}", {
        println!("fmt arg executed");
        "A debug log"
    });
```

This used to print "fmt arg executed" even when the log threshold for
`CAT` was filtering `debug` out.

Note that this could break existing code that would incorrectly rely
on the side effect.
2022-09-13 19:25:14 +02:00
Sebastian Dröge 319f1c68a5 gstreamer: Simplify and speed up log message string construction
For pre-1.20 simply use `%s` as format string instead of escaping the
`%` inline while writing. This allows a simpler implementation and is
also faster, see https://github.com/gtk-rs/gtk-rs-core/pull/583.
2022-02-26 13:33:00 +02:00
François Laignel 972c4e75ac remove gst_ prefix for log macros
It's quite quite common to use similar macros in the form `log::debug!`
or `glib::clone!`. This MR renames the gst log macros so that we can
`gst::debug!` instead of `gst_debug!` and whithout the need for
`use gst::gst_debug`.
2022-02-21 18:56:06 +01:00
Sebastian Dröge b66a00ed07 gstreamer: Minor cleanup 2022-01-24 14:48:36 +02:00
Sebastian Dröge ab0eb8a1a4 gstreamer: Add bindings for gst_debug_log_get_line() 2022-01-24 14:48:21 +02:00
Sebastian Dröge 279f1a404b gstreamer: Use glib::SList instead of our own version of it for listing all debug categories 2021-11-16 20:18:31 +02:00
Sebastian Dröge e68790d579 gstreamer: Directly format into a NUL-terminated C string for debug log messages
And also replace `%` with `%%` for < 1.20 inline, and for >= 1.20 use
the new `gst_debug_log_literal()` function that doesn't require this and
also reduces string allocations further.
2021-11-16 20:18:31 +02:00
Sebastian Dröge f27a2bddd6 gstreamer: Add bindings for DebugCategory::all() to list all available debug categories 2021-11-09 09:58:22 +00:00
Guillaume Gomez 5ba79976a9 Generate missing doc aliases for newtypes 2021-06-01 15:15:59 +02:00
Marijn Suijten 540062b97c Add missing doc aliases to manual code
Using the same script as [1], called with:

    python3 add_doc_alias.py gstreamer*/**/src

[1]: https://github.com/gtk-rs/gtk-rs-core/pull/83
2021-05-19 22:36:18 +02:00
François Laignel 49583597ed manual code: fix-getters-def doc aliases 2021-05-03 20:46:57 +02:00
Bilal Elmoussaoui 890cd03632 manual renames of to_glib into into_glib 2021-04-27 19:44:41 +02:00