Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions moq-relay-ietf/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "moq-relay-ietf"
description = "Media over QUIC"
authors = ["Luke Curley", "Manish Kumar Pandit"]
authors = ["Luke Curley", "Manish Kumar Pandit", "Mike English"]
repository = "https://github.com/cloudflare/moq-rs"
license = "MIT OR Apache-2.0"

Expand Down Expand Up @@ -30,7 +30,7 @@ url = "2"

# Async stuff
tokio = { version = "1", features = ["full"] }
# tokio-util = "0.7"
tokio-util = "0.7"
futures = "0.3"
async-trait = "0.1"

Expand Down
27 changes: 11 additions & 16 deletions moq-relay-ietf/src/producer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ use moq_transport::{
session::{Publisher, SessionError, Subscribed, TrackStatusRequested},
};

use crate::{Locals, RemotesConsumer};
use crate::{Locals, RemoteManager};

/// Producer of tracks to a remote Subscriber
#[derive(Clone)]
pub struct Producer {
publisher: Publisher,
locals: Locals,
remotes: Option<RemotesConsumer>,
remotes: RemoteManager,
}

impl Producer {
pub fn new(publisher: Publisher, locals: Locals, remotes: Option<RemotesConsumer>) -> Self {
pub fn new(publisher: Publisher, locals: Locals, remotes: RemoteManager) -> Self {
Self {
publisher,
locals,
Expand Down Expand Up @@ -89,21 +89,16 @@ impl Producer {
}
}

if let Some(remotes) = self.remotes {
// Check remote tracks second, and serve from remote if possible
match remotes.route(&namespace).await {
Ok(remote) => {
if let Some(remote) = remote {
if let Some(track) = remote.subscribe(&namespace, &track_name)? {
log::info!("serving subscribe from remote: {:?}", track.info);
return Ok(subscribed.serve(track.reader).await?);
}
}
}
Err(e) => {
log::error!("failed to route to remote: {}", e);
match self.remotes.subscribe(&namespace, &track_name).await {
Ok(track) => {
if let Some(track) = track {
log::info!("serving subscribe from remote: {:?}", track.info);
return Ok(subscribed.serve(track).await?);
}
}
Err(e) => {
log::error!("failed to route to remote: {}", e);
}
}
// Track not found - close the subscription with not found error
let err = ServeError::not_found_ctx(format!(
Expand Down
19 changes: 5 additions & 14 deletions moq-relay-ietf/src/relay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ use futures::{stream::FuturesUnordered, FutureExt, StreamExt};
use moq_native_ietf::quic::{self, Endpoint};
use url::Url;

use crate::{
Consumer, Coordinator, Locals, Producer, Remotes, RemotesConsumer, RemotesProducer, Session,
};
use crate::{Consumer, Coordinator, Locals, Producer, RemoteManager, Session};

// A type alias for boxed future
type ServerFuture = Pin<
Expand Down Expand Up @@ -56,7 +54,7 @@ pub struct Relay {
announce_url: Option<Url>,
mlog_dir: Option<PathBuf>,
locals: Locals,
remotes: Option<(RemotesProducer, RemotesConsumer)>,
remotes: RemoteManager,
coordinator: Arc<dyn Coordinator>,
}

Expand Down Expand Up @@ -101,18 +99,14 @@ impl Relay {
.collect::<Vec<_>>();

// Create remote manager - uses coordinator for namespace lookups
let remotes = Remotes {
coordinator: config.coordinator.clone(),
quic: remote_clients[0].clone(),
}
.produce();
let remotes = RemoteManager::new(config.coordinator.clone(), remote_clients);

Ok(Self {
quic_endpoints: endpoints,
announce_url: config.announce,
mlog_dir: config.mlog_dir,
locals,
remotes: Some(remotes),
remotes,
coordinator: config.coordinator,
})
}
Expand All @@ -122,10 +116,7 @@ impl Relay {
let mut tasks = FuturesUnordered::new();

// Split remotes producer/consumer and spawn producer task
let remotes = self.remotes.map(|(producer, consumer)| {
tasks.push(producer.run().boxed());
consumer
});
let remotes = self.remotes;

// Start the forwarder, if any
let forward_producer = if let Some(url) = &self.announce_url {
Expand Down
Loading