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
use ffi::*;
use std::mem;
use std::slice::{self,from_raw_parts,from_raw_parts_mut};

pub type MapInfo = GstMapInfo;

impl MapInfo{
    #[inline]
    pub fn size(&self) -> u64{
        self.size as u64
    }

    #[inline]
    pub fn data<'a,T>(&self) -> &'a [T]{
        unsafe{ from_raw_parts( mem::transmute(self.data), self.len::<T>() ) }
    }

    #[inline]
    pub fn data_mut<'a,T>(&mut self) -> &'a mut [T]{
        unsafe{ from_raw_parts_mut( mem::transmute(self.data), self.len::<T>() ) }
    }

    #[inline]
    pub fn iter<'a,T>(&'a self) -> slice::Iter<'a,T>{
		self.data::<T>().iter()
	}

    #[inline]
    pub fn iter_mut<'a,T>(&'a mut self) -> slice::IterMut<'a,T>{
		self.data_mut::<T>().iter_mut()
	}

    #[inline]
	pub fn len<T>(&self) -> usize{
		(self.size() / mem::size_of::<T>() as u64)  as usize
	}
}

#[derive(Clone,Copy)]
pub enum Map{
	Read = GST_MAP_READ as isize,
	Write = GST_MAP_WRITE as isize
}