This commit is contained in:
Daniel Løvbrøtte Olsen 2020-03-25 22:30:22 +01:00
parent a1512e6889
commit a4ab569437
4 changed files with 393 additions and 28 deletions

341
Cargo.lock generated
View File

@ -5,6 +5,9 @@ name = "AV1Master"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"rocket", "rocket",
"rocket_contrib",
"serde",
"serde_json",
] ]
[[package]] [[package]]
@ -15,7 +18,7 @@ checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [ dependencies = [
"hermit-abi", "hermit-abi",
"libc", "libc",
"winapi", "winapi 0.3.8",
] ]
[[package]] [[package]]
@ -96,7 +99,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "066ceb7928ca93a9bedc6d0e612a8a0424048b0ab1f75971b203d01420c055d7" checksum = "066ceb7928ca93a9bedc6d0e612a8a0424048b0ab1f75971b203d01420c055d7"
dependencies = [ dependencies = [
"devise_core", "devise_core",
"quote", "quote 0.6.13",
] ]
[[package]] [[package]]
@ -106,11 +109,58 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf41c59b22b5e3ec0ea55c7847e5f358d340f3a8d6d53a5cf4f1564967f96487" checksum = "cf41c59b22b5e3ec0ea55c7847e5f358d340f3a8d6d53a5cf4f1564967f96487"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"proc-macro2", "proc-macro2 0.4.30",
"quote", "quote 0.6.13",
"syn", "syn 0.15.44",
] ]
[[package]]
name = "filetime"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ff6d4dab0aa0c8e6346d46052e93b13a16cf847b54ed357087c35011048cc7d"
dependencies = [
"cfg-if",
"libc",
"redox_syscall",
"winapi 0.3.8",
]
[[package]]
name = "fsevent"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ab7d1bd1bd33cc98b0889831b72da23c0aa4df9cec7e0702f46ecea04b35db6"
dependencies = [
"bitflags",
"fsevent-sys",
]
[[package]]
name = "fsevent-sys"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f41b048a94555da0f42f1d632e2e19510084fb8e303b0daa2816e733fb3644a0"
dependencies = [
"libc",
]
[[package]]
name = "fuchsia-zircon"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82"
dependencies = [
"bitflags",
"fuchsia-zircon-sys",
]
[[package]]
name = "fuchsia-zircon-sys"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
[[package]] [[package]]
name = "glob" name = "glob"
version = "0.3.0" version = "0.3.0"
@ -171,6 +221,51 @@ dependencies = [
"autocfg", "autocfg",
] ]
[[package]]
name = "inotify"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24e40d6fd5d64e2082e0c796495c8ef5ad667a96d03e5aaa0becfd9d47bcbfb8"
dependencies = [
"bitflags",
"inotify-sys",
"libc",
]
[[package]]
name = "inotify-sys"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e74a1aa87c59aeff6ef2cc2fa62d41bc43f54952f55652656b18a02fd5e356c0"
dependencies = [
"libc",
]
[[package]]
name = "iovec"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e"
dependencies = [
"libc",
]
[[package]]
name = "itoa"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b8b7a7c0c47db5545ed3fef7468ee7bb5b74691498139e4b3f6a20685dc6dd8e"
[[package]]
name = "kernel32-sys"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
dependencies = [
"winapi 0.2.8",
"winapi-build",
]
[[package]] [[package]]
name = "language-tags" name = "language-tags"
version = "0.2.2" version = "0.2.2"
@ -183,6 +278,12 @@ version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "lazycell"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f"
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.68" version = "0.2.68"
@ -228,6 +329,78 @@ dependencies = [
"log 0.3.9", "log 0.3.9",
] ]
[[package]]
name = "mio"
version = "0.6.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "302dec22bcf6bae6dfb69c647187f4b4d0fb6f535521f7bc022430ce8e12008f"
dependencies = [
"cfg-if",
"fuchsia-zircon",
"fuchsia-zircon-sys",
"iovec",
"kernel32-sys",
"libc",
"log 0.4.8",
"miow",
"net2",
"slab",
"winapi 0.2.8",
]
[[package]]
name = "mio-extras"
version = "2.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "52403fe290012ce777c4626790c8951324a2b9e3316b3143779c72b029742f19"
dependencies = [
"lazycell",
"log 0.4.8",
"mio",
"slab",
]
[[package]]
name = "miow"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919"
dependencies = [
"kernel32-sys",
"net2",
"winapi 0.2.8",
"ws2_32-sys",
]
[[package]]
name = "net2"
version = "0.2.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42550d9fb7b6684a6d404d9fa7250c2eb2646df731d1c06afc06dcee9e1bcf88"
dependencies = [
"cfg-if",
"libc",
"winapi 0.3.8",
]
[[package]]
name = "notify"
version = "4.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "80ae4a7688d1fab81c5bf19c64fc8db920be8d519ce6336ed4e7efe024724dbd"
dependencies = [
"bitflags",
"filetime",
"fsevent",
"fsevent-sys",
"inotify",
"libc",
"mio",
"mio-extras",
"walkdir",
"winapi 0.3.8",
]
[[package]] [[package]]
name = "num_cpus" name = "num_cpus"
version = "1.12.0" version = "1.12.0"
@ -253,9 +426,9 @@ version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "336db4a192cc7f54efeb0c4e11a9245394824cc3bcbd37ba3ff51240c35d7a6e" checksum = "336db4a192cc7f54efeb0c4e11a9245394824cc3bcbd37ba3ff51240c35d7a6e"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2 0.4.30",
"quote", "quote 0.6.13",
"syn", "syn 0.15.44",
"version_check 0.1.5", "version_check 0.1.5",
"yansi 0.4.0", "yansi 0.4.0",
] ]
@ -272,7 +445,16 @@ version = "0.4.30"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" checksum = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759"
dependencies = [ dependencies = [
"unicode-xid", "unicode-xid 0.1.0",
]
[[package]]
name = "proc-macro2"
version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c09721c6781493a2a492a96b5a5bf19b65917fe6728884e7c44dd0c60ca3435"
dependencies = [
"unicode-xid 0.2.0",
] ]
[[package]] [[package]]
@ -281,7 +463,16 @@ version = "0.6.13"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1" checksum = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2 0.4.30",
]
[[package]]
name = "quote"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2bdc6c187c65bca4260c9011c9e3132efe4909da44726bad24cf7572ae338d7f"
dependencies = [
"proc-macro2 1.0.9",
] ]
[[package]] [[package]]
@ -332,12 +523,25 @@ dependencies = [
"devise", "devise",
"glob", "glob",
"indexmap", "indexmap",
"quote", "quote 0.6.13",
"rocket_http", "rocket_http",
"version_check 0.9.1", "version_check 0.9.1",
"yansi 0.5.0", "yansi 0.5.0",
] ]
[[package]]
name = "rocket_contrib"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a10e7471279bc2d4a21b6fddd9589016bb119e6fbb547b216dd54ef237f28341"
dependencies = [
"log 0.4.8",
"notify",
"rocket",
"serde",
"serde_json",
]
[[package]] [[package]]
name = "rocket_http" name = "rocket_http"
version = "0.4.4" version = "0.4.4"
@ -352,20 +556,66 @@ dependencies = [
"smallvec", "smallvec",
"state", "state",
"time", "time",
"unicode-xid", "unicode-xid 0.1.0",
] ]
[[package]]
name = "ryu"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "535622e6be132bccd223f4bb2b8ac8d53cda3c7a6394944d3b2b33fb974f9d76"
[[package]] [[package]]
name = "safemem" name = "safemem"
version = "0.3.3" version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ef703b7cb59335eae2eb93ceb664c0eb7ea6bf567079d843e09420219668e072" checksum = "ef703b7cb59335eae2eb93ceb664c0eb7ea6bf567079d843e09420219668e072"
[[package]]
name = "same-file"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"
dependencies = [
"winapi-util",
]
[[package]] [[package]]
name = "serde" name = "serde"
version = "1.0.105" version = "1.0.105"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e707fbbf255b8fc8c3b99abb91e7257a622caeb20a9818cbadbeeede4e0932ff" checksum = "e707fbbf255b8fc8c3b99abb91e7257a622caeb20a9818cbadbeeede4e0932ff"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.105"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac5d00fc561ba2724df6758a17de23df5914f20e41cb00f94d5b7ae42fffaff8"
dependencies = [
"proc-macro2 1.0.9",
"quote 1.0.3",
"syn 1.0.17",
]
[[package]]
name = "serde_json"
version = "1.0.48"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9371ade75d4c2d6cb154141b9752cf3781ec9c05e0e5cf35060e1e70ee7b9c25"
dependencies = [
"itoa",
"ryu",
"serde",
]
[[package]]
name = "slab"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
[[package]] [[package]]
name = "smallvec" name = "smallvec"
@ -385,9 +635,20 @@ version = "0.15.44"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5" checksum = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2 0.4.30",
"quote", "quote 0.6.13",
"unicode-xid", "unicode-xid 0.1.0",
]
[[package]]
name = "syn"
version = "1.0.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0df0eb663f387145cab623dea85b09c2c5b4b0aef44e945d928e682fce71bb03"
dependencies = [
"proc-macro2 1.0.9",
"quote 1.0.3",
"unicode-xid 0.2.0",
] ]
[[package]] [[package]]
@ -398,7 +659,7 @@ checksum = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f"
dependencies = [ dependencies = [
"libc", "libc",
"redox_syscall", "redox_syscall",
"winapi", "winapi 0.3.8",
] ]
[[package]] [[package]]
@ -455,6 +716,12 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
[[package]]
name = "unicode-xid"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"
[[package]] [[package]]
name = "untrusted" name = "untrusted"
version = "0.6.2" version = "0.6.2"
@ -484,6 +751,23 @@ version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "078775d0255232fb988e6fccf26ddc9d1ac274299aaedcedce21c6f72cc533ce" checksum = "078775d0255232fb988e6fccf26ddc9d1ac274299aaedcedce21c6f72cc533ce"
[[package]]
name = "walkdir"
version = "2.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "777182bc735b6424e1a57516d35ed72cb8019d85c8c9bf536dccb3445c1a2f7d"
dependencies = [
"same-file",
"winapi 0.3.8",
"winapi-util",
]
[[package]]
name = "winapi"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
[[package]] [[package]]
name = "winapi" name = "winapi"
version = "0.3.8" version = "0.3.8"
@ -494,18 +778,43 @@ dependencies = [
"winapi-x86_64-pc-windows-gnu", "winapi-x86_64-pc-windows-gnu",
] ]
[[package]]
name = "winapi-build"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc"
[[package]] [[package]]
name = "winapi-i686-pc-windows-gnu" name = "winapi-i686-pc-windows-gnu"
version = "0.4.0" version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-util"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ccfbf554c6ad11084fb7517daca16cfdcaccbdadba4fc336f032a8b12c2ad80"
dependencies = [
"winapi 0.3.8",
]
[[package]] [[package]]
name = "winapi-x86_64-pc-windows-gnu" name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0" version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "ws2_32-sys"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e"
dependencies = [
"winapi 0.2.8",
"winapi-build",
]
[[package]] [[package]]
name = "yansi" name = "yansi"
version = "0.4.0" version = "0.4.0"

