mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
gstreamer-1.0 backend: Version updates and squelch warnings
This commit is contained in:
parent
c5c455236e
commit
f192bd1079
2 changed files with 40 additions and 47 deletions
|
@ -22,18 +22,18 @@ log = "0.4"
|
||||||
byteorder = "1.3"
|
byteorder = "1.3"
|
||||||
shell-words = "0.1.0"
|
shell-words = "0.1.0"
|
||||||
|
|
||||||
alsa = { version = "0.2.1", optional = true }
|
alsa = { version = "0.2", optional = true }
|
||||||
portaudio-rs = { version = "0.3.0", optional = true }
|
portaudio-rs = { version = "0.3", optional = true }
|
||||||
libpulse-sys = { version = "0.0.0", optional = true }
|
libpulse-sys = { version = "0.0.0", optional = true }
|
||||||
jack = { version = "0.5.3", optional = true }
|
jack = { version = "0.5", optional = true }
|
||||||
libc = { version = "0.2", optional = true }
|
libc = { version = "0.2", optional = true }
|
||||||
rodio = { version = "0.9", optional = true, default-features = false }
|
rodio = { version = "0.9", optional = true, default-features = false }
|
||||||
cpal = { version = "0.8", optional = true }
|
cpal = { version = "0.8", optional = true }
|
||||||
sdl2 = { version = "0.32", optional = true }
|
sdl2 = { version = "0.32", optional = true }
|
||||||
gstreamer = { version = "0.15.0", optional = true }
|
gstreamer = { version = "0.15", optional = true }
|
||||||
gstreamer-app = { version = "0.15.0", optional = true }
|
gstreamer-app = { version = "0.15", optional = true }
|
||||||
glib = { version = "0.9.0", optional = true }
|
glib = { version = "0.9", optional = true }
|
||||||
zerocopy = { version = "0.2.8", optional = true }
|
zerocopy = { version = "0.2", optional = true }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
alsa-backend = ["alsa"]
|
alsa-backend = ["alsa"]
|
||||||
|
|
|
@ -1,20 +1,17 @@
|
||||||
use super::{Open, Sink};
|
use super::{Open, Sink};
|
||||||
use std::{io, thread, time, process::exit};
|
use std::{io, thread};
|
||||||
use std::sync::mpsc::{sync_channel, SyncSender};
|
use std::sync::mpsc::{sync_channel, SyncSender};
|
||||||
use gst::prelude::*;
|
use gst::prelude::*;
|
||||||
use gst::*;
|
use gst::*;
|
||||||
use gst_app::*;
|
|
||||||
use glib::MainLoop;
|
|
||||||
use zerocopy::*;
|
use zerocopy::*;
|
||||||
|
|
||||||
pub struct GstreamerSink {
|
pub struct GstreamerSink {
|
||||||
tx: SyncSender<Vec<u8>>,
|
tx: SyncSender<Vec<u8>>
|
||||||
pipeline: gst::Pipeline
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Open for GstreamerSink {
|
impl Open for GstreamerSink {
|
||||||
fn open(device: Option<String>) -> GstreamerSink {
|
fn open(device: Option<String>) -> GstreamerSink {
|
||||||
gst::init();
|
gst::init().expect("Failed to init gstreamer!");
|
||||||
let pipeline_str_preamble = r#"appsrc caps="audio/x-raw,format=S16LE,layout=interleaved,channels=2,rate=44100" block=true max-bytes=4096 name=appsrc0 "#;
|
let pipeline_str_preamble = r#"appsrc caps="audio/x-raw,format=S16LE,layout=interleaved,channels=2,rate=44100" block=true max-bytes=4096 name=appsrc0 "#;
|
||||||
let pipeline_str_rest = r#" ! audioconvert ! autoaudiosink"#;
|
let pipeline_str_rest = r#" ! audioconvert ! autoaudiosink"#;
|
||||||
let pipeline_str : String = match device {
|
let pipeline_str : String = match device {
|
||||||
|
@ -26,10 +23,10 @@ impl Open for GstreamerSink {
|
||||||
gst::init().unwrap();
|
gst::init().unwrap();
|
||||||
let pipelinee = gst::parse_launch(&*pipeline_str).expect("New Pipeline error");
|
let pipelinee = gst::parse_launch(&*pipeline_str).expect("New Pipeline error");
|
||||||
let pipeline = pipelinee.dynamic_cast::<gst::Pipeline>().expect("Couldn't cast pipeline element at runtime!");
|
let pipeline = pipelinee.dynamic_cast::<gst::Pipeline>().expect("Couldn't cast pipeline element at runtime!");
|
||||||
let mut bus = pipeline.get_bus().expect("Couldn't get bus from pipeline");
|
let bus = pipeline.get_bus().expect("Couldn't get bus from pipeline");
|
||||||
let mut mainloop = glib::MainLoop::new(None, false);
|
let mainloop = glib::MainLoop::new(None, false);
|
||||||
let mut appsrce : gst::Element = pipeline.get_by_name("appsrc0").expect("Couldn't get appsrc from pipeline");
|
let appsrce : gst::Element = pipeline.get_by_name("appsrc0").expect("Couldn't get appsrc from pipeline");
|
||||||
let mut appsrc : gst_app::AppSrc = appsrce.dynamic_cast::<gst_app::AppSrc>().expect("Couldn't cast AppSrc element at runtime!");
|
let appsrc : gst_app::AppSrc = appsrce.dynamic_cast::<gst_app::AppSrc>().expect("Couldn't cast AppSrc element at runtime!");
|
||||||
let bufferpool = gst::BufferPool::new();
|
let bufferpool = gst::BufferPool::new();
|
||||||
let appsrc_caps = appsrc.get_caps().expect("get appsrc caps failed");
|
let appsrc_caps = appsrc.get_caps().expect("get appsrc caps failed");
|
||||||
let mut conf = bufferpool.get_config();
|
let mut conf = bufferpool.get_config();
|
||||||
|
@ -40,49 +37,45 @@ impl Open for GstreamerSink {
|
||||||
let (tx, rx) = sync_channel::<Vec<u8>>(128);
|
let (tx, rx) = sync_channel::<Vec<u8>>(128);
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
for data in rx {
|
for data in rx {
|
||||||
let mut buffer = bufferpool.acquire_buffer(None);
|
let buffer = bufferpool.acquire_buffer(None);
|
||||||
if(!buffer.is_err()) {
|
if !buffer.is_err() {
|
||||||
let mut okbuffer = buffer.unwrap();
|
let mut okbuffer = buffer.unwrap();
|
||||||
let mutbuf = okbuffer.make_mut();
|
let mutbuf = okbuffer.make_mut();
|
||||||
mutbuf.set_size(data.len());
|
mutbuf.set_size(data.len());
|
||||||
mutbuf.copy_from_slice(0, data.as_bytes());
|
mutbuf.copy_from_slice(0, data.as_bytes()).expect("Failed to copy from slice");
|
||||||
let eat = appsrc.push_buffer(okbuffer);
|
let _eat = appsrc.push_buffer(okbuffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
unsafe {
|
let thread_mainloop = mainloop;
|
||||||
let thread_mainloop = mainloop;
|
let watch_mainloop = thread_mainloop.clone();
|
||||||
let watch_mainloop = thread_mainloop.clone();
|
bus.add_watch(move |_, msg| {
|
||||||
bus.add_watch(move |_, msg| {
|
match msg.view() {
|
||||||
use gst::MessageView;
|
MessageView::Eos(..) => watch_mainloop.quit(),
|
||||||
match msg.view() {
|
MessageView::Error(err) => {
|
||||||
MessageView::Eos(..) => watch_mainloop.quit(),
|
println!(
|
||||||
MessageView::Error(err) => {
|
"Error from {:?}: {} ({:?})",
|
||||||
println!(
|
err.get_src().map(|s| s.get_path_string()),
|
||||||
"Error from {:?}: {} ({:?})",
|
err.get_error(),
|
||||||
err.get_src().map(|s| s.get_path_string()),
|
err.get_debug()
|
||||||
err.get_error(),
|
);
|
||||||
err.get_debug()
|
watch_mainloop.quit();
|
||||||
);
|
}
|
||||||
watch_mainloop.quit();
|
_ => (),
|
||||||
}
|
};
|
||||||
_ => (),
|
|
||||||
};
|
glib::Continue(true)
|
||||||
|
})
|
||||||
glib::Continue(true)
|
.expect("Failed to add bus watch");
|
||||||
})
|
thread_mainloop.run();
|
||||||
.expect("Failed to add bus watch");
|
|
||||||
thread_mainloop.run();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
pipeline.set_state(gst::State::Playing).expect("Unable to set the pipeline to the `Playing` state");
|
pipeline.set_state(gst::State::Playing).expect("Unable to set the pipeline to the `Playing` state");
|
||||||
|
|
||||||
GstreamerSink {
|
GstreamerSink {
|
||||||
tx: tx,
|
tx: tx
|
||||||
pipeline: pipeline
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue