Commit 1e12354c authored by Philippe Normand's avatar Philippe Normand 🥑 Committed by Sebastian Dröge

GstPlayer: make it build and add simple example

parent 8badc33d
......@@ -112,6 +112,7 @@ dependencies = [
"glib 0.1.3 (git+https://github.com/gtk-rs/glib)",
"gstreamer 0.1.0",
"gstreamer-app 0.1.0",
"gstreamer-player 0.1.0",
"gtk 0.1.3 (git+https://github.com/gtk-rs/gtk)",
"send-cell 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-core 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -327,6 +328,35 @@ dependencies = [
"pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "gstreamer-player"
version = "0.1.0"
dependencies = [
"bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
"glib 0.1.3 (git+https://github.com/gtk-rs/glib)",
"glib-sys 0.3.4 (git+https://github.com/gtk-rs/sys)",
"gobject-sys 0.3.4 (git+https://github.com/gtk-rs/sys)",
"gstreamer 0.1.0",
"gstreamer-player-sys 0.1.1 (git+https://github.com/sdroege/gstreamer-sys)",
"gstreamer-sys 0.1.1 (git+https://github.com/sdroege/gstreamer-sys)",
"libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)",
"rustdoc-stripper 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "gstreamer-player-sys"
version = "0.1.1"
source = "git+https://github.com/sdroege/gstreamer-sys#669b24f66122067891bb5548e3ef85bc63493c19"
dependencies = [
"bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
"glib-sys 0.3.4 (git+https://github.com/gtk-rs/sys)",
"gobject-sys 0.3.4 (git+https://github.com/gtk-rs/sys)",
"gstreamer-sys 0.1.1 (git+https://github.com/sdroege/gstreamer-sys)",
"gstreamer-video-sys 0.1.1 (git+https://github.com/sdroege/gstreamer-sys)",
"libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)",
"pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "gstreamer-sys"
version = "0.1.1"
......@@ -658,6 +688,7 @@ dependencies = [
"checksum gstreamer-app-sys 0.1.1 (git+https://github.com/sdroege/gstreamer-sys)" = "<none>"
"checksum gstreamer-audio-sys 0.1.1 (git+https://github.com/sdroege/gstreamer-sys)" = "<none>"
"checksum gstreamer-base-sys 0.1.1 (git+https://github.com/sdroege/gstreamer-sys)" = "<none>"
"checksum gstreamer-player-sys 0.1.1 (git+https://github.com/sdroege/gstreamer-sys)" = "<none>"
"checksum gstreamer-sys 0.1.1 (git+https://github.com/sdroege/gstreamer-sys)" = "<none>"
"checksum gstreamer-tag-sys 0.1.1 (git+https://github.com/sdroege/gstreamer-sys)" = "<none>"
"checksum gstreamer-video-sys 0.1.1 (git+https://github.com/sdroege/gstreamer-sys)" = "<none>"
......
......@@ -4,6 +4,7 @@ members = [
"gstreamer",
"gstreamer-app",
"gstreamer-audio",
"gstreamer-player",
"gstreamer-video",
"examples",
]
......@@ -2,7 +2,7 @@
girs_dir = "gir-files"
library = "GstPlayer"
version = "1.0"
min_cfg_version = "1.10"
min_cfg_version = "1.12"
target_path = "gstreamer-player"
work_mode = "normal"
concurrency = "send+sync"
......@@ -14,7 +14,6 @@ external_libraries = [
]
generate = [
"GstPlayer.Player",
"GstPlayer.PlayerAudioInfo",
"GstPlayer.PlayerColorBalanceType",
"GstPlayer.PlayerError",
......@@ -36,7 +35,6 @@ manual = [
"GLib.MainContext",
"GObject.Object",
"Gst.ClockTime",
"Gst.Structure",
"Gst.Element",
]
......@@ -54,3 +52,81 @@ ref_mode = "ref"
name = "Gst.Sample"
status = "manual"
ref_mode = "ref"
[[object]]
name = "Gst.Structure"
status = "manual"
ref_mode = "ref-mut"
[[object]]
name = "GstPlayer.Player"
status = "generate"
trait = false
[[object.function]]
name = "visualizations_free"
# correct mutability
ignore = true
[[object.function]]
name = "set_config"
# Pass by value
ignore = true
[[object.function]]
name = "new"
ignore = true
[[object.signal]]
name = "buffering"
concurrency = "send"
[[object.signal]]
name = "duration-changed"
concurrency = "send"
[[object.signal]]
name = "end-of-stream"
concurrency = "send"
[[object.signal]]
name = "error"
concurrency = "send"
[[object.signal]]
name = "media-info-updated"
concurrency = "send"
[[object.signal]]
name = "mute-changed"
concurrency = "send"
[[object.signal]]
name = "position-changed"
concurrency = "send"
[[object.signal]]
name = "seek-done"
concurrency = "send"
[[object.signal]]
name = "state-changed"
concurrency = "send"
[[object.signal]]
name = "uri-loaded"
concurrency = "send"
[[object.signal]]
name = "video-dimensions-changed"
concurrency = "send"
[[object.signal]]
name = "volume-changed"
concurrency = "send"
[[object.signal]]
name = "warning"
concurrency = "send"
This diff is collapsed.
......@@ -7,8 +7,13 @@ authors = ["Sebastian Dröge <sebastian@centricular.com>"]
glib = { version = "0.1.3", git = "https://github.com/gtk-rs/glib" }
gstreamer = { path = "../gstreamer" }
gstreamer-app = { path = "../gstreamer-app" }
gstreamer-player = { path = "../gstreamer-player", optional = true }
gtk = { version = "0.1.3", git = "https://github.com/gtk-rs/gtk", features = ["v3_6"] }
gio = { version = "0.1.3", git = "https://github.com/gtk-rs/gio" }
futures = "0.1"
tokio-core = "0.1"
send-cell = "0.1"
[features]
gst-player = ["gstreamer-player"]
default-features = []
extern crate gstreamer as gst;
#[cfg(feature = "gst-player")]
extern crate gstreamer_player as gst_player;
extern crate glib;
#[allow(unused_imports)]
use glib::ObjectExt;
extern crate send_cell;
use std::env;
pub mod utils;
#[cfg(feature = "gst-player")]
fn main_loop(uri: &str) -> Result<(), utils::ExampleError> {
gst::init().map_err(utils::ExampleError::InitFailed)?;
let main_loop = glib::MainLoop::new(None, false);
let dispatcher = gst_player::PlayerGMainContextSignalDispatcher::new(None).unwrap();
let player = gst_player::Player::new(None, Some(&dispatcher));
player
.set_property("uri", &glib::Value::from(uri))
.expect("Can't set uri property");
let result = std::cell::RefCell::new(Some(Ok(())));
let error = std::sync::Arc::new(std::sync::Mutex::new(send_cell::SendCell::new(result)));
let error_clone = error.clone();
let player_clone = player.clone();
let main_loop_clone = main_loop.clone();
player.connect_end_of_stream(move |_| {
let main_loop = &main_loop_clone;
let player = &player_clone;
player.stop();
main_loop.quit();
});
let player_clone = player.clone();
let main_loop_clone = main_loop.clone();
player.connect_error(move |_, err| {
let main_loop = &main_loop_clone;
let player = &player_clone;
let error = std::sync::Arc::clone(&error_clone);
let guard = error.lock().unwrap();
let cell = &*guard;
let refcell = cell.get();
*refcell.borrow_mut() = Some(Err(utils::ExampleError::ElementError(
"player".to_owned(),
err.clone(),
"".to_owned(),
)));
player.stop();
main_loop.quit();
});
player.play();
main_loop.run();
let guard = error.as_ref().lock().unwrap();
let cell = &*guard;
let refcell = cell.get();
let result = refcell.borrow();
if let Some(ref e) = *result {
return e.clone();
} else {
Ok(())
}
}
#[cfg(not(feature = "gst-player"))]
#[allow(unused_variables)]
fn main_loop(uri: &str) -> Result<(), utils::ExampleError> {
Err(utils::ExampleError::MissingFeature("gst-player"))
}
fn main() {
let args: Vec<_> = env::args().collect();
let uri: &str = if args.len() == 2 {
args[1].as_ref()
} else {
panic!("Usage: player uri");
};
match main_loop(uri) {
Ok(r) => r,
Err(e) => eprintln!("Error! {}", e),
}
}
......@@ -5,13 +5,14 @@ use gst::*;
extern crate glib;
use std::fmt;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub enum ExampleError {
InitFailed(glib::Error),
ElementNotFound(&'static str),
ElementLinkFailed(::std::string::String, ::std::string::String),
SetStateError(::std::string::String),
ElementError(::std::string::String, glib::Error, ::std::string::String),
MissingFeature(&'static str),
}
impl fmt::Display for ExampleError {
......@@ -30,6 +31,12 @@ impl fmt::Display for ExampleError {
ExampleError::ElementError(ref element, ref err, ref debug) => {
write!(f, "Error from {}: {} ({:?})", element, err, debug)
}
ExampleError::MissingFeature(ref feature) => write!(
f,
"Feature {} is required. Please rebuild with --features {}",
feature,
feature
),
}
}
}
......
......@@ -25,8 +25,8 @@ version = "0.1"
optional = true
[features]
v1_10 = ["gstreamer-sys/v1_10"]
v1_12 = ["gstreamer-sys/v1_12", "v1_10"]
v1_10 = ["gstreamer-sys/v1_10", "gstreamer-app-sys/v1_10"]
v1_12 = ["gstreamer-sys/v1_12", "gstreamer-app-sys/v1_12", "v1_10"]
embed-lgpl-docs = ["rustdoc-stripper"]
purge-lgpl-docs = ["rustdoc-stripper"]
default-features = []
[package]
name = "gstreamer-player"
version = "0.1.0"
authors = ["Sebastian Dröge <sebastian@centricular.com>"]
categories = ["api-bindings", "multimedia"]
description = "Rust bindings for GStreamer Player library"
repository = "https://github.com/sdroege/gstreamer-rs"
license = "MIT/Apache-2.0"
documentation = "https://gstreamer.freedesktop.org"
keywords = ["gstreamer", "multimedia", "audio", "video", "gnome"]
build = "build.rs"
[dependencies]
bitflags = "0.9"
libc = "0.2"
glib-sys = { version = "0.3.4", git = "https://github.com/gtk-rs/sys" }
gobject-sys = { version = "0.3.4", git = "https://github.com/gtk-rs/sys" }
gstreamer-sys = { version = "0.1.1", git = "https://github.com/sdroege/gstreamer-sys", features = ["v1_12"] }
gstreamer-player-sys = { version = "0.1.1", git = "https://github.com/sdroege/gstreamer-sys", features = ["v1_12"] }
glib = { version = "0.1.3", git = "https://github.com/gtk-rs/glib" }
gstreamer = { version = "0.1.0", path = "../gstreamer", features = ["v1_12"] }
[build-dependencies.rustdoc-stripper]
version = "0.1"
optional = true
[features]
embed-lgpl-docs = ["rustdoc-stripper"]
purge-lgpl-docs = ["rustdoc-stripper"]
default-features = []
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-player/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() {}
// This file was generated by gir (f00d658) from gir-files (???)
// This file was generated by gir (3294959) from gir-files (???)
// DO NOT EDIT
use ffi;
......
// This file was generated by gir (f00d658) from gir-files (???)
// This file was generated by gir (3294959) from gir-files (???)
// DO NOT EDIT
use ffi;
......
// This file was generated by gir (f00d658) from gir-files (???)
// This file was generated by gir (3294959) from gir-files (???)
// DO NOT EDIT
mod player;
pub use self::player::Player;
pub use self::player::PlayerExt;
mod player_audio_info;
pub use self::player_audio_info::PlayerAudioInfo;
......@@ -52,7 +51,6 @@ pub use self::enums::PlayerState;
#[doc(hidden)]
pub mod traits {
pub use super::PlayerExt;
pub use super::PlayerAudioInfoExt;
pub use super::PlayerGMainContextSignalDispatcherExt;
pub use super::PlayerMediaInfoExt;
......
This diff is collapsed.
// This file was generated by gir (f00d658) from gir-files (???)
// This file was generated by gir (3294959) from gir-files (???)
// DO NOT EDIT
use PlayerStreamInfo;
......
// This file was generated by gir (f00d658) from gir-files (???)
// This file was generated by gir (3294959) from gir-files (???)
// DO NOT EDIT
use PlayerSignalDispatcher;
......
// This file was generated by gir (f00d658) from gir-files (???)
// This file was generated by gir (3294959) from gir-files (???)
// DO NOT EDIT
use PlayerAudioInfo;
......@@ -34,16 +34,12 @@ pub trait PlayerMediaInfoExt {
fn get_image_sample(&self) -> Option<gst::Sample>;
#[cfg(feature = "v1_12")]
fn get_number_of_audio_streams(&self) -> u32;
#[cfg(feature = "v1_12")]
fn get_number_of_streams(&self) -> u32;
#[cfg(feature = "v1_12")]
fn get_number_of_subtitle_streams(&self) -> u32;
#[cfg(feature = "v1_12")]
fn get_number_of_video_streams(&self) -> u32;
fn get_stream_list(&self) -> Vec<PlayerStreamInfo>;
......@@ -88,28 +84,24 @@ impl<O: IsA<PlayerMediaInfo>> PlayerMediaInfoExt for O {
}
}
#[cfg(feature = "v1_12")]
fn get_number_of_audio_streams(&self) -> u32 {
unsafe {
ffi::gst_player_media_info_get_number_of_audio_streams(self.to_glib_none().0)
}
}
#[cfg(feature = "v1_12")]
fn get_number_of_streams(&self) -> u32 {
unsafe {
ffi::gst_player_media_info_get_number_of_streams(self.to_glib_none().0)
}
}
#[cfg(feature = "v1_12")]
fn get_number_of_subtitle_streams(&self) -> u32 {
unsafe {
ffi::gst_player_media_info_get_number_of_subtitle_streams(self.to_glib_none().0)
}
}
#[cfg(feature = "v1_12")]
fn get_number_of_video_streams(&self) -> u32 {
unsafe {
ffi::gst_player_media_info_get_number_of_video_streams(self.to_glib_none().0)
......
// This file was generated by gir (f00d658) from gir-files (???)
// This file was generated by gir (3294959) from gir-files (???)
// DO NOT EDIT
use ffi;
......
// This file was generated by gir (f00d658) from gir-files (???)
// This file was generated by gir (3294959) from gir-files (???)
// DO NOT EDIT
use ffi;
......
// This file was generated by gir (f00d658) from gir-files (???)
// This file was generated by gir (3294959) from gir-files (???)
// DO NOT EDIT
use PlayerStreamInfo;
......
// This file was generated by gir (f00d658) from gir-files (???)
// This file was generated by gir (3294959) from gir-files (???)
// DO NOT EDIT
use PlayerStreamInfo;
......
// This file was generated by gir (f00d658) from gir-files (???)
// This file was generated by gir (3294959) from gir-files (???)
// DO NOT EDIT
use PlayerVideoRenderer;
......
// This file was generated by gir (f00d658) from gir-files (???)
// This file was generated by gir (3294959) from gir-files (???)
// DO NOT EDIT
use ffi;
......
// This file was generated by gir (f00d658) from gir-files (???)
// This file was generated by gir (3294959) from gir-files (???)
// DO NOT EDIT
use ffi;
......
// Copyright (C) 2017 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 libc;
extern crate glib_sys as glib_ffi;
extern crate gobject_sys as gobject_ffi;
extern crate gstreamer_sys as gst_ffi;
extern crate gstreamer_player_sys as ffi;
extern crate gstreamer as gst;
#[macro_use]
extern crate glib;
macro_rules! callback_guard {
() => (
let _guard = ::glib::CallbackGuard::new();
)
}
macro_rules! skip_assert_initialized {
() => (
)
}
macro_rules! assert_initialized_main_thread {
() => (
)
}
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))]
mod auto;
pub use auto::*;
pub use auto::traits::*;
mod player;
// Copyright (C) 2017 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 Player;
use PlayerSignalDispatcher;
use PlayerVideoRenderer;
use ffi;
use glib::translate::*;
use gst;
impl Player {
pub fn new(
video_renderer: Option<&PlayerVideoRenderer>,
signal_dispatcher: Option<&PlayerSignalDispatcher>,
) -> Player {
assert_initialized_main_thread!();
let (major, minor, _, _) = gst::version();
if (major, minor) > (1, 12) {
let video_renderer = video_renderer.to_glib_full();
let signal_dispatcher = signal_dispatcher.to_glib_full();
unsafe { from_glib_full(ffi::gst_player_new(video_renderer, signal_dispatcher)) }
} else {
// Workaround for bad floating reference handling in 1.12. This issue was fixed for 1.13 in
// https://cgit.freedesktop.org/gstreamer/gst-plugins-bad/commit/gst-libs/gst/player/gstplayer.c?id=634cd87c76f58b5e1383715bafd5614db825c7d1
let video_renderer = video_renderer.to_glib_none();
let signal_dispatcher = signal_dispatcher.to_glib_none();
unsafe { from_glib_none(ffi::gst_player_new(video_renderer.0, signal_dispatcher.0)) }
}
}
#[allow(dead_code)]
fn set_config(&self, config: gst::Structure) -> bool {
unsafe {
from_glib(ffi::gst_player_set_config(
self.to_glib_none().0,
config.into_ptr(),
))
}
}
}
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