examples: use Cargo.toml required-features

This lets us avoid #ifdef forests
This commit is contained in:
Mathieu Duponchelle 2018-02-26 17:47:08 +01:00 committed by Sebastian Dröge
parent 45bb8fe3e0
commit ab0df6ddf0
6 changed files with 62 additions and 85 deletions

View file

@ -34,3 +34,65 @@ v1_10 = ["gstreamer/v1_10"]
[badges]
travis-ci = { repository = "sdroege/gstreamer-rs", branch = "master" }
[[bin]]
name = "appsink"
[[bin]]
name = "appsrc"
[[bin]]
name = "decodebin"
[[bin]]
name = "events"
[[bin]]
name = "gtksink"
required-features = ["gtksink"]
[[bin]]
name = "gtkvideooverlay"
required-features = ["gtkvideooverlay"]
[[bin]]
name = "iterator"
[[bin]]
name = "launch_glib_main"
[[bin]]
name = "launch"
[[bin]]
name = "pad_probes"
[[bin]]
name = "playbin"
[[bin]]
name = "player"
required-features = ["gst-player"]
[[bin]]
name = "queries"
[[bin]]
name = "rtpfecclient"
[[bin]]
name = "rtpfecserver"
[[bin]]
name = "rtsp-server"
required-features = ["gst-rtsp-server"]
[[bin]]
name = "tagsetter"
[[bin]]
name = "toc"
[[bin]]
name = "tokio"
required-features = ["tokio"]

View file

