aboutsummaryrefslogtreecommitdiff
path: root/stream/types/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'stream/types/src/lib.rs')
-rw-r--r--stream/types/src/lib.rs40
1 files changed, 38 insertions, 2 deletions
diff --git a/stream/types/src/lib.rs b/stream/types/src/lib.rs
index d1583e9..433b757 100644
--- a/stream/types/src/lib.rs
+++ b/stream/types/src/lib.rs
@@ -4,7 +4,7 @@
Copyright (C) 2026 metamuffin <metamuffin.org>
*/
use serde::{Deserialize, Serialize};
-use std::{collections::BTreeMap, fmt::Display, str::FromStr};
+use std::{collections::BTreeMap, fmt::Display, fmt::Write, str::FromStr};
pub type TrackNum = usize;
pub type FormatNum = usize;
@@ -92,7 +92,43 @@ pub struct StreamFormatInfo {
pub bit_depth: Option<u8>,
}
-#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
+impl std::hash::Hash for StreamFormatInfo {
+ fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
+ self.codec.hash(state);
+ self.codec_param.hash(state);
+ (self.bitrate as i64).hash(state);
+ self.remux.hash(state);
+ self.containers.hash(state);
+ self.width.hash(state);
+ self.height.hash(state);
+ (self.samplerate.unwrap_or(0.) as i64).hash(state);
+ self.channels.hash(state);
+ self.bit_depth.hash(state);
+ }
+}
+impl StreamFormatInfo {
+ pub fn metadata_str(&self) -> String {
+ let mut o = String::new();
+ if let Some(w) = self.width {
+ write!(o, "w{w}").unwrap();
+ }
+ if let Some(h) = self.height {
+ write!(o, "h{h}").unwrap();
+ }
+ if let Some(r) = self.samplerate {
+ write!(o, "r{r:.02}").unwrap();
+ }
+ if let Some(b) = self.bit_depth {
+ write!(o, "b{b}").unwrap();
+ }
+ if let Some(c) = self.channels {
+ write!(o, "c{c}").unwrap();
+ }
+ o
+ }
+}
+
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize, Hash)]
#[serde(rename_all = "lowercase")]
pub enum StreamContainer {
WebM,