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
use ffi::*;
use ::Transfer;
use ::Element;
use ::Caps;
use std::mem;
use reference::Reference;

use std::ops::{Deref, DerefMut};

pub struct AppSrc{
    appsrc: ::Element
}

unsafe impl Sync for AppSrc {}
unsafe impl Send for AppSrc {}

impl AppSrc{
    pub fn new(name: &str) -> Option<AppSrc>{
        let appsrc = ::Element::new("appsrc",name);
        match appsrc{
            Some(appsrc) => Some(AppSrc{appsrc: appsrc}),
            None => None
        }
    }

    pub fn new_from_element(element: ::Element) -> AppSrc{
        AppSrc{appsrc: element}
    }

    /// Set the capabilities on the `AppSrc`. After calling this method, the source will only
    /// produce caps that match `caps`. Once caps is set, the caps on the buffers MUST either
    /// match the caps OR be left unspecified.
    ///
    /// Before operating an `AppSrc`, the `caps` property MUST be set to fixed caps describing
    /// the format of the data that will be pushed with appsrc EXCEPT when pushing buffers with
    /// unknown caps, in which case no caps should be set. This is typically true of file-like
    /// sources that push raw byte buffers.
    pub fn set_caps(&mut self, caps: &Caps){
        unsafe{
            gst_app_src_set_caps(self.gst_appsrc_mut(), caps.gst_caps());
        }
    }

    pub fn caps(&self) -> Option<Caps>{
        unsafe{
	        let gst_caps = gst_app_src_get_caps(mem::transmute(self.gst_appsrc()));
	        Caps::new(gst_caps)
	    }
    }

    pub fn latency(&self) -> (u64,u64){
        unsafe{
            let mut min: u64 = 0;
            let mut max: u64 = 0;
            gst_app_src_get_latency(mem::transmute(self.gst_appsrc()), &mut min, &mut max);
            (min,max)
        }
    }

    pub fn push_buffer(&mut self, buffer: ::Buffer) -> GstFlowReturn{
        unsafe{
            gst_app_src_push_buffer(self.gst_appsrc_mut(), buffer.transfer())
        }
    }

    pub fn end_of_stream(&mut self) -> GstFlowReturn{
        unsafe{
            gst_app_src_end_of_stream(self.gst_appsrc_mut())
        }
    }

    pub unsafe fn gst_appsrc(&self) -> *const GstAppSrc{
        self.appsrc.gst_element() as *const GstAppSrc
    }

    pub unsafe fn gst_appsrc_mut(&mut self) -> *mut GstAppSrc{
        self.appsrc.gst_element_mut() as *mut GstAppSrc
    }
}

impl AsRef<::Element> for AppSrc{
    fn as_ref(&self) -> &Element{
        &self.appsrc
    }
}

impl AsMut<::Element> for AppSrc{
    fn as_mut(&mut self) -> &mut Element{
        &mut self.appsrc
    }
}

impl From<AppSrc> for Element{
    fn from(b: AppSrc) -> Element{
        b.appsrc
    }
}

impl Deref for AppSrc{
    type Target = Element;
    fn deref(&self) -> &Element{
        &self.appsrc
    }
}

impl DerefMut for AppSrc{
    fn deref_mut(&mut self) -> &mut Element{
        &mut self.appsrc
    }
}

impl ::Transfer for AppSrc{
    unsafe fn transfer(self) -> *mut GstElement{
        self.appsrc.transfer()
    }
}

impl Reference for AppSrc{
    fn reference(&self) -> AppSrc{
        AppSrc{ appsrc: self.appsrc.reference() }
    }
}