1 // Copyright (C) 2019 Vivia Nikolaidou <vivia@ahiru.eu>
2 //
3 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6 // option. This file may not be copied, modified, or distributed
7 // except according to those terms.
8 
9 use std::mem;
10 
11 use glib::translate::*;
12 
13 use MemoryFlags;
14 
15 #[derive(Debug, Clone)]
16 pub struct AllocationParams(gst_sys::GstAllocationParams);
17 
18 unsafe impl Send for AllocationParams {}
19 unsafe impl Sync for AllocationParams {}
20 
21 impl AllocationParams {
get_flags(&self) -> MemoryFlags22     pub fn get_flags(&self) -> MemoryFlags {
23         from_glib(self.0.flags)
24     }
25 
get_align(&self) -> usize26     pub fn get_align(&self) -> usize {
27         self.0.align
28     }
29 
get_prefix(&self) -> usize30     pub fn get_prefix(&self) -> usize {
31         self.0.prefix
32     }
33 
get_padding(&self) -> usize34     pub fn get_padding(&self) -> usize {
35         self.0.padding
36     }
37 
new(flags: MemoryFlags, align: usize, prefix: usize, padding: usize) -> Self38     pub fn new(flags: MemoryFlags, align: usize, prefix: usize, padding: usize) -> Self {
39         assert_initialized_main_thread!();
40         let allocationparams = unsafe {
41             let mut allocationparams: gst_sys::GstAllocationParams = mem::zeroed();
42 
43             allocationparams.flags = flags.to_glib();
44             allocationparams.align = align;
45             allocationparams.prefix = prefix;
46             allocationparams.padding = padding;
47 
48             allocationparams
49         };
50 
51         AllocationParams(allocationparams)
52     }
53 
as_ptr(&self) -> *const gst_sys::GstAllocationParams54     pub fn as_ptr(&self) -> *const gst_sys::GstAllocationParams {
55         &self.0
56     }
57 }
58 
59 impl From<gst_sys::GstAllocationParams> for AllocationParams {
from(params: gst_sys::GstAllocationParams) -> Self60     fn from(params: gst_sys::GstAllocationParams) -> Self {
61         AllocationParams(params)
62     }
63 }
64