use new colibri crate & vendored xmpp-parsers

This commit is contained in:
Jasper Hugo 2021-10-06 12:06:27 +07:00
parent a6089293a6
commit 2b2ceca515
9 changed files with 57 additions and 128 deletions

52
Cargo.lock generated
View File

@ -184,6 +184,17 @@ dependencies = [
"objc", "objc",
] ]
[[package]]
name = "colibri"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e90829b3ef30aafd6f707b32665623656cae1c3fd5dfdf090f41bb8855f336d5"
dependencies = [
"serde",
"serde_json",
"serde_with",
]
[[package]] [[package]]
name = "core-foundation" name = "core-foundation"
version = "0.9.1" version = "0.9.1"
@ -512,6 +523,7 @@ version = "0.2.2"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"cocoa", "cocoa",
"colibri",
"futures", "futures",
"glib", "glib",
"gstreamer", "gstreamer",
@ -694,6 +706,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "19e0935b518d535e6de070bdcfc9ab8970cefc57b94ef13b26baf6967cf65a73" checksum = "19e0935b518d535e6de070bdcfc9ab8970cefc57b94ef13b26baf6967cf65a73"
dependencies = [ dependencies = [
"minidom-gst-meet", "minidom-gst-meet",
"serde",
] ]
[[package]] [[package]]
@ -719,12 +732,13 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]] [[package]]
name = "lib-gst-meet" name = "lib-gst-meet"
version = "0.3.1" version = "0.4.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-stream", "async-stream",
"async-trait", "async-trait",
"bytes", "bytes",
"colibri",
"futures", "futures",
"glib", "glib",
"gstreamer", "gstreamer",
@ -885,9 +899,9 @@ dependencies = [
[[package]] [[package]]
name = "nix" name = "nix"
version = "0.22.1" version = "0.22.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7555d6c7164cc913be1ce7f95cbecdabda61eb2ccd89008524af306fb7f5031" checksum = "d3bb9a13fa32bc5aeb64150cd3f32d6cf4c748f8f8a417cce5d2eb976a8370ba"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"cc", "cc",
@ -1118,9 +1132,9 @@ dependencies = [
[[package]] [[package]]
name = "quote" name = "quote"
version = "1.0.9" version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
] ]
@ -1389,9 +1403,9 @@ checksum = "c307a32c1c5c437f38c7fd45d753050587732ba8628319fbdf12a7e289ccc590"
[[package]] [[package]]
name = "smallvec" name = "smallvec"
version = "1.6.1" version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e" checksum = "1ecab6c735a6bb4139c0caafd0cc3635748bbb3acf4550e8138122099251f309"
[[package]] [[package]]
name = "spin" name = "spin"
@ -1455,9 +1469,9 @@ checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601"
[[package]] [[package]]
name = "syn" name = "syn"
version = "1.0.77" version = "1.0.80"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5239bc68e0fef57495900cfea4e8dc75596d9a319d7e16b1e0a440d24e6fe0a0" checksum = "d010a1623fbd906d51d650a9916aaefc05ffa0e4053ff7fe601167f3e715d194"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -1570,9 +1584,9 @@ dependencies = [
[[package]] [[package]]
name = "tokio-macros" name = "tokio-macros"
version = "1.3.0" version = "1.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "54473be61f4ebe4efd09cec9bd5d16fa51d70ea0192213d754d2d500457db110" checksum = "154794c8f499c2619acd19e839294703e9e32e7630ef5f46ea80d4ef0fbee5eb"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -1629,9 +1643,9 @@ dependencies = [
[[package]] [[package]]
name = "tracing" name = "tracing"
version = "0.1.28" version = "0.1.29"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "84f96e095c0c82419687c20ddf5cb3eadb61f4e1405923c9dc8e53a1adacbda8" checksum = "375a639232caf30edfc78e8d89b2d4c375515393e7af7e16f01cd96917fb2105"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"pin-project-lite", "pin-project-lite",
@ -1641,9 +1655,9 @@ dependencies = [
[[package]] [[package]]
name = "tracing-attributes" name = "tracing-attributes"
version = "0.1.16" version = "0.1.18"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "98863d0dd09fa59a1b79c6750ad80dbda6b75f4e71c437a6a1a8cb91a8bcbd77" checksum = "f4f480b8f81512e825f337ad51e94c1eb5d3bbdf2b363dcd01e2b19a9ffe3f8e"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -1652,9 +1666,9 @@ dependencies = [
[[package]] [[package]]
name = "tracing-core" name = "tracing-core"
version = "0.1.20" version = "0.1.21"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "46125608c26121c81b0c6d693eab5a420e416da7e43c426d2e8f7df8da8a3acf" checksum = "1f4ed65637b8390770814083d20756f87bfa2c21bf2f110babdc5438351746e4"
dependencies = [ dependencies = [
"lazy_static", "lazy_static",
] ]
@ -1672,9 +1686,9 @@ dependencies = [
[[package]] [[package]]
name = "tracing-subscriber" name = "tracing-subscriber"
version = "0.2.24" version = "0.2.25"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fdd0568dbfe3baf7048b7908d2b32bca0d81cd56bec6d2a8f894b01d74f86be3" checksum = "0e0d2eaa99c3c2e41547cfa109e910a68ea03823cccad4a0525dcbc9b01e8c71"
dependencies = [ dependencies = [
"chrono", "chrono",
"parking_lot", "parking_lot",

View File

@ -8,10 +8,11 @@ authors = ["Jasper Hugo <jasper@avstack.io>"]
[dependencies] [dependencies]
anyhow = { version = "1", default-features = false, features = ["std"] } anyhow = { version = "1", default-features = false, features = ["std"] }
colibri = { version = "0.1", default-features = false }
futures = { version = "0.3", default-features = false } futures = { version = "0.3", default-features = false }
glib = { version = "0.14", default-features = false, features = ["log"] } glib = { version = "0.14", default-features = false, features = ["log"] }
gstreamer = { version = "0.17", default-features = false, features = ["v1_16"] } gstreamer = { version = "0.17", default-features = false, features = ["v1_16"] }
lib-gst-meet = { version = "0.3", path = "../lib-gst-meet", default-features = false, features = ["tracing-subscriber"] } lib-gst-meet = { version = "0.4", path = "../lib-gst-meet", default-features = false, features = ["tracing-subscriber"] }
structopt = { version = "0.3", default-features = false } structopt = { version = "0.3", default-features = false }
tokio = { version = "1", default-features = false, features = ["macros", "rt-multi-thread", "signal", "sync", "time"] } tokio = { version = "1", default-features = false, features = ["macros", "rt-multi-thread", "signal", "sync", "time"] }
tokio-stream = { version = "0.1", default-features = false } tokio-stream = { version = "0.1", default-features = false }

View File

@ -3,13 +3,13 @@ use std::time::Duration;
use anyhow::{bail, Context, Result}; use anyhow::{bail, Context, Result};
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
use cocoa::appkit::NSApplication; use cocoa::appkit::NSApplication;
use colibri::{ColibriMessage, Constraints, VideoType};
use glib::ObjectExt; use glib::ObjectExt;
use gstreamer::{ use gstreamer::{
prelude::{ElementExt, GstBinExt}, prelude::{ElementExt, GstBinExt},
GhostPad, GhostPad,
}; };
use lib_gst_meet::{ use lib_gst_meet::{
colibri::{ColibriMessage, Constraints, VideoType},
Authentication, init_tracing, JitsiConference, JitsiConferenceConfig, Connection, Authentication, init_tracing, JitsiConference, JitsiConferenceConfig, Connection,
}; };
use structopt::StructOpt; use structopt::StructOpt;

View File

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

View File

@ -14,7 +14,7 @@ use glib::{
translate::{from_glib, from_glib_full, ToGlibPtr}, translate::{from_glib, from_glib_full, ToGlibPtr},
}; };
use lib_gst_meet::JitsiConferenceConfig; use lib_gst_meet::JitsiConferenceConfig;
pub use lib_gst_meet::{init_tracing, JitsiConference, JitsiConnection, MediaType}; pub use lib_gst_meet::{init_tracing, Authentication, Connection, JitsiConference, MediaType};
use tokio::runtime::Runtime; use tokio::runtime::Runtime;
pub struct Context { pub struct Context {
@ -80,14 +80,15 @@ pub unsafe extern "C" fn gstmeet_connection_new(
context: *mut Context, context: *mut Context,
websocket_url: *const c_char, websocket_url: *const c_char,
xmpp_domain: *const c_char, xmpp_domain: *const c_char,
) -> *mut JitsiConnection { ) -> *mut Connection {
let websocket_url = CStr::from_ptr(websocket_url); let websocket_url = CStr::from_ptr(websocket_url);
let xmpp_domain = CStr::from_ptr(xmpp_domain); let xmpp_domain = CStr::from_ptr(xmpp_domain);
(*context) (*context)
.runtime .runtime
.block_on(JitsiConnection::new( .block_on(Connection::new(
&websocket_url.to_string_lossy(), &websocket_url.to_string_lossy(),
&xmpp_domain.to_string_lossy(), &xmpp_domain.to_string_lossy(),
Authentication::Anonymous,
)) ))
.map(|(connection, background)| { .map(|(connection, background)| {
(*context).runtime.spawn(background); (*context).runtime.spawn(background);
@ -97,14 +98,14 @@ pub unsafe extern "C" fn gstmeet_connection_new(
} }
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn gstmeet_connection_free(connection: *mut JitsiConnection) { pub unsafe extern "C" fn gstmeet_connection_free(connection: *mut Connection) {
Box::from_raw(connection); Box::from_raw(connection);
} }
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn gstmeet_connection_connect( pub unsafe extern "C" fn gstmeet_connection_connect(
context: *mut Context, context: *mut Context,
connection: *mut JitsiConnection, connection: *mut Connection,
) -> bool { ) -> bool {
(*context) (*context)
.runtime .runtime
@ -116,7 +117,7 @@ pub unsafe extern "C" fn gstmeet_connection_connect(
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn gstmeet_connection_join_conference( pub unsafe extern "C" fn gstmeet_connection_join_conference(
context: *mut Context, context: *mut Context,
connection: *mut JitsiConnection, connection: *mut Connection,
glib_main_context: *mut GMainContext, glib_main_context: *mut GMainContext,
config: *const ConferenceConfig, config: *const ConferenceConfig,
) -> *mut JitsiConference { ) -> *mut JitsiConference {
@ -144,10 +145,11 @@ pub unsafe extern "C" fn gstmeet_connection_join_conference(
video_codec: CStr::from_ptr((*config).video_codec) video_codec: CStr::from_ptr((*config).video_codec)
.to_string_lossy() .to_string_lossy()
.to_string(), .to_string(),
extra_muc_features: vec![],
}; };
(*context) (*context)
.runtime .runtime
.block_on((*connection).join_conference(from_glib_full(glib_main_context), config)) .block_on(JitsiConference::join((*connection).clone(), from_glib_full(glib_main_context), config))
.ok_raw_or_log() .ok_raw_or_log()
} }
@ -233,7 +235,11 @@ pub unsafe extern "C" fn gstmeet_conference_on_participant(
let ctx = ctx.clone(); let ctx = ctx.clone();
Box::pin(async move { Box::pin(async move {
let participant = Participant { let participant = Participant {
jid: CString::new(participant.jid.to_string())?.into_raw() as *const _, jid: participant
.jid
.map(|jid| Ok::<_, anyhow::Error>(CString::new(jid.to_string())?.into_raw() as *const _))
.transpose()?
.unwrap_or_else(ptr::null),
muc_jid: CString::new(participant.muc_jid.to_string())?.into_raw() as *const _, muc_jid: CString::new(participant.muc_jid.to_string())?.into_raw() as *const _,
nick: participant nick: participant
.nick .nick

View File

@ -1,7 +1,7 @@
[package] [package]
name = "lib-gst-meet" name = "lib-gst-meet"
description = "Connect GStreamer pipelines to Jitsi Meet conferences" description = "Connect GStreamer pipelines to Jitsi Meet conferences"
version = "0.3.1" version = "0.4.0"
edition = "2018" edition = "2018"
license = "MIT/Apache-2.0" license = "MIT/Apache-2.0"
authors = ["Jasper Hugo <jasper@avstack.io>"] authors = ["Jasper Hugo <jasper@avstack.io>"]
@ -11,6 +11,7 @@ anyhow = { version = "1", default-features = false, features = ["std"] }
async-stream = { version = "0.3", default-features = false } async-stream = { version = "0.3", default-features = false }
async-trait = { version = "0.1", default-features = false } async-trait = { version = "0.1", default-features = false }
bytes = { version = "1", default-features = false, features = ["std"] } bytes = { version = "1", default-features = false, features = ["std"] }
colibri = { version = "0.1", default-features = false }
futures = { version = "0.3", default-features = false } futures = { version = "0.3", default-features = false }
glib = { version = "0.14", default-features = false } glib = { version = "0.14", default-features = false }
gstreamer = { version = "0.17", default-features = false, features = ["v1_20"] } gstreamer = { version = "0.17", default-features = false, features = ["v1_20"] }
@ -40,7 +41,7 @@ tracing-subscriber = { version = "0.2", optional = true, default-features = fals
"tracing-log", "tracing-log",
] } ] }
uuid = { version = "0.8", default-features = false, features = ["v4"] } uuid = { version = "0.8", default-features = false, features = ["v4"] }
xmpp-parsers = { path = "../../xmpp-rs/xmpp-parsers", package = "xmpp-parsers-gst-meet", version = "0.18", default-features = false } xmpp-parsers = { path = "../xmpp-parsers", package = "xmpp-parsers-gst-meet", version = "0.18", default-features = false }
[features] [features]
default = [] default = []

View File

@ -1,6 +1,7 @@
use std::{collections::HashMap, sync::Arc}; use std::{collections::HashMap, sync::Arc};
use anyhow::Result; use anyhow::Result;
use colibri::ColibriMessage;
use futures::{ use futures::{
sink::SinkExt, sink::SinkExt,
stream::{StreamExt, TryStreamExt}, stream::{StreamExt, TryStreamExt},
@ -12,100 +13,6 @@ use tokio_stream::wrappers::ReceiverStream;
use tokio_tungstenite::tungstenite::{http::Request, Message}; use tokio_tungstenite::tungstenite::{http::Request, Message};
use tracing::{debug, error, info, warn}; use tracing::{debug, error, info, warn};
#[serde_as]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(tag = "colibriClass")]
pub enum ColibriMessage {
#[serde(rename_all = "camelCase")]
DominantSpeakerEndpointChangeEvent {
dominant_speaker_endpoint: String,
previous_speakers: Vec<String>,
},
#[serde(rename_all = "camelCase")]
EndpointConnectivityStatusChangeEvent {
endpoint: String,
#[serde_as(as = "DisplayFromStr")]
active: bool,
},
#[serde(rename_all = "camelCase")]
EndpointMessage {
from: String,
to: Option<String>,
msg_payload: serde_json::Value,
},
#[serde(rename_all = "camelCase")]
EndpointStats {
from: String,
bitrate: Bitrates,
packet_loss: PacketLoss,
connection_quality: f32,
#[serde(rename = "jvbRTT")]
jvb_rtt: Option<u16>,
server_region: String,
max_enabled_resolution: u16,
},
#[serde(rename_all = "camelCase")]
LastNChangedEvent { last_n: u16 },
#[serde(rename_all = "camelCase")]
LastNEndpointsChangeEvent { last_n_endpoints: Vec<String> },
#[serde(rename_all = "camelCase")]
ReceiverVideoConstraint { max_frame_height: u16 },
#[serde(rename_all = "camelCase")]
ReceiverVideoConstraints {
last_n: Option<u16>,
selected_endpoints: Option<Vec<String>>,
on_stage_endpoints: Option<Vec<String>>,
default_constraints: Option<Constraints>,
constraints: Option<HashMap<String, Constraints>>,
},
#[serde(rename_all = "camelCase")]
SelectedEndpointsChangedEvent { selected_endpoints: Vec<String> },
#[serde(rename_all = "camelCase")]
SenderVideoConstraints { video_constraints: Constraints },
#[serde(rename_all = "camelCase")]
ServerHello { version: Option<String> },
#[serde(rename_all = "camelCase")]
VideoTypeMessage { video_type: VideoType },
}
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub enum VideoType {
Camera,
Desktop,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Constraints {
pub ideal_height: Option<u16>,
pub max_height: Option<u16>,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Bitrates {
pub audio: Bitrate,
pub video: Bitrate,
#[serde(flatten)]
pub total: Bitrate,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Bitrate {
pub upload: u32,
pub download: u32,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct PacketLoss {
pub total: u32,
pub download: u32,
pub upload: u32,
}
pub(crate) struct ColibriChannel { pub(crate) struct ColibriChannel {
send_tx: mpsc::Sender<ColibriMessage>, send_tx: mpsc::Sender<ColibriMessage>,
recv_tx: Arc<Mutex<Vec<mpsc::Sender<ColibriMessage>>>>, recv_tx: Arc<Mutex<Vec<mpsc::Sender<ColibriMessage>>>>,

View File

@ -2,6 +2,7 @@ use std::{collections::HashMap, convert::TryFrom, fmt, future::Future, pin::Pin,
use anyhow::{anyhow, bail, Context, Result}; use anyhow::{anyhow, bail, Context, Result};
use async_trait::async_trait; use async_trait::async_trait;
use colibri::ColibriMessage;
use futures::stream::StreamExt; use futures::stream::StreamExt;
use gstreamer::prelude::{ElementExt, ElementExtManual, GstBinExt}; use gstreamer::prelude::{ElementExt, ElementExtManual, GstBinExt};
use maplit::hashmap; use maplit::hashmap;
@ -27,7 +28,7 @@ use xmpp_parsers::{
}; };
use crate::{ use crate::{
colibri::{ColibriChannel, ColibriMessage}, colibri::ColibriChannel,
jingle::JingleSession, jingle::JingleSession,
source::MediaType, source::MediaType,
stanza_filter::StanzaFilter, stanza_filter::StanzaFilter,

View File

@ -8,7 +8,6 @@ mod util;
mod xmpp; mod xmpp;
pub use crate::{ pub use crate::{
colibri::ColibriMessage,
conference::{Feature, JitsiConference, JitsiConferenceConfig, Participant}, conference::{Feature, JitsiConference, JitsiConferenceConfig, Participant},
source::MediaType, source::MediaType,
stanza_filter::StanzaFilter, stanza_filter::StanzaFilter,