added support for configuring tracing via API, made connected() private

This commit is contained in:
Jasper Hugo 2021-08-17 11:55:17 +07:00
parent 2fd02c7e68
commit b593ca6697
9 changed files with 40 additions and 32 deletions

3
Cargo.lock generated
View File

@ -485,7 +485,6 @@ dependencies = [
"tokio",
"tokio-stream",
"tracing",
"tracing-subscriber",
]
[[package]]
@ -663,6 +662,7 @@ dependencies = [
"tokio-stream",
"tokio-tungstenite",
"tracing",
"tracing-subscriber",
"uuid",
"xmpp-parsers-gst-meet",
]
@ -676,6 +676,7 @@ dependencies = [
"gstreamer",
"lib-gst-meet",
"tokio",
"tracing",
]
[[package]]

View File

@ -11,18 +11,11 @@ anyhow = { version = "1", default-features = false, features = ["std"] }
futures = { version = "0.3", default-features = false }
glib = { version = "0.14", default-features = false, features = ["log"] }
gstreamer = { version = "0.17", default-features = false, features = ["v1_16"] }
lib-gst-meet = { version = "0.2", path = "../lib-gst-meet", default-features = false }
lib-gst-meet = { version = "0.2", path = "../lib-gst-meet", default-features = false, features = ["tracing-subscriber"] }
structopt = { version = "0.3", default-features = false }
tokio = { version = "1", default-features = false, features = ["macros", "rt-multi-thread", "signal", "sync", "time"] }
tokio-stream = { version = "0.1", default-features = false }
tracing = { version = "0.1", default-features = false, features = ["attributes", "std"] }
tracing-subscriber = { version = "0.2", default-features = false, features = [
"chrono",
"fmt",
"smallvec",
"parking_lot",
"tracing-log",
] }
[target.'cfg(target_os = "macos")'.dependencies]
cocoa = { version = "0.24", default-features = false }

View File

@ -7,7 +7,7 @@ use gstreamer::{
prelude::{ElementExt, GstBinExt},
GhostPad,
};
use lib_gst_meet::{JitsiConferenceConfig, JitsiConnection};
use lib_gst_meet::{init_tracing, JitsiConferenceConfig, JitsiConnection};
use structopt::StructOpt;
use tokio::{signal::ctrl_c, task, time::timeout};
use tracing::{info, warn};
@ -228,12 +228,4 @@ async fn main_inner() -> Result<()> {
task::spawn_blocking(move || main_loop.run()).await?;
Ok(())
}
fn init_tracing(level: tracing::Level) {
tracing_subscriber::fmt()
.with_max_level(level)
.with_span_events(tracing_subscriber::fmt::format::FmtSpan::CLOSE)
.with_target(false)
.init();
}
}

View File

@ -10,8 +10,9 @@ authors = ["Jasper Hugo <jasper@avstack.io>"]
anyhow = { version = "1", default-features = false }
glib = { version = "0.14", default-features = false }
gstreamer = { version = "0.17", default-features = false }
lib-gst-meet = { version = "0.2", path = "../lib-gst-meet", default-features = false }
lib-gst-meet = { version = "0.2", path = "../lib-gst-meet", default-features = false, features = ["tracing-subscriber"] }
tokio = { version = "1", default-features = false, features = ["rt-multi-thread"] }
tracing = { version = "0.1", default-features = false }
[lib]
name = "gstmeet"

View File

@ -33,6 +33,8 @@ typedef enum {VIDEO, AUDIO} MediaType;
struct Context *gstmeet_init(void);
void gstmeet_init_tracing(const char *level);
void gstmeet_deinit(struct Context *context);
JitsiConnection *gstmeet_connection_new(struct Context *context,

View File

@ -7,7 +7,7 @@ use std::{
use anyhow::Result;
use glib::{ffi::GMainContext, translate::{from_glib_full, ToGlibPtr}};
pub use lib_gst_meet::{JitsiConference, JitsiConnection, MediaType};
pub use lib_gst_meet::{init_tracing, JitsiConference, JitsiConnection, MediaType};
use lib_gst_meet::JitsiConferenceConfig;
use tokio::runtime::Runtime;
@ -55,6 +55,15 @@ pub extern "C" fn gstmeet_init() -> *mut Context {
.ok_raw_or_log()
}
#[no_mangle]
pub unsafe extern "C" fn gstmeet_init_tracing(level: *const c_char) {
let level = CStr::from_ptr(level)
.to_string_lossy()
.parse()
.expect("invalid tracing level");
init_tracing(level);
}
#[no_mangle]
pub unsafe extern "C" fn gstmeet_deinit(context: *mut Context) {
Box::from_raw(context);
@ -126,20 +135,11 @@ pub unsafe extern "C" fn gstmeet_connection_join_conference(
.ok_raw_or_log()
}
#[no_mangle]
pub unsafe extern "C" fn gstmeet_conference_connected(context: *mut Context, conference: *mut JitsiConference) -> bool {
(*context)
.runtime
.block_on((*conference).connected())
.map_err(|e| eprintln!("lib-gst-meet: {:?}", e))
.is_ok()
}
#[no_mangle]
pub unsafe extern "C" fn gstmeet_conference_leave(context: *mut Context, conference: *mut JitsiConference) -> bool {
(*context)
.runtime
.block_on(Box::from_raw(conference).connected())
.block_on(Box::from_raw(conference).leave())
.map_err(|e| eprintln!("lib-gst-meet: {:?}", e))
.is_ok()
}

View File

@ -28,5 +28,15 @@ tokio = { version = "1", default-features = false, features = ["rt-multi-thread"
tokio-stream = { version = "0.1", default-features = false, features = ["time"] }
tokio-tungstenite = { version = "0.14", default-features = false, features = ["connect", "rustls-tls"] }
tracing = { version = "0.1", default-features = false, features = ["attributes", "std"] }
tracing-subscriber = { version = "0.2", optional = true, default-features = false, features = [
"chrono",
"fmt",
"smallvec",
"parking_lot",
"tracing-log",
] }
uuid = { version = "0.8", default-features = false, features = ["v4"] }
xmpp-parsers = { package = "xmpp-parsers-gst-meet", version = "0.18", default-features = false }
[features]
default = []

View File

@ -143,7 +143,7 @@ impl JitsiConference {
})
}
pub async fn connected(&self) -> Result<()> {
pub(crate) async fn connected(&self) -> Result<()> {
let rx = {
let mut locked_inner = self.inner.lock().await;
locked_inner

View File

@ -12,3 +12,12 @@ pub use crate::{
connection::JitsiConnection,
source::{MediaType, Source},
};
#[cfg(feature = "tracing-subscriber")]
pub fn init_tracing(level: tracing::Level) {
tracing_subscriber::fmt()
.with_max_level(level)
.with_span_events(tracing_subscriber::fmt::format::FmtSpan::CLOSE)
.with_target(false)
.init();
}