From ad1d78b599ee6f20835e0fcfa54e7a9eac770b49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Sat, 10 Oct 2020 11:00:48 +0300 Subject: [PATCH] examples: Move to Rust 2018 edition --- tutorials/Cargo.toml | 11 +++++---- tutorials/src/bin/basic-tutorial-1.rs | 1 - tutorials/src/bin/basic-tutorial-12.rs | 3 --- tutorials/src/bin/basic-tutorial-2.rs | 2 +- tutorials/src/bin/basic-tutorial-3.rs | 2 +- tutorials/src/bin/basic-tutorial-4.rs | 4 ++-- tutorials/src/bin/basic-tutorial-5.rs | 32 ++++++++++---------------- tutorials/src/bin/basic-tutorial-6.rs | 4 ++-- tutorials/src/bin/basic-tutorial-7.rs | 2 +- tutorials/src/bin/basic-tutorial-8.rs | 11 +++------ tutorials/src/bin/basic-tutorial-9.rs | 4 ---- 11 files changed, 28 insertions(+), 48 deletions(-) diff --git a/tutorials/Cargo.toml b/tutorials/Cargo.toml index be2c3a46b..440b23a00 100644 --- a/tutorials/Cargo.toml +++ b/tutorials/Cargo.toml @@ -3,16 +3,17 @@ name = "tutorials" version = "0.17.0" license = "MIT" authors = ["Sebastian Dröge "] +edition = "2018" [dependencies] glib = { git = "https://github.com/gtk-rs/glib" } gdk = { git = "https://github.com/gtk-rs/gdk", optional = true } gtk = { git = "https://github.com/gtk-rs/gtk", optional = true } -gstreamer = { path = "../gstreamer" } -gstreamer-audio = { path = "../gstreamer-audio" } -gstreamer-video = { path = "../gstreamer-video" } -gstreamer-app = { path = "../gstreamer-app" } -gstreamer-pbutils = { path = "../gstreamer-pbutils" } +gst = { package = "gstreamer", path = "../gstreamer" } +gst-audio = { package = "gstreamer-audio", path = "../gstreamer-audio" } +gst-video = { package = "gstreamer-video", path = "../gstreamer-video" } +gst-app = { package = "gstreamer-app", path = "../gstreamer-app" } +gst-pbutils = { package = "gstreamer-pbutils", path = "../gstreamer-pbutils" } byte-slice-cast = "0.3" anyhow = "1" diff --git a/tutorials/src/bin/basic-tutorial-1.rs b/tutorials/src/bin/basic-tutorial-1.rs index d1e237070..5091fe9e0 100644 --- a/tutorials/src/bin/basic-tutorial-1.rs +++ b/tutorials/src/bin/basic-tutorial-1.rs @@ -1,4 +1,3 @@ -extern crate gstreamer as gst; use gst::prelude::*; #[path = "../tutorials-common.rs"] diff --git a/tutorials/src/bin/basic-tutorial-12.rs b/tutorials/src/bin/basic-tutorial-12.rs index ebfbeb239..5475d053c 100644 --- a/tutorials/src/bin/basic-tutorial-12.rs +++ b/tutorials/src/bin/basic-tutorial-12.rs @@ -1,9 +1,6 @@ -extern crate glib; -extern crate gstreamer as gst; use gst::prelude::*; use std::io::Write; -extern crate anyhow; use anyhow::Error; #[path = "../tutorials-common.rs"] diff --git a/tutorials/src/bin/basic-tutorial-2.rs b/tutorials/src/bin/basic-tutorial-2.rs index 44c1df23e..b7c3b5d93 100644 --- a/tutorials/src/bin/basic-tutorial-2.rs +++ b/tutorials/src/bin/basic-tutorial-2.rs @@ -1,4 +1,3 @@ -extern crate gstreamer as gst; use gst::prelude::*; #[path = "../tutorials-common.rs"] @@ -33,6 +32,7 @@ fn tutorial_main() { let bus = pipeline.get_bus().unwrap(); for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) { use gst::MessageView; + match msg.view() { MessageView::Error(err) => { eprintln!( diff --git a/tutorials/src/bin/basic-tutorial-3.rs b/tutorials/src/bin/basic-tutorial-3.rs index 019618d2c..843110155 100644 --- a/tutorials/src/bin/basic-tutorial-3.rs +++ b/tutorials/src/bin/basic-tutorial-3.rs @@ -1,4 +1,3 @@ -extern crate gstreamer as gst; use gst::prelude::*; #[path = "../tutorials-common.rs"] @@ -85,6 +84,7 @@ fn tutorial_main() { let bus = pipeline.get_bus().unwrap(); for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) { use gst::MessageView; + match msg.view() { MessageView::Error(err) => { eprintln!( diff --git a/tutorials/src/bin/basic-tutorial-4.rs b/tutorials/src/bin/basic-tutorial-4.rs index e992cd523..0a5d7703e 100644 --- a/tutorials/src/bin/basic-tutorial-4.rs +++ b/tutorials/src/bin/basic-tutorial-4.rs @@ -1,6 +1,4 @@ -extern crate gstreamer as gst; use gst::prelude::*; -use gst::MessageView; use std::io; use std::io::Write; @@ -100,6 +98,8 @@ fn tutorial_main() { } fn handle_message(custom_data: &mut CustomData, msg: &gst::Message) { + use gst::MessageView; + match msg.view() { MessageView::Error(err) => { println!( diff --git a/tutorials/src/bin/basic-tutorial-5.rs b/tutorials/src/bin/basic-tutorial-5.rs index 812d79bfa..44f195e5e 100644 --- a/tutorials/src/bin/basic-tutorial-5.rs +++ b/tutorials/src/bin/basic-tutorial-5.rs @@ -3,19 +3,11 @@ mod tutorial5 { use std::os::raw::c_void; use std::process; - extern crate glib; - use self::glib::object::ObjectType; - use self::glib::*; + use gdk::prelude::*; + use gtk::prelude::*; - extern crate gdk; - use self::gdk::prelude::*; - - extern crate gtk; - use self::gtk::*; - - extern crate gstreamer as gst; - extern crate gstreamer_video as gst_video; - use self::gst_video::prelude::*; + use gst::prelude::*; + use gst_video::prelude::*; use std::ops; @@ -24,14 +16,14 @@ mod tutorial5 { // it from the main context again later and drop the // references it keeps inside its closures struct AppWindow { - main_window: Window, + main_window: gtk::Window, timeout_id: Option, } impl ops::Deref for AppWindow { - type Target = Window; + type Target = gtk::Window; - fn deref(&self) -> &Window { + fn deref(&self) -> >k::Window { &self.main_window } } @@ -106,7 +98,7 @@ mod tutorial5 { // This creates all the GTK+ widgets that compose our application, and registers the callbacks fn create_ui(playbin: &gst::Element) -> AppWindow { - let main_window = Window::new(WindowType::Toplevel); + let main_window = gtk::Window::new(gtk::WindowType::Toplevel); main_window.connect_delete_event(|_, _| { gtk::main_quit(); Inhibit(false) @@ -186,13 +178,13 @@ mod tutorial5 { Continue(true) }); - let controls = Box::new(Orientation::Horizontal, 0); + let controls = gtk::Box::new(gtk::Orientation::Horizontal, 0); controls.pack_start(&play_button, false, false, 0); controls.pack_start(&pause_button, false, false, 0); controls.pack_start(&stop_button, false, false, 0); controls.pack_start(&slider, true, true, 2); - let video_window = DrawingArea::new(); + let video_window = gtk::DrawingArea::new(); let video_overlay = playbin .clone() @@ -282,11 +274,11 @@ mod tutorial5 { _ => (), }); - let vbox = Box::new(Orientation::Horizontal, 0); + let vbox = gtk::Box::new(gtk::Orientation::Horizontal, 0); vbox.pack_start(&video_window, true, true, 0); vbox.pack_start(&streams_list, false, false, 2); - let main_box = Box::new(Orientation::Vertical, 0); + let main_box = gtk::Box::new(gtk::Orientation::Vertical, 0); main_box.pack_start(&vbox, true, true, 0); main_box.pack_start(&controls, false, false, 0); main_window.add(&main_box); diff --git a/tutorials/src/bin/basic-tutorial-6.rs b/tutorials/src/bin/basic-tutorial-6.rs index 5e3eea658..f825f79c9 100644 --- a/tutorials/src/bin/basic-tutorial-6.rs +++ b/tutorials/src/bin/basic-tutorial-6.rs @@ -1,6 +1,4 @@ -extern crate gstreamer as gst; use gst::prelude::*; -use gst::MessageView; #[path = "../tutorials-common.rs"] mod tutorials_common; @@ -127,6 +125,8 @@ fn tutorial_main() { let bus = pipeline.get_bus().unwrap(); for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) { + use gst::MessageView; + match msg.view() { MessageView::Error(err) => { println!( diff --git a/tutorials/src/bin/basic-tutorial-7.rs b/tutorials/src/bin/basic-tutorial-7.rs index 5e9ede154..54390adfb 100644 --- a/tutorials/src/bin/basic-tutorial-7.rs +++ b/tutorials/src/bin/basic-tutorial-7.rs @@ -1,4 +1,3 @@ -extern crate gstreamer as gst; use gst::prelude::*; #[path = "../tutorials-common.rs"] @@ -70,6 +69,7 @@ fn tutorial_main() { let bus = pipeline.get_bus().unwrap(); for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) { use gst::MessageView; + match msg.view() { MessageView::Error(err) => { eprintln!( diff --git a/tutorials/src/bin/basic-tutorial-8.rs b/tutorials/src/bin/basic-tutorial-8.rs index 9aa6f3edd..771090e80 100644 --- a/tutorials/src/bin/basic-tutorial-8.rs +++ b/tutorials/src/bin/basic-tutorial-8.rs @@ -1,16 +1,11 @@ use std::sync::{Arc, Mutex}; -extern crate byte_slice_cast; use byte_slice_cast::*; -extern crate gstreamer as gst; -use gst::prelude::*; -extern crate gstreamer_audio as gst_audio; -use gst_audio::AudioInfo; -extern crate gstreamer_app as gst_app; -use gst_app::{AppSink, AppSrc}; -extern crate glib; use glib::source::SourceId; +use gst::prelude::*; +use gst_app::{AppSink, AppSrc}; +use gst_audio::AudioInfo; const CHUNK_SIZE: usize = 1024; // Amount of bytes we are sending in each buffer const SAMPLE_RATE: u32 = 44_100; // Samples per second we are sending diff --git a/tutorials/src/bin/basic-tutorial-9.rs b/tutorials/src/bin/basic-tutorial-9.rs index e9dc9dbb2..558ca2e84 100644 --- a/tutorials/src/bin/basic-tutorial-9.rs +++ b/tutorials/src/bin/basic-tutorial-9.rs @@ -1,9 +1,5 @@ -extern crate anyhow; use anyhow::Error; -extern crate glib; -extern crate gstreamer as gst; -extern crate gstreamer_pbutils as gst_pbutils; use gst_pbutils::{ prelude::*, Discoverer, DiscovererContainerInfo, DiscovererInfo, DiscovererResult, DiscovererStreamInfo,