-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dgw): support asciicast streaming (#1165)
Co-authored-by: Benoît Cortier <[email protected]>
- Loading branch information
1 parent
0ed70d2
commit 8a52585
Showing
33 changed files
with
555 additions
and
130 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
name = "ascii-streamer" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
anyhow = "1.0" | ||
serde_json = "1.0" | ||
tokio = { version = "1.42", features = ["io-util", "sync"] } | ||
tracing = "0.1" | ||
|
||
[lints] | ||
workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#[macro_use] | ||
extern crate tracing; | ||
|
||
use std::{future::Future, sync::Arc}; | ||
|
||
use tokio::{ | ||
io::{AsyncBufReadExt, BufReader}, | ||
sync::Notify, | ||
}; | ||
|
||
pub trait AsciiStreamSocket { | ||
fn send(&mut self, value: String) -> impl Future<Output = anyhow::Result<()>> + Send; | ||
fn close(&mut self) -> impl Future<Output = ()> + Send; | ||
} | ||
|
||
#[tracing::instrument(skip_all)] | ||
pub async fn ascii_stream( | ||
mut websocket: impl AsciiStreamSocket, | ||
input_stream: impl tokio::io::AsyncRead + Unpin, | ||
shutdown_signal: Arc<Notify>, | ||
when_new_chunk_appended: impl Fn() -> tokio::sync::oneshot::Receiver<()>, | ||
) -> anyhow::Result<()> { | ||
info!("Starting ASCII streaming"); | ||
// Write all the data from the input stream to the output stream. | ||
let buf_reader = BufReader::new(input_stream); | ||
let mut lines = BufReader::new(buf_reader).lines(); | ||
|
||
loop { | ||
match lines.next_line().await { | ||
Ok(Some(line)) => { | ||
websocket.send(line.clone()).await?; | ||
} | ||
Ok(None) => { | ||
break; | ||
} | ||
Err(e) => { | ||
warn!(error=%e, "Error reading line"); | ||
continue; | ||
} | ||
} | ||
} | ||
|
||
loop { | ||
tokio::select! { | ||
_ = when_new_chunk_appended() => { | ||
loop { | ||
match lines.next_line().await { | ||
Ok(Some(line)) => { | ||
websocket.send(line.clone()).await?; | ||
} | ||
Ok(None) => { | ||
debug!("EOF reached"); | ||
break; | ||
} | ||
Err(e) => { | ||
warn!(error=%e, "Error reading line"); | ||
continue; | ||
} | ||
} | ||
} | ||
} | ||
_ = shutdown_signal.notified() => { | ||
break; | ||
} | ||
} | ||
} | ||
|
||
// Note: though sometimes we end the loop with error | ||
// but we still needs to send 1000 code to the client | ||
// as it is what is expected for the ascii-player to end the playback properly | ||
websocket.close().await; | ||
debug!("Shutting down ASCII streaming"); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[package] | ||
name = "streamer" | ||
name = "video-streamer" | ||
version = "0.0.0" | ||
authors = ["Devolutions Inc. <[email protected]>"] | ||
edition = "2021" | ||
|
@@ -20,7 +20,7 @@ tracing = "0.1" | |
webm-iterable = { version = "0.6", features = ["futures"] } | ||
cadeau = { version = "0.5", features = ["dlopen"] } | ||
thiserror = "2" | ||
num_cpus = "1.16.0" | ||
num_cpus = "1.16" | ||
|
||
[dev-dependencies] | ||
tracing-subscriber = "0.3" | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.