From 5713bfc7b04a2a1479267893b2cd611aeca5da6e Mon Sep 17 00:00:00 2001 From: Arkadiusz Hiler Date: Fri, 4 Nov 2022 14:30:33 +0200 Subject: [PATCH] media-converter: Update to the newest gst bindings. 1. ElementImpl trait requires GstObjectImpl 2. gst logging macros are no longer globals prefixed with gst_, they live inside gst:: instead 3. element is not longer passed around in many places, it can be accessed as self.obj() or self.instance() 4. query_default is now a part of gst::Pad and takes the pad as an argument 5. some constructors were changed to use from_$type() 6. query.view_mut() returns QueryViewMut 7. ElementFactory::make now returns a builder that we have to .build() There are some extra cleanups as well: 1. spurious 'mut' and '&' are removed, a lot of that can be infered or were turned into a dereference by the compiler anyway 2. !bla.is_ok() are now bla.is_err() 3. some unneeded imports were removed --- media-converter/Cargo.lock | 167 ++++++++++++------------ media-converter/Cargo.toml | 14 +- media-converter/src/audioconv/imp.rs | 77 ++++++----- media-converter/src/audioconvbin/imp.rs | 27 ++-- media-converter/src/fossilize.rs | 1 - media-converter/src/videoconv/imp.rs | 84 ++++++------ 6 files changed, 182 insertions(+), 188 deletions(-) diff --git a/media-converter/Cargo.lock b/media-converter/Cargo.lock index 4e1d84fb..6ef6281a 100644 --- a/media-converter/Cargo.lock +++ b/media-converter/Cargo.lock @@ -23,6 +23,12 @@ version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bfb6d71005dc22a708c7496eee5c8dc0300ee47355de6256c3b35b12b5fef596" +[[package]] +name = "atomic_refcell" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73b5e5f48b927f04e952dedc932f31995a65a0bf65ec971c74436e51bf6e970d" + [[package]] name = "autocfg" version = "1.1.0" @@ -43,9 +49,9 @@ checksum = "c1ad822118d20d2c234f427000d5acc36eabe1e29a348c89b63dd60b13f28e5d" [[package]] name = "cfg-expr" -version = "0.8.1" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b412e83326147c2bb881f8b40edfbf9905b9b8abaebd0e47ca190ba62fda8f0e" +checksum = "b0357a6402b295ca3a86bc148e84df46c02e41f41fef186bda662557ef6328aa" dependencies = [ "smallvec", ] @@ -83,12 +89,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "either" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" - [[package]] name = "futures-channel" version = "0.3.24" @@ -115,6 +115,17 @@ dependencies = [ "futures-util", ] +[[package]] +name = "futures-macro" +version = "0.3.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42cd15d1c7456c04dbdf7e88bcd69760d74f3a798d6444e16974b505b0e62f17" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "futures-task" version = "0.3.24" @@ -128,6 +139,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44fb6cb1be61cc1d2e43b262516aafcf63b241cffdb1d3fa115f91d9c7b09c90" dependencies = [ "futures-core", + "futures-macro", "futures-task", "pin-project-lite", "pin-utils", @@ -135,29 +147,45 @@ dependencies = [ ] [[package]] -name = "glib" -version = "0.14.8" +name = "gio-sys" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c515f1e62bf151ef6635f528d05b02c11506de986e43b34a5c920ef0b3796a4" +checksum = "6da1bba9d3f2ab13a6e9932c40f240dc99ebc9f0bdc35cfb130d1a3df36f374c" +dependencies = [ + "glib-sys", + "gobject-sys", + "libc", + "system-deps", + "winapi", +] + +[[package]] +name = "glib" +version = "0.16.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5abffa711471e015eb93d65d6ea20e7e9f6f7951fc0a1042280439319b2de06" dependencies = [ "bitflags", "futures-channel", "futures-core", "futures-executor", "futures-task", + "futures-util", + "gio-sys", "glib-macros", "glib-sys", "gobject-sys", "libc", "once_cell", "smallvec", + "thiserror", ] [[package]] name = "glib-macros" -version = "0.14.1" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2aad66361f66796bfc73f530c51ef123970eb895ffba991a234fcf7bea89e518" +checksum = "e195c1311fa6b04d7b896ea39385f6bd60ef5d25bf74a7c11c8c3f94f6c1a572" dependencies = [ "anyhow", "heck", @@ -170,9 +198,9 @@ dependencies = [ [[package]] name = "glib-sys" -version = "0.14.0" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c1d60554a212445e2a858e42a0e48cece1bd57b311a19a9468f70376cf554ae" +checksum = "b33357bb421a77bd849f6a0bfcaf3b4b256a2577802971bb5dd522d530f27021" dependencies = [ "libc", "system-deps", @@ -180,9 +208,9 @@ dependencies = [ [[package]] name = "gobject-sys" -version = "0.14.0" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa92cae29759dae34ab5921d73fff5ad54b3d794ab842c117e36cafc7994c3f5" +checksum = "63ca11a57400f3d4fda594e002844be47900c9fb8b29e2155c6e37a1f24e51b3" dependencies = [ "glib-sys", "libc", @@ -191,18 +219,18 @@ dependencies = [ [[package]] name = "gst-plugin-version-helper" -version = "0.7.3" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a6a4dd1cb931cc6b49af354a68f21b3aee46b5b07370215d942f3a71542123f" +checksum = "747ffe0e4067acfb98d6f7cbbe0a1901794587a93ab2b36c4652bc75c28d865d" dependencies = [ "chrono", ] [[package]] name = "gstreamer" -version = "0.17.4" +version = "0.19.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6a255f142048ba2c4a4dce39106db1965abe355d23f4b5335edea43a553faa4" +checksum = "7e428081934c617115320750b7827f8f13131d9c3ae90b647c14a5d6019f47b4" dependencies = [ "bitflags", "cfg-if", @@ -216,6 +244,7 @@ dependencies = [ "num-integer", "num-rational", "once_cell", + "option-operations", "paste", "pretty-hex", "thiserror", @@ -223,11 +252,10 @@ dependencies = [ [[package]] name = "gstreamer-audio" -version = "0.17.2" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "420b6bcb1759231f01172751da094e7afa5cd9edf40bee7475f5bc86df433c57" +checksum = "affbf8dd22eb301f21a3ae659358a6e069850b35cab6522d40738c9500f85b17" dependencies = [ - "array-init", "bitflags", "cfg-if", "glib", @@ -240,9 +268,9 @@ dependencies = [ [[package]] name = "gstreamer-audio-sys" -version = "0.17.0" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d066ddfd05f63836f35ac4a5830d5bb2f7f3d6c33c870e9b15c667d20f65d7f6" +checksum = "f6d6a3ad336150faf2125e29ac025b1fa152dca08b4cb2496f1e7d9c83b51e8b" dependencies = [ "glib-sys", "gobject-sys", @@ -254,10 +282,11 @@ dependencies = [ [[package]] name = "gstreamer-base" -version = "0.17.2" +version = "0.19.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c0c1d8c62eb5d08fb80173609f2eea71d385393363146e4e78107facbd67715" +checksum = "326674197c010e91a98d0f55a032abe22b1fd932456dbcdc3415450b4b653817" dependencies = [ + "atomic_refcell", "bitflags", "cfg-if", "glib", @@ -268,9 +297,9 @@ dependencies = [ [[package]] name = "gstreamer-base-sys" -version = "0.17.0" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28169a7b58edb93ad8ac766f0fa12dcd36a2af4257a97ee10194c7103baf3e27" +checksum = "cd55d3858fa65a99286c1cbe8db001f4ce5cff6a038f1c1253f5d99f840970de" dependencies = [ "glib-sys", "gobject-sys", @@ -281,9 +310,9 @@ dependencies = [ [[package]] name = "gstreamer-sys" -version = "0.17.3" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a81704feeb3e8599913bdd1e738455c2991a01ff4a1780cb62200993e454cc3e" +checksum = "fbaafc66df32b334d4aa28025fd5d83cadc971e1910205e140ea070f4ac4834f" dependencies = [ "glib-sys", "gobject-sys", @@ -293,9 +322,9 @@ dependencies = [ [[package]] name = "gstreamer-video" -version = "0.17.2" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3447ee95c8e79daec0b163260cf6a3de9bc19ff47a01b533787f900074a3476" +checksum = "a9b96daff8a3d853588e61207afac81a4879f3972430f6609721601ab757d7fd" dependencies = [ "bitflags", "cfg-if", @@ -310,9 +339,9 @@ dependencies = [ [[package]] name = "gstreamer-video-sys" -version = "0.17.0" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b81608f4182bdddd5bd33aaaa341d5544eda12b067a3dab75b1b7d2de01a3ba7" +checksum = "066ee44cd8d84f19a18c646128c1890878c034d3fb9f34d8d5f07311bbd9f41f" dependencies = [ "glib-sys", "gobject-sys", @@ -324,12 +353,9 @@ dependencies = [ [[package]] name = "heck" -version = "0.3.3" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" -dependencies = [ - "unicode-segmentation", -] +checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" [[package]] name = "iana-time-zone" @@ -344,15 +370,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "itertools" -version = "0.10.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" -dependencies = [ - "either", -] - [[package]] name = "js-sys" version = "0.3.60" @@ -419,6 +436,15 @@ version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e82dad04139b71a90c080c8463fe0dc7902db5192d939bd0950f074d014339e1" +[[package]] +name = "option-operations" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c26d27bb1aeab65138e4bf7666045169d1717febcc9ff870166be8348b223d0" +dependencies = [ + "paste", +] + [[package]] name = "paste" version = "1.0.9" @@ -445,9 +471,9 @@ checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae" [[package]] name = "pretty-hex" -version = "0.2.1" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc5c99d529f0d30937f6f4b8a86d988047327bb88d04d2c4afc356de74722131" +checksum = "c6fa0831dd7cc608c38a5e323422a0077678fa5744aa2be4ad91c4ece8eec8d5" [[package]] name = "proc-macro-crate" @@ -538,24 +564,6 @@ version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1" -[[package]] -name = "strum" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aaf86bbcfd1fa9670b7a129f64fc0c9fcbbfe4f1bc4210e9e98fe71ffc12cde2" - -[[package]] -name = "strum_macros" -version = "0.21.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d06aaeeee809dbc59eb4556183dd927df67db1540de5be8d3ec0b6636358a5ec" -dependencies = [ - "heck", - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "syn" version = "1.0.101" @@ -569,18 +577,13 @@ dependencies = [ [[package]] name = "system-deps" -version = "3.2.0" +version = "6.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "480c269f870722b3b08d2f13053ce0c2ab722839f472863c3e2d61ff3a1c2fa6" +checksum = "2955b1fe31e1fa2fbd1976b71cc69a606d7d4da16f6de3333d0c92d51419aeff" dependencies = [ - "anyhow", "cfg-expr", "heck", - "itertools", "pkg-config", - "strum", - "strum_macros", - "thiserror", "toml", "version-compare", ] @@ -620,17 +623,11 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dcc811dc4066ac62f84f11307873c4850cb653bfa9b1719cee2bd2204a4bc5dd" -[[package]] -name = "unicode-segmentation" -version = "1.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fdbf052a0783de01e944a6ce7a8cb939e295b1e7be835a1112c3b9a7f047a5a" - [[package]] name = "version-compare" -version = "0.0.11" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c18c859eead79d8b95d09e4678566e8d70105c4e7b251f707a03df32442661b" +checksum = "fe88247b92c1df6b6de80ddc290f3976dbdf2f5f5d3fd049a9fb598c6dd5ca73" [[package]] name = "version_check" diff --git a/media-converter/Cargo.toml b/media-converter/Cargo.toml index 177d370c..ca681355 100644 --- a/media-converter/Cargo.toml +++ b/media-converter/Cargo.toml @@ -8,14 +8,14 @@ edition = "2021" description = "Proton media converter" [dependencies] -glib = "0.14" -gstreamer = "0.17.4" +glib = "0.16" +gstreamer = "0.19.1" # the versions are not in sync, the submodules below haven't seen any changes -# since 0.17.2 release so .3 and .4 releases haven't happened -gstreamer-base = "0.17.2" -gstreamer-video = "0.17.2" -gstreamer-audio = "0.17.2" +# since 0.19.0 release so .1 release haven't happened for them +gstreamer-base = "0.19.1" +gstreamer-video = "0.19.0" +gstreamer-audio = "0.19.0" once_cell = "1.9" crc32fast = "1.3" @@ -27,7 +27,7 @@ crate-type = ["cdylib"] path = "src/lib.rs" [build-dependencies] -gst-plugin-version-helper = "0.7.2" +gst-plugin-version-helper = "0.7.4" [profile.release] lto = true diff --git a/media-converter/src/audioconv/imp.rs b/media-converter/src/audioconv/imp.rs index d494b84c..3c24ef6e 100644 --- a/media-converter/src/audioconv/imp.rs +++ b/media-converter/src/audioconv/imp.rs @@ -32,13 +32,11 @@ use crate::format_hash; use crate::HASH_SEED; use crate::discarding_disabled; -use gst; use gst::glib; use gst::prelude::*; use gst::subclass::prelude::*; use gst::EventView; -use gst::QueryView; -use gst_audio; +use gst::QueryViewMut; use std::sync::Mutex; use std::io; @@ -463,16 +461,16 @@ impl StreamState { offs += 16; } - gst_trace!(CAT, "stream id {} is a subset of {}, so not recording stream", self.cur_hash, *stream_id); - return true; + gst::trace!(CAT, "stream id {} is a subset of {}, so not recording stream", self.cur_hash, *stream_id); + true }); } if !found { if *DUMPING_DISABLED { - gst_trace!(CAT, "dumping disabled, so not recording stream id {}", self.cur_hash); + gst::trace!(CAT, "dumping disabled, so not recording stream id {}", self.cur_hash); } else { - gst_trace!(CAT, "recording stream id {}", self.cur_hash); + gst::trace!(CAT, "recording stream id {}", self.cur_hash); db.write_entry(AUDIOCONV_FOZ_TAG_CODECINFO, self.buffers[0].0, &mut self.codec_info.as_ref().unwrap().serialize().as_slice(), @@ -594,9 +592,9 @@ impl AudioConvState { let buf_len = mapped.size(); let hash = hash_data(mapped.as_slice(), buf_len, &mut self.hash_state) - .map_err(|e|{ gst_warning!(CAT, "Hashing buffer failed! {}", e); io::ErrorKind::Other })?; + .map_err(|e|{ gst::warning!(CAT, "Hashing buffer failed! {}", e); io::ErrorKind::Other })?; let loop_hash = hash_data(mapped.as_slice(), buf_len, &mut self.loop_hash_state) - .map_err(|e|{ gst_warning!(CAT, "Hashing buffer failed! {}", e); io::ErrorKind::Other })?; + .map_err(|e|{ gst::warning!(CAT, "Hashing buffer failed! {}", e); io::ErrorKind::Other })?; let try_loop = match self.stream_state.record_buffer(hash, loop_hash, mapped, Some(self.codec_data.as_ref().unwrap()))? { LoopState::NoLoop => { self.loop_hash_state.reset(); false }, @@ -605,9 +603,9 @@ impl AudioConvState { }; if try_loop { - gst_log!(CAT, "Buffer hash: {} (loop: {})", format_hash(hash), format_hash(loop_hash)); + gst::log!(CAT, "Buffer hash: {} (loop: {})", format_hash(hash), format_hash(loop_hash)); }else{ - gst_log!(CAT, "Buffer hash: {}", format_hash(hash)); + gst::log!(CAT, "Buffer hash: {}", format_hash(hash)); } /* try to read transcoded data */ @@ -658,14 +656,14 @@ impl ObjectSubclass for AudioConv { AudioConv::catch_panic_pad_function( parent, || Err(gst::FlowError::Error), - |audioconv, element| audioconv.chain(pad, element, buffer) + |audioconv| audioconv.chain(pad, buffer) ) }) .event_function(|pad, parent, event| { AudioConv::catch_panic_pad_function( parent, || false, - |audioconv, element| audioconv.sink_event(pad, element, event) + |audioconv| audioconv.sink_event(pad, event) ) }).build(); @@ -675,14 +673,14 @@ impl ObjectSubclass for AudioConv { AudioConv::catch_panic_pad_function( parent, || false, - |audioconv, element| audioconv.src_query(pad, element, query) + |audioconv| audioconv.src_query(pad, query) ) }) .activatemode_function(|pad, parent, mode, active| { AudioConv::catch_panic_pad_function( parent, || Err(loggable_error!(CAT, "Panic activating srcpad with mode")), - |audioconv, element| audioconv.src_activatemode(pad, element, mode, active) + |audioconv| audioconv.src_activatemode(pad, mode, active) ) }).build(); @@ -695,14 +693,18 @@ impl ObjectSubclass for AudioConv { } impl ObjectImpl for AudioConv { - fn constructed(&self, obj: &Self::Type) { - self.parent_constructed(obj); + fn constructed(&self) { + self.parent_constructed(); + + let obj = self.obj(); obj.add_pad(&self.sinkpad).unwrap(); obj.add_pad(&self.srcpad).unwrap(); } } +impl GstObjectImpl for AudioConv { } + impl ElementImpl for AudioConv { fn metadata() -> Option<&'static gst::subclass::ElementMetadata> { static ELEMENT_METADATA: Lazy = Lazy::new(|| { @@ -744,11 +746,10 @@ impl ElementImpl for AudioConv { fn change_state( &self, - element: &super::AudioConv, transition: gst::StateChange ) -> Result { - gst_log!(CAT, obj: element, "State transition: {:?}", transition); + gst::log!(CAT, imp: self, "State transition: {:?}", transition); match transition { gst::StateChange::NullToReady => { @@ -762,7 +763,7 @@ impl ElementImpl for AudioConv { let db = &mut (*DUMP_FOZDB).lock().unwrap(); let db = &mut db.open(true).fozdb; if db.is_none() { - gst_error!(CAT, "Failed to open fossilize db!"); + gst::error!(CAT, "Failed to open fossilize db!"); return Err(gst::StateChangeError); } } @@ -783,7 +784,7 @@ impl ElementImpl for AudioConv { let old_state = self.state.lock().unwrap().take(); // dispose of state if let Some(old_state) = old_state { if old_state.stream_state.write_to_foz().is_err() { - gst_warning!(CAT, "Error writing out stream data!"); + gst::warning!(CAT, "Error writing out stream data!"); } } }, @@ -791,7 +792,7 @@ impl ElementImpl for AudioConv { _ => (), }; - self.parent_change_state(element, transition) + self.parent_change_state(transition) /* XXX on ReadyToNull, sodium drops state _again_ here... why? */ } @@ -802,10 +803,9 @@ impl AudioConv { fn chain( &self, _pad: &gst::Pad, - _element: &super::AudioConv, buffer: gst::Buffer ) -> Result { - gst_log!(CAT, "Handling buffer {:?}", buffer); + gst::log!(CAT, "Handling buffer {:?}", buffer); let mut state = self.state.lock().unwrap(); let mut state = match &mut *state { @@ -814,7 +814,7 @@ impl AudioConv { }; let ptnadata = state.open_transcode_file(buffer).map_err(|_| { - gst_error!(CAT, "ERROR! Failed to read transcoded audio! Things will go badly..."); gst::FlowError::Error + gst::error!(CAT, "ERROR! Failed to read transcoded audio! Things will go badly..."); gst::FlowError::Error })?; let mut offs: usize = 0; @@ -825,7 +825,7 @@ impl AudioConv { } if offs + 4 >= ptnadata.len() { - gst_warning!(CAT, "Short read on ptna header?"); + gst::warning!(CAT, "Short read on ptna header?"); break; } @@ -838,7 +838,7 @@ impl AudioConv { (packet_hdr & AUDIOCONV_ENCODED_LENGTH_MASK) as usize); if offs + encoded_len > ptnadata.len() { - gst_warning!(CAT, "Short read on ptna data?"); + gst::warning!(CAT, "Short read on ptna data?"); break; } @@ -854,14 +854,16 @@ impl AudioConv { let mut buffer = gst::Buffer::with_size(encoded_len as usize).unwrap(); if !pkt_is_header && padding_len > 0 { - gst_audio::AudioClippingMeta::add(buffer.get_mut().unwrap(), gst::format::Default(0), gst::format::Default(padding_len as u64)); + gst_audio::AudioClippingMeta::add(buffer.get_mut().unwrap(), + gst::format::Default::ZERO, + gst::format::Default::from_u64(padding_len as u64)); } let mut writable = buffer.into_mapped_buffer_writable().unwrap(); writable.as_mut_slice().copy_from_slice(&ptnadata[offs..offs + encoded_len]); - gst_log!(CAT, "pushing one packet of len {}", encoded_len); + gst::log!(CAT, "pushing one packet of len {}", encoded_len); self.srcpad.push(writable.into_buffer())?; if pkt_is_header { @@ -877,10 +879,9 @@ impl AudioConv { fn sink_event( &self, pad: &gst::Pad, - element: &super::AudioConv, event: gst::Event ) -> bool { - gst_log!(CAT, obj:pad, "Got an event {:?}", event); + gst::log!(CAT, obj:pad, "Got an event {:?}", event); match event.view() { EventView::Caps(event_caps) => { @@ -889,7 +890,7 @@ impl AudioConv { let head = match NeedTranscodeHead::new_from_caps(&event_caps.caps()){ Ok(h) => h, Err(e) => { - gst_error!(CAT, "Invalid WMA caps!"); + gst::error!(CAT, "Invalid WMA caps!"); e.log(); return false; }, @@ -916,21 +917,20 @@ impl AudioConv { }; drop(state); - pad.event_default(Some(element), event) + gst::Pad::event_default(pad, Some(&*self.obj()), event) }, - _ => pad.event_default(Some(element), event) + _ => gst::Pad::event_default(pad, Some(&*self.obj()), event) } } fn src_query( &self, pad: &gst::Pad, - element: &super::AudioConv, query: &mut gst::QueryRef) -> bool { - gst_log!(CAT, obj: pad, "got query: {:?}", query); + gst::log!(CAT, obj: pad, "got query: {:?}", query); match query.view_mut() { - QueryView::Scheduling(mut q) => { + QueryViewMut::Scheduling(q) => { let mut peer_query = gst::query::Scheduling::new(); let res = self.sinkpad.peer_query(&mut peer_query); if ! res { @@ -942,14 +942,13 @@ impl AudioConv { q.set(flags, min, max, align); true }, - _ => pad.query_default(Some(element), query) + _ => gst::Pad::query_default(pad, Some(&*self.obj()), query) } } fn src_activatemode( &self, _pad: &gst::Pad, - _element: &super::AudioConv, mode: gst::PadMode, active: bool ) -> Result<(), gst::LoggableError> { diff --git a/media-converter/src/audioconvbin/imp.rs b/media-converter/src/audioconvbin/imp.rs index dc469ed6..dc36d56a 100644 --- a/media-converter/src/audioconvbin/imp.rs +++ b/media-converter/src/audioconvbin/imp.rs @@ -28,7 +28,6 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -use gst; use gst::glib; use gst::prelude::*; use gst::subclass::prelude::*; @@ -86,13 +85,13 @@ impl ObjectSubclass for AudioConvBin { AudioConvBin::catch_panic_pad_function( parent, || false, - |audioconvbin, element| audioconvbin.sink_event(pad, element, event) + |audioconvbin| audioconvbin.sink_event(pad, event) ) }).build(); - let audioconv = gst::ElementFactory::make("protonaudioconverter", None).unwrap(); - let opusdec = gst::ElementFactory::make("opusdec", None).unwrap(); - let capssetter = gst::ElementFactory::make("capssetter", None).unwrap(); + let audioconv = gst::ElementFactory::make("protonaudioconverter").build().unwrap(); + let opusdec = gst::ElementFactory::make("opusdec").build().unwrap(); + let capssetter = gst::ElementFactory::make("capssetter").build().unwrap(); AudioConvBin { audioconv, @@ -105,8 +104,10 @@ impl ObjectSubclass for AudioConvBin { } impl ObjectImpl for AudioConvBin { - fn constructed(&self, obj: &Self::Type) { - self.parent_constructed(obj); + fn constructed(&self) { + self.parent_constructed(); + + let obj = self.obj(); obj.add(&self.audioconv).unwrap(); obj.add(&self.opusdec).unwrap(); @@ -127,6 +128,8 @@ impl ObjectImpl for AudioConvBin { } } +impl GstObjectImpl for AudioConvBin { } + impl BinImpl for AudioConvBin { } impl ElementImpl for AudioConvBin { @@ -175,7 +178,6 @@ impl AudioConvBin { fn sink_event( &self, pad: &gst::GhostPad, - element: &super::AudioConvBin, event: gst::Event ) -> bool { match event.view() { @@ -193,20 +195,19 @@ impl AudioConvBin { .build(); rate_caps.append_structure(s); } - self.capssetter.set_property("caps", - &rate_caps).unwrap(); + self.capssetter.set_property("caps", &rate_caps); }else{ - gst_warning!(CAT, "event has no rate"); + gst::warning!(CAT, "event has no rate"); } } else { - gst_warning!(CAT, "event has no structure"); + gst::warning!(CAT, "event has no structure"); } /* forward on to the real pad */ self.audioconv.static_pad("sink").unwrap() .send_event(event) }, - _ => pad.event_default(Some(element), event) + _ => gst::Pad::event_default(pad, Some(&*self.obj()), event) } } } diff --git a/media-converter/src/fossilize.rs b/media-converter/src/fossilize.rs index 658399a6..a52104ff 100644 --- a/media-converter/src/fossilize.rs +++ b/media-converter/src/fossilize.rs @@ -50,7 +50,6 @@ use std::io::Seek; use std::fs::OpenOptions; use std::convert::From; use std::collections::HashMap; -use crc32fast; use crate::*; diff --git a/media-converter/src/videoconv/imp.rs b/media-converter/src/videoconv/imp.rs index 95556d2a..6045ab03 100644 --- a/media-converter/src/videoconv/imp.rs +++ b/media-converter/src/videoconv/imp.rs @@ -35,12 +35,11 @@ use crate::copy_into_array; use crate::BufferedReader; use crate::discarding_disabled; -use gst; use gst::glib; use gst::prelude::*; use gst::subclass::prelude::*; use gst::EventView; -use gst::QueryView; +use gst::QueryViewMut; use std::sync::Mutex; use std::fs; @@ -327,14 +326,14 @@ impl VideoConvState { fn begin_transcode(&mut self, hash: u128) -> bool { if let Some(read_fozdb) = &mut self.read_fozdb { if let Ok(transcoded_size) = read_fozdb.entry_size(VIDEOCONV_FOZ_TAG_MKVDATA, hash) { - gst_log!(CAT, "Found an MKV video for hash {}", format_hash(hash)); + gst::log!(CAT, "Found an MKV video for hash {}", format_hash(hash)); self.transcode_hash = Some(hash); self.our_duration = Some(transcoded_size as u64); self.transcoded_tag = VIDEOCONV_FOZ_TAG_MKVDATA; return true; } if let Ok(transcoded_size) = read_fozdb.entry_size(VIDEOCONV_FOZ_TAG_OGVDATA, hash) { - gst_log!(CAT, "Found an OGV video for hash {}", format_hash(hash)); + gst::log!(CAT, "Found an OGV video for hash {}", format_hash(hash)); self.transcode_hash = Some(hash); self.our_duration = Some(transcoded_size as u64); self.transcoded_tag = VIDEOCONV_FOZ_TAG_OGVDATA; @@ -342,7 +341,7 @@ impl VideoConvState { } } - gst_log!(CAT, "No transcoded video for {}. Substituting a blank video.", format_hash(hash)); + gst::log!(CAT, "No transcoded video for {}. Substituting a blank video.", format_hash(hash)); self.transcode_hash = None; self.our_duration = Some(include_bytes!("../../blank.mkv").len() as u64); @@ -390,7 +389,7 @@ impl ObjectSubclass for VideoConv { VideoConv::catch_panic_pad_function( parent, || false, - |videoconv, element| videoconv.sink_event(pad, element, event) + |videoconv| videoconv.sink_event(pad, event) ) }).build(); @@ -400,21 +399,21 @@ impl ObjectSubclass for VideoConv { VideoConv::catch_panic_pad_function( parent, || Err(gst::FlowError::Error), - |videoconv, element| videoconv.range(pad, element, offset, in_buf, size) + |videoconv| videoconv.range(pad, offset, in_buf, size) ) }) .query_function(|pad, parent, query| { VideoConv::catch_panic_pad_function( parent, || false, - |videoconv, element| videoconv.src_query(pad, element, query) + |videoconv| videoconv.src_query(pad, query) ) }) .activatemode_function(|pad, parent, mode, active| { VideoConv::catch_panic_pad_function( parent, || Err(loggable_error!(CAT, "Panic activating srcpad with mode")), - |videoconv, element| videoconv.src_activatemode(pad, element, mode, active) + |videoconv| videoconv.src_activatemode(pad, mode, active) ) }).build(); @@ -427,14 +426,18 @@ impl ObjectSubclass for VideoConv { } impl ObjectImpl for VideoConv { - fn constructed(&self, obj: &Self::Type) { - self.parent_constructed(obj); + fn constructed(&self) { + self.parent_constructed(); + + let obj = self.obj(); obj.add_pad(&self.sinkpad).unwrap(); obj.add_pad(&self.srcpad).unwrap(); } } +impl GstObjectImpl for VideoConv { } + impl ElementImpl for VideoConv { fn metadata() -> Option<&'static gst::subclass::ElementMetadata> { static ELEMENT_METADATA: Lazy = Lazy::new(|| { @@ -485,11 +488,10 @@ impl ElementImpl for VideoConv { fn change_state( &self, - element: &super::VideoConv, transition: gst::StateChange ) -> Result { - gst_log!(CAT, obj: element, "State transition: {:?}", transition); + gst::log!(CAT, imp: self, "State transition: {:?}", transition); match transition { gst::StateChange::NullToReady => { @@ -514,7 +516,7 @@ impl ElementImpl for VideoConv { _ => (), }; - self.parent_change_state(element, transition) + self.parent_change_state(transition) /* XXX on ReadyToNull, sodium drops state _again_ here... why? */ } @@ -551,7 +553,6 @@ impl VideoConv { fn range( &self, _pad: &gst::Pad, - _element: &super::VideoConv, offset: u64, in_buf: Option<&mut gst::BufferRef>, requested_size: u32, @@ -559,17 +560,17 @@ impl VideoConv { let mut state = self.state.lock().unwrap(); - let mut state = match &mut *state { + let state = match &mut *state { Some(s) => s, None => { return Err(gst::FlowError::Error); } }; if state.upstream_duration.is_none() { - self.query_upstream_duration(&mut state); + self.query_upstream_duration(state); } - let ups_offset = self.duration_ours_to_upstream(&state, offset).unwrap(); - let ups_requested_size = self.duration_ours_to_upstream(&state, requested_size as u64).unwrap() as u32; + let ups_offset = self.duration_ours_to_upstream(state, offset).unwrap(); + let ups_requested_size = self.duration_ours_to_upstream(state, requested_size as u64).unwrap() as u32; /* read and ignore upstream bytes */ self.sinkpad.pull_range(ups_offset, ups_requested_size)?; @@ -617,10 +618,9 @@ impl VideoConv { fn sink_event( &self, pad: &gst::Pad, - element: &super::VideoConv, event: gst::Event ) -> bool { - gst_log!(CAT, obj:pad, "Got an event {:?}", event); + gst::log!(CAT, obj:pad, "Got an event {:?}", event); match event.view() { EventView::Caps(_) => { @@ -629,18 +629,18 @@ impl VideoConv { let caps = { let mut state = self.state.lock().unwrap(); - let mut state = match &mut *state { + let state = match &mut *state { Some(s) => s, - None => { gst_error!(CAT, "VideoConv not yet in READY state?"); return false; }, + None => { gst::error!(CAT, "VideoConv not yet in READY state?"); return false; }, }; - if !self.sinkpad.activate_mode(gst::PadMode::Pull, true).is_ok() { - gst_error!(CAT, "Failed to activate sinkpad in pull mode"); + if self.sinkpad.activate_mode(gst::PadMode::Pull, true).is_err() { + gst::error!(CAT, "Failed to activate sinkpad in pull mode"); return false; } - if !self.init_transcode(&mut state).is_ok() { - gst_error!(CAT, "Failed to init transcode"); + if self.init_transcode(state).is_err() { + gst::error!(CAT, "Failed to init transcode"); return false; } @@ -653,7 +653,7 @@ impl VideoConv { self.srcpad.push_event(gst::event::Caps::new(&caps)) } - _ => pad.event_default(Some(element), event) + _ => gst::Pad::event_default(pad, Some(&*self.obj()), event) } } @@ -661,12 +661,12 @@ impl VideoConv { let mut query = gst::query::Duration::new(gst::Format::Bytes); if self.sinkpad.peer_query(&mut query) { - state.upstream_duration = match query.result().try_into().unwrap() { - Some(gst::format::Bytes(size)) => Some(size), + state.upstream_duration = match query.result() { + gst::GenericFormattedValue::Bytes(Some(size)) => Some(*size), _ => None, } }else{ - gst_warning!(CAT, "upstream duration query failure"); + gst::warning!(CAT, "upstream duration query failure"); } } @@ -682,12 +682,11 @@ impl VideoConv { fn src_query( &self, pad: &gst::Pad, - element: &super::VideoConv, query: &mut gst::QueryRef) -> bool { - gst_log!(CAT, obj: pad, "got query: {:?}", query); + gst::log!(CAT, obj: pad, "got query: {:?}", query); match query.view_mut() { - QueryView::Scheduling(mut q) => { + QueryViewMut::Scheduling(q) => { let mut peer_query = gst::query::Scheduling::new(); let res = self.sinkpad.peer_query(&mut peer_query); if ! res { @@ -700,29 +699,29 @@ impl VideoConv { q.add_scheduling_modes(&[gst::PadMode::Pull]); true }, - QueryView::Duration(ref mut q) => { + QueryViewMut::Duration(ref mut q) => { let mut state = self.state.lock().unwrap(); - let mut state = match &mut *state { + let state = match &mut *state { Some(s) => s, None => { return false; } }; if state.upstream_duration.is_none() { - self.query_upstream_duration(&mut state); + self.query_upstream_duration(state); } if let Some(sz) = state.our_duration { if q.format() == gst::Format::Bytes { - q.set(gst::format::Bytes(sz)); + q.set(gst::format::Bytes::from_u64(sz)); return true } } false } - _ => pad.query_default(Some(element), query) + _ => gst::Pad::query_default(pad, Some(&*self.obj()), query) } } @@ -736,7 +735,7 @@ impl VideoConv { let mut db = &mut db.open(true).fozdb; let db = match &mut db { Some(d) => d, - None => { gst_error!(CAT, "Unable to open fozdb!"); return Err(io::Error::new(io::ErrorKind::Other, "unable to open fozdb")); }, + None => { gst::error!(CAT, "Unable to open fozdb!"); return Err(io::Error::new(io::ErrorKind::Other, "unable to open fozdb")); }, }; let mut chunks = Vec::::new(); @@ -754,11 +753,11 @@ impl VideoConv { chunks.push(chunk_hash); db.write_entry(VIDEOCONV_FOZ_TAG_VIDEODATA, chunk_hash, &mut BufferedReader::new(&*buf, readed), fossilize::CRCCheck::WithCRC) - .map_err(|e| { gst_warning!(CAT, "Error writing video data to fozdb: {:?}", e); io::Error::new(io::ErrorKind::Other, "error writing video data to fozdb") } )?; + .map_err(|e| { gst::warning!(CAT, "Error writing video data to fozdb: {:?}", e); io::Error::new(io::ErrorKind::Other, "error writing video data to fozdb") } )?; } db.write_entry(VIDEOCONV_FOZ_TAG_STREAM, hash, &mut StreamSerializer::new(&chunks), fossilize::CRCCheck::WithCRC) - .map_err(|e| { gst_warning!(CAT, "Error writing stream data to fozdb: {:?}", e); io::Error::new(io::ErrorKind::Other, "error writing stream data to fozdb") } )?; + .map_err(|e| { gst::warning!(CAT, "Error writing stream data to fozdb: {:?}", e); io::Error::new(io::ErrorKind::Other, "error writing stream data to fozdb") } )?; Ok(()) } @@ -786,7 +785,6 @@ impl VideoConv { fn src_activatemode( &self, _pad: &gst::Pad, - _element: &super::VideoConv, mode: gst::PadMode, active: bool ) -> Result<(), gst::LoggableError> {