From 0b348406efb5ffa41a409c3dc8428a12f7b404bb Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Mon, 22 Nov 2021 10:12:51 +0100 Subject: [PATCH] s3sink: add metadata property This property can be used to set metadata on the S3 storage object. --- net/rusoto/src/s3sink/imp.rs | 40 +++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/net/rusoto/src/s3sink/imp.rs b/net/rusoto/src/s3sink/imp.rs index 549eaf3dc..0d43ff518 100644 --- a/net/rusoto/src/s3sink/imp.rs +++ b/net/rusoto/src/s3sink/imp.rs @@ -9,7 +9,7 @@ use gst::glib; use gst::prelude::*; use gst::subclass::prelude::*; -use gst::{gst_debug, gst_error, gst_info, gst_trace}; +use gst::{gst_debug, gst_error, gst_info, gst_log, gst_trace, gst_warning}; use gst_base::subclass::prelude::*; @@ -23,6 +23,7 @@ use rusoto_s3::{ use once_cell::sync::Lazy; +use std::collections::HashMap; use std::sync::Mutex; use crate::s3url::*; @@ -87,6 +88,7 @@ struct Settings { buffer_size: u64, access_key: Option, secret_access_key: Option, + metadata: Option, } impl Settings { @@ -118,6 +120,29 @@ impl Settings { self.key.as_ref().unwrap() ) } + + fn to_metadata(&self, element: &super::S3Sink) -> Option> { + self.metadata.as_ref().map(|structure| { + let mut hash = HashMap::new(); + + for (key, value) in structure.iter() { + if let Ok(Ok(value_str)) = value.transform::().map(|v| v.get()) { + gst_log!(CAT, obj: element, "metadata '{}' -> '{}'", key, value_str); + hash.insert(key.to_string(), value_str); + } else { + gst_warning!( + CAT, + obj: element, + "Failed to convert metadata '{}' to string ('{:?}')", + key, + value + ); + } + } + + hash + }) + } } impl Default for Settings { @@ -130,6 +155,7 @@ impl Default for Settings { buffer_size: DEFAULT_BUFFER_SIZE, access_key: None, secret_access_key: None, + metadata: None, } } } @@ -242,6 +268,7 @@ impl S3Sink { bucket: url.bucket.clone(), key: url.object.clone(), content_type: settings.content_type.clone(), + metadata: settings.to_metadata(&self.instance()), ..Default::default() } } @@ -485,6 +512,13 @@ impl ObjectImpl for S3Sink { None, glib::ParamFlags::READWRITE | gst::PARAM_FLAG_MUTABLE_READY, ), + glib::ParamSpecBoxed::new( + "metadata", + "Metadata", + "A map of metadata to store with the object in S3; field values need to be convertible to strings.", + gst::Structure::static_type(), + glib::ParamFlags::READWRITE | gst::PARAM_FLAG_MUTABLE_READY, + ), ] }); @@ -554,6 +588,9 @@ impl ObjectImpl for S3Sink { "secret-access-key" => { settings.secret_access_key = value.get().expect("type checked upstream"); } + "metadata" => { + settings.metadata = value.get().expect("type checked upstream"); + } _ => unimplemented!(), } } @@ -576,6 +613,7 @@ impl ObjectImpl for S3Sink { } "access-key" => settings.access_key.to_value(), "secret-access-key" => settings.secret_access_key.to_value(), + "metadata" => settings.metadata.to_value(), _ => unimplemented!(), } }