View File

@ -8,3 +8,11 @@ edition = "2018"
[dependencies] [dependencies]
rocket = "0.4.4" rocket = "0.4.4"
serde = {version = "1.0", features = ["derive"]}
serde_json = "1.0"
[dependencies.rocket_contrib]
version = "0.4.4"
default-features = false
features = ["json"]

View File

@ -1,23 +1,70 @@
#![feature(proc_macro_hygiene, decl_macro)] #![feature(proc_macro_hygiene, decl_macro)]
#[macro_use] extern crate rocket; #[macro_use] extern crate rocket;
use rocket::State;
use rocket::response::status::NotFound;
use rocket_contrib::json::Json;
use serde_json::Value;
use std::path::PathBuf; use std::path::PathBuf;
use std::sync::Mutex;
mod workunit; mod workunit;
use workunit::WUnit; use workunit::WUnit;
const VERSION: &str = "0.1.0";
#[derive(Default, Debug)]
struct SharedState {
list: Mutex<Vec<WUnit>>
}
#[get("/")] #[get("/")]
fn index() -> &'static str { fn index() -> &'static str {
"Welcome to the AV1 Encoder Master Server" "Welcome to the AV1 Encoder Master Server"
} }
#[get("/get_work/<max_length>")] #[get("/version")]
fn getJobs(max_length: u32, ) -> Result<String, std::io::Error> { fn version() -> &'static str {
let mut work = WUnit::default(); "0.1.0"
Ok(format!("{:#?}", work)) }
#[get("/get_jobs")]
fn getJobs(shared: State<SharedState>) -> Json<Value> {
// let shared_data: &SharedState = shared.inner();
let list = shared.list.lock().unwrap();
println!("get jobs blah");
// println!("{:#?}", Json(list));
Json(serde_json::to_value(&list[..]).unwrap())
}
#[get("/get_job/<id>")]
fn getJob(id: usize, shared: State<SharedState>) -> Result<String, NotFound<String>> {
let shared_data: &SharedState = shared.inner();
let list = shared_data.list.lock().unwrap();
let job = list.get(id).ok_or(NotFound(format!("Job not Found: {id}", id = id)));
match job {
Ok(j) => Ok(format!("{:#?}", j)),
Err(e) => Err(e)
}
}
#[get("/add_job")]
fn addJob(shared: State<SharedState>) -> Result<String, std::io::Error> {
let shared_data: &SharedState = shared.inner();
shared_data.list.lock().unwrap().push(WUnit::default());
Ok(format!("{:#?}", shared_data))
} }
fn main() { fn main() {
rocket::ignite().mount("/", routes![index, getJobs]).launch(); rocket::ignite()
.manage(SharedState::default())
.mount("/", routes![index, version, getJobs, getJob, addJob])
.launch();
} }

