From d2cf18ff453bb32d99ee9110539546c561eb2720 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Fri, 11 Sep 2020 14:59:37 +0300 Subject: [PATCH] Add command-line parsing, logging/GStreamer setup and runtime setup --- Cargo.lock | 181 +++++++++++--------------------------- Cargo.toml | 30 ++----- LICENSE | 23 +++++ common/Cargo.toml | 6 ++ common/LICENSE | 23 +++++ common/src/lib.rs | 3 + publisher/Cargo.toml | 21 +++++ publisher/LICENSE | 23 +++++ publisher/src/config.rs | 69 +++++++++++++++ publisher/src/main.rs | 31 +++++++ server/Cargo.toml | 25 ++++++ server/LICENSE | 23 +++++ server/cert.pem | 29 ++++++ server/key.pem | 52 +++++++++++ server/src/config.rs | 28 ++++++ server/src/main.rs | 60 +++++++++++++ src/bin/publisher/main.rs | 3 - src/bin/server/main.rs | 3 - src/main.rs | 3 - 19 files changed, 474 insertions(+), 162 deletions(-) create mode 100644 LICENSE create mode 100644 common/Cargo.toml create mode 100644 common/LICENSE create mode 100644 common/src/lib.rs create mode 100644 publisher/Cargo.toml create mode 100644 publisher/LICENSE create mode 100644 publisher/src/config.rs create mode 100644 publisher/src/main.rs create mode 100644 server/Cargo.toml create mode 100644 server/LICENSE create mode 100644 server/cert.pem create mode 100644 server/key.pem create mode 100644 server/src/config.rs create mode 100644 server/src/main.rs delete mode 100644 src/bin/publisher/main.rs delete mode 100644 src/bin/server/main.rs delete mode 100644 src/main.rs diff --git a/Cargo.lock b/Cargo.lock index 825e9f7..0dd7cb3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -71,6 +71,8 @@ dependencies = [ "futures", "http", "log", + "openssl", + "tokio-openssl", "trust-dns-proto", "trust-dns-resolver", ] @@ -86,6 +88,7 @@ dependencies = [ "actix-rt", "actix-service", "actix-threadpool", + "actix-tls 1.0.0", "actix-utils 1.0.6", "base64 0.11.0", "bitflags", @@ -233,6 +236,8 @@ dependencies = [ "either", "futures", "log", + "openssl", + "tokio-openssl", ] [[package]] @@ -245,8 +250,8 @@ dependencies = [ "actix-service", "actix-utils 2.0.0", "futures-util", - "native-tls", - "tokio-tls", + "openssl", + "tokio-openssl", ] [[package]] @@ -314,6 +319,7 @@ dependencies = [ "log", "mime", "net2", + "openssl", "pin-project", "regex", "serde", @@ -425,10 +431,10 @@ dependencies = [ "futures-io", "futures-util", "log", - "native-tls", + "openssl", "pin-project", "tokio", - "tokio-native-tls", + "tokio-openssl", "tungstenite", ] @@ -465,6 +471,7 @@ dependencies = [ "futures-core", "log", "mime", + "openssl", "percent-encoding", "rand", "serde", @@ -616,22 +623,6 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2df960f5d869b2dd8532793fde43eb5427cceb126c929747a26823ab0eeb536" -[[package]] -name = "core-foundation" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57d24c7a13c43e870e37c1556b74555437870a04514f7685f5b354e090567171" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3a71ab494c0b5b860bdc8407ae08978052417070c2ced38573a9157ad75b8ac" - [[package]] name = "cpuid-bool" version = "0.1.2" @@ -921,9 +912,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.1.14" +version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb" +checksum = "fc587bc0ec293155d5bfa6b9891ec18a1e330c234f896ea47fbada4cadbe47e6" dependencies = [ "cfg-if", "libc", @@ -938,9 +929,9 @@ checksum = "aaf91faf136cb47367fa430cd46e37a788775e7fa104f8b4bcb3861dc389b724" [[package]] name = "glib" -version = "0.10.1" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5e0533f48640d86e8e2f3cee778a9f97588d4a0bec8be065ee51ea52346d6c1" +checksum = "5f11a45bde4cf9567653a14ff96cdbb01e6d2a89651746dbc118319dfdac433e" dependencies = [ "bitflags", "futures-channel", @@ -1261,9 +1252,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.76" +version = "0.2.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "755456fae044e6fa1ebbbd1b3e902ae19e73097ed4ed87bb79934a867c007bc3" +checksum = "f2f96b10ec2560088a8e76961b00d47107b3a625fecb76dedb29ee7ccbf98235" [[package]] name = "linked-hash-map" @@ -1394,24 +1385,6 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0419348c027fa7be448d2ae7ea0e4e04c2334c31dc4e74ab29f00a2a7ca69204" -[[package]] -name = "native-tls" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b0d88c06fe90d5ee94048ba40409ef1d9315d86f6f38c2efdaad4fb50c58b2d" -dependencies = [ - "lazy_static", - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "net2" version = "0.2.35" @@ -1495,12 +1468,6 @@ dependencies = [ "openssl-sys", ] -[[package]] -name = "openssl-probe" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" - [[package]] name = "openssl-sys" version = "0.9.58" @@ -1622,9 +1589,9 @@ checksum = "c36fa947111f5c62a733b652544dd0016a43ce89619538a8ef92724a6f501a20" [[package]] name = "pretty-hex" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8a6a27f79f3ec19193cd2ecfe9b73276b79026529466aef45d70d0f9eca651b" +checksum = "bc5c99d529f0d30937f6f4b8a86d988047327bb88d04d2c4afc356de74722131" [[package]] name = "proc-macro-crate" @@ -1673,9 +1640,9 @@ checksum = "eba180dafb9038b050a4c280019bbedf9f2467b61e5d892dcad585bb57aadc5a" [[package]] name = "proc-macro2" -version = "1.0.20" +version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "175c513d55719db99da20232b06cda8bab6b83ec2d04e3283edf0213c37c1a29" +checksum = "36e28516df94f3dd551a587da5357459d9b36d945a7c37c3557928c1c2ff2a2c" dependencies = [ "unicode-xid", ] @@ -1760,15 +1727,6 @@ version = "0.6.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26412eb97c6b088a6997e05f69403a802a92d520de2f8e63c2b65f9e0f47c4e8" -[[package]] -name = "remove_dir_all" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" -dependencies = [ - "winapi 0.3.9", -] - [[package]] name = "resolv-conf" version = "0.6.3" @@ -1791,45 +1749,12 @@ version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" -[[package]] -name = "schannel" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75" -dependencies = [ - "lazy_static", - "winapi 0.3.9", -] - [[package]] name = "scopeguard" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" -[[package]] -name = "security-framework" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64808902d7d99f78eaddd2b4e2509713babc3dc3c85ad6f4c447680f3c01e535" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17bf11d99252f512695eb468de5516e5cf75455521e69dfe343f3b74e4748405" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "serde" version = "1.0.115" @@ -1916,9 +1841,9 @@ checksum = "fbee7696b84bbf3d89a1c2eccff0850e3047ed46bfcd2e92c29a2d074d57e252" [[package]] name = "socket2" -version = "0.3.12" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03088793f677dce356f3ccc2edb1b314ad191ab702a5de3faf49304f7e104918" +checksum = "b1fa70dc5c8104ec096f4fe7ede7a221d35ae13dcd19ba1ad9a81d2cab9a1c44" dependencies = [ "cfg-if", "libc", @@ -2012,20 +1937,6 @@ dependencies = [ "version-compare", ] -[[package]] -name = "tempfile" -version = "3.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" -dependencies = [ - "cfg-if", - "libc", - "rand", - "redox_syscall", - "remove_dir_all", - "winapi 0.3.9", -] - [[package]] name = "termcolor" version = "1.1.0" @@ -2121,22 +2032,12 @@ dependencies = [ ] [[package]] -name = "tokio-native-tls" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd608593a919a8e05a7d1fc6df885e40f6a88d3a70a3a7eff23ff27964eda069" -dependencies = [ - "native-tls", - "tokio", -] - -[[package]] -name = "tokio-tls" -version = "0.3.1" +name = "tokio-openssl" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a70f4fcd7b3b24fb194f837560168208f669ca8cb70d0c4b862944452396343" +checksum = "3c4b08c5f4208e699ede3df2520aca2e82401b2de33f45e96696a074480be594" dependencies = [ - "native-tls", + "openssl", "tokio", ] @@ -2249,7 +2150,6 @@ dependencies = [ "httparse", "input_buffer", "log", - "native-tls", "rand", "sha-1", "url", @@ -2351,9 +2251,32 @@ version = "0.10.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" +[[package]] +name = "webrtc-audio-publisher" +version = "0.1.0" +dependencies = [ + "anyhow", + "async-tungstenite", + "env_logger", + "futures", + "glib", + "gstreamer", + "gstreamer-webrtc", + "log", + "serde", + "serde_json", + "structopt", + "tokio", + "webrtc-audio-publishing", +] + [[package]] name = "webrtc-audio-publishing" version = "0.1.0" + +[[package]] +name = "webrtc-audio-server" +version = "0.1.0" dependencies = [ "actix-rt", "actix-service", @@ -2361,17 +2284,17 @@ dependencies = [ "actix-web", "actix-web-actors", "anyhow", - "async-tungstenite", "env_logger", "futures", "glib", "gstreamer", "gstreamer-webrtc", "log", + "openssl", "serde", "serde_json", "structopt", - "tokio", + "webrtc-audio-publishing", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 9bdf5e7..a511fbc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,25 +1,7 @@ -[package] -name = "webrtc-audio-publishing" -version = "0.1.0" -authors = ["Sebastian Dröge "] -edition = "2018" -license = "MIT" +[workspace] -[dependencies] -anyhow = "1" -gst = { version = "0.16", package = "gstreamer" } -gst-webrtc = { version = "0.16", package = "gstreamer-webrtc" } -glib = "0.10" -futures = "0.3" -actix-rt = "1" -actix-web = "2" -actix-web-actors = "2" -actix-service = "1" -actix-tls = { version = "2", features = ["nativetls"] } -log = "0.4" -env_logger = "0.7" -serde = "1" -serde_json = "1" -structopt = "0.3" -tokio = "0.2" -async-tungstenite = { version = "0.8", features = ["tokio-runtime", "tokio-native-tls"] } +members = [ + "common", + "server", + "publisher", +] diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..3d76f6e --- /dev/null +++ b/LICENSE @@ -0,0 +1,23 @@ +The MIT License (MIT) + +Copyright (c) 2017 Sebastian Dröge . + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + + diff --git a/common/Cargo.toml b/common/Cargo.toml new file mode 100644 index 0000000..117ff9c --- /dev/null +++ b/common/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "webrtc-audio-publishing" +version = "0.1.0" +authors = ["Sebastian Dröge "] +edition = "2018" +license = "MIT" diff --git a/common/LICENSE b/common/LICENSE new file mode 100644 index 0000000..3d76f6e --- /dev/null +++ b/common/LICENSE @@ -0,0 +1,23 @@ +The MIT License (MIT) + +Copyright (c) 2017 Sebastian Dröge . + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + + diff --git a/common/src/lib.rs b/common/src/lib.rs new file mode 100644 index 0000000..c13e803 --- /dev/null +++ b/common/src/lib.rs @@ -0,0 +1,3 @@ +// Copyright (C) 2020 Sebastian Dröge +// +// Licensed under the MIT license, see the LICENSE file or diff --git a/publisher/Cargo.toml b/publisher/Cargo.toml new file mode 100644 index 0000000..6a7d0b0 --- /dev/null +++ b/publisher/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "webrtc-audio-publisher" +version = "0.1.0" +authors = ["Sebastian Dröge "] +edition = "2018" +license = "MIT" + +[dependencies] +anyhow = "1" +gst = { version = "0.16", package = "gstreamer" } +gst-webrtc = { version = "0.16", package = "gstreamer-webrtc" } +glib = "0.10" +futures = "0.3" +log = "0.4" +env_logger = "0.7" +serde = "1" +serde_json = "1" +structopt = "0.3" +tokio = "0.2" +async-tungstenite = { version = "0.8", features = ["tokio-runtime", "tokio-openssl"] } +webrtc-audio-publishing = { path = "../common" } diff --git a/publisher/LICENSE b/publisher/LICENSE new file mode 100644 index 0000000..3d76f6e --- /dev/null +++ b/publisher/LICENSE @@ -0,0 +1,23 @@ +The MIT License (MIT) + +Copyright (c) 2017 Sebastian Dröge . + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + + diff --git a/publisher/src/config.rs b/publisher/src/config.rs new file mode 100644 index 0000000..f72400f --- /dev/null +++ b/publisher/src/config.rs @@ -0,0 +1,69 @@ +// Copyright (C) 2020 Sebastian Dröge +// +// Licensed under the MIT license, see the LICENSE file or + +use anyhow::{bail, Error}; + +use structopt::StructOpt; + +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +pub enum ChannelConfiguration { + Mono, + Stereo, +} + +impl std::str::FromStr for ChannelConfiguration { + type Err = Error; + + fn from_str(s: &str) -> Result { + match s { + "mono" => Ok(ChannelConfiguration::Mono), + "stereo" => Ok(ChannelConfiguration::Stereo), + _ => bail!( + "Invalid channel configuration '{}', valid values: 'mono', 'stereo'", + s + ), + } + } +} + +#[derive(Debug, StructOpt)] +#[structopt( + name = "webrtc-audio-publisher", + about = "Publish an audio stream via WebRTC." +)] +pub struct Config { + /// Input stream to record, e.g. pulseaudio:default or jack:default. + #[structopt(short, long)] + pub input_stream: String, + + /// Server to publish the stream on, e.g. https://localhost:8080 + #[structopt(short, long)] + pub server: String, + /// Room to create on the server. If it is published to already then this is an error. + #[structopt(short = "r", long)] + pub server_room: String, + /// Description to use for the room. + #[structopt(long)] + pub server_room_description: Option, + + /// TURN server to use, e.g. turn://user:password@foo.bar.com:3478. + #[structopt(long)] + pub turn_server: Option, + /// TURN server to use, e.g. stun://stun.l.google.com:19302. + #[structopt(long)] + pub stun_server: Option, + + /// Bitrate to encode the stream to. + #[structopt(short, long, default_value = "96000")] + pub bitrate: u32, + /// Volume to use, 1.0 means no change. + #[structopt(short, long, default_value = "1.0")] + pub volume: f64, + /// Sample rate to convert to. + #[structopt(long, default_value = "48000")] + pub sample_rate: u32, + /// Channel configuration to use, can be mono or stereo. + #[structopt(long, default_value = "mono")] + pub channel_configuration: ChannelConfiguration, +} diff --git a/publisher/src/main.rs b/publisher/src/main.rs new file mode 100644 index 0000000..1fbc070 --- /dev/null +++ b/publisher/src/main.rs @@ -0,0 +1,31 @@ +// Copyright (C) 2020 Sebastian Dröge +// +// Licensed under the MIT license, see the LICENSE file or + +use anyhow::Error; +use structopt::StructOpt; + +mod config; +use config::Config; + +async fn run(_cfg: &Config) -> Result<(), Error> { + Ok(()) +} + +fn main() -> Result<(), Error> { + let cfg = Config::from_args(); + + gst::init()?; + + let env = env_logger::Env::new() + .filter_or("WEBRTC_AUDIO_PUBLISHER_LOG", "warn") + .write_style("WEBRTC_AUDIO_PUBLISHER_LOG_STYLE"); + env_logger::init_from_env(env); + + let mut runtime = tokio::runtime::Builder::new() + .basic_scheduler() + .enable_all() + .build()?; + + runtime.block_on(run(&cfg)) +} diff --git a/server/Cargo.toml b/server/Cargo.toml new file mode 100644 index 0000000..1e6130e --- /dev/null +++ b/server/Cargo.toml @@ -0,0 +1,25 @@ +[package] +name = "webrtc-audio-server" +version = "0.1.0" +authors = ["Sebastian Dröge "] +edition = "2018" +license = "MIT" + +[dependencies] +anyhow = "1" +gst = { version = "0.16", package = "gstreamer" } +gst-webrtc = { version = "0.16", package = "gstreamer-webrtc" } +glib = "0.10" +futures = "0.3" +actix-rt = "1" +actix-web = { version = "2", features = ["openssl"] } +actix-web-actors = "2" +actix-service = "1" +actix-tls = { version = "2", features = ["openssl"] } +openssl = "0.10" +log = "0.4" +env_logger = "0.7" +serde = "1" +serde_json = "1" +structopt = "0.3" +webrtc-audio-publishing = { path = "../common" } diff --git a/server/LICENSE b/server/LICENSE new file mode 100644 index 0000000..3d76f6e --- /dev/null +++ b/server/LICENSE @@ -0,0 +1,23 @@ +The MIT License (MIT) + +Copyright (c) 2017 Sebastian Dröge . + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + + diff --git a/server/cert.pem b/server/cert.pem new file mode 100644 index 0000000..66538dd --- /dev/null +++ b/server/cert.pem @@ -0,0 +1,29 @@ +-----BEGIN CERTIFICATE----- +MIIFCTCCAvGgAwIBAgIULvKcnQ/rxK5FwL5xHK6jGSkSm/AwDQYJKoZIhvcNAQEL +BQAwFDESMBAGA1UEAwwJbG9jYWxob3N0MB4XDTIwMDkxMTEyMDAyMloXDTIxMDkx +MTEyMDAyMlowFDESMBAGA1UEAwwJbG9jYWxob3N0MIICIjANBgkqhkiG9w0BAQEF +AAOCAg8AMIICCgKCAgEA0hj0t4JmlIFpcDc4bSJ1cM1HwaulrUh0j05ZVslCY6P9 +sBJfHj92ujVb8hbXIzoBD7BhY4VtVm2vRZjQyzuBxB9nZcOsiYC8DDxDuT4tXmYR +H2Ridx0G/AIOL6SmZdBW79jGYpd9P9hyN056bXLqyn+V3KmShGP6Y7uUN2Anoi1b +yrXAaCAb/f4c7Uksvimg69pDb7gy2wDCROU6TTBiN2PEzeoTrhe34IBychlcZck9 +gXk6HpbpnEy8k2p8FU+k9Dtwx+5Kw/4zrlvWBXwk8B8cFLMxLVKp/QKX9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Vod319m3EMY9h/mhxbS0FhP69CxjI +Q0TMisEavchBky9Ul3KZptlF08ToFPBeSyPzdWXz+xXQc99oors/Ft6a39LfQQhH +NQY5i6KTSXubFTOUHPPFOeStE2hvst637ytpgYc9hYFCruCBPIig/WiBl4be +-----END CERTIFICATE----- diff --git a/server/key.pem b/server/key.pem new file mode 100644 index 0000000..79e91f4 --- /dev/null +++ b/server/key.pem @@ -0,0 +1,52 @@ +-----BEGIN PRIVATE KEY----- +MIIJQgIBADANBgkqhkiG9w0BAQEFAASCCSwwggkoAgEAAoICAQDSGPS3gmaUgWlw +NzhtInVwzUfBq6WtSHSPTllWyUJjo/2wEl8eP3a6NVvyFtcjOgEPsGFjhW1Wba9F +mNDLO4HEH2dlw6yJgLwMPEO5Pi1eZhEfZGJ3HQb8Ag4vpKZl0Fbv2MZil30/2HI3 +TnptcurKf5XcqZKEY/pju5Q3YCeiLVvKtcBoIBv9/hztSSy+KaDr2kNvuDLbAMJE +5TpNMGI3Y8TN6hOuF7fggHJyGVxlyT2BeToelumcTLyTanwVT6T0O3DH7krD/jOu +W9YFfCTwHxwUszEtUqn9Apf0C0hYXMaWZFhNOWt6crBrw+ylxTJsfTLccJ9pe54N +vl0tkdPSUVbxZ0reHuRT/7rB8Gr+33H7bQZ3YfAd2JA5sOs2oZ5ZL2Lm0dvxVU2M +2vWW/SXY/YY9/F3rkNP2XATRlXWKeUUIa2WVGSbvlufJs8LL9QfPjlOgHy3O9WwV +tybLa4xOUO94KbN/gVdiXqUgam3ItqtGVKl+I9spWInMJCqcKO/2yjJKXwLQX46r +1v8u2Gc8EpWZdyFUaPF7fBsNcKy349c7rbfJfCj5yfKdQLt+6O6cEZZNa0eXr9nR +I9Gt3FAjrFvLh2rra1hGUPef0UhC9tcgxoysjBIJQnNsa4gYb1d5lvsC7chRHBAq +1OTqykYl1827i9AZ7rsf0uRFVKmPKwIDAQABAoICAB0VN0rv0iNchqvx+O2ih39F +61jz2ctS7E+qGNPaqEYCvWtSH7igMF82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VOU6b/HZD/WlNCEd67QLMzdBayT +zQQL1hrS+VWRfxo7lC6a1RDDQObglBa4hoGsvqmGyeP9ftns73vzsSOUbc7Z+PFO +SbMRsChv9GP7pzGTzknYpoGBTUPgOxl9belFfgyDK4h0qJmo7TOvHJCPebFT0mSa +n6rcYW42gf4fRNWs9lUWLt1b/xECw0wpjVQL8wZSmCKSpGNAuOiG1YoS9lgfIx8u +xmt5PpufRE3d3gspSW3cM2NDwbM/ZQ== +-----END PRIVATE KEY----- diff --git a/server/src/config.rs b/server/src/config.rs new file mode 100644 index 0000000..0571314 --- /dev/null +++ b/server/src/config.rs @@ -0,0 +1,28 @@ +// Copyright (C) 2020 Sebastian Dröge +// +// Licensed under the MIT license, see the LICENSE file or + +use std::path::PathBuf; + +use structopt::StructOpt; + +#[derive(Debug, StructOpt)] +#[structopt( + name = "webrtc-audio-server", + about = "Receives audio streams via WebRTC from publishers and provides them to WebRTC clients." +)] +pub struct Config { + /// Port to use. + #[structopt(short, long, default_value = "8080")] + pub port: u16, + + /// Use TLS. + #[structopt(short = "t", long)] + pub use_tls: bool, + /// Certificate public key file. + #[structopt(short = "c", long, required_if("use_tls", "true"))] + pub certificate_file: Option, + /// Certificate private key file. + #[structopt(short = "k", long, required_if("use_tls", "true"))] + pub key_file: Option, +} diff --git a/server/src/main.rs b/server/src/main.rs new file mode 100644 index 0000000..454ccaa --- /dev/null +++ b/server/src/main.rs @@ -0,0 +1,60 @@ +// Copyright (C) 2020 Sebastian Dröge +// +// Licensed under the MIT license, see the LICENSE file or + +mod config; + +use anyhow::Error; + +use structopt::StructOpt; + +use config::Config; + +use actix_rt::System; + +use actix_web::{web, App, HttpResponse, HttpServer, Responder}; + +async fn index() -> impl Responder { + HttpResponse::Ok().body("Hello world!") +} + +async fn run(cfg: Config) -> Result<(), Error> { + let server = HttpServer::new(|| App::new().route("/", web::get().to(index))); + + let server = if cfg.use_tls { + use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod}; + + let mut builder = SslAcceptor::mozilla_intermediate(SslMethod::tls())?; + builder.set_private_key_file( + cfg.key_file.as_ref().expect("No key file given"), + SslFiletype::PEM, + )?; + builder.set_certificate_chain_file( + cfg.certificate_file + .as_ref() + .expect("No certificate file given"), + )?; + + server.bind_openssl(format!("0.0.0.0:{}", cfg.port), builder)? + } else { + server.bind(format!("0.0.0.0:{}", cfg.port))? + }; + + server.run().await?; + + Ok(()) +} + +fn main() -> Result<(), Error> { + let cfg = Config::from_args(); + + gst::init()?; + + let env = env_logger::Env::new() + .filter_or("WEBRTC_AUDIO_SERVER_LOG", "warn") + .write_style("WEBRTC_AUDIO_SERVER_LOG_STYLE"); + env_logger::init_from_env(env); + + let mut system = System::new("WebRTC Audio Server"); + system.block_on(run(cfg)) +} diff --git a/src/bin/publisher/main.rs b/src/bin/publisher/main.rs deleted file mode 100644 index e7a11a9..0000000 --- a/src/bin/publisher/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("Hello, world!"); -} diff --git a/src/bin/server/main.rs b/src/bin/server/main.rs deleted file mode 100644 index e7a11a9..0000000 --- a/src/bin/server/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("Hello, world!"); -} diff --git a/src/main.rs b/src/main.rs deleted file mode 100644 index e7a11a9..0000000 --- a/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("Hello, world!"); -} -- GitLab