mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2025-02-20 22:56:20 +00:00
tutorial: Update to 2018 edition
This commit is contained in:
parent
810f27886b
commit
c3cd12d08b
12 changed files with 36 additions and 58 deletions
|
@ -9,10 +9,10 @@ description = "Rust Tutorial Plugin"
|
|||
|
||||
[dependencies]
|
||||
glib = { git = "https://github.com/gtk-rs/gtk-rs" }
|
||||
gstreamer = { git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" }
|
||||
gstreamer-base = { git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" }
|
||||
gstreamer-video = { git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" }
|
||||
gstreamer-audio = { git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" }
|
||||
gst = { package = "gstreamer", git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" }
|
||||
gst-base = { package = "gstreamer-base", git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" }
|
||||
gst-video = { package = "gstreamer-video", git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" }
|
||||
gst-audio = { package = "gstreamer-audio", git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" }
|
||||
byte-slice-cast = "1.0"
|
||||
num-traits = "0.2"
|
||||
once_cell = "1.0"
|
||||
|
|
|
@ -10,6 +10,7 @@ use glib::subclass;
|
|||
use glib::subclass::prelude::*;
|
||||
use gst::prelude::*;
|
||||
use gst::subclass::prelude::*;
|
||||
use gst::{gst_log, gst_trace};
|
||||
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
|
@ -121,7 +122,7 @@ impl ObjectSubclass for Identity {
|
|||
type Class = subclass::simple::ClassStruct<Self>;
|
||||
|
||||
// This macro provides some boilerplate.
|
||||
glib_object_subclass!();
|
||||
glib::glib_object_subclass!();
|
||||
|
||||
// Called when a new instance is to be created. We need to return an instance
|
||||
// of our struct here and also get the class struct passed in case it's needed
|
||||
|
|
|
@ -11,7 +11,7 @@ use glib::prelude::*;
|
|||
mod imp;
|
||||
|
||||
// The public Rust wrapper type for our element
|
||||
glib_wrapper! {
|
||||
glib::glib_wrapper! {
|
||||
pub struct Identity(ObjectSubclass<imp::Identity>) @extends gst::Element, gst::Object;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,14 +6,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#[macro_use]
|
||||
extern crate glib;
|
||||
#[macro_use]
|
||||
extern crate gstreamer as gst;
|
||||
extern crate gstreamer_audio as gst_audio;
|
||||
extern crate gstreamer_base as gst_base;
|
||||
extern crate gstreamer_video as gst_video;
|
||||
|
||||
mod identity;
|
||||
mod progressbin;
|
||||
mod rgb2gray;
|
||||
|
@ -34,7 +26,7 @@ fn plugin_init(plugin: &gst::Plugin) -> Result<(), glib::BoolError> {
|
|||
// Plugin name, plugin description, plugin entry point function, version number of this plugin,
|
||||
// license of the plugin, source package name, binary package name, origin where it comes from
|
||||
// and the date/time of release.
|
||||
gst_plugin_define!(
|
||||
gst::gst_plugin_define!(
|
||||
rstutorial,
|
||||
env!("CARGO_PKG_DESCRIPTION"),
|
||||
plugin_init,
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
use glib::prelude::*;
|
||||
use glib::subclass;
|
||||
use glib::subclass::prelude::*;
|
||||
use gst::gst_info;
|
||||
use gst::prelude::*;
|
||||
use gst::subclass::prelude::*;
|
||||
use std::sync::Mutex;
|
||||
|
@ -63,7 +64,7 @@ impl ObjectSubclass for ProgressBin {
|
|||
type Class = subclass::simple::ClassStruct<Self>;
|
||||
|
||||
// This macro provides some boilerplate.
|
||||
glib_object_subclass!();
|
||||
glib::glib_object_subclass!();
|
||||
|
||||
// Called when a new instance is to be created. We need to return an instance
|
||||
// of our struct here and also get the class struct passed in case it's needed
|
||||
|
|
|
@ -13,7 +13,7 @@ mod imp;
|
|||
// This enum may be used to control what type of output the progressbin should produce.
|
||||
// It also serves the secondary purpose of illustrating how to add enum-type properties
|
||||
// to a plugin written in rust.
|
||||
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy, GEnum)]
|
||||
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy, glib::GEnum)]
|
||||
#[repr(u32)]
|
||||
#[genum(type_name = "GstProgressBinOutput")]
|
||||
pub enum ProgressBinOutput {
|
||||
|
@ -30,7 +30,7 @@ pub enum ProgressBinOutput {
|
|||
}
|
||||
|
||||
// The public Rust wrapper type for our element
|
||||
glib_wrapper! {
|
||||
glib::glib_wrapper! {
|
||||
pub struct ProgressBin(ObjectSubclass<imp::ProgressBin>) @extends gst::Bin, gst::Element, gst::Object;
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ use glib::subclass;
|
|||
use glib::subclass::prelude::*;
|
||||
use gst::prelude::*;
|
||||
use gst::subclass::prelude::*;
|
||||
use gst::{gst_debug, gst_element_error, gst_info, gst_loggable_error};
|
||||
use gst_base::subclass::prelude::*;
|
||||
|
||||
use std::i32;
|
||||
|
@ -121,7 +122,7 @@ impl ObjectSubclass for Rgb2Gray {
|
|||
type Class = subclass::simple::ClassStruct<Self>;
|
||||
|
||||
// This macro provides some boilerplate
|
||||
glib_object_subclass!();
|
||||
glib::glib_object_subclass!();
|
||||
|
||||
// Called when a new instance is to be created. We need to return an instance
|
||||
// of our struct here.
|
||||
|
|
|
@ -11,7 +11,7 @@ use glib::prelude::*;
|
|||
mod imp;
|
||||
|
||||
// The public Rust wrapper type for our element
|
||||
glib_wrapper! {
|
||||
glib::glib_wrapper! {
|
||||
pub struct Rgb2Gray(ObjectSubclass<imp::Rgb2Gray>) @extends gst_base::BaseTransform, gst::Element, gst::Object;
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ use glib::subclass;
|
|||
use glib::subclass::prelude::*;
|
||||
use gst::prelude::*;
|
||||
use gst::subclass::prelude::*;
|
||||
use gst::{gst_debug, gst_element_error, gst_error, gst_info, gst_log, gst_loggable_error};
|
||||
use gst_base::prelude::*;
|
||||
use gst_base::subclass::prelude::*;
|
||||
|
||||
|
@ -206,7 +207,7 @@ impl ObjectSubclass for SineSrc {
|
|||
type Class = subclass::simple::ClassStruct<Self>;
|
||||
|
||||
// This macro provides some boilerplate.
|
||||
glib_object_subclass!();
|
||||
glib::glib_object_subclass!();
|
||||
|
||||
// Called when a new instance is to be created. We need to return an instance
|
||||
// of our struct here.
|
||||
|
|
|
@ -11,7 +11,7 @@ use glib::prelude::*;
|
|||
mod imp;
|
||||
|
||||
// The public Rust wrapper type for our element
|
||||
glib_wrapper! {
|
||||
glib::glib_wrapper! {
|
||||
pub struct SineSrc(ObjectSubclass<imp::SineSrc>) @extends gst_base::BaseSrc, gst::Element, gst::Object;
|
||||
}
|
||||
|
||||
|
|
|
@ -42,9 +42,9 @@ description = "Rust Tutorial Plugin"
|
|||
|
||||
[dependencies]
|
||||
glib = { git = "https://github.com/gtk-rs/glib" }
|
||||
gstreamer = { git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" }
|
||||
gstreamer-base = { git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" }
|
||||
gstreamer-video = { git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" }
|
||||
gst = { package = "gstreamer", git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" }
|
||||
gst-base = { package = "gstreamer-base", git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" }
|
||||
gst-video = { package = "gstreamer-video", git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" }
|
||||
once_cell = "1.0"
|
||||
|
||||
[lib]
|
||||
|
@ -70,22 +70,12 @@ If you now run the `gst-inspect-1.0` tool on the `libgstrstutorial.so`, it will
|
|||
|
||||
## Plugin Initialization
|
||||
|
||||
Let’s start editing `src/lib.rs` to make this an actual GStreamer plugin. First of all, we need to add various extern crate directives to be able to use our dependencies and also mark some of them `#[macro_use]` because we’re going to use `macros` defined in some of them. This looks like the following
|
||||
|
||||
```
|
||||
#[macro_use]
|
||||
extern crate glib;
|
||||
#[macro_use]
|
||||
extern crate gstreamer as gst;
|
||||
extern crate gstreamer_base as gst_base;
|
||||
extern crate gstreamer_video as gst_video;
|
||||
extern crate once_cell;
|
||||
```
|
||||
Let’s start editing `src/lib.rs` to make this an actual GStreamer plugin.
|
||||
|
||||
Next we make use of the `gst_plugin_define!` `macro` from the `gstreamer` crate to set-up the static metadata of the plugin (and make the shared library recognizeable by GStreamer to be a valid plugin), and to define the name of our entry point function (`plugin_init`) where we will register all the elements that this plugin provides.
|
||||
|
||||
```rust
|
||||
gst_plugin_define!(
|
||||
gst::gst_plugin_define!(
|
||||
rstutorial,
|
||||
env!("CARGO_PKG_DESCRIPTION"),
|
||||
plugin_init,
|
||||
|
@ -115,8 +105,6 @@ The static plugin metadata that we provide here is
|
|||
Next we create `build.rs` in the project main directory.
|
||||
|
||||
```rust
|
||||
extern crate gst_plugin_version_helper;
|
||||
|
||||
fn main() {
|
||||
gst_plugin_version_helper::get_info()
|
||||
}
|
||||
|
@ -153,19 +141,16 @@ fn plugin_init(plugin: &gst::Plugin) -> Result<(), glib::BoolError> {
|
|||
}
|
||||
```
|
||||
|
||||
With that our `src/lib.rs` is complete, and all following code is only in `src/rgb2gray/imp.rs`. At the top of the new file we first need to add various `use-directives` to import various types and functions we’re going to use into the current module’s scope.
|
||||
With that our `src/lib.rs` is complete, and all following code is only in `src/rgb2gray/imp.rs`. At the top of the new file we first need to add various `use-directives` to import various types, macros and functions we’re going to use into the current module’s scope.
|
||||
|
||||
```rust
|
||||
use glib;
|
||||
use glib::subclass;
|
||||
use glib::subclass::prelude::*;
|
||||
|
||||
use gst;
|
||||
use gst::prelude::*;
|
||||
use gst::subclass::prelude::*;
|
||||
use gst_base;
|
||||
use gst::{gst_debug, gst_element_error, gst_info, gst_loggable_error};
|
||||
use gst_base::subclass::prelude::*;
|
||||
use gst_video;
|
||||
|
||||
use std::i32;
|
||||
use std::sync::Mutex;
|
||||
|
@ -190,7 +175,7 @@ impl ObjectSubclass for Rgb2Gray {
|
|||
type Class = subclass::simple::ClassStruct<Self>;
|
||||
|
||||
// This macro provides some boilerplate
|
||||
glib_object_subclass!();
|
||||
glib::glib_object_subclass!();
|
||||
|
||||
fn new() -> Self {
|
||||
Self {}
|
||||
|
@ -213,7 +198,7 @@ use glib::prelude::*;
|
|||
mod imp;
|
||||
|
||||
// The public Rust wrapper type for our element
|
||||
glib_wrapper! {
|
||||
glib::glib_wrapper! {
|
||||
pub struct Rgb2Gray(ObjectSubclass<imp::Rgb2Gray>) @extends gst_base::BaseTransform, gst::Element, gst::Object;
|
||||
}
|
||||
|
||||
|
@ -305,7 +290,7 @@ impl ObjectSubclass for Rgb2Gray {
|
|||
type Instance = gst::subclass::ElementInstanceStruct<Self>;
|
||||
type Class = subclass::simple::ClassStruct<Self>;
|
||||
|
||||
glib_object_subclass!();
|
||||
glib::glib_object_subclass!();
|
||||
}
|
||||
|
||||
impl ObjectImpl for Rgb2Gray {}
|
||||
|
@ -320,7 +305,7 @@ use glib::prelude::*;
|
|||
|
||||
mod imp;
|
||||
|
||||
glib_wrapper! {
|
||||
glib::glib_wrapper! {
|
||||
pub struct Rgb2Gray(ObjectSubclass<imp::Rgb2Gray>) @extends gst_base::BaseTransform, gst::Element, gst::Object;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,19 +22,16 @@ So let's get started with all the boilerplate. This time our element will be bas
|
|||
In `src/sinesrc/imp.rs`:
|
||||
|
||||
```rust
|
||||
use glib;
|
||||
use gst;
|
||||
use glib::prelude::*;
|
||||
use glib::subclass::prelude::*;
|
||||
use gst::prelude::*;
|
||||
use gst::subclass::prelude::*;
|
||||
use gst::{gst_debug, gst_element_error, gst_error, gst_info, gst_log, gst_loggable_error};
|
||||
use gst_base::prelude::*;
|
||||
use gst_audio;
|
||||
use gst_base::subclass::prelude::*;
|
||||
|
||||
use byte_slice_cast::*;
|
||||
|
||||
use gst_plugin::properties::*;
|
||||
use gst_plugin::object::*;
|
||||
use gst_plugin::element::*;
|
||||
use gst_plugin::base_src::*;
|
||||
|
||||
use std::{i32, u32};
|
||||
use std::sync::Mutex;
|
||||
use std::ops::Rem;
|
||||
|
@ -157,7 +154,7 @@ impl ObjectSubclass for SineSrc {
|
|||
type Class = subclass::simple::ClassStruct<Self>;
|
||||
|
||||
// This macro provides some boilerplate.
|
||||
glib_object_subclass!();
|
||||
glib::glib_object_subclass!();
|
||||
|
||||
// Called when a new instance is to be created. We need to return an instance
|
||||
// of our struct here.
|
||||
|
@ -383,7 +380,7 @@ use glib::prelude::*;
|
|||
mod imp;
|
||||
|
||||
// The public Rust wrapper type for our element
|
||||
glib_wrapper! {
|
||||
glib::glib_wrapper! {
|
||||
pub struct SineSrc(ObjectSubclass<imp::SineSrc>) @extends gst_base::BaseSrc, gst::Element, gst::Object;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue