Add async

This commit is contained in:
Wanjohi
2023-12-15 16:40:41 +03:00
parent fe5f352d9d
commit d890aa0011
2 changed files with 49 additions and 3 deletions

View File

@@ -1,6 +1,9 @@
use gst::glib;
use gst::glib::once_cell::sync::Lazy;
use tokio::runtime;
mod moqsink;
mod relayurl;
use gst::glib;
fn plugin_init(plugin: &gst::Plugin) -> Result<(), glib::BoolError> {
moqsink::register(plugin)?;
@@ -17,4 +20,13 @@ gst::plugin_define!(
env!("CARGO_PKG_NAME"),
env!("CARGO_PKG_REPOSITORY"),
env!("BUILD_REL_DATE")
);
);
//TODO: https://github.com/sdroege/gst-plugin-rs/blob/1faef49b51746a82c5b99a09a1034220cf92af9d/net/webrtc/src/lib.rs#L44C1-L50C4
pub static RUNTIME: Lazy<runtime::Runtime> = Lazy::new(|| {
runtime::Builder::new_multi_thread()
.enable_all()
.worker_threads(1)
.build()
.unwrap()
});

View File

@@ -8,6 +8,8 @@ use std::sync::Mutex;
use crate::relayurl::*;
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use tokio::runtime::Runtime;
use tokio::sync::mpsc;
use moq_transport::cache::{broadcast, fragment, segment, track};
use url::Url;
@@ -117,6 +119,38 @@ impl MoqSink {
}
};
// // Initialize shared state and channels
// let (sender, receiver) = mpsc::channel(32);
// // self.sender = Some(sender);
// // Spawn a new thread to run the Tokio runtime
// std::thread::spawn(move || {
// // Create a new Tokio runtime
// let rt = Runtime::new().unwrap();
// // Block on the async code within the Tokio runtime
// rt.block_on(async move {
// // Set up your async tasks here
// let session_task = session.run();
// let media_task = media.run();
// tokio::select! {
// res = session_task => {
// // Handle session result
// // You might want to send a message to the GStreamer element using the channel
// },
// res = media_task => {
// // Handle media result
// // You might want to send a message to the GStreamer element using the channel
// },
// msg = receiver.recv() => {
// // Handle messages sent from the GStreamer element to the Tokio runtime
// // These might be control commands or data to process
// }
// }
// });
// });
Ok(())
}
@@ -305,4 +339,4 @@ impl BaseSinkImpl for MoqSink {
fn start(&self) -> Result<(), gst::ErrorMessage> {
self.start()
}
}
}