cidre/cv/
pixel_buffer_pool.rs1use crate::{arc, cf, cv, define_cf_type, define_opts, os};
2
3define_cf_type!(
4 #[doc(alias = "CVPixelBufferPoolRef")]
5 PixelBufPool(cf::Type)
6);
7
8impl PixelBufPool {
9 #[doc(alias = "CVPixelBufferPoolCreate")]
10 #[inline]
11 pub fn new(
12 pool_attrs: Option<&cf::Dictionary>,
13 pixel_buf_attrs: Option<&cf::Dictionary>,
14 ) -> os::Result<arc::R<Self>> {
15 unsafe {
16 os::result_unchecked(|pool_out| {
17 Self::create_in(pool_attrs, pixel_buf_attrs, pool_out, None)
18 })
19 }
20 }
21
22 #[doc(alias = "CVPixelBufferPoolCreate")]
23 #[inline]
24 pub unsafe fn create_in(
25 pool_attrs: Option<&cf::Dictionary>,
26 pixel_buf_attrs: Option<&cf::Dictionary>,
27 pool_out: *mut Option<arc::R<PixelBufPool>>,
28 allocator: Option<&cf::Allocator>,
29 ) -> cv::Return {
30 unsafe { CVPixelBufferPoolCreate(allocator, pool_attrs, pixel_buf_attrs, pool_out) }
31 }
32
33 #[doc(alias = "CVPixelBufferPoolGetAttribute")]
34 #[inline]
35 pub fn attrs(&self) -> Option<&cf::Dictionary> {
36 unsafe { CVPixelBufferPoolGetAttributes(self) }
37 }
38
39 #[doc(alias = "CVPixelBufferPoolGetPixelBufferAttributes")]
40 #[inline]
41 pub fn pixel_buf_attrs(&self) -> Option<&cf::Dictionary> {
42 unsafe { CVPixelBufferPoolGetPixelBufferAttributes(self) }
43 }
44
45 #[inline]
46 pub unsafe fn create_pixel_buffer_in(
47 &self,
48 pixel_buf_out: *mut Option<arc::R<cv::PixelBuf>>,
49 allocator: Option<&cf::Allocator>,
50 ) -> cv::Return {
51 unsafe { CVPixelBufferPoolCreatePixelBuffer(allocator, self, pixel_buf_out) }
52 }
53
54 #[inline]
55 pub fn pixel_buf(&self) -> os::Result<arc::R<cv::PixelBuf>> {
56 unsafe {
57 os::result_unchecked(|pixel_buf_out| self.create_pixel_buffer_in(pixel_buf_out, None))
58 }
59 }
60
61 #[doc(alias = "CVPixelBufferPoolCreatePixelBufferWithAuxAttributes")]
62 #[inline]
63 pub unsafe fn create_pixel_buf_with_aux_attributes_in(
64 &self,
65 allocator: Option<&cf::Allocator>,
66 aux_attrs: Option<&cf::Dictionary>,
67 pixel_buf_out: *mut Option<arc::R<cv::PixelBuf>>,
68 ) -> cv::Return {
69 unsafe {
70 CVPixelBufferPoolCreatePixelBufferWithAuxAttributes(
71 allocator,
72 self,
73 aux_attrs,
74 pixel_buf_out,
75 )
76 }
77 }
78
79 #[inline]
80 pub fn pixel_buf_with_aux_attrs(
81 &self,
82 aux_attrs: Option<&cf::Dictionary>,
83 ) -> os::Result<arc::R<cv::PixelBuf>> {
84 unsafe {
85 os::result_unchecked(|pixel_buf_out| {
86 self.create_pixel_buf_with_aux_attributes_in(None, aux_attrs, pixel_buf_out)
87 })
88 }
89 }
90
91 #[inline]
92 pub fn flush(&self, options: FlushFlags) {
93 unsafe { CVPixelBufferPoolFlush(self, options) }
94 }
95}
96
97unsafe extern "C-unwind" {
98 fn CVPixelBufferPoolCreate(
99 allocator: Option<&cf::Allocator>,
100 pool_attrs: Option<&cf::Dictionary>,
101 pixel_buf_attrs: Option<&cf::Dictionary>,
102 pool_out: *mut Option<arc::R<PixelBufPool>>,
103 ) -> cv::Return;
104
105 fn CVPixelBufferPoolGetAttributes(pool: &PixelBufPool) -> Option<&cf::Dictionary>;
106 fn CVPixelBufferPoolGetPixelBufferAttributes(pool: &PixelBufPool) -> Option<&cf::Dictionary>;
107
108 fn CVPixelBufferPoolCreatePixelBuffer(
109 allocator: Option<&cf::Allocator>,
110 pixel_buf_pool: &PixelBufPool,
111 pixel_buf_out: *mut Option<arc::R<cv::PixelBuf>>,
112 ) -> cv::Return;
113
114 fn CVPixelBufferPoolCreatePixelBufferWithAuxAttributes(
115 allocator: Option<&cf::Allocator>,
116 pixel_buf_pool: &PixelBufPool,
117 aux_attrs: Option<&cf::Dictionary>,
118 pixel_buf_out: *mut Option<arc::R<cv::PixelBuf>>,
119 ) -> cv::Return;
120
121 fn CVPixelBufferPoolFlush(pool: &PixelBufPool, options: FlushFlags);
122
123}
124
125pub mod keys {
126 use crate::cf;
127
128 #[doc(alias = "kCVPixelBufferPoolMinimumBufferCountKey")]
129 #[inline]
130 pub fn minimum_buffer_count() -> &'static cf::String {
131 unsafe { kCVPixelBufferPoolMinimumBufferCountKey }
132 }
133
134 #[doc(alias = "kCVPixelBufferPoolMaximumBufferAgeKey")]
135 #[inline]
136 pub fn maximum_buffer_age() -> &'static cf::String {
137 unsafe { kCVPixelBufferPoolMaximumBufferAgeKey }
138 }
139
140 unsafe extern "C" {
141 static kCVPixelBufferPoolMinimumBufferCountKey: &'static cf::String;
142 static kCVPixelBufferPoolMaximumBufferAgeKey: &'static cf::String;
143 }
144}
145
146pub mod aux_attr_keys {
147 use crate::cf;
148
149 #[doc(alias = "kCVPixelBufferPoolAllocationThresholdKey")]
150 #[inline]
151 pub fn allocation_threashold() -> &'static cf::String {
152 unsafe { kCVPixelBufferPoolAllocationThresholdKey }
153 }
154
155 unsafe extern "C" {
156 static kCVPixelBufferPoolAllocationThresholdKey: &'static cf::String;
157 }
158}
159
160pub mod notifications {
161 use crate::cf;
162
163 #[doc(alias = "kCVPixelBufferPoolFreeBufferNotification")]
164 #[inline]
165 pub fn free_buf() -> &'static cf::NotificationName {
166 unsafe { kCVPixelBufferPoolFreeBufferNotification }
167 }
168
169 unsafe extern "C" {
170 static kCVPixelBufferPoolFreeBufferNotification: &'static cf::NotificationName;
171 }
172}
173
174define_opts!(
175 #[doc(alias = "CVPixelBufferPoolFlushFlags")]
176 pub FlushFlags(u64)
177);
178
179impl FlushFlags {
180 pub const NONE: Self = Self(0);
181
182 #[doc(alias = "kCVPixelBufferPoolFlushExcessBuffers")]
184 pub const EXCESS_BUFFERS: Self = Self(1);
185}