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 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
use ffi::*; use std::os::raw::c_void; use util::*; use std::ops::{Deref, DerefMut}; use structure::Structure; use reference::Reference; use object::{Property, FromProperty}; use miniobject::MiniObject; use object::Object; #[derive(Clone)] pub struct Caps{ caps: MiniObject } impl Caps{ pub unsafe fn new(caps: *mut GstCaps) -> Option<Caps>{ MiniObject::new_from_gst_miniobject(caps as *mut GstMiniObject) .map(|miniobject| Caps{ caps: miniobject }) } pub fn new_empty() -> Caps{ unsafe{ Caps::new(gst_caps_new_empty()).unwrap() } } pub fn new_empty_simple(media_type: &str) -> Caps{ unsafe{ let cmedia_type = CString::new(media_type).unwrap(); Caps::new(gst_caps_new_empty_simple(cmedia_type.as_ptr())).unwrap() } } pub fn new_any() -> Caps{ unsafe{ Caps::new(gst_caps_new_any()).unwrap() } } pub fn is_writable(&self) -> bool{ unsafe{ gst_mini_object_is_writable(self.caps.gst_miniobject())!=0 } } pub fn from_string(desc: &str) -> Option<Caps>{ let cdesc = CString::new(desc).unwrap(); unsafe{ Caps::new(gst_caps_from_string(mem::transmute(cdesc.as_ptr()))) } } pub fn to_string(&self) -> &str{ unsafe{ from_c_str!(gst_caps_to_string(self.gst_caps())) } } pub fn video_info(&self) -> Option<::VideoInfo>{ unsafe{ let videoinfo = mem::zeroed(); if gst_video_info_from_caps (mem::transmute(&videoinfo), self.gst_caps()) == 1 { Some(videoinfo) }else{ None } } } pub unsafe fn gst_caps(&self) -> *const GstCaps{ self.caps.gst_miniobject() as *const GstCaps } pub unsafe fn gst_caps_mut(&mut self) -> *mut GstCaps{ self.caps.gst_miniobject_mut() as *mut GstCaps } pub fn structure(&self, index: u32) -> Option<Structure>{ unsafe{ let structure = gst_caps_get_structure(self.gst_caps(), index); Structure::new_from_gst_structure(structure) } } } impl ::Transfer<GstCaps> for Caps{ unsafe fn transfer(self) -> *mut GstCaps{ self.caps.transfer() as *mut GstCaps } } impl Reference for Caps{ fn reference(&self) -> Caps{ Caps{ caps: self.caps.reference() } } } impl<'a> Property for &'a Caps{ type Target = *mut GstCaps; #[inline] fn set_to(&self, key: &str, e: &mut Object){ let cname = CString::new(key).unwrap(); unsafe{ g_object_set(e.gst_object() as *mut c_void, cname.as_ptr(), self.gst_caps(), ptr::null::<gchar>()); } } } impl Property for Caps{ type Target = *mut GstCaps; #[inline] fn set_to(&self, key: &str, e: &mut Object){ let cname = CString::new(key).unwrap(); unsafe{ g_object_set(e.gst_object() as *mut c_void, cname.as_ptr(), self.gst_caps(), ptr::null::<gchar>()); } } } impl<'a> FromProperty for Caps{ fn from_property(caps: *mut GstCaps) -> Caps{ unsafe{ Caps::new(caps).unwrap() } } } impl PartialEq for Caps{ fn eq(&self, other: &Caps) -> bool{ unsafe{ gst_caps_is_equal(mem::transmute(self), mem::transmute(other)) != 0 } } } impl Eq for Caps{} impl AsRef<MiniObject> for Caps{ fn as_ref(&self) -> &MiniObject{ &self.caps } } impl AsMut<MiniObject> for Caps{ fn as_mut(&mut self) -> &mut MiniObject{ &mut self.caps } } impl From<Caps> for MiniObject{ fn from(b: Caps) -> MiniObject{ b.caps } } impl Deref for Caps{ type Target = MiniObject; fn deref(&self) -> &MiniObject{ &self.caps } } impl DerefMut for Caps{ fn deref_mut(&mut self) -> &mut MiniObject{ &mut self.caps } }