aboutsummaryrefslogtreecommitdiff
path: root/stream/types
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2026-03-04 01:50:37 +0100
committermetamuffin <metamuffin@disroot.org>2026-03-04 01:50:37 +0100
commit3eaba0353512ee6ebb909722fde931136b44a4f8 (patch)
tree06d1352bfd6c170fae6cf2af21eb3efaf3b9fe35 /stream/types
parent4c70753ee7311f644401669e6fde7b4a6cd32992 (diff)
downloadjellything-3eaba0353512ee6ebb909722fde931136b44a4f8.tar
jellything-3eaba0353512ee6ebb909722fde931136b44a4f8.tar.bz2
jellything-3eaba0353512ee6ebb909722fde931136b44a4f8.tar.zst
codec parameter string in stream info
Diffstat (limited to 'stream/types')
-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,