mirror of
https://github.com/librespot-org/librespot.git
synced 2024-11-08 16:45:43 +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"
|
||||
shell-words = "0.1.0"
|
||||
|
||||
alsa = { version = "0.2.1", optional = true }
|
||||
portaudio-rs = { version = "0.3.0", optional = true }
|
||||
alsa = { version = "0.2", optional = true }
|
||||
portaudio-rs = { version = "0.3", 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 }
|
||||
rodio = { version = "0.9", optional = true, default-features = false }
|
||||
cpal = { version = "0.8", optional = true }
|
||||
sdl2 = { version = "0.32", optional = true }
|
||||
gstreamer = { version = "0.15.0", optional = true }
|
||||
gstreamer-app = { version = "0.15.0", optional = true }
|
||||
glib = { version = "0.9.0", optional = true }
|
||||
zerocopy = { version = "0.2.8", optional = true }
|
||||
gstreamer = { version = "0.15", optional = true }
|
||||
gstreamer-app = { version = "0.15", optional = true }
|
||||
glib = { version = "0.9", optional = true }
|
||||
zerocopy = { version = "0.2", optional = true }
|
||||
|
||||
[features]
|
||||
alsa-backend = ["alsa"]
|
||||
|
|
|
@ -1,20 +1,17 @@
|
|||
use super::{Open, Sink};
|
||||
use std::{io, thread, time, process::exit};
|
||||
use std::{io, thread};
|
||||
use std::sync::mpsc::{sync_channel, SyncSender};
|
||||
use gst::prelude::*;
|
||||
use gst::*;
|
||||
use gst_app::*;
|
||||
use glib::MainLoop;
|
||||
use zerocopy::*;
|
||||
|
||||
pub struct GstreamerSink {
|
||||
tx: SyncSender<Vec<u8>>,
|
||||
pipeline: gst::Pipeline
|
||||
tx: SyncSender<Vec<u8>>
|
||||
}
|
||||
|
||||
impl Open for 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_rest = r#" ! audioconvert ! autoaudiosink"#;
|
||||
let pipeline_str : String = match device {
|
||||
|
@ -26,10 +23,10 @@ impl Open for GstreamerSink {
|
|||
gst::init().unwrap();
|
||||
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 mut bus = pipeline.get_bus().expect("Couldn't get bus from pipeline");
|
||||
let mut mainloop = glib::MainLoop::new(None, false);
|
||||
let mut 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 bus = pipeline.get_bus().expect("Couldn't get bus from pipeline");
|
||||
let mainloop = glib::MainLoop::new(None, false);
|
||||
let appsrce : gst::Element = pipeline.get_by_name("appsrc0").expect("Couldn't get appsrc from pipeline");
|
||||
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 appsrc_caps = appsrc.get_caps().expect("get appsrc caps failed");
|
||||
let mut conf = bufferpool.get_config();
|
||||
|
@ -40,49 +37,45 @@ impl Open for GstreamerSink {
|
|||
let (tx, rx) = sync_channel::<Vec<u8>>(128);
|
||||
thread::spawn(move || {
|
||||
for data in rx {
|
||||
let mut buffer = bufferpool.acquire_buffer(None);
|
||||
if(!buffer.is_err()) {
|
||||
let buffer = bufferpool.acquire_buffer(None);
|
||||
if !buffer.is_err() {
|
||||
let mut okbuffer = buffer.unwrap();
|
||||
let mutbuf = okbuffer.make_mut();
|
||||
mutbuf.set_size(data.len());
|
||||
mutbuf.copy_from_slice(0, data.as_bytes());
|
||||
let eat = appsrc.push_buffer(okbuffer);
|
||||
mutbuf.copy_from_slice(0, data.as_bytes()).expect("Failed to copy from slice");
|
||||
let _eat = appsrc.push_buffer(okbuffer);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
thread::spawn(move || {
|
||||
unsafe {
|
||||
let thread_mainloop = mainloop;
|
||||
let watch_mainloop = thread_mainloop.clone();
|
||||
bus.add_watch(move |_, msg| {
|
||||
use gst::MessageView;
|
||||
match msg.view() {
|
||||
MessageView::Eos(..) => watch_mainloop.quit(),
|
||||
MessageView::Error(err) => {
|
||||
println!(
|
||||
"Error from {:?}: {} ({:?})",
|
||||
err.get_src().map(|s| s.get_path_string()),
|
||||
err.get_error(),
|
||||
err.get_debug()
|
||||
);
|
||||
watch_mainloop.quit();
|
||||
}
|
||||
_ => (),
|
||||
};
|
||||
|
||||
glib::Continue(true)
|
||||
})
|
||||
.expect("Failed to add bus watch");
|
||||
thread_mainloop.run();
|
||||
}
|
||||
let thread_mainloop = mainloop;
|
||||
let watch_mainloop = thread_mainloop.clone();
|
||||
bus.add_watch(move |_, msg| {
|
||||
match msg.view() {
|
||||
MessageView::Eos(..) => watch_mainloop.quit(),
|
||||
MessageView::Error(err) => {
|
||||
println!(
|
||||
"Error from {:?}: {} ({:?})",
|
||||
err.get_src().map(|s| s.get_path_string()),
|
||||
err.get_error(),
|
||||
err.get_debug()
|
||||
);
|
||||
watch_mainloop.quit();
|
||||
}
|
||||
_ => (),
|
||||
};
|
||||
|
||||
glib::Continue(true)
|
||||
})
|
||||
.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");
|
||||
|
||||
GstreamerSink {
|
||||
tx: tx,
|
||||
pipeline: pipeline
|
||||
tx: tx
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue