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:
Sebastian Dröge 2017-08-30 12:48:01 +03:00
parent da1a0c31d8
commit f05df73088
8 changed files with 55 additions and 1 deletions

View file

@ -29,6 +29,8 @@ impl AppSinkCallbacks {
G: Fn(&AppSink) -> gst::FlowReturn + Send + Sync + 'static,
H: Fn(&AppSink) -> gst::FlowReturn + Send + Sync + 'static,
{
skip_assert_initialized!();
AppSinkCallbacks {
eos: Box::new(eos),
new_preroll: Box::new(new_preroll),

View file

@ -28,6 +28,8 @@ impl AppSrcCallbacks {
G: Fn(&AppSrc) + Send + Sync + 'static,
H: Fn(&AppSrc, u64) -> bool + Send + Sync + 'static,
{
skip_assert_initialized!();
AppSrcCallbacks {
need_data: Box::new(need_data),
enough_data: Box::new(enough_data),

View file

@ -18,6 +18,14 @@ extern crate gstreamer as gst;
#[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.");
}
)
}
macro_rules! skip_assert_initialized {
() => (
)

View file

@ -23,6 +23,8 @@ pub enum VideoEndianness {
impl FromGlib<i32> for VideoEndianness {
fn from_glib(value: i32) -> Self {
skip_assert_initialized!();
match value {
1234 => VideoEndianness::LittleEndian,
4321 => VideoEndianness::BigEndian,
@ -45,10 +47,14 @@ impl ToGlib for VideoEndianness {
impl ::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)) }
}
pub fn from_fourcc(fourcc: u32) -> ::VideoFormat {
assert_initialized_main_thread!();
unsafe { from_glib(ffi::gst_video_format_from_fourcc(fourcc)) }
}
@ -61,6 +67,8 @@ impl ::VideoFormat {
green_mask: u32,
alpha_mask: u32,
) -> ::VideoFormat {
assert_initialized_main_thread!();
unsafe {
from_glib(ffi::gst_video_format_from_masks(
depth as i32,
@ -87,6 +95,8 @@ impl str::FromStr for ::VideoFormat {
type Err = ();
fn from_str(s: &str) -> Result<Self, ()> {
skip_assert_initialized!();
let format = Self::from_string(s);
if format == ::VideoFormat::Unknown {
Err(())

View file

@ -19,6 +19,8 @@ pub struct VideoFormatInfo(&'static ffi::GstVideoFormatInfo);
impl VideoFormatInfo {
pub fn from_format(format: ::VideoFormat) -> VideoFormatInfo {
assert_initialized_main_thread!();
unsafe {
let info = ffi::gst_video_format_get_info(format.to_glib());
assert!(!info.is_null());
@ -173,6 +175,7 @@ impl str::FromStr for ::VideoFormatInfo {
type Err = ();
fn from_str(s: &str) -> Result<Self, ()> {
skip_assert_initialized!();
let format = s.parse()?;
Ok(VideoFormatInfo::from_format(format))
}
@ -180,6 +183,7 @@ impl str::FromStr for ::VideoFormatInfo {
impl From<::VideoFormat> for VideoFormatInfo {
fn from(f: ::VideoFormat) -> Self {
skip_assert_initialized!();
Self::from_format(f)
}
}

View file

@ -74,6 +74,8 @@ impl<T> VideoFrame<T> {
dest: &mut VideoFrame<Writable>,
plane: u32,
) -> Result<(), glib::BoolError> {
skip_assert_initialized!();
unsafe {
let res: bool = from_glib(ffi::gst_video_frame_copy_plane(&mut dest.0, &self.0, plane));
if res {
@ -177,6 +179,8 @@ impl VideoFrame<Readable> {
buffer: gst::Buffer,
info: &::VideoInfo,
) -> Result<VideoFrame<Readable>, gst::Buffer> {
assert_initialized_main_thread!();
unsafe {
let mut frame = mem::zeroed();
let res: bool = from_glib(ffi::gst_video_frame_map(
@ -202,6 +206,8 @@ impl VideoFrame<Readable> {
id: i32,
info: &::VideoInfo,
) -> Result<VideoFrame<Readable>, gst::Buffer> {
assert_initialized_main_thread!();
unsafe {
let mut frame = mem::zeroed();
let res: bool = from_glib(ffi::gst_video_frame_map_id(
@ -233,6 +239,8 @@ impl VideoFrame<Writable> {
buffer: gst::Buffer,
info: &::VideoInfo,
) -> Result<VideoFrame<Writable>, gst::Buffer> {
assert_initialized_main_thread!();
unsafe {
let mut frame = mem::zeroed();
let res: bool = from_glib(ffi::gst_video_frame_map(
@ -259,6 +267,8 @@ impl VideoFrame<Writable> {
id: i32,
info: &::VideoInfo,
) -> Result<VideoFrame<Writable>, gst::Buffer> {
assert_initialized_main_thread!();
unsafe {
let mut frame = mem::zeroed();
let res: bool = from_glib(ffi::gst_video_frame_map_id(

View file

@ -92,6 +92,7 @@ impl VideoColorimetry {
transfer: ::VideoTransferFunction,
primaries: ::VideoColorPrimaries,
) -> Self {
assert_initialized_main_thread!();
let colorimetry = unsafe {
let mut colorimetry: ffi::GstVideoColorimetry = mem::zeroed();
@ -112,6 +113,8 @@ impl VideoColorimetry {
}
pub fn from_string(s: &str) -> Option<Self> {
assert_initialized_main_thread!();
unsafe {
let mut colorimetry = mem::zeroed();
let valid: bool = from_glib(ffi::gst_video_colorimetry_from_string(
@ -145,6 +148,7 @@ impl str::FromStr for ::VideoColorimetry {
type Err = ();
fn from_str(s: &str) -> Result<Self, ()> {
skip_assert_initialized!();
Self::from_string(s).ok_or(())
}
}
@ -370,6 +374,8 @@ impl<'a> VideoInfoBuilder<'a> {
impl VideoInfo {
pub fn new<'a>(format: ::VideoFormat, width: u32, height: u32) -> VideoInfoBuilder<'a> {
assert_initialized_main_thread!();
#[cfg(not(feature = "v1_12"))]
{
VideoInfoBuilder {
@ -414,6 +420,8 @@ impl VideoInfo {
}
pub fn from_caps(caps: &gst::Caps) -> Option<Self> {
assert_initialized_main_thread!();
unsafe {
let mut info = mem::uninitialized();
if from_glib(ffi::gst_video_info_from_caps(&mut info, caps.as_ptr())) {
@ -547,6 +555,8 @@ impl VideoInfo {
src_val: i64,
dest_fmt: gst::Format,
) -> Option<i64> {
skip_assert_initialized!();
unsafe {
let mut dest_val = mem::uninitialized();
if from_glib(ffi::gst_video_info_convert(
@ -668,6 +678,8 @@ impl ::VideoFieldOrder {
}
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)) }
}
}
@ -677,6 +689,7 @@ impl str::FromStr for ::VideoFieldOrder {
type Err = ();
fn from_str(s: &str) -> Result<Self, ()> {
skip_assert_initialized!();
Ok(Self::from_string(s))
}
}
@ -694,6 +707,8 @@ impl ::VideoInterlaceMode {
}
pub fn from_string(s: &str) -> Self {
assert_initialized_main_thread!();
unsafe {
from_glib(ffi::gst_video_interlace_mode_from_string(
s.to_glib_none().0,
@ -706,6 +721,7 @@ impl str::FromStr for ::VideoInterlaceMode {
type Err = ();
fn from_str(s: &str) -> Result<Self, ()> {
skip_assert_initialized!();
Ok(Self::from_string(s))
}
}

View file

@ -35,7 +35,9 @@ macro_rules! callback_guard {
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.");
}
)
}