A complete program that can play back a file
This commit is contained in:
parent
ee56513299
commit
04a6e607a3
|
@ -1,49 +1,103 @@
|
|||
use gstreamer::prelude::*;
|
||||
use gstreamer::{prelude::*, Element, Pad};
|
||||
use pipewire::{context::Context, main_loop::MainLoop};
|
||||
|
||||
fn main() {
|
||||
gstreamer::init();
|
||||
|
||||
// let srcfactory = gstreamer::ElementFactory::find("filesrc").unwrap().load().unwrap();
|
||||
let srcfactory = gstreamer::ElementFactory::find("videotestsrc")
|
||||
let source = gstreamer::ElementFactory::find("filesrc")
|
||||
.unwrap()
|
||||
.load()
|
||||
.unwrap()
|
||||
.create()
|
||||
.name("source")
|
||||
.property(
|
||||
"location",
|
||||
"/home/savanni/Music/tavern-music.ogg",
|
||||
)
|
||||
// .property(
|
||||
// "location",
|
||||
// "/home/savanni/Music/Night at Work _ Instrumental Chill Music Mix [n9Y2Eb4BaSg].m4a",
|
||||
// )
|
||||
.build()
|
||||
.unwrap();
|
||||
let sinkfactory = gstreamer::ElementFactory::find("autovideosink")
|
||||
let decoder = gstreamer::ElementFactory::find("decodebin")
|
||||
.unwrap()
|
||||
.load()
|
||||
.unwrap()
|
||||
.create()
|
||||
.name("decoder")
|
||||
.build()
|
||||
.unwrap();
|
||||
let video_effect = gstreamer::ElementFactory::find("vertigotv")
|
||||
let sink = gstreamer::ElementFactory::find("autoaudiosink")
|
||||
.unwrap()
|
||||
.load()
|
||||
.unwrap()
|
||||
.create()
|
||||
.name("sink")
|
||||
.build()
|
||||
.unwrap();
|
||||
let convert = gstreamer::ElementFactory::find("audioconvert")
|
||||
.unwrap()
|
||||
.load()
|
||||
.unwrap()
|
||||
.create()
|
||||
.name("convert")
|
||||
.build()
|
||||
.unwrap();
|
||||
let resample = gstreamer::ElementFactory::find("audioresample")
|
||||
.unwrap()
|
||||
.load()
|
||||
.unwrap()
|
||||
.create()
|
||||
.name("resample")
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
println!("source factory type: {:?}", srcfactory.element_type());
|
||||
println!("sink factory type: {:?}", sinkfactory.element_type());
|
||||
println!("video factory type: {:?}", video_effect.element_type());
|
||||
|
||||
let source = srcfactory.create().name("source").build().unwrap();
|
||||
let sink = sinkfactory.create().name("sink").build().unwrap();
|
||||
let filter = video_effect.create().name("filter").build().unwrap();
|
||||
|
||||
// let source = gstreamer::ElementFactory::make("videotestsrc");
|
||||
// let sink = gstreamer::ElementFactory::make("autovideosink");
|
||||
let pipeline = gstreamer::Pipeline::new();
|
||||
pipeline.add(&source).unwrap();
|
||||
pipeline.add(&sink).unwrap();
|
||||
pipeline.add(&filter).unwrap();
|
||||
source.link(&filter).unwrap();
|
||||
filter.link(&sink).unwrap();
|
||||
pipeline.add(&decoder).unwrap();
|
||||
pipeline.add(&convert).unwrap();
|
||||
pipeline.add(&resample).unwrap();
|
||||
|
||||
source.link(&decoder).unwrap();
|
||||
convert.link(&resample).unwrap();
|
||||
resample.link(&sink).unwrap();
|
||||
|
||||
decoder.connect_pad_added(move |element, pad| handle_pad_added(element, pad, &convert));
|
||||
|
||||
/*
|
||||
println!("source: {:?}", source);
|
||||
source.foreach_pad(|_, pad| {
|
||||
println!("\tpad: {:?} {}, {:?}", pad, pad.name(), pad.direction());
|
||||
true
|
||||
});
|
||||
let source_pad = source.get_pad(pad.name());
|
||||
source_pad
|
||||
*/
|
||||
|
||||
// source.connect_pad_added(handle_pad_added);
|
||||
// source.link(&convert).unwrap();
|
||||
|
||||
pipeline.set_state(gstreamer::State::Playing).unwrap();
|
||||
|
||||
let bus = pipeline.bus().unwrap();
|
||||
let msg = bus.timed_pop_filtered(
|
||||
gstreamer::ClockTime::NONE,
|
||||
&[gstreamer::MessageType::Error, gstreamer::MessageType::Eos],
|
||||
);
|
||||
|
||||
// let msg = bus.timed_pop_filtered(
|
||||
// gstreamer::ClockTime::NONE,
|
||||
// &[gstreamer::MessageType::Error, gstreamer::MessageType::Eos],
|
||||
// );
|
||||
while let Some(msg) = bus.timed_pop(gstreamer::ClockTime::NONE) {
|
||||
println!("message: {:?}", msg);
|
||||
}
|
||||
|
||||
pipeline.set_state(gstreamer::State::Null);
|
||||
pipeline.set_state(gstreamer::State::Null).unwrap();
|
||||
}
|
||||
|
||||
fn handle_pad_added(element: &Element, pad: &Pad, converter: &Element) {
|
||||
println!("handle_pad_added");
|
||||
println!("\t{:?}", element);
|
||||
println!("\t{:?}, {:?}", pad, pad.current_caps());
|
||||
let converter_pad = converter.static_pad("sink").unwrap();
|
||||
pad.link(&converter_pad).unwrap();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue