forked from mirrors/gstreamer-rs
Fix clippy warnings in the examples
This commit is contained in:
parent
d7baadee22
commit
b08a101cc6
4 changed files with 21 additions and 30 deletions
|
@ -3,9 +3,6 @@ use gst::*;
|
||||||
extern crate gstreamer_app as gst_app;
|
extern crate gstreamer_app as gst_app;
|
||||||
use gst_app::*;
|
use gst_app::*;
|
||||||
|
|
||||||
extern crate glib;
|
|
||||||
use glib::*;
|
|
||||||
|
|
||||||
use std::u64;
|
use std::u64;
|
||||||
use std::i16;
|
use std::i16;
|
||||||
use std::i32;
|
use std::i32;
|
||||||
|
@ -24,10 +21,10 @@ fn main() {
|
||||||
appsink.set_caps(&Caps::new_simple(
|
appsink.set_caps(&Caps::new_simple(
|
||||||
"audio/x-raw",
|
"audio/x-raw",
|
||||||
&[
|
&[
|
||||||
(&"format", &"S16BE"),
|
("format", &"S16BE"),
|
||||||
(&"layout", &"interleaved"),
|
("layout", &"interleaved"),
|
||||||
(&"channels", &(1i32)),
|
("channels", &(1i32)),
|
||||||
(&"rate", &IntRange::<i32>::new(1, i32::MAX)),
|
("rate", &IntRange::<i32>::new(1, i32::MAX)),
|
||||||
],
|
],
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
|
@ -3,9 +3,6 @@ use gst::*;
|
||||||
extern crate gstreamer_app as gst_app;
|
extern crate gstreamer_app as gst_app;
|
||||||
use gst_app::*;
|
use gst_app::*;
|
||||||
|
|
||||||
extern crate glib;
|
|
||||||
use glib::*;
|
|
||||||
|
|
||||||
use std::u64;
|
use std::u64;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
|
|
||||||
|
@ -27,10 +24,10 @@ fn main() {
|
||||||
appsrc.set_caps(&Caps::new_simple(
|
appsrc.set_caps(&Caps::new_simple(
|
||||||
"video/x-raw",
|
"video/x-raw",
|
||||||
&[
|
&[
|
||||||
(&"format", &"BGRx"),
|
("format", &"BGRx"),
|
||||||
(&"width", &(WIDTH as i32)),
|
("width", &(WIDTH as i32)),
|
||||||
(&"height", &(HEIGHT as i32)),
|
("height", &(HEIGHT as i32)),
|
||||||
(&"framerate", &Fraction::new(2, 1)),
|
("framerate", &Fraction::new(2, 1)),
|
||||||
],
|
],
|
||||||
));
|
));
|
||||||
appsrc.set_property_format(Format::Time);
|
appsrc.set_property_format(Format::Time);
|
||||||
|
|
|
@ -29,7 +29,7 @@ fn main() {
|
||||||
// Need to move a new reference into the closure
|
// Need to move a new reference into the closure
|
||||||
let pipeline_clone = pipeline.clone();
|
let pipeline_clone = pipeline.clone();
|
||||||
decodebin.connect_pad_added(move |_, src_pad| {
|
decodebin.connect_pad_added(move |_, src_pad| {
|
||||||
let ref pipeline = pipeline_clone;
|
let pipeline = &pipeline_clone;
|
||||||
|
|
||||||
let (is_audio, is_video) = {
|
let (is_audio, is_video) = {
|
||||||
let caps = src_pad.get_current_caps().unwrap();
|
let caps = src_pad.get_current_caps().unwrap();
|
||||||
|
|
|
@ -20,21 +20,18 @@ fn main() {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let src_pad = src.get_static_pad("src").unwrap();
|
let src_pad = src.get_static_pad("src").unwrap();
|
||||||
src_pad.add_probe(PAD_PROBE_TYPE_BUFFER, |_, probe_info| {
|
src_pad.add_probe(PAD_PROBE_TYPE_BUFFER, |_, probe_info| {
|
||||||
match probe_info.data {
|
if let Some(PadProbeData::Buffer(ref buffer)) = probe_info.data {
|
||||||
Some(PadProbeData::Buffer(ref buffer)) => {
|
let map = buffer.map_read().unwrap();
|
||||||
let map = buffer.map_read().unwrap();
|
let data = map.as_slice();
|
||||||
let data = map.as_slice();
|
let sum: f64 = data.chunks(2)
|
||||||
let sum: f64 = data.chunks(2)
|
.map(|sample| {
|
||||||
.map(|sample| {
|
let u: u16 = ((sample[0] as u16) << 8) | (sample[1] as u16);
|
||||||
let u: u16 = ((sample[0] as u16) << 8) | (sample[1] as u16);
|
let f = (u as i16 as f64) / (i16::MAX as f64);
|
||||||
let f = (u as i16 as f64) / (i16::MAX as f64);
|
f * f
|
||||||
f * f
|
})
|
||||||
})
|
.sum();
|
||||||
.sum();
|
let rms = (sum / ((data.len() / 2) as f64)).sqrt();
|
||||||
let rms = (sum / ((data.len() / 2) as f64)).sqrt();
|
println!("rms: {}", rms);
|
||||||
println!("rms: {}", rms);
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PadProbeReturn::Ok
|
PadProbeReturn::Ok
|
||||||
|
|
Loading…
Reference in a new issue