From 48b9a5400b8311215a8bb5010125f83d390ccd25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Tue, 13 Oct 2020 12:38:02 +0300 Subject: [PATCH] Update byte-slice-cast dependency to 1.0 --- audio/audiofx/Cargo.toml | 2 +- audio/claxon/Cargo.toml | 2 +- audio/claxon/src/claxondec.rs | 46 +++++++++++++++++++++++++---------- audio/csound/Cargo.toml | 2 +- audio/lewton/Cargo.toml | 2 +- tutorial/Cargo.toml | 2 +- 6 files changed, 38 insertions(+), 18 deletions(-) diff --git a/audio/audiofx/Cargo.toml b/audio/audiofx/Cargo.toml index d1c8ae8e..a289b5b7 100644 --- a/audio/audiofx/Cargo.toml +++ b/audio/audiofx/Cargo.toml @@ -12,7 +12,7 @@ glib = { git = "https://github.com/gtk-rs/glib" } gstreamer = { git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" } gstreamer-base = { git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" } gstreamer-audio = { git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" } -byte-slice-cast = "0.3" +byte-slice-cast = "1.0" num-traits = "0.2" lazy_static = "1.0" ebur128 = "0.1" diff --git a/audio/claxon/Cargo.toml b/audio/claxon/Cargo.toml index c0443785..4baf2ce8 100644 --- a/audio/claxon/Cargo.toml +++ b/audio/claxon/Cargo.toml @@ -13,7 +13,7 @@ gstreamer = { git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" } gstreamer-audio = { git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" } gstreamer-check = { git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" } claxon = { version = "0.4" } -byte-slice-cast = "~0.3.4" +byte-slice-cast = "1.0" atomic_refcell = "0.1" [lib] diff --git a/audio/claxon/src/claxondec.rs b/audio/claxon/src/claxondec.rs index 9ccfc25c..34e1e99e 100644 --- a/audio/claxon/src/claxondec.rs +++ b/audio/claxon/src/claxondec.rs @@ -301,7 +301,7 @@ impl ClaxonDec { }; let depth_adjusted = depth.adjust_samples(v); - let outbuf = gst::Buffer::from_slice(depth_adjusted); + let outbuf = gst::Buffer::from_mut_slice(depth_adjusted); element.finish_frame(Some(outbuf), 1) } } @@ -318,6 +318,32 @@ enum AudioDepth { I32, } +enum ByteVec { + I8(Vec), + I16(Vec), + I32(Vec), +} + +impl AsRef<[u8]> for ByteVec { + fn as_ref(&self) -> &[u8] { + match self { + ByteVec::I8(ref vec) => vec.as_byte_slice(), + ByteVec::I16(ref vec) => vec.as_byte_slice(), + ByteVec::I32(ref vec) => vec.as_byte_slice(), + } + } +} + +impl AsMut<[u8]> for ByteVec { + fn as_mut(&mut self) -> &mut [u8] { + match self { + ByteVec::I8(ref mut vec) => vec.as_mut_byte_slice(), + ByteVec::I16(ref mut vec) => vec.as_mut_byte_slice(), + ByteVec::I32(ref mut vec) => vec.as_mut_byte_slice(), + } + } +} + impl AudioDepth { /// Validate input audio depth. fn validate(input: u32) -> Result { @@ -335,19 +361,13 @@ impl AudioDepth { /// /// This takes a vector of 32bits samples, adjusts the depth of each, /// and returns the adjusted bytes stream. - fn adjust_samples(&self, input: Vec) -> Vec { + fn adjust_samples(&self, input: Vec) -> ByteVec { match *self { - AudioDepth::I8 => input - .into_iter() - .map(|x| x as i8) - .collect::>() - .into_byte_vec(), - AudioDepth::I16 => input - .into_iter() - .map(|x| x as i16) - .collect::>() - .into_byte_vec(), - AudioDepth::I24 | AudioDepth::I32 => input.into_byte_vec(), + AudioDepth::I8 => ByteVec::I8(input.into_iter().map(|x| x as i8).collect::>()), + AudioDepth::I16 => { + ByteVec::I16(input.into_iter().map(|x| x as i16).collect::>()) + } + AudioDepth::I24 | AudioDepth::I32 => ByteVec::I32(input), } } } diff --git a/audio/csound/Cargo.toml b/audio/csound/Cargo.toml index 933a4472..4393f3e3 100644 --- a/audio/csound/Cargo.toml +++ b/audio/csound/Cargo.toml @@ -15,7 +15,7 @@ gst_audio = { package = "gstreamer-audio", git = "https://gitlab.freedesktop.org gst_check = { package = "gstreamer-check", git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" } csound = "0.1.8" once_cell = "1.0" -byte-slice-cast = "0.3" +byte-slice-cast = "1.0" [lib] name = "gstcsound" diff --git a/audio/lewton/Cargo.toml b/audio/lewton/Cargo.toml index 5c085911..bab708c3 100644 --- a/audio/lewton/Cargo.toml +++ b/audio/lewton/Cargo.toml @@ -13,7 +13,7 @@ gstreamer = { git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" } gstreamer-audio = { git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" } gstreamer-check = { git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" } lewton = { version = "0.10", default-features = false } -byte-slice-cast = "0.3" +byte-slice-cast = "1.0" atomic_refcell = "0.1" lazy_static = "1.0" diff --git a/tutorial/Cargo.toml b/tutorial/Cargo.toml index e48d5eee..e89e8e2d 100644 --- a/tutorial/Cargo.toml +++ b/tutorial/Cargo.toml @@ -13,7 +13,7 @@ gstreamer = { git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" } gstreamer-base = { git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" } gstreamer-video = { git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" } gstreamer-audio = { git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" } -byte-slice-cast = "0.3" +byte-slice-cast = "1.0" num-traits = "0.2" once_cell = "1.0"