@ -1,30 +1,19 @@
#[cfg(feature = "gtksink")]
extern crate gstreamer as gst;
#[cfg(feature = "gtksink")]
use gst::prelude::*;
#[cfg(feature = "gtksink")]
extern crate glib;
#[cfg(feature = "gtksink")]
extern crate gio;
#[cfg(feature = "gtksink")]
use gio::prelude::*;
#[cfg(feature = "gtksink")]
extern crate gtk;
#[cfg(feature = "gtksink")]
use gtk::prelude::*;
#[cfg(feature = "gtksink")]
use std::env;
#[cfg(feature = "gtksink")]
extern crate send_cell;
#[cfg(feature = "gtksink")]
use send_cell::SendCell;
#[cfg(feature = "gtksink")]
fn create_ui(app: &gtk::Application) {
let pipeline = gst::Pipeline::new(None);
let src = gst::ElementFactory::make("videotestsrc", None).unwrap();
@ -109,7 +98,6 @@ fn create_ui(app: &gtk::Application) {
});
}
#[cfg(feature = "gtksink")]
fn main() {
gst::init().unwrap();
gtk::init().unwrap();
@ -120,8 +108,3 @@ fn main() {
let args = env::args().collect::<Vec<_>>();
app.run(&args);
}
#[cfg(not(feature = "gtksink"))]
fn main() {
println!("Please compile with --feature gtksink");
}

View file

@ -1,48 +1,30 @@
#[cfg(feature = "gtkvideooverlay")]
extern crate gstreamer as gst;
#[cfg(feature = "gtkvideooverlay")]
use gst::prelude::*;
#[cfg(feature = "gtkvideooverlay")]
extern crate gstreamer_video as gst_video;
#[cfg(feature = "gtkvideooverlay")]
use gst_video::prelude::*;
#[cfg(feature = "gtkvideooverlay")]
extern crate glib;
#[cfg(feature = "gtkvideooverlay")]
use glib::translate::ToGlibPtr;
#[cfg(feature = "gtkvideooverlay")]
extern crate gio;
#[cfg(feature = "gtkvideooverlay")]
use gio::prelude::*;
#[cfg(feature = "gtkvideooverlay")]
extern crate gtk;
#[cfg(feature = "gtkvideooverlay")]
use gtk::prelude::*;
#[cfg(feature = "gtkvideooverlay")]
extern crate gdk;
#[cfg(feature = "gtkvideooverlay")]
use gdk::prelude::*;
#[cfg(feature = "gtkvideooverlay")]
use std::env;
#[cfg(feature = "gtkvideooverlay")]
use std::os::raw::c_void;
#[cfg(feature = "gtkvideooverlay")]
extern crate send_cell;
#[cfg(feature = "gtkvideooverlay")]
use send_cell::SendCell;
#[cfg(feature = "gtkvideooverlay")]
use std::process;
#[cfg(feature = "gtkvideooverlay")]
fn create_ui(app: &gtk::Application) {
let pipeline = gst::Pipeline::new(None);
let src = gst::ElementFactory::make("videotestsrc", None).unwrap();
@ -179,7 +161,6 @@ fn create_ui(app: &gtk::Application) {
});
}
#[cfg(feature = "gtkvideooverlay")]
fn main() {
#[cfg(not(unix))]
{
@ -196,8 +177,3 @@ fn main() {
let args = env::args().collect::<Vec<_>>();
app.run(&args);
}
#[cfg(not(feature = "gtkvideooverlay"))]
fn main() {
println!("Please compile with --feature gtkvideooverlay");
}

View file

@ -1,15 +1,11 @@
extern crate gstreamer as gst;
#[cfg(feature = "gst-player")]
use gst::prelude::*;
#[cfg(feature = "gst-player")]
extern crate gstreamer_player as gst_player;
#[cfg(feature = "gst-player")]
extern crate glib;
use std::env;
#[cfg(feature = "gst-player")]
use std::sync::{Arc, Mutex};
extern crate failure;
@ -21,7 +17,6 @@ use failure::Error;
#[path = "../examples-common.rs"]
mod examples_common;
#[cfg(feature = "gst-player")]
fn main_loop(uri: &str) -> Result<(), Error> {
gst::init()?;
@ -78,13 +73,6 @@ fn example_main() {
std::process::exit(-1)
};
#[cfg(not(feature = "gst-player"))]
{
eprintln!("Feature gst-player is required. Please rebuild with --features gst-player");
std::process::exit(-1)
}
#[cfg(feature = "gst-player")]
match main_loop(uri) {
Ok(r) => r,
Err(e) => eprintln!("Error! {}", e),

View file

@ -1,11 +1,8 @@
#[cfg(feature = "gst-rtsp-server")]
use std::env;
extern crate gstreamer as gst;
#[cfg(feature = "gst-rtsp-server")]
extern crate gstreamer_rtsp_server as gst_rtsp_server;
#[cfg(feature = "gst-rtsp-server")]
use gst_rtsp_server::prelude::*;
extern crate glib;
@ -13,7 +10,6 @@ extern crate glib;
extern crate failure;
use failure::Error;
#[cfg(feature = "gst-rtsp-server")]
#[macro_use]
extern crate failure_derive;
@ -22,15 +18,12 @@ mod examples_common;
#[derive(Debug, Fail)]
#[fail(display = "Could not get mount points")]
#[cfg(feature = "gst-rtsp-server")]
struct NoMountPoints;
#[derive(Debug, Fail)]
#[fail(display = "Usage: {} LAUNCH_LINE", _0)]
#[cfg(feature = "gst-rtsp-server")]
struct UsageError(String);
#[cfg(feature = "gst-rtsp-server")]
fn main_loop() -> Result<(), Error> {
let args: Vec<_> = env::args().collect();
@ -62,16 +55,6 @@ fn main_loop() -> Result<(), Error> {
fn example_main() -> Result<(), Error> {
gst::init()?;
#[cfg(not(feature = "gst-rtsp-server"))]
{
eprintln!(
"Feature gst-rtsp-server is required. Please rebuild with --features gst-rtsp-server"
);
std::process::exit(-1)
}
#[cfg(feature = "gst-rtsp-server")]
main_loop()
}

View file

@ -1,25 +1,16 @@
#[cfg(feature = "tokio")]
extern crate gstreamer as gst;
#[cfg(feature = "tokio")]
use gst::prelude::*;
#[cfg(feature = "tokio")]
extern crate futures;
#[cfg(feature = "tokio")]
use futures::stream::Stream;
#[cfg(feature = "tokio")]
extern crate tokio_core;
#[cfg(feature = "tokio")]
use tokio_core::reactor::Core;
#[cfg(feature = "tokio")]
use std::env;
#[cfg(feature = "tokio")]
#[path = "../examples-common.rs"]
mod examples_common;
#[cfg(feature = "tokio")]
fn example_main() {
let pipeline_str = env::args().collect::<Vec<String>>()[1..].join(" ");
@ -63,14 +54,8 @@ fn example_main() {
assert_ne!(ret, gst::StateChangeReturn::Failure);
}
#[cfg(feature = "tokio")]
fn main() {
// tutorials_common::run is only required to set up the application environent on macOS
// (but not necessary in normal Cocoa applications where this is set up autmatically)
examples_common::run(example_main);
}
#[cfg(not(feature = "tokio"))]
fn main() {
println!("Please compile with --features tokio");
}