mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-11-26 19:41:09 +00:00
Add test for pad tasks
This commit is contained in:
parent
c471a67e78
commit
f4958b71d7
1 changed files with 33 additions and 8 deletions
|
@ -22,6 +22,7 @@ use std::ptr;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
|
|
||||||
|
use glib;
|
||||||
use glib::{IsA, StaticType};
|
use glib::{IsA, StaticType};
|
||||||
use glib::translate::{from_glib, from_glib_borrow, from_glib_full, from_glib_none, FromGlib,
|
use glib::translate::{from_glib, from_glib_borrow, from_glib_full, from_glib_none, FromGlib,
|
||||||
ToGlib, ToGlibPtr};
|
ToGlib, ToGlibPtr};
|
||||||
|
@ -168,7 +169,7 @@ pub trait PadExtManual {
|
||||||
where
|
where
|
||||||
F: Fn(&Pad, &Option<::Object>) + Send + Sync + 'static;
|
F: Fn(&Pad, &Option<::Object>) + Send + Sync + 'static;
|
||||||
|
|
||||||
fn start_task<F: FnMut() + Send + 'static>(&self, func: F) -> bool;
|
fn start_task<F: FnMut() + Send + 'static>(&self, func: F) -> Result<(), glib::BoolError>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<O: IsA<Pad>> PadExtManual for O {
|
impl<O: IsA<Pad>> PadExtManual for O {
|
||||||
|
@ -570,14 +571,17 @@ impl<O: IsA<Pad>> PadExtManual for O {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start_task<F: FnMut() + Send + 'static>(&self, func: F) -> bool {
|
fn start_task<F: FnMut() + Send + 'static>(&self, func: F) -> Result<(), glib::BoolError> {
|
||||||
unsafe {
|
unsafe {
|
||||||
from_glib(ffi::gst_pad_start_task(
|
glib::error::BoolError::from_glib(
|
||||||
self.to_glib_none().0,
|
ffi::gst_pad_start_task(
|
||||||
Some(trampoline_pad_task),
|
self.to_glib_none().0,
|
||||||
into_raw_pad_task(func),
|
Some(trampoline_pad_task),
|
||||||
Some(destroy_closure_pad_task),
|
into_raw_pad_task(func),
|
||||||
))
|
Some(destroy_closure_pad_task),
|
||||||
|
),
|
||||||
|
"Failed to start pad task",
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -921,6 +925,7 @@ mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use prelude::*;
|
use prelude::*;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
use std::sync::mpsc::channel;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_event_chain_functions() {
|
fn test_event_chain_functions() {
|
||||||
|
@ -970,4 +975,24 @@ mod tests {
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_task() {
|
||||||
|
::init().unwrap();
|
||||||
|
|
||||||
|
let pad = ::Pad::new("sink", ::PadDirection::Sink);
|
||||||
|
let (sender, receiver) = channel();
|
||||||
|
|
||||||
|
let mut i = 0;
|
||||||
|
let pad_clone = pad.clone();
|
||||||
|
pad.start_task(move || {
|
||||||
|
i += 1;
|
||||||
|
if i == 3 {
|
||||||
|
sender.send(i).unwrap();
|
||||||
|
pad_clone.pause_task().unwrap();
|
||||||
|
}
|
||||||
|
}).unwrap();
|
||||||
|
|
||||||
|
assert_eq!(receiver.recv().unwrap(), 3);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue