#![doc = include_str!("../README.mkd")]
#![deny(unreachable_pub)]
#![deny(unsafe_op_in_unsafe_fn)]
pub use log::attach_span;
use tracing_core::field::Value;
#[macro_use]
mod macros;
mod callsite;
#[cfg(feature = "tracing-chrome")]
mod chrometracer;
#[cfg(feature = "tracing-subscriber")]
mod fmttracer;
mod log;
mod tracer;
pub const TARGET: &str = "gstreamer";
trait UnsizeValue {
fn unsize_value(&self) -> Option<&dyn Value>;
}
impl<V: Value> UnsizeValue for Option<V> {
fn unsize_value(&self) -> Option<&dyn Value> {
match self {
Some(ref v) => Some(v as &dyn Value),
None => None,
}
}
}
struct PadFlags(u32);
impl std::fmt::Display for PadFlags {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
use gstreamer::ffi as gffi;
f.write_str("{")?;
let mut sep = false;
let flags = [
(gffi::GST_PAD_FLAG_ACCEPT_INTERSECT, "ACCEPT_INTERSECT"),
(gffi::GST_PAD_FLAG_ACCEPT_TEMPLATE, "ACCEPT_TEMPLATE"),
(gffi::GST_PAD_FLAG_BLOCKED, "BLOCKED"),
(gffi::GST_PAD_FLAG_BLOCKING, "BLOCKING"),
(gffi::GST_PAD_FLAG_EOS, "EOS"),
(gffi::GST_PAD_FLAG_FIXED_CAPS, "FIXED_CAPS"),
(gffi::GST_PAD_FLAG_FLUSHING, "FLUSHING"),
(gffi::GST_PAD_FLAG_NEED_PARENT, "NEED_PARENT"),
(gffi::GST_PAD_FLAG_NEED_RECONFIGURE, "NEED_RECONFIGURE"),
(gffi::GST_PAD_FLAG_PENDING_EVENTS, "PENDING_EVENTS"),
(gffi::GST_PAD_FLAG_PROXY_ALLOCATION, "PROXY_ALLOCATION"),
(gffi::GST_PAD_FLAG_PROXY_CAPS, "PROXY_CAPS"),
(gffi::GST_PAD_FLAG_PROXY_SCHEDULING, "PROXY_SCHEDULING"),
];
for (flag, name) in flags {
if self.0 & flag != 0 {
if sep {
f.write_str(", ")?;
}
f.write_str(name)?;
sep = true;
}
}
f.write_str("}")?;
Ok(())
}
}
fn state_desc(state: gstreamer::ffi::GstState) -> &'static str {
use gstreamer::ffi as gffi;
match state {
gffi::GST_STATE_NULL => "null",
gffi::GST_STATE_PAUSED => "paused",
gffi::GST_STATE_PLAYING => "playing",
gffi::GST_STATE_READY => "ready",
gffi::GST_STATE_VOID_PENDING => "void-pending",
_ => "unknown",
}
}
pub fn integrate_events() {
log::debug_add_log_function();
}
pub fn integrate_spans() {
gstreamer::glib::Object::new::<tracer::TracingTracer>();
}
pub fn disintegrate_events() {
log::debug_remove_log_function();
}
pub fn register(p: Option<&gstreamer::Plugin>) -> Result<(), gstreamer::glib::BoolError> {
gstreamer::Tracer::register(
p,
"rusttracing",
<tracer::TracingTracer as gstreamer::glib::types::StaticType>::static_type(),
)?;
#[cfg(feature = "tracing-chrome")]
gstreamer::Tracer::register(
p,
"chrometracing",
<chrometracer::ChromeTracer as gstreamer::glib::types::StaticType>::static_type(),
)?;
#[cfg(feature = "tracing-subscriber")]
gstreamer::Tracer::register(
p,
"fmttracing",
<fmttracer::FmtTracer as gstreamer::glib::types::StaticType>::static_type(),
)?;
Ok(())
}
mod gst_plugin {
fn plugin_init(plugin: &gstreamer::Plugin) -> Result<(), gstreamer::glib::BoolError> {
crate::register(Some(plugin))
}
gstreamer::plugin_define!(
tracing_gstreamer,
env!("CARGO_PKG_DESCRIPTION"),
plugin_init,
env!("CARGO_PKG_VERSION"),
"unknown", "https://github.com/standard-ai/tracing-gstreamer",
"tracing_gstreamer",
"https://github.com/standard-ai/tracing-gstreamer"
);
}
#[cfg(test)]
mod tests;
#[cfg(test)]
fn main() {
tests::run()
}