Commit 33295b75 authored by Sebastian Dröge's avatar Sebastian Dröge 🍵

Add initial version of gstreamer-check

Covers GstHarness and GstTestClock

Fixes https://github.com/sdroege/gstreamer-rs/issues/148
parent 5b75f11c
......@@ -13,6 +13,7 @@ members = [
"gstreamer-video",
"gstreamer-pbutils",
"gstreamer-webrtc",
"gstreamer-check",
"examples",
"tutorials",
]
......@@ -16,7 +16,6 @@ external_libraries = [
]
generate = [
"GstCheck.TestClock",
]
manual = [
......@@ -31,3 +30,8 @@ manual = [
name = "Gst.ClockTime"
status = "manual"
conversion_type = "scalar"
[[object]]
name = "GstCheck.TestClock"
status = "generate"
trait = false
[package]
name = "gstreamer-check"
version = "0.13.0"
authors = ["Sebastian Dröge <sebastian@centricular.com>"]
categories = ["api-bindings", "multimedia"]
description = "Rust bindings for GStreamer Check library"
repository = "https://github.com/sdroege/gstreamer-rs"
license = "MIT/Apache-2.0"
readme = "README.md"
homepage = "https://gstreamer.freedesktop.org"
documentation = "https://sdroege.github.io/rustdoc/gstreamer/gstreamer_check"
keywords = ["gstreamer", "multimedia", "audio", "video", "gnome"]
build = "build.rs"
[dependencies]
bitflags = "1.0"
glib-sys = { git = "https://github.com/gtk-rs/sys" }
gobject-sys = { git = "https://github.com/gtk-rs/sys" }
gstreamer-sys = { git = "https://github.com/sdroege/gstreamer-sys", features = ["v1_8"] }
gstreamer-check-sys = { git = "https://github.com/sdroege/gstreamer-sys", features = ["v1_8"] }
glib = { git = "https://github.com/gtk-rs/glib" }
gstreamer = { path = "../gstreamer" }
[build-dependencies.rustdoc-stripper]
version = "0.1"
optional = true
[features]
v1_10 = ["gstreamer-sys/v1_10", "gstreamer-check-sys/v1_10"]
v1_12 = ["gstreamer-sys/v1_12", "gstreamer-check-sys/v1_12", "v1_10"]
v1_14 = ["gstreamer-sys/v1_14", "gstreamer-check-sys/v1_14", "v1_12"]
#v1_16 = ["gstreamer-sys/v1_16", "gstreamer-check-sys/v1_16", "v1_14"]
embed-lgpl-docs = ["rustdoc-stripper"]
purge-lgpl-docs = ["rustdoc-stripper"]
dox = ["gstreamer-check-sys/dox", "glib/dox", "gstreamer/dox"]
default-features = []
[badges]
travis-ci = { repository = "sdroege/gstreamer-rs", branch = "master" }
This diff is collapsed.
Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the
Software without restriction, including without
limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice
shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
# gstreamer-rs [![crates.io](https://img.shields.io/crates/v/gstreamer-app.svg)](https://crates.io/crates/gstreamer-app) [![Build Status](https://travis-ci.org/sdroege/gstreamer-rs.svg?branch=master)](https://travis-ci.org/sdroege/gstreamer-rs)
[GStreamer](https://gstreamer.freedesktop.org/) (Check library) bindings for Rust.
Documentation can be found [here](https://sdroege.github.io/rustdoc/gstreamer/gstreamer/).
These bindings are providing a safe API that can be used to interface with
GStreamer, e.g. for writing GStreamer-based applications.
For background and motivation, see the [announcement blogpost](https://coaxion.net/blog/2017/07/writing-gstreamer-applications-in-rust/).
The bindings (since 0.8.0) are autogenerated with [gir](https://github.com/gtk-rs/gir/)
based on the [GObject-Introspection](https://wiki.gnome.org/Projects/GObjectIntrospection/)
API metadata provided by the GStreamer project. Older versions before 0.8.0 were manually
written and the repository can be found [here](https://github.com/arturoc/gstreamer1.0-rs).
The API of the two is incompatible.
A crate for writing GStreamer plugins in Rust can be found here: https://github.com/sdroege/gst-plugin-rs
## Table of Contents
1. [Installation](#installation)
1. [Linux/BSDs](#installation-linux)
1. [macOS](#installation-macos)
1. [Windows](#installation-windows)
1. [Getting Started](#getting-started)
1. [License](#license)
1. [Contribution](#contribution)
<a name="installation"/>
## Installation
To build the GStreamer bindings or anything depending on them, you need to
have at least GStreamer 1.8 and gst-plugins-base 1.8 installed. In addition,
some of the examples/tutorials require various GStreamer plugins to be
available, which can be found in gst-plugins-base, gst-plugins-good,
gst-plugins-bad, gst-plugins-ugly and/or gst-libav.
<a name="installation-linux"/>
### Linux/BSDs
You need to install the above mentioned packages with your distributions
package manager, or build them from source.
On Debian/Ubuntu they can be installed with
```
$ apt-get install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev \
gstreamer1.0-plugins-base gstreamer1.0-plugins-good \
gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly \
gstreamer1.0-libav
```
Package names on other distributions should be similar.
Please submit a pull request with instructions for yours.
<a name="installation-macos"/>
### macOS
You can install GStreamer and the plugins via [Homebrew](https://brew.sh/) or
by installing the [binaries](https://gstreamer.freedesktop.org/data/pkg/osx/)
provided by the GStreamer project.
#### Homebrew
```
$ brew install gstreamer gst-plugins-base gst-plugins-good \
gst-plugins-bad gst-plugins-ugly gst-libav
```
#### GStreamer Binaries
You need to download the *two* `.pkg` files from the GStreamer website and
install them, e.g. `gstreamer-1.0-1.12.3-x86_64.pkg` and
`gstreamer-1.0-devel-1.12.3-x86_64.pkg`.
After installation, you also need to install `pkg-config` (e.g. via Homebrew)
and set the `PKG_CONFIG_PATH` environment variable
```
$ export PKG_CONFIG_PATH="/Frameworks/GStreamer.framework/Versions/Current/lib/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}"
```
<a name="installation-windows"/>
### Windows
You can install GStreamer and the plugins via [MSYS2](http://www.msys2.org/)
with `pacman` or by installing the
[binaries](https://gstreamer.freedesktop.org/data/pkg/windows/) provided by
the GStreamer project.
#### MSYS2 / pacman
```
$ pacman -S pkg-config mingw-w64-x86_64-gstreamer mingw-w64-x86_64-gst-plugins-base \
mingw-w64-x86_64-gst-plugins-good mingw-w64-x86_64-gst-plugins-bad \
mingw-w64-x86_64-gst-plugins-ugly mingw-w64-x86_64-gst-libav
```
#### GStreamer Binaries
You need to download the *two* `.msi` files for your platform from the
GStreamer website and install them, e.g. `gstreamer-1.0-x86_64-1.12.3.msi` and
`gstreamer-1.0-devel-x86_64-1.12.3.msi`.
After installation, you also need to install `pkg-config` (e.g. via MSYS2 or
from [here](https://sourceforge.net/projects/pkgconfiglite/))
and set the `PKG_CONFIG_PATH` environment variable
```
$ export PKG_CONFIG_PATH="c:\\gstreamer\\1.0\\x86_64\\lib\\pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}"
```
<a name="getting-started"/>
## Getting Started
The API reference can be found
[here](https://sdroege.github.io/rustdoc/gstreamer/gstreamer/), however it is
only the Rust API reference and does not explain any of the concepts.
For getting started with GStreamer development, the best would be to follow
the [documentation](https://gstreamer.freedesktop.org/documentation/) on the
GStreamer website, especially the [Application Development
Manual](https://gstreamer.freedesktop.org/documentation/application-development/).
While being C-centric, it explains all the fundamental concepts of GStreamer
and the code examples should be relatively easily translatable to Rust. The
API is basically the same, function/struct names are the same and everything
is only more convenient (hopefully) and safer.
In addition there are
[tutorials](https://gstreamer.freedesktop.org/documentation/tutorials/) on the
GStreamer website. Many of them were ported to Rust already and the code can
be found in the
[tutorials](https://github.com/sdroege/gstreamer-rs/tree/master/tutorials)
directory.
Some further examples for various aspects of GStreamer and how to use it from
Rust can be found in the
[examples](https://github.com/sdroege/gstreamer-rs/tree/master/examples)
directory.
<a name="license"/>
## LICENSE
gstreamer-rs and all crates contained in here are licensed under either of
* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
http://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT](LICENSE-MIT) or
http://opensource.org/licenses/MIT)
at your option.
GStreamer itself is licensed under the Lesser General Public License version
2.1 or (at your option) any later version:
https://www.gnu.org/licenses/lgpl-2.1.html
<a name="contribution"/>
## Contribution
Any kinds of contributions are welcome as a pull request.
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in gstreamer-rs by you, as defined in the Apache-2.0 license, shall be
dual licensed as above, without any additional terms or conditions.
fn main() {
manage_docs();
}
#[cfg(any(feature = "embed-lgpl-docs", feature = "purge-lgpl-docs"))]
fn manage_docs() {
extern crate stripper_lib;
use std::io;
let path = "src";
let ignores: &[&str] = &[];
stripper_lib::loop_over_files(
path.as_ref(),
&mut |w, s| stripper_lib::strip_comments(w, s, &mut io::sink(), true),
&ignores,
false,
);
#[cfg(feature = "embed-lgpl-docs")]
{
let docs = include_str!("../docs/gstreamer-check/docs.md");
let mut infos = stripper_lib::parse_cmts(docs.lines(), true);
stripper_lib::loop_over_files(
path.as_ref(),
&mut |w, s| stripper_lib::regenerate_comments(w, s, &mut infos, true, true),
&ignores,
false,
);
}
}
#[cfg(not(any(feature = "embed-lgpl-docs", feature = "purge-lgpl-docs")))]
fn manage_docs() {}
......@@ -4,9 +4,7 @@
mod test_clock;
pub use self::test_clock::TestClock;
pub use self::test_clock::TestClockExt;
#[doc(hidden)]
pub mod traits {
pub use super::TestClockExt;
}
......@@ -3,11 +3,9 @@
// DO NOT EDIT
use ffi;
use glib;
use glib::StaticType;
use glib::Value;
use glib::object::Downcast;
use glib::object::IsA;
use glib::signal::SignalHandlerId;
use glib::signal::connect;
use glib::translate::*;
......@@ -46,116 +44,67 @@ impl TestClock {
}
}
//pub fn id_list_get_latest_time(pending_list: /*Ignored*/&[&gst::ClockID]) -> gst::ClockTime {
// unsafe { TODO: call ffi::gst_test_clock_id_list_get_latest_time() }
//}
}
impl Default for TestClock {
fn default() -> Self {
Self::new()
}
}
unsafe impl Send for TestClock {}
unsafe impl Sync for TestClock {}
pub trait TestClockExt {
fn advance_time(&self, delta: gst::ClockTimeDiff);
fn crank(&self) -> bool;
fn get_next_entry_time(&self) -> gst::ClockTime;
//fn has_id(&self, id: /*Ignored*/gst::ClockID) -> bool;
fn peek_id_count(&self) -> u32;
//fn peek_next_pending_id(&self, pending_id: /*Ignored*/&mut gst::ClockID) -> bool;
//fn process_id_list(&self, pending_list: /*Ignored*/&[&gst::ClockID]) -> u32;
//fn process_next_clock_id(&self) -> /*Ignored*/Option<gst::ClockID>;
fn set_time(&self, new_time: gst::ClockTime);
//fn wait_for_multiple_pending_ids(&self, count: u32, pending_list: /*Unimplemented*/Vec<gst::ClockID>);
//fn wait_for_next_pending_id(&self, pending_id: /*Ignored*/&mut gst::ClockID);
fn wait_for_pending_id_count(&self, count: u32);
fn get_property_clock_type(&self) -> gst::ClockType;
fn set_property_clock_type(&self, clock_type: gst::ClockType);
fn get_property_start_time(&self) -> u64;
fn connect_property_clock_type_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId;
}
impl<O: IsA<TestClock> + IsA<glib::object::Object>> TestClockExt for O {
fn advance_time(&self, delta: gst::ClockTimeDiff) {
pub fn advance_time(&self, delta: gst::ClockTimeDiff) {
unsafe {
ffi::gst_test_clock_advance_time(self.to_glib_none().0, delta);
}
}
fn crank(&self) -> bool {
pub fn crank(&self) -> bool {
unsafe {
from_glib(ffi::gst_test_clock_crank(self.to_glib_none().0))
}
}
fn get_next_entry_time(&self) -> gst::ClockTime {
pub fn get_next_entry_time(&self) -> gst::ClockTime {
unsafe {
from_glib(ffi::gst_test_clock_get_next_entry_time(self.to_glib_none().0))
}
}
//fn has_id(&self, id: /*Ignored*/gst::ClockID) -> bool {
//pub fn has_id(&self, id: /*Ignored*/gst::ClockID) -> bool {
// unsafe { TODO: call ffi::gst_test_clock_has_id() }
//}
fn peek_id_count(&self) -> u32 {
pub fn peek_id_count(&self) -> u32 {
unsafe {
ffi::gst_test_clock_peek_id_count(self.to_glib_none().0)
}
}
//fn peek_next_pending_id(&self, pending_id: /*Ignored*/&mut gst::ClockID) -> bool {
//pub fn peek_next_pending_id(&self, pending_id: /*Ignored*/&mut gst::ClockID) -> bool {
// unsafe { TODO: call ffi::gst_test_clock_peek_next_pending_id() }
//}
//fn process_id_list(&self, pending_list: /*Ignored*/&[&gst::ClockID]) -> u32 {
//pub fn process_id_list(&self, pending_list: /*Ignored*/&[&gst::ClockID]) -> u32 {
// unsafe { TODO: call ffi::gst_test_clock_process_id_list() }
//}
//fn process_next_clock_id(&self) -> /*Ignored*/Option<gst::ClockID> {
//pub fn process_next_clock_id(&self) -> /*Ignored*/Option<gst::ClockID> {
// unsafe { TODO: call ffi::gst_test_clock_process_next_clock_id() }
//}
fn set_time(&self, new_time: gst::ClockTime) {
pub fn set_time(&self, new_time: gst::ClockTime) {
unsafe {
ffi::gst_test_clock_set_time(self.to_glib_none().0, new_time.to_glib());
}
}
//fn wait_for_multiple_pending_ids(&self, count: u32, pending_list: /*Unimplemented*/Vec<gst::ClockID>) {
//pub fn wait_for_multiple_pending_ids(&self, count: u32, pending_list: /*Unimplemented*/Vec<gst::ClockID>) {
// unsafe { TODO: call ffi::gst_test_clock_wait_for_multiple_pending_ids() }
//}
//fn wait_for_next_pending_id(&self, pending_id: /*Ignored*/&mut gst::ClockID) {
//pub fn wait_for_next_pending_id(&self, pending_id: /*Ignored*/&mut gst::ClockID) {
// unsafe { TODO: call ffi::gst_test_clock_wait_for_next_pending_id() }
//}
fn wait_for_pending_id_count(&self, count: u32) {
pub fn wait_for_pending_id_count(&self, count: u32) {
unsafe {
ffi::gst_test_clock_wait_for_pending_id_count(self.to_glib_none().0, count);
}
}
fn get_property_clock_type(&self) -> gst::ClockType {
pub fn get_property_clock_type(&self) -> gst::ClockType {
unsafe {
let mut value = Value::from_type(<gst::ClockType as StaticType>::static_type());
gobject_ffi::g_object_get_property(self.to_glib_none().0, "clock-type".to_glib_none().0, value.to_glib_none_mut().0);
......@@ -163,13 +112,13 @@ impl<O: IsA<TestClock> + IsA<glib::object::Object>> TestClockExt for O {
}
}
fn set_property_clock_type(&self, clock_type: gst::ClockType) {
pub fn set_property_clock_type(&self, clock_type: gst::ClockType) {
unsafe {
gobject_ffi::g_object_set_property(self.to_glib_none().0, "clock-type".to_glib_none().0, Value::from(&clock_type).to_glib_none().0);
}
}
fn get_property_start_time(&self) -> u64 {
pub fn get_property_start_time(&self) -> u64 {
unsafe {
let mut value = Value::from_type(<u64 as StaticType>::static_type());
gobject_ffi::g_object_get_property(self.to_glib_none().0, "start-time".to_glib_none().0, value.to_glib_none_mut().0);
......@@ -177,17 +126,29 @@ impl<O: IsA<TestClock> + IsA<glib::object::Object>> TestClockExt for O {
}
}
fn connect_property_clock_type_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
//pub fn id_list_get_latest_time(pending_list: /*Ignored*/&[&gst::ClockID]) -> gst::ClockTime {
// unsafe { TODO: call ffi::gst_test_clock_id_list_get_latest_time() }
//}
pub fn connect_property_clock_type_notify<F: Fn(&TestClock) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
unsafe {
let f: Box_<Box_<Fn(&Self) + Send + Sync + 'static>> = Box_::new(Box_::new(f));
let f: Box_<Box_<Fn(&TestClock) + Send + Sync + 'static>> = Box_::new(Box_::new(f));
connect(self.to_glib_none().0, "notify::clock-type",
transmute(notify_clock_type_trampoline::<Self> as usize), Box_::into_raw(f) as *mut _)
transmute(notify_clock_type_trampoline as usize), Box_::into_raw(f) as *mut _)
}
}
}
unsafe extern "C" fn notify_clock_type_trampoline<P>(this: *mut ffi::GstTestClock, _param_spec: glib_ffi::gpointer, f: glib_ffi::gpointer)
where P: IsA<TestClock> {
let f: &&(Fn(&P) + Send + Sync + 'static) = transmute(f);
f(&TestClock::from_glib_borrow(this).downcast_unchecked())
impl Default for TestClock {
fn default() -> Self {
Self::new()
}
}
unsafe impl Send for TestClock {}
unsafe impl Sync for TestClock {}
unsafe extern "C" fn notify_clock_type_trampoline(this: *mut ffi::GstTestClock, _param_spec: glib_ffi::gpointer, f: glib_ffi::gpointer) {
let f: &&(Fn(&TestClock) + Send + Sync + 'static) = transmute(f);
f(&from_glib_borrow(this))
}
This diff is collapsed.
// Copyright (C) 2018 Sebastian Dröge <sebastian@centricular.com>
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern crate glib_sys as glib_ffi;
extern crate gobject_sys as gobject_ffi;
extern crate gstreamer as gst;
extern crate gstreamer_check_sys as ffi;
extern crate gstreamer_sys as gst_ffi;
#[macro_use]
extern crate glib;
macro_rules! assert_initialized_main_thread {
() => {
if unsafe { ::gst_ffi::gst_is_initialized() } != ::glib_ffi::GTRUE {
panic!("GStreamer has not been initialized. Call `gst::init` first.");
}
};
}
pub use glib::{Cast, Continue, Error, IsA, StaticType, ToValue, Type, TypedValue, Value};
#[cfg_attr(feature = "cargo-clippy", allow(unreadable_literal))]
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
#[cfg_attr(feature = "cargo-clippy", allow(too_many_arguments))]
#[cfg_attr(feature = "cargo-clippy", allow(match_same_arms))]
#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
mod auto;
pub use auto::*;
mod test_clock;
mod harness;
pub use harness::*;
// Re-export all the traits in a prelude module, so that applications
// can always "use gst::prelude::*" without getting conflicts
pub mod prelude {
pub use glib::prelude::*;
pub use gst::prelude::*;
pub use auto::traits::*;
}
// Copyright (C) 2018 Sebastian Dröge <sebastian@centricular.com>
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use ffi;
#[cfg(any(feature = "v1_14", feature = "dox"))]
use glib::translate::*;
use gst;
use std::ptr;
use TestClock;
impl TestClock {
pub fn has_id(&self, id: &gst::ClockId) -> bool {
unsafe { from_glib(ffi::gst_test_clock_has_id(self.to_glib_none().0, id.to_glib_none().0)) }
}
pub fn peek_next_pending_id(&self) -> Option<gst::ClockId> {
unsafe {
let mut id = ptr::null_mut();
let ret: bool = from_glib(ffi::gst_test_clock_peek_next_pending_id(self.to_glib_none().0, &mut id));
if ret {
from_glib_full(id)
} else {
None
}
}
}
pub fn process_id_list(&self, pending_list: &[&gst::ClockId]) -> u32 {
unsafe {
ffi::gst_test_clock_process_id_list(self.to_glib_none().0, pending_list.to_glib_none().0)
}
}
pub fn process_next_clock_id(&self) -> Option<gst::ClockId> {
unsafe {
from_glib_full(ffi::gst_test_clock_process_next_clock_id(self.to_glib_none().0))
}
}
pub fn wait_for_multiple_pending_ids(&self, count: u32) -> Vec<gst::ClockId> {
unsafe {
let mut pending_list = ptr::null_mut();
ffi::gst_test_clock_wait_for_multiple_pending_ids(self.to_glib_none().0, count, &mut pending_list);
FromGlibPtrContainer::from_glib_full(pending_list)
}
}
pub fn wait_for_next_pending_id(&self) -> gst::ClockId {
unsafe {
let mut id = ptr::null_mut();
ffi::gst_test_clock_wait_for_next_pending_id(self.to_glib_none().0, &mut id);
from_glib_full(id)
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment