#![cfg(feature = "ogg")]
use std::io::Cursor;
use optivorbis::{remuxer::ogg_to_ogg::Settings, OggToOgg, Remuxer, VorbisCommentFieldsAction, VorbisOptimizerSettings, VorbisVendorStringAction};
use crate::cfg::{acfg, ConfigHolder};
use super::Result_;
acfg!(
MinifierOGG: OGGConfig
);
impl ConfigHolder<MinifierOGG> {
pub(super) fn minify(&self, b: &[u8], vout: &mut Vec<u8>) -> Result_ {
OggToOgg::new(Settings::default(), self.ogg_opts()).remux(&mut Cursor::new(b), vout)?;
Ok(())
}
}
#[cfg_attr(feature = "serde-cfg", derive(serde::Serialize, serde::Deserialize))]
pub struct OGGConfig {
pub remove_comments: bool
}
impl Default for OGGConfig {
fn default() -> Self {
Self { remove_comments: true }
}
}
impl OGGConfig {
#[inline]
fn ogg_opts(&self) -> VorbisOptimizerSettings {
let mut opts = VorbisOptimizerSettings::default();
opts.comment_fields_action = if self.remove_comments {
VorbisCommentFieldsAction::Delete
} else {
VorbisCommentFieldsAction::Copy
};
opts.vendor_string_action = if self.remove_comments {
VorbisVendorStringAction::Empty
} else {
VorbisVendorStringAction::Copy
};
opts
}
}