1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
use ffi::*; use caps::Caps; use reference::Reference; use object::Object; use std::ptr; use std::mem; use std::ops::{Deref, DerefMut}; pub struct Pad{ pad: Object } #[derive(Debug)] #[repr(isize)] pub enum LinkReturn{ WrongHierarchy = GST_PAD_LINK_WRONG_HIERARCHY as isize, WasLinked = GST_PAD_LINK_WAS_LINKED as isize, WrongDirection = GST_PAD_LINK_WRONG_DIRECTION as isize, NoFormat = GST_PAD_LINK_NOFORMAT as isize, NoSched = GST_PAD_LINK_NOSCHED as isize, Refused = GST_PAD_LINK_REFUSED as isize, } impl Pad{ pub unsafe fn new(pad: *mut GstPad) -> Option<Pad>{ Object::new(pad as *mut GstObject).map(|obj| Pad{ pad: obj }) } pub fn link(&mut self, sink: &mut Pad) -> Result<(), LinkReturn>{ unsafe{ let ret = gst_pad_link(self.gst_pad_mut(), sink.gst_pad_mut()); if ret == GST_PAD_LINK_OK{ Ok(()) }else{ Err(mem::transmute(ret as isize)) } } } pub fn is_linked(&self) -> bool{ unsafe{ let pad: &mut GstPad = mem::transmute(self.gst_pad()); pad.peer != ptr::null_mut() } } pub fn query_caps(&self, filter: Option<Caps>) -> Option<Caps>{ unsafe{ let caps = gst_pad_query_caps(self.gst_pad() as *mut GstPad, filter.map(|mut caps| caps.gst_caps_mut()).unwrap_or(ptr::null_mut())); Caps::new(caps) } } pub unsafe fn gst_pad(&self) -> *const GstPad{ self.pad.gst_object() as *const GstPad } pub unsafe fn gst_pad_mut(&mut self) -> *mut GstPad{ self.pad.gst_object_mut() as *mut GstPad } } impl ::Transfer<GstPad> for Pad{ unsafe fn transfer(self) -> *mut GstPad{ self.pad.transfer() as *mut GstPad } } impl Reference for Pad{ fn reference(&self) -> Pad{ Pad{ pad: self.pad.reference() } } } impl AsRef<Object> for Pad{ fn as_ref(&self) -> &Object{ &self.pad } } impl AsMut<Object> for Pad{ fn as_mut(&mut self) -> &mut Object{ &mut self.pad } } impl From<Pad> for Object{ fn from(b: Pad) -> Object{ b.pad } } impl Deref for Pad{ type Target = Object; fn deref(&self) -> &Object{ &self.pad } } impl DerefMut for Pad{ fn deref_mut(&mut self) -> &mut Object{ &mut self.pad } }