View File

@ -1,6 +1,7 @@
use std::path::PathBuf; use std::path::PathBuf;
use serde::{Serialize, Deserialize};
#[derive(Default, Debug)] #[derive(Default, Debug, Serialize, Deserialize)]
pub struct WUnit { pub struct WUnit {
file_name: PathBuf, file_name: PathBuf,
priority: u16, priority: u16,
@ -10,7 +11,7 @@ pub struct WUnit {
} }
#[derive(Debug)] #[derive(Debug, Serialize, Deserialize)]
struct EOptions { struct EOptions {
mode: EMode, mode: EMode,
resolution: Resolution, resolution: Resolution,
@ -36,7 +37,7 @@ impl Default for EOptions {
} }
} }
#[derive(Debug)] #[derive(Debug, Serialize, Deserialize)]
enum EMode { enum EMode {
// Quality (CRF), Constrained Quality, Variable Bitrate, Constant Bitrate // Quality (CRF), Constrained Quality, Variable Bitrate, Constant Bitrate
Q(u8), Q(u8),
@ -50,13 +51,13 @@ impl Default for EMode {
} }
} }
#[derive(Default, Debug)] #[derive(Default, Debug, Serialize, Deserialize)]
struct Resolution { struct Resolution {
width: Option<u16>, width: Option<u16>,
height: Option<u16> height: Option<u16>
} }
#[derive(Debug)] #[derive(Debug, Serialize, Deserialize)]
enum EColorDepth { enum EColorDepth {
Eight = 8, Eight = 8,
Ten = 10, Ten = 10,
@ -68,7 +69,7 @@ impl Default for EColorDepth {
} }
} }
#[derive(Debug)] #[derive(Debug, Serialize, Deserialize)]
enum EStatus { enum EStatus {
Queued, Queued,
Reserved, Reserved,