Add initial libgstvideo bindings

Only VideoFormat and VideoFormatInfo and related API for now.

https://github.com/sdroege/gstreamer-rs/issues/5
This commit is contained in:
Sebastian Dröge 2017-08-11 00:41:55 +03:00
parent 21c4173051
commit 3a50ca61e3
11 changed files with 1150 additions and 3 deletions

36
Cargo.lock generated
View file

@ -1,15 +1,14 @@
[root]
name = "gstreamer-audio"
name = "gstreamer-video"
version = "0.1.0"
dependencies = [
"array-init 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"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-audio-sys 0.1.1 (git+https://github.com/sdroege/gstreamer-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)",
"rustdoc-stripper 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -284,6 +283,22 @@ dependencies = [
"pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "gstreamer-audio"
version = "0.1.0"
dependencies = [
"array-init 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"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-audio-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-audio-sys"
version = "0.1.1"
@ -338,6 +353,20 @@ dependencies = [
"pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "gstreamer-video-sys"
version = "0.1.1"
source = "git+https://github.com/sdroege/gstreamer-sys#252abbaeda64a3fdd8ccab291297500e3cdf6499"
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-base-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)",
"pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "gtk"
version = "0.1.3"
@ -631,6 +660,7 @@ dependencies = [
"checksum gstreamer-base-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>"
"checksum gtk 0.1.3 (git+https://github.com/gtk-rs/gtk)" = "<none>"
"checksum gtk-sys 0.3.4 (git+https://github.com/gtk-rs/sys)" = "<none>"
"checksum iovec 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "29d062ee61fccdf25be172e70f34c9f6efc597e1fb8f6526e8437b2046ab26be"

View file

@ -4,5 +4,6 @@ members = [
"gstreamer",
"gstreamer-app",
"gstreamer-audio",
"gstreamer-video",
"examples",
]

38
Gir_GstVideo.toml Normal file
View file

@ -0,0 +1,38 @@
[options]
girs_dir = "gir-files"
library = "GstVideo"
version = "1.0"
min_cfg_version = "1.8"
target_path = "gstreamer-video"
work_mode = "normal"
concurrency = "send+sync"
generate_safety_asserts = true
external_libraries = [
"GLib",
"GObject",
"Gst",
]
generate = [
"GstVideo.VideoFormat",
"GstVideo.VideoFormatFlags",
"GstVideo.VideoTileMode",
"GstVideo.VideoInterlaceMode",
"GstVideo.VideoFlags",
"GstVideo.VideoChromaSite",
]
manual = [
"GObject.Object",
"Gst.Object",
"GstVideo.VideoInfo",
"GstVideo.VideoFormatInfo",
"GstVideo.VideoColorimetry",
]
[[object]]
name = "Gst.Caps"
status = "manual"
ref_mode = "ref"

View file

@ -0,0 +1,32 @@
[package]
name = "gstreamer-video"
version = "0.1.0"
authors = ["Sebastian Dröge <sebastian@centricular.com>"]
categories = ["api-bindings", "multimedia"]
description = "Rust bindings for GStreamer Video 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_8"] }
gstreamer-video-sys = { version = "0.1.1", git = "https://github.com/sdroege/gstreamer-sys", features = ["v1_8"] }
glib = { version = "0.1.3", git = "https://github.com/gtk-rs/glib" }
gstreamer = { version = "0.1.0", path = "../gstreamer" }
[build-dependencies.rustdoc-stripper]
version = "0.1"
optional = true
[features]
v1_10 = ["gstreamer-sys/v1_10"]
v1_12 = ["gstreamer-sys/v1_12", "v1_10"]
embed-lgpl-docs = ["rustdoc-stripper"]
purge-lgpl-docs = ["rustdoc-stripper"]
default-features = []

34
gstreamer-video/build.rs Normal file
View file

@ -0,0 +1,34 @@
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-video/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() {}

View file

@ -0,0 +1,421 @@
// This file was generated by gir (cf27827) from gir-files (???)
// DO NOT EDIT
use ffi;
use glib::Type;
use glib::StaticType;
use glib::value::{FromValue, FromValueOptional, SetValue, Value};
use gobject_ffi;
use glib::translate::*;
use std;
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
pub enum VideoFormat {
Unknown,
Encoded,
I420,
Yv12,
Yuy2,
Uyvy,
Ayuv,
Rgbx,
Bgrx,
Xrgb,
Xbgr,
Rgba,
Bgra,
Argb,
Abgr,
Rgb,
Bgr,
Y41b,
Y42b,
Yvyu,
Y444,
V210,
V216,
Nv12,
Nv21,
Gray8,
Gray16Be,
Gray16Le,
V308,
Rgb16,
Bgr16,
Rgb15,
Bgr15,
Uyvp,
A420,
Rgb8p,
Yuv9,
Yvu9,
Iyu1,
Argb64,
Ayuv64,
R210,
I42010be,
I42010le,
I42210be,
I42210le,
Y44410be,
Y44410le,
Gbr,
Gbr10be,
Gbr10le,
Nv16,
Nv24,
Nv1264z32,
A42010be,
A42010le,
A42210be,
A42210le,
A44410be,
A44410le,
Nv61,
P01010be,
P01010le,
Iyu2,
Vyuy,
Gbra,
Gbra10be,
Gbra10le,
Gbr12be,
Gbr12le,
Gbra12be,
Gbra12le,
I42012be,
I42012le,
I42212be,
I42212le,
Y44412be,
Y44412le,
#[doc(hidden)]
__Unknown(i32),
}
#[doc(hidden)]
impl ToGlib for VideoFormat {
type GlibType = ffi::GstVideoFormat;
fn to_glib(&self) -> ffi::GstVideoFormat {
match *self {
VideoFormat::Unknown => ffi::GST_VIDEO_FORMAT_UNKNOWN,
VideoFormat::Encoded => ffi::GST_VIDEO_FORMAT_ENCODED,
VideoFormat::I420 => ffi::GST_VIDEO_FORMAT_I420,
VideoFormat::Yv12 => ffi::GST_VIDEO_FORMAT_YV12,
VideoFormat::Yuy2 => ffi::GST_VIDEO_FORMAT_YUY2,
VideoFormat::Uyvy => ffi::GST_VIDEO_FORMAT_UYVY,
VideoFormat::Ayuv => ffi::GST_VIDEO_FORMAT_AYUV,
VideoFormat::Rgbx => ffi::GST_VIDEO_FORMAT_RGBx,
VideoFormat::Bgrx => ffi::GST_VIDEO_FORMAT_BGRx,
VideoFormat::Xrgb => ffi::GST_VIDEO_FORMAT_xRGB,
VideoFormat::Xbgr => ffi::GST_VIDEO_FORMAT_xBGR,
VideoFormat::Rgba => ffi::GST_VIDEO_FORMAT_RGBA,
VideoFormat::Bgra => ffi::GST_VIDEO_FORMAT_BGRA,
VideoFormat::Argb => ffi::GST_VIDEO_FORMAT_ARGB,
VideoFormat::Abgr => ffi::GST_VIDEO_FORMAT_ABGR,
VideoFormat::Rgb => ffi::GST_VIDEO_FORMAT_RGB,
VideoFormat::Bgr => ffi::GST_VIDEO_FORMAT_BGR,
VideoFormat::Y41b => ffi::GST_VIDEO_FORMAT_Y41B,
VideoFormat::Y42b => ffi::GST_VIDEO_FORMAT_Y42B,
VideoFormat::Yvyu => ffi::GST_VIDEO_FORMAT_YVYU,
VideoFormat::Y444 => ffi::GST_VIDEO_FORMAT_Y444,
VideoFormat::V210 => ffi::GST_VIDEO_FORMAT_v210,
VideoFormat::V216 => ffi::GST_VIDEO_FORMAT_v216,
VideoFormat::Nv12 => ffi::GST_VIDEO_FORMAT_NV12,
VideoFormat::Nv21 => ffi::GST_VIDEO_FORMAT_NV21,
VideoFormat::Gray8 => ffi::GST_VIDEO_FORMAT_GRAY8,
VideoFormat::Gray16Be => ffi::GST_VIDEO_FORMAT_GRAY16_BE,
VideoFormat::Gray16Le => ffi::GST_VIDEO_FORMAT_GRAY16_LE,
VideoFormat::V308 => ffi::GST_VIDEO_FORMAT_v308,
VideoFormat::Rgb16 => ffi::GST_VIDEO_FORMAT_RGB16,
VideoFormat::Bgr16 => ffi::GST_VIDEO_FORMAT_BGR16,
VideoFormat::Rgb15 => ffi::GST_VIDEO_FORMAT_RGB15,
VideoFormat::Bgr15 => ffi::GST_VIDEO_FORMAT_BGR15,
VideoFormat::Uyvp => ffi::GST_VIDEO_FORMAT_UYVP,
VideoFormat::A420 => ffi::GST_VIDEO_FORMAT_A420,
VideoFormat::Rgb8p => ffi::GST_VIDEO_FORMAT_RGB8P,
VideoFormat::Yuv9 => ffi::GST_VIDEO_FORMAT_YUV9,
VideoFormat::Yvu9 => ffi::GST_VIDEO_FORMAT_YVU9,
VideoFormat::Iyu1 => ffi::GST_VIDEO_FORMAT_IYU1,
VideoFormat::Argb64 => ffi::GST_VIDEO_FORMAT_ARGB64,
VideoFormat::Ayuv64 => ffi::GST_VIDEO_FORMAT_AYUV64,
VideoFormat::R210 => ffi::GST_VIDEO_FORMAT_r210,
VideoFormat::I42010be => ffi::GST_VIDEO_FORMAT_I420_10BE,
VideoFormat::I42010le => ffi::GST_VIDEO_FORMAT_I420_10LE,
VideoFormat::I42210be => ffi::GST_VIDEO_FORMAT_I422_10BE,
VideoFormat::I42210le => ffi::GST_VIDEO_FORMAT_I422_10LE,
VideoFormat::Y44410be => ffi::GST_VIDEO_FORMAT_Y444_10BE,
VideoFormat::Y44410le => ffi::GST_VIDEO_FORMAT_Y444_10LE,
VideoFormat::Gbr => ffi::GST_VIDEO_FORMAT_GBR,
VideoFormat::Gbr10be => ffi::GST_VIDEO_FORMAT_GBR_10BE,
VideoFormat::Gbr10le => ffi::GST_VIDEO_FORMAT_GBR_10LE,
VideoFormat::Nv16 => ffi::GST_VIDEO_FORMAT_NV16,
VideoFormat::Nv24 => ffi::GST_VIDEO_FORMAT_NV24,
VideoFormat::Nv1264z32 => ffi::GST_VIDEO_FORMAT_NV12_64Z32,
VideoFormat::A42010be => ffi::GST_VIDEO_FORMAT_A420_10BE,
VideoFormat::A42010le => ffi::GST_VIDEO_FORMAT_A420_10LE,
VideoFormat::A42210be => ffi::GST_VIDEO_FORMAT_A422_10BE,
VideoFormat::A42210le => ffi::GST_VIDEO_FORMAT_A422_10LE,
VideoFormat::A44410be => ffi::GST_VIDEO_FORMAT_A444_10BE,
VideoFormat::A44410le => ffi::GST_VIDEO_FORMAT_A444_10LE,
VideoFormat::Nv61 => ffi::GST_VIDEO_FORMAT_NV61,
VideoFormat::P01010be => ffi::GST_VIDEO_FORMAT_P010_10BE,
VideoFormat::P01010le => ffi::GST_VIDEO_FORMAT_P010_10LE,
VideoFormat::Iyu2 => ffi::GST_VIDEO_FORMAT_IYU2,
VideoFormat::Vyuy => ffi::GST_VIDEO_FORMAT_VYUY,
VideoFormat::Gbra => ffi::GST_VIDEO_FORMAT_GBRA,
VideoFormat::Gbra10be => ffi::GST_VIDEO_FORMAT_GBRA_10BE,
VideoFormat::Gbra10le => ffi::GST_VIDEO_FORMAT_GBRA_10LE,
VideoFormat::Gbr12be => ffi::GST_VIDEO_FORMAT_GBR_12BE,
VideoFormat::Gbr12le => ffi::GST_VIDEO_FORMAT_GBR_12LE,
VideoFormat::Gbra12be => ffi::GST_VIDEO_FORMAT_GBRA_12BE,
VideoFormat::Gbra12le => ffi::GST_VIDEO_FORMAT_GBRA_12LE,
VideoFormat::I42012be => ffi::GST_VIDEO_FORMAT_I420_12BE,
VideoFormat::I42012le => ffi::GST_VIDEO_FORMAT_I420_12LE,
VideoFormat::I42212be => ffi::GST_VIDEO_FORMAT_I422_12BE,
VideoFormat::I42212le => ffi::GST_VIDEO_FORMAT_I422_12LE,
VideoFormat::Y44412be => ffi::GST_VIDEO_FORMAT_Y444_12BE,
VideoFormat::Y44412le => ffi::GST_VIDEO_FORMAT_Y444_12LE,
VideoFormat::__Unknown(value) => unsafe { std::mem::transmute(value) },
}
}
}
#[doc(hidden)]
impl FromGlib<ffi::GstVideoFormat> for VideoFormat {
fn from_glib(value: ffi::GstVideoFormat) -> Self {
skip_assert_initialized!();
match value as i32 {
0 => VideoFormat::Unknown,
1 => VideoFormat::Encoded,
2 => VideoFormat::I420,
3 => VideoFormat::Yv12,
4 => VideoFormat::Yuy2,
5 => VideoFormat::Uyvy,
6 => VideoFormat::Ayuv,
7 => VideoFormat::Rgbx,
8 => VideoFormat::Bgrx,
9 => VideoFormat::Xrgb,
10 => VideoFormat::Xbgr,
11 => VideoFormat::Rgba,
12 => VideoFormat::Bgra,
13 => VideoFormat::Argb,
14 => VideoFormat::Abgr,
15 => VideoFormat::Rgb,
16 => VideoFormat::Bgr,
17 => VideoFormat::Y41b,
18 => VideoFormat::Y42b,
19 => VideoFormat::Yvyu,
20 => VideoFormat::Y444,
21 => VideoFormat::V210,
22 => VideoFormat::V216,
23 => VideoFormat::Nv12,
24 => VideoFormat::Nv21,
25 => VideoFormat::Gray8,
26 => VideoFormat::Gray16Be,
27 => VideoFormat::Gray16Le,
28 => VideoFormat::V308,
29 => VideoFormat::Rgb16,
30 => VideoFormat::Bgr16,
31 => VideoFormat::Rgb15,
32 => VideoFormat::Bgr15,
33 => VideoFormat::Uyvp,
34 => VideoFormat::A420,
35 => VideoFormat::Rgb8p,
36 => VideoFormat::Yuv9,
37 => VideoFormat::Yvu9,
38 => VideoFormat::Iyu1,
39 => VideoFormat::Argb64,
40 => VideoFormat::Ayuv64,
41 => VideoFormat::R210,
42 => VideoFormat::I42010be,
43 => VideoFormat::I42010le,
44 => VideoFormat::I42210be,
45 => VideoFormat::I42210le,
46 => VideoFormat::Y44410be,
47 => VideoFormat::Y44410le,
48 => VideoFormat::Gbr,
49 => VideoFormat::Gbr10be,
50 => VideoFormat::Gbr10le,
51 => VideoFormat::Nv16,
52 => VideoFormat::Nv24,
53 => VideoFormat::Nv1264z32,
54 => VideoFormat::A42010be,
55 => VideoFormat::A42010le,
56 => VideoFormat::A42210be,
57 => VideoFormat::A42210le,
58 => VideoFormat::A44410be,
59 => VideoFormat::A44410le,
60 => VideoFormat::Nv61,
61 => VideoFormat::P01010be,
62 => VideoFormat::P01010le,
63 => VideoFormat::Iyu2,
64 => VideoFormat::Vyuy,
65 => VideoFormat::Gbra,
66 => VideoFormat::Gbra10be,
67 => VideoFormat::Gbra10le,
68 => VideoFormat::Gbr12be,
69 => VideoFormat::Gbr12le,
70 => VideoFormat::Gbra12be,
71 => VideoFormat::Gbra12le,
72 => VideoFormat::I42012be,
73 => VideoFormat::I42012le,
74 => VideoFormat::I42212be,
75 => VideoFormat::I42212le,
76 => VideoFormat::Y44412be,
77 => VideoFormat::Y44412le,
value => VideoFormat::__Unknown(value),
}
}
}
impl StaticType for VideoFormat {
fn static_type() -> Type {
unsafe { from_glib(ffi::gst_video_format_get_type()) }
}
}
impl<'a> FromValueOptional<'a> for VideoFormat {
unsafe fn from_value_optional(value: &Value) -> Option<Self> {
Some(FromValue::from_value(value))
}
}
impl<'a> FromValue<'a> for VideoFormat {
unsafe fn from_value(value: &Value) -> Self {
from_glib(std::mem::transmute::<i32, ffi::GstVideoFormat>(
gobject_ffi::g_value_get_enum(value.to_glib_none().0),
))
}
}
impl SetValue for VideoFormat {
unsafe fn set_value(value: &mut Value, this: &Self) {
gobject_ffi::g_value_set_enum(value.to_glib_none_mut().0, this.to_glib() as i32)
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
pub enum VideoInterlaceMode {
Progressive,
Interleaved,
Mixed,
Fields,
#[doc(hidden)]
__Unknown(i32),
}
#[doc(hidden)]
impl ToGlib for VideoInterlaceMode {
type GlibType = ffi::GstVideoInterlaceMode;
fn to_glib(&self) -> ffi::GstVideoInterlaceMode {
match *self {
VideoInterlaceMode::Progressive => ffi::GST_VIDEO_INTERLACE_MODE_PROGRESSIVE,
VideoInterlaceMode::Interleaved => ffi::GST_VIDEO_INTERLACE_MODE_INTERLEAVED,
VideoInterlaceMode::Mixed => ffi::GST_VIDEO_INTERLACE_MODE_MIXED,
VideoInterlaceMode::Fields => ffi::GST_VIDEO_INTERLACE_MODE_FIELDS,
VideoInterlaceMode::__Unknown(value) => unsafe { std::mem::transmute(value) },
}
}
}
#[doc(hidden)]
impl FromGlib<ffi::GstVideoInterlaceMode> for VideoInterlaceMode {
fn from_glib(value: ffi::GstVideoInterlaceMode) -> Self {
skip_assert_initialized!();
match value as i32 {
0 => VideoInterlaceMode::Progressive,
1 => VideoInterlaceMode::Interleaved,
2 => VideoInterlaceMode::Mixed,
3 => VideoInterlaceMode::Fields,
value => VideoInterlaceMode::__Unknown(value),
}
}
}
impl StaticType for VideoInterlaceMode {
fn static_type() -> Type {
unsafe { from_glib(ffi::gst_video_interlace_mode_get_type()) }
}
}
impl<'a> FromValueOptional<'a> for VideoInterlaceMode {
unsafe fn from_value_optional(value: &Value) -> Option<Self> {
Some(FromValue::from_value(value))
}
}
impl<'a> FromValue<'a> for VideoInterlaceMode {
unsafe fn from_value(value: &Value) -> Self {
from_glib(std::mem::transmute::<i32, ffi::GstVideoInterlaceMode>(
gobject_ffi::g_value_get_enum(value.to_glib_none().0),
))
}
}
impl SetValue for VideoInterlaceMode {
unsafe fn set_value(value: &mut Value, this: &Self) {
gobject_ffi::g_value_set_enum(value.to_glib_none_mut().0, this.to_glib() as i32)
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
pub enum VideoTileMode {
Unknown,
Zflipz2x2,
#[doc(hidden)]
__Unknown(i32),
}
#[doc(hidden)]
impl ToGlib for VideoTileMode {
type GlibType = ffi::GstVideoTileMode;
fn to_glib(&self) -> ffi::GstVideoTileMode {
match *self {
VideoTileMode::Unknown => ffi::GST_VIDEO_TILE_MODE_UNKNOWN,
VideoTileMode::Zflipz2x2 => ffi::GST_VIDEO_TILE_MODE_ZFLIPZ_2X2,
VideoTileMode::__Unknown(value) => unsafe { std::mem::transmute(value) },
}
}
}
#[doc(hidden)]
impl FromGlib<ffi::GstVideoTileMode> for VideoTileMode {
fn from_glib(value: ffi::GstVideoTileMode) -> Self {
skip_assert_initialized!();
match value as i32 {
0 => VideoTileMode::Unknown,
65536 => VideoTileMode::Zflipz2x2,
value => VideoTileMode::__Unknown(value),
}
}
}
impl StaticType for VideoTileMode {
fn static_type() -> Type {
unsafe { from_glib(ffi::gst_video_tile_mode_get_type()) }
}
}
impl<'a> FromValueOptional<'a> for VideoTileMode {
unsafe fn from_value_optional(value: &Value) -> Option<Self> {
Some(FromValue::from_value(value))
}
}
impl<'a> FromValue<'a> for VideoTileMode {
unsafe fn from_value(value: &Value) -> Self {
from_glib(std::mem::transmute::<i32, ffi::GstVideoTileMode>(
gobject_ffi::g_value_get_enum(value.to_glib_none().0),
))
}
}
impl SetValue for VideoTileMode {
unsafe fn set_value(value: &mut Value, this: &Self) {
gobject_ffi::g_value_set_enum(value.to_glib_none_mut().0, this.to_glib() as i32)
}
}

View file

@ -0,0 +1,174 @@
// This file was generated by gir (cf27827) from gir-files (???)
// DO NOT EDIT
use ffi;
use glib::Type;
use glib::StaticType;
use glib::value::{FromValue, FromValueOptional, SetValue, Value};
use gobject_ffi;
use glib::translate::*;
bitflags! {
pub struct VideoChromaSite: u32 {
const VIDEO_CHROMA_SITE_UNKNOWN = 0;
const VIDEO_CHROMA_SITE_NONE = 1;
const VIDEO_CHROMA_SITE_H_COSITED = 2;
const VIDEO_CHROMA_SITE_V_COSITED = 4;
const VIDEO_CHROMA_SITE_ALT_LINE = 8;
const VIDEO_CHROMA_SITE_COSITED = 6;
const VIDEO_CHROMA_SITE_JPEG = 1;
const VIDEO_CHROMA_SITE_MPEG2 = 2;
const VIDEO_CHROMA_SITE_DV = 14;
}
}
#[doc(hidden)]
impl ToGlib for VideoChromaSite {
type GlibType = ffi::GstVideoChromaSite;
fn to_glib(&self) -> ffi::GstVideoChromaSite {
ffi::GstVideoChromaSite::from_bits_truncate(self.bits())
}
}
#[doc(hidden)]
impl FromGlib<ffi::GstVideoChromaSite> for VideoChromaSite {
fn from_glib(value: ffi::GstVideoChromaSite) -> VideoChromaSite {
skip_assert_initialized!();
VideoChromaSite::from_bits_truncate(value.bits())
}
}
impl StaticType for VideoChromaSite {
fn static_type() -> Type {
unsafe { from_glib(ffi::gst_video_chroma_site_get_type()) }
}
}
impl<'a> FromValueOptional<'a> for VideoChromaSite {
unsafe fn from_value_optional(value: &Value) -> Option<Self> {
Some(FromValue::from_value(value))
}
}
impl<'a> FromValue<'a> for VideoChromaSite {
unsafe fn from_value(value: &Value) -> Self {
from_glib(ffi::GstVideoChromaSite::from_bits_truncate(
gobject_ffi::g_value_get_flags(value.to_glib_none().0),
))
}
}
impl SetValue for VideoChromaSite {
unsafe fn set_value(value: &mut Value, this: &Self) {
gobject_ffi::g_value_set_flags(value.to_glib_none_mut().0, this.to_glib().bits())
}
}
bitflags! {
pub struct VideoFlags: u32 {
const VIDEO_FLAG_NONE = 0;
const VIDEO_FLAG_VARIABLE_FPS = 1;
const VIDEO_FLAG_PREMULTIPLIED_ALPHA = 2;
}
}
#[doc(hidden)]
impl ToGlib for VideoFlags {
type GlibType = ffi::GstVideoFlags;
fn to_glib(&self) -> ffi::GstVideoFlags {
ffi::GstVideoFlags::from_bits_truncate(self.bits())
}
}
#[doc(hidden)]
impl FromGlib<ffi::GstVideoFlags> for VideoFlags {
fn from_glib(value: ffi::GstVideoFlags) -> VideoFlags {
skip_assert_initialized!();
VideoFlags::from_bits_truncate(value.bits())
}
}
impl StaticType for VideoFlags {
fn static_type() -> Type {
unsafe { from_glib(ffi::gst_video_flags_get_type()) }
}
}
impl<'a> FromValueOptional<'a> for VideoFlags {
unsafe fn from_value_optional(value: &Value) -> Option<Self> {
Some(FromValue::from_value(value))
}
}
impl<'a> FromValue<'a> for VideoFlags {
unsafe fn from_value(value: &Value) -> Self {
from_glib(ffi::GstVideoFlags::from_bits_truncate(
gobject_ffi::g_value_get_flags(value.to_glib_none().0),
))
}
}
impl SetValue for VideoFlags {
unsafe fn set_value(value: &mut Value, this: &Self) {
gobject_ffi::g_value_set_flags(value.to_glib_none_mut().0, this.to_glib().bits())
}
}
bitflags! {
pub struct VideoFormatFlags: u32 {
const VIDEO_FORMAT_FLAG_YUV = 1;
const VIDEO_FORMAT_FLAG_RGB = 2;
const VIDEO_FORMAT_FLAG_GRAY = 4;
const VIDEO_FORMAT_FLAG_ALPHA = 8;
const VIDEO_FORMAT_FLAG_LE = 16;
const VIDEO_FORMAT_FLAG_PALETTE = 32;
const VIDEO_FORMAT_FLAG_COMPLEX = 64;
const VIDEO_FORMAT_FLAG_UNPACK = 128;
const VIDEO_FORMAT_FLAG_TILED = 256;
}
}
#[doc(hidden)]
impl ToGlib for VideoFormatFlags {
type GlibType = ffi::GstVideoFormatFlags;
fn to_glib(&self) -> ffi::GstVideoFormatFlags {
ffi::GstVideoFormatFlags::from_bits_truncate(self.bits())
}
}
#[doc(hidden)]
impl FromGlib<ffi::GstVideoFormatFlags> for VideoFormatFlags {
fn from_glib(value: ffi::GstVideoFormatFlags) -> VideoFormatFlags {
skip_assert_initialized!();
VideoFormatFlags::from_bits_truncate(value.bits())
}
}
impl StaticType for VideoFormatFlags {
fn static_type() -> Type {
unsafe { from_glib(ffi::gst_video_format_flags_get_type()) }
}
}
impl<'a> FromValueOptional<'a> for VideoFormatFlags {
unsafe fn from_value_optional(value: &Value) -> Option<Self> {
Some(FromValue::from_value(value))
}
}
impl<'a> FromValue<'a> for VideoFormatFlags {
unsafe fn from_value(value: &Value) -> Self {
from_glib(ffi::GstVideoFormatFlags::from_bits_truncate(
gobject_ffi::g_value_get_flags(value.to_glib_none().0),
))
}
}
impl SetValue for VideoFormatFlags {
unsafe fn set_value(value: &mut Value, this: &Self) {
gobject_ffi::g_value_set_flags(value.to_glib_none_mut().0, this.to_glib().bits())
}
}

View file

@ -0,0 +1,36 @@
// This file was generated by gir (cf27827) from gir-files (???)
// DO NOT EDIT
mod enums;
pub use self::enums::VideoFormat;
pub use self::enums::VideoInterlaceMode;
pub use self::enums::VideoTileMode;
mod flags;
pub use self::flags::VideoChromaSite;
pub use self::flags::VIDEO_CHROMA_SITE_UNKNOWN;
pub use self::flags::VIDEO_CHROMA_SITE_NONE;
pub use self::flags::VIDEO_CHROMA_SITE_H_COSITED;
pub use self::flags::VIDEO_CHROMA_SITE_V_COSITED;
pub use self::flags::VIDEO_CHROMA_SITE_ALT_LINE;
pub use self::flags::VIDEO_CHROMA_SITE_COSITED;
pub use self::flags::VIDEO_CHROMA_SITE_JPEG;
pub use self::flags::VIDEO_CHROMA_SITE_MPEG2;
pub use self::flags::VIDEO_CHROMA_SITE_DV;
pub use self::flags::VideoFlags;
pub use self::flags::VIDEO_FLAG_NONE;
pub use self::flags::VIDEO_FLAG_VARIABLE_FPS;
pub use self::flags::VIDEO_FLAG_PREMULTIPLIED_ALPHA;
pub use self::flags::VideoFormatFlags;
pub use self::flags::VIDEO_FORMAT_FLAG_YUV;
pub use self::flags::VIDEO_FORMAT_FLAG_RGB;
pub use self::flags::VIDEO_FORMAT_FLAG_GRAY;
pub use self::flags::VIDEO_FORMAT_FLAG_ALPHA;
pub use self::flags::VIDEO_FORMAT_FLAG_LE;
pub use self::flags::VIDEO_FORMAT_FLAG_PALETTE;
pub use self::flags::VIDEO_FORMAT_FLAG_COMPLEX;
pub use self::flags::VIDEO_FORMAT_FLAG_UNPACK;
pub use self::flags::VIDEO_FORMAT_FLAG_TILED;
#[doc(hidden)]
pub mod traits {}

View file

@ -0,0 +1,46 @@
// 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.
#[macro_use]
extern crate bitflags;
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_video_sys as ffi;
extern crate gstreamer as gst;
#[macro_use]
extern crate glib;
macro_rules! assert_initialized_main_thread {
() => (
use gst_ffi;
assert_eq!(unsafe {gst_ffi::gst_is_initialized()}, ::glib_ffi::GTRUE)
)
}
macro_rules! skip_assert_initialized {
() => (
)
}
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 video_format;
pub use video_format::*;
mod video_format_info;
pub use video_format_info::*;

View file

@ -0,0 +1,103 @@
// 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 ffi;
use std::ffi::CStr;
use std::fmt;
use std::str;
use glib::translate::{from_glib, FromGlib, ToGlib, ToGlibPtr};
#[derive(PartialEq, Eq, Debug)]
pub enum VideoEndianness {
Unknown,
LittleEndian = 1234,
BigEndian = 4321,
}
impl FromGlib<i32> for VideoEndianness {
fn from_glib(value: i32) -> Self {
match value {
1234 => VideoEndianness::LittleEndian,
4321 => VideoEndianness::BigEndian,
_ => VideoEndianness::Unknown,
}
}
}
impl ToGlib for VideoEndianness {
type GlibType = i32;
fn to_glib(&self) -> i32 {
match *self {
VideoEndianness::LittleEndian => 1234,
VideoEndianness::BigEndian => 4321,
_ => 0,
}
}
}
impl ::VideoFormat {
pub fn from_string(s: &str) -> ::VideoFormat {
unsafe { from_glib(ffi::gst_video_format_from_string(s.to_glib_none().0)) }
}
pub fn from_fourcc(fourcc: u32) -> ::VideoFormat {
unsafe { from_glib(ffi::gst_video_format_from_fourcc(fourcc)) }
}
pub fn from_masks(
depth: u32,
bpp: u32,
endianness: ::VideoEndianness,
red_mask: u32,
blue_mask: u32,
green_mask: u32,
alpha_mask: u32,
) -> ::VideoFormat {
unsafe {
from_glib(ffi::gst_video_format_from_masks(
depth as i32,
bpp as i32,
endianness.to_glib(),
red_mask,
blue_mask,
green_mask,
alpha_mask,
))
}
}
pub fn to_string(&self) -> &'static str {
unsafe {
CStr::from_ptr(ffi::gst_video_format_to_string(self.to_glib()))
.to_str()
.unwrap()
}
}
}
impl str::FromStr for ::VideoFormat {
type Err = ();
fn from_str(s: &str) -> Result<Self, ()> {
let format = Self::from_string(s);
if format == ::VideoFormat::Unknown {
Err(())
} else {
Ok(format)
}
}
}
impl fmt::Display for ::VideoFormat {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
f.write_str(self.to_string())
}
}

View file

@ -0,0 +1,232 @@
// 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 ffi;
use std::ffi::CStr;
use std::fmt;
use std::str;
use glib;
use glib::translate::{from_glib, ToGlib};
pub struct VideoFormatInfo(&'static ffi::GstVideoFormatInfo);
impl VideoFormatInfo {
pub fn from_format(format: ::VideoFormat) -> VideoFormatInfo {
unsafe {
let info = ffi::gst_video_format_get_info(format.to_glib());
assert!(!info.is_null());
VideoFormatInfo(&*info)
}
}
pub fn format(&self) -> ::VideoFormat {
from_glib(self.0.format)
}
pub fn name(&self) -> &'static str {
unsafe { CStr::from_ptr(self.0.name).to_str().unwrap() }
}
pub fn description(&self) -> &'static str {
unsafe { CStr::from_ptr(self.0.description).to_str().unwrap() }
}
pub fn flags(&self) -> ::VideoFormatFlags {
from_glib(self.0.flags)
}
pub fn bits(&self) -> u32 {
self.0.bits
}
pub fn n_components(&self) -> u32 {
self.0.n_components
}
pub fn shift(&self) -> &[u32] {
&self.0.shift[0..(self.0.n_components as usize)]
}
pub fn depth(&self) -> &[u32] {
&self.0.depth[0..(self.0.n_components as usize)]
}
pub fn pixel_stride(&self) -> &[i32] {
&self.0.pixel_stride[0..(self.0.n_components as usize)]
}
pub fn n_planes(&self) -> u32 {
self.0.n_planes
}
pub fn plane(&self) -> &[u32] {
&self.0.plane[0..(self.0.n_components as usize)]
}
pub fn poffset(&self) -> &[u32] {
&self.0.poffset[0..(self.0.n_components as usize)]
}
pub fn w_sub(&self) -> &[u32] {
&self.0.w_sub[0..(self.0.n_components as usize)]
}
pub fn h_sub(&self) -> &[u32] {
&self.0.h_sub[0..(self.0.n_components as usize)]
}
pub fn tile_mode(&self) -> ::VideoTileMode {
from_glib(self.0.tile_mode)
}
pub fn tile_ws(&self) -> u32 {
self.0.tile_ws
}
pub fn tile_hs(&self) -> u32 {
self.0.tile_hs
}
pub fn unpack_format(&self) -> ::VideoFormat {
from_glib(self.0.unpack_format)
}
pub fn pack_lines(&self) -> i32 {
self.0.pack_lines
}
pub fn has_alpha(&self) -> bool {
self.0.flags.contains(ffi::GST_VIDEO_FORMAT_FLAG_ALPHA)
}
pub fn has_palette(&self) -> bool {
self.0.flags.contains(ffi::GST_VIDEO_FORMAT_FLAG_PALETTE)
}
pub fn is_complex(&self) -> bool {
self.0.flags.contains(ffi::GST_VIDEO_FORMAT_FLAG_COMPLEX)
}
pub fn is_gray(&self) -> bool {
self.0.flags.contains(ffi::GST_VIDEO_FORMAT_FLAG_GRAY)
}
pub fn is_le(&self) -> bool {
self.0.flags.contains(ffi::GST_VIDEO_FORMAT_FLAG_LE)
}
pub fn is_rgb(&self) -> bool {
self.0.flags.contains(ffi::GST_VIDEO_FORMAT_FLAG_RGB)
}
pub fn is_tiled(&self) -> bool {
self.0.flags.contains(ffi::GST_VIDEO_FORMAT_FLAG_TILED)
}
pub fn is_yuv(&self) -> bool {
self.0.flags.contains(ffi::GST_VIDEO_FORMAT_FLAG_YUV)
}
pub fn scale_width(&self, component: u8, width: u32) -> u32 {
(-((-(width as i64)) >> self.w_sub()[component as usize])) as u32
}
pub fn scale_height(&self, component: u8, height: u32) -> u32 {
(-((-(height as i64)) >> self.h_sub()[component as usize])) as u32
}
// TODO: pack/unpack
}
unsafe impl Sync for VideoFormatInfo {}
unsafe impl Send for VideoFormatInfo {}
impl PartialEq for VideoFormatInfo {
fn eq(&self, other: &Self) -> bool {
self.format() == other.format()
}
}
impl Eq for VideoFormatInfo {}
impl fmt::Debug for VideoFormatInfo {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
f.write_str(self.name())
}
}
impl fmt::Display for VideoFormatInfo {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
f.write_str(self.name())
}
}
impl str::FromStr for ::VideoFormatInfo {
type Err = ();
fn from_str(s: &str) -> Result<Self, ()> {
let format = s.parse()?;
Ok(VideoFormatInfo::from_format(format))
}
}
impl From<::VideoFormat> for VideoFormatInfo {
fn from(f: ::VideoFormat) -> Self {
Self::from_format(f)
}
}
#[doc(hidden)]
impl glib::translate::GlibPtrDefault for VideoFormatInfo {
type GlibType = *mut ffi::GstVideoFormatInfo;
}
#[doc(hidden)]
impl<'a> glib::translate::ToGlibPtr<'a, *const ffi::GstVideoFormatInfo> for VideoFormatInfo {
type Storage = &'a VideoFormatInfo;
fn to_glib_none(&'a self) -> glib::translate::Stash<'a, *const ffi::GstVideoFormatInfo, Self> {
glib::translate::Stash(self.0, self)
}
fn to_glib_full(&self) -> *const ffi::GstVideoFormatInfo {
unimplemented!()
}
}
#[doc(hidden)]
impl glib::translate::FromGlibPtrNone<*mut ffi::GstVideoFormatInfo> for VideoFormatInfo {
#[inline]
unsafe fn from_glib_none(ptr: *mut ffi::GstVideoFormatInfo) -> Self {
VideoFormatInfo(&*ptr)
}
}
#[cfg(test)]
mod tests {
use super::*;
use gst;
#[test]
fn test_get() {
gst::init().unwrap();
let info = VideoFormatInfo::from_format(::VideoFormat::I420);
assert_eq!(info.name(), "I420");
let other_info = "I420".parse().unwrap();
assert_eq!(info, other_info);
assert_eq!(info.scale_width(0, 128), 128);
assert_eq!(info.scale_width(1, 128), 64);
assert_eq!(info.scale_width(2, 128), 64);
}
}