mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-12-23 00:26:31 +00:00
Add various gst_init() assertions to video/app bindings
audio and core should come next. Also print something more meaningful than using assert_eq!().
This commit is contained in:
parent
da1a0c31d8
commit
f05df73088
8 changed files with 55 additions and 1 deletions
|
@ -29,6 +29,8 @@ impl AppSinkCallbacks {
|
||||||
G: Fn(&AppSink) -> gst::FlowReturn + Send + Sync + 'static,
|
G: Fn(&AppSink) -> gst::FlowReturn + Send + Sync + 'static,
|
||||||
H: Fn(&AppSink) -> gst::FlowReturn + Send + Sync + 'static,
|
H: Fn(&AppSink) -> gst::FlowReturn + Send + Sync + 'static,
|
||||||
{
|
{
|
||||||
|
skip_assert_initialized!();
|
||||||
|
|
||||||
AppSinkCallbacks {
|
AppSinkCallbacks {
|
||||||
eos: Box::new(eos),
|
eos: Box::new(eos),
|
||||||
new_preroll: Box::new(new_preroll),
|
new_preroll: Box::new(new_preroll),
|
||||||
|
|
|
@ -28,6 +28,8 @@ impl AppSrcCallbacks {
|
||||||
G: Fn(&AppSrc) + Send + Sync + 'static,
|
G: Fn(&AppSrc) + Send + Sync + 'static,
|
||||||
H: Fn(&AppSrc, u64) -> bool + Send + Sync + 'static,
|
H: Fn(&AppSrc, u64) -> bool + Send + Sync + 'static,
|
||||||
{
|
{
|
||||||
|
skip_assert_initialized!();
|
||||||
|
|
||||||
AppSrcCallbacks {
|
AppSrcCallbacks {
|
||||||
need_data: Box::new(need_data),
|
need_data: Box::new(need_data),
|
||||||
enough_data: Box::new(enough_data),
|
enough_data: Box::new(enough_data),
|
||||||
|
|
|
@ -18,6 +18,14 @@ extern crate gstreamer as gst;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate glib;
|
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.");
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
macro_rules! skip_assert_initialized {
|
macro_rules! skip_assert_initialized {
|
||||||
() => (
|
() => (
|
||||||
)
|
)
|
||||||
|
|
|
@ -23,6 +23,8 @@ pub enum VideoEndianness {
|
||||||
|
|
||||||
impl FromGlib<i32> for VideoEndianness {
|
impl FromGlib<i32> for VideoEndianness {
|
||||||
fn from_glib(value: i32) -> Self {
|
fn from_glib(value: i32) -> Self {
|
||||||
|
skip_assert_initialized!();
|
||||||
|
|
||||||
match value {
|
match value {
|
||||||
1234 => VideoEndianness::LittleEndian,
|
1234 => VideoEndianness::LittleEndian,
|
||||||
4321 => VideoEndianness::BigEndian,
|
4321 => VideoEndianness::BigEndian,
|
||||||
|
@ -45,10 +47,14 @@ impl ToGlib for VideoEndianness {
|
||||||
|
|
||||||
impl ::VideoFormat {
|
impl ::VideoFormat {
|
||||||
pub fn from_string(s: &str) -> ::VideoFormat {
|
pub fn from_string(s: &str) -> ::VideoFormat {
|
||||||
|
assert_initialized_main_thread!();
|
||||||
|
|
||||||
unsafe { from_glib(ffi::gst_video_format_from_string(s.to_glib_none().0)) }
|
unsafe { from_glib(ffi::gst_video_format_from_string(s.to_glib_none().0)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_fourcc(fourcc: u32) -> ::VideoFormat {
|
pub fn from_fourcc(fourcc: u32) -> ::VideoFormat {
|
||||||
|
assert_initialized_main_thread!();
|
||||||
|
|
||||||
unsafe { from_glib(ffi::gst_video_format_from_fourcc(fourcc)) }
|
unsafe { from_glib(ffi::gst_video_format_from_fourcc(fourcc)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,6 +67,8 @@ impl ::VideoFormat {
|
||||||
green_mask: u32,
|
green_mask: u32,
|
||||||
alpha_mask: u32,
|
alpha_mask: u32,
|
||||||
) -> ::VideoFormat {
|
) -> ::VideoFormat {
|
||||||
|
assert_initialized_main_thread!();
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
from_glib(ffi::gst_video_format_from_masks(
|
from_glib(ffi::gst_video_format_from_masks(
|
||||||
depth as i32,
|
depth as i32,
|
||||||
|
@ -87,6 +95,8 @@ impl str::FromStr for ::VideoFormat {
|
||||||
type Err = ();
|
type Err = ();
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self, ()> {
|
fn from_str(s: &str) -> Result<Self, ()> {
|
||||||
|
skip_assert_initialized!();
|
||||||
|
|
||||||
let format = Self::from_string(s);
|
let format = Self::from_string(s);
|
||||||
if format == ::VideoFormat::Unknown {
|
if format == ::VideoFormat::Unknown {
|
||||||
Err(())
|
Err(())
|
||||||
|
|
|
@ -19,6 +19,8 @@ pub struct VideoFormatInfo(&'static ffi::GstVideoFormatInfo);
|
||||||
|
|
||||||
impl VideoFormatInfo {
|
impl VideoFormatInfo {
|
||||||
pub fn from_format(format: ::VideoFormat) -> VideoFormatInfo {
|
pub fn from_format(format: ::VideoFormat) -> VideoFormatInfo {
|
||||||
|
assert_initialized_main_thread!();
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let info = ffi::gst_video_format_get_info(format.to_glib());
|
let info = ffi::gst_video_format_get_info(format.to_glib());
|
||||||
assert!(!info.is_null());
|
assert!(!info.is_null());
|
||||||
|
@ -173,6 +175,7 @@ impl str::FromStr for ::VideoFormatInfo {
|
||||||
type Err = ();
|
type Err = ();
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self, ()> {
|
fn from_str(s: &str) -> Result<Self, ()> {
|
||||||
|
skip_assert_initialized!();
|
||||||
let format = s.parse()?;
|
let format = s.parse()?;
|
||||||
Ok(VideoFormatInfo::from_format(format))
|
Ok(VideoFormatInfo::from_format(format))
|
||||||
}
|
}
|
||||||
|
@ -180,6 +183,7 @@ impl str::FromStr for ::VideoFormatInfo {
|
||||||
|
|
||||||
impl From<::VideoFormat> for VideoFormatInfo {
|
impl From<::VideoFormat> for VideoFormatInfo {
|
||||||
fn from(f: ::VideoFormat) -> Self {
|
fn from(f: ::VideoFormat) -> Self {
|
||||||
|
skip_assert_initialized!();
|
||||||
Self::from_format(f)
|
Self::from_format(f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,6 +74,8 @@ impl<T> VideoFrame<T> {
|
||||||
dest: &mut VideoFrame<Writable>,
|
dest: &mut VideoFrame<Writable>,
|
||||||
plane: u32,
|
plane: u32,
|
||||||
) -> Result<(), glib::BoolError> {
|
) -> Result<(), glib::BoolError> {
|
||||||
|
skip_assert_initialized!();
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let res: bool = from_glib(ffi::gst_video_frame_copy_plane(&mut dest.0, &self.0, plane));
|
let res: bool = from_glib(ffi::gst_video_frame_copy_plane(&mut dest.0, &self.0, plane));
|
||||||
if res {
|
if res {
|
||||||
|
@ -177,6 +179,8 @@ impl VideoFrame<Readable> {
|
||||||
buffer: gst::Buffer,
|
buffer: gst::Buffer,
|
||||||
info: &::VideoInfo,
|
info: &::VideoInfo,
|
||||||
) -> Result<VideoFrame<Readable>, gst::Buffer> {
|
) -> Result<VideoFrame<Readable>, gst::Buffer> {
|
||||||
|
assert_initialized_main_thread!();
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut frame = mem::zeroed();
|
let mut frame = mem::zeroed();
|
||||||
let res: bool = from_glib(ffi::gst_video_frame_map(
|
let res: bool = from_glib(ffi::gst_video_frame_map(
|
||||||
|
@ -202,6 +206,8 @@ impl VideoFrame<Readable> {
|
||||||
id: i32,
|
id: i32,
|
||||||
info: &::VideoInfo,
|
info: &::VideoInfo,
|
||||||
) -> Result<VideoFrame<Readable>, gst::Buffer> {
|
) -> Result<VideoFrame<Readable>, gst::Buffer> {
|
||||||
|
assert_initialized_main_thread!();
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut frame = mem::zeroed();
|
let mut frame = mem::zeroed();
|
||||||
let res: bool = from_glib(ffi::gst_video_frame_map_id(
|
let res: bool = from_glib(ffi::gst_video_frame_map_id(
|
||||||
|
@ -233,6 +239,8 @@ impl VideoFrame<Writable> {
|
||||||
buffer: gst::Buffer,
|
buffer: gst::Buffer,
|
||||||
info: &::VideoInfo,
|
info: &::VideoInfo,
|
||||||
) -> Result<VideoFrame<Writable>, gst::Buffer> {
|
) -> Result<VideoFrame<Writable>, gst::Buffer> {
|
||||||
|
assert_initialized_main_thread!();
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut frame = mem::zeroed();
|
let mut frame = mem::zeroed();
|
||||||
let res: bool = from_glib(ffi::gst_video_frame_map(
|
let res: bool = from_glib(ffi::gst_video_frame_map(
|
||||||
|
@ -259,6 +267,8 @@ impl VideoFrame<Writable> {
|
||||||
id: i32,
|
id: i32,
|
||||||
info: &::VideoInfo,
|
info: &::VideoInfo,
|
||||||
) -> Result<VideoFrame<Writable>, gst::Buffer> {
|
) -> Result<VideoFrame<Writable>, gst::Buffer> {
|
||||||
|
assert_initialized_main_thread!();
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut frame = mem::zeroed();
|
let mut frame = mem::zeroed();
|
||||||
let res: bool = from_glib(ffi::gst_video_frame_map_id(
|
let res: bool = from_glib(ffi::gst_video_frame_map_id(
|
||||||
|
|
|
@ -92,6 +92,7 @@ impl VideoColorimetry {
|
||||||
transfer: ::VideoTransferFunction,
|
transfer: ::VideoTransferFunction,
|
||||||
primaries: ::VideoColorPrimaries,
|
primaries: ::VideoColorPrimaries,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
assert_initialized_main_thread!();
|
||||||
|
|
||||||
let colorimetry = unsafe {
|
let colorimetry = unsafe {
|
||||||
let mut colorimetry: ffi::GstVideoColorimetry = mem::zeroed();
|
let mut colorimetry: ffi::GstVideoColorimetry = mem::zeroed();
|
||||||
|
@ -112,6 +113,8 @@ impl VideoColorimetry {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_string(s: &str) -> Option<Self> {
|
pub fn from_string(s: &str) -> Option<Self> {
|
||||||
|
assert_initialized_main_thread!();
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut colorimetry = mem::zeroed();
|
let mut colorimetry = mem::zeroed();
|
||||||
let valid: bool = from_glib(ffi::gst_video_colorimetry_from_string(
|
let valid: bool = from_glib(ffi::gst_video_colorimetry_from_string(
|
||||||
|
@ -145,6 +148,7 @@ impl str::FromStr for ::VideoColorimetry {
|
||||||
type Err = ();
|
type Err = ();
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self, ()> {
|
fn from_str(s: &str) -> Result<Self, ()> {
|
||||||
|
skip_assert_initialized!();
|
||||||
Self::from_string(s).ok_or(())
|
Self::from_string(s).ok_or(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -370,6 +374,8 @@ impl<'a> VideoInfoBuilder<'a> {
|
||||||
|
|
||||||
impl VideoInfo {
|
impl VideoInfo {
|
||||||
pub fn new<'a>(format: ::VideoFormat, width: u32, height: u32) -> VideoInfoBuilder<'a> {
|
pub fn new<'a>(format: ::VideoFormat, width: u32, height: u32) -> VideoInfoBuilder<'a> {
|
||||||
|
assert_initialized_main_thread!();
|
||||||
|
|
||||||
#[cfg(not(feature = "v1_12"))]
|
#[cfg(not(feature = "v1_12"))]
|
||||||
{
|
{
|
||||||
VideoInfoBuilder {
|
VideoInfoBuilder {
|
||||||
|
@ -414,6 +420,8 @@ impl VideoInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_caps(caps: &gst::Caps) -> Option<Self> {
|
pub fn from_caps(caps: &gst::Caps) -> Option<Self> {
|
||||||
|
assert_initialized_main_thread!();
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut info = mem::uninitialized();
|
let mut info = mem::uninitialized();
|
||||||
if from_glib(ffi::gst_video_info_from_caps(&mut info, caps.as_ptr())) {
|
if from_glib(ffi::gst_video_info_from_caps(&mut info, caps.as_ptr())) {
|
||||||
|
@ -547,6 +555,8 @@ impl VideoInfo {
|
||||||
src_val: i64,
|
src_val: i64,
|
||||||
dest_fmt: gst::Format,
|
dest_fmt: gst::Format,
|
||||||
) -> Option<i64> {
|
) -> Option<i64> {
|
||||||
|
skip_assert_initialized!();
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut dest_val = mem::uninitialized();
|
let mut dest_val = mem::uninitialized();
|
||||||
if from_glib(ffi::gst_video_info_convert(
|
if from_glib(ffi::gst_video_info_convert(
|
||||||
|
@ -668,6 +678,8 @@ impl ::VideoFieldOrder {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_string(s: &str) -> Self {
|
pub fn from_string(s: &str) -> Self {
|
||||||
|
assert_initialized_main_thread!();
|
||||||
|
|
||||||
unsafe { from_glib(ffi::gst_video_field_order_from_string(s.to_glib_none().0)) }
|
unsafe { from_glib(ffi::gst_video_field_order_from_string(s.to_glib_none().0)) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -677,6 +689,7 @@ impl str::FromStr for ::VideoFieldOrder {
|
||||||
type Err = ();
|
type Err = ();
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self, ()> {
|
fn from_str(s: &str) -> Result<Self, ()> {
|
||||||
|
skip_assert_initialized!();
|
||||||
Ok(Self::from_string(s))
|
Ok(Self::from_string(s))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -694,6 +707,8 @@ impl ::VideoInterlaceMode {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_string(s: &str) -> Self {
|
pub fn from_string(s: &str) -> Self {
|
||||||
|
assert_initialized_main_thread!();
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
from_glib(ffi::gst_video_interlace_mode_from_string(
|
from_glib(ffi::gst_video_interlace_mode_from_string(
|
||||||
s.to_glib_none().0,
|
s.to_glib_none().0,
|
||||||
|
@ -706,6 +721,7 @@ impl str::FromStr for ::VideoInterlaceMode {
|
||||||
type Err = ();
|
type Err = ();
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self, ()> {
|
fn from_str(s: &str) -> Result<Self, ()> {
|
||||||
|
skip_assert_initialized!();
|
||||||
Ok(Self::from_string(s))
|
Ok(Self::from_string(s))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,9 @@ macro_rules! callback_guard {
|
||||||
|
|
||||||
macro_rules! assert_initialized_main_thread {
|
macro_rules! assert_initialized_main_thread {
|
||||||
() => (
|
() => (
|
||||||
assert_eq!(unsafe {ffi::gst_is_initialized()}, ::glib_ffi::GTRUE)
|
if unsafe {::ffi::gst_is_initialized()} != ::glib_ffi::GTRUE {
|
||||||
|
panic!("GStreamer has not been initialized. Call `gst::init` first.");
|
||||||